Skip to content

Commit

Permalink
fix: formatting + README + extra connection null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed May 14, 2019
1 parent 0c506ff commit e0b3057
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RequestManager, HTTPTransport, Client } from '@open-rpc/client-js';
const transport = new HTTPTransport('http://localhost:8545');
const client = new Client(new RequestManager([transport]));
const result = await client.request(‘addition’, [2, 2]);
// => 4
// => { jsonrpc: '2.0', id: 1, result: 4 }
```

### Contributing
Expand Down
13 changes: 4 additions & 9 deletions src/example.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import Client from ".";
import RequestManager from "./RequestManager";
import Transport from "./transports/HTTPTransport";

const t = new Transport("http://localhost:8545");

import { Client, RequestManager, HTTPTransport } from ".";
const t = new HTTPTransport("http://localhost:3333");
const c = new Client(new RequestManager([t]));

// make request for eth_blockNumber
c.request("eth_blockNumber", []).then((b: any) => {
console.log('in then', b); //tslint:disable-line
c.request("addition", [2, 2]).then((result: any) => {
console.log('addition result: ', result); // tslint:disable-line
});
1 change: 0 additions & 1 deletion src/transports/Transport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export default interface ITransport {
connect(): Promise<any>;
close(): void;
Expand Down
11 changes: 1 addition & 10 deletions src/transports/WebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import WebSocket from "isomorphic-ws";
import ITransport from "./Transport";

class WebSocketTransport implements ITransport {
public connection: WebSocket | undefined;
public connection: WebSocket;
constructor(uri: string) {
this.connection = new WebSocket(uri);
}
Expand All @@ -18,23 +18,14 @@ class WebSocketTransport implements ITransport {
});
}
public onData(callback: any) {
if (!this.connection) {
return;
}
this.connection.addEventListener("message", (ev: MessageEvent) => {
callback(ev.data);
});
}
public sendData(data: any) {
if (!this.connection) {
return;
}
this.connection.send(data);
}
public close() {
if (!this.connection) {
return;
}
this.connection.close();
}
}
Expand Down

0 comments on commit e0b3057

Please sign in to comment.