ソースを参照

Merge branch 'external_api'

j8
Lyubomir Marinov 8年前
コミット
3f0aa500f7
5個のファイルの変更69行の追加90行の削除
  1. 42
    85
      conference.js
  2. 7
    0
      doc/api.md
  3. 12
    2
      modules/API/API.js
  4. 6
    2
      modules/API/external/external_api.js
  5. 2
    1
      modules/TokenData/TokenData.js

+ 42
- 85
conference.js ファイルの表示

16
 
16
 
17
 import {reportError} from './modules/util/helpers';
17
 import {reportError} from './modules/util/helpers';
18
 
18
 
19
-import UIErrors from './modules/UI/UIErrors';
20
 import UIUtil from './modules/UI/util/UIUtil';
19
 import UIUtil from './modules/UI/util/UIUtil';
21
 
20
 
22
 const ConnectionErrors = JitsiMeetJS.errors.connection;
21
 const ConnectionErrors = JitsiMeetJS.errors.connection;
42
 /**
41
 /**
43
  * Listens whether conference had been left from local user when we are trying
42
  * Listens whether conference had been left from local user when we are trying
44
  * to navigate away from current page.
43
  * to navigate away from current page.
45
- * @type {ConferenceLeftListener}
44
+ * @type {HangupConferenceLeftListener}
46
  */
45
  */
47
 let conferenceLeftListener = null;
46
 let conferenceLeftListener = null;
48
 
47
 
220
     }, 3000);
219
     }, 3000);
221
 }
220
 }
222
 
221
 
223
-/**
224
- * Executes connection.disconnect and shows the feedback dialog
225
- * @param {boolean} [requestFeedback=false] if user feedback should be requested
226
- * @returns Promise.
227
- */
228
-function disconnectAndShowFeedback(requestFeedback) {
229
-    APP.UI.hideRingOverLay();
230
-    connection.disconnect();
231
-    APP.API.notifyConferenceLeft(APP.conference.roomName);
232
-    if (requestFeedback) {
233
-        return APP.UI.requestFeedback();
234
-    } else {
235
-        return Promise.resolve();
236
-    }
237
-}
238
 
222
 
239
 /**
223
 /**
240
- * Disconnect from the conference and optionally request user feedback.
241
- * @param {boolean} [requestFeedback=false] if user feedback should be requested
224
+ * Listens for CONFERENCE_LEFT event after hangup function has been executed.
242
  */
225
  */
243
-function hangup (requestFeedback = false) {
244
-    const errCallback = (err) => {
245
-
246
-        // If we want to break out the chain in our error handler, it needs
247
-        // to return a rejected promise. In the case of feedback request
248
-        // in progress it's important to not redirect to the welcome page
249
-        // (see below maybeRedirectToWelcomePage call).
250
-        if (err === UIErrors.FEEDBACK_REQUEST_IN_PROGRESS) {
251
-            return Promise.reject('Feedback request in progress.');
252
-        }
253
-        else {
254
-            console.error('Error occurred during hanging up: ', err);
255
-            return Promise.resolve();
256
-        }
257
-    };
258
-    const disconnect = disconnectAndShowFeedback.bind(null, requestFeedback);
259
-
260
-    if (!conferenceLeftListener)
261
-        conferenceLeftListener = new ConferenceLeftListener();
262
-
263
-    // Make sure that leave is resolved successfully and the set the handlers
264
-    // to be invoked once conference had been left
265
-    APP.conference._room.leave()
266
-        .then(conferenceLeftListener.setHandler(disconnect, errCallback))
267
-        .catch(errCallback);
268
-}
269
-
270
-/**
271
- * Listens for CONFERENCE_LEFT event so we can check whether it has finished.
272
- * The handler will be called once the conference had been left or if it
273
- * was already left when we are adding the handler.
274
- */
275
-class ConferenceLeftListener {
226
+class HangupConferenceLeftListener {
276
     /**
227
     /**
277
-     * Creates ConferenceLeftListener and start listening for conference
278
-     * failed event.
228
+     * Creates HangupConferenceLeftListener and start listening for conference
229
+     * left event. On CONFERENCE_LEFT event calls should disconnect the user
230
+     * and maybe show the feedback dialog.
231
+     * @param {boolean} [requestFeedback=false] if user feedback should be
232
+     * requested
279
      */
233
      */
280
-    constructor() {
234
+    constructor(requestFeedback) {
235
+        this.requestFeedback = requestFeedback;
281
         room.on(ConferenceEvents.CONFERENCE_LEFT,
236
         room.on(ConferenceEvents.CONFERENCE_LEFT,
282
             this._handleConferenceLeft.bind(this));
237
             this._handleConferenceLeft.bind(this));
283
     }
238
     }
284
 
239
 
285
     /**
240
     /**
286
-     * Handles the conference left event, if we have a handler we invoke it.
241
+     * Handles the conference left event.
287
      * @private
242
      * @private
288
      */
243
      */
289
     _handleConferenceLeft() {
244
     _handleConferenceLeft() {
290
-        this.conferenceLeft = true;
291
-
292
-        if (this.handler)
293
-            this._handleLeave();
294
-    }
295
-
296
-    /**
297
-     * Sets the handlers. If we already left the conference invoke them.
298
-     * @param handler
299
-     * @param errCallback
300
-     */
301
-    setHandler (handler, errCallback) {
302
-        this.handler = handler;
303
-        this.errCallback = errCallback;
304
-
305
-        if (this.conferenceLeft)
306
-            this._handleLeave();
245
+        this._disconnectAndShowFeedback()
246
+            .then(() => {
247
+                APP.API.notifyReadyToClose();
248
+                maybeRedirectToWelcomePage();
249
+            }).catch(console.log);
307
     }
250
     }
308
 
251
 
309
     /**
252
     /**
310
-     * Invokes the handlers.
253
+     * Executes connection.disconnect and shows the feedback dialog
254
+     * @returns Promise.
311
      * @private
255
      * @private
312
      */
256
      */
313
-    _handleLeave()
314
-    {
315
-        this.handler()
316
-            .catch(this.errCallback)
317
-            .then(maybeRedirectToWelcomePage)
318
-            .catch(function(err){
319
-                console.log(err);
320
-            });
257
+    _disconnectAndShowFeedback() {
258
+        APP.UI.hideRingOverLay();
259
+        connection.disconnect();
260
+        APP.API.notifyConferenceLeft(APP.conference.roomName);
261
+        return (this.requestFeedback) ?
262
+            APP.UI.requestFeedback() : Promise.resolve();
321
     }
263
     }
322
 }
264
 }
323
 
265
 
1477
 
1419
 
1478
         // call hangup
1420
         // call hangup
1479
         APP.UI.addListener(UIEvents.HANGUP, () => {
1421
         APP.UI.addListener(UIEvents.HANGUP, () => {
1480
-            hangup(true);
1422
+            this.hangup(true);
1481
         });
1423
         });
1482
 
1424
 
1483
         // logout
1425
         // logout
1484
         APP.UI.addListener(UIEvents.LOGOUT, () => {
1426
         APP.UI.addListener(UIEvents.LOGOUT, () => {
1485
-            AuthHandler.logout(room).then(function (url) {
1427
+            AuthHandler.logout(room).then(url => {
1486
                 if (url) {
1428
                 if (url) {
1487
                     window.location.href = url;
1429
                     window.location.href = url;
1488
                 } else {
1430
                 } else {
1489
-                    hangup(true);
1431
+                    this.hangup(true);
1490
                 }
1432
                 }
1491
             });
1433
             });
1492
         });
1434
         });
1827
         if(room) {
1769
         if(room) {
1828
             room.sendApplicationLog(JSON.stringify({name, value}));
1770
             room.sendApplicationLog(JSON.stringify({name, value}));
1829
         }
1771
         }
1772
+    },
1773
+    /**
1774
+     * Disconnect from the conference and optionally request user feedback.
1775
+     * @param {boolean} [requestFeedback=false] if user feedback should be
1776
+     * requested
1777
+     */
1778
+    hangup (requestFeedback = false) {
1779
+        if (!conferenceLeftListener) {
1780
+            conferenceLeftListener
1781
+                = new HangupConferenceLeftListener(requestFeedback);
1782
+        }
1783
+
1784
+        //FIXME: Do something for the use case when we are not receiving
1785
+        // CONFERENCE_LEFT for some reason
1786
+        room.leave();
1830
     }
1787
     }
1831
 };
1788
 };

+ 7
- 0
doc/api.md ファイルの表示

82
 api.executeCommand('toggleShareScreen', [])
82
 api.executeCommand('toggleShareScreen', [])
83
 ```
83
 ```
84
 
84
 
85
+* **hangup** - Hangups the call. No arguments are required.
86
+```
87
+api.executeCommand('hangup', [])
88
+```
89
+
85
 You can also execute multiple commands using the method ```executeCommands```.
90
 You can also execute multiple commands using the method ```executeCommands```.
86
 ```
91
 ```
87
 api.executeCommands(commands)
92
 api.executeCommands(commands)
156
 }
161
 }
157
 ```
162
 ```
158
 
163
 
164
+* **readyToClose** - event notification fired when Jitsi Meet is ready to be closed (hangup operations are completed).
165
+
159
 You can also add multiple event listeners by using ```addEventListeners```.
166
 You can also add multiple event listeners by using ```addEventListeners```.
160
 This method requires one argument of type Object. The object argument must
167
 This method requires one argument of type Object. The object argument must
161
 have keys with the names of the events and values the listeners of the events.
168
 have keys with the names of the events and values the listeners of the events.

+ 12
- 2
modules/API/API.js ファイルの表示

50
         "toggle-film-strip": APP.UI.toggleFilmStrip,
50
         "toggle-film-strip": APP.UI.toggleFilmStrip,
51
         "toggle-chat": APP.UI.toggleChat,
51
         "toggle-chat": APP.UI.toggleChat,
52
         "toggle-contact-list": APP.UI.toggleContactList,
52
         "toggle-contact-list": APP.UI.toggleContactList,
53
-        "toggle-share-screen": APP.conference.toggleScreenSharing
53
+        "toggle-share-screen": APP.conference.toggleScreenSharing,
54
+        "video-hangup": () => APP.conference.hangup()
54
     };
55
     };
55
     Object.keys(commands).forEach(function (key) {
56
     Object.keys(commands).forEach(function (key) {
56
         postis.listen(key, commands[key]);
57
         postis.listen(key, commands[key]);
78
     "participant-joined": false,
79
     "participant-joined": false,
79
     "participant-left": false,
80
     "participant-left": false,
80
     "video-conference-joined": false,
81
     "video-conference-joined": false,
81
-    "video-conference-left": false
82
+    "video-conference-left": false,
83
+    "video-ready-to-close": false
82
 };
84
 };
83
 
85
 
84
 /**
86
 /**
243
         triggerEvent("video-conference-left", {roomName: room});
245
         triggerEvent("video-conference-left", {roomName: room});
244
     },
246
     },
245
 
247
 
248
+    /**
249
+     * Notify external application (if API is enabled) that
250
+     * we are ready to be closed.
251
+     */
252
+    notifyReadyToClose () {
253
+        triggerEvent("video-ready-to-close", {});
254
+    },
255
+
246
     /**
256
     /**
247
      * Removes the listeners.
257
      * Removes the listeners.
248
      */
258
      */

+ 6
- 2
modules/API/external/external_api.js ファイルの表示

33
     "toggleFilmStrip": "toggle-film-strip",
33
     "toggleFilmStrip": "toggle-film-strip",
34
     "toggleChat": "toggle-chat",
34
     "toggleChat": "toggle-chat",
35
     "toggleContactList": "toggle-contact-list",
35
     "toggleContactList": "toggle-contact-list",
36
-    "toggleShareScreen": "toggle-share-screen"
36
+    "toggleShareScreen": "toggle-share-screen",
37
+    "hangup": "video-hangup"
37
 };
38
 };
38
 
39
 
39
 /**
40
 /**
47
     "participantJoined": "participant-joined",
48
     "participantJoined": "participant-joined",
48
     "participantLeft": "participant-left",
49
     "participantLeft": "participant-left",
49
     "videoConferenceJoined": "video-conference-joined",
50
     "videoConferenceJoined": "video-conference-joined",
50
-    "videoConferenceLeft": "video-conference-left"
51
+    "videoConferenceLeft": "video-conference-left",
52
+    "readyToClose": "video-ready-to-close"
51
 };
53
 };
52
 
54
 
53
 /**
55
 /**
246
  * {{
248
  * {{
247
  * roomName: room //the room name of the conference
249
  * roomName: room //the room name of the conference
248
  * }}
250
  * }}
251
+ * readyToClose - all hangup operations are completed and Jitsi Meet is ready
252
+ * to be disposed.
249
  * @param object
253
  * @param object
250
  */
254
  */
251
 JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {
255
 JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {

+ 2
- 1
modules/TokenData/TokenData.js ファイルの表示

76
         //External API settings
76
         //External API settings
77
         this.externalAPISettings = {
77
         this.externalAPISettings = {
78
             forceEnable: true,
78
             forceEnable: true,
79
-            enabledEvents: ["video-conference-joined", "video-conference-left"]
79
+            enabledEvents: ["video-conference-joined", "video-conference-left",
80
+                "video-ready-to-close"]
80
         };
81
         };
81
         this._decode();
82
         this._decode();
82
         // Use JWT param as token if there is not other token set and if the
83
         // Use JWT param as token if there is not other token set and if the

読み込み中…
キャンセル
保存