Fix error appearing when disconnecting HMR client

Reviewed By: cpojer

Differential Revision: D5944285

fbshipit-source-id: 5751f6ad2b999872aa3d33e1c7fca105b3156da4
This commit is contained in:
Rafael Oleza 2017-09-29 17:56:26 -07:00 committed by Facebook Github Bot
parent d3e1a21399
commit 38ec30bc2e
1 changed files with 7 additions and 1 deletions

View File

@ -47,9 +47,14 @@ function attachWebsocketServer<TClient: Object>({
});
wss.on('connection', async ws => {
let connected = true;
const url = ws.upgradeReq.url;
const sendFn = ws.send.bind(ws);
const sendFn = (...args) => {
if (connected) {
ws.send(...args);
}
};
const client = await websocketServer.onClientConnect(url, sendFn);
@ -60,6 +65,7 @@ function attachWebsocketServer<TClient: Object>({
ws.on('close', () => {
websocketServer.onClientDisconnect &&
websocketServer.onClientDisconnect(client);
connected = false;
});
ws.on('message', message => {