🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

websocket-rpc-client

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket-rpc-client

websocket JSON-RPC 2.0 client

0.2.0
latest
Version published
Weekly downloads
15
-40%
Maintainers
1
Weekly downloads
 
Created

WebSocket JSON-RPC Client

Javascript library implements JSON-RPC protocol for WebSockets

Installation

npm install --save websocket-rpc-client

Usage

Connecting

import WS from 'websocket-rpc-client';

var params = {
    url: 'ws://url_to_ws_server/',
    reconnectTimeout: 5000,
    reconnectCount: 2,
}

WS.start(params).then(function(){
    // on success
}).catch(function(){
    // on failure
})

Send Data

    // send a request of format  {id:1, method: "signIn", params: {"username":"username", "password":"password"}}
    WS.send("signIn", {
        "username":"username",
        "password":"password",
    }).then(function(resp) {
        // on success
    }).catch(function(e) {
        // on error
    })

Subscribe on events

WS.subscribe('onConnect', function(params){
    // ...
});

Unsubscribe on events

WS.unsubscribe('onConnect'[,function])

FAQs

Package last updated on 21 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts