isp-etp-js-client
v2.0.1
Published
Event transport protocol library for Java Script
Downloads
17
Readme
isp-etp-js-client
- Simple event transport protocol client for Java Script for server.
- Design API inspired by socket.io.
- event payload marshaling/unmarshaling to/from
json
Install
yarn add isp-etp-js-client
Example
import ws from "isp-etp-js-client";
const cli = ws("ws://127.0.0.1:7777/isp-etp/", {
params: {
token: token, //will add to GET params in initial request
}
});
cli.onConnect(() => { //call every time when connection successfully established
console.log("connected");
socket.emit("some_event", {"some_payload": "yep"}); //c
});
cli.onError(err => { //call every time when error occurred while connecting or data deserializing
console.error(err);
});
cli.onDisconnect(evt => { //call every time when connection could not established or closed
if (!evt.wasClean) { //indicate that connection was closed by client or server
console.error(evt);
}
setTimeout(() => socket.connect(), 1000); //for automatically reconnection just call connect() once again
});
cli.on('test_event', payload => { //subscribe to any custom events
console.log("test_event", payload);
});
cli.connect();
cli.close() //call to close connection, you can provides two params: code: number, reason: string
Note
v1
of client not compatible withv2
serverv2
js client currently not support emitWithAck/onWithAck