( authToken: string | null, createWebSocket: (url: string) => WebSocket )
| 156 | } |
| 157 | |
| 158 | function createBrowserClient( |
| 159 | authToken: string | null, |
| 160 | createWebSocket: (url: string) => WebSocket |
| 161 | ): { |
| 162 | client: APIClient; |
| 163 | cleanup: () => void; |
| 164 | ws: WebSocket; |
| 165 | } { |
| 166 | const apiBaseUrl = getBrowserBackendBaseUrl(); |
| 167 | |
| 168 | const wsUrl = new URL(`${apiBaseUrl}/orpc/ws`); |
| 169 | wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:"; |
| 170 | if (authToken) { |
| 171 | wsUrl.searchParams.set("token", authToken); |
| 172 | } |
| 173 | |
| 174 | const ws = createWebSocket(wsUrl.toString()); |
| 175 | const link = new WebSocketLink({ websocket: ws }); |
| 176 | |
| 177 | return { |
| 178 | client: createClient(link), |
| 179 | cleanup: () => closeWebSocketSafely(ws), |
| 180 | ws, |
| 181 | }; |
| 182 | } |
| 183 | |
| 184 | function ManagedAPIProvider(props: Omit<APIProviderProps, "client">) { |
| 185 | const [state, setState] = useState<ConnectionState>({ status: "connecting" }); |
no test coverage detected