Implement WSHello

master
Harald Wolff 2019-11-26 12:22:27 +01:00
parent b870fe214c
commit 4f67439042
1 changed files with 34 additions and 1 deletions

View File

@ -192,7 +192,21 @@
this.closing = false;
this.websocket = new WebSocket(this.options.url);
this.websocket.onopen = (e) =>{ console.log("WebSocket connected"); this._state = "ONLINE"; };
this.websocket.onopen = (e) =>{
console.log("WebSocket connected");
this._state = "ONLINE";
let WSHello = {
ApplicationSessionID: this.LNVue.sessionID(),
};
console.log("WSHello request",WSHello);
this.request("WSHello",WSHello)
.then((wsh)=>{
console.log("WSHello response",wsh);
this.LNVue.sessionID(wsh.message.ApplicationSessionID);
});
};
this.websocket.onclose = (e)=>{ this._onclose(e); this._state = "OFFLINE"; };
this.websocket.onerror = (e)=>{ this._onerror(e); this._state = "ERROR"; };
this.websocket.onmessage = (e)=>{ this._onmessage(e); };
@ -345,7 +359,26 @@
});
}
storage(){
return window.localStorage;
}
sessionID(){
if (arguments.length == 1){
this.storage().setItem("LNVueSessionID",arguments[0]);
console.log("LNVue.SID <= " + arguments[0]);
return this;
} else
{
let sid = this.storage().getItem("LNVueSessionID");
console.log("LNVue.SID == " + sid);
if (!sid)
{
sid = "00000000-0000-0000-0000-000000000000";
}
return sid;
}
}
Version(){ return "0.2alpha"; };
getCurrentPromises() {