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

Function parseSocketIOUrl

src/lib/socket-io.ts:4–21  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

2import { QueryParams, SendMessage } from './types';
3
4export const parseSocketIOUrl = (url: string) => {
5 if (url) {
6 const isSecure = /^https|wss/.test(url);
7 const strippedProtocol = url.replace(/^(https?|wss?)(:\/\/)?/, '');
8 const removedFinalBackSlack = strippedProtocol.replace(/\/$/, '');
9 const protocol = isSecure ? 'wss' : 'ws';
10
11 return `${protocol}://${removedFinalBackSlack}${SOCKET_IO_PATH}`;
12 } else if (url === '') {
13 const isSecure = /^https/.test(window.location.protocol);
14 const protocol = isSecure ? 'wss' : 'ws';
15 const port = window.location.port ? `:${window.location.port}` : '';
16
17 return `${protocol}://${window.location.hostname}${port}${SOCKET_IO_PATH}`;
18 }
19
20 return url;
21};
22
23export const appendQueryParams = (url: string, params: QueryParams = {}): string => {
24 const hasParamsRegex = /\?([\w]+=[\w]+)/;

Callers 3

socket-io.test.tsFile · 0.90
getUrlFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…