feat: 更新@kevisual/api依赖版本至0.0.62,优化WsProxyManager和请求处理逻辑
This commit is contained in:
@@ -161,6 +161,11 @@ export class WsProxyManager {
|
||||
this.wssMap.delete(oldId);
|
||||
this.wssMap.set(newId, value);
|
||||
value.id = newId;
|
||||
// @ts-ignore
|
||||
if (value.ws?.data) {
|
||||
// @ts-ignore
|
||||
value.ws.data.userApp = newId;
|
||||
}
|
||||
logger.debug(`WsProxyManager changeId: ${oldId} -> ${newId}`);
|
||||
}
|
||||
}
|
||||
@@ -218,11 +223,11 @@ export class WsProxyManager {
|
||||
}, this.PING_INTERVAL);
|
||||
}
|
||||
async createNewConnection(opts: { ws: any; user: string, userApp: string, isLogin?: boolean }) {
|
||||
const id = opts.userApp;
|
||||
let id = opts.userApp;
|
||||
let realId: string = id;
|
||||
const isLogin = opts.isLogin || false;
|
||||
const has = this.wssMap.has(id);
|
||||
const registryId = '-registry-' + generateRegistryId(); // 生成一个随机六位字符串作为注册 ID
|
||||
let registryId = '-registry-' + generateRegistryId(); // 生成一个随机六位字符串作为注册 ID
|
||||
let isNeedVerify = !isLogin;
|
||||
if (has) {
|
||||
const value = this.wssMap.get(id);
|
||||
@@ -236,8 +241,10 @@ export class WsProxyManager {
|
||||
wsMessage.sendConnected();
|
||||
return { wsMessage, isNew: false, id: id };
|
||||
} else {
|
||||
// 没有关闭,需要重新注册鉴权一下, 生成新的 id 连接.
|
||||
isNeedVerify = true;
|
||||
// 没有关闭 生成新的 id 连接.
|
||||
id = id + '-mult-' + generateRegistryId(4);
|
||||
realId = id;
|
||||
logger.debug('之前的连接未关闭,使用新的 ID 连接 ws', id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,6 +258,6 @@ export class WsProxyManager {
|
||||
}
|
||||
}
|
||||
// 生成一个随机六位字符串作为注册 ID
|
||||
const generateRegistryId = () => {
|
||||
return Math.random().toString(36).substring(2, 8);
|
||||
const generateRegistryId = (len = 6) => {
|
||||
return Math.random().toString(36).substring(2, 2 + len);
|
||||
}
|
||||
Reference in New Issue
Block a user