@luckbox/notification-client
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

notification-client

A two-way Redis-based notification client

Basic example

import { NotificationPublisher, NotificationSubscriber } from './src/index';

(async () => {
  const publisher = new NotificationPublisher({
    namespace: 'test-ns',
    prefix: 'pre',
    redisConfig: {}
  });

  const subscriber = new NotificationSubscriber({
    handler: console.log,
    loggerFactory: { create: () => console } as any,
    prefix: 'pre',
    redisConfig: {}
  });

  await subscriber.subscribe();

  setInterval(async () => {
    await publisher.publish('event', 'some message');
  }, 1000);
})();

API

NotificationPublisher

constructor(params: Object)

Name Type Description
params.namespace String The namespace that identifies this client
params.prefix String The prefix the server is configured with
params.redisConfig Object A RedisOptions obj

publish(event, message[, rooms, user])

Name Type Description
event String The event name to emit
message Any The message to send - could be any JSON-serializable data
rooms Array An optional list of rooms names to send the message to
user Number or String An optional user or handle ID to send the message to

NotificationSubscriber

constructor(params: Object)

Name Type Description
params.prefix String The prefix the server is configured with
params.redisConfig Object A RedisOptions obj
params.handler Function Callback to be invoked when a message is received

/@luckbox/notification-client/

    Package Sidebar

    Install

    npm i @luckbox/notification-client

    Weekly Downloads

    4

    Version

    2.0.2

    License

    ISC

    Unpacked Size

    31.7 kB

    Total Files

    13

    Last publish

    Collaborators

    • ttecss
    • zupper