diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 2a52fdd..eed1df6 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -10,6 +10,7 @@ "dependencies": { "@noble/curves": "^1.1.0", "@noble/hashes": "^1.3.1", + "detect-node": "^2.1.0", "level": "^8.0.0", "multiformats": "^12.0.1", "p-defer": "^4.0.0", @@ -5971,6 +5972,11 @@ "node": ">=8" } }, + "node_modules/detect-node": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz", + "integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==" + }, "node_modules/diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", diff --git a/package.json b/package.json index e83c438..d32ead0 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies": { "@noble/curves": "^1.1.0", "@noble/hashes": "^1.3.1", + "detect-node": "^2.1.0", "level": "^8.0.0", "multiformats": "^12.0.1", "p-defer": "^4.0.0", diff --git a/src/transports/index.ts b/src/transports/index.ts index ee3b81d..b8f5df5 100644 --- a/src/transports/index.ts +++ b/src/transports/index.ts @@ -2,7 +2,7 @@ import { URL } from "url"; import { TcpPeer } from "#transports/tcp.js"; import { WebSocketPeer } from "#transports/webSocket.js"; import { PeerStatic } from "#types.js"; - +import isNode from "detect-node"; const transports = new Map(); export function registerTransport(type: string, transport: PeerStatic) { @@ -37,6 +37,8 @@ export function createTransportPeer( return new transport(socket, connectionUris); } -registerTransport("tcp", TcpPeer); +if (isNode) { + registerTransport("tcp", TcpPeer); +} registerTransport("ws", WebSocketPeer); registerTransport("wss", WebSocketPeer);