1.6.1 • Published 7 years ago

sz-json-rpc v1.6.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

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();
}
1.6.1

7 years ago

1.6.0

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

3.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago