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 UIErrors from './modules/UI/UIErrors';
import UIUtil from './modules/UI/util/UIUtil';
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
* to navigate away from current page.
* @type {ConferenceLeftListener}
* @type {HangupConferenceLeftListener}
*/
let conferenceLeftListener = null;
@ -220,104 +219,47 @@ function maybeRedirectToWelcomePage(showThankYou) {
}, 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.
* @param {boolean} [requestFeedback=false] if user feedback should be requested
* Listens for CONFERENCE_LEFT event after hangup function has been executed.
*/
function hangup (requestFeedback = false) {
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 {
class HangupConferenceLeftListener {
/**
* Creates ConferenceLeftListener and start listening for conference
* failed event.
* Creates HangupConferenceLeftListener and start listening for conference
* 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,
this._handleConferenceLeft.bind(this));
}
/**
* Handles the conference left event, if we have a handler we invoke it.
* Handles the conference left event.
* @private
*/
_handleConferenceLeft() {
this.conferenceLeft = true;
if (this.handler)
this._handleLeave();
}
/**
* 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();
this._disconnectAndShowFeedback()
.then(() => {
APP.API.notifyReadyToClose();
maybeRedirectToWelcomePage();
}).catch(console.log);
}
/**
* Invokes the handlers.
* Executes connection.disconnect and shows the feedback dialog
* @returns Promise.
* @private
*/
_handleLeave()
{
this.handler()
.catch(this.errCallback)
.then(maybeRedirectToWelcomePage)
.catch(function(err){
console.log(err);
});
_disconnectAndShowFeedback() {
APP.UI.hideRingOverLay();
connection.disconnect();
APP.API.notifyConferenceLeft(APP.conference.roomName);
return (this.requestFeedback) ?
APP.UI.requestFeedback() : Promise.resolve();
}
}
@ -1477,16 +1419,16 @@ export default {
// call hangup
APP.UI.addListener(UIEvents.HANGUP, () => {
hangup(true);
this.hangup(true);
});
// logout
APP.UI.addListener(UIEvents.LOGOUT, () => {
AuthHandler.logout(room).then(function (url) {
AuthHandler.logout(room).then(url => {
if (url) {
window.location.href = url;
} else {
hangup(true);
this.hangup(true);
}
});
});
@ -1827,5 +1769,20 @@ export default {
if(room) {
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', [])
```
* **hangup** - Hangups the call. No arguments are required.
```
api.executeCommand('hangup', [])
```
You can also execute multiple commands using the method ```executeCommands```.
```
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```.
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.

@ -50,7 +50,8 @@ function initCommands() {
"toggle-film-strip": APP.UI.toggleFilmStrip,
"toggle-chat": APP.UI.toggleChat,
"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) {
postis.listen(key, commands[key]);
@ -78,7 +79,8 @@ const events = {
"participant-joined": false,
"participant-left": 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});
},
/**
* Notify external application (if API is enabled) that
* we are ready to be closed.
*/
notifyReadyToClose () {
triggerEvent("video-ready-to-close", {});
},
/**
* Removes the listeners.
*/

@ -33,7 +33,8 @@ var commands = {
"toggleFilmStrip": "toggle-film-strip",
"toggleChat": "toggle-chat",
"toggleContactList": "toggle-contact-list",
"toggleShareScreen": "toggle-share-screen"
"toggleShareScreen": "toggle-share-screen",
"hangup": "video-hangup"
};
/**
@ -47,7 +48,8 @@ var events = {
"participantJoined": "participant-joined",
"participantLeft": "participant-left",
"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
* }}
* readyToClose - all hangup operations are completed and Jitsi Meet is ready
* to be disposed.
* @param object
*/
JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {

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

Loading…
Cancel
Save