websocket-rpc-client

0.2.0 • Public • Published

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])

/websocket-rpc-client/

    Package Sidebar

    Install

    npm i websocket-rpc-client

    Weekly Downloads

    75

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • draedful