confirm that a socket is ready to send before sending
This commit is contained in:
parent
4b238de84c
commit
9fa7da60b9
@ -14,7 +14,12 @@ let historyKeeperKeys = {};
|
|||||||
|
|
||||||
const now = function () { return (new Date()).getTime(); };
|
const now = function () { return (new Date()).getTime(); };
|
||||||
|
|
||||||
|
const socketSendable = function (socket) {
|
||||||
|
return socket && socket.readyState === 1;
|
||||||
|
};
|
||||||
|
|
||||||
const sendMsg = function (ctx, user, msg) {
|
const sendMsg = function (ctx, user, msg) {
|
||||||
|
if (!socketSendable(user.socket)) { return; }
|
||||||
try {
|
try {
|
||||||
if (ctx.config.logToStdout) { console.log('<' + JSON.stringify(msg)); }
|
if (ctx.config.logToStdout) { console.log('<' + JSON.stringify(msg)); }
|
||||||
user.socket.send(JSON.stringify(msg));
|
user.socket.send(JSON.stringify(msg));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user