File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ import { nanoid } from "./nanoid.js";
3434const COORDINATOR_HOST = "127.0.0.1" ;
3535
3636/** Timeout for connecting to the coordinator before giving up. */
37- const CONNECT_TIMEOUT_MS = 2000 ;
37+ const CONNECT_TIMEOUT_MS = 1000 ;
3838
3939// ---------------------------------------------------------------------------
4040// Async socket write helper (not exported)
@@ -132,6 +132,12 @@ export class TcpTransport implements MeshTransport {
132132 return this . _isCoordinator ;
133133 }
134134
135+ get hasCoordinatorConnection ( ) : boolean {
136+ return (
137+ this . coordinatorSocket !== undefined && ! this . coordinatorSocket . destroyed
138+ ) ;
139+ }
140+
135141 // -----------------------------------------------------------------------
136142 // MeshTransport — Data server
137143 // -----------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ import { nanoid } from "./nanoid.js";
3535// ---------------------------------------------------------------------------
3636
3737const COORDINATOR_HOST = "127.0.0.1" ;
38- const CONNECT_TIMEOUT_MS = 2000 ;
38+ const CONNECT_TIMEOUT_MS = 1000 ;
3939
4040/**
4141 * Wrap tls.createServer with a retry for intermittent OpenSSL ASN.1 races
@@ -161,6 +161,12 @@ export class TlsTransport {
161161 return this . _isCoordinator ;
162162 }
163163
164+ get hasCoordinatorConnection ( ) : boolean {
165+ return (
166+ this . coordinatorSocket !== undefined && ! this . coordinatorSocket . destroyed
167+ ) ;
168+ }
169+
164170 // -----------------------------------------------------------------------
165171 // TLS options
166172 // -----------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -68,6 +68,11 @@ export interface TransportEvents {
6868 */
6969 onPeerDisconnected ( handle : ConnectionHandle ) : void ;
7070
71+ /**
72+ * A non-fatal error occurred that consumers should know about.
73+ */
74+ onError ?( error : Error ) : void ;
75+
7176 /**
7277 * A peer introduced itself to the coordinator.
7378 * Only fires on the coordinator instance.
@@ -123,6 +128,9 @@ export interface MeshTransport {
123128 /** Whether this instance is the mesh coordinator. */
124129 readonly isCoordinator : boolean ;
125130
131+ /** Whether this instance has a live connection to a coordinator. */
132+ readonly hasCoordinatorConnection : boolean ;
133+
126134 /**
127135 * Start the data server on an OS-assigned port.
128136 * Resolves when the server is listening.
Original file line number Diff line number Diff line change @@ -109,6 +109,10 @@ export class WebSocketTransport implements MeshTransport {
109109 return this . _isCoordinator ;
110110 }
111111
112+ get hasCoordinatorConnection ( ) : boolean {
113+ return this . coordinatorWs ?. readyState === WebSocket . OPEN ;
114+ }
115+
112116 // -----------------------------------------------------------------------
113117 // MeshTransport — Data server
114118 // -----------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments