forked from circlecloud/tera
1
0
Fork 0
tera/src/rpc/manager.ts

37 lines
1.1 KiB
TypeScript

import { CcServerBoot } from "@cc-server/core";
import { TYPE, interfaces, io } from "@cc-server/ws";
import { lazyInjectNamed, Container } from "@cc-server/ioc";
import { PowNamespace, WebNamespace } from "./server";
class TeraManager {
@lazyInjectNamed(TYPE.Namespace, PowNamespace.name)
powNsp: interfaces.Namespace;
@lazyInjectNamed(TYPE.Namespace, WebNamespace.name)
webNsp: interfaces.Namespace;
pows: { [key: string]: io.Socket };
WsServer: CcServerBoot;
constructor() {
this.pows = {};
let container = new Container();
this.WsServer = new CcServerBoot(container).build();
}
SendToClient(msg: any) {
this.webNsp.nsp.to('pow').send(JSON.stringify(msg))
let index = 0;
for (let id in this.pows) {
const pow = this.pows[id];
if (typeof msg === "object") {
msg.NodeNum = index;
}
pow.send(msg)
index++
}
}
SendToWebClient(msg: any) {
this.webNsp.nsp.send(msg)
}
}
let teraManager = new TeraManager();
export { teraManager }