Skip to content

Commit 8dc75ad

Browse files
committed
fix: socket-io client must only use websocket transport
1 parent 7d3444b commit 8dc75ad

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

client/README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ await sub.unsubscribe();
4545
### Socket.io
4646

4747
```js
48-
import { io } from "socket.io-client";
49-
import * as stacks from '@stacks/blockchain-api-client';
48+
import { StacksApiSocketClient } from '@stacks/blockchain-api-client';
5049

51-
// for testnet, replace with https://api.testnet.hiro.so/
52-
const socketUrl = "https://api.mainnet.hiro.so/";
50+
// for testnet, replace with https://api.testnet.hiro.so
51+
const socketUrl = "https://api.mainnet.hiro.so";
5352

54-
const socket = io(socketUrl);
55-
const sc = new stacks.StacksApiSocketClient(socket);
53+
const sc = new StacksApiSocketClient({ url: socketUrl });
5654

5755
sc.subscribeAddressTransactions('ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA', (address, tx) => {
5856
console.log('address:', address);

client/src/socket-io/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ function createStacksApiSocket(opts?: StacksApiSocketConnectionOptions) {
4646
subscriptions: Array.from(new Set(opts?.subscriptions)).join(','),
4747
},
4848
};
49+
if (!socketOpts.transports) {
50+
socketOpts.transports = ['websocket'];
51+
}
4952
const socket: StacksApiSocket = io(getWsUrl(opts?.url ?? BASE_PATH).href, socketOpts);
5053
return socket;
5154
}

0 commit comments

Comments
 (0)