From 360c2f7133a1707dbd670bd842cbadf32fda6dd8 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 4 Dec 2017 16:38:34 +0100 Subject: [PATCH] Now ws-client only targets _onmessage when same URL+URI --- view/lib/ws-client-es6.js | 4 ++++ view/main.js | 17 +++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/view/lib/ws-client-es6.js b/view/lib/ws-client-es6.js index bf8a357..df4443f 100644 --- a/view/lib/ws-client-es6.js +++ b/view/lib/ws-client-es6.js @@ -132,6 +132,10 @@ class WSClient{ return; } + /* (3) If not for this channel -> exit */ + if( msg_event.target.url != this.server_url+'/'+this.channel_uri ) + return; + /* (3) Try to JSON parse */ var parsedMsg = null; try{ diff --git a/view/main.js b/view/main.js index cc0e510..125c46d 100755 --- a/view/main.js +++ b/view/main.js @@ -38,10 +38,11 @@ new Vue({ /* (1) Connection channel */ window.wsc_connect = window.wsc.channel('connect').listen(function(msg, err){ + console.log('connect received', msg, err); // {1} Manage error // if( msg == null && err != null ){ window.gstore.data.info.message = 'Erreur de connexion WebSocket@connect ('+err+')'; - window.gstore.data.info.type = 'warning'; + window.gstore.data.info.type = 'error'; window.gstore.data.info.active = true; setTimeout(function(){ window.gstore.data.info.active=false; }, 5000); /*TEMP*/return; @@ -49,10 +50,9 @@ window.wsc_connect = window.wsc.channel('connect').listen(function(msg, err){ } // {2} Manage wsclient error // - if( msg.connected == null || msg.error == null || msg.error !== 0 ){ + if( msg.connected == null || typeof msg.error != 'boolean' || msg.error !== false ){ console.warn('websocket error: '+msg.error); - if( msg.error == null ) window.gstore.data.info.message = 'Erreur de connexion WebSocket@connect (Unknown Error)'; - else window.gstore.data.info.message = 'Erreur de connexion WebSocket@connect ('+msg.error+')'; + window.gstore.data.info.message = 'Erreur de connexion WebSocket@connect'; window.gstore.data.info.type = 'warning'; window.gstore.data.info.active = true; setTimeout(function(){ window.gstore.data.info.active=false; }, 5000); @@ -69,10 +69,12 @@ window.wsc_connect = window.wsc.channel('connect').listen(function(msg, err){ /* (2) Message channel */ window.wsc_chat = window.wsc.channel('chat').listen(function(msg, err){ + console.log('chat received', msg, err); + // {1} Manage error // if( msg == null && err != null ){ window.gstore.data.info.message = 'Erreur de connexion WebSocket@connect ('+err+')'; - window.gstore.data.info.type = 'warning'; + window.gstore.data.info.type = 'error'; window.gstore.data.info.active = true; setTimeout(function(){ window.gstore.data.info.active=false; }, 5000); /*TEMP*/return; @@ -80,10 +82,9 @@ window.wsc_chat = window.wsc.channel('chat').listen(function(msg, err){ } // {2} Manage wsclient error // - if( msg.msg == null || msg.error == null || msg.error !== 0 ){ + if( msg.msg == null || typeof msg.error != 'boolean' || msg.error !== false ){ console.warn('websocket error: '+msg.error); - if( msg.error == null ) window.gstore.data.info.message = 'Erreur de connexion WebSocket@connect (Unknown Error)'; - else window.gstore.data.info.message = 'Erreur de connexion WebSocket@connect ('+msg.error+')'; + window.gstore.data.info.message = 'Erreur de connexion WebSocket@connect'; window.gstore.data.info.type = 'warning'; window.gstore.data.info.active = true; setTimeout(function(){ window.gstore.data.info.active=false; }, 5000);