SDK websocket handshake messages not emitted (#21956)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
Brainslug
2024-03-25 11:38:20 +01:00
committed by GitHub
parent 114b249d00
commit 545c381a6a
2 changed files with 10 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"@directus/sdk": patch
---
Fixed SDK websocket handshake messages not being emitted

View File

@@ -235,6 +235,11 @@ export function realtime(config: WebSocketConfig = {}) {
ws.addEventListener('open', async (evt: Event) => {
debug('info', `Connection open.`);
state = { code: 'open', connection: ws, firstMessage: true };
reconnectState.attempts = 0;
reconnectState.active = false;
handleMessages(self);
if (config.authMode === 'handshake' && hasAuth(self)) {
const access_token = await self.getToken();
@@ -262,12 +267,7 @@ export function realtime(config: WebSocketConfig = {}) {
}
}
state = { code: 'open', connection: ws, firstMessage: true };
reconnectState.attempts = 0;
reconnectState.active = false;
eventHandlers['open'].forEach((handler) => handler.call(ws, evt));
handleMessages(self);
resolved = true;
resolve(ws);