Просмотр исходного кода

Merge pull request #520 from isymchych/improve-settings

Apply new settings without clickint "Update" button
j8
yanas 9 лет назад
Родитель
Сommit
ed85658ce5

+ 16
- 20
conference.js Просмотреть файл

@@ -331,10 +331,9 @@ export default {
331 331
             // update list of available devices
332 332
             if (JitsiMeetJS.isDeviceListAvailable() &&
333 333
                 JitsiMeetJS.isDeviceChangeAvailable()) {
334
-                JitsiMeetJS.enumerateDevices((devices) => {
335
-                    this.availableDevices = devices;
336
-                    APP.UI.onAvailableDevicesChanged();
337
-                });
334
+                JitsiMeetJS.enumerateDevices(
335
+                    devices => APP.UI.onAvailableDevicesChanged(devices)
336
+                );
338 337
             }
339 338
             // XXX The API will take care of disconnecting from the XMPP server
340 339
             // (and, thus, leaving the room) on unload.
@@ -398,10 +397,6 @@ export default {
398 397
     listMembersIds () {
399 398
         return room.getParticipants().map(p => p.getId());
400 399
     },
401
-    /**
402
-     * List of available cameras and microphones.
403
-     */
404
-    availableDevices: [],
405 400
     /**
406 401
      * Check if SIP is supported.
407 402
      * @returns {boolean}
@@ -412,12 +407,6 @@ export default {
412 407
     get membersCount () {
413 408
         return room.getParticipants().length + 1;
414 409
     },
415
-    get startAudioMuted () {
416
-        return room && room.getStartMutedPolicy().audio;
417
-    },
418
-    get startVideoMuted () {
419
-        return room && room.getStartMutedPolicy().video;
420
-    },
421 410
     /**
422 411
      * Returns true if the callstats integration is enabled, otherwise returns
423 412
      * false.
@@ -689,7 +678,6 @@ export default {
689 678
         room.on(ConferenceEvents.USER_JOINED, (id, user) => {
690 679
             console.log('USER %s connnected', id, user);
691 680
             APP.API.notifyUserJoined(id);
692
-            // FIXME email???
693 681
             APP.UI.addUser(id, user.getDisplayName());
694 682
 
695 683
             // chek the roles for the new user and reflect them
@@ -907,7 +895,13 @@ export default {
907 895
             });
908 896
         });
909 897
 
910
-        APP.UI.addListener(UIEvents.EMAIL_CHANGED, (email) => {
898
+        APP.UI.addListener(UIEvents.EMAIL_CHANGED, (email = '') => {
899
+            email = email.trim();
900
+
901
+            if (email === APP.settings.getEmail()) {
902
+                return;
903
+            }
904
+
911 905
             APP.settings.setEmail(email);
912 906
             APP.UI.setUserAvatar(room.myUserId(), email);
913 907
             sendEmail(email);
@@ -930,14 +924,16 @@ export default {
930 924
 
931 925
         APP.UI.addListener(UIEvents.START_MUTED_CHANGED,
932 926
             (startAudioMuted, startVideoMuted) => {
933
-                room.setStartMutedPolicy({audio: startAudioMuted,
934
-                    video: startVideoMuted});
927
+                room.setStartMutedPolicy({
928
+                    audio: startAudioMuted,
929
+                    video: startVideoMuted
930
+                });
935 931
             }
936 932
         );
937 933
         room.on(
938 934
             ConferenceEvents.START_MUTED_POLICY_CHANGED,
939
-            (policy) => {
940
-                APP.UI.onStartMutedChanged();
935
+            ({ audio, video }) => {
936
+                APP.UI.onStartMutedChanged(audio, video);
941 937
             }
942 938
         );
943 939
         room.on(ConferenceEvents.STARTED_MUTED, () => {

+ 9
- 8
css/settingsmenu.css Просмотреть файл

@@ -27,13 +27,6 @@
27 27
     margin-right: auto;
28 28
 }
29 29
 
30
-#settingsmenu button {
31
-    width: 45%;
32
-    left: 26%;
33
-    padding: 0;
34
-    margin-top: 10px;
35
-}
36
-
37 30
 #settingsmenu #avatar {
38 31
     width: 24%;
39 32
     left: 38%;
@@ -45,8 +38,9 @@
45 38
     padding: 34px;
46 39
 }
47 40
 
48
-#languages_selectbox{
41
+#languages_selectbox {
49 42
     height: 40px;
43
+    cursor: pointer;
50 44
 }
51 45
 
52 46
 
@@ -54,6 +48,10 @@
54 48
     padding-left: 10%;
55 49
     text-indent: -10%;
56 50
 
51
+    margin-top: 10px;
52
+
53
+    display: none; /* hide by default */
54
+
57 55
     /* clearfix */
58 56
     overflow: auto;
59 57
     zoom: 1;
@@ -70,10 +68,12 @@
70 68
 .startMutedLabel {
71 69
     width: 94%;
72 70
     float: left;
71
+    cursor: pointer;
73 72
 }
74 73
 
75 74
 #devicesOptions {
76 75
     display: none;
76
+    margin-top: 10px;
77 77
 }
78 78
 
79 79
 #devicesOptions label {
@@ -87,4 +87,5 @@
87 87
 
88 88
 #devicesOptions select {
89 89
     height: 40px;
90
+    cursor: pointer;
90 91
 }

+ 1
- 1
index.html Просмотреть файл

@@ -219,6 +219,7 @@
219 219
             <div class="arrow-up"></div>
220 220
             <input type="text" id="setDisplayName" data-i18n="[placeholder]settings.name" placeholder="Name">
221 221
             <input type="text" id="setEmail" placeholder="E-Mail">
222
+            <select id="languages_selectbox"></select>
222 223
             <div id = "startMutedOptions">
223 224
                 <label class = "startMutedLabel">
224 225
                     <input type="checkbox" id="startAudioMuted">
@@ -239,7 +240,6 @@
239 240
                     <select id="selectMic"></select>
240 241
                 </label>
241 242
             </div>
242
-            <button id="updateSettings" data-i18n="settings.update"></button>
243 243
             <a id="downloadlog" data-container="body" data-toggle="popover" data-placement="right" data-i18n="[data-content]downloadlogs" ><i class="fa fa-cloud-download"></i></a>
244 244
         </div>
245 245
         <div class="feedbackButton">

+ 6
- 10
modules/UI/UI.js Просмотреть файл

@@ -212,10 +212,10 @@ UI.showChatError = function (err, msg) {
212 212
  */
213 213
 UI.changeDisplayName = function (id, displayName) {
214 214
     ContactList.onDisplayNameChange(id, displayName);
215
-    SettingsMenu.onDisplayNameChange(id, displayName);
216 215
     VideoLayout.onDisplayNameChanged(id, displayName);
217 216
 
218
-    if (APP.conference.isLocalId(id)) {
217
+    if (APP.conference.isLocalId(id) || id === 'localVideoContainer') {
218
+        SettingsMenu.changeDisplayName(displayName);
219 219
         Chat.setChatConversationMode(!!displayName);
220 220
     }
221 221
 };
@@ -256,10 +256,6 @@ UI.mucJoined = function () {
256 256
  * Setup some UI event listeners.
257 257
  */
258 258
 function registerListeners() {
259
-    UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
260
-        UI.setUserAvatar(APP.conference.localId, email);
261
-    });
262
-
263 259
     UI.addListener(UIEvents.PREZI_CLICKED, function () {
264 260
         preziManager.handlePreziButtonClicked();
265 261
     });
@@ -538,7 +534,7 @@ UI.updateLocalRole = function (isModerator) {
538 534
 
539 535
     Toolbar.showSipCallButton(isModerator);
540 536
     Toolbar.showRecordingButton(isModerator);
541
-    SettingsMenu.onRoleChanged();
537
+    SettingsMenu.showStartMutedOptions(isModerator);
542 538
 
543 539
     if (isModerator) {
544 540
         messageHandler.notify(null, "notify.me", 'connected', "notify.moderator");
@@ -1022,8 +1018,8 @@ UI.stopPrezi = function (userId) {
1022 1018
   }
1023 1019
 };
1024 1020
 
1025
-UI.onStartMutedChanged = function () {
1026
-    SettingsMenu.onStartMutedChanged();
1021
+UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) {
1022
+    SettingsMenu.updateStartMutedBox(startAudioMuted, startVideoMuted);
1027 1023
 };
1028 1024
 
1029 1025
 /**
@@ -1031,7 +1027,7 @@ UI.onStartMutedChanged = function () {
1031 1027
  * @param {object[]} devices new list of available devices
1032 1028
  */
1033 1029
 UI.onAvailableDevicesChanged = function (devices) {
1034
-    SettingsMenu.onAvailableDevicesChanged(devices);
1030
+    SettingsMenu.changeDevicesList(devices);
1035 1031
 };
1036 1032
 
1037 1033
 /**

+ 1
- 4
modules/UI/side_pannels/SidePanelToggler.js Просмотреть файл

@@ -161,10 +161,7 @@ var PanelToggler = {
161 161
         toggle(SettingsMenu,
162 162
             '#settingsmenu',
163 163
             null,
164
-            function() {
165
-                $('#setDisplayName').val(Settings.getDisplayName());
166
-                $('#setEmail').val(Settings.getEmail());
167
-            },
164
+            function() {},
168 165
             null);
169 166
     },
170 167
 

+ 106
- 63
modules/UI/side_pannels/settings/SettingsMenu.js Просмотреть файл

@@ -4,23 +4,34 @@ import UIEvents from "../../../../service/UI/UIEvents";
4 4
 import languages from "../../../../service/translation/languages";
5 5
 import Settings from '../../../settings/Settings';
6 6
 
7
-function generateLanguagesSelectBox() {
8
-    var currentLang = APP.translation.getCurrentLanguage();
9
-    var html = '<select id="languages_selectbox">';
10
-    var langArray = languages.getLanguages();
11
-    for(var i = 0; i < langArray.length; i++) {
12
-        var lang = langArray[i];
13
-        html += "<option ";
14
-        if(lang === currentLang)
15
-            html += "selected ";
16
-        html += "value=\"" + lang + "\" data-i18n='languages:" + lang + "'>";
17
-        html += "</option>";
7
+/**
8
+ * Generate html select options for available languages.
9
+ * @param {string[]} items available languages
10
+ * @param {string} [currentLang] current language
11
+ * @returns {string}
12
+ */
13
+function generateLanguagesOptions(items, currentLang) {
14
+    return items.map(function (lang) {
15
+        let attrs = {
16
+            value: lang,
17
+            'data-i18n': `languages:${lang}`
18
+        };
18 19
 
19
-    }
20
+        if (lang === currentLang) {
21
+            attrs.selected = 'selected';
22
+        }
20 23
 
21
-    return html + "</select>";
24
+        let attrsStr = UIUtil.attrsToString(attrs);
25
+        return `<option ${attrsStr}></option>`;
26
+    }).join('\n');
22 27
 }
23 28
 
29
+/**
30
+ * Generate html select options for available physical devices.
31
+ * @param {{ deviceId, label }[]} items available devices
32
+ * @param {string} [selectedId] id of selected device
33
+ * @returns {string}
34
+ */
24 35
 function generateDevicesOptions(items, selectedId) {
25 36
     return items.map(function (item) {
26 37
         let attrs = {
@@ -39,89 +50,121 @@ function generateDevicesOptions(items, selectedId) {
39 50
 
40 51
 export default {
41 52
     init (emitter) {
42
-        function update() {
43
-            let displayName = $('#setDisplayName').val();
44 53
 
45
-            emitter.emit(UIEvents.NICKNAME_CHANGED, displayName);
46
-
47
-            let language = $("#languages_selectbox").val();
48
-            if (language !== Settings.getLanguage()) {
49
-                emitter.emit(UIEvents.LANG_CHANGED, language);
54
+        // DISPLAY NAME
55
+        function updateDisplayName () {
56
+            emitter.emit(UIEvents.NICKNAME_CHANGED, $('#setDisplayName').val());
57
+        }
58
+        $('#setDisplayName')
59
+            .val(Settings.getDisplayName())
60
+            .keyup(function (event) {
61
+                if (event.keyCode === 13) { // enter
62
+                    updateDisplayName();
63
+                }
64
+            })
65
+            .focusout(updateDisplayName);
66
+
67
+
68
+        // EMAIL
69
+        function updateEmail () {
70
+            emitter.emit(UIEvents.EMAIL_CHANGED, $('#setEmail').val());
71
+        }
72
+        $('#setEmail')
73
+            .val(Settings.getEmail())
74
+            .keyup(function (event) {
75
+            if (event.keyCode === 13) { // enter
76
+                updateEmail();
50 77
             }
78
+        }).focusout(updateEmail);
51 79
 
52
-            let email = UIUtil.escapeHtml($('#setEmail').val());
53
-            if (email !== Settings.getEmail()) {
54
-                emitter.emit(UIEvents.EMAIL_CHANGED, email);
55
-            }
56 80
 
81
+        // START MUTED
82
+        $("#startMutedOptions").change(function () {
57 83
             let startAudioMuted = $("#startAudioMuted").is(":checked");
58 84
             let startVideoMuted = $("#startVideoMuted").is(":checked");
59
-            if (startAudioMuted !== APP.conference.startAudioMuted
60
-                || startVideoMuted !== APP.conference.startVideoMuted) {
61
-                emitter.emit(
62
-                    UIEvents.START_MUTED_CHANGED,
63
-                    startAudioMuted,
64
-                    startVideoMuted
65
-                );
66
-            }
85
+            emitter.emit(
86
+                UIEvents.START_MUTED_CHANGED,
87
+                startAudioMuted,
88
+                startVideoMuted
89
+            );
90
+        });
67 91
 
68
-            let cameraDeviceId = $('#selectCamera').val();
92
+
93
+        // LANGUAGES BOX
94
+        let languagesBox = $("#languages_selectbox");
95
+        languagesBox.html(generateLanguagesOptions(
96
+            languages.getLanguages(),
97
+            APP.translation.getCurrentLanguage()
98
+        ));
99
+        APP.translation.translateElement(languagesBox);
100
+        languagesBox.change(function () {
101
+            emitter.emit(UIEvents.LANG_CHANGED, languagesBox.val());
102
+        });
103
+
104
+
105
+        // DEVICES LIST
106
+        this.changeDevicesList([]);
107
+        $('#selectCamera').change(function () {
108
+            let cameraDeviceId = $(this).val();
69 109
             if (cameraDeviceId !== Settings.getCameraDeviceId()) {
70 110
                 emitter.emit(UIEvents.VIDEO_DEVICE_CHANGED, cameraDeviceId);
71 111
             }
72
-
73
-            let micDeviceId = $('#selectMic').val();
112
+        });
113
+        $('#selectMic').change(function () {
114
+            let micDeviceId = $(this).val();
74 115
             if (micDeviceId !== Settings.getMicDeviceId()) {
75 116
                 emitter.emit(UIEvents.AUDIO_DEVICE_CHANGED, micDeviceId);
76 117
             }
77
-        }
78
-
79
-        let startMutedBlock = $("#startMutedOptions");
80
-        startMutedBlock.before(generateLanguagesSelectBox());
81
-        APP.translation.translateElement($("#languages_selectbox"));
82
-
83
-        this.onAvailableDevicesChanged();
84
-        this.onRoleChanged();
85
-        this.onStartMutedChanged();
86
-
87
-        $("#updateSettings").click(update);
88
-        $('#settingsmenu>input').keyup(function(event){
89
-            if (event.keyCode === 13) {//enter
90
-                update();
91
-            }
92 118
         });
93 119
     },
94 120
 
95
-    onRoleChanged () {
96
-        if(APP.conference.isModerator) {
121
+    /**
122
+     * If start audio muted/start video muted options should be visible or not.
123
+     * @param {boolean} show
124
+     */
125
+    showStartMutedOptions (show) {
126
+        if (show) {
97 127
             $("#startMutedOptions").css("display", "block");
98
-        }
99
-        else {
128
+        } else {
100 129
             $("#startMutedOptions").css("display", "none");
101 130
         }
102 131
     },
103 132
 
104
-    onStartMutedChanged () {
105
-        $("#startAudioMuted").attr("checked", APP.conference.startAudioMuted);
106
-        $("#startVideoMuted").attr("checked", APP.conference.startVideoMuted);
133
+    updateStartMutedBox (startAudioMuted, startVideoMuted) {
134
+        $("#startAudioMuted").attr("checked", startAudioMuted);
135
+        $("#startVideoMuted").attr("checked", startVideoMuted);
107 136
     },
108 137
 
138
+    /**
139
+     * Check if settings menu is visible or not.
140
+     * @returns {boolean}
141
+     */
109 142
     isVisible () {
110 143
         return $('#settingsmenu').is(':visible');
111 144
     },
112 145
 
113
-    onDisplayNameChange (id, newDisplayName) {
114
-        if(id === 'localVideoContainer' || APP.conference.isLocalId(id)) {
115
-            $('#setDisplayName').val(newDisplayName);
116
-        }
146
+    /**
147
+     * Change user display name in the settings menu.
148
+     * @param {string} newDisplayName
149
+     */
150
+    changeDisplayName (newDisplayName) {
151
+        $('#setDisplayName').val(newDisplayName);
117 152
     },
118 153
 
154
+    /**
155
+     * Change user avatar in the settings menu.
156
+     * @param {string} avatarUrl url of the new avatar
157
+     */
119 158
     changeAvatar (avatarUrl) {
120 159
         $('#avatar').attr('src', avatarUrl);
121 160
     },
122 161
 
123
-    onAvailableDevicesChanged () {
124
-        let devices = APP.conference.availableDevices;
162
+    /**
163
+     * Change available cameras/microphones or hide selects completely if
164
+     * no devices available.
165
+     * @param {{ deviceId, label, kind }[]} devices list of available devices
166
+     */
167
+    changeDevicesList (devices) {
125 168
         if (!devices.length) {
126 169
             $('#devicesOptions').hide();
127 170
             return;

+ 2
- 3
modules/settings/Settings.js Просмотреть файл

@@ -30,7 +30,7 @@ if (supportsLocalStorage()) {
30 30
         console.log("generated id", window.localStorage.jitsiMeetId);
31 31
     }
32 32
 
33
-    email = window.localStorage.email || '';
33
+    email = UIUtil.unescapeHtml(window.localStorage.email || '');
34 34
     displayName = UIUtil.unescapeHtml(window.localStorage.displayname || '');
35 35
     language = window.localStorage.language;
36 36
     cameraDeviceId = window.localStorage.cameraDeviceId || '';
@@ -68,8 +68,7 @@ export default {
68 68
      */
69 69
     setEmail: function (newEmail) {
70 70
         email = newEmail;
71
-        window.localStorage.email = newEmail;
72
-        return email;
71
+        window.localStorage.email = UIUtil.escapeHtml(newEmail);
73 72
     },
74 73
 
75 74
     /**

Загрузка…
Отмена
Сохранить