full site update
This commit is contained in:
39
node_modules/crossws/dist/adapters/bun.d.mts
generated
vendored
Normal file
39
node_modules/crossws/dist/adapters/bun.d.mts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { WebSocketHandler, ServerWebSocket, Server } from 'bun';
|
||||
import { Adapter, AdapterInstance, Peer, AdapterOptions } from '../index.mjs';
|
||||
import '../shared/crossws.BQXMA5bH.mjs';
|
||||
|
||||
interface BunAdapter extends AdapterInstance {
|
||||
websocket: WebSocketHandler<ContextData>;
|
||||
handleUpgrade(req: Request, server: Server): Promise<Response | undefined>;
|
||||
}
|
||||
interface BunOptions extends AdapterOptions {
|
||||
}
|
||||
type ContextData = {
|
||||
peer?: BunPeer;
|
||||
request: Request;
|
||||
server?: Server;
|
||||
context: Peer["context"];
|
||||
};
|
||||
declare const bunAdapter: Adapter<BunAdapter, BunOptions>;
|
||||
|
||||
declare class BunPeer extends Peer<{
|
||||
ws: ServerWebSocket<ContextData>;
|
||||
request: Request;
|
||||
peers: Set<BunPeer>;
|
||||
}> {
|
||||
get remoteAddress(): string;
|
||||
get context(): Peer["context"];
|
||||
send(data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): number;
|
||||
publish(topic: string, data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): number;
|
||||
subscribe(topic: string): void;
|
||||
unsubscribe(topic: string): void;
|
||||
close(code?: number, reason?: string): void;
|
||||
terminate(): void;
|
||||
}
|
||||
|
||||
export { bunAdapter as default };
|
||||
export type { BunAdapter, BunOptions };
|
39
node_modules/crossws/dist/adapters/bun.d.ts
generated
vendored
Normal file
39
node_modules/crossws/dist/adapters/bun.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { WebSocketHandler, ServerWebSocket, Server } from 'bun';
|
||||
import { Adapter, AdapterInstance, Peer, AdapterOptions } from '../index.js';
|
||||
import '../shared/crossws.BQXMA5bH.js';
|
||||
|
||||
interface BunAdapter extends AdapterInstance {
|
||||
websocket: WebSocketHandler<ContextData>;
|
||||
handleUpgrade(req: Request, server: Server): Promise<Response | undefined>;
|
||||
}
|
||||
interface BunOptions extends AdapterOptions {
|
||||
}
|
||||
type ContextData = {
|
||||
peer?: BunPeer;
|
||||
request: Request;
|
||||
server?: Server;
|
||||
context: Peer["context"];
|
||||
};
|
||||
declare const bunAdapter: Adapter<BunAdapter, BunOptions>;
|
||||
|
||||
declare class BunPeer extends Peer<{
|
||||
ws: ServerWebSocket<ContextData>;
|
||||
request: Request;
|
||||
peers: Set<BunPeer>;
|
||||
}> {
|
||||
get remoteAddress(): string;
|
||||
get context(): Peer["context"];
|
||||
send(data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): number;
|
||||
publish(topic: string, data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): number;
|
||||
subscribe(topic: string): void;
|
||||
unsubscribe(topic: string): void;
|
||||
close(code?: number, reason?: string): void;
|
||||
terminate(): void;
|
||||
}
|
||||
|
||||
export { bunAdapter as default };
|
||||
export type { BunAdapter, BunOptions };
|
89
node_modules/crossws/dist/adapters/bun.mjs
generated
vendored
Normal file
89
node_modules/crossws/dist/adapters/bun.mjs
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
|
||||
import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
|
||||
import 'uncrypto';
|
||||
|
||||
const bunAdapter = (options = {}) => {
|
||||
const hooks = new AdapterHookable(options);
|
||||
const peers = /* @__PURE__ */ new Set();
|
||||
return {
|
||||
...adapterUtils(peers),
|
||||
async handleUpgrade(request, server) {
|
||||
const { upgradeHeaders, endResponse, context } = await hooks.upgrade(request);
|
||||
if (endResponse) {
|
||||
return endResponse;
|
||||
}
|
||||
const upgradeOK = server.upgrade(request, {
|
||||
data: {
|
||||
server,
|
||||
request,
|
||||
context
|
||||
},
|
||||
headers: upgradeHeaders
|
||||
});
|
||||
if (!upgradeOK) {
|
||||
return new Response("Upgrade failed", { status: 500 });
|
||||
}
|
||||
},
|
||||
websocket: {
|
||||
message: (ws, message) => {
|
||||
const peer = getPeer(ws, peers);
|
||||
hooks.callHook("message", peer, new Message(message, peer));
|
||||
},
|
||||
open: (ws) => {
|
||||
const peer = getPeer(ws, peers);
|
||||
peers.add(peer);
|
||||
hooks.callHook("open", peer);
|
||||
},
|
||||
close: (ws, code, reason) => {
|
||||
const peer = getPeer(ws, peers);
|
||||
peers.delete(peer);
|
||||
hooks.callHook("close", peer, { code, reason });
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
function getPeer(ws, peers) {
|
||||
if (ws.data?.peer) {
|
||||
return ws.data.peer;
|
||||
}
|
||||
const peer = new BunPeer({ ws, request: ws.data.request, peers });
|
||||
ws.data = {
|
||||
...ws.data,
|
||||
peer
|
||||
};
|
||||
return peer;
|
||||
}
|
||||
class BunPeer extends Peer {
|
||||
get remoteAddress() {
|
||||
return this._internal.ws.remoteAddress;
|
||||
}
|
||||
get context() {
|
||||
return this._internal.ws.data.context;
|
||||
}
|
||||
send(data, options) {
|
||||
return this._internal.ws.send(toBufferLike(data), options?.compress);
|
||||
}
|
||||
publish(topic, data, options) {
|
||||
return this._internal.ws.publish(
|
||||
topic,
|
||||
toBufferLike(data),
|
||||
options?.compress
|
||||
);
|
||||
}
|
||||
subscribe(topic) {
|
||||
this._topics.add(topic);
|
||||
this._internal.ws.subscribe(topic);
|
||||
}
|
||||
unsubscribe(topic) {
|
||||
this._topics.delete(topic);
|
||||
this._internal.ws.unsubscribe(topic);
|
||||
}
|
||||
close(code, reason) {
|
||||
this._internal.ws.close(code, reason);
|
||||
}
|
||||
terminate() {
|
||||
this._internal.ws.terminate();
|
||||
}
|
||||
}
|
||||
|
||||
export { bunAdapter as default };
|
42
node_modules/crossws/dist/adapters/cloudflare-durable.d.mts
generated
vendored
Normal file
42
node_modules/crossws/dist/adapters/cloudflare-durable.d.mts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import * as CF from '@cloudflare/workers-types';
|
||||
import { DurableObject } from 'cloudflare:workers';
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
|
||||
import { W as WebSocket$1 } from '../shared/crossws.BQXMA5bH.mjs';
|
||||
|
||||
type ResolveDurableStub = (req: CF.Request, env: unknown, context: CF.ExecutionContext) => CF.DurableObjectStub | Promise<CF.DurableObjectStub>;
|
||||
interface CloudflareOptions extends AdapterOptions {
|
||||
/**
|
||||
* Durable Object binding name from environment.
|
||||
*
|
||||
* **Note:** This option will be ignored if `resolveDurableStub` is provided.
|
||||
*
|
||||
* @default "$DurableObject"
|
||||
*/
|
||||
bindingName?: string;
|
||||
/**
|
||||
* Durable Object instance name.
|
||||
*
|
||||
* **Note:** This option will be ignored if `resolveDurableStub` is provided.
|
||||
*
|
||||
* @default "crossws"
|
||||
*/
|
||||
instanceName?: string;
|
||||
/**
|
||||
* Custom function that resolves Durable Object binding to handle the WebSocket upgrade.
|
||||
*
|
||||
* **Note:** This option will override `bindingName` and `instanceName`.
|
||||
*/
|
||||
resolveDurableStub?: ResolveDurableStub;
|
||||
}
|
||||
declare const cloudflareDurableAdapter: Adapter<CloudflareDurableAdapter, CloudflareOptions>;
|
||||
|
||||
interface CloudflareDurableAdapter extends AdapterInstance {
|
||||
handleUpgrade(req: Request | CF.Request, env: unknown, context: CF.ExecutionContext): Promise<Response>;
|
||||
handleDurableInit(obj: DurableObject, state: DurableObjectState, env: unknown): void;
|
||||
handleDurableUpgrade(obj: DurableObject, req: Request | CF.Request): Promise<Response>;
|
||||
handleDurableMessage(obj: DurableObject, ws: WebSocket | CF.WebSocket | WebSocket$1, message: ArrayBuffer | string): Promise<void>;
|
||||
handleDurableClose(obj: DurableObject, ws: WebSocket | CF.WebSocket | WebSocket$1, code: number, reason: string, wasClean: boolean): Promise<void>;
|
||||
}
|
||||
|
||||
export { cloudflareDurableAdapter as default };
|
||||
export type { CloudflareDurableAdapter, CloudflareOptions };
|
42
node_modules/crossws/dist/adapters/cloudflare-durable.d.ts
generated
vendored
Normal file
42
node_modules/crossws/dist/adapters/cloudflare-durable.d.ts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import * as CF from '@cloudflare/workers-types';
|
||||
import { DurableObject } from 'cloudflare:workers';
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
|
||||
import { W as WebSocket$1 } from '../shared/crossws.BQXMA5bH.js';
|
||||
|
||||
type ResolveDurableStub = (req: CF.Request, env: unknown, context: CF.ExecutionContext) => CF.DurableObjectStub | Promise<CF.DurableObjectStub>;
|
||||
interface CloudflareOptions extends AdapterOptions {
|
||||
/**
|
||||
* Durable Object binding name from environment.
|
||||
*
|
||||
* **Note:** This option will be ignored if `resolveDurableStub` is provided.
|
||||
*
|
||||
* @default "$DurableObject"
|
||||
*/
|
||||
bindingName?: string;
|
||||
/**
|
||||
* Durable Object instance name.
|
||||
*
|
||||
* **Note:** This option will be ignored if `resolveDurableStub` is provided.
|
||||
*
|
||||
* @default "crossws"
|
||||
*/
|
||||
instanceName?: string;
|
||||
/**
|
||||
* Custom function that resolves Durable Object binding to handle the WebSocket upgrade.
|
||||
*
|
||||
* **Note:** This option will override `bindingName` and `instanceName`.
|
||||
*/
|
||||
resolveDurableStub?: ResolveDurableStub;
|
||||
}
|
||||
declare const cloudflareDurableAdapter: Adapter<CloudflareDurableAdapter, CloudflareOptions>;
|
||||
|
||||
interface CloudflareDurableAdapter extends AdapterInstance {
|
||||
handleUpgrade(req: Request | CF.Request, env: unknown, context: CF.ExecutionContext): Promise<Response>;
|
||||
handleDurableInit(obj: DurableObject, state: DurableObjectState, env: unknown): void;
|
||||
handleDurableUpgrade(obj: DurableObject, req: Request | CF.Request): Promise<Response>;
|
||||
handleDurableMessage(obj: DurableObject, ws: WebSocket | CF.WebSocket | WebSocket$1, message: ArrayBuffer | string): Promise<void>;
|
||||
handleDurableClose(obj: DurableObject, ws: WebSocket | CF.WebSocket | WebSocket$1, code: number, reason: string, wasClean: boolean): Promise<void>;
|
||||
}
|
||||
|
||||
export { cloudflareDurableAdapter as default };
|
||||
export type { CloudflareDurableAdapter, CloudflareOptions };
|
141
node_modules/crossws/dist/adapters/cloudflare-durable.mjs
generated
vendored
Normal file
141
node_modules/crossws/dist/adapters/cloudflare-durable.mjs
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
|
||||
import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
|
||||
import 'uncrypto';
|
||||
|
||||
const cloudflareDurableAdapter = (opts = {}) => {
|
||||
const hooks = new AdapterHookable(opts);
|
||||
const peers = /* @__PURE__ */ new Set();
|
||||
const resolveDurableStub = opts.resolveDurableStub || ((_req, env, _context) => {
|
||||
const bindingName = opts.bindingName || "$DurableObject";
|
||||
const binding = env[bindingName];
|
||||
if (!binding) {
|
||||
throw new Error(
|
||||
`Durable Object binding "${bindingName}" not available`
|
||||
);
|
||||
}
|
||||
const instanceId = binding.idFromName(opts.instanceName || "crossws");
|
||||
return binding.get(instanceId);
|
||||
});
|
||||
return {
|
||||
...adapterUtils(peers),
|
||||
handleUpgrade: async (req, env, context) => {
|
||||
const stub = await resolveDurableStub(req, env, context);
|
||||
return stub.fetch(req);
|
||||
},
|
||||
handleDurableInit: async (obj, state, env) => {
|
||||
},
|
||||
handleDurableUpgrade: async (obj, request) => {
|
||||
const { upgradeHeaders, endResponse } = await hooks.upgrade(
|
||||
request
|
||||
);
|
||||
if (endResponse) {
|
||||
return endResponse;
|
||||
}
|
||||
const pair = new WebSocketPair();
|
||||
const client = pair[0];
|
||||
const server = pair[1];
|
||||
const peer = CloudflareDurablePeer._restore(
|
||||
obj,
|
||||
server,
|
||||
request
|
||||
);
|
||||
peers.add(peer);
|
||||
obj.ctx.acceptWebSocket(server);
|
||||
await hooks.callHook("open", peer);
|
||||
return new Response(null, {
|
||||
status: 101,
|
||||
webSocket: client,
|
||||
headers: upgradeHeaders
|
||||
});
|
||||
},
|
||||
handleDurableMessage: async (obj, ws, message) => {
|
||||
const peer = CloudflareDurablePeer._restore(obj, ws);
|
||||
await hooks.callHook("message", peer, new Message(message, peer));
|
||||
},
|
||||
handleDurableClose: async (obj, ws, code, reason, wasClean) => {
|
||||
const peer = CloudflareDurablePeer._restore(obj, ws);
|
||||
peers.delete(peer);
|
||||
const details = { code, reason, wasClean };
|
||||
await hooks.callHook("close", peer, details);
|
||||
}
|
||||
};
|
||||
};
|
||||
class CloudflareDurablePeer extends Peer {
|
||||
get peers() {
|
||||
return new Set(
|
||||
this.#getwebsockets().map(
|
||||
(ws) => CloudflareDurablePeer._restore(this._internal.durable, ws)
|
||||
)
|
||||
);
|
||||
}
|
||||
#getwebsockets() {
|
||||
return this._internal.durable.ctx.getWebSockets();
|
||||
}
|
||||
send(data) {
|
||||
return this._internal.ws.send(toBufferLike(data));
|
||||
}
|
||||
subscribe(topic) {
|
||||
super.subscribe(topic);
|
||||
const state = getAttachedState(this._internal.ws);
|
||||
if (!state.t) {
|
||||
state.t = /* @__PURE__ */ new Set();
|
||||
}
|
||||
state.t.add(topic);
|
||||
setAttachedState(this._internal.ws, state);
|
||||
}
|
||||
publish(topic, data) {
|
||||
const websockets = this.#getwebsockets();
|
||||
if (websockets.length < 2) {
|
||||
return;
|
||||
}
|
||||
const dataBuff = toBufferLike(data);
|
||||
for (const ws of websockets) {
|
||||
if (ws === this._internal.ws) {
|
||||
continue;
|
||||
}
|
||||
const state = getAttachedState(ws);
|
||||
if (state.t?.has(topic)) {
|
||||
ws.send(dataBuff);
|
||||
}
|
||||
}
|
||||
}
|
||||
close(code, reason) {
|
||||
this._internal.ws.close(code, reason);
|
||||
}
|
||||
static _restore(durable, ws, request) {
|
||||
let peer = ws._crosswsPeer;
|
||||
if (peer) {
|
||||
return peer;
|
||||
}
|
||||
const state = ws.deserializeAttachment() || {};
|
||||
peer = ws._crosswsPeer = new CloudflareDurablePeer({
|
||||
ws,
|
||||
request: request || { url: state.u },
|
||||
durable
|
||||
});
|
||||
if (state.i) {
|
||||
peer._id = state.i;
|
||||
}
|
||||
if (request?.url) {
|
||||
state.u = request.url;
|
||||
}
|
||||
state.i = peer.id;
|
||||
setAttachedState(ws, state);
|
||||
return peer;
|
||||
}
|
||||
}
|
||||
function getAttachedState(ws) {
|
||||
let state = ws._crosswsState;
|
||||
if (state) {
|
||||
return state;
|
||||
}
|
||||
state = ws.deserializeAttachment() || {};
|
||||
ws._crosswsState = state;
|
||||
return state;
|
||||
}
|
||||
function setAttachedState(ws, state) {
|
||||
ws._crosswsState = state;
|
||||
ws.serializeAttachment(state);
|
||||
}
|
||||
|
||||
export { cloudflareDurableAdapter as default };
|
13
node_modules/crossws/dist/adapters/cloudflare.d.mts
generated
vendored
Normal file
13
node_modules/crossws/dist/adapters/cloudflare.d.mts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
|
||||
import * as CF from '@cloudflare/workers-types';
|
||||
import '../shared/crossws.BQXMA5bH.mjs';
|
||||
|
||||
interface CloudflareAdapter extends AdapterInstance {
|
||||
handleUpgrade(req: CF.Request, env: unknown, context: CF.ExecutionContext): Promise<CF.Response>;
|
||||
}
|
||||
interface CloudflareOptions extends AdapterOptions {
|
||||
}
|
||||
declare const cloudflareAdapter: Adapter<CloudflareAdapter, CloudflareOptions>;
|
||||
|
||||
export { cloudflareAdapter as default };
|
||||
export type { CloudflareAdapter, CloudflareOptions };
|
13
node_modules/crossws/dist/adapters/cloudflare.d.ts
generated
vendored
Normal file
13
node_modules/crossws/dist/adapters/cloudflare.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
|
||||
import * as CF from '@cloudflare/workers-types';
|
||||
import '../shared/crossws.BQXMA5bH.js';
|
||||
|
||||
interface CloudflareAdapter extends AdapterInstance {
|
||||
handleUpgrade(req: CF.Request, env: unknown, context: CF.ExecutionContext): Promise<CF.Response>;
|
||||
}
|
||||
interface CloudflareOptions extends AdapterOptions {
|
||||
}
|
||||
declare const cloudflareAdapter: Adapter<CloudflareAdapter, CloudflareOptions>;
|
||||
|
||||
export { cloudflareAdapter as default };
|
||||
export type { CloudflareAdapter, CloudflareOptions };
|
68
node_modules/crossws/dist/adapters/cloudflare.mjs
generated
vendored
Normal file
68
node_modules/crossws/dist/adapters/cloudflare.mjs
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
|
||||
import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
|
||||
import { W as WSError } from '../shared/crossws.By9qWDAI.mjs';
|
||||
import 'uncrypto';
|
||||
|
||||
const cloudflareAdapter = (options = {}) => {
|
||||
const hooks = new AdapterHookable(options);
|
||||
const peers = /* @__PURE__ */ new Set();
|
||||
return {
|
||||
...adapterUtils(peers),
|
||||
handleUpgrade: async (request, env, cfCtx) => {
|
||||
const { upgradeHeaders, endResponse, context } = await hooks.upgrade(
|
||||
request
|
||||
);
|
||||
if (endResponse) {
|
||||
return endResponse;
|
||||
}
|
||||
const pair = new WebSocketPair();
|
||||
const client = pair[0];
|
||||
const server = pair[1];
|
||||
const peer = new CloudflarePeer({
|
||||
ws: client,
|
||||
peers,
|
||||
wsServer: server,
|
||||
request,
|
||||
cfEnv: env,
|
||||
cfCtx,
|
||||
context
|
||||
});
|
||||
peers.add(peer);
|
||||
server.accept();
|
||||
hooks.callHook("open", peer);
|
||||
server.addEventListener("message", (event) => {
|
||||
hooks.callHook(
|
||||
"message",
|
||||
peer,
|
||||
new Message(event.data, peer, event)
|
||||
);
|
||||
});
|
||||
server.addEventListener("error", (event) => {
|
||||
peers.delete(peer);
|
||||
hooks.callHook("error", peer, new WSError(event.error));
|
||||
});
|
||||
server.addEventListener("close", (event) => {
|
||||
peers.delete(peer);
|
||||
hooks.callHook("close", peer, event);
|
||||
});
|
||||
return new Response(null, {
|
||||
status: 101,
|
||||
webSocket: client,
|
||||
headers: upgradeHeaders
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
class CloudflarePeer extends Peer {
|
||||
send(data) {
|
||||
this._internal.wsServer.send(toBufferLike(data));
|
||||
return 0;
|
||||
}
|
||||
publish(_topic, _message) {
|
||||
}
|
||||
close(code, reason) {
|
||||
this._internal.ws.close(code, reason);
|
||||
}
|
||||
}
|
||||
|
||||
export { cloudflareAdapter as default };
|
19
node_modules/crossws/dist/adapters/deno.d.mts
generated
vendored
Normal file
19
node_modules/crossws/dist/adapters/deno.d.mts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
|
||||
import '../shared/crossws.BQXMA5bH.mjs';
|
||||
|
||||
interface DenoAdapter extends AdapterInstance {
|
||||
handleUpgrade(req: Request, info: ServeHandlerInfo): Promise<Response>;
|
||||
}
|
||||
interface DenoOptions extends AdapterOptions {
|
||||
}
|
||||
type ServeHandlerInfo = {
|
||||
remoteAddr?: {
|
||||
transport: string;
|
||||
hostname: string;
|
||||
port: number;
|
||||
};
|
||||
};
|
||||
declare const denoAdapter: Adapter<DenoAdapter, DenoOptions>;
|
||||
|
||||
export { denoAdapter as default };
|
||||
export type { DenoAdapter, DenoOptions };
|
19
node_modules/crossws/dist/adapters/deno.d.ts
generated
vendored
Normal file
19
node_modules/crossws/dist/adapters/deno.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
|
||||
import '../shared/crossws.BQXMA5bH.js';
|
||||
|
||||
interface DenoAdapter extends AdapterInstance {
|
||||
handleUpgrade(req: Request, info: ServeHandlerInfo): Promise<Response>;
|
||||
}
|
||||
interface DenoOptions extends AdapterOptions {
|
||||
}
|
||||
type ServeHandlerInfo = {
|
||||
remoteAddr?: {
|
||||
transport: string;
|
||||
hostname: string;
|
||||
port: number;
|
||||
};
|
||||
};
|
||||
declare const denoAdapter: Adapter<DenoAdapter, DenoOptions>;
|
||||
|
||||
export { denoAdapter as default };
|
||||
export type { DenoAdapter, DenoOptions };
|
69
node_modules/crossws/dist/adapters/deno.mjs
generated
vendored
Normal file
69
node_modules/crossws/dist/adapters/deno.mjs
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
|
||||
import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
|
||||
import { W as WSError } from '../shared/crossws.By9qWDAI.mjs';
|
||||
import 'uncrypto';
|
||||
|
||||
const denoAdapter = (options = {}) => {
|
||||
const hooks = new AdapterHookable(options);
|
||||
const peers = /* @__PURE__ */ new Set();
|
||||
return {
|
||||
...adapterUtils(peers),
|
||||
handleUpgrade: async (request, info) => {
|
||||
const { upgradeHeaders, endResponse, context } = await hooks.upgrade(request);
|
||||
if (endResponse) {
|
||||
return endResponse;
|
||||
}
|
||||
const upgrade = Deno.upgradeWebSocket(request, {
|
||||
// @ts-expect-error https://github.com/denoland/deno/pull/22242
|
||||
headers: upgradeHeaders
|
||||
});
|
||||
const peer = new DenoPeer({
|
||||
ws: upgrade.socket,
|
||||
request,
|
||||
peers,
|
||||
denoInfo: info,
|
||||
context
|
||||
});
|
||||
peers.add(peer);
|
||||
upgrade.socket.addEventListener("open", () => {
|
||||
hooks.callHook("open", peer);
|
||||
});
|
||||
upgrade.socket.addEventListener("message", (event) => {
|
||||
hooks.callHook("message", peer, new Message(event.data, peer, event));
|
||||
});
|
||||
upgrade.socket.addEventListener("close", () => {
|
||||
peers.delete(peer);
|
||||
hooks.callHook("close", peer, {});
|
||||
});
|
||||
upgrade.socket.addEventListener("error", (error) => {
|
||||
peers.delete(peer);
|
||||
hooks.callHook("error", peer, new WSError(error));
|
||||
});
|
||||
return upgrade.response;
|
||||
}
|
||||
};
|
||||
};
|
||||
class DenoPeer extends Peer {
|
||||
get remoteAddress() {
|
||||
return this._internal.denoInfo.remoteAddr?.hostname;
|
||||
}
|
||||
send(data) {
|
||||
return this._internal.ws.send(toBufferLike(data));
|
||||
}
|
||||
publish(topic, data) {
|
||||
const dataBuff = toBufferLike(data);
|
||||
for (const peer of this._internal.peers) {
|
||||
if (peer !== this && peer._topics.has(topic)) {
|
||||
peer._internal.ws.send(dataBuff);
|
||||
}
|
||||
}
|
||||
}
|
||||
close(code, reason) {
|
||||
this._internal.ws.close(code, reason);
|
||||
}
|
||||
terminate() {
|
||||
this._internal.ws.terminate();
|
||||
}
|
||||
}
|
||||
|
||||
export { denoAdapter as default };
|
299
node_modules/crossws/dist/adapters/node.d.mts
generated
vendored
Normal file
299
node_modules/crossws/dist/adapters/node.d.mts
generated
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
|
||||
import { Agent, ClientRequestArgs, IncomingMessage, ClientRequest, Server as Server$1, OutgoingHttpHeaders } from 'node:http';
|
||||
import { DuplexOptions, Duplex } from 'node:stream';
|
||||
import { EventEmitter } from 'events';
|
||||
import { Server as Server$2 } from 'node:https';
|
||||
import { SecureContextOptions } from 'node:tls';
|
||||
import { URL } from 'node:url';
|
||||
import { ZlibOptions } from 'node:zlib';
|
||||
import '../shared/crossws.BQXMA5bH.mjs';
|
||||
|
||||
type BufferLike = string | Buffer | DataView | number | ArrayBufferView | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly any[] | readonly number[] | {
|
||||
valueOf(): ArrayBuffer;
|
||||
} | {
|
||||
valueOf(): SharedArrayBuffer;
|
||||
} | {
|
||||
valueOf(): Uint8Array;
|
||||
} | {
|
||||
valueOf(): readonly number[];
|
||||
} | {
|
||||
valueOf(): string;
|
||||
} | {
|
||||
[Symbol.toPrimitive](hint: string): string;
|
||||
};
|
||||
declare class WebSocket extends EventEmitter {
|
||||
static readonly createWebSocketStream: typeof createWebSocketStream;
|
||||
static readonly WebSocketServer: WebSocketServer;
|
||||
static readonly Server: typeof Server;
|
||||
static readonly WebSocket: typeof WebSocket;
|
||||
/** The connection is not yet open. */
|
||||
static readonly CONNECTING: 0;
|
||||
/** The connection is open and ready to communicate. */
|
||||
static readonly OPEN: 1;
|
||||
/** The connection is in the process of closing. */
|
||||
static readonly CLOSING: 2;
|
||||
/** The connection is closed. */
|
||||
static readonly CLOSED: 3;
|
||||
binaryType: "nodebuffer" | "arraybuffer" | "fragments";
|
||||
readonly bufferedAmount: number;
|
||||
readonly extensions: string;
|
||||
/** Indicates whether the websocket is paused */
|
||||
readonly isPaused: boolean;
|
||||
readonly protocol: string;
|
||||
/** The current state of the connection */
|
||||
readonly readyState: typeof WebSocket.CONNECTING | typeof WebSocket.OPEN | typeof WebSocket.CLOSING | typeof WebSocket.CLOSED;
|
||||
readonly url: string;
|
||||
/** The connection is not yet open. */
|
||||
readonly CONNECTING: 0;
|
||||
/** The connection is open and ready to communicate. */
|
||||
readonly OPEN: 1;
|
||||
/** The connection is in the process of closing. */
|
||||
readonly CLOSING: 2;
|
||||
/** The connection is closed. */
|
||||
readonly CLOSED: 3;
|
||||
onopen: ((event: Event) => void) | null;
|
||||
onerror: ((event: ErrorEvent) => void) | null;
|
||||
onclose: ((event: CloseEvent) => void) | null;
|
||||
onmessage: ((event: MessageEvent) => void) | null;
|
||||
constructor(address: null);
|
||||
constructor(address: string | URL, options?: ClientOptions | ClientRequestArgs);
|
||||
constructor(address: string | URL, protocols?: string | string[], options?: ClientOptions | ClientRequestArgs);
|
||||
close(code?: number, data?: string | Buffer): void;
|
||||
ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void;
|
||||
pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void;
|
||||
send(data: BufferLike, cb?: (err?: Error) => void): void;
|
||||
send(data: BufferLike, options: {
|
||||
mask?: boolean | undefined;
|
||||
binary?: boolean | undefined;
|
||||
compress?: boolean | undefined;
|
||||
fin?: boolean | undefined;
|
||||
}, cb?: (err?: Error) => void): void;
|
||||
terminate(): void;
|
||||
/**
|
||||
* Pause the websocket causing it to stop emitting events. Some events can still be
|
||||
* emitted after this is called, until all buffered data is consumed. This method
|
||||
* is a noop if the ready state is `CONNECTING` or `CLOSED`.
|
||||
*/
|
||||
pause(): void;
|
||||
/**
|
||||
* Make a paused socket resume emitting events. This method is a noop if the ready
|
||||
* state is `CONNECTING` or `CLOSED`.
|
||||
*/
|
||||
resume(): void;
|
||||
addEventListener(method: "message", cb: (event: MessageEvent) => void, options?: EventListenerOptions): void;
|
||||
addEventListener(method: "close", cb: (event: CloseEvent) => void, options?: EventListenerOptions): void;
|
||||
addEventListener(method: "error", cb: (event: ErrorEvent) => void, options?: EventListenerOptions): void;
|
||||
addEventListener(method: "open", cb: (event: Event) => void, options?: EventListenerOptions): void;
|
||||
removeEventListener(method: "message", cb: (event: MessageEvent) => void): void;
|
||||
removeEventListener(method: "close", cb: (event: CloseEvent) => void): void;
|
||||
removeEventListener(method: "error", cb: (event: ErrorEvent) => void): void;
|
||||
removeEventListener(method: "open", cb: (event: Event) => void): void;
|
||||
on(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
||||
on(event: "error", listener: (this: WebSocket, err: Error) => void): this;
|
||||
on(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
||||
on(event: "message", listener: (this: WebSocket, data: RawData, isBinary: boolean) => void): this;
|
||||
on(event: "open", listener: (this: WebSocket) => void): this;
|
||||
on(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
||||
on(event: "unexpected-response", listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
||||
once(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
||||
once(event: "error", listener: (this: WebSocket, err: Error) => void): this;
|
||||
once(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
||||
once(event: "message", listener: (this: WebSocket, data: RawData, isBinary: boolean) => void): this;
|
||||
once(event: "open", listener: (this: WebSocket) => void): this;
|
||||
once(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
||||
once(event: "unexpected-response", listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
once(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
||||
off(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
||||
off(event: "error", listener: (this: WebSocket, err: Error) => void): this;
|
||||
off(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
||||
off(event: "message", listener: (this: WebSocket, data: RawData, isBinary: boolean) => void): this;
|
||||
off(event: "open", listener: (this: WebSocket) => void): this;
|
||||
off(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
||||
off(event: "unexpected-response", listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
off(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
||||
addListener(event: "close", listener: (code: number, reason: Buffer) => void): this;
|
||||
addListener(event: "error", listener: (err: Error) => void): this;
|
||||
addListener(event: "upgrade", listener: (request: IncomingMessage) => void): this;
|
||||
addListener(event: "message", listener: (data: RawData, isBinary: boolean) => void): this;
|
||||
addListener(event: "open", listener: () => void): this;
|
||||
addListener(event: "ping" | "pong", listener: (data: Buffer) => void): this;
|
||||
addListener(event: "unexpected-response", listener: (request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
removeListener(event: "close", listener: (code: number, reason: Buffer) => void): this;
|
||||
removeListener(event: "error", listener: (err: Error) => void): this;
|
||||
removeListener(event: "upgrade", listener: (request: IncomingMessage) => void): this;
|
||||
removeListener(event: "message", listener: (data: RawData, isBinary: boolean) => void): this;
|
||||
removeListener(event: "open", listener: () => void): this;
|
||||
removeListener(event: "ping" | "pong", listener: (data: Buffer) => void): this;
|
||||
removeListener(event: "unexpected-response", listener: (request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
}
|
||||
/**
|
||||
* Data represents the raw message payload received over the
|
||||
*/
|
||||
type RawData = Buffer | ArrayBuffer | Buffer[];
|
||||
/**
|
||||
* Data represents the message payload received over the
|
||||
*/
|
||||
type Data = string | Buffer | ArrayBuffer | Buffer[];
|
||||
/**
|
||||
* CertMeta represents the accepted types for certificate & key data.
|
||||
*/
|
||||
type CertMeta = string | string[] | Buffer | Buffer[];
|
||||
/**
|
||||
* VerifyClientCallbackSync is a synchronous callback used to inspect the
|
||||
* incoming message. The return value (boolean) of the function determines
|
||||
* whether or not to accept the handshake.
|
||||
*/
|
||||
type VerifyClientCallbackSync<Request extends IncomingMessage = IncomingMessage> = (info: {
|
||||
origin: string;
|
||||
secure: boolean;
|
||||
req: Request;
|
||||
}) => boolean;
|
||||
/**
|
||||
* VerifyClientCallbackAsync is an asynchronous callback used to inspect the
|
||||
* incoming message. The return value (boolean) of the function determines
|
||||
* whether or not to accept the handshake.
|
||||
*/
|
||||
type VerifyClientCallbackAsync<Request extends IncomingMessage = IncomingMessage> = (info: {
|
||||
origin: string;
|
||||
secure: boolean;
|
||||
req: Request;
|
||||
}, callback: (res: boolean, code?: number, message?: string, headers?: OutgoingHttpHeaders) => void) => void;
|
||||
interface ClientOptions extends SecureContextOptions {
|
||||
protocol?: string | undefined;
|
||||
followRedirects?: boolean | undefined;
|
||||
generateMask?(mask: Buffer): void;
|
||||
handshakeTimeout?: number | undefined;
|
||||
maxRedirects?: number | undefined;
|
||||
perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
|
||||
localAddress?: string | undefined;
|
||||
protocolVersion?: number | undefined;
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
} | undefined;
|
||||
origin?: string | undefined;
|
||||
agent?: Agent | undefined;
|
||||
host?: string | undefined;
|
||||
family?: number | undefined;
|
||||
checkServerIdentity?(servername: string, cert: CertMeta): boolean;
|
||||
rejectUnauthorized?: boolean | undefined;
|
||||
maxPayload?: number | undefined;
|
||||
skipUTF8Validation?: boolean | undefined;
|
||||
}
|
||||
interface PerMessageDeflateOptions {
|
||||
serverNoContextTakeover?: boolean | undefined;
|
||||
clientNoContextTakeover?: boolean | undefined;
|
||||
serverMaxWindowBits?: number | undefined;
|
||||
clientMaxWindowBits?: number | undefined;
|
||||
zlibDeflateOptions?: {
|
||||
flush?: number | undefined;
|
||||
finishFlush?: number | undefined;
|
||||
chunkSize?: number | undefined;
|
||||
windowBits?: number | undefined;
|
||||
level?: number | undefined;
|
||||
memLevel?: number | undefined;
|
||||
strategy?: number | undefined;
|
||||
dictionary?: Buffer | Buffer[] | DataView | undefined;
|
||||
info?: boolean | undefined;
|
||||
} | undefined;
|
||||
zlibInflateOptions?: ZlibOptions | undefined;
|
||||
threshold?: number | undefined;
|
||||
concurrencyLimit?: number | undefined;
|
||||
}
|
||||
interface Event {
|
||||
type: string;
|
||||
target: WebSocket;
|
||||
}
|
||||
interface ErrorEvent {
|
||||
error: any;
|
||||
message: string;
|
||||
type: string;
|
||||
target: WebSocket;
|
||||
}
|
||||
interface CloseEvent {
|
||||
wasClean: boolean;
|
||||
code: number;
|
||||
reason: string;
|
||||
type: string;
|
||||
target: WebSocket;
|
||||
}
|
||||
interface MessageEvent {
|
||||
data: Data;
|
||||
type: string;
|
||||
target: WebSocket;
|
||||
}
|
||||
interface EventListenerOptions {
|
||||
once?: boolean | undefined;
|
||||
}
|
||||
interface ServerOptions<U extends typeof WebSocket = typeof WebSocket, V extends typeof IncomingMessage = typeof IncomingMessage> {
|
||||
host?: string | undefined;
|
||||
port?: number | undefined;
|
||||
backlog?: number | undefined;
|
||||
server?: Server$1<V> | Server$2<V> | undefined;
|
||||
verifyClient?: VerifyClientCallbackAsync<InstanceType<V>> | VerifyClientCallbackSync<InstanceType<V>> | undefined;
|
||||
handleProtocols?: (protocols: Set<string>, request: InstanceType<V>) => string | false;
|
||||
path?: string | undefined;
|
||||
noServer?: boolean | undefined;
|
||||
clientTracking?: boolean | undefined;
|
||||
perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
|
||||
maxPayload?: number | undefined;
|
||||
skipUTF8Validation?: boolean | undefined;
|
||||
WebSocket?: U | undefined;
|
||||
}
|
||||
interface AddressInfo {
|
||||
address: string;
|
||||
family: string;
|
||||
port: number;
|
||||
}
|
||||
declare class Server<T extends typeof WebSocket = typeof WebSocket, U extends typeof IncomingMessage = typeof IncomingMessage> extends EventEmitter {
|
||||
options: ServerOptions<T, U>;
|
||||
path: string;
|
||||
clients: Set<InstanceType<T>>;
|
||||
constructor(options?: ServerOptions<T, U>, callback?: () => void);
|
||||
address(): AddressInfo | string;
|
||||
close(cb?: (err?: Error) => void): void;
|
||||
handleUpgrade(request: InstanceType<U>, socket: Duplex, upgradeHead: Buffer, callback: (client: InstanceType<T>, request: InstanceType<U>) => void): void;
|
||||
shouldHandle(request: InstanceType<U>): boolean | Promise<boolean>;
|
||||
on(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
on(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
||||
on(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
||||
on(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
||||
on(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
||||
once(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
once(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
||||
once(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
||||
once(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
||||
once(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
||||
off(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
off(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
||||
off(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
||||
off(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
||||
off(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
||||
addListener(event: "connection", cb: (client: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
addListener(event: "error", cb: (err: Error) => void): this;
|
||||
addListener(event: "headers", cb: (headers: string[], request: InstanceType<U>) => void): this;
|
||||
addListener(event: "close" | "listening", cb: () => void): this;
|
||||
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
removeListener(event: "connection", cb: (client: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
removeListener(event: "error", cb: (err: Error) => void): this;
|
||||
removeListener(event: "headers", cb: (headers: string[], request: InstanceType<U>) => void): this;
|
||||
removeListener(event: "close" | "listening", cb: () => void): this;
|
||||
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
}
|
||||
type WebSocketServer = Server;
|
||||
declare function createWebSocketStream(websocket: WebSocket, options?: DuplexOptions): Duplex;
|
||||
|
||||
interface NodeAdapter extends AdapterInstance {
|
||||
handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer): Promise<void>;
|
||||
closeAll: (code?: number, data?: string | Buffer, force?: boolean) => void;
|
||||
}
|
||||
interface NodeOptions extends AdapterOptions {
|
||||
wss?: WebSocketServer;
|
||||
serverOptions?: ServerOptions;
|
||||
}
|
||||
declare const nodeAdapter: Adapter<NodeAdapter, NodeOptions>;
|
||||
|
||||
export { nodeAdapter as default };
|
||||
export type { NodeAdapter, NodeOptions };
|
299
node_modules/crossws/dist/adapters/node.d.ts
generated
vendored
Normal file
299
node_modules/crossws/dist/adapters/node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
|
||||
import { Agent, ClientRequestArgs, IncomingMessage, ClientRequest, Server as Server$1, OutgoingHttpHeaders } from 'node:http';
|
||||
import { DuplexOptions, Duplex } from 'node:stream';
|
||||
import { EventEmitter } from 'events';
|
||||
import { Server as Server$2 } from 'node:https';
|
||||
import { SecureContextOptions } from 'node:tls';
|
||||
import { URL } from 'node:url';
|
||||
import { ZlibOptions } from 'node:zlib';
|
||||
import '../shared/crossws.BQXMA5bH.js';
|
||||
|
||||
type BufferLike = string | Buffer | DataView | number | ArrayBufferView | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly any[] | readonly number[] | {
|
||||
valueOf(): ArrayBuffer;
|
||||
} | {
|
||||
valueOf(): SharedArrayBuffer;
|
||||
} | {
|
||||
valueOf(): Uint8Array;
|
||||
} | {
|
||||
valueOf(): readonly number[];
|
||||
} | {
|
||||
valueOf(): string;
|
||||
} | {
|
||||
[Symbol.toPrimitive](hint: string): string;
|
||||
};
|
||||
declare class WebSocket extends EventEmitter {
|
||||
static readonly createWebSocketStream: typeof createWebSocketStream;
|
||||
static readonly WebSocketServer: WebSocketServer;
|
||||
static readonly Server: typeof Server;
|
||||
static readonly WebSocket: typeof WebSocket;
|
||||
/** The connection is not yet open. */
|
||||
static readonly CONNECTING: 0;
|
||||
/** The connection is open and ready to communicate. */
|
||||
static readonly OPEN: 1;
|
||||
/** The connection is in the process of closing. */
|
||||
static readonly CLOSING: 2;
|
||||
/** The connection is closed. */
|
||||
static readonly CLOSED: 3;
|
||||
binaryType: "nodebuffer" | "arraybuffer" | "fragments";
|
||||
readonly bufferedAmount: number;
|
||||
readonly extensions: string;
|
||||
/** Indicates whether the websocket is paused */
|
||||
readonly isPaused: boolean;
|
||||
readonly protocol: string;
|
||||
/** The current state of the connection */
|
||||
readonly readyState: typeof WebSocket.CONNECTING | typeof WebSocket.OPEN | typeof WebSocket.CLOSING | typeof WebSocket.CLOSED;
|
||||
readonly url: string;
|
||||
/** The connection is not yet open. */
|
||||
readonly CONNECTING: 0;
|
||||
/** The connection is open and ready to communicate. */
|
||||
readonly OPEN: 1;
|
||||
/** The connection is in the process of closing. */
|
||||
readonly CLOSING: 2;
|
||||
/** The connection is closed. */
|
||||
readonly CLOSED: 3;
|
||||
onopen: ((event: Event) => void) | null;
|
||||
onerror: ((event: ErrorEvent) => void) | null;
|
||||
onclose: ((event: CloseEvent) => void) | null;
|
||||
onmessage: ((event: MessageEvent) => void) | null;
|
||||
constructor(address: null);
|
||||
constructor(address: string | URL, options?: ClientOptions | ClientRequestArgs);
|
||||
constructor(address: string | URL, protocols?: string | string[], options?: ClientOptions | ClientRequestArgs);
|
||||
close(code?: number, data?: string | Buffer): void;
|
||||
ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void;
|
||||
pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void;
|
||||
send(data: BufferLike, cb?: (err?: Error) => void): void;
|
||||
send(data: BufferLike, options: {
|
||||
mask?: boolean | undefined;
|
||||
binary?: boolean | undefined;
|
||||
compress?: boolean | undefined;
|
||||
fin?: boolean | undefined;
|
||||
}, cb?: (err?: Error) => void): void;
|
||||
terminate(): void;
|
||||
/**
|
||||
* Pause the websocket causing it to stop emitting events. Some events can still be
|
||||
* emitted after this is called, until all buffered data is consumed. This method
|
||||
* is a noop if the ready state is `CONNECTING` or `CLOSED`.
|
||||
*/
|
||||
pause(): void;
|
||||
/**
|
||||
* Make a paused socket resume emitting events. This method is a noop if the ready
|
||||
* state is `CONNECTING` or `CLOSED`.
|
||||
*/
|
||||
resume(): void;
|
||||
addEventListener(method: "message", cb: (event: MessageEvent) => void, options?: EventListenerOptions): void;
|
||||
addEventListener(method: "close", cb: (event: CloseEvent) => void, options?: EventListenerOptions): void;
|
||||
addEventListener(method: "error", cb: (event: ErrorEvent) => void, options?: EventListenerOptions): void;
|
||||
addEventListener(method: "open", cb: (event: Event) => void, options?: EventListenerOptions): void;
|
||||
removeEventListener(method: "message", cb: (event: MessageEvent) => void): void;
|
||||
removeEventListener(method: "close", cb: (event: CloseEvent) => void): void;
|
||||
removeEventListener(method: "error", cb: (event: ErrorEvent) => void): void;
|
||||
removeEventListener(method: "open", cb: (event: Event) => void): void;
|
||||
on(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
||||
on(event: "error", listener: (this: WebSocket, err: Error) => void): this;
|
||||
on(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
||||
on(event: "message", listener: (this: WebSocket, data: RawData, isBinary: boolean) => void): this;
|
||||
on(event: "open", listener: (this: WebSocket) => void): this;
|
||||
on(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
||||
on(event: "unexpected-response", listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
||||
once(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
||||
once(event: "error", listener: (this: WebSocket, err: Error) => void): this;
|
||||
once(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
||||
once(event: "message", listener: (this: WebSocket, data: RawData, isBinary: boolean) => void): this;
|
||||
once(event: "open", listener: (this: WebSocket) => void): this;
|
||||
once(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
||||
once(event: "unexpected-response", listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
once(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
||||
off(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
||||
off(event: "error", listener: (this: WebSocket, err: Error) => void): this;
|
||||
off(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
||||
off(event: "message", listener: (this: WebSocket, data: RawData, isBinary: boolean) => void): this;
|
||||
off(event: "open", listener: (this: WebSocket) => void): this;
|
||||
off(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
||||
off(event: "unexpected-response", listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
off(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
||||
addListener(event: "close", listener: (code: number, reason: Buffer) => void): this;
|
||||
addListener(event: "error", listener: (err: Error) => void): this;
|
||||
addListener(event: "upgrade", listener: (request: IncomingMessage) => void): this;
|
||||
addListener(event: "message", listener: (data: RawData, isBinary: boolean) => void): this;
|
||||
addListener(event: "open", listener: () => void): this;
|
||||
addListener(event: "ping" | "pong", listener: (data: Buffer) => void): this;
|
||||
addListener(event: "unexpected-response", listener: (request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
removeListener(event: "close", listener: (code: number, reason: Buffer) => void): this;
|
||||
removeListener(event: "error", listener: (err: Error) => void): this;
|
||||
removeListener(event: "upgrade", listener: (request: IncomingMessage) => void): this;
|
||||
removeListener(event: "message", listener: (data: RawData, isBinary: boolean) => void): this;
|
||||
removeListener(event: "open", listener: () => void): this;
|
||||
removeListener(event: "ping" | "pong", listener: (data: Buffer) => void): this;
|
||||
removeListener(event: "unexpected-response", listener: (request: ClientRequest, response: IncomingMessage) => void): this;
|
||||
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
}
|
||||
/**
|
||||
* Data represents the raw message payload received over the
|
||||
*/
|
||||
type RawData = Buffer | ArrayBuffer | Buffer[];
|
||||
/**
|
||||
* Data represents the message payload received over the
|
||||
*/
|
||||
type Data = string | Buffer | ArrayBuffer | Buffer[];
|
||||
/**
|
||||
* CertMeta represents the accepted types for certificate & key data.
|
||||
*/
|
||||
type CertMeta = string | string[] | Buffer | Buffer[];
|
||||
/**
|
||||
* VerifyClientCallbackSync is a synchronous callback used to inspect the
|
||||
* incoming message. The return value (boolean) of the function determines
|
||||
* whether or not to accept the handshake.
|
||||
*/
|
||||
type VerifyClientCallbackSync<Request extends IncomingMessage = IncomingMessage> = (info: {
|
||||
origin: string;
|
||||
secure: boolean;
|
||||
req: Request;
|
||||
}) => boolean;
|
||||
/**
|
||||
* VerifyClientCallbackAsync is an asynchronous callback used to inspect the
|
||||
* incoming message. The return value (boolean) of the function determines
|
||||
* whether or not to accept the handshake.
|
||||
*/
|
||||
type VerifyClientCallbackAsync<Request extends IncomingMessage = IncomingMessage> = (info: {
|
||||
origin: string;
|
||||
secure: boolean;
|
||||
req: Request;
|
||||
}, callback: (res: boolean, code?: number, message?: string, headers?: OutgoingHttpHeaders) => void) => void;
|
||||
interface ClientOptions extends SecureContextOptions {
|
||||
protocol?: string | undefined;
|
||||
followRedirects?: boolean | undefined;
|
||||
generateMask?(mask: Buffer): void;
|
||||
handshakeTimeout?: number | undefined;
|
||||
maxRedirects?: number | undefined;
|
||||
perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
|
||||
localAddress?: string | undefined;
|
||||
protocolVersion?: number | undefined;
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
} | undefined;
|
||||
origin?: string | undefined;
|
||||
agent?: Agent | undefined;
|
||||
host?: string | undefined;
|
||||
family?: number | undefined;
|
||||
checkServerIdentity?(servername: string, cert: CertMeta): boolean;
|
||||
rejectUnauthorized?: boolean | undefined;
|
||||
maxPayload?: number | undefined;
|
||||
skipUTF8Validation?: boolean | undefined;
|
||||
}
|
||||
interface PerMessageDeflateOptions {
|
||||
serverNoContextTakeover?: boolean | undefined;
|
||||
clientNoContextTakeover?: boolean | undefined;
|
||||
serverMaxWindowBits?: number | undefined;
|
||||
clientMaxWindowBits?: number | undefined;
|
||||
zlibDeflateOptions?: {
|
||||
flush?: number | undefined;
|
||||
finishFlush?: number | undefined;
|
||||
chunkSize?: number | undefined;
|
||||
windowBits?: number | undefined;
|
||||
level?: number | undefined;
|
||||
memLevel?: number | undefined;
|
||||
strategy?: number | undefined;
|
||||
dictionary?: Buffer | Buffer[] | DataView | undefined;
|
||||
info?: boolean | undefined;
|
||||
} | undefined;
|
||||
zlibInflateOptions?: ZlibOptions | undefined;
|
||||
threshold?: number | undefined;
|
||||
concurrencyLimit?: number | undefined;
|
||||
}
|
||||
interface Event {
|
||||
type: string;
|
||||
target: WebSocket;
|
||||
}
|
||||
interface ErrorEvent {
|
||||
error: any;
|
||||
message: string;
|
||||
type: string;
|
||||
target: WebSocket;
|
||||
}
|
||||
interface CloseEvent {
|
||||
wasClean: boolean;
|
||||
code: number;
|
||||
reason: string;
|
||||
type: string;
|
||||
target: WebSocket;
|
||||
}
|
||||
interface MessageEvent {
|
||||
data: Data;
|
||||
type: string;
|
||||
target: WebSocket;
|
||||
}
|
||||
interface EventListenerOptions {
|
||||
once?: boolean | undefined;
|
||||
}
|
||||
interface ServerOptions<U extends typeof WebSocket = typeof WebSocket, V extends typeof IncomingMessage = typeof IncomingMessage> {
|
||||
host?: string | undefined;
|
||||
port?: number | undefined;
|
||||
backlog?: number | undefined;
|
||||
server?: Server$1<V> | Server$2<V> | undefined;
|
||||
verifyClient?: VerifyClientCallbackAsync<InstanceType<V>> | VerifyClientCallbackSync<InstanceType<V>> | undefined;
|
||||
handleProtocols?: (protocols: Set<string>, request: InstanceType<V>) => string | false;
|
||||
path?: string | undefined;
|
||||
noServer?: boolean | undefined;
|
||||
clientTracking?: boolean | undefined;
|
||||
perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
|
||||
maxPayload?: number | undefined;
|
||||
skipUTF8Validation?: boolean | undefined;
|
||||
WebSocket?: U | undefined;
|
||||
}
|
||||
interface AddressInfo {
|
||||
address: string;
|
||||
family: string;
|
||||
port: number;
|
||||
}
|
||||
declare class Server<T extends typeof WebSocket = typeof WebSocket, U extends typeof IncomingMessage = typeof IncomingMessage> extends EventEmitter {
|
||||
options: ServerOptions<T, U>;
|
||||
path: string;
|
||||
clients: Set<InstanceType<T>>;
|
||||
constructor(options?: ServerOptions<T, U>, callback?: () => void);
|
||||
address(): AddressInfo | string;
|
||||
close(cb?: (err?: Error) => void): void;
|
||||
handleUpgrade(request: InstanceType<U>, socket: Duplex, upgradeHead: Buffer, callback: (client: InstanceType<T>, request: InstanceType<U>) => void): void;
|
||||
shouldHandle(request: InstanceType<U>): boolean | Promise<boolean>;
|
||||
on(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
on(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
||||
on(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
||||
on(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
||||
on(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
||||
once(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
once(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
||||
once(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
||||
once(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
||||
once(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
||||
off(event: "connection", cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
off(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
||||
off(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
||||
off(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
||||
off(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
||||
addListener(event: "connection", cb: (client: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
addListener(event: "error", cb: (err: Error) => void): this;
|
||||
addListener(event: "headers", cb: (headers: string[], request: InstanceType<U>) => void): this;
|
||||
addListener(event: "close" | "listening", cb: () => void): this;
|
||||
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
removeListener(event: "connection", cb: (client: InstanceType<T>, request: InstanceType<U>) => void): this;
|
||||
removeListener(event: "error", cb: (err: Error) => void): this;
|
||||
removeListener(event: "headers", cb: (headers: string[], request: InstanceType<U>) => void): this;
|
||||
removeListener(event: "close" | "listening", cb: () => void): this;
|
||||
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
}
|
||||
type WebSocketServer = Server;
|
||||
declare function createWebSocketStream(websocket: WebSocket, options?: DuplexOptions): Duplex;
|
||||
|
||||
interface NodeAdapter extends AdapterInstance {
|
||||
handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer): Promise<void>;
|
||||
closeAll: (code?: number, data?: string | Buffer, force?: boolean) => void;
|
||||
}
|
||||
interface NodeOptions extends AdapterOptions {
|
||||
wss?: WebSocketServer;
|
||||
serverOptions?: ServerOptions;
|
||||
}
|
||||
declare const nodeAdapter: Adapter<NodeAdapter, NodeOptions>;
|
||||
|
||||
export { nodeAdapter as default };
|
||||
export type { NodeAdapter, NodeOptions };
|
163
node_modules/crossws/dist/adapters/node.mjs
generated
vendored
Normal file
163
node_modules/crossws/dist/adapters/node.mjs
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
|
||||
import { A as AdapterHookable, a as adapterUtils } from '../shared/crossws.D9ehKjSh.mjs';
|
||||
import { W as WSError } from '../shared/crossws.By9qWDAI.mjs';
|
||||
import { _ as _WebSocketServer } from '../shared/crossws.CipVM6lf.mjs';
|
||||
import 'uncrypto';
|
||||
import 'stream';
|
||||
import 'events';
|
||||
import 'http';
|
||||
import 'crypto';
|
||||
import 'buffer';
|
||||
import 'zlib';
|
||||
import 'https';
|
||||
import 'net';
|
||||
import 'tls';
|
||||
import 'url';
|
||||
|
||||
const nodeAdapter = (options = {}) => {
|
||||
const hooks = new AdapterHookable(options);
|
||||
const peers = /* @__PURE__ */ new Set();
|
||||
const wss = options.wss || new _WebSocketServer({
|
||||
noServer: true,
|
||||
...options.serverOptions
|
||||
});
|
||||
wss.on("connection", (ws, nodeReq) => {
|
||||
const request = new NodeReqProxy(nodeReq);
|
||||
const peer = new NodePeer({ ws, request, peers, nodeReq });
|
||||
peers.add(peer);
|
||||
hooks.callHook("open", peer);
|
||||
ws.on("message", (data) => {
|
||||
if (Array.isArray(data)) {
|
||||
data = Buffer.concat(data);
|
||||
}
|
||||
hooks.callHook("message", peer, new Message(data, peer));
|
||||
});
|
||||
ws.on("error", (error) => {
|
||||
peers.delete(peer);
|
||||
hooks.callHook("error", peer, new WSError(error));
|
||||
});
|
||||
ws.on("close", (code, reason) => {
|
||||
peers.delete(peer);
|
||||
hooks.callHook("close", peer, {
|
||||
code,
|
||||
reason: reason?.toString()
|
||||
});
|
||||
});
|
||||
});
|
||||
wss.on("headers", (outgoingHeaders, req) => {
|
||||
const upgradeHeaders = req._upgradeHeaders;
|
||||
if (upgradeHeaders) {
|
||||
for (const [key, value] of new Headers(upgradeHeaders)) {
|
||||
outgoingHeaders.push(`${key}: ${value}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
return {
|
||||
...adapterUtils(peers),
|
||||
handleUpgrade: async (nodeReq, socket, head) => {
|
||||
const request = new NodeReqProxy(nodeReq);
|
||||
const { upgradeHeaders, endResponse, context } = await hooks.upgrade(request);
|
||||
if (endResponse) {
|
||||
return sendResponse(socket, endResponse);
|
||||
}
|
||||
nodeReq._request = request;
|
||||
nodeReq._upgradeHeaders = upgradeHeaders;
|
||||
nodeReq._context = context;
|
||||
wss.handleUpgrade(nodeReq, socket, head, (ws) => {
|
||||
wss.emit("connection", ws, nodeReq);
|
||||
});
|
||||
},
|
||||
closeAll: (code, data, force) => {
|
||||
for (const client of wss.clients) {
|
||||
if (force) {
|
||||
client.terminate();
|
||||
} else {
|
||||
client.close(code, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
class NodePeer extends Peer {
|
||||
get remoteAddress() {
|
||||
return this._internal.nodeReq.socket?.remoteAddress;
|
||||
}
|
||||
get context() {
|
||||
return this._internal.nodeReq._context;
|
||||
}
|
||||
send(data, options) {
|
||||
const dataBuff = toBufferLike(data);
|
||||
const isBinary = typeof dataBuff !== "string";
|
||||
this._internal.ws.send(dataBuff, {
|
||||
compress: options?.compress,
|
||||
binary: isBinary,
|
||||
...options
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
publish(topic, data, options) {
|
||||
const dataBuff = toBufferLike(data);
|
||||
const isBinary = typeof data !== "string";
|
||||
const sendOptions = {
|
||||
compress: options?.compress,
|
||||
binary: isBinary,
|
||||
...options
|
||||
};
|
||||
for (const peer of this._internal.peers) {
|
||||
if (peer !== this && peer._topics.has(topic)) {
|
||||
peer._internal.ws.send(dataBuff, sendOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
close(code, data) {
|
||||
this._internal.ws.close(code, data);
|
||||
}
|
||||
terminate() {
|
||||
this._internal.ws.terminate();
|
||||
}
|
||||
}
|
||||
class NodeReqProxy {
|
||||
_req;
|
||||
_headers;
|
||||
_url;
|
||||
constructor(req) {
|
||||
this._req = req;
|
||||
}
|
||||
get url() {
|
||||
if (!this._url) {
|
||||
const req = this._req;
|
||||
const host = req.headers["host"] || "localhost";
|
||||
const isSecure = req.socket?.encrypted ?? req.headers["x-forwarded-proto"] === "https";
|
||||
this._url = `${isSecure ? "https" : "http"}://${host}${req.url}`;
|
||||
}
|
||||
return this._url;
|
||||
}
|
||||
get headers() {
|
||||
if (!this._headers) {
|
||||
this._headers = new Headers(this._req.headers);
|
||||
}
|
||||
return this._headers;
|
||||
}
|
||||
}
|
||||
async function sendResponse(socket, res) {
|
||||
const head = [
|
||||
`HTTP/1.1 ${res.status || 200} ${res.statusText || ""}`,
|
||||
...[...res.headers.entries()].map(
|
||||
([key, value]) => `${encodeURIComponent(key)}: ${encodeURIComponent(value)}`
|
||||
)
|
||||
];
|
||||
socket.write(head.join("\r\n") + "\r\n\r\n");
|
||||
if (res.body) {
|
||||
for await (const chunk of res.body) {
|
||||
socket.write(chunk);
|
||||
}
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
socket.end(() => {
|
||||
socket.destroy();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export { nodeAdapter as default };
|
13
node_modules/crossws/dist/adapters/sse.d.mts
generated
vendored
Normal file
13
node_modules/crossws/dist/adapters/sse.d.mts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
|
||||
import '../shared/crossws.BQXMA5bH.mjs';
|
||||
|
||||
interface SSEAdapter extends AdapterInstance {
|
||||
fetch(req: Request): Promise<Response>;
|
||||
}
|
||||
interface SSEOptions extends AdapterOptions {
|
||||
bidir?: boolean;
|
||||
}
|
||||
declare const sseAdapter: Adapter<SSEAdapter, SSEOptions>;
|
||||
|
||||
export { sseAdapter as default };
|
||||
export type { SSEAdapter, SSEOptions };
|
13
node_modules/crossws/dist/adapters/sse.d.ts
generated
vendored
Normal file
13
node_modules/crossws/dist/adapters/sse.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
|
||||
import '../shared/crossws.BQXMA5bH.js';
|
||||
|
||||
interface SSEAdapter extends AdapterInstance {
|
||||
fetch(req: Request): Promise<Response>;
|
||||
}
|
||||
interface SSEOptions extends AdapterOptions {
|
||||
bidir?: boolean;
|
||||
}
|
||||
declare const sseAdapter: Adapter<SSEAdapter, SSEOptions>;
|
||||
|
||||
export { sseAdapter as default };
|
||||
export type { SSEAdapter, SSEOptions };
|
121
node_modules/crossws/dist/adapters/sse.mjs
generated
vendored
Normal file
121
node_modules/crossws/dist/adapters/sse.mjs
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
import { M as Message, P as Peer, a as toString } from '../shared/crossws.DfCzGthR.mjs';
|
||||
import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
|
||||
import 'uncrypto';
|
||||
|
||||
const sseAdapter = (opts = {}) => {
|
||||
const hooks = new AdapterHookable(opts);
|
||||
const peers = /* @__PURE__ */ new Set();
|
||||
const peersMap = opts.bidir ? /* @__PURE__ */ new Map() : void 0;
|
||||
return {
|
||||
...adapterUtils(peers),
|
||||
fetch: async (request) => {
|
||||
const { upgradeHeaders, endResponse, context } = await hooks.upgrade(request);
|
||||
if (endResponse) {
|
||||
return endResponse;
|
||||
}
|
||||
let peer;
|
||||
if (opts.bidir && request.body && request.headers.has("x-crossws-id")) {
|
||||
const id = request.headers.get("x-crossws-id");
|
||||
peer = peersMap?.get(id);
|
||||
if (!peer) {
|
||||
return new Response("invalid peer id", { status: 400 });
|
||||
}
|
||||
const stream = request.body.pipeThrough(new TextDecoderStream());
|
||||
try {
|
||||
for await (const chunk of stream) {
|
||||
hooks.callHook("message", peer, new Message(chunk, peer));
|
||||
}
|
||||
} catch {
|
||||
await stream.cancel().catch(() => {
|
||||
});
|
||||
}
|
||||
return new Response(null, {});
|
||||
} else {
|
||||
const ws = new SSEWebSocketStub();
|
||||
peer = new SSEPeer({
|
||||
peers,
|
||||
peersMap,
|
||||
request,
|
||||
hooks,
|
||||
ws,
|
||||
context
|
||||
});
|
||||
peers.add(peer);
|
||||
if (opts.bidir) {
|
||||
peersMap.set(peer.id, peer);
|
||||
peer._sendEvent("crossws-id", peer.id);
|
||||
}
|
||||
}
|
||||
let headers = {
|
||||
"Content-Type": "text/event-stream",
|
||||
"Cache-Control": "no-cache",
|
||||
Connection: "keep-alive"
|
||||
};
|
||||
if (opts.bidir) {
|
||||
headers["x-crossws-id"] = peer.id;
|
||||
}
|
||||
if (upgradeHeaders) {
|
||||
headers = new Headers(headers);
|
||||
for (const [key, value] of new Headers(upgradeHeaders)) {
|
||||
headers.set(key, value);
|
||||
}
|
||||
}
|
||||
return new Response(peer._sseStream, { headers });
|
||||
}
|
||||
};
|
||||
};
|
||||
class SSEPeer extends Peer {
|
||||
_sseStream;
|
||||
// server -> client
|
||||
_sseStreamController;
|
||||
constructor(_internal) {
|
||||
super(_internal);
|
||||
_internal.ws.readyState = 0;
|
||||
this._sseStream = new ReadableStream({
|
||||
start: (controller) => {
|
||||
_internal.ws.readyState = 1;
|
||||
this._sseStreamController = controller;
|
||||
_internal.hooks.callHook("open", this);
|
||||
},
|
||||
cancel: () => {
|
||||
_internal.ws.readyState = 2;
|
||||
_internal.peers.delete(this);
|
||||
_internal.peersMap?.delete(this.id);
|
||||
Promise.resolve(this._internal.hooks.callHook("close", this)).finally(
|
||||
() => {
|
||||
_internal.ws.readyState = 3;
|
||||
}
|
||||
);
|
||||
}
|
||||
}).pipeThrough(new TextEncoderStream());
|
||||
}
|
||||
_sendEvent(event, data) {
|
||||
const lines = data.split("\n");
|
||||
this._sseStreamController?.enqueue(
|
||||
`event: ${event}
|
||||
${lines.map((l) => `data: ${l}`)}
|
||||
|
||||
`
|
||||
);
|
||||
}
|
||||
send(data) {
|
||||
this._sendEvent("message", toString(data));
|
||||
return 0;
|
||||
}
|
||||
publish(topic, data) {
|
||||
const dataBuff = toString(data);
|
||||
for (const peer of this._internal.peers) {
|
||||
if (peer !== this && peer._topics.has(topic)) {
|
||||
peer._sendEvent("message", dataBuff);
|
||||
}
|
||||
}
|
||||
}
|
||||
close() {
|
||||
this._sseStreamController?.close();
|
||||
}
|
||||
}
|
||||
class SSEWebSocketStub {
|
||||
readyState;
|
||||
}
|
||||
|
||||
export { sseAdapter as default };
|
59
node_modules/crossws/dist/adapters/uws.d.mts
generated
vendored
Normal file
59
node_modules/crossws/dist/adapters/uws.d.mts
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Adapter, AdapterInstance, Peer, AdapterOptions } from '../index.mjs';
|
||||
import { W as WebSocket } from '../shared/crossws.BQXMA5bH.mjs';
|
||||
import uws from 'uWebSockets.js';
|
||||
|
||||
type UserData = {
|
||||
peer?: UWSPeer;
|
||||
req: uws.HttpRequest;
|
||||
res: uws.HttpResponse;
|
||||
protocol: string;
|
||||
extensions: string;
|
||||
context: Peer["context"];
|
||||
};
|
||||
type WebSocketHandler = uws.WebSocketBehavior<UserData>;
|
||||
interface UWSAdapter extends AdapterInstance {
|
||||
websocket: WebSocketHandler;
|
||||
}
|
||||
interface UWSOptions extends AdapterOptions {
|
||||
uws?: Exclude<uws.WebSocketBehavior<any>, "close" | "drain" | "message" | "open" | "ping" | "pong" | "subscription" | "upgrade">;
|
||||
}
|
||||
declare const uwsAdapter: Adapter<UWSAdapter, UWSOptions>;
|
||||
|
||||
declare class UWSPeer extends Peer<{
|
||||
peers: Set<UWSPeer>;
|
||||
request: UWSReqProxy;
|
||||
uws: uws.WebSocket<UserData>;
|
||||
ws: UwsWebSocketProxy;
|
||||
uwsData: UserData;
|
||||
}> {
|
||||
get remoteAddress(): string | undefined;
|
||||
get context(): Record<string, unknown>;
|
||||
send(data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): number;
|
||||
subscribe(topic: string): void;
|
||||
unsubscribe(topic: string): void;
|
||||
publish(topic: string, message: string, options?: {
|
||||
compress?: boolean;
|
||||
}): number;
|
||||
close(code?: number, reason?: uws.RecognizedString): void;
|
||||
terminate(): void;
|
||||
}
|
||||
declare class UWSReqProxy {
|
||||
private _headers?;
|
||||
private _rawHeaders;
|
||||
url: string;
|
||||
constructor(_req: uws.HttpRequest);
|
||||
get headers(): Headers;
|
||||
}
|
||||
declare class UwsWebSocketProxy implements Partial<WebSocket> {
|
||||
private _uws;
|
||||
readyState?: number;
|
||||
constructor(_uws: uws.WebSocket<UserData>);
|
||||
get bufferedAmount(): number;
|
||||
get protocol(): string;
|
||||
get extensions(): string;
|
||||
}
|
||||
|
||||
export { uwsAdapter as default };
|
||||
export type { UWSAdapter, UWSOptions };
|
59
node_modules/crossws/dist/adapters/uws.d.ts
generated
vendored
Normal file
59
node_modules/crossws/dist/adapters/uws.d.ts
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Adapter, AdapterInstance, Peer, AdapterOptions } from '../index.js';
|
||||
import { W as WebSocket } from '../shared/crossws.BQXMA5bH.js';
|
||||
import uws from 'uWebSockets.js';
|
||||
|
||||
type UserData = {
|
||||
peer?: UWSPeer;
|
||||
req: uws.HttpRequest;
|
||||
res: uws.HttpResponse;
|
||||
protocol: string;
|
||||
extensions: string;
|
||||
context: Peer["context"];
|
||||
};
|
||||
type WebSocketHandler = uws.WebSocketBehavior<UserData>;
|
||||
interface UWSAdapter extends AdapterInstance {
|
||||
websocket: WebSocketHandler;
|
||||
}
|
||||
interface UWSOptions extends AdapterOptions {
|
||||
uws?: Exclude<uws.WebSocketBehavior<any>, "close" | "drain" | "message" | "open" | "ping" | "pong" | "subscription" | "upgrade">;
|
||||
}
|
||||
declare const uwsAdapter: Adapter<UWSAdapter, UWSOptions>;
|
||||
|
||||
declare class UWSPeer extends Peer<{
|
||||
peers: Set<UWSPeer>;
|
||||
request: UWSReqProxy;
|
||||
uws: uws.WebSocket<UserData>;
|
||||
ws: UwsWebSocketProxy;
|
||||
uwsData: UserData;
|
||||
}> {
|
||||
get remoteAddress(): string | undefined;
|
||||
get context(): Record<string, unknown>;
|
||||
send(data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): number;
|
||||
subscribe(topic: string): void;
|
||||
unsubscribe(topic: string): void;
|
||||
publish(topic: string, message: string, options?: {
|
||||
compress?: boolean;
|
||||
}): number;
|
||||
close(code?: number, reason?: uws.RecognizedString): void;
|
||||
terminate(): void;
|
||||
}
|
||||
declare class UWSReqProxy {
|
||||
private _headers?;
|
||||
private _rawHeaders;
|
||||
url: string;
|
||||
constructor(_req: uws.HttpRequest);
|
||||
get headers(): Headers;
|
||||
}
|
||||
declare class UwsWebSocketProxy implements Partial<WebSocket> {
|
||||
private _uws;
|
||||
readyState?: number;
|
||||
constructor(_uws: uws.WebSocket<UserData>);
|
||||
get bufferedAmount(): number;
|
||||
get protocol(): string;
|
||||
get extensions(): string;
|
||||
}
|
||||
|
||||
export { uwsAdapter as default };
|
||||
export type { UWSAdapter, UWSOptions };
|
183
node_modules/crossws/dist/adapters/uws.mjs
generated
vendored
Normal file
183
node_modules/crossws/dist/adapters/uws.mjs
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
|
||||
import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
|
||||
import 'uncrypto';
|
||||
|
||||
const uwsAdapter = (options = {}) => {
|
||||
const hooks = new AdapterHookable(options);
|
||||
const peers = /* @__PURE__ */ new Set();
|
||||
return {
|
||||
...adapterUtils(peers),
|
||||
websocket: {
|
||||
...options.uws,
|
||||
close(ws, code, message) {
|
||||
const peer = getPeer(ws, peers);
|
||||
peer._internal.ws.readyState = 2;
|
||||
peers.delete(peer);
|
||||
hooks.callHook("close", peer, {
|
||||
code,
|
||||
reason: message?.toString()
|
||||
});
|
||||
peer._internal.ws.readyState = 3;
|
||||
},
|
||||
message(ws, message, isBinary) {
|
||||
const peer = getPeer(ws, peers);
|
||||
hooks.callHook("message", peer, new Message(message, peer));
|
||||
},
|
||||
open(ws) {
|
||||
const peer = getPeer(ws, peers);
|
||||
peers.add(peer);
|
||||
hooks.callHook("open", peer);
|
||||
},
|
||||
async upgrade(res, req, uwsContext) {
|
||||
let aborted = false;
|
||||
res.onAborted(() => {
|
||||
aborted = true;
|
||||
});
|
||||
const { upgradeHeaders, endResponse, context } = await hooks.upgrade(
|
||||
new UWSReqProxy(req)
|
||||
);
|
||||
if (endResponse) {
|
||||
res.writeStatus(`${endResponse.status} ${endResponse.statusText}`);
|
||||
for (const [key, value] of endResponse.headers) {
|
||||
res.writeHeader(key, value);
|
||||
}
|
||||
if (endResponse.body) {
|
||||
for await (const chunk of endResponse.body) {
|
||||
if (aborted) break;
|
||||
res.write(chunk);
|
||||
}
|
||||
}
|
||||
if (!aborted) {
|
||||
res.end();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (aborted) {
|
||||
return;
|
||||
}
|
||||
res.writeStatus("101 Switching Protocols");
|
||||
if (upgradeHeaders) {
|
||||
const headers = upgradeHeaders instanceof Headers ? upgradeHeaders : new Headers(upgradeHeaders);
|
||||
for (const [key, value] of headers) {
|
||||
res.writeHeader(key, value);
|
||||
}
|
||||
}
|
||||
res.cork(() => {
|
||||
const key = req.getHeader("sec-websocket-key");
|
||||
const protocol = req.getHeader("sec-websocket-protocol");
|
||||
const extensions = req.getHeader("sec-websocket-extensions");
|
||||
res.upgrade(
|
||||
{
|
||||
req,
|
||||
res,
|
||||
protocol,
|
||||
extensions,
|
||||
context
|
||||
},
|
||||
key,
|
||||
protocol,
|
||||
extensions,
|
||||
uwsContext
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
function getPeer(uws, peers) {
|
||||
const uwsData = uws.getUserData();
|
||||
if (uwsData.peer) {
|
||||
return uwsData.peer;
|
||||
}
|
||||
const peer = new UWSPeer({
|
||||
peers,
|
||||
uws,
|
||||
ws: new UwsWebSocketProxy(uws),
|
||||
request: new UWSReqProxy(uwsData.req),
|
||||
uwsData
|
||||
});
|
||||
uwsData.peer = peer;
|
||||
return peer;
|
||||
}
|
||||
class UWSPeer extends Peer {
|
||||
get remoteAddress() {
|
||||
try {
|
||||
const addr = new TextDecoder().decode(
|
||||
this._internal.uws.getRemoteAddressAsText()
|
||||
);
|
||||
return addr;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
get context() {
|
||||
return this._internal.uwsData.context;
|
||||
}
|
||||
send(data, options) {
|
||||
const dataBuff = toBufferLike(data);
|
||||
const isBinary = typeof dataBuff !== "string";
|
||||
return this._internal.uws.send(dataBuff, isBinary, options?.compress);
|
||||
}
|
||||
subscribe(topic) {
|
||||
this._topics.add(topic);
|
||||
this._internal.uws.subscribe(topic);
|
||||
}
|
||||
unsubscribe(topic) {
|
||||
this._topics.delete(topic);
|
||||
this._internal.uws.unsubscribe(topic);
|
||||
}
|
||||
publish(topic, message, options) {
|
||||
const data = toBufferLike(message);
|
||||
const isBinary = typeof data !== "string";
|
||||
this._internal.uws.publish(topic, data, isBinary, options?.compress);
|
||||
return 0;
|
||||
}
|
||||
close(code, reason) {
|
||||
this._internal.uws.end(code, reason);
|
||||
}
|
||||
terminate() {
|
||||
this._internal.uws.close();
|
||||
}
|
||||
}
|
||||
class UWSReqProxy {
|
||||
_headers;
|
||||
_rawHeaders = [];
|
||||
url;
|
||||
constructor(_req) {
|
||||
let host = "localhost";
|
||||
let proto = "http";
|
||||
_req.forEach((key, value) => {
|
||||
if (key === "host") {
|
||||
host = value;
|
||||
} else if (key === "x-forwarded-proto" && value === "https") {
|
||||
proto = "https";
|
||||
}
|
||||
this._rawHeaders.push([key, value]);
|
||||
});
|
||||
const query = _req.getQuery();
|
||||
const pathname = _req.getUrl();
|
||||
this.url = `${proto}://${host}${pathname}${query ? `?${query}` : ""}`;
|
||||
}
|
||||
get headers() {
|
||||
if (!this._headers) {
|
||||
this._headers = new Headers(this._rawHeaders);
|
||||
}
|
||||
return this._headers;
|
||||
}
|
||||
}
|
||||
class UwsWebSocketProxy {
|
||||
constructor(_uws) {
|
||||
this._uws = _uws;
|
||||
}
|
||||
readyState = 1;
|
||||
get bufferedAmount() {
|
||||
return this._uws?.getBufferedAmount();
|
||||
}
|
||||
get protocol() {
|
||||
return this._uws?.getUserData().protocol;
|
||||
}
|
||||
get extensions() {
|
||||
return this._uws?.getUserData().extensions;
|
||||
}
|
||||
}
|
||||
|
||||
export { uwsAdapter as default };
|
157
node_modules/crossws/dist/index.d.mts
generated
vendored
Normal file
157
node_modules/crossws/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
import { W as WebSocket } from './shared/crossws.BQXMA5bH.mjs';
|
||||
|
||||
declare const kNodeInspect: unique symbol;
|
||||
|
||||
interface AdapterInternal {
|
||||
ws: unknown;
|
||||
request: UpgradeRequest;
|
||||
peers?: Set<Peer>;
|
||||
context?: Peer["context"];
|
||||
}
|
||||
declare abstract class Peer<Internal extends AdapterInternal = AdapterInternal> {
|
||||
#private;
|
||||
protected _internal: Internal;
|
||||
protected _topics: Set<string>;
|
||||
protected _id?: string;
|
||||
constructor(internal: Internal);
|
||||
get context(): Record<string, unknown>;
|
||||
/**
|
||||
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the peer.
|
||||
*/
|
||||
get id(): string;
|
||||
/** IP address of the peer */
|
||||
get remoteAddress(): string | undefined;
|
||||
/** upgrade request */
|
||||
get request(): UpgradeRequest;
|
||||
/**
|
||||
* Get the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance.
|
||||
*
|
||||
* **Note:** crossws adds polyfill for the following properties if native values are not available:
|
||||
* - `protocol`: Extracted from the `sec-websocket-protocol` header.
|
||||
* - `extensions`: Extracted from the `sec-websocket-extensions` header.
|
||||
* - `url`: Extracted from the request URL (http -> ws).
|
||||
* */
|
||||
get websocket(): Partial<WebSocket>;
|
||||
/** All connected peers to the server */
|
||||
get peers(): Set<Peer>;
|
||||
/** All topics, this peer has been subscribed to. */
|
||||
get topics(): Set<string>;
|
||||
abstract close(code?: number, reason?: string): void;
|
||||
/** Abruptly close the connection */
|
||||
terminate(): void;
|
||||
/** Subscribe to a topic */
|
||||
subscribe(topic: string): void;
|
||||
/** Unsubscribe from a topic */
|
||||
unsubscribe(topic: string): void;
|
||||
/** Send a message to the peer. */
|
||||
abstract send(data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): number | void | undefined;
|
||||
/** Send message to subscribes of topic */
|
||||
abstract publish(topic: string, data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): void;
|
||||
toString(): string;
|
||||
[Symbol.toPrimitive](): string;
|
||||
[Symbol.toStringTag](): "WebSocket";
|
||||
[kNodeInspect](): Record<string, unknown>;
|
||||
}
|
||||
|
||||
interface AdapterInstance {
|
||||
readonly peers: Set<Peer>;
|
||||
readonly publish: Peer["publish"];
|
||||
}
|
||||
interface AdapterOptions {
|
||||
resolve?: ResolveHooks;
|
||||
hooks?: Partial<Hooks>;
|
||||
}
|
||||
type Adapter<AdapterT extends AdapterInstance = AdapterInstance, Options extends AdapterOptions = AdapterOptions> = (options?: Options) => AdapterT;
|
||||
declare function defineWebSocketAdapter<AdapterT extends AdapterInstance = AdapterInstance, Options extends AdapterOptions = AdapterOptions>(factory: Adapter<AdapterT, Options>): Adapter<AdapterT, Options>;
|
||||
|
||||
declare class WSError extends Error {
|
||||
constructor(...args: any[]);
|
||||
}
|
||||
|
||||
declare class Message implements Partial<MessageEvent> {
|
||||
#private;
|
||||
/** Access to the original [message event](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event) if available. */
|
||||
readonly event?: MessageEvent;
|
||||
/** Access to the Peer that emitted the message. */
|
||||
readonly peer?: Peer;
|
||||
/** Raw message data (can be of any type). */
|
||||
readonly rawData: unknown;
|
||||
constructor(rawData: unknown, peer: Peer, event?: MessageEvent);
|
||||
/**
|
||||
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the message.
|
||||
*/
|
||||
get id(): string;
|
||||
/**
|
||||
* Get data as [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
||||
*/
|
||||
uint8Array(): Uint8Array;
|
||||
/**
|
||||
* Get data as [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
||||
*/
|
||||
arrayBuffer(): ArrayBuffer | SharedArrayBuffer;
|
||||
/**
|
||||
* Get data as [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded. */
|
||||
blob(): Blob;
|
||||
/**
|
||||
* Get stringified text version of the message.
|
||||
*
|
||||
* If raw data is in any other format, it will be automatically converted and decoded.
|
||||
*/
|
||||
text(): string;
|
||||
/**
|
||||
* Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
|
||||
*/
|
||||
json<T = unknown>(): T;
|
||||
/**
|
||||
* Message data (value varies based on `peer.websocket.binaryType`).
|
||||
*/
|
||||
get data(): unknown;
|
||||
toString(): string;
|
||||
[Symbol.toPrimitive](): string;
|
||||
[kNodeInspect](): {
|
||||
data: unknown;
|
||||
};
|
||||
}
|
||||
|
||||
declare function defineHooks<T extends Partial<Hooks> = Partial<Hooks>>(hooks: T): T;
|
||||
type ResolveHooks = (info: RequestInit | Peer) => Partial<Hooks> | Promise<Partial<Hooks>>;
|
||||
type MaybePromise<T> = T | Promise<T>;
|
||||
type UpgradeRequest = Request | {
|
||||
url: string;
|
||||
headers: Headers;
|
||||
};
|
||||
interface Hooks {
|
||||
/** Upgrading */
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
* @throws {Response}
|
||||
*/
|
||||
upgrade: (request: UpgradeRequest & {
|
||||
context: Peer["context"];
|
||||
}) => MaybePromise<Response | ResponseInit | void>;
|
||||
/** A message is received */
|
||||
message: (peer: Peer, message: Message) => MaybePromise<void>;
|
||||
/** A socket is opened */
|
||||
open: (peer: Peer) => MaybePromise<void>;
|
||||
/** A socket is closed */
|
||||
close: (peer: Peer, details: {
|
||||
code?: number;
|
||||
reason?: string;
|
||||
}) => MaybePromise<void>;
|
||||
/** An error occurs */
|
||||
error: (peer: Peer, error: WSError) => MaybePromise<void>;
|
||||
}
|
||||
|
||||
export { Message, Peer, WSError, defineHooks, defineWebSocketAdapter };
|
||||
export type { Adapter, AdapterInstance, AdapterInternal, AdapterOptions, Hooks, ResolveHooks };
|
157
node_modules/crossws/dist/index.d.ts
generated
vendored
Normal file
157
node_modules/crossws/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
import { W as WebSocket } from './shared/crossws.BQXMA5bH.js';
|
||||
|
||||
declare const kNodeInspect: unique symbol;
|
||||
|
||||
interface AdapterInternal {
|
||||
ws: unknown;
|
||||
request: UpgradeRequest;
|
||||
peers?: Set<Peer>;
|
||||
context?: Peer["context"];
|
||||
}
|
||||
declare abstract class Peer<Internal extends AdapterInternal = AdapterInternal> {
|
||||
#private;
|
||||
protected _internal: Internal;
|
||||
protected _topics: Set<string>;
|
||||
protected _id?: string;
|
||||
constructor(internal: Internal);
|
||||
get context(): Record<string, unknown>;
|
||||
/**
|
||||
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the peer.
|
||||
*/
|
||||
get id(): string;
|
||||
/** IP address of the peer */
|
||||
get remoteAddress(): string | undefined;
|
||||
/** upgrade request */
|
||||
get request(): UpgradeRequest;
|
||||
/**
|
||||
* Get the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance.
|
||||
*
|
||||
* **Note:** crossws adds polyfill for the following properties if native values are not available:
|
||||
* - `protocol`: Extracted from the `sec-websocket-protocol` header.
|
||||
* - `extensions`: Extracted from the `sec-websocket-extensions` header.
|
||||
* - `url`: Extracted from the request URL (http -> ws).
|
||||
* */
|
||||
get websocket(): Partial<WebSocket>;
|
||||
/** All connected peers to the server */
|
||||
get peers(): Set<Peer>;
|
||||
/** All topics, this peer has been subscribed to. */
|
||||
get topics(): Set<string>;
|
||||
abstract close(code?: number, reason?: string): void;
|
||||
/** Abruptly close the connection */
|
||||
terminate(): void;
|
||||
/** Subscribe to a topic */
|
||||
subscribe(topic: string): void;
|
||||
/** Unsubscribe from a topic */
|
||||
unsubscribe(topic: string): void;
|
||||
/** Send a message to the peer. */
|
||||
abstract send(data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): number | void | undefined;
|
||||
/** Send message to subscribes of topic */
|
||||
abstract publish(topic: string, data: unknown, options?: {
|
||||
compress?: boolean;
|
||||
}): void;
|
||||
toString(): string;
|
||||
[Symbol.toPrimitive](): string;
|
||||
[Symbol.toStringTag](): "WebSocket";
|
||||
[kNodeInspect](): Record<string, unknown>;
|
||||
}
|
||||
|
||||
interface AdapterInstance {
|
||||
readonly peers: Set<Peer>;
|
||||
readonly publish: Peer["publish"];
|
||||
}
|
||||
interface AdapterOptions {
|
||||
resolve?: ResolveHooks;
|
||||
hooks?: Partial<Hooks>;
|
||||
}
|
||||
type Adapter<AdapterT extends AdapterInstance = AdapterInstance, Options extends AdapterOptions = AdapterOptions> = (options?: Options) => AdapterT;
|
||||
declare function defineWebSocketAdapter<AdapterT extends AdapterInstance = AdapterInstance, Options extends AdapterOptions = AdapterOptions>(factory: Adapter<AdapterT, Options>): Adapter<AdapterT, Options>;
|
||||
|
||||
declare class WSError extends Error {
|
||||
constructor(...args: any[]);
|
||||
}
|
||||
|
||||
declare class Message implements Partial<MessageEvent> {
|
||||
#private;
|
||||
/** Access to the original [message event](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event) if available. */
|
||||
readonly event?: MessageEvent;
|
||||
/** Access to the Peer that emitted the message. */
|
||||
readonly peer?: Peer;
|
||||
/** Raw message data (can be of any type). */
|
||||
readonly rawData: unknown;
|
||||
constructor(rawData: unknown, peer: Peer, event?: MessageEvent);
|
||||
/**
|
||||
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the message.
|
||||
*/
|
||||
get id(): string;
|
||||
/**
|
||||
* Get data as [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
||||
*/
|
||||
uint8Array(): Uint8Array;
|
||||
/**
|
||||
* Get data as [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
||||
*/
|
||||
arrayBuffer(): ArrayBuffer | SharedArrayBuffer;
|
||||
/**
|
||||
* Get data as [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded. */
|
||||
blob(): Blob;
|
||||
/**
|
||||
* Get stringified text version of the message.
|
||||
*
|
||||
* If raw data is in any other format, it will be automatically converted and decoded.
|
||||
*/
|
||||
text(): string;
|
||||
/**
|
||||
* Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
|
||||
*/
|
||||
json<T = unknown>(): T;
|
||||
/**
|
||||
* Message data (value varies based on `peer.websocket.binaryType`).
|
||||
*/
|
||||
get data(): unknown;
|
||||
toString(): string;
|
||||
[Symbol.toPrimitive](): string;
|
||||
[kNodeInspect](): {
|
||||
data: unknown;
|
||||
};
|
||||
}
|
||||
|
||||
declare function defineHooks<T extends Partial<Hooks> = Partial<Hooks>>(hooks: T): T;
|
||||
type ResolveHooks = (info: RequestInit | Peer) => Partial<Hooks> | Promise<Partial<Hooks>>;
|
||||
type MaybePromise<T> = T | Promise<T>;
|
||||
type UpgradeRequest = Request | {
|
||||
url: string;
|
||||
headers: Headers;
|
||||
};
|
||||
interface Hooks {
|
||||
/** Upgrading */
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
* @throws {Response}
|
||||
*/
|
||||
upgrade: (request: UpgradeRequest & {
|
||||
context: Peer["context"];
|
||||
}) => MaybePromise<Response | ResponseInit | void>;
|
||||
/** A message is received */
|
||||
message: (peer: Peer, message: Message) => MaybePromise<void>;
|
||||
/** A socket is opened */
|
||||
open: (peer: Peer) => MaybePromise<void>;
|
||||
/** A socket is closed */
|
||||
close: (peer: Peer, details: {
|
||||
code?: number;
|
||||
reason?: string;
|
||||
}) => MaybePromise<void>;
|
||||
/** An error occurs */
|
||||
error: (peer: Peer, error: WSError) => MaybePromise<void>;
|
||||
}
|
||||
|
||||
export { Message, Peer, WSError, defineHooks, defineWebSocketAdapter };
|
||||
export type { Adapter, AdapterInstance, AdapterInternal, AdapterOptions, Hooks, ResolveHooks };
|
1
node_modules/crossws/dist/index.mjs
generated
vendored
Normal file
1
node_modules/crossws/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export { d as defineHooks, b as defineWebSocketAdapter } from './shared/crossws.D9ehKjSh.mjs';
|
297
node_modules/crossws/dist/shared/crossws.BQXMA5bH.d.mts
generated
vendored
Normal file
297
node_modules/crossws/dist/shared/crossws.BQXMA5bH.d.mts
generated
vendored
Normal file
@@ -0,0 +1,297 @@
|
||||
/**
|
||||
* A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent)
|
||||
*/
|
||||
interface CloseEvent extends Event {
|
||||
/**
|
||||
* Returns the WebSocket connection close code provided by the server.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/code)
|
||||
*/
|
||||
readonly code: number;
|
||||
/**
|
||||
* Returns the WebSocket connection close reason provided by the server.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/reason)
|
||||
*/
|
||||
readonly reason: string;
|
||||
/**
|
||||
* Returns true if the connection closed cleanly; false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/wasClean)
|
||||
*/
|
||||
readonly wasClean: boolean;
|
||||
}
|
||||
/**
|
||||
* An event which takes place in the DOM.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event)
|
||||
*/
|
||||
interface Event {
|
||||
/**
|
||||
* Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/bubbles)
|
||||
*/
|
||||
readonly bubbles: boolean;
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble)
|
||||
*/
|
||||
cancelBubble: boolean;
|
||||
/**
|
||||
* Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelable)
|
||||
*/
|
||||
readonly cancelable: boolean;
|
||||
/**
|
||||
* Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composed)
|
||||
*/
|
||||
readonly composed: boolean;
|
||||
/**
|
||||
* Returns the object whose event listener's callback is currently being invoked.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget)
|
||||
*/
|
||||
readonly currentTarget: EventTarget | null;
|
||||
/**
|
||||
* Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented)
|
||||
*/
|
||||
readonly defaultPrevented: boolean;
|
||||
/**
|
||||
* Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/eventPhase)
|
||||
*/
|
||||
readonly eventPhase: number;
|
||||
/**
|
||||
* Returns true if event was dispatched by the user agent, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/isTrusted)
|
||||
*/
|
||||
readonly isTrusted: boolean;
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/returnValue)
|
||||
*/
|
||||
returnValue: boolean;
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/srcElement)
|
||||
*/
|
||||
readonly srcElement: EventTarget | null;
|
||||
/**
|
||||
* Returns the object to which event is dispatched (its target).
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target)
|
||||
*/
|
||||
readonly target: EventTarget | null;
|
||||
/**
|
||||
* Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/timeStamp)
|
||||
*/
|
||||
readonly timeStamp: DOMHighResTimeStamp;
|
||||
/**
|
||||
* Returns the type of event, e.g. "click", "hashchange", or "submit".
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/type)
|
||||
*/
|
||||
readonly type: string;
|
||||
/**
|
||||
* Returns the invocation target objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composedPath)
|
||||
*/
|
||||
composedPath(): EventTarget[];
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/initEvent)
|
||||
*/
|
||||
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
|
||||
/**
|
||||
* If invoked when the cancelable attribute value is true, and while executing a listener for the event with passive set to false, signals to the operation that caused event to be dispatched that it needs to be canceled.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/preventDefault)
|
||||
*/
|
||||
preventDefault(): void;
|
||||
/**
|
||||
* Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopImmediatePropagation)
|
||||
*/
|
||||
stopImmediatePropagation(): void;
|
||||
/**
|
||||
* When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation)
|
||||
*/
|
||||
stopPropagation(): void;
|
||||
readonly NONE: 0;
|
||||
readonly CAPTURING_PHASE: 1;
|
||||
readonly AT_TARGET: 2;
|
||||
readonly BUBBLING_PHASE: 3;
|
||||
}
|
||||
/**
|
||||
* EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget)
|
||||
*/
|
||||
interface EventTarget {
|
||||
/**
|
||||
* Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
|
||||
*
|
||||
* The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
|
||||
*
|
||||
* When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
|
||||
*
|
||||
* When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
|
||||
*
|
||||
* When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
|
||||
*
|
||||
* If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
|
||||
*
|
||||
* The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
|
||||
*/
|
||||
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
|
||||
/**
|
||||
* Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
|
||||
*/
|
||||
dispatchEvent(event: Event): boolean;
|
||||
/**
|
||||
* Removes the event listener in target's event listener list with the same type, callback, and options.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
|
||||
*/
|
||||
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
||||
}
|
||||
/**
|
||||
* A message received by a target object.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent)
|
||||
*/
|
||||
interface MessageEvent<T = any> extends Event {
|
||||
/**
|
||||
* Returns the data of the message.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/data)
|
||||
*/
|
||||
readonly data: T;
|
||||
/**
|
||||
* Returns the last event ID string, for server-sent events.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/lastEventId)
|
||||
*/
|
||||
readonly lastEventId: string;
|
||||
/**
|
||||
* Returns the origin of the message, for server-sent events and cross-document messaging.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/origin)
|
||||
*/
|
||||
readonly origin: string;
|
||||
/**
|
||||
* Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/ports)
|
||||
*/
|
||||
readonly ports: ReadonlyArray<MessagePort>;
|
||||
/**
|
||||
* Returns the WindowProxy of the source window, for cross-document messaging, and the MessagePort being attached, in the connect event fired at SharedWorkerGlobalScope objects.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/source)
|
||||
*/
|
||||
readonly source: MessageEventSource | null;
|
||||
/** @deprecated */
|
||||
initMessageEvent(type: string, bubbles?: boolean, cancelable?: boolean, data?: any, origin?: string, lastEventId?: string, source?: MessageEventSource | null, ports?: MessagePort[]): void;
|
||||
}
|
||||
/**
|
||||
* Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
|
||||
*/
|
||||
interface WebSocket extends EventTarget {
|
||||
/**
|
||||
* Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
|
||||
*
|
||||
* Can be set, to change how binary data is returned. The default is "blob".
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType)
|
||||
*/
|
||||
binaryType: BinaryType | (string & {});
|
||||
/**
|
||||
* Returns the number of bytes of application data (UTF-8 text and binary data) that have been queued using send() but not yet been transmitted to the network.
|
||||
*
|
||||
* If the WebSocket connection is closed, this attribute's value will only increase with each call to the send() method. (The number does not reset to zero once the connection closes.)
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/bufferedAmount)
|
||||
*/
|
||||
readonly bufferedAmount: number;
|
||||
/**
|
||||
* Returns the extensions selected by the server, if any.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
|
||||
*/
|
||||
readonly extensions: string;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close_event) */
|
||||
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/error_event) */
|
||||
onerror: ((this: WebSocket, ev: Event) => any) | null;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/message_event) */
|
||||
onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/open_event) */
|
||||
onopen: ((this: WebSocket, ev: Event) => any) | null;
|
||||
/**
|
||||
* Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
|
||||
*/
|
||||
readonly protocol: string;
|
||||
/**
|
||||
* Returns the state of the WebSocket object's connection. It can have the values described below.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
|
||||
*/
|
||||
readonly readyState: number;
|
||||
/**
|
||||
* Returns the URL that was used to establish the WebSocket connection.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
|
||||
*/
|
||||
readonly url: string;
|
||||
/**
|
||||
* Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
|
||||
*/
|
||||
close(code?: number, reason?: string): void;
|
||||
/**
|
||||
* Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
|
||||
*/
|
||||
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
||||
readonly CONNECTING: 0;
|
||||
readonly OPEN: 1;
|
||||
readonly CLOSING: 2;
|
||||
readonly CLOSED: 3;
|
||||
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
||||
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
||||
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
||||
}
|
||||
|
||||
export type { CloseEvent as C, EventTarget as E, MessageEvent as M, WebSocket as W, Event as a };
|
297
node_modules/crossws/dist/shared/crossws.BQXMA5bH.d.ts
generated
vendored
Normal file
297
node_modules/crossws/dist/shared/crossws.BQXMA5bH.d.ts
generated
vendored
Normal file
@@ -0,0 +1,297 @@
|
||||
/**
|
||||
* A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent)
|
||||
*/
|
||||
interface CloseEvent extends Event {
|
||||
/**
|
||||
* Returns the WebSocket connection close code provided by the server.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/code)
|
||||
*/
|
||||
readonly code: number;
|
||||
/**
|
||||
* Returns the WebSocket connection close reason provided by the server.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/reason)
|
||||
*/
|
||||
readonly reason: string;
|
||||
/**
|
||||
* Returns true if the connection closed cleanly; false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/wasClean)
|
||||
*/
|
||||
readonly wasClean: boolean;
|
||||
}
|
||||
/**
|
||||
* An event which takes place in the DOM.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event)
|
||||
*/
|
||||
interface Event {
|
||||
/**
|
||||
* Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/bubbles)
|
||||
*/
|
||||
readonly bubbles: boolean;
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble)
|
||||
*/
|
||||
cancelBubble: boolean;
|
||||
/**
|
||||
* Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelable)
|
||||
*/
|
||||
readonly cancelable: boolean;
|
||||
/**
|
||||
* Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composed)
|
||||
*/
|
||||
readonly composed: boolean;
|
||||
/**
|
||||
* Returns the object whose event listener's callback is currently being invoked.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget)
|
||||
*/
|
||||
readonly currentTarget: EventTarget | null;
|
||||
/**
|
||||
* Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented)
|
||||
*/
|
||||
readonly defaultPrevented: boolean;
|
||||
/**
|
||||
* Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/eventPhase)
|
||||
*/
|
||||
readonly eventPhase: number;
|
||||
/**
|
||||
* Returns true if event was dispatched by the user agent, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/isTrusted)
|
||||
*/
|
||||
readonly isTrusted: boolean;
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/returnValue)
|
||||
*/
|
||||
returnValue: boolean;
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/srcElement)
|
||||
*/
|
||||
readonly srcElement: EventTarget | null;
|
||||
/**
|
||||
* Returns the object to which event is dispatched (its target).
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target)
|
||||
*/
|
||||
readonly target: EventTarget | null;
|
||||
/**
|
||||
* Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/timeStamp)
|
||||
*/
|
||||
readonly timeStamp: DOMHighResTimeStamp;
|
||||
/**
|
||||
* Returns the type of event, e.g. "click", "hashchange", or "submit".
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/type)
|
||||
*/
|
||||
readonly type: string;
|
||||
/**
|
||||
* Returns the invocation target objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composedPath)
|
||||
*/
|
||||
composedPath(): EventTarget[];
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/initEvent)
|
||||
*/
|
||||
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
|
||||
/**
|
||||
* If invoked when the cancelable attribute value is true, and while executing a listener for the event with passive set to false, signals to the operation that caused event to be dispatched that it needs to be canceled.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/preventDefault)
|
||||
*/
|
||||
preventDefault(): void;
|
||||
/**
|
||||
* Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopImmediatePropagation)
|
||||
*/
|
||||
stopImmediatePropagation(): void;
|
||||
/**
|
||||
* When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation)
|
||||
*/
|
||||
stopPropagation(): void;
|
||||
readonly NONE: 0;
|
||||
readonly CAPTURING_PHASE: 1;
|
||||
readonly AT_TARGET: 2;
|
||||
readonly BUBBLING_PHASE: 3;
|
||||
}
|
||||
/**
|
||||
* EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget)
|
||||
*/
|
||||
interface EventTarget {
|
||||
/**
|
||||
* Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
|
||||
*
|
||||
* The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
|
||||
*
|
||||
* When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
|
||||
*
|
||||
* When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
|
||||
*
|
||||
* When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
|
||||
*
|
||||
* If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
|
||||
*
|
||||
* The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
|
||||
*/
|
||||
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
|
||||
/**
|
||||
* Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
|
||||
*/
|
||||
dispatchEvent(event: Event): boolean;
|
||||
/**
|
||||
* Removes the event listener in target's event listener list with the same type, callback, and options.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
|
||||
*/
|
||||
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
||||
}
|
||||
/**
|
||||
* A message received by a target object.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent)
|
||||
*/
|
||||
interface MessageEvent<T = any> extends Event {
|
||||
/**
|
||||
* Returns the data of the message.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/data)
|
||||
*/
|
||||
readonly data: T;
|
||||
/**
|
||||
* Returns the last event ID string, for server-sent events.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/lastEventId)
|
||||
*/
|
||||
readonly lastEventId: string;
|
||||
/**
|
||||
* Returns the origin of the message, for server-sent events and cross-document messaging.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/origin)
|
||||
*/
|
||||
readonly origin: string;
|
||||
/**
|
||||
* Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/ports)
|
||||
*/
|
||||
readonly ports: ReadonlyArray<MessagePort>;
|
||||
/**
|
||||
* Returns the WindowProxy of the source window, for cross-document messaging, and the MessagePort being attached, in the connect event fired at SharedWorkerGlobalScope objects.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/source)
|
||||
*/
|
||||
readonly source: MessageEventSource | null;
|
||||
/** @deprecated */
|
||||
initMessageEvent(type: string, bubbles?: boolean, cancelable?: boolean, data?: any, origin?: string, lastEventId?: string, source?: MessageEventSource | null, ports?: MessagePort[]): void;
|
||||
}
|
||||
/**
|
||||
* Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket)
|
||||
*/
|
||||
interface WebSocket extends EventTarget {
|
||||
/**
|
||||
* Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
|
||||
*
|
||||
* Can be set, to change how binary data is returned. The default is "blob".
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType)
|
||||
*/
|
||||
binaryType: BinaryType | (string & {});
|
||||
/**
|
||||
* Returns the number of bytes of application data (UTF-8 text and binary data) that have been queued using send() but not yet been transmitted to the network.
|
||||
*
|
||||
* If the WebSocket connection is closed, this attribute's value will only increase with each call to the send() method. (The number does not reset to zero once the connection closes.)
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/bufferedAmount)
|
||||
*/
|
||||
readonly bufferedAmount: number;
|
||||
/**
|
||||
* Returns the extensions selected by the server, if any.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
|
||||
*/
|
||||
readonly extensions: string;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close_event) */
|
||||
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/error_event) */
|
||||
onerror: ((this: WebSocket, ev: Event) => any) | null;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/message_event) */
|
||||
onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/open_event) */
|
||||
onopen: ((this: WebSocket, ev: Event) => any) | null;
|
||||
/**
|
||||
* Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
|
||||
*/
|
||||
readonly protocol: string;
|
||||
/**
|
||||
* Returns the state of the WebSocket object's connection. It can have the values described below.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
|
||||
*/
|
||||
readonly readyState: number;
|
||||
/**
|
||||
* Returns the URL that was used to establish the WebSocket connection.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
|
||||
*/
|
||||
readonly url: string;
|
||||
/**
|
||||
* Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
|
||||
*/
|
||||
close(code?: number, reason?: string): void;
|
||||
/**
|
||||
* Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
|
||||
*
|
||||
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
|
||||
*/
|
||||
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
||||
readonly CONNECTING: 0;
|
||||
readonly OPEN: 1;
|
||||
readonly CLOSING: 2;
|
||||
readonly CLOSED: 3;
|
||||
addEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
||||
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
||||
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
||||
}
|
||||
|
||||
export type { CloseEvent as C, EventTarget as E, MessageEvent as M, WebSocket as W, Event as a };
|
8
node_modules/crossws/dist/shared/crossws.By9qWDAI.mjs
generated
vendored
Normal file
8
node_modules/crossws/dist/shared/crossws.By9qWDAI.mjs
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
class WSError extends Error {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.name = "WSError";
|
||||
}
|
||||
}
|
||||
|
||||
export { WSError as W };
|
4973
node_modules/crossws/dist/shared/crossws.CipVM6lf.mjs
generated
vendored
Normal file
4973
node_modules/crossws/dist/shared/crossws.CipVM6lf.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
86
node_modules/crossws/dist/shared/crossws.D9ehKjSh.mjs
generated
vendored
Normal file
86
node_modules/crossws/dist/shared/crossws.D9ehKjSh.mjs
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
class AdapterHookable {
|
||||
options;
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
}
|
||||
callHook(name, arg1, arg2) {
|
||||
const globalHook = this.options.hooks?.[name];
|
||||
const globalPromise = globalHook?.(arg1, arg2);
|
||||
const resolveHooksPromise = this.options.resolve?.(arg1);
|
||||
if (!resolveHooksPromise) {
|
||||
return globalPromise;
|
||||
}
|
||||
const resolvePromise = resolveHooksPromise instanceof Promise ? resolveHooksPromise.then((hooks) => hooks?.[name]) : resolveHooksPromise?.[name];
|
||||
return Promise.all([globalPromise, resolvePromise]).then(
|
||||
([globalRes, hook]) => {
|
||||
const hookResPromise = hook?.(arg1, arg2);
|
||||
return hookResPromise instanceof Promise ? hookResPromise.then((hookRes) => hookRes || globalRes) : hookResPromise || globalRes;
|
||||
}
|
||||
);
|
||||
}
|
||||
async upgrade(request) {
|
||||
let context = request.context;
|
||||
if (!context) {
|
||||
context = {};
|
||||
Object.defineProperty(request, "context", {
|
||||
enumerable: true,
|
||||
value: context
|
||||
});
|
||||
}
|
||||
try {
|
||||
const res = await this.callHook(
|
||||
"upgrade",
|
||||
request
|
||||
);
|
||||
if (!res) {
|
||||
return { context };
|
||||
}
|
||||
if (res.ok === false) {
|
||||
return { context, endResponse: res };
|
||||
}
|
||||
if (res.headers) {
|
||||
return {
|
||||
context,
|
||||
upgradeHeaders: res.headers
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
const errResponse = error.response || error;
|
||||
if (errResponse instanceof Response) {
|
||||
return {
|
||||
context,
|
||||
endResponse: errResponse
|
||||
};
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return { context };
|
||||
}
|
||||
}
|
||||
function defineHooks(hooks) {
|
||||
return hooks;
|
||||
}
|
||||
|
||||
function adapterUtils(peers) {
|
||||
return {
|
||||
peers,
|
||||
publish(topic, message, options) {
|
||||
let firstPeerWithTopic;
|
||||
for (const peer of peers) {
|
||||
if (peer.topics.has(topic)) {
|
||||
firstPeerWithTopic = peer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (firstPeerWithTopic) {
|
||||
firstPeerWithTopic.send(message, options);
|
||||
firstPeerWithTopic.publish(topic, message, options);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function defineWebSocketAdapter(factory) {
|
||||
return factory;
|
||||
}
|
||||
|
||||
export { AdapterHookable as A, adapterUtils as a, defineWebSocketAdapter as b, defineHooks as d };
|
325
node_modules/crossws/dist/shared/crossws.DfCzGthR.mjs
generated
vendored
Normal file
325
node_modules/crossws/dist/shared/crossws.DfCzGthR.mjs
generated
vendored
Normal file
@@ -0,0 +1,325 @@
|
||||
import { randomUUID } from 'uncrypto';
|
||||
|
||||
const kNodeInspect = /* @__PURE__ */ Symbol.for(
|
||||
"nodejs.util.inspect.custom"
|
||||
);
|
||||
function toBufferLike(val) {
|
||||
if (val === void 0 || val === null) {
|
||||
return "";
|
||||
}
|
||||
const type = typeof val;
|
||||
if (type === "string") {
|
||||
return val;
|
||||
}
|
||||
if (type === "number" || type === "boolean" || type === "bigint") {
|
||||
return val.toString();
|
||||
}
|
||||
if (type === "function" || type === "symbol") {
|
||||
return "{}";
|
||||
}
|
||||
if (val instanceof Uint8Array || val instanceof ArrayBuffer) {
|
||||
return val;
|
||||
}
|
||||
if (isPlainObject(val)) {
|
||||
return JSON.stringify(val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
function toString(val) {
|
||||
if (typeof val === "string") {
|
||||
return val;
|
||||
}
|
||||
const data = toBufferLike(val);
|
||||
if (typeof data === "string") {
|
||||
return data;
|
||||
}
|
||||
const base64 = btoa(String.fromCharCode(...new Uint8Array(data)));
|
||||
return `data:application/octet-stream;base64,${base64}`;
|
||||
}
|
||||
function isPlainObject(value) {
|
||||
if (value === null || typeof value !== "object") {
|
||||
return false;
|
||||
}
|
||||
const prototype = Object.getPrototypeOf(value);
|
||||
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
||||
return false;
|
||||
}
|
||||
if (Symbol.iterator in value) {
|
||||
return false;
|
||||
}
|
||||
if (Symbol.toStringTag in value) {
|
||||
return Object.prototype.toString.call(value) === "[object Module]";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class Message {
|
||||
/** Access to the original [message event](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event) if available. */
|
||||
event;
|
||||
/** Access to the Peer that emitted the message. */
|
||||
peer;
|
||||
/** Raw message data (can be of any type). */
|
||||
rawData;
|
||||
#id;
|
||||
#uint8Array;
|
||||
#arrayBuffer;
|
||||
#blob;
|
||||
#text;
|
||||
#json;
|
||||
constructor(rawData, peer, event) {
|
||||
this.rawData = rawData || "";
|
||||
this.peer = peer;
|
||||
this.event = event;
|
||||
}
|
||||
/**
|
||||
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the message.
|
||||
*/
|
||||
get id() {
|
||||
if (!this.#id) {
|
||||
this.#id = randomUUID();
|
||||
}
|
||||
return this.#id;
|
||||
}
|
||||
// --- data views ---
|
||||
/**
|
||||
* Get data as [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
||||
*/
|
||||
uint8Array() {
|
||||
const _uint8Array = this.#uint8Array;
|
||||
if (_uint8Array) {
|
||||
return _uint8Array;
|
||||
}
|
||||
const rawData = this.rawData;
|
||||
if (rawData instanceof Uint8Array) {
|
||||
return this.#uint8Array = rawData;
|
||||
}
|
||||
if (rawData instanceof ArrayBuffer || rawData instanceof SharedArrayBuffer) {
|
||||
this.#arrayBuffer = rawData;
|
||||
return this.#uint8Array = new Uint8Array(rawData);
|
||||
}
|
||||
if (typeof rawData === "string") {
|
||||
this.#text = rawData;
|
||||
return this.#uint8Array = new TextEncoder().encode(this.#text);
|
||||
}
|
||||
if (Symbol.iterator in rawData) {
|
||||
return this.#uint8Array = new Uint8Array(rawData);
|
||||
}
|
||||
if (typeof rawData?.length === "number") {
|
||||
return this.#uint8Array = new Uint8Array(rawData);
|
||||
}
|
||||
if (rawData instanceof DataView) {
|
||||
return this.#uint8Array = new Uint8Array(
|
||||
rawData.buffer,
|
||||
rawData.byteOffset,
|
||||
rawData.byteLength
|
||||
);
|
||||
}
|
||||
throw new TypeError(
|
||||
`Unsupported message type: ${Object.prototype.toString.call(rawData)}`
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Get data as [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
||||
*/
|
||||
arrayBuffer() {
|
||||
const _arrayBuffer = this.#arrayBuffer;
|
||||
if (_arrayBuffer) {
|
||||
return _arrayBuffer;
|
||||
}
|
||||
const rawData = this.rawData;
|
||||
if (rawData instanceof ArrayBuffer || rawData instanceof SharedArrayBuffer) {
|
||||
return this.#arrayBuffer = rawData;
|
||||
}
|
||||
return this.#arrayBuffer = this.uint8Array().buffer;
|
||||
}
|
||||
/**
|
||||
* Get data as [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) value.
|
||||
*
|
||||
* If raw data is in any other format or string, it will be automatically converted and encoded. */
|
||||
blob() {
|
||||
const _blob = this.#blob;
|
||||
if (_blob) {
|
||||
return _blob;
|
||||
}
|
||||
const rawData = this.rawData;
|
||||
if (rawData instanceof Blob) {
|
||||
return this.#blob = rawData;
|
||||
}
|
||||
return this.#blob = new Blob([this.uint8Array()]);
|
||||
}
|
||||
/**
|
||||
* Get stringified text version of the message.
|
||||
*
|
||||
* If raw data is in any other format, it will be automatically converted and decoded.
|
||||
*/
|
||||
text() {
|
||||
const _text = this.#text;
|
||||
if (_text) {
|
||||
return _text;
|
||||
}
|
||||
const rawData = this.rawData;
|
||||
if (typeof rawData === "string") {
|
||||
return this.#text = rawData;
|
||||
}
|
||||
return this.#text = new TextDecoder().decode(this.uint8Array());
|
||||
}
|
||||
/**
|
||||
* Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
|
||||
*/
|
||||
json() {
|
||||
const _json = this.#json;
|
||||
if (_json) {
|
||||
return _json;
|
||||
}
|
||||
return this.#json = JSON.parse(this.text());
|
||||
}
|
||||
/**
|
||||
* Message data (value varies based on `peer.websocket.binaryType`).
|
||||
*/
|
||||
get data() {
|
||||
switch (this.peer?.websocket?.binaryType) {
|
||||
case "arraybuffer": {
|
||||
return this.arrayBuffer();
|
||||
}
|
||||
case "blob": {
|
||||
return this.blob();
|
||||
}
|
||||
case "nodebuffer": {
|
||||
return globalThis.Buffer ? Buffer.from(this.uint8Array()) : this.uint8Array();
|
||||
}
|
||||
case "uint8array": {
|
||||
return this.uint8Array();
|
||||
}
|
||||
case "text": {
|
||||
return this.text();
|
||||
}
|
||||
default: {
|
||||
return this.rawData;
|
||||
}
|
||||
}
|
||||
}
|
||||
// --- inspect ---
|
||||
toString() {
|
||||
return this.text();
|
||||
}
|
||||
[Symbol.toPrimitive]() {
|
||||
return this.text();
|
||||
}
|
||||
[kNodeInspect]() {
|
||||
return { data: this.rawData };
|
||||
}
|
||||
}
|
||||
|
||||
class Peer {
|
||||
_internal;
|
||||
_topics;
|
||||
_id;
|
||||
#ws;
|
||||
constructor(internal) {
|
||||
this._topics = /* @__PURE__ */ new Set();
|
||||
this._internal = internal;
|
||||
}
|
||||
get context() {
|
||||
return this._internal.context ??= {};
|
||||
}
|
||||
/**
|
||||
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the peer.
|
||||
*/
|
||||
get id() {
|
||||
if (!this._id) {
|
||||
this._id = randomUUID();
|
||||
}
|
||||
return this._id;
|
||||
}
|
||||
/** IP address of the peer */
|
||||
get remoteAddress() {
|
||||
return void 0;
|
||||
}
|
||||
/** upgrade request */
|
||||
get request() {
|
||||
return this._internal.request;
|
||||
}
|
||||
/**
|
||||
* Get the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance.
|
||||
*
|
||||
* **Note:** crossws adds polyfill for the following properties if native values are not available:
|
||||
* - `protocol`: Extracted from the `sec-websocket-protocol` header.
|
||||
* - `extensions`: Extracted from the `sec-websocket-extensions` header.
|
||||
* - `url`: Extracted from the request URL (http -> ws).
|
||||
* */
|
||||
get websocket() {
|
||||
if (!this.#ws) {
|
||||
const _ws = this._internal.ws;
|
||||
const _request = this._internal.request;
|
||||
this.#ws = _request ? createWsProxy(_ws, _request) : _ws;
|
||||
}
|
||||
return this.#ws;
|
||||
}
|
||||
/** All connected peers to the server */
|
||||
get peers() {
|
||||
return this._internal.peers || /* @__PURE__ */ new Set();
|
||||
}
|
||||
/** All topics, this peer has been subscribed to. */
|
||||
get topics() {
|
||||
return this._topics;
|
||||
}
|
||||
/** Abruptly close the connection */
|
||||
terminate() {
|
||||
this.close();
|
||||
}
|
||||
/** Subscribe to a topic */
|
||||
subscribe(topic) {
|
||||
this._topics.add(topic);
|
||||
}
|
||||
/** Unsubscribe from a topic */
|
||||
unsubscribe(topic) {
|
||||
this._topics.delete(topic);
|
||||
}
|
||||
// --- inspect ---
|
||||
toString() {
|
||||
return this.id;
|
||||
}
|
||||
[Symbol.toPrimitive]() {
|
||||
return this.id;
|
||||
}
|
||||
[Symbol.toStringTag]() {
|
||||
return "WebSocket";
|
||||
}
|
||||
[kNodeInspect]() {
|
||||
return Object.fromEntries(
|
||||
[
|
||||
["id", this.id],
|
||||
["remoteAddress", this.remoteAddress],
|
||||
["peers", this.peers],
|
||||
["webSocket", this.websocket]
|
||||
].filter((p) => p[1])
|
||||
);
|
||||
}
|
||||
}
|
||||
function createWsProxy(ws, request) {
|
||||
return new Proxy(ws, {
|
||||
get: (target, prop) => {
|
||||
const value = Reflect.get(target, prop);
|
||||
if (!value) {
|
||||
switch (prop) {
|
||||
case "protocol": {
|
||||
return request?.headers?.get("sec-websocket-protocol") || "";
|
||||
}
|
||||
case "extensions": {
|
||||
return request?.headers?.get("sec-websocket-extensions") || "";
|
||||
}
|
||||
case "url": {
|
||||
return request?.url?.replace(/^http/, "ws") || void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { Message as M, Peer as P, toString as a, toBufferLike as t };
|
3
node_modules/crossws/dist/websocket/native.d.mts
generated
vendored
Normal file
3
node_modules/crossws/dist/websocket/native.d.mts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const WebSocket: typeof globalThis.WebSocket;
|
||||
|
||||
export { WebSocket as default };
|
3
node_modules/crossws/dist/websocket/native.d.ts
generated
vendored
Normal file
3
node_modules/crossws/dist/websocket/native.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const WebSocket: typeof globalThis.WebSocket;
|
||||
|
||||
export { WebSocket as default };
|
3
node_modules/crossws/dist/websocket/native.mjs
generated
vendored
Normal file
3
node_modules/crossws/dist/websocket/native.mjs
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const WebSocket = globalThis.WebSocket;
|
||||
|
||||
export { WebSocket as default };
|
3
node_modules/crossws/dist/websocket/node.d.mts
generated
vendored
Normal file
3
node_modules/crossws/dist/websocket/node.d.mts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const Websocket: typeof globalThis.WebSocket;
|
||||
|
||||
export { Websocket as default };
|
3
node_modules/crossws/dist/websocket/node.d.ts
generated
vendored
Normal file
3
node_modules/crossws/dist/websocket/node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const Websocket: typeof globalThis.WebSocket;
|
||||
|
||||
export { Websocket as default };
|
15
node_modules/crossws/dist/websocket/node.mjs
generated
vendored
Normal file
15
node_modules/crossws/dist/websocket/node.mjs
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { a as _WebSocket } from '../shared/crossws.CipVM6lf.mjs';
|
||||
import 'stream';
|
||||
import 'events';
|
||||
import 'http';
|
||||
import 'crypto';
|
||||
import 'buffer';
|
||||
import 'zlib';
|
||||
import 'https';
|
||||
import 'net';
|
||||
import 'tls';
|
||||
import 'url';
|
||||
|
||||
const Websocket = globalThis.WebSocket || _WebSocket;
|
||||
|
||||
export { Websocket as default };
|
42
node_modules/crossws/dist/websocket/sse.d.mts
generated
vendored
Normal file
42
node_modules/crossws/dist/websocket/sse.d.mts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { E as EventTarget, W as WebSocket, C as CloseEvent, a as Event, M as MessageEvent } from '../shared/crossws.BQXMA5bH.mjs';
|
||||
|
||||
type Ctor<T> = {
|
||||
prototype: T;
|
||||
new (): T;
|
||||
};
|
||||
declare const _EventTarget: Ctor<EventTarget>;
|
||||
interface WebSocketSSEOptions {
|
||||
protocols?: string | string[];
|
||||
/** enabled by default */
|
||||
bidir?: boolean;
|
||||
/** enabled by default */
|
||||
stream?: boolean;
|
||||
headers?: HeadersInit;
|
||||
}
|
||||
declare class WebSocketSSE extends _EventTarget implements WebSocket {
|
||||
#private;
|
||||
static CONNECTING: number;
|
||||
static OPEN: number;
|
||||
static CLOSING: number;
|
||||
static CLOSED: number;
|
||||
readonly CONNECTING = 0;
|
||||
readonly OPEN = 1;
|
||||
readonly CLOSING = 2;
|
||||
readonly CLOSED = 3;
|
||||
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
|
||||
onerror: ((this: WebSocket, ev: Event) => any) | null;
|
||||
onopen: ((this: WebSocket, ev: Event) => any) | null;
|
||||
onmessage: ((this: WebSocket, ev: MessageEvent<any>) => any) | null;
|
||||
binaryType: BinaryType;
|
||||
readyState: number;
|
||||
readonly url: string;
|
||||
readonly protocol: string;
|
||||
readonly extensions: string;
|
||||
readonly bufferedAmount: number;
|
||||
constructor(url: string, init?: string | string[] | WebSocketSSEOptions);
|
||||
close(_code?: number, _reason?: string): void;
|
||||
send(data: any): Promise<void>;
|
||||
}
|
||||
|
||||
export { WebSocketSSE };
|
||||
export type { WebSocketSSEOptions };
|
42
node_modules/crossws/dist/websocket/sse.d.ts
generated
vendored
Normal file
42
node_modules/crossws/dist/websocket/sse.d.ts
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { E as EventTarget, W as WebSocket, C as CloseEvent, a as Event, M as MessageEvent } from '../shared/crossws.BQXMA5bH.js';
|
||||
|
||||
type Ctor<T> = {
|
||||
prototype: T;
|
||||
new (): T;
|
||||
};
|
||||
declare const _EventTarget: Ctor<EventTarget>;
|
||||
interface WebSocketSSEOptions {
|
||||
protocols?: string | string[];
|
||||
/** enabled by default */
|
||||
bidir?: boolean;
|
||||
/** enabled by default */
|
||||
stream?: boolean;
|
||||
headers?: HeadersInit;
|
||||
}
|
||||
declare class WebSocketSSE extends _EventTarget implements WebSocket {
|
||||
#private;
|
||||
static CONNECTING: number;
|
||||
static OPEN: number;
|
||||
static CLOSING: number;
|
||||
static CLOSED: number;
|
||||
readonly CONNECTING = 0;
|
||||
readonly OPEN = 1;
|
||||
readonly CLOSING = 2;
|
||||
readonly CLOSED = 3;
|
||||
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
|
||||
onerror: ((this: WebSocket, ev: Event) => any) | null;
|
||||
onopen: ((this: WebSocket, ev: Event) => any) | null;
|
||||
onmessage: ((this: WebSocket, ev: MessageEvent<any>) => any) | null;
|
||||
binaryType: BinaryType;
|
||||
readyState: number;
|
||||
readonly url: string;
|
||||
readonly protocol: string;
|
||||
readonly extensions: string;
|
||||
readonly bufferedAmount: number;
|
||||
constructor(url: string, init?: string | string[] | WebSocketSSEOptions);
|
||||
close(_code?: number, _reason?: string): void;
|
||||
send(data: any): Promise<void>;
|
||||
}
|
||||
|
||||
export { WebSocketSSE };
|
||||
export type { WebSocketSSEOptions };
|
127
node_modules/crossws/dist/websocket/sse.mjs
generated
vendored
Normal file
127
node_modules/crossws/dist/websocket/sse.mjs
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
const _EventTarget = EventTarget;
|
||||
const defaultOptions = Object.freeze({
|
||||
bidir: true,
|
||||
stream: true
|
||||
});
|
||||
class WebSocketSSE extends _EventTarget {
|
||||
static CONNECTING = 0;
|
||||
static OPEN = 1;
|
||||
static CLOSING = 2;
|
||||
static CLOSED = 3;
|
||||
CONNECTING = 0;
|
||||
OPEN = 1;
|
||||
CLOSING = 2;
|
||||
CLOSED = 3;
|
||||
/* eslint-disable unicorn/no-null */
|
||||
onclose = null;
|
||||
onerror = null;
|
||||
onopen = null;
|
||||
onmessage = null;
|
||||
/* eslint-enable unicorn/no-null */
|
||||
binaryType = "blob";
|
||||
readyState = WebSocketSSE.CONNECTING;
|
||||
url;
|
||||
protocol = "";
|
||||
extensions = "";
|
||||
bufferedAmount = 0;
|
||||
#options = {};
|
||||
#sse;
|
||||
#id;
|
||||
#sendController;
|
||||
#queue = [];
|
||||
constructor(url, init) {
|
||||
super();
|
||||
this.url = url.replace(/^ws/, "http");
|
||||
if (typeof init === "string") {
|
||||
this.#options = { ...defaultOptions, protocols: init };
|
||||
} else if (Array.isArray(init)) {
|
||||
this.#options = { ...defaultOptions, protocols: init };
|
||||
} else {
|
||||
this.#options = { ...defaultOptions, ...init };
|
||||
}
|
||||
this.#sse = new EventSource(this.url);
|
||||
this.#sse.addEventListener("open", (_sseEvent) => {
|
||||
this.readyState = WebSocketSSE.OPEN;
|
||||
const event = new Event("open");
|
||||
this.onopen?.(event);
|
||||
this.dispatchEvent(event);
|
||||
});
|
||||
this.#sse.addEventListener("message", (sseEvent) => {
|
||||
const _event = new MessageEvent("message", {
|
||||
data: sseEvent.data
|
||||
});
|
||||
this.onmessage?.(_event);
|
||||
this.dispatchEvent(_event);
|
||||
});
|
||||
if (this.#options.bidir) {
|
||||
this.#sse.addEventListener("crossws-id", (sseEvent) => {
|
||||
this.#id = sseEvent.data;
|
||||
if (this.#options.stream) {
|
||||
fetch(this.url, {
|
||||
method: "POST",
|
||||
// @ts-expect-error
|
||||
duplex: "half",
|
||||
headers: {
|
||||
"content-type": "application/octet-stream",
|
||||
"x-crossws-id": this.#id
|
||||
},
|
||||
body: new ReadableStream({
|
||||
start: (controller) => {
|
||||
this.#sendController = controller;
|
||||
},
|
||||
cancel: () => {
|
||||
this.#sendController = void 0;
|
||||
}
|
||||
}).pipeThrough(new TextEncoderStream())
|
||||
}).catch(() => {
|
||||
});
|
||||
}
|
||||
for (const data of this.#queue) {
|
||||
this.send(data);
|
||||
}
|
||||
this.#queue = [];
|
||||
});
|
||||
}
|
||||
this.#sse.addEventListener("error", (_sseEvent) => {
|
||||
const event = new Event("error");
|
||||
this.onerror?.(event);
|
||||
this.dispatchEvent(event);
|
||||
});
|
||||
this.#sse.addEventListener("close", (_sseEvent) => {
|
||||
this.readyState = WebSocketSSE.CLOSED;
|
||||
const event = new Event("close");
|
||||
this.onclose?.(event);
|
||||
this.dispatchEvent(event);
|
||||
});
|
||||
}
|
||||
close(_code, _reason) {
|
||||
this.readyState = WebSocketSSE.CLOSING;
|
||||
this.#sse.close();
|
||||
this.readyState = WebSocketSSE.CLOSED;
|
||||
}
|
||||
async send(data) {
|
||||
if (!this.#options.bidir) {
|
||||
throw new Error("bdir option is not enabled!");
|
||||
}
|
||||
if (this.readyState !== WebSocketSSE.OPEN) {
|
||||
throw new Error("WebSocket is not open!");
|
||||
}
|
||||
if (!this.#id) {
|
||||
this.#queue.push(data);
|
||||
return;
|
||||
}
|
||||
if (this.#sendController) {
|
||||
this.#sendController.enqueue(data);
|
||||
return;
|
||||
}
|
||||
await fetch(this.url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"x-crossws-id": this.#id
|
||||
},
|
||||
body: data
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { WebSocketSSE };
|
Reference in New Issue
Block a user