[lib.content-controller] fixed recursive websocket restart
This commit is contained in:
parent
d077cdc909
commit
1c4db78b36
|
@ -150,15 +150,17 @@ 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 });
|
||||||
|
|
||||||
// 3. Bind events
|
// 3. Bind events
|
||||||
csock.onreceive = gs.get.content.ws_handler.bind({ event: 'receive' });
|
csock.onreceive = gs.get.content.ws_handler.bind({ event: 'receive' });
|
||||||
csock.onclose = gs.get.content.ws_handler.bind({ event: 'close' });
|
csock.onclose = gs.get.content.ws_handler.bind({ event: 'close' });
|
||||||
|
|
||||||
// 4. Start communication
|
// 4. Start communication
|
||||||
csock.bind();
|
csock.bind();
|
||||||
|
@ -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' )
|
||||||
|
|
Loading…
Reference in New Issue