Sitelet https://github.com/open-rpc/client-js/commit/e0b3057
Skip to content

Commit e0b3057

Browse files
committed
fix: formatting + README + extra connection null checks
1 parent 0c506ff commit e0b3057

4 files changed

Lines changed: 6 additions & 21 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { RequestManager, HTTPTransport, Client } from '@open-rpc/client-js';
66
const transport = new HTTPTransport('http://localhost:8545');
77
const client = new Client(new RequestManager([transport]));
88
const result = await client.request(‘addition’, [2, 2]);
9-
// => 4
9+
// => { jsonrpc: '2.0', id: 1, result: 4 }
1010
```
1111

1212
### Contributing

‎src/example.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import Client from ".";
2-
import RequestManager from "./RequestManager";
3-
import Transport from "./transports/HTTPTransport";
4-
5-
const t = new Transport("http://localhost:8545");
6-
1+
import { Client, RequestManager, HTTPTransport } from ".";
2+
const t = new HTTPTransport("http://localhost:3333");
73
const c = new Client(new RequestManager([t]));
84

9-
// make request for eth_blockNumber
10-
c.request("eth_blockNumber", []).then((b: any) => {
11-
console.log('in then', b); //tslint:disable-line
5+
c.request("addition", [2, 2]).then((result: any) => {
6+
console.log('addition result: ', result); // tslint:disable-line
127
});

‎src/transports/Transport.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export default interface ITransport {
32
connect(): Promise<any>;
43
close(): void;

‎src/transports/WebSocketTransport.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import WebSocket from "isomorphic-ws";
22
import ITransport from "./Transport";
33

44
class WebSocketTransport implements ITransport {
5-
public connection: WebSocket | undefined;
5+
public connection: WebSocket;
66
constructor(uri: string) {
77
this.connection = new WebSocket(uri);
88
}
@@ -18,23 +18,14 @@ class WebSocketTransport implements ITransport {
1818
});
1919
}
2020
public onData(callback: any) {
21-
if (!this.connection) {
22-
return;
23-
}
2421
this.connection.addEventListener("message", (ev: MessageEvent) => {
2522
callback(ev.data);
2623
});
2724
}
2825
public sendData(data: any) {
29-
if (!this.connection) {
30-
return;
31-
}
3226
this.connection.send(data);
3327
}
3428
public close() {
35-
if (!this.connection) {
36-
return;
37-
}
3829
this.connection.close();
3930
}
4031
}

0 commit comments

Comments
 (0)