-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjitsi_url_generator.js
62 lines (51 loc) · 1.43 KB
/
jitsi_url_generator.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
function JitsiUrlGenerator(callback, domain, roomName, paramGroups) {
this.callback = callback;
this.domain = domain || "";
this.roomName = roomName || "";
this.paramGroups = paramGroups || {};
}
JitsiUrlGenerator.prototype.trigger = function () {
// If domain or room name not set, trigger callback with empty url
if (!this.domain || !this.roomName) {
this.callback("");
return;
}
let params = [];
for (let group of Object.values(this.paramGroups)) {
params = params.concat(flattenParamGroup(group));
}
let url = "https://" + this.domain + "/" + this.roomName;
if (params.length > 0) {
url += '#' + params.join("&");
}
this.callback(url);
};
JitsiUrlGenerator.prototype.updateRoomName = function (roomName) {
this.roomName = roomName;
this.trigger();
return this;
};
JitsiUrlGenerator.prototype.updateDomain = function (domain) {
this.domain = domain;
this.trigger();
return this;
};
JitsiUrlGenerator.prototype.updateParamGroup = function (group, params) {
this.paramGroups[group] = params;
this.trigger();
return this;
};
function makeUrlGenerator(callback, domain, roomName, paramGroup) {
let urlGen = new JitsiUrlGenerator(callback, domain, roomName, paramGroup);
urlGen.trigger();
return urlGen;
}
function flattenParamGroup(group) {
let params = [];
for (let p in group) {
if (group.hasOwnProperty(p)) {
params.push(p + '=' + group[p]);
}
}
return params;
}