@buoy-gg/external-sync 7.0.32 → 7.0.34

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.
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.buildHandshakeQuery = buildHandshakeQuery;
7
+ exports.getInstanceId = getInstanceId;
6
8
  exports.useExternalSyncSocket = useExternalSyncSocket;
7
9
  var _react = require("react");
8
10
  var _socket = require("socket.io-client");
@@ -31,6 +33,36 @@ let currentSocketURL = "";
31
33
  */
32
34
  const makeConnectionNonce = () => `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
33
35
 
36
+ /**
37
+ * Identifies this JS RUNTIME, not this socket. Held on globalThis so every
38
+ * socket the runtime opens (Fast Refresh, remounts, a double-mounted dev
39
+ * tools layer) carries the same value, while a second app that pinned the
40
+ * same deviceId carries a different one. That difference is the only way
41
+ * the broker can tell "one device, many sockets" from "many devices, one
42
+ * id" — it flags the latter as a collision in the device list.
43
+ */
44
+ function getInstanceId() {
45
+ const g = globalThis;
46
+ if (!g.__buoyInstanceId) g.__buoyInstanceId = makeConnectionNonce();
47
+ return g.__buoyInstanceId;
48
+ }
49
+ /**
50
+ * The socket.io handshake query — the ONE place the device says who it is.
51
+ * `connectionNonce` is fresh per socket instance; `instanceId` is fixed per
52
+ * runtime (see above). Pure, so the shape is unit-tested.
53
+ */
54
+ function buildHandshakeQuery(identity) {
55
+ return {
56
+ deviceName: identity.deviceName,
57
+ deviceId: identity.persistentDeviceId,
58
+ platform: identity.platform,
59
+ extraDeviceInfo: JSON.stringify(identity.extraDeviceInfo),
60
+ envVariables: JSON.stringify(identity.envVariables),
61
+ connectionNonce: makeConnectionNonce(),
62
+ instanceId: getInstanceId()
63
+ };
64
+ }
65
+
34
66
  /**
35
67
  * Hook that manages a Socket.IO connection for device-to-dashboard communication.
36
68
  *
@@ -112,14 +144,13 @@ function useExternalSyncSocket({
112
144
  (0, _logger.log)(`${logPrefix} Creating new socket instance to ${platformUrl}`, enableLogs);
113
145
  globalSocketInstance = (0, _socket.io)(platformUrl, {
114
146
  autoConnect: true,
115
- query: {
147
+ query: buildHandshakeQuery({
116
148
  deviceName,
117
- deviceId: persistentDeviceId,
149
+ persistentDeviceId,
118
150
  platform,
119
- extraDeviceInfo: JSON.stringify(extraDeviceInfo),
120
- envVariables: JSON.stringify(envVariables),
121
- connectionNonce: makeConnectionNonce()
122
- },
151
+ extraDeviceInfo,
152
+ envVariables
153
+ }),
123
154
  reconnection: true,
124
155
  reconnectionAttempts: Infinity,
125
156
  reconnectionDelay: 1000,
@@ -182,14 +213,13 @@ function useExternalSyncSocket({
182
213
  (0, _logger.log)(`${logPrefix} Creating new socket connection to ${platformUrl}`, enableLogs);
183
214
  globalSocketInstance = (0, _socket.io)(platformUrl, {
184
215
  autoConnect: true,
185
- query: {
216
+ query: buildHandshakeQuery({
186
217
  deviceName,
187
- deviceId: persistentDeviceId,
218
+ persistentDeviceId,
188
219
  platform,
189
- extraDeviceInfo: JSON.stringify(extraDeviceInfo),
190
- envVariables: JSON.stringify(envVariables),
191
- connectionNonce: makeConnectionNonce()
192
- },
220
+ extraDeviceInfo,
221
+ envVariables
222
+ }),
193
223
  reconnection: true,
194
224
  reconnectionAttempts: Infinity,
195
225
  reconnectionDelay: 1000,
@@ -27,6 +27,36 @@ let currentSocketURL = "";
27
27
  */
28
28
  const makeConnectionNonce = () => `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
29
29
 
30
+ /**
31
+ * Identifies this JS RUNTIME, not this socket. Held on globalThis so every
32
+ * socket the runtime opens (Fast Refresh, remounts, a double-mounted dev
33
+ * tools layer) carries the same value, while a second app that pinned the
34
+ * same deviceId carries a different one. That difference is the only way
35
+ * the broker can tell "one device, many sockets" from "many devices, one
36
+ * id" — it flags the latter as a collision in the device list.
37
+ */
38
+ export function getInstanceId() {
39
+ const g = globalThis;
40
+ if (!g.__buoyInstanceId) g.__buoyInstanceId = makeConnectionNonce();
41
+ return g.__buoyInstanceId;
42
+ }
43
+ /**
44
+ * The socket.io handshake query — the ONE place the device says who it is.
45
+ * `connectionNonce` is fresh per socket instance; `instanceId` is fixed per
46
+ * runtime (see above). Pure, so the shape is unit-tested.
47
+ */
48
+ export function buildHandshakeQuery(identity) {
49
+ return {
50
+ deviceName: identity.deviceName,
51
+ deviceId: identity.persistentDeviceId,
52
+ platform: identity.platform,
53
+ extraDeviceInfo: JSON.stringify(identity.extraDeviceInfo),
54
+ envVariables: JSON.stringify(identity.envVariables),
55
+ connectionNonce: makeConnectionNonce(),
56
+ instanceId: getInstanceId()
57
+ };
58
+ }
59
+
30
60
  /**
31
61
  * Hook that manages a Socket.IO connection for device-to-dashboard communication.
32
62
  *
@@ -108,14 +138,13 @@ export function useExternalSyncSocket({
108
138
  log(`${logPrefix} Creating new socket instance to ${platformUrl}`, enableLogs);
109
139
  globalSocketInstance = socketIO(platformUrl, {
110
140
  autoConnect: true,
111
- query: {
141
+ query: buildHandshakeQuery({
112
142
  deviceName,
113
- deviceId: persistentDeviceId,
143
+ persistentDeviceId,
114
144
  platform,
115
- extraDeviceInfo: JSON.stringify(extraDeviceInfo),
116
- envVariables: JSON.stringify(envVariables),
117
- connectionNonce: makeConnectionNonce()
118
- },
145
+ extraDeviceInfo,
146
+ envVariables
147
+ }),
119
148
  reconnection: true,
120
149
  reconnectionAttempts: Infinity,
121
150
  reconnectionDelay: 1000,
@@ -178,14 +207,13 @@ export function useExternalSyncSocket({
178
207
  log(`${logPrefix} Creating new socket connection to ${platformUrl}`, enableLogs);
179
208
  globalSocketInstance = socketIO(platformUrl, {
180
209
  autoConnect: true,
181
- query: {
210
+ query: buildHandshakeQuery({
182
211
  deviceName,
183
- deviceId: persistentDeviceId,
212
+ persistentDeviceId,
184
213
  platform,
185
- extraDeviceInfo: JSON.stringify(extraDeviceInfo),
186
- envVariables: JSON.stringify(envVariables),
187
- connectionNonce: makeConnectionNonce()
188
- },
214
+ extraDeviceInfo,
215
+ envVariables
216
+ }),
189
217
  reconnection: true,
190
218
  reconnectionAttempts: Infinity,
191
219
  reconnectionDelay: 1000,
@@ -1,5 +1,27 @@
1
1
  import { Socket } from "socket.io-client";
2
2
  import type { UseExternalSyncSocketProps } from "./types";
3
+ /**
4
+ * Identifies this JS RUNTIME, not this socket. Held on globalThis so every
5
+ * socket the runtime opens (Fast Refresh, remounts, a double-mounted dev
6
+ * tools layer) carries the same value, while a second app that pinned the
7
+ * same deviceId carries a different one. That difference is the only way
8
+ * the broker can tell "one device, many sockets" from "many devices, one
9
+ * id" — it flags the latter as a collision in the device list.
10
+ */
11
+ export declare function getInstanceId(): string;
12
+ export interface HandshakeIdentity {
13
+ deviceName: string;
14
+ persistentDeviceId: string;
15
+ platform: string;
16
+ extraDeviceInfo?: Record<string, string>;
17
+ envVariables?: Record<string, string>;
18
+ }
19
+ /**
20
+ * The socket.io handshake query — the ONE place the device says who it is.
21
+ * `connectionNonce` is fresh per socket instance; `instanceId` is fixed per
22
+ * runtime (see above). Pure, so the shape is unit-tested.
23
+ */
24
+ export declare function buildHandshakeQuery(identity: HandshakeIdentity): Record<string, string>;
3
25
  /**
4
26
  * Hook that manages a Socket.IO connection for device-to-dashboard communication.
5
27
  *
@@ -1 +1 @@
1
- {"version":3,"file":"useExternalSyncSocket.d.ts","sourceRoot":"","sources":["../../src/useExternalSyncSocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AA0B1D;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,UAAkB,GACnB,EAAE,0BAA0B;;;;;EA4O5B"}
1
+ {"version":3,"file":"useExternalSyncSocket.d.ts","sourceRoot":"","sources":["../../src/useExternalSyncSocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AA0B1D;;;;;;;GAOG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAItC;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUvF;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,UAAkB,GACnB,EAAE,0BAA0B;;;;;EA0O5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buoy-gg/external-sync",
3
- "version": "7.0.32",
3
+ "version": "7.0.34",
4
4
  "description": "Generic device-to-desktop sync for Buoy dev tools",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",