Browse Source

Removes UI dependancies in the xmpp module.

j8
hristoterezov 10 years ago
parent
commit
899f0ee83d

+ 3
- 3
index.html View File

27
     <script src="service/desktopsharing/DesktopSharingEventTypes.js?v=1"></script>
27
     <script src="service/desktopsharing/DesktopSharingEventTypes.js?v=1"></script>
28
     <script src="libs/modules/simulcast.bundle.js?v=5"></script>
28
     <script src="libs/modules/simulcast.bundle.js?v=5"></script>
29
     <script src="libs/modules/connectionquality.bundle.js?v=2"></script>
29
     <script src="libs/modules/connectionquality.bundle.js?v=2"></script>
30
-    <script src="libs/modules/UI.bundle.js?v=10"></script>
30
+    <script src="libs/modules/UI.bundle.js?v=11"></script>
31
     <script src="libs/modules/statistics.bundle.js?v=4"></script>
31
     <script src="libs/modules/statistics.bundle.js?v=4"></script>
32
     <script src="libs/modules/RTC.bundle.js?v=6"></script>
32
     <script src="libs/modules/RTC.bundle.js?v=6"></script>
33
     <script src="libs/modules/desktopsharing.bundle.js?v=3"></script><!-- desktop sharing -->
33
     <script src="libs/modules/desktopsharing.bundle.js?v=3"></script><!-- desktop sharing -->
34
-    <script src="libs/modules/xmpp.bundle.js?v=5"></script>
34
+    <script src="libs/modules/xmpp.bundle.js?v=6"></script>
35
     <script src="libs/modules/keyboardshortcut.bundle.js?v=1"></script>
35
     <script src="libs/modules/keyboardshortcut.bundle.js?v=1"></script>
36
     <script src="app.js?v=30"></script><!-- application logic -->
36
     <script src="app.js?v=30"></script><!-- application logic -->
37
-    <script src="libs/modules/API.bundle.js?v=1"></script>
37
+    <script src="libs/modules/API.bundle.js?v=2"></script>
38
 
38
 
39
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
39
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
40
     <link rel="stylesheet" href="css/font.css?v=6"/>
40
     <link rel="stylesheet" href="css/font.css?v=6"/>

+ 15
- 0
libs/modules/API.bundle.js View File

133
 
133
 
134
 }
134
 }
135
 
135
 
136
+function setupListeners() {
137
+    xmpp.addListener(XMPPEvents.MUC_ENTER, function (from) {
138
+        API.triggerEvent("participantJoined", {jid: from});
139
+    });
140
+    xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, function (from, nick, txt, myjid) {
141
+        if (from != myjid)
142
+            API.triggerEvent("incomingMessage",
143
+                {"from": from, "nick": nick, "message": txt});
144
+    });
145
+    xmpp.addListener(XMPPEvents.MUC_LEFT, function (jid) {
146
+        API.triggerEvent("participantLeft", {jid: jid});
147
+    });
148
+}
149
+
136
 var API = {
150
 var API = {
137
     /**
151
     /**
138
      * Check whether the API should be enabled or not.
152
      * Check whether the API should be enabled or not.
161
             window.attachEvent('onmessage', processMessage);
175
             window.attachEvent('onmessage', processMessage);
162
         }
176
         }
163
         sendMessage({type: "system", loaded: true});
177
         sendMessage({type: "system", loaded: true});
178
+        setupListeners();
164
     },
179
     },
165
     /**
180
     /**
166
      * Checks whether the event is enabled ot not.
181
      * Checks whether the event is enabled ot not.

+ 47
- 38
libs/modules/UI.bundle.js View File

140
     });
140
     });
141
     xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
141
     xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
142
     xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
142
     xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
143
+    xmpp.addListener(XMPPEvents.LOCALROLE_CHANGED, onLocalRoleChange);
144
+    xmpp.addListener(XMPPEvents.MUC_ENTER, onMucEntered);
145
+    xmpp.addListener(XMPPEvents.MUC_ROLE_CHANGED, onMucRoleChanged);
146
+    xmpp.addListener(XMPPEvents.PRESENCE_STATUS, onMucPresenceStatus);
147
+    xmpp.addListener(XMPPEvents.SUBJECT_CHANGED, chatSetSubject);
148
+    xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, updateChatConversation);
149
+    xmpp.addListener(XMPPEvents.MUC_LEFT, onMucLeft);
150
+    xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordReqiured);
151
+    xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
152
+    xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
143
 }
153
 }
144
 
154
 
145
 function bindEvents()
155
 function bindEvents()
291
     Chat.toggleSmileys();
301
     Chat.toggleSmileys();
292
 };
302
 };
293
 
303
 
294
-UI.chatAddError = function(errorMessage, originalText)
304
+function chatAddError(errorMessage, originalText)
295
 {
305
 {
296
     return Chat.chatAddError(errorMessage, originalText);
306
     return Chat.chatAddError(errorMessage, originalText);
297
 };
307
 };
298
 
308
 
299
-UI.chatSetSubject = function(text)
309
+function chatSetSubject(text)
300
 {
310
 {
301
     return Chat.chatSetSubject(text);
311
     return Chat.chatSetSubject(text);
302
 };
312
 };
303
 
313
 
304
-UI.updateChatConversation = function (from, displayName, message) {
314
+function updateChatConversation(from, displayName, message) {
305
     return Chat.updateChatConversation(from, displayName, message);
315
     return Chat.updateChatConversation(from, displayName, message);
306
 };
316
 };
307
 
317
 
329
         onDisplayNameChanged('localVideoContainer', displayName + ' (me)');
339
         onDisplayNameChanged('localVideoContainer', displayName + ' (me)');
330
 }
340
 }
331
 
341
 
332
-UI.initEtherpad = function (name) {
342
+function initEtherpad(name) {
333
     Etherpad.init(name);
343
     Etherpad.init(name);
334
 };
344
 };
335
 
345
 
336
-UI.onMucLeft = function (jid) {
346
+function onMucLeft(jid) {
337
     console.log('left.muc', jid);
347
     console.log('left.muc', jid);
338
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
348
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
339
         '>.displayname').html();
349
         '>.displayname').html();
375
     return BottomToolbar.toggleContactList();
385
     return BottomToolbar.toggleContactList();
376
 };
386
 };
377
 
387
 
378
-UI.onLocalRoleChange = function (jid, info, pres) {
388
+function onLocalRoleChange(jid, info, pres, isModerator, isExternalAuthEnabled)
389
+{
379
 
390
 
380
     console.info("My role changed, new role: " + info.role);
391
     console.info("My role changed, new role: " + info.role);
381
-    var isModerator = xmpp.isModerator();
382
-
392
+    onModeratorStatusChanged(isModerator);
383
     VideoLayout.showModeratorIndicator();
393
     VideoLayout.showModeratorIndicator();
384
     Toolbar.showAuthenticateButton(
394
     Toolbar.showAuthenticateButton(
385
-            xmpp.isExternalAuthEnabled() && !isModerator);
395
+            isExternalAuthEnabled && !isModerator);
386
 
396
 
387
     if (isModerator) {
397
     if (isModerator) {
388
         Authentication.closeAuthenticationWindow();
398
         Authentication.closeAuthenticationWindow();
389
         messageHandler.notify(
399
         messageHandler.notify(
390
             'Me', 'connected', 'Moderator rights granted !');
400
             'Me', 'connected', 'Moderator rights granted !');
391
     }
401
     }
392
-};
402
+}
393
 
403
 
394
-UI.onModeratorStatusChanged = function (isModerator) {
404
+function onModeratorStatusChanged(isModerator) {
395
 
405
 
396
     Toolbar.showSipCallButton(isModerator);
406
     Toolbar.showSipCallButton(isModerator);
397
     Toolbar.showRecordingButton(
407
     Toolbar.showRecordingButton(
406
     }
416
     }
407
 };
417
 };
408
 
418
 
409
-UI.onPasswordReqiured = function (callback) {
419
+function onPasswordReqiured(callback) {
410
     // password is required
420
     // password is required
411
     Toolbar.lockLockButton();
421
     Toolbar.lockLockButton();
412
 
422
 
429
             }
439
             }
430
         }
440
         }
431
     );
441
     );
432
-};
433
-
434
-UI.onAuthenticationRequired = function (intervalCallback) {
435
-    Authentication.openAuthenticationDialog(
436
-        roomName, intervalCallback, function () {
437
-            Toolbar.authenticateClicked();
438
-        });
439
-};
440
-
441
-UI.setRecordingButtonState = function (state) {
442
-    Toolbar.setRecordingButtonState(state);
443
-};
444
-
445
-UI.inputDisplayNameHandler = function (value) {
446
-    VideoLayout.inputDisplayNameHandler(value);
447
-};
448
-
449
-UI.onMucEntered = function (jid, id, displayName) {
442
+}
443
+function onMucEntered(jid, id, displayName) {
450
     messageHandler.notify(displayName || 'Somebody',
444
     messageHandler.notify(displayName || 'Somebody',
451
         'connected',
445
         'connected',
452
         'connected');
446
         'connected');
453
 
447
 
454
     // Add Peer's container
448
     // Add Peer's container
455
     VideoLayout.ensurePeerContainerExists(jid,id);
449
     VideoLayout.ensurePeerContainerExists(jid,id);
456
-};
450
+}
457
 
451
 
458
-UI.onMucPresenceStatus = function ( jid, info) {
452
+function onMucPresenceStatus( jid, info) {
459
     VideoLayout.setPresenceStatus(
453
     VideoLayout.setPresenceStatus(
460
             'participant_' + Strophe.getResourceFromJid(jid), info.status);
454
             'participant_' + Strophe.getResourceFromJid(jid), info.status);
461
-};
455
+}
462
 
456
 
463
-UI.onMucRoleChanged = function (role, displayName) {
457
+function onMucRoleChanged(role, displayName) {
464
     VideoLayout.showModeratorIndicator();
458
     VideoLayout.showModeratorIndicator();
465
 
459
 
466
     if (role === 'moderator') {
460
     if (role === 'moderator') {
473
             'connected',
467
             'connected',
474
                 'Moderator rights granted to ' + displayName + '!');
468
                 'Moderator rights granted to ' + displayName + '!');
475
     }
469
     }
470
+}
471
+
472
+UI.onAuthenticationRequired = function (intervalCallback) {
473
+    Authentication.openAuthenticationDialog(
474
+        roomName, intervalCallback, function () {
475
+            Toolbar.authenticateClicked();
476
+        });
477
+};
478
+
479
+UI.setRecordingButtonState = function (state) {
480
+    Toolbar.setRecordingButtonState(state);
481
+};
482
+
483
+UI.inputDisplayNameHandler = function (value) {
484
+    VideoLayout.inputDisplayNameHandler(value);
476
 };
485
 };
477
 
486
 
478
 UI.updateLocalConnectionStats = function(percent, stats)
487
 UI.updateLocalConnectionStats = function(percent, stats)
2464
 
2473
 
2465
         var chatBottomButtonElement
2474
         var chatBottomButtonElement
2466
             = document.getElementById('chatBottomButton').parentNode;
2475
             = document.getElementById('chatBottomButton').parentNode;
2467
-        var bottomLeftIndent = (Util.getTextWidth(chatBottomButtonElement) -
2468
-            Util.getTextWidth(unreadMsgBottomElement)) / 2;
2469
-        var bottomTopIndent = (Util.getTextHeight(chatBottomButtonElement) -
2470
-            Util.getTextHeight(unreadMsgBottomElement)) / 2 - 2;
2476
+        var bottomLeftIndent = (UIUtil.getTextWidth(chatBottomButtonElement) -
2477
+            UIUtil.getTextWidth(unreadMsgBottomElement)) / 2;
2478
+        var bottomTopIndent = (UIUtil.getTextHeight(chatBottomButtonElement) -
2479
+            UIUtil.getTextHeight(unreadMsgBottomElement)) / 2 - 2;
2471
 
2480
 
2472
         unreadMsgBottomElement.setAttribute(
2481
         unreadMsgBottomElement.setAttribute(
2473
             'style',
2482
             'style',

+ 20
- 23
libs/modules/xmpp.bundle.js View File

2855
 
2855
 
2856
     init: function (xmpp) {
2856
     init: function (xmpp) {
2857
         this.xmppService = xmpp;
2857
         this.xmppService = xmpp;
2858
-        this.onLocalRoleChange = function (from, member, pres) {
2859
-            UI.onModeratorStatusChanged(Moderator.isModerator());
2860
-        };
2861
     },
2858
     },
2862
 
2859
 
2863
     onMucLeft: function (jid) {
2860
     onMucLeft: function (jid) {
3333
             var etherpad = $(pres).find('>etherpad');
3330
             var etherpad = $(pres).find('>etherpad');
3334
             if (etherpad.length) {
3331
             if (etherpad.length) {
3335
                 if (config.etherpad_base && !Moderator.isModerator()) {
3332
                 if (config.etherpad_base && !Moderator.isModerator()) {
3336
-                    UI.initEtherpad(etherpad.text());
3333
+                    eventEmitter.emit(XMPPEvents.ETHERPAD, etherpad.text());
3337
                 }
3334
                 }
3338
             }
3335
             }
3339
 
3336
 
3410
                 if (member.affiliation == 'owner') this.isOwner = true;
3407
                 if (member.affiliation == 'owner') this.isOwner = true;
3411
                 if (this.role !== member.role) {
3408
                 if (this.role !== member.role) {
3412
                     this.role = member.role;
3409
                     this.role = member.role;
3413
-                    if (Moderator.onLocalRoleChange)
3414
-                        Moderator.onLocalRoleChange(from, member, pres);
3415
-                    UI.onLocalRoleChange(from, member, pres);
3410
+
3411
+                    eventEmitter.emit(XMPPEvents.LOCALROLE_CHANGED,
3412
+                        from, member, pres, Moderator.isModerator(),
3413
+                        Moderator.isExternalAuthEnabled());
3416
                 }
3414
                 }
3417
                 if (!this.joined) {
3415
                 if (!this.joined) {
3418
                     this.joined = true;
3416
                     this.joined = true;
3434
                     if (email.length > 0) {
3432
                     if (email.length > 0) {
3435
                         id = email.text();
3433
                         id = email.text();
3436
                     }
3434
                     }
3437
-                    UI.onMucEntered(from, id, member.displayName);
3438
-                    API.triggerEvent("participantJoined", {jid: from});
3435
+                    eventEmitter.emit(XMPPEvents.MUC_ENTER, from, id, member.displayName);
3439
                 }
3436
                 }
3440
             } else {
3437
             } else {
3441
                 // Presence update for existing participant
3438
                 // Presence update for existing participant
3442
                 // Watch role change:
3439
                 // Watch role change:
3443
                 if (this.members[from].role != member.role) {
3440
                 if (this.members[from].role != member.role) {
3444
                     this.members[from].role = member.role;
3441
                     this.members[from].role = member.role;
3445
-                    UI.onMucRoleChanged(member.role, member.displayName);
3442
+                    eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED,
3443
+                        member.role, member.displayName);
3446
                 }
3444
                 }
3447
             }
3445
             }
3448
 
3446
 
3449
             // Always trigger presence to update bindings
3447
             // Always trigger presence to update bindings
3450
-            $(document).trigger('presence.muc', [from, member, pres]);
3451
             this.parsePresence(from, member, pres);
3448
             this.parsePresence(from, member, pres);
3452
 
3449
 
3453
             // Trigger status message update
3450
             // Trigger status message update
3454
             if (member.status) {
3451
             if (member.status) {
3455
-                UI.onMucPresenceStatus(from, member);
3452
+                eventEmitter.emit(XMPPEvents.PRESENCE_STATUS, from, member);
3456
             }
3453
             }
3457
 
3454
 
3458
             return true;
3455
             return true;
3489
             if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
3486
             if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
3490
                 console.log('on password required', from);
3487
                 console.log('on password required', from);
3491
                 var self = this;
3488
                 var self = this;
3492
-                UI.onPasswordReqiured(function (value) {
3489
+                eventEmitter.emit(XMPPEvents.PASSWORD_REQUIRED, function (value) {
3493
                     self.doJoin(from, value);
3490
                     self.doJoin(from, value);
3494
                 });
3491
                 });
3495
             } else if ($(pres).find(
3492
             } else if ($(pres).find(
3538
         onMessage: function (msg) {
3535
         onMessage: function (msg) {
3539
             // FIXME: this is a hack. but jingle on muc makes nickchanges hard
3536
             // FIXME: this is a hack. but jingle on muc makes nickchanges hard
3540
             var from = msg.getAttribute('from');
3537
             var from = msg.getAttribute('from');
3541
-            var nick = $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]').text() || Strophe.getResourceFromJid(from);
3538
+            var nick =
3539
+                $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]')
3540
+                    .text() ||
3541
+                Strophe.getResourceFromJid(from);
3542
 
3542
 
3543
             var txt = $(msg).find('>body').text();
3543
             var txt = $(msg).find('>body').text();
3544
             var type = msg.getAttribute("type");
3544
             var type = msg.getAttribute("type");
3545
             if (type == "error") {
3545
             if (type == "error") {
3546
-                UI.chatAddError($(msg).find('>text').text(), txt);
3546
+                eventEmitter.emit(XMPPEvents.CHAT_ERROR_RECEIVED,
3547
+                    $(msg).find('>text').text(), txt);
3547
                 return true;
3548
                 return true;
3548
             }
3549
             }
3549
 
3550
 
3551
             if (subject.length) {
3552
             if (subject.length) {
3552
                 var subjectText = subject.text();
3553
                 var subjectText = subject.text();
3553
                 if (subjectText || subjectText == "") {
3554
                 if (subjectText || subjectText == "") {
3554
-                    UI.chatSetSubject(subjectText);
3555
+                    eventEmitter.emit(XMPPEvents.SUBJECT_CHANGED, subjectText);
3555
                     console.log("Subject is changed to " + subjectText);
3556
                     console.log("Subject is changed to " + subjectText);
3556
                 }
3557
                 }
3557
             }
3558
             }
3559
 
3560
 
3560
             if (txt) {
3561
             if (txt) {
3561
                 console.log('chat', nick, txt);
3562
                 console.log('chat', nick, txt);
3562
-                UI.updateChatConversation(from, nick, txt);
3563
-                if (from != this.myroomjid)
3564
-                    API.triggerEvent("incomingMessage",
3565
-                        {"from": from, "nick": nick, "message": txt});
3563
+                eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
3564
+                    from, nick, txt, this.myroomjid);
3566
             }
3565
             }
3567
             return true;
3566
             return true;
3568
         },
3567
         },
3689
             }
3688
             }
3690
 
3689
 
3691
             pres.up();
3690
             pres.up();
3692
-//        console.debug(pres.toString());
3693
             this.connection.send(pres);
3691
             this.connection.send(pres);
3694
         },
3692
         },
3695
         addDisplayNameToPresence: function (displayName) {
3693
         addDisplayNameToPresence: function (displayName) {
3774
             return null;
3772
             return null;
3775
         },
3773
         },
3776
         onParticipantLeft: function (jid) {
3774
         onParticipantLeft: function (jid) {
3777
-            UI.onMucLeft(jid);
3778
 
3775
 
3779
-            API.triggerEvent("participantLeft", {jid: jid});
3776
+            eventEmitter.emit(XMPPEvents.MUC_LEFT, jid);
3780
 
3777
 
3781
             this.connection.jingle.terminateByJid(jid);
3778
             this.connection.jingle.terminateByJid(jid);
3782
 
3779
 

+ 15
- 0
modules/API/API.js View File

132
 
132
 
133
 }
133
 }
134
 
134
 
135
+function setupListeners() {
136
+    xmpp.addListener(XMPPEvents.MUC_ENTER, function (from) {
137
+        API.triggerEvent("participantJoined", {jid: from});
138
+    });
139
+    xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, function (from, nick, txt, myjid) {
140
+        if (from != myjid)
141
+            API.triggerEvent("incomingMessage",
142
+                {"from": from, "nick": nick, "message": txt});
143
+    });
144
+    xmpp.addListener(XMPPEvents.MUC_LEFT, function (jid) {
145
+        API.triggerEvent("participantLeft", {jid: jid});
146
+    });
147
+}
148
+
135
 var API = {
149
 var API = {
136
     /**
150
     /**
137
      * Check whether the API should be enabled or not.
151
      * Check whether the API should be enabled or not.
160
             window.attachEvent('onmessage', processMessage);
174
             window.attachEvent('onmessage', processMessage);
161
         }
175
         }
162
         sendMessage({type: "system", loaded: true});
176
         sendMessage({type: "system", loaded: true});
177
+        setupListeners();
163
     },
178
     },
164
     /**
179
     /**
165
      * Checks whether the event is enabled ot not.
180
      * Checks whether the event is enabled ot not.

+ 43
- 34
modules/UI/UI.js View File

139
     });
139
     });
140
     xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
140
     xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
141
     xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
141
     xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
142
+    xmpp.addListener(XMPPEvents.LOCALROLE_CHANGED, onLocalRoleChange);
143
+    xmpp.addListener(XMPPEvents.MUC_ENTER, onMucEntered);
144
+    xmpp.addListener(XMPPEvents.MUC_ROLE_CHANGED, onMucRoleChanged);
145
+    xmpp.addListener(XMPPEvents.PRESENCE_STATUS, onMucPresenceStatus);
146
+    xmpp.addListener(XMPPEvents.SUBJECT_CHANGED, chatSetSubject);
147
+    xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, updateChatConversation);
148
+    xmpp.addListener(XMPPEvents.MUC_LEFT, onMucLeft);
149
+    xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordReqiured);
150
+    xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
151
+    xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
142
 }
152
 }
143
 
153
 
144
 function bindEvents()
154
 function bindEvents()
290
     Chat.toggleSmileys();
300
     Chat.toggleSmileys();
291
 };
301
 };
292
 
302
 
293
-UI.chatAddError = function(errorMessage, originalText)
303
+function chatAddError(errorMessage, originalText)
294
 {
304
 {
295
     return Chat.chatAddError(errorMessage, originalText);
305
     return Chat.chatAddError(errorMessage, originalText);
296
 };
306
 };
297
 
307
 
298
-UI.chatSetSubject = function(text)
308
+function chatSetSubject(text)
299
 {
309
 {
300
     return Chat.chatSetSubject(text);
310
     return Chat.chatSetSubject(text);
301
 };
311
 };
302
 
312
 
303
-UI.updateChatConversation = function (from, displayName, message) {
313
+function updateChatConversation(from, displayName, message) {
304
     return Chat.updateChatConversation(from, displayName, message);
314
     return Chat.updateChatConversation(from, displayName, message);
305
 };
315
 };
306
 
316
 
328
         onDisplayNameChanged('localVideoContainer', displayName + ' (me)');
338
         onDisplayNameChanged('localVideoContainer', displayName + ' (me)');
329
 }
339
 }
330
 
340
 
331
-UI.initEtherpad = function (name) {
341
+function initEtherpad(name) {
332
     Etherpad.init(name);
342
     Etherpad.init(name);
333
 };
343
 };
334
 
344
 
335
-UI.onMucLeft = function (jid) {
345
+function onMucLeft(jid) {
336
     console.log('left.muc', jid);
346
     console.log('left.muc', jid);
337
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
347
     var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
338
         '>.displayname').html();
348
         '>.displayname').html();
374
     return BottomToolbar.toggleContactList();
384
     return BottomToolbar.toggleContactList();
375
 };
385
 };
376
 
386
 
377
-UI.onLocalRoleChange = function (jid, info, pres) {
387
+function onLocalRoleChange(jid, info, pres, isModerator, isExternalAuthEnabled)
388
+{
378
 
389
 
379
     console.info("My role changed, new role: " + info.role);
390
     console.info("My role changed, new role: " + info.role);
380
-    var isModerator = xmpp.isModerator();
381
-
391
+    onModeratorStatusChanged(isModerator);
382
     VideoLayout.showModeratorIndicator();
392
     VideoLayout.showModeratorIndicator();
383
     Toolbar.showAuthenticateButton(
393
     Toolbar.showAuthenticateButton(
384
-            xmpp.isExternalAuthEnabled() && !isModerator);
394
+            isExternalAuthEnabled && !isModerator);
385
 
395
 
386
     if (isModerator) {
396
     if (isModerator) {
387
         Authentication.closeAuthenticationWindow();
397
         Authentication.closeAuthenticationWindow();
388
         messageHandler.notify(
398
         messageHandler.notify(
389
             'Me', 'connected', 'Moderator rights granted !');
399
             'Me', 'connected', 'Moderator rights granted !');
390
     }
400
     }
391
-};
401
+}
392
 
402
 
393
-UI.onModeratorStatusChanged = function (isModerator) {
403
+function onModeratorStatusChanged(isModerator) {
394
 
404
 
395
     Toolbar.showSipCallButton(isModerator);
405
     Toolbar.showSipCallButton(isModerator);
396
     Toolbar.showRecordingButton(
406
     Toolbar.showRecordingButton(
405
     }
415
     }
406
 };
416
 };
407
 
417
 
408
-UI.onPasswordReqiured = function (callback) {
418
+function onPasswordReqiured(callback) {
409
     // password is required
419
     // password is required
410
     Toolbar.lockLockButton();
420
     Toolbar.lockLockButton();
411
 
421
 
428
             }
438
             }
429
         }
439
         }
430
     );
440
     );
431
-};
432
-
433
-UI.onAuthenticationRequired = function (intervalCallback) {
434
-    Authentication.openAuthenticationDialog(
435
-        roomName, intervalCallback, function () {
436
-            Toolbar.authenticateClicked();
437
-        });
438
-};
439
-
440
-UI.setRecordingButtonState = function (state) {
441
-    Toolbar.setRecordingButtonState(state);
442
-};
443
-
444
-UI.inputDisplayNameHandler = function (value) {
445
-    VideoLayout.inputDisplayNameHandler(value);
446
-};
447
-
448
-UI.onMucEntered = function (jid, id, displayName) {
441
+}
442
+function onMucEntered(jid, id, displayName) {
449
     messageHandler.notify(displayName || 'Somebody',
443
     messageHandler.notify(displayName || 'Somebody',
450
         'connected',
444
         'connected',
451
         'connected');
445
         'connected');
452
 
446
 
453
     // Add Peer's container
447
     // Add Peer's container
454
     VideoLayout.ensurePeerContainerExists(jid,id);
448
     VideoLayout.ensurePeerContainerExists(jid,id);
455
-};
449
+}
456
 
450
 
457
-UI.onMucPresenceStatus = function ( jid, info) {
451
+function onMucPresenceStatus( jid, info) {
458
     VideoLayout.setPresenceStatus(
452
     VideoLayout.setPresenceStatus(
459
             'participant_' + Strophe.getResourceFromJid(jid), info.status);
453
             'participant_' + Strophe.getResourceFromJid(jid), info.status);
460
-};
454
+}
461
 
455
 
462
-UI.onMucRoleChanged = function (role, displayName) {
456
+function onMucRoleChanged(role, displayName) {
463
     VideoLayout.showModeratorIndicator();
457
     VideoLayout.showModeratorIndicator();
464
 
458
 
465
     if (role === 'moderator') {
459
     if (role === 'moderator') {
472
             'connected',
466
             'connected',
473
                 'Moderator rights granted to ' + displayName + '!');
467
                 'Moderator rights granted to ' + displayName + '!');
474
     }
468
     }
469
+}
470
+
471
+UI.onAuthenticationRequired = function (intervalCallback) {
472
+    Authentication.openAuthenticationDialog(
473
+        roomName, intervalCallback, function () {
474
+            Toolbar.authenticateClicked();
475
+        });
476
+};
477
+
478
+UI.setRecordingButtonState = function (state) {
479
+    Toolbar.setRecordingButtonState(state);
480
+};
481
+
482
+UI.inputDisplayNameHandler = function (value) {
483
+    VideoLayout.inputDisplayNameHandler(value);
475
 };
484
 };
476
 
485
 
477
 UI.updateLocalConnectionStats = function(percent, stats)
486
 UI.updateLocalConnectionStats = function(percent, stats)

+ 4
- 4
modules/UI/side_pannels/chat/Chat.js View File

41
 
41
 
42
         var chatBottomButtonElement
42
         var chatBottomButtonElement
43
             = document.getElementById('chatBottomButton').parentNode;
43
             = document.getElementById('chatBottomButton').parentNode;
44
-        var bottomLeftIndent = (Util.getTextWidth(chatBottomButtonElement) -
45
-            Util.getTextWidth(unreadMsgBottomElement)) / 2;
46
-        var bottomTopIndent = (Util.getTextHeight(chatBottomButtonElement) -
47
-            Util.getTextHeight(unreadMsgBottomElement)) / 2 - 2;
44
+        var bottomLeftIndent = (UIUtil.getTextWidth(chatBottomButtonElement) -
45
+            UIUtil.getTextWidth(unreadMsgBottomElement)) / 2;
46
+        var bottomTopIndent = (UIUtil.getTextHeight(chatBottomButtonElement) -
47
+            UIUtil.getTextHeight(unreadMsgBottomElement)) / 2 - 2;
48
 
48
 
49
         unreadMsgBottomElement.setAttribute(
49
         unreadMsgBottomElement.setAttribute(
50
             'style',
50
             'style',

+ 0
- 3
modules/xmpp/moderator.js View File

54
 
54
 
55
     init: function (xmpp) {
55
     init: function (xmpp) {
56
         this.xmppService = xmpp;
56
         this.xmppService = xmpp;
57
-        this.onLocalRoleChange = function (from, member, pres) {
58
-            UI.onModeratorStatusChanged(Moderator.isModerator());
59
-        };
60
     },
57
     },
61
 
58
 
62
     onMucLeft: function (jid) {
59
     onMucLeft: function (jid) {

+ 20
- 20
modules/xmpp/strophe.emuc.js View File

104
             var etherpad = $(pres).find('>etherpad');
104
             var etherpad = $(pres).find('>etherpad');
105
             if (etherpad.length) {
105
             if (etherpad.length) {
106
                 if (config.etherpad_base && !Moderator.isModerator()) {
106
                 if (config.etherpad_base && !Moderator.isModerator()) {
107
-                    UI.initEtherpad(etherpad.text());
107
+                    eventEmitter.emit(XMPPEvents.ETHERPAD, etherpad.text());
108
                 }
108
                 }
109
             }
109
             }
110
 
110
 
181
                 if (member.affiliation == 'owner') this.isOwner = true;
181
                 if (member.affiliation == 'owner') this.isOwner = true;
182
                 if (this.role !== member.role) {
182
                 if (this.role !== member.role) {
183
                     this.role = member.role;
183
                     this.role = member.role;
184
-                    if (Moderator.onLocalRoleChange)
185
-                        Moderator.onLocalRoleChange(from, member, pres);
186
-                    UI.onLocalRoleChange(from, member, pres);
184
+
185
+                    eventEmitter.emit(XMPPEvents.LOCALROLE_CHANGED,
186
+                        from, member, pres, Moderator.isModerator(),
187
+                        Moderator.isExternalAuthEnabled());
187
                 }
188
                 }
188
                 if (!this.joined) {
189
                 if (!this.joined) {
189
                     this.joined = true;
190
                     this.joined = true;
205
                     if (email.length > 0) {
206
                     if (email.length > 0) {
206
                         id = email.text();
207
                         id = email.text();
207
                     }
208
                     }
208
-                    UI.onMucEntered(from, id, member.displayName);
209
-                    API.triggerEvent("participantJoined", {jid: from});
209
+                    eventEmitter.emit(XMPPEvents.MUC_ENTER, from, id, member.displayName);
210
                 }
210
                 }
211
             } else {
211
             } else {
212
                 // Presence update for existing participant
212
                 // Presence update for existing participant
213
                 // Watch role change:
213
                 // Watch role change:
214
                 if (this.members[from].role != member.role) {
214
                 if (this.members[from].role != member.role) {
215
                     this.members[from].role = member.role;
215
                     this.members[from].role = member.role;
216
-                    UI.onMucRoleChanged(member.role, member.displayName);
216
+                    eventEmitter.emit(XMPPEvents.MUC_ROLE_CHANGED,
217
+                        member.role, member.displayName);
217
                 }
218
                 }
218
             }
219
             }
219
 
220
 
220
             // Always trigger presence to update bindings
221
             // Always trigger presence to update bindings
221
-            $(document).trigger('presence.muc', [from, member, pres]);
222
             this.parsePresence(from, member, pres);
222
             this.parsePresence(from, member, pres);
223
 
223
 
224
             // Trigger status message update
224
             // Trigger status message update
225
             if (member.status) {
225
             if (member.status) {
226
-                UI.onMucPresenceStatus(from, member);
226
+                eventEmitter.emit(XMPPEvents.PRESENCE_STATUS, from, member);
227
             }
227
             }
228
 
228
 
229
             return true;
229
             return true;
260
             if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
260
             if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
261
                 console.log('on password required', from);
261
                 console.log('on password required', from);
262
                 var self = this;
262
                 var self = this;
263
-                UI.onPasswordReqiured(function (value) {
263
+                eventEmitter.emit(XMPPEvents.PASSWORD_REQUIRED, function (value) {
264
                     self.doJoin(from, value);
264
                     self.doJoin(from, value);
265
                 });
265
                 });
266
             } else if ($(pres).find(
266
             } else if ($(pres).find(
309
         onMessage: function (msg) {
309
         onMessage: function (msg) {
310
             // FIXME: this is a hack. but jingle on muc makes nickchanges hard
310
             // FIXME: this is a hack. but jingle on muc makes nickchanges hard
311
             var from = msg.getAttribute('from');
311
             var from = msg.getAttribute('from');
312
-            var nick = $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]').text() || Strophe.getResourceFromJid(from);
312
+            var nick =
313
+                $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]')
314
+                    .text() ||
315
+                Strophe.getResourceFromJid(from);
313
 
316
 
314
             var txt = $(msg).find('>body').text();
317
             var txt = $(msg).find('>body').text();
315
             var type = msg.getAttribute("type");
318
             var type = msg.getAttribute("type");
316
             if (type == "error") {
319
             if (type == "error") {
317
-                UI.chatAddError($(msg).find('>text').text(), txt);
320
+                eventEmitter.emit(XMPPEvents.CHAT_ERROR_RECEIVED,
321
+                    $(msg).find('>text').text(), txt);
318
                 return true;
322
                 return true;
319
             }
323
             }
320
 
324
 
322
             if (subject.length) {
326
             if (subject.length) {
323
                 var subjectText = subject.text();
327
                 var subjectText = subject.text();
324
                 if (subjectText || subjectText == "") {
328
                 if (subjectText || subjectText == "") {
325
-                    UI.chatSetSubject(subjectText);
329
+                    eventEmitter.emit(XMPPEvents.SUBJECT_CHANGED, subjectText);
326
                     console.log("Subject is changed to " + subjectText);
330
                     console.log("Subject is changed to " + subjectText);
327
                 }
331
                 }
328
             }
332
             }
330
 
334
 
331
             if (txt) {
335
             if (txt) {
332
                 console.log('chat', nick, txt);
336
                 console.log('chat', nick, txt);
333
-                UI.updateChatConversation(from, nick, txt);
334
-                if (from != this.myroomjid)
335
-                    API.triggerEvent("incomingMessage",
336
-                        {"from": from, "nick": nick, "message": txt});
337
+                eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
338
+                    from, nick, txt, this.myroomjid);
337
             }
339
             }
338
             return true;
340
             return true;
339
         },
341
         },
460
             }
462
             }
461
 
463
 
462
             pres.up();
464
             pres.up();
463
-//        console.debug(pres.toString());
464
             this.connection.send(pres);
465
             this.connection.send(pres);
465
         },
466
         },
466
         addDisplayNameToPresence: function (displayName) {
467
         addDisplayNameToPresence: function (displayName) {
545
             return null;
546
             return null;
546
         },
547
         },
547
         onParticipantLeft: function (jid) {
548
         onParticipantLeft: function (jid) {
548
-            UI.onMucLeft(jid);
549
 
549
 
550
-            API.triggerEvent("participantLeft", {jid: jid});
550
+            eventEmitter.emit(XMPPEvents.MUC_LEFT, jid);
551
 
551
 
552
             this.connection.jingle.terminateByJid(jid);
552
             this.connection.jingle.terminateByJid(jid);
553
 
553
 

+ 11
- 1
service/xmpp/XMPPEvents.js View File

8
     USER_ID_CHANGED: "xmpp.user_id_changed",
8
     USER_ID_CHANGED: "xmpp.user_id_changed",
9
     CHANGED_STREAMS: "xmpp.changed_streams",
9
     CHANGED_STREAMS: "xmpp.changed_streams",
10
     MUC_JOINED: "xmpp.muc_joined",
10
     MUC_JOINED: "xmpp.muc_joined",
11
+    MUC_ENTER: "xmpp.muc_enter",
12
+    MUC_ROLE_CHANGED: "xmpp.muc_role_changed",
13
+    MUC_LEFT: "xmpp.muc_left",
11
     DISPLAY_NAME_CHANGED: "xmpp.display_name_changed",
14
     DISPLAY_NAME_CHANGED: "xmpp.display_name_changed",
12
-    REMOTE_STATS: "xmpp.remote_stats"
15
+    REMOTE_STATS: "xmpp.remote_stats",
16
+    LOCALROLE_CHANGED: "xmpp.localrole_changed",
17
+    PRESENCE_STATUS: "xmpp.presence_status",
18
+    SUBJECT_CHANGED: "xmpp.subject_changed",
19
+    MESSAGE_RECEIVED: "xmpp.message_received",
20
+    PASSWORD_REQUIRED: "xmpp.password_required",
21
+    CHAT_ERROR_RECEIVED: "xmpp.chat_error_received",
22
+    ETHERPAD: "xmpp.etherpad"
13
 };
23
 };
14
 //module.exports = XMPPEvents;
24
 //module.exports = XMPPEvents;

Loading…
Cancel
Save