-
Notifications
You must be signed in to change notification settings - Fork 0
/
converser.js
38 lines (36 loc) · 1.59 KB
/
converser.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
function Client(apikey)
{
this.apikey = apikey;
var httpregisterdevice;
if (typeof XMLHttpRequest == "undefined")
XMLHttpRequest = function () {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {}
//Microsoft.XMLHTTP points to Msxml2.XMLHTTP and is redundant
throw new Error("This browser does not support XMLHttpRequest.");
};
this.registerdevice = function(useridentity, deviceos, devicemodel, successcb){
var dat = '{"ident" : "' + useridentity + '", "device" : { "os" : "' + deviceos + '", "model" : "' + devicemodel + '"}}';
console.log(dat);
console.log('dat.length :' + dat.length);
httpregisterdevice = new XMLHttpRequest();
httpregisterdevice.open("POST", "https://api.converser.io/subscribe", true);
httpregisterdevice.setRequestHeader("X-CONVERSER-APP-ID", this.apikey);
httpregisterdevice.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpregisterdevice.setRequestHeader("Content-length", dat.length);
httpregisterdevice.onreadystatechange = function() {
console.log(httpregisterdevice);
// httpregisterdevice.status == 200 no status in response
if(httpregisterdevice.readyState == 4) {
console.log(httpregisterdevice.getAllResponseHeaders());
console.log("recieved : " + httpregisterdevice.responseText);
successcb(httpregisterdevice.responseText);
}
}
httpregisterdevice.send(dat);
}
}