silverwolf-x's picture
download
raw
815 Bytes
import { normalizedAssetPrefix } from '../../../shared/lib/normalized-asset-prefix'
function getSocketProtocol(assetPrefix: string): string {
let protocol = window.location.protocol
try {
// assetPrefix is a url
protocol = new URL(assetPrefix).protocol
} catch {}
return protocol === 'http:' ? 'ws:' : 'wss:'
}
export function getSocketUrl(assetPrefix: string | undefined): string {
const prefix = normalizedAssetPrefix(assetPrefix)
const protocol = getSocketProtocol(assetPrefix || '')
if (URL.canParse(prefix)) {
// since normalized asset prefix is ensured to be a URL format,
// we can safely replace the protocol
return prefix.replace(/^http/, 'ws')
}
const { hostname, port } = window.location
return `${protocol}//${hostname}${port ? `:${port}` : ''}${prefix}`
}

Xet Storage Details

Size:
815 Bytes
·
Xet hash:
01597a473b2a12d7db7ff0d521e55e7d88e61c033b30a63b2998257f49a3fff4

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.