瀏覽代碼

refactoring

master
isymchych 10 年之前
父節點
當前提交
4f91ac01fd

+ 13
- 11
modules/UI/UI.js 查看文件

14
 import UIEvents from "../../service/UI/UIEvents";
14
 import UIEvents from "../../service/UI/UIEvents";
15
 
15
 
16
 import VideoLayout from "./videolayout/VideoLayout";
16
 import VideoLayout from "./videolayout/VideoLayout";
17
+import SettingsMenu from "./side_pannels/settings/SettingsMenu";
17
 
18
 
18
 var Prezi = require("./prezi/Prezi");
19
 var Prezi = require("./prezi/Prezi");
19
 var Etherpad = require("./etherpad/Etherpad");
20
 var Etherpad = require("./etherpad/Etherpad");
20
 var EventEmitter = require("events");
21
 var EventEmitter = require("events");
21
-var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
22
 var Settings = require("./../settings/Settings");
22
 var Settings = require("./../settings/Settings");
23
 UI.messageHandler = require("./util/MessageHandler");
23
 UI.messageHandler = require("./util/MessageHandler");
24
 var messageHandler = UI.messageHandler;
24
 var messageHandler = UI.messageHandler;
255
     registerListeners();
255
     registerListeners();
256
 
256
 
257
     VideoLayout.init(eventEmitter);
257
     VideoLayout.init(eventEmitter);
258
+    ContactList.init(eventEmitter);
258
 
259
 
259
     bindEvents();
260
     bindEvents();
260
     setupPrezi();
261
     setupPrezi();
355
 }
356
 }
356
 
357
 
357
 UI.addUser = function (id, displayName) {
358
 UI.addUser = function (id, displayName) {
359
+    ContactList.addContact(id);
360
+
358
     messageHandler.notify(
361
     messageHandler.notify(
359
         displayName,'notify.somebody', 'connected', 'notify.connected'
362
         displayName,'notify.somebody', 'connected', 'notify.connected'
360
     );
363
     );
367
     UI.setUserAvatar(id, displayName);
370
     UI.setUserAvatar(id, displayName);
368
 
371
 
369
     // Add Peer's container
372
     // Add Peer's container
370
-    VideoLayout.ensurePeerContainerExists(id);
373
+    VideoLayout.addParticipantContainer(id);
371
 };
374
 };
372
 
375
 
373
 UI.removeUser = function (id, displayName) {
376
 UI.removeUser = function (id, displayName) {
374
-    console.log('left.muc', id);
375
-    messageHandler.notify(displayName,'notify.somebody',
376
-        'disconnected',
377
-        'notify.disconnected');
378
-    if (!config.startAudioMuted ||
379
-        config.startAudioMuted > APP.conference.membersCount) {
377
+    ContactList.removeContact(id);
378
+
379
+    messageHandler.notify(
380
+        displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
381
+    );
382
+
383
+    if (!config.startAudioMuted || config.startAudioMuted > APP.conference.membersCount) {
380
         UIUtil.playSoundNotification('userLeft');
384
         UIUtil.playSoundNotification('userLeft');
381
     }
385
     }
382
 
386
 
383
-    ContactList.removeContact(id);
384
-
385
-    VideoLayout.participantLeft(id);
387
+    VideoLayout.removeParticipantContainer(id);
386
 };
388
 };
387
 
389
 
388
 function onMucPresenceStatus(jid, info) {
390
 function onMucPresenceStatus(jid, info) {

+ 24
- 31
modules/UI/side_pannels/contactlist/ContactList.js 查看文件

1
 /* global $, APP */
1
 /* global $, APP */
2
 import Avatar from '../../avatar/Avatar';
2
 import Avatar from '../../avatar/Avatar';
3
+import UIEvents from '../../../../service/UI/UIEvents';
3
 
4
 
4
-var numberOfContacts = 0;
5
-var notificationInterval;
5
+let numberOfContacts = 0;
6
+let notificationInterval;
6
 
7
 
7
 /**
8
 /**
8
  * Updates the number of participants in the contact list button and sets
9
  * Updates the number of participants in the contact list button and sets
30
  * @return {object} the newly created avatar element
31
  * @return {object} the newly created avatar element
31
  */
32
  */
32
 function createAvatar(jid) {
33
 function createAvatar(jid) {
33
-    var avatar = document.createElement('img');
34
+    let avatar = document.createElement('img');
34
     avatar.className = "icon-avatar avatar";
35
     avatar.className = "icon-avatar avatar";
35
     avatar.src = Avatar.getContactListUrl(jid);
36
     avatar.src = Avatar.getContactListUrl(jid);
36
 
37
 
43
  * @param displayName the display name to set
44
  * @param displayName the display name to set
44
  */
45
  */
45
 function createDisplayNameParagraph(key, displayName) {
46
 function createDisplayNameParagraph(key, displayName) {
46
-    var p = document.createElement('p');
47
+    let p = document.createElement('p');
47
     if (displayName) {
48
     if (displayName) {
48
         p.innerText = displayName;
49
         p.innerText = displayName;
49
     } else if(key) {
50
     } else if(key) {
76
  * Contact list.
77
  * Contact list.
77
  */
78
  */
78
 var ContactList = {
79
 var ContactList = {
80
+    init (emitter) {
81
+        this.emitter = emitter;
82
+    },
79
     /**
83
     /**
80
      * Indicates if the chat is currently visible.
84
      * Indicates if the chat is currently visible.
81
      *
85
      *
82
      * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
86
      * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
83
      * otherwise
87
      * otherwise
84
      */
88
      */
85
-    isVisible: function () {
89
+    isVisible () {
86
         return $('#contactlist').is(":visible");
90
         return $('#contactlist').is(":visible");
87
     },
91
     },
88
 
92
 
89
-    /**
90
-     * Adds a contact for the given id if such doesn't yet exist.
91
-     *
92
-     */
93
-    ensureAddContact: function (id) {
94
-        if (!contactElExists(id)) {
95
-            ContactList.addContact(id);
96
-        }
97
-    },
98
-
99
     /**
93
     /**
100
      * Adds a contact for the given id.
94
      * Adds a contact for the given id.
101
      *
95
      *
102
      */
96
      */
103
-    addContact: function (id) {
104
-        var contactlist = $('#contacts');
97
+    addContact (id) {
98
+        let contactlist = $('#contacts');
105
 
99
 
106
-        var newContact = document.createElement('li');
100
+        let newContact = document.createElement('li');
107
         newContact.id = id;
101
         newContact.id = id;
108
         newContact.className = "clickable";
102
         newContact.className = "clickable";
109
-        newContact.onclick = function (event) {
103
+        newContact.onclick = (event) => {
110
             if (event.currentTarget.className === "clickable") {
104
             if (event.currentTarget.className === "clickable") {
111
-                $(ContactList).trigger('contactclicked', [id]);
105
+                this.emitter.emit(UIEvents.CONTACT_CLICKED, id);
112
             }
106
             }
113
         };
107
         };
114
 
108
 
127
      * Removes a contact for the given id.
121
      * Removes a contact for the given id.
128
      *
122
      *
129
      */
123
      */
130
-    removeContact: function (id) {
124
+    removeContact (id) {
131
         let contact = getContactEl(id);
125
         let contact = getContactEl(id);
132
 
126
 
133
         if (contact.length > 0) {
127
         if (contact.length > 0) {
136
         }
130
         }
137
     },
131
     },
138
 
132
 
139
-    setVisualNotification: function (show, stopGlowingIn) {
140
-        var glower = $('#contactListButton');
133
+    setVisualNotification (show, stopGlowingIn) {
134
+        let glower = $('#contactListButton');
141
 
135
 
142
         if (show && !notificationInterval) {
136
         if (show && !notificationInterval) {
143
             notificationInterval = window.setInterval(function () {
137
             notificationInterval = window.setInterval(function () {
144
                 glower.toggleClass('active glowing');
138
                 glower.toggleClass('active glowing');
145
             }, 800);
139
             }, 800);
146
-        }
147
-        else if (!show && notificationInterval) {
140
+        } else if (!show && notificationInterval) {
148
             stopGlowing(glower);
141
             stopGlowing(glower);
149
         }
142
         }
150
         if (stopGlowingIn) {
143
         if (stopGlowingIn) {
154
         }
147
         }
155
     },
148
     },
156
 
149
 
157
-    setClickable: function (id, isClickable) {
150
+    setClickable (id, isClickable) {
158
         getContactEl(id).toggleClass('clickable', isClickable);
151
         getContactEl(id).toggleClass('clickable', isClickable);
159
     },
152
     },
160
 
153
 
161
-    onDisplayNameChange: function (id, displayName) {
154
+    onDisplayNameChange (id, displayName) {
162
         if (id === 'localVideoContainer') {
155
         if (id === 'localVideoContainer') {
163
             id = APP.conference.localId;
156
             id = APP.conference.localId;
164
         }
157
         }
165
-        var contactName = $(`#contacts #${id}>p`);
158
+        let contactName = $(`#contacts #${id}>p`);
166
 
159
 
167
         if (displayName) {
160
         if (displayName) {
168
             contactName.html(displayName);
161
             contactName.html(displayName);
169
         }
162
         }
170
     },
163
     },
171
 
164
 
172
-    changeUserAvatar: function (id, contactListUrl) {
165
+    changeUserAvatar (id, contactListUrl) {
173
         // set the avatar in the contact list
166
         // set the avatar in the contact list
174
-        var contact = $(`#${id}>img`);
167
+        let contact = $(`#${id}>img`);
175
         if (contact.length > 0) {
168
         if (contact.length > 0) {
176
             contact.attr('src', contactListUrl);
169
             contact.attr('src', contactListUrl);
177
         }
170
         }
178
     }
171
     }
179
 };
172
 };
180
 
173
 
181
-module.exports = ContactList;
174
+export default ContactList;

+ 2
- 3
modules/UI/side_pannels/settings/SettingsMenu.js 查看文件

21
 }
21
 }
22
 
22
 
23
 
23
 
24
-var SettingsMenu = {
24
+const SettingsMenu = {
25
 
25
 
26
     init: function (emitter) {
26
     init: function (emitter) {
27
         this.emitter = emitter;
27
         this.emitter = emitter;
97
     }
97
     }
98
 };
98
 };
99
 
99
 
100
-
101
-module.exports = SettingsMenu;
100
+export default SettingsMenu;

+ 2
- 1
modules/UI/videolayout/ConnectionIndicator.js 查看文件

365
  */
365
  */
366
 ConnectionIndicator.prototype.updatePopoverData = function () {
366
 ConnectionIndicator.prototype.updatePopoverData = function () {
367
     this.popover.updateContent(
367
     this.popover.updateContent(
368
-        "<div class=\"connection_info\">" + this.generateText() + "</div>");
368
+        `<div class="connection_info">${this.generateText()}</div>`
369
+    );
369
     APP.translation.translateElement($(".connection_info"));
370
     APP.translation.translateElement($(".connection_info"));
370
 };
371
 };
371
 
372
 

+ 15
- 30
modules/UI/videolayout/VideoLayout.js 查看文件

2
 /* jshint -W101 */
2
 /* jshint -W101 */
3
 
3
 
4
 import AudioLevels from "../audio_levels/AudioLevels";
4
 import AudioLevels from "../audio_levels/AudioLevels";
5
-import ContactList from "../side_pannels/contactlist/ContactList";
6
 
5
 
7
 import UIEvents from "../../../service/UI/UIEvents";
6
 import UIEvents from "../../../service/UI/UIEvents";
8
 import UIUtil from "../util/UIUtil";
7
 import UIUtil from "../util/UIUtil";
36
 /**
35
 /**
37
  * On contact list item clicked.
36
  * On contact list item clicked.
38
  */
37
  */
39
-$(ContactList).bind('contactclicked', function(event, id) {
40
-    if (!id) {
41
-        return;
42
-    }
43
-
38
+function onContactClicked (id) {
44
     if (APP.conference.isLocalId(id)) {
39
     if (APP.conference.isLocalId(id)) {
45
         $("#localVideoContainer").click();
40
         $("#localVideoContainer").click();
46
         return;
41
         return;
47
     }
42
     }
48
 
43
 
49
-    var remoteVideo = remoteVideos[id];
44
+    let remoteVideo = remoteVideos[id];
50
     if (remoteVideo && remoteVideo.selectVideoElement().length) {
45
     if (remoteVideo && remoteVideo.selectVideoElement().length) {
51
-        var videoThumb = remoteVideo.selectVideoElement()[0];
46
+        let videoThumb = remoteVideo.selectVideoElement()[0];
52
         // It is not always the case that a videoThumb exists (if there is
47
         // It is not always the case that a videoThumb exists (if there is
53
         // no actual video).
48
         // no actual video).
54
         if (RTC.getVideoSrc(videoThumb)) {
49
         if (RTC.getVideoSrc(videoThumb)) {
72
             eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id);
67
             eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id);
73
         }
68
         }
74
     }
69
     }
75
-});
70
+}
76
 
71
 
77
 /**
72
 /**
78
  * Returns the corresponding resource id to the given peer container
73
  * Returns the corresponding resource id to the given peer container
106
 
101
 
107
         VideoLayout.resizeLargeVideoContainer();
102
         VideoLayout.resizeLargeVideoContainer();
108
 
103
 
104
+        emitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
109
     },
105
     },
110
 
106
 
111
     isInLastN (resource) {
107
     isInLastN (resource) {
242
 
238
 
243
     onRemoteStreamAdded (stream) {
239
     onRemoteStreamAdded (stream) {
244
         let id = stream.getParticipantId();
240
         let id = stream.getParticipantId();
245
-        VideoLayout.ensurePeerContainerExists(id);
246
 
241
 
247
         remoteVideos[id].addRemoteStreamElement(stream);
242
         remoteVideos[id].addRemoteStreamElement(stream);
248
     },
243
     },
340
      * @return Returns <tt>true</tt> if the peer container exists,
335
      * @return Returns <tt>true</tt> if the peer container exists,
341
      * <tt>false</tt> - otherwise
336
      * <tt>false</tt> - otherwise
342
      */
337
      */
343
-    ensurePeerContainerExists (id) {
344
-        ContactList.ensureAddContact(id);
345
-
346
-        if (remoteVideos[id]) {
347
-            return;
348
-        }
349
-
338
+    addParticipantContainer (id) {
350
         let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
339
         let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
351
         remoteVideos[id] = remoteVideo;
340
         remoteVideos[id] = remoteVideo;
352
 
341
 
534
         if (resourceJid === APP.xmpp.myResource()) {
523
         if (resourceJid === APP.xmpp.myResource()) {
535
             localVideoThumbnail.showAudioIndicator(isMuted);
524
             localVideoThumbnail.showAudioIndicator(isMuted);
536
         } else {
525
         } else {
537
-            VideoLayout.ensurePeerContainerExists(jid);
538
             remoteVideos[resourceJid].showAudioIndicator(isMuted);
526
             remoteVideos[resourceJid].showAudioIndicator(isMuted);
539
             if (APP.xmpp.isModerator()) {
527
             if (APP.xmpp.isModerator()) {
540
                 remoteVideos[resourceJid].updateRemoteVideoMenu(isMuted);
528
                 remoteVideos[resourceJid].updateRemoteVideoMenu(isMuted);
555
         } else {
543
         } else {
556
             var resource = Strophe.getResourceFromJid(jid);
544
             var resource = Strophe.getResourceFromJid(jid);
557
 
545
 
558
-            VideoLayout.ensurePeerContainerExists(jid);
559
             var remoteVideo = remoteVideos[resource];
546
             var remoteVideo = remoteVideos[resource];
560
             remoteVideo.showVideoIndicator(value);
547
             remoteVideo.showVideoIndicator(value);
561
 
548
 
575
             APP.conference.isLocalId(id)) {
562
             APP.conference.isLocalId(id)) {
576
             localVideoThumbnail.setDisplayName(displayName);
563
             localVideoThumbnail.setDisplayName(displayName);
577
         } else {
564
         } else {
578
-            VideoLayout.ensurePeerContainerExists(id);
579
             remoteVideos[id].setDisplayName(displayName, status);
565
             remoteVideos[id].setDisplayName(displayName, status);
580
         }
566
         }
581
     },
567
     },
801
 
787
 
802
     /**
788
     /**
803
      * Updates remote stats.
789
      * Updates remote stats.
804
-     * @param jid the jid associated with the stats
790
+     * @param id the id associated with the stats
805
      * @param percent the connection quality percent
791
      * @param percent the connection quality percent
806
      * @param object the stats data
792
      * @param object the stats data
807
      */
793
      */
808
-    updateConnectionStats (jid, percent, object) {
809
-        var resourceJid = Strophe.getResourceFromJid(jid);
810
-
811
-        if (remoteVideos[resourceJid])
812
-            remoteVideos[resourceJid].updateStatsIndicator(percent, object);
794
+    updateConnectionStats (id, percent, object) {
795
+        if (remoteVideos[id]) {
796
+            remoteVideos[id].updateStatsIndicator(percent, object);
797
+        }
813
     },
798
     },
814
 
799
 
815
     /**
800
     /**
816
      * Hides the connection indicator
801
      * Hides the connection indicator
817
-     * @param jid
802
+     * @param id
818
      */
803
      */
819
-    hideConnectionIndicator (jid) {
820
-        remoteVideos[Strophe.getResourceFromJid(jid)].hideConnectionIndicator();
804
+    hideConnectionIndicator (id) {
805
+        remoteVideos[id].hideConnectionIndicator();
821
     },
806
     },
822
 
807
 
823
     /**
808
     /**
830
         localVideoThumbnail.hideIndicator();
815
         localVideoThumbnail.hideIndicator();
831
     },
816
     },
832
 
817
 
833
-    participantLeft (id) {
818
+    removeParticipantContainer (id) {
834
         // Unlock large video
819
         // Unlock large video
835
         if (focusedVideoResourceJid === id) {
820
         if (focusedVideoResourceJid === id) {
836
             console.info("Focused video owner has left the conference");
821
             console.info("Focused video owner has left the conference");

+ 1
- 0
service/UI/UIEvents.js 查看文件

32
     TOGGLE_SETTINGS: "UI.toggle_settings",
32
     TOGGLE_SETTINGS: "UI.toggle_settings",
33
     TOGGLE_CONTACT_LIST: "UI.toggle_contact_list",
33
     TOGGLE_CONTACT_LIST: "UI.toggle_contact_list",
34
     TOGGLE_FILM_STRIP: "UI.toggle_film_strip",
34
     TOGGLE_FILM_STRIP: "UI.toggle_film_strip",
35
+    CONTACT_CLICKED: "UI.contact_clicked",
35
     HANGUP: "UI.hangup",
36
     HANGUP: "UI.hangup",
36
     LOGOUT: "UI.logout",
37
     LOGOUT: "UI.logout",
37
     RECORDING_TOGGLE: "UI.recording_toggle",
38
     RECORDING_TOGGLE: "UI.recording_toggle",

Loading…
取消
儲存