MCPcopy
hub / github.com/robtaussig/react-use-websocket / start

Function start

src/lib/use-websocket.ts:88–116  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86 let expectClose = false;
87
88 const start = async () => {
89 convertedUrl.current = await getUrl(url, optionsCache);
90
91 const protectedSetLastMessage = (message: WebSocketEventMap['message']) => {
92 if (!expectClose) {
93 setLastMessage(message);
94 }
95 };
96
97 const protectedSetReadyState = (state: ReadyState) => {
98 if (!expectClose) {
99 setReadyState(prev => ({
100 ...prev,
101 ...(convertedUrl.current && {[convertedUrl.current]: state}),
102 }));
103 }
104 };
105
106 removeListeners = createOrJoinSocket(
107 webSocketRef,
108 convertedUrl.current,
109 protectedSetReadyState,
110 optionsCache,
111 protectedSetLastMessage,
112 startRef,
113 reconnectCount,
114 sendMessage,
115 );
116 };
117
118 startRef.current = () => {
119 if (!expectClose) {

Callers 1

useWebSocketFunction · 0.85

Calls 2

getUrlFunction · 0.90
createOrJoinSocketFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…