feat: use avo EE & disconnect API
This commit is contained in:
parent
092079625f
commit
3905bd5f09
|
@ -1,9 +1,14 @@
|
|||
const {EventEmitter} = require('events');
|
||||
const SocketServer = require('socket.io');
|
||||
|
||||
import {compose} from '@avocado/core';
|
||||
import {EventEmitter} from '@avocado/mixins';
|
||||
import {SocketIoParser, allPackets, idFromPacket} from '@avocado/packet';
|
||||
|
||||
export class Server extends EventEmitter {
|
||||
const decorateServer = compose(
|
||||
EventEmitter,
|
||||
);
|
||||
|
||||
export class Server extends decorateServer(class {}) {
|
||||
|
||||
constructor(httpServer) {
|
||||
super();
|
||||
|
@ -20,7 +25,11 @@ export class Server extends EventEmitter {
|
|||
|
||||
}
|
||||
|
||||
class ServerSocket extends EventEmitter {
|
||||
const decorateSocket = compose(
|
||||
EventEmitter,
|
||||
);
|
||||
|
||||
class ServerSocket extends decorateSocket(class {}) {
|
||||
|
||||
constructor(socket) {
|
||||
super();
|
||||
|
@ -36,6 +45,10 @@ class ServerSocket extends EventEmitter {
|
|||
});
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.socket.disconnect(true);
|
||||
}
|
||||
|
||||
send(packet) {
|
||||
const id = idFromPacket(packet.constructor);
|
||||
this.socket.emit(id, packet.data);
|
||||
|
|
Loading…
Reference in New Issue
Block a user