social_stream 0.12.8 → 0.12.9
Sign up to get free protection for your applications and to get access to all the features.
- data/base/app/assets/stylesheets/header.css.scss +2 -2
- data/base/app/controllers/conversations_controller.rb +1 -1
- data/base/app/views/settings/_index.html.erb +3 -0
- data/base/app/views/toolbar/_home.html.erb +1 -1
- data/base/config/locales/en.yml +2 -1
- data/base/config/locales/es.yml +3 -2
- data/base/lib/social_stream/base/version.rb +1 -1
- data/documents/config/locales/es.yml +1 -1
- data/documents/lib/social_stream/documents/version.rb +1 -1
- data/documents/social_stream-documents.gemspec +1 -1
- data/lib/social_stream/version.rb +1 -1
- data/presence/app/assets/javascripts/chat_audio.js +73 -0
- data/presence/app/assets/javascripts/chat_interface_manager.js.erb +197 -0
- data/presence/app/assets/javascripts/chat_parser.js +243 -0
- data/presence/app/assets/javascripts/chat_utilities.js +71 -0
- data/presence/app/assets/javascripts/chat_window_manager.js +138 -0
- data/presence/app/assets/javascripts/social_stream-presence.js +3 -0
- data/presence/app/assets/javascripts/store.js +0 -7
- data/presence/app/assets/javascripts/xmpp_client_management.js.erb +304 -0
- data/presence/app/assets/stylesheets/chat.css +40 -0
- data/presence/app/assets/stylesheets/social_stream-presence.css +1 -0
- data/presence/app/controllers/xmpp_controller.rb +43 -9
- data/presence/app/views/{xmpp/_chat_connecting.html.erb → chat/_connecting.html.erb} +0 -0
- data/presence/app/views/{xmpp/_chat_contacts.html.erb → chat/_contacts.html.erb} +0 -0
- data/presence/app/views/{xmpp/_chat.html.erb → chat/_index.html.erb} +3 -13
- data/presence/app/views/{xmpp/_chat_off.html.erb → chat/_off.html.erb} +0 -0
- data/presence/app/views/chat/_settings.html.erb +38 -0
- data/presence/config/routes.rb +1 -1
- data/presence/db/migrate/20111116194112_add_chat_enabled_column_to_user.rb +9 -0
- data/presence/{app → vendor}/assets/javascripts/jquery.tools.tooltip.js +0 -0
- data/presence/{app → vendor}/assets/javascripts/jquery.ui.chatbox.js +14 -12
- data/presence/{app → vendor}/assets/javascripts/strophe.js +0 -0
- data/presence/{app → vendor}/assets/stylesheets/jquery.ui.chatbox.css +0 -0
- data/social_stream.gemspec +2 -2
- metadata +26 -21
- data/presence/app/assets/javascripts/jquery-ui-1.8.14.custom.min.js +0 -789
- data/presence/app/assets/javascripts/jquery.tools.min.js +0 -17
- data/presence/app/assets/javascripts/xmpp_client.js.erb +0 -962
@@ -1,962 +0,0 @@
|
|
1
|
-
////////////////////
|
2
|
-
//Test functions
|
3
|
-
////////////////////
|
4
|
-
|
5
|
-
function log(msg) {
|
6
|
-
//console.log(msg)
|
7
|
-
}
|
8
|
-
|
9
|
-
////////////////////
|
10
|
-
//Hash table
|
11
|
-
////////////////////
|
12
|
-
var statusMessage = new Array();
|
13
|
-
statusMessage[''] = "";
|
14
|
-
statusMessage['chat'] = "";
|
15
|
-
statusMessage['away'] = "Away";
|
16
|
-
statusMessage['xa'] = "Away";
|
17
|
-
statusMessage['dnd'] = "Busy";
|
18
|
-
|
19
|
-
var statusIcons = new Array();
|
20
|
-
statusIcons[''] = "available";
|
21
|
-
statusIcons['chat'] = "available";
|
22
|
-
statusIcons['away'] = "away";
|
23
|
-
statusIcons['xa'] = "away";
|
24
|
-
statusIcons['dnd'] = "dnd";
|
25
|
-
|
26
|
-
var chatIcons = new Array();
|
27
|
-
chatIcons[':)'] = "face-smile.png";
|
28
|
-
chatIcons[':('] = "face-sad.png";
|
29
|
-
chatIcons['(B)'] = "beer.png";
|
30
|
-
chatIcons['(C)'] = "clock.png";
|
31
|
-
chatIcons['(P)'] = "present.png";
|
32
|
-
chatIcons[':P']= "face-raspberry.png";
|
33
|
-
chatIcons[':Z']= "face-tired.png";
|
34
|
-
chatIcons['(R)']= "rain.png";
|
35
|
-
chatIcons['(S)']= "sun.png";
|
36
|
-
chatIcons[';)']= "face-wink.png";
|
37
|
-
|
38
|
-
////////////////////
|
39
|
-
//Connect functions
|
40
|
-
////////////////////
|
41
|
-
|
42
|
-
function connectToServerWithCookie(){
|
43
|
-
try {
|
44
|
-
connection = new Strophe.Connection(BOSH_SERVICE);
|
45
|
-
connection.connect(user_jid, cookie, onConnect);
|
46
|
-
} catch (err) {
|
47
|
-
//"Handle errors"
|
48
|
-
return false;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
//Password: Get from chatPassword param if exists, instead try to get from sessionStorage.
|
53
|
-
function connectToServerWithPassword(chatPassword){
|
54
|
-
|
55
|
-
//Get Password
|
56
|
-
if ((chatPassword!=null)&&(chatPassword!="")){
|
57
|
-
var password = chatPassword;
|
58
|
-
} else if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)) {
|
59
|
-
var password = sessionStorage.getItem("ss_user_pass");
|
60
|
-
} else {
|
61
|
-
return false;
|
62
|
-
}
|
63
|
-
|
64
|
-
try {
|
65
|
-
//Connect actual user to the chat
|
66
|
-
connection = new Strophe.Connection(BOSH_SERVICE);
|
67
|
-
connection.connect(user_jid, password, onConnect);
|
68
|
-
} catch (err) {
|
69
|
-
//"Handle errors"
|
70
|
-
return false;
|
71
|
-
}
|
72
|
-
|
73
|
-
return true;
|
74
|
-
}
|
75
|
-
|
76
|
-
|
77
|
-
////////////////////
|
78
|
-
//Reconnect button functions
|
79
|
-
////////////////////
|
80
|
-
|
81
|
-
var connectButtonTimer;
|
82
|
-
var periodBetweenAttempts=15; //(seg)
|
83
|
-
var connectButtonTimerCounter=periodBetweenAttempts;
|
84
|
-
|
85
|
-
function connectButtonTimerFunction(){
|
86
|
-
if(connectButtonTimerCounter < periodBetweenAttempts){
|
87
|
-
connectButtonTimerCounter++;
|
88
|
-
} else if (connectButtonTimerCounter == periodBetweenAttempts) {
|
89
|
-
$("#chat_header_title").html('<%=I18n.t('chat.disconnected')%>')
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
function requestConnectToChat(){
|
94
|
-
if (connectButtonTimerCounter > (periodBetweenAttempts-1)) {
|
95
|
-
connectButtonTimerCounter=0;
|
96
|
-
$("#chat_header_title").html('<%=I18n.t('chat.connecting')%>')
|
97
|
-
return true
|
98
|
-
} else {
|
99
|
-
return false
|
100
|
-
}
|
101
|
-
}
|
102
|
-
|
103
|
-
////////////////////
|
104
|
-
//Strophe functions
|
105
|
-
////////////////////
|
106
|
-
|
107
|
-
//Global variables
|
108
|
-
var userStatus = "chat";
|
109
|
-
var awayTimerPeriod = 16000;
|
110
|
-
var timerPeriod = 5000;
|
111
|
-
var refreshMinTime = 3*timerPeriod;
|
112
|
-
var awayTime = 300000;
|
113
|
-
var awayCounter = 0;
|
114
|
-
var timerCounter = 0;
|
115
|
-
var connection = null;
|
116
|
-
var userConnected = false;
|
117
|
-
var reconnectAttempts = 3;
|
118
|
-
var awayTimer;
|
119
|
-
var timer;
|
120
|
-
var requestContacts=false;
|
121
|
-
var cyclesToRefresh = (refreshMinTime/timerPeriod);
|
122
|
-
|
123
|
-
function onConnect(status) {
|
124
|
-
|
125
|
-
//Status.ERROR An error has occurred
|
126
|
-
//Status.CONNECTING The connection is currently being made
|
127
|
-
//Status.CONNFAIL The connection attempt failed
|
128
|
-
//Status.AUTHENTICATING The connection is authenticating
|
129
|
-
//Status.AUTHFAIL The authentication attempt failed
|
130
|
-
//Status.CONNECTED The connection has succeeded
|
131
|
-
//Status.DISCONNECTED The connection has been terminated
|
132
|
-
//Status.DISCONNECTING The connection is currently being terminated
|
133
|
-
//Status.ATTACHED The connection has been attached
|
134
|
-
|
135
|
-
log('Strophe onConnect callback call with status ' + status);
|
136
|
-
|
137
|
-
if (status == Strophe.Status.ATTACHED){
|
138
|
-
log('Strophe connection attached');
|
139
|
-
return;
|
140
|
-
}
|
141
|
-
|
142
|
-
if (status == Strophe.Status.AUTHENTICATING ){
|
143
|
-
log('Strophe connection AUTHENTICATING');
|
144
|
-
return;
|
145
|
-
}
|
146
|
-
|
147
|
-
if (status == Strophe.Status.CONNECTING) {
|
148
|
-
log('Strophe is connecting.');
|
149
|
-
return;
|
150
|
-
}
|
151
|
-
|
152
|
-
|
153
|
-
clearTimeout(initialTimer);
|
154
|
-
|
155
|
-
if (status == Strophe.Status.CONNFAIL) {
|
156
|
-
log('Strophe failed to connect.');
|
157
|
-
userConnected = false;
|
158
|
-
setTimeout ("onReconnect()", 3000);
|
159
|
-
} else if (status == Strophe.Status.AUTHFAIL) {
|
160
|
-
log('Strophe authentication fail.');
|
161
|
-
if ((window.sessionStorage)&&(sessionStorage.getItem("ss_user_pass") != null)){
|
162
|
-
sessionStorage.setItem("ss_user_pass",null);
|
163
|
-
}
|
164
|
-
userConnected = false;
|
165
|
-
} else if (status == Strophe.Status.ERROR) {
|
166
|
-
log('Strophe error.');
|
167
|
-
userConnected = false;
|
168
|
-
} else if (status == Strophe.Status.DISCONNECTED) {
|
169
|
-
log('Strophe is disconnected.');
|
170
|
-
userConnected = false;
|
171
|
-
clearTimeout(awayTimer);
|
172
|
-
setTimeout ("onReconnect()", 3000);
|
173
|
-
} else if (status == Strophe.Status.CONNECTED) {
|
174
|
-
log('Strophe is connected.');
|
175
|
-
log('Presenze stanza send for:' + connection.jid);
|
176
|
-
connection.addHandler(onMessage, null, 'message', null, null, null);
|
177
|
-
connection.addHandler(onPresence, null, 'presence', null, null, null);
|
178
|
-
//addHandler:(callback, namespace to match, stanza name, stanza type, stanza id , stanza from, options)
|
179
|
-
sendStatus(userStatus);
|
180
|
-
userConnected = true;
|
181
|
-
awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
|
182
|
-
timer = setInterval("timerFunction()", timerPeriod);
|
183
|
-
}
|
184
|
-
|
185
|
-
updateChatWindow();
|
186
|
-
}
|
187
|
-
|
188
|
-
function onReconnect(){
|
189
|
-
if ((connection != null)&&(!userConnected)) {
|
190
|
-
if (reconnectAttempts>0) {
|
191
|
-
reconnectAttempts--;
|
192
|
-
connectToServer(null);
|
193
|
-
setTimeout ("onReconnect()", 9000);
|
194
|
-
} else {
|
195
|
-
//Notify issue to Rails App Server?
|
196
|
-
}
|
197
|
-
}
|
198
|
-
}
|
199
|
-
|
200
|
-
function onMessage(msg) {
|
201
|
-
var to = msg.getAttribute('to');
|
202
|
-
var from = msg.getAttribute('from');
|
203
|
-
var type = msg.getAttribute('type');
|
204
|
-
var elems = msg.getElementsByTagName('body');
|
205
|
-
|
206
|
-
if (type == "chat" && elems.length > 0) {
|
207
|
-
|
208
|
-
var body = elems[0];
|
209
|
-
var from_slug = from.split("@")[0];
|
210
|
-
var from_name = $("#" + from_slug).attr("name");
|
211
|
-
var from_jid = from_slug + "@" + domain;
|
212
|
-
|
213
|
-
|
214
|
-
if (typeof ($('div.user_presence[slug=' + from_slug + ']').attr('name')) == 'undefined') {
|
215
|
-
//No connectionBox for this user!
|
216
|
-
var from_name = from_slug;
|
217
|
-
refreshChatWindow();
|
218
|
-
} else {
|
219
|
-
showConnectionBoxFromSlug(from_slug);
|
220
|
-
var from_name = $('div.user_presence[slug=' + from_slug + ']').attr('name');
|
221
|
-
}
|
222
|
-
|
223
|
-
if (createChatBox(from_slug,from_name,from_jid,user_name,user_jid)) {
|
224
|
-
} else {
|
225
|
-
window[getChatVariableFromSlug(from_slug)].chatbox("option", "boxManager").toggleBox(true);
|
226
|
-
}
|
227
|
-
|
228
|
-
content = parseContent(Strophe.getText(body));
|
229
|
-
//Send message to chatBox and post-message functions.
|
230
|
-
$("#" + from_slug).chatbox("option", "boxManager").addMsg(from_name, content);
|
231
|
-
rotatePriority(from_slug);
|
232
|
-
blinkTitleOnMessage(from_name);
|
233
|
-
if (mustPlaySoundForChatWindow(window[getChatVariableFromSlug(from_slug)])){
|
234
|
-
playSound("onMessageAudio");
|
235
|
-
}
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
// we must return true to keep the handler alive.
|
240
|
-
// returning false would remove it after it finishes.
|
241
|
-
return true;
|
242
|
-
}
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
function onPresence(presence) {
|
247
|
-
|
248
|
-
//Check presence stanza type
|
249
|
-
ptype = $(presence).attr('type');
|
250
|
-
|
251
|
-
switch (ptype){
|
252
|
-
case undefined:
|
253
|
-
processAvailablePresenceStanza(presence)
|
254
|
-
break;
|
255
|
-
case "available":
|
256
|
-
processAvailablePresenceStanza(presence)
|
257
|
-
break;
|
258
|
-
case "unavailable":
|
259
|
-
processUnavailablePresenceStanza(presence)
|
260
|
-
break;
|
261
|
-
default :
|
262
|
-
//Stanza type not recognize
|
263
|
-
processAvailablePresenceStanza(presence)
|
264
|
-
}
|
265
|
-
|
266
|
-
return true;
|
267
|
-
}
|
268
|
-
|
269
|
-
function processAvailablePresenceStanza(presence){
|
270
|
-
from = $(presence).attr('from');
|
271
|
-
slug = from.split("@")[0];
|
272
|
-
|
273
|
-
if (slug != user_slug) {
|
274
|
-
if (getConnectionBoxFromSlug(slug)!=null){
|
275
|
-
status = $(presence).find('show').text();
|
276
|
-
setUserIconStatus(slug, status);
|
277
|
-
if (cacheConnectedUsers.indexOf(slug) != -1) {
|
278
|
-
showConnectionBoxFromSlug(slug);
|
279
|
-
}
|
280
|
-
} else {
|
281
|
-
setTimeout("refreshChatWindow()", 3000);
|
282
|
-
}
|
283
|
-
}
|
284
|
-
}
|
285
|
-
|
286
|
-
function processUnavailablePresenceStanza(presence){
|
287
|
-
from = $(presence).attr('from');
|
288
|
-
slug = from.split("@")[0];
|
289
|
-
|
290
|
-
if (slug != user_slug) {
|
291
|
-
if (getConnectionBoxFromSlug(slug)!=null){
|
292
|
-
hideConnectionBoxFromSlug(slug)
|
293
|
-
}
|
294
|
-
}
|
295
|
-
}
|
296
|
-
|
297
|
-
function sendChatMessage(from,to,text){
|
298
|
-
var type = "chat";
|
299
|
-
var body= $build("body");
|
300
|
-
body.t(text);
|
301
|
-
var message = $msg({to: to, from: from, type: 'chat'}).cnode(body.tree());
|
302
|
-
connection.send(message.tree());
|
303
|
-
resumeAwayTimerIfAway();
|
304
|
-
return true;
|
305
|
-
}
|
306
|
-
|
307
|
-
function authByCookie(){
|
308
|
-
var authMethod = '<%= SocialStream::Presence.auth_method %>';
|
309
|
-
return authMethod=="cookie";
|
310
|
-
}
|
311
|
-
|
312
|
-
function authByPassword(){
|
313
|
-
var authMethod = '<%= SocialStream::Presence.auth_method %>';
|
314
|
-
return authMethod=="password";
|
315
|
-
}
|
316
|
-
|
317
|
-
function ifCookie(){
|
318
|
-
return (!(typeof cookie == 'undefined'))
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
///////////////////////////////////////////////////////
|
324
|
-
// Parser functions
|
325
|
-
// Allow new features in chat msg like links, images, emoticons, ...
|
326
|
-
///////////////////////////////////////////////////////
|
327
|
-
|
328
|
-
//Patterns
|
329
|
-
var html_tag_pattern=/.*\<[^>]+>.*/g
|
330
|
-
var simple_word_pattern=/^[aA-zZ0-9]+$/g
|
331
|
-
var http_urls_pattern=/(http(s)?:\/\/)([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
|
332
|
-
var www_urls_pattern = /(www[.])([aA-zZ0-9%=_&+?])+([./-][aA-zZ0-9%=_&+?]+)*[/]?/g
|
333
|
-
var icons_a_pattern=/\([A-Z]\)/g
|
334
|
-
var icons_b_pattern=/((:|;)([()A-Z]))/g
|
335
|
-
var youtube_video_pattern=/(http(s)?:\/\/)?(((youtu.be\/)([aA-zZ0-9]+))|((www.youtube.com\/watch\?v=)([aA-z0-9Z&=.])+))/g
|
336
|
-
|
337
|
-
function parseContent(content){
|
338
|
-
|
339
|
-
if (content.match(html_tag_pattern)!=null){
|
340
|
-
content = content.replace(/>/g, ">");
|
341
|
-
content = content.replace(/</g, "<");
|
342
|
-
return "<pre>" + content + "</pre>"
|
343
|
-
}
|
344
|
-
|
345
|
-
words = content.split(" ");
|
346
|
-
for(i=0; i<words.length; i++){
|
347
|
-
words[i] = parseWord(words[i]);
|
348
|
-
}
|
349
|
-
|
350
|
-
return words.join(" ");
|
351
|
-
}
|
352
|
-
|
353
|
-
function parseWord(word){
|
354
|
-
|
355
|
-
//Look for empty or simple words
|
356
|
-
if ((word.trim()=="")||(word.match(simple_word_pattern)!=null)){
|
357
|
-
return word
|
358
|
-
}
|
359
|
-
|
360
|
-
//Look for http urls
|
361
|
-
var http_urls = word.match(http_urls_pattern)
|
362
|
-
if (http_urls!=null){
|
363
|
-
var url = http_urls[0]
|
364
|
-
var type = getUrlType(url);
|
365
|
-
|
366
|
-
switch(type){
|
367
|
-
case "link":
|
368
|
-
var link = buildUrlLink(url,url)
|
369
|
-
var subwords = splitFirst(word,url)
|
370
|
-
return parseWord(subwords[0]) + link + parseWord(subwords[1])
|
371
|
-
case "image":
|
372
|
-
var imageLink = buildImageLink(url);
|
373
|
-
var subwords = splitFirst(word,url)
|
374
|
-
return parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
|
375
|
-
case "video-youtube":
|
376
|
-
var youtubeLink = buildYoutubeVideoLink(url);
|
377
|
-
var subwords = splitFirst(word,url)
|
378
|
-
return parseWord(subwords[0]) + youtubeLink + parseWord(subwords[1])
|
379
|
-
default:
|
380
|
-
return word
|
381
|
-
}
|
382
|
-
}
|
383
|
-
|
384
|
-
|
385
|
-
//Look for www urls
|
386
|
-
var www_urls = word.match(www_urls_pattern)
|
387
|
-
if (www_urls!=null){
|
388
|
-
var url = www_urls[0]
|
389
|
-
var type = getUrlType(url);
|
390
|
-
|
391
|
-
switch(type){
|
392
|
-
case "link":
|
393
|
-
var link = buildUrlLink("http://" + url,url)
|
394
|
-
var subwords = splitFirst(word,url)
|
395
|
-
return parseWord(subwords[0]) + link + parseWord(subwords[1])
|
396
|
-
case "image":
|
397
|
-
var imageLink = buildImageLink("http://" + url);
|
398
|
-
var subwords = splitFirst(word,url)
|
399
|
-
return parseWord(subwords[0]) + imageLink + parseWord(subwords[1])
|
400
|
-
case "video-youtube":
|
401
|
-
var youtubeLink = buildYoutubeVideoLink("http://" + url);
|
402
|
-
var subwords = splitFirst(word,url)
|
403
|
-
return parseWord(subwords[0]) + youtubeLink + parseWord(subwords[1])
|
404
|
-
default:
|
405
|
-
return word
|
406
|
-
}
|
407
|
-
}
|
408
|
-
|
409
|
-
//Look for icons: Regex
|
410
|
-
var icons_a = word.match(icons_a_pattern)
|
411
|
-
if(icons_a!=null){
|
412
|
-
for(g=0; g<icons_a.length; g++){
|
413
|
-
word = word.replace(buildRegex(icons_a[g]), buildIconImage(icons_a[g]))
|
414
|
-
}
|
415
|
-
}
|
416
|
-
|
417
|
-
var icons_b = word.match(icons_b_pattern)
|
418
|
-
if(icons_b!=null){
|
419
|
-
for(h=0; h<icons_b.length; h++){
|
420
|
-
word = word.replace(buildRegex(icons_b[h]), buildIconImage(icons_b[h]))
|
421
|
-
}
|
422
|
-
}
|
423
|
-
|
424
|
-
|
425
|
-
//No special content detected (maybe emoticons but not special pattern like urls)
|
426
|
-
return word
|
427
|
-
}
|
428
|
-
|
429
|
-
function splitFirst(word,key){
|
430
|
-
split=[]
|
431
|
-
cut = word.split(key);
|
432
|
-
split[0]=cut[0]
|
433
|
-
cut.shift()
|
434
|
-
paste = cut.join(key)
|
435
|
-
split[1]=paste
|
436
|
-
return split
|
437
|
-
}
|
438
|
-
|
439
|
-
function buildIconImage(icon){
|
440
|
-
if (icon in chatIcons){
|
441
|
-
image_file = chatIcons[icon]
|
442
|
-
return "<img class=\"chatEmoticon\" src=\"assets/emoticons/" + image_file + "\"/>";
|
443
|
-
}
|
444
|
-
return icon
|
445
|
-
}
|
446
|
-
|
447
|
-
function buildUrlLink(url,name){
|
448
|
-
return "<a target=\"_blank\" class=\"chatLink\" href=\"" + url + "\">" + name + "</a>";
|
449
|
-
}
|
450
|
-
|
451
|
-
function buildImageLink(url){
|
452
|
-
return "<a target=\"_blank\" class=\"chatImageLink\" href=\"" + url + "\">" + "<img class=\"chatImage\" src=\"" + url + "\"/>" + "</a>";
|
453
|
-
}
|
454
|
-
|
455
|
-
function buildYoutubeVideoLink(url){
|
456
|
-
//Get youtube video id
|
457
|
-
var youtube_video_id=url.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
|
458
|
-
var youtube_api_url = "http://gdata.youtube.com/feeds/api/videos/" + youtube_video_id
|
459
|
-
|
460
|
-
//Get info from the video
|
461
|
-
$.ajax({
|
462
|
-
type: "GET",
|
463
|
-
url: youtube_api_url,
|
464
|
-
cache: false,
|
465
|
-
dataType:'jsonp',
|
466
|
-
success: function(data){
|
467
|
-
var url_name = url;
|
468
|
-
var youtube_video_thumbnail = "";
|
469
|
-
|
470
|
-
//Video title
|
471
|
-
var video_title = $(data).find("media\\:title")
|
472
|
-
if (video_title.length > 0) {
|
473
|
-
//url_name = url + " (" + $(video_title).text() + ")";
|
474
|
-
url_name = $(video_title).text()
|
475
|
-
}
|
476
|
-
|
477
|
-
//Thumbnails
|
478
|
-
var thumbnails = $(data).find("media\\:thumbnail")
|
479
|
-
if (thumbnails.length>0){
|
480
|
-
var thumbnail_url = $(thumbnails[0]).attr("url")
|
481
|
-
if (thumbnail_url!=null){
|
482
|
-
youtube_video_thumbnail = "<p><img class=\"chatVideoImage\" src=\"" + thumbnail_url + "\"/></p>";
|
483
|
-
}
|
484
|
-
}
|
485
|
-
|
486
|
-
//Replace video link
|
487
|
-
$("a[youtube_id=" + youtube_video_id + "]").html(buildUrlLink(url,url_name)+youtube_video_thumbnail);
|
488
|
-
},
|
489
|
-
error: function(xOptions, textStatus){
|
490
|
-
//Handle errors
|
491
|
-
}
|
492
|
-
});
|
493
|
-
|
494
|
-
return "<a target=\"_blank\" youtube_id=\"" + youtube_video_id + "\" class=\"chatLink\" href=\"" + url + "\">" + url + "</a>";
|
495
|
-
}
|
496
|
-
|
497
|
-
function buildRegex(word){
|
498
|
-
word = word.replace(")","\\)")
|
499
|
-
word = word.replace("(","\\(")
|
500
|
-
var pattern = "(" + word + ")";
|
501
|
-
pattern = buildPattern(pattern)
|
502
|
-
return (new RegExp(pattern,'g'));
|
503
|
-
}
|
504
|
-
|
505
|
-
function buildPattern(pattern){
|
506
|
-
//Escape pattern special characters
|
507
|
-
pattern = pattern.replace("+","\\+")
|
508
|
-
pattern = pattern.replace("?","\\?")
|
509
|
-
return pattern
|
510
|
-
}
|
511
|
-
|
512
|
-
|
513
|
-
function getUrlType(url){
|
514
|
-
|
515
|
-
if (url.match(youtube_video_pattern)!=null){
|
516
|
-
return "video-youtube"
|
517
|
-
}
|
518
|
-
|
519
|
-
var urlArray = url.split(".");
|
520
|
-
if (urlArray!=null && urlArray.length>0){
|
521
|
-
var extension= urlArray[urlArray.length-1]
|
522
|
-
} else {
|
523
|
-
var extension = null;
|
524
|
-
}
|
525
|
-
|
526
|
-
switch(extension){
|
527
|
-
case "jpg":
|
528
|
-
return "image"
|
529
|
-
break;
|
530
|
-
case "png":
|
531
|
-
return "image"
|
532
|
-
break;
|
533
|
-
case "gif":
|
534
|
-
return "image"
|
535
|
-
break;
|
536
|
-
default:
|
537
|
-
return "link"
|
538
|
-
}
|
539
|
-
}
|
540
|
-
|
541
|
-
////////////////////
|
542
|
-
//Audio functions
|
543
|
-
////////////////////
|
544
|
-
|
545
|
-
//Global audio variables
|
546
|
-
var onMessageAudio;
|
547
|
-
|
548
|
-
var html5_audiotypes=[
|
549
|
-
["mp3","audio/mpeg"],
|
550
|
-
//["mp4","audio/mp4"],
|
551
|
-
//["ogg","audio/ogg"],
|
552
|
-
["wav","audio/wav"]
|
553
|
-
]
|
554
|
-
|
555
|
-
function initAudio(){
|
556
|
-
//Init all audio files
|
557
|
-
initSound("onMessageAudio");
|
558
|
-
}
|
559
|
-
|
560
|
-
function initSound(sound){
|
561
|
-
|
562
|
-
//Check support for HTML5 audio
|
563
|
-
var html5audio=document.createElement('audio')
|
564
|
-
|
565
|
-
if (html5audio.canPlayType){
|
566
|
-
path = 'assets/chat/' + sound;
|
567
|
-
window[sound] = new Audio();
|
568
|
-
|
569
|
-
for(i=0; i<html5_audiotypes.length; i++){
|
570
|
-
if (window[sound].canPlayType(html5_audiotypes[i][1])) {
|
571
|
-
var source= document.createElement('source');
|
572
|
-
source.type= html5_audiotypes[i][1];
|
573
|
-
source.src= path + '.' + html5_audiotypes[i][0];
|
574
|
-
window[sound].addEventListener('ended', endSoundListener);
|
575
|
-
window[sound].appendChild(source);
|
576
|
-
}
|
577
|
-
}
|
578
|
-
} else {
|
579
|
-
//Browser doesn't support HTML5 audio
|
580
|
-
}
|
581
|
-
}
|
582
|
-
|
583
|
-
function endSoundListener(){ }
|
584
|
-
|
585
|
-
function playSound(sound){
|
586
|
-
if (window[sound]!=null){
|
587
|
-
window[sound].play();
|
588
|
-
} else {
|
589
|
-
//Fallback option: When browser doesn't support HTML5 audio
|
590
|
-
$('body').append('<embed src="/' + sound + '.mp3" autostart="true" hidden="true" loop="false">');
|
591
|
-
}
|
592
|
-
}
|
593
|
-
|
594
|
-
function initAndPlaySound(sound){
|
595
|
-
initSound(sound);
|
596
|
-
playSound(sound);
|
597
|
-
}
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
////////////////////
|
602
|
-
//Chat view jquery
|
603
|
-
////////////////////
|
604
|
-
|
605
|
-
function setUserFunctions(){
|
606
|
-
|
607
|
-
$("div.user_presence").click(function(event, ui){
|
608
|
-
var guest_name = $(this).attr("name");
|
609
|
-
var guest_slug = $(this).attr("slug");
|
610
|
-
var guest_jid = guest_slug + "@" + domain;
|
611
|
-
|
612
|
-
if (createChatBox(guest_slug, guest_name, guest_jid, user_name, user_jid)) {
|
613
|
-
} else {
|
614
|
-
window[getChatVariableFromSlug(guest_slug)].chatbox("option", "boxManager").toggleBox(true);
|
615
|
-
};
|
616
|
-
});
|
617
|
-
|
618
|
-
//JQuery DropdwanStatus
|
619
|
-
|
620
|
-
$(".dropdown dt a").click(function(event) {
|
621
|
-
event.preventDefault();
|
622
|
-
$(".dropdown dd ul").toggle();
|
623
|
-
});
|
624
|
-
|
625
|
-
$(".dropdown dd ul li a.option").click(function(event) {
|
626
|
-
event.preventDefault();
|
627
|
-
var text = $(this).html();
|
628
|
-
$(".dropdown dt a span").html(text);
|
629
|
-
userStatus = getSelectedValue("status");
|
630
|
-
sendStatus(userStatus);
|
631
|
-
$(".dropdown dd ul").hide();
|
632
|
-
});
|
633
|
-
|
634
|
-
|
635
|
-
function getSelectedValue(id) {
|
636
|
-
return $("#" + id).find("dt a span.value").html();
|
637
|
-
}
|
638
|
-
|
639
|
-
$(document).bind('click', function(e) {
|
640
|
-
var $clicked = $(e.target);
|
641
|
-
if (! $clicked.parents().hasClass("dropdown")){
|
642
|
-
//Click outside the select...
|
643
|
-
$(".dropdown dd ul").hide();
|
644
|
-
}
|
645
|
-
});
|
646
|
-
}
|
647
|
-
|
648
|
-
|
649
|
-
function awayTimerFunction(){
|
650
|
-
awayCounter++;
|
651
|
-
if (awayCounter > (awayTime/awayTimerPeriod)){
|
652
|
-
userStatus = "away";
|
653
|
-
sendStatus(userStatus);
|
654
|
-
clearTimeout(awayTimer);
|
655
|
-
} else {
|
656
|
-
userStatus = "chat";
|
657
|
-
}
|
658
|
-
}
|
659
|
-
|
660
|
-
function resumeAwayTimerIfAway(){
|
661
|
-
if (userStatus == "away"){
|
662
|
-
awayCounter = 0;
|
663
|
-
userStatus = "chat";
|
664
|
-
sendStatus(userStatus);
|
665
|
-
awayTimer = setInterval("awayTimerFunction()", awayTimerPeriod);
|
666
|
-
}
|
667
|
-
}
|
668
|
-
|
669
|
-
function timerFunction(){
|
670
|
-
timerCounter++;
|
671
|
-
|
672
|
-
if((timerCounter > cyclesToRefresh)&&(requestContacts)) {
|
673
|
-
requestContacts = false;
|
674
|
-
updateChatWindow();
|
675
|
-
}
|
676
|
-
}
|
677
|
-
|
678
|
-
function refreshChatWindow(){
|
679
|
-
if(timerCounter > cyclesToRefresh){
|
680
|
-
updateChatWindow();
|
681
|
-
} else {
|
682
|
-
requestContacts = true;
|
683
|
-
}
|
684
|
-
}
|
685
|
-
|
686
|
-
function updateChatWindow(){
|
687
|
-
timerCounter=0;
|
688
|
-
log("updateChatWindow()");
|
689
|
-
$.post("/chatWindow", { userConnected: userConnected }, function(data){
|
690
|
-
$(".tooltip").hide() //Prevent tooltips
|
691
|
-
$("#chat_partial").html(data);
|
692
|
-
if (userConnected) {
|
693
|
-
$(".user_presence a[title]").tooltip();
|
694
|
-
setUserFunctions();
|
695
|
-
}
|
696
|
-
});
|
697
|
-
}
|
698
|
-
|
699
|
-
function sendStatus(status){
|
700
|
-
if (status in statusMessage){
|
701
|
-
//Send status to the XMPP Server
|
702
|
-
var pres = $pres()
|
703
|
-
.c('status')
|
704
|
-
.t(statusMessage[status]).up() //Status message
|
705
|
-
.c('show')
|
706
|
-
.t(status);
|
707
|
-
connection.send(pres.tree());
|
708
|
-
}
|
709
|
-
}
|
710
|
-
|
711
|
-
|
712
|
-
function mustPlaySoundForChatWindow(chatBox){
|
713
|
-
//Deny conditions
|
714
|
-
if(userStatus == "dnd"){
|
715
|
-
return false;
|
716
|
-
}
|
717
|
-
|
718
|
-
//Accept conditions
|
719
|
-
if (!chatFocus){
|
720
|
-
return true;
|
721
|
-
}
|
722
|
-
|
723
|
-
//Default action
|
724
|
-
return false
|
725
|
-
}
|
726
|
-
|
727
|
-
|
728
|
-
var chatFocus;
|
729
|
-
|
730
|
-
function onChatBlur() {
|
731
|
-
chatFocus = false;
|
732
|
-
};
|
733
|
-
|
734
|
-
function onChatFocus(){
|
735
|
-
stopBlink();
|
736
|
-
titles = []; //Remove titles after StopBlink!
|
737
|
-
chatFocus = true;
|
738
|
-
};
|
739
|
-
|
740
|
-
function initFocusListeners(){
|
741
|
-
if (/*@cc_on!@*/false) { // check for Internet Explorer
|
742
|
-
document.onfocusin = onFocus;
|
743
|
-
document.onfocusout = onBlur;
|
744
|
-
} else {
|
745
|
-
window.onfocus = onChatFocus;
|
746
|
-
window.onblur = onChatBlur;
|
747
|
-
}
|
748
|
-
}
|
749
|
-
|
750
|
-
|
751
|
-
var blinkTimer;
|
752
|
-
var titles=[];
|
753
|
-
|
754
|
-
function blinkTitle(titles,index){
|
755
|
-
$(document).attr("title", titles[index]);
|
756
|
-
index = (index+1)%titles.length
|
757
|
-
blinkTimer=setTimeout(function(){blinkTitle(titles,index)}, 2000);
|
758
|
-
}
|
759
|
-
|
760
|
-
function stopBlink(){
|
761
|
-
clearTimeout(blinkTimer);
|
762
|
-
if (titles.length > 0) {
|
763
|
-
$(document).attr("title", titles[0]);
|
764
|
-
}
|
765
|
-
}
|
766
|
-
|
767
|
-
function blinkTitleOnMessage(username){
|
768
|
-
if (!chatFocus){
|
769
|
-
if (titles.length==0){
|
770
|
-
titles.push($(document).attr("title"))
|
771
|
-
}
|
772
|
-
if (titles.indexOf(username) == -1){
|
773
|
-
titles.push(username + " says...")
|
774
|
-
}
|
775
|
-
stopBlink();
|
776
|
-
blinkTitle(titles,titles.length-1);
|
777
|
-
}
|
778
|
-
}
|
779
|
-
|
780
|
-
function getConnectionBoxFromSlug(slug){
|
781
|
-
if ($('div.user_presence[slug=' + slug + ']').length > 0){
|
782
|
-
return ($('div.user_presence[slug=' + slug + ']'))[0];
|
783
|
-
} else {
|
784
|
-
return null;
|
785
|
-
}
|
786
|
-
}
|
787
|
-
|
788
|
-
|
789
|
-
var cacheConnectedUsers = [];
|
790
|
-
function hideConnectionBoxFromSlug(slug){
|
791
|
-
if ($('div.user_presence[slug=' + slug + ']').length > 0){
|
792
|
-
$('div.user_presence[slug=' + slug + ']').hide();
|
793
|
-
if(cacheConnectedUsers.indexOf(slug)==-1){
|
794
|
-
cacheConnectedUsers.push(slug);
|
795
|
-
}
|
796
|
-
}
|
797
|
-
}
|
798
|
-
|
799
|
-
function showConnectionBoxFromSlug(slug){
|
800
|
-
if ($('div.user_presence[slug=' + slug + ']').length > 0){
|
801
|
-
if (!($('div.user_presence[slug=' + slug + ']').is(":visible"))){
|
802
|
-
$('div.user_presence[slug=' + slug + ']').show();
|
803
|
-
}
|
804
|
-
}
|
805
|
-
}
|
806
|
-
|
807
|
-
function setUserIconStatus(slug, status){
|
808
|
-
if (status in statusIcons) {
|
809
|
-
iconName = statusIcons[status];
|
810
|
-
var $img_status = $('img.presence_status');
|
811
|
-
connectionBox = getConnectionBoxFromSlug(slug);
|
812
|
-
$(connectionBox).find($img_status).attr("src", "/assets/status/" + iconName + ".png")
|
813
|
-
}
|
814
|
-
}
|
815
|
-
|
816
|
-
function getAllConnectedSlugs(){
|
817
|
-
connectedSlugs=[];
|
818
|
-
connectionBoxes = $('div.user_presence[slug]');
|
819
|
-
$.each(connectionBoxes, function(index, value) {
|
820
|
-
if($(value).is(":visible")){
|
821
|
-
connectedSlugs.push($(value).attr("slug"))
|
822
|
-
}
|
823
|
-
});
|
824
|
-
return connectedSlugs
|
825
|
-
}
|
826
|
-
|
827
|
-
|
828
|
-
////////////////////
|
829
|
-
//Chat functions
|
830
|
-
////////////////////
|
831
|
-
|
832
|
-
var nBox = 0;
|
833
|
-
var maxBox = 5;
|
834
|
-
var chatBoxWidth = 230;
|
835
|
-
var visibleChatBoxes = new Array();
|
836
|
-
var chatBoxSeparation = chatBoxWidth+12;
|
837
|
-
|
838
|
-
|
839
|
-
function createChatBox(guest_slug,guest_name,guest_jid,user_name,user_jid){
|
840
|
-
|
841
|
-
//Create chatbox for new conversations
|
842
|
-
//Open chatbox for old conversations
|
843
|
-
|
844
|
-
//Box Variable name = getChatVariableFromSlug(guest_slug)
|
845
|
-
if (typeof window[getChatVariableFromSlug(guest_slug)] == 'undefined') {
|
846
|
-
|
847
|
-
//Add div with id = guest_slug
|
848
|
-
$("#chat_divs").append("<div id=" + guest_slug + " name=" + guest_name + "></div>")
|
849
|
-
|
850
|
-
//Add CSS [...]
|
851
|
-
|
852
|
-
|
853
|
-
//Offset Management for new box
|
854
|
-
boxParams = getBoxParams();
|
855
|
-
var offset = boxParams[0];
|
856
|
-
var position = boxParams[1];
|
857
|
-
|
858
|
-
|
859
|
-
window[getChatVariableFromSlug(guest_slug)] = $("#" + guest_slug).chatbox({id: user_name,
|
860
|
-
user:{key : "value"},
|
861
|
-
hidden: false,
|
862
|
-
offset: offset, // relative to right edge of the browser window
|
863
|
-
width: chatBoxWidth, // width of the chatbox
|
864
|
-
title : guest_name,
|
865
|
-
position: position,
|
866
|
-
priority: visibleChatBoxes.length+1,
|
867
|
-
boxClosed: function(id) {
|
868
|
-
|
869
|
-
position = $("#" + guest_slug).chatbox("option", "position");
|
870
|
-
|
871
|
-
for (i=position+1;i<visibleChatBoxes.length+1;i++){
|
872
|
-
visibleChatBoxes[i-1].chatbox("option", "offset", visibleChatBoxes[i-1].chatbox("option", "offset") - chatBoxSeparation);
|
873
|
-
visibleChatBoxes[i-1].chatbox("option", "position", visibleChatBoxes[i-1].chatbox("option", "position") - 1 );
|
874
|
-
}
|
875
|
-
|
876
|
-
visibleChatBoxes.splice(position-1,1);
|
877
|
-
$("#" + guest_slug).chatbox("option", "hidden", true);
|
878
|
-
nBox--;
|
879
|
-
},
|
880
|
-
|
881
|
-
messageSent : function(id, user, msg) {
|
882
|
-
rotatePriority(guest_slug);
|
883
|
-
$("#" + guest_slug).chatbox("option", "boxManager").addMsg(id, parseContent(msg));
|
884
|
-
sendChatMessage(user_jid,guest_jid,msg);
|
885
|
-
}});
|
886
|
-
|
887
|
-
visibleChatBoxes[position-1] = window[getChatVariableFromSlug(guest_slug)];
|
888
|
-
|
889
|
-
return true;
|
890
|
-
|
891
|
-
} else {
|
892
|
-
|
893
|
-
if (visibleChatBoxes.indexOf(window[getChatVariableFromSlug(guest_slug)]) == -1) {
|
894
|
-
|
895
|
-
//Offset Management for old box
|
896
|
-
boxParams = getBoxParams();
|
897
|
-
var offset = boxParams[0];
|
898
|
-
var position = boxParams[1];
|
899
|
-
|
900
|
-
window[getChatVariableFromSlug(guest_slug)].chatbox("option", "offset", offset);
|
901
|
-
window[getChatVariableFromSlug(guest_slug)].chatbox("option", "position", position);
|
902
|
-
visibleChatBoxes[position-1] = window[getChatVariableFromSlug(guest_slug)];
|
903
|
-
}
|
904
|
-
|
905
|
-
window[getChatVariableFromSlug(guest_slug)].chatbox("option", "hidden", false);
|
906
|
-
return false;
|
907
|
-
}
|
908
|
-
|
909
|
-
}
|
910
|
-
|
911
|
-
function getBoxParams(){
|
912
|
-
|
913
|
-
var boxParams = new Array(2);
|
914
|
-
|
915
|
-
if (nBox==maxBox){
|
916
|
-
//Select box to replaced
|
917
|
-
replaced = visibleChatBoxes[getBoxIndexToReplace()];
|
918
|
-
replaced.chatbox("option", "hidden", true)
|
919
|
-
index = visibleChatBoxes.indexOf(replaced);
|
920
|
-
boxParams[0] = replaced.chatbox("option", "offset")
|
921
|
-
boxParams[1] = replaced.chatbox("option", "position")
|
922
|
-
} else {
|
923
|
-
nBox++;
|
924
|
-
boxParams[0] = (nBox-1)*(chatBoxSeparation);
|
925
|
-
boxParams[1] = nBox;
|
926
|
-
}
|
927
|
-
|
928
|
-
return boxParams
|
929
|
-
}
|
930
|
-
|
931
|
-
|
932
|
-
function getBoxIndexToReplace(){
|
933
|
-
|
934
|
-
tmp = visibleChatBoxes[0];
|
935
|
-
for (i=0;i<visibleChatBoxes.length;i++){
|
936
|
-
if (visibleChatBoxes[i].chatbox("option", "priority") > tmp.chatbox("option", "priority")) {
|
937
|
-
tmp = visibleChatBoxes[i];
|
938
|
-
}
|
939
|
-
}
|
940
|
-
|
941
|
-
return visibleChatBoxes.indexOf(tmp);
|
942
|
-
}
|
943
|
-
|
944
|
-
function rotatePriority(guest_slug){
|
945
|
-
priority = $("#" + guest_slug).chatbox("option", "priority")
|
946
|
-
if(priority>1){
|
947
|
-
for (i=0;i<visibleChatBoxes.length;i++){
|
948
|
-
if(visibleChatBoxes[i].chatbox("option", "priority")<priority){
|
949
|
-
visibleChatBoxes[i].chatbox("option", "priority",visibleChatBoxes[i].chatbox("option", "priority")+1);
|
950
|
-
}
|
951
|
-
}
|
952
|
-
$("#" + guest_slug).chatbox("option", "priority", 1);
|
953
|
-
}
|
954
|
-
}
|
955
|
-
|
956
|
-
function getChatVariableFromSlug(slug){
|
957
|
-
return "slug_" + slug;
|
958
|
-
}
|
959
|
-
|
960
|
-
function getSlugFromChatVariable(variable){
|
961
|
-
return variable.split("_")[1];
|
962
|
-
}
|