@buoy-gg/sync-broker 7.0.26 → 7.0.27
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/index.js +27 -9
- package/dist/index.mjs +27 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -170,7 +170,29 @@ function socketHandle({ io }) {
|
|
|
170
170
|
function handleClose(id, reason) {
|
|
171
171
|
const user = users.find((user2) => user2.id === id);
|
|
172
172
|
const deviceId = deviceIdMap.get(id);
|
|
173
|
-
|
|
173
|
+
deviceIdMap.delete(id);
|
|
174
|
+
let survivor;
|
|
175
|
+
if (deviceId) {
|
|
176
|
+
for (const [socketId, mappedDeviceId] of deviceIdMap) {
|
|
177
|
+
if (mappedDeviceId === deviceId) survivor = socketId;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (deviceId && survivor) {
|
|
181
|
+
const userIndex = users.findIndex((u) => u.deviceId === deviceId);
|
|
182
|
+
if (userIndex !== -1 && users[userIndex].id === id) {
|
|
183
|
+
users[userIndex].id = survivor;
|
|
184
|
+
}
|
|
185
|
+
const deviceIndex = allDevices.findIndex((d) => d.deviceId === deviceId);
|
|
186
|
+
if (deviceIndex !== -1 && allDevices[deviceIndex].id === id) {
|
|
187
|
+
allDevices[deviceIndex].id = survivor;
|
|
188
|
+
}
|
|
189
|
+
if (activeConnectionsMap.get(deviceId) === id) {
|
|
190
|
+
activeConnectionsMap.set(deviceId, survivor);
|
|
191
|
+
}
|
|
192
|
+
console.log(
|
|
193
|
+
`${LOG_PREFIX} Client disconnected - ID: ${id}, Name: ${user?.deviceName || "Unknown"} - Device ${deviceId} still connected via ${survivor}`
|
|
194
|
+
);
|
|
195
|
+
} else {
|
|
174
196
|
users = users.filter((user2) => user2.id !== id);
|
|
175
197
|
console.log(
|
|
176
198
|
`${LOG_PREFIX} Client disconnected - ID: ${id}, Name: ${user?.deviceName || "Unknown"} - Removing user record`
|
|
@@ -186,19 +208,15 @@ function socketHandle({ io }) {
|
|
|
186
208
|
activeConnectionsMap.delete(deviceId);
|
|
187
209
|
}
|
|
188
210
|
}
|
|
189
|
-
} else {
|
|
190
|
-
console.log(
|
|
191
|
-
`${LOG_PREFIX} Client disconnected - ID: ${id}, Name: ${user?.deviceName || "Unknown"} - Keeping user record for same device with ID: ${deviceId}`
|
|
192
|
-
);
|
|
193
211
|
}
|
|
194
|
-
deviceIdMap.delete(id);
|
|
195
212
|
const wasDashboard = dashboardClients.includes(id);
|
|
196
213
|
dashboardClients = dashboardClients.filter((clientId) => clientId !== id);
|
|
197
214
|
releaseDashboardWatches(id);
|
|
215
|
+
const stillConnected = Boolean(deviceId && survivor);
|
|
198
216
|
brokerLog(
|
|
199
|
-
wasDashboard ? "debug" : "warn",
|
|
200
|
-
`Disconnected: ${user?.deviceName || id} (${reason ?? "unknown"})`,
|
|
201
|
-
{ socketId: id, reason, wasDashboard }
|
|
217
|
+
wasDashboard || stillConnected ? "debug" : "warn",
|
|
218
|
+
stillConnected ? `Socket closed for ${user?.deviceName || id} (${reason ?? "unknown"}) \u2014 device still connected via another socket` : `Disconnected: ${user?.deviceName || id} (${reason ?? "unknown"})`,
|
|
219
|
+
{ socketId: id, reason, wasDashboard, stillConnected }
|
|
202
220
|
);
|
|
203
221
|
emitAllDevices();
|
|
204
222
|
console.log(
|
package/dist/index.mjs
CHANGED
|
@@ -130,7 +130,29 @@ function socketHandle({ io }) {
|
|
|
130
130
|
function handleClose(id, reason) {
|
|
131
131
|
const user = users.find((user2) => user2.id === id);
|
|
132
132
|
const deviceId = deviceIdMap.get(id);
|
|
133
|
-
|
|
133
|
+
deviceIdMap.delete(id);
|
|
134
|
+
let survivor;
|
|
135
|
+
if (deviceId) {
|
|
136
|
+
for (const [socketId, mappedDeviceId] of deviceIdMap) {
|
|
137
|
+
if (mappedDeviceId === deviceId) survivor = socketId;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (deviceId && survivor) {
|
|
141
|
+
const userIndex = users.findIndex((u) => u.deviceId === deviceId);
|
|
142
|
+
if (userIndex !== -1 && users[userIndex].id === id) {
|
|
143
|
+
users[userIndex].id = survivor;
|
|
144
|
+
}
|
|
145
|
+
const deviceIndex = allDevices.findIndex((d) => d.deviceId === deviceId);
|
|
146
|
+
if (deviceIndex !== -1 && allDevices[deviceIndex].id === id) {
|
|
147
|
+
allDevices[deviceIndex].id = survivor;
|
|
148
|
+
}
|
|
149
|
+
if (activeConnectionsMap.get(deviceId) === id) {
|
|
150
|
+
activeConnectionsMap.set(deviceId, survivor);
|
|
151
|
+
}
|
|
152
|
+
console.log(
|
|
153
|
+
`${LOG_PREFIX} Client disconnected - ID: ${id}, Name: ${user?.deviceName || "Unknown"} - Device ${deviceId} still connected via ${survivor}`
|
|
154
|
+
);
|
|
155
|
+
} else {
|
|
134
156
|
users = users.filter((user2) => user2.id !== id);
|
|
135
157
|
console.log(
|
|
136
158
|
`${LOG_PREFIX} Client disconnected - ID: ${id}, Name: ${user?.deviceName || "Unknown"} - Removing user record`
|
|
@@ -146,19 +168,15 @@ function socketHandle({ io }) {
|
|
|
146
168
|
activeConnectionsMap.delete(deviceId);
|
|
147
169
|
}
|
|
148
170
|
}
|
|
149
|
-
} else {
|
|
150
|
-
console.log(
|
|
151
|
-
`${LOG_PREFIX} Client disconnected - ID: ${id}, Name: ${user?.deviceName || "Unknown"} - Keeping user record for same device with ID: ${deviceId}`
|
|
152
|
-
);
|
|
153
171
|
}
|
|
154
|
-
deviceIdMap.delete(id);
|
|
155
172
|
const wasDashboard = dashboardClients.includes(id);
|
|
156
173
|
dashboardClients = dashboardClients.filter((clientId) => clientId !== id);
|
|
157
174
|
releaseDashboardWatches(id);
|
|
175
|
+
const stillConnected = Boolean(deviceId && survivor);
|
|
158
176
|
brokerLog(
|
|
159
|
-
wasDashboard ? "debug" : "warn",
|
|
160
|
-
`Disconnected: ${user?.deviceName || id} (${reason ?? "unknown"})`,
|
|
161
|
-
{ socketId: id, reason, wasDashboard }
|
|
177
|
+
wasDashboard || stillConnected ? "debug" : "warn",
|
|
178
|
+
stillConnected ? `Socket closed for ${user?.deviceName || id} (${reason ?? "unknown"}) \u2014 device still connected via another socket` : `Disconnected: ${user?.deviceName || id} (${reason ?? "unknown"})`,
|
|
179
|
+
{ socketId: id, reason, wasDashboard, stillConnected }
|
|
162
180
|
);
|
|
163
181
|
emitAllDevices();
|
|
164
182
|
console.log(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/sync-broker",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.27",
|
|
4
4
|
"description": "Headless Socket.IO broker for the Buoy devtool sync protocol (v1) — routes messages between devices and dashboard/MCP clients",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|