(url: string)
| 2 | import { QueryParams, SendMessage } from './types'; |
| 3 | |
| 4 | export 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 | |
| 23 | export const appendQueryParams = (url: string, params: QueryParams = {}): string => { |
| 24 | const hasParamsRegex = /\?([\w]+=[\w]+)/; |
no outgoing calls
no test coverage detected
searching dependent graphs…