1.0.8 • Published 3 years ago

@netuno/ws-client v1.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

ws-client

Client to integrations with Netuno WebSocket and Services.

More about the Netuno Platform.

This module makes is easy to support WebSocket in web applications.

Install

npm i -S @netuno/ws-client

Import

import _ws from '@netuno/ws-client';

Config

Defines the main events:

_ws.config({
    url: 'ws://localhost:9000/ws/example',
    servicesPrefix: '/services',
    method: 'GET',
    autoReconnect: true,
    connect: (event) => {
        ...
    },
    close: (event) => {
        ...
    },
    error: (error) => {
        ...
    },
    message: (data, event) => {
        ...
    }
});

Connect

_ws.connect();

Close

_ws.close();

Listener

Add listener:

const listenerRef = _ws.addListener({
    method: 'GET', // Optional
    service: "my/service",
    success: (data) => {
        ...
    },
    fail: (error)=> {
        ...
    }
});

Remove listener:

_ws.removeListener(listenerRef);

Send Service

Send data to the service, and the output comes in the associated listener.

_ws.sendService({
    method: 'GET', // Optional
    service: 'my/service',
    data: {
        message: 'Hi...' 
    }
});
1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago