@deffector/standalone 0.1.0 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deffector/standalone",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "DevTools for effector outside a browser tab: the deffector panel for SSR servers, Node scripts, tests and React Native",
5
5
  "keywords": [
6
6
  "effector",
package/server.mjs CHANGED
@@ -16,6 +16,17 @@ const CONTENT_TYPES = {
16
16
  };
17
17
  /** Traces and big state snapshots travel as one message. */
18
18
  const MAX_MESSAGE_BYTES = 64 * 1024 * 1024;
19
+
20
+ /** Why a socket closed, when it was not a normal close (page reload, process exit). */
21
+ function describeCloseCode(code) {
22
+ if (code === 1009) {
23
+ return ` — a message was larger than ${MAX_MESSAGE_BYTES / 1024 / 1024} MB; please report this at https://github.com/mxmvshnvsk/deffector/issues`;
24
+ }
25
+ // a normal close, a page reload or a tab that went away
26
+ if ([1000, 1001, 1005, 1006].includes(code)) return '';
27
+ return ` (code ${code})`;
28
+ }
29
+
19
30
  /** A panel that has not picked an agent follows the most recently connected one. */
20
31
  const AUTO = 'auto';
21
32
 
@@ -128,9 +139,10 @@ function createRelay(log) {
128
139
  for (const panel of agent.panels)
129
140
  if (panel.ws.readyState === WebSocket.OPEN) panel.ws.send(text);
130
141
  });
131
- ws.on('close', () => {
142
+ ws.on('close', (code) => {
132
143
  agents.delete(id);
133
- log(`[deffector] agent disconnected: ${agent.hello?.app?.name ?? id}`);
144
+ const name = agent.hello?.app?.name ?? id;
145
+ log(`[deffector] agent disconnected: ${name}${describeCloseCode(code)}`);
134
146
  for (const panel of agent.panels) {
135
147
  panel.agentId = null;
136
148
  pair(panel);