pages235/src/parseServerAddress.ts
Vitaly 65af9a73c2
feat: rework hand! enable by default, fix bow anim (#261)
* refactor swing animation to controller

* idle animator!!!!

* implelment state switch transition

* a huge fix for UI server edit!

* adjust ui scaling so main menu elements clip less

* view bobbing, new config name, ws:

* EXTREMELY important fixes to entities rendering

* a lot of fixes, add dns resolve fallback

* improve f3 E, fix modal not found edge case

* set correctly target for old browsers, should fix ios 14 crash

* unecessary big refactor, to fix ts err

* fix isWysiwyg check

* fix entities rendering count
2025-02-15 05:14:36 +03:00

54 lines
1.3 KiB
TypeScript

export const parseServerAddress = (address: string | undefined, removeHttp = true): ParsedServerAddress => {
if (!address) {
return { host: '', isWebSocket: false, serverIpFull: '' }
}
if (/^ws:[^/]/.test(address)) address = address.replace('ws:', 'ws://')
if (/^wss:[^/]/.test(address)) address = address.replace('wss:', 'wss://')
const isWebSocket = address.startsWith('ws://') || address.startsWith('wss://')
if (isWebSocket) {
return { host: address, isWebSocket: true, serverIpFull: address }
}
if (removeHttp) {
address = address.replace(/^https?:\/\//, '')
}
const parts = address.split(':')
let version: string | null = null
let port: string | null = null
for (let i = 0; i < parts.length; i++) {
const part = parts[i]
if (/^\d+\.\d+(\.\d+)?$/.test(part)) {
version = part
parts.splice(i, 1)
i--
}
if (/^\d+$/.test(part)) {
port = part
parts.splice(i, 1)
i--
}
}
const host = parts.join(':')
return {
host,
...(port ? { port } : {}),
...(version ? { version } : {}),
isWebSocket: false,
serverIpFull: port ? `${host}:${port}` : host
}
}
export interface ParsedServerAddress {
host: string
port?: string
version?: string
isWebSocket: boolean
serverIpFull: string
}