-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnctalkcapabilities.js
56 lines (46 loc) · 1.74 KB
/
nctalkcapabilities.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
class TalkCapabilities {
constructor(nchttp) {
this.nchttp = nchttp;
this.conversationAPIversion = 0;
}
_geturl() {
return "/ocs/v1.php/cloud/capabilities?format=json";
}
get(Callback) {
this.nchttp.RequestfromHost("GET", this._geturl(), null, (retcode, res) => {
switch (retcode) {
case "OK":
//here we have the full response, html or json object findIndex
//ocs.data.capabilities.spreed.features
//payload.ocs.data.capabilities.spreed.features[0]
try {
this.capabilities = JSON.parse(res.body);
}
catch (e) {
this.capabilities = undefined;
Callback("ERROR", `Capabilities reply string is not a JSON ${res.body}`);
break;
}
this.spreedfeatures = this.capabilities.ocs.data.capabilities.spreed.features;
if (this.spreedfeatures.find((element) => element.includes("conversation")) == "conversation-v4") {
this.conversationAPIversion = 4;
}
else {
this.conversationAPIversion = 2;
}
Callback("OK", res);
break;
case "ERROR":
Callback("ERROR", res);
break;
}
});
}
GetConversationAPIVersion() {
return this.conversationAPIversion;
}
CheckFeature(str) {
return this.spreedfeatures.find((element) => element.includes(str));
}
}
module.exports = TalkCapabilities;