|
@@ -48,7 +48,7 @@ var JitsiMeetExternalAPI = (function()
|
48
|
48
|
this.iframeHolder.style.width = width + "px";
|
49
|
49
|
this.iframeHolder.style.height = height + "px";
|
50
|
50
|
this.frameName = "jitsiConferenceFrame" + JitsiMeetExternalAPI.id;
|
51
|
|
- this.url = "https://" + domain + "/";
|
|
51
|
+ this.url = "http://" + domain + "/";
|
52
|
52
|
if(room_name)
|
53
|
53
|
this.url += room_name;
|
54
|
54
|
this.url += "#external";
|
|
@@ -57,12 +57,16 @@ var JitsiMeetExternalAPI = (function()
|
57
|
57
|
this.frame = document.createElement("iframe");
|
58
|
58
|
this.frame.src = this.url;
|
59
|
59
|
this.frame.name = this.frameName;
|
|
60
|
+ this.frame.id = this.frameName;
|
60
|
61
|
this.frame.width = "100%";
|
61
|
62
|
this.frame.height = "100%";
|
|
63
|
+ this.frame.setAttribute("allowFullScreen","true");
|
62
|
64
|
this.frame = this.iframeHolder.appendChild(this.frame);
|
63
|
65
|
|
|
66
|
+
|
64
|
67
|
this.frameLoaded = false;
|
65
|
68
|
this.initialCommands = [];
|
|
69
|
+ this.eventHandlers = {};
|
66
|
70
|
this.initListeners();
|
67
|
71
|
}
|
68
|
72
|
|
|
@@ -108,7 +112,7 @@ var JitsiMeetExternalAPI = (function()
|
108
|
112
|
var argumentsArray = argumentsList;
|
109
|
113
|
if(!argumentsArray)
|
110
|
114
|
argumentsArray = [];
|
111
|
|
- var object = {};
|
|
115
|
+ var object = {type: "command", action: "execute"};
|
112
|
116
|
object[name] = argumentsArray;
|
113
|
117
|
this.sendMessage(object);
|
114
|
118
|
};
|
|
@@ -125,9 +129,147 @@ var JitsiMeetExternalAPI = (function()
|
125
|
129
|
* arguments for the command.
|
126
|
130
|
*/
|
127
|
131
|
JitsiMeetExternalAPI.prototype.executeCommands = function (object) {
|
|
132
|
+ object.type = "command";
|
|
133
|
+ object.action = "execute";
|
128
|
134
|
this.sendMessage(object);
|
129
|
135
|
};
|
130
|
136
|
|
|
137
|
+ /**
|
|
138
|
+ * Adds event listeners to Meet Jitsi. The object key should be the name of the
|
|
139
|
+ * event and value - the listener.
|
|
140
|
+ * Currently we support the following
|
|
141
|
+ * events:
|
|
142
|
+ * incommingMessage - receives event notifications about incomming
|
|
143
|
+ * messages. The listener will receive object with the following structure:
|
|
144
|
+ * {{
|
|
145
|
+ * "from": from,//JID of the user that sent the message
|
|
146
|
+ * "nick": nick,//the nickname of the user that sent the message
|
|
147
|
+ * "message": txt//the text of the message
|
|
148
|
+ * }}
|
|
149
|
+ * outgoingMessage - receives event notifications about outgoing
|
|
150
|
+ * messages. The listener will receive object with the following structure:
|
|
151
|
+ * {{
|
|
152
|
+ * "message": txt//the text of the message
|
|
153
|
+ * }}
|
|
154
|
+ * displayNameChanged - receives event notifications about display name
|
|
155
|
+ * change. The listener will receive object with the following structure:
|
|
156
|
+ * {{
|
|
157
|
+ * jid: jid,//the JID of the participant that changed his display name
|
|
158
|
+ * displayname: displayName //the new display name
|
|
159
|
+ * }}
|
|
160
|
+ * participantJoined - receives event notifications about new participant.
|
|
161
|
+ * The listener will receive object with the following structure:
|
|
162
|
+ * {{
|
|
163
|
+ * jid: jid //the jid of the participant
|
|
164
|
+ * }}
|
|
165
|
+ * participantLeft - receives event notifications about participant that left room.
|
|
166
|
+ * The listener will receive object with the following structure:
|
|
167
|
+ * {{
|
|
168
|
+ * jid: jid //the jid of the participant
|
|
169
|
+ * }}
|
|
170
|
+ * @param object
|
|
171
|
+ */
|
|
172
|
+ JitsiMeetExternalAPI.prototype.addEventListeners
|
|
173
|
+ = function (object)
|
|
174
|
+ {
|
|
175
|
+
|
|
176
|
+ var message = {type: "event", action: "add", events: []};
|
|
177
|
+ for(var i in object)
|
|
178
|
+ {
|
|
179
|
+ message.events.push(i);
|
|
180
|
+ this.eventHandlers[i] = object[i];
|
|
181
|
+ }
|
|
182
|
+ this.sendMessage(message);
|
|
183
|
+ };
|
|
184
|
+
|
|
185
|
+ /**
|
|
186
|
+ * Adds event listeners to Meet Jitsi. Currently we support the following
|
|
187
|
+ * events:
|
|
188
|
+ * incommingMessage - receives event notifications about incomming
|
|
189
|
+ * messages. The listener will receive object with the following structure:
|
|
190
|
+ * {{
|
|
191
|
+ * "from": from,//JID of the user that sent the message
|
|
192
|
+ * "nick": nick,//the nickname of the user that sent the message
|
|
193
|
+ * "message": txt//the text of the message
|
|
194
|
+ * }}
|
|
195
|
+ * outgoingMessage - receives event notifications about outgoing
|
|
196
|
+ * messages. The listener will receive object with the following structure:
|
|
197
|
+ * {{
|
|
198
|
+ * "message": txt//the text of the message
|
|
199
|
+ * }}
|
|
200
|
+ * displayNameChanged - receives event notifications about display name
|
|
201
|
+ * change. The listener will receive object with the following structure:
|
|
202
|
+ * {{
|
|
203
|
+ * jid: jid,//the JID of the participant that changed his display name
|
|
204
|
+ * displayname: displayName //the new display name
|
|
205
|
+ * }}
|
|
206
|
+ * participantJoined - receives event notifications about new participant.
|
|
207
|
+ * The listener will receive object with the following structure:
|
|
208
|
+ * {{
|
|
209
|
+ * jid: jid //the jid of the participant
|
|
210
|
+ * }}
|
|
211
|
+ * participantLeft - receives event notifications about participant that left room.
|
|
212
|
+ * The listener will receive object with the following structure:
|
|
213
|
+ * {{
|
|
214
|
+ * jid: jid //the jid of the participant
|
|
215
|
+ * }}
|
|
216
|
+ * @param event the name of the event
|
|
217
|
+ * @param listener the listener
|
|
218
|
+ */
|
|
219
|
+ JitsiMeetExternalAPI.prototype.addEventListener
|
|
220
|
+ = function (event, listener)
|
|
221
|
+ {
|
|
222
|
+
|
|
223
|
+ var message = {type: "event", action: "add", events: [event]};
|
|
224
|
+ this.eventHandlers[event] = listener;
|
|
225
|
+ this.sendMessage(message);
|
|
226
|
+ };
|
|
227
|
+
|
|
228
|
+ /**
|
|
229
|
+ * Removes event listener.
|
|
230
|
+ * @param event the name of the event.
|
|
231
|
+ */
|
|
232
|
+ JitsiMeetExternalAPI.prototype.removeEventListener
|
|
233
|
+ = function (event)
|
|
234
|
+ {
|
|
235
|
+ if(!this.eventHandlers[event])
|
|
236
|
+ {
|
|
237
|
+ console.error("The event " + event + " is not registered.");
|
|
238
|
+ return;
|
|
239
|
+ }
|
|
240
|
+ var message = {type: "event", action: "remove", events: [event]};
|
|
241
|
+ delete this.eventHandlers[event];
|
|
242
|
+ this.sendMessage(message);
|
|
243
|
+ };
|
|
244
|
+
|
|
245
|
+ /**
|
|
246
|
+ * Removes event listeners.
|
|
247
|
+ * @param events array with the names of the events.
|
|
248
|
+ */
|
|
249
|
+ JitsiMeetExternalAPI.prototype.removeEventListeners
|
|
250
|
+ = function (events)
|
|
251
|
+ {
|
|
252
|
+ var eventsArray = [];
|
|
253
|
+ for(var i = 0; i < events.length; i++)
|
|
254
|
+ {
|
|
255
|
+ var event = events[i];
|
|
256
|
+ if(!this.eventHandlers[event])
|
|
257
|
+ {
|
|
258
|
+ console.error("The event " + event + " is not registered.");
|
|
259
|
+ continue;
|
|
260
|
+ }
|
|
261
|
+ delete this.eventHandlers[event];
|
|
262
|
+ eventsArray.push(event);
|
|
263
|
+ }
|
|
264
|
+
|
|
265
|
+ if(eventsArray.length > 0)
|
|
266
|
+ {
|
|
267
|
+ this.sendMessage(
|
|
268
|
+ {type: "event", action: "remove", events: eventsArray});
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ };
|
|
272
|
+
|
131
|
273
|
/**
|
132
|
274
|
* Processes message events sent from Jitsi Meet
|
133
|
275
|
* @param event the event
|
|
@@ -138,11 +280,34 @@ var JitsiMeetExternalAPI = (function()
|
138
|
280
|
try {
|
139
|
281
|
message = JSON.parse(event.data);
|
140
|
282
|
} catch (e) {}
|
141
|
|
- if(message.loaded)
|
|
283
|
+
|
|
284
|
+ if(!message.type) {
|
|
285
|
+ console.error("Message without type is received.");
|
|
286
|
+ return;
|
|
287
|
+ }
|
|
288
|
+ switch (message.type)
|
142
|
289
|
{
|
143
|
|
- this.onFrameLoaded();
|
|
290
|
+ case "system":
|
|
291
|
+ if(message.loaded)
|
|
292
|
+ {
|
|
293
|
+ this.onFrameLoaded();
|
|
294
|
+ }
|
|
295
|
+ break;
|
|
296
|
+ case "event":
|
|
297
|
+ if(message.action != "result" ||
|
|
298
|
+ !message.event || !this.eventHandlers[message.event])
|
|
299
|
+ {
|
|
300
|
+ console.warn("The received event cannot be parsed.");
|
|
301
|
+ return;
|
|
302
|
+ }
|
|
303
|
+ this.eventHandlers[message.event](message.result);
|
|
304
|
+ break;
|
|
305
|
+ default :
|
|
306
|
+ console.error("Unknown message type.");
|
|
307
|
+ return;
|
144
|
308
|
}
|
145
|
309
|
|
|
310
|
+
|
146
|
311
|
};
|
147
|
312
|
|
148
|
313
|
/**
|
|
@@ -191,7 +356,14 @@ var JitsiMeetExternalAPI = (function()
|
191
|
356
|
window.detachEvent('onmessage',
|
192
|
357
|
this.eventListener);
|
193
|
358
|
}
|
194
|
|
- this.iframeHolder.parentNode.removeChild(this.iframeHolder);
|
|
359
|
+ var frame = document.getElementById(this.frameName);
|
|
360
|
+ if(frame)
|
|
361
|
+ frame.src = 'about:blank';
|
|
362
|
+ var self = this;
|
|
363
|
+ window.setTimeout(function () {
|
|
364
|
+ self.iframeHolder.removeChild(self.frame);
|
|
365
|
+ self.iframeHolder.parentNode.removeChild(self.iframeHolder);
|
|
366
|
+ }, 10);
|
195
|
367
|
};
|
196
|
368
|
|
197
|
369
|
return JitsiMeetExternalAPI;
|