Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sz-json-rpc

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sz-json-rpc

JSON-RPC that works on browser.

  • 1.6.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

sz-json-rpc



JSON-RPC that works on browser.

Installation
  $ npm install sz-json-rpc --save
Example
  • Using json-rpc adapter to send requests.
var webSocket = new WebSocket('ws://localhost:5000');
var ws = new SzJsonRpc().ws(webSocket);
ws.on('open', () => {
  ws.request('ping')((err, response) => {
    if (err) throw err;
    console.log('response', response);
  });
});
ws.on('close', (reason) => {
  // this will not show when onbeforeunload event call .close
  console.log('close', reason);
});
window.onbeforeunload = function() {
  ws.close();
}
  • Using connector to do some tricks like auto reconect, queue requests when socket isn't ready and dispatch when it is live.
const conn = new SzJsonRpc().wsConnection(WebSocket, 'ws://localhost:5000', {
  onWSConnect: (ws) => {
    ws.send('login', {}, (err, response) => {
      if(err)
        console.error(err);
    });
    ws.send('ping', null, (err, response) => {
      console.log(response);
    });
  }
});

window.onbeforeunload = function() {
  if (conn.socketReady())
    conn.curSocket.close();
}

Keywords

FAQs

Package last updated on 04 Mar 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc