# Websocket
# Installation
npm install @vite/vitejs-ws --save
yarn add @vite/vitejs-ws
# Module Import
import WS_RPC from "@vite/vitejs-ws";
const { WS_RPC } = require('@vite/vitejs-ws');
# Constructor
Constructor Parameters:
url : string
Connection URL. Default isws://localhost:31420
timeout? : number
Timeout(ms). Default is60000
__namedParameters? : object
headers? : object
: Request headerprotocol?
: ProtocolclientConfig? : object
: require('websocket').w3cwebsocket ==> clientConfig (opens new window)retryTimes? : number
: Retry times. Default is10
retryInterval? : number
: Retry interval(ms). Default is10000
Example:
import WS_RPC from "@vite/vitejs-ws";
const wsProvider = new WS_RPC("ws://localhost:8080");
# Properties
Name | Type | Description |
---|---|---|
url | string | Connection URL |
protocol | string | Protocol |
headers | object | Request header |
clientConfig | object | Client config object |
type | string | Protocol type |
timeout | number(ms) | Timeout |
# Methods
# abort
Abort current connection and discard all pending requests
# request
Call RPC API and return response
Parameters:
methodName : string
Name of API methodparams : any
Passed-in parameters
Returns:
- Promise<
JsonRPC response
> RPC response
- Promise<
# sendNotification
Call RPC API and do not return response
- Parameters:
methodName : string
Name of API methodparams : any
Passed-in parameters
# batch
Call a batch of RPC APIs
Parameters:
requests : array<object>
type : string<request | notification | batch>
: TypemethodName : string
: Name of API methodparams : any
: Passed-in parameters
Returns:
- Promise<
JsonRPC response
> RPC response
- Promise<
# reconnect
Reconnect
# disconnect
Disconnect
# subscribe
Subscribe to event
- Parameters:
callback : Function
Callback function will be called when the event occurs
# unsubscribe
Cancel subscription