Fix error appearing when disconnecting HMR client
Reviewed By: cpojer Differential Revision: D5944285 fbshipit-source-id: 5751f6ad2b999872aa3d33e1c7fca105b3156da4
This commit is contained in:
parent
d3e1a21399
commit
38ec30bc2e
|
@ -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 => {
|
||||
|
|
Loading…
Reference in New Issue