websocket-rpc-protocol
Advanced tools
Comparing version
@@ -0,3 +1,3 @@ | ||
import { createId } from 'crypto-id'; | ||
import { signal } from 'easy-signal'; | ||
import { createId } from 'crypto-id'; | ||
const CONNECTION_TIMEOUT = 5000; | ||
@@ -172,3 +172,3 @@ const BASE_RETRY_TIME = 1000; | ||
update(); | ||
socket.close(); | ||
socket.close(1000); | ||
if (socket) | ||
@@ -285,1 +285,2 @@ socket.onclose(); | ||
} | ||
//# sourceMappingURL=client.js.map |
{ | ||
"name": "websocket-rpc-protocol", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"description": "A JSON RPC protocol for working over websockets. Sheds the weight of JSON RPC to simplify argument names and adds features.", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"prepare": "tsc" | ||
@@ -8,0 +9,0 @@ }, |
export declare type APIMethod = (ws: WebSocket, ...args: any[]) => any; | ||
export declare type API = { | ||
export interface API { | ||
[key: string]: APIMethod | API; | ||
}; | ||
} | ||
export interface ServerAPI { | ||
@@ -11,7 +11,2 @@ onConnect: (socket: WebSocket) => void; | ||
} | ||
export default function createServer(version: string, api: API): { | ||
send: (socket: WebSocket, data: any) => void; | ||
push: (socket: WebSocket, data: any, forRequest?: number) => void; | ||
onConnect: (socket: WebSocket) => void; | ||
onMessage: (socket: WebSocket, event: MessageEvent) => Promise<void>; | ||
}; | ||
export default function createServer(version: string, api: API): ServerAPI; |
@@ -0,2 +1,4 @@ | ||
; | ||
// Exposes an API to a websocket endpoint using the protocol described in PROTOCOL.md | ||
// use server-single if one server can handle multiple clients without state, otherwise use server | ||
export default function createServer(version, api) { | ||
@@ -95,1 +97,2 @@ const thisApi = { send, push, onConnect, onMessage }; | ||
} | ||
//# sourceMappingURL=server-single.js.map |
// Exposes an API to a websocket endpoint using the protocol described in PROTOCOL.md | ||
// Use server to handle 1 API per socket for state, use server-single if one server can handle multiple sockets | ||
export default async function createServer(socket, version, apiFactory) { | ||
@@ -115,1 +116,2 @@ const thisApi = { send, push, close }; | ||
} | ||
//# sourceMappingURL=server.js.map |
@@ -0,3 +1,3 @@ | ||
import { createId } from 'crypto-id'; | ||
import { signal, Signal } from 'easy-signal'; | ||
import { createId } from 'crypto-id'; | ||
@@ -221,3 +221,3 @@ const CONNECTION_TIMEOUT = 5000; | ||
update(); | ||
socket.close(); | ||
socket.close(1000); | ||
if (socket) (socket.onclose as any)(); | ||
@@ -224,0 +224,0 @@ } |
import { Signal, Unsubscriber } from 'easy-signal'; | ||
export type APIMethod = (ws: WebSocket, ...args: any[]) => any; | ||
export type API = {[key: string]: APIMethod | API}; | ||
export interface API { | ||
[key: string]: APIMethod | API | ||
}; | ||
@@ -14,3 +16,4 @@ export interface ServerAPI { | ||
// Exposes an API to a websocket endpoint using the protocol described in PROTOCOL.md | ||
export default function createServer(version: string, api: API) { | ||
// use server-single if one server can handle multiple clients without state, otherwise use server | ||
export default function createServer(version: string, api: API): ServerAPI { | ||
const thisApi = { send, push, onConnect, onMessage }; | ||
@@ -17,0 +20,0 @@ const streamingRequests = new Map<number, (aborted?: boolean) => boolean>(); |
@@ -14,2 +14,3 @@ import { Signal, Unsubscriber } from 'easy-signal'; | ||
// Exposes an API to a websocket endpoint using the protocol described in PROTOCOL.md | ||
// Use server to handle 1 API per socket for state, use server-single if one server can handle multiple sockets | ||
export default async function createServer(socket: WebSocket, version: string, apiFactory: APIFactory) { | ||
@@ -16,0 +17,0 @@ const thisApi = { send, push, close }; |
@@ -5,2 +5,3 @@ { | ||
"declaration": true, | ||
"sourceMap": true, | ||
"moduleResolution": "node", | ||
@@ -7,0 +8,0 @@ "esModuleInterop": true, |
63154
38.86%17
21.43%1097
0.27%