1.0.1 • Published 6 years ago
sync-websockets v1.0.1
sync-websocket
A simple way to wait for the result of a websocket request.
When you need to await for a message, use the send method, it will include an id to the request, when you receive a message containing this id, the SyncWebsocket object will resolve the pending Promise.
In case that wasn't clear enough, when the other peer returns a result, its message should include the id.
Install
npm install sync-websocketUsage
const SyncWebsocket = require('sync-websocket')
const syncws = new SyncWebsocket()API
Class: SyncWebsocket
new SyncWebsocket
Creates a new synchronous websocket handler.
send(socket, data)
socket{WebSocket}data{Object}
Returns a Promise
Sends a message to the defined socket, with the specified data.
Adds an id field, that would be overwritten if it already exists.
The send method stringifies the data. So the other peer will receive a string.
receive(data)
data{Object}
Resolves the promise identified by the id field found in data
1.0.1
6 years ago