diff --git a/src/io/backend/frontendmanager.js b/src/io/backend/frontendmanager.js index 7cd465ee..730fb321 100644 --- a/src/io/backend/frontendmanager.js +++ b/src/io/backend/frontendmanager.js @@ -15,48 +15,38 @@ export default class FrontendManager { } this.frontendConnections[socket.endpoint] = socket; - socket.on('data', this.onData.bind(this, socket)); + socket.on('SocketConnectEvent', this.onSocketConnect.bind(this, socket)); + socket.on('SocketFrameEvent', this.onSocketFrame.bind(this, socket)); } - onData(socket, data) { - switch (data.$type) { - case 'socketConnect': - this.onSocketConnect(socket, data); - break; - case 'socketFrame': - this.onSocketFrame(socket, data); - break; - } - } - - onSocketConnect(frontendConnection, data) { + onSocketConnect(frontendConnection, socketID, socketIP) { const mapKey = frontendConnection.endpoint; const proxiedSocket = new ProxiedSocket( - data.socketID, - data.socketData, + socketID, + socketIP, this.socketEmitter, frontendConnection); if (!this.frontendProxiedSockets.hasOwnProperty(mapKey)) { this.frontendProxiedSockets[mapKey] = {}; - } else if (this.frontendProxiedSockets[mapKey].hasOwnProperty(data.socketID)) { + } else if (this.frontendProxiedSockets[mapKey].hasOwnProperty(socketID)) { // TODO: Handle this gracefully throw new Error(); } - this.frontendProxiedSockets[mapKey][data.socketID] = proxiedSocket; + this.frontendProxiedSockets[mapKey][socketID] = proxiedSocket; ioServer.handleConnection(proxiedSocket); } - onSocketFrame(frontendConnection, data) { + onSocketFrame(frontendConnection, socketID, event, args) { const mapKey = frontendConnection.endpoint; const socketMap = this.frontendProxiedSockets[mapKey]; - if (!socketMap || !socketMap.hasOwnProperty(data.socketID)) { + if (!socketMap || !socketMap.hasOwnProperty(socketID)) { // TODO throw new Error(); } - const socket = socketMap[data.socketID]; - socket.onProxiedEventReceived.apply(socket, [data.event].concat(data.args)); + const socket = socketMap[socketID]; + socket.onProxiedEventReceived.apply(socket, [event].concat(args)); } } diff --git a/src/io/backend/iobackend.js b/src/io/backend/iobackend.js index 9d0de5c2..1f0a875e 100644 --- a/src/io/backend/iobackend.js +++ b/src/io/backend/iobackend.js @@ -1,4 +1,4 @@ -import Server from 'cytube-common/lib/tcpjson/server'; +import Server from 'cytube-common/lib/proxy/server'; import FrontendManager from './frontendmanager'; export default class IOBackend { diff --git a/src/io/backend/proxiedsocket.js b/src/io/backend/proxiedsocket.js index 64db50a2..49e034c2 100644 --- a/src/io/backend/proxiedsocket.js +++ b/src/io/backend/proxiedsocket.js @@ -1,11 +1,11 @@ import { EventEmitter } from 'events'; export default class ProxiedSocket extends EventEmitter { - constructor(socketID, socketData, socketEmitter, frontendConnection) { + constructor(socketID, socketIP, socketEmitter, frontendConnection) { super(); this.id = socketID; - this.ip = socketData.ip; - this._realip = socketData.ip; + this.ip = socketIP; + this._realip = socketIP; this.socketEmitter = socketEmitter; this.frontendConnection = frontendConnection; } @@ -21,7 +21,7 @@ export default class ProxiedSocket extends EventEmitter { join(channel) { this.frontendConnection.write( - this.frontendConnection.protocol.socketJoinSocketChannels( + this.frontendConnection.protocol.newSocketJoinRoomsEvent( this.id, [channel] ) ); @@ -29,7 +29,7 @@ export default class ProxiedSocket extends EventEmitter { disconnect() { this.frontendConnection.write( - this.frontendConnection.protocol.socketKick(this.id) + this.frontendConnection.protocol.newSocketKickEvent(this.id) ); } }