@rivetkit/engine-runner 2.0.22-rc.1 → 2.0.22-rc.2
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/.turbo/turbo-build.log +10 -10
- package/dist/mod.cjs +180 -93
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +11 -4
- package/dist/mod.d.ts +11 -4
- package/dist/mod.js +180 -93
- package/dist/mod.js.map +1 -1
- package/package.json +2 -2
- package/src/mod.ts +49 -40
- package/src/tunnel.ts +160 -49
- package/src/websocket-tunnel-adapter.ts +33 -9
|
@@ -17,7 +17,7 @@ export class WebSocketTunnelAdapter {
|
|
|
17
17
|
#protocol = "";
|
|
18
18
|
#url = "";
|
|
19
19
|
#sendCallback: (data: ArrayBuffer | string, isBinary: boolean) => void;
|
|
20
|
-
#closeCallback: (code?: number, reason?: string) => void;
|
|
20
|
+
#closeCallback: (code?: number, reason?: string, retry?: boolean) => void;
|
|
21
21
|
|
|
22
22
|
// Event buffering for events fired before listeners are attached
|
|
23
23
|
#bufferedEvents: Array<{
|
|
@@ -28,7 +28,11 @@ export class WebSocketTunnelAdapter {
|
|
|
28
28
|
constructor(
|
|
29
29
|
webSocketId: string,
|
|
30
30
|
sendCallback: (data: ArrayBuffer | string, isBinary: boolean) => void,
|
|
31
|
-
closeCallback: (
|
|
31
|
+
closeCallback: (
|
|
32
|
+
code?: number,
|
|
33
|
+
reason?: string,
|
|
34
|
+
retry?: boolean,
|
|
35
|
+
) => void,
|
|
32
36
|
) {
|
|
33
37
|
this.#webSocketId = webSocketId;
|
|
34
38
|
this.#sendCallback = sendCallback;
|
|
@@ -186,6 +190,14 @@ export class WebSocketTunnelAdapter {
|
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
close(code?: number, reason?: string): void {
|
|
193
|
+
this.closeInner(code, reason);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
__closeWithRetry(code?: number, reason?: string): void {
|
|
197
|
+
this.closeInner(code, reason, true);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
closeInner(code?: number, reason?: string, retry: boolean = false): void {
|
|
189
201
|
if (
|
|
190
202
|
this.#readyState === 2 || // CLOSING
|
|
191
203
|
this.#readyState === 3 // CLOSED
|
|
@@ -196,7 +208,7 @@ export class WebSocketTunnelAdapter {
|
|
|
196
208
|
this.#readyState = 2; // CLOSING
|
|
197
209
|
|
|
198
210
|
// Send close through tunnel
|
|
199
|
-
this.#closeCallback(code, reason);
|
|
211
|
+
this.#closeCallback(code, reason, retry);
|
|
200
212
|
|
|
201
213
|
// Update state and fire event
|
|
202
214
|
this.#readyState = 3; // CLOSED
|
|
@@ -410,7 +422,7 @@ export class WebSocketTunnelAdapter {
|
|
|
410
422
|
}
|
|
411
423
|
|
|
412
424
|
// Internal methods called by the Tunnel class
|
|
413
|
-
_handleOpen(): void {
|
|
425
|
+
_handleOpen(requestId: ArrayBuffer): void {
|
|
414
426
|
if (this.#readyState !== 0) {
|
|
415
427
|
// CONNECTING
|
|
416
428
|
return;
|
|
@@ -420,16 +432,23 @@ export class WebSocketTunnelAdapter {
|
|
|
420
432
|
|
|
421
433
|
const event = {
|
|
422
434
|
type: "open",
|
|
435
|
+
rivetRequestId: requestId,
|
|
423
436
|
target: this,
|
|
424
437
|
};
|
|
425
438
|
|
|
426
439
|
this.#fireEvent("open", event);
|
|
427
440
|
}
|
|
428
441
|
|
|
429
|
-
|
|
442
|
+
/// Returns false if the message was sent off.
|
|
443
|
+
_handleMessage(
|
|
444
|
+
requestId: ArrayBuffer,
|
|
445
|
+
data: string | Uint8Array,
|
|
446
|
+
index: number,
|
|
447
|
+
isBinary: boolean,
|
|
448
|
+
): boolean {
|
|
430
449
|
if (this.#readyState !== 1) {
|
|
431
450
|
// OPEN
|
|
432
|
-
return;
|
|
451
|
+
return true;
|
|
433
452
|
}
|
|
434
453
|
|
|
435
454
|
let messageData: any;
|
|
@@ -460,15 +479,19 @@ export class WebSocketTunnelAdapter {
|
|
|
460
479
|
}
|
|
461
480
|
|
|
462
481
|
const event = {
|
|
463
|
-
data: messageData,
|
|
464
482
|
type: "message",
|
|
483
|
+
data: messageData,
|
|
484
|
+
rivetRequestId: requestId,
|
|
485
|
+
rivetMessageIndex: index,
|
|
465
486
|
target: this,
|
|
466
487
|
};
|
|
467
488
|
|
|
468
489
|
this.#fireEvent("message", event);
|
|
490
|
+
|
|
491
|
+
return false;
|
|
469
492
|
}
|
|
470
493
|
|
|
471
|
-
_handleClose(code?: number, reason?: string): void {
|
|
494
|
+
_handleClose(requestId: ArrayBuffer, code?: number, reason?: string): void {
|
|
472
495
|
if (this.#readyState === 3) {
|
|
473
496
|
// CLOSED
|
|
474
497
|
return;
|
|
@@ -477,10 +500,11 @@ export class WebSocketTunnelAdapter {
|
|
|
477
500
|
this.#readyState = 3; // CLOSED
|
|
478
501
|
|
|
479
502
|
const event = {
|
|
503
|
+
type: "close",
|
|
480
504
|
wasClean: true,
|
|
481
505
|
code: code || 1000,
|
|
482
506
|
reason: reason || "",
|
|
483
|
-
|
|
507
|
+
rivetRequestId: requestId,
|
|
484
508
|
target: this,
|
|
485
509
|
};
|
|
486
510
|
|