Client to integrations with Netuno WebSocket and Services.
More about the Netuno Platform.
This module makes is easy to support WebSocket in web applications.
npm i -S @netuno/ws-client
import _ws from '@netuno/ws-client';
Defines the main events:
_ws.config({
url: 'ws:https://localhost:9000/ws/example',
servicesPrefix: '/services',
method: 'GET',
autoReconnect: true,
connect: (event) => {
...
},
close: (event) => {
...
},
error: (error) => {
...
},
message: (data, event) => {
...
}
});
_ws.connect();
_ws.close();
Add listener:
const listenerRef = _ws.addListener({
method: 'GET', // Optional
service: "my/service",
success: (data) => {
...
},
fail: (error)=> {
...
}
});
Remove listener:
_ws.removeListener(listenerRef);
Send data to the service, and the output comes in the associated listener.
_ws.sendService({
method: 'GET', // Optional
service: 'my/service',
data: {
message: 'Hi...'
}
});