crossws 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  const StubRequest = /* @__PURE__ */ (() => {
3
3
  class StubRequest {
4
4
  url;
5
- _signal;
5
+ _abortController;
6
6
  _headers;
7
7
  _init;
8
8
  constructor(url, init = {}) {
@@ -20,7 +20,8 @@ const StubRequest = /* @__PURE__ */ (() => {
20
20
  return "GET";
21
21
  }
22
22
  get signal() {
23
- return this._signal ??= new AbortSignal();
23
+ if (!this._abortController) this._abortController = new AbortController();
24
+ return this._abortController.signal;
24
25
  }
25
26
  get cache() {
26
27
  return "default";
@@ -26,21 +26,21 @@ declare abstract class Peer<Internal extends AdapterInternal = AdapterInternal>
26
26
  get context(): PeerContext;
27
27
  get namespace(): string;
28
28
  /**
29
- * Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the peer.
30
- */
29
+ * Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the peer.
30
+ */
31
31
  get id(): string;
32
32
  /** IP address of the peer */
33
33
  get remoteAddress(): string | undefined;
34
34
  /** upgrade request */
35
35
  get request(): Request;
36
36
  /**
37
- * Get the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance.
38
- *
39
- * **Note:** crossws adds polyfill for the following properties if native values are not available:
40
- * - `protocol`: Extracted from the `sec-websocket-protocol` header.
41
- * - `extensions`: Extracted from the `sec-websocket-extensions` header.
42
- * - `url`: Extracted from the request URL (http -> ws).
43
- * */
37
+ * Get the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance.
38
+ *
39
+ * **Note:** crossws adds polyfill for the following properties if native values are not available:
40
+ * - `protocol`: Extracted from the `sec-websocket-protocol` header.
41
+ * - `extensions`: Extracted from the `sec-websocket-extensions` header.
42
+ * - `url`: Extracted from the request URL (http -> ws).
43
+ * */
44
44
  get websocket(): Partial<WebSocket>;
45
45
  /** All connected peers to the server */
46
46
  get peers(): Set<Peer>;
@@ -78,39 +78,39 @@ declare class Message implements Partial<MessageEvent> {
78
78
  readonly rawData: unknown;
79
79
  constructor(rawData: unknown, peer: Peer, event?: MessageEvent);
80
80
  /**
81
- * Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the message.
82
- */
81
+ * Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the message.
82
+ */
83
83
  get id(): string;
84
84
  /**
85
- * Get data as [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.
86
- *
87
- * If raw data is in any other format or string, it will be automatically converted and encoded.
88
- */
85
+ * Get data as [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.
86
+ *
87
+ * If raw data is in any other format or string, it will be automatically converted and encoded.
88
+ */
89
89
  uint8Array(): Uint8Array;
90
90
  /**
91
- * 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.
92
- *
93
- * If raw data is in any other format or string, it will be automatically converted and encoded.
94
- */
91
+ * 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.
92
+ *
93
+ * If raw data is in any other format or string, it will be automatically converted and encoded.
94
+ */
95
95
  arrayBuffer(): ArrayBuffer | SharedArrayBuffer;
96
96
  /**
97
- * Get data as [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) value.
98
- *
99
- * If raw data is in any other format or string, it will be automatically converted and encoded. */
97
+ * Get data as [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) value.
98
+ *
99
+ * If raw data is in any other format or string, it will be automatically converted and encoded. */
100
100
  blob(): Blob;
101
101
  /**
102
- * Get stringified text version of the message.
103
- *
104
- * If raw data is in any other format, it will be automatically converted and decoded.
105
- */
102
+ * Get stringified text version of the message.
103
+ *
104
+ * If raw data is in any other format, it will be automatically converted and decoded.
105
+ */
106
106
  text(): string;
107
107
  /**
108
- * Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
109
- */
108
+ * Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
109
+ */
110
110
  json<T = unknown>(): T;
111
111
  /**
112
- * Message data (value varies based on `peer.websocket.binaryType`).
113
- */
112
+ * Message data (value varies based on `peer.websocket.binaryType`).
113
+ */
114
114
  get data(): unknown;
115
115
  toString(): string;
116
116
  [Symbol.toPrimitive](): string;
@@ -125,16 +125,16 @@ type ResolveHooks = (request: Request & {
125
125
  type MaybePromise<T> = T | Promise<T>;
126
126
  interface Hooks {
127
127
  /**
128
- * Upgrading a request to a WebSocket connection.
129
- *
130
- * - You can throw a Response to abort the upgrade.
131
- * - You can return { headers } to modify the response.
132
- * - You can return { namespace } to change the pub/sub namespace.
133
- * - You can return { context } to provide a custom peer context.
134
- *
135
- * @param request
136
- * @throws {Response}
137
- */
128
+ * Upgrading a request to a WebSocket connection.
129
+ *
130
+ * - You can throw a Response to abort the upgrade.
131
+ * - You can return { headers } to modify the response.
132
+ * - You can return { namespace } to change the pub/sub namespace.
133
+ * - You can return { context } to provide a custom peer context.
134
+ *
135
+ * @param request
136
+ * @throws {Response}
137
+ */
138
138
  upgrade: (request: Request & {
139
139
  readonly context?: Record<string, unknown>;
140
140
  }) => MaybePromise<{
@@ -10,26 +10,26 @@ type WSDurableObjectStub = CF.DurableObjectStub & {
10
10
  type ResolveDurableStub = (req: CF.Request | undefined, env: unknown, context: CF.ExecutionContext | undefined) => WSDurableObjectStub | undefined | Promise<WSDurableObjectStub | undefined>;
11
11
  interface CloudflareOptions extends AdapterOptions {
12
12
  /**
13
- * Durable Object binding name from environment.
14
- *
15
- * **Note:** This option will be ignored if `resolveDurableStub` is provided.
16
- *
17
- * @default "$DurableObject"
18
- */
13
+ * Durable Object binding name from environment.
14
+ *
15
+ * **Note:** This option will be ignored if `resolveDurableStub` is provided.
16
+ *
17
+ * @default "$DurableObject"
18
+ */
19
19
  bindingName?: string;
20
20
  /**
21
- * Durable Object instance name.
22
- *
23
- * **Note:** This option will be ignored if `resolveDurableStub` is provided.
24
- *
25
- * @default "crossws"
26
- */
21
+ * Durable Object instance name.
22
+ *
23
+ * **Note:** This option will be ignored if `resolveDurableStub` is provided.
24
+ *
25
+ * @default "crossws"
26
+ */
27
27
  instanceName?: string;
28
28
  /**
29
- * Custom function that resolves Durable Object binding to handle the WebSocket upgrade.
30
- *
31
- * **Note:** This option will override `bindingName` and `instanceName`.
32
- */
29
+ * Custom function that resolves Durable Object binding to handle the WebSocket upgrade.
30
+ *
31
+ * **Note:** This option will override `bindingName` and `instanceName`.
32
+ */
33
33
  resolveDurableStub?: ResolveDurableStub;
34
34
  }
35
35
  declare const cloudflareAdapter: Adapter<CloudflareDurableAdapter, CloudflareOptions>;
@@ -417,7 +417,7 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
417
417
  callback(err);
418
418
  return;
419
419
  }
420
- const data$1 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
420
+ const data = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
421
421
  if (this._inflate._readableState.endEmitted) {
422
422
  this._inflate.close();
423
423
  this._inflate = null;
@@ -426,7 +426,7 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
426
426
  this._inflate[kBuffers] = [];
427
427
  if (fin && this.params[`${endpoint}_no_context_takeover`]) this._inflate.reset();
428
428
  }
429
- callback(null, data$1);
429
+ callback(null, data);
430
430
  });
431
431
  }
432
432
  /**
@@ -454,13 +454,13 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
454
454
  this._deflate.write(data);
455
455
  this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
456
456
  if (!this._deflate) return;
457
- let data$1 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
458
- if (fin) data$1 = new FastBuffer(data$1.buffer, data$1.byteOffset, data$1.length - 4);
457
+ let data = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
458
+ if (fin) data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
459
459
  this._deflate[kCallback] = null;
460
460
  this._deflate[kTotalLength] = 0;
461
461
  this._deflate[kBuffers] = [];
462
462
  if (fin && this.params[`${endpoint}_no_context_takeover`]) this._deflate.reset();
463
- callback(null, data$1);
463
+ callback(null, data);
464
464
  });
465
465
  }
466
466
  };
@@ -2625,7 +2625,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2625
2625
  ...options,
2626
2626
  headers: {}
2627
2627
  };
2628
- if (headers) for (const [key$1, value] of Object.entries(headers)) options.headers[key$1.toLowerCase()] = value;
2628
+ if (headers) for (const [key, value] of Object.entries(headers)) options.headers[key.toLowerCase()] = value;
2629
2629
  } else if (websocket.listenerCount("redirect") === 0) {
2630
2630
  const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2631
2631
  if (!isSameHost || websocket._originalSecure && !isSecure) {
@@ -3057,9 +3057,9 @@ var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3057
3057
  return;
3058
3058
  }
3059
3059
  let called = false;
3060
- ws.once("error", function error(err$1) {
3060
+ ws.once("error", function error(err) {
3061
3061
  called = true;
3062
- callback(err$1);
3062
+ callback(err);
3063
3063
  });
3064
3064
  ws.once("close", function close() {
3065
3065
  if (!called) callback(err);
@@ -3129,9 +3129,9 @@ var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
3129
3129
  } else if (code === 44) {
3130
3130
  if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
3131
3131
  if (end === -1) end = i;
3132
- const protocol$1 = header.slice(start, end);
3133
- if (protocols.has(protocol$1)) throw new SyntaxError(`The "${protocol$1}" subprotocol is duplicated`);
3134
- protocols.add(protocol$1);
3132
+ const protocol = header.slice(start, end);
3133
+ if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3134
+ protocols.add(protocol);
3135
3135
  start = end = -1;
3136
3136
  } else throw new SyntaxError(`Unexpected character at index ${i}`);
3137
3137
  }
@@ -70,15 +70,15 @@ declare class WebSocket extends EventEmitter {
70
70
  }, cb?: (err?: Error) => void): void;
71
71
  terminate(): void;
72
72
  /**
73
- * Pause the websocket causing it to stop emitting events. Some events can still be
74
- * emitted after this is called, until all buffered data is consumed. This method
75
- * is a noop if the ready state is `CONNECTING` or `CLOSED`.
76
- */
73
+ * Pause the websocket causing it to stop emitting events. Some events can still be
74
+ * emitted after this is called, until all buffered data is consumed. This method
75
+ * is a noop if the ready state is `CONNECTING` or `CLOSED`.
76
+ */
77
77
  pause(): void;
78
78
  /**
79
- * Make a paused socket resume emitting events. This method is a noop if the ready
80
- * state is `CONNECTING` or `CLOSED`.
81
- */
79
+ * Make a paused socket resume emitting events. This method is a noop if the ready
80
+ * state is `CONNECTING` or `CLOSED`.
81
+ */
82
82
  resume(): void;
83
83
  addEventListener(method: "message", cb: (event: MessageEvent) => void, options?: EventListenerOptions): void;
84
84
  addEventListener(method: "close", cb: (event: CloseEvent) => void, options?: EventListenerOptions): void;
@@ -6,22 +6,22 @@
6
6
  */
7
7
  interface CloseEvent extends Event {
8
8
  /**
9
- * Returns the WebSocket connection close code provided by the server.
10
- *
11
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/code)
12
- */
9
+ * Returns the WebSocket connection close code provided by the server.
10
+ *
11
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/code)
12
+ */
13
13
  readonly code: number;
14
14
  /**
15
- * Returns the WebSocket connection close reason provided by the server.
16
- *
17
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/reason)
18
- */
15
+ * Returns the WebSocket connection close reason provided by the server.
16
+ *
17
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/reason)
18
+ */
19
19
  readonly reason: string;
20
20
  /**
21
- * Returns true if the connection closed cleanly; false otherwise.
22
- *
23
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/wasClean)
24
- */
21
+ * Returns true if the connection closed cleanly; false otherwise.
22
+ *
23
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/wasClean)
24
+ */
25
25
  readonly wasClean: boolean;
26
26
  }
27
27
  /**
@@ -31,112 +31,112 @@ interface CloseEvent extends Event {
31
31
  */
32
32
  interface Event {
33
33
  /**
34
- * 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.
35
- *
36
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/bubbles)
37
- */
34
+ * 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.
35
+ *
36
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/bubbles)
37
+ */
38
38
  readonly bubbles: boolean;
39
39
  /**
40
- * @deprecated
41
- *
42
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble)
43
- */
40
+ * @deprecated
41
+ *
42
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble)
43
+ */
44
44
  cancelBubble: boolean;
45
45
  /**
46
- * 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.
47
- *
48
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelable)
49
- */
46
+ * 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.
47
+ *
48
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelable)
49
+ */
50
50
  readonly cancelable: boolean;
51
51
  /**
52
- * 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.
53
- *
54
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composed)
55
- */
52
+ * 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.
53
+ *
54
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composed)
55
+ */
56
56
  readonly composed: boolean;
57
57
  /**
58
- * Returns the object whose event listener's callback is currently being invoked.
59
- *
60
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget)
61
- */
58
+ * Returns the object whose event listener's callback is currently being invoked.
59
+ *
60
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget)
61
+ */
62
62
  readonly currentTarget: EventTarget | null;
63
63
  /**
64
- * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
65
- *
66
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented)
67
- */
64
+ * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
65
+ *
66
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented)
67
+ */
68
68
  readonly defaultPrevented: boolean;
69
69
  /**
70
- * Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
71
- *
72
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/eventPhase)
73
- */
70
+ * Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
71
+ *
72
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/eventPhase)
73
+ */
74
74
  readonly eventPhase: number;
75
75
  /**
76
- * Returns true if event was dispatched by the user agent, and false otherwise.
77
- *
78
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/isTrusted)
79
- */
76
+ * Returns true if event was dispatched by the user agent, and false otherwise.
77
+ *
78
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/isTrusted)
79
+ */
80
80
  readonly isTrusted: boolean;
81
81
  /**
82
- * @deprecated
83
- *
84
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/returnValue)
85
- */
82
+ * @deprecated
83
+ *
84
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/returnValue)
85
+ */
86
86
  returnValue: boolean;
87
87
  /**
88
- * @deprecated
89
- *
90
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/srcElement)
91
- */
88
+ * @deprecated
89
+ *
90
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/srcElement)
91
+ */
92
92
  readonly srcElement: EventTarget | null;
93
93
  /**
94
- * Returns the object to which event is dispatched (its target).
95
- *
96
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target)
97
- */
94
+ * Returns the object to which event is dispatched (its target).
95
+ *
96
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target)
97
+ */
98
98
  readonly target: EventTarget | null;
99
99
  /**
100
- * Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
101
- *
102
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/timeStamp)
103
- */
100
+ * Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
101
+ *
102
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/timeStamp)
103
+ */
104
104
  readonly timeStamp: DOMHighResTimeStamp;
105
105
  /**
106
- * Returns the type of event, e.g. "click", "hashchange", or "submit".
107
- *
108
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/type)
109
- */
106
+ * Returns the type of event, e.g. "click", "hashchange", or "submit".
107
+ *
108
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/type)
109
+ */
110
110
  readonly type: string;
111
111
  /**
112
- * 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.
113
- *
114
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composedPath)
115
- */
112
+ * 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.
113
+ *
114
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composedPath)
115
+ */
116
116
  composedPath(): EventTarget[];
117
117
  /**
118
- * @deprecated
119
- *
120
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/initEvent)
121
- */
118
+ * @deprecated
119
+ *
120
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/initEvent)
121
+ */
122
122
  initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
123
123
  /**
124
- * 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.
125
- *
126
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/preventDefault)
127
- */
124
+ * 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.
125
+ *
126
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/preventDefault)
127
+ */
128
128
  preventDefault(): void;
129
129
  /**
130
- * 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.
131
- *
132
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopImmediatePropagation)
133
- */
130
+ * 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.
131
+ *
132
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopImmediatePropagation)
133
+ */
134
134
  stopImmediatePropagation(): void;
135
135
  /**
136
- * When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
137
- *
138
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation)
139
- */
136
+ * When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
137
+ *
138
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation)
139
+ */
140
140
  stopPropagation(): void;
141
141
  readonly NONE: 0;
142
142
  readonly CAPTURING_PHASE: 1;
@@ -150,34 +150,34 @@ interface Event {
150
150
  */
151
151
  interface EventTarget {
152
152
  /**
153
- * 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.
154
- *
155
- * 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.
156
- *
157
- * 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.
158
- *
159
- * 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.
160
- *
161
- * When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
162
- *
163
- * If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
164
- *
165
- * The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
166
- *
167
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
168
- */
153
+ * 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.
154
+ *
155
+ * 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.
156
+ *
157
+ * 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.
158
+ *
159
+ * 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.
160
+ *
161
+ * When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
162
+ *
163
+ * If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
164
+ *
165
+ * The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
166
+ *
167
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
168
+ */
169
169
  addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
170
170
  /**
171
- * 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.
172
- *
173
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
174
- */
171
+ * 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.
172
+ *
173
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
174
+ */
175
175
  dispatchEvent(event: Event): boolean;
176
176
  /**
177
- * Removes the event listener in target's event listener list with the same type, callback, and options.
178
- *
179
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
180
- */
177
+ * Removes the event listener in target's event listener list with the same type, callback, and options.
178
+ *
179
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
180
+ */
181
181
  removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
182
182
  }
183
183
  /**
@@ -187,34 +187,34 @@ interface EventTarget {
187
187
  */
188
188
  interface MessageEvent<T = any> extends Event {
189
189
  /**
190
- * Returns the data of the message.
191
- *
192
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/data)
193
- */
190
+ * Returns the data of the message.
191
+ *
192
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/data)
193
+ */
194
194
  readonly data: T;
195
195
  /**
196
- * Returns the last event ID string, for server-sent events.
197
- *
198
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/lastEventId)
199
- */
196
+ * Returns the last event ID string, for server-sent events.
197
+ *
198
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/lastEventId)
199
+ */
200
200
  readonly lastEventId: string;
201
201
  /**
202
- * Returns the origin of the message, for server-sent events and cross-document messaging.
203
- *
204
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/origin)
205
- */
202
+ * Returns the origin of the message, for server-sent events and cross-document messaging.
203
+ *
204
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/origin)
205
+ */
206
206
  readonly origin: string;
207
207
  /**
208
- * Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging.
209
- *
210
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/ports)
211
- */
208
+ * Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging.
209
+ *
210
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/ports)
211
+ */
212
212
  readonly ports: ReadonlyArray<MessagePort>;
213
213
  /**
214
- * Returns the WindowProxy of the source window, for cross-document messaging, and the MessagePort being attached, in the connect event fired at SharedWorkerGlobalScope objects.
215
- *
216
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/source)
217
- */
214
+ * Returns the WindowProxy of the source window, for cross-document messaging, and the MessagePort being attached, in the connect event fired at SharedWorkerGlobalScope objects.
215
+ *
216
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/source)
217
+ */
218
218
  readonly source: MessageEventSource | null;
219
219
  /** @deprecated */
220
220
  initMessageEvent(type: string, bubbles?: boolean, cancelable?: boolean, data?: any, origin?: string, lastEventId?: string, source?: MessageEventSource | null, ports?: MessagePort[]): void;
@@ -226,26 +226,26 @@ interface MessageEvent<T = any> extends Event {
226
226
  */
227
227
  interface WebSocket extends EventTarget {
228
228
  /**
229
- * Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
230
- *
231
- * Can be set, to change how binary data is returned. The default is "blob".
232
- *
233
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType)
234
- */
229
+ * Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
230
+ *
231
+ * Can be set, to change how binary data is returned. The default is "blob".
232
+ *
233
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType)
234
+ */
235
235
  binaryType: BinaryType | (string & {});
236
236
  /**
237
- * 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.
238
- *
239
- * 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.)
240
- *
241
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/bufferedAmount)
242
- */
237
+ * 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.
238
+ *
239
+ * 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.)
240
+ *
241
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/bufferedAmount)
242
+ */
243
243
  readonly bufferedAmount: number;
244
244
  /**
245
- * Returns the extensions selected by the server, if any.
246
- *
247
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
248
- */
245
+ * Returns the extensions selected by the server, if any.
246
+ *
247
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
248
+ */
249
249
  readonly extensions: string;
250
250
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close_event) */
251
251
  onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
@@ -256,34 +256,34 @@ interface WebSocket extends EventTarget {
256
256
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/open_event) */
257
257
  onopen: ((this: WebSocket, ev: Event) => any) | null;
258
258
  /**
259
- * 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.
260
- *
261
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
262
- */
259
+ * 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.
260
+ *
261
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
262
+ */
263
263
  readonly protocol: string;
264
264
  /**
265
- * Returns the state of the WebSocket object's connection. It can have the values described below.
266
- *
267
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
268
- */
265
+ * Returns the state of the WebSocket object's connection. It can have the values described below.
266
+ *
267
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
268
+ */
269
269
  readonly readyState: number;
270
270
  /**
271
- * Returns the URL that was used to establish the WebSocket connection.
272
- *
273
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
274
- */
271
+ * Returns the URL that was used to establish the WebSocket connection.
272
+ *
273
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
274
+ */
275
275
  readonly url: string;
276
276
  /**
277
- * Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
278
- *
279
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
280
- */
277
+ * Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
278
+ *
279
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
280
+ */
281
281
  close(code?: number, reason?: string): void;
282
282
  /**
283
- * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
284
- *
285
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
286
- */
283
+ * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
284
+ *
285
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
286
+ */
287
287
  send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
288
288
  readonly CONNECTING: 0;
289
289
  readonly OPEN: 1;
@@ -2,15 +2,15 @@ import { i as AdapterHookable, r as getPeers, t as adapterUtils } from "../_chun
2
2
  import { n as Message, r as toBufferLike, t as Peer } from "../_chunks/peer.mjs";
3
3
  import { t as StubRequest } from "../_chunks/_request.mjs";
4
4
  import { t as WSError } from "../_chunks/error.mjs";
5
- import { env } from "cloudflare:workers";
5
+ import { env as env$1 } from "cloudflare:workers";
6
6
 
7
7
  //#region src/adapters/cloudflare.ts
8
8
  const cloudflareAdapter = (opts = {}) => {
9
9
  const hooks = new AdapterHookable(opts);
10
10
  const globalPeers = /* @__PURE__ */ new Map();
11
- const resolveDurableStub = opts.resolveDurableStub || ((_req, env$1, _context) => {
11
+ const resolveDurableStub = opts.resolveDurableStub || ((_req, env, _context) => {
12
12
  const bindingName = opts.bindingName || "$DurableObject";
13
- const binding = (env$1 || env)[bindingName];
13
+ const binding = (env || env$1)[bindingName];
14
14
  if (binding) {
15
15
  const instanceId = binding.idFromName(opts.instanceName || "crossws");
16
16
  return binding.get(instanceId);
@@ -59,7 +59,7 @@ const cloudflareAdapter = (opts = {}) => {
59
59
  headers: upgradeHeaders
60
60
  });
61
61
  },
62
- handleDurableInit: async (obj, state, env$1) => {},
62
+ handleDurableInit: async (obj, state, env) => {},
63
63
  handleDurableUpgrade: async (obj, request) => {
64
64
  const { upgradeHeaders, endResponse, namespace } = await hooks.upgrade(request);
65
65
  if (endResponse) return endResponse;
@@ -91,14 +91,14 @@ const cloudflareAdapter = (opts = {}) => {
91
91
  };
92
92
  await hooks.callHook("close", peer, details);
93
93
  },
94
- handleDurablePublish: async (_obj, topic, data, opts$1) => {
95
- return durablePublish(topic, data, opts$1);
94
+ handleDurablePublish: async (_obj, topic, data, opts) => {
95
+ return durablePublish(topic, data, opts);
96
96
  },
97
- publish: async (topic, data, opts$1) => {
98
- const stub = await resolveDurableStub(void 0, env, void 0);
97
+ publish: async (topic, data, opts) => {
98
+ const stub = await resolveDurableStub(void 0, env$1, void 0);
99
99
  if (!stub) throw new Error("[crossws] Durable Object binding cannot be resolved.");
100
100
  try {
101
- return await stub.webSocketPublish(topic, data, opts$1);
101
+ return await stub.webSocketPublish(topic, data, opts);
102
102
  } catch (error) {
103
103
  console.error(error);
104
104
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crossws",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Cross-platform WebSocket Servers for Node.js, Deno, Bun and Cloudflare Workers",
5
5
  "homepage": "https://crossws.h3.dev",
6
6
  "repository": "h3js/crossws",
@@ -68,14 +68,14 @@
68
68
  "crossws": "workspace:*"
69
69
  },
70
70
  "devDependencies": {
71
- "@cloudflare/workers-types": "^4.20260118.0",
71
+ "@cloudflare/workers-types": "^4.20260127.0",
72
72
  "@types/bun": "^1.3.6",
73
73
  "@types/deno": "^2.5.0",
74
- "@types/node": "^25.0.9",
75
- "@types/web": "^0.0.318",
74
+ "@types/node": "^25.0.10",
75
+ "@types/web": "^0.0.323",
76
76
  "@types/ws": "^8.18.1",
77
- "@typescript/native-preview": "7.0.0-dev.20260119.1",
78
- "@vitest/coverage-v8": "^4.0.17",
77
+ "@typescript/native-preview": "^7.0.0-dev.20260127.1",
78
+ "@vitest/coverage-v8": "^4.0.18",
79
79
  "automd": "^0.4.2",
80
80
  "changelogen": "^0.6.2",
81
81
  "consola": "^3.4.2",
@@ -84,18 +84,18 @@
84
84
  "eventsource": "^4.1.0",
85
85
  "execa": "^9.6.1",
86
86
  "get-port-please": "^3.2.0",
87
- "h3": "^2.0.1-rc.8",
87
+ "h3": "^2.0.1-rc.11",
88
88
  "jiti": "^2.6.1",
89
89
  "listhen": "^1.9.0",
90
- "obuild": "^0.4.16",
91
- "prettier": "^3.8.0",
90
+ "obuild": "^0.4.20",
91
+ "prettier": "^3.8.1",
92
92
  "srvx": "^0.10.1",
93
93
  "typescript": "^5.9.3",
94
94
  "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.57.0",
95
95
  "unbuild": "^3.6.1",
96
- "undici": "^7.18.2",
97
- "vitest": "^4.0.17",
98
- "wrangler": "^4.59.2",
96
+ "undici": "^7.19.1",
97
+ "vitest": "^4.0.18",
98
+ "wrangler": "^4.60.0",
99
99
  "ws": "^8.19.0"
100
100
  },
101
101
  "peerDependencies": {
@@ -106,7 +106,7 @@
106
106
  "optional": true
107
107
  }
108
108
  },
109
- "packageManager": "pnpm@10.28.1",
109
+ "packageManager": "pnpm@10.28.2",
110
110
  "pnpm": {
111
111
  "ignoredBuiltDependencies": [
112
112
  "@parcel/watcher",