streamby-core 0.26.7 → 0.26.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/services/wsHub.js +13 -2
- package/package.json +1 -1
package/dist/services/wsHub.js
CHANGED
|
@@ -11,15 +11,21 @@ function initWsHub(wss, config) {
|
|
|
11
11
|
try {
|
|
12
12
|
const auth = await config.authProvider(req);
|
|
13
13
|
if (!auth?.userId) {
|
|
14
|
+
console.warn('⚠️ WS auth returned no userId — closing connection');
|
|
14
15
|
ws.close(1008, 'Unauthorized');
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
userId = auth.userId;
|
|
18
19
|
}
|
|
19
|
-
catch {
|
|
20
|
+
catch (err) {
|
|
21
|
+
console.error('❌ WS auth error:', err);
|
|
20
22
|
ws.close(1008, 'Unauthorized');
|
|
21
23
|
return;
|
|
22
24
|
}
|
|
25
|
+
if (ws.readyState !== ws_1.WebSocket.OPEN) {
|
|
26
|
+
console.warn(`⚠️ WS closed before setup completed for user ${userId}`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
23
29
|
if (!connections.has(userId))
|
|
24
30
|
connections.set(userId, new Set());
|
|
25
31
|
connections.get(userId).add(ws);
|
|
@@ -28,7 +34,12 @@ function initWsHub(wss, config) {
|
|
|
28
34
|
if (connections.get(userId)?.size === 0)
|
|
29
35
|
connections.delete(userId);
|
|
30
36
|
});
|
|
31
|
-
|
|
37
|
+
try {
|
|
38
|
+
ws.send(JSON.stringify({ type: 'connected', userId }));
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.error(`❌ WS send error for user ${userId}:`, err);
|
|
42
|
+
}
|
|
32
43
|
});
|
|
33
44
|
}
|
|
34
45
|
function emitToUser(userId, event) {
|