1.0.6 • Published 5 years ago

firehose-helper v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

firehose-helper

Create new Firehose object and publish events into it. E.g. when a user has accepted a contact request event record will be created and put to that firehose.

This may also be used by Protocol V3.

FsHelper

  • Requiring FsHelper exposes a function, that accepts a single parameter of the streamName which is used put event records in.

  • FsHelper is an event emitter, that emits when an event record is consumed. This can then be used on to perform other functionality, e.g. record statistics, remove an entry from a cache.

Installation

Execute the following to install the dependency and add to package.json:

npm install firehose-helper --save

Example Usage

In the app.js (or potentially a separate init.js) the new FsHelper must be created and then putMessage method should be executed to let the service put event records to that Firehose:

const FsHelper = require('firehose-helper');

let EVENT_ONE = 'EVENT_ADD_CONTACT';
let ADD_CONTACT_MESSAGE = {
    "Event_Name": 'ADD_CONTACT',
    "Subscriber_ID": 78566808,
    "Session_ID": 1234567890,
    "Token_ID": 77777777,
    "Event_DateTime_UTC": "2019-04-03 19:04:56",
    "Event_DateTime_Local": "2019-04-03 21:04:56",
    "Target_Subscriber_ID": 78545677
  };

let EVENT_TWO = 'EVENT_REMOVE_CONTACT';
let REMOVE_CONTACT_MESSAGE = {
    "Event_Name": 'REMOVE_CONTACT',
    "Subscriber_ID": 78566808,
    "Session_ID": 1234567890,
    "Token_ID": 77777777,
    "Event_DateTime_UTC": "2019-04-03 19:04:56",
    "Event_DateTime_Local": "2019-04-03 21:04:56",
    "Target_Subscriber_ID": 78545677
};

let EVENT_THREE = 'EVENT_GROUP_PEEK';
let GROUP_PEEK_MESSAGE = {
    "Subscriber_ID": 78566808,
    "Session_ID": 1234567890,
    "Token_ID": 77777777,
    "Event_DateTime_UTC": "2019-04-03 19:04:56",
    "Event_DateTime_Local": "2019-04-03 21:04:56",
    "GroupID": 78545677
};


let fsHelperAddContact = new FsHelper("add-contact-event");
fsHelperAddContact.putMessage(EVENT_ONE, JSON.stringify(ADD_CONTACT_MESSAGE));

let fsHelperRemoveContact = new FsHelper("remove-contact-event");
fsHelperRemoveContact.putMessage(EVENT_TWO, JSON.stringify(REMOVE_CONTACT_MESSAGE));

let fsHelperGroupPeek = new FsHelper("group-peek-event");
fsHelperGroupPeek.putMessage(EVENT_THREE, JSON.stringify(GROUP_PEEK_MESSAGE));

FsHelper can be used as an event emitter in other files to perform required actions:

fsHelperAddContact.on(EVENT_ONE, function (data) {
  console.log('EVENT: ',EVENT_ONE, ':  Message: ' + data); //Do something, e.g. COUNT stats
});
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago