ref(iframe_api): Use ES6
This commit is contained in:
parent
e2e04e3f16
commit
78119df2db
|
@ -1,34 +1,29 @@
|
||||||
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
||||||
|
import postisInit from "postis";
|
||||||
/**
|
|
||||||
* Implements API class that embeds Jitsi Meet in external applications.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var postisInit = require("postis");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum width for the Jitsi Meet frame
|
* The minimum width for the Jitsi Meet frame
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
var MIN_WIDTH = 790;
|
const MIN_WIDTH = 790;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum height for the Jitsi Meet frame
|
* The minimum height for the Jitsi Meet frame
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
var MIN_HEIGHT = 300;
|
const MIN_HEIGHT = 300;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last id of api object
|
* Last id of api object
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
var id = 0;
|
let id = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the names of the commands expected by the API with the name of the
|
* Maps the names of the commands expected by the API with the name of the
|
||||||
* commands expected by jitsi-meet
|
* commands expected by jitsi-meet
|
||||||
*/
|
*/
|
||||||
var commands = {
|
const commands = {
|
||||||
"displayName": "display-name",
|
"displayName": "display-name",
|
||||||
"toggleAudio": "toggle-audio",
|
"toggleAudio": "toggle-audio",
|
||||||
"toggleVideo": "toggle-video",
|
"toggleVideo": "toggle-video",
|
||||||
|
@ -45,7 +40,7 @@ var commands = {
|
||||||
* Maps the names of the events expected by the API with the name of the
|
* Maps the names of the events expected by the API with the name of the
|
||||||
* events expected by jitsi-meet
|
* events expected by jitsi-meet
|
||||||
*/
|
*/
|
||||||
var events = {
|
const events = {
|
||||||
"incomingMessage": "incoming-message",
|
"incomingMessage": "incoming-message",
|
||||||
"outgoingMessage": "outgoing-message",
|
"outgoingMessage": "outgoing-message",
|
||||||
"displayNameChange": "display-name-change",
|
"displayNameChange": "display-name-change",
|
||||||
|
@ -101,6 +96,10 @@ function configToURLParamsArray(config) {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The IFrame API interface class.
|
||||||
|
*/
|
||||||
|
class JitsiMeetExternalAPI {
|
||||||
/**
|
/**
|
||||||
* Constructs new API instance. Creates iframe element that loads
|
* Constructs new API instance. Creates iframe element that loads
|
||||||
* Jitsi Meet.
|
* Jitsi Meet.
|
||||||
|
@ -118,12 +117,14 @@ function configToURLParamsArray(config) {
|
||||||
* authentication.
|
* authentication.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function JitsiMeetExternalAPI(domain, room_name, width, height, parentNode,
|
constructor(domain, room_name, width, height, parentNode,
|
||||||
configOverwrite, interfaceConfigOverwrite, noSsl, jwt) {
|
configOverwrite, interfaceConfigOverwrite, noSsl, jwt) {
|
||||||
if (!width || width < MIN_WIDTH)
|
if (!width || width < MIN_WIDTH) {
|
||||||
width = MIN_WIDTH;
|
width = MIN_WIDTH;
|
||||||
if (!height || height < MIN_HEIGHT)
|
}
|
||||||
|
if (!height || height < MIN_HEIGHT) {
|
||||||
height = MIN_HEIGHT;
|
height = MIN_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
this.parentNode = null;
|
this.parentNode = null;
|
||||||
if (parentNode) {
|
if (parentNode) {
|
||||||
|
@ -136,14 +137,17 @@ function JitsiMeetExternalAPI(domain, room_name, width, height, parentNode,
|
||||||
this.iframeHolder =
|
this.iframeHolder =
|
||||||
this.parentNode.appendChild(document.createElement("div"));
|
this.parentNode.appendChild(document.createElement("div"));
|
||||||
this.iframeHolder.id = "jitsiConference" + id;
|
this.iframeHolder.id = "jitsiConference" + id;
|
||||||
if(width)
|
if (width) {
|
||||||
this.iframeHolder.style.width = width + "px";
|
this.iframeHolder.style.width = width + "px";
|
||||||
if(height)
|
}
|
||||||
|
if (height) {
|
||||||
this.iframeHolder.style.height = height + "px";
|
this.iframeHolder.style.height = height + "px";
|
||||||
|
}
|
||||||
this.frameName = "jitsiConferenceFrame" + id;
|
this.frameName = "jitsiConferenceFrame" + id;
|
||||||
this.url = (noSsl) ? "http" : "https" +"://" + domain + "/";
|
this.url = (noSsl) ? "http" : "https" +"://" + domain + "/";
|
||||||
if(room_name)
|
if (room_name) {
|
||||||
this.url += room_name;
|
this.url += room_name;
|
||||||
|
}
|
||||||
|
|
||||||
if (jwt) {
|
if (jwt) {
|
||||||
this.url += '?jwt=' + jwt;
|
this.url += '?jwt=' + jwt;
|
||||||
|
@ -199,14 +203,16 @@ function JitsiMeetExternalAPI(domain, room_name, width, height, parentNode,
|
||||||
* @param name the name of the command
|
* @param name the name of the command
|
||||||
* @param arguments array of arguments
|
* @param arguments array of arguments
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype.executeCommand
|
executeCommand(name, ...argumentsList) {
|
||||||
= function(name, ...argumentsList) {
|
|
||||||
if(!(name in commands)) {
|
if(!(name in commands)) {
|
||||||
logger.error("Not supported command name.");
|
logger.error("Not supported command name.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendMessage(this.postis, {method: commands[name], params: argumentsList});
|
sendMessage(this.postis, {
|
||||||
};
|
method: commands[name],
|
||||||
|
params: argumentsList
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes commands. The available commands are:
|
* Executes commands. The available commands are:
|
||||||
|
@ -222,10 +228,11 @@ JitsiMeetExternalAPI.prototype.executeCommand
|
||||||
* object are the commands that will be executed and the values are the
|
* object are the commands that will be executed and the values are the
|
||||||
* arguments for the command.
|
* arguments for the command.
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype.executeCommands = function(object) {
|
executeCommands(object) {
|
||||||
for(var key in object)
|
for (var key in object) {
|
||||||
this.executeCommand(key, object[key]);
|
this.executeCommand(key, object[key]);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds event listeners to Meet Jitsi. The object key should be the name of
|
* Adds event listeners to Meet Jitsi. The object key should be the name of
|
||||||
|
@ -261,8 +268,8 @@ JitsiMeetExternalAPI.prototype.executeCommands = function(object) {
|
||||||
* {{
|
* {{
|
||||||
* jid: jid //the jid of the participant
|
* jid: jid //the jid of the participant
|
||||||
* }}
|
* }}
|
||||||
* video-conference-joined - receives event notifications about the local user
|
* video-conference-joined - receives event notifications about the local
|
||||||
* has successfully joined the video conference.
|
* user has successfully joined the video conference.
|
||||||
* The listener will receive object with the following structure:
|
* The listener will receive object with the following structure:
|
||||||
* {{
|
* {{
|
||||||
* roomName: room //the room name of the conference
|
* roomName: room //the room name of the conference
|
||||||
|
@ -273,14 +280,15 @@ 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
|
* readyToClose - all hangup operations are completed and Jitsi Meet is
|
||||||
* to be disposed.
|
* ready to be disposed.
|
||||||
* @param object
|
* @param object
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {
|
addEventListeners(object) {
|
||||||
for(var i in object)
|
for (var i in object) {
|
||||||
this.addEventListener(i, object[i]);
|
this.addEventListener(i, object[i]);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds event listeners to Meet Jitsi. Currently we support the following
|
* Adds event listeners to Meet Jitsi. Currently we support the following
|
||||||
|
@ -314,8 +322,8 @@ JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {
|
||||||
* {{
|
* {{
|
||||||
* jid: jid //the jid of the participant
|
* jid: jid //the jid of the participant
|
||||||
* }}
|
* }}
|
||||||
* video-conference-joined - receives event notifications fired when the local
|
* video-conference-joined - receives event notifications fired when the
|
||||||
* user has joined the video conference.
|
* local user has joined the video conference.
|
||||||
* The listener will receive object with the following structure:
|
* The listener will receive object with the following structure:
|
||||||
* {{
|
* {{
|
||||||
* roomName: room //the room name of the conference
|
* roomName: room //the room name of the conference
|
||||||
|
@ -329,7 +337,7 @@ JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {
|
||||||
* @param event the name of the event
|
* @param event the name of the event
|
||||||
* @param listener the listener
|
* @param listener the listener
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype.addEventListener = function(event, listener) {
|
addEventListener(event, listener) {
|
||||||
if (!(event in events)) {
|
if (!(event in events)) {
|
||||||
logger.error("Not supported event name.");
|
logger.error("Not supported event name.");
|
||||||
return;
|
return;
|
||||||
|
@ -337,70 +345,71 @@ JitsiMeetExternalAPI.prototype.addEventListener = function(event, listener) {
|
||||||
// We cannot remove listeners from postis that's why we are handling the
|
// We cannot remove listeners from postis that's why we are handling the
|
||||||
// callback that way.
|
// callback that way.
|
||||||
if (!this.postisListeners[event]) {
|
if (!this.postisListeners[event]) {
|
||||||
this.postis.listen(events[event], function(data) {
|
this.postis.listen(events[event], data => {
|
||||||
if((event in this.eventHandlers) &&
|
if((event in this.eventHandlers) &&
|
||||||
typeof this.eventHandlers[event] === "function")
|
typeof this.eventHandlers[event] === "function")
|
||||||
this.eventHandlers[event].call(null, data);
|
this.eventHandlers[event].call(null, data);
|
||||||
}.bind(this));
|
});
|
||||||
this.postisListeners[event] = true;
|
this.postisListeners[event] = true;
|
||||||
}
|
}
|
||||||
this.eventHandlers[event] = listener;
|
this.eventHandlers[event] = listener;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes event listener.
|
* Removes event listener.
|
||||||
* @param event the name of the event.
|
* @param event the name of the event.
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype.removeEventListener = function(event) {
|
removeEventListener(event) {
|
||||||
if(!(event in this.eventHandlers))
|
if(!(event in this.eventHandlers))
|
||||||
{
|
{
|
||||||
logger.error("The event " + event + " is not registered.");
|
logger.error("The event " + event + " is not registered.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete this.eventHandlers[event];
|
delete this.eventHandlers[event];
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes event listeners.
|
* Removes event listeners.
|
||||||
* @param events array with the names of the events.
|
* @param events array with the names of the events.
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype.removeEventListeners = function(events) {
|
removeEventListeners(events) {
|
||||||
for(var i = 0; i < events.length; i++)
|
for(var i = 0; i < events.length; i++) {
|
||||||
this.removeEventListener(events[i]);
|
this.removeEventListener(events[i]);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of participants in the conference.
|
* Returns the number of participants in the conference.
|
||||||
* NOTE: the local participant is included.
|
* NOTE: the local participant is included.
|
||||||
* @returns {int} the number of participants in the conference.
|
* @returns {int} the number of participants in the conference.
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype.getNumberOfParticipants = function() {
|
getNumberOfParticipants() {
|
||||||
return this.numberOfParticipants;
|
return this.numberOfParticipants;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setups listeners that are used internally for JitsiMeetExternalAPI.
|
* Setups listeners that are used internally for JitsiMeetExternalAPI.
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype._setupListeners = function() {
|
_setupListeners() {
|
||||||
this.postis.listen("participant-joined",
|
this.postis.listen("participant-joined",
|
||||||
changeParticipantNumber.bind(null, this, 1));
|
changeParticipantNumber.bind(null, this, 1));
|
||||||
this.postis.listen("participant-left",
|
this.postis.listen("participant-left",
|
||||||
changeParticipantNumber.bind(null, this, -1));
|
changeParticipantNumber.bind(null, this, -1));
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the listeners and removes the Jitsi Meet frame.
|
* Removes the listeners and removes the Jitsi Meet frame.
|
||||||
*/
|
*/
|
||||||
JitsiMeetExternalAPI.prototype.dispose = function() {
|
dispose() {
|
||||||
this.postis.destroy();
|
this.postis.destroy();
|
||||||
var frame = document.getElementById(this.frameName);
|
var frame = document.getElementById(this.frameName);
|
||||||
if(frame)
|
if(frame)
|
||||||
frame.src = 'about:blank';
|
frame.src = 'about:blank';
|
||||||
var self = this;
|
window.setTimeout( () => {
|
||||||
window.setTimeout(function () {
|
this.iframeHolder.removeChild(this.frame);
|
||||||
self.iframeHolder.removeChild(self.frame);
|
this.iframeHolder.parentNode.removeChild(this.iframeHolder);
|
||||||
self.iframeHolder.parentNode.removeChild(self.iframeHolder);
|
|
||||||
}, 10);
|
}, 10);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = JitsiMeetExternalAPI;
|
module.exports = JitsiMeetExternalAPI;
|
||||||
|
|
Loading…
Reference in New Issue