MCPcopy Index your code
hub / github.com/coder/coder / createWebSocket

Function createWebSocket

site/src/api/api.ts:4004–4022  ·  view source on GitHub ↗

* Utility function to help create a WebSocket connection with Coder's API.

(
	path: string,
	params: URLSearchParams = new URLSearchParams(),
)

Source from the content-addressed store, hash-verified

4002 * Utility function to help create a WebSocket connection with Coder's API.
4003 */
4004function createWebSocket(
4005 path: string,
4006 params: URLSearchParams = new URLSearchParams(),
4007) {
4008 // When running in an embedded context (e.g. VS Code webview),
4009 // the session token is set via the API header but browsers
4010 // cannot attach custom headers to WebSocket connections.
4011 // Pass it as a query parameter instead.
4012 const token = API.getSessionToken();
4013 if (token) {
4014 params.set(SessionTokenCookie, token);
4015 }
4016 const protocol = location.protocol === "https:" ? "wss:" : "ws:";
4017 const socket = new WebSocket(
4018 `${protocol}//${location.host}${path}?${params}`,
4019 );
4020 socket.binaryType = "blob";
4021 return socket;
4022}
4023
4024// Other non-API methods defined here to make it a little easier to find them.
4025interface ClientApi extends ApiMethods {

Callers 5

watchChatGitFunction · 0.85
watchChatDesktopFunction · 0.85
watchBuildLogsByBuildIdFunction · 0.85
ApiMethodsClass · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected