<a href="https://www.npmjs.com/package/@netuno/ws-client"><img src="https://img.shields.io/npm/v/@netuno/ws-client.svg?style=flat" alt="npm version"></a>
npm install @netuno/ws-clientnpm i -S @netuno/ws-client
import _ws from '@netuno/ws-client';
_ws.config({
url: 'ws://localhost:9000/ws/example',
servicesPrefix: '/services',
method: 'GET',
autoReconnect: true,
connect: (event) => {
...
},
close: (event) => {
...
},
error: (error) => {
...
},
message: (data, event) => {
...
}
});
`
$3
`
_ws.connect();
`
$3
`
_ws.close();
`
$3
Add listener:
`
const listenerRef = _ws.addListener({
method: 'GET', // Optional
service: "my/service",
success: (data) => {
...
},
fail: (error)=> {
...
}
});
`
Remove listener:
`
_ws.removeListener(listenerRef);
`
$3
Send data to the service, and the output comes in the associated listener.
`
_ws.sendService({
method: 'GET', // Optional
service: 'my/service',
data: {
message: 'Hi...'
}
});
``