2.0.2 • Published 1 year ago

@luckbox/notification-client v2.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
1 year ago

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)

NameTypeDescription
params.namespaceStringThe namespace that identifies this client
params.prefixStringThe prefix the server is configured with
params.redisConfigObjectA RedisOptions obj

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

NameTypeDescription
eventStringThe event name to emit
messageAnyThe message to send - could be any JSON-serializable data
roomsArrayAn optional list of rooms names to send the message to
userNumber or StringAn optional user or handle ID to send the message to

NotificationSubscriber

constructor(params: Object)

NameTypeDescription
params.prefixStringThe prefix the server is configured with
params.redisConfigObjectA RedisOptions obj
params.handlerFunctionCallback to be invoked when a message is received
2.0.2

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago