msw 2.2.3 → 2.3.0-ws.rc-1
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/cli/init.js +0 -0
- package/config/scripts/postinstall.js +0 -0
- package/lib/browser/index.d.mts +7 -6
- package/lib/browser/index.d.ts +7 -6
- package/lib/browser/index.js +32 -15
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +32 -15
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-jOzqbxSK.d.ts → GraphQLHandler-Cbu12sb0.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-AenIUdwE.d.mts → GraphQLHandler-QGQY_9Rc.d.mts} +1 -1
- package/lib/core/{HttpResponse-wcp03c7-.d.mts → HttpResponse-BWB1yDNM.d.mts} +2 -2
- package/lib/core/{HttpResponse-_514VQ9z.d.ts → HttpResponse-DeJBWGN5.d.ts} +2 -2
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +15 -12
- package/lib/core/SetupApi.d.ts +15 -12
- package/lib/core/SetupApi.js +3 -1
- package/lib/core/SetupApi.js.map +1 -1
- package/lib/core/SetupApi.mjs +3 -1
- package/lib/core/SetupApi.mjs.map +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +38 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +38 -0
- package/lib/core/handlers/WebSocketHandler.js +65 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -0
- package/lib/core/handlers/WebSocketHandler.mjs +47 -0
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -0
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +5 -2
- package/lib/core/index.d.ts +5 -2
- package/lib/core/index.js +3 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +3 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/executeHandlers.js +4 -0
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +6 -0
- package/lib/core/utils/executeHandlers.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -2
- package/lib/core/utils/handleRequest.d.ts +2 -2
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/handleWebSocketEvent.d.mts +10 -0
- package/lib/core/utils/handleWebSocketEvent.d.ts +10 -0
- package/lib/core/utils/handleWebSocketEvent.js +56 -0
- package/lib/core/utils/handleWebSocketEvent.js.map +1 -0
- package/lib/core/utils/handleWebSocketEvent.mjs +40 -0
- package/lib/core/utils/handleWebSocketEvent.mjs.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +2 -1
- package/lib/core/utils/matching/matchRequestUrl.d.ts +2 -1
- package/lib/core/utils/matching/matchRequestUrl.js +4 -0
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +4 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +64 -0
- package/lib/core/ws/WebSocketClientManager.d.ts +64 -0
- package/lib/core/ws/WebSocketClientManager.js +123 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -0
- package/lib/core/ws/WebSocketClientManager.mjs +103 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
- package/lib/core/ws/webSocketInterceptor.d.mts +5 -0
- package/lib/core/ws/webSocketInterceptor.d.ts +5 -0
- package/lib/core/ws/webSocketInterceptor.js +26 -0
- package/lib/core/ws/webSocketInterceptor.js.map +1 -0
- package/lib/core/ws/webSocketInterceptor.mjs +6 -0
- package/lib/core/ws/webSocketInterceptor.mjs.map +1 -0
- package/lib/core/ws/ws.d.mts +44 -0
- package/lib/core/ws/ws.d.ts +44 -0
- package/lib/core/ws/ws.js +82 -0
- package/lib/core/ws/ws.js.map +1 -0
- package/lib/core/ws/ws.mjs +65 -0
- package/lib/core/ws/ws.mjs.map +1 -0
- package/lib/iife/index.js +703 -17
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +6 -5
- package/lib/native/index.d.ts +6 -5
- package/lib/native/index.js +7 -0
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +7 -0
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +8 -7
- package/lib/node/index.d.ts +8 -7
- package/lib/node/index.js +7 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +7 -0
- package/lib/node/index.mjs.map +1 -1
- package/package.json +27 -22
- package/src/browser/setupWorker/glossary.ts +10 -10
- package/src/browser/setupWorker/setupWorker.ts +17 -3
- package/src/core/SetupApi.ts +28 -20
- package/src/core/handlers/WebSocketHandler.ts +89 -0
- package/src/core/index.ts +3 -0
- package/src/core/utils/executeHandlers.ts +6 -2
- package/src/core/utils/handleRequest.ts +1 -2
- package/src/core/utils/handleWebSocketEvent.ts +49 -0
- package/src/core/utils/matching/matchRequestUrl.test.ts +44 -0
- package/src/core/utils/matching/matchRequestUrl.ts +4 -0
- package/src/core/ws/WebSocketClientManager.test.ts +159 -0
- package/src/core/ws/WebSocketClientManager.ts +170 -0
- package/src/core/ws/webSocketInterceptor.ts +3 -0
- package/src/core/ws/ws.test.ts +23 -0
- package/src/core/ws/ws.ts +108 -0
- package/src/node/SetupServerApi.ts +8 -7
- package/src/node/SetupServerCommonApi.ts +10 -1
- package/src/node/glossary.ts +5 -7
- package/src/node/setupServer.ts +2 -1
package/lib/iife/index.js
CHANGED
|
@@ -41,7 +41,8 @@ var MockServiceWorker = (() => {
|
|
|
41
41
|
http: () => http,
|
|
42
42
|
matchRequestUrl: () => matchRequestUrl,
|
|
43
43
|
passthrough: () => passthrough,
|
|
44
|
-
setupWorker: () => setupWorker
|
|
44
|
+
setupWorker: () => setupWorker,
|
|
45
|
+
ws: () => ws
|
|
45
46
|
});
|
|
46
47
|
|
|
47
48
|
// node_modules/.pnpm/outvariant@1.4.2/node_modules/outvariant/lib/index.mjs
|
|
@@ -402,7 +403,9 @@ var MockServiceWorker = (() => {
|
|
|
402
403
|
}
|
|
403
404
|
restoreHandlers() {
|
|
404
405
|
this.handlersController.currentHandlers().forEach((handler) => {
|
|
405
|
-
|
|
406
|
+
if ("isUsed" in handler) {
|
|
407
|
+
handler.isUsed = false;
|
|
408
|
+
}
|
|
406
409
|
});
|
|
407
410
|
}
|
|
408
411
|
resetHandlers(...nextHandlers) {
|
|
@@ -1121,7 +1124,7 @@ var MockServiceWorker = (() => {
|
|
|
1121
1124
|
return stringToRegexp(path, keys, options);
|
|
1122
1125
|
}
|
|
1123
1126
|
|
|
1124
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1127
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
|
|
1125
1128
|
var encoder = new TextEncoder();
|
|
1126
1129
|
function encodeBuffer(text) {
|
|
1127
1130
|
return encoder.encode(text);
|
|
@@ -1147,6 +1150,9 @@ var MockServiceWorker = (() => {
|
|
|
1147
1150
|
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
1148
1151
|
}
|
|
1149
1152
|
|
|
1153
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/chunk-HAGW22AN.mjs
|
|
1154
|
+
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1155
|
+
|
|
1150
1156
|
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
1151
1157
|
function isNodeProcess() {
|
|
1152
1158
|
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
@@ -1434,8 +1440,7 @@ var MockServiceWorker = (() => {
|
|
|
1434
1440
|
return message3.toString();
|
|
1435
1441
|
}
|
|
1436
1442
|
|
|
1437
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1438
|
-
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1443
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/chunk-SGO3INLV.mjs
|
|
1439
1444
|
function getGlobalSymbol(symbol) {
|
|
1440
1445
|
return (
|
|
1441
1446
|
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
|
|
@@ -1579,7 +1584,7 @@ var MockServiceWorker = (() => {
|
|
|
1579
1584
|
}
|
|
1580
1585
|
};
|
|
1581
1586
|
|
|
1582
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1587
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1583
1588
|
var BatchInterceptor = class extends Interceptor {
|
|
1584
1589
|
constructor(options) {
|
|
1585
1590
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -1687,6 +1692,9 @@ var MockServiceWorker = (() => {
|
|
|
1687
1692
|
params
|
|
1688
1693
|
};
|
|
1689
1694
|
}
|
|
1695
|
+
function isPath(value) {
|
|
1696
|
+
return typeof value === "string" || value instanceof RegExp;
|
|
1697
|
+
}
|
|
1690
1698
|
|
|
1691
1699
|
// src/core/utils/request/toPublicUrl.ts
|
|
1692
1700
|
function toPublicUrl(url) {
|
|
@@ -5607,6 +5615,199 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5607
5615
|
link: createGraphQLLink
|
|
5608
5616
|
};
|
|
5609
5617
|
|
|
5618
|
+
// src/core/handlers/WebSocketHandler.ts
|
|
5619
|
+
var kEmitter = Symbol("kEmitter");
|
|
5620
|
+
var kDispatchEvent = Symbol("kDispatchEvent");
|
|
5621
|
+
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
5622
|
+
var WebSocketHandler = class {
|
|
5623
|
+
constructor(url) {
|
|
5624
|
+
this.url = url;
|
|
5625
|
+
this[kEmitter] = new Emitter();
|
|
5626
|
+
}
|
|
5627
|
+
[kEmitter];
|
|
5628
|
+
parse(args) {
|
|
5629
|
+
const connection = args.event.data;
|
|
5630
|
+
const match2 = matchRequestUrl(connection.client.url, this.url);
|
|
5631
|
+
return {
|
|
5632
|
+
match: match2
|
|
5633
|
+
};
|
|
5634
|
+
}
|
|
5635
|
+
predicate(args) {
|
|
5636
|
+
return args.parsedResult.match.matches;
|
|
5637
|
+
}
|
|
5638
|
+
async [kDispatchEvent](event) {
|
|
5639
|
+
const parsedResult = this.parse({ event });
|
|
5640
|
+
const shouldIntercept = this.predicate({ event, parsedResult });
|
|
5641
|
+
if (!shouldIntercept) {
|
|
5642
|
+
return;
|
|
5643
|
+
}
|
|
5644
|
+
if (!Reflect.get(event, kDefaultPrevented)) {
|
|
5645
|
+
Reflect.set(event, kDefaultPrevented, true);
|
|
5646
|
+
}
|
|
5647
|
+
const connection = event.data;
|
|
5648
|
+
this[kEmitter].emit("connection", {
|
|
5649
|
+
client: connection.client,
|
|
5650
|
+
server: connection.server,
|
|
5651
|
+
params: parsedResult.match.params || {}
|
|
5652
|
+
});
|
|
5653
|
+
}
|
|
5654
|
+
};
|
|
5655
|
+
|
|
5656
|
+
// src/core/ws/WebSocketClientManager.ts
|
|
5657
|
+
var kAddByClientId = Symbol("kAddByClientId");
|
|
5658
|
+
var WebSocketClientManager = class {
|
|
5659
|
+
constructor(channel) {
|
|
5660
|
+
this.channel = channel;
|
|
5661
|
+
this.clients = /* @__PURE__ */ new Set();
|
|
5662
|
+
this.channel.addEventListener("message", (message3) => {
|
|
5663
|
+
const { type, payload } = message3.data;
|
|
5664
|
+
switch (type) {
|
|
5665
|
+
case "connection:open": {
|
|
5666
|
+
this.onRemoteConnection(payload.clientId, new URL(payload.url));
|
|
5667
|
+
break;
|
|
5668
|
+
}
|
|
5669
|
+
}
|
|
5670
|
+
});
|
|
5671
|
+
}
|
|
5672
|
+
/**
|
|
5673
|
+
* All active WebSocket client connections.
|
|
5674
|
+
*/
|
|
5675
|
+
clients;
|
|
5676
|
+
/**
|
|
5677
|
+
* Adds the given `WebSocket` client connection to the set
|
|
5678
|
+
* of all connections. The given connection is always the complete
|
|
5679
|
+
* connection object because `addConnection()` is called only
|
|
5680
|
+
* for the opened connections in the same runtime.
|
|
5681
|
+
*/
|
|
5682
|
+
addConnection(client) {
|
|
5683
|
+
this.clients.add(client);
|
|
5684
|
+
this.channel.postMessage({
|
|
5685
|
+
type: "connection:open",
|
|
5686
|
+
payload: {
|
|
5687
|
+
clientId: client.id,
|
|
5688
|
+
url: client.url.toString()
|
|
5689
|
+
}
|
|
5690
|
+
});
|
|
5691
|
+
const handleExtraneousMessage = (message3) => {
|
|
5692
|
+
const { type, payload } = message3.data;
|
|
5693
|
+
if (typeof payload === "object" && "clientId" in payload && payload.clientId !== client.id) {
|
|
5694
|
+
return;
|
|
5695
|
+
}
|
|
5696
|
+
switch (type) {
|
|
5697
|
+
case "extraneous:send": {
|
|
5698
|
+
client.send(payload.data);
|
|
5699
|
+
break;
|
|
5700
|
+
}
|
|
5701
|
+
case "extraneous:close": {
|
|
5702
|
+
client.close(payload.code, payload.reason);
|
|
5703
|
+
break;
|
|
5704
|
+
}
|
|
5705
|
+
}
|
|
5706
|
+
};
|
|
5707
|
+
const abortController = new AbortController();
|
|
5708
|
+
this.channel.addEventListener("message", handleExtraneousMessage, {
|
|
5709
|
+
signal: abortController.signal
|
|
5710
|
+
});
|
|
5711
|
+
client.addEventListener("close", () => abortController.abort(), {
|
|
5712
|
+
once: true
|
|
5713
|
+
});
|
|
5714
|
+
}
|
|
5715
|
+
/**
|
|
5716
|
+
* Adds a client connection wrapper to operate with
|
|
5717
|
+
* WebSocket client connections in other runtimes.
|
|
5718
|
+
*/
|
|
5719
|
+
onRemoteConnection(id, url) {
|
|
5720
|
+
this.clients.add(
|
|
5721
|
+
// Create a connection-compatible instance that can
|
|
5722
|
+
// operate with this client from a different runtime
|
|
5723
|
+
// using the BroadcastChannel messages.
|
|
5724
|
+
new WebSocketRemoteClientConnection(id, url, this.channel)
|
|
5725
|
+
);
|
|
5726
|
+
}
|
|
5727
|
+
};
|
|
5728
|
+
var WebSocketRemoteClientConnection = class {
|
|
5729
|
+
constructor(id, url, channel) {
|
|
5730
|
+
this.id = id;
|
|
5731
|
+
this.url = url;
|
|
5732
|
+
this.channel = channel;
|
|
5733
|
+
}
|
|
5734
|
+
send(data) {
|
|
5735
|
+
this.channel.postMessage({
|
|
5736
|
+
type: "extraneous:send",
|
|
5737
|
+
payload: {
|
|
5738
|
+
clientId: this.id,
|
|
5739
|
+
data
|
|
5740
|
+
}
|
|
5741
|
+
});
|
|
5742
|
+
}
|
|
5743
|
+
close(code, reason) {
|
|
5744
|
+
this.channel.postMessage({
|
|
5745
|
+
type: "extraneous:close",
|
|
5746
|
+
payload: {
|
|
5747
|
+
clientId: this.id,
|
|
5748
|
+
code,
|
|
5749
|
+
reason
|
|
5750
|
+
}
|
|
5751
|
+
});
|
|
5752
|
+
}
|
|
5753
|
+
};
|
|
5754
|
+
|
|
5755
|
+
// src/core/ws/ws.ts
|
|
5756
|
+
var wsBroadcastChannel = new BroadcastChannel("msw:ws-client-manager");
|
|
5757
|
+
function createWebSocketLinkHandler(url) {
|
|
5758
|
+
invariant(url, "Expected a WebSocket server URL but got undefined");
|
|
5759
|
+
invariant(
|
|
5760
|
+
isPath(url),
|
|
5761
|
+
"Expected a WebSocket server URL but got %s",
|
|
5762
|
+
typeof url
|
|
5763
|
+
);
|
|
5764
|
+
const clientManager = new WebSocketClientManager(wsBroadcastChannel);
|
|
5765
|
+
return {
|
|
5766
|
+
clients: clientManager.clients,
|
|
5767
|
+
on(event, listener) {
|
|
5768
|
+
const handler = new WebSocketHandler(url);
|
|
5769
|
+
handler[kEmitter].on("connection", ({ client }) => {
|
|
5770
|
+
clientManager.addConnection(client);
|
|
5771
|
+
});
|
|
5772
|
+
handler[kEmitter].on(event, listener);
|
|
5773
|
+
return handler;
|
|
5774
|
+
},
|
|
5775
|
+
/**
|
|
5776
|
+
* Broadcasts the given data to all WebSocket clients.
|
|
5777
|
+
*
|
|
5778
|
+
* @example
|
|
5779
|
+
* const service = ws.link('wss://example.com')
|
|
5780
|
+
* service.on('connection', () => {
|
|
5781
|
+
* service.broadcast('hello, everyone!')
|
|
5782
|
+
* })
|
|
5783
|
+
*/
|
|
5784
|
+
broadcast(data) {
|
|
5785
|
+
this.broadcastExcept([], data);
|
|
5786
|
+
},
|
|
5787
|
+
/**
|
|
5788
|
+
* Broadcasts the given data to all WebSocket clients
|
|
5789
|
+
* except the ones provided in the `clients` argument.
|
|
5790
|
+
*
|
|
5791
|
+
* @example
|
|
5792
|
+
* const service = ws.link('wss://example.com')
|
|
5793
|
+
* service.on('connection', ({ client }) => {
|
|
5794
|
+
* service.broadcastExcept(client, 'hi, the rest of you!')
|
|
5795
|
+
* })
|
|
5796
|
+
*/
|
|
5797
|
+
broadcastExcept(clients, data) {
|
|
5798
|
+
const ignoreClients = Array.prototype.concat(clients).map((client) => client.id);
|
|
5799
|
+
clientManager.clients.forEach((otherClient) => {
|
|
5800
|
+
if (!ignoreClients.includes(otherClient.id)) {
|
|
5801
|
+
otherClient.send(data);
|
|
5802
|
+
}
|
|
5803
|
+
});
|
|
5804
|
+
}
|
|
5805
|
+
};
|
|
5806
|
+
}
|
|
5807
|
+
var ws = {
|
|
5808
|
+
link: createWebSocketLinkHandler
|
|
5809
|
+
};
|
|
5810
|
+
|
|
5610
5811
|
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
5611
5812
|
var until = async (promise) => {
|
|
5612
5813
|
try {
|
|
@@ -5629,6 +5830,9 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5629
5830
|
let matchingHandler = null;
|
|
5630
5831
|
let result = null;
|
|
5631
5832
|
for (const handler of handlers) {
|
|
5833
|
+
if (!(handler instanceof RequestHandler)) {
|
|
5834
|
+
continue;
|
|
5835
|
+
}
|
|
5632
5836
|
result = await handler.run({ request, requestId, resolutionContext });
|
|
5633
5837
|
if (result !== null) {
|
|
5634
5838
|
matchingHandler = handler;
|
|
@@ -6481,14 +6685,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6481
6685
|
}
|
|
6482
6686
|
};
|
|
6483
6687
|
|
|
6484
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6485
|
-
function uuidv4() {
|
|
6486
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
6487
|
-
const r = Math.random() * 16 | 0;
|
|
6488
|
-
const v = c == "x" ? r : r & 3 | 8;
|
|
6489
|
-
return v.toString(16);
|
|
6490
|
-
});
|
|
6491
|
-
}
|
|
6688
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/chunk-OUWBQF3Z.mjs
|
|
6492
6689
|
var RequestController = class {
|
|
6493
6690
|
constructor(request) {
|
|
6494
6691
|
this.request = request;
|
|
@@ -6526,7 +6723,16 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6526
6723
|
}
|
|
6527
6724
|
}
|
|
6528
6725
|
|
|
6529
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6726
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/chunk-CEKC26XE.mjs
|
|
6727
|
+
function uuidv4() {
|
|
6728
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
6729
|
+
const r = Math.random() * 16 | 0;
|
|
6730
|
+
const v = c == "x" ? r : r & 3 | 8;
|
|
6731
|
+
return v.toString(16);
|
|
6732
|
+
});
|
|
6733
|
+
}
|
|
6734
|
+
|
|
6735
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/chunk-65OQZE6W.mjs
|
|
6530
6736
|
function isPropertyAccessible2(obj, key) {
|
|
6531
6737
|
try {
|
|
6532
6738
|
obj[key];
|
|
@@ -6673,7 +6879,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6673
6879
|
});
|
|
6674
6880
|
}
|
|
6675
6881
|
|
|
6676
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6882
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/chunk-6ZIL5FW4.mjs
|
|
6677
6883
|
function concatArrayBuffer(left, right) {
|
|
6678
6884
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
6679
6885
|
result.set(left, 0);
|
|
@@ -7272,7 +7478,11 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7272
7478
|
const XMLHttpRequestProxy = new Proxy(globalThis.XMLHttpRequest, {
|
|
7273
7479
|
construct(target, args, newTarget) {
|
|
7274
7480
|
logger.info("constructed new XMLHttpRequest");
|
|
7275
|
-
const originalRequest = Reflect.construct(
|
|
7481
|
+
const originalRequest = Reflect.construct(
|
|
7482
|
+
target,
|
|
7483
|
+
args,
|
|
7484
|
+
newTarget
|
|
7485
|
+
);
|
|
7276
7486
|
const prototypeDescriptors = Object.getOwnPropertyDescriptors(
|
|
7277
7487
|
target.prototype
|
|
7278
7488
|
);
|
|
@@ -7491,6 +7701,475 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7491
7701
|
}
|
|
7492
7702
|
}
|
|
7493
7703
|
|
|
7704
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
7705
|
+
function bindEvent(target, event) {
|
|
7706
|
+
Object.defineProperty(event, "target", {
|
|
7707
|
+
enumerable: true,
|
|
7708
|
+
writable: true,
|
|
7709
|
+
value: target
|
|
7710
|
+
});
|
|
7711
|
+
return event;
|
|
7712
|
+
}
|
|
7713
|
+
var kCancelable = Symbol("kCancelable");
|
|
7714
|
+
var kDefaultPrevented2 = Symbol("kDefaultPrevented");
|
|
7715
|
+
var CancelableMessageEvent = class extends MessageEvent {
|
|
7716
|
+
constructor(type, init) {
|
|
7717
|
+
super(type, init);
|
|
7718
|
+
this[kCancelable] = !!init.cancelable;
|
|
7719
|
+
this[kDefaultPrevented2] = false;
|
|
7720
|
+
}
|
|
7721
|
+
get cancelable() {
|
|
7722
|
+
return this[kCancelable];
|
|
7723
|
+
}
|
|
7724
|
+
get defaultPrevented() {
|
|
7725
|
+
return this[kDefaultPrevented2];
|
|
7726
|
+
}
|
|
7727
|
+
preventDefault() {
|
|
7728
|
+
if (this.cancelable && !this[kDefaultPrevented2]) {
|
|
7729
|
+
this[kDefaultPrevented2] = true;
|
|
7730
|
+
}
|
|
7731
|
+
}
|
|
7732
|
+
};
|
|
7733
|
+
var CloseEvent = class extends Event {
|
|
7734
|
+
constructor(type, init = {}) {
|
|
7735
|
+
super(type, init);
|
|
7736
|
+
this.code = init.code === void 0 ? 0 : init.code;
|
|
7737
|
+
this.reason = init.reason === void 0 ? "" : init.reason;
|
|
7738
|
+
this.wasClean = init.wasClean === void 0 ? false : init.wasClean;
|
|
7739
|
+
}
|
|
7740
|
+
};
|
|
7741
|
+
var kEmitter2 = Symbol("kEmitter");
|
|
7742
|
+
var WebSocketClientConnection = class {
|
|
7743
|
+
constructor(socket, transport) {
|
|
7744
|
+
this.socket = socket;
|
|
7745
|
+
this.transport = transport;
|
|
7746
|
+
this.id = uuidv4();
|
|
7747
|
+
this.url = new URL(socket.url);
|
|
7748
|
+
this[kEmitter2] = new EventTarget();
|
|
7749
|
+
this.transport.onOutgoing = (data) => {
|
|
7750
|
+
this[kEmitter2].dispatchEvent(
|
|
7751
|
+
bindEvent(this.socket, new MessageEvent("message", { data }))
|
|
7752
|
+
);
|
|
7753
|
+
};
|
|
7754
|
+
this.transport.onClose = (event) => {
|
|
7755
|
+
this[kEmitter2].dispatchEvent(
|
|
7756
|
+
bindEvent(this.socket, new CloseEvent("close", event))
|
|
7757
|
+
);
|
|
7758
|
+
};
|
|
7759
|
+
}
|
|
7760
|
+
/**
|
|
7761
|
+
* Listen for the outgoing events from the connected WebSocket client.
|
|
7762
|
+
*/
|
|
7763
|
+
addEventListener(event, listener, options) {
|
|
7764
|
+
this[kEmitter2].addEventListener(event, listener, options);
|
|
7765
|
+
}
|
|
7766
|
+
/**
|
|
7767
|
+
* Removes the listener for the given event.
|
|
7768
|
+
*/
|
|
7769
|
+
removeEventListener(event, listener, options) {
|
|
7770
|
+
this[kEmitter2].removeEventListener(
|
|
7771
|
+
event,
|
|
7772
|
+
listener,
|
|
7773
|
+
options
|
|
7774
|
+
);
|
|
7775
|
+
}
|
|
7776
|
+
/**
|
|
7777
|
+
* Send data to the connected client.
|
|
7778
|
+
*/
|
|
7779
|
+
send(data) {
|
|
7780
|
+
this.transport.send(data);
|
|
7781
|
+
}
|
|
7782
|
+
/**
|
|
7783
|
+
* Close the WebSocket connection.
|
|
7784
|
+
* @param {number} code A status code (see https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1).
|
|
7785
|
+
* @param {string} reason A custom connection close reason.
|
|
7786
|
+
*/
|
|
7787
|
+
close(code, reason) {
|
|
7788
|
+
this.transport.close(code, reason);
|
|
7789
|
+
}
|
|
7790
|
+
};
|
|
7791
|
+
var kEmitter22 = Symbol("kEmitter");
|
|
7792
|
+
var WebSocketServerConnection = class {
|
|
7793
|
+
constructor(socket, transport, createConnection) {
|
|
7794
|
+
this.socket = socket;
|
|
7795
|
+
this.transport = transport;
|
|
7796
|
+
this.createConnection = createConnection;
|
|
7797
|
+
this[kEmitter22] = new EventTarget();
|
|
7798
|
+
this.transport.onIncoming = (event) => {
|
|
7799
|
+
const messageEvent = bindEvent(
|
|
7800
|
+
this.realWebSocket,
|
|
7801
|
+
new CancelableMessageEvent("message", {
|
|
7802
|
+
data: event.data,
|
|
7803
|
+
origin: event.origin,
|
|
7804
|
+
cancelable: true
|
|
7805
|
+
})
|
|
7806
|
+
);
|
|
7807
|
+
this[kEmitter22].dispatchEvent(messageEvent);
|
|
7808
|
+
if (!messageEvent.defaultPrevented) {
|
|
7809
|
+
this.socket.dispatchEvent(
|
|
7810
|
+
bindEvent(
|
|
7811
|
+
/**
|
|
7812
|
+
* @note Bind the forwarded original server events
|
|
7813
|
+
* to the mock WebSocket instance so it would
|
|
7814
|
+
* dispatch them straight away.
|
|
7815
|
+
*/
|
|
7816
|
+
this.socket,
|
|
7817
|
+
// Clone the message event again to prevent
|
|
7818
|
+
// the "already being dispatched" exception.
|
|
7819
|
+
new MessageEvent("message", {
|
|
7820
|
+
data: event.data,
|
|
7821
|
+
origin: event.origin
|
|
7822
|
+
})
|
|
7823
|
+
)
|
|
7824
|
+
);
|
|
7825
|
+
}
|
|
7826
|
+
};
|
|
7827
|
+
}
|
|
7828
|
+
/**
|
|
7829
|
+
* Server ready state.
|
|
7830
|
+
* Proxies the ready state of the original WebSocket instance,
|
|
7831
|
+
* if set. If the original connection hasn't been established,
|
|
7832
|
+
* defaults to `-1`.
|
|
7833
|
+
*/
|
|
7834
|
+
get readyState() {
|
|
7835
|
+
if (this.realWebSocket) {
|
|
7836
|
+
return this.realWebSocket.readyState;
|
|
7837
|
+
}
|
|
7838
|
+
return -1;
|
|
7839
|
+
}
|
|
7840
|
+
/**
|
|
7841
|
+
* Open connection to the original WebSocket server.
|
|
7842
|
+
*/
|
|
7843
|
+
connect() {
|
|
7844
|
+
invariant(
|
|
7845
|
+
this.readyState === -1,
|
|
7846
|
+
'Failed to call "connect()" on the original WebSocket instance: the connection already open'
|
|
7847
|
+
);
|
|
7848
|
+
const ws2 = this.createConnection();
|
|
7849
|
+
ws2.binaryType = this.socket.binaryType;
|
|
7850
|
+
this.socket.addEventListener(
|
|
7851
|
+
"close",
|
|
7852
|
+
(event) => {
|
|
7853
|
+
ws2.close(event.code, event.reason);
|
|
7854
|
+
},
|
|
7855
|
+
{ once: true }
|
|
7856
|
+
);
|
|
7857
|
+
ws2.addEventListener("message", (event) => {
|
|
7858
|
+
this.transport.onIncoming(event);
|
|
7859
|
+
});
|
|
7860
|
+
ws2.addEventListener("error", () => {
|
|
7861
|
+
this.socket.dispatchEvent(bindEvent(this.socket, new Event("error")));
|
|
7862
|
+
});
|
|
7863
|
+
this.realWebSocket = ws2;
|
|
7864
|
+
}
|
|
7865
|
+
/**
|
|
7866
|
+
* Listen for the incoming events from the original WebSocket server.
|
|
7867
|
+
*/
|
|
7868
|
+
addEventListener(event, listener, options) {
|
|
7869
|
+
this[kEmitter22].addEventListener(
|
|
7870
|
+
event,
|
|
7871
|
+
listener.bind(this.realWebSocket),
|
|
7872
|
+
options
|
|
7873
|
+
);
|
|
7874
|
+
}
|
|
7875
|
+
/**
|
|
7876
|
+
* Removes the listener for the given event.
|
|
7877
|
+
*/
|
|
7878
|
+
removeEventListener(event, listener, options) {
|
|
7879
|
+
this[kEmitter22].removeEventListener(
|
|
7880
|
+
event,
|
|
7881
|
+
listener,
|
|
7882
|
+
options
|
|
7883
|
+
);
|
|
7884
|
+
}
|
|
7885
|
+
/**
|
|
7886
|
+
* Send data to the original WebSocket server.
|
|
7887
|
+
* @example
|
|
7888
|
+
* server.send('hello')
|
|
7889
|
+
* server.send(new Blob(['hello']))
|
|
7890
|
+
* server.send(new TextEncoder().encode('hello'))
|
|
7891
|
+
*/
|
|
7892
|
+
send(data) {
|
|
7893
|
+
const { realWebSocket } = this;
|
|
7894
|
+
invariant(
|
|
7895
|
+
realWebSocket,
|
|
7896
|
+
'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "await server.connect()"?',
|
|
7897
|
+
this.socket.url
|
|
7898
|
+
);
|
|
7899
|
+
if (realWebSocket.readyState === realWebSocket.CONNECTING) {
|
|
7900
|
+
realWebSocket.addEventListener(
|
|
7901
|
+
"open",
|
|
7902
|
+
() => {
|
|
7903
|
+
realWebSocket.send(data);
|
|
7904
|
+
},
|
|
7905
|
+
{ once: true }
|
|
7906
|
+
);
|
|
7907
|
+
return;
|
|
7908
|
+
}
|
|
7909
|
+
realWebSocket.send(data);
|
|
7910
|
+
}
|
|
7911
|
+
};
|
|
7912
|
+
var WebSocketTransport = class {
|
|
7913
|
+
};
|
|
7914
|
+
var WEBSOCKET_CLOSE_CODE_RANGE_ERROR = "InvalidAccessError: close code out of user configurable range";
|
|
7915
|
+
var kOnSend = Symbol("kOnSend");
|
|
7916
|
+
var kClose = Symbol("kClose");
|
|
7917
|
+
var WebSocketOverride = class extends EventTarget {
|
|
7918
|
+
constructor(url, protocols) {
|
|
7919
|
+
super();
|
|
7920
|
+
this.CONNECTING = 0;
|
|
7921
|
+
this.OPEN = 1;
|
|
7922
|
+
this.CLOSING = 2;
|
|
7923
|
+
this.CLOSED = 3;
|
|
7924
|
+
this._onopen = null;
|
|
7925
|
+
this._onmessage = null;
|
|
7926
|
+
this._onerror = null;
|
|
7927
|
+
this._onclose = null;
|
|
7928
|
+
this.url = url.toString();
|
|
7929
|
+
this.protocol = "";
|
|
7930
|
+
this.extensions = "";
|
|
7931
|
+
this.binaryType = "blob";
|
|
7932
|
+
this.readyState = this.CONNECTING;
|
|
7933
|
+
this.bufferedAmount = 0;
|
|
7934
|
+
Reflect.set(this, "readyState", this.CONNECTING);
|
|
7935
|
+
queueMicrotask(() => {
|
|
7936
|
+
Reflect.set(this, "readyState", this.OPEN);
|
|
7937
|
+
this.protocol = protocols ? protocols[0] : "ws";
|
|
7938
|
+
this.dispatchEvent(bindEvent(this, new Event("open")));
|
|
7939
|
+
});
|
|
7940
|
+
}
|
|
7941
|
+
set onopen(listener) {
|
|
7942
|
+
this.removeEventListener("open", this._onopen);
|
|
7943
|
+
this._onopen = listener;
|
|
7944
|
+
if (listener !== null) {
|
|
7945
|
+
this.addEventListener("open", listener);
|
|
7946
|
+
}
|
|
7947
|
+
}
|
|
7948
|
+
get onopen() {
|
|
7949
|
+
return this._onopen;
|
|
7950
|
+
}
|
|
7951
|
+
set onmessage(listener) {
|
|
7952
|
+
this.removeEventListener(
|
|
7953
|
+
"message",
|
|
7954
|
+
this._onmessage
|
|
7955
|
+
);
|
|
7956
|
+
this._onmessage = listener;
|
|
7957
|
+
if (listener !== null) {
|
|
7958
|
+
this.addEventListener("message", listener);
|
|
7959
|
+
}
|
|
7960
|
+
}
|
|
7961
|
+
get onmessage() {
|
|
7962
|
+
return this._onmessage;
|
|
7963
|
+
}
|
|
7964
|
+
set onerror(listener) {
|
|
7965
|
+
this.removeEventListener("error", this._onerror);
|
|
7966
|
+
this._onerror = listener;
|
|
7967
|
+
if (listener !== null) {
|
|
7968
|
+
this.addEventListener("error", listener);
|
|
7969
|
+
}
|
|
7970
|
+
}
|
|
7971
|
+
get onerror() {
|
|
7972
|
+
return this._onerror;
|
|
7973
|
+
}
|
|
7974
|
+
set onclose(listener) {
|
|
7975
|
+
this.removeEventListener("close", this._onclose);
|
|
7976
|
+
this._onclose = listener;
|
|
7977
|
+
if (listener !== null) {
|
|
7978
|
+
this.addEventListener("close", listener);
|
|
7979
|
+
}
|
|
7980
|
+
}
|
|
7981
|
+
get onclose() {
|
|
7982
|
+
return this._onclose;
|
|
7983
|
+
}
|
|
7984
|
+
/**
|
|
7985
|
+
* @see https://websockets.spec.whatwg.org/#ref-for-dom-websocket-send%E2%91%A0
|
|
7986
|
+
*/
|
|
7987
|
+
send(data) {
|
|
7988
|
+
if (this.readyState === this.CONNECTING) {
|
|
7989
|
+
this.close();
|
|
7990
|
+
throw new DOMException("InvalidStateError");
|
|
7991
|
+
}
|
|
7992
|
+
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) {
|
|
7993
|
+
return;
|
|
7994
|
+
}
|
|
7995
|
+
this.bufferedAmount += getDataSize(data);
|
|
7996
|
+
queueMicrotask(() => {
|
|
7997
|
+
var _a2;
|
|
7998
|
+
this.bufferedAmount = 0;
|
|
7999
|
+
(_a2 = this[kOnSend]) == null ? void 0 : _a2.call(this, data);
|
|
8000
|
+
});
|
|
8001
|
+
}
|
|
8002
|
+
close(code = 1e3, reason) {
|
|
8003
|
+
invariant(code, WEBSOCKET_CLOSE_CODE_RANGE_ERROR);
|
|
8004
|
+
invariant(
|
|
8005
|
+
code === 1e3 || code >= 3e3 && code <= 4999,
|
|
8006
|
+
WEBSOCKET_CLOSE_CODE_RANGE_ERROR
|
|
8007
|
+
);
|
|
8008
|
+
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) {
|
|
8009
|
+
return;
|
|
8010
|
+
}
|
|
8011
|
+
this[kClose](code, reason);
|
|
8012
|
+
}
|
|
8013
|
+
[(kOnSend, kClose)](code = 1e3, reason) {
|
|
8014
|
+
this.readyState = this.CLOSING;
|
|
8015
|
+
queueMicrotask(() => {
|
|
8016
|
+
this.readyState = this.CLOSED;
|
|
8017
|
+
if (code > 1e3 && code <= 1015) {
|
|
8018
|
+
this.dispatchEvent(bindEvent(this, new Event("error")));
|
|
8019
|
+
}
|
|
8020
|
+
this.dispatchEvent(
|
|
8021
|
+
bindEvent(
|
|
8022
|
+
this,
|
|
8023
|
+
new CloseEvent("close", {
|
|
8024
|
+
code,
|
|
8025
|
+
reason,
|
|
8026
|
+
wasClean: code === 1e3
|
|
8027
|
+
})
|
|
8028
|
+
)
|
|
8029
|
+
);
|
|
8030
|
+
this._onopen = null;
|
|
8031
|
+
this._onmessage = null;
|
|
8032
|
+
this._onerror = null;
|
|
8033
|
+
this._onclose = null;
|
|
8034
|
+
});
|
|
8035
|
+
}
|
|
8036
|
+
addEventListener(type, listener, options) {
|
|
8037
|
+
return super.addEventListener(
|
|
8038
|
+
type,
|
|
8039
|
+
listener,
|
|
8040
|
+
options
|
|
8041
|
+
);
|
|
8042
|
+
}
|
|
8043
|
+
removeEventListener(type, callback, options) {
|
|
8044
|
+
return super.removeEventListener(type, callback, options);
|
|
8045
|
+
}
|
|
8046
|
+
};
|
|
8047
|
+
WebSocketOverride.CONNECTING = 0;
|
|
8048
|
+
WebSocketOverride.OPEN = 1;
|
|
8049
|
+
WebSocketOverride.CLOSING = 2;
|
|
8050
|
+
WebSocketOverride.CLOSED = 3;
|
|
8051
|
+
function getDataSize(data) {
|
|
8052
|
+
if (typeof data === "string") {
|
|
8053
|
+
return data.length;
|
|
8054
|
+
}
|
|
8055
|
+
if (data instanceof Blob) {
|
|
8056
|
+
return data.size;
|
|
8057
|
+
}
|
|
8058
|
+
return data.byteLength;
|
|
8059
|
+
}
|
|
8060
|
+
var WebSocketClassTransport = class extends WebSocketTransport {
|
|
8061
|
+
constructor(socket) {
|
|
8062
|
+
super();
|
|
8063
|
+
this.socket = socket;
|
|
8064
|
+
this.onOutgoing = () => {
|
|
8065
|
+
};
|
|
8066
|
+
this.onIncoming = () => {
|
|
8067
|
+
};
|
|
8068
|
+
this.onClose = () => {
|
|
8069
|
+
};
|
|
8070
|
+
this.socket.addEventListener("close", (event) => this.onClose(event), {
|
|
8071
|
+
once: true
|
|
8072
|
+
});
|
|
8073
|
+
this.socket[kOnSend] = (...args) => this.onOutgoing(...args);
|
|
8074
|
+
}
|
|
8075
|
+
send(data) {
|
|
8076
|
+
queueMicrotask(() => {
|
|
8077
|
+
const message3 = bindEvent(
|
|
8078
|
+
/**
|
|
8079
|
+
* @note Setting this event's "target" to the
|
|
8080
|
+
* WebSocket override instance is important.
|
|
8081
|
+
* This way it can tell apart original incoming events
|
|
8082
|
+
* (must be forwarded to the transport) from the
|
|
8083
|
+
* mocked message events like the one below
|
|
8084
|
+
* (must be dispatched on the client instance).
|
|
8085
|
+
*/
|
|
8086
|
+
this.socket,
|
|
8087
|
+
new MessageEvent("message", {
|
|
8088
|
+
data,
|
|
8089
|
+
origin: this.socket.url
|
|
8090
|
+
})
|
|
8091
|
+
);
|
|
8092
|
+
this.socket.dispatchEvent(message3);
|
|
8093
|
+
});
|
|
8094
|
+
}
|
|
8095
|
+
close(code, reason) {
|
|
8096
|
+
this.socket[kClose](code, reason);
|
|
8097
|
+
}
|
|
8098
|
+
};
|
|
8099
|
+
var _WebSocketInterceptor = class extends Interceptor {
|
|
8100
|
+
constructor() {
|
|
8101
|
+
super(_WebSocketInterceptor.symbol);
|
|
8102
|
+
}
|
|
8103
|
+
checkEnvironment() {
|
|
8104
|
+
return typeof globalThis.WebSocket !== "undefined";
|
|
8105
|
+
}
|
|
8106
|
+
setup() {
|
|
8107
|
+
const originalWebSocket = globalThis.WebSocket;
|
|
8108
|
+
const webSocketProxy = new Proxy(globalThis.WebSocket, {
|
|
8109
|
+
construct: (target, args, newTarget) => {
|
|
8110
|
+
const [url, protocols] = args;
|
|
8111
|
+
const createConnection = () => {
|
|
8112
|
+
return Reflect.construct(target, args, newTarget);
|
|
8113
|
+
};
|
|
8114
|
+
const socket = new WebSocketOverride(url, protocols);
|
|
8115
|
+
const transport = new WebSocketClassTransport(socket);
|
|
8116
|
+
queueMicrotask(() => {
|
|
8117
|
+
this.emitter.emit("connection", {
|
|
8118
|
+
client: new WebSocketClientConnection(socket, transport),
|
|
8119
|
+
server: new WebSocketServerConnection(
|
|
8120
|
+
socket,
|
|
8121
|
+
transport,
|
|
8122
|
+
createConnection
|
|
8123
|
+
)
|
|
8124
|
+
});
|
|
8125
|
+
});
|
|
8126
|
+
return socket;
|
|
8127
|
+
}
|
|
8128
|
+
});
|
|
8129
|
+
globalThis.WebSocket = webSocketProxy;
|
|
8130
|
+
this.subscriptions.push(() => {
|
|
8131
|
+
globalThis.WebSocket = originalWebSocket;
|
|
8132
|
+
});
|
|
8133
|
+
}
|
|
8134
|
+
};
|
|
8135
|
+
var WebSocketInterceptor = _WebSocketInterceptor;
|
|
8136
|
+
WebSocketInterceptor.symbol = Symbol("websocket");
|
|
8137
|
+
|
|
8138
|
+
// src/core/ws/webSocketInterceptor.ts
|
|
8139
|
+
var webSocketInterceptor = new WebSocketInterceptor();
|
|
8140
|
+
|
|
8141
|
+
// src/core/utils/handleWebSocketEvent.ts
|
|
8142
|
+
function handleWebSocketEvent(getCurrentHandlers) {
|
|
8143
|
+
webSocketInterceptor.on("connection", (connection) => {
|
|
8144
|
+
const handlers = getCurrentHandlers();
|
|
8145
|
+
const connectionEvent = new MessageEvent("connection", {
|
|
8146
|
+
data: connection
|
|
8147
|
+
/**
|
|
8148
|
+
* @note This message event should be marked as "cancelable"
|
|
8149
|
+
* to have its default prevented using "event.preventDefault()".
|
|
8150
|
+
* There's a bug in Node.js that breaks the "cancelable" flag.
|
|
8151
|
+
* @see https://github.com/nodejs/node/issues/51767
|
|
8152
|
+
*/
|
|
8153
|
+
});
|
|
8154
|
+
Object.defineProperty(connectionEvent, kDefaultPrevented, {
|
|
8155
|
+
enumerable: false,
|
|
8156
|
+
writable: true,
|
|
8157
|
+
value: false
|
|
8158
|
+
});
|
|
8159
|
+
for (const handler of handlers) {
|
|
8160
|
+
if (handler instanceof WebSocketHandler) {
|
|
8161
|
+
handler[kDispatchEvent](connectionEvent);
|
|
8162
|
+
}
|
|
8163
|
+
}
|
|
8164
|
+
if (!Reflect.get(connectionEvent, kDefaultPrevented)) {
|
|
8165
|
+
connection.server.connect();
|
|
8166
|
+
connection.client.addEventListener("message", (event) => {
|
|
8167
|
+
connection.server.send(event.data);
|
|
8168
|
+
});
|
|
8169
|
+
}
|
|
8170
|
+
});
|
|
8171
|
+
}
|
|
8172
|
+
|
|
7494
8173
|
// src/browser/setupWorker/setupWorker.ts
|
|
7495
8174
|
var SetupWorkerApi = class extends SetupApi {
|
|
7496
8175
|
context;
|
|
@@ -7607,6 +8286,13 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7607
8286
|
DEFAULT_START_OPTIONS,
|
|
7608
8287
|
options
|
|
7609
8288
|
);
|
|
8289
|
+
handleWebSocketEvent(() => {
|
|
8290
|
+
return this.handlersController.currentHandlers();
|
|
8291
|
+
});
|
|
8292
|
+
webSocketInterceptor.apply();
|
|
8293
|
+
this.subscriptions.push(() => {
|
|
8294
|
+
webSocketInterceptor.dispose();
|
|
8295
|
+
});
|
|
7610
8296
|
return await this.startHandler(this.context.startOptions, options);
|
|
7611
8297
|
}
|
|
7612
8298
|
stop() {
|