Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
fix(transport): Code style issues and enableLegacyFormat param bug
hristoterezovb49c1c6ba265
diff --git a/modules/API/API.js b/modules/API/API.jsindex 18c7f3e678..a9c50c76f4 100644--- a/modules/API/API.js+++ b/modules/API/API.js@@ -1,5 +1,5 @@import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';-import { transport } from '../transport';+import { getJitsiMeetTransport } from '../transport';import { API_ID } from './constants';@@ -18,6 +18,13 @@ let commands = {};*/let initialScreenSharingState = false;+/**+ * The transport instance used for communication with external apps.+ *+ * @type {Transport}+ */+const transport = getJitsiMeetTransport();+/*** Initializes supported commands.*diff --git a/modules/API/constants.js b/modules/API/constants.jsindex e59fbabe0b..3bbf0e5dcb 100644--- a/modules/API/constants.js+++ b/modules/API/constants.js@@ -3,4 +3,6 @@ declare var getConfigParamsFromUrl: Function;/*** JitsiMeetExternalAPI id - unique for a webpage.*/-export const API_ID = getConfigParamsFromUrl().jitsi_meet_external_api_id;+export const API_ID+ = typeof getConfigParamsFromUrl === 'function'+ ? getConfigParamsFromUrl().jitsi_meet_external_api_id : undefined;diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.jsindex 24ec9b7c94..b72dc05a44 100644--- a/modules/API/external/external_api.js+++ b/modules/API/external/external_api.js@@ -1,8 +1,9 @@import EventEmitter from 'events';-import PostMessageTransportBackend- from '../../transport/PostMessageTransportBackend';-import Transport from '../../transport/Transport';+import {+ PostMessageTransportBackend,+ Transport+} from '../../transport';const logger = require('jitsi-meet-logger').getLogger(__filename);@@ -184,7 +185,7 @@ class JitsiMeetExternalAPI extends EventEmitter {this._createIFrame(Math.max(height, MIN_HEIGHT),Math.max(width, MIN_WIDTH));this._transport = new Transport({- transport: new PostMessageTransportBackend({+ backend: new PostMessageTransportBackend({postisOptions: {scope: `jitsi_meet_external_api_${id}`,window: this.frame.contentWindowdiff --git a/modules/remotecontrol/Receiver.js b/modules/remotecontrol/Receiver.jsindex b6e31150a1..444a226db3 100644--- a/modules/remotecontrol/Receiver.js+++ b/modules/remotecontrol/Receiver.js@@ -7,13 +7,20 @@ import {PERMISSIONS_ACTIONS,REMOTE_CONTROL_EVENT_TYPE} from "../../service/remotecontrol/Constants";-import { transport } from '../transport';+import { getJitsiMeetTransport } from '../transport';import RemoteControlParticipant from "./RemoteControlParticipant";const ConferenceEvents = JitsiMeetJS.events.conference;const logger = require("jitsi-meet-logger").getLogger(__filename);+/**+ * The transport instance used for communication with external apps.+ *+ * @type {Transport}+ */+const transport = getJitsiMeetTransport();+/*** This class represents the receiver party for a remote controller session.* It handles "remote-control-event" events and sends them to thediff --git a/modules/transport/PostMessageTransportBackend.js b/modules/transport/PostMessageTransportBackend.jsindex f79c96211c..7ab8cc7e61 100644--- a/modules/transport/PostMessageTransportBackend.js+++ b/modules/transport/PostMessageTransportBackend.js@@ -10,8 +10,8 @@ const DEFAULT_POSTIS_OPTIONS = {};/**- * The list of methods of incomming postis messages that we have to support for- * backward compatability for the users that are directly sending messages to+ * The list of methods of incoming postis messages that we have to support for+ * backward compatibility for the users that are directly sending messages to* Jitsi Meet (without using external_api.js)** @type {string[]}@@ -31,7 +31,7 @@ const LEGACY_INCOMING_METHODS = [/*** The list of methods of outgoing postis messages that we have to support for- * backward compatability for the users that are directly listening to the+ * backward compatibility for the users that are directly listening to the* postis messages send by Jitsi Meet(without using external_api.js).** @type {string[]}@@ -70,10 +70,18 @@ export default class PostMessageTransportBackend {...postisOptions});+ /**+ * If true PostMessageTransportBackend will process and send data using+ * the legacy format and in the same time the current format. Otherwise+ * all data received that is using the legacy format will be ignored and+ * no data with the legacy format will be sent.+ *+ * @type {boolean}+ */this._enableLegacyFormat = enableLegacyFormat;- if (!this._enableLegacyFormat) {- // backward compatability+ if (this._enableLegacyFormat) {+ // backward compatibilityLEGACY_INCOMING_METHODS.forEach(method =>this.postis.listen(method,@@ -91,7 +99,7 @@ export default class PostMessageTransportBackend {}/**- * Handles incomming legacy postis data.+ * Handles incoming legacy postis data.** @param {string} method - The method property from postis data object.* @param {Any} params - The params property from postis data object.@@ -142,7 +150,7 @@ export default class PostMessageTransportBackend {params: data});- if (!this._enableLegacyFormat) {+ if (this._enableLegacyFormat) {// For the legacy use case we don't need any new fields defined in// Transport class. That's why we are passing only the original// object passed by the consumer of the Transport class which isdiff --git a/modules/transport/Transport.js b/modules/transport/Transport.jsindex 52d6cca6b5..1d0eece9db 100644--- a/modules/transport/Transport.js+++ b/modules/transport/Transport.js@@ -5,45 +5,74 @@ import {} from './constants';/**- * Stores the currnet transport that have to be used.+ * Stores the currnet transport backend that have to be used. Also implements+ * request/response mechanism.*/export default class Transport {/*** Creates new instance.** @param {Object} options - Optional parameters for configuration of the- * transport.+ * transport backend.*/- constructor({ transport } = {}) {+ constructor({ backend } = {}) {+ /**+ * The request ID counter used for the id property of the request. This+ * property is used to match the responses with the request.+ *+ * @type {number}+ */this._requestID = 0;+ /**+ * Maps an IDs of the requests and handlers that will process the+ * responses of those requests.+ *+ * @type {Map<number, Function>}+ */this._responseHandlers = new Map();+ /**+ * Maps an event name and listener that have been added to the Transport+ * instance.+ *+ * @type {Map<string, Function>}+ */this._listeners = new Map();+ /**+ * A set with the events and requests that were received but not+ * processed by any listener. They are later passed on every new+ * listener until they are processed.+ *+ * @type {Set<Object>}+ */this._unprocessedMessages = new Set();+ /**+ * Alias.+ */this.addListener = this.on;- if (transport) {- this.setTransport(transport);+ if (backend) {+ this.setBackend(backend);}}/**- * Disposes the current transport.+ * Disposes the current transport backend.** @returns {void}*/- _disposeTransport() {- if (this._transport) {- this._transport.dispose();- this._transport = null;+ _disposeBackend() {+ if (this._backend) {+ this._backend.dispose();+ this._backend = null;}}/**- * Handles incomming data from the transport.+ * Handles incoming data from the transport backend.** @param {Object} data - The data.* @returns {void}@@ -56,13 +85,9 @@ export default class Transport {handler(data);this._responseHandlers.delete(data.id);}-- return;- }-- if (data.type === MESSAGE_TYPE_REQUEST) {+ } else if (data.type === MESSAGE_TYPE_REQUEST) {this.emit('request', data.data, (result, error) => {- this._transport.send({+ this._backend.send({type: MESSAGE_TYPE_RESPONSE,error,id: data.id,@@ -83,7 +108,7 @@ export default class Transport {this._responseHandlers.clear();this._unprocessedMessages.clear();this.removeAllListeners();- this._disposeTransport();+ this._disposeBackend();}/**@@ -91,7 +116,8 @@ export default class Transport {* the order they were registered, passing the supplied arguments to each.** @param {string} eventName - The name of the event.- * @returns {boolean} True if the event had listeners, false otherwise.+ * @returns {boolean} True if the event has been processed by any listener,+ * false otherwise.*/emit(eventName, ...args) {const listenersForEvent = this._listeners.get(eventName);@@ -141,7 +167,8 @@ export default class Transport {/*** Removes all listeners, or those of the specified eventName.*- * @param {string} eventName - The name of the event.+ * @param {string} [eventName] - The name of the event. If this parameter is+ * not specified all listeners will be removed.* @returns {Transport} References to the instance of Transport class, so* that calls can be chained.*/@@ -181,8 +208,8 @@ export default class Transport {* @returns {void}*/sendEvent(data = {}) {- if (this._transport) {- this._transport.send({+ if (this._backend) {+ this._backend.send({type: MESSAGE_TYPE_EVENT,data});@@ -196,8 +223,8 @@ export default class Transport {* @returns {Promise}*/sendRequest(data) {- if (!this._transport) {- return Promise.reject(new Error('No transport defined!'));+ if (!this._backend) {+ return Promise.reject(new Error('No transport backend defined!'));}this._requestID++;@@ -215,7 +242,7 @@ export default class Transport {}});- this._transport.send({+ this._backend.send({type: MESSAGE_TYPE_REQUEST,data,id@@ -224,15 +251,15 @@ export default class Transport {}/**- * Changes the current transport.+ * Changes the current backend transport.*- * @param {Object} transport - The new transport that will be used.+ * @param {Object} backend - The new transport backend that will be used.* @returns {void}*/- setTransport(transport) {- this._disposeTransport();+ setBackend(backend) {+ this._disposeBackend();- this._transport = transport;- this._transport.setReceiveCallback(this._onDataReceived.bind(this));+ this._backend = backend;+ this._backend.setReceiveCallback(this._onDataReceived.bind(this));}}diff --git a/modules/transport/index.js b/modules/transport/index.jsindex 788031f638..4fefa93aa3 100644--- a/modules/transport/index.js+++ b/modules/transport/index.js@@ -1,9 +1,16 @@-import { API_ID } from '../API';+// FIXME: change to '../API' when we update to webpack2. If we do this now all+// files from API modules will be included in external_api.js.+import { API_ID } from '../API/constants';import { getJitsiMeetGlobalNS } from '../util/helpers';import Transport from './Transport';import PostMessageTransportBackend from './PostMessageTransportBackend';+export {+ Transport,+ PostMessageTransportBackend+};+/*** Option for the default low level transport.*@@ -15,19 +22,38 @@ if (typeof API_ID === 'number') {postisOptions.scope = `jitsi_meet_external_api_${API_ID}`;}-export const transport = new Transport({- transport: new PostMessageTransportBackend({- enableLegacyFormat: true,- postisOptions- })-});+/**+ * The instance of Transport class that will be used by Jitsi Meet.+ *+ * @type {Transport}+ */+let transport;++/**+ * Returns the instance of Transport class that will be used by Jitsi Meet.+ *+ * @returns {Transport}+ */+export function getJitsiMeetTransport() {+ if (!transport) {+ transport = new Transport({+ backend: new PostMessageTransportBackend({+ enableLegacyFormat: true,+ postisOptions+ })+ });+ }++ return transport;+}/*** Sets the transport to passed transport.*- * @param {Object} newTransport - The new transport.+ * @param {Object} externalTransportBackend - The new transport.* @returns {void}*/-getJitsiMeetGlobalNS().useNewExternalTransport = function(newTransport) {- transport.setTransport(newTransport);+getJitsiMeetGlobalNS().setExternalTransportBackend = function(+ externalTransportBackend) {+ transport.setBackend(externalTransportBackend);};diff --git a/modules/util/helpers.js b/modules/util/helpers.jsindex 9c333d6fa2..e824bb7865 100644--- a/modules/util/helpers.js+++ b/modules/util/helpers.js@@ -84,8 +84,11 @@ export function debounce(fn, wait = 0, options = {}) {* we store everything that needs to be global (for some reason).*/export function getJitsiMeetGlobalNS() {- if(!window.JitsiMeetGlobalNS) {- window.JitsiMeetGlobalNS = { };+ if(!window.JitsiMeetJS) {+ window.JitsiMeetJS = { };}- return window.JitsiMeetGlobalNS;+ if(!window.JitsiMeetJS.app) {+ window.JitsiMeetJS.app = { };+ }+ return window.JitsiMeetJS.app;}diff --git a/react/index.web.js b/react/index.web.jsindex d8ef1424e5..987e1d4fcb 100644--- a/react/index.web.js+++ b/react/index.web.js@@ -3,7 +3,7 @@import React from 'react';import ReactDOM from 'react-dom';-import { transport } from '../modules/transport';+import { getJitsiMeetTransport } from '../modules/transport';import config from './config';import { App } from './features/app';@@ -36,5 +36,5 @@ window.addEventListener('beforeunload', () => {APP.logCollectorStarted = false;}APP.API.dispose();- transport.dispose();+ getJitsiMeetTransport().dispose();});