|
@@ -1,11 +1,5 @@
|
1
|
1
|
/* global APP, getConfigParamsFromUrl */
|
2
|
2
|
|
3
|
|
-/**
|
4
|
|
- * Implements API class that communicates with external api class
|
5
|
|
- * and provides interface to access Jitsi Meet features by external
|
6
|
|
- * applications that embed Jitsi Meet
|
7
|
|
- */
|
8
|
|
-
|
9
|
3
|
import postisInit from 'postis';
|
10
|
4
|
|
11
|
5
|
import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
|
|
@@ -13,27 +7,27 @@ import * as JitsiMeetConferenceEvents from '../../ConferenceEvents';
|
13
|
7
|
/**
|
14
|
8
|
* List of the available commands.
|
15
|
9
|
* @type {{
|
16
|
|
- * displayName: inputDisplayNameHandler,
|
17
|
|
- * toggleAudio: toggleAudio,
|
18
|
|
- * toggleVideo: toggleVideo,
|
19
|
|
- * toggleFilmStrip: toggleFilmStrip,
|
20
|
|
- * toggleChat: toggleChat,
|
21
|
|
- * toggleContactList: toggleContactList
|
22
|
|
- * }}
|
|
10
|
+ * displayName: inputDisplayNameHandler,
|
|
11
|
+ * toggleAudio: toggleAudio,
|
|
12
|
+ * toggleVideo: toggleVideo,
|
|
13
|
+ * toggleFilmStrip: toggleFilmStrip,
|
|
14
|
+ * toggleChat: toggleChat,
|
|
15
|
+ * toggleContactList: toggleContactList
|
|
16
|
+ * }}
|
23
|
17
|
*/
|
24
|
18
|
let commands = {};
|
25
|
19
|
|
26
|
|
-let hashParams = getConfigParamsFromUrl();
|
|
20
|
+const hashParams = getConfigParamsFromUrl();
|
27
|
21
|
|
28
|
22
|
/**
|
29
|
23
|
* JitsiMeetExternalAPI id - unique for a webpage.
|
30
|
24
|
*/
|
31
|
|
-let jitsi_meet_external_api_id = hashParams.jitsi_meet_external_api_id;
|
|
25
|
+const jitsiMeetExternalApiId = hashParams.jitsi_meet_external_api_id;
|
32
|
26
|
|
33
|
27
|
/**
|
34
|
28
|
* Object that will execute sendMessage
|
35
|
29
|
*/
|
36
|
|
-let target = window.opener ? window.opener : window.parent;
|
|
30
|
+const target = window.opener ? window.opener : window.parent;
|
37
|
31
|
|
38
|
32
|
/**
|
39
|
33
|
* Postis instance. Used to communicate with the external application.
|
|
@@ -64,56 +58,64 @@ function toggleScreenSharing() {
|
64
|
58
|
}
|
65
|
59
|
}
|
66
|
60
|
|
|
61
|
+/**
|
|
62
|
+ * Initializes supported commands.
|
|
63
|
+ *
|
|
64
|
+ * @returns {void}
|
|
65
|
+ */
|
67
|
66
|
function initCommands() {
|
68
|
67
|
commands = {
|
69
|
|
- "display-name":
|
|
68
|
+ 'display-name':
|
70
|
69
|
APP.conference.changeLocalDisplayName.bind(APP.conference),
|
71
|
|
- "toggle-audio": APP.conference.toggleAudioMuted.bind(APP.conference),
|
72
|
|
- "toggle-video": APP.conference.toggleVideoMuted.bind(APP.conference),
|
73
|
|
- "toggle-film-strip": APP.UI.toggleFilmstrip,
|
74
|
|
- "toggle-chat": APP.UI.toggleChat,
|
75
|
|
- "toggle-contact-list": APP.UI.toggleContactList,
|
76
|
|
- "toggle-share-screen": toggleScreenSharing,
|
77
|
|
- "video-hangup": () => APP.conference.hangup(),
|
78
|
|
- "email": APP.conference.changeLocalEmail,
|
79
|
|
- "avatar-url": APP.conference.changeLocalAvatarUrl,
|
80
|
|
- "remote-control-event": event =>
|
81
|
|
- APP.remoteControl.onRemoteControlAPIEvent(event)
|
|
70
|
+ 'toggle-audio': APP.conference.toggleAudioMuted.bind(APP.conference),
|
|
71
|
+ 'toggle-video': APP.conference.toggleVideoMuted.bind(APP.conference),
|
|
72
|
+ 'toggle-film-strip': APP.UI.toggleFilmstrip,
|
|
73
|
+ 'toggle-chat': APP.UI.toggleChat,
|
|
74
|
+ 'toggle-contact-list': APP.UI.toggleContactList,
|
|
75
|
+ 'toggle-share-screen': toggleScreenSharing,
|
|
76
|
+ 'video-hangup': () => APP.conference.hangup(),
|
|
77
|
+ 'email': APP.conference.changeLocalEmail,
|
|
78
|
+ 'avatar-url': APP.conference.changeLocalAvatarUrl,
|
|
79
|
+ 'remote-control-event':
|
|
80
|
+ event => APP.remoteControl.onRemoteControlAPIEvent(event)
|
82
|
81
|
};
|
83
|
|
- Object.keys(commands).forEach(function (key) {
|
84
|
|
- postis.listen(key, args => commands[key](...args));
|
85
|
|
- });
|
|
82
|
+ Object.keys(commands).forEach(
|
|
83
|
+ key => postis.listen(key, args => commands[key](...args)));
|
86
|
84
|
}
|
87
|
85
|
|
88
|
86
|
/**
|
89
|
87
|
* Sends message to the external application.
|
90
|
|
- * @param message {object}
|
91
|
|
- * @param method {string}
|
92
|
|
- * @param params {object} the object that will be sent as JSON string
|
|
88
|
+ *
|
|
89
|
+ * @param {Object} message - The message to be sent.
|
|
90
|
+ * @returns {void}
|
93
|
91
|
*/
|
94
|
92
|
function sendMessage(message) {
|
95
|
|
- if(enabled) {
|
|
93
|
+ if (enabled) {
|
96
|
94
|
postis.send(message);
|
97
|
95
|
}
|
98
|
96
|
}
|
99
|
97
|
|
100
|
98
|
/**
|
101
|
99
|
* Check whether the API should be enabled or not.
|
|
100
|
+ *
|
102
|
101
|
* @returns {boolean}
|
103
|
102
|
*/
|
104
|
|
-function shouldBeEnabled () {
|
105
|
|
- return (typeof jitsi_meet_external_api_id === "number");
|
|
103
|
+function shouldBeEnabled() {
|
|
104
|
+ return typeof jitsiMeetExternalApiId === 'number';
|
106
|
105
|
}
|
107
|
106
|
|
108
|
107
|
/**
|
109
|
108
|
* Sends event object to the external application that has been subscribed
|
110
|
109
|
* for that event.
|
111
|
|
- * @param name the name event
|
112
|
|
- * @param object data associated with the event
|
|
110
|
+ *
|
|
111
|
+ * @param {string} name - The name event.
|
|
112
|
+ * @param {Object} object - Data associated with the event.
|
|
113
|
+ * @returns {void}
|
113
|
114
|
*/
|
114
|
|
-function triggerEvent (name, object) {
|
115
|
|
- if(enabled) {
|
116
|
|
- sendMessage({method: name, params: object});
|
|
115
|
+function triggerEvent(name, object) {
|
|
116
|
+ if (enabled) {
|
|
117
|
+ sendMessage({ method: name,
|
|
118
|
+ params: object });
|
117
|
119
|
}
|
118
|
120
|
}
|
119
|
121
|
|
|
@@ -130,24 +132,27 @@ function onScreenSharingEnable(enabled = false) {
|
130
|
132
|
}
|
131
|
133
|
}
|
132
|
134
|
|
|
135
|
+/**
|
|
136
|
+ * Implements API class that communicates with external api class
|
|
137
|
+ * and provides interface to access Jitsi Meet features by external
|
|
138
|
+ * applications that embed Jitsi Meet
|
|
139
|
+ */
|
133
|
140
|
class API {
|
134
|
|
- /**
|
135
|
|
- * Constructs new instance
|
136
|
|
- * @constructor
|
137
|
|
- */
|
138
|
|
- constructor() { }
|
139
|
|
-
|
140
|
141
|
/**
|
141
|
142
|
* Initializes the APIConnector. Setups message event listeners that will
|
142
|
143
|
* receive information from external applications that embed Jitsi Meet.
|
143
|
144
|
* It also sends a message to the external application that APIConnector
|
144
|
145
|
* is initialized.
|
145
|
|
- * @param options {object}
|
146
|
|
- * @param forceEnable {boolean} if true the module will be enabled.
|
|
146
|
+ *
|
|
147
|
+ * @param {Object} options - Optional parameters.
|
|
148
|
+ * @param {boolean} options.forceEnable - If true the module will be
|
|
149
|
+ * enabled.
|
|
150
|
+ * @returns {void}
|
147
|
151
|
*/
|
148
|
|
- init (options = {}) {
|
149
|
|
- if(!shouldBeEnabled() && !options.forceEnable)
|
|
152
|
+ init(options = {}) {
|
|
153
|
+ if (!shouldBeEnabled() && !options.forceEnable) {
|
150
|
154
|
return;
|
|
155
|
+ }
|
151
|
156
|
|
152
|
157
|
if(!enabled) {
|
153
|
158
|
APP.conference.addListener(
|
|
@@ -156,122 +161,150 @@ class API {
|
156
|
161
|
enabled = true;
|
157
|
162
|
}
|
158
|
163
|
|
159
|
|
- if(!postis) {
|
|
164
|
+ if (!postis) {
|
160
|
165
|
this._initPostis();
|
161
|
166
|
}
|
162
|
167
|
}
|
163
|
168
|
|
164
|
169
|
/**
|
165
|
|
- * initializes postis library.
|
|
170
|
+ * Initializes postis library.
|
|
171
|
+ *
|
|
172
|
+ * @returns {void}
|
|
173
|
+ *
|
166
|
174
|
* @private
|
167
|
175
|
*/
|
168
|
176
|
_initPostis() {
|
169
|
|
- let postisOptions = {
|
|
177
|
+ const postisOptions = {
|
170
|
178
|
window: target
|
171
|
179
|
};
|
172
|
|
- if(typeof jitsi_meet_external_api_id === "number")
|
|
180
|
+
|
|
181
|
+ if (typeof jitsiMeetExternalApiId === 'number') {
|
173
|
182
|
postisOptions.scope
|
174
|
|
- = "jitsi_meet_external_api_" + jitsi_meet_external_api_id;
|
|
183
|
+ = `jitsi_meet_external_api_${jitsiMeetExternalApiId}`;
|
|
184
|
+ }
|
175
|
185
|
postis = postisInit(postisOptions);
|
176
|
186
|
initCommands();
|
177
|
187
|
}
|
178
|
188
|
|
179
|
189
|
/**
|
180
|
190
|
* Notify external application (if API is enabled) that message was sent.
|
181
|
|
- * @param {string} body message body
|
|
191
|
+ *
|
|
192
|
+ * @param {string} body - Message body.
|
|
193
|
+ * @returns {void}
|
182
|
194
|
*/
|
183
|
|
- notifySendingChatMessage (body) {
|
184
|
|
- triggerEvent("outgoing-message", {"message": body});
|
|
195
|
+ notifySendingChatMessage(body) {
|
|
196
|
+ triggerEvent('outgoing-message', { 'message': body });
|
185
|
197
|
}
|
186
|
198
|
|
187
|
199
|
/**
|
188
|
200
|
* Notify external application (if API is enabled) that
|
189
|
201
|
* message was received.
|
190
|
|
- * @param {string} id user id
|
191
|
|
- * @param {string} nick user nickname
|
192
|
|
- * @param {string} body message body
|
193
|
|
- * @param {number} ts message creation timestamp
|
|
202
|
+ *
|
|
203
|
+ * @param {Object} options - Object with the message properties.
|
|
204
|
+ * @returns {void}
|
194
|
205
|
*/
|
195
|
|
- notifyReceivedChatMessage (id, nick, body, ts) {
|
|
206
|
+ notifyReceivedChatMessage(options = {}) {
|
|
207
|
+ const { id, nick, body, ts } = options;
|
|
208
|
+
|
196
|
209
|
if (APP.conference.isLocalId(id)) {
|
197
|
210
|
return;
|
198
|
211
|
}
|
199
|
212
|
|
200
|
213
|
triggerEvent(
|
201
|
|
- "incoming-message",
|
202
|
|
- {"from": id, "nick": nick, "message": body, "stamp": ts}
|
|
214
|
+ 'incoming-message',
|
|
215
|
+ { 'from': id,
|
|
216
|
+ 'nick': nick,
|
|
217
|
+ 'message': body,
|
|
218
|
+ 'stamp': ts }
|
203
|
219
|
);
|
204
|
220
|
}
|
205
|
221
|
|
206
|
222
|
/**
|
207
|
223
|
* Notify external application (if API is enabled) that
|
208
|
224
|
* user joined the conference.
|
209
|
|
- * @param {string} id user id
|
|
225
|
+ *
|
|
226
|
+ * @param {string} id - User id.
|
|
227
|
+ * @returns {void}
|
210
|
228
|
*/
|
211
|
|
- notifyUserJoined (id) {
|
212
|
|
- triggerEvent("participant-joined", {id});
|
|
229
|
+ notifyUserJoined(id) {
|
|
230
|
+ triggerEvent('participant-joined', { id });
|
213
|
231
|
}
|
214
|
232
|
|
215
|
233
|
/**
|
216
|
234
|
* Notify external application (if API is enabled) that
|
217
|
235
|
* user left the conference.
|
218
|
|
- * @param {string} id user id
|
|
236
|
+ *
|
|
237
|
+ * @param {string} id - User id.
|
|
238
|
+ * @returns {void}
|
219
|
239
|
*/
|
220
|
|
- notifyUserLeft (id) {
|
221
|
|
- triggerEvent("participant-left", {id});
|
|
240
|
+ notifyUserLeft(id) {
|
|
241
|
+ triggerEvent('participant-left', { id });
|
222
|
242
|
}
|
223
|
243
|
|
224
|
244
|
/**
|
225
|
245
|
* Notify external application (if API is enabled) that
|
226
|
246
|
* user changed their nickname.
|
227
|
|
- * @param {string} id user id
|
228
|
|
- * @param {string} displayName user nickname
|
|
247
|
+ *
|
|
248
|
+ * @param {string} id - User id.
|
|
249
|
+ * @param {string} displayName - User nickname.
|
|
250
|
+ * @returns {void}
|
229
|
251
|
*/
|
230
|
|
- notifyDisplayNameChanged (id, displayName) {
|
231
|
|
- triggerEvent("display-name-change", {id, displayname: displayName});
|
|
252
|
+ notifyDisplayNameChanged(id, displayName) {
|
|
253
|
+ triggerEvent('display-name-change', { id,
|
|
254
|
+ displayname: displayName });
|
232
|
255
|
}
|
233
|
256
|
|
234
|
257
|
/**
|
235
|
258
|
* Notify external application (if API is enabled) that
|
236
|
|
- * user changed their nickname.
|
237
|
|
- * @param {string} id user id
|
238
|
|
- * @param {string} displayName user nickname
|
|
259
|
+ * the conference has been joined.
|
|
260
|
+ *
|
|
261
|
+ * @param {string} room - The room name.
|
|
262
|
+ * @returns {void}
|
239
|
263
|
*/
|
240
|
|
- notifyConferenceJoined (room) {
|
241
|
|
- triggerEvent("video-conference-joined", {roomName: room});
|
|
264
|
+ notifyConferenceJoined(room) {
|
|
265
|
+ triggerEvent('video-conference-joined', { roomName: room });
|
242
|
266
|
}
|
243
|
267
|
|
244
|
268
|
/**
|
245
|
269
|
* Notify external application (if API is enabled) that
|
246
|
270
|
* user changed their nickname.
|
247
|
|
- * @param {string} id user id
|
248
|
|
- * @param {string} displayName user nickname
|
|
271
|
+ *
|
|
272
|
+ * @param {string} room - User id.
|
|
273
|
+ * @param {string} displayName - User nickname.
|
|
274
|
+ * @returns {void}
|
249
|
275
|
*/
|
250
|
|
- notifyConferenceLeft (room) {
|
251
|
|
- triggerEvent("video-conference-left", {roomName: room});
|
|
276
|
+ notifyConferenceLeft(room) {
|
|
277
|
+ triggerEvent('video-conference-left', { roomName: room });
|
252
|
278
|
}
|
253
|
279
|
|
254
|
280
|
/**
|
255
|
281
|
* Notify external application (if API is enabled) that
|
256
|
282
|
* we are ready to be closed.
|
|
283
|
+ *
|
|
284
|
+ * @returns {void}
|
257
|
285
|
*/
|
258
|
|
- notifyReadyToClose () {
|
259
|
|
- triggerEvent("video-ready-to-close", {});
|
|
286
|
+ notifyReadyToClose() {
|
|
287
|
+ triggerEvent('video-ready-to-close', {});
|
260
|
288
|
}
|
261
|
289
|
|
262
|
290
|
/**
|
263
|
291
|
* Sends remote control event.
|
264
|
|
- * @param {RemoteControlEvent} event the remote control event.
|
|
292
|
+ *
|
|
293
|
+ * @param {RemoteControlEvent} event - The remote control event.
|
|
294
|
+ * @returns {void}
|
265
|
295
|
*/
|
266
|
296
|
sendRemoteControlEvent(event) {
|
267
|
|
- sendMessage({method: "remote-control-event", params: event});
|
|
297
|
+ sendMessage({ method: 'remote-control-event',
|
|
298
|
+ params: event });
|
268
|
299
|
}
|
269
|
300
|
|
270
|
301
|
/**
|
271
|
302
|
* Removes the listeners.
|
|
303
|
+ *
|
|
304
|
+ * @returns {void}
|
272
|
305
|
*/
|
273
|
|
- dispose () {
|
274
|
|
- if(enabled) {
|
|
306
|
+ dispose() {
|
|
307
|
+ if (enabled) {
|
275
|
308
|
postis.destroy();
|
276
|
309
|
APP.conference.removeListener(
|
277
|
310
|
JitsiMeetConferenceEvents.DESKTOP_SHARING_ENABLED_CHANGED,
|