Skip to content

Commit

Permalink
remove unecessary JsonRpcParams = any export
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Feb 27, 2024
1 parent fdc0ee5 commit 077db21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/json-rpc-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class JsonRpcSocket {
static async connect(url: string, options: JsonRpcSocketOptions = {}): Promise<JsonRpcSocket> {
const { connectTimeout = CONNECT_TIMEOUT, responseTimeout = RESPONSE_TIMEOUT, onclose, onerror } = options;

const socket = new WebSocket(url);
const socket = new WebSocket(url, { timeout: connectTimeout });

socket.onclose = onclose;
socket.onerror = onerror;
Expand Down
9 changes: 4 additions & 5 deletions src/lib/json-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export type JsonRpcId = string | number | null;
export type JsonRpcParams = any;
export type JsonRpcVersion = '2.0';

export interface JsonRpcRequest {
jsonrpc: JsonRpcVersion;
id?: JsonRpcId;
method: string;
params?: JsonRpcParams;
params?: any;
/** JSON RPC Subscription Extension Parameters */
subscription?: {
id: JsonRpcId
Expand Down Expand Up @@ -76,7 +75,7 @@ export const createJsonRpcErrorResponse = (

export const createJsonRpcNotification = (
method: string,
params?: JsonRpcParams,
params?: any,
): JsonRpcRequest => {
return {
jsonrpc: '2.0',
Expand All @@ -88,7 +87,7 @@ export const createJsonRpcNotification = (
export const createJsonRpcSubscriptionRequest = (
id: JsonRpcId,
method: string,
params?: JsonRpcParams,
params?: any,
subscriptionId?: JsonRpcId
): JsonRpcRequest => {
return {
Expand All @@ -105,7 +104,7 @@ export const createJsonRpcSubscriptionRequest = (
export const createJsonRpcRequest = (
id: JsonRpcId,
method: string,
params?: JsonRpcParams,
params?: any,
): JsonRpcRequest => {
return {
jsonrpc: '2.0',
Expand Down
4 changes: 3 additions & 1 deletion tests/json-rpc-socket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ describe('JsonRpcSocket', () => {
const onErrorHandler = { onerror: ():void => {} };
const onErrorSpy = sinon.spy(onErrorHandler, 'onerror');

await JsonRpcSocket.connect('ws://127.0.0.1:9003', { onerror: onErrorHandler.onerror });
await JsonRpcSocket.connect('ws://127.0.0.1:9003', { onerror: onErrorHandler.onerror, connectTimeout: 1 });
// const serverSocket = [...wsServer.clients][0];
// serverSocket.emit('error', { type: 'error', target: null, message: 'unknown error' });

await new Promise((resolve) => setTimeout(resolve, 5)); // wait for close event to arrive
expect(onErrorSpy.callCount).to.equal(1, 'error');
Expand Down

0 comments on commit 077db21

Please sign in to comment.