[lib.content-controller] fixed recursive websocket restart

This commit is contained in:
xdrm-brackets 2018-04-04 11:34:54 +02:00
parent d077cdc909
commit 1c4db78b36
1 changed files with 7 additions and 3 deletions

View File

@ -150,8 +150,10 @@ export default class ContentController{
console.warn(`new ws(/channel/${this.cid})`); console.warn(`new ws(/channel/${this.cid})`);
// 1. Close websocket if exists // 1. Close websocket if exists
if ( window.csock instanceof wscd ) if( window.csock instanceof wscd ){
csock.onclose = function(){}; // stop propagating recursive ws_connect()
csock.close(); csock.close();
}
// 2. Create new connection // 2. Create new connection
window.csock = new wscd(`wss://ws.douscord.xdrm.io/channel/${this.cid}`, { token: auth.token }); window.csock = new wscd(`wss://ws.douscord.xdrm.io/channel/${this.cid}`, { token: auth.token });
@ -177,9 +179,11 @@ export default class ContentController{
console.warn('ws(', this.event, _response || '', ')'); console.warn('ws(', this.event, _response || '', ')');
/* (1) Manage error */
if( this.event === null ) if( this.event === null )
return; return;
/* (2) CLOSE event -> reconnect in 500ms /* (2) CLOSE event -> reconnect in 500ms
---------------------------------------------------------*/ ---------------------------------------------------------*/
if( this.event === 'close' ) if( this.event === 'close' )