Closed rgillan closed 11 years ago
Hi, How do you re-establish a connection? The ws.create does not exist. The only way to re-establish a connection is to create a new instance.
Sorry, meant was the wrong reference. When we call close to close the WebSocket, it indeed closes. When we try to create a new connection (wsSocket = new plugins.WebSocket(config[0], config[1], config[2]);) it hangs and never establishes the new WebSocket. We never see the onOpen response.
Cheers
On 10/05/2013, at 11:57 PM, knowledgecode wrote:
Hi, How do you re-establish a connection? The ws.create does not exist. The only way to re-establish a connection is to create a new instance.
— Reply to this email directly or view it on GitHub.
Have you been able to replicate our problem? Let us know if we can help with further testing,
Cheers Rob
No, I haven't. Would you show me your code snippet? If that helps, when you re-establish, are the parameters the same as first time?
Here's our Javascript that talks to the module:
config is an array containing url, subprotocol, origin
var wsSocket = null; dzhonWS = function () {};
dzhonWS.prototype.wsCreate = function (config) { if (!wsSocket) { wsSocket = new plugins.WebSocket(config[0], config[1], config[2]); console.log('wsCreate:' + wsConfig); wsSocket.onopen = function () { console.log('onopen'); onWsOpen(); }; wsSocket.onmessage = function (message) { console.log('onmessage:' + message); onWsMessage(JSON.parse(message)); }; wsSocket.onerror = function (error) { console.log('onerror'); onWsError(error); }; wsSocket.onclose = function () { console.log('onclose'); onWsClose(); }; } };
dzhonWS.prototype.wsSend = function (message) { wsSocket.send(message[0]); };
dzhonWS.prototype.wsClose = function () { wsSocket.close(); };
wsSocket is supposed to be closed in the onWsClose method called, will check and get back to you. Might be the culprit.
Is the wsSocket set to null in the onWsClose method? I think that just closing the wsSocket will not work the following the if sentence.
if (!wsSocket) { wsSocket = new plugins.WebSocket(config[0], config[1], config[2]); console.log('wsCreate:' + wsConfig); wsSocket.onopen = function () { console.log('onopen'); onWsOpen(); };
Will confirm in the morning, thanks for your help with all this.
We've confirmed that setting wsSocket to null in the onClose method resolves this issue. Thanks for all your help
Hi, When we pass a ws.close() to the plugin, it closes correctly (we see a disconnection on our server with code:1000 normal disconnection). When we try and re-establish a connection (ws.create) nothing hits the server and the plugin appears to hang. We think this was not the case prior to the last update adding the origin when it looks like you also refactored some of the code. Cheers Rob