Skip to content

Commit c34af58

Browse files
committed
For good measure, dynamic load both transports just in case
1 parent 14525a6 commit c34af58

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/core/transport/WebSocketTransportFactory.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { ITransport, ITransportFactory } from "./Transport.js";
2-
import { NativeWebSocketTransport } from "./NativeWebSocketTransport.js";
32

43
/**
54
* A transport factory that uses WebSockets to send and receive messages.
@@ -14,6 +13,8 @@ export const WebSocketTransportFactory: ITransportFactory = async (
1413
): Promise<ITransport> => {
1514
// Browsers, Deno, Bun, and Node 22+ support WebSockets natively
1615
if (typeof WebSocket === "function") {
16+
const transportModule = await import("./NativeWebSocketTransport.js");
17+
const { NativeWebSocketTransport } = transportModule;
1718
const socket = new WebSocket(url);
1819
socket.binaryType = "arraybuffer";
1920
return new NativeWebSocketTransport(socket);
@@ -23,7 +24,8 @@ export const WebSocketTransportFactory: ITransportFactory = async (
2324
// Dynamically import the dependencies as they may not
2425
// be available in a browser environment.
2526
const ws = await import("ws");
26-
const { WsWebSocketTransport } = await import("./WsWebSocketTransport.js");
27+
const transportModule = await import("./WsWebSocketTransport.js");
28+
const { WsWebSocketTransport } = transportModule;
2729
const socket = new ws.WebSocket(url);
2830
socket.binaryType = "arraybuffer";
2931
return new WsWebSocketTransport(socket);

0 commit comments

Comments
 (0)