Selaa lähdekoodia

refactoring

master
isymchych 10 vuotta sitten
vanhempi
commit
4f91ac01fd

+ 13
- 11
modules/UI/UI.js Näytä tiedosto

@@ -14,11 +14,11 @@ import UIUtil from "./util/UIUtil";
14 14
 import UIEvents from "../../service/UI/UIEvents";
15 15
 
16 16
 import VideoLayout from "./videolayout/VideoLayout";
17
+import SettingsMenu from "./side_pannels/settings/SettingsMenu";
17 18
 
18 19
 var Prezi = require("./prezi/Prezi");
19 20
 var Etherpad = require("./etherpad/Etherpad");
20 21
 var EventEmitter = require("events");
21
-var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
22 22
 var Settings = require("./../settings/Settings");
23 23
 UI.messageHandler = require("./util/MessageHandler");
24 24
 var messageHandler = UI.messageHandler;
@@ -255,6 +255,7 @@ UI.start = function () {
255 255
     registerListeners();
256 256
 
257 257
     VideoLayout.init(eventEmitter);
258
+    ContactList.init(eventEmitter);
258 259
 
259 260
     bindEvents();
260 261
     setupPrezi();
@@ -355,6 +356,8 @@ function initEtherpad(name) {
355 356
 }
356 357
 
357 358
 UI.addUser = function (id, displayName) {
359
+    ContactList.addContact(id);
360
+
358 361
     messageHandler.notify(
359 362
         displayName,'notify.somebody', 'connected', 'notify.connected'
360 363
     );
@@ -367,22 +370,21 @@ UI.addUser = function (id, displayName) {
367 370
     UI.setUserAvatar(id, displayName);
368 371
 
369 372
     // Add Peer's container
370
-    VideoLayout.ensurePeerContainerExists(id);
373
+    VideoLayout.addParticipantContainer(id);
371 374
 };
372 375
 
373 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 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 390
 function onMucPresenceStatus(jid, info) {

+ 24
- 31
modules/UI/side_pannels/contactlist/ContactList.js Näytä tiedosto

@@ -1,8 +1,9 @@
1 1
 /* global $, APP */
2 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 9
  * Updates the number of participants in the contact list button and sets
@@ -30,7 +31,7 @@ function updateNumberOfParticipants(delta) {
30 31
  * @return {object} the newly created avatar element
31 32
  */
32 33
 function createAvatar(jid) {
33
-    var avatar = document.createElement('img');
34
+    let avatar = document.createElement('img');
34 35
     avatar.className = "icon-avatar avatar";
35 36
     avatar.src = Avatar.getContactListUrl(jid);
36 37
 
@@ -43,7 +44,7 @@ function createAvatar(jid) {
43 44
  * @param displayName the display name to set
44 45
  */
45 46
 function createDisplayNameParagraph(key, displayName) {
46
-    var p = document.createElement('p');
47
+    let p = document.createElement('p');
47 48
     if (displayName) {
48 49
         p.innerText = displayName;
49 50
     } else if(key) {
@@ -76,39 +77,32 @@ function contactElExists (id) {
76 77
  * Contact list.
77 78
  */
78 79
 var ContactList = {
80
+    init (emitter) {
81
+        this.emitter = emitter;
82
+    },
79 83
     /**
80 84
      * Indicates if the chat is currently visible.
81 85
      *
82 86
      * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
83 87
      * otherwise
84 88
      */
85
-    isVisible: function () {
89
+    isVisible () {
86 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 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 101
         newContact.id = id;
108 102
         newContact.className = "clickable";
109
-        newContact.onclick = function (event) {
103
+        newContact.onclick = (event) => {
110 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,7 +121,7 @@ var ContactList = {
127 121
      * Removes a contact for the given id.
128 122
      *
129 123
      */
130
-    removeContact: function (id) {
124
+    removeContact (id) {
131 125
         let contact = getContactEl(id);
132 126
 
133 127
         if (contact.length > 0) {
@@ -136,15 +130,14 @@ var ContactList = {
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 136
         if (show && !notificationInterval) {
143 137
             notificationInterval = window.setInterval(function () {
144 138
                 glower.toggleClass('active glowing');
145 139
             }, 800);
146
-        }
147
-        else if (!show && notificationInterval) {
140
+        } else if (!show && notificationInterval) {
148 141
             stopGlowing(glower);
149 142
         }
150 143
         if (stopGlowingIn) {
@@ -154,28 +147,28 @@ var ContactList = {
154 147
         }
155 148
     },
156 149
 
157
-    setClickable: function (id, isClickable) {
150
+    setClickable (id, isClickable) {
158 151
         getContactEl(id).toggleClass('clickable', isClickable);
159 152
     },
160 153
 
161
-    onDisplayNameChange: function (id, displayName) {
154
+    onDisplayNameChange (id, displayName) {
162 155
         if (id === 'localVideoContainer') {
163 156
             id = APP.conference.localId;
164 157
         }
165
-        var contactName = $(`#contacts #${id}>p`);
158
+        let contactName = $(`#contacts #${id}>p`);
166 159
 
167 160
         if (displayName) {
168 161
             contactName.html(displayName);
169 162
         }
170 163
     },
171 164
 
172
-    changeUserAvatar: function (id, contactListUrl) {
165
+    changeUserAvatar (id, contactListUrl) {
173 166
         // set the avatar in the contact list
174
-        var contact = $(`#${id}>img`);
167
+        let contact = $(`#${id}>img`);
175 168
         if (contact.length > 0) {
176 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 Näytä tiedosto

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

+ 2
- 1
modules/UI/videolayout/ConnectionIndicator.js Näytä tiedosto

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

+ 15
- 30
modules/UI/videolayout/VideoLayout.js Näytä tiedosto

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

+ 1
- 0
service/UI/UIEvents.js Näytä tiedosto

@@ -32,6 +32,7 @@ export default {
32 32
     TOGGLE_SETTINGS: "UI.toggle_settings",
33 33
     TOGGLE_CONTACT_LIST: "UI.toggle_contact_list",
34 34
     TOGGLE_FILM_STRIP: "UI.toggle_film_strip",
35
+    CONTACT_CLICKED: "UI.contact_clicked",
35 36
     HANGUP: "UI.hangup",
36 37
     LOGOUT: "UI.logout",
37 38
     RECORDING_TOGGLE: "UI.recording_toggle",

Loading…
Peruuta
Tallenna