* Ensure the worker is connected, initiating connection if needed. * @param config The Dash config with websocket settings
(config: {
websocket?: {
url?: string;
worker_url?: string;
inactivity_timeout?: number;
heartbeat_interval?: number;
};
})
| 159 | * @param config The Dash config with websocket settings |
| 160 | */ |
| 161 | public async ensureConnected(config: { |
| 162 | websocket?: { |
| 163 | url?: string; |
| 164 | worker_url?: string; |
| 165 | inactivity_timeout?: number; |
| 166 | heartbeat_interval?: number; |
| 167 | }; |
| 168 | }): Promise<void> { |
| 169 | // Already connected |
| 170 | if (this.isConnected) { |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | // Connection in progress, wait for it |
| 175 | if (this.connectionPromise) { |
| 176 | await this.connectionPromise; |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | // Need to initiate connection |
| 181 | if (!config.websocket?.url || !config.websocket?.worker_url) { |
| 182 | throw new Error('WebSocket config not available'); |
| 183 | } |
| 184 | |
| 185 | if (typeof SharedWorker === 'undefined') { |
| 186 | throw new Error('SharedWorker not supported'); |
| 187 | } |
| 188 | |
| 189 | // Build WebSocket URL |
| 190 | const wsProtocol = |
| 191 | window.location.protocol === 'https:' ? 'wss:' : 'ws:'; |
| 192 | const host = window.location.host; |
| 193 | const wsUrl = `${wsProtocol}//${host}${config.websocket.url}`; |
| 194 | |
| 195 | await this.connect( |
| 196 | config.websocket.worker_url, |
| 197 | wsUrl, |
| 198 | config.websocket.inactivity_timeout, |
| 199 | config.websocket.heartbeat_interval |
| 200 | ); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Send a callback request to the server via the worker. |
no test coverage detected