crossws 0.4.3 → 0.4.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/adapters/bunny.d.ts +2 -0
- package/dist/THIRD-PARTY-LICENSES.md +33 -0
- package/dist/_chunks/_request.mjs +4 -6
- package/dist/_chunks/_types.d.mts +2 -3
- package/dist/_chunks/adapter.d.mts +45 -53
- package/dist/_chunks/adapter.mjs +6 -7
- package/dist/_chunks/bun.d.mts +0 -3
- package/dist/_chunks/bunny.d.mts +22 -0
- package/dist/_chunks/cloudflare.d.mts +16 -19
- package/dist/_chunks/deno.d.mts +0 -3
- package/dist/_chunks/error.mjs +1 -4
- package/dist/_chunks/libs/ws.mjs +77 -1179
- package/dist/_chunks/node.d.mts +43 -14
- package/dist/_chunks/node.mjs +129 -0
- package/dist/_chunks/peer.mjs +1 -59
- package/dist/_chunks/rolldown-runtime.mjs +7 -15
- package/dist/_chunks/sse.d.mts +0 -3
- package/dist/_chunks/web.d.mts +164 -166
- package/dist/adapters/bun.mjs +1 -6
- package/dist/adapters/bunny.d.mts +2 -0
- package/dist/adapters/bunny.mjs +68 -0
- package/dist/adapters/cloudflare.mjs +7 -12
- package/dist/adapters/deno.mjs +1 -6
- package/dist/adapters/node.d.mts +2 -2
- package/dist/adapters/node.mjs +2 -125
- package/dist/adapters/sse.mjs +1 -6
- package/dist/adapters/uws.d.mts +0 -5
- package/dist/adapters/uws.mjs +2 -7
- package/dist/index.d.mts +81 -1
- package/dist/index.mjs +161 -2
- package/dist/server/bun.d.mts +0 -6
- package/dist/server/bun.mjs +3 -7
- package/dist/server/bunny.d.mts +5 -0
- package/dist/server/bunny.mjs +23 -0
- package/dist/server/cloudflare.d.mts +0 -6
- package/dist/server/cloudflare.mjs +3 -7
- package/dist/server/default.d.mts +0 -6
- package/dist/server/default.mjs +3 -7
- package/dist/server/deno.d.mts +0 -6
- package/dist/server/deno.mjs +3 -7
- package/dist/server/node.d.mts +0 -6
- package/dist/server/node.mjs +3 -9
- package/dist/websocket/native.d.mts +0 -2
- package/dist/websocket/native.mjs +1 -5
- package/dist/websocket/node.d.mts +0 -2
- package/dist/websocket/node.mjs +1 -7
- package/dist/websocket/sse.d.mts +0 -3
- package/dist/websocket/sse.mjs +1 -4
- package/package.json +42 -40
- package/server/bunny.d.ts +2 -0
package/dist/_chunks/web.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region types/web.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute.
|
|
4
3
|
*
|
|
@@ -6,22 +5,22 @@
|
|
|
6
5
|
*/
|
|
7
6
|
interface CloseEvent extends Event {
|
|
8
7
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
* Returns the WebSocket connection close code provided by the server.
|
|
9
|
+
*
|
|
10
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/code)
|
|
11
|
+
*/
|
|
13
12
|
readonly code: number;
|
|
14
13
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
* Returns the WebSocket connection close reason provided by the server.
|
|
15
|
+
*
|
|
16
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/reason)
|
|
17
|
+
*/
|
|
19
18
|
readonly reason: string;
|
|
20
19
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
* Returns true if the connection closed cleanly; false otherwise.
|
|
21
|
+
*
|
|
22
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/wasClean)
|
|
23
|
+
*/
|
|
25
24
|
readonly wasClean: boolean;
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
@@ -31,112 +30,112 @@ interface CloseEvent extends Event {
|
|
|
31
30
|
*/
|
|
32
31
|
interface Event {
|
|
33
32
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
* 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.
|
|
34
|
+
*
|
|
35
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/bubbles)
|
|
36
|
+
*/
|
|
38
37
|
readonly bubbles: boolean;
|
|
39
38
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
* @deprecated
|
|
40
|
+
*
|
|
41
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble)
|
|
42
|
+
*/
|
|
44
43
|
cancelBubble: boolean;
|
|
45
44
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
* 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.
|
|
46
|
+
*
|
|
47
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelable)
|
|
48
|
+
*/
|
|
50
49
|
readonly cancelable: boolean;
|
|
51
50
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
* 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.
|
|
52
|
+
*
|
|
53
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composed)
|
|
54
|
+
*/
|
|
56
55
|
readonly composed: boolean;
|
|
57
56
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
* Returns the object whose event listener's callback is currently being invoked.
|
|
58
|
+
*
|
|
59
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget)
|
|
60
|
+
*/
|
|
62
61
|
readonly currentTarget: EventTarget | null;
|
|
63
62
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
* Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
|
|
64
|
+
*
|
|
65
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented)
|
|
66
|
+
*/
|
|
68
67
|
readonly defaultPrevented: boolean;
|
|
69
68
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
* Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
|
|
70
|
+
*
|
|
71
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/eventPhase)
|
|
72
|
+
*/
|
|
74
73
|
readonly eventPhase: number;
|
|
75
74
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
* Returns true if event was dispatched by the user agent, and false otherwise.
|
|
76
|
+
*
|
|
77
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/isTrusted)
|
|
78
|
+
*/
|
|
80
79
|
readonly isTrusted: boolean;
|
|
81
80
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
* @deprecated
|
|
82
|
+
*
|
|
83
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/returnValue)
|
|
84
|
+
*/
|
|
86
85
|
returnValue: boolean;
|
|
87
86
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
* @deprecated
|
|
88
|
+
*
|
|
89
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/srcElement)
|
|
90
|
+
*/
|
|
92
91
|
readonly srcElement: EventTarget | null;
|
|
93
92
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
* Returns the object to which event is dispatched (its target).
|
|
94
|
+
*
|
|
95
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target)
|
|
96
|
+
*/
|
|
98
97
|
readonly target: EventTarget | null;
|
|
99
98
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
* Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
|
|
100
|
+
*
|
|
101
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/timeStamp)
|
|
102
|
+
*/
|
|
104
103
|
readonly timeStamp: DOMHighResTimeStamp;
|
|
105
104
|
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
* Returns the type of event, e.g. "click", "hashchange", or "submit".
|
|
106
|
+
*
|
|
107
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/type)
|
|
108
|
+
*/
|
|
110
109
|
readonly type: string;
|
|
111
110
|
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
* 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.
|
|
112
|
+
*
|
|
113
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composedPath)
|
|
114
|
+
*/
|
|
116
115
|
composedPath(): EventTarget[];
|
|
117
116
|
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
* @deprecated
|
|
118
|
+
*
|
|
119
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/initEvent)
|
|
120
|
+
*/
|
|
122
121
|
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
|
|
123
122
|
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
* 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.
|
|
124
|
+
*
|
|
125
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/preventDefault)
|
|
126
|
+
*/
|
|
128
127
|
preventDefault(): void;
|
|
129
128
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
* 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.
|
|
130
|
+
*
|
|
131
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopImmediatePropagation)
|
|
132
|
+
*/
|
|
134
133
|
stopImmediatePropagation(): void;
|
|
135
134
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
* When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
|
|
136
|
+
*
|
|
137
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation)
|
|
138
|
+
*/
|
|
140
139
|
stopPropagation(): void;
|
|
141
140
|
readonly NONE: 0;
|
|
142
141
|
readonly CAPTURING_PHASE: 1;
|
|
@@ -150,34 +149,34 @@ interface Event {
|
|
|
150
149
|
*/
|
|
151
150
|
interface EventTarget {
|
|
152
151
|
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
152
|
+
* 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.
|
|
153
|
+
*
|
|
154
|
+
* 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.
|
|
155
|
+
*
|
|
156
|
+
* 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.
|
|
157
|
+
*
|
|
158
|
+
* 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.
|
|
159
|
+
*
|
|
160
|
+
* When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
|
|
161
|
+
*
|
|
162
|
+
* If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
|
|
163
|
+
*
|
|
164
|
+
* The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
|
|
165
|
+
*
|
|
166
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
|
|
167
|
+
*/
|
|
169
168
|
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
|
|
170
169
|
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
* 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.
|
|
171
|
+
*
|
|
172
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
|
|
173
|
+
*/
|
|
175
174
|
dispatchEvent(event: Event): boolean;
|
|
176
175
|
/**
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
* Removes the event listener in target's event listener list with the same type, callback, and options.
|
|
177
|
+
*
|
|
178
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
|
|
179
|
+
*/
|
|
181
180
|
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
|
182
181
|
}
|
|
183
182
|
/**
|
|
@@ -187,34 +186,34 @@ interface EventTarget {
|
|
|
187
186
|
*/
|
|
188
187
|
interface MessageEvent<T = any> extends Event {
|
|
189
188
|
/**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
* Returns the data of the message.
|
|
190
|
+
*
|
|
191
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/data)
|
|
192
|
+
*/
|
|
194
193
|
readonly data: T;
|
|
195
194
|
/**
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
195
|
+
* Returns the last event ID string, for server-sent events.
|
|
196
|
+
*
|
|
197
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/lastEventId)
|
|
198
|
+
*/
|
|
200
199
|
readonly lastEventId: string;
|
|
201
200
|
/**
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
201
|
+
* Returns the origin of the message, for server-sent events and cross-document messaging.
|
|
202
|
+
*
|
|
203
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/origin)
|
|
204
|
+
*/
|
|
206
205
|
readonly origin: string;
|
|
207
206
|
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
207
|
+
* Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging.
|
|
208
|
+
*
|
|
209
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/ports)
|
|
210
|
+
*/
|
|
212
211
|
readonly ports: ReadonlyArray<MessagePort>;
|
|
213
212
|
/**
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
213
|
+
* Returns the WindowProxy of the source window, for cross-document messaging, and the MessagePort being attached, in the connect event fired at SharedWorkerGlobalScope objects.
|
|
214
|
+
*
|
|
215
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/source)
|
|
216
|
+
*/
|
|
218
217
|
readonly source: MessageEventSource | null;
|
|
219
218
|
/** @deprecated */
|
|
220
219
|
initMessageEvent(type: string, bubbles?: boolean, cancelable?: boolean, data?: any, origin?: string, lastEventId?: string, source?: MessageEventSource | null, ports?: MessagePort[]): void;
|
|
@@ -226,26 +225,26 @@ interface MessageEvent<T = any> extends Event {
|
|
|
226
225
|
*/
|
|
227
226
|
interface WebSocket extends EventTarget {
|
|
228
227
|
/**
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
228
|
+
* Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
|
|
229
|
+
*
|
|
230
|
+
* Can be set, to change how binary data is returned. The default is "blob".
|
|
231
|
+
*
|
|
232
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType)
|
|
233
|
+
*/
|
|
235
234
|
binaryType: BinaryType | (string & {});
|
|
236
235
|
/**
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
236
|
+
* 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.
|
|
237
|
+
*
|
|
238
|
+
* 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.)
|
|
239
|
+
*
|
|
240
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/bufferedAmount)
|
|
241
|
+
*/
|
|
243
242
|
readonly bufferedAmount: number;
|
|
244
243
|
/**
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
* Returns the extensions selected by the server, if any.
|
|
245
|
+
*
|
|
246
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions)
|
|
247
|
+
*/
|
|
249
248
|
readonly extensions: string;
|
|
250
249
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close_event) */
|
|
251
250
|
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
|
|
@@ -256,34 +255,34 @@ interface WebSocket extends EventTarget {
|
|
|
256
255
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/open_event) */
|
|
257
256
|
onopen: ((this: WebSocket, ev: Event) => any) | null;
|
|
258
257
|
/**
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
258
|
+
* 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.
|
|
259
|
+
*
|
|
260
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol)
|
|
261
|
+
*/
|
|
263
262
|
readonly protocol: string;
|
|
264
263
|
/**
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
264
|
+
* Returns the state of the WebSocket object's connection. It can have the values described below.
|
|
265
|
+
*
|
|
266
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState)
|
|
267
|
+
*/
|
|
269
268
|
readonly readyState: number;
|
|
270
269
|
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
270
|
+
* Returns the URL that was used to establish the WebSocket connection.
|
|
271
|
+
*
|
|
272
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url)
|
|
273
|
+
*/
|
|
275
274
|
readonly url: string;
|
|
276
275
|
/**
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
* Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
|
|
277
|
+
*
|
|
278
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close)
|
|
279
|
+
*/
|
|
281
280
|
close(code?: number, reason?: string): void;
|
|
282
281
|
/**
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
282
|
+
* Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
|
|
283
|
+
*
|
|
284
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send)
|
|
285
|
+
*/
|
|
287
286
|
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
288
287
|
readonly CONNECTING: 0;
|
|
289
288
|
readonly OPEN: 1;
|
|
@@ -294,5 +293,4 @@ interface WebSocket extends EventTarget {
|
|
|
294
293
|
removeEventListener<K extends keyof WebSocketEventMap>(type: K, listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
|
|
295
294
|
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
296
295
|
}
|
|
297
|
-
//#endregion
|
|
298
296
|
export { WebSocket as a, MessageEvent as i, Event as n, EventTarget as r, CloseEvent as t };
|
package/dist/adapters/bun.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { i as AdapterHookable, r as getPeers, t as adapterUtils } from "../_chunks/adapter.mjs";
|
|
2
2
|
import { n as Message, r as toBufferLike, t as Peer } from "../_chunks/peer.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/adapters/bun.ts
|
|
5
3
|
const bunAdapter = (options = {}) => {
|
|
6
4
|
if (typeof Bun === "undefined") throw new Error("[crossws] Using Bun adapter in an incompatible environment.");
|
|
7
5
|
const hooks = new AdapterHookable(options);
|
|
@@ -44,7 +42,6 @@ const bunAdapter = (options = {}) => {
|
|
|
44
42
|
}
|
|
45
43
|
};
|
|
46
44
|
};
|
|
47
|
-
var bun_default = bunAdapter;
|
|
48
45
|
function getPeer(ws, peers) {
|
|
49
46
|
if (ws.data.peer) return ws.data.peer;
|
|
50
47
|
const peer = new BunPeer({
|
|
@@ -84,6 +81,4 @@ var BunPeer = class extends Peer {
|
|
|
84
81
|
this._internal.ws.terminate();
|
|
85
82
|
}
|
|
86
83
|
};
|
|
87
|
-
|
|
88
|
-
//#endregion
|
|
89
|
-
export { bun_default as default };
|
|
84
|
+
export { bunAdapter as default };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { i as AdapterHookable, r as getPeers, t as adapterUtils } from "../_chunks/adapter.mjs";
|
|
2
|
+
import { n as Message, r as toBufferLike, t as Peer } from "../_chunks/peer.mjs";
|
|
3
|
+
import { t as WSError } from "../_chunks/error.mjs";
|
|
4
|
+
const bunnyAdapter = (options = {}) => {
|
|
5
|
+
const hooks = new AdapterHookable(options);
|
|
6
|
+
const globalPeers = /* @__PURE__ */ new Map();
|
|
7
|
+
return {
|
|
8
|
+
...adapterUtils(globalPeers),
|
|
9
|
+
handleUpgrade: async (request) => {
|
|
10
|
+
if (!request.upgradeWebSocket || typeof request.upgradeWebSocket !== "function") throw new Error("[crossws] Bunny adapter requires the request to have an upgradeWebSocket method.");
|
|
11
|
+
const { endResponse, context, namespace, upgradeHeaders } = await hooks.upgrade(request);
|
|
12
|
+
if (endResponse) return endResponse;
|
|
13
|
+
const negotiatedProtocol = (upgradeHeaders instanceof Headers ? upgradeHeaders : new Headers(upgradeHeaders)).get("sec-websocket-protocol") ?? options.protocol;
|
|
14
|
+
const upgradeOptions = {};
|
|
15
|
+
if (negotiatedProtocol) upgradeOptions.protocol = negotiatedProtocol;
|
|
16
|
+
if (options.idleTimeout !== void 0) upgradeOptions.idleTimeout = options.idleTimeout;
|
|
17
|
+
const { response, socket } = request.upgradeWebSocket(Object.keys(upgradeOptions).length > 0 ? upgradeOptions : void 0);
|
|
18
|
+
const remoteAddress = request.headers.get("x-real-ip") || void 0;
|
|
19
|
+
const peers = getPeers(globalPeers, namespace);
|
|
20
|
+
const peer = new BunnyPeer({
|
|
21
|
+
ws: socket,
|
|
22
|
+
request,
|
|
23
|
+
namespace,
|
|
24
|
+
remoteAddress,
|
|
25
|
+
peers,
|
|
26
|
+
context
|
|
27
|
+
});
|
|
28
|
+
peers.add(peer);
|
|
29
|
+
socket.addEventListener("open", () => {
|
|
30
|
+
hooks.callHook("open", peer);
|
|
31
|
+
});
|
|
32
|
+
socket.addEventListener("message", (event) => {
|
|
33
|
+
hooks.callHook("message", peer, new Message(event.data, peer, event));
|
|
34
|
+
});
|
|
35
|
+
socket.addEventListener("close", (event) => {
|
|
36
|
+
peers.delete(peer);
|
|
37
|
+
hooks.callHook("close", peer, {
|
|
38
|
+
code: event.code,
|
|
39
|
+
reason: event.reason
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
socket.addEventListener("error", (error) => {
|
|
43
|
+
peers.delete(peer);
|
|
44
|
+
hooks.callHook("error", peer, new WSError(error));
|
|
45
|
+
});
|
|
46
|
+
return response;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
var BunnyPeer = class extends Peer {
|
|
51
|
+
get remoteAddress() {
|
|
52
|
+
return this._internal.remoteAddress;
|
|
53
|
+
}
|
|
54
|
+
send(data) {
|
|
55
|
+
return this._internal.ws.send(toBufferLike(data));
|
|
56
|
+
}
|
|
57
|
+
publish(topic, data) {
|
|
58
|
+
const dataBuff = toBufferLike(data);
|
|
59
|
+
for (const peer of this._internal.peers) if (peer !== this && peer._topics.has(topic)) peer._internal.ws.send(dataBuff);
|
|
60
|
+
}
|
|
61
|
+
close(code, reason) {
|
|
62
|
+
this._internal.ws.close(code, reason);
|
|
63
|
+
}
|
|
64
|
+
terminate() {
|
|
65
|
+
this._internal.ws.close();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export { bunnyAdapter as default };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { i as AdapterHookable, r as getPeers, t as adapterUtils } from "../_chunks/adapter.mjs";
|
|
2
2
|
import { n as Message, r as toBufferLike, t as Peer } from "../_chunks/peer.mjs";
|
|
3
|
-
import { t as StubRequest } from "../_chunks/_request.mjs";
|
|
4
3
|
import { t as WSError } from "../_chunks/error.mjs";
|
|
4
|
+
import { t as StubRequest } from "../_chunks/_request.mjs";
|
|
5
5
|
import { env } from "cloudflare:workers";
|
|
6
|
-
|
|
7
|
-
//#region src/adapters/cloudflare.ts
|
|
8
6
|
const cloudflareAdapter = (opts = {}) => {
|
|
9
7
|
const hooks = new AdapterHookable(opts);
|
|
10
8
|
const globalPeers = /* @__PURE__ */ new Map();
|
|
@@ -59,7 +57,7 @@ const cloudflareAdapter = (opts = {}) => {
|
|
|
59
57
|
headers: upgradeHeaders
|
|
60
58
|
});
|
|
61
59
|
},
|
|
62
|
-
handleDurableInit: async (
|
|
60
|
+
handleDurableInit: async (_obj, _state, _env) => {},
|
|
63
61
|
handleDurableUpgrade: async (obj, request) => {
|
|
64
62
|
const { upgradeHeaders, endResponse, namespace } = await hooks.upgrade(request);
|
|
65
63
|
if (endResponse) return endResponse;
|
|
@@ -91,14 +89,14 @@ const cloudflareAdapter = (opts = {}) => {
|
|
|
91
89
|
};
|
|
92
90
|
await hooks.callHook("close", peer, details);
|
|
93
91
|
},
|
|
94
|
-
handleDurablePublish: async (_obj, topic, data, opts
|
|
95
|
-
return durablePublish(topic, data, opts
|
|
92
|
+
handleDurablePublish: async (_obj, topic, data, opts) => {
|
|
93
|
+
return durablePublish(topic, data, opts);
|
|
96
94
|
},
|
|
97
|
-
publish: async (topic, data, opts
|
|
95
|
+
publish: async (topic, data, opts) => {
|
|
98
96
|
const stub = await resolveDurableStub(void 0, env, void 0);
|
|
99
97
|
if (!stub) throw new Error("[crossws] Durable Object binding cannot be resolved.");
|
|
100
98
|
try {
|
|
101
|
-
return await stub.webSocketPublish(topic, data, opts
|
|
99
|
+
return await stub.webSocketPublish(topic, data, opts);
|
|
102
100
|
} catch (error) {
|
|
103
101
|
console.error(error);
|
|
104
102
|
throw error;
|
|
@@ -106,7 +104,6 @@ const cloudflareAdapter = (opts = {}) => {
|
|
|
106
104
|
}
|
|
107
105
|
};
|
|
108
106
|
};
|
|
109
|
-
var cloudflare_default = cloudflareAdapter;
|
|
110
107
|
var CloudflareDurablePeer = class CloudflareDurablePeer extends Peer {
|
|
111
108
|
get peers() {
|
|
112
109
|
return new Set(this.#getwebsockets().map((ws) => CloudflareDurablePeer._restore(this._internal.durable, ws)));
|
|
@@ -176,6 +173,4 @@ function setAttachedState(ws, state) {
|
|
|
176
173
|
ws._crosswsState = state;
|
|
177
174
|
ws.serializeAttachment(state);
|
|
178
175
|
}
|
|
179
|
-
|
|
180
|
-
//#endregion
|
|
181
|
-
export { cloudflare_default as default };
|
|
176
|
+
export { cloudflareAdapter as default };
|
package/dist/adapters/deno.mjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { i as AdapterHookable, r as getPeers, t as adapterUtils } from "../_chunks/adapter.mjs";
|
|
2
2
|
import { n as Message, r as toBufferLike, t as Peer } from "../_chunks/peer.mjs";
|
|
3
3
|
import { t as WSError } from "../_chunks/error.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/adapters/deno.ts
|
|
6
4
|
const denoAdapter = (options = {}) => {
|
|
7
5
|
if (typeof Deno === "undefined") throw new Error("[crossws] Using Deno adapter in an incompatible environment.");
|
|
8
6
|
const hooks = new AdapterHookable(options);
|
|
@@ -45,7 +43,6 @@ const denoAdapter = (options = {}) => {
|
|
|
45
43
|
}
|
|
46
44
|
};
|
|
47
45
|
};
|
|
48
|
-
var deno_default = denoAdapter;
|
|
49
46
|
var DenoPeer = class extends Peer {
|
|
50
47
|
get remoteAddress() {
|
|
51
48
|
return this._internal.denoInfo.remoteAddr?.hostname;
|
|
@@ -64,6 +61,4 @@ var DenoPeer = class extends Peer {
|
|
|
64
61
|
this._internal.ws.terminate();
|
|
65
62
|
}
|
|
66
63
|
};
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
export { deno_default as default };
|
|
64
|
+
export { denoAdapter as default };
|
package/dist/adapters/node.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as NodeOptions, r as nodeAdapter, t as NodeAdapter } from "../_chunks/node.mjs";
|
|
2
|
-
export { NodeAdapter, NodeOptions, nodeAdapter as default };
|
|
1
|
+
import { a as fromNodeUpgradeHandler, i as NodeUpgradeHandler, n as NodeOptions, r as nodeAdapter, t as NodeAdapter } from "../_chunks/node.mjs";
|
|
2
|
+
export { NodeAdapter, NodeOptions, NodeUpgradeHandler, nodeAdapter as default, fromNodeUpgradeHandler };
|