Plantronics Developer Connection - Java https://developer.plantronics.com/blog/java en 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