MCPcopy Index your code
hub / github.com/plotly/dash / ensureConnected

Method ensureConnected

dash/dash-renderer/src/utils/workerClient.ts:161–201  ·  view source on GitHub ↗

* 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;
        };
    })

Source from the content-addressed store, hash-verified

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.

Callers 2

handleWebsocketCallbackFunction · 0.80
initializeWebSocketFunction · 0.80

Calls 1

connectMethod · 0.95

Tested by

no test coverage detected