Explorar el Código

ref(iframe_api): ESLint support for API.js

master
hristoterezov hace 8 años
padre
commit
0f42f18100
Se han modificado 4 ficheros con 136 adiciones y 98 borrados
  1. 8
    3
      conference.js
  2. 3
    0
      modules/API/.eslintrc.js
  3. 125
    92
      modules/API/API.js
  4. 0
    3
      modules/API/external/.eslintrc.js

+ 8
- 3
conference.js Ver fichero

1360
             room.on(ConferenceEvents.CONNECTION_RESTORED, () => {
1360
             room.on(ConferenceEvents.CONNECTION_RESTORED, () => {
1361
                 APP.UI.markVideoInterrupted(false);
1361
                 APP.UI.markVideoInterrupted(false);
1362
             });
1362
             });
1363
-            room.on(ConferenceEvents.MESSAGE_RECEIVED, (id, text, ts) => {
1363
+            room.on(ConferenceEvents.MESSAGE_RECEIVED, (id, body, ts) => {
1364
                 let nick = getDisplayName(id);
1364
                 let nick = getDisplayName(id);
1365
-                APP.API.notifyReceivedChatMessage(id, nick, text, ts);
1366
-                APP.UI.addMessage(id, nick, text, ts);
1365
+                APP.API.notifyReceivedChatMessage({
1366
+                    id,
1367
+                    nick,
1368
+                    body,
1369
+                    ts
1370
+                });
1371
+                APP.UI.addMessage(id, nick, body, ts);
1367
             });
1372
             });
1368
             APP.UI.addListener(UIEvents.MESSAGE_CREATED, (message) => {
1373
             APP.UI.addListener(UIEvents.MESSAGE_CREATED, (message) => {
1369
                 APP.API.notifySendingChatMessage(message);
1374
                 APP.API.notifySendingChatMessage(message);

+ 3
- 0
modules/API/.eslintrc.js Ver fichero

1
+module.exports = {
2
+    'extends': '../../react/.eslintrc.js'
3
+};

+ 125
- 92
modules/API/API.js Ver fichero

1
 /* global APP, getConfigParamsFromUrl */
1
 /* global APP, getConfigParamsFromUrl */
2
 
2
 
3
-/**
4
- * Implements API class that communicates with external api class
5
- * and provides interface to access Jitsi Meet features by external
6
- * applications that embed Jitsi Meet
7
- */
8
-
9
 import postisInit from 'postis';
3
 import postisInit from 'postis';
10
 
4
 
11
 import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
5
 import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
13
 /**
7
 /**
14
  * List of the available commands.
8
  * List of the available commands.
15
  * @type {{
9
  * @type {{
16
- *              displayName: inputDisplayNameHandler,
17
- *              toggleAudio: toggleAudio,
18
- *              toggleVideo: toggleVideo,
19
- *              toggleFilmStrip: toggleFilmStrip,
20
- *              toggleChat: toggleChat,
21
- *              toggleContactList: toggleContactList
22
- *          }}
10
+ *     displayName: inputDisplayNameHandler,
11
+ *     toggleAudio: toggleAudio,
12
+ *     toggleVideo: toggleVideo,
13
+ *     toggleFilmStrip: toggleFilmStrip,
14
+ *     toggleChat: toggleChat,
15
+ *     toggleContactList: toggleContactList
16
+ * }}
23
  */
17
  */
24
 let commands = {};
18
 let commands = {};
25
 
19
 
26
-let hashParams = getConfigParamsFromUrl();
20
+const hashParams = getConfigParamsFromUrl();
27
 
21
 
28
 /**
22
 /**
29
  * JitsiMeetExternalAPI id - unique for a webpage.
23
  * JitsiMeetExternalAPI id - unique for a webpage.
30
  */
24
  */
31
-let jitsi_meet_external_api_id = hashParams.jitsi_meet_external_api_id;
25
+const jitsiMeetExternalApiId = hashParams.jitsi_meet_external_api_id;
32
 
26
 
33
 /**
27
 /**
34
  * Object that will execute sendMessage
28
  * Object that will execute sendMessage
35
  */
29
  */
36
-let target = window.opener ? window.opener : window.parent;
30
+const target = window.opener ? window.opener : window.parent;
37
 
31
 
38
 /**
32
 /**
39
  * Postis instance. Used to communicate with the external application.
33
  * Postis instance. Used to communicate with the external application.
64
     }
58
     }
65
 }
59
 }
66
 
60
 
61
+/**
62
+ * Initializes supported commands.
63
+ *
64
+ * @returns {void}
65
+ */
67
 function initCommands() {
66
 function initCommands() {
68
     commands = {
67
     commands = {
69
-        "display-name":
68
+        'display-name':
70
             APP.conference.changeLocalDisplayName.bind(APP.conference),
69
             APP.conference.changeLocalDisplayName.bind(APP.conference),
71
-        "toggle-audio": APP.conference.toggleAudioMuted.bind(APP.conference),
72
-        "toggle-video": APP.conference.toggleVideoMuted.bind(APP.conference),
73
-        "toggle-film-strip": APP.UI.toggleFilmstrip,
74
-        "toggle-chat": APP.UI.toggleChat,
75
-        "toggle-contact-list": APP.UI.toggleContactList,
76
-        "toggle-share-screen": toggleScreenSharing,
77
-        "video-hangup": () => APP.conference.hangup(),
78
-        "email": APP.conference.changeLocalEmail,
79
-        "avatar-url": APP.conference.changeLocalAvatarUrl,
80
-        "remote-control-event": event =>
81
-            APP.remoteControl.onRemoteControlAPIEvent(event)
70
+        'toggle-audio': APP.conference.toggleAudioMuted.bind(APP.conference),
71
+        'toggle-video': APP.conference.toggleVideoMuted.bind(APP.conference),
72
+        'toggle-film-strip': APP.UI.toggleFilmstrip,
73
+        'toggle-chat': APP.UI.toggleChat,
74
+        'toggle-contact-list': APP.UI.toggleContactList,
75
+        'toggle-share-screen': toggleScreenSharing,
76
+        'video-hangup': () => APP.conference.hangup(),
77
+        'email': APP.conference.changeLocalEmail,
78
+        'avatar-url': APP.conference.changeLocalAvatarUrl,
79
+        'remote-control-event':
80
+            event => APP.remoteControl.onRemoteControlAPIEvent(event)
82
     };
81
     };
83
-    Object.keys(commands).forEach(function (key) {
84
-        postis.listen(key, args => commands[key](...args));
85
-    });
82
+    Object.keys(commands).forEach(
83
+        key => postis.listen(key, args => commands[key](...args)));
86
 }
84
 }
87
 
85
 
88
 /**
86
 /**
89
  * Sends message to the external application.
87
  * Sends message to the external application.
90
- * @param message {object}
91
- * @param method {string}
92
- * @param params {object} the object that will be sent as JSON string
88
+ *
89
+ * @param {Object} message - The message to be sent.
90
+ * @returns {void}
93
  */
91
  */
94
 function sendMessage(message) {
92
 function sendMessage(message) {
95
-    if(enabled) {
93
+    if (enabled) {
96
         postis.send(message);
94
         postis.send(message);
97
     }
95
     }
98
 }
96
 }
99
 
97
 
100
 /**
98
 /**
101
  * Check whether the API should be enabled or not.
99
  * Check whether the API should be enabled or not.
100
+ *
102
  * @returns {boolean}
101
  * @returns {boolean}
103
  */
102
  */
104
-function shouldBeEnabled () {
105
-    return (typeof jitsi_meet_external_api_id === "number");
103
+function shouldBeEnabled() {
104
+    return typeof jitsiMeetExternalApiId === 'number';
106
 }
105
 }
107
 
106
 
108
 /**
107
 /**
109
  * Sends event object to the external application that has been subscribed
108
  * Sends event object to the external application that has been subscribed
110
  * for that event.
109
  * for that event.
111
- * @param name the name event
112
- * @param object data associated with the event
110
+ *
111
+ * @param {string} name - The name event.
112
+ * @param {Object} object - Data associated with the event.
113
+ * @returns {void}
113
  */
114
  */
114
-function triggerEvent (name, object) {
115
-    if(enabled) {
116
-        sendMessage({method: name, params: object});
115
+function triggerEvent(name, object) {
116
+    if (enabled) {
117
+        sendMessage({ method: name,
118
+            params: object });
117
     }
119
     }
118
 }
120
 }
119
 
121
 
130
     }
132
     }
131
 }
133
 }
132
 
134
 
135
+/**
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
139
+ */
133
 class API {
140
 class API {
134
-    /**
135
-     * Constructs new instance
136
-     * @constructor
137
-     */
138
-    constructor() { }
139
-
140
     /**
141
     /**
141
      * Initializes the APIConnector. Setups message event listeners that will
142
      * Initializes the APIConnector. Setups message event listeners that will
142
      * receive information from external applications that embed Jitsi Meet.
143
      * receive information from external applications that embed Jitsi Meet.
143
      * It also sends a message to the external application that APIConnector
144
      * It also sends a message to the external application that APIConnector
144
      * is initialized.
145
      * is initialized.
145
-     * @param options {object}
146
-     * @param forceEnable {boolean} if true the module will be enabled.
146
+     *
147
+     * @param {Object} options - Optional parameters.
148
+     * @param {boolean} options.forceEnable - If true the module will be
149
+     * enabled.
150
+     * @returns {void}
147
      */
151
      */
148
-    init (options = {}) {
149
-        if(!shouldBeEnabled() && !options.forceEnable)
152
+    init(options = {}) {
153
+        if (!shouldBeEnabled() && !options.forceEnable) {
150
             return;
154
             return;
155
+        }
151
 
156
 
152
         if(!enabled) {
157
         if(!enabled) {
153
             APP.conference.addListener(
158
             APP.conference.addListener(
156
             enabled = true;
161
             enabled = true;
157
         }
162
         }
158
 
163
 
159
-        if(!postis) {
164
+        if (!postis) {
160
             this._initPostis();
165
             this._initPostis();
161
         }
166
         }
162
     }
167
     }
163
 
168
 
164
     /**
169
     /**
165
-     * initializes postis library.
170
+     * Initializes postis library.
171
+     *
172
+     * @returns {void}
173
+     *
166
      * @private
174
      * @private
167
      */
175
      */
168
     _initPostis() {
176
     _initPostis() {
169
-        let postisOptions = {
177
+        const postisOptions = {
170
             window: target
178
             window: target
171
         };
179
         };
172
-        if(typeof jitsi_meet_external_api_id === "number")
180
+
181
+        if (typeof jitsiMeetExternalApiId === 'number') {
173
             postisOptions.scope
182
             postisOptions.scope
174
-                = "jitsi_meet_external_api_" + jitsi_meet_external_api_id;
183
+                = `jitsi_meet_external_api_${jitsiMeetExternalApiId}`;
184
+        }
175
         postis = postisInit(postisOptions);
185
         postis = postisInit(postisOptions);
176
         initCommands();
186
         initCommands();
177
     }
187
     }
178
 
188
 
179
     /**
189
     /**
180
      * Notify external application (if API is enabled) that message was sent.
190
      * Notify external application (if API is enabled) that message was sent.
181
-     * @param {string} body message body
191
+     *
192
+     * @param {string} body - Message body.
193
+     * @returns {void}
182
      */
194
      */
183
-    notifySendingChatMessage (body) {
184
-        triggerEvent("outgoing-message", {"message": body});
195
+    notifySendingChatMessage(body) {
196
+        triggerEvent('outgoing-message', { 'message': body });
185
     }
197
     }
186
 
198
 
187
     /**
199
     /**
188
      * Notify external application (if API is enabled) that
200
      * Notify external application (if API is enabled) that
189
      * message was received.
201
      * message was received.
190
-     * @param {string} id user id
191
-     * @param {string} nick user nickname
192
-     * @param {string} body message body
193
-     * @param {number} ts message creation timestamp
202
+     *
203
+     * @param {Object} options - Object with the message properties.
204
+     * @returns {void}
194
      */
205
      */
195
-    notifyReceivedChatMessage (id, nick, body, ts) {
206
+    notifyReceivedChatMessage(options = {}) {
207
+        const { id, nick, body, ts } = options;
208
+
196
         if (APP.conference.isLocalId(id)) {
209
         if (APP.conference.isLocalId(id)) {
197
             return;
210
             return;
198
         }
211
         }
199
 
212
 
200
         triggerEvent(
213
         triggerEvent(
201
-            "incoming-message",
202
-            {"from": id, "nick": nick, "message": body, "stamp": ts}
214
+            'incoming-message',
215
+            { 'from': id,
216
+                'nick': nick,
217
+                'message': body,
218
+                'stamp': ts }
203
         );
219
         );
204
     }
220
     }
205
 
221
 
206
     /**
222
     /**
207
      * Notify external application (if API is enabled) that
223
      * Notify external application (if API is enabled) that
208
      * user joined the conference.
224
      * user joined the conference.
209
-     * @param {string} id user id
225
+     *
226
+     * @param {string} id - User id.
227
+     * @returns {void}
210
      */
228
      */
211
-    notifyUserJoined (id) {
212
-        triggerEvent("participant-joined", {id});
229
+    notifyUserJoined(id) {
230
+        triggerEvent('participant-joined', { id });
213
     }
231
     }
214
 
232
 
215
     /**
233
     /**
216
      * Notify external application (if API is enabled) that
234
      * Notify external application (if API is enabled) that
217
      * user left the conference.
235
      * user left the conference.
218
-     * @param {string} id user id
236
+     *
237
+     * @param {string} id - User id.
238
+     * @returns {void}
219
      */
239
      */
220
-    notifyUserLeft (id) {
221
-        triggerEvent("participant-left", {id});
240
+    notifyUserLeft(id) {
241
+        triggerEvent('participant-left', { id });
222
     }
242
     }
223
 
243
 
224
     /**
244
     /**
225
      * Notify external application (if API is enabled) that
245
      * Notify external application (if API is enabled) that
226
      * user changed their nickname.
246
      * user changed their nickname.
227
-     * @param {string} id user id
228
-     * @param {string} displayName user nickname
247
+     *
248
+     * @param {string} id - User id.
249
+     * @param {string} displayName - User nickname.
250
+     * @returns {void}
229
      */
251
      */
230
-    notifyDisplayNameChanged (id, displayName) {
231
-        triggerEvent("display-name-change", {id, displayname: displayName});
252
+    notifyDisplayNameChanged(id, displayName) {
253
+        triggerEvent('display-name-change', { id,
254
+            displayname: displayName });
232
     }
255
     }
233
 
256
 
234
     /**
257
     /**
235
      * Notify external application (if API is enabled) that
258
      * Notify external application (if API is enabled) that
236
-     * user changed their nickname.
237
-     * @param {string} id user id
238
-     * @param {string} displayName user nickname
259
+     * the conference has been joined.
260
+     *
261
+     * @param {string} room - The room name.
262
+     * @returns {void}
239
      */
263
      */
240
-    notifyConferenceJoined (room) {
241
-        triggerEvent("video-conference-joined", {roomName: room});
264
+    notifyConferenceJoined(room) {
265
+        triggerEvent('video-conference-joined', { roomName: room });
242
     }
266
     }
243
 
267
 
244
     /**
268
     /**
245
      * Notify external application (if API is enabled) that
269
      * Notify external application (if API is enabled) that
246
      * user changed their nickname.
270
      * user changed their nickname.
247
-     * @param {string} id user id
248
-     * @param {string} displayName user nickname
271
+     *
272
+     * @param {string} room - User id.
273
+     * @param {string} displayName - User nickname.
274
+     * @returns {void}
249
      */
275
      */
250
-    notifyConferenceLeft (room) {
251
-        triggerEvent("video-conference-left", {roomName: room});
276
+    notifyConferenceLeft(room) {
277
+        triggerEvent('video-conference-left', { roomName: room });
252
     }
278
     }
253
 
279
 
254
     /**
280
     /**
255
      * Notify external application (if API is enabled) that
281
      * Notify external application (if API is enabled) that
256
      * we are ready to be closed.
282
      * we are ready to be closed.
283
+     *
284
+     * @returns {void}
257
      */
285
      */
258
-    notifyReadyToClose () {
259
-        triggerEvent("video-ready-to-close", {});
286
+    notifyReadyToClose() {
287
+        triggerEvent('video-ready-to-close', {});
260
     }
288
     }
261
 
289
 
262
     /**
290
     /**
263
      * Sends remote control event.
291
      * Sends remote control event.
264
-     * @param {RemoteControlEvent} event the remote control event.
292
+     *
293
+     * @param {RemoteControlEvent} event - The remote control event.
294
+     * @returns {void}
265
      */
295
      */
266
     sendRemoteControlEvent(event) {
296
     sendRemoteControlEvent(event) {
267
-        sendMessage({method: "remote-control-event", params: event});
297
+        sendMessage({ method: 'remote-control-event',
298
+            params: event });
268
     }
299
     }
269
 
300
 
270
     /**
301
     /**
271
      * Removes the listeners.
302
      * Removes the listeners.
303
+     *
304
+     * @returns {void}
272
      */
305
      */
273
-    dispose () {
274
-        if(enabled) {
306
+    dispose() {
307
+        if (enabled) {
275
             postis.destroy();
308
             postis.destroy();
276
             APP.conference.removeListener(
309
             APP.conference.removeListener(
277
                 JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
310
                 JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,

+ 0
- 3
modules/API/external/.eslintrc.js Ver fichero

1
-module.exports = {
2
-    'extends': '../../../react/.eslintrc.js'
3
-};

Loading…
Cancelar
Guardar