Files
SnowLuma/.pnpm-store/v11/files/1c/2383323c0799a9263d58c4bcdce3a354ece51e85b7b163ef819dacfa545c714c0087e32e536944fbe84d08c8ad8ec855ed06bb0b2b776fab37f27c2738812f
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

57 lines
1.4 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
//#region src/helper/websocket/index.ts
/**
* A context for controlling WebSockets
*/
var WSContext = class {
#init;
constructor(init) {
this.#init = init;
this.raw = init.raw;
this.url = init.url ? new URL(init.url) : null;
this.protocol = init.protocol ?? null;
}
send(source, options) {
this.#init.send(source, options ?? {});
}
raw;
binaryType = "arraybuffer";
get readyState() {
return this.#init.readyState;
}
url;
protocol;
close(code, reason) {
this.#init.close(code, reason);
}
};
const createWSMessageEvent = (source) => {
return new MessageEvent("message", { data: source });
};
/**
* Create a WebSocket adapter/helper
*/
const defineWebSocketHelper = (handler) => {
return ((...args) => {
if (typeof args[0] === "function") {
const [createEvents, options] = args;
return async function upgradeWebSocket(c, next) {
const result = await handler(c, await createEvents(c), options);
if (result) return result;
await next();
};
} else {
const [c, events, options] = args;
return (async () => {
const upgraded = await handler(c, events, options);
if (!upgraded) throw new Error("Failed to upgrade WebSocket");
return upgraded;
})();
}
});
};
//#endregion
exports.WSContext = WSContext;
exports.createWSMessageEvent = createWSMessageEvent;
exports.defineWebSocketHelper = defineWebSocketHelper;