Files
NapCatQQ/.pnpm-store/v3/files/7f/aeb0eea067195c9b6d79f98e3e9535e6b9d12b17c8135bc620b389a8a551f3364b28ca03435ff81f41335ec2344199e162436defe80e069fe802ed840aba37
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

39 lines
1.9 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setUpSocketIOPing = exports.appendQueryParams = exports.parseSocketIOUrl = void 0;
var constants_1 = require("./constants");
var parseSocketIOUrl = function (url) {
if (url) {
var isSecure = /^https|wss/.test(url);
var strippedProtocol = url.replace(/^(https?|wss?)(:\/\/)?/, '');
var removedFinalBackSlack = strippedProtocol.replace(/\/$/, '');
var protocol = isSecure ? 'wss' : 'ws';
return "".concat(protocol, "://").concat(removedFinalBackSlack).concat(constants_1.SOCKET_IO_PATH);
}
else if (url === '') {
var isSecure = /^https/.test(window.location.protocol);
var protocol = isSecure ? 'wss' : 'ws';
var port = window.location.port ? ":".concat(window.location.port) : '';
return "".concat(protocol, "://").concat(window.location.hostname).concat(port).concat(constants_1.SOCKET_IO_PATH);
}
return url;
};
exports.parseSocketIOUrl = parseSocketIOUrl;
var appendQueryParams = function (url, params) {
if (params === void 0) { params = {}; }
var hasParamsRegex = /\?([\w]+=[\w]+)/;
var alreadyHasParams = hasParamsRegex.test(url);
var stringified = "".concat(Object.entries(params).reduce(function (next, _a) {
var key = _a[0], value = _a[1];
return next + "".concat(key, "=").concat(value, "&");
}, '').slice(0, -1));
return "".concat(url).concat(alreadyHasParams ? '&' : '?').concat(stringified);
};
exports.appendQueryParams = appendQueryParams;
var setUpSocketIOPing = function (sendMessage, interval) {
if (interval === void 0) { interval = constants_1.SOCKET_IO_PING_INTERVAL; }
var ping = function () { return sendMessage(constants_1.SOCKET_IO_PING_CODE); };
return window.setInterval(ping, interval);
};
exports.setUpSocketIOPing = setUpSocketIOPing;
//# sourceMappingURL=socket-io.js.map