|
|
@@ -1,34 +1,29 @@
|
|
1
|
1
|
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
|
2
|
|
-
|
|
3
|
|
-/**
|
|
4
|
|
- * Implements API class that embeds Jitsi Meet in external applications.
|
|
5
|
|
- */
|
|
6
|
|
-
|
|
7
|
|
-var postisInit = require("postis");
|
|
|
2
|
+import postisInit from "postis";
|
|
8
|
3
|
|
|
9
|
4
|
/**
|
|
10
|
5
|
* The minimum width for the Jitsi Meet frame
|
|
11
|
6
|
* @type {number}
|
|
12
|
7
|
*/
|
|
13
|
|
-var MIN_WIDTH = 790;
|
|
|
8
|
+const MIN_WIDTH = 790;
|
|
14
|
9
|
|
|
15
|
10
|
/**
|
|
16
|
11
|
* The minimum height for the Jitsi Meet frame
|
|
17
|
12
|
* @type {number}
|
|
18
|
13
|
*/
|
|
19
|
|
-var MIN_HEIGHT = 300;
|
|
|
14
|
+const MIN_HEIGHT = 300;
|
|
20
|
15
|
|
|
21
|
16
|
/**
|
|
22
|
17
|
* Last id of api object
|
|
23
|
18
|
* @type {number}
|
|
24
|
19
|
*/
|
|
25
|
|
-var id = 0;
|
|
|
20
|
+let id = 0;
|
|
26
|
21
|
|
|
27
|
22
|
/**
|
|
28
|
23
|
* Maps the names of the commands expected by the API with the name of the
|
|
29
|
24
|
* commands expected by jitsi-meet
|
|
30
|
25
|
*/
|
|
31
|
|
-var commands = {
|
|
|
26
|
+const commands = {
|
|
32
|
27
|
"displayName": "display-name",
|
|
33
|
28
|
"toggleAudio": "toggle-audio",
|
|
34
|
29
|
"toggleVideo": "toggle-video",
|
|
|
@@ -45,7 +40,7 @@ var commands = {
|
|
45
|
40
|
* Maps the names of the events expected by the API with the name of the
|
|
46
|
41
|
* events expected by jitsi-meet
|
|
47
|
42
|
*/
|
|
48
|
|
-var events = {
|
|
|
43
|
+const events = {
|
|
49
|
44
|
"incomingMessage": "incoming-message",
|
|
50
|
45
|
"outgoingMessage": "outgoing-message",
|
|
51
|
46
|
"displayNameChange": "display-name-change",
|
|
|
@@ -102,305 +97,319 @@ function configToURLParamsArray(config) {
|
|
102
|
97
|
}
|
|
103
|
98
|
|
|
104
|
99
|
/**
|
|
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
|
|
118
|
|
- * authentication.
|
|
119
|
|
- * @constructor
|
|
|
100
|
+ * The IFrame API interface class.
|
|
120
|
101
|
*/
|
|
121
|
|
-function JitsiMeetExternalAPI(domain, room_name, width, height, parentNode,
|
|
122
|
|
- configOverwrite, interfaceConfigOverwrite, noSsl, jwt) {
|
|
123
|
|
- if (!width || width < MIN_WIDTH)
|
|
124
|
|
- width = MIN_WIDTH;
|
|
125
|
|
- if (!height || height < MIN_HEIGHT)
|
|
126
|
|
- height = MIN_HEIGHT;
|
|
127
|
|
-
|
|
128
|
|
- this.parentNode = null;
|
|
129
|
|
- if (parentNode) {
|
|
130
|
|
- this.parentNode = parentNode;
|
|
131
|
|
- } else {
|
|
132
|
|
- var scriptTag = document.scripts[document.scripts.length - 1];
|
|
133
|
|
- this.parentNode = scriptTag.parentNode;
|
|
134
|
|
- }
|
|
|
102
|
+class JitsiMeetExternalAPI {
|
|
|
103
|
+ /**
|
|
|
104
|
+ * Constructs new API instance. Creates iframe element that loads
|
|
|
105
|
+ * Jitsi Meet.
|
|
|
106
|
+ * @param domain the domain name of the server that hosts the conference
|
|
|
107
|
+ * @param room_name the name of the room to join
|
|
|
108
|
+ * @param width width of the iframe
|
|
|
109
|
+ * @param height height of the iframe
|
|
|
110
|
+ * @param parent_node the node that will contain the iframe
|
|
|
111
|
+ * @param configOverwrite object containing configuration options defined in
|
|
|
112
|
+ * config.js to be overridden.
|
|
|
113
|
+ * @param interfaceConfigOverwrite object containing configuration options
|
|
|
114
|
+ * defined in interface_config.js to be overridden.
|
|
|
115
|
+ * @param noSsl if the value is true https won't be used
|
|
|
116
|
+ * @param {string} [jwt] the JWT token if needed by jitsi-meet for
|
|
|
117
|
+ * authentication.
|
|
|
118
|
+ * @constructor
|
|
|
119
|
+ */
|
|
|
120
|
+ constructor(domain, room_name, width, height, parentNode,
|
|
|
121
|
+ configOverwrite, interfaceConfigOverwrite, noSsl, jwt) {
|
|
|
122
|
+ if (!width || width < MIN_WIDTH) {
|
|
|
123
|
+ width = MIN_WIDTH;
|
|
|
124
|
+ }
|
|
|
125
|
+ if (!height || height < MIN_HEIGHT) {
|
|
|
126
|
+ height = MIN_HEIGHT;
|
|
|
127
|
+ }
|
|
135
|
128
|
|
|
136
|
|
- this.iframeHolder =
|
|
137
|
|
- this.parentNode.appendChild(document.createElement("div"));
|
|
138
|
|
- this.iframeHolder.id = "jitsiConference" + id;
|
|
139
|
|
- if(width)
|
|
140
|
|
- this.iframeHolder.style.width = width + "px";
|
|
141
|
|
- if(height)
|
|
142
|
|
- this.iframeHolder.style.height = height + "px";
|
|
143
|
|
- this.frameName = "jitsiConferenceFrame" + id;
|
|
144
|
|
- this.url = (noSsl) ? "http" : "https" +"://" + domain + "/";
|
|
145
|
|
- if(room_name)
|
|
146
|
|
- this.url += room_name;
|
|
|
129
|
+ this.parentNode = null;
|
|
|
130
|
+ if (parentNode) {
|
|
|
131
|
+ this.parentNode = parentNode;
|
|
|
132
|
+ } else {
|
|
|
133
|
+ var scriptTag = document.scripts[document.scripts.length - 1];
|
|
|
134
|
+ this.parentNode = scriptTag.parentNode;
|
|
|
135
|
+ }
|
|
147
|
136
|
|
|
148
|
|
- if (jwt) {
|
|
149
|
|
- this.url += '?jwt=' + jwt;
|
|
150
|
|
- }
|
|
|
137
|
+ this.iframeHolder =
|
|
|
138
|
+ this.parentNode.appendChild(document.createElement("div"));
|
|
|
139
|
+ this.iframeHolder.id = "jitsiConference" + id;
|
|
|
140
|
+ if (width) {
|
|
|
141
|
+ this.iframeHolder.style.width = width + "px";
|
|
|
142
|
+ }
|
|
|
143
|
+ if (height) {
|
|
|
144
|
+ this.iframeHolder.style.height = height + "px";
|
|
|
145
|
+ }
|
|
|
146
|
+ this.frameName = "jitsiConferenceFrame" + id;
|
|
|
147
|
+ this.url = (noSsl) ? "http" : "https" +"://" + domain + "/";
|
|
|
148
|
+ if (room_name) {
|
|
|
149
|
+ this.url += room_name;
|
|
|
150
|
+ }
|
|
151
|
151
|
|
|
152
|
|
- this.url += "#jitsi_meet_external_api_id=" + id;
|
|
|
152
|
+ if (jwt) {
|
|
|
153
|
+ this.url += '?jwt=' + jwt;
|
|
|
154
|
+ }
|
|
153
|
155
|
|
|
154
|
|
- const configURLParams = configToURLParamsArray(configOverwrite);
|
|
155
|
|
- if (configURLParams.length) {
|
|
156
|
|
- this.url += '&config.' + configURLParams.join('&config.');
|
|
157
|
|
- }
|
|
|
156
|
+ this.url += "#jitsi_meet_external_api_id=" + id;
|
|
158
|
157
|
|
|
159
|
|
- const interfaceConfigURLParams
|
|
160
|
|
- = configToURLParamsArray(interfaceConfigOverwrite);
|
|
161
|
|
- if (interfaceConfigURLParams.length) {
|
|
162
|
|
- this.url += '&interfaceConfig.'
|
|
163
|
|
- + interfaceConfigURLParams.join('&interfaceConfig.');
|
|
164
|
|
- }
|
|
|
158
|
+ const configURLParams = configToURLParamsArray(configOverwrite);
|
|
|
159
|
+ if (configURLParams.length) {
|
|
|
160
|
+ this.url += '&config.' + configURLParams.join('&config.');
|
|
|
161
|
+ }
|
|
165
|
162
|
|
|
166
|
|
- this.frame = document.createElement("iframe");
|
|
167
|
|
- this.frame.src = this.url;
|
|
168
|
|
- this.frame.name = this.frameName;
|
|
169
|
|
- this.frame.id = this.frameName;
|
|
170
|
|
- this.frame.width = "100%";
|
|
171
|
|
- this.frame.height = "100%";
|
|
172
|
|
- this.frame.setAttribute("allowFullScreen","true");
|
|
173
|
|
- this.frame = this.iframeHolder.appendChild(this.frame);
|
|
174
|
|
- this.postis = postisInit({
|
|
175
|
|
- window: this.frame.contentWindow,
|
|
176
|
|
- scope: "jitsi_meet_external_api_" + id
|
|
177
|
|
- });
|
|
|
163
|
+ const interfaceConfigURLParams
|
|
|
164
|
+ = configToURLParamsArray(interfaceConfigOverwrite);
|
|
|
165
|
+ if (interfaceConfigURLParams.length) {
|
|
|
166
|
+ this.url += '&interfaceConfig.'
|
|
|
167
|
+ + interfaceConfigURLParams.join('&interfaceConfig.');
|
|
|
168
|
+ }
|
|
178
|
169
|
|
|
179
|
|
- this.eventHandlers = {};
|
|
|
170
|
+ this.frame = document.createElement("iframe");
|
|
|
171
|
+ this.frame.src = this.url;
|
|
|
172
|
+ this.frame.name = this.frameName;
|
|
|
173
|
+ this.frame.id = this.frameName;
|
|
|
174
|
+ this.frame.width = "100%";
|
|
|
175
|
+ this.frame.height = "100%";
|
|
|
176
|
+ this.frame.setAttribute("allowFullScreen","true");
|
|
|
177
|
+ this.frame = this.iframeHolder.appendChild(this.frame);
|
|
|
178
|
+ this.postis = postisInit({
|
|
|
179
|
+ window: this.frame.contentWindow,
|
|
|
180
|
+ scope: "jitsi_meet_external_api_" + id
|
|
|
181
|
+ });
|
|
180
|
182
|
|
|
181
|
|
- // Map<{string} event_name, {boolean} postis_listener_added>
|
|
182
|
|
- this.postisListeners = {};
|
|
|
183
|
+ this.eventHandlers = {};
|
|
183
|
184
|
|
|
184
|
|
- this.numberOfParticipants = 1;
|
|
185
|
|
- this._setupListeners();
|
|
|
185
|
+ // Map<{string} event_name, {boolean} postis_listener_added>
|
|
|
186
|
+ this.postisListeners = {};
|
|
186
|
187
|
|
|
187
|
|
- id++;
|
|
188
|
|
-}
|
|
|
188
|
+ this.numberOfParticipants = 1;
|
|
|
189
|
+ this._setupListeners();
|
|
189
|
190
|
|
|
190
|
|
-/**
|
|
191
|
|
- * Executes command. The available commands are:
|
|
192
|
|
- * displayName - sets the display name of the local participant to the value
|
|
193
|
|
- * passed in the arguments array.
|
|
194
|
|
- * toggleAudio - mutes / unmutes audio with no arguments
|
|
195
|
|
- * toggleVideo - mutes / unmutes video with no arguments
|
|
196
|
|
- * filmStrip - hides / shows the film strip with no arguments
|
|
197
|
|
- * If the command doesn't require any arguments the parameter should be set
|
|
198
|
|
- * to empty array or it may be omitted.
|
|
199
|
|
- * @param name the name of the command
|
|
200
|
|
- * @param arguments array of arguments
|
|
201
|
|
- */
|
|
202
|
|
-JitsiMeetExternalAPI.prototype.executeCommand
|
|
203
|
|
-= function(name, ...argumentsList) {
|
|
204
|
|
- if(!(name in commands)) {
|
|
205
|
|
- logger.error("Not supported command name.");
|
|
206
|
|
- return;
|
|
|
191
|
+ id++;
|
|
207
|
192
|
}
|
|
208
|
|
- sendMessage(this.postis, {method: commands[name], params: argumentsList});
|
|
209
|
|
-};
|
|
210
|
193
|
|
|
211
|
|
-/**
|
|
212
|
|
- * Executes commands. The available commands are:
|
|
213
|
|
- * displayName - sets the display name of the local participant to the value
|
|
214
|
|
- * passed in the arguments array.
|
|
215
|
|
- * toggleAudio - mutes / unmutes audio. no arguments
|
|
216
|
|
- * toggleVideo - mutes / unmutes video. no arguments
|
|
217
|
|
- * filmStrip - hides / shows the film strip. no arguments
|
|
218
|
|
- * toggleChat - hides / shows chat. no arguments.
|
|
219
|
|
- * toggleContactList - hides / shows contact list. no arguments.
|
|
220
|
|
- * toggleShareScreen - starts / stops screen sharing. no arguments.
|
|
221
|
|
- * @param object the object with commands to be executed. The keys of the
|
|
222
|
|
- * object are the commands that will be executed and the values are the
|
|
223
|
|
- * arguments for the command.
|
|
224
|
|
- */
|
|
225
|
|
-JitsiMeetExternalAPI.prototype.executeCommands = function(object) {
|
|
226
|
|
- for(var key in object)
|
|
227
|
|
- this.executeCommand(key, object[key]);
|
|
228
|
|
-};
|
|
|
194
|
+ /**
|
|
|
195
|
+ * Executes command. The available commands are:
|
|
|
196
|
+ * displayName - sets the display name of the local participant to the value
|
|
|
197
|
+ * passed in the arguments array.
|
|
|
198
|
+ * toggleAudio - mutes / unmutes audio with no arguments
|
|
|
199
|
+ * toggleVideo - mutes / unmutes video with no arguments
|
|
|
200
|
+ * filmStrip - hides / shows the film strip with no arguments
|
|
|
201
|
+ * If the command doesn't require any arguments the parameter should be set
|
|
|
202
|
+ * to empty array or it may be omitted.
|
|
|
203
|
+ * @param name the name of the command
|
|
|
204
|
+ * @param arguments array of arguments
|
|
|
205
|
+ */
|
|
|
206
|
+ executeCommand(name, ...argumentsList) {
|
|
|
207
|
+ if(!(name in commands)) {
|
|
|
208
|
+ logger.error("Not supported command name.");
|
|
|
209
|
+ return;
|
|
|
210
|
+ }
|
|
|
211
|
+ sendMessage(this.postis, {
|
|
|
212
|
+ method: commands[name],
|
|
|
213
|
+ params: argumentsList
|
|
|
214
|
+ });
|
|
|
215
|
+ }
|
|
229
|
216
|
|
|
230
|
|
-/**
|
|
231
|
|
- * Adds event listeners to Meet Jitsi. The object key should be the name of
|
|
232
|
|
- * the event and value - the listener.
|
|
233
|
|
- * Currently we support the following
|
|
234
|
|
- * events:
|
|
235
|
|
- * incomingMessage - receives event notifications about incoming
|
|
236
|
|
- * messages. The listener will receive object with the following structure:
|
|
237
|
|
- * {{
|
|
238
|
|
- * "from": from,//JID of the user that sent the message
|
|
239
|
|
- * "nick": nick,//the nickname of the user that sent the message
|
|
240
|
|
- * "message": txt//the text of the message
|
|
241
|
|
- * }}
|
|
242
|
|
- * outgoingMessage - receives event notifications about outgoing
|
|
243
|
|
- * messages. The listener will receive object with the following structure:
|
|
244
|
|
- * {{
|
|
245
|
|
- * "message": txt//the text of the message
|
|
246
|
|
- * }}
|
|
247
|
|
- * displayNameChanged - receives event notifications about display name
|
|
248
|
|
- * change. The listener will receive object with the following structure:
|
|
249
|
|
- * {{
|
|
250
|
|
- * jid: jid,//the JID of the participant that changed his display name
|
|
251
|
|
- * displayname: displayName //the new display name
|
|
252
|
|
- * }}
|
|
253
|
|
- * participantJoined - receives event notifications about new participant.
|
|
254
|
|
- * The listener will receive object with the following structure:
|
|
255
|
|
- * {{
|
|
256
|
|
- * jid: jid //the jid of the participant
|
|
257
|
|
- * }}
|
|
258
|
|
- * participantLeft - receives event notifications about the participant that
|
|
259
|
|
- * left the room.
|
|
260
|
|
- * The listener will receive object with the following structure:
|
|
261
|
|
- * {{
|
|
262
|
|
- * jid: jid //the jid of the participant
|
|
263
|
|
- * }}
|
|
264
|
|
- * video-conference-joined - receives event notifications about the local user
|
|
265
|
|
- * has successfully joined the video conference.
|
|
266
|
|
- * The listener will receive object with the following structure:
|
|
267
|
|
- * {{
|
|
268
|
|
- * roomName: room //the room name of the conference
|
|
269
|
|
- * }}
|
|
270
|
|
- * video-conference-left - receives event notifications about the local user
|
|
271
|
|
- * has left the video conference.
|
|
272
|
|
- * The listener will receive object with the following structure:
|
|
273
|
|
- * {{
|
|
274
|
|
- * roomName: room //the room name of the conference
|
|
275
|
|
- * }}
|
|
276
|
|
- * readyToClose - all hangup operations are completed and Jitsi Meet is ready
|
|
277
|
|
- * to be disposed.
|
|
278
|
|
- * @param object
|
|
279
|
|
- */
|
|
280
|
|
-JitsiMeetExternalAPI.prototype.addEventListeners = function(object) {
|
|
281
|
|
- for(var i in object)
|
|
282
|
|
- this.addEventListener(i, object[i]);
|
|
283
|
|
-};
|
|
|
217
|
+ /**
|
|
|
218
|
+ * Executes commands. The available commands are:
|
|
|
219
|
+ * displayName - sets the display name of the local participant to the value
|
|
|
220
|
+ * passed in the arguments array.
|
|
|
221
|
+ * toggleAudio - mutes / unmutes audio. no arguments
|
|
|
222
|
+ * toggleVideo - mutes / unmutes video. no arguments
|
|
|
223
|
+ * filmStrip - hides / shows the film strip. no arguments
|
|
|
224
|
+ * toggleChat - hides / shows chat. no arguments.
|
|
|
225
|
+ * toggleContactList - hides / shows contact list. no arguments.
|
|
|
226
|
+ * toggleShareScreen - starts / stops screen sharing. no arguments.
|
|
|
227
|
+ * @param object the object with commands to be executed. The keys of the
|
|
|
228
|
+ * object are the commands that will be executed and the values are the
|
|
|
229
|
+ * arguments for the command.
|
|
|
230
|
+ */
|
|
|
231
|
+ executeCommands(object) {
|
|
|
232
|
+ for (var key in object) {
|
|
|
233
|
+ this.executeCommand(key, object[key]);
|
|
|
234
|
+ }
|
|
|
235
|
+ }
|
|
284
|
236
|
|
|
285
|
|
-/**
|
|
286
|
|
- * Adds event listeners to Meet Jitsi. Currently we support the following
|
|
287
|
|
- * events:
|
|
288
|
|
- * incomingMessage - receives event notifications about incoming
|
|
289
|
|
- * messages. The listener will receive object with the following structure:
|
|
290
|
|
- * {{
|
|
291
|
|
- * "from": from,//JID of the user that sent the message
|
|
292
|
|
- * "nick": nick,//the nickname of the user that sent the message
|
|
293
|
|
- * "message": txt//the text of the message
|
|
294
|
|
- * }}
|
|
295
|
|
- * outgoingMessage - receives event notifications about outgoing
|
|
296
|
|
- * messages. The listener will receive object with the following structure:
|
|
297
|
|
- * {{
|
|
298
|
|
- * "message": txt//the text of the message
|
|
299
|
|
- * }}
|
|
300
|
|
- * displayNameChanged - receives event notifications about display name
|
|
301
|
|
- * change. The listener will receive object with the following structure:
|
|
302
|
|
- * {{
|
|
303
|
|
- * jid: jid,//the JID of the participant that changed his display name
|
|
304
|
|
- * displayname: displayName //the new display name
|
|
305
|
|
- * }}
|
|
306
|
|
- * participantJoined - receives event notifications about new participant.
|
|
307
|
|
- * The listener will receive object with the following structure:
|
|
308
|
|
- * {{
|
|
309
|
|
- * jid: jid //the jid of the participant
|
|
310
|
|
- * }}
|
|
311
|
|
- * participantLeft - receives event notifications about participant the that
|
|
312
|
|
- * left the room.
|
|
313
|
|
- * The listener will receive object with the following structure:
|
|
314
|
|
- * {{
|
|
315
|
|
- * jid: jid //the jid of the participant
|
|
316
|
|
- * }}
|
|
317
|
|
- * video-conference-joined - receives event notifications fired when the local
|
|
318
|
|
- * user has joined the video conference.
|
|
319
|
|
- * The listener will receive object with the following structure:
|
|
320
|
|
- * {{
|
|
321
|
|
- * roomName: room //the room name of the conference
|
|
322
|
|
- * }}
|
|
323
|
|
- * video-conference-left - receives event notifications fired when the local
|
|
324
|
|
- * user has joined the video conference.
|
|
325
|
|
- * The listener will receive object with the following structure:
|
|
326
|
|
- * {{
|
|
327
|
|
- * roomName: room //the room name of the conference
|
|
328
|
|
- * }}
|
|
329
|
|
- * @param event the name of the event
|
|
330
|
|
- * @param listener the listener
|
|
331
|
|
- */
|
|
332
|
|
-JitsiMeetExternalAPI.prototype.addEventListener = function(event, listener) {
|
|
333
|
|
- if(!(event in events)) {
|
|
334
|
|
- logger.error("Not supported event name.");
|
|
335
|
|
- return;
|
|
|
237
|
+ /**
|
|
|
238
|
+ * Adds event listeners to Meet Jitsi. The object key should be the name of
|
|
|
239
|
+ * the event and value - the listener.
|
|
|
240
|
+ * Currently we support the following
|
|
|
241
|
+ * events:
|
|
|
242
|
+ * incomingMessage - receives event notifications about incoming
|
|
|
243
|
+ * messages. The listener will receive object with the following structure:
|
|
|
244
|
+ * {{
|
|
|
245
|
+ * "from": from,//JID of the user that sent the message
|
|
|
246
|
+ * "nick": nick,//the nickname of the user that sent the message
|
|
|
247
|
+ * "message": txt//the text of the message
|
|
|
248
|
+ * }}
|
|
|
249
|
+ * outgoingMessage - receives event notifications about outgoing
|
|
|
250
|
+ * messages. The listener will receive object with the following structure:
|
|
|
251
|
+ * {{
|
|
|
252
|
+ * "message": txt//the text of the message
|
|
|
253
|
+ * }}
|
|
|
254
|
+ * displayNameChanged - receives event notifications about display name
|
|
|
255
|
+ * change. The listener will receive object with the following structure:
|
|
|
256
|
+ * {{
|
|
|
257
|
+ * jid: jid,//the JID of the participant that changed his display name
|
|
|
258
|
+ * displayname: displayName //the new display name
|
|
|
259
|
+ * }}
|
|
|
260
|
+ * participantJoined - receives event notifications about new participant.
|
|
|
261
|
+ * The listener will receive object with the following structure:
|
|
|
262
|
+ * {{
|
|
|
263
|
+ * jid: jid //the jid of the participant
|
|
|
264
|
+ * }}
|
|
|
265
|
+ * participantLeft - receives event notifications about the participant that
|
|
|
266
|
+ * left the room.
|
|
|
267
|
+ * The listener will receive object with the following structure:
|
|
|
268
|
+ * {{
|
|
|
269
|
+ * jid: jid //the jid of the participant
|
|
|
270
|
+ * }}
|
|
|
271
|
+ * video-conference-joined - receives event notifications about the local
|
|
|
272
|
+ * user has successfully joined the video conference.
|
|
|
273
|
+ * The listener will receive object with the following structure:
|
|
|
274
|
+ * {{
|
|
|
275
|
+ * roomName: room //the room name of the conference
|
|
|
276
|
+ * }}
|
|
|
277
|
+ * video-conference-left - receives event notifications about the local user
|
|
|
278
|
+ * has left the video conference.
|
|
|
279
|
+ * The listener will receive object with the following structure:
|
|
|
280
|
+ * {{
|
|
|
281
|
+ * roomName: room //the room name of the conference
|
|
|
282
|
+ * }}
|
|
|
283
|
+ * readyToClose - all hangup operations are completed and Jitsi Meet is
|
|
|
284
|
+ * ready to be disposed.
|
|
|
285
|
+ * @param object
|
|
|
286
|
+ */
|
|
|
287
|
+ addEventListeners(object) {
|
|
|
288
|
+ for (var i in object) {
|
|
|
289
|
+ this.addEventListener(i, object[i]);
|
|
|
290
|
+ }
|
|
336
|
291
|
}
|
|
337
|
|
- // We cannot remove listeners from postis that's why we are handling the
|
|
338
|
|
- // callback that way.
|
|
339
|
|
- if(!this.postisListeners[event]) {
|
|
340
|
|
- this.postis.listen(events[event], function(data) {
|
|
341
|
|
- if((event in this.eventHandlers) &&
|
|
342
|
|
- typeof this.eventHandlers[event] === "function")
|
|
343
|
|
- this.eventHandlers[event].call(null, data);
|
|
344
|
|
- }.bind(this));
|
|
345
|
|
- this.postisListeners[event] = true;
|
|
|
292
|
+
|
|
|
293
|
+ /**
|
|
|
294
|
+ * Adds event listeners to Meet Jitsi. Currently we support the following
|
|
|
295
|
+ * events:
|
|
|
296
|
+ * incomingMessage - receives event notifications about incoming
|
|
|
297
|
+ * messages. The listener will receive object with the following structure:
|
|
|
298
|
+ * {{
|
|
|
299
|
+ * "from": from,//JID of the user that sent the message
|
|
|
300
|
+ * "nick": nick,//the nickname of the user that sent the message
|
|
|
301
|
+ * "message": txt//the text of the message
|
|
|
302
|
+ * }}
|
|
|
303
|
+ * outgoingMessage - receives event notifications about outgoing
|
|
|
304
|
+ * messages. The listener will receive object with the following structure:
|
|
|
305
|
+ * {{
|
|
|
306
|
+ * "message": txt//the text of the message
|
|
|
307
|
+ * }}
|
|
|
308
|
+ * displayNameChanged - receives event notifications about display name
|
|
|
309
|
+ * change. The listener will receive object with the following structure:
|
|
|
310
|
+ * {{
|
|
|
311
|
+ * jid: jid,//the JID of the participant that changed his display name
|
|
|
312
|
+ * displayname: displayName //the new display name
|
|
|
313
|
+ * }}
|
|
|
314
|
+ * participantJoined - receives event notifications about new participant.
|
|
|
315
|
+ * The listener will receive object with the following structure:
|
|
|
316
|
+ * {{
|
|
|
317
|
+ * jid: jid //the jid of the participant
|
|
|
318
|
+ * }}
|
|
|
319
|
+ * participantLeft - receives event notifications about participant the that
|
|
|
320
|
+ * left the room.
|
|
|
321
|
+ * The listener will receive object with the following structure:
|
|
|
322
|
+ * {{
|
|
|
323
|
+ * jid: jid //the jid of the participant
|
|
|
324
|
+ * }}
|
|
|
325
|
+ * video-conference-joined - receives event notifications fired when the
|
|
|
326
|
+ * local user has joined the video conference.
|
|
|
327
|
+ * The listener will receive object with the following structure:
|
|
|
328
|
+ * {{
|
|
|
329
|
+ * roomName: room //the room name of the conference
|
|
|
330
|
+ * }}
|
|
|
331
|
+ * video-conference-left - receives event notifications fired when the local
|
|
|
332
|
+ * user has joined the video conference.
|
|
|
333
|
+ * The listener will receive object with the following structure:
|
|
|
334
|
+ * {{
|
|
|
335
|
+ * roomName: room //the room name of the conference
|
|
|
336
|
+ * }}
|
|
|
337
|
+ * @param event the name of the event
|
|
|
338
|
+ * @param listener the listener
|
|
|
339
|
+ */
|
|
|
340
|
+ addEventListener(event, listener) {
|
|
|
341
|
+ if (!(event in events)) {
|
|
|
342
|
+ logger.error("Not supported event name.");
|
|
|
343
|
+ return;
|
|
|
344
|
+ }
|
|
|
345
|
+ // We cannot remove listeners from postis that's why we are handling the
|
|
|
346
|
+ // callback that way.
|
|
|
347
|
+ if (!this.postisListeners[event]) {
|
|
|
348
|
+ this.postis.listen(events[event], data => {
|
|
|
349
|
+ if((event in this.eventHandlers) &&
|
|
|
350
|
+ typeof this.eventHandlers[event] === "function")
|
|
|
351
|
+ this.eventHandlers[event].call(null, data);
|
|
|
352
|
+ });
|
|
|
353
|
+ this.postisListeners[event] = true;
|
|
|
354
|
+ }
|
|
|
355
|
+ this.eventHandlers[event] = listener;
|
|
346
|
356
|
}
|
|
347
|
|
- this.eventHandlers[event] = listener;
|
|
348
|
|
-};
|
|
349
|
357
|
|
|
350
|
|
-/**
|
|
351
|
|
- * Removes event listener.
|
|
352
|
|
- * @param event the name of the event.
|
|
353
|
|
- */
|
|
354
|
|
-JitsiMeetExternalAPI.prototype.removeEventListener = function(event) {
|
|
355
|
|
- if(!(event in this.eventHandlers))
|
|
356
|
|
- {
|
|
357
|
|
- logger.error("The event " + event + " is not registered.");
|
|
358
|
|
- return;
|
|
|
358
|
+ /**
|
|
|
359
|
+ * Removes event listener.
|
|
|
360
|
+ * @param event the name of the event.
|
|
|
361
|
+ */
|
|
|
362
|
+ removeEventListener(event) {
|
|
|
363
|
+ if(!(event in this.eventHandlers))
|
|
|
364
|
+ {
|
|
|
365
|
+ logger.error("The event " + event + " is not registered.");
|
|
|
366
|
+ return;
|
|
|
367
|
+ }
|
|
|
368
|
+ delete this.eventHandlers[event];
|
|
359
|
369
|
}
|
|
360
|
|
- delete this.eventHandlers[event];
|
|
361
|
|
-};
|
|
362
|
370
|
|
|
363
|
|
-/**
|
|
364
|
|
- * Removes event listeners.
|
|
365
|
|
- * @param events array with the names of the events.
|
|
366
|
|
- */
|
|
367
|
|
-JitsiMeetExternalAPI.prototype.removeEventListeners = function(events) {
|
|
368
|
|
- for(var i = 0; i < events.length; i++)
|
|
369
|
|
- this.removeEventListener(events[i]);
|
|
370
|
|
-};
|
|
|
371
|
+ /**
|
|
|
372
|
+ * Removes event listeners.
|
|
|
373
|
+ * @param events array with the names of the events.
|
|
|
374
|
+ */
|
|
|
375
|
+ removeEventListeners(events) {
|
|
|
376
|
+ for(var i = 0; i < events.length; i++) {
|
|
|
377
|
+ this.removeEventListener(events[i]);
|
|
|
378
|
+ }
|
|
|
379
|
+ }
|
|
371
|
380
|
|
|
372
|
|
-/**
|
|
373
|
|
- * Returns the number of participants in the conference.
|
|
374
|
|
- * NOTE: the local participant is included.
|
|
375
|
|
- * @returns {int} the number of participants in the conference.
|
|
376
|
|
- */
|
|
377
|
|
-JitsiMeetExternalAPI.prototype.getNumberOfParticipants = function() {
|
|
378
|
|
- return this.numberOfParticipants;
|
|
379
|
|
-};
|
|
|
381
|
+ /**
|
|
|
382
|
+ * Returns the number of participants in the conference.
|
|
|
383
|
+ * NOTE: the local participant is included.
|
|
|
384
|
+ * @returns {int} the number of participants in the conference.
|
|
|
385
|
+ */
|
|
|
386
|
+ getNumberOfParticipants() {
|
|
|
387
|
+ return this.numberOfParticipants;
|
|
|
388
|
+ }
|
|
380
|
389
|
|
|
381
|
|
-/**
|
|
382
|
|
- * Setups listeners that are used internally for JitsiMeetExternalAPI.
|
|
383
|
|
- */
|
|
384
|
|
-JitsiMeetExternalAPI.prototype._setupListeners = function() {
|
|
385
|
|
- this.postis.listen("participant-joined",
|
|
386
|
|
- changeParticipantNumber.bind(null, this, 1));
|
|
387
|
|
- this.postis.listen("participant-left",
|
|
388
|
|
- changeParticipantNumber.bind(null, this, -1));
|
|
389
|
|
-};
|
|
|
390
|
+ /**
|
|
|
391
|
+ * Setups listeners that are used internally for JitsiMeetExternalAPI.
|
|
|
392
|
+ */
|
|
|
393
|
+ _setupListeners() {
|
|
|
394
|
+ this.postis.listen("participant-joined",
|
|
|
395
|
+ changeParticipantNumber.bind(null, this, 1));
|
|
|
396
|
+ this.postis.listen("participant-left",
|
|
|
397
|
+ changeParticipantNumber.bind(null, this, -1));
|
|
|
398
|
+ }
|
|
390
|
399
|
|
|
391
|
|
-/**
|
|
392
|
|
- * Removes the listeners and removes the Jitsi Meet frame.
|
|
393
|
|
- */
|
|
394
|
|
-JitsiMeetExternalAPI.prototype.dispose = function() {
|
|
395
|
|
- this.postis.destroy();
|
|
396
|
|
- var frame = document.getElementById(this.frameName);
|
|
397
|
|
- if(frame)
|
|
398
|
|
- frame.src = 'about:blank';
|
|
399
|
|
- var self = this;
|
|
400
|
|
- window.setTimeout(function () {
|
|
401
|
|
- self.iframeHolder.removeChild(self.frame);
|
|
402
|
|
- self.iframeHolder.parentNode.removeChild(self.iframeHolder);
|
|
403
|
|
- }, 10);
|
|
404
|
|
-};
|
|
|
400
|
+ /**
|
|
|
401
|
+ * Removes the listeners and removes the Jitsi Meet frame.
|
|
|
402
|
+ */
|
|
|
403
|
+ dispose() {
|
|
|
404
|
+ this.postis.destroy();
|
|
|
405
|
+ var frame = document.getElementById(this.frameName);
|
|
|
406
|
+ if(frame)
|
|
|
407
|
+ frame.src = 'about:blank';
|
|
|
408
|
+ window.setTimeout( () => {
|
|
|
409
|
+ this.iframeHolder.removeChild(this.frame);
|
|
|
410
|
+ this.iframeHolder.parentNode.removeChild(this.iframeHolder);
|
|
|
411
|
+ }, 10);
|
|
|
412
|
+ }
|
|
|
413
|
+}
|
|
405
|
414
|
|
|
406
|
415
|
module.exports = JitsiMeetExternalAPI;
|