Handle when a frontend disconnects

This commit is contained in:
calzoneman 2016-01-01 18:25:12 -08:00
parent 9a262da13d
commit cdb20e8d40
1 changed files with 15 additions and 0 deletions

View File

@ -15,10 +15,25 @@ export default class FrontendManager {
} }
this.frontendConnections[socket.endpoint] = socket; this.frontendConnections[socket.endpoint] = socket;
socket.on('close', this.onFrontendDisconnect.bind(this, socket));
socket.on('SocketConnectEvent', this.onSocketConnect.bind(this, socket)); socket.on('SocketConnectEvent', this.onSocketConnect.bind(this, socket));
socket.on('SocketFrameEvent', this.onSocketFrame.bind(this, socket)); socket.on('SocketFrameEvent', this.onSocketFrame.bind(this, socket));
} }
onFrontendDisconnect(socket) {
const endpoint = socket.endpoint;
if (this.frontendConnections.hasOwnProperty(endpoint)) {
if (this.frontendProxiedSockets.hasOwnProperty(endpoint)) {
logger.warn(`Frontend ${endpoint} disconnected`);
this.frontendProxiedSockets[endpoint].forEach(proxySocket => {
proxySocket.onProxiedEventReceived('disconnect');
});
delete this.frontendProxiedSockets[endpoint];
}
delete this.frontendConnections[endpoint];
}
}
onSocketConnect(frontendConnection, socketID, socketIP, socketUser) { onSocketConnect(frontendConnection, socketID, socketIP, socketUser) {
const mapKey = frontendConnection.endpoint; const mapKey = frontendConnection.endpoint;
const proxiedSocket = new ProxiedSocket( const proxiedSocket = new ProxiedSocket(