56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { Application, ChannelService, FrontendSession, pinus, RemoterClass, HandlerService, } from 'pinus';
|
|
import { STATUS } from '../../../consts/statusCode';
|
|
import { resResult } from '../../../pubUtils/util';
|
|
import { reloadResources } from '../../../pubUtils/data';
|
|
export default function (app: Application) {
|
|
new HandlerService(app, {});
|
|
return new ConnectorRemote(app);
|
|
}
|
|
|
|
export class ConnectorRemote {
|
|
|
|
constructor(private app: Application) {
|
|
this.app = app;
|
|
this.channelService = app.get('channelService');
|
|
}
|
|
private channelService: ChannelService;
|
|
private maintenServers: number[] = []; // 维护中的服务器
|
|
|
|
public async remoteLogin(uid: string) {
|
|
let sessionService = this.app.get('sessionService');
|
|
let sessions = sessionService.getByUid(uid);
|
|
if (!!sessions) {
|
|
sessions.forEach(session => {
|
|
let roleId = session.get('roleId');
|
|
let sid = session.get('sid');
|
|
let uids = [{ uid: roleId, sid }];
|
|
this.channelService.pushMessageByUids('onRemoteLogin', resResult(STATUS.LOGIN_ERR), uids);
|
|
});
|
|
}
|
|
await sessionService.akick(uid);
|
|
}
|
|
|
|
public async pushMessage(uid: string, route: string, data: any) {
|
|
let sid = pinus.app.getServerId();
|
|
if (!!sid) {
|
|
let uids = [{ uid, sid }];
|
|
this.channelService.pushMessageByUids(route, resResult(STATUS.SUCCESS, { mails: data }), uids);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 重载json资源
|
|
*/
|
|
public async reloadResources() {
|
|
reloadResources();
|
|
}
|
|
|
|
public setServerMainten(maintenServers: number[]) {
|
|
return this.maintenServers = maintenServers;
|
|
}
|
|
|
|
public getServerMainten() {
|
|
return this.maintenServers;
|
|
}
|
|
}
|