Permalink
Browse files

Fix error appearing when disconnecting HMR client

Reviewed By: cpojer

Differential Revision: D5944285

fbshipit-source-id: 5751f6ad2b999872aa3d33e1c7fca105b3156da4
  • Loading branch information...
rafeca authored and facebook-github-bot committed Sep 30, 2017
1 parent d3e1a21 commit 38ec30bc2efb0edc525ab733f5a3b9ceb0274fad
Showing with 7 additions and 1 deletion.
  1. +7 −1 local-cli/server/util/attachWebsocketServer.js
@@ -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 => {

0 comments on commit 38ec30b

Please sign in to comment.