MCPcopy
hub / github.com/coder/mux / createBrowserClient

Function createBrowserClient

src/browser/contexts/API.tsx:158–182  ·  view source on GitHub ↗
(
  authToken: string | null,
  createWebSocket: (url: string) => WebSocket
)

Source from the content-addressed store, hash-verified

156}
157
158function 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
184function ManagedAPIProvider(props: Omit<APIProviderProps, "client">) {
185 const [state, setState] = useState<ConnectionState>({ status: "connecting" });

Callers 1

ManagedAPIProviderFunction · 0.85

Calls 4

getBrowserBackendBaseUrlFunction · 0.90
createClientFunction · 0.90
closeWebSocketSafelyFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected