WebSocket

Installation

npm install @vite/vitejs-ws --save
yarn add @vite/vitejs-ws

Import

import WS_RPC from "@vite/vitejs-ws";
const { WS_RPC } = require('@vite/vitejs-ws');

Constructor

  • Constructor Parameters:

    • url : string Connection url. Default is 'ws://localhost:31420'
    • timeout? : number Timeout(ms). Default is 60000
    • __namedParameters? : object
  • Example:

import WS_RPC from "@vite/vitejs-ws";
const wsProvider = new WS_RPC("ws://localhost:8080");

Properties

The following properties are specifically supported in WebSocket.

Name Type Description
url string Connection url
protocol string Protocol
headers object Request header
clientConfig object Client config

Methods

The following methods are specifically supported in WebSocket.

Reconnect

Reconnect

disconnect

Disconnect

subscribe

Subscribe to events

  • Parameters:
    • callback : Function Callback function will be invoked when subscribed event is triggered and pushed back

unSubscribe

Unsubscribe