@enclave-vm/runtime 2.19.2 → 2.20.0-rc.1
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/channels/websocket-channel.d.ts +2 -0
- package/esm/index.mjs +19 -4
- package/index.js +19 -4
- package/package.json +4 -4
|
@@ -60,6 +60,8 @@ export declare class WebSocketChannel implements RuntimeChannel {
|
|
|
60
60
|
private readonly messageHandlers;
|
|
61
61
|
private retryCount;
|
|
62
62
|
private retryTimeout;
|
|
63
|
+
/** Fails the connect that is in progress, if any. */
|
|
64
|
+
private pendingConnectFailure;
|
|
63
65
|
private messageBuffer;
|
|
64
66
|
constructor(config: WebSocketChannelConfig);
|
|
65
67
|
/**
|
package/esm/index.mjs
CHANGED
|
@@ -431,6 +431,8 @@ var WebSocketChannel = class {
|
|
|
431
431
|
messageHandlers = /* @__PURE__ */ new Set();
|
|
432
432
|
retryCount = 0;
|
|
433
433
|
retryTimeout = null;
|
|
434
|
+
/** Fails the connect that is in progress, if any. */
|
|
435
|
+
pendingConnectFailure = null;
|
|
434
436
|
messageBuffer = [];
|
|
435
437
|
constructor(config) {
|
|
436
438
|
const maxBufferedMessages = config.maxBufferedMessages ?? DEFAULT_MAX_BUFFERED_MESSAGES;
|
|
@@ -465,11 +467,19 @@ var WebSocketChannel = class {
|
|
|
465
467
|
/**
|
|
466
468
|
* Connect to the WebSocket server
|
|
467
469
|
*/
|
|
468
|
-
|
|
470
|
+
connect() {
|
|
469
471
|
if (this.state === "connected" || this.state === "connecting") {
|
|
470
|
-
return;
|
|
472
|
+
return Promise.resolve();
|
|
471
473
|
}
|
|
472
474
|
return new Promise((resolve, reject) => {
|
|
475
|
+
let settled = false;
|
|
476
|
+
const fail = (error) => {
|
|
477
|
+
if (settled) return;
|
|
478
|
+
settled = true;
|
|
479
|
+
this.pendingConnectFailure = null;
|
|
480
|
+
reject(error);
|
|
481
|
+
};
|
|
482
|
+
this.pendingConnectFailure = fail;
|
|
473
483
|
this.state = "connecting";
|
|
474
484
|
this.log(`Connecting to ${this.config.url}`);
|
|
475
485
|
const WebSocketImpl = typeof WebSocket !== "undefined" ? WebSocket : __require("ws");
|
|
@@ -477,12 +487,15 @@ var WebSocketChannel = class {
|
|
|
477
487
|
this.ws = socket;
|
|
478
488
|
const timeout = setTimeout(() => {
|
|
479
489
|
if (this.state === "connecting") {
|
|
490
|
+
fail(new Error("Connection timeout"));
|
|
480
491
|
socket.close();
|
|
481
|
-
reject(new Error("Connection timeout"));
|
|
482
492
|
}
|
|
483
493
|
}, this.config.connectionTimeoutMs);
|
|
484
494
|
socket.onopen = () => {
|
|
485
495
|
clearTimeout(timeout);
|
|
496
|
+
if (settled) return;
|
|
497
|
+
settled = true;
|
|
498
|
+
this.pendingConnectFailure = null;
|
|
486
499
|
this.state = "connected";
|
|
487
500
|
this.retryCount = 0;
|
|
488
501
|
this.log("Connected");
|
|
@@ -492,6 +505,7 @@ var WebSocketChannel = class {
|
|
|
492
505
|
socket.onclose = (event) => {
|
|
493
506
|
clearTimeout(timeout);
|
|
494
507
|
this.log(`Disconnected: ${event.code} ${event.reason}`);
|
|
508
|
+
fail(new Error("Connection closed before it opened"));
|
|
495
509
|
if (this.state !== "closed") {
|
|
496
510
|
this.state = "disconnected";
|
|
497
511
|
this.handleDisconnect();
|
|
@@ -501,7 +515,7 @@ var WebSocketChannel = class {
|
|
|
501
515
|
clearTimeout(timeout);
|
|
502
516
|
this.log(`Error: ${error}`);
|
|
503
517
|
if (this.state === "connecting") {
|
|
504
|
-
|
|
518
|
+
fail(new Error("Connection failed"));
|
|
505
519
|
}
|
|
506
520
|
};
|
|
507
521
|
socket.onmessage = (event) => {
|
|
@@ -536,6 +550,7 @@ var WebSocketChannel = class {
|
|
|
536
550
|
*/
|
|
537
551
|
close() {
|
|
538
552
|
this.state = "closed";
|
|
553
|
+
this.pendingConnectFailure?.(new Error("Channel closed"));
|
|
539
554
|
if (this.retryTimeout) {
|
|
540
555
|
clearTimeout(this.retryTimeout);
|
|
541
556
|
this.retryTimeout = null;
|
package/index.js
CHANGED
|
@@ -459,6 +459,8 @@ var WebSocketChannel = class {
|
|
|
459
459
|
messageHandlers = /* @__PURE__ */ new Set();
|
|
460
460
|
retryCount = 0;
|
|
461
461
|
retryTimeout = null;
|
|
462
|
+
/** Fails the connect that is in progress, if any. */
|
|
463
|
+
pendingConnectFailure = null;
|
|
462
464
|
messageBuffer = [];
|
|
463
465
|
constructor(config) {
|
|
464
466
|
const maxBufferedMessages = config.maxBufferedMessages ?? DEFAULT_MAX_BUFFERED_MESSAGES;
|
|
@@ -493,11 +495,19 @@ var WebSocketChannel = class {
|
|
|
493
495
|
/**
|
|
494
496
|
* Connect to the WebSocket server
|
|
495
497
|
*/
|
|
496
|
-
|
|
498
|
+
connect() {
|
|
497
499
|
if (this.state === "connected" || this.state === "connecting") {
|
|
498
|
-
return;
|
|
500
|
+
return Promise.resolve();
|
|
499
501
|
}
|
|
500
502
|
return new Promise((resolve, reject) => {
|
|
503
|
+
let settled = false;
|
|
504
|
+
const fail = (error) => {
|
|
505
|
+
if (settled) return;
|
|
506
|
+
settled = true;
|
|
507
|
+
this.pendingConnectFailure = null;
|
|
508
|
+
reject(error);
|
|
509
|
+
};
|
|
510
|
+
this.pendingConnectFailure = fail;
|
|
501
511
|
this.state = "connecting";
|
|
502
512
|
this.log(`Connecting to ${this.config.url}`);
|
|
503
513
|
const WebSocketImpl = typeof WebSocket !== "undefined" ? WebSocket : require("ws");
|
|
@@ -505,12 +515,15 @@ var WebSocketChannel = class {
|
|
|
505
515
|
this.ws = socket;
|
|
506
516
|
const timeout = setTimeout(() => {
|
|
507
517
|
if (this.state === "connecting") {
|
|
518
|
+
fail(new Error("Connection timeout"));
|
|
508
519
|
socket.close();
|
|
509
|
-
reject(new Error("Connection timeout"));
|
|
510
520
|
}
|
|
511
521
|
}, this.config.connectionTimeoutMs);
|
|
512
522
|
socket.onopen = () => {
|
|
513
523
|
clearTimeout(timeout);
|
|
524
|
+
if (settled) return;
|
|
525
|
+
settled = true;
|
|
526
|
+
this.pendingConnectFailure = null;
|
|
514
527
|
this.state = "connected";
|
|
515
528
|
this.retryCount = 0;
|
|
516
529
|
this.log("Connected");
|
|
@@ -520,6 +533,7 @@ var WebSocketChannel = class {
|
|
|
520
533
|
socket.onclose = (event) => {
|
|
521
534
|
clearTimeout(timeout);
|
|
522
535
|
this.log(`Disconnected: ${event.code} ${event.reason}`);
|
|
536
|
+
fail(new Error("Connection closed before it opened"));
|
|
523
537
|
if (this.state !== "closed") {
|
|
524
538
|
this.state = "disconnected";
|
|
525
539
|
this.handleDisconnect();
|
|
@@ -529,7 +543,7 @@ var WebSocketChannel = class {
|
|
|
529
543
|
clearTimeout(timeout);
|
|
530
544
|
this.log(`Error: ${error}`);
|
|
531
545
|
if (this.state === "connecting") {
|
|
532
|
-
|
|
546
|
+
fail(new Error("Connection failed"));
|
|
533
547
|
}
|
|
534
548
|
};
|
|
535
549
|
socket.onmessage = (event) => {
|
|
@@ -564,6 +578,7 @@ var WebSocketChannel = class {
|
|
|
564
578
|
*/
|
|
565
579
|
close() {
|
|
566
580
|
this.state = "closed";
|
|
581
|
+
this.pendingConnectFailure?.(new Error("Channel closed"));
|
|
567
582
|
if (this.retryTimeout) {
|
|
568
583
|
clearTimeout(this.retryTimeout);
|
|
569
584
|
this.retryTimeout = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enclave-vm/runtime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0-rc.1",
|
|
4
4
|
"description": "Building blocks of a runtime worker for EnclaveJS: session bookkeeping and channels (does not execute code)",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"homepage": "https://github.com/agentfront/enclave",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"enclave-runtime": "./cli.js"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@enclave-vm/core": "2.
|
|
40
|
-
"@enclave-vm/stream": "2.
|
|
41
|
-
"@enclave-vm/types": "2.
|
|
39
|
+
"@enclave-vm/core": "2.20.0-rc.1",
|
|
40
|
+
"@enclave-vm/stream": "2.20.0-rc.1",
|
|
41
|
+
"@enclave-vm/types": "2.20.0-rc.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"ws": "^8.19.0"
|