Plantronics Developer Connection - plantronics https://developer.plantronics.com/blog/plantronics en Advanced SDK Topic: Ensuring Resilience with Plantronics COM API https://developer.plantronics.com/article/advanced-sdk-topic-ensuring-resilience-plantronics-com-api <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/resilience" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">resilience</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/resilient" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">resilient</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/com" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">COM</a></span> <span class="field-item odd 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 even 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 odd label label-default keyword-label"><a href="/blog/sdk" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">SDK</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"><strong>Author:</strong> Lewis Collins, Plantronics<br /> <br /> When using the Plantronics COM API how do you ensure the connection to the Plantronics Hub software is working? <ul> <li>What if the user accidentally shuts down Plantronics Hub (or it crashes), or user upgrades it which would also result in it shutting down and starting again. Would your software re-connect to the COM API automatically?</li> <li>What if Plantronics Hub is not installed, will your software still attempt to connect to it, resulting in long COM timeout? (Will this timeout impact your applications performance)?</li> </ul> On this page I present a solution to these problems that ensures resilience of connection to Plantronics COM API covering the scenarios mentioned above.<br /> <br /> The approach is as follows: <ol> <li>Move all the code that connects / interacts with Plantronics COM API into a seperate class with its own thread. Now Plantronics COM API interaction is done on its own thread it will not impact your application's performance even if a COM timeout / exception occurs. This class is called HubSDKConnector.</li> <li>In HubSDKConnector add a watchdog timer that polls (attempts to use) the COM API every 5 seconds. If the connection fails (exception occurs) it will attempt to re-establish connection. Note, this interval is slowed to 60 seconds if HubSDKConnector detects that a Plantronics Hub upgrade is in progress (Hub installer is running). This corner case allows user to upgrade Hub without your application attempting to request COM API again, which would respawn the Hub EXE before install operation completes, therefore requiring a reboot to complete install - this is not desirable</li> </ol> <strong><img alt="enlightened" height="23" src="http://developer.plantronics.com/profiles/apigee/libraries/ckeditor/plugins/smiley/images/lightbulb.png" title="enlightened" width="23" /> Code for this sample:</strong> <a href="https://github.com/plantronics/pdc/tree/master/Advanced/ResilientPLTDemo" target="_blank">click here&gt;&gt;</a> (note: you must be registered and signed in to access this).<br /> <br /> The code is functionally the same is as the basic C# sample (<a href="/article/get-started-code-samples">in Get Started, C# Tab</a>), with the integration code moved into HubSDKConnector.cs. The code is in C#, but the same concept could be implemented in C++ with the Plantronics COM API.<br /> <br /> Here is a screenshot of it running.<br /> <br /> <em><strong>What do you think of this solution?</strong></em> Let me know your feedback or questions using the form at the bottom of the page. Have fun! :-)<br /> Lewis.<br /> <br /> <div class="media media-element-container media-default"><div id="file-164" class="file file-image file-image-png"> <h2 class="element-invisible"><a href="/files/resilientpltdemopng-0">ResilientPLTDemo.png</a></h2> <div class="content"> <img height="832" width="1530" class="media-element file-default img-responsive" typeof="foaf:Image" src="https://developer.plantronics.com/sites/default/files/ResilientPLTDemo_0.png" alt="" /> </div> </div> </div><br /> <br />  </div></div></div> Thu, 27 Apr 2017 10:02:55 +0000 lcollins 507 at https://developer.plantronics.com https://developer.plantronics.com/article/advanced-sdk-topic-ensuring-resilience-plantronics-com-api#comments Integrate Plantronics REST API from Go https://developer.plantronics.com/article/integrate-plantronics-rest-api-go <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/go" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">go</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/rest" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">REST</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/plantronics" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">plantronics</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 /> I have recently created an example integrate from the Go language to the Plantronics REST API.<br /> <br /> It is still a work in progress but it is functional for receiving device, session and session manager events. (For further guidance on the REST Service API URLs you can use, check out the Java and JavaScript integration samples elsewhere on this site).<br /> <br /> Obtain Go language (golang) from here: <a href="https://golang.org/">https://golang.org/</a><br /> <br /> Obtain the sample code from here: <a href="/system/files/plt%20go%20sample.zip">http://developer.plantronics.com/system/files/plt%20go%20sample.zip</a><br /> <strong>Note: </strong>you must login to this site to download that file.<br /> <br /> Here is how you connect to Plantronics from Go (code snippet):<br />   <pre class="prettyprint"> func httpGetJSON(url string) (map[string]interface{}) {     var dat map[string]interface{}     resp, err := http.Get(url)     if err != nil {         log.Fatal(err)     }     defer resp.Body.Close()     if b, err2 := ioutil.ReadAll(resp.Body); err2 == nil {         if err := json.Unmarshal(b, &amp;dat); err != nil {             log.Fatal(err)         }     }     return dat } func connectToPlantronics() { fmt.Print("Connecting to Plantronics...\r\n") var jsondata map[string]interface{} = httpGetJSON("http://127.0.0.1:32017/Spokes/DeviceServices/Attach?uid=0123456789") fmt.Print("\r\nSession ID:\r\n\r\n"+jsondata["Result"].(string)+"\r\n\r\n") sessionId = jsondata["Result"].(string) var result string = httpGet("http://127.0.0.1:32017/Spokes/SessionManager/Register?name="+pluginName) fmt.Print("\r\nResult:\r\n\r\n"+result+"\r\n\r\n") pluginRegistered = true go eventsListenerThread(sessionId,pluginName) // start monitoring events after connect to api } </pre> <br /> Below is a picture of the code in action, having received a "Don" event (when I put on the Plantronics headset)...<br /> Have fun!<br /> Lewis.<br /> <br /> <div class="media media-element-container media-default"><div id="file-111" class="file file-image file-image-png"> <h2 class="element-invisible"><a href="/files/go-samplepng">go sample.png</a></h2> <div class="content"> <img height="798" width="915" class="media-element file-default img-responsive" typeof="foaf:Image" src="https://developer.plantronics.com/sites/default/files/go%20sample.png" alt="" /> </div> </div> </div></div></div></div> Thu, 01 Sep 2016 12:06:32 +0000 lcollins 384 at https://developer.plantronics.com https://developer.plantronics.com/article/integrate-plantronics-rest-api-go#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