Merge branch 'external_api'

pull/984/head
Lyubomir Marinov 8 years ago
commit 3f0aa500f7
  1. 127
      conference.js
  2. 7
      doc/api.md
  3. 14
      modules/API/API.js
  4. 8
      modules/API/external/external_api.js
  5. 3
      modules/TokenData/TokenData.js

@ -16,7 +16,6 @@ import mediaDeviceHelper from './modules/devices/mediaDeviceHelper';
import {reportError} from './modules/util/helpers'; import {reportError} from './modules/util/helpers';
import UIErrors from './modules/UI/UIErrors';
import UIUtil from './modules/UI/util/UIUtil'; import UIUtil from './modules/UI/util/UIUtil';
const ConnectionErrors = JitsiMeetJS.errors.connection; const ConnectionErrors = JitsiMeetJS.errors.connection;
@ -42,7 +41,7 @@ let DSExternalInstallationInProgress = false;
/** /**
* Listens whether conference had been left from local user when we are trying * Listens whether conference had been left from local user when we are trying
* to navigate away from current page. * to navigate away from current page.
* @type {ConferenceLeftListener} * @type {HangupConferenceLeftListener}
*/ */
let conferenceLeftListener = null; let conferenceLeftListener = null;
@ -220,104 +219,47 @@ function maybeRedirectToWelcomePage(showThankYou) {
}, 3000); }, 3000);
} }
/**
* Executes connection.disconnect and shows the feedback dialog
* @param {boolean} [requestFeedback=false] if user feedback should be requested
* @returns Promise.
*/
function disconnectAndShowFeedback(requestFeedback) {
APP.UI.hideRingOverLay();
connection.disconnect();
APP.API.notifyConferenceLeft(APP.conference.roomName);
if (requestFeedback) {
return APP.UI.requestFeedback();
} else {
return Promise.resolve();
}
}
/** /**
* Disconnect from the conference and optionally request user feedback. * Listens for CONFERENCE_LEFT event after hangup function has been executed.
* @param {boolean} [requestFeedback=false] if user feedback should be requested
*/ */
function hangup (requestFeedback = false) { class HangupConferenceLeftListener {
const errCallback = (err) => {
// If we want to break out the chain in our error handler, it needs
// to return a rejected promise. In the case of feedback request
// in progress it's important to not redirect to the welcome page
// (see below maybeRedirectToWelcomePage call).
if (err === UIErrors.FEEDBACK_REQUEST_IN_PROGRESS) {
return Promise.reject('Feedback request in progress.');
}
else {
console.error('Error occurred during hanging up: ', err);
return Promise.resolve();
}
};
const disconnect = disconnectAndShowFeedback.bind(null, requestFeedback);
if (!conferenceLeftListener)
conferenceLeftListener = new ConferenceLeftListener();
// Make sure that leave is resolved successfully and the set the handlers
// to be invoked once conference had been left
APP.conference._room.leave()
.then(conferenceLeftListener.setHandler(disconnect, errCallback))
.catch(errCallback);
}
/**
* Listens for CONFERENCE_LEFT event so we can check whether it has finished.
* The handler will be called once the conference had been left or if it
* was already left when we are adding the handler.
*/
class ConferenceLeftListener {
/** /**
* Creates ConferenceLeftListener and start listening for conference * Creates HangupConferenceLeftListener and start listening for conference
* failed event. * left event. On CONFERENCE_LEFT event calls should disconnect the user
* and maybe show the feedback dialog.
* @param {boolean} [requestFeedback=false] if user feedback should be
* requested
*/ */
constructor() { constructor(requestFeedback) {
this.requestFeedback = requestFeedback;
room.on(ConferenceEvents.CONFERENCE_LEFT, room.on(ConferenceEvents.CONFERENCE_LEFT,
this._handleConferenceLeft.bind(this)); this._handleConferenceLeft.bind(this));
} }
/** /**
* Handles the conference left event, if we have a handler we invoke it. * Handles the conference left event.
* @private * @private
*/ */
_handleConferenceLeft() { _handleConferenceLeft() {
this.conferenceLeft = true; this._disconnectAndShowFeedback()
.then(() => {
if (this.handler) APP.API.notifyReadyToClose();
this._handleLeave(); maybeRedirectToWelcomePage();
} }).catch(console.log);
/**
* Sets the handlers. If we already left the conference invoke them.
* @param handler
* @param errCallback
*/
setHandler (handler, errCallback) {
this.handler = handler;
this.errCallback = errCallback;
if (this.conferenceLeft)
this._handleLeave();
} }
/** /**
* Invokes the handlers. * Executes connection.disconnect and shows the feedback dialog
* @returns Promise.
* @private * @private
*/ */
_handleLeave() _disconnectAndShowFeedback() {
{ APP.UI.hideRingOverLay();
this.handler() connection.disconnect();
.catch(this.errCallback) APP.API.notifyConferenceLeft(APP.conference.roomName);
.then(maybeRedirectToWelcomePage) return (this.requestFeedback) ?
.catch(function(err){ APP.UI.requestFeedback() : Promise.resolve();
console.log(err);
});
} }
} }
@ -1477,16 +1419,16 @@ export default {
// call hangup // call hangup
APP.UI.addListener(UIEvents.HANGUP, () => { APP.UI.addListener(UIEvents.HANGUP, () => {
hangup(true); this.hangup(true);
}); });
// logout // logout
APP.UI.addListener(UIEvents.LOGOUT, () => { APP.UI.addListener(UIEvents.LOGOUT, () => {
AuthHandler.logout(room).then(function (url) { AuthHandler.logout(room).then(url => {
if (url) { if (url) {
window.location.href = url; window.location.href = url;
} else { } else {
hangup(true); this.hangup(true);
} }
}); });
}); });
@ -1827,5 +1769,20 @@ export default {
if(room) { if(room) {
room.sendApplicationLog(JSON.stringify({name, value})); room.sendApplicationLog(JSON.stringify({name, value}));
} }
},
/**
* Disconnect from the conference and optionally request user feedback.
* @param {boolean} [requestFeedback=false] if user feedback should be
* requested
*/
hangup (requestFeedback = false) {
if (!conferenceLeftListener) {
conferenceLeftListener
= new HangupConferenceLeftListener(requestFeedback);
}
//FIXME: Do something for the use case when we are not receiving
// CONFERENCE_LEFT for some reason
room.leave();
} }
}; };

@ -82,6 +82,11 @@ api.executeCommand('toggleContactList', [])
api.executeCommand('toggleShareScreen', []) api.executeCommand('toggleShareScreen', [])
``` ```
* **hangup** - Hangups the call. No arguments are required.
```
api.executeCommand('hangup', [])
```
You can also execute multiple commands using the method ```executeCommands```. You can also execute multiple commands using the method ```executeCommands```.
``` ```
api.executeCommands(commands) api.executeCommands(commands)
@ -156,6 +161,8 @@ roomName: room //the room name of the conference
} }
``` ```
* **readyToClose** - event notification fired when Jitsi Meet is ready to be closed (hangup operations are completed).
You can also add multiple event listeners by using ```addEventListeners```. You can also add multiple event listeners by using ```addEventListeners```.
This method requires one argument of type Object. The object argument must This method requires one argument of type Object. The object argument must
have keys with the names of the events and values the listeners of the events. have keys with the names of the events and values the listeners of the events.

@ -50,7 +50,8 @@ function initCommands() {
"toggle-film-strip": APP.UI.toggleFilmStrip, "toggle-film-strip": APP.UI.toggleFilmStrip,
"toggle-chat": APP.UI.toggleChat, "toggle-chat": APP.UI.toggleChat,
"toggle-contact-list": APP.UI.toggleContactList, "toggle-contact-list": APP.UI.toggleContactList,
"toggle-share-screen": APP.conference.toggleScreenSharing "toggle-share-screen": APP.conference.toggleScreenSharing,
"video-hangup": () => APP.conference.hangup()
}; };
Object.keys(commands).forEach(function (key) { Object.keys(commands).forEach(function (key) {
postis.listen(key, commands[key]); postis.listen(key, commands[key]);
@ -78,7 +79,8 @@ const events = {
"participant-joined": false, "participant-joined": false,
"participant-left": false, "participant-left": false,
"video-conference-joined": false, "video-conference-joined": false,
"video-conference-left": false "video-conference-left": false,
"video-ready-to-close": false
}; };
/** /**
@ -243,6 +245,14 @@ export default {
triggerEvent("video-conference-left", {roomName: room}); triggerEvent("video-conference-left", {roomName: room});
}, },
/**
* Notify external application (if API is enabled) that
* we are ready to be closed.
*/
notifyReadyToClose () {
triggerEvent("video-ready-to-close", {});
},
/** /**
* Removes the listeners. * Removes the listeners.
*/ */

@ -33,7 +33,8 @@ var commands = {
"toggleFilmStrip": "toggle-film-strip", "toggleFilmStrip": "toggle-film-strip",
"toggleChat": "toggle-chat", "toggleChat": "toggle-chat",
"toggleContactList": "toggle-contact-list", "toggleContactList": "toggle-contact-list",
"toggleShareScreen": "toggle-share-screen" "toggleShareScreen": "toggle-share-screen",
"hangup": "video-hangup"
}; };
/** /**
@ -47,7 +48,8 @@ var events = {
"participantJoined": "participant-joined", "participantJoined": "participant-joined",
"participantLeft": "participant-left", "participantLeft": "participant-left",
"videoConferenceJoined": "video-conference-joined", "videoConferenceJoined": "video-conference-joined",
"videoConferenceLeft": "video-conference-left" "videoConferenceLeft": "video-conference-left",
"readyToClose": "video-ready-to-close"
}; };
/** /**
@ -246,6 +248,8 @@ JitsiMeetExternalAPI.prototype.executeCommands = function(object) {
* {{ * {{
* roomName: room //the room name of the conference * roomName: room //the room name of the conference
* }} * }}
* readyToClose - all hangup operations are completed and Jitsi Meet is ready
* to be disposed.
* @param object * @param object
*/ */
JitsiMeetExternalAPI.prototype.addEventListeners = function(object) { JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {

@ -76,7 +76,8 @@ class TokenData{
//External API settings //External API settings
this.externalAPISettings = { this.externalAPISettings = {
forceEnable: true, forceEnable: true,
enabledEvents: ["video-conference-joined", "video-conference-left"] enabledEvents: ["video-conference-joined", "video-conference-left",
"video-ready-to-close"]
}; };
this._decode(); this._decode();
// Use JWT param as token if there is not other token set and if the // Use JWT param as token if there is not other token set and if the

Loading…
Cancel
Save