Overview

In this article, I describe how to access the Plantronics Manager Pro APIs for real-time events. The source code is pointing at the "Sandbox" tenant. However, once you have access to your own tenant you will just change the relavent URLs and security tokens (the tenant information provided during Hub install and generating a PubNub channel to receive your realtime events). This example is written in C#, but there are many other languages supporting PubNub.

The streaming APIs provide access to real-time events from your Plantronics products and Plantronics Manager Pro cloud service that occur on the particular customer tenant's UC infrastructure, including:
  • mute events
  • QD events
  • acoustic events.
  • and more...
These real-time events are received as JSON and are suitable for integration with custom applications that need real-time status of your UC platform. This sample implements a basic event reciever to illustrates the simple logging of the received JSON on the console.

Design

The below diagram shows how a partner solution is able to connect to the Open Data Access Streaming API and receive the realtime events from the Plantronics Manager Pro cloud platform. Each Plantronics Manager Pro tenant that has Open Data Access enabled can optionally push various realtime events to a tenant-specific PubNub channel. You can then develop apps that listen to that PubNub channel and consume the realtime events.

Code

This sample code illustrates how to listen for the Plantronics Open Data Access PubNub channel for a particular tenant:

PubNubSimpleReceiver

Below is the sample code C# code that defines the tenant's GitHub keys in the App.config file (Subscribe Key, Publish Key and Subscribe Channel). It uses the NuGet package called PubNub to connect to the PubNub channel. The code then defines a callback to handle messages received (with pubnub.AddListener), that just displays the message contents to the console. It also adds a handler for the PubNub status messages, so you can see if it was connected successfully, etc.

 
using System;
using PubnubApi;
using System.Configuration;

namespace PubNubSimpleReceiver
{
    /// <summary>
    /// This Program demo illustrates how to consume the Plantronics Web Services API realtime stream,
    /// to receive headset events such as QD (quick disconnect) connected/disconnected and Mute (muted/unmuted).
    /// NOTE: In order to work you must edit the .config file in this project (or alongside the EXE) and add
    /// your settings, as follows:
    /// - PubNub_SubscribeKey - this key is provided by your PubNub developer account
    /// - PubNub_PublishKey - this key is provided by your PubNub developer account
    /// - PubNub_SubscribeChannel - this channel id you create in your PubNub developer account
    /// Author: Lewis.Collins@Plantronics.com, 11th July 2017
    /// </summary>
    class Program
    {
        static public Pubnub pubnub;

        static public void Main()
        {
            PNConfiguration config = new PNConfiguration();
            config.SubscribeKey = ConfigurationManager.AppSettings.Get("PubNub_SubscribeKey");
            config.PublishKey = ConfigurationManager.AppSettings.Get("PubNub_PublishKey");

            pubnub = new Pubnub(config);
            pubnub.AddListener(new SubscribeCallbackExt(
                (pubnubObj, message) =>
                {
                    // Log the new message stored in message.Message to the console
                    if (message != null)
                    {
                        Console.WriteLine("Msg: " + message.Message +
                            (message.Channel != null ? ", On chan: " + message.Channel : "") );
                    }
                },
                (pubnubObj, presence) => { },
                (pubnubObj, status) =>
                {
                    Console.WriteLine("PubNub Status: " + status.Category);
                }
            ));

            // Subscripe to your PubNub channel and wait for events
            pubnub.Subscribe<string>()
                .Channels(new string[] {
                    ConfigurationManager.AppSettings.Get("PubNub_SubscribeChannel")
                })
                .Execute();

            System.Console.WriteLine("press enter to quit...");
            System.Console.ReadLine();
        }
    }
}

Screenshot

The below screenshot shows the application running and awaiting realtime events from the sandbox tenant.