-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnctalkrooms.js
53 lines (43 loc) · 1.45 KB
/
nctalkrooms.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
class TalkRooms {
constructor(nchttp, capabilities) {
this.nchttp = nchttp;
this.capabilities = capabilities;
// Build url
let conversation_feature = capabilities.CheckFeature("conversation-v");
if (conversation_feature == "conversation-v4") {
this.conversationAPIversion = 4;
}
else {
this.conversationAPIversion = 2;
}
}
_geturl() {
return `/ocs/v2.php/apps/spreed/api/v${this.conversationAPIversion}/room?format=json`;
}
fetch(Callback) {
this.nchttp.RequestfromHost("GET", this._geturl(), null, (retcode, res) => {
switch (retcode) {
case "OK":
try {
this.roomlist = JSON.parse(res.body).ocs.data;
}
catch (e) {
this.roomlist = undefined;
Callback("ERROR", `ERROR reply string is not a JSON ${res.body}`);
break;
}
//console.log("TalkRooms get OK", this.roomlist);
Callback("OK", res);
break;
case "ERROR":
//console.log("TalkRooms get ERROR", res);
Callback("ERROR", res);
break;
}
});
}
getlistofrooms() {
return this.roomlist;
}
}
module.exports = TalkRooms;