0.69.0 • Published 2 years ago

@curium.rocks/ping-pong-emitter v0.69.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ping-pong-emitter

Quality Gate Status Coverage Security Rating

Purpose

The purpose of this class is to create an emitter that will periodically emit a ping message expecting a pong response. Likewise, it can be pinged, and it will send a pong back. This can be used as a test class for emitter transceivers, as well as a general comm link check akin to a keep alive.

How to use

Install

npm install --save @curium.rocks/ping-pong-emitter

API Documentation

You can view the API documentation here.

Examples

import {isPingPongMessage, PingPongEmitter, PingPongMessage, PingPongMessageType} from '@curium.rocks/ping-pong-emitter';
import {IDataEvent} from '@curium.rocks/data-emitter-base';

const emitter = new PingPongEmitter('unique-id', 'usefull-name', 'lengthy description', 1000);
emitter.startPolling();
const disposable = emitter.onData(async (evt) => {
    if(!isPingPongMessage(evt.data)) console.log('What... not a ping pong message!');
    if((evt.data as PingPongMessage).type == PingPongMessageType.PING) {
        console.log("I've been pinged!, I better send a pong");
        await emitter.sendCommand({
            actionId: 'unique-action-id',
            payload: {
                type: PingPongMessageType.PONG
            }
        });
        console.log("Ponged back!");
    }
});

// check on the state 

const state = await emitter.probeStatus();

if (state.bit) {
    console.log('BIT flag on indicates BIT failure, not getting pongs!');
}

// want to change the ping interval

const cmdResult = await emitter.sendCommand({
    actionId: 'unique-id',
    name: 'new-name',
    id: 'new-emitter-id',
    description: 'new-emitter-description',
    interval: 5000 //interval in ms
});

// check cmd result

if(!cmdResult.success) {
    console.log(`Error while executing cmd: ${cmdResult.actionId}, reason: ${cmdResult.failureReason}`);
}

// when done cleanup
emitter.dispose();
0.62.0

2 years ago

0.67.0

2 years ago

0.63.0

2 years ago

0.68.0

2 years ago

0.64.0

2 years ago

0.69.0

2 years ago

0.65.0

2 years ago

0.66.0

2 years ago

0.59.0

3 years ago

0.55.0

3 years ago

0.51.0

3 years ago

0.48.0

3 years ago

0.56.0

3 years ago

0.52.0

3 years ago

0.49.0

3 years ago

0.60.0

3 years ago

0.57.0

3 years ago

0.53.0

3 years ago

0.46.0

3 years ago

0.61.0

3 years ago

0.58.0

3 years ago

0.54.0

3 years ago

0.50.0

3 years ago

0.47.0

3 years ago

0.43.0

3 years ago

0.20.0

3 years ago

0.41.0

3 years ago

0.19.0

3 years ago

0.38.0

3 years ago

0.36.0

3 years ago

0.34.0

3 years ago

0.11.0

3 years ago

0.13.0

3 years ago

0.15.0

3 years ago

0.17.0

3 years ago

0.32.0

3 years ago

0.30.0

3 years ago

0.29.0

3 years ago

0.27.0

3 years ago

0.25.0

3 years ago

0.44.0

3 years ago

0.23.0

3 years ago

0.9.0

3 years ago

0.5.0

3 years ago

0.7.0

3 years ago

0.42.0

3 years ago

0.21.0

3 years ago

0.40.0

3 years ago

0.39.0

3 years ago

0.37.0

3 years ago

0.35.0

3 years ago

0.33.0

3 years ago

0.12.0

3 years ago

0.14.0

3 years ago

0.16.0

3 years ago

0.18.0

3 years ago

0.10.0

3 years ago

0.31.0

3 years ago

0.28.0

3 years ago

0.26.0

3 years ago

0.24.0

3 years ago

0.45.0

3 years ago

0.22.0

3 years ago

0.8.0

3 years ago

0.4.0

3 years ago

0.6.0

3 years ago

0.1.1-27

3 years ago

0.1.1-28

3 years ago

0.1.1-29

3 years ago

0.1.1-25

3 years ago

0.1.1-26

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.1-34

3 years ago

0.1.1-35

3 years ago

0.1.1-36

3 years ago

0.1.1-37

3 years ago

0.1.1-30

3 years ago

0.1.1-31

3 years ago

0.1.1-32

3 years ago

0.1.1-33

3 years ago

0.1.1-23

3 years ago

0.1.1-24

3 years ago

0.1.1-22

3 years ago

0.1.1-21

3 years ago

0.1.1-16

3 years ago

0.1.1-17

3 years ago

0.1.1-18

3 years ago

0.1.1-19

3 years ago

0.1.1-20

3 years ago

0.1.1-14

4 years ago

0.1.1-15

4 years ago

0.1.1-13

4 years ago

0.1.1-12

4 years ago

0.1.1-11

4 years ago

0.1.1-10

4 years ago

0.1.1-9

4 years ago

0.1.1-6

4 years ago

0.1.1-8

4 years ago

0.1.1-7

4 years ago

0.1.1-5

4 years ago

0.1.1-4

4 years ago

0.1.1-3

4 years ago

0.1.1-2

4 years ago

0.1.1-1

4 years ago

0.1.1-0

4 years ago