浏览代码

feat(iframe_api): Implement readyToClose event and hangup command

master
hristoterezov 9 年前
父节点
当前提交
47d39ed5ca
共有 5 个文件被更改,包括 71 次插入71 次删除
  1. 44
    66
      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

+ 44
- 66
conference.js 查看文件

229
     APP.UI.hideRingOverLay();
229
     APP.UI.hideRingOverLay();
230
     connection.disconnect();
230
     connection.disconnect();
231
     APP.API.notifyConferenceLeft(APP.conference.roomName);
231
     APP.API.notifyConferenceLeft(APP.conference.roomName);
232
-    if (requestFeedback) {
233
-        return APP.UI.requestFeedback();
234
-    } else {
235
-        return Promise.resolve();
236
-    }
237
-}
238
-
239
-/**
240
- * Disconnect from the conference and optionally request user feedback.
241
- * @param {boolean} [requestFeedback=false] if user feedback should be requested
242
- */
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);
232
+    let promise = (requestFeedback?
233
+        APP.UI.requestFeedback(): Promise.resolve());
234
+    promise.then(() => APP.API.notifyReadyToClose());
235
+    return promise;
268
 }
236
 }
269
 
237
 
270
 /**
238
 /**
276
     /**
244
     /**
277
      * Creates ConferenceLeftListener and start listening for conference
245
      * Creates ConferenceLeftListener and start listening for conference
278
      * failed event.
246
      * failed event.
247
+     * @param {Function} handler the function that will be called when
248
+     * CONFERENCE_LEFT event is fired.
249
+     * @param errCallback
279
      */
250
      */
280
-    constructor() {
251
+    constructor(handler) {
252
+        this.handler = handler;
281
         room.on(ConferenceEvents.CONFERENCE_LEFT,
253
         room.on(ConferenceEvents.CONFERENCE_LEFT,
282
             this._handleConferenceLeft.bind(this));
254
             this._handleConferenceLeft.bind(this));
283
     }
255
     }
287
      * @private
259
      * @private
288
      */
260
      */
289
     _handleConferenceLeft() {
261
     _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();
307
-    }
308
-
309
-    /**
310
-     * Invokes the handlers.
311
-     * @private
312
-     */
313
-    _handleLeave()
314
-    {
315
         this.handler()
262
         this.handler()
316
-            .catch(this.errCallback)
317
             .then(maybeRedirectToWelcomePage)
263
             .then(maybeRedirectToWelcomePage)
318
             .catch(function(err){
264
             .catch(function(err){
319
                 console.log(err);
265
                 console.log(err);
1477
 
1423
 
1478
         // call hangup
1424
         // call hangup
1479
         APP.UI.addListener(UIEvents.HANGUP, () => {
1425
         APP.UI.addListener(UIEvents.HANGUP, () => {
1480
-            hangup(true);
1426
+            this.hangup(true);
1481
         });
1427
         });
1482
 
1428
 
1483
         // logout
1429
         // logout
1484
         APP.UI.addListener(UIEvents.LOGOUT, () => {
1430
         APP.UI.addListener(UIEvents.LOGOUT, () => {
1485
-            AuthHandler.logout(room).then(function (url) {
1431
+            AuthHandler.logout(room).then(url => {
1486
                 if (url) {
1432
                 if (url) {
1487
                     window.location.href = url;
1433
                     window.location.href = url;
1488
                 } else {
1434
                 } else {
1489
-                    hangup(true);
1435
+                    this.hangup(true);
1490
                 }
1436
                 }
1491
             });
1437
             });
1492
         });
1438
         });
1827
         if(room) {
1773
         if(room) {
1828
             room.sendApplicationLog(JSON.stringify({name, value}));
1774
             room.sendApplicationLog(JSON.stringify({name, value}));
1829
         }
1775
         }
1776
+    },
1777
+    /**
1778
+     * Disconnect from the conference and optionally request user feedback.
1779
+     * @param {boolean} [requestFeedback=false] if user feedback should be
1780
+     * requested
1781
+     */
1782
+    hangup (requestFeedback = false) {
1783
+        const errCallback = (err) => {
1784
+            // If we want to break out the chain in our error handler, it needs
1785
+            // to return a rejected promise. In the case of feedback request
1786
+            // in progress it's important to not redirect to the welcome page
1787
+            // (see below maybeRedirectToWelcomePage call).
1788
+            if (err === UIErrors.FEEDBACK_REQUEST_IN_PROGRESS) {
1789
+                return Promise.reject('Feedback request in progress.');
1790
+            }
1791
+            else {
1792
+                console.error('Error occurred during hanging up: ', err);
1793
+                return Promise.resolve();
1794
+            }
1795
+        };
1796
+
1797
+        const disconnect = () => {
1798
+            return disconnectAndShowFeedback(requestFeedback)
1799
+                        .catch(errCallback);
1800
+        };
1801
+
1802
+        if (!conferenceLeftListener) {
1803
+            conferenceLeftListener
1804
+                = new ConferenceLeftListener(disconnect, errCallback);
1805
+        }
1806
+
1807
+        room.leave().catch(errCallback);
1830
     }
1808
     }
1831
 };
1809
 };

+ 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

正在加载...
取消
保存