Przeglądaj źródła

feat(iframe_api): Implement readyToClose event and hangup command

j8
hristoterezov 8 lat temu
rodzic
commit
47d39ed5ca

+ 44
- 66
conference.js Wyświetl plik

@@ -229,42 +229,10 @@ function disconnectAndShowFeedback(requestFeedback) {
229 229
     APP.UI.hideRingOverLay();
230 230
     connection.disconnect();
231 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,8 +244,12 @@ class ConferenceLeftListener {
276 244
     /**
277 245
      * Creates ConferenceLeftListener and start listening for conference
278 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 253
         room.on(ConferenceEvents.CONFERENCE_LEFT,
282 254
             this._handleConferenceLeft.bind(this));
283 255
     }
@@ -287,33 +259,7 @@ class ConferenceLeftListener {
287 259
      * @private
288 260
      */
289 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 262
         this.handler()
316
-            .catch(this.errCallback)
317 263
             .then(maybeRedirectToWelcomePage)
318 264
             .catch(function(err){
319 265
                 console.log(err);
@@ -1477,16 +1423,16 @@ export default {
1477 1423
 
1478 1424
         // call hangup
1479 1425
         APP.UI.addListener(UIEvents.HANGUP, () => {
1480
-            hangup(true);
1426
+            this.hangup(true);
1481 1427
         });
1482 1428
 
1483 1429
         // logout
1484 1430
         APP.UI.addListener(UIEvents.LOGOUT, () => {
1485
-            AuthHandler.logout(room).then(function (url) {
1431
+            AuthHandler.logout(room).then(url => {
1486 1432
                 if (url) {
1487 1433
                     window.location.href = url;
1488 1434
                 } else {
1489
-                    hangup(true);
1435
+                    this.hangup(true);
1490 1436
                 }
1491 1437
             });
1492 1438
         });
@@ -1827,5 +1773,37 @@ export default {
1827 1773
         if(room) {
1828 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 Wyświetl plik

@@ -82,6 +82,11 @@ api.executeCommand('toggleContactList', [])
82 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 90
 You can also execute multiple commands using the method ```executeCommands```.
86 91
 ```
87 92
 api.executeCommands(commands)
@@ -156,6 +161,8 @@ roomName: room //the room name of the conference
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 166
 You can also add multiple event listeners by using ```addEventListeners```.
160 167
 This method requires one argument of type Object. The object argument must
161 168
 have keys with the names of the events and values the listeners of the events.

+ 12
- 2
modules/API/API.js Wyświetl plik

@@ -50,7 +50,8 @@ function initCommands() {
50 50
         "toggle-film-strip": APP.UI.toggleFilmStrip,
51 51
         "toggle-chat": APP.UI.toggleChat,
52 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 56
     Object.keys(commands).forEach(function (key) {
56 57
         postis.listen(key, commands[key]);
@@ -78,7 +79,8 @@ const events = {
78 79
     "participant-joined": false,
79 80
     "participant-left": false,
80 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,6 +245,14 @@ export default {
243 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 257
      * Removes the listeners.
248 258
      */

+ 6
- 2
modules/API/external/external_api.js Wyświetl plik

@@ -33,7 +33,8 @@ var commands = {
33 33
     "toggleFilmStrip": "toggle-film-strip",
34 34
     "toggleChat": "toggle-chat",
35 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,7 +48,8 @@ var events = {
47 48
     "participantJoined": "participant-joined",
48 49
     "participantLeft": "participant-left",
49 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,6 +248,8 @@ JitsiMeetExternalAPI.prototype.executeCommands = function(object) {
246 248
  * {{
247 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 253
  * @param object
250 254
  */
251 255
 JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {

+ 2
- 1
modules/TokenData/TokenData.js Wyświetl plik

@@ -76,7 +76,8 @@ class TokenData{
76 76
         //External API settings
77 77
         this.externalAPISettings = {
78 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 82
         this._decode();
82 83
         // Use JWT param as token if there is not other token set and if the

Ładowanie…
Anuluj
Zapisz