diff --git a/modules/chronik-client/README.md b/modules/chronik-client/README.md --- a/modules/chronik-client/README.md +++ b/modules/chronik-client/README.md @@ -103,3 +103,4 @@ - 0.24.0 - Support `subscribeToAddress` and `unsubscribeFromAddress` methods in the `ChronikClientNode` websocket - 0.25.0 - Organize websocket subscriptions for `ChronikClientNode` under object instead of array - 0.25.1 - Move `ecashaddrjs` from dev dependency to dependency +- 0.25.2 - Fix this package to work in the browser without requiring `Buffer` shim diff --git a/modules/chronik-client/package-lock.json b/modules/chronik-client/package-lock.json --- a/modules/chronik-client/package-lock.json +++ b/modules/chronik-client/package-lock.json @@ -1,12 +1,12 @@ { "name": "chronik-client", - "version": "0.25.1", + "version": "0.25.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "chronik-client", - "version": "0.25.1", + "version": "0.25.2", "license": "MIT", "dependencies": { "@types/ws": "^8.2.1", diff --git a/modules/chronik-client/package.json b/modules/chronik-client/package.json --- a/modules/chronik-client/package.json +++ b/modules/chronik-client/package.json @@ -1,6 +1,6 @@ { "name": "chronik-client", - "version": "0.25.1", + "version": "0.25.2", "description": "A client for accessing the Chronik Indexer API", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/modules/chronik-client/src/ChronikClient.ts b/modules/chronik-client/src/ChronikClient.ts --- a/modules/chronik-client/src/ChronikClient.ts +++ b/modules/chronik-client/src/ChronikClient.ts @@ -356,9 +356,11 @@ return; } const data = - wsMsg.data instanceof Buffer - ? (wsMsg.data as Uint8Array) - : new Uint8Array(await (wsMsg.data as Blob).arrayBuffer()); + typeof window === 'undefined' + ? // NodeJS + (wsMsg.data as Uint8Array) + : // Browser + new Uint8Array(await (wsMsg.data as Blob).arrayBuffer()); const msg = proto.SubscribeMsg.decode(data); if (msg.error) { this.onMessage({ diff --git a/modules/chronik-client/src/ChronikClientNode.ts b/modules/chronik-client/src/ChronikClientNode.ts --- a/modules/chronik-client/src/ChronikClientNode.ts +++ b/modules/chronik-client/src/ChronikClientNode.ts @@ -539,9 +539,11 @@ return; } const data = - wsMsg.data instanceof Buffer - ? (wsMsg.data as Uint8Array) - : new Uint8Array(await (wsMsg.data as Blob).arrayBuffer()); + typeof window === 'undefined' + ? // NodeJS + (wsMsg.data as Uint8Array) + : // Browser + new Uint8Array(await (wsMsg.data as Blob).arrayBuffer()); const msg = proto.WsMsg.decode(data); if (typeof msg.error !== 'undefined') { this.onMessage({ type: 'Error', ...msg.error });