Skip to content

Commit f9f655b

Browse files
author
Fabrice Bascoulergue
committed
Fix websocket client disconnect implementation
1 parent 984bfe8 commit f9f655b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"parser": "@typescript-eslint/parser",
3030
"extends": ["plugin:@typescript-eslint/recommended"],
3131
"rules": {
32+
"@typescript-eslint/ban-ts-comment": "off",
3233
"@typescript-eslint/no-non-null-assertion": "off",
3334
"@typescript-eslint/no-use-before-define": "off",
3435
"@typescript-eslint/no-warning-comments": "off",

src/client/LumClient.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ export class LumClient {
6868
* Disconnect the underlying tendermint client
6969
*/
7070
disconnect() {
71+
// Temporary fix missing stop calls from the cosmjs socket implementation
72+
// @ts-ignore
73+
this.tmClient.client && this.tmClient.client.socket && this.tmClient.client.events && this.tmClient.client.socket.events._stopNow();
74+
// @ts-ignore
75+
this.tmClient.client &&
76+
// @ts-ignore
77+
this.tmClient.client.socket &&
78+
// @ts-ignore
79+
this.tmClient.client.socket.connectionStatus &&
80+
// @ts-ignore
81+
this.tmClient.client.socket.connectionStatus.updates &&
82+
// @ts-ignore
83+
this.tmClient.client.socket.connectionStatus.updates._stopNow();
84+
85+
// Disconnect the client
7186
this.tmClient.disconnect();
7287
}
7388

tests/client.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LumWallet, LumWalletFactory, LumClient, LumUtils, LumConstants, LumRegistry, LumTypes, LumMessages } from '../src';
22
import axios from 'axios';
3-
import { BeamData, BeamState } from "../src/codec/chain/beam/beam";
3+
import { BeamData, BeamState } from '../src/codec/chain/beam/beam';
44

55
const randomString = (): string => {
66
return Math.random().toString(36).substring(7);
@@ -12,7 +12,7 @@ describe('LumClient', () => {
1212
let w2: LumWallet;
1313

1414
beforeAll(async () => {
15-
clt = await LumClient.connect('http://node0.testnet.lum.network/rpc');
15+
clt = await LumClient.connect('https://node0.testnet.lum.network/rpc');
1616

1717
// Prepare the wallets
1818
w1 = await LumWalletFactory.fromMnemonic(LumUtils.generateMnemonic());
@@ -47,6 +47,12 @@ describe('LumClient', () => {
4747
await expect(clt.disconnect()).resolves.toBeTruthy();
4848
});
4949

50+
it('should allow to connect via webshockets', async () => {
51+
const wsClt = await LumClient.connect('wss://node0.testnet.lum.network/rpc');
52+
expect(await wsClt.status()).toBeTruthy();
53+
wsClt.disconnect();
54+
});
55+
5056
it('should open a beam and close it', async () => {
5157
const beamId = randomString();
5258

@@ -251,7 +257,7 @@ describe('LumClient', () => {
251257
url: 'https://test.com',
252258
signature: 'test',
253259
},
254-
})
260+
}),
255261
);
256262

257263
const fee = {

0 commit comments

Comments
 (0)