|
|
@@ -1,5 +1,8 @@
|
|
1
|
1
|
import EventEmitter from 'events';
|
|
2
|
|
-import postisInit from 'postis';
|
|
|
2
|
+
|
|
|
3
|
+import PostMessageTransportBackend
|
|
|
4
|
+ from '../../transport/PostMessageTransportBackend';
|
|
|
5
|
+import Transport from '../../transport/Transport';
|
|
3
|
6
|
|
|
4
|
7
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
5
|
8
|
|
|
|
@@ -25,14 +28,14 @@ const commands = {
|
|
25
|
28
|
* events expected by jitsi-meet
|
|
26
|
29
|
*/
|
|
27
|
30
|
const events = {
|
|
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'
|
|
|
31
|
+ 'display-name-change': 'displayNameChange',
|
|
|
32
|
+ 'incoming-message': 'incomingMessage',
|
|
|
33
|
+ 'outgoing-message': 'outgoingMessage',
|
|
|
34
|
+ 'participant-joined': 'participantJoined',
|
|
|
35
|
+ 'participant-left': 'participantLeft',
|
|
|
36
|
+ 'video-ready-to-close': 'readyToClose',
|
|
|
37
|
+ 'video-conference-joined': 'videoConferenceJoined',
|
|
|
38
|
+ 'video-conference-left': 'videoConferenceLeft'
|
|
36
|
39
|
};
|
|
37
|
40
|
|
|
38
|
41
|
/**
|
|
|
@@ -180,9 +183,13 @@ class JitsiMeetExternalAPI extends EventEmitter {
|
|
180
|
183
|
});
|
|
181
|
184
|
this._createIFrame(Math.max(height, MIN_HEIGHT),
|
|
182
|
185
|
Math.max(width, MIN_WIDTH));
|
|
183
|
|
- this.postis = postisInit({
|
|
184
|
|
- scope: `jitsi_meet_external_api_${id}`,
|
|
185
|
|
- window: this.frame.contentWindow
|
|
|
186
|
+ this._transport = new Transport({
|
|
|
187
|
+ transport: new PostMessageTransportBackend({
|
|
|
188
|
+ postisOptions: {
|
|
|
189
|
+ scope: `jitsi_meet_external_api_${id}`,
|
|
|
190
|
+ window: this.frame.contentWindow
|
|
|
191
|
+ }
|
|
|
192
|
+ })
|
|
186
|
193
|
});
|
|
187
|
194
|
this.numberOfParticipants = 1;
|
|
188
|
195
|
this._setupListeners();
|
|
|
@@ -225,17 +232,28 @@ class JitsiMeetExternalAPI extends EventEmitter {
|
|
225
|
232
|
* @private
|
|
226
|
233
|
*/
|
|
227
|
234
|
_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
|
235
|
|
|
233
|
|
- for (const eventName in events) { // eslint-disable-line guard-for-in
|
|
234
|
|
- const postisMethod = events[eventName];
|
|
|
236
|
+ this._transport.on('event', event => {
|
|
|
237
|
+ const { name, data } = event;
|
|
235
|
238
|
|
|
236
|
|
- this.postis.listen(postisMethod,
|
|
237
|
|
- (...args) => this.emit(eventName, ...args));
|
|
238
|
|
- }
|
|
|
239
|
+ if (name === 'participant-joined') {
|
|
|
240
|
+ changeParticipantNumber(this, 1);
|
|
|
241
|
+ }
|
|
|
242
|
+
|
|
|
243
|
+ if (name === 'participant-left') {
|
|
|
244
|
+ changeParticipantNumber(this, -1);
|
|
|
245
|
+ }
|
|
|
246
|
+
|
|
|
247
|
+ const eventName = events[name];
|
|
|
248
|
+
|
|
|
249
|
+ if (eventName) {
|
|
|
250
|
+ this.emit(eventName, data);
|
|
|
251
|
+
|
|
|
252
|
+ return true;
|
|
|
253
|
+ }
|
|
|
254
|
+
|
|
|
255
|
+ return false;
|
|
|
256
|
+ });
|
|
239
|
257
|
}
|
|
240
|
258
|
|
|
241
|
259
|
/**
|
|
|
@@ -319,10 +337,7 @@ class JitsiMeetExternalAPI extends EventEmitter {
|
|
319
|
337
|
* @returns {void}
|
|
320
|
338
|
*/
|
|
321
|
339
|
dispose() {
|
|
322
|
|
- if (this.postis) {
|
|
323
|
|
- this.postis.destroy();
|
|
324
|
|
- this.postis = null;
|
|
325
|
|
- }
|
|
|
340
|
+ this._transport.dispose();
|
|
326
|
341
|
this.removeAllListeners();
|
|
327
|
342
|
if (this.iframeHolder) {
|
|
328
|
343
|
this.iframeHolder.parentNode.removeChild(this.iframeHolder);
|
|
|
@@ -348,16 +363,9 @@ class JitsiMeetExternalAPI extends EventEmitter {
|
|
348
|
363
|
|
|
349
|
364
|
return;
|
|
350
|
365
|
}
|
|
351
|
|
-
|
|
352
|
|
- if (!this.postis) {
|
|
353
|
|
- logger.error('Cannot execute command using disposed instance.');
|
|
354
|
|
-
|
|
355
|
|
- return;
|
|
356
|
|
- }
|
|
357
|
|
-
|
|
358
|
|
- this.postis.send({
|
|
359
|
|
- method: commands[name],
|
|
360
|
|
- params: args
|
|
|
366
|
+ this._transport.sendEvent({
|
|
|
367
|
+ name: commands[name],
|
|
|
368
|
+ data: args
|
|
361
|
369
|
});
|
|
362
|
370
|
}
|
|
363
|
371
|
|