buffer messages while session creates

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-08-19 19:34:58 +02:00
parent 00f694f906
commit 28d65ec277
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0

View File

@ -128,10 +128,17 @@ export function start (storageFactory: (workspace: string) => Promise<ServerStor
const wss = new Server({ noServer: true })
// eslint-disable-next-line @typescript-eslint/no-misused-promises
wss.on('connection', async (ws: WebSocket, request: any, token: _Token) => {
const buffer: string[] = []
ws.on('message', (msg: string) => { buffer.push(msg) })
const session = await sessions.addSession(ws, token, storageFactory)
// eslint-disable-next-line @typescript-eslint/no-misused-promises
ws.on('message', async (msg: string) => await handleRequest(session, ws, msg))
ws.on('close', (code: number, reason: string) => sessions.close(ws, token, code, reason))
for (const msg of buffer) {
await handleRequest(session, ws, msg)
}
})
const server = createServer()