From 9fa7da60b994d06a8af9dad3b3df711afd566057 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 3 Oct 2016 15:38:42 +0200 Subject: [PATCH] confirm that a socket is ready to send before sending --- NetfluxWebsocketSrv.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NetfluxWebsocketSrv.js b/NetfluxWebsocketSrv.js index 98d79f72f..a96e41f2d 100644 --- a/NetfluxWebsocketSrv.js +++ b/NetfluxWebsocketSrv.js @@ -14,7 +14,12 @@ let historyKeeperKeys = {}; const now = function () { return (new Date()).getTime(); }; +const socketSendable = function (socket) { + return socket && socket.readyState === 1; +}; + const sendMsg = function (ctx, user, msg) { + if (!socketSendable(user.socket)) { return; } try { if (ctx.config.logToStdout) { console.log('<' + JSON.stringify(msg)); } user.socket.send(JSON.stringify(msg));