Plantronics Developer Connection - integration https://developer.plantronics.com/blog/integration en Implement Proximity Detection (Near/Far) with Voyager Focus UC/5200 UC and BT600 dongle https://developer.plantronics.com/article/implement-proximity-detection-nearfar-voyager-focus-uc5200-uc-and-bt600-dongle <div class="field field-name-field-keywords field-type-taxonomy-term-reference field-label-above"> <div class="field-label">Keywords:&nbsp;</div> <div class="field-items"> <span class="field-item even label label-default keyword-label"><a href="/blog/proximity" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">proximity</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/near" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">near</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/far" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">far</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/sdk" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">SDK</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/api" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">API</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/integration" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">integration</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/5200" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">5200</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/uc" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">uc</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/focus" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">focus</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/voyager" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">voyager</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/bt600" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">bt600</a></span> </div> </div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded">Greetings!<br /> <br /> The Plantronics SDK feature for receiving proximity events when headset is Near or Far from PC can still be used with the new line of products based on BT600 dongle (Voyager Focus UC, Voyager 5200 UC).<br /> <br /> <strong>**Full sample code for this article located here**:</strong> <a href="/system/files/FocusProximityExample.zip">/system/files/FocusProximityExample.zip</a><br /> (You must be logged in to download the file).<br /> <br /> You can register for Proximity with these devices using the latest SDK version 3.8.51454.38364, located here: <a href="http://developer.plantronics.com/windows">http://developer.plantronics.com/windows</a><br /> <br /> You need to register for DeviceListener HeadsetStateChanged events, like this:<br />   <pre class="prettyprint"> m_deviceListenerEvents.onHeadsetStateChanged += m_deviceListenerEvents_onHeadsetStateChanged;</pre> <br /> Then you register to receive proximity:<br />   <pre class="prettyprint"> m_hostCommandExt.EnableProximity(true); // enable proximity reporting for device m_hostCommandExt.RequestProximity(); // request to receive asyncrounous near/far proximity event to HeadsetStateChanged event handler. </pre> <br /> When you handle the HeadsetStateChanged events you can see if you are near or far:<br /> (Note, there are a couple of edge cases for the older legacy wireless products where you need to re-register for proximity on InRange and ProximityDisabled, these do not apply to BT600). <pre class="prettyprint"> private static void m_deviceListenerEvents_onHeadsetStateChanged(COMDeviceListenerEventArgs args) { switch (args.HeadsetStateChange) { case DeviceHeadsetStateChange.HeadsetStateChange_Near: Console.WriteLine("&gt;&gt;Headset NEAR (via deviceListener event)"); break; case DeviceHeadsetStateChange.HeadsetStateChange_Far: Console.WriteLine("&gt;&gt;Headset FAR (via deviceListener event)"); // this is NOT working. for now use workaround in m_deviceComEvents_onDataReceived below. break; case DeviceHeadsetStateChange.HeadsetStateChange_ProximityDisabled: // Immediately re-enable proximity RegisterForProximity(true); break; case DeviceHeadsetStateChange.HeadsetStateChange_InRange: // Immediately re-enable proximity RegisterForProximity(true); break; } } </pre> Finally, there is a known issue with the current SDK version that we need to workaround to get the "Far" event. (the "Far" event is not currently reported via DeviceListener, expected to be implemented in later SDK release 3.9).<br /> <br /> For the workaround register to receive "raw" headset data events:<br />   <pre class="prettyprint"> m_deviceComEvents = m_activeDevice as ICOMDeviceEvents_Event; m_deviceComEvents.onDataReceived += m_deviceComEvents_onDataReceived; </pre> <br /> Then when you receive raw data event, use the code below to work out when the device is "Far":<br />   <pre class="prettyprint"> private static string byteArrayToString(byte[] p) { StringBuilder b = new StringBuilder(); foreach (byte x in p) b.Append(x.ToString("X2")); return b.ToString(); } private static void m_deviceComEvents_onDataReceived(ref object report) { byte[] reportbuf = (byte[])report; string datareporthex = byteArrayToString(reportbuf); // use raw device data to implement proximity Far event string command = datareporthex.Substring(18, 4); switch (command) { case "0806": string nearfar = datareporthex.Substring(26, 2); if (nearfar == "00") // this workaround is required with 3.8 for now as Far is not done in Spokes SDK (will be in 3.9) { Console.WriteLine("&gt;&gt;Headset FAR (via raw device data event)"); } break; } } </pre> <br /> Here is a picture of the code in action:<br /> <div class="media media-element-container media-default"><div id="file-113" class="file file-image file-image-png"> <h2 class="element-invisible"><a href="/files/focus-proximity-examplepng">focus proximity example.png</a></h2> <div class="content"> <img height="277" width="917" class="media-element file-default img-responsive" typeof="foaf:Image" src="https://developer.plantronics.com/sites/default/files/focus%20proximity%20example.png" alt="" /> </div> </div> </div><br /> <br /> That's it! Have fun with proximity <img alt="laugh" height="23" src="http://developer.plantronics.com/profiles/apigee/libraries/ckeditor/plugins/smiley/images/teeth_smile.png" title="laugh" width="23" /><br /> Lewis.<br /> <br /> <strong>**Full sample code for this article located here**:</strong> <a href="/system/files/FocusProximityExample.zip">/system/files/FocusProximityExample.zip</a></div></div></div> Fri, 02 Sep 2016 13:32:28 +0000 lcollins 385 at https://developer.plantronics.com https://developer.plantronics.com/article/implement-proximity-detection-nearfar-voyager-focus-uc5200-uc-and-bt600-dongle#comments Using Plantronics SDK from Java https://developer.plantronics.com/article/using-plantronics-sdk-java <div class="field field-name-field-keywords field-type-taxonomy-term-reference field-label-above"> <div class="field-label">Keywords:&nbsp;</div> <div class="field-items"> <span class="field-item even label label-default keyword-label"><a href="/blog/java" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Java</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/plantronics" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">plantronics</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/sdk" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">SDK</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/integration" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">integration</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/rest" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">REST</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/service" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Service</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/api" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">API</a></span> </div> </div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><span style="color:#FF0000;">*Update 22nd Jan 2016*</span>: Since the SDK version 3.7.x, you can now optionally use https:// port <span style="color:#FF0000;"><strong>32018</strong></span> in addition to http:// on port <strong>32017</strong>! (however for https you may need to manually deploy the self-signed certificate if using Firefox or Java).<br /> <br /> <strong>Sample code:</strong><br /> <a href="/system/files/PlantronicsRESTDemo%20-%20Milestone%201%20full%20call%20control%20and%20events%20listening.zip">Download this sample code as a ZIP</a><br />   <pre class="brush: java"> String tmpResult =     RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/DeviceServices/Attach?uid=0123456789" );</pre> This code requires the convenience function SendRESTCommand (available <a href="/system/files/PlantronicsRESTDemo%20-%20Milestone%201%20full%20call%20control%20and%20events%20listening.zip">in the sample code ZIP</a>).<br /> <br /> 0123456789 is a magic uid which tells the REST Service API to attach to the "primary" Plantronics device (primary device is settable via the Plantronics Hub user interface, in the case you have more than one Plantroncis device attached to your PC).<br /> <br /> Now we can examine the tmpResult variable to see if the attach was a success. <pre class="brush: java"> int pos = tmpResult.indexOf("\"Result\":\""); if (pos&gt;-1) {     tmpResult = tmpResult.substring(pos+10);     pos = tmpResult.indexOf("\"");     if (pos&gt;-1)     {         tmpResult = tmpResult.substring(0, pos);         System.out.println("Session id is: " + tmpResult);         sessionid = tmpResult;     } }</pre> This code is extracting the sessionid from the HTTP response. We need that later for some of the other REST Service API commands. Note, the HTTP response is in fact JSON, so it would be better to parse with a JSON parser, but I haven't adopted a suitable JSON parser yet...<br /> <br /> After a short delay we can go ahead an register a REST Service API plugin. The plugin is needed for some of the call control commands. <pre class="brush: java"> try {     Thread.sleep(250); } catch (InterruptedException ex) {     Logger.getLogger(PlantronicsRESTDemo.class.getName()).log(Level.SEVERE, null, ex); }                                   if (sessionid.length()&gt;0) {     RESTConvenienceClass.SendRESTCommand(         "http://127.0.0.1:32017/Spokes/SessionManager/Register?name=My%20Java%20Plugin"     );                    pluginRegistered = true; }</pre> Now we are able to poll for device events using further REST Service API commands, like this:<br /> (Note: the sessid and plugin_name need to match what we registered earlier).<br /> The contents of the responses we get back tell us lots of information, such as when user has answered a call with headset, mutes a call, takes headset off, etc. <pre class="brush: java"> RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/DeviceServices/Events?sess="         + sessid         + "&amp;queue=0" ) RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/CallServices/Events" ); RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/CallServices/SessionManagerCallEvents?name="         + plugin_name );</pre> Finally we can control the headset by telling it when we are going on a call, for example:<br /> An incoming call (pass an integer callid, used to refer to this call during its lifecycle, and pass an optional caller name for Plantronics' display device products): <pre class="brush: java"> callid = callid + 1; caller_name = "Bob%20Smith"; RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/CallServices/IncomingCall?name=My%20Java%20Plugin&amp;callID=%7B%22Id%22%3A%22"         + callid         + "%22%7D&amp;contact=%7B%22Name%22%3A%22"         + caller_name         + "%22%7D&amp;tones=Unknown&amp;route=ToHeadset" );</pre> End the call: <pre class="brush: java"> RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/CallServices/TerminateCall?name=My%20Java%20Plugin&amp;callID=%7B%22Id%22%3A%22"         + callid         + "%22%7D" );</pre> For more examples and to see a complete Java implementation, <a href="/system/files/PlantronicsRESTDemo%20-%20Milestone%201%20full%20call%20control%20and%20events%20listening.zip">download the sample code ZIP</a>.<br /> <br /> Here is a screeshot of the sample code in action running under <a href="https://netbeans.org/" target="_blank">NetBeans IDE</a>:<br /> <br /> false<br /> <br /> Have fun!<br /> <br /> <br /> <br /> <br /> <br />  </div></div></div> Thu, 05 Nov 2015 12:40:30 +0000 lcollins 162 at https://developer.plantronics.com https://developer.plantronics.com/article/using-plantronics-sdk-java#comments