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

Function initializeWebSocket

dash/dash-renderer/src/observers/websocketObserver.ts:53–264  ·  view source on GitHub ↗
(
    store: Store<IStoreState>,
    config: DashConfig
)

Source from the content-addressed store, hash-verified

51 * @param config Dash configuration
52 */
53export async function initializeWebSocket(
54 store: Store<IStoreState>,
55 config: DashConfig
56): Promise<void> {
57 // Initialize WebSocket if:
58 // 1. Global websocket is enabled, OR
59 // 2. WebSocket config is available (for per-callback websocket=True)
60 const wsAvailable = !!(
61 config.websocket?.url && config.websocket?.worker_url
62 );
63 if (!wsAvailable) {
64 return;
65 }
66
67 // Check if SharedWorker is supported
68 if (typeof SharedWorker === 'undefined') {
69 console.warn(
70 'SharedWorker not supported in this browser. ' +
71 'WebSocket callbacks will fall back to HTTP.'
72 );
73 return;
74 }
75
76 const workerClient = getWorkerClient();
77
78 // Helper to process a single set_props payload
79 const processSetProps = (payload: SetPropsPayload) => {
80 const {componentId, props: rawProps} = payload;
81 const parsedId = parseComponentId(componentId);
82 const state = store.getState();
83 const componentPath = getPath(state.paths, parsedId);
84
85 if (!componentPath) {
86 console.warn(
87 `SET_PROPS: Component ${componentId} not found in layout`
88 );
89 return;
90 }
91
92 // Get old component for Patch processing and path recomputation
93 const oldComponent = path(componentPath, state.layout) as Record<
94 string,
95 unknown
96 > | null;
97 const oldProps = (oldComponent?.props || {}) as Record<string, unknown>;
98
99 // Process props to handle Patch objects
100 const processedProps = parsePatchProps(rawProps, oldProps);
101
102 // Update the component props
103 store.dispatch(
104 updateProps({
105 props: processedProps,
106 itempath: componentPath,
107 renderType: 'websocket'
108 }) as any
109 );
110

Callers 1

AppProviderFunction · 0.90

Calls 15

getWorkerClientFunction · 0.90
getPathFunction · 0.90
makeResolvedCallbackFunction · 0.90
resolveDepsFunction · 0.90
processSetPropsFunction · 0.85
parseComponentIdFunction · 0.85
buildWebSocketUrlFunction · 0.85
sendGetPropsResponseMethod · 0.80
reduceMethod · 0.80
pushMethod · 0.80
notifyTabVisibleMethod · 0.80
ensureConnectedMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…