app/assets/javascripts/videochat.js.erb in social_stream-presence-0.8.4 vs app/assets/javascripts/videochat.js.erb in social_stream-presence-0.8.6

- old
+ new

@@ -1,19 +1,17 @@ //////////////////// //Global constants //////////////////// var opentok_apiKey = '<%=SocialStream::Presence.opentok_api_key%>'; - //Correspondence between slugs and session ids var slugOfSession = new Array(); //slugOfSession['session_id'] = "slug"; //////////////////// //Videochat button actions //////////////////// - function clickVideoChatButton(slug){ var videoBoxVisibility = toggleVideoBoxForSlug(slug); if (videoBoxVisibility) { openVideoChatWindow(slug); @@ -26,11 +24,10 @@ function closeVideoChatWindow(slug){ closeVideoSession(slug); return; } - //Single variable for all slugs. var reconnectAttemptsVideo = 1; function openVideoChatWindow(slug){ @@ -85,11 +82,10 @@ //Start negotiation negotiateVideoChatSession(slug); } - //////////////////// //Session establishment //////////////////// //VideoChat Session: Step 1 @@ -132,11 +128,10 @@ showNotificationOnVideoBox(slug, I18n.t('chat.videochat.serverIssue')); contactsInfo[slug].videoChatStatus="disconnected"; }); } - //VideoChat Session: Step 3 function sendVideoChatRequestToUser(slug){ contactsInfo[slug].videoChatStatus="waiting"; showNotificationOnVideoBox(slug,I18n.t('chat.videochat.waiting')); sendIQStanzaToRequestVideochat(slug); @@ -200,11 +195,10 @@ ///////////// // Videochat interface functions //////////// - function clientInfoReceivedTrigger(slug){ //Check for videochat request if ((slug in contactsInfo)&&(contactsInfo[slug].videoChatStatus="negotiating")){ connectingVideoChatSession(slug); } @@ -212,38 +206,31 @@ function showNotificationOnVideoBox(slug,msg){ setVideoBoxContent(slug,"<p class=\"video-info\"> " + msg +" </p>"); } - function updateInterfaceAfterVideoRequestReceived(slug){ if (contactsInfo[slug].videoChatStatus!="disconnected"){ sendIQStanzaToResponseVideochat(slug,"busy"); return; } else { contactsInfo[slug].videoChatStatus="pending"; } - var jid = slug+"@"+contactsInfo[slug].domain + //Show or create chatbox + createBuddyChatBox(slug); - //Show chatbox - if (createChatBox(slug, getNameFromSlug(slug), jid, user_name, user_jid)) { - } else { - getChatBoxForSlug(slug).chatbox("option", "boxManager").toggleBox(true); - }; - var chatBox = getChatBoxForSlug(slug); //Show invitation message showInvitationInVideoBox(slug); //Show videobox toggleVideoBoxForSlug(slug,true); } - function showInvitationInVideoBox(slug){ var title = "<p class=\"video-info\">" + I18n.t("chat.videochat.call", {name: getNameFromSlug(slug)}) + " </p>"; var msg = title + "<p class=\"video-request\"> <a class=\"videoChatButton\" slug=\""+slug+"\" value=\"yes\">" + I18n.t("chat.videochat.accept") + "</a> -" + " <a class=\"videoChatButton\" slug=\""+slug+"\" value=\"no\">" + I18n.t("chat.videochat.deny") + "</a> </p>"; setVideoBoxContent(slug,msg); @@ -335,22 +322,21 @@ function clickVideoChangeChatButton(slug){ togglePublisherDivOnVideoChat(slug); } + + //////////////// /// Tokbox management //////////////// - var OPENTOK_PUBLISHER_WIDTH = 235; var OPENTOK_PUBLISHER_HEIGHT = 145; var OPENTOK_SUBSCRIBER_WIDTH = 235; var OPENTOK_SUBSCRIBER_HEIGHT = 145; - - function initVideoCallWith(slug){ if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) { showNotificationOnVideoBox(slug,I18n.t('chat.videochat.requirements')); contactsInfo[slug].videoChatStatus="disconnected"; } else { @@ -363,11 +349,10 @@ contactsInfo[slug].session.connect(opentok_apiKey, contactsInfo[slug].user_token); slugOfSession[contactsInfo[slug].session_id] = slug; } } - function sessionConnectedHandler(event) { if (event.target.sessionId in slugOfSession){ var slug = slugOfSession[event.target.sessionId]; contactsInfo[slug].videoChatStatus="connected"; $(getChatBoxButtonForSlug(slug,"videoChange")).find("span").show(); @@ -398,35 +383,31 @@ } else { //Close } } - function sessionDisconnectedHandler(event) { // This signals that the user was disconnected from the Session. Any subscribers and publishers // will automatically be removed. This default behaviour can be prevented using event.preventDefault() var slug = slugOfSession[event.target.sessionId]; contactsInfo[slug].publisher = null; contactsInfo[slug].videoChatStatus="disconnected"; } - function streamCreatedHandler(event) { var slug = slugOfSession[event.target.sessionId]; subscribeToStreams(event.streams,slug); } function streamDestroyedHandler(event) { // This signals that a stream was destroyed. Any Subscribers will automatically be removed. // This default behaviour can be prevented using event.preventDefault() var slug = slugOfSession[event.target.sessionId]; - log("streamDestroyedHandler: se destruyo el stream de " + slug) closeVideoSession(slug); } - function subscribeToStreams(streams,slug) { var session = contactsInfo[slug].session for (var i = 0; i < streams.length; i++) { @@ -449,10 +430,9 @@ var subscriberProps = { width: OPENTOK_SUBSCRIBER_WIDTH, height: OPENTOK_SUBSCRIBER_HEIGHT }; session.subscribe(streams[i], stubDiv.id, subscriberProps); } } - function accessAllowed(event){ var slug = event.target.replacedDivId.split("&")[1]; togglePublisherDivOnVideoChat(slug); } \ No newline at end of file