libzapitu 1.0.0-alpha.21 → 1.0.0-alpha.22
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/lib/worker/child.js +6 -3
- package/lib/worker/proxy.js +13 -2
- package/package.json +1 -1
package/lib/worker/child.js
CHANGED
|
@@ -203,12 +203,15 @@ function createSocket(socketId, rawConfig) {
|
|
|
203
203
|
/* best-effort */
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
|
-
// Send immediately (may be empty) and also on connection.open
|
|
206
|
+
// Send immediately (may be empty) and also on connection.open.
|
|
207
|
+
// IMPORTANT: we send socket-info synchronously in the connection.update
|
|
208
|
+
// listener so it arrives at the parent BEFORE the forwarded event.
|
|
209
|
+
// Otherwise wsocket.user would be undefined when the parent's
|
|
210
|
+
// connection.update handler runs.
|
|
207
211
|
sendSocketInfo();
|
|
208
212
|
sock.ev.on('connection.update', (update) => {
|
|
209
213
|
if ((update === null || update === void 0 ? void 0 : update.connection) === 'open') {
|
|
210
|
-
|
|
211
|
-
setTimeout(sendSocketInfo, 100);
|
|
214
|
+
sendSocketInfo();
|
|
212
215
|
}
|
|
213
216
|
// When the socket closes, clean up this socket entry so a new
|
|
214
217
|
// init with a different socketId can reuse this worker.
|
package/lib/worker/proxy.js
CHANGED
|
@@ -180,7 +180,7 @@ function spawnWorker() {
|
|
|
180
180
|
};
|
|
181
181
|
// Global message handler — dispatches to the right socket's emitter
|
|
182
182
|
worker.on('message', (msg) => {
|
|
183
|
-
var _a, _b, _c;
|
|
183
|
+
var _a, _b, _c, _d;
|
|
184
184
|
if (!msg || typeof msg !== 'object')
|
|
185
185
|
return;
|
|
186
186
|
const socketId = msg.socketId;
|
|
@@ -201,6 +201,17 @@ function spawnWorker() {
|
|
|
201
201
|
Object.assign(cfg.auth.creds, map['creds.update']);
|
|
202
202
|
log === null || log === void 0 ? void 0 : log.debug({ me: (_b = cfg.auth.creds.me) === null || _b === void 0 ? void 0 : _b.id }, 'synced creds.update to parent');
|
|
203
203
|
}
|
|
204
|
+
// Also update localProps.user so wsocket.user and its
|
|
205
|
+
// nested properties (id, lid, name, verifiedName, etc.)
|
|
206
|
+
// stay in sync with the worker's authState.creds.me.
|
|
207
|
+
const credsUpdate = map['creds.update'];
|
|
208
|
+
if (credsUpdate === null || credsUpdate === void 0 ? void 0 : credsUpdate.me) {
|
|
209
|
+
const props = slot.props.get(socketId);
|
|
210
|
+
if (props) {
|
|
211
|
+
props.user = { ...props.user, ...credsUpdate.me };
|
|
212
|
+
log === null || log === void 0 ? void 0 : log.debug({ me: (_c = credsUpdate.me) === null || _c === void 0 ? void 0 : _c.id }, 'synced user to localProps');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
204
215
|
}
|
|
205
216
|
// Emit the aggregated 'event' for ev.process() compatibility
|
|
206
217
|
ev.emit('event', map);
|
|
@@ -211,7 +222,7 @@ function spawnWorker() {
|
|
|
211
222
|
// When the socket closes, clean up proxy-side resources.
|
|
212
223
|
// The worker already removed its entry; we remove the
|
|
213
224
|
// emitter so a future startSock() can create a fresh one.
|
|
214
|
-
if (((
|
|
225
|
+
if (((_d = map['connection.update']) === null || _d === void 0 ? void 0 : _d.connection) === 'close') {
|
|
215
226
|
cleanupSocket(slot, socketId, log || createNoopLogger());
|
|
216
227
|
}
|
|
217
228
|
}
|