Plantronics SDK developers can access the ICOMHostCommandExt interface by casting the COMHostCommand property in ICOMDevice. If it returns a valid interface then you can call RequestProximity() to request the proximity. If the request is successful RequestProximity() will return true otherwise false. The proximity response from the headset will be reported to the host as an async event so application developers have to register for Proximity events by registering either for onHeadsetStateChanged event exposed in ICOMDeviceListener property of ICOMDevice or by registering for the onHeadsetStateChanged event exposed in ICOMDeviceEventsExt. Developers can access the ICOMDeviceEventsExt interface by casting the ICOMDeviceEvents property in ICOMDevice. If it returns a valid interface then you can register for HeadsetstateChanged event
Following interfaces ICOMHostCommandExt, ICOMDeviceEventsExt, ICOMDeviceListenerEvents will expose proximity events and a way to request proximity as part of the Plantronics SDK. These interfaces can be accessed by applications that directly interface with the device manager or plug-ins that interface with the Plantronics SDK.
ICOMHostCommandExt Interface
public interface ICOMHostCommandExt { ... void EnableProximity(bool bEnable); void RequestProximity(); ... }
bool RequestProximity()
RequestProximity() will send a request to the Plantronics device connected to the USB to get the proximity of the headset. This function returns true if the request is successful otherwise false. On a device that doesn’t support proximity the SDK will throw a DeviceManagerException and applications should handle that exception.
bool EnableProximity(bool bEnable)
EnableProximity() will send a command to the device to enable or disable Proximity reporting from the headset. bEnable = true, enables proximity reporting and bEnable=false disables proximity reporting.
ICOMDeviceEventsExt Interface
public interface ICOMDeviceEventsExt { ... void onHeadsetStateChanged(COMHeadsetStateEventArgs args); }
IDeviceListenerEvents Interface
public interface ICOMDeviceListenerEvents { //ATD: Covers Mobile, PSTN and other ATD events void onATDStateChanged(COMDeviceListenerEventArgs args); //Base: Covers Base, Hub, Handset events void onBaseButtonPressed(COMDeviceListenerEventArgs args); void onBaseStateChanged(COMDeviceListenerEventArgs args); //Headset : Covers Corded, Cordless headsets events void onHeadsetButtonPressed(COMDeviceListenerEventArgs args); void onHeadsetStateChanged(COMDeviceListenerEventArgs args); }
Code snippets:
Sample 1: Requesting Headset Proximity
static ICOMHostCommandExt _command; private static COMDevice _device; static void Main() { //Get a valid _device COMSessionManager mgr = new COMSessionManager(); COMSession sess; mgr.Register("My Session", out sess); _device = sess.GetActiveDevice(); //Cast HostCommand and init _command. _command = _device.HostCommand as ICOMHostCommandExt; RequestProximity(); } private static void RequestProximity() { try { if (_command != null) _command.RequestProximity(); } catch (COMException ex) { Console.WriteLine(ex.Message + "\r\nPlease use a _device that supports proximity."); } }
Sample 2: Registering for Headset Proximity via ICOMDeviceEventsExt:
static ICOMDeviceEventsExt_Event _events; static ICOMHostCommandExt _command; private static COMDevice _device; static void Main() { //Get a valid _device COMSessionManager mgr = new COMSessionManager(); COMSession sess; mgr.Register("My Session", out sess); _device = sess.GetActiveDevice(); //Cast HostCommand and init _command and _events. _command = _device.HostCommand as ICOMHostCommandExt; _events = _device as ICOMDeviceEventsExt_Event; _events.onHeadsetStateChanged += events_HeadsetStateChanged; } private static void events_HeadsetStateChanged(COMHeadsetStateEventArgs args) { StringBuilder strB = new StringBuilder(); strB.Append("Device Event: "); if (args.HeadsetState == DeviceHeadsetState.HeadsetState_Proximity) strB.Append(String.Format("Headset Proximity received. (Proximity = {0})", args.Proximity)); else strB.Append(String.Format("Headset state changed. ({0})", args.HeadsetState)); strB.AppendLine(); Console.WriteLine(strB.ToString()); }
Sample 3: Registering for Headset Proximity via ICOMDeviceListenerEvents
static ICOMHostCommandExt _command; static ICOMDeviceListenerEvents_Event _devListener; private static COMDevice _device; static void Main() { //Get a valid _device COMSessionManager mgr = new COMSessionManager(); COMSession sess; mgr.Register("My Session", out sess); _device = sess.GetActiveDevice(); //Cast HostCommand and DeviceListener and init _command and _devListener. _command = _device.HostCommand as ICOMHostCommandExt; _devListener = _device.DeviceListener; _devListener.onHeadsetStateChanged += devListener_HeadsetStateChanged; } private static void devListener_HeadsetStateChanged(COMDeviceListenerEventArgs args) { StringBuilder strB = new StringBuilder(); strB.Append("Device Event: "); strB.Append(String.Format("Headset state changed. ({0})", args.HeadsetStateChange)); strB.AppendLine(); Console.WriteLine(strB.ToString()); }
Download link: Plantronics SDK Headset Proximity Sample.zip