@scp-dev/broker 0.2.1 → 0.3.0
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 +19 -4
- package/package.json +3 -3
- package/src/server.ts +19 -4
package/dist/index.js
CHANGED
|
@@ -1375,15 +1375,22 @@ async function startBroker(options) {
|
|
|
1375
1375
|
judge.sweep();
|
|
1376
1376
|
}, SWEEP_MS);
|
|
1377
1377
|
const known = /* @__PURE__ */ new Map();
|
|
1378
|
-
|
|
1378
|
+
const wakes = /* @__PURE__ */ new Map();
|
|
1379
|
+
for (const view of localViews()) {
|
|
1380
|
+
known.set(view.id, view.presence);
|
|
1381
|
+
wakes.set(view.id, view.wake);
|
|
1382
|
+
}
|
|
1379
1383
|
const presenceTimer = setInterval(() => {
|
|
1380
1384
|
core.endExited();
|
|
1381
1385
|
const live = /* @__PURE__ */ new Set();
|
|
1382
1386
|
for (const view of localViews()) {
|
|
1383
1387
|
live.add(view.id);
|
|
1384
1388
|
if ((known.get(view.id) ?? "offline") !== view.presence) presenceChanged(view);
|
|
1389
|
+
else if (wakes.has(view.id) && wakes.get(view.id) !== view.wake) bridge?.changed(view.id);
|
|
1390
|
+
wakes.set(view.id, view.wake);
|
|
1385
1391
|
}
|
|
1386
1392
|
for (const id of known.keys()) if (!live.has(id)) known.delete(id);
|
|
1393
|
+
for (const id of wakes.keys()) if (!live.has(id)) wakes.delete(id);
|
|
1387
1394
|
}, options.presenceEveryMs ?? PRESENCE_MS);
|
|
1388
1395
|
const ownership = setInterval(() => {
|
|
1389
1396
|
if (closing || ownsState()) return;
|
|
@@ -1493,9 +1500,15 @@ async function startBroker(options) {
|
|
|
1493
1500
|
const was = s.data.waker;
|
|
1494
1501
|
if (was === endpoint) return;
|
|
1495
1502
|
s.data.waker = endpoint;
|
|
1496
|
-
if (was)
|
|
1497
|
-
|
|
1498
|
-
|
|
1503
|
+
if (was) {
|
|
1504
|
+
const wake2 = core.whoami(was).wake;
|
|
1505
|
+
core.waker(was, false, { grace: s.data.transient === true });
|
|
1506
|
+
if (!presenceMoved(was) && core.whoami(was).wake !== wake2) bridge?.changed(was);
|
|
1507
|
+
}
|
|
1508
|
+
if (endpoint) {
|
|
1509
|
+
core.waker(endpoint, true);
|
|
1510
|
+
presenceMoved(endpoint);
|
|
1511
|
+
}
|
|
1499
1512
|
}
|
|
1500
1513
|
function presenceMoved(id) {
|
|
1501
1514
|
const view = core.whoami(id);
|
|
@@ -1986,11 +1999,13 @@ async function startBroker(options) {
|
|
|
1986
1999
|
return view;
|
|
1987
2000
|
}
|
|
1988
2001
|
case "event": {
|
|
2002
|
+
const wake2 = core.whoami(me).wake;
|
|
1989
2003
|
const row = core.event(me, params, hookOf(s));
|
|
1990
2004
|
notifyFleet({ type: "activity", ...row });
|
|
1991
2005
|
bridge?.activity(me, row);
|
|
1992
2006
|
const after = core.whoami(me);
|
|
1993
2007
|
if ((known.get(me) ?? "offline") !== after.presence) presenceChanged(after);
|
|
2008
|
+
else if (after.wake !== wake2) bridge?.changed(me);
|
|
1994
2009
|
return row;
|
|
1995
2010
|
}
|
|
1996
2011
|
case "inject": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scp-dev/broker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Swarm Communication Protocol local broker: a unix socket JSON-RPC daemon over the relay core, its client and the bridge to an account hub.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://scp.dev",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"typecheck": "tsc -p ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@scp-dev/core": "0.
|
|
41
|
-
"@scp-dev/hub": "0.
|
|
40
|
+
"@scp-dev/core": "0.2.0",
|
|
41
|
+
"@scp-dev/hub": "0.6.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tsup": "^8.5.1"
|
package/src/server.ts
CHANGED
|
@@ -292,15 +292,22 @@ export async function startBroker(options: BrokerOptions): Promise<Broker> {
|
|
|
292
292
|
judge.sweep()
|
|
293
293
|
}, SWEEP_MS)
|
|
294
294
|
const known = new Map<string, Presence>()
|
|
295
|
-
|
|
295
|
+
const wakes = new Map<string, string | null | undefined>()
|
|
296
|
+
for (const view of localViews()) {
|
|
297
|
+
known.set(view.id, view.presence)
|
|
298
|
+
wakes.set(view.id, view.wake)
|
|
299
|
+
}
|
|
296
300
|
const presenceTimer = setInterval(() => {
|
|
297
301
|
core.endExited()
|
|
298
302
|
const live = new Set<string>()
|
|
299
303
|
for (const view of localViews()) {
|
|
300
304
|
live.add(view.id)
|
|
301
305
|
if ((known.get(view.id) ?? "offline") !== view.presence) presenceChanged(view)
|
|
306
|
+
else if (wakes.has(view.id) && wakes.get(view.id) !== view.wake) bridge?.changed(view.id)
|
|
307
|
+
wakes.set(view.id, view.wake)
|
|
302
308
|
}
|
|
303
309
|
for (const id of known.keys()) if (!live.has(id)) known.delete(id)
|
|
310
|
+
for (const id of wakes.keys()) if (!live.has(id)) wakes.delete(id)
|
|
304
311
|
}, options.presenceEveryMs ?? PRESENCE_MS)
|
|
305
312
|
const ownership = setInterval(() => {
|
|
306
313
|
if (closing || ownsState()) return
|
|
@@ -432,9 +439,15 @@ export async function startBroker(options: BrokerOptions): Promise<Broker> {
|
|
|
432
439
|
const was = s.data.waker
|
|
433
440
|
if (was === endpoint) return
|
|
434
441
|
s.data.waker = endpoint
|
|
435
|
-
if (was)
|
|
436
|
-
|
|
437
|
-
|
|
442
|
+
if (was) {
|
|
443
|
+
const wake = core.whoami(was).wake
|
|
444
|
+
core.waker(was, false, { grace: s.data.transient === true })
|
|
445
|
+
if (!presenceMoved(was) && core.whoami(was).wake !== wake) bridge?.changed(was)
|
|
446
|
+
}
|
|
447
|
+
if (endpoint) {
|
|
448
|
+
core.waker(endpoint, true)
|
|
449
|
+
presenceMoved(endpoint)
|
|
450
|
+
}
|
|
438
451
|
}
|
|
439
452
|
|
|
440
453
|
/** reports an endpoint's presence when it is not the one last reported; whether it was not */
|
|
@@ -976,11 +989,13 @@ export async function startBroker(options: BrokerOptions): Promise<Broker> {
|
|
|
976
989
|
return view
|
|
977
990
|
}
|
|
978
991
|
case "event": {
|
|
992
|
+
const wake = core.whoami(me).wake
|
|
979
993
|
const row = core.event(me, params, hookOf(s))
|
|
980
994
|
notifyFleet({ type: "activity", ...row })
|
|
981
995
|
bridge?.activity(me, row)
|
|
982
996
|
const after = core.whoami(me)
|
|
983
997
|
if ((known.get(me) ?? "offline") !== after.presence) presenceChanged(after)
|
|
998
|
+
else if (after.wake !== wake) bridge?.changed(me)
|
|
984
999
|
return row
|
|
985
1000
|
}
|
|
986
1001
|
case "inject": {
|