3.0.3 • Published 4 years ago

mesg-pusher v3.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

mesg-pusher License Latest Release Build Status mesg-cli semantic-release Codacy Badge Dependencies

MESG Service for Pusher ID: com.mesg.pusher

MESGPusher

Contents

Installation

MESG SDK

This service requires MESG SDK to be installed first.

You can install MESG SDK by running the following command or follow the installation guide.

npm install -g mesg-cli

Deploy the Service

To deploy this service, go to this service page on the MESG Marketplace and click the button "get/buy this service".

Features

Currently able to use Pusher channels, channel, trigger and triggerBatch features from MESG.

Use case

MESG Applications on different servers communicating together over Pusher notifications.

Example

  1. on MESG Application on a server A : use this MESG Service to send notifications over Pusher.

  2. on MESG Application on a server B : listen to the notifications emitted by MESG Application on a server A over Pusher.

How to listen in a MESG Application

Install MESG and Pusher dependencies :

yarn add mesg-js pusher-js

Create a socket connection to listen and react to Pusher notifications :

// in a MESG Application
const { application } = require('mesg-js')
const mesg = application()
const Pusher = require('pusher-js')
const pusher = new Pusher('PUSHER_APP_KEY', { cluster: 'PUSHER_CLUSTER', forceTLS: true }) // replace with your credentials
const INSTANCE_HASH = await mesg.resolve('com.mesg.pusher')
const CHANNEL = 'some-channel'
const EVENT = 'some-event'
const CREDENTIALS = { appId: 'PUSHER_APP_ID', key: 'PUSHER_APP_KEY', secret: 'PUSHER_APP_SECRET' } // replace with your credentials
// subscribe to Pusher channel
const channel = pusher.subscribe(CHANNEL)
// on Pusher notification received
channel.bind(EVENT, data => {
  // example : launch MESG service trigger task
  mesg.executeTask({
    instanceHash: INSTANCE_HASH,
    taskKey: 'trigger',
    inputs: mesg.encodeData({ ...CREDENTIALS, channel: CHANNEL, event: EVENT, ...data })
  })
})

Environment variables

Instead of providing Pusher credentials or options on each request, these can be provided via command line arguments or .env file, as shown below in Integration tests.

As usual, user inputs always takes precedence on defined environment variables.

NameEnviroment Variable
appIdPUSHER_APP_ID
clusterPUSHER_CLUSTER
useTLSPUSHER_USE_TLS
hostPUSHER_HOST
keepAlivePUSHER_KEEP_ALIVE
keyPUSHER_APP_KEY
portPUSHER_PORT
proxyPUSHER_PROXY
secretPUSHER_APP_SECRET
timeoutPUSHER_TIMEOUT

Integration tests

In order to launch them locally you will have to pass the environment variables along with your command, like so :

  • via command line arguments :
    export PUSHER_APP_ID=... && export PUSHER_APP_KEY=... && export PUSHER_APP_SECRET=... && export PUSHER_CLUSTER=... && export MESG_ACCOUNT=... && export MESG_PASSPHRASE=... && yarn test
  • via .env file :
    • file
      export PUSHER_APP_ID=...
      export PUSHER_APP_KEY=...
      export PUSHER_APP_SECRET=...
      export PUSHER_CLUSTER=...
      export MESG_ACCOUNT=...
      export MESG_PASSPHRASE=...
    • command
      source .env && yarn test

Definitions

Tasks

Task key: trigger

triggers an event on one or more channels

Inputs
NameKeyTypeDescription
appIdappIdStringoptional Pusher application ID
keykeyStringoptional Pusher application key
secretsecretStringoptional Pusher application secret key
useTLSuseTLSBooleanoptional whether to encrypt notification, defaults to false
clusterclusterStringoptional if `host` is present, it will override the `cluster` option
hosthostStringoptional whether to use a different host, defaults to api.pusherapp.com
portportNumberoptional whether to use a different port, defaults to 80 for unuseTLS and 443 for useTLS
proxyproxyStringoptional URL to proxy the requests through
timeouttimeoutNumberoptional timeout for all requests in milliseconds
keepAlivekeepAliveBooleanoptional enables keep-alive, defaults to false
namenameStringevent name
datadataObjectevent data (maximum 10Kb)
channelschannelsObjectoptional array of one or more channel names - limited to 100 channels
channelchannelStringoptional channel name if publishing to a single channel (can be used instead of channels)
socket_idsocket_idObjectoptional excludes the event from being sent to a specific connection
Outputs
NameKeyTypeDescription
messagemessageStringa dummy 'sent' message

Task key: triggerBatch

triggers multiple events in a single call (up to 10 per call on the multi-tenant clusters)

Inputs
NameKeyTypeDescription
appIdappIdStringoptional Pusher application ID
keykeyStringoptional Pusher application key
secretsecretStringoptional Pusher application secret key
useTLSuseTLSBooleanoptional whether to encrypt notification, defaults to false
clusterclusterStringoptional if `host` is present, it will override the `cluster` option
hosthostStringoptional whether to use a different host, defaults to api.pusherapp.com
portportNumberoptional whether to use a different port, defaults to 80 for unuseTLS and 443 for useTLS
proxyproxyStringoptional URL to proxy the requests through
timeouttimeoutNumberoptional timeout for all requests in milliseconds
keepAlivekeepAliveBooleanoptional enables keep-alive, defaults to false
batchbatchObjectarray of events (maximum 10)
Outputs
NameKeyTypeDescription
messagemessageStringa dummy 'sent' message

Task key: channels

get the list of the channel within an application that have active subscriptions (also referred to as being occupied)

Inputs
NameKeyTypeDescription
appIdappIdStringoptional Pusher application ID
keykeyStringoptional Pusher application key
secretsecretStringoptional Pusher application secret key
useTLSuseTLSBooleanoptional whether to encrypt notification, defaults to false
clusterclusterStringoptional if `host` is present, it will override the `cluster` option
hosthostStringoptional whether to use a different host, defaults to api.pusherapp.com
portportNumberoptional whether to use a different port, defaults to 80 for unuseTLS and 443 for useTLS
proxyproxyStringoptional URL to proxy the requests through
timeouttimeoutNumberoptional timeout for all requests in milliseconds
keepAlivekeepAliveBooleanoptional enables keep-alive, defaults to false
paramsparamsObjectoptional additional parameters to be sent as query string parameters (see HTTP API Reference)
Outputs
NameKeyTypeDescription
channelschannelsStringarray of channel names

Task key: channel

fetch one or some attributes for a given channel

Inputs
NameKeyTypeDescription
appIdappIdStringoptional Pusher application ID
keykeyStringoptional Pusher application key
secretsecretStringoptional Pusher application secret key
useTLSuseTLSBooleanoptional whether to encrypt notification, defaults to false
clusterclusterStringoptional if `host` is present, it will override the `cluster` option
hosthostStringoptional whether to use a different host, defaults to api.pusherapp.com
portportNumberoptional whether to use a different port, defaults to 80 for unuseTLS and 443 for useTLS
proxyproxyStringoptional URL to proxy the requests through
timeouttimeoutNumberoptional timeout for all requests in milliseconds
keepAlivekeepAliveBooleanoptional enables keep-alive, defaults to false
paramsparamsObjectoptional additional parameters to be sent as query string parameters (see HTTP API Reference)
Outputs
NameKeyTypeDescription
occupiedoccupiedBooleanwhether the channel currently has active subscriptions
user_countuser_countNumberoptional number of distinct users currently subscribed to this channel (a single user may be subscribed many times, but will only count as one)
subscription_countsubscription_countNumberoptional number of connections currently subscribed to this channel (not available by default, has to be enabled in dashboard)
3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.3

5 years ago