diff --git a/packages/socket/src/server.js b/packages/socket/src/server.js index ea2716f..ebd8957 100644 --- a/packages/socket/src/server.js +++ b/packages/socket/src/server.js @@ -1,17 +1,11 @@ -import {Class, compose, EventEmitter} from '@latus/core'; import SocketIoServer from 'socket.io'; import ServerSocket from './socket'; import SocketIoParser from './packet/socket.io-parser'; -const decorate = compose( - EventEmitter, -); - -export default class SocketServer extends decorate(Class) { +export default class SocketServer { constructor(httpServer, latus) { - super(); // eslint-disable-next-line no-param-reassign latus.config['%sockets'] = this; this.onConnect = this.onConnect.bind(this); @@ -30,7 +24,7 @@ export default class SocketServer extends decorate(Class) { }); this.io.on('connect', this.onConnect); this.io.use((socket, next) => { - latus.invokeMiddleware('@latus/socket/connection', socket, next); + latus.invokeMiddleware('@latus/socket/authenticate', socket, next); }); const Packets = latus.invokeReduce('@latus/socket/packets'); // eslint-disable-next-line no-param-reassign @@ -50,7 +44,7 @@ export default class SocketServer extends decorate(Class) { const serverSocket = new ServerSocket(socket, this.latus); serverSocket.req.latus = this.latus; serverSocket.req.adapter = this.io.of('/').adapter; - this.emit('connect', serverSocket); + this.latus.invokeSequential('@latus/socket/connect', serverSocket); } send(packet, channel = '/') { diff --git a/packages/user/src/passport.js b/packages/user/src/passport.js index b24537a..840b57d 100644 --- a/packages/user/src/passport.js +++ b/packages/user/src/passport.js @@ -26,10 +26,10 @@ export default { passport.session()(req, res, next); }); }, - '@latus/socket/connection': () => (socket, next) => { - debug('@latus/socket/connection: passport.initialize()'); + '@latus/socket/authenticate': () => (socket, next) => { + debug('@latus/socket/authenticate: passport.initialize()'); passport.initialize()(socket.handshake, undefined, () => { - debug('@latus/socket/connection: passport.session()'); + debug('@latus/socket/authenticate: passport.session()'); passport.session()(socket.handshake, undefined, () => { /* eslint-disable no-param-reassign */ socket.handshake.login = LogOps.logIn; diff --git a/packages/user/src/session.js b/packages/user/src/session.js index 72ac123..05c63c0 100644 --- a/packages/user/src/session.js +++ b/packages/user/src/session.js @@ -34,10 +34,10 @@ export default { }); }; }, - '@latus/socket/connection': (latus) => { + '@latus/socket/authenticate': (latus) => { const fn = socketSession(latus.config['%session']); return (socket, next) => { - debug('@latus/socket/connection: session()'); + debug('@latus/socket/authenticate: session()'); fn(socket, next); }; },