crossws 0.4.2 → 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.
- package/dist/_chunks/_request.mjs +83 -0
- package/dist/_chunks/_types.d.mts +24 -0
- package/dist/_chunks/adapter.d.mts +174 -0
- package/dist/_chunks/adapter.mjs +93 -0
- package/dist/_chunks/bun.d.mts +38 -0
- package/dist/_chunks/cloudflare.d.mts +45 -0
- package/dist/_chunks/deno.d.mts +17 -0
- package/dist/_chunks/error.mjs +10 -0
- package/dist/_chunks/libs/ws.mjs +3531 -0
- package/dist/_chunks/node.d.mts +299 -0
- package/dist/_chunks/peer.mjs +244 -0
- package/dist/_chunks/rolldown-runtime.mjs +32 -0
- package/dist/_chunks/sse.d.mts +12 -0
- package/dist/_chunks/web.d.mts +298 -0
- package/dist/adapters/bun.d.mts +2 -41
- package/dist/adapters/bun.mjs +83 -93
- package/dist/adapters/cloudflare.d.mts +2 -46
- package/dist/adapters/cloudflare.mjs +173 -219
- package/dist/adapters/deno.d.mts +2 -19
- package/dist/adapters/deno.mjs +65 -74
- package/dist/adapters/node.d.mts +2 -299
- package/dist/adapters/node.mjs +119 -156
- package/dist/adapters/sse.d.mts +2 -13
- package/dist/adapters/sse.mjs +98 -118
- package/dist/adapters/uws.d.mts +44 -44
- package/dist/adapters/uws.mjs +152 -175
- package/dist/index.d.mts +2 -170
- package/dist/index.mjs +3 -1
- package/dist/server/bun.d.mts +8 -21
- package/dist/server/bun.mjs +24 -31
- package/dist/server/cloudflare.d.mts +8 -21
- package/dist/server/cloudflare.mjs +21 -30
- package/dist/server/default.d.mts +8 -21
- package/dist/server/default.mjs +22 -26
- package/dist/server/deno.d.mts +8 -21
- package/dist/server/deno.mjs +21 -24
- package/dist/server/node.d.mts +8 -21
- package/dist/server/node.mjs +32 -43
- package/dist/websocket/native.d.mts +3 -2
- package/dist/websocket/native.mjs +4 -1
- package/dist/websocket/node.d.mts +3 -2
- package/dist/websocket/node.mjs +7 -13
- package/dist/websocket/sse.d.mts +34 -34
- package/dist/websocket/sse.mjs +112 -121
- package/package.json +14 -13
- package/dist/shared/crossws.B31KJMcF.mjs +0 -83
- package/dist/shared/crossws.BQXMA5bH.d.mts +0 -297
- package/dist/shared/crossws.By9qWDAI.mjs +0 -8
- package/dist/shared/crossws.C5pESzqN.mjs +0 -4993
- package/dist/shared/crossws.CP-89VBK.d.mts +0 -23
- package/dist/shared/crossws.CPlNx7g8.mjs +0 -105
- package/dist/shared/crossws.WpyOHUXc.mjs +0 -330
package/dist/index.d.mts
CHANGED
|
@@ -1,170 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare const kNodeInspect: unique symbol;
|
|
4
|
-
|
|
5
|
-
interface PeerContext extends Record<string, unknown> {
|
|
6
|
-
}
|
|
7
|
-
interface AdapterInternal {
|
|
8
|
-
ws: unknown;
|
|
9
|
-
request: Request;
|
|
10
|
-
namespace: string;
|
|
11
|
-
peers?: Set<Peer>;
|
|
12
|
-
context?: PeerContext;
|
|
13
|
-
}
|
|
14
|
-
declare abstract class Peer<Internal extends AdapterInternal = AdapterInternal> {
|
|
15
|
-
#private;
|
|
16
|
-
protected _internal: Internal;
|
|
17
|
-
protected _topics: Set<string>;
|
|
18
|
-
protected _id?: string;
|
|
19
|
-
constructor(internal: Internal);
|
|
20
|
-
get context(): PeerContext;
|
|
21
|
-
get namespace(): string;
|
|
22
|
-
/**
|
|
23
|
-
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the peer.
|
|
24
|
-
*/
|
|
25
|
-
get id(): string;
|
|
26
|
-
/** IP address of the peer */
|
|
27
|
-
get remoteAddress(): string | undefined;
|
|
28
|
-
/** upgrade request */
|
|
29
|
-
get request(): Request;
|
|
30
|
-
/**
|
|
31
|
-
* Get the [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance.
|
|
32
|
-
*
|
|
33
|
-
* **Note:** crossws adds polyfill for the following properties if native values are not available:
|
|
34
|
-
* - `protocol`: Extracted from the `sec-websocket-protocol` header.
|
|
35
|
-
* - `extensions`: Extracted from the `sec-websocket-extensions` header.
|
|
36
|
-
* - `url`: Extracted from the request URL (http -> ws).
|
|
37
|
-
* */
|
|
38
|
-
get websocket(): Partial<WebSocket>;
|
|
39
|
-
/** All connected peers to the server */
|
|
40
|
-
get peers(): Set<Peer>;
|
|
41
|
-
/** All topics, this peer has been subscribed to. */
|
|
42
|
-
get topics(): Set<string>;
|
|
43
|
-
abstract close(code?: number, reason?: string): void;
|
|
44
|
-
/** Abruptly close the connection */
|
|
45
|
-
terminate(): void;
|
|
46
|
-
/** Subscribe to a topic */
|
|
47
|
-
subscribe(topic: string): void;
|
|
48
|
-
/** Unsubscribe from a topic */
|
|
49
|
-
unsubscribe(topic: string): void;
|
|
50
|
-
/** Send a message to the peer. */
|
|
51
|
-
abstract send(data: unknown, options?: {
|
|
52
|
-
compress?: boolean;
|
|
53
|
-
}): number | void | undefined;
|
|
54
|
-
/** Send message to subscribes of topic */
|
|
55
|
-
abstract publish(topic: string, data: unknown, options?: {
|
|
56
|
-
compress?: boolean;
|
|
57
|
-
}): void;
|
|
58
|
-
toString(): string;
|
|
59
|
-
[Symbol.toPrimitive](): string;
|
|
60
|
-
[Symbol.toStringTag](): "WebSocket";
|
|
61
|
-
[kNodeInspect](): unknown;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
interface AdapterInstance {
|
|
65
|
-
readonly peers: Map<string, Set<Peer>>;
|
|
66
|
-
readonly publish: (topic: string, data: unknown, options?: {
|
|
67
|
-
compress?: boolean;
|
|
68
|
-
namespace?: string;
|
|
69
|
-
}) => void;
|
|
70
|
-
}
|
|
71
|
-
interface AdapterOptions {
|
|
72
|
-
resolve?: ResolveHooks;
|
|
73
|
-
getNamespace?: (request: Request) => string;
|
|
74
|
-
hooks?: Partial<Hooks>;
|
|
75
|
-
}
|
|
76
|
-
type Adapter<AdapterT extends AdapterInstance = AdapterInstance, Options extends AdapterOptions = AdapterOptions> = (options?: Options) => AdapterT;
|
|
77
|
-
declare function defineWebSocketAdapter<AdapterT extends AdapterInstance = AdapterInstance, Options extends AdapterOptions = AdapterOptions>(factory: Adapter<AdapterT, Options>): Adapter<AdapterT, Options>;
|
|
78
|
-
|
|
79
|
-
declare class WSError extends Error {
|
|
80
|
-
constructor(...args: any[]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
declare class Message implements Partial<MessageEvent> {
|
|
84
|
-
#private;
|
|
85
|
-
/** Access to the original [message event](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event) if available. */
|
|
86
|
-
readonly event?: MessageEvent;
|
|
87
|
-
/** Access to the Peer that emitted the message. */
|
|
88
|
-
readonly peer?: Peer;
|
|
89
|
-
/** Raw message data (can be of any type). */
|
|
90
|
-
readonly rawData: unknown;
|
|
91
|
-
constructor(rawData: unknown, peer: Peer, event?: MessageEvent);
|
|
92
|
-
/**
|
|
93
|
-
* Unique random [uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID) identifier for the message.
|
|
94
|
-
*/
|
|
95
|
-
get id(): string;
|
|
96
|
-
/**
|
|
97
|
-
* Get data as [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.
|
|
98
|
-
*
|
|
99
|
-
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
|
100
|
-
*/
|
|
101
|
-
uint8Array(): Uint8Array;
|
|
102
|
-
/**
|
|
103
|
-
* 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.
|
|
104
|
-
*
|
|
105
|
-
* If raw data is in any other format or string, it will be automatically converted and encoded.
|
|
106
|
-
*/
|
|
107
|
-
arrayBuffer(): ArrayBuffer | SharedArrayBuffer;
|
|
108
|
-
/**
|
|
109
|
-
* Get data as [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) value.
|
|
110
|
-
*
|
|
111
|
-
* If raw data is in any other format or string, it will be automatically converted and encoded. */
|
|
112
|
-
blob(): Blob;
|
|
113
|
-
/**
|
|
114
|
-
* Get stringified text version of the message.
|
|
115
|
-
*
|
|
116
|
-
* If raw data is in any other format, it will be automatically converted and decoded.
|
|
117
|
-
*/
|
|
118
|
-
text(): string;
|
|
119
|
-
/**
|
|
120
|
-
* Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
|
|
121
|
-
*/
|
|
122
|
-
json<T = unknown>(): T;
|
|
123
|
-
/**
|
|
124
|
-
* Message data (value varies based on `peer.websocket.binaryType`).
|
|
125
|
-
*/
|
|
126
|
-
get data(): unknown;
|
|
127
|
-
toString(): string;
|
|
128
|
-
[Symbol.toPrimitive](): string;
|
|
129
|
-
[kNodeInspect](): unknown;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
declare function defineHooks<T extends Partial<Hooks> = Partial<Hooks>>(hooks: T): T;
|
|
133
|
-
type ResolveHooks = (request: Request & {
|
|
134
|
-
readonly context?: PeerContext;
|
|
135
|
-
}) => Partial<Hooks> | Promise<Partial<Hooks>>;
|
|
136
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
137
|
-
interface Hooks {
|
|
138
|
-
/**
|
|
139
|
-
* Upgrading a request to a WebSocket connection.
|
|
140
|
-
*
|
|
141
|
-
* - You can throw a Response to abort the upgrade.
|
|
142
|
-
* - You can return { headers } to modify the response.
|
|
143
|
-
* - You can return { namespace } to change the pub/sub namespace.
|
|
144
|
-
* - You can return { context } to provide a custom peer context.
|
|
145
|
-
*
|
|
146
|
-
* @param request
|
|
147
|
-
* @throws {Response}
|
|
148
|
-
*/
|
|
149
|
-
upgrade: (request: Request & {
|
|
150
|
-
readonly context?: Record<string, unknown>;
|
|
151
|
-
}) => MaybePromise<{
|
|
152
|
-
headers?: HeadersInit;
|
|
153
|
-
namespace?: string;
|
|
154
|
-
context?: PeerContext;
|
|
155
|
-
} | Response | void>;
|
|
156
|
-
/** A message is received */
|
|
157
|
-
message: (peer: Peer, message: Message) => MaybePromise<void>;
|
|
158
|
-
/** A socket is opened */
|
|
159
|
-
open: (peer: Peer) => MaybePromise<void>;
|
|
160
|
-
/** A socket is closed */
|
|
161
|
-
close: (peer: Peer, details: {
|
|
162
|
-
code?: number;
|
|
163
|
-
reason?: string;
|
|
164
|
-
}) => MaybePromise<void>;
|
|
165
|
-
/** An error occurs */
|
|
166
|
-
error: (peer: Peer, error: WSError) => MaybePromise<void>;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export { Message, Peer, WSError, defineHooks, defineWebSocketAdapter };
|
|
170
|
-
export type { Adapter, AdapterInstance, AdapterInternal, AdapterOptions, Hooks, PeerContext, ResolveHooks };
|
|
1
|
+
import { a as Hooks, c as Message, d as PeerContext, f as WSError, i as defineWebSocketAdapter, l as AdapterInternal, n as AdapterInstance, o as ResolveHooks, r as AdapterOptions, s as defineHooks, t as Adapter, u as Peer } from "./_chunks/adapter.mjs";
|
|
2
|
+
export { type Adapter, type AdapterInstance, type AdapterInternal, type AdapterOptions, type Hooks, type Message, type Peer, type PeerContext, type ResolveHooks, type WSError, defineHooks, defineWebSocketAdapter };
|
package/dist/index.mjs
CHANGED
package/dist/server/bun.d.mts
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import 'bun';
|
|
7
|
-
import '../adapters/deno.mjs';
|
|
8
|
-
import '../adapters/node.mjs';
|
|
9
|
-
import 'node:http';
|
|
10
|
-
import 'node:stream';
|
|
11
|
-
import 'events';
|
|
12
|
-
import 'node:https';
|
|
13
|
-
import 'node:tls';
|
|
14
|
-
import 'node:url';
|
|
15
|
-
import 'node:zlib';
|
|
16
|
-
import '../adapters/sse.mjs';
|
|
17
|
-
import '../adapters/cloudflare.mjs';
|
|
18
|
-
import '@cloudflare/workers-types';
|
|
19
|
-
import 'cloudflare:workers';
|
|
1
|
+
import "../_chunks/bun.mjs";
|
|
2
|
+
import "../_chunks/cloudflare.mjs";
|
|
3
|
+
import "../_chunks/node.mjs";
|
|
4
|
+
import { n as WSOptions, t as ServerWithWSOptions } from "../_chunks/_types.mjs";
|
|
5
|
+
import { Server, ServerPlugin } from "srvx";
|
|
20
6
|
|
|
7
|
+
//#region src/server/bun.d.ts
|
|
21
8
|
declare function plugin(wsOpts: WSOptions): ServerPlugin;
|
|
22
9
|
declare function serve(options: ServerWithWSOptions): Server;
|
|
23
|
-
|
|
24
|
-
export { plugin, serve };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { plugin, serve };
|
package/dist/server/bun.mjs
CHANGED
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import '../shared/crossws.WpyOHUXc.mjs';
|
|
4
|
-
import '../shared/crossws.CPlNx7g8.mjs';
|
|
1
|
+
import bun_default from "../adapters/bun.mjs";
|
|
2
|
+
import { serve as serve$1 } from "srvx/bun";
|
|
5
3
|
|
|
4
|
+
//#region src/server/bun.ts
|
|
6
5
|
function plugin(wsOpts) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
server.options.bun ??= {};
|
|
23
|
-
if (server.options.bun.websocket) {
|
|
24
|
-
throw new Error("websocket handlers for bun already set!");
|
|
25
|
-
}
|
|
26
|
-
server.options.bun.websocket = ws.websocket;
|
|
27
|
-
};
|
|
6
|
+
return (server) => {
|
|
7
|
+
const ws = bun_default({
|
|
8
|
+
hooks: wsOpts,
|
|
9
|
+
resolve: wsOpts.resolve,
|
|
10
|
+
...wsOpts.options?.bun
|
|
11
|
+
});
|
|
12
|
+
server.options.middleware.unshift((req, next) => {
|
|
13
|
+
if (req.headers.get("upgrade")?.toLowerCase() === "websocket") return ws.handleUpgrade(req, req.runtime.bun.server);
|
|
14
|
+
return next();
|
|
15
|
+
});
|
|
16
|
+
server.options.bun ??= {};
|
|
17
|
+
if (server.options.bun.websocket) throw new Error("websocket handlers for bun already set!");
|
|
18
|
+
server.options.bun.websocket = ws.websocket;
|
|
19
|
+
};
|
|
28
20
|
}
|
|
29
21
|
function serve(options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
if (options.websocket) {
|
|
23
|
+
options.plugins ||= [];
|
|
24
|
+
options.plugins.push(plugin(options.websocket));
|
|
25
|
+
}
|
|
26
|
+
return serve$1(options);
|
|
35
27
|
}
|
|
36
28
|
|
|
37
|
-
|
|
29
|
+
//#endregion
|
|
30
|
+
export { plugin, serve };
|
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import 'bun';
|
|
7
|
-
import '../adapters/deno.mjs';
|
|
8
|
-
import '../adapters/node.mjs';
|
|
9
|
-
import 'node:http';
|
|
10
|
-
import 'node:stream';
|
|
11
|
-
import 'events';
|
|
12
|
-
import 'node:https';
|
|
13
|
-
import 'node:tls';
|
|
14
|
-
import 'node:url';
|
|
15
|
-
import 'node:zlib';
|
|
16
|
-
import '../adapters/sse.mjs';
|
|
17
|
-
import '../adapters/cloudflare.mjs';
|
|
18
|
-
import '@cloudflare/workers-types';
|
|
19
|
-
import 'cloudflare:workers';
|
|
1
|
+
import "../_chunks/bun.mjs";
|
|
2
|
+
import "../_chunks/cloudflare.mjs";
|
|
3
|
+
import "../_chunks/node.mjs";
|
|
4
|
+
import { n as WSOptions, t as ServerWithWSOptions } from "../_chunks/_types.mjs";
|
|
5
|
+
import { Server, ServerPlugin } from "srvx";
|
|
20
6
|
|
|
7
|
+
//#region src/server/cloudflare.d.ts
|
|
21
8
|
declare function plugin(wsOpts: WSOptions): ServerPlugin;
|
|
22
9
|
declare function serve(options: ServerWithWSOptions): Server;
|
|
23
|
-
|
|
24
|
-
export { plugin, serve };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { plugin, serve };
|
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import 'cloudflare:workers';
|
|
4
|
-
import '../shared/crossws.WpyOHUXc.mjs';
|
|
5
|
-
import '../shared/crossws.CPlNx7g8.mjs';
|
|
6
|
-
import '../shared/crossws.B31KJMcF.mjs';
|
|
7
|
-
import '../shared/crossws.By9qWDAI.mjs';
|
|
1
|
+
import cloudflare_default from "../adapters/cloudflare.mjs";
|
|
2
|
+
import { serve as serve$1 } from "srvx/cloudflare";
|
|
8
3
|
|
|
4
|
+
//#region src/server/cloudflare.ts
|
|
9
5
|
function plugin(wsOpts) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
req.runtime.cloudflare.context
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return next();
|
|
25
|
-
});
|
|
26
|
-
};
|
|
6
|
+
return (server) => {
|
|
7
|
+
const ws = cloudflare_default({
|
|
8
|
+
hooks: wsOpts,
|
|
9
|
+
resolve: wsOpts.resolve,
|
|
10
|
+
...wsOpts.options?.cloudflare
|
|
11
|
+
});
|
|
12
|
+
server.options.middleware.unshift((req, next) => {
|
|
13
|
+
if (req.headers.get("upgrade")?.toLowerCase() === "websocket") return ws.handleUpgrade(req, req.runtime.cloudflare.env, req.runtime.cloudflare.context);
|
|
14
|
+
return next();
|
|
15
|
+
});
|
|
16
|
+
};
|
|
27
17
|
}
|
|
28
18
|
function serve(options) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
if (options.websocket) {
|
|
20
|
+
options.plugins ||= [];
|
|
21
|
+
options.plugins.push(plugin(options.websocket));
|
|
22
|
+
}
|
|
23
|
+
return serve$1(options);
|
|
34
24
|
}
|
|
35
25
|
|
|
36
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
export { plugin, serve };
|
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import 'bun';
|
|
7
|
-
import '../adapters/deno.mjs';
|
|
8
|
-
import '../adapters/node.mjs';
|
|
9
|
-
import 'node:http';
|
|
10
|
-
import 'node:stream';
|
|
11
|
-
import 'events';
|
|
12
|
-
import 'node:https';
|
|
13
|
-
import 'node:tls';
|
|
14
|
-
import 'node:url';
|
|
15
|
-
import 'node:zlib';
|
|
16
|
-
import '../adapters/sse.mjs';
|
|
17
|
-
import '../adapters/cloudflare.mjs';
|
|
18
|
-
import '@cloudflare/workers-types';
|
|
19
|
-
import 'cloudflare:workers';
|
|
1
|
+
import "../_chunks/bun.mjs";
|
|
2
|
+
import "../_chunks/cloudflare.mjs";
|
|
3
|
+
import "../_chunks/node.mjs";
|
|
4
|
+
import { n as WSOptions, t as ServerWithWSOptions } from "../_chunks/_types.mjs";
|
|
5
|
+
import { Server, ServerPlugin } from "srvx";
|
|
20
6
|
|
|
7
|
+
//#region src/server/default.d.ts
|
|
21
8
|
declare function plugin(wsOpts: WSOptions): ServerPlugin;
|
|
22
9
|
declare function serve(options: ServerWithWSOptions): Server;
|
|
23
|
-
|
|
24
|
-
export { plugin, serve };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { plugin, serve };
|
package/dist/server/default.mjs
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import '../shared/crossws.WpyOHUXc.mjs';
|
|
4
|
-
import '../shared/crossws.CPlNx7g8.mjs';
|
|
1
|
+
import sse_default from "../adapters/sse.mjs";
|
|
2
|
+
import { serve as serve$1 } from "srvx";
|
|
5
3
|
|
|
4
|
+
//#region src/server/default.ts
|
|
6
5
|
function plugin(wsOpts) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return next();
|
|
21
|
-
});
|
|
22
|
-
};
|
|
6
|
+
const ws = sse_default({
|
|
7
|
+
hooks: wsOpts,
|
|
8
|
+
resolve: wsOpts.resolve,
|
|
9
|
+
...wsOpts.options?.sse
|
|
10
|
+
});
|
|
11
|
+
console.warn("[crossws] Using SSE adapter for WebSocket support. This requires a custom WebSocket client (https://crossws.h3.dev/adapters/sse).");
|
|
12
|
+
return (server) => {
|
|
13
|
+
server.options.middleware.unshift((req, next) => {
|
|
14
|
+
if (req.headers.get("upgrade")?.toLowerCase() === "websocket") return ws.fetch(req);
|
|
15
|
+
return next();
|
|
16
|
+
});
|
|
17
|
+
};
|
|
23
18
|
}
|
|
24
19
|
function serve(options) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
if (options.websocket) {
|
|
21
|
+
options.plugins ||= [];
|
|
22
|
+
options.plugins.push(plugin(options.websocket));
|
|
23
|
+
}
|
|
24
|
+
return serve$1(options);
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
//#endregion
|
|
28
|
+
export { plugin, serve };
|
package/dist/server/deno.d.mts
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import 'bun';
|
|
7
|
-
import '../adapters/deno.mjs';
|
|
8
|
-
import '../adapters/node.mjs';
|
|
9
|
-
import 'node:http';
|
|
10
|
-
import 'node:stream';
|
|
11
|
-
import 'events';
|
|
12
|
-
import 'node:https';
|
|
13
|
-
import 'node:tls';
|
|
14
|
-
import 'node:url';
|
|
15
|
-
import 'node:zlib';
|
|
16
|
-
import '../adapters/sse.mjs';
|
|
17
|
-
import '../adapters/cloudflare.mjs';
|
|
18
|
-
import '@cloudflare/workers-types';
|
|
19
|
-
import 'cloudflare:workers';
|
|
1
|
+
import "../_chunks/bun.mjs";
|
|
2
|
+
import "../_chunks/cloudflare.mjs";
|
|
3
|
+
import "../_chunks/node.mjs";
|
|
4
|
+
import { n as WSOptions, t as ServerWithWSOptions } from "../_chunks/_types.mjs";
|
|
5
|
+
import { Server, ServerPlugin } from "srvx";
|
|
20
6
|
|
|
7
|
+
//#region src/server/deno.d.ts
|
|
21
8
|
declare function plugin(wsOpts: WSOptions): ServerPlugin;
|
|
22
9
|
declare function serve(options: ServerWithWSOptions): Server;
|
|
23
|
-
|
|
24
|
-
export { plugin, serve };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { plugin, serve };
|
package/dist/server/deno.mjs
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import '../shared/crossws.WpyOHUXc.mjs';
|
|
4
|
-
import '../shared/crossws.CPlNx7g8.mjs';
|
|
5
|
-
import '../shared/crossws.By9qWDAI.mjs';
|
|
1
|
+
import deno_default from "../adapters/deno.mjs";
|
|
2
|
+
import { serve as serve$1 } from "srvx/deno";
|
|
6
3
|
|
|
4
|
+
//#region src/server/deno.ts
|
|
7
5
|
function plugin(wsOpts) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
};
|
|
6
|
+
return (server) => {
|
|
7
|
+
const ws = deno_default({
|
|
8
|
+
hooks: wsOpts,
|
|
9
|
+
resolve: wsOpts.resolve,
|
|
10
|
+
...wsOpts.options?.deno
|
|
11
|
+
});
|
|
12
|
+
server.options.middleware.unshift((req, next) => {
|
|
13
|
+
if (req.headers.get("upgrade")?.toLowerCase() === "websocket") return ws.handleUpgrade(req, req.runtime.deno.info);
|
|
14
|
+
return next();
|
|
15
|
+
});
|
|
16
|
+
};
|
|
21
17
|
}
|
|
22
18
|
function serve(options) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
if (options.websocket) {
|
|
20
|
+
options.plugins ||= [];
|
|
21
|
+
options.plugins.push(plugin(options.websocket));
|
|
22
|
+
}
|
|
23
|
+
return serve$1(options);
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
export { plugin, serve };
|
package/dist/server/node.d.mts
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import 'bun';
|
|
7
|
-
import '../adapters/deno.mjs';
|
|
8
|
-
import '../adapters/node.mjs';
|
|
9
|
-
import 'node:http';
|
|
10
|
-
import 'node:stream';
|
|
11
|
-
import 'events';
|
|
12
|
-
import 'node:https';
|
|
13
|
-
import 'node:tls';
|
|
14
|
-
import 'node:url';
|
|
15
|
-
import 'node:zlib';
|
|
16
|
-
import '../adapters/sse.mjs';
|
|
17
|
-
import '../adapters/cloudflare.mjs';
|
|
18
|
-
import '@cloudflare/workers-types';
|
|
19
|
-
import 'cloudflare:workers';
|
|
1
|
+
import "../_chunks/bun.mjs";
|
|
2
|
+
import "../_chunks/cloudflare.mjs";
|
|
3
|
+
import "../_chunks/node.mjs";
|
|
4
|
+
import { n as WSOptions, t as ServerWithWSOptions } from "../_chunks/_types.mjs";
|
|
5
|
+
import { Server, ServerPlugin } from "srvx";
|
|
20
6
|
|
|
7
|
+
//#region src/server/node.d.ts
|
|
21
8
|
declare function plugin(wsOpts: WSOptions): ServerPlugin;
|
|
22
9
|
declare function serve(options: ServerWithWSOptions): Server;
|
|
23
|
-
|
|
24
|
-
export { plugin, serve };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { plugin, serve };
|
package/dist/server/node.mjs
CHANGED
|
@@ -1,49 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import '../shared/crossws.By9qWDAI.mjs';
|
|
6
|
-
import '../shared/crossws.C5pESzqN.mjs';
|
|
7
|
-
import 'stream';
|
|
8
|
-
import 'events';
|
|
9
|
-
import 'http';
|
|
10
|
-
import 'crypto';
|
|
11
|
-
import 'buffer';
|
|
12
|
-
import 'zlib';
|
|
13
|
-
import 'https';
|
|
14
|
-
import 'net';
|
|
15
|
-
import 'tls';
|
|
16
|
-
import 'url';
|
|
17
|
-
import '../shared/crossws.B31KJMcF.mjs';
|
|
1
|
+
import "../_chunks/rolldown-runtime.mjs";
|
|
2
|
+
import "../_chunks/libs/ws.mjs";
|
|
3
|
+
import node_default from "../adapters/node.mjs";
|
|
4
|
+
import { NodeRequest, serve as serve$1 } from "srvx/node";
|
|
18
5
|
|
|
6
|
+
//#region src/server/node.ts
|
|
19
7
|
function plugin(wsOpts) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
8
|
+
return (server) => {
|
|
9
|
+
const ws = node_default({
|
|
10
|
+
hooks: wsOpts,
|
|
11
|
+
resolve: wsOpts.resolve,
|
|
12
|
+
...wsOpts.options?.deno
|
|
13
|
+
});
|
|
14
|
+
const originalServe = server.serve;
|
|
15
|
+
server.serve = () => {
|
|
16
|
+
server.node?.server.on("upgrade", (req, socket, head) => {
|
|
17
|
+
ws.handleUpgrade(req, socket, head, new NodeRequest({
|
|
18
|
+
req,
|
|
19
|
+
upgrade: {
|
|
20
|
+
socket,
|
|
21
|
+
head
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
return originalServe.call(server);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
40
28
|
}
|
|
41
29
|
function serve(options) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
if (options.websocket) {
|
|
31
|
+
options.plugins ||= [];
|
|
32
|
+
options.plugins.push(plugin(options.websocket));
|
|
33
|
+
}
|
|
34
|
+
return serve$1(options);
|
|
47
35
|
}
|
|
48
36
|
|
|
49
|
-
|
|
37
|
+
//#endregion
|
|
38
|
+
export { plugin, serve };
|