File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments