crossws 0.3.4 → 0.3.5

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.
package/README.md CHANGED
@@ -9,13 +9,13 @@
9
9
 
10
10
  Elegant, typed, and simple toolkit to implement cross-platform WebSocket servers.
11
11
 
12
- 👉 [📖 documentation](https://crossws.unjs.io)
12
+ 👉 [📖 documentation](https://crossws.h3.dev)
13
13
 
14
14
  ## Features
15
15
 
16
- 🧩 Seamlessly integrates with [Bun](https://crossws.unjs.io/adapters/bun), [Cloudflare Workers](https://crossws.unjs.io/adapters/cloudflare), [Deno](https://crossws.unjs.io/adapters/deno) and [Node.js](https://crossws.unjs.io/adapters/node) and any compatible web framework.
16
+ 🧩 Seamlessly integrates with [Bun](https://crossws.h3.dev/adapters/bun), [Cloudflare Workers](https://crossws.h3.dev/adapters/cloudflare), [Deno](https://crossws.h3.dev/adapters/deno) and [Node.js](https://crossws.h3.dev/adapters/node) and any compatible web framework.
17
17
 
18
- ✅ Prebundled with [ws](https://github.com/websockets/ws) for Node.js support with alternative/much faster [uWebSockets](https://crossws.unjs.io/adapters/node#uwebsockets) adapter.
18
+ ✅ Prebundled with [ws](https://github.com/websockets/ws) for Node.js support with alternative/much faster [uWebSockets](https://crossws.h3.dev/adapters/node#uwebsockets) adapter.
19
19
 
20
20
  📦 Extremely lightweight and tree-shakable conditional ESM exports.
21
21
 
@@ -44,11 +44,11 @@ Elegant, typed, and simple toolkit to implement cross-platform WebSocket servers
44
44
 
45
45
  <!-- automd:contributors license=MIT author="pi0" -->
46
46
 
47
- Published under the [MIT](https://github.com/unjs/crossws/blob/main/LICENSE) license.
48
- Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/crossws/graphs/contributors) 💛
47
+ Published under the [MIT](https://github.com/h3js/crossws/blob/main/LICENSE) license.
48
+ Made by [@pi0](https://github.com/pi0) and [community](https://github.com/h3js/crossws/graphs/contributors) 💛
49
49
  <br><br>
50
- <a href="https://github.com/unjs/crossws/graphs/contributors">
51
- <img src="https://contrib.rocks/image?repo=unjs/crossws" />
50
+ <a href="https://github.com/h3js/crossws/graphs/contributors">
51
+ <img src="https://contrib.rocks/image?repo=h3js/crossws" />
52
52
  </a>
53
53
 
54
54
  <!-- /automd -->
@@ -1,6 +1,6 @@
1
- import { WebSocketHandler, Server, ServerWebSocket } from 'bun';
2
- import { AdapterInstance, AdapterOptions, Peer, Adapter } from '../index.mjs';
3
- import '../shared/crossws.ChIJSJVK.mjs';
1
+ import { WebSocketHandler, ServerWebSocket, Server } from 'bun';
2
+ import { Adapter, AdapterInstance, Peer, AdapterOptions } from '../index.mjs';
3
+ import '../shared/crossws.BQXMA5bH.mjs';
4
4
 
5
5
  interface BunAdapter extends AdapterInstance {
6
6
  websocket: WebSocketHandler<ContextData>;
@@ -35,4 +35,5 @@ declare class BunPeer extends Peer<{
35
35
  terminate(): void;
36
36
  }
37
37
 
38
- export { type BunAdapter, type BunOptions, bunAdapter as default };
38
+ export { bunAdapter as default };
39
+ export type { BunAdapter, BunOptions };
@@ -1,6 +1,6 @@
1
- import { WebSocketHandler, Server, ServerWebSocket } from 'bun';
2
- import { AdapterInstance, AdapterOptions, Peer, Adapter } from '../index.js';
3
- import '../shared/crossws.ChIJSJVK.js';
1
+ import { WebSocketHandler, ServerWebSocket, Server } from 'bun';
2
+ import { Adapter, AdapterInstance, Peer, AdapterOptions } from '../index.js';
3
+ import '../shared/crossws.BQXMA5bH.js';
4
4
 
5
5
  interface BunAdapter extends AdapterInstance {
6
6
  websocket: WebSocketHandler<ContextData>;
@@ -35,4 +35,5 @@ declare class BunPeer extends Peer<{
35
35
  terminate(): void;
36
36
  }
37
37
 
38
- export { type BunAdapter, type BunOptions, bunAdapter as default };
38
+ export { bunAdapter as default };
39
+ export type { BunAdapter, BunOptions };
@@ -1,4 +1,4 @@
1
- import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.BS81iGZK.mjs';
1
+ import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
2
2
  import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
3
3
  import 'uncrypto';
4
4
 
@@ -1,7 +1,7 @@
1
1
  import * as CF from '@cloudflare/workers-types';
2
2
  import { DurableObject } from 'cloudflare:workers';
3
- import { AdapterOptions, Adapter, AdapterInstance } from '../index.mjs';
4
- import { W as WebSocket$1 } from '../shared/crossws.ChIJSJVK.mjs';
3
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
4
+ import { W as WebSocket$1 } from '../shared/crossws.BQXMA5bH.mjs';
5
5
 
6
6
  type ResolveDurableStub = (req: CF.Request, env: unknown, context: CF.ExecutionContext) => CF.DurableObjectStub | Promise<CF.DurableObjectStub>;
7
7
  interface CloudflareOptions extends AdapterOptions {
@@ -38,4 +38,5 @@ interface CloudflareDurableAdapter extends AdapterInstance {
38
38
  handleDurableClose(obj: DurableObject, ws: WebSocket | CF.WebSocket | WebSocket$1, code: number, reason: string, wasClean: boolean): Promise<void>;
39
39
  }
40
40
 
41
- export { type CloudflareDurableAdapter, type CloudflareOptions, cloudflareDurableAdapter as default };
41
+ export { cloudflareDurableAdapter as default };
42
+ export type { CloudflareDurableAdapter, CloudflareOptions };
@@ -1,7 +1,7 @@
1
1
  import * as CF from '@cloudflare/workers-types';
2
2
  import { DurableObject } from 'cloudflare:workers';
3
- import { AdapterOptions, Adapter, AdapterInstance } from '../index.js';
4
- import { W as WebSocket$1 } from '../shared/crossws.ChIJSJVK.js';
3
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
4
+ import { W as WebSocket$1 } from '../shared/crossws.BQXMA5bH.js';
5
5
 
6
6
  type ResolveDurableStub = (req: CF.Request, env: unknown, context: CF.ExecutionContext) => CF.DurableObjectStub | Promise<CF.DurableObjectStub>;
7
7
  interface CloudflareOptions extends AdapterOptions {
@@ -38,4 +38,5 @@ interface CloudflareDurableAdapter extends AdapterInstance {
38
38
  handleDurableClose(obj: DurableObject, ws: WebSocket | CF.WebSocket | WebSocket$1, code: number, reason: string, wasClean: boolean): Promise<void>;
39
39
  }
40
40
 
41
- export { type CloudflareDurableAdapter, type CloudflareOptions, cloudflareDurableAdapter as default };
41
+ export { cloudflareDurableAdapter as default };
42
+ export type { CloudflareDurableAdapter, CloudflareOptions };
@@ -1,4 +1,4 @@
1
- import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.BS81iGZK.mjs';
1
+ import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
2
2
  import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
3
3
  import 'uncrypto';
4
4
 
@@ -1,6 +1,6 @@
1
- import { AdapterInstance, AdapterOptions, Adapter } from '../index.mjs';
1
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
2
2
  import * as CF from '@cloudflare/workers-types';
3
- import '../shared/crossws.ChIJSJVK.mjs';
3
+ import '../shared/crossws.BQXMA5bH.mjs';
4
4
 
5
5
  interface CloudflareAdapter extends AdapterInstance {
6
6
  handleUpgrade(req: CF.Request, env: unknown, context: CF.ExecutionContext): Promise<CF.Response>;
@@ -9,4 +9,5 @@ interface CloudflareOptions extends AdapterOptions {
9
9
  }
10
10
  declare const cloudflareAdapter: Adapter<CloudflareAdapter, CloudflareOptions>;
11
11
 
12
- export { type CloudflareAdapter, type CloudflareOptions, cloudflareAdapter as default };
12
+ export { cloudflareAdapter as default };
13
+ export type { CloudflareAdapter, CloudflareOptions };
@@ -1,6 +1,6 @@
1
- import { AdapterInstance, AdapterOptions, Adapter } from '../index.js';
1
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
2
2
  import * as CF from '@cloudflare/workers-types';
3
- import '../shared/crossws.ChIJSJVK.js';
3
+ import '../shared/crossws.BQXMA5bH.js';
4
4
 
5
5
  interface CloudflareAdapter extends AdapterInstance {
6
6
  handleUpgrade(req: CF.Request, env: unknown, context: CF.ExecutionContext): Promise<CF.Response>;
@@ -9,4 +9,5 @@ interface CloudflareOptions extends AdapterOptions {
9
9
  }
10
10
  declare const cloudflareAdapter: Adapter<CloudflareAdapter, CloudflareOptions>;
11
11
 
12
- export { type CloudflareAdapter, type CloudflareOptions, cloudflareAdapter as default };
12
+ export { cloudflareAdapter as default };
13
+ export type { CloudflareAdapter, CloudflareOptions };
@@ -1,4 +1,4 @@
1
- import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.BS81iGZK.mjs';
1
+ import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
2
2
  import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
3
3
  import { W as WSError } from '../shared/crossws.By9qWDAI.mjs';
4
4
  import 'uncrypto';
@@ -1,5 +1,5 @@
1
- import { AdapterInstance, AdapterOptions, Adapter } from '../index.mjs';
2
- import '../shared/crossws.ChIJSJVK.mjs';
1
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
2
+ import '../shared/crossws.BQXMA5bH.mjs';
3
3
 
4
4
  interface DenoAdapter extends AdapterInstance {
5
5
  handleUpgrade(req: Request, info: ServeHandlerInfo): Promise<Response>;
@@ -15,4 +15,5 @@ type ServeHandlerInfo = {
15
15
  };
16
16
  declare const denoAdapter: Adapter<DenoAdapter, DenoOptions>;
17
17
 
18
- export { type DenoAdapter, type DenoOptions, denoAdapter as default };
18
+ export { denoAdapter as default };
19
+ export type { DenoAdapter, DenoOptions };
@@ -1,5 +1,5 @@
1
- import { AdapterInstance, AdapterOptions, Adapter } from '../index.js';
2
- import '../shared/crossws.ChIJSJVK.js';
1
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
2
+ import '../shared/crossws.BQXMA5bH.js';
3
3
 
4
4
  interface DenoAdapter extends AdapterInstance {
5
5
  handleUpgrade(req: Request, info: ServeHandlerInfo): Promise<Response>;
@@ -15,4 +15,5 @@ type ServeHandlerInfo = {
15
15
  };
16
16
  declare const denoAdapter: Adapter<DenoAdapter, DenoOptions>;
17
17
 
18
- export { type DenoAdapter, type DenoOptions, denoAdapter as default };
18
+ export { denoAdapter as default };
19
+ export type { DenoAdapter, DenoOptions };
@@ -1,4 +1,4 @@
1
- import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.BS81iGZK.mjs';
1
+ import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
2
2
  import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
3
3
  import { W as WSError } from '../shared/crossws.By9qWDAI.mjs';
4
4
  import 'uncrypto';
@@ -1,12 +1,12 @@
1
- import { AdapterInstance, AdapterOptions, Adapter } from '../index.mjs';
2
- import { IncomingMessage, Server as Server$1, ClientRequestArgs, ClientRequest, OutgoingHttpHeaders, Agent } from 'node:http';
3
- import { Duplex, DuplexOptions } from 'node:stream';
1
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
2
+ import { Agent, ClientRequestArgs, IncomingMessage, ClientRequest, Server as Server$1, OutgoingHttpHeaders } from 'node:http';
3
+ import { DuplexOptions, Duplex } from 'node:stream';
4
4
  import { EventEmitter } from 'events';
5
5
  import { Server as Server$2 } from 'node:https';
6
6
  import { SecureContextOptions } from 'node:tls';
7
7
  import { URL } from 'node:url';
8
8
  import { ZlibOptions } from 'node:zlib';
9
- import '../shared/crossws.ChIJSJVK.mjs';
9
+ import '../shared/crossws.BQXMA5bH.mjs';
10
10
 
11
11
  type BufferLike = string | Buffer | DataView | number | ArrayBufferView | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly any[] | readonly number[] | {
12
12
  valueOf(): ArrayBuffer;
@@ -286,8 +286,8 @@ type WebSocketServer = Server;
286
286
  declare function createWebSocketStream(websocket: WebSocket, options?: DuplexOptions): Duplex;
287
287
 
288
288
  interface NodeAdapter extends AdapterInstance {
289
- handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer): void;
290
- closeAll: (code?: number, data?: string | Buffer) => void;
289
+ handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer): Promise<void>;
290
+ closeAll: (code?: number, data?: string | Buffer, force?: boolean) => void;
291
291
  }
292
292
  interface NodeOptions extends AdapterOptions {
293
293
  wss?: WebSocketServer;
@@ -295,4 +295,5 @@ interface NodeOptions extends AdapterOptions {
295
295
  }
296
296
  declare const nodeAdapter: Adapter<NodeAdapter, NodeOptions>;
297
297
 
298
- export { type NodeAdapter, type NodeOptions, nodeAdapter as default };
298
+ export { nodeAdapter as default };
299
+ export type { NodeAdapter, NodeOptions };
@@ -1,12 +1,12 @@
1
- import { AdapterInstance, AdapterOptions, Adapter } from '../index.js';
2
- import { IncomingMessage, Server as Server$1, ClientRequestArgs, ClientRequest, OutgoingHttpHeaders, Agent } from 'node:http';
3
- import { Duplex, DuplexOptions } from 'node:stream';
1
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
2
+ import { Agent, ClientRequestArgs, IncomingMessage, ClientRequest, Server as Server$1, OutgoingHttpHeaders } from 'node:http';
3
+ import { DuplexOptions, Duplex } from 'node:stream';
4
4
  import { EventEmitter } from 'events';
5
5
  import { Server as Server$2 } from 'node:https';
6
6
  import { SecureContextOptions } from 'node:tls';
7
7
  import { URL } from 'node:url';
8
8
  import { ZlibOptions } from 'node:zlib';
9
- import '../shared/crossws.ChIJSJVK.js';
9
+ import '../shared/crossws.BQXMA5bH.js';
10
10
 
11
11
  type BufferLike = string | Buffer | DataView | number | ArrayBufferView | Uint8Array | ArrayBuffer | SharedArrayBuffer | readonly any[] | readonly number[] | {
12
12
  valueOf(): ArrayBuffer;
@@ -286,8 +286,8 @@ type WebSocketServer = Server;
286
286
  declare function createWebSocketStream(websocket: WebSocket, options?: DuplexOptions): Duplex;
287
287
 
288
288
  interface NodeAdapter extends AdapterInstance {
289
- handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer): void;
290
- closeAll: (code?: number, data?: string | Buffer) => void;
289
+ handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer): Promise<void>;
290
+ closeAll: (code?: number, data?: string | Buffer, force?: boolean) => void;
291
291
  }
292
292
  interface NodeOptions extends AdapterOptions {
293
293
  wss?: WebSocketServer;
@@ -295,4 +295,5 @@ interface NodeOptions extends AdapterOptions {
295
295
  }
296
296
  declare const nodeAdapter: Adapter<NodeAdapter, NodeOptions>;
297
297
 
298
- export { type NodeAdapter, type NodeOptions, nodeAdapter as default };
298
+ export { nodeAdapter as default };
299
+ export type { NodeAdapter, NodeOptions };
@@ -1,9 +1,9 @@
1
- import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.BS81iGZK.mjs';
2
- import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
1
+ import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
2
+ import { A as AdapterHookable, a as adapterUtils } from '../shared/crossws.D9ehKjSh.mjs';
3
3
  import { W as WSError } from '../shared/crossws.By9qWDAI.mjs';
4
- import 'stream';
5
- import { _ as _WebSocketServer } from '../shared/crossws.DelSCW9g.mjs';
4
+ import { _ as _WebSocketServer } from '../shared/crossws.CipVM6lf.mjs';
6
5
  import 'uncrypto';
6
+ import 'stream';
7
7
  import 'events';
8
8
  import 'http';
9
9
  import 'crypto';
@@ -67,9 +67,13 @@ const nodeAdapter = (options = {}) => {
67
67
  wss.emit("connection", ws, nodeReq);
68
68
  });
69
69
  },
70
- closeAll: (code, data) => {
70
+ closeAll: (code, data, force) => {
71
71
  for (const client of wss.clients) {
72
- client.close(code, data);
72
+ if (force) {
73
+ client.terminate();
74
+ } else {
75
+ client.close(code, data);
76
+ }
73
77
  }
74
78
  }
75
79
  };
@@ -149,7 +153,10 @@ async function sendResponse(socket, res) {
149
153
  }
150
154
  }
151
155
  return new Promise((resolve) => {
152
- socket.end(resolve);
156
+ socket.end(() => {
157
+ socket.destroy();
158
+ resolve();
159
+ });
153
160
  });
154
161
  }
155
162
 
@@ -1,5 +1,5 @@
1
- import { AdapterInstance, AdapterOptions, Adapter } from '../index.mjs';
2
- import '../shared/crossws.ChIJSJVK.mjs';
1
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.mjs';
2
+ import '../shared/crossws.BQXMA5bH.mjs';
3
3
 
4
4
  interface SSEAdapter extends AdapterInstance {
5
5
  fetch(req: Request): Promise<Response>;
@@ -9,4 +9,5 @@ interface SSEOptions extends AdapterOptions {
9
9
  }
10
10
  declare const sseAdapter: Adapter<SSEAdapter, SSEOptions>;
11
11
 
12
- export { type SSEAdapter, type SSEOptions, sseAdapter as default };
12
+ export { sseAdapter as default };
13
+ export type { SSEAdapter, SSEOptions };
@@ -1,5 +1,5 @@
1
- import { AdapterInstance, AdapterOptions, Adapter } from '../index.js';
2
- import '../shared/crossws.ChIJSJVK.js';
1
+ import { Adapter, AdapterInstance, AdapterOptions } from '../index.js';
2
+ import '../shared/crossws.BQXMA5bH.js';
3
3
 
4
4
  interface SSEAdapter extends AdapterInstance {
5
5
  fetch(req: Request): Promise<Response>;
@@ -9,4 +9,5 @@ interface SSEOptions extends AdapterOptions {
9
9
  }
10
10
  declare const sseAdapter: Adapter<SSEAdapter, SSEOptions>;
11
11
 
12
- export { type SSEAdapter, type SSEOptions, sseAdapter as default };
12
+ export { sseAdapter as default };
13
+ export type { SSEAdapter, SSEOptions };
@@ -1,11 +1,11 @@
1
- import { M as Message, P as Peer, a as toString } from '../shared/crossws.BS81iGZK.mjs';
1
+ import { M as Message, P as Peer, a as toString } from '../shared/crossws.DfCzGthR.mjs';
2
2
  import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
3
3
  import 'uncrypto';
4
4
 
5
5
  const sseAdapter = (opts = {}) => {
6
6
  const hooks = new AdapterHookable(opts);
7
7
  const peers = /* @__PURE__ */ new Set();
8
- const peersMap = opts.bidir ? /* @__PURE__ */ new Map() : undefined;
8
+ const peersMap = opts.bidir ? /* @__PURE__ */ new Map() : void 0;
9
9
  return {
10
10
  ...adapterUtils(peers),
11
11
  fetch: async (request) => {
@@ -1,5 +1,5 @@
1
- import { AdapterInstance, AdapterOptions, Adapter, Peer } from '../index.mjs';
2
- import { W as WebSocket } from '../shared/crossws.ChIJSJVK.mjs';
1
+ import { Adapter, AdapterInstance, Peer, AdapterOptions } from '../index.mjs';
2
+ import { W as WebSocket } from '../shared/crossws.BQXMA5bH.mjs';
3
3
  import uws from 'uWebSockets.js';
4
4
 
5
5
  type UserData = {
@@ -55,4 +55,5 @@ declare class UwsWebSocketProxy implements Partial<WebSocket> {
55
55
  get extensions(): string;
56
56
  }
57
57
 
58
- export { type UWSAdapter, type UWSOptions, uwsAdapter as default };
58
+ export { uwsAdapter as default };
59
+ export type { UWSAdapter, UWSOptions };
@@ -1,5 +1,5 @@
1
- import { AdapterInstance, AdapterOptions, Adapter, Peer } from '../index.js';
2
- import { W as WebSocket } from '../shared/crossws.ChIJSJVK.js';
1
+ import { Adapter, AdapterInstance, Peer, AdapterOptions } from '../index.js';
2
+ import { W as WebSocket } from '../shared/crossws.BQXMA5bH.js';
3
3
  import uws from 'uWebSockets.js';
4
4
 
5
5
  type UserData = {
@@ -55,4 +55,5 @@ declare class UwsWebSocketProxy implements Partial<WebSocket> {
55
55
  get extensions(): string;
56
56
  }
57
57
 
58
- export { type UWSAdapter, type UWSOptions, uwsAdapter as default };
58
+ export { uwsAdapter as default };
59
+ export type { UWSAdapter, UWSOptions };
@@ -1,4 +1,4 @@
1
- import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.BS81iGZK.mjs';
1
+ import { M as Message, P as Peer, t as toBufferLike } from '../shared/crossws.DfCzGthR.mjs';
2
2
  import { a as adapterUtils, A as AdapterHookable } from '../shared/crossws.D9ehKjSh.mjs';
3
3
  import 'uncrypto';
4
4
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { W as WebSocket } from './shared/crossws.ChIJSJVK.mjs';
1
+ import { W as WebSocket } from './shared/crossws.BQXMA5bH.mjs';
2
2
 
3
3
  declare const kNodeInspect: unique symbol;
4
4
 
@@ -153,4 +153,5 @@ interface Hooks {
153
153
  error: (peer: Peer, error: WSError) => MaybePromise<void>;
154
154
  }
155
155
 
156
- export { type Adapter, type AdapterInstance, type AdapterOptions, type Hooks, Message, Peer, type ResolveHooks, WSError, defineHooks, defineWebSocketAdapter };
156
+ export { Message, Peer, WSError, defineHooks, defineWebSocketAdapter };
157
+ export type { Adapter, AdapterInstance, AdapterInternal, AdapterOptions, Hooks, ResolveHooks };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { W as WebSocket } from './shared/crossws.ChIJSJVK.js';
1
+ import { W as WebSocket } from './shared/crossws.BQXMA5bH.js';
2
2
 
3
3
  declare const kNodeInspect: unique symbol;
4
4
 
@@ -153,4 +153,5 @@ interface Hooks {
153
153
  error: (peer: Peer, error: WSError) => MaybePromise<void>;
154
154
  }
155
155
 
156
- export { type Adapter, type AdapterInstance, type AdapterOptions, type Hooks, Message, Peer, type ResolveHooks, WSError, defineHooks, defineWebSocketAdapter };
156
+ export { Message, Peer, WSError, defineHooks, defineWebSocketAdapter };
157
+ export type { Adapter, AdapterInstance, AdapterInternal, AdapterOptions, Hooks, ResolveHooks };
@@ -294,4 +294,4 @@ interface WebSocket extends EventTarget {
294
294
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
295
295
  }
296
296
 
297
- export type { CloseEvent as C, Event as E, MessageEvent as M, WebSocket as W, EventTarget as a };
297
+ export type { CloseEvent as C, EventTarget as E, MessageEvent as M, WebSocket as W, Event as a };
@@ -294,4 +294,4 @@ interface WebSocket extends EventTarget {
294
294
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
295
295
  }
296
296
 
297
- export type { CloseEvent as C, Event as E, MessageEvent as M, WebSocket as W, EventTarget as a };
297
+ export type { CloseEvent as C, EventTarget as E, MessageEvent as M, WebSocket as W, Event as a };
@@ -1,6 +1,6 @@
1
+ import require$$0$2 from 'stream';
1
2
  import require$$0$3 from 'events';
2
3
  import require$$2 from 'http';
3
- import require$$0$2 from 'stream';
4
4
  import require$$1 from 'crypto';
5
5
  import require$$0$1 from 'buffer';
6
6
  import require$$0 from 'zlib';
@@ -743,6 +743,14 @@ function requirePermessageDeflate () {
743
743
  this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
744
744
  this[kError][kStatusCode] = 1009;
745
745
  this.removeListener('data', inflateOnData);
746
+
747
+ //
748
+ // The choice to employ `zlib.reset()` over `zlib.close()` is dictated by the
749
+ // fact that in Node.js versions prior to 13.10.0, the callback for
750
+ // `zlib.flush()` is not called if `zlib.close()` is used. Utilizing
751
+ // `zlib.reset()` ensures that either the callback is invoked or an error is
752
+ // emitted.
753
+ //
746
754
  this.reset();
747
755
  }
748
756
 
@@ -758,6 +766,12 @@ function requirePermessageDeflate () {
758
766
  // closed when an error is emitted.
759
767
  //
760
768
  this[kPerMessageDeflate]._inflate = null;
769
+
770
+ if (this[kError]) {
771
+ this[kCallback](this[kError]);
772
+ return;
773
+ }
774
+
761
775
  err[kStatusCode] = 1007;
762
776
  this[kCallback](err);
763
777
  }
@@ -1639,8 +1653,6 @@ function requireReceiver () {
1639
1653
  return receiver;
1640
1654
  }
1641
1655
 
1642
- requireReceiver();
1643
-
1644
1656
  /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex" }] */
1645
1657
 
1646
1658
  var sender;
@@ -1649,6 +1661,8 @@ var hasRequiredSender;
1649
1661
  function requireSender () {
1650
1662
  if (hasRequiredSender) return sender;
1651
1663
  hasRequiredSender = 1;
1664
+
1665
+ const { Duplex } = require$$0$2;
1652
1666
  const { randomFillSync } = require$$1;
1653
1667
 
1654
1668
  const PerMessageDeflate = requirePermessageDeflate();
@@ -2197,7 +2211,7 @@ function requireSender () {
2197
2211
  /**
2198
2212
  * Sends a frame.
2199
2213
  *
2200
- * @param {Buffer[]} list The frame to send
2214
+ * @param {(Buffer | String)[]} list The frame to send
2201
2215
  * @param {Function} [cb] Callback
2202
2216
  * @private
2203
2217
  */
@@ -2249,8 +2263,6 @@ function requireSender () {
2249
2263
  return sender;
2250
2264
  }
2251
2265
 
2252
- requireSender();
2253
-
2254
2266
  var eventTarget;
2255
2267
  var hasRequiredEventTarget;
2256
2268
 
@@ -2777,6 +2789,7 @@ function requireWebsocket () {
2777
2789
  const net = require$$3;
2778
2790
  const tls = require$$4;
2779
2791
  const { randomBytes, createHash } = require$$1;
2792
+ const { Duplex, Readable } = require$$0$2;
2780
2793
  const { URL } = require$$7;
2781
2794
 
2782
2795
  const PerMessageDeflate = requirePermessageDeflate();
@@ -3476,7 +3489,7 @@ function requireWebsocket () {
3476
3489
  if (parsedUrl.protocol !== 'ws:' && !isSecure && !isIpcUrl) {
3477
3490
  invalidUrlMessage =
3478
3491
  'The URL\'s protocol must be one of "ws:", "wss:", ' +
3479
- '"http:", "https", or "ws+unix:"';
3492
+ '"http:", "https:", or "ws+unix:"';
3480
3493
  } else if (isIpcUrl && !parsedUrl.pathname) {
3481
3494
  invalidUrlMessage = "The URL's pathname is empty";
3482
3495
  } else if (parsedUrl.hash) {
@@ -4157,6 +4170,182 @@ function requireWebsocket () {
4157
4170
  return websocket;
4158
4171
  }
4159
4172
 
4173
+ /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^WebSocket$" }] */
4174
+
4175
+ var stream;
4176
+ var hasRequiredStream;
4177
+
4178
+ function requireStream () {
4179
+ if (hasRequiredStream) return stream;
4180
+ hasRequiredStream = 1;
4181
+
4182
+ requireWebsocket();
4183
+ const { Duplex } = require$$0$2;
4184
+
4185
+ /**
4186
+ * Emits the `'close'` event on a stream.
4187
+ *
4188
+ * @param {Duplex} stream The stream.
4189
+ * @private
4190
+ */
4191
+ function emitClose(stream) {
4192
+ stream.emit('close');
4193
+ }
4194
+
4195
+ /**
4196
+ * The listener of the `'end'` event.
4197
+ *
4198
+ * @private
4199
+ */
4200
+ function duplexOnEnd() {
4201
+ if (!this.destroyed && this._writableState.finished) {
4202
+ this.destroy();
4203
+ }
4204
+ }
4205
+
4206
+ /**
4207
+ * The listener of the `'error'` event.
4208
+ *
4209
+ * @param {Error} err The error
4210
+ * @private
4211
+ */
4212
+ function duplexOnError(err) {
4213
+ this.removeListener('error', duplexOnError);
4214
+ this.destroy();
4215
+ if (this.listenerCount('error') === 0) {
4216
+ // Do not suppress the throwing behavior.
4217
+ this.emit('error', err);
4218
+ }
4219
+ }
4220
+
4221
+ /**
4222
+ * Wraps a `WebSocket` in a duplex stream.
4223
+ *
4224
+ * @param {WebSocket} ws The `WebSocket` to wrap
4225
+ * @param {Object} [options] The options for the `Duplex` constructor
4226
+ * @return {Duplex} The duplex stream
4227
+ * @public
4228
+ */
4229
+ function createWebSocketStream(ws, options) {
4230
+ let terminateOnDestroy = true;
4231
+
4232
+ const duplex = new Duplex({
4233
+ ...options,
4234
+ autoDestroy: false,
4235
+ emitClose: false,
4236
+ objectMode: false,
4237
+ writableObjectMode: false
4238
+ });
4239
+
4240
+ ws.on('message', function message(msg, isBinary) {
4241
+ const data =
4242
+ !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
4243
+
4244
+ if (!duplex.push(data)) ws.pause();
4245
+ });
4246
+
4247
+ ws.once('error', function error(err) {
4248
+ if (duplex.destroyed) return;
4249
+
4250
+ // Prevent `ws.terminate()` from being called by `duplex._destroy()`.
4251
+ //
4252
+ // - If the `'error'` event is emitted before the `'open'` event, then
4253
+ // `ws.terminate()` is a noop as no socket is assigned.
4254
+ // - Otherwise, the error is re-emitted by the listener of the `'error'`
4255
+ // event of the `Receiver` object. The listener already closes the
4256
+ // connection by calling `ws.close()`. This allows a close frame to be
4257
+ // sent to the other peer. If `ws.terminate()` is called right after this,
4258
+ // then the close frame might not be sent.
4259
+ terminateOnDestroy = false;
4260
+ duplex.destroy(err);
4261
+ });
4262
+
4263
+ ws.once('close', function close() {
4264
+ if (duplex.destroyed) return;
4265
+
4266
+ duplex.push(null);
4267
+ });
4268
+
4269
+ duplex._destroy = function (err, callback) {
4270
+ if (ws.readyState === ws.CLOSED) {
4271
+ callback(err);
4272
+ process.nextTick(emitClose, duplex);
4273
+ return;
4274
+ }
4275
+
4276
+ let called = false;
4277
+
4278
+ ws.once('error', function error(err) {
4279
+ called = true;
4280
+ callback(err);
4281
+ });
4282
+
4283
+ ws.once('close', function close() {
4284
+ if (!called) callback(err);
4285
+ process.nextTick(emitClose, duplex);
4286
+ });
4287
+
4288
+ if (terminateOnDestroy) ws.terminate();
4289
+ };
4290
+
4291
+ duplex._final = function (callback) {
4292
+ if (ws.readyState === ws.CONNECTING) {
4293
+ ws.once('open', function open() {
4294
+ duplex._final(callback);
4295
+ });
4296
+ return;
4297
+ }
4298
+
4299
+ // If the value of the `_socket` property is `null` it means that `ws` is a
4300
+ // client websocket and the handshake failed. In fact, when this happens, a
4301
+ // socket is never assigned to the websocket. Wait for the `'error'` event
4302
+ // that will be emitted by the websocket.
4303
+ if (ws._socket === null) return;
4304
+
4305
+ if (ws._socket._writableState.finished) {
4306
+ callback();
4307
+ if (duplex._readableState.endEmitted) duplex.destroy();
4308
+ } else {
4309
+ ws._socket.once('finish', function finish() {
4310
+ // `duplex` is not destroyed here because the `'end'` event will be
4311
+ // emitted on `duplex` after this `'finish'` event. The EOF signaling
4312
+ // `null` chunk is, in fact, pushed when the websocket emits `'close'`.
4313
+ callback();
4314
+ });
4315
+ ws.close();
4316
+ }
4317
+ };
4318
+
4319
+ duplex._read = function () {
4320
+ if (ws.isPaused) ws.resume();
4321
+ };
4322
+
4323
+ duplex._write = function (chunk, encoding, callback) {
4324
+ if (ws.readyState === ws.CONNECTING) {
4325
+ ws.once('open', function open() {
4326
+ duplex._write(chunk, encoding, callback);
4327
+ });
4328
+ return;
4329
+ }
4330
+
4331
+ ws.send(chunk, callback);
4332
+ };
4333
+
4334
+ duplex.on('end', duplexOnEnd);
4335
+ duplex.on('error', duplexOnError);
4336
+ return duplex;
4337
+ }
4338
+
4339
+ stream = createWebSocketStream;
4340
+ return stream;
4341
+ }
4342
+
4343
+ requireStream();
4344
+
4345
+ requireReceiver();
4346
+
4347
+ requireSender();
4348
+
4160
4349
  var websocketExports = requireWebsocket();
4161
4350
  const _WebSocket = /*@__PURE__*/getDefaultExportFromCjs(websocketExports);
4162
4351
 
@@ -4241,6 +4430,7 @@ function requireWebsocketServer () {
4241
4430
 
4242
4431
  const EventEmitter = require$$0$3;
4243
4432
  const http = require$$2;
4433
+ const { Duplex } = require$$0$2;
4244
4434
  const { createHash } = require$$1;
4245
4435
 
4246
4436
  const extension = requireExtension();
@@ -4,7 +4,7 @@ const kNodeInspect = /* @__PURE__ */ Symbol.for(
4
4
  "nodejs.util.inspect.custom"
5
5
  );
6
6
  function toBufferLike(val) {
7
- if (val === undefined || val === null) {
7
+ if (val === void 0 || val === null) {
8
8
  return "";
9
9
  }
10
10
  const type = typeof val;
@@ -237,7 +237,7 @@ class Peer {
237
237
  }
238
238
  /** IP address of the peer */
239
239
  get remoteAddress() {
240
- return undefined;
240
+ return void 0;
241
241
  }
242
242
  /** upgrade request */
243
243
  get request() {
@@ -313,7 +313,7 @@ function createWsProxy(ws, request) {
313
313
  return request?.headers?.get("sec-websocket-extensions") || "";
314
314
  }
315
315
  case "url": {
316
- return request?.url?.replace(/^http/, "ws") || undefined;
316
+ return request?.url?.replace(/^http/, "ws") || void 0;
317
317
  }
318
318
  }
319
319
  }
@@ -1,5 +1,5 @@
1
+ import { a as _WebSocket } from '../shared/crossws.CipVM6lf.mjs';
1
2
  import 'stream';
2
- import { a as _WebSocket } from '../shared/crossws.DelSCW9g.mjs';
3
3
  import 'events';
4
4
  import 'http';
5
5
  import 'crypto';
@@ -1,4 +1,4 @@
1
- import { W as WebSocket, C as CloseEvent, E as Event, M as MessageEvent, a as EventTarget } from '../shared/crossws.ChIJSJVK.mjs';
1
+ import { E as EventTarget, W as WebSocket, C as CloseEvent, a as Event, M as MessageEvent } from '../shared/crossws.BQXMA5bH.mjs';
2
2
 
3
3
  type Ctor<T> = {
4
4
  prototype: T;
@@ -38,4 +38,5 @@ declare class WebSocketSSE extends _EventTarget implements WebSocket {
38
38
  send(data: any): Promise<void>;
39
39
  }
40
40
 
41
- export { WebSocketSSE, type WebSocketSSEOptions };
41
+ export { WebSocketSSE };
42
+ export type { WebSocketSSEOptions };
@@ -1,4 +1,4 @@
1
- import { W as WebSocket, C as CloseEvent, E as Event, M as MessageEvent, a as EventTarget } from '../shared/crossws.ChIJSJVK.js';
1
+ import { E as EventTarget, W as WebSocket, C as CloseEvent, a as Event, M as MessageEvent } from '../shared/crossws.BQXMA5bH.js';
2
2
 
3
3
  type Ctor<T> = {
4
4
  prototype: T;
@@ -38,4 +38,5 @@ declare class WebSocketSSE extends _EventTarget implements WebSocket {
38
38
  send(data: any): Promise<void>;
39
39
  }
40
40
 
41
- export { WebSocketSSE, type WebSocketSSEOptions };
41
+ export { WebSocketSSE };
42
+ export type { WebSocketSSEOptions };
@@ -70,7 +70,7 @@ class WebSocketSSE extends _EventTarget {
70
70
  this.#sendController = controller;
71
71
  },
72
72
  cancel: () => {
73
- this.#sendController = undefined;
73
+ this.#sendController = void 0;
74
74
  }
75
75
  }).pipeThrough(new TextEncoderStream())
76
76
  }).catch(() => {
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "crossws",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Cross-platform WebSocket Servers for Node.js, Deno, Bun and Cloudflare Workers",
5
- "repository": "unjs/crossws",
5
+ "repository": "h3js/crossws",
6
+ "homepage": "https://crossws.h3.dev",
6
7
  "license": "MIT",
7
8
  "sideEffects": false,
8
9
  "type": "module",
@@ -87,33 +88,40 @@
87
88
  "uncrypto": "^0.1.3"
88
89
  },
89
90
  "devDependencies": {
90
- "@cloudflare/workers-types": "^4.20250204.0",
91
- "@types/bun": "^1.2.2",
92
- "@types/deno": "^2.0.0",
93
- "@types/eventsource": "^1.1.15",
94
- "@types/node": "^22.13.1",
95
- "@types/web": "^0.0.202",
96
- "@types/ws": "^8.5.14",
97
- "@vitest/coverage-v8": "^3.0.5",
98
- "automd": "^0.3.12",
99
- "changelogen": "^0.5.7",
100
- "consola": "^3.4.0",
101
- "eslint": "^9.20.0",
91
+ "@cloudflare/workers-types": "^4.20250506.0",
92
+ "@types/bun": "^1.2.12",
93
+ "@types/deno": "^2.3.0",
94
+ "@types/node": "^22.15.14",
95
+ "@types/web": "^0.0.232",
96
+ "@types/ws": "^8.18.1",
97
+ "@vitest/coverage-v8": "^3.1.3",
98
+ "automd": "^0.4.0",
99
+ "changelogen": "^0.6.1",
100
+ "consola": "^3.4.2",
101
+ "eslint": "^9.26.0",
102
102
  "eslint-config-unjs": "^0.4.2",
103
- "eventsource": "^3.0.5",
103
+ "eventsource": "^3.0.6",
104
104
  "execa": "^9.5.2",
105
105
  "get-port-please": "^3.1.2",
106
- "h3": "^1.15.0",
106
+ "h3": "^1.15.3",
107
107
  "jiti": "^2.4.2",
108
108
  "listhen": "^1.9.0",
109
- "prettier": "^3.5.0",
110
- "typescript": "^5.7.3",
109
+ "prettier": "^3.5.3",
110
+ "typescript": "^5.8.3",
111
111
  "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.44.0",
112
- "unbuild": "^3.3.1",
113
- "undici": "^7.3.0",
114
- "vitest": "^3.0.5",
115
- "wrangler": "^3.107.3",
116
- "ws": "^8.18.0"
112
+ "unbuild": "^3.5.0",
113
+ "undici": "^7.8.0",
114
+ "vitest": "^3.1.3",
115
+ "wrangler": "^4.14.1",
116
+ "ws": "^8.18.2"
117
117
  },
118
- "packageManager": "pnpm@10.2.1"
118
+ "packageManager": "pnpm@10.10.0",
119
+ "pnpm": {
120
+ "ignoredBuiltDependencies": [
121
+ "@parcel/watcher",
122
+ "esbuild",
123
+ "sharp",
124
+ "workerd"
125
+ ]
126
+ }
119
127
  }