|
"use strict"; |
|
var __importDefault = (this && this.__importDefault) || function (mod) { |
|
return (mod && mod.__esModule) ? mod : { "default": mod }; |
|
}; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.url = void 0; |
|
const engine_io_client_1 = require("engine.io-client"); |
|
const debug_1 = __importDefault(require("debug")); |
|
const debug = debug_1.default("socket.io-client:url"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function url(uri, path = "", loc) { |
|
let obj = uri; |
|
|
|
loc = loc || (typeof location !== "undefined" && location); |
|
if (null == uri) |
|
uri = loc.protocol + "//" + loc.host; |
|
|
|
if (typeof uri === "string") { |
|
if ("/" === uri.charAt(0)) { |
|
if ("/" === uri.charAt(1)) { |
|
uri = loc.protocol + uri; |
|
} |
|
else { |
|
uri = loc.host + uri; |
|
} |
|
} |
|
if (!/^(https?|wss?):\/\//.test(uri)) { |
|
debug("protocol-less url %s", uri); |
|
if ("undefined" !== typeof loc) { |
|
uri = loc.protocol + "//" + uri; |
|
} |
|
else { |
|
uri = "https://" + uri; |
|
} |
|
} |
|
|
|
debug("parse %s", uri); |
|
obj = engine_io_client_1.parse(uri); |
|
} |
|
|
|
if (!obj.port) { |
|
if (/^(http|ws)$/.test(obj.protocol)) { |
|
obj.port = "80"; |
|
} |
|
else if (/^(http|ws)s$/.test(obj.protocol)) { |
|
obj.port = "443"; |
|
} |
|
} |
|
obj.path = obj.path || "/"; |
|
const ipv6 = obj.host.indexOf(":") !== -1; |
|
const host = ipv6 ? "[" + obj.host + "]" : obj.host; |
|
|
|
obj.id = obj.protocol + "://" + host + ":" + obj.port + path; |
|
|
|
obj.href = |
|
obj.protocol + |
|
"://" + |
|
host + |
|
(loc && loc.port === obj.port ? "" : ":" + obj.port); |
|
return obj; |
|
} |
|
exports.url = url; |
|
|