mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-12 19:30:52 +00:00
SessionId duplicate fix (#4676)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
0b06f0bbe7
commit
bbe6141eb9
@ -205,6 +205,13 @@ class Connection implements ClientConnection {
|
||||
websocket.onmessage = (event: MessageEvent) => {
|
||||
const resp = readResponse<any>(event.data, binaryResponse)
|
||||
if (resp.id === -1 && resp.result === 'hello') {
|
||||
if ((resp as HelloResponse).alreadyConnected === true) {
|
||||
this.sessionId = generateId()
|
||||
if (typeof sessionStorage !== 'undefined') {
|
||||
sessionStorage.setItem('session.id.' + this.url, this.sessionId)
|
||||
}
|
||||
reject(new Error('alreadyConnected'))
|
||||
}
|
||||
if ((resp as HelloResponse).binary) {
|
||||
binaryResponse = true
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ export interface HelloRequest extends Request<any[]> {
|
||||
export interface HelloResponse extends Response<any> {
|
||||
binary: boolean
|
||||
reconnect?: boolean
|
||||
alreadyConnected?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,6 +214,17 @@ class TSessionManager implements SessionManager {
|
||||
let workspace = this.workspaces.get(wsString)
|
||||
await workspace?.closing
|
||||
workspace = this.workspaces.get(wsString)
|
||||
if (sessionId !== undefined && workspace?.sessions?.has(sessionId) === true) {
|
||||
const helloResponse: HelloResponse = {
|
||||
id: -1,
|
||||
result: 'hello',
|
||||
binary: false,
|
||||
reconnect: false,
|
||||
alreadyConnected: true
|
||||
}
|
||||
await ws.send(ctx, helloResponse, false, false)
|
||||
return { error: new Error('Session already exists') }
|
||||
}
|
||||
const workspaceName = workspaceInfo.workspaceName ?? workspaceInfo.workspaceUrl ?? workspaceInfo.workspace
|
||||
|
||||
if (workspace === undefined) {
|
||||
|
Loading…
Reference in New Issue
Block a user