Push notification module for Akera.io web service based on socket.io.
Messages can be broadcasted due to incoming messages from clients or from back-end business logic periodically executed - 'long pool'.
Installation
$ npm install akera-push-notification
Docs
Quick Start
This module can be loaded either as application or broker level service which
is usually done by adding a reference to it in corresponding services
section
in akera-web.json
configuration file - either globally if mounted at application
level or on each broker's configuration section.
"brokers":
Service options available:
>- channels
: the socket.io notification channels collection (array).
For each notification channel the name
property is mandatory and must be unique on each namespace.
name
: the notification channel namerequireAuthentication
: the notification channel require authentication, if set to true only authenticated clients are subscribed to itpollingInterval
: the long polling interval (milliseconds), used in conjunction withpolllingApi
to periodically make a back-end call that might push back notification on this channelrun4gl
: options for the back-end akera.io business logic API
messageApi
: the API procedure that will be executed when a message is received on this channel
messageBroadcast
: broadcast flag, if true the incoming message will be broadcasted to all listening clientsmessageChannel
: the channel name where the return of message API procedure is to be sent, defaults to channel namepollingApi
: the API procedure that will be executed by the long polling mechanism - ifpollingInterval
value is setpollingChannel
: the channel name where the return of long polling API procedure is to be sent, defaults to channel name
All API procedures - message handlers and long polling - must have the following signature:
- [in] [
character
]name
: the notification channel name- [in] [
longchar
]message data
: the notification message data (if any)- [out] [
character
]response name
: the notification channel name where the response is to be sent, defaults topollingChannel
for long polling and tomessageChannel
for message handler API- [out] [
logical
]broadcast
: broadcast flag, if set to true the response message will be broadcasted to all listeners, otherwise only the message originator gets it - long polling responses are always broadcasted- [out] [
longchar
]response data
: the response message, if not set nothing is sent back or broadcasted
/* Push notification handler */
define input parameter channelName as character.
define input parameter messageData as longchar.
define output parameter responseChannel as character.
define output parameter broadcastResponse as logical.
define output parameter responseData as longchar.
if messageData > '' then
responseData = 'echo> ' + messageData.
else
responseData = 'time> ' + string(now).
/* randomly broadcast the message
ignored for long polling - always broadcast those
*/
broadcastResponse = random(1, 100) mod 2 eq 0.
If used directly with Express.js application (or StrongLoop) the configuration object passed in must also contain akera.io broker information so back-end business logic can be executed.
var SocketIo = ; appio = socket; var AkeraPush = ; app /* express.js app */ "broker": "host": "localhost" "port": 7300 "channels": "name": "event" "requireAuthentication": true ... /* push notification configuration */ true /* flag set to true for express.js app */;
License
MIT