Comply w/ coding style
This commit is contained in:
parent
0f42f18100
commit
f4de65a647
|
@ -6,39 +6,9 @@ import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of the available commands.
|
* List of the available commands.
|
||||||
* @type {{
|
|
||||||
* displayName: inputDisplayNameHandler,
|
|
||||||
* toggleAudio: toggleAudio,
|
|
||||||
* toggleVideo: toggleVideo,
|
|
||||||
* toggleFilmStrip: toggleFilmStrip,
|
|
||||||
* toggleChat: toggleChat,
|
|
||||||
* toggleContactList: toggleContactList
|
|
||||||
* }}
|
|
||||||
*/
|
*/
|
||||||
let commands = {};
|
let commands = {};
|
||||||
|
|
||||||
const hashParams = getConfigParamsFromUrl();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JitsiMeetExternalAPI id - unique for a webpage.
|
|
||||||
*/
|
|
||||||
const jitsiMeetExternalApiId = hashParams.jitsi_meet_external_api_id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Object that will execute sendMessage
|
|
||||||
*/
|
|
||||||
const target = window.opener ? window.opener : window.parent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Postis instance. Used to communicate with the external application.
|
|
||||||
*/
|
|
||||||
let postis;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current status (enabled/disabled) of API.
|
|
||||||
*/
|
|
||||||
let enabled = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state of screen sharing(started/stopped) before the screen sharing is
|
* The state of screen sharing(started/stopped) before the screen sharing is
|
||||||
* enabled and initialized.
|
* enabled and initialized.
|
||||||
|
@ -48,15 +18,21 @@ let enabled = false;
|
||||||
let initialScreenSharingState = false;
|
let initialScreenSharingState = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes on toggle-share-screen command.
|
* JitsiMeetExternalAPI id - unique for a webpage.
|
||||||
*/
|
*/
|
||||||
function toggleScreenSharing() {
|
const jitsiMeetExternalApiId
|
||||||
if(!APP.conference.isDesktopSharingEnabled) {
|
= getConfigParamsFromUrl().jitsi_meet_external_api_id;
|
||||||
initialScreenSharingState = !initialScreenSharingState;
|
|
||||||
} else {
|
/**
|
||||||
APP.conference.toggleScreenSharing();
|
* Postis instance. Used to communicate with the external application. If
|
||||||
}
|
* undefined, then API is disabled.
|
||||||
}
|
*/
|
||||||
|
let postis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object that will execute sendMessage.
|
||||||
|
*/
|
||||||
|
const target = window.opener || window.parent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes supported commands.
|
* Initializes supported commands.
|
||||||
|
@ -83,6 +59,19 @@ function initCommands() {
|
||||||
key => postis.listen(key, args => commands[key](...args)));
|
key => postis.listen(key, args => commands[key](...args)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens for desktop/screen sharing enabled events and toggles the screen
|
||||||
|
* sharing if needed.
|
||||||
|
*
|
||||||
|
* @param {boolean} enabled - Current screen sharing enabled status.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function onDesktopSharingEnabledChanged(enabled = false) {
|
||||||
|
if (enabled && initialScreenSharingState) {
|
||||||
|
toggleScreenSharing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends message to the external application.
|
* Sends message to the external application.
|
||||||
*
|
*
|
||||||
|
@ -90,7 +79,7 @@ function initCommands() {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function sendMessage(message) {
|
function sendMessage(message) {
|
||||||
if (enabled) {
|
if (postis) {
|
||||||
postis.send(message);
|
postis.send(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,48 +94,47 @@ function shouldBeEnabled() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends event object to the external application that has been subscribed
|
* Executes on toggle-share-screen command.
|
||||||
* for that event.
|
*
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function toggleScreenSharing() {
|
||||||
|
if (APP.conference.isDesktopSharingEnabled) {
|
||||||
|
APP.conference.toggleScreenSharing();
|
||||||
|
} else {
|
||||||
|
initialScreenSharingState = !initialScreenSharingState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends event object to the external application that has been subscribed for
|
||||||
|
* that event.
|
||||||
*
|
*
|
||||||
* @param {string} name - The name event.
|
* @param {string} name - The name event.
|
||||||
* @param {Object} object - Data associated with the event.
|
* @param {Object} object - Data associated with the event.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function triggerEvent(name, object) {
|
function triggerEvent(name, object) {
|
||||||
if (enabled) {
|
sendMessage({
|
||||||
sendMessage({ method: name,
|
method: name,
|
||||||
params: object });
|
params: object
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for screen sharing enabled events and toggles the screen sharing if
|
* Implements API class that communicates with external API class and provides
|
||||||
* needed.
|
* interface to access Jitsi Meet features by external applications that embed
|
||||||
*
|
* Jitsi Meet.
|
||||||
* @param {boolean} enabled - Current screen sharing enabled status.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function onScreenSharingEnable(enabled = false) {
|
|
||||||
if(enabled && initialScreenSharingState) {
|
|
||||||
toggleScreenSharing();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 {
|
||||||
/**
|
/**
|
||||||
* Initializes the APIConnector. Setups message event listeners that will
|
* Initializes the API. Setups message event listeners that will receive
|
||||||
* receive information from external applications that embed Jitsi Meet.
|
* information from external applications that embed Jitsi Meet. It also
|
||||||
* It also sends a message to the external application that APIConnector
|
* sends a message to the external application that API is initialized.
|
||||||
* is initialized.
|
|
||||||
*
|
*
|
||||||
* @param {Object} options - Optional parameters.
|
* @param {Object} options - Optional parameters.
|
||||||
* @param {boolean} options.forceEnable - If true the module will be
|
* @param {boolean} options.forceEnable - True to forcefully enable the
|
||||||
* enabled.
|
* module.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
init(options = {}) {
|
init(options = {}) {
|
||||||
|
@ -154,14 +142,10 @@ class API {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!enabled) {
|
if (!postis) {
|
||||||
APP.conference.addListener(
|
APP.conference.addListener(
|
||||||
JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
|
JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
|
||||||
onScreenSharingEnable);
|
onDesktopSharingEnabledChanged);
|
||||||
enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!postis) {
|
|
||||||
this._initPostis();
|
this._initPostis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,8 +181,8 @@ class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that message was
|
||||||
* message was received.
|
* received.
|
||||||
*
|
*
|
||||||
* @param {Object} options - Object with the message properties.
|
* @param {Object} options - Object with the message properties.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
|
@ -212,16 +196,17 @@ class API {
|
||||||
|
|
||||||
triggerEvent(
|
triggerEvent(
|
||||||
'incoming-message',
|
'incoming-message',
|
||||||
{ 'from': id,
|
{
|
||||||
'nick': nick,
|
'from': id,
|
||||||
'message': body,
|
'message': body,
|
||||||
'stamp': ts }
|
'nick': nick,
|
||||||
);
|
'stamp': ts
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that user joined the
|
||||||
* user joined the conference.
|
* conference.
|
||||||
*
|
*
|
||||||
* @param {string} id - User id.
|
* @param {string} id - User id.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
|
@ -231,8 +216,8 @@ class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that user left the
|
||||||
* user left the conference.
|
* conference.
|
||||||
*
|
*
|
||||||
* @param {string} id - User id.
|
* @param {string} id - User id.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
|
@ -242,21 +227,25 @@ class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that user changed their
|
||||||
* user changed their nickname.
|
* nickname.
|
||||||
*
|
*
|
||||||
* @param {string} id - User id.
|
* @param {string} id - User id.
|
||||||
* @param {string} displayName - User nickname.
|
* @param {string} displayName - User nickname.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
notifyDisplayNameChanged(id, displayName) {
|
notifyDisplayNameChanged(id, displayName) {
|
||||||
triggerEvent('display-name-change', { id,
|
triggerEvent(
|
||||||
displayname: displayName });
|
'display-name-change',
|
||||||
|
{
|
||||||
|
displayname: displayName,
|
||||||
|
id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that the conference has
|
||||||
* the conference has been joined.
|
* been joined.
|
||||||
*
|
*
|
||||||
* @param {string} room - The room name.
|
* @param {string} room - The room name.
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
|
@ -266,8 +255,8 @@ class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that user changed their
|
||||||
* user changed their nickname.
|
* nickname.
|
||||||
*
|
*
|
||||||
* @param {string} room - User id.
|
* @param {string} room - User id.
|
||||||
* @param {string} displayName - User nickname.
|
* @param {string} displayName - User nickname.
|
||||||
|
@ -278,8 +267,8 @@ class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify external application (if API is enabled) that
|
* Notify external application (if API is enabled) that we are ready to be
|
||||||
* we are ready to be closed.
|
* closed.
|
||||||
*
|
*
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
|
@ -294,8 +283,10 @@ class API {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
sendRemoteControlEvent(event) {
|
sendRemoteControlEvent(event) {
|
||||||
sendMessage({ method: 'remote-control-event',
|
sendMessage({
|
||||||
params: event });
|
method: 'remote-control-event',
|
||||||
|
params: event
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -304,11 +295,13 @@ class API {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
dispose() {
|
dispose() {
|
||||||
if (enabled) {
|
if (postis) {
|
||||||
postis.destroy();
|
postis.destroy();
|
||||||
|
postis = undefined;
|
||||||
|
|
||||||
APP.conference.removeListener(
|
APP.conference.removeListener(
|
||||||
JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
|
JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
|
||||||
onScreenSharingEnable);
|
onDesktopSharingEnabledChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue