Quantcast
Channel: PDC Blogs
Viewing all articles
Browse latest Browse all 26

Hello Plantronics World! How to quickly support Plantronics devices...

$
0
0

Hi all,

 

I have some updated source code for the Hello Plantronics World samples. These sample apps are intended as a quick introduction to integrating your app with Plantronics.

 

It does not show all the features but demonstrates call control, mute sync, line control and how to receive a variety of headset events. See end of post for download links for the project source files.

 

hello plt 2.x world.png

 

Let's take a look at how it's coded up.

 

It is a C# WPF application utilizing .NET Framework 4.0 (this is minimum version of .NET required by our Spokes SDK 2.x .NET Interop DLL).

 

In the Window Loaded event grab the singleton provided by Spokes Wrapper, add some event handlers, then call Connect.

(See below for what SetLogger is for!)

 

        private void Window_Loaded(object sender, RoutedEventArgs e)        {            // get Spokes singleton           m_spokes = Spokes.Instance;            // set us as the Spokes debug logger           m_spokes.SetLogger(this);            // register event handlers...            // detect when Plantronics device is added or removed from PC:           m_spokes.Attached += new Spokes.AttachedEventHandler(m_spokes_Attached);           m_spokes.Detached += new Spokes.DetachedEventHandler(m_spokes_Detached);            // detect when we are on a VoIP call:           m_spokes.OnCall += new Spokes.OnCallEventHandler(m_spokes_OnCall);           m_spokes.NotOnCall += new Spokes.NotOnCallEventHandler(m_spokes_NotOnCall);            // detect when user answers/ends a call using headset buttons:            m_spokes.CallAnswered += new Spokes.CallAnsweredEventHandler(m_spokes_CallAnswered);           m_spokes.CallEnded += new Spokes.CallEndedEventHandler(m_spokes_CallEnded);            // detect when we are on a Mobile call:           m_spokes.OnMobileCall += new Spokes.OnMobileCallEventHandler(m_spokes_OnMobileCall);           m_spokes.NotOnMobileCall += new Spokes.NotOnMobileCallEventHandler(m_spokes_NotOnMobileCall);           m_spokes.MobileCallerId += new Spokes.MobileCallerIdEventHandler(m_spokes_MobileCallerId);            // detect if we are wearing the headset:           m_spokes.PutOn += new Spokes.PutOnEventHandler(m_spokes_PutOn);           m_spokes.TakenOff += new Spokes.TakenOffEventHandler(m_spokes_TakenOff);            // detect if headset is docked:           m_spokes.Docked += new Spokes.DockedEventHandler(m_spokes_Docked);           m_spokes.UnDocked += new Spokes.DockedEventHandler(m_spokes_UnDocked);           // now connect to Spokes           m_spokes.Connect("Hello Spokes 2.x World");        }

 

The main app window has some buttons to show call control and mute etc.

The click event code of those buttons are below.

 

For example if your softphone app has an incoming call, call the IncomingCall function with a unique call id.

This causes the Plantronics headset to ring

 

Pressing "talk button" on headset will answer the call. The fact call was answered can be received via CallAnswered event (see below).

 

        private void incomingcallbtn_Click(object sender, RoutedEventArgs e)        {            m_spokes.IncomingCall(++callid);            UpdateCallIdTextBox();        }        private void UpdateCallIdTextBox()        {            callIdTextBox.Dispatcher.Invoke(new Action(delegate()            {                callIdTextBox.Text = callid.ToString();            }));        }        private void Outgoingcallbtn_Click(object sender, RoutedEventArgs e)        {           m_spokes.OutgoingCall(++callid);           UpdateCallIdTextBox();        }        private void mutecallbtn_Click(object sender, RoutedEventArgs e)        {           m_spokes.SetMute(true);        }        private void unmutecallbtn_Click(object sender, RoutedEventArgs e)        {           m_spokes.SetMute(false);        }

 

The implementations of the event handlers provide some arguments objects with useful fields.

 

For instance CallAnswered and CallEnded events receive the internal callid (i.e. that you used when you called IncomingCall/OutgoingCall earlier), and the CallSource. CallSource is the name of the app that user took a call on - your app, or another Spokes-supported softphone e.g. Lync or Skype. Now you can write apps that can monitor users' calling activity also in 3rd party softphones!

 

        void m_spokes_CallEnded(object sender, CallEndedArgs e)        {           DebugPrint(MethodInfo.GetCurrentMethod().Name, "@@@ VoIP call was Ended: id=" + e.CallId + ", source=" + e.CallSource);        }        void m_spokes_CallAnswered(object sender, CallAnsweredArgs e)        {           DebugPrint(MethodInfo.GetCurrentMethod().Name, "@@@ VoIP call was Answered: id="+e.CallId+", source="+e.CallSource);        }

 

Some of the other event handlers provide useful headset state info - below are the PutOn/TakenOff events for the wearing sensor (supported by Voyager Pro, Voyager Legend UC, Blackwire C720 and Blackwire C520).

Also the Attached/Detached event to know when a Plantronics device was plugged into the PC:

 

        void m_spokes_TakenOff(object sender, WearingStateArgs e)        {           DebugPrint(MethodInfo.GetCurrentMethod().Name, "@@@ Headset "+(e.m_isInitialStateEvent?"INITIALLY ":"")+"Taken Off");        }        void m_spokes_PutOn(object sender, WearingStateArgs e)        {           DebugPrint(MethodInfo.GetCurrentMethod().Name, "@@@ Headset " + (e.m_isInitialStateEvent ? "INITIALLY " : "") + "Put On");        }        void m_spokes_Detached(object sender, EventArgs e)        {           DebugPrint(MethodInfo.GetCurrentMethod().Name, "@@@ Plantronics Device was detached");        }        void m_spokes_Attached(object sender, AttachedArgs e)        {           DebugPrint(MethodInfo.GetCurrentMethod().Name, "@@@ Plantronics Device \"" + e.m_device.ProductName + "\" was attached");        }

 

Finally here is a useful debugging facility. The DebugLogger interface allows your app to receive Spokes debugging information about events received etc so you could optionally log this to a file (in this app it is just appending to a TextBox):

(When you obtained the Spokes instance earlier pass your app's class that implements DebugLogger using the m_spokes.SetLogger(this) method).

 

        public void DebugPrint(string methodname, string str)        {           eventsLogTextBox.Dispatcher.Invoke(new Action(delegate()            {                string datetime = DateTime.Now.ToString("HH:mm:ss.fff");                eventsLogTextBox.AppendText((String.Format("{0}: {1}: {2}(): {3}\r\n", ++linenum, datetime, methodname, str)));                eventsLogTextBox.ScrollToEnd();            }));        }

 

That's it!

 

Here are the download links:

 

Grab the Samples repo from: pltdev/Samples · GitHub

Find the app for Spokes 2.x under Samples\HelloPLTWorld2.x

(And when Spokes 3.0 is launched under Samples\HelloPLTWorld3.0)

 

Note: the projects link to the wrappers source code under: Samples\wrappers

 

Let us know how you get on! Do you find Spokes Wrapper useful? Or do you prefer to use the native Spokes SDK directly (COM Service, COM Service .NET Interop, REST Service)?

 

Thanks,

Lewis


Viewing all articles
Browse latest Browse all 26

Trending Articles