登录优化:gate可变为短链接

This commit is contained in:
luying
2021-08-26 14:06:43 +08:00
parent e3f3b5f2a1
commit 4069220698
24 changed files with 141 additions and 14 deletions

View File

@@ -1,44 +0,0 @@
import * as crc from 'crc';
import { ServerInfo } from 'pinus';
let roleRoute = new Map<string, Map<string, string>>()
export function dispatch(uid: string, connectors: ServerInfo[], serverType: string = '') {
//测试代码
// if (serverType == 'activity') {
// if (uid == 'SPDtGqx9Gw') {
// if (connectors.length > 1) {
// connectors = connectors.filter(obj => { return obj.id != 'activity-server-1' })
// }
// } else {
// connectors = connectors.filter(obj => { return obj.id == 'activity-server-1' })
// }
// }
if (serverType) {
let roleRouteData = roleRoute.get(uid);
let serverId = '';
if (roleRouteData) {
serverId = roleRouteData.get(serverType);
if (serverId) {
let index = connectors.findIndex(obj => { return obj.id === serverId });
if (index != -1) {
// console.log('aaaaaaaaa 1', roleRouteData)
return connectors[index];
}
}
}
let index = Math.abs(crc.crc32(uid)) % connectors.length;
if (!roleRouteData) {
roleRouteData = new Map<string, string>()
}
roleRouteData.set(serverType, connectors[index].id);
roleRoute.set(uid, roleRouteData)
// console.log('aaaaaaaaa 2', roleRouteData)
return connectors[index];
}
let index = Math.abs(crc.crc32(uid)) % connectors.length;
return connectors[index];
}

View File

@@ -1,5 +1,5 @@
import { dispatch } from './dispatcher';
import { dispatch } from '../pubUtils/dispatcher';
import { Session, Application } from 'pinus';
export function chat(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {