social_stream 0.26.1 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/README.rdoc +10 -0
  2. data/base/lib/social_stream/base/version.rb +1 -1
  3. data/base/social_stream-base.gemspec +1 -1
  4. data/lib/social_stream/release/component.rb +5 -0
  5. data/lib/social_stream/release/global.rb +8 -7
  6. data/lib/social_stream/release/kernel.rb +24 -0
  7. data/lib/social_stream/version.rb +1 -1
  8. data/presence/app/assets/javascripts/jquery.flexselect.sstreampresence.js +2 -2
  9. data/presence/app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js +5 -5
  10. data/presence/app/assets/javascripts/presence.js.erb +6 -4
  11. data/presence/app/assets/javascripts/presence_XmppClient.js.erb +1146 -996
  12. data/presence/app/assets/javascripts/presence_audio.js.erb +74 -60
  13. data/presence/app/assets/javascripts/presence_game.js.erb +35 -22
  14. data/presence/app/assets/javascripts/presence_game_comunication.js.erb +22 -5
  15. data/presence/app/assets/javascripts/presence_game_factory.js.erb +1 -1
  16. data/presence/app/assets/javascripts/presence_game_interface.js.erb +33 -13
  17. data/presence/app/assets/javascripts/presence_notifications.js +206 -183
  18. data/presence/app/assets/javascripts/presence_parser.js +265 -247
  19. data/presence/app/assets/javascripts/presence_persistence.js +199 -188
  20. data/presence/app/assets/javascripts/presence_store.js +22 -11
  21. data/presence/app/assets/javascripts/presence_uiManager.js.erb +553 -530
  22. data/presence/app/assets/javascripts/presence_utilities.js +244 -219
  23. data/presence/app/assets/javascripts/presence_videochat.js.erb +436 -409
  24. data/presence/app/assets/javascripts/presence_windowManager.js +586 -532
  25. data/presence/app/views/chat/_index.html.erb +7 -13
  26. data/presence/config/locales/en.yml +2 -1
  27. data/presence/config/locales/es.yml +2 -1
  28. data/presence/ejabberd/ejabberd_files.zip +0 -0
  29. data/presence/ejabberd/ejabberd_scripts/authentication_script +9 -2
  30. data/presence/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
  31. data/presence/lib/generators/social_stream/presence/templates/initializer.rb +4 -0
  32. data/presence/lib/social_stream-presence.rb +3 -0
  33. data/presence/lib/social_stream/presence/version.rb +1 -1
  34. data/presence/lib/social_stream/presence/xmpp_server_order.rb +1 -0
  35. data/release.thor +33 -13
  36. data/social_stream.gemspec +2 -2
  37. metadata +90 -29
@@ -1,443 +1,470 @@
1
1
  ////////////////////
2
- //Global constants
2
+ //videochat Module
3
3
  ////////////////////
4
- var opentok_apiKey = '<%=SocialStream::Presence.opentok_api_key%>';
5
4
 
6
- //Correspondence between slugs and session ids
7
- var slugOfSession = new Array();
8
- //slugOfSession['session_id'] = "slug";
5
+ PRESENCE.VIDEOCHAT = (function(P,$,undefined){
9
6
 
10
- ////////////////////
11
- //Videochat button actions
12
- ////////////////////
13
- function clickVideoChatButton(slug){
14
- var videoBoxVisibility = toggleVideoBoxForSlug(slug);
15
-
16
- if (videoBoxVisibility) {
17
- openVideoChatWindow(slug);
18
- } else {
19
- closeVideoChatWindow(slug);
7
+ var init = function(){
8
+ checkVideocallFeature();
20
9
  }
21
- }
22
-
23
- function closeVideoChatWindow(slug){
24
- //Show games button
25
- $(getChatBoxButtonForSlug(slug,"games")).show()
26
- closeVideoSession(slug);
27
- return;
28
- }
29
10
 
30
- //Single variable for all slugs.
31
- var reconnectAttemptsVideo = 1;
32
-
33
- function openVideoChatWindow(slug){
34
-
35
- //Hide games button
36
- $(getChatBoxButtonForSlug(slug,"games")).hide()
37
-
38
- if (slug in contactsInfo) {
39
- var connectionStatus = contactsInfo[slug].videoChatStatus;
40
- } else {
41
- var connectionStatus = null;
42
- }
43
-
44
- if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) {
45
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.requirements'));
46
- if(connectionStatus!=null){
47
- contactsInfo[slug].videoChatStatus = "disconnected";
48
- }
49
- return;
50
- }
51
-
52
- if(! isUserConnected()){
53
- showNotificationOnVideoBox(slug, I18n.t("chat.videochat.offline"));
54
- if(connectionStatus!=null){
55
- contactsInfo[slug].videoChatStatus = "disconnected";
11
+ //Videochat variables
12
+ var opentok_apiKey = '<%=SocialStream::Presence.opentok_api_key%>';
13
+
14
+ //Correspondence between slugs and session ids
15
+ var slugOfSession = new Array();
16
+ //slugOfSession['session_id'] = "slug";
17
+
18
+ ////////////////////
19
+ //Videochat button actions
20
+ ////////////////////
21
+ var clickVideoChatButton = function(slug){
22
+ var videoBoxVisibility = PRESENCE.WINDOW.toggleVideoBoxForSlug(slug);
23
+
24
+ if (videoBoxVisibility) {
25
+ openVideoChatWindow(slug);
26
+ } else {
27
+ closeVideoChatWindow(slug);
56
28
  }
57
- return;
58
- }
59
-
60
- if(! isSlugChatConnected(slug)){
61
- showNotificationOnVideoBox(slug, I18n.t("chat.videochat.guestOffline", {name: getNameFromSlug(slug)}));
62
- if(connectionStatus!=null){
63
- contactsInfo[slug].videoChatStatus = "disconnected";
64
- }
65
- return;
66
- }
67
-
68
- if(connectionStatus==null){
69
- if(reconnectAttemptsVideo > 0){
70
- reconnectAttemptsVideo--;
71
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.connectingWait'));
72
- setTimeout(function() { openVideoChatWindow(slug); }, 5000);
73
- } else {
74
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.unable'));
75
- }
76
- return;
77
- } else {
78
- reconnectAttemptsVideo = 1;
79
29
  }
80
30
 
81
- if(connectionStatus!="disconnected"){
82
- return;
83
- }
84
-
85
- //connectionStatus=="disconnected"
86
- //Start negotiation
87
- negotiateVideoChatSession(slug);
88
- }
89
-
90
-
91
- ////////////////////
92
- //Session establishment
93
- ////////////////////
94
-
95
- //VideoChat Session: Step 1
96
- function negotiateVideoChatSession(slug){
97
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.negotiating'));
98
- contactsInfo[slug].videoChatStatus="negotiating";
99
-
100
- if(contactsInfo[slug].version != null){
101
- connectingVideoChatSession(slug);
102
- return;
103
- } else {
104
- sendIQStanzaForRequestClientInfo(slug);
105
- }
106
- }
107
-
108
- //VideoChat Session: Step 2
109
- function connectingVideoChatSession(slug){
110
- if (contactsInfo[slug].version == getJavascriptXMPPClientName()) {
111
- contactsInfo[slug].videoChatStatus="connecting";
112
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.connecting'));
113
- requestSessionIDAndTokenForVideoChat(slug);
114
- } else {
115
- showNotificationOnVideoBox(slug,I18n.t("chat.videochat.clientIssue", {name: getNameFromSlug(slug)}));
116
- contactsInfo[slug].videoChatStatus="disconnected";
31
+ var closeVideoChatWindow = function(slug){
32
+ //Show games button
33
+ $(PRESENCE.WINDOW.getChatBoxButtonForSlug(slug,"games")).show()
34
+ closeVideoSession(slug);
35
+ return;
117
36
  }
118
- }
119
-
120
- function requestSessionIDAndTokenForVideoChat(slug){
121
- $.post("/requestVideoChat.xml", { }, function(data){
122
- var session = $(data).find("session");
123
- if (session.length == 1) {
124
- if (($(session).find("id").length == 1) && (($(session).find("user_token").length == 1)) && (($(session).find("guest_token").length == 1))) {
125
- contactsInfo[slug].session_id = $(session).find("id").text();
126
- contactsInfo[slug].user_token = $(session).find("user_token").text();
127
- contactsInfo[slug].guest_token = $(session).find("guest_token").text();
128
- sendVideoChatRequestToUser(slug);
129
- return;
130
- }
37
+
38
+ //Single variable for all slugs.
39
+ var reconnectAttemptsVideo = 1;
40
+
41
+ var openVideoChatWindow = function(slug){
42
+
43
+ //Hide games button
44
+ $(PRESENCE.WINDOW.getChatBoxButtonForSlug(slug,"games")).hide()
45
+
46
+ if (slug in contactsInfo) {
47
+ var connectionStatus = contactsInfo[slug].videoChatStatus;
48
+ } else {
49
+ var connectionStatus = null;
50
+ }
51
+
52
+ if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) {
53
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.requirements'));
54
+ if(connectionStatus!=null){
55
+ contactsInfo[slug].videoChatStatus = "disconnected";
56
+ }
57
+ return;
58
+ }
59
+
60
+ if(! PRESENCE.XMPPClient.isUserConnected()){
61
+ showNotificationOnVideoBox(slug, I18n.t("chat.videochat.offline"));
62
+ if(connectionStatus!=null){
63
+ contactsInfo[slug].videoChatStatus = "disconnected";
64
+ }
65
+ return;
131
66
  }
132
- showNotificationOnVideoBox(slug, I18n.t('chat.videochat.serverIssue'));
133
- contactsInfo[slug].videoChatStatus="disconnected";
134
- });
135
- }
136
-
137
- //VideoChat Session: Step 3
138
- function sendVideoChatRequestToUser(slug){
139
- contactsInfo[slug].videoChatStatus="waiting";
140
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.waiting'));
141
- sendIQStanzaToRequestVideochat(slug);
142
- }
143
-
144
- //VideoChat Session: Step 4
145
- function receiveVideoChatResponseFromUser(slug,response){
146
67
 
147
- if(contactsInfo[slug].videoChatStatus!="waiting"){
148
- return;
68
+ if(! PRESENCE.UIMANAGER.isSlugChatConnected(slug)){
69
+ showNotificationOnVideoBox(slug, I18n.t("chat.videochat.guestOffline", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)}));
70
+ if(connectionStatus!=null){
71
+ contactsInfo[slug].videoChatStatus = "disconnected";
72
+ }
73
+ return;
74
+ }
75
+
76
+ if(connectionStatus==null){
77
+ if(reconnectAttemptsVideo > 0){
78
+ reconnectAttemptsVideo--;
79
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.connectingWait'));
80
+ setTimeout(function() { openVideoChatWindow(slug); }, 5000);
81
+ } else {
82
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.unable'));
83
+ }
84
+ return;
85
+ } else {
86
+ reconnectAttemptsVideo = 1;
87
+ }
88
+
89
+ if(connectionStatus!="disconnected"){
90
+ return;
91
+ }
92
+
93
+ //connectionStatus=="disconnected"
94
+ //Start negotiation
95
+ negotiateVideoChatSession(slug);
149
96
  }
150
97
 
151
- if(response=="yes"){
152
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.establishing'));
153
- contactsInfo[slug].videoChatStatus="establishing";
154
- initVideoCallWith(slug);
155
- } else if (response=="no"){
156
- showNotificationOnVideoBox(slug,I18n.t("chat.videochat.rejected", {name: getNameFromSlug(slug)}));
157
- contactsInfo[slug].videoChatStatus="disconnected";
158
- } else {
159
- showNotificationOnVideoBox(slug,I18n.t("chat.videochat.rejectedBusy", {name: getNameFromSlug(slug)}));
160
- contactsInfo[slug].videoChatStatus="disconnected";
98
+
99
+ ////////////////////
100
+ //Session establishment
101
+ ////////////////////
102
+
103
+ //VideoChat Session: Step 1
104
+ var negotiateVideoChatSession = function(slug){
105
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.negotiating'));
106
+ contactsInfo[slug].videoChatStatus="negotiating";
107
+
108
+ if(contactsInfo[slug].version != null){
109
+ connectingVideoChatSession(slug);
110
+ return;
111
+ } else {
112
+ PRESENCE.XMPPClient.sendIQStanzaForRequestClientInfo(slug);
113
+ }
161
114
  }
162
- }
163
-
164
- //Cancelation received
165
- function receiveVideoChatCancelationFromUser(slug){
166
- if(slug in contactsInfo){
167
- if(contactsInfo[slug].videoChatStatus=="pending"){
168
- showNotificationOnVideoBox(slug,I18n.t("chat.videochat.cancel", {name: getNameFromSlug(slug)}));
169
- contactsInfo[slug].videoChatStatus="disconnected";
170
- }
171
- } else {
172
- closeVideoSession(slug);
115
+
116
+ //VideoChat Session: Step 2
117
+ var connectingVideoChatSession = function(slug){
118
+ if (contactsInfo[slug].version == PRESENCE.XMPPClient.getJavascriptXMPPClientName()) {
119
+ contactsInfo[slug].videoChatStatus="connecting";
120
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.connecting'));
121
+ requestSessionIDAndTokenForVideoChat(slug);
122
+ } else {
123
+ showNotificationOnVideoBox(slug,I18n.t("chat.videochat.clientIssue", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)}));
124
+ contactsInfo[slug].videoChatStatus="disconnected";
125
+ }
173
126
  }
174
- }
175
-
176
- //VideoChat Session: Step 5
177
- function closeVideoSession(slug){
178
- if(slug in contactsInfo){
179
- var connectionStatus = contactsInfo[slug].videoChatStatus;
180
-
181
- if(connectionStatus=="connected"){
182
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.disconnecting'));
183
- //Close opentok session...
184
- if(contactsInfo[slug].session.connected){
185
- contactsInfo[slug].session.disconnect();
127
+
128
+ var requestSessionIDAndTokenForVideoChat = function(slug){
129
+ $.post("/requestVideoChat.xml", { }, function(data){
130
+ var session = $(data).find("session");
131
+ if (session.length == 1) {
132
+ if (($(session).find("id").length == 1) && (($(session).find("user_token").length == 1)) && (($(session).find("guest_token").length == 1))) {
133
+ contactsInfo[slug].session_id = $(session).find("id").text();
134
+ contactsInfo[slug].user_token = $(session).find("user_token").text();
135
+ contactsInfo[slug].guest_token = $(session).find("guest_token").text();
136
+ sendVideoChatRequestToUser(slug);
137
+ return;
138
+ }
186
139
  }
187
- restoreChatBoxAfterVideoCall(slug);
188
- } else if(connectionStatus=="waiting"){
189
- sendIQStanzaToCancelVideochat(slug);
190
- } else if(connectionStatus=="pending"){
191
- sendIQStanzaToResponseVideochat(slug,"no");
192
- }
193
- contactsInfo[slug].videoChatStatus="disconnected";
140
+ showNotificationOnVideoBox(slug, I18n.t('chat.videochat.serverIssue'));
141
+ contactsInfo[slug].videoChatStatus="disconnected";
142
+ });
194
143
  }
195
144
 
196
- toggleVideoBoxForSlug(slug,false);
197
- }
198
-
199
-
200
-
201
- /////////////
202
- // Videochat interface functions
203
- ////////////
204
- function clientInfoReceivedTrigger(slug){
205
- //Check for videochat request
206
- if ((slug in contactsInfo)&&(contactsInfo[slug].videoChatStatus="negotiating")){
207
- connectingVideoChatSession(slug);
208
- }
209
- }
210
-
211
- function showNotificationOnVideoBox(slug,msg){
212
- setVideoBoxContent(slug,"<p class=\"video-info\"> " + msg +" </p>");
213
- }
214
-
215
- function updateInterfaceAfterVideoRequestReceived(slug){
145
+ //VideoChat Session: Step 3
146
+ var sendVideoChatRequestToUser = function(slug){
147
+ contactsInfo[slug].videoChatStatus="waiting";
148
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.waiting'));
149
+ PRESENCE.XMPPClient.sendIQStanzaToRequestVideochat(slug);
150
+ }
151
+
152
+ //VideoChat Session: Step 4
153
+ var receiveVideoChatResponseFromUser = function(slug,response){
154
+
155
+ if(contactsInfo[slug].videoChatStatus!="waiting"){
156
+ return;
157
+ }
158
+
159
+ if(response=="yes"){
160
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.establishing'));
161
+ contactsInfo[slug].videoChatStatus="establishing";
162
+ initVideoCallWith(slug);
163
+ } else if (response=="no"){
164
+ showNotificationOnVideoBox(slug,I18n.t("chat.videochat.rejected", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)}));
165
+ contactsInfo[slug].videoChatStatus="disconnected";
166
+ } else {
167
+ showNotificationOnVideoBox(slug,I18n.t("chat.videochat.rejectedBusy", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)}));
168
+ contactsInfo[slug].videoChatStatus="disconnected";
169
+ }
170
+ }
171
+
172
+ //Cancelation received
173
+ var receiveVideoChatCancelationFromUser = function(slug){
174
+ if(slug in contactsInfo){
175
+ if(contactsInfo[slug].videoChatStatus=="pending"){
176
+ showNotificationOnVideoBox(slug,I18n.t("chat.videochat.cancel", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)}));
177
+ contactsInfo[slug].videoChatStatus="disconnected";
178
+ }
179
+ } else {
180
+ closeVideoSession(slug);
181
+ }
182
+ }
216
183
 
217
- if (contactsInfo[slug].videoChatStatus!="disconnected"){
218
- sendIQStanzaToResponseVideochat(slug,"busy");
219
- return;
220
- } else {
221
- contactsInfo[slug].videoChatStatus="pending";
184
+ //VideoChat Session: Step 5
185
+ var closeVideoSession = function(slug){
186
+ if(slug in contactsInfo){
187
+ var connectionStatus = contactsInfo[slug].videoChatStatus;
188
+
189
+ if(connectionStatus=="connected"){
190
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.disconnecting'));
191
+ //Close opentok session...
192
+ if(contactsInfo[slug].session.connected){
193
+ contactsInfo[slug].session.disconnect();
194
+ }
195
+ restoreChatBoxAfterVideoCall(slug);
196
+ } else if(connectionStatus=="waiting"){
197
+ PRESENCE.XMPPClient.sendIQStanzaToCancelVideochat(slug);
198
+ } else if(connectionStatus=="pending"){
199
+ PRESENCE.XMPPClient.sendIQStanzaToResponseVideochat(slug,"no");
200
+ }
201
+ contactsInfo[slug].videoChatStatus="disconnected";
202
+ }
203
+
204
+ PRESENCE.WINDOW.toggleVideoBoxForSlug(slug,false);
222
205
  }
223
206
 
224
- //Show or create chatbox
225
- createBuddyChatBox(slug);
226
207
 
227
- var chatBox = getChatBoxForSlug(slug);
228
208
 
229
- //Show invitation message
230
- showInvitationInVideoBox(slug);
209
+ /////////////
210
+ // Videochat interface functions
211
+ ////////////
212
+ var clientInfoReceivedTrigger = function(slug){
213
+ //Check for videochat request
214
+ if ((slug in contactsInfo)&&(contactsInfo[slug].videoChatStatus="negotiating")){
215
+ connectingVideoChatSession(slug);
216
+ }
217
+ }
231
218
 
232
- //Show videobox
233
- toggleVideoBoxForSlug(slug,true);
234
- }
235
-
236
- function showInvitationInVideoBox(slug){
237
- var title = "<p class=\"video-info\">" + I18n.t("chat.videochat.call", {name: getNameFromSlug(slug)}) + " </p>";
238
- var msg = title + "<p class=\"video-request\"> <a class=\"videoChatButton\" slug=\""+slug+"\" value=\"yes\">" + I18n.t("chat.videochat.accept") + "</a> -"
239
- + " <a class=\"videoChatButton\" slug=\""+slug+"\" value=\"no\">" + I18n.t("chat.videochat.deny") + "</a> </p>";
240
- setVideoBoxContent(slug,msg);
241
- setVideochatRequestButtonsFunction();
242
- }
243
-
244
- function setVideochatRequestButtonsFunction(){
245
- $(".videoChatButton").click(function(event) {
246
- event.preventDefault();
247
- var result = $(this).attr("value");
248
- var slug = $(this).attr("slug");
249
- sendIQStanzaToResponseVideochat(slug,result);
250
-
251
- if(result=="yes"){
252
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.establishing'));
253
- contactsInfo[slug].videoChatStatus="establishing";
254
- initVideoCallWith(slug);
255
- } else {
256
- contactsInfo[slug].videoChatStatus="disconnected";
257
- closeVideoSession(slug);
258
- }
259
- });
260
- }
261
-
262
- function togglePublisherDivOnVideoChat(slug){
263
- var publisherDiv = getPublisherVideoBoxForSlug(slug);
264
- var chatBox = getChatBoxForSlug(slug);
265
- var videoBox = getVideoBoxForSlug(slug);
219
+ var showNotificationOnVideoBox = function(slug,msg){
220
+ PRESENCE.WINDOW.setVideoBoxContent(slug,"<p class=\"video-info\"> " + msg +" </p>");
221
+ }
266
222
 
267
- if((chatBox==null)||(videoBox==null)||(publisherDiv==null)){
268
- return;
223
+ var updateInterfaceAfterVideoRequestReceived = function(slug){
224
+
225
+ if (contactsInfo[slug].videoChatStatus!="disconnected"){
226
+ PRESENCE.XMPPClient.sendIQStanzaToResponseVideochat(slug,"busy");
227
+ return;
228
+ } else {
229
+ contactsInfo[slug].videoChatStatus="pending";
230
+ }
231
+
232
+ //Show or create chatbox
233
+ PRESENCE.WINDOW.createBuddyChatBox(slug);
234
+
235
+ var chatBox = PRESENCE.WINDOW.getChatBoxForSlug(slug);
236
+
237
+ //Show invitation message
238
+ showInvitationInVideoBox(slug);
239
+
240
+ //Show videobox
241
+ PRESENCE.WINDOW.toggleVideoBoxForSlug(slug,true);
269
242
  }
270
243
 
271
- var videoBoxVisibility = publisherDiv.css("z-index")!="-1";
272
-
273
- var desp = OPENTOK_PUBLISHER_HEIGHT + 1;
274
-
275
- var scrollHeight = $(chatBox)[0].scrollHeight;
276
- var outerHeight = chatBox.outerHeight();
277
- var diff = scrollHeight - chatBox.scrollTop() - outerHeight;
278
- var scrollMov = 145;
279
-
280
- if (! videoBoxVisibility){
281
- //Show publisher div
282
- publisherDiv.css("z-index","100");
283
- //Resize windows
284
- chatBox.css("height",chatBox.height() - desp );
285
- videoBox.css("height",videoBox.height() + desp );
286
- chatBox.scrollTop(chatBox.scrollTop() + scrollMov);
287
- } else {
288
- //Hide publisher div
289
- publisherDiv.css("z-index","-1");
290
- //Resize windows
291
- chatBox.css("height",chatBox.height() + desp );
292
- videoBox.css("height",videoBox.height() - desp );
293
- if(diff < desp){
294
- chatBox.scrollTop(chatBox.scrollTop() - diff);
295
- } else {
296
- chatBox.scrollTop(chatBox.scrollTop() - scrollMov);
297
- }
298
- }
299
- }
300
-
301
- function restoreChatBoxAfterVideoCall(slug){
302
- //Original dimensions
303
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.disconnected'));
304
- $(getChatBoxButtonForSlug(slug,"videoChange")).find("span").hide();
305
- toggleVideoBoxForSlug(slug,false);
306
- var chatBox = getChatBoxForSlug(slug);
307
- chatBox.height(chatBoxHeight);
308
- }
309
-
310
- function checkVideocallFeature(){
311
- if (opentok_apiKey=="default"){
312
- //Hide videochat buttons
313
-
314
- //Changing Tooltip CSS class by JQuery
315
- var ss = document.styleSheets;
316
- for (var i=0; i<ss.length; i++) {
317
- var rules = ss[i].cssRules || ss[i].rules;
318
- for (var j=0; j<rules.length; j++) {
319
- if (rules[j].selectorText === ".chat-videothick") {
320
- rules[j].style.display = 'none'
321
- }
322
- }
323
- }
244
+ var showInvitationInVideoBox = function(slug){
245
+ var title = "<p class=\"video-info\">" + I18n.t("chat.videochat.call", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)}) + " </p>";
246
+ var msg = title + "<p class=\"video-request\"> <a class=\"videoChatButton\" slug=\""+slug+"\" value=\"yes\">" + I18n.t("chat.videochat.accept") + "</a> -"
247
+ + " <a class=\"videoChatButton\" slug=\""+slug+"\" value=\"no\">" + I18n.t("chat.videochat.deny") + "</a> </p>";
248
+ PRESENCE.WINDOW.setVideoBoxContent(slug,msg);
249
+ setVideochatRequestButtonsFunction();
250
+ }
251
+
252
+ var setVideochatRequestButtonsFunction = function(){
253
+ $(".videoChatButton").click(function(event) {
254
+ event.preventDefault();
255
+ var result = $(this).attr("value");
256
+ var slug = $(this).attr("slug");
257
+ PRESENCE.XMPPClient.sendIQStanzaToResponseVideochat(slug,result);
258
+
259
+ if(result=="yes"){
260
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.establishing'));
261
+ contactsInfo[slug].videoChatStatus="establishing";
262
+ initVideoCallWith(slug);
263
+ } else {
264
+ contactsInfo[slug].videoChatStatus="disconnected";
265
+ closeVideoSession(slug);
266
+ }
267
+ });
268
+ }
269
+
270
+ var togglePublisherDivOnVideoChat = function(slug){
271
+ var publisherDiv = PRESENCE.WINDOW.getPublisherVideoBoxForSlug(slug);
272
+ var chatBox = PRESENCE.WINDOW.getChatBoxForSlug(slug);
273
+ var videoBox = PRESENCE.WINDOW.getVideoBoxForSlug(slug);
274
+
275
+ if((chatBox==null)||(videoBox==null)||(publisherDiv==null)){
276
+ return;
277
+ }
278
+
279
+ var videoBoxVisibility = publisherDiv.css("z-index")!="-1";
280
+
281
+ var desp = OPENTOK_PUBLISHER_HEIGHT + 1;
282
+
283
+ var scrollHeight = $(chatBox)[0].scrollHeight;
284
+ var outerHeight = chatBox.outerHeight();
285
+ var diff = scrollHeight - chatBox.scrollTop() - outerHeight;
286
+ var scrollMov = 145;
287
+
288
+ if (! videoBoxVisibility){
289
+ //Show publisher div
290
+ publisherDiv.css("z-index","100");
291
+ //Resize windows
292
+ chatBox.css("height",chatBox.height() - desp );
293
+ videoBox.css("height",videoBox.height() + desp );
294
+ chatBox.scrollTop(chatBox.scrollTop() + scrollMov);
295
+ } else {
296
+ //Hide publisher div
297
+ publisherDiv.css("z-index","-1");
298
+ //Resize windows
299
+ chatBox.css("height",chatBox.height() + desp );
300
+ videoBox.css("height",videoBox.height() - desp );
301
+ if(diff < desp){
302
+ chatBox.scrollTop(chatBox.scrollTop() - diff);
303
+ } else {
304
+ chatBox.scrollTop(chatBox.scrollTop() - scrollMov);
305
+ }
306
+ }
307
+ }
308
+
309
+ var restoreChatBoxAfterVideoCall = function(slug){
310
+ //Original dimensions
311
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.disconnected'));
312
+ $(PRESENCE.WINDOW.getChatBoxButtonForSlug(slug,"videoChange")).find("span").hide();
313
+ PRESENCE.WINDOW.toggleVideoBoxForSlug(slug,false);
314
+ var chatBox = PRESENCE.WINDOW.getChatBoxForSlug(slug);
315
+ chatBox.height(PRESENCE.WINDOW.getChatBoxHeight());
316
+ }
317
+
318
+ var checkVideocallFeature = function(){
319
+ if (opentok_apiKey=="default"){
320
+ //Hide videochat buttons
321
+
322
+ //Changing chat-videothick CSS class by JQuery
323
+ var ss = document.styleSheets;
324
+ for (var i=0; i<ss.length; i++) {
325
+ var rules = ss[i].cssRules || ss[i].rules;
326
+ if (rules != undefined){
327
+ for (var j=0; j<rules.length; j++) {
328
+ if (rules[j].selectorText === ".chat-videothick") {
329
+ rules[j].style.display = 'none'
330
+ }
331
+ }
332
+ }
333
+ }
334
+ }
335
+ }
336
+
337
+ var clickVideoChangeChatButton = function(slug){
338
+ togglePublisherDivOnVideoChat(slug);
324
339
  }
325
- }
326
-
327
- function clickVideoChangeChatButton(slug){
328
- togglePublisherDivOnVideoChat(slug);
329
- }
330
-
331
-
332
-
333
- ////////////////
334
- /// Tokbox management
335
- ////////////////
336
- var OPENTOK_PUBLISHER_WIDTH = 235;
337
- var OPENTOK_PUBLISHER_HEIGHT = 145;
338
-
339
- var OPENTOK_SUBSCRIBER_WIDTH = 235;
340
- var OPENTOK_SUBSCRIBER_HEIGHT = 145;
341
-
342
- function initVideoCallWith(slug){
343
- if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) {
344
- showNotificationOnVideoBox(slug,I18n.t('chat.videochat.requirements'));
345
- contactsInfo[slug].videoChatStatus="disconnected";
346
- } else {
347
- //TB.setLogLevel(TB.DEBUG);
348
- contactsInfo[slug].session = TB.initSession(contactsInfo[slug].session_id);
349
- contactsInfo[slug].session.addEventListener('sessionConnected', sessionConnectedHandler);
350
- contactsInfo[slug].session.addEventListener('sessionDisconnected', sessionDisconnectedHandler);
351
- contactsInfo[slug].session.addEventListener('streamCreated', streamCreatedHandler);
352
- contactsInfo[slug].session.addEventListener('streamDestroyed', streamDestroyedHandler);
353
- contactsInfo[slug].session.connect(opentok_apiKey, contactsInfo[slug].user_token);
354
- slugOfSession[contactsInfo[slug].session_id] = slug;
355
- }
356
- }
357
340
 
358
- function sessionConnectedHandler(event) {
359
- if (event.target.sessionId in slugOfSession){
341
+
342
+ ////////////////
343
+ /// Tokbox management
344
+ ////////////////
345
+ var OPENTOK_PUBLISHER_WIDTH = 235;
346
+ var OPENTOK_PUBLISHER_HEIGHT = 145;
347
+
348
+ var OPENTOK_SUBSCRIBER_WIDTH = 235;
349
+ var OPENTOK_SUBSCRIBER_HEIGHT = 145;
350
+
351
+ var initVideoCallWith = function(slug){
352
+ if (TB.checkSystemRequirements() != TB.HAS_REQUIREMENTS) {
353
+ showNotificationOnVideoBox(slug,I18n.t('chat.videochat.requirements'));
354
+ contactsInfo[slug].videoChatStatus="disconnected";
355
+ } else {
356
+ //TB.setLogLevel(TB.DEBUG);
357
+ contactsInfo[slug].session = TB.initSession(contactsInfo[slug].session_id);
358
+ contactsInfo[slug].session.addEventListener('sessionConnected', PRESENCE.VIDEOCHAT.sessionConnectedHandler);
359
+ contactsInfo[slug].session.addEventListener('sessionDisconnected', PRESENCE.VIDEOCHAT.sessionDisconnectedHandler);
360
+ contactsInfo[slug].session.addEventListener('streamCreated', PRESENCE.VIDEOCHAT.streamCreatedHandler);
361
+ contactsInfo[slug].session.addEventListener('streamDestroyed', PRESENCE.VIDEOCHAT.streamDestroyedHandler);
362
+ contactsInfo[slug].session.connect(opentok_apiKey, contactsInfo[slug].user_token);
363
+ slugOfSession[contactsInfo[slug].session_id] = slug;
364
+ }
365
+ }
366
+
367
+ var sessionConnectedHandler = function(event) {
368
+ if (event.target.sessionId in slugOfSession){
369
+ var slug = slugOfSession[event.target.sessionId];
370
+ contactsInfo[slug].videoChatStatus="connected";
371
+ $(PRESENCE.WINDOW.getChatBoxButtonForSlug(slug,"videoChange")).find("span").show();
372
+
373
+ //Create publishing div
374
+ var parentDiv = document.createElement('div');
375
+ var pubID = 'stream_publish_videochat_' + slug;
376
+ parentDiv.setAttribute('id', pubID);
377
+ parentDiv.setAttribute('class', 'stream_publish_videochat');
378
+
379
+ var stubDiv = document.createElement("div");
380
+ stubDiv.id = "opentok_publisher&" + slug;
381
+ parentDiv.appendChild(stubDiv);
382
+
383
+ //Interface update
384
+ PRESENCE.WINDOW.setVideoBoxContent(slug,parentDiv);
385
+
386
+ //Publish
387
+ var publisherProps = {width: OPENTOK_PUBLISHER_WIDTH, height: OPENTOK_PUBLISHER_HEIGHT};
388
+ contactsInfo[slug].publisher = contactsInfo[slug].session.publish(stubDiv.id, publisherProps);
389
+ contactsInfo[slug].publisher.addEventListener('accessAllowed', accessAllowed);
390
+
391
+ //Subscribe
392
+ subscribeToStreams(event.streams,slug);
393
+
394
+ //Toggle!
395
+ togglePublisherDivOnVideoChat(slug);
396
+ } else {
397
+ //Close
398
+ }
399
+ }
400
+
401
+ var sessionDisconnectedHandler = function(event) {
402
+ // This signals that the user was disconnected from the Session. Any subscribers and publishers
403
+ // will automatically be removed. This default behaviour can be prevented using event.preventDefault()
404
+
360
405
  var slug = slugOfSession[event.target.sessionId];
361
- contactsInfo[slug].videoChatStatus="connected";
362
- $(getChatBoxButtonForSlug(slug,"videoChange")).find("span").show();
363
-
364
- //Create publishing div
365
- var parentDiv = document.createElement('div');
366
- var pubID = 'stream_publish_videochat_' + slug;
367
- parentDiv.setAttribute('id', pubID);
368
- parentDiv.setAttribute('class', 'stream_publish_videochat');
369
-
370
- var stubDiv = document.createElement("div");
371
- stubDiv.id = "opentok_publisher&" + slug;
372
- parentDiv.appendChild(stubDiv);
373
-
374
- //Interface update
375
- setVideoBoxContent(slug,parentDiv);
376
-
377
- //Publish
378
- var publisherProps = {width: OPENTOK_PUBLISHER_WIDTH, height: OPENTOK_PUBLISHER_HEIGHT};
379
- contactsInfo[slug].publisher = contactsInfo[slug].session.publish(stubDiv.id, publisherProps);
380
- contactsInfo[slug].publisher.addEventListener('accessAllowed', accessAllowed);
381
-
382
- //Subscribe
383
- subscribeToStreams(event.streams,slug);
384
-
385
- //Toggle!
386
- togglePublisherDivOnVideoChat(slug);
387
- } else {
388
- //Close
406
+ contactsInfo[slug].publisher = null;
407
+ contactsInfo[slug].videoChatStatus="disconnected";
408
+ }
409
+
410
+ var streamCreatedHandler = function(event) {
411
+ var slug = slugOfSession[event.target.sessionId];
412
+ subscribeToStreams(event.streams,slug);
413
+ }
414
+
415
+ var streamDestroyedHandler = function(event) {
416
+ // This signals that a stream was destroyed. Any Subscribers will automatically be removed.
417
+ // This default behaviour can be prevented using event.preventDefault()
418
+ var slug = slugOfSession[event.target.sessionId];
419
+ closeVideoSession(slug);
420
+ }
421
+
422
+ var subscribeToStreams = function(streams,slug) {
423
+ var session = contactsInfo[slug].session
424
+
425
+ for (var i = 0; i < streams.length; i++) {
426
+
427
+ // Make sure we don't subscribe to ourself
428
+ if (streams[i].connection.connectionId == session.connection.connectionId) {
429
+ return;
430
+ }
431
+
432
+ // Create subscriber div
433
+ var parentDiv = document.createElement('div');
434
+ parentDiv.setAttribute('class', 'stream_videochat');
435
+
436
+ var stubDiv = document.createElement("div");
437
+ stubDiv.id = 'stream' + streams[i].streamId;
438
+ parentDiv.appendChild(stubDiv);
439
+
440
+ PRESENCE.WINDOW.addVideoBoxContent(slug,parentDiv);
441
+
442
+ // Subscribe to the stream
443
+ var subscriberProps = { width: OPENTOK_SUBSCRIBER_WIDTH,
444
+ height: OPENTOK_SUBSCRIBER_HEIGHT };
445
+ session.subscribe(streams[i], stubDiv.id, subscriberProps);
446
+ }
447
+ }
448
+
449
+ var accessAllowed = function(event){
450
+ var slug = event.target.replacedDivId.split("&")[1];
451
+ togglePublisherDivOnVideoChat(slug);
389
452
  }
390
- }
391
-
392
- function sessionDisconnectedHandler(event) {
393
- // This signals that the user was disconnected from the Session. Any subscribers and publishers
394
- // will automatically be removed. This default behaviour can be prevented using event.preventDefault()
395
-
396
- var slug = slugOfSession[event.target.sessionId];
397
- contactsInfo[slug].publisher = null;
398
- contactsInfo[slug].videoChatStatus="disconnected";
399
- }
400
-
401
- function streamCreatedHandler(event) {
402
- var slug = slugOfSession[event.target.sessionId];
403
- subscribeToStreams(event.streams,slug);
404
- }
405
-
406
- function streamDestroyedHandler(event) {
407
- // This signals that a stream was destroyed. Any Subscribers will automatically be removed.
408
- // This default behaviour can be prevented using event.preventDefault()
409
- var slug = slugOfSession[event.target.sessionId];
410
- closeVideoSession(slug);
411
- }
412
-
413
- function subscribeToStreams(streams,slug) {
414
- var session = contactsInfo[slug].session
415
-
416
- for (var i = 0; i < streams.length; i++) {
417
453
 
418
- // Make sure we don't subscribe to ourself
419
- if (streams[i].connection.connectionId == session.connection.connectionId) {
420
- return;
421
- }
422
-
423
- // Create subscriber div
424
- var parentDiv = document.createElement('div');
425
- parentDiv.setAttribute('class', 'stream_videochat');
426
-
427
- var stubDiv = document.createElement("div");
428
- stubDiv.id = 'stream' + streams[i].streamId;
429
- parentDiv.appendChild(stubDiv);
430
-
431
- addVideoBoxContent(slug,parentDiv);
432
-
433
- // Subscribe to the stream
434
- var subscriberProps = { width: OPENTOK_SUBSCRIBER_WIDTH,
435
- height: OPENTOK_SUBSCRIBER_HEIGHT };
436
- session.subscribe(streams[i], stubDiv.id, subscriberProps);
437
- }
438
- }
454
+ return {
455
+ init: init,
456
+ clickVideoChatButton : clickVideoChatButton,
457
+ clientInfoReceivedTrigger : clientInfoReceivedTrigger,
458
+ closeVideoSession : closeVideoSession,
459
+ updateInterfaceAfterVideoRequestReceived : updateInterfaceAfterVideoRequestReceived,
460
+ receiveVideoChatResponseFromUser : receiveVideoChatResponseFromUser,
461
+ receiveVideoChatCancelationFromUser : receiveVideoChatCancelationFromUser,
462
+ clickVideoChangeChatButton : clickVideoChangeChatButton,
463
+ sessionConnectedHandler : sessionConnectedHandler,
464
+ sessionDisconnectedHandler : sessionDisconnectedHandler,
465
+ streamCreatedHandler : streamCreatedHandler,
466
+ streamDestroyedHandler : streamDestroyedHandler
467
+ };
468
+
469
+ }) (PRESENCE, jQuery);
439
470
 
440
- function accessAllowed(event){
441
- var slug = event.target.replacedDivId.split("&")[1];
442
- togglePublisherDivOnVideoChat(slug);
443
- }