0.11.1 • Published 11 months ago

@ryinner/web-socket-manager v0.11.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 months ago

WebSocketManager

That a simple webSocket wrapper.

Install

npm install @ryinner/web-socket-manager --save

Usage

//Only one ws
const ws = createWebSocket({ url: 'url' });

// add operation - interval server request
// if you add same operation, its handler will add to operation handlers.
ws.addOperation<MyAnswerInterface>({
    method: 'method',
    request: () => {
        const computed = 1;
        return { myFieldToWebSocket: computed };
    },
    handlers: [
        (answerFromServer) => {
            // smth
        }
    ]
});

// remove operation
ws.removeOperation('method');

//remove handler
ws.removeHandler('method', handler);

// start websocket
ws.open();

// close websocket
ws.close();

// also you can use it in multiply mode
const wsList = createWebSocket({ base: { url: 'url' }, interval: { url: 'url2', additionalQueryParams: { secret_key: 123 }, interval: 3000 } });

// get wsManager
wsList.getConnection('base');

const handler = (answerFromServer) => {
    // smth
};

// push operation to base
wsList.addOperation('base', {
    method: 'method',
    request: () => {
        const computed = 1;
        return { myFieldToWebSocket: computed };
    },
    handlers: [
        handler
    ]
});
// remove handler
wsList.removeHandler('test', 'method', handler);
// remove operation
wsList.removeOperation('test', 'method');

Server answer

Manager expect this server answer format.

{
    "method": "methodName",
    "data": {
        "someDataField": 1
    }
}
0.11.1

11 months ago

0.11.0

11 months ago

0.10.0

11 months ago

0.9.18

12 months ago

0.9.17

12 months ago

0.9.16

12 months ago

0.9.15

12 months ago

0.9.14

12 months ago

0.9.13

12 months ago

0.9.12

12 months ago

0.9.11

12 months ago

0.9.8

12 months ago

0.9.7

12 months ago

0.9.5

12 months ago

0.9.4

12 months ago

0.9.3

12 months ago