Bladeren bron

Comply w/ coding style

j8
Lyubo Marinov 8 jaren geleden
bovenliggende
commit
f4de65a647
1 gewijzigde bestanden met toevoegingen van 84 en 91 verwijderingen
  1. 84
    91
      modules/API/API.js

+ 84
- 91
modules/API/API.js Bestand weergeven

@@ -6,57 +6,33 @@ import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
6 6
 
7 7
 /**
8 8
  * List of the available commands.
9
- * @type {{
10
- *     displayName: inputDisplayNameHandler,
11
- *     toggleAudio: toggleAudio,
12
- *     toggleVideo: toggleVideo,
13
- *     toggleFilmStrip: toggleFilmStrip,
14
- *     toggleChat: toggleChat,
15
- *     toggleContactList: toggleContactList
16
- * }}
17 9
  */
18 10
 let commands = {};
19 11
 
20
-const hashParams = getConfigParamsFromUrl();
21
-
22 12
 /**
23
- * JitsiMeetExternalAPI id - unique for a webpage.
13
+ * The state of screen sharing(started/stopped) before the screen sharing is
14
+ * enabled and initialized.
15
+ * NOTE: This flag help us to cache the state and use it if toggle-share-screen
16
+ * was received before the initialization.
24 17
  */
25
-const jitsiMeetExternalApiId = hashParams.jitsi_meet_external_api_id;
18
+let initialScreenSharingState = false;
26 19
 
27 20
 /**
28
- * Object that will execute sendMessage
21
+ * JitsiMeetExternalAPI id - unique for a webpage.
29 22
  */
30
-const target = window.opener ? window.opener : window.parent;
23
+const jitsiMeetExternalApiId
24
+    = getConfigParamsFromUrl().jitsi_meet_external_api_id;
31 25
 
32 26
 /**
33
- * Postis instance. Used to communicate with the external application.
27
+ * Postis instance. Used to communicate with the external application. If
28
+ * undefined, then API is disabled.
34 29
  */
35 30
 let postis;
36 31
 
37 32
 /**
38
- * Current status (enabled/disabled) of API.
33
+ * Object that will execute sendMessage.
39 34
  */
40
-let enabled = false;
41
-
42
-/**
43
- * The state of screen sharing(started/stopped) before the screen sharing is
44
- * enabled and initialized.
45
- * NOTE: This flag help us to cache the state and use it if toggle-share-screen
46
- * was received before the initialization.
47
- */
48
-let initialScreenSharingState = false;
49
-
50
-/**
51
- * Executes on toggle-share-screen command.
52
- */
53
-function toggleScreenSharing() {
54
-    if(!APP.conference.isDesktopSharingEnabled) {
55
-        initialScreenSharingState = !initialScreenSharingState;
56
-    } else {
57
-        APP.conference.toggleScreenSharing();
58
-    }
59
-}
35
+const target = window.opener || window.parent;
60 36
 
61 37
 /**
62 38
  * Initializes supported commands.
@@ -83,6 +59,19 @@ function initCommands() {
83 59
         key => postis.listen(key, args => commands[key](...args)));
84 60
 }
85 61
 
62
+/**
63
+ * Listens for desktop/screen sharing enabled events and toggles the screen
64
+ * sharing if needed.
65
+ *
66
+ * @param {boolean} enabled - Current screen sharing enabled status.
67
+ * @returns {void}
68
+ */
69
+function onDesktopSharingEnabledChanged(enabled = false) {
70
+    if (enabled && initialScreenSharingState) {
71
+        toggleScreenSharing();
72
+    }
73
+}
74
+
86 75
 /**
87 76
  * Sends message to the external application.
88 77
  *
@@ -90,7 +79,7 @@ function initCommands() {
90 79
  * @returns {void}
91 80
  */
92 81
 function sendMessage(message) {
93
-    if (enabled) {
82
+    if (postis) {
94 83
         postis.send(message);
95 84
     }
96 85
 }
@@ -105,48 +94,47 @@ function shouldBeEnabled() {
105 94
 }
106 95
 
107 96
 /**
108
- * Sends event object to the external application that has been subscribed
109
- * for that event.
97
+ * Executes on toggle-share-screen command.
110 98
  *
111
- * @param {string} name - The name event.
112
- * @param {Object} object - Data associated with the event.
113 99
  * @returns {void}
114 100
  */
115
-function triggerEvent(name, object) {
116
-    if (enabled) {
117
-        sendMessage({ method: name,
118
-            params: object });
101
+function toggleScreenSharing() {
102
+    if (APP.conference.isDesktopSharingEnabled) {
103
+        APP.conference.toggleScreenSharing();
104
+    } else {
105
+        initialScreenSharingState = !initialScreenSharingState;
119 106
     }
120 107
 }
121 108
 
122 109
 /**
123
- * Listens for screen sharing enabled events and toggles the screen sharing if
124
- * needed.
110
+ * Sends event object to the external application that has been subscribed for
111
+ * that event.
125 112
  *
126
- * @param {boolean} enabled - Current screen sharing enabled status.
113
+ * @param {string} name - The name event.
114
+ * @param {Object} object - Data associated with the event.
127 115
  * @returns {void}
128 116
  */
129
-function onScreenSharingEnable(enabled = false) {
130
-    if(enabled && initialScreenSharingState) {
131
-        toggleScreenSharing();
132
-    }
117
+function triggerEvent(name, object) {
118
+    sendMessage({
119
+        method: name,
120
+        params: object
121
+    });
133 122
 }
134 123
 
135 124
 /**
136
- * Implements API class that communicates with external api class
137
- * and provides interface to access Jitsi Meet features by external
138
- * applications that embed Jitsi Meet
125
+ * Implements API class that communicates with external API class and provides
126
+ * interface to access Jitsi Meet features by external applications that embed
127
+ * Jitsi Meet.
139 128
  */
140 129
 class API {
141 130
     /**
142
-     * Initializes the APIConnector. Setups message event listeners that will
143
-     * receive information from external applications that embed Jitsi Meet.
144
-     * It also sends a message to the external application that APIConnector
145
-     * is initialized.
131
+     * Initializes the API. Setups message event listeners that will receive
132
+     * information from external applications that embed Jitsi Meet. It also
133
+     * sends a message to the external application that API is initialized.
146 134
      *
147 135
      * @param {Object} options - Optional parameters.
148
-     * @param {boolean} options.forceEnable - If true the module will be
149
-     * enabled.
136
+     * @param {boolean} options.forceEnable - True to forcefully enable the
137
+     * module.
150 138
      * @returns {void}
151 139
      */
152 140
     init(options = {}) {
@@ -154,14 +142,10 @@ class API {
154 142
             return;
155 143
         }
156 144
 
157
-        if(!enabled) {
145
+        if (!postis) {
158 146
             APP.conference.addListener(
159 147
                 JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
160
-                onScreenSharingEnable);
161
-            enabled = true;
162
-        }
163
-
164
-        if (!postis) {
148
+                onDesktopSharingEnabledChanged);
165 149
             this._initPostis();
166 150
         }
167 151
     }
@@ -197,8 +181,8 @@ class API {
197 181
     }
198 182
 
199 183
     /**
200
-     * Notify external application (if API is enabled) that
201
-     * message was received.
184
+     * Notify external application (if API is enabled) that message was
185
+     * received.
202 186
      *
203 187
      * @param {Object} options - Object with the message properties.
204 188
      * @returns {void}
@@ -212,16 +196,17 @@ class API {
212 196
 
213 197
         triggerEvent(
214 198
             'incoming-message',
215
-            { 'from': id,
216
-                'nick': nick,
199
+            {
200
+                'from': id,
217 201
                 'message': body,
218
-                'stamp': ts }
219
-        );
202
+                'nick': nick,
203
+                'stamp': ts
204
+            });
220 205
     }
221 206
 
222 207
     /**
223
-     * Notify external application (if API is enabled) that
224
-     * user joined the conference.
208
+     * Notify external application (if API is enabled) that user joined the
209
+     * conference.
225 210
      *
226 211
      * @param {string} id - User id.
227 212
      * @returns {void}
@@ -231,8 +216,8 @@ class API {
231 216
     }
232 217
 
233 218
     /**
234
-     * Notify external application (if API is enabled) that
235
-     * user left the conference.
219
+     * Notify external application (if API is enabled) that user left the
220
+     * conference.
236 221
      *
237 222
      * @param {string} id - User id.
238 223
      * @returns {void}
@@ -242,21 +227,25 @@ class API {
242 227
     }
243 228
 
244 229
     /**
245
-     * Notify external application (if API is enabled) that
246
-     * user changed their nickname.
230
+     * Notify external application (if API is enabled) that user changed their
231
+     * nickname.
247 232
      *
248 233
      * @param {string} id - User id.
249 234
      * @param {string} displayName - User nickname.
250 235
      * @returns {void}
251 236
      */
252 237
     notifyDisplayNameChanged(id, displayName) {
253
-        triggerEvent('display-name-change', { id,
254
-            displayname: displayName });
238
+        triggerEvent(
239
+            'display-name-change',
240
+            {
241
+                displayname: displayName,
242
+                id
243
+            });
255 244
     }
256 245
 
257 246
     /**
258
-     * Notify external application (if API is enabled) that
259
-     * the conference has been joined.
247
+     * Notify external application (if API is enabled) that the conference has
248
+     * been joined.
260 249
      *
261 250
      * @param {string} room - The room name.
262 251
      * @returns {void}
@@ -266,8 +255,8 @@ class API {
266 255
     }
267 256
 
268 257
     /**
269
-     * Notify external application (if API is enabled) that
270
-     * user changed their nickname.
258
+     * Notify external application (if API is enabled) that user changed their
259
+     * nickname.
271 260
      *
272 261
      * @param {string} room - User id.
273 262
      * @param {string} displayName - User nickname.
@@ -278,8 +267,8 @@ class API {
278 267
     }
279 268
 
280 269
     /**
281
-     * Notify external application (if API is enabled) that
282
-     * we are ready to be closed.
270
+     * Notify external application (if API is enabled) that we are ready to be
271
+     * closed.
283 272
      *
284 273
      * @returns {void}
285 274
      */
@@ -294,8 +283,10 @@ class API {
294 283
      * @returns {void}
295 284
      */
296 285
     sendRemoteControlEvent(event) {
297
-        sendMessage({ method: 'remote-control-event',
298
-            params: event });
286
+        sendMessage({
287
+            method: 'remote-control-event',
288
+            params: event
289
+        });
299 290
     }
300 291
 
301 292
     /**
@@ -304,11 +295,13 @@ class API {
304 295
      * @returns {void}
305 296
      */
306 297
     dispose() {
307
-        if (enabled) {
298
+        if (postis) {
308 299
             postis.destroy();
300
+            postis = undefined;
301
+
309 302
             APP.conference.removeListener(
310 303
                 JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
311
-                onScreenSharingEnable);
304
+                onDesktopSharingEnabledChanged);
312 305
         }
313 306
     }
314 307
 }

Laden…
Annuleren
Opslaan