@replit/river 0.12.6 → 0.13.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/README.md +4 -1
- package/dist/{builder-c593de11.d.ts → builder-169fbf7f.d.ts} +16 -7
- package/dist/{chunk-AFLZ6INU.js → chunk-CBRQM65K.js} +29 -10
- package/dist/{chunk-IIBVKYDB.js → chunk-CDH7QSB4.js} +39 -1
- package/dist/{chunk-XFFS4UOD.js → chunk-MGGIUH5O.js} +7 -7
- package/dist/{chunk-VLBVQX5H.js → chunk-NPXAAD7M.js} +1 -1
- package/dist/{chunk-4SDJ5VN4.js → chunk-R2IMXRVU.js} +150 -116
- package/dist/{connection-ba37d174.d.ts → connection-ab681c08.d.ts} +1 -1
- package/dist/{messageFraming-b200ef25.d.ts → connection-dd789651.d.ts} +17 -2
- package/dist/{index-54e0f99c.d.ts → index-21c1b21d.d.ts} +29 -13
- package/dist/router/index.cjs +31 -13
- package/dist/router/index.d.cts +5 -5
- package/dist/router/index.d.ts +5 -5
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/uds/client.cjs +143 -121
- package/dist/transport/impls/uds/client.d.cts +2 -3
- package/dist/transport/impls/uds/client.d.ts +2 -3
- package/dist/transport/impls/uds/client.js +5 -6
- package/dist/transport/impls/uds/server.cjs +151 -127
- package/dist/transport/impls/uds/server.d.cts +2 -3
- package/dist/transport/impls/uds/server.d.ts +2 -3
- package/dist/transport/impls/uds/server.js +4 -5
- package/dist/transport/impls/ws/client.cjs +147 -123
- package/dist/transport/impls/ws/client.d.cts +4 -4
- package/dist/transport/impls/ws/client.d.ts +4 -4
- package/dist/transport/impls/ws/client.js +7 -7
- package/dist/transport/impls/ws/server.cjs +151 -127
- package/dist/transport/impls/ws/server.d.cts +2 -2
- package/dist/transport/impls/ws/server.d.ts +2 -2
- package/dist/transport/impls/ws/server.js +4 -4
- package/dist/transport/index.cjs +202 -167
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +3 -3
- package/dist/util/testHelpers.cjs +294 -16
- package/dist/util/testHelpers.d.cts +2 -2
- package/dist/util/testHelpers.d.ts +2 -2
- package/dist/util/testHelpers.js +30 -8
- package/package.json +1 -9
- package/dist/chunk-PBPXYLI6.js +0 -44
- package/dist/chunk-Q7GL34DZ.js +0 -47
- package/dist/connection-1f9971d8.d.ts +0 -17
- package/dist/connection-24d878ac.d.ts +0 -18
- package/dist/transport/impls/stdio/client.cjs +0 -904
- package/dist/transport/impls/stdio/client.d.cts +0 -27
- package/dist/transport/impls/stdio/client.d.ts +0 -27
- package/dist/transport/impls/stdio/client.js +0 -42
- package/dist/transport/impls/stdio/server.cjs +0 -879
- package/dist/transport/impls/stdio/server.d.cts +0 -25
- package/dist/transport/impls/stdio/server.d.ts +0 -25
- package/dist/transport/impls/stdio/server.js +0 -33
|
@@ -36,8 +36,8 @@ var TransportMessageSchema = (t) => import_typebox.Type.Object({
|
|
|
36
36
|
to: import_typebox.Type.String(),
|
|
37
37
|
seq: import_typebox.Type.Integer(),
|
|
38
38
|
ack: import_typebox.Type.Integer(),
|
|
39
|
-
serviceName: import_typebox.Type.Optional(import_typebox.Type.
|
|
40
|
-
procedureName: import_typebox.Type.Optional(import_typebox.Type.
|
|
39
|
+
serviceName: import_typebox.Type.Optional(import_typebox.Type.String()),
|
|
40
|
+
procedureName: import_typebox.Type.Optional(import_typebox.Type.String()),
|
|
41
41
|
streamId: import_typebox.Type.String(),
|
|
42
42
|
controlFlags: import_typebox.Type.Integer(),
|
|
43
43
|
payload: t
|
|
@@ -51,7 +51,7 @@ var ControlMessageCloseSchema = import_typebox.Type.Object({
|
|
|
51
51
|
var PROTOCOL_VERSION = "v1";
|
|
52
52
|
var ControlMessageHandshakeRequestSchema = import_typebox.Type.Object({
|
|
53
53
|
type: import_typebox.Type.Literal("HANDSHAKE_REQ"),
|
|
54
|
-
protocolVersion: import_typebox.Type.
|
|
54
|
+
protocolVersion: import_typebox.Type.String(),
|
|
55
55
|
instanceId: import_typebox.Type.String()
|
|
56
56
|
});
|
|
57
57
|
var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
|
|
@@ -76,7 +76,7 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
|
|
|
76
76
|
var OpaqueTransportMessageSchema = TransportMessageSchema(
|
|
77
77
|
import_typebox.Type.Unknown()
|
|
78
78
|
);
|
|
79
|
-
function
|
|
79
|
+
function handshakeRequestMessage(from, to, instanceId) {
|
|
80
80
|
return {
|
|
81
81
|
id: (0, import_nanoid.nanoid)(),
|
|
82
82
|
from,
|
|
@@ -129,6 +129,60 @@ var EventDispatcher = class {
|
|
|
129
129
|
|
|
130
130
|
// transport/session.ts
|
|
131
131
|
var import_nanoid2 = require("nanoid");
|
|
132
|
+
|
|
133
|
+
// codec/json.ts
|
|
134
|
+
var encoder = new TextEncoder();
|
|
135
|
+
var decoder = new TextDecoder();
|
|
136
|
+
function uint8ArrayToBase64(uint8Array) {
|
|
137
|
+
let binary = "";
|
|
138
|
+
uint8Array.forEach((byte) => {
|
|
139
|
+
binary += String.fromCharCode(byte);
|
|
140
|
+
});
|
|
141
|
+
return btoa(binary);
|
|
142
|
+
}
|
|
143
|
+
function base64ToUint8Array(base64) {
|
|
144
|
+
const binaryString = atob(base64);
|
|
145
|
+
const uint8Array = new Uint8Array(binaryString.length);
|
|
146
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
147
|
+
uint8Array[i] = binaryString.charCodeAt(i);
|
|
148
|
+
}
|
|
149
|
+
return uint8Array;
|
|
150
|
+
}
|
|
151
|
+
var NaiveJsonCodec = {
|
|
152
|
+
toBuffer: (obj) => {
|
|
153
|
+
return encoder.encode(
|
|
154
|
+
JSON.stringify(obj, function replacer(key) {
|
|
155
|
+
const val = this[key];
|
|
156
|
+
if (val instanceof Uint8Array) {
|
|
157
|
+
return { $t: uint8ArrayToBase64(val) };
|
|
158
|
+
} else {
|
|
159
|
+
return val;
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
},
|
|
164
|
+
fromBuffer: (buff) => {
|
|
165
|
+
try {
|
|
166
|
+
const parsed = JSON.parse(
|
|
167
|
+
decoder.decode(buff),
|
|
168
|
+
function reviver(_key, val) {
|
|
169
|
+
if (val?.$t) {
|
|
170
|
+
return base64ToUint8Array(val.$t);
|
|
171
|
+
} else {
|
|
172
|
+
return val;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
if (typeof parsed === "object")
|
|
177
|
+
return parsed;
|
|
178
|
+
return null;
|
|
179
|
+
} catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// transport/session.ts
|
|
132
186
|
var nanoid2 = (0, import_nanoid2.customAlphabet)("1234567890abcdefghijklmnopqrstuvxyz", 6);
|
|
133
187
|
var unsafeId = () => nanoid2();
|
|
134
188
|
var Connection = class {
|
|
@@ -140,8 +194,15 @@ var Connection = class {
|
|
|
140
194
|
var HEARTBEAT_INTERVAL_MS = 1e3;
|
|
141
195
|
var HEARTBEATS_TILL_DEAD = 2;
|
|
142
196
|
var SESSION_DISCONNECT_GRACE_MS = 5e3;
|
|
197
|
+
var defaultSessionOptions = {
|
|
198
|
+
heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
|
|
199
|
+
heartbeatsUntilDead: HEARTBEATS_TILL_DEAD,
|
|
200
|
+
sessionDisconnectGraceMs: SESSION_DISCONNECT_GRACE_MS,
|
|
201
|
+
codec: NaiveJsonCodec
|
|
202
|
+
};
|
|
143
203
|
var Session = class {
|
|
144
204
|
codec;
|
|
205
|
+
options;
|
|
145
206
|
/**
|
|
146
207
|
* The buffer of messages that have been sent but not yet acknowledged.
|
|
147
208
|
*/
|
|
@@ -177,16 +238,17 @@ var Session = class {
|
|
|
177
238
|
* The interval for sending heartbeats.
|
|
178
239
|
*/
|
|
179
240
|
heartbeat;
|
|
180
|
-
constructor(
|
|
241
|
+
constructor(from, connectedTo, conn, options) {
|
|
242
|
+
this.options = options;
|
|
181
243
|
this.debugId = `sess-${unsafeId()}`;
|
|
182
244
|
this.from = from;
|
|
183
245
|
this.to = connectedTo;
|
|
184
246
|
this.connection = conn;
|
|
185
|
-
this.codec = codec;
|
|
247
|
+
this.codec = options.codec;
|
|
186
248
|
this.heartbeatMisses = 0;
|
|
187
249
|
this.heartbeat = setInterval(
|
|
188
250
|
() => this.sendHeartbeat(),
|
|
189
|
-
|
|
251
|
+
options.heartbeatIntervalMs
|
|
190
252
|
);
|
|
191
253
|
}
|
|
192
254
|
/**
|
|
@@ -222,7 +284,7 @@ var Session = class {
|
|
|
222
284
|
return fullMsg.id;
|
|
223
285
|
}
|
|
224
286
|
sendHeartbeat() {
|
|
225
|
-
if (this.heartbeatMisses >=
|
|
287
|
+
if (this.heartbeatMisses >= this.options.heartbeatsUntilDead) {
|
|
226
288
|
if (this.connection) {
|
|
227
289
|
log?.info(
|
|
228
290
|
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
@@ -292,7 +354,7 @@ var Session = class {
|
|
|
292
354
|
this.disconnectionGrace = setTimeout(() => {
|
|
293
355
|
this.close();
|
|
294
356
|
cb();
|
|
295
|
-
},
|
|
357
|
+
}, this.options.sessionDisconnectGraceMs);
|
|
296
358
|
}
|
|
297
359
|
// called on reconnect of the underlying session
|
|
298
360
|
cancelGrace() {
|
|
@@ -330,58 +392,6 @@ var Session = class {
|
|
|
330
392
|
}
|
|
331
393
|
};
|
|
332
394
|
|
|
333
|
-
// codec/json.ts
|
|
334
|
-
var encoder = new TextEncoder();
|
|
335
|
-
var decoder = new TextDecoder();
|
|
336
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
337
|
-
let binary = "";
|
|
338
|
-
uint8Array.forEach((byte) => {
|
|
339
|
-
binary += String.fromCharCode(byte);
|
|
340
|
-
});
|
|
341
|
-
return btoa(binary);
|
|
342
|
-
}
|
|
343
|
-
function base64ToUint8Array(base64) {
|
|
344
|
-
const binaryString = atob(base64);
|
|
345
|
-
const uint8Array = new Uint8Array(binaryString.length);
|
|
346
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
347
|
-
uint8Array[i] = binaryString.charCodeAt(i);
|
|
348
|
-
}
|
|
349
|
-
return uint8Array;
|
|
350
|
-
}
|
|
351
|
-
var NaiveJsonCodec = {
|
|
352
|
-
toBuffer: (obj) => {
|
|
353
|
-
return encoder.encode(
|
|
354
|
-
JSON.stringify(obj, function replacer(key) {
|
|
355
|
-
const val = this[key];
|
|
356
|
-
if (val instanceof Uint8Array) {
|
|
357
|
-
return { $t: uint8ArrayToBase64(val) };
|
|
358
|
-
} else {
|
|
359
|
-
return val;
|
|
360
|
-
}
|
|
361
|
-
})
|
|
362
|
-
);
|
|
363
|
-
},
|
|
364
|
-
fromBuffer: (buff) => {
|
|
365
|
-
try {
|
|
366
|
-
const parsed = JSON.parse(
|
|
367
|
-
decoder.decode(buff),
|
|
368
|
-
function reviver(_key, val) {
|
|
369
|
-
if (val?.$t) {
|
|
370
|
-
return base64ToUint8Array(val.$t);
|
|
371
|
-
} else {
|
|
372
|
-
return val;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
);
|
|
376
|
-
if (typeof parsed === "object")
|
|
377
|
-
return parsed;
|
|
378
|
-
return null;
|
|
379
|
-
} catch {
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
|
|
385
395
|
// transport/transport.ts
|
|
386
396
|
var import_nanoid3 = require("nanoid");
|
|
387
397
|
|
|
@@ -394,13 +404,13 @@ function coerceErrorString(err) {
|
|
|
394
404
|
}
|
|
395
405
|
|
|
396
406
|
// transport/transport.ts
|
|
397
|
-
var
|
|
398
|
-
var
|
|
407
|
+
var RECONNECT_JITTER_MAX_MS = 500;
|
|
408
|
+
var RECONNECT_INTERVAL_MS = 250;
|
|
399
409
|
var defaultTransportOptions = {
|
|
400
|
-
retryIntervalMs:
|
|
401
|
-
retryJitterMs:
|
|
410
|
+
retryIntervalMs: RECONNECT_INTERVAL_MS,
|
|
411
|
+
retryJitterMs: RECONNECT_JITTER_MAX_MS,
|
|
402
412
|
retryAttemptsMax: 5,
|
|
403
|
-
|
|
413
|
+
...defaultSessionOptions
|
|
404
414
|
};
|
|
405
415
|
var Transport = class {
|
|
406
416
|
/**
|
|
@@ -471,7 +481,7 @@ var Transport = class {
|
|
|
471
481
|
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
472
482
|
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
473
483
|
log?.warn(
|
|
474
|
-
`${this.clientId} --
|
|
484
|
+
`${this.clientId} -- connection from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
475
485
|
);
|
|
476
486
|
oldSession.close();
|
|
477
487
|
this.deleteSession(oldSession);
|
|
@@ -494,10 +504,10 @@ var Transport = class {
|
|
|
494
504
|
}
|
|
495
505
|
createSession(connectedTo, conn) {
|
|
496
506
|
const session = new Session(
|
|
497
|
-
this.codec,
|
|
498
507
|
this.clientId,
|
|
499
508
|
connectedTo,
|
|
500
|
-
conn
|
|
509
|
+
conn,
|
|
510
|
+
this.options
|
|
501
511
|
);
|
|
502
512
|
this.sessions.set(session.to, session);
|
|
503
513
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
@@ -540,7 +550,7 @@ var Transport = class {
|
|
|
540
550
|
parseMsg(msg) {
|
|
541
551
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
542
552
|
if (parsedMsg === null) {
|
|
543
|
-
const decodedBuffer = new TextDecoder().decode(msg);
|
|
553
|
+
const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
|
|
544
554
|
log?.error(
|
|
545
555
|
`${this.clientId} -- received malformed msg, killing conn: ${decodedBuffer}`
|
|
546
556
|
);
|
|
@@ -554,11 +564,7 @@ var Transport = class {
|
|
|
554
564
|
);
|
|
555
565
|
return null;
|
|
556
566
|
}
|
|
557
|
-
return
|
|
558
|
-
...parsedMsg,
|
|
559
|
-
serviceName: parsedMsg.serviceName === null ? void 0 : parsedMsg.serviceName,
|
|
560
|
-
procedureName: parsedMsg.procedureName === null ? void 0 : parsedMsg.procedureName
|
|
561
|
-
};
|
|
567
|
+
return parsedMsg;
|
|
562
568
|
}
|
|
563
569
|
/**
|
|
564
570
|
* Called when a message is received by this transport.
|
|
@@ -577,11 +583,18 @@ var Transport = class {
|
|
|
577
583
|
session.cancelGrace();
|
|
578
584
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
579
585
|
if (msg.seq !== session.nextExpectedSeq) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
msg
|
|
583
|
-
|
|
584
|
-
|
|
586
|
+
if (msg.seq < session.nextExpectedSeq) {
|
|
587
|
+
log?.debug(
|
|
588
|
+
`${this.clientId} -- received duplicate msg (got: ${msg.seq}, wanted: ${session.nextExpectedSeq}), discarding: ${JSON.stringify(
|
|
589
|
+
msg
|
|
590
|
+
)}`
|
|
591
|
+
);
|
|
592
|
+
} else {
|
|
593
|
+
log?.error(
|
|
594
|
+
`${this.clientId} -- received out-of-order msg (got: ${msg.seq}, wanted: ${session.nextExpectedSeq}), marking connection as dead: ${JSON.stringify(msg)}`
|
|
595
|
+
);
|
|
596
|
+
session.closeStaleConnection(session.connection);
|
|
597
|
+
}
|
|
585
598
|
return;
|
|
586
599
|
}
|
|
587
600
|
if (!isAck(msg.controlFlags)) {
|
|
@@ -599,7 +612,7 @@ var Transport = class {
|
|
|
599
612
|
}
|
|
600
613
|
/**
|
|
601
614
|
* Removes a listener from this transport.
|
|
602
|
-
* @param the type of event to
|
|
615
|
+
* @param the type of event to un-listen on
|
|
603
616
|
* @param handler The message handler to remove.
|
|
604
617
|
*/
|
|
605
618
|
removeEventListener(type, handler) {
|
|
@@ -676,23 +689,31 @@ var ClientTransport = class extends Transport {
|
|
|
676
689
|
*/
|
|
677
690
|
inflightConnectionPromises;
|
|
678
691
|
tryReconnecting = true;
|
|
679
|
-
|
|
692
|
+
connectedTo;
|
|
693
|
+
constructor(clientId, connectedTo, providedOptions) {
|
|
680
694
|
super(clientId, providedOptions);
|
|
695
|
+
this.connectedTo = connectedTo;
|
|
681
696
|
this.inflightConnectionPromises = /* @__PURE__ */ new Map();
|
|
682
697
|
}
|
|
683
698
|
handleConnection(conn, to) {
|
|
684
|
-
const
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
699
|
+
const handshakeHandler = (data) => {
|
|
700
|
+
const handshake = this.receiveHandshakeResponseMessage(data);
|
|
701
|
+
if (!handshake) {
|
|
702
|
+
conn.close();
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
this.onConnect(conn, handshake.from, handshake.instanceId);
|
|
706
|
+
conn.removeDataListener(handshakeHandler);
|
|
707
|
+
conn.addDataListener((data2) => {
|
|
708
|
+
const parsed = this.parseMsg(data2);
|
|
688
709
|
if (!parsed) {
|
|
689
710
|
conn.close();
|
|
690
711
|
return;
|
|
691
712
|
}
|
|
692
713
|
this.handleMsg(parsed);
|
|
693
714
|
});
|
|
694
|
-
}
|
|
695
|
-
conn.addDataListener(
|
|
715
|
+
};
|
|
716
|
+
conn.addDataListener(handshakeHandler);
|
|
696
717
|
conn.addCloseListener(() => {
|
|
697
718
|
this.onDisconnect(conn, to);
|
|
698
719
|
void this.connect(to);
|
|
@@ -703,6 +724,32 @@ var ClientTransport = class extends Transport {
|
|
|
703
724
|
);
|
|
704
725
|
});
|
|
705
726
|
}
|
|
727
|
+
receiveHandshakeResponseMessage(data) {
|
|
728
|
+
const parsed = this.parseMsg(data);
|
|
729
|
+
if (!parsed)
|
|
730
|
+
return false;
|
|
731
|
+
if (!import_value.Value.Check(ControlMessageHandshakeResponseSchema, parsed.payload)) {
|
|
732
|
+
log?.warn(
|
|
733
|
+
`${this.clientId} -- received invalid handshake resp: ${JSON.stringify(
|
|
734
|
+
parsed
|
|
735
|
+
)}`
|
|
736
|
+
);
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
if (!parsed.payload.status.ok) {
|
|
740
|
+
log?.warn(
|
|
741
|
+
`${this.clientId} -- received failed handshake resp: ${JSON.stringify(
|
|
742
|
+
parsed
|
|
743
|
+
)}`
|
|
744
|
+
);
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
const instanceId = parsed.payload.status.instanceId;
|
|
748
|
+
log?.debug(
|
|
749
|
+
`${this.clientId} -- handshake from ${parsed.from} ok (instance: ${instanceId})`
|
|
750
|
+
);
|
|
751
|
+
return { instanceId, from: parsed.from };
|
|
752
|
+
}
|
|
706
753
|
/**
|
|
707
754
|
* Manually attempts to connect to a client.
|
|
708
755
|
* @param to The client ID of the node to connect to.
|
|
@@ -721,10 +768,7 @@ var ClientTransport = class extends Transport {
|
|
|
721
768
|
}
|
|
722
769
|
try {
|
|
723
770
|
const conn = await reconnectPromise;
|
|
724
|
-
this.
|
|
725
|
-
const requestMsg = bootRequestMessage(this.clientId, to, this.instanceId);
|
|
726
|
-
log?.debug(`${this.clientId} -- sending boot handshake to ${to}`);
|
|
727
|
-
conn.send(this.codec.toBuffer(requestMsg));
|
|
771
|
+
this.sendHandshake(to, conn);
|
|
728
772
|
} catch (error) {
|
|
729
773
|
const errStr = coerceErrorString(error);
|
|
730
774
|
this.inflightConnectionPromises.delete(to);
|
|
@@ -742,34 +786,14 @@ var ClientTransport = class extends Transport {
|
|
|
742
786
|
}
|
|
743
787
|
}
|
|
744
788
|
}
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
log?.warn(
|
|
754
|
-
`${this.clientId} -- received invalid handshake resp: ${JSON.stringify(parsed)}`
|
|
755
|
-
);
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
if (!parsed.payload.status.ok) {
|
|
759
|
-
log?.warn(
|
|
760
|
-
`${this.clientId} -- received failed handshake resp: ${JSON.stringify(
|
|
761
|
-
parsed
|
|
762
|
-
)}`
|
|
763
|
-
);
|
|
764
|
-
return;
|
|
765
|
-
}
|
|
766
|
-
const serverInstanceId = parsed.payload.status.instanceId;
|
|
767
|
-
log?.debug(
|
|
768
|
-
`${this.clientId} -- handshake from ${parsed.from} ok (server instance: ${serverInstanceId})`
|
|
769
|
-
);
|
|
770
|
-
sessionCb(this.onConnect(conn, parsed.from, serverInstanceId));
|
|
771
|
-
};
|
|
772
|
-
return bootHandler;
|
|
789
|
+
sendHandshake(to, conn) {
|
|
790
|
+
const requestMsg = handshakeRequestMessage(
|
|
791
|
+
this.clientId,
|
|
792
|
+
to,
|
|
793
|
+
this.instanceId
|
|
794
|
+
);
|
|
795
|
+
log?.debug(`${this.clientId} -- sending handshake request to ${to}`);
|
|
796
|
+
conn.send(this.codec.toBuffer(requestMsg));
|
|
773
797
|
}
|
|
774
798
|
onDisconnect(conn, connectedTo) {
|
|
775
799
|
this.inflightConnectionPromises.delete(connectedTo);
|
|
@@ -820,12 +844,12 @@ var WebSocketClientTransport = class extends ClientTransport {
|
|
|
820
844
|
/**
|
|
821
845
|
* Creates a new WebSocketClientTransport instance.
|
|
822
846
|
* @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
|
|
823
|
-
* @param
|
|
847
|
+
* @param clientId The ID of the client using the transport. This should be unique per session.
|
|
824
848
|
* @param serverId The ID of the server this transport is connecting to.
|
|
825
849
|
* @param providedOptions An optional object containing configuration options for the transport.
|
|
826
850
|
*/
|
|
827
|
-
constructor(wsGetter,
|
|
828
|
-
super(
|
|
851
|
+
constructor(wsGetter, clientId, serverId, providedOptions) {
|
|
852
|
+
super(clientId, serverId, providedOptions);
|
|
829
853
|
this.wsGetter = wsGetter;
|
|
830
854
|
this.serverId = serverId;
|
|
831
855
|
void this.connect(this.serverId);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
3
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
2
|
+
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js';
|
|
3
|
+
import { W as WebSocketConnection } from '../../../connection-ab681c08.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
|
|
@@ -18,11 +18,11 @@ declare class WebSocketClientTransport extends ClientTransport<WebSocketConnecti
|
|
|
18
18
|
/**
|
|
19
19
|
* Creates a new WebSocketClientTransport instance.
|
|
20
20
|
* @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
|
|
21
|
-
* @param
|
|
21
|
+
* @param clientId The ID of the client using the transport. This should be unique per session.
|
|
22
22
|
* @param serverId The ID of the server this transport is connecting to.
|
|
23
23
|
* @param providedOptions An optional object containing configuration options for the transport.
|
|
24
24
|
*/
|
|
25
|
-
constructor(wsGetter: () => Promise<WebSocket>,
|
|
25
|
+
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<TransportOptions>);
|
|
26
26
|
reopen(): void;
|
|
27
27
|
createNewOutgoingConnection(to: string): Promise<WebSocketConnection>;
|
|
28
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
3
|
-
import { W as WebSocketConnection } from '../../../connection-
|
|
2
|
+
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js';
|
|
3
|
+
import { W as WebSocketConnection } from '../../../connection-ab681c08.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
|
|
@@ -18,11 +18,11 @@ declare class WebSocketClientTransport extends ClientTransport<WebSocketConnecti
|
|
|
18
18
|
/**
|
|
19
19
|
* Creates a new WebSocketClientTransport instance.
|
|
20
20
|
* @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
|
|
21
|
-
* @param
|
|
21
|
+
* @param clientId The ID of the client using the transport. This should be unique per session.
|
|
22
22
|
* @param serverId The ID of the server this transport is connecting to.
|
|
23
23
|
* @param providedOptions An optional object containing configuration options for the transport.
|
|
24
24
|
*/
|
|
25
|
-
constructor(wsGetter: () => Promise<WebSocket>,
|
|
25
|
+
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<TransportOptions>);
|
|
26
26
|
reopen(): void;
|
|
27
27
|
createNewOutgoingConnection(to: string): Promise<WebSocketConnection>;
|
|
28
28
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WebSocketConnection
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-NPXAAD7M.js";
|
|
4
4
|
import {
|
|
5
5
|
ClientTransport
|
|
6
|
-
} from "../../../chunk-
|
|
7
|
-
import "../../../chunk-
|
|
8
|
-
import "../../../chunk-XFFS4UOD.js";
|
|
6
|
+
} from "../../../chunk-R2IMXRVU.js";
|
|
7
|
+
import "../../../chunk-MGGIUH5O.js";
|
|
9
8
|
import {
|
|
10
9
|
log
|
|
11
10
|
} from "../../../chunk-H4BYJELI.js";
|
|
11
|
+
import "../../../chunk-GZ7HCLLM.js";
|
|
12
12
|
|
|
13
13
|
// transport/impls/ws/client.ts
|
|
14
14
|
var WebSocketClientTransport = class extends ClientTransport {
|
|
@@ -20,12 +20,12 @@ var WebSocketClientTransport = class extends ClientTransport {
|
|
|
20
20
|
/**
|
|
21
21
|
* Creates a new WebSocketClientTransport instance.
|
|
22
22
|
* @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
|
|
23
|
-
* @param
|
|
23
|
+
* @param clientId The ID of the client using the transport. This should be unique per session.
|
|
24
24
|
* @param serverId The ID of the server this transport is connecting to.
|
|
25
25
|
* @param providedOptions An optional object containing configuration options for the transport.
|
|
26
26
|
*/
|
|
27
|
-
constructor(wsGetter,
|
|
28
|
-
super(
|
|
27
|
+
constructor(wsGetter, clientId, serverId, providedOptions) {
|
|
28
|
+
super(clientId, serverId, providedOptions);
|
|
29
29
|
this.wsGetter = wsGetter;
|
|
30
30
|
this.serverId = serverId;
|
|
31
31
|
void this.connect(this.serverId);
|