-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-jitsi.js
71 lines (65 loc) · 1.72 KB
/
MMM-jitsi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Module.register("MMM-jitsi", {
// Default module config.
defaults: {
domain: "meet.jit.si",
launchOnStart: true,
options: {}
},
// Generates dom object
getDom: function() {
this.wrapper = document.createElement("div");
if (this.config.launchOnStart) {
this.startJitsi();
}
return this.wrapper;
},
// adds IFrame to wrapper
startJitsi: function() {
if (!this.api) {
this.config.options.parentNode = this.wrapper;
this.api = new JitsiMeetExternalAPI(
this.config.domain,
this.config.options
);
}
},
// disposes of IFrame
disposeJitsi: function() {
if (this.api) {
this.api.dispose();
this.api = null;
}
},
// toggle between launching and disposing jitsi
toggleJitsi: function() {
if (this.api) {
this.disposeJitsi();
} else {
this.startJitsi();
}
},
// Load JitsiMeetExternalAPI
getScripts: function() {
return ["https://meet.jit.si/external_api.js"];
},
// Wrapper around Jitsi API commands and event listeners.
notificationReceived: function(notification, payload, _sender) {
if (notification.startsWith("JITSI-")) {
let command = notification.substr(6);
if (command == "START") {
this.startJitsi();
} else if (command == "DISPOSE") {
this.disposeJitsi();
} else if (command == "TOGGLE") {
this.toggleJitsi();
} else if (command.startsWith("EventListener-")) {
let event = notification.substr(14);
this.api.addEventListener(event, payload);
} else if (command == "COMMANDS") {
this.api.executeCommand(payload);
} else {
this.api.executeCommand(command, payload);
}
}
}
});