streamby-core 0.26.7 → 0.26.9

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.
@@ -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,14 @@ function initWsHub(wss, config) {
28
34
  if (connections.get(userId)?.size === 0)
29
35
  connections.delete(userId);
30
36
  });
31
- ws.send(JSON.stringify({ type: 'connected', userId }));
37
+ try {
38
+ const payload = JSON.stringify({ type: 'connected', userId });
39
+ console.log(`📤 WS sending to ${userId}:`, payload);
40
+ ws.send(payload, { binary: false });
41
+ }
42
+ catch (err) {
43
+ console.error(`❌ WS send error for user ${userId}:`, err);
44
+ }
32
45
  });
33
46
  }
34
47
  function emitToUser(userId, event) {
@@ -38,6 +51,6 @@ function emitToUser(userId, event) {
38
51
  const payload = JSON.stringify(event);
39
52
  for (const ws of userConnections) {
40
53
  if (ws.readyState === ws_1.WebSocket.OPEN)
41
- ws.send(payload);
54
+ ws.send(payload, { binary: false });
42
55
  }
43
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.26.7",
3
+ "version": "0.26.9",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",