diff --git a/webpack/lib/content-controller.js b/webpack/lib/content-controller.js index 9acca39..84c6ad9 100644 --- a/webpack/lib/content-controller.js +++ b/webpack/lib/content-controller.js @@ -150,15 +150,17 @@ export default class ContentController{ console.warn(`new ws(/channel/${this.cid})`); // 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(); + } // 2. Create new connection window.csock = new wscd(`wss://ws.douscord.xdrm.io/channel/${this.cid}`, { token: auth.token }); // 3. Bind events - csock.onreceive = gs.get.content.ws_handler.bind({ event: 'receive' }); - csock.onclose = gs.get.content.ws_handler.bind({ event: 'close' }); + csock.onreceive = gs.get.content.ws_handler.bind({ event: 'receive' }); + csock.onclose = gs.get.content.ws_handler.bind({ event: 'close' }); // 4. Start communication csock.bind(); @@ -177,9 +179,11 @@ export default class ContentController{ console.warn('ws(', this.event, _response || '', ')'); + /* (1) Manage error */ if( this.event === null ) return; + /* (2) CLOSE event -> reconnect in 500ms ---------------------------------------------------------*/ if( this.event === 'close' )