flow: feekses
This commit is contained in:
parent
d0731bbac8
commit
c47777063e
|
@ -49,6 +49,7 @@ export const $$latus = {
|
|||
createDatabaseConnection(latus).then(next);
|
||||
},
|
||||
'@latus/repl/context': (latus) => ({
|
||||
Models: latus.config['%models'],
|
||||
sequelize: latus.config['%sequelize'],
|
||||
}),
|
||||
},
|
||||
|
|
|
@ -31,6 +31,9 @@ export default class SocketClient extends decorate(Class) {
|
|||
};
|
||||
this.latus = latus;
|
||||
this.socket = null;
|
||||
const Packets = latus.invokeReduce('@latus/socket/packets', {}, (r, o) => ({...r, ...o}));
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
latus.config['%packets'] = latus.invokeComposed('@latus/socket/packets/decorate', Packets);
|
||||
}
|
||||
|
||||
connect(address) {
|
||||
|
@ -61,7 +64,7 @@ export default class SocketClient extends decorate(Class) {
|
|||
'ping',
|
||||
'pong’',
|
||||
].forEach((type) => this.socket.on('type', (...args) => this.emit(type, ...args)));
|
||||
const Packets = all(this.latus);
|
||||
const Packets = Object.values(all(this.latus));
|
||||
for (let i = 0; i < Packets.length; i++) {
|
||||
const Packet = Packets[i];
|
||||
const {id} = Packet;
|
||||
|
|
|
@ -10,10 +10,11 @@ export const $$latus = {
|
|||
'@latus/socket/client': {},
|
||||
}),
|
||||
'@latus/http/server/up': async (httpServer, latus) => {
|
||||
createSocketServer(latus).open(httpServer);
|
||||
createSocketServer(httpServer, latus);
|
||||
},
|
||||
'@latus/repl/context': (latus) => ({
|
||||
socketServer: latus.config['%sockets'],
|
||||
Packets: latus.config['%packets'],
|
||||
sockets: latus.config['%sockets'],
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import SocketServer from './server';
|
||||
|
||||
export function createSocketServer(latus) {
|
||||
return new SocketServer(latus);
|
||||
export function createSocketServer(httpServer, latus) {
|
||||
return new SocketServer(httpServer, latus);
|
||||
}
|
||||
|
||||
export function destroySocketServer(socketServer) {
|
||||
|
|
|
@ -1,21 +1,5 @@
|
|||
import {arrayFlatten} from '@latus/core';
|
||||
export const all = (latus) => latus.config['%packets'];
|
||||
|
||||
const ensurePackets = (latus) => {
|
||||
if (!latus.config['%packets']) {
|
||||
const Packets = arrayFlatten(latus.invokeFlat('@latus/socket/packets'));
|
||||
/* eslint-disable no-param-reassign */
|
||||
Packets.forEach((Packet, i) => {
|
||||
Packet.id = i;
|
||||
});
|
||||
latus.config['%packets'] = Packets;
|
||||
/* eslint-enable no-param-reassign */
|
||||
}
|
||||
return latus.config['%packets'];
|
||||
};
|
||||
|
||||
export const all = (latus) => ensurePackets(latus);
|
||||
|
||||
export const fromId = (latus, id) => {
|
||||
const Packets = ensurePackets(latus);
|
||||
return Packets.find((Packet) => Packet.id === id);
|
||||
};
|
||||
export const fromId = (latus, id) => (
|
||||
Object.entries(all(latus)).find(([, Packet]) => Packet.id === id)[1]
|
||||
);
|
||||
|
|
|
@ -10,12 +10,35 @@ const decorate = compose(
|
|||
|
||||
export default class SocketServer extends decorate(Class) {
|
||||
|
||||
constructor(latus) {
|
||||
constructor(httpServer, latus) {
|
||||
super();
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
latus.config['%sockets'] = this;
|
||||
this.onConnect = this.onConnect.bind(this);
|
||||
this.latus = latus;
|
||||
const {
|
||||
config: {
|
||||
'@latus/core': {id},
|
||||
'@latus/socket': {middleware},
|
||||
},
|
||||
} = latus;
|
||||
this.io = SocketIoServer(httpServer, {
|
||||
parser: SocketIoParser(latus),
|
||||
path: `/${id}`,
|
||||
perMessageDeflate: false,
|
||||
serveClient: false,
|
||||
...latus.invokeReduce('@latus/socket/server', {}, (r, o) => ({...r, ...o})),
|
||||
});
|
||||
this.io.on('connect', this.onConnect);
|
||||
for (let i = 0; i < middleware.length; i++) {
|
||||
const fn = latus.invokePlugin('@latus/socket/middleware', middleware[i], this);
|
||||
if (fn) {
|
||||
this.io.use(fn);
|
||||
}
|
||||
}
|
||||
const Packets = latus.invokeReduce('@latus/socket/packets', {}, (r, o) => ({...r, ...o}));
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
latus.config['%packets'] = latus.invokeComposed('@latus/socket/packets/decorate', Packets);
|
||||
}
|
||||
|
||||
close(fn) {
|
||||
|
@ -34,29 +57,6 @@ export default class SocketServer extends decorate(Class) {
|
|||
this.emit('connect', serverSocket);
|
||||
}
|
||||
|
||||
open(httpServer) {
|
||||
const {
|
||||
config: {
|
||||
'@latus/core': {id},
|
||||
'@latus/socket': {middleware},
|
||||
},
|
||||
} = this.latus;
|
||||
this.io = SocketIoServer(httpServer, {
|
||||
parser: SocketIoParser(this.latus),
|
||||
path: `/${id}`,
|
||||
perMessageDeflate: false,
|
||||
serveClient: false,
|
||||
...this.latus.invokeReduce('@latus/socket/server', {}, (r, o) => ({...r, ...o})),
|
||||
});
|
||||
this.io.on('connect', this.onConnect);
|
||||
for (let i = 0; i < middleware.length; i++) {
|
||||
const fn = this.latus.invokePlugin('@latus/socket/middleware', middleware[i], this);
|
||||
if (fn) {
|
||||
this.io.use(fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
send(packet, channel = '/') {
|
||||
const {id} = packet.constructor;
|
||||
this.io.sockets.to(channel).binary(true).emit(id, packet.data);
|
||||
|
|
|
@ -913,16 +913,16 @@
|
|||
|
||||
"@latus/core@1.0.0", "@latus/core@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://npm.i12e.cha0s.io/@latus%2fcore/-/core-1.0.0.tgz#e1ef5253501ffd7f64358da2c18a89a42eb72cc1"
|
||||
integrity sha512-SNCzQ7tcYDE8tO5Q/acV3UlyXxOSNpAXCzgbBSUE/H13qrSjilKKm7DNYOkNNZOIDZRfJPauGM2bMZurJlGhlw==
|
||||
resolved "https://npm.i12e.cha0s.io/@latus%2fcore/-/core-1.0.0.tgz#b0f9689f828025be1cc5b59a050511e54b6528ee"
|
||||
integrity sha512-oN/zNrs+Cian5YIsbKSwj0i30nRLepuOzaAbT6/oT51NGxM+t6urt2DWlS306FGZ59Dx9yU9WN8zqQS/v3iSKw==
|
||||
dependencies:
|
||||
js-yaml "3.14.0"
|
||||
webpack-virtual-modules "0.3.2"
|
||||
|
||||
"@latus/db@1.0.0", "@latus/db@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://npm.i12e.cha0s.io/@latus%2fdb/-/db-1.0.0.tgz#9c6149f68f82481dc312492fa0648cbd4f82949d"
|
||||
integrity sha512-xLLb8vXTR3O9b7X1ei1x8GCFQjtyLB5I/BHkenMOQ2TQskVe70rgxcrX1l7qn5T07xKHAG18mD5oOky7aUzgtQ==
|
||||
resolved "https://npm.i12e.cha0s.io/@latus%2fdb/-/db-1.0.0.tgz#4bf06d00f395c1ba0b24bc3153a93dc751f3eff8"
|
||||
integrity sha512-gGFcbslyQQI5pYTRwdABBv2eFcmsiBYXGQHGeNKqvzK9Vgc038o5yPdtILn7Z1NWgkNbI6OrKGHeXe1R6e3Pkw==
|
||||
dependencies:
|
||||
"@latus/core" "^1.0.0"
|
||||
mysql2 "^2.2.5"
|
||||
|
@ -930,8 +930,8 @@
|
|||
|
||||
"@latus/http@1.0.0", "@latus/http@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://npm.i12e.cha0s.io/@latus%2fhttp/-/http-1.0.0.tgz#5ac6f163c8839e5da80ab42e5b00af1b89854c35"
|
||||
integrity sha512-eUskGZe1fQOzhi4gxMnirryUYp4ASehteCNhk/mEIy5dccSvMJHgc5zVuUkM9/XXW0YtJ1uH/xYde1w79VvZEw==
|
||||
resolved "https://npm.i12e.cha0s.io/@latus%2fhttp/-/http-1.0.0.tgz#9f5d80ee5c56ddeb81f4d83be59261f162139c14"
|
||||
integrity sha512-QCYw1YG1431MjcVxlQ09+V6JjAabX+IUq5hSBQ77TQ6ciQrJRSI/VHBqoJ/vVgDrwXm+MgnN/2OwU1hztV/RUQ==
|
||||
dependencies:
|
||||
"@latus/core" "1.0.0"
|
||||
"@neutrinojs/web" "^9.1.0"
|
||||
|
@ -969,8 +969,8 @@
|
|||
|
||||
"@latus/socket@1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://npm.i12e.cha0s.io/@latus%2fsocket/-/socket-1.0.0.tgz#d2cc02c6daefec8366265b83e8e745bb4759898e"
|
||||
integrity sha512-eKTtej14PYRf6d8vYlXA1s3AGp7PxtCtqkJIruIE2e5BpjdhJbtxp65MEunSKr5eW5g8PkLDKrl39RXJ3X2pmg==
|
||||
resolved "https://npm.i12e.cha0s.io/@latus%2fsocket/-/socket-1.0.0.tgz#85c7fce28d7ad87d2462cf79d1e86fd732130ef0"
|
||||
integrity sha512-PjQtO6HymDv6Pb4xz/muGkb+m1r6G1SYaE7cc92XD25AGATohkTqUb5s0ZOlUSZibX7xJxMDZomk90yuZHJkcg==
|
||||
dependencies:
|
||||
"@latus/core" "^1.0.0"
|
||||
"@latus/http" "^1.0.0"
|
||||
|
|
Loading…
Reference in New Issue
Block a user