|
@@ -1,40 +1,23 @@
|
1
|
|
-const logger = require("jitsi-meet-logger").getLogger(__filename);
|
2
|
|
-import postisInit from "postis";
|
3
|
|
-import EventEmitter from "events";
|
|
1
|
+import EventEmitter from 'events';
|
|
2
|
+import postisInit from 'postis';
|
4
|
3
|
|
5
|
|
-/**
|
6
|
|
- * The minimum width for the Jitsi Meet frame
|
7
|
|
- * @type {number}
|
8
|
|
- */
|
9
|
|
-const MIN_WIDTH = 790;
|
10
|
|
-
|
11
|
|
-/**
|
12
|
|
- * The minimum height for the Jitsi Meet frame
|
13
|
|
- * @type {number}
|
14
|
|
- */
|
15
|
|
-const MIN_HEIGHT = 300;
|
16
|
|
-
|
17
|
|
-/**
|
18
|
|
- * Last id of api object
|
19
|
|
- * @type {number}
|
20
|
|
- */
|
21
|
|
-let id = 0;
|
|
4
|
+const logger = require('jitsi-meet-logger').getLogger(__filename);
|
22
|
5
|
|
23
|
6
|
/**
|
24
|
7
|
* Maps the names of the commands expected by the API with the name of the
|
25
|
8
|
* commands expected by jitsi-meet
|
26
|
9
|
*/
|
27
|
10
|
const commands = {
|
28
|
|
- "displayName": "display-name",
|
29
|
|
- "toggleAudio": "toggle-audio",
|
30
|
|
- "toggleVideo": "toggle-video",
|
31
|
|
- "toggleFilmStrip": "toggle-film-strip",
|
32
|
|
- "toggleChat": "toggle-chat",
|
33
|
|
- "toggleContactList": "toggle-contact-list",
|
34
|
|
- "toggleShareScreen": "toggle-share-screen",
|
35
|
|
- "hangup": "video-hangup",
|
36
|
|
- "email": "email",
|
37
|
|
- "avatarUrl": "avatar-url"
|
|
11
|
+ avatarUrl: 'avatar-url',
|
|
12
|
+ displayName: 'display-name',
|
|
13
|
+ email: 'email',
|
|
14
|
+ hangup: 'video-hangup',
|
|
15
|
+ toggleAudio: 'toggle-audio',
|
|
16
|
+ toggleChat: 'toggle-chat',
|
|
17
|
+ toggleContactList: 'toggle-contact-list',
|
|
18
|
+ toggleFilmStrip: 'toggle-film-strip',
|
|
19
|
+ toggleShareScreen: 'toggle-share-screen',
|
|
20
|
+ toggleVideo: 'toggle-video'
|
38
|
21
|
};
|
39
|
22
|
|
40
|
23
|
/**
|
|
@@ -42,35 +25,42 @@ const commands = {
|
42
|
25
|
* events expected by jitsi-meet
|
43
|
26
|
*/
|
44
|
27
|
const events = {
|
45
|
|
- "incomingMessage": "incoming-message",
|
46
|
|
- "outgoingMessage": "outgoing-message",
|
47
|
|
- "displayNameChange": "display-name-change",
|
48
|
|
- "participantJoined": "participant-joined",
|
49
|
|
- "participantLeft": "participant-left",
|
50
|
|
- "videoConferenceJoined": "video-conference-joined",
|
51
|
|
- "videoConferenceLeft": "video-conference-left",
|
52
|
|
- "readyToClose": "video-ready-to-close"
|
|
28
|
+ displayNameChange: 'display-name-change',
|
|
29
|
+ incomingMessage: 'incoming-message',
|
|
30
|
+ outgoingMessage: 'outgoing-message',
|
|
31
|
+ participantJoined: 'participant-joined',
|
|
32
|
+ participantLeft: 'participant-left',
|
|
33
|
+ readyToClose: 'video-ready-to-close',
|
|
34
|
+ videoConferenceJoined: 'video-conference-joined',
|
|
35
|
+ videoConferenceLeft: 'video-conference-left'
|
53
|
36
|
};
|
54
|
37
|
|
55
|
38
|
/**
|
56
|
|
- * Sends the passed object to Jitsi Meet
|
57
|
|
- * @param postis {Postis object} the postis instance that is going to be used
|
58
|
|
- * to send the message
|
59
|
|
- * @param object the object to be sent
|
60
|
|
- * - method {sting}
|
61
|
|
- * - params {object}
|
|
39
|
+ * Last id of api object
|
|
40
|
+ * @type {number}
|
62
|
41
|
*/
|
63
|
|
-function sendMessage(postis, object) {
|
64
|
|
- postis.send(object);
|
65
|
|
-}
|
|
42
|
+let id = 0;
|
|
43
|
+
|
|
44
|
+/**
|
|
45
|
+ * The minimum height for the Jitsi Meet frame
|
|
46
|
+ * @type {number}
|
|
47
|
+ */
|
|
48
|
+const MIN_HEIGHT = 300;
|
|
49
|
+
|
|
50
|
+/**
|
|
51
|
+ * The minimum width for the Jitsi Meet frame
|
|
52
|
+ * @type {number}
|
|
53
|
+ */
|
|
54
|
+const MIN_WIDTH = 790;
|
66
|
55
|
|
67
|
56
|
/**
|
68
|
57
|
* Adds given number to the numberOfParticipants property of given APIInstance.
|
69
|
|
- * @param {JitsiMeetExternalAPI} APIInstance the instance of the
|
70
|
|
- * JitsiMeetExternalAPI
|
71
|
|
- * @param {int} number - the number of participants to be added to
|
|
58
|
+ *
|
|
59
|
+ * @param {JitsiMeetExternalAPI} APIInstance - The instance of the API.
|
|
60
|
+ * @param {int} number - The number of participants to be added to
|
72
|
61
|
* numberOfParticipants property (this parameter can be negative number if the
|
73
|
62
|
* numberOfParticipants should be decreased).
|
|
63
|
+ * @returns {void}
|
74
|
64
|
*/
|
75
|
65
|
function changeParticipantNumber(APIInstance, number) {
|
76
|
66
|
APIInstance.numberOfParticipants += number;
|
|
@@ -80,179 +70,206 @@ function changeParticipantNumber(APIInstance, number) {
|
80
|
70
|
* Generates array with URL params based on the passed config object that will
|
81
|
71
|
* be used for the Jitsi Meet URL generation.
|
82
|
72
|
*
|
83
|
|
- * @param config {object} the config object.
|
84
|
|
- * @returns {Array<string>} the array with URL param strings.
|
|
73
|
+ * @param {Object} config - The config object.
|
|
74
|
+ * @returns {Array<string>} The array with URL param strings.
|
85
|
75
|
*/
|
86
|
|
-function configToURLParamsArray(config) {
|
|
76
|
+function configToURLParamsArray(config = {}) {
|
87
|
77
|
const params = [];
|
88
|
78
|
|
89
|
|
- for (const key in config) {
|
|
79
|
+ for (const key in config) { // eslint-disable-line guard-for-in
|
90
|
80
|
try {
|
91
|
|
- params.push(key + '='
|
92
|
|
- + encodeURIComponent(JSON.stringify(config[key])));
|
|
81
|
+ params.push(`${key}=${
|
|
82
|
+ encodeURIComponent(JSON.stringify(config[key]))}`);
|
93
|
83
|
} catch (e) {
|
94
|
84
|
console.warn(`Error encoding ${key}: ${e}`);
|
95
|
85
|
}
|
96
|
86
|
}
|
|
87
|
+
|
97
|
88
|
return params;
|
98
|
89
|
}
|
99
|
90
|
|
|
91
|
+/**
|
|
92
|
+ * Generates the URL for the iframe.
|
|
93
|
+ *
|
|
94
|
+ * @param {string} domain - The domain name of the server that hosts the
|
|
95
|
+ * conference.
|
|
96
|
+ * @param {string} [options] - Another optional parameters.
|
|
97
|
+ * @param {Object} [options.configOverwrite] - Object containing configuration
|
|
98
|
+ * options defined in config.js to be overridden.
|
|
99
|
+ * @param {Object} [options.interfaceConfigOverwrite] - Object containing
|
|
100
|
+ * configuration options defined in interface_config.js to be overridden.
|
|
101
|
+ * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
|
|
102
|
+ * authentication.
|
|
103
|
+ * @param {boolean} [options.noSsl] - If the value is true https won't be used.
|
|
104
|
+ * @param {string} [options.roomName] - The name of the room to join.
|
|
105
|
+ * @returns {string} The URL.
|
|
106
|
+ */
|
|
107
|
+function generateURL(domain, options = {}) {
|
|
108
|
+ const {
|
|
109
|
+ configOverwrite,
|
|
110
|
+ interfaceConfigOverwrite,
|
|
111
|
+ jwt,
|
|
112
|
+ noSSL,
|
|
113
|
+ roomName
|
|
114
|
+ } = options;
|
|
115
|
+
|
|
116
|
+ let url = `${noSSL ? 'http' : 'https'}://${domain}/${roomName || ''}`;
|
|
117
|
+
|
|
118
|
+ if (jwt) {
|
|
119
|
+ url += `?jwt=${jwt}`;
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ url += `#jitsi_meet_external_api_id=${id}`;
|
|
123
|
+
|
|
124
|
+ const configURLParams = configToURLParamsArray(configOverwrite);
|
|
125
|
+
|
|
126
|
+ if (configURLParams.length) {
|
|
127
|
+ url += `&config.${configURLParams.join('&config.')}`;
|
|
128
|
+ }
|
|
129
|
+
|
|
130
|
+ const interfaceConfigURLParams
|
|
131
|
+ = configToURLParamsArray(interfaceConfigOverwrite);
|
|
132
|
+
|
|
133
|
+ if (interfaceConfigURLParams.length) {
|
|
134
|
+ url += `&interfaceConfig.${
|
|
135
|
+ interfaceConfigURLParams.join('&interfaceConfig.')}`;
|
|
136
|
+ }
|
|
137
|
+
|
|
138
|
+ return url;
|
|
139
|
+}
|
|
140
|
+
|
100
|
141
|
/**
|
101
|
142
|
* The IFrame API interface class.
|
102
|
143
|
*/
|
103
|
144
|
class JitsiMeetExternalAPI extends EventEmitter {
|
104
|
145
|
/**
|
105
|
|
- * Constructs new API instance. Creates iframe element that loads
|
106
|
|
- * Jitsi Meet.
|
107
|
|
- * @param domain the domain name of the server that hosts the conference
|
108
|
|
- * @param room_name the name of the room to join
|
109
|
|
- * @param width width of the iframe
|
110
|
|
- * @param height height of the iframe
|
111
|
|
- * @param parent_node the node that will contain the iframe
|
112
|
|
- * @param configOverwrite object containing configuration options defined in
|
113
|
|
- * config.js to be overridden.
|
114
|
|
- * @param interfaceConfigOverwrite object containing configuration options
|
115
|
|
- * defined in interface_config.js to be overridden.
|
116
|
|
- * @param noSsl if the value is true https won't be used
|
117
|
|
- * @param {string} [jwt] the JWT token if needed by jitsi-meet for
|
|
146
|
+ * Constructs new API instance. Creates iframe and loads Jitsi Meet in it.
|
|
147
|
+ *
|
|
148
|
+ * @param {string} domain - The domain name of the server that hosts the
|
|
149
|
+ * conference.
|
|
150
|
+ * @param {string} [roomName] - The name of the room to join.
|
|
151
|
+ * @param {number} [width] - Width of the iframe.
|
|
152
|
+ * @param {number} [height] - Height of the iframe.
|
|
153
|
+ * @param {DOMElement} [parentNode] - The node that will contain the
|
|
154
|
+ * iframe.
|
|
155
|
+ * @param {Object} [configOverwrite] - Object containing configuration
|
|
156
|
+ * options defined in config.js to be overridden.
|
|
157
|
+ * @param {Object} [interfaceConfigOverwrite] - Object containing
|
|
158
|
+ * configuration options defined in interface_config.js to be overridden.
|
|
159
|
+ * @param {boolean} [noSSL] - If the value is true https won't be used.
|
|
160
|
+ * @param {string} [jwt] - The JWT token if needed by jitsi-meet for
|
118
|
161
|
* authentication.
|
119
|
|
- * @constructor
|
120
|
162
|
*/
|
121
|
|
- constructor(domain, room_name, width, height, parentNode,
|
122
|
|
- configOverwrite, interfaceConfigOverwrite, noSsl, jwt) {
|
|
163
|
+ constructor(domain, // eslint-disable-line max-params
|
|
164
|
+ roomName = '',
|
|
165
|
+ width = MIN_WIDTH,
|
|
166
|
+ height = MIN_HEIGHT,
|
|
167
|
+ parentNode = document.body,
|
|
168
|
+ configOverwrite = {},
|
|
169
|
+ interfaceConfigOverwrite = {},
|
|
170
|
+ noSSL = false,
|
|
171
|
+ jwt = undefined) {
|
123
|
172
|
super();
|
|
173
|
+ this.parentNode = parentNode;
|
|
174
|
+ this.url = generateURL(domain, {
|
|
175
|
+ configOverwrite,
|
|
176
|
+ interfaceConfigOverwrite,
|
|
177
|
+ jwt,
|
|
178
|
+ noSSL,
|
|
179
|
+ roomName
|
|
180
|
+ });
|
|
181
|
+ this._createIFrame(Math.max(height, MIN_HEIGHT),
|
|
182
|
+ Math.max(width, MIN_WIDTH));
|
|
183
|
+ this.postis = postisInit({
|
|
184
|
+ scope: `jitsi_meet_external_api_${id}`,
|
|
185
|
+ window: this.frame.contentWindow
|
|
186
|
+ });
|
|
187
|
+ this.numberOfParticipants = 1;
|
|
188
|
+ this._setupListeners();
|
|
189
|
+ id++;
|
|
190
|
+ }
|
124
|
191
|
|
125
|
|
- if (!width || width < MIN_WIDTH) {
|
126
|
|
- width = MIN_WIDTH;
|
127
|
|
- }
|
128
|
|
- if (!height || height < MIN_HEIGHT) {
|
129
|
|
- height = MIN_HEIGHT;
|
130
|
|
- }
|
131
|
|
-
|
132
|
|
- this.parentNode = null;
|
133
|
|
- if (parentNode) {
|
134
|
|
- this.parentNode = parentNode;
|
135
|
|
- } else {
|
136
|
|
- var scriptTag = document.scripts[document.scripts.length - 1];
|
137
|
|
- this.parentNode = scriptTag.parentNode;
|
138
|
|
- }
|
139
|
|
-
|
140
|
|
- this.iframeHolder =
|
141
|
|
- this.parentNode.appendChild(document.createElement("div"));
|
142
|
|
- this.iframeHolder.id = "jitsiConference" + id;
|
143
|
|
- if (width) {
|
144
|
|
- this.iframeHolder.style.width = width + "px";
|
145
|
|
- }
|
146
|
|
- if (height) {
|
147
|
|
- this.iframeHolder.style.height = height + "px";
|
148
|
|
- }
|
149
|
|
- this.frameName = "jitsiConferenceFrame" + id;
|
150
|
|
- this.url = (noSsl) ? "http" : "https" +"://" + domain + "/";
|
151
|
|
- if (room_name) {
|
152
|
|
- this.url += room_name;
|
153
|
|
- }
|
154
|
|
-
|
155
|
|
- if (jwt) {
|
156
|
|
- this.url += '?jwt=' + jwt;
|
157
|
|
- }
|
158
|
|
-
|
159
|
|
- this.url += "#jitsi_meet_external_api_id=" + id;
|
160
|
|
-
|
161
|
|
- const configURLParams = configToURLParamsArray(configOverwrite);
|
162
|
|
- if (configURLParams.length) {
|
163
|
|
- this.url += '&config.' + configURLParams.join('&config.');
|
164
|
|
- }
|
|
192
|
+ /**
|
|
193
|
+ * Creates the iframe element.
|
|
194
|
+ *
|
|
195
|
+ * @param {number} height - The height of the iframe.
|
|
196
|
+ * @param {number} width - The with of the iframe.
|
|
197
|
+ * @returns {void}
|
|
198
|
+ *
|
|
199
|
+ * @private
|
|
200
|
+ */
|
|
201
|
+ _createIFrame(height, width) {
|
|
202
|
+ this.iframeHolder
|
|
203
|
+ = this.parentNode.appendChild(document.createElement('div'));
|
|
204
|
+ this.iframeHolder.id = `jitsiConference${id}`;
|
|
205
|
+ this.iframeHolder.style.width = `${width}px`;
|
|
206
|
+ this.iframeHolder.style.height = `${height}px`;
|
165
|
207
|
|
166
|
|
- const interfaceConfigURLParams
|
167
|
|
- = configToURLParamsArray(interfaceConfigOverwrite);
|
168
|
|
- if (interfaceConfigURLParams.length) {
|
169
|
|
- this.url += '&interfaceConfig.'
|
170
|
|
- + interfaceConfigURLParams.join('&interfaceConfig.');
|
171
|
|
- }
|
|
208
|
+ this.frameName = `jitsiConferenceFrame${id}`;
|
172
|
209
|
|
173
|
|
- this.frame = document.createElement("iframe");
|
|
210
|
+ this.frame = document.createElement('iframe');
|
174
|
211
|
this.frame.src = this.url;
|
175
|
212
|
this.frame.name = this.frameName;
|
176
|
213
|
this.frame.id = this.frameName;
|
177
|
|
- this.frame.width = "100%";
|
178
|
|
- this.frame.height = "100%";
|
179
|
|
- this.frame.setAttribute("allowFullScreen","true");
|
|
214
|
+ this.frame.width = '100%';
|
|
215
|
+ this.frame.height = '100%';
|
|
216
|
+ this.frame.setAttribute('allowFullScreen', 'true');
|
180
|
217
|
this.frame = this.iframeHolder.appendChild(this.frame);
|
181
|
|
- this.postis = postisInit({
|
182
|
|
- window: this.frame.contentWindow,
|
183
|
|
- scope: "jitsi_meet_external_api_" + id
|
184
|
|
- });
|
185
|
|
-
|
186
|
|
- this.eventHandlers = {};
|
187
|
|
-
|
188
|
|
- // Map<{string} event_name, {boolean} postis_listener_added>
|
189
|
|
- this.postisListeners = {};
|
190
|
|
-
|
191
|
|
- this.numberOfParticipants = 1;
|
192
|
|
- this._setupListeners();
|
193
|
|
-
|
194
|
|
- id++;
|
195
|
218
|
}
|
196
|
219
|
|
197
|
220
|
/**
|
198
|
|
- * Executes command. The available commands are:
|
199
|
|
- * displayName - sets the display name of the local participant to the value
|
200
|
|
- * passed in the arguments array.
|
201
|
|
- * toggleAudio - mutes / unmutes audio with no arguments
|
202
|
|
- * toggleVideo - mutes / unmutes video with no arguments
|
203
|
|
- * filmStrip - hides / shows the film strip with no arguments
|
204
|
|
- * If the command doesn't require any arguments the parameter should be set
|
205
|
|
- * to empty array or it may be omitted.
|
206
|
|
- * @param name the name of the command
|
207
|
|
- * @param arguments array of arguments
|
|
221
|
+ * Setups listeners that are used internally for JitsiMeetExternalAPI.
|
|
222
|
+ *
|
|
223
|
+ * @returns {void}
|
|
224
|
+ *
|
|
225
|
+ * @private
|
208
|
226
|
*/
|
209
|
|
- executeCommand(name, ...argumentsList) {
|
210
|
|
- if(!(name in commands)) {
|
211
|
|
- logger.error("Not supported command name.");
|
212
|
|
- return;
|
|
227
|
+ _setupListeners() {
|
|
228
|
+ this.postis.listen('participant-joined',
|
|
229
|
+ changeParticipantNumber.bind(null, this, 1));
|
|
230
|
+ this.postis.listen('participant-left',
|
|
231
|
+ changeParticipantNumber.bind(null, this, -1));
|
|
232
|
+
|
|
233
|
+ for (const eventName in events) { // eslint-disable-line guard-for-in
|
|
234
|
+ const postisMethod = events[eventName];
|
|
235
|
+
|
|
236
|
+ this.postis.listen(postisMethod,
|
|
237
|
+ (...args) => this.emit(eventName, ...args));
|
213
|
238
|
}
|
214
|
|
- sendMessage(this.postis, {
|
215
|
|
- method: commands[name],
|
216
|
|
- params: argumentsList
|
217
|
|
- });
|
218
|
239
|
}
|
219
|
240
|
|
220
|
241
|
/**
|
221
|
|
- * Executes commands. The available commands are:
|
222
|
|
- * displayName - sets the display name of the local participant to the value
|
223
|
|
- * passed in the arguments array.
|
224
|
|
- * toggleAudio - mutes / unmutes audio. no arguments
|
225
|
|
- * toggleVideo - mutes / unmutes video. no arguments
|
226
|
|
- * filmStrip - hides / shows the film strip. no arguments
|
227
|
|
- * toggleChat - hides / shows chat. no arguments.
|
228
|
|
- * toggleContactList - hides / shows contact list. no arguments.
|
229
|
|
- * toggleShareScreen - starts / stops screen sharing. no arguments.
|
230
|
|
- * @param object the object with commands to be executed. The keys of the
|
231
|
|
- * object are the commands that will be executed and the values are the
|
232
|
|
- * arguments for the command.
|
|
242
|
+ * Adds event listener to Meet Jitsi.
|
|
243
|
+ *
|
|
244
|
+ * @param {string} event - The name of the event.
|
|
245
|
+ * @param {Function} listener - The listener.
|
|
246
|
+ * @returns {void}
|
|
247
|
+ *
|
|
248
|
+ * @deprecated
|
|
249
|
+ * NOTE: This method is not removed for backward comatability purposes.
|
233
|
250
|
*/
|
234
|
|
- executeCommands(object) {
|
235
|
|
- for (var key in object) {
|
236
|
|
- this.executeCommand(key, object[key]);
|
237
|
|
- }
|
|
251
|
+ addEventListener(event, listener) {
|
|
252
|
+ this.on(event, listener);
|
238
|
253
|
}
|
239
|
254
|
|
240
|
255
|
/**
|
241
|
|
- * Adds event listeners to Meet Jitsi. The object key should be the name of
|
|
256
|
+ * Adds event listeners to Meet Jitsi.
|
|
257
|
+ *
|
|
258
|
+ * @param {Object} listeners - The object key should be the name of
|
242
|
259
|
* the event and value - the listener.
|
243
|
260
|
* Currently we support the following
|
244
|
261
|
* events:
|
245
|
262
|
* incomingMessage - receives event notifications about incoming
|
246
|
263
|
* messages. The listener will receive object with the following structure:
|
247
|
264
|
* {{
|
248
|
|
- * "from": from,//JID of the user that sent the message
|
249
|
|
- * "nick": nick,//the nickname of the user that sent the message
|
250
|
|
- * "message": txt//the text of the message
|
|
265
|
+ * 'from': from,//JID of the user that sent the message
|
|
266
|
+ * 'nick': nick,//the nickname of the user that sent the message
|
|
267
|
+ * 'message': txt//the text of the message
|
251
|
268
|
* }}
|
252
|
269
|
* outgoingMessage - receives event notifications about outgoing
|
253
|
270
|
* messages. The listener will receive object with the following structure:
|
254
|
271
|
* {{
|
255
|
|
- * "message": txt//the text of the message
|
|
272
|
+ * 'message': txt//the text of the message
|
256
|
273
|
* }}
|
257
|
274
|
* displayNameChanged - receives event notifications about display name
|
258
|
275
|
* change. The listener will receive object with the following structure:
|
|
@@ -285,126 +302,116 @@ class JitsiMeetExternalAPI extends EventEmitter {
|
285
|
302
|
* }}
|
286
|
303
|
* readyToClose - all hangup operations are completed and Jitsi Meet is
|
287
|
304
|
* ready to be disposed.
|
288
|
|
- * @param object
|
|
305
|
+ * @returns {void}
|
289
|
306
|
*
|
|
307
|
+ * @deprecated
|
290
|
308
|
* NOTE: This method is not removed for backward comatability purposes.
|
291
|
309
|
*/
|
292
|
|
- addEventListeners(object) {
|
293
|
|
- for (var i in object) {
|
294
|
|
- this.addEventListener(i, object[i]);
|
|
310
|
+ addEventListeners(listeners) {
|
|
311
|
+ for (const event in listeners) { // eslint-disable-line guard-for-in
|
|
312
|
+ this.addEventListener(event, listeners[event]);
|
295
|
313
|
}
|
296
|
314
|
}
|
297
|
315
|
|
298
|
316
|
/**
|
299
|
|
- * Adds event listeners to Meet Jitsi. Currently we support the following
|
300
|
|
- * events:
|
301
|
|
- * incomingMessage - receives event notifications about incoming
|
302
|
|
- * messages. The listener will receive object with the following structure:
|
303
|
|
- * {{
|
304
|
|
- * "from": from,//JID of the user that sent the message
|
305
|
|
- * "nick": nick,//the nickname of the user that sent the message
|
306
|
|
- * "message": txt//the text of the message
|
307
|
|
- * }}
|
308
|
|
- * outgoingMessage - receives event notifications about outgoing
|
309
|
|
- * messages. The listener will receive object with the following structure:
|
310
|
|
- * {{
|
311
|
|
- * "message": txt//the text of the message
|
312
|
|
- * }}
|
313
|
|
- * displayNameChanged - receives event notifications about display name
|
314
|
|
- * change. The listener will receive object with the following structure:
|
315
|
|
- * {{
|
316
|
|
- * jid: jid,//the JID of the participant that changed his display name
|
317
|
|
- * displayname: displayName //the new display name
|
318
|
|
- * }}
|
319
|
|
- * participantJoined - receives event notifications about new participant.
|
320
|
|
- * The listener will receive object with the following structure:
|
321
|
|
- * {{
|
322
|
|
- * jid: jid //the jid of the participant
|
323
|
|
- * }}
|
324
|
|
- * participantLeft - receives event notifications about participant the that
|
325
|
|
- * left the room.
|
326
|
|
- * The listener will receive object with the following structure:
|
327
|
|
- * {{
|
328
|
|
- * jid: jid //the jid of the participant
|
329
|
|
- * }}
|
330
|
|
- * video-conference-joined - receives event notifications fired when the
|
331
|
|
- * local user has joined the video conference.
|
332
|
|
- * The listener will receive object with the following structure:
|
333
|
|
- * {{
|
334
|
|
- * roomName: room //the room name of the conference
|
335
|
|
- * }}
|
336
|
|
- * video-conference-left - receives event notifications fired when the local
|
337
|
|
- * user has joined the video conference.
|
338
|
|
- * The listener will receive object with the following structure:
|
339
|
|
- * {{
|
340
|
|
- * roomName: room //the room name of the conference
|
341
|
|
- * }}
|
342
|
|
- * @param event the name of the event
|
343
|
|
- * @param listener the listener
|
|
317
|
+ * Removes the listeners and removes the Jitsi Meet frame.
|
344
|
318
|
*
|
345
|
|
- * NOTE: This method is not removed for backward comatability purposes.
|
|
319
|
+ * @returns {void}
|
346
|
320
|
*/
|
347
|
|
- addEventListener(event, listener) {
|
348
|
|
- this.on(event, listener);
|
|
321
|
+ dispose() {
|
|
322
|
+ const frame = document.getElementById(this.frameName);
|
|
323
|
+
|
|
324
|
+ this.postis.destroy();
|
|
325
|
+ if (frame) {
|
|
326
|
+ frame.src = 'about:blank';
|
|
327
|
+ }
|
|
328
|
+ window.setTimeout(() => {
|
|
329
|
+ this.iframeHolder.removeChild(this.frame);
|
|
330
|
+ this.iframeHolder.parentNode.removeChild(this.iframeHolder);
|
|
331
|
+ }, 10);
|
349
|
332
|
}
|
350
|
333
|
|
351
|
334
|
/**
|
352
|
|
- * Removes event listener.
|
353
|
|
- * @param event the name of the event.
|
354
|
|
- * NOTE: This method is not removed for backward comatability purposes.
|
|
335
|
+ * Executes command. The available commands are:
|
|
336
|
+ * displayName - sets the display name of the local participant to the value
|
|
337
|
+ * passed in the arguments array.
|
|
338
|
+ * toggleAudio - mutes / unmutes audio with no arguments.
|
|
339
|
+ * toggleVideo - mutes / unmutes video with no arguments.
|
|
340
|
+ * filmStrip - hides / shows the film strip with no arguments.
|
|
341
|
+ * If the command doesn't require any arguments the parameter should be set
|
|
342
|
+ * to empty array or it may be omitted.
|
|
343
|
+ *
|
|
344
|
+ * @param {string} name - The name of the command.
|
|
345
|
+ * @returns {void}
|
355
|
346
|
*/
|
356
|
|
- removeEventListener(event) {
|
357
|
|
- this.removeListeners(event);
|
|
347
|
+ executeCommand(name, ...args) {
|
|
348
|
+ if (!(name in commands)) {
|
|
349
|
+ logger.error('Not supported command name.');
|
|
350
|
+
|
|
351
|
+ return;
|
|
352
|
+ }
|
|
353
|
+ this.postis.send({
|
|
354
|
+ method: commands[name],
|
|
355
|
+ params: args
|
|
356
|
+ });
|
358
|
357
|
}
|
359
|
358
|
|
360
|
359
|
/**
|
361
|
|
- * Removes event listeners.
|
362
|
|
- * @param events array with the names of the events.
|
363
|
|
- * NOTE: This method is not removed for backward comatability purposes.
|
|
360
|
+ * Executes commands. The available commands are:
|
|
361
|
+ * displayName - sets the display name of the local participant to the value
|
|
362
|
+ * passed in the arguments array.
|
|
363
|
+ * toggleAudio - mutes / unmutes audio. no arguments
|
|
364
|
+ * toggleVideo - mutes / unmutes video. no arguments
|
|
365
|
+ * filmStrip - hides / shows the film strip. no arguments
|
|
366
|
+ * toggleChat - hides / shows chat. no arguments.
|
|
367
|
+ * toggleContactList - hides / shows contact list. no arguments.
|
|
368
|
+ * toggleShareScreen - starts / stops screen sharing. no arguments.
|
|
369
|
+ *
|
|
370
|
+ * @param {Object} commandList - The object with commands to be executed.
|
|
371
|
+ * The keys of the object are the commands that will be executed and the
|
|
372
|
+ * values are the arguments for the command.
|
|
373
|
+ * @returns {void}
|
364
|
374
|
*/
|
365
|
|
- removeEventListeners(events) {
|
366
|
|
- for(var i = 0; i < events.length; i++) {
|
367
|
|
- this.removeEventListener(events[i]);
|
|
375
|
+ executeCommands(commandList) {
|
|
376
|
+ for (const key in commandList) { // eslint-disable-line guard-for-in
|
|
377
|
+ this.executeCommand(key, commandList[key]);
|
368
|
378
|
}
|
369
|
379
|
}
|
370
|
380
|
|
371
|
381
|
/**
|
372
|
|
- * Returns the number of participants in the conference.
|
373
|
|
- * NOTE: the local participant is included.
|
374
|
|
- * @returns {int} the number of participants in the conference.
|
|
382
|
+ * Returns the number of participants in the conference. The local
|
|
383
|
+ * participant is included.
|
|
384
|
+ *
|
|
385
|
+ * @returns {int} The number of participants in the conference.
|
375
|
386
|
*/
|
376
|
387
|
getNumberOfParticipants() {
|
377
|
388
|
return this.numberOfParticipants;
|
378
|
389
|
}
|
379
|
390
|
|
380
|
391
|
/**
|
381
|
|
- * Setups listeners that are used internally for JitsiMeetExternalAPI.
|
|
392
|
+ * Removes event listener.
|
|
393
|
+ *
|
|
394
|
+ * @param {string} event - The name of the event.
|
|
395
|
+ * @returns {void}
|
|
396
|
+ *
|
|
397
|
+ * @deprecated
|
|
398
|
+ * NOTE: This method is not removed for backward comatability purposes.
|
382
|
399
|
*/
|
383
|
|
- _setupListeners() {
|
384
|
|
- this.postis.listen("participant-joined",
|
385
|
|
- changeParticipantNumber.bind(null, this, 1));
|
386
|
|
- this.postis.listen("participant-left",
|
387
|
|
- changeParticipantNumber.bind(null, this, -1));
|
388
|
|
-
|
389
|
|
- for (const eventName in events) {
|
390
|
|
- const postisMethod = events[eventName];
|
391
|
|
- this.postis.listen(postisMethod,
|
392
|
|
- (...args) => this.emit(eventName, ...args));
|
393
|
|
- }
|
|
400
|
+ removeEventListener(event) {
|
|
401
|
+ this.removeListeners(event);
|
394
|
402
|
}
|
395
|
403
|
|
396
|
404
|
/**
|
397
|
|
- * Removes the listeners and removes the Jitsi Meet frame.
|
|
405
|
+ * Removes event listeners.
|
|
406
|
+ *
|
|
407
|
+ * @param {Array<string>} eventList - Array with the names of the events.
|
|
408
|
+ * @returns {void}
|
|
409
|
+ *
|
|
410
|
+ * @deprecated
|
|
411
|
+ * NOTE: This method is not removed for backward comatability purposes.
|
398
|
412
|
*/
|
399
|
|
- dispose() {
|
400
|
|
- this.postis.destroy();
|
401
|
|
- var frame = document.getElementById(this.frameName);
|
402
|
|
- if(frame)
|
403
|
|
- frame.src = 'about:blank';
|
404
|
|
- window.setTimeout( () => {
|
405
|
|
- this.iframeHolder.removeChild(this.frame);
|
406
|
|
- this.iframeHolder.parentNode.removeChild(this.iframeHolder);
|
407
|
|
- }, 10);
|
|
413
|
+ removeEventListeners(eventList) {
|
|
414
|
+ eventList.forEach(event => this.removeEventListener(event));
|
408
|
415
|
}
|
409
|
416
|
}
|
410
|
417
|
|