ref(iframe_api): ESLint support for API.js
This commit is contained in:
parent
e7a3ee477d
commit
0f42f18100
|
@ -1360,10 +1360,15 @@ export default {
|
||||||
room.on(ConferenceEvents.CONNECTION_RESTORED, () => {
|
room.on(ConferenceEvents.CONNECTION_RESTORED, () => {
|
||||||
APP.UI.markVideoInterrupted(false);
|
APP.UI.markVideoInterrupted(false);
|
||||||
});
|
});
|
||||||
room.on(ConferenceEvents.MESSAGE_RECEIVED, (id, text, ts) => {
|
room.on(ConferenceEvents.MESSAGE_RECEIVED, (id, body, ts) => {
|
||||||
let nick = getDisplayName(id);
|
let nick = getDisplayName(id);
|
||||||
APP.API.notifyReceivedChatMessage(id, nick, text, ts);
|
APP.API.notifyReceivedChatMessage({
|
||||||
APP.UI.addMessage(id, nick, text, ts);
|
id,
|
||||||
|
nick,
|
||||||
|
body,
|
||||||
|
ts
|
||||||
|
});
|
||||||
|
APP.UI.addMessage(id, nick, body, ts);
|
||||||
});
|
});
|
||||||
APP.UI.addListener(UIEvents.MESSAGE_CREATED, (message) => {
|
APP.UI.addListener(UIEvents.MESSAGE_CREATED, (message) => {
|
||||||
APP.API.notifySendingChatMessage(message);
|
APP.API.notifySendingChatMessage(message);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
'extends': '../../react/.eslintrc.js'
|
||||||
|
};
|
|
@ -1,11 +1,5 @@
|
||||||
/* global APP, getConfigParamsFromUrl */
|
/* global APP, getConfigParamsFromUrl */
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements API class that communicates with external api class
|
|
||||||
* and provides interface to access Jitsi Meet features by external
|
|
||||||
* applications that embed Jitsi Meet
|
|
||||||
*/
|
|
||||||
|
|
||||||
import postisInit from 'postis';
|
import postisInit from 'postis';
|
||||||
|
|
||||||
import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
|
import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
|
||||||
|
@ -13,27 +7,27 @@ import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
|
||||||
/**
|
/**
|
||||||
* List of the available commands.
|
* List of the available commands.
|
||||||
* @type {{
|
* @type {{
|
||||||
* displayName: inputDisplayNameHandler,
|
* displayName: inputDisplayNameHandler,
|
||||||
* toggleAudio: toggleAudio,
|
* toggleAudio: toggleAudio,
|
||||||
* toggleVideo: toggleVideo,
|
* toggleVideo: toggleVideo,
|
||||||
* toggleFilmStrip: toggleFilmStrip,
|
* toggleFilmStrip: toggleFilmStrip,
|
||||||
* toggleChat: toggleChat,
|
* toggleChat: toggleChat,
|
||||||
* toggleContactList: toggleContactList
|
* toggleContactList: toggleContactList
|
||||||
* }}
|
* }}
|
||||||
*/
|
*/
|
||||||
let commands = {};
|
let commands = {};
|
||||||
|
|
||||||
let hashParams = getConfigParamsFromUrl();
|
const hashParams = getConfigParamsFromUrl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JitsiMeetExternalAPI id - unique for a webpage.
|
* JitsiMeetExternalAPI id - unique for a webpage.
|
||||||
*/
|
*/
|
||||||
let jitsi_meet_external_api_id = hashParams.jitsi_meet_external_api_id;
|
const jitsiMeetExternalApiId = hashParams.jitsi_meet_external_api_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object that will execute sendMessage
|
* Object that will execute sendMessage
|
||||||
*/
|
*/
|
||||||
let target = window.opener ? window.opener : window.parent;
|
const target = window.opener ? window.opener : window.parent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Postis instance. Used to communicate with the external application.
|
* Postis instance. Used to communicate with the external application.
|
||||||
|
@ -64,56 +58,64 @@ function toggleScreenSharing() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes supported commands.
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
function initCommands() {
|
function initCommands() {
|
||||||
commands = {
|
commands = {
|
||||||
"display-name":
|
'display-name':
|
||||||
APP.conference.changeLocalDisplayName.bind(APP.conference),
|
APP.conference.changeLocalDisplayName.bind(APP.conference),
|
||||||
"toggle-audio": APP.conference.toggleAudioMuted.bind(APP.conference),
|
'toggle-audio': APP.conference.toggleAudioMuted.bind(APP.conference),
|
||||||
"toggle-video": APP.conference.toggleVideoMuted.bind(APP.conference),
|
'toggle-video': APP.conference.toggleVideoMuted.bind(APP.conference),
|
||||||
"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": toggleScreenSharing,
|
'toggle-share-screen': toggleScreenSharing,
|
||||||
"video-hangup": () => APP.conference.hangup(),
|
'video-hangup': () => APP.conference.hangup(),
|
||||||
"email": APP.conference.changeLocalEmail,
|
'email': APP.conference.changeLocalEmail,
|
||||||
"avatar-url": APP.conference.changeLocalAvatarUrl,
|
'avatar-url': APP.conference.changeLocalAvatarUrl,
|
||||||
"remote-control-event": event =>
|
'remote-control-event':
|
||||||
APP.remoteControl.onRemoteControlAPIEvent(event)
|
event => APP.remoteControl.onRemoteControlAPIEvent(event)
|
||||||
};
|
};
|
||||||
Object.keys(commands).forEach(function (key) {
|
Object.keys(commands).forEach(
|
||||||
postis.listen(key, args => commands[key](...args));
|
key => postis.listen(key, args => commands[key](...args)));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends message to the external application.
|
* Sends message to the external application.
|
||||||
* @param message {object}
|
*
|
||||||
* @param method {string}
|
* @param {Object} message - The message to be sent.
|
||||||
* @param params {object} the object that will be sent as JSON string
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function sendMessage(message) {
|
function sendMessage(message) {
|
||||||
if(enabled) {
|
if (enabled) {
|
||||||
postis.send(message);
|
postis.send(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the API should be enabled or not.
|
* Check whether the API should be enabled or not.
|
||||||
|
*
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function shouldBeEnabled () {
|
function shouldBeEnabled() {
|
||||||
return (typeof jitsi_meet_external_api_id === "number");
|
return typeof jitsiMeetExternalApiId === 'number';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends event object to the external application that has been subscribed
|
* Sends event object to the external application that has been subscribed
|
||||||
* for that event.
|
* for that event.
|
||||||
* @param name the name event
|
*
|
||||||
* @param object data associated with the event
|
* @param {string} name - The name event.
|
||||||
|
* @param {Object} object - Data associated with the event.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function triggerEvent (name, object) {
|
function triggerEvent(name, object) {
|
||||||
if(enabled) {
|
if (enabled) {
|
||||||
sendMessage({method: name, params: object});
|
sendMessage({ method: name,
|
||||||
|
params: object });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,24 +132,27 @@ function onScreenSharingEnable(enabled = false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements API class that communicates with external api class
|
||||||
|
* and provides interface to access Jitsi Meet features by external
|
||||||
|
* applications that embed Jitsi Meet
|
||||||
|
*/
|
||||||
class API {
|
class API {
|
||||||
/**
|
|
||||||
* Constructs new instance
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
constructor() { }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the APIConnector. Setups message event listeners that will
|
* Initializes the APIConnector. Setups message event listeners that will
|
||||||
* receive information from external applications that embed Jitsi Meet.
|
* receive information from external applications that embed Jitsi Meet.
|
||||||
* It also sends a message to the external application that APIConnector
|
* It also sends a message to the external application that APIConnector
|
||||||
* is initialized.
|
* is initialized.
|
||||||
* @param options {object}
|
*
|
||||||
* @param forceEnable {boolean} if true the module will be enabled.
|
* @param {Object} options - Optional parameters.
|
||||||
|
* @param {boolean} options.forceEnable - If true the module will be
|
||||||
|
* enabled.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
init (options = {}) {
|
init(options = {}) {
|
||||||
if(!shouldBeEnabled() && !options.forceEnable)
|
if (!shouldBeEnabled() && !options.forceEnable) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(!enabled) {
|
if(!enabled) {
|
||||||
APP.conference.addListener(
|
APP.conference.addListener(
|
||||||
|
@ -156,122 +161,150 @@ class API {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!postis) {
|
if (!postis) {
|
||||||
this._initPostis();
|
this._initPostis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initializes postis library.
|
* Initializes postis library.
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_initPostis() {
|
_initPostis() {
|
||||||
let postisOptions = {
|
const postisOptions = {
|
||||||
window: target
|
window: target
|
||||||
};
|
};
|
||||||
if(typeof jitsi_meet_external_api_id === "number")
|
|
||||||
|
if (typeof jitsiMeetExternalApiId === 'number') {
|
||||||
postisOptions.scope
|
postisOptions.scope
|
||||||
= "jitsi_meet_external_api_" + jitsi_meet_external_api_id;
|
= `jitsi_meet_external_api_${jitsiMeetExternalApiId}`;
|
||||||
|
}
|
||||||
postis = postisInit(postisOptions);
|
postis = postisInit(postisOptions);
|
||||||
initCommands();
|
initCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that message was sent.
|
* Notify external application (if API is enabled) that message was sent.
|
||||||
* @param {string} body message body
|
*
|
||||||
|
* @param {string} body - Message body.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
notifySendingChatMessage (body) {
|
notifySendingChatMessage(body) {
|
||||||
triggerEvent("outgoing-message", {"message": body});
|
triggerEvent('outgoing-message', { 'message': body });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that
|
||||||
* message was received.
|
* message was received.
|
||||||
* @param {string} id user id
|
*
|
||||||
* @param {string} nick user nickname
|
* @param {Object} options - Object with the message properties.
|
||||||
* @param {string} body message body
|
* @returns {void}
|
||||||
* @param {number} ts message creation timestamp
|
|
||||||
*/
|
*/
|
||||||
notifyReceivedChatMessage (id, nick, body, ts) {
|
notifyReceivedChatMessage(options = {}) {
|
||||||
|
const { id, nick, body, ts } = options;
|
||||||
|
|
||||||
if (APP.conference.isLocalId(id)) {
|
if (APP.conference.isLocalId(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerEvent(
|
triggerEvent(
|
||||||
"incoming-message",
|
'incoming-message',
|
||||||
{"from": id, "nick": nick, "message": body, "stamp": ts}
|
{ 'from': id,
|
||||||
|
'nick': nick,
|
||||||
|
'message': body,
|
||||||
|
'stamp': ts }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that
|
||||||
* user joined the conference.
|
* user joined the conference.
|
||||||
* @param {string} id user id
|
*
|
||||||
|
* @param {string} id - User id.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
notifyUserJoined (id) {
|
notifyUserJoined(id) {
|
||||||
triggerEvent("participant-joined", {id});
|
triggerEvent('participant-joined', { id });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that
|
||||||
* user left the conference.
|
* user left the conference.
|
||||||
* @param {string} id user id
|
*
|
||||||
|
* @param {string} id - User id.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
notifyUserLeft (id) {
|
notifyUserLeft(id) {
|
||||||
triggerEvent("participant-left", {id});
|
triggerEvent('participant-left', { id });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that
|
||||||
* user changed their nickname.
|
* user changed their nickname.
|
||||||
* @param {string} id user id
|
*
|
||||||
* @param {string} displayName user nickname
|
* @param {string} id - User id.
|
||||||
|
* @param {string} displayName - User nickname.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
notifyDisplayNameChanged (id, displayName) {
|
notifyDisplayNameChanged(id, displayName) {
|
||||||
triggerEvent("display-name-change", {id, displayname: displayName});
|
triggerEvent('display-name-change', { id,
|
||||||
|
displayname: displayName });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify external application (if API is enabled) that
|
||||||
|
* the conference has been joined.
|
||||||
|
*
|
||||||
|
* @param {string} room - The room name.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
notifyConferenceJoined(room) {
|
||||||
|
triggerEvent('video-conference-joined', { roomName: room });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that
|
||||||
* user changed their nickname.
|
* user changed their nickname.
|
||||||
* @param {string} id user id
|
*
|
||||||
* @param {string} displayName user nickname
|
* @param {string} room - User id.
|
||||||
|
* @param {string} displayName - User nickname.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
notifyConferenceJoined (room) {
|
notifyConferenceLeft(room) {
|
||||||
triggerEvent("video-conference-joined", {roomName: room});
|
triggerEvent('video-conference-left', { roomName: room });
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify external application (if API is enabled) that
|
|
||||||
* user changed their nickname.
|
|
||||||
* @param {string} id user id
|
|
||||||
* @param {string} displayName user nickname
|
|
||||||
*/
|
|
||||||
notifyConferenceLeft (room) {
|
|
||||||
triggerEvent("video-conference-left", {roomName: room});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that
|
||||||
* we are ready to be closed.
|
* we are ready to be closed.
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
notifyReadyToClose () {
|
notifyReadyToClose() {
|
||||||
triggerEvent("video-ready-to-close", {});
|
triggerEvent('video-ready-to-close', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends remote control event.
|
* Sends remote control event.
|
||||||
* @param {RemoteControlEvent} event the remote control event.
|
*
|
||||||
|
* @param {RemoteControlEvent} event - The remote control event.
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
sendRemoteControlEvent(event) {
|
sendRemoteControlEvent(event) {
|
||||||
sendMessage({method: "remote-control-event", params: event});
|
sendMessage({ method: 'remote-control-event',
|
||||||
|
params: event });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the listeners.
|
* Removes the listeners.
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
dispose () {
|
dispose() {
|
||||||
if(enabled) {
|
if (enabled) {
|
||||||
postis.destroy();
|
postis.destroy();
|
||||||
APP.conference.removeListener(
|
APP.conference.removeListener(
|
||||||
JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
|
JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
'extends': '../../../react/.eslintrc.js'
|
|
||||||
};
|
|
Loading…
Reference in New Issue