use persistent autentication.

This commit is contained in:
Miroslav Šedivý 2020-11-28 15:28:11 +01:00
parent bc443cb3a0
commit f796eb236b
6 changed files with 14 additions and 15 deletions

View file

@ -25,14 +25,15 @@ export class NekoWebSocket extends EventEmitter<NekoWebSocketEvents> {
return typeof this._ws !== 'undefined' && this._ws.readyState === WebSocket.OPEN
}
public connect(url: string, password: string) {
public connect(url: string, id: string, secret: string) {
if (this.connected) {
throw new Error('attempting to create websocket while connection open')
}
this.emit('connecting')
this._ws = new WebSocket(`${url}ws?password=${password}`)
const ws_url = url.replace(/^http/, 'ws').replace(/\/$|\/ws$/, '')
this._ws = new WebSocket(`${ws_url}/ws?id=${encodeURIComponent(id)}&secret=${encodeURIComponent(secret)}`)
this._log.debug(`connecting to ${this._ws.url}`)
this._ws.onopen = this.onConnected.bind(this)