-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from jsonjoy-com/devex
Devex
- Loading branch information
Showing
10 changed files
with
76 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {CborJsonValueCodec} from '@jsonjoy.com/json-pack/lib/codecs/cbor'; | ||
import {Writer} from '@jsonjoy.com/util/lib/buffers/Writer'; | ||
import {RpcCodec} from '../common/codec/RpcCodec'; | ||
import {BinaryRpcMessageCodec} from '../common/codec/binary'; | ||
import {createClient} from './createClient'; | ||
|
||
/** | ||
* Constructs a JSON Reactive RPC client. | ||
* | ||
* ```typescript | ||
* const client = createBinaryClient('wss://api.host.com', 'token'); | ||
* ``` | ||
* | ||
* @param url RPC endpoint. | ||
* @param token Authentication token. | ||
* @returns An RPC client. | ||
*/ | ||
export const createBinaryClient = (url: string, token?: string) => { | ||
const writer = new Writer(1024 * 4); | ||
const msg = new BinaryRpcMessageCodec(); | ||
const req = new CborJsonValueCodec(writer); | ||
const codec = new RpcCodec(msg, req, req); | ||
return createClient(codec, url, token); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {RpcPersistentClient} from '../common/rpc/RpcPersistentClient'; | ||
import {WebSocketChannel} from '../common/channel/channel'; | ||
import type {RpcCodec} from '../common/codec/RpcCodec'; | ||
|
||
/** | ||
* Constructs a {@link RpcPersistentClient} with the given codec. | ||
* | ||
* ```typescript | ||
* const client = createRpcPersistentClient(codec, 'wss://api.host.com', 'token'); | ||
* ``` | ||
* | ||
* @param codec RPC codec. | ||
* @param url RPC endpoint. | ||
* @param token Authentication token. | ||
* @returns An RPC client. | ||
*/ | ||
export const createClient = (codec: RpcCodec, url: string, token?: string) => { | ||
const protocols: string[] = [codec.specifier()]; | ||
if (token) protocols.push(token); | ||
const client = new RpcPersistentClient({ | ||
codec, | ||
channel: { | ||
newChannel: () => | ||
new WebSocketChannel({ | ||
newSocket: () => new WebSocket(url, protocols), | ||
}), | ||
}, | ||
}); | ||
client.start(); | ||
return client; | ||
}; |
17 changes: 4 additions & 13 deletions
17
src/browser/createJsonWsRpcClient.ts → src/browser/createJsonClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
import {JsonJsonValueCodec} from '@jsonjoy.com/json-pack/lib/codecs/json'; | ||
import {Writer} from '@jsonjoy.com/util/lib/buffers/Writer'; | ||
import {RpcPersistentClient, WebSocketChannel} from '../common'; | ||
import {RpcCodec} from '../common/codec/RpcCodec'; | ||
import {CompactRpcMessageCodec} from '../common/codec/compact'; | ||
import {createClient} from './createClient'; | ||
|
||
/** | ||
* Constructs a JSON Reactive RPC client. | ||
* | ||
* @param url RPC endpoint. | ||
* @param token Authentication token. | ||
* @returns An RPC client. | ||
*/ | ||
export const createJsonWsRpcClient = (url: string, token: string) => { | ||
export const createJsonClient = (url: string, token?: string) => { | ||
const writer = new Writer(1024 * 4); | ||
const msg = new CompactRpcMessageCodec(); | ||
const req = new JsonJsonValueCodec(writer); | ||
const codec = new RpcCodec(msg, req, req); | ||
const client = new RpcPersistentClient({ | ||
codec, | ||
channel: { | ||
newChannel: () => | ||
new WebSocketChannel({ | ||
newSocket: () => new WebSocket(url, [codec.specifier(), token]), | ||
}), | ||
}, | ||
}); | ||
client.start(); | ||
return client; | ||
return createClient(codec, url, token); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export {createClient} from './createClient'; | ||
export {createBinaryClient} from './createBinaryClient'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type * from './types'; | ||
export * from './context'; | ||
export * from './Http1Server'; | ||
export * from './RpcServer'; | ||
export * from './util'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export * from './uws'; | ||
export * from './context'; | ||
export * from './errors'; | ||
export * from './ws'; | ||
export * from './http1'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './codec'; | ||
export {WsServerConnection, WsServerConnectionSocket} from './server/WsServerConnection'; |