social_stream-presence 0.13.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/jquery.flexselect.sstreampresence.js +2 -2
- data/app/assets/javascripts/jquery.ui.chatbox.sstreampresence.js +5 -5
- data/app/assets/javascripts/presence.js.erb +6 -4
- data/app/assets/javascripts/presence_XmppClient.js.erb +1136 -996
- data/app/assets/javascripts/presence_audio.js.erb +74 -60
- data/app/assets/javascripts/presence_game.js.erb +35 -22
- data/app/assets/javascripts/presence_game_comunication.js.erb +22 -5
- data/app/assets/javascripts/presence_game_factory.js.erb +1 -1
- data/app/assets/javascripts/presence_game_interface.js.erb +33 -13
- data/app/assets/javascripts/presence_notifications.js +206 -183
- data/app/assets/javascripts/presence_parser.js +265 -247
- data/app/assets/javascripts/presence_persistence.js +199 -188
- data/app/assets/javascripts/presence_store.js +22 -11
- data/app/assets/javascripts/presence_uiManager.js.erb +553 -530
- data/app/assets/javascripts/presence_utilities.js +244 -219
- data/app/assets/javascripts/presence_videochat.js.erb +436 -409
- data/app/assets/javascripts/presence_windowManager.js +586 -532
- data/app/views/chat/_index.html.erb +7 -13
- data/config/locales/en.yml +2 -1
- data/config/locales/es.yml +2 -1
- data/ejabberd/ejabberd_files.zip +0 -0
- data/ejabberd/ejabberd_scripts/authentication_script +9 -2
- data/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
- data/lib/generators/social_stream/presence/templates/initializer.rb +4 -0
- data/lib/social_stream/presence/version.rb +1 -1
- data/lib/social_stream/presence/xmpp_server_order.rb +1 -0
- data/lib/social_stream-presence.rb +3 -0
- metadata +68 -63
@@ -1,443 +1,470 @@
|
|
1
1
|
////////////////////
|
2
|
-
//
|
2
|
+
//videochat Module
|
3
3
|
////////////////////
|
4
|
-
var opentok_apiKey = '<%=SocialStream::Presence.opentok_api_key%>';
|
5
4
|
|
6
|
-
|
7
|
-
var slugOfSession = new Array();
|
8
|
-
//slugOfSession['session_id'] = "slug";
|
5
|
+
PRESENCE.VIDEOCHAT = (function(P,$,undefined){
|
9
6
|
|
10
|
-
|
11
|
-
|
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
|
-
//
|
31
|
-
var
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
//
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
148
|
-
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
function
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
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
|
-
|
230
|
-
|
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
|
-
|
233
|
-
|
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
|
-
|
268
|
-
|
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
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
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
|
-
|
359
|
-
|
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
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
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
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
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
|
-
}
|