Skip to content

Commit

Permalink
Merge pull request #41 from cosmos-client/ws
Browse files Browse the repository at this point in the history
feat: ws
  • Loading branch information
kimurayu45z authored Jul 29, 2021
2 parents 323815f + 7b729e8 commit e5ca1f2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cosmos-client",
"description": "REST API Client for Cosmos SDK Blockchain",
"version": "0.42.12",
"version": "0.42.13",
"author": "LCNEM, Inc.",
"bugs": {
"url": "https://github.com/cosmos-client/cosmos-client-ts/issues"
Expand Down
7 changes: 3 additions & 4 deletions src/websocket/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WebSocketSubject } from 'rxjs/webSocket';
import { CosmosSDK } from '../sdk';

type BaseSchema = {
id: '1';
Expand All @@ -11,11 +10,11 @@ export type RequestSchema = BaseSchema & {
params: string[];
};

export type ResponseSchema = BaseSchema & ({ result: any } | { error: string });
export type ResponseSchema = BaseSchema & { result?: any; error?: string };

export function connect(sdk: CosmosSDK) {
export function connect(url: string) {
const ws = new WebSocketSubject<RequestSchema | ResponseSchema>({
url: `${sdk.url}/websocket`,
url: `${url}/websocket`,
});

return ws;
Expand Down
5 changes: 2 additions & 3 deletions src/websocket/websocket.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cosmosclient, websocket } from '..';
import { websocket } from '..';

function sleep(sec: number) {
return new Promise((resolve, _) => {
Expand All @@ -11,8 +11,7 @@ function sleep(sec: number) {
describe('websocket', () => {
it('websocker', async () => {
expect.hasAssertions();
const sdk = new cosmosclient.CosmosSDK('ws://localhost:26657', 'testchain');
const ws = websocket.connect(sdk);
const ws = websocket.connect('ws://localhost:26657');

ws.next({
id: '1',
Expand Down

0 comments on commit e5ca1f2

Please sign in to comment.