Skip to content

netuno-org/ws-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ws-client

npm version

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:https://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...' 
    }
});