@actuallab/rpc 12.1.69 → 12.1.100
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.cjs +18 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +18 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -272,6 +272,7 @@ type RpcObjectKind = (typeof RpcObjectKind)[keyof typeof RpcObjectKind];
|
|
|
272
272
|
interface IRpcObject {
|
|
273
273
|
readonly id: RpcObjectId;
|
|
274
274
|
readonly kind: RpcObjectKind;
|
|
275
|
+
readonly allowReconnect: boolean;
|
|
275
276
|
reconnect(): void;
|
|
276
277
|
disconnect(): void;
|
|
277
278
|
}
|
|
@@ -423,6 +424,7 @@ interface RpcStreamRef {
|
|
|
423
424
|
readonly localId: number;
|
|
424
425
|
readonly ackPeriod: number;
|
|
425
426
|
readonly ackAdvance: number;
|
|
427
|
+
readonly allowReconnect: boolean;
|
|
426
428
|
}
|
|
427
429
|
/**
|
|
428
430
|
* Parses a stream reference string of the form "{hostId},{localId},{ackPeriod},{ackAdvance}".
|
|
@@ -443,6 +445,7 @@ declare function parseStreamRef(value: unknown): RpcStreamRef | null;
|
|
|
443
445
|
declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
|
|
444
446
|
readonly id: RpcObjectId;
|
|
445
447
|
readonly kind: 1;
|
|
448
|
+
readonly allowReconnect: boolean;
|
|
446
449
|
readonly peer: RpcPeer;
|
|
447
450
|
readonly ackPeriod: number;
|
|
448
451
|
readonly ackAdvance: number;
|
|
@@ -494,13 +497,14 @@ declare function resolveStreamRefs(value: unknown, peer: RpcPeer): unknown;
|
|
|
494
497
|
declare class RpcStreamSender<T> implements IRpcObject {
|
|
495
498
|
readonly id: RpcObjectId;
|
|
496
499
|
readonly kind: 0;
|
|
500
|
+
readonly allowReconnect: boolean;
|
|
497
501
|
readonly peer: RpcPeer;
|
|
498
502
|
readonly ackPeriod: number;
|
|
499
503
|
readonly ackAdvance: number;
|
|
500
504
|
private _nextIndex;
|
|
501
505
|
private _ended;
|
|
502
506
|
private _started;
|
|
503
|
-
constructor(peer: RpcPeer, ackPeriod?: number, ackAdvance?: number);
|
|
507
|
+
constructor(peer: RpcPeer, ackPeriod?: number, ackAdvance?: number, allowReconnect?: boolean);
|
|
504
508
|
/** Returns the stream reference string for the $sys.Ok response. */
|
|
505
509
|
toRef(): string;
|
|
506
510
|
/** Called by system call handler when $sys.Ack is received from the client. */
|
package/dist/index.d.ts
CHANGED
|
@@ -272,6 +272,7 @@ type RpcObjectKind = (typeof RpcObjectKind)[keyof typeof RpcObjectKind];
|
|
|
272
272
|
interface IRpcObject {
|
|
273
273
|
readonly id: RpcObjectId;
|
|
274
274
|
readonly kind: RpcObjectKind;
|
|
275
|
+
readonly allowReconnect: boolean;
|
|
275
276
|
reconnect(): void;
|
|
276
277
|
disconnect(): void;
|
|
277
278
|
}
|
|
@@ -423,6 +424,7 @@ interface RpcStreamRef {
|
|
|
423
424
|
readonly localId: number;
|
|
424
425
|
readonly ackPeriod: number;
|
|
425
426
|
readonly ackAdvance: number;
|
|
427
|
+
readonly allowReconnect: boolean;
|
|
426
428
|
}
|
|
427
429
|
/**
|
|
428
430
|
* Parses a stream reference string of the form "{hostId},{localId},{ackPeriod},{ackAdvance}".
|
|
@@ -443,6 +445,7 @@ declare function parseStreamRef(value: unknown): RpcStreamRef | null;
|
|
|
443
445
|
declare class RpcStream<T> implements AsyncIterable<T>, IRpcObject {
|
|
444
446
|
readonly id: RpcObjectId;
|
|
445
447
|
readonly kind: 1;
|
|
448
|
+
readonly allowReconnect: boolean;
|
|
446
449
|
readonly peer: RpcPeer;
|
|
447
450
|
readonly ackPeriod: number;
|
|
448
451
|
readonly ackAdvance: number;
|
|
@@ -494,13 +497,14 @@ declare function resolveStreamRefs(value: unknown, peer: RpcPeer): unknown;
|
|
|
494
497
|
declare class RpcStreamSender<T> implements IRpcObject {
|
|
495
498
|
readonly id: RpcObjectId;
|
|
496
499
|
readonly kind: 0;
|
|
500
|
+
readonly allowReconnect: boolean;
|
|
497
501
|
readonly peer: RpcPeer;
|
|
498
502
|
readonly ackPeriod: number;
|
|
499
503
|
readonly ackAdvance: number;
|
|
500
504
|
private _nextIndex;
|
|
501
505
|
private _ended;
|
|
502
506
|
private _started;
|
|
503
|
-
constructor(peer: RpcPeer, ackPeriod?: number, ackAdvance?: number);
|
|
507
|
+
constructor(peer: RpcPeer, ackPeriod?: number, ackAdvance?: number, allowReconnect?: boolean);
|
|
504
508
|
/** Returns the stream reference string for the $sys.Ok response. */
|
|
505
509
|
toRef(): string;
|
|
506
510
|
/** Called by system call handler when $sys.Ack is received from the client. */
|
package/dist/index.js
CHANGED
|
@@ -310,17 +310,19 @@ var RpcObjectKind = { Local: 0, Remote: 1 };
|
|
|
310
310
|
function parseStreamRef(value) {
|
|
311
311
|
if (typeof value !== "string") return null;
|
|
312
312
|
const parts = value.split(",");
|
|
313
|
-
if (parts.length
|
|
313
|
+
if (parts.length < 4 || parts.length > 5) return null;
|
|
314
314
|
const hostId = parts[0];
|
|
315
315
|
const localId = parseInt(parts[1], 10);
|
|
316
316
|
const ackPeriod = parseInt(parts[2], 10);
|
|
317
317
|
const ackAdvance = parseInt(parts[3], 10);
|
|
318
318
|
if (isNaN(localId) || isNaN(ackPeriod) || isNaN(ackAdvance)) return null;
|
|
319
|
-
|
|
319
|
+
const allowReconnect = parts.length < 5 || parts[4] !== "0";
|
|
320
|
+
return { hostId, localId, ackPeriod, ackAdvance, allowReconnect };
|
|
320
321
|
}
|
|
321
322
|
var RpcStream = class {
|
|
322
323
|
id;
|
|
323
324
|
kind = RpcObjectKind.Remote;
|
|
325
|
+
allowReconnect;
|
|
324
326
|
peer;
|
|
325
327
|
ackPeriod;
|
|
326
328
|
ackAdvance;
|
|
@@ -335,6 +337,7 @@ var RpcStream = class {
|
|
|
335
337
|
_ackSentUpTo = 0;
|
|
336
338
|
constructor(ref, peer) {
|
|
337
339
|
this.id = { hostId: ref.hostId, localId: ref.localId };
|
|
340
|
+
this.allowReconnect = ref.allowReconnect;
|
|
338
341
|
this.peer = peer;
|
|
339
342
|
this.ackPeriod = ref.ackPeriod;
|
|
340
343
|
this.ackAdvance = ref.ackAdvance;
|
|
@@ -380,7 +383,11 @@ var RpcStream = class {
|
|
|
380
383
|
}
|
|
381
384
|
// -- IRpcObject --
|
|
382
385
|
reconnect() {
|
|
383
|
-
|
|
386
|
+
if (this.allowReconnect) {
|
|
387
|
+
this._sendAck(this._nextExpectedIndex, true);
|
|
388
|
+
} else {
|
|
389
|
+
this.disconnect();
|
|
390
|
+
}
|
|
384
391
|
}
|
|
385
392
|
disconnect() {
|
|
386
393
|
if (this._completed) return;
|
|
@@ -633,22 +640,24 @@ var DEFAULT_ACK_ADVANCE = 128;
|
|
|
633
640
|
var RpcStreamSender = class {
|
|
634
641
|
id;
|
|
635
642
|
kind = RpcObjectKind.Local;
|
|
643
|
+
allowReconnect;
|
|
636
644
|
peer;
|
|
637
645
|
ackPeriod;
|
|
638
646
|
ackAdvance;
|
|
639
647
|
_nextIndex = 0;
|
|
640
648
|
_ended = false;
|
|
641
649
|
_started = new PromiseSource4();
|
|
642
|
-
constructor(peer, ackPeriod = DEFAULT_ACK_PERIOD, ackAdvance = DEFAULT_ACK_ADVANCE) {
|
|
650
|
+
constructor(peer, ackPeriod = DEFAULT_ACK_PERIOD, ackAdvance = DEFAULT_ACK_ADVANCE, allowReconnect = true) {
|
|
643
651
|
const localId = peer.sharedObjects.nextId();
|
|
644
652
|
this.id = { hostId: peer.hub.hubId, localId };
|
|
653
|
+
this.allowReconnect = allowReconnect;
|
|
645
654
|
this.peer = peer;
|
|
646
655
|
this.ackPeriod = ackPeriod;
|
|
647
656
|
this.ackAdvance = ackAdvance;
|
|
648
657
|
}
|
|
649
658
|
/** Returns the stream reference string for the $sys.Ok response. */
|
|
650
659
|
toRef() {
|
|
651
|
-
return `${this.id.hostId},${this.id.localId},${this.ackPeriod},${this.ackAdvance}`;
|
|
660
|
+
return `${this.id.hostId},${this.id.localId},${this.ackPeriod},${this.ackAdvance},${this.allowReconnect ? "1" : "0"}`;
|
|
652
661
|
}
|
|
653
662
|
/** Called by system call handler when $sys.Ack is received from the client. */
|
|
654
663
|
onAck(_nextIndex, _hostId) {
|
|
@@ -738,7 +747,10 @@ var RpcRemoteObjectTracker = class {
|
|
|
738
747
|
}
|
|
739
748
|
reconnectAll() {
|
|
740
749
|
for (const obj of this._objects.values()) {
|
|
741
|
-
obj.
|
|
750
|
+
if (obj.allowReconnect)
|
|
751
|
+
obj.reconnect();
|
|
752
|
+
else
|
|
753
|
+
obj.disconnect();
|
|
742
754
|
}
|
|
743
755
|
}
|
|
744
756
|
};
|