Package Exports
- jsonrpc-websocket-client
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jsonrpc-websocket-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
jsonrpc-websocket-client 
JSON-RPC 2 over WebSocket
Install
Installation of the npm package:
> npm install --save jsonrpc-websocket-clientUsage
import Client from 'jsonrpc-websocket-client'
async function main () {
const client = new Client('ws://example.org')
console.log(client.status)
// → disconnected
await client.connect()
console.log(client.status)
// → connected
console.log(
await client.call('method', [1, 2, 3])
)
await client.close()
}
// Run the main function and prints any errors.
main().catch(error => {
console.error(error)
process.exit(1)
})Creation
const client = new Client(opts)opts is either a string (the URL of the server) or an object with
the following properties:
url: URL of the JSON-RPC serverprotocols(optional): the WebSocket sub-protocols to use
Connection management
Status
console.log(client.status)Possible values:
connectedconnectingdisconnected
Connection
await client.connect()Disconnection
await client.close()This method can also be used to abort the connection while connecting.
Events
Connection
client.on('connecting', () => {
console.log('client is connecting...')
})
client.on('connected', () => {
console.log('client is now connected')
})Disconnection
client.on('disconnected', () => {
console.log('client is now disconnected')
})Notification
client.on('notification', notification => {
console.log('notification received', notification)
})Development
Installing dependencies
> npm installCompilation
The sources files are watched and automatically recompiled on changes.
> npm run devTests
> npm run test-devContributions
Contributions are very welcomed, either on the documentation or on the code.
You may:
- report any issue you've encountered;
- fork and create a pull request.
License
ISC © Julien Fontanet