This commit is contained in:
xy
2026-03-13 01:38:40 +00:00
parent e6e4f88257
commit 28855885cd
311 changed files with 89544 additions and 94350 deletions

View File

@@ -1,38 +1,39 @@
import { STATUS } from './../../../consts/statusCode';
import { dispatch } from '../../../pubUtils/dispatcher';
import { Application, BackendSession, HandlerService, pinus, } from 'pinus';
import { resResult } from '../../../pubUtils/util';
import { redisClient } from '../../../services/redisService';
export default function (app: Application) {
new HandlerService(app, {});
return new GateHandler(app);
}
export class GateHandler {
constructor(private app: Application) {
}
/**
* Gate handler that dispatch user to connectors.
*
* @param {Object} msg message from client
* @param {Object} session
*
*/
async queryEntry(msg: { userCode: string }, session: BackendSession) {
let { userCode } = msg;
if (!userCode) {
return resResult(STATUS.WRONG_PARMS);
}
// get all connectors
let connectors = this.app.getServersByType('connector');
// console.log(connectors);
if (!connectors || connectors.length === 0) {
return resResult(STATUS.CONNECTOR_ERR);
}
// select connector
let res = await dispatch(redisClient(), userCode, connectors, 'connector');
return resResult(STATUS.SUCCESS, { host: res.clientHost, port: res.clientPort });
}
}
import { STATUS } from './../../../consts/statusCode';
import { dispatch } from '@pubUtils/dispatcher';
import { Application, BackendSession, HandlerService, pinus, } from 'pinus';
import { resResult } from '@pubUtils/util';
import { redisClient } from '../../../services/redisService';
export default function (app: Application) {
new HandlerService(app, {});
return new GateHandler(app);
}
export class GateHandler {
constructor(private app: Application) {
}
/**
* Gate handler that dispatch user to connectors.
*
* @param {Object} msg message from client
* @param {Object} session
*
*/
async queryEntry(msg: { userCode: string }, session: BackendSession) {
let { userCode } = msg;
if (!userCode) {
return resResult(STATUS.WRONG_PARMS);
}
// get all connectors
let connectors = this.app.getServersByType('connector');
// console.log(connectors);
if (!connectors || connectors.length === 0) {
return resResult(STATUS.CONNECTOR_ERR);
}
// select connector
let res = await dispatch(redisClient(), userCode, connectors, 'connector');
return resResult(STATUS.SUCCESS, { host: res.clientHost, port: res.clientPort });
}
}