Skip to content

Commit 32f1791

Browse files
committed
feat(reactive-rpc): 🎸 add convenience methods for RPC client instantiation
1 parent 50d3b0a commit 32f1791

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {CborJsonValueCodec} from "../../json-pack/codecs/cbor";
2+
import {Writer} from "../../util/buffers/Writer";
3+
import {RpcPersistentClient, WebSocketChannel} from "../common";
4+
import {RpcCodec} from "../common/codec/RpcCodec";
5+
import {BinaryRpcMessageCodec} from "../common/codec/binary";
6+
7+
export const createBinaryWsRpcClient = (url: string) => {
8+
const writer = new Writer(1024 * 4);
9+
const msg = new BinaryRpcMessageCodec();
10+
const req = new CborJsonValueCodec(writer);
11+
const codec = new RpcCodec(msg, req, req);
12+
const client = new RpcPersistentClient({
13+
codec,
14+
channel: {
15+
newChannel: () =>
16+
new WebSocketChannel({
17+
newSocket: () => new WebSocket(url, [codec.specifier()]),
18+
}),
19+
},
20+
});
21+
client.start();
22+
return client;
23+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {JsonJsonValueCodec} from "../../json-pack/codecs/json";
2+
import {Writer} from "../../util/buffers/Writer";
3+
import {RpcPersistentClient, WebSocketChannel} from "../common";
4+
import {RpcCodec} from "../common/codec/RpcCodec";
5+
import {CompactRpcMessageCodec} from "../common/codec/compact";
6+
7+
export const createJsonWsRpcClient = (url: string) => {
8+
const writer = new Writer(1024 * 4);
9+
const msg = new CompactRpcMessageCodec();
10+
const req = new JsonJsonValueCodec(writer);
11+
const codec = new RpcCodec(msg, req, req);
12+
const client = new RpcPersistentClient({
13+
codec,
14+
channel: {
15+
newChannel: () =>
16+
new WebSocketChannel({
17+
newSocket: () => new WebSocket(url, [codec.specifier()]),
18+
}),
19+
},
20+
});
21+
client.start();
22+
return client;
23+
};

0 commit comments

Comments
 (0)