Files

9 lines
10 KiB
JavaScript
Raw Permalink Normal View History

/**
* skills-service-manager - Skills Services Manager
* @version v4.0.6
* @license Copyright (c) 2017, Jibo, Inc. All rights reserved.
* All use of the Jibo SDK is subject to the Jibo SDK End User License Agreement (EULA)
* distributed herewith. If you did not receive a copy of the EULA, you may view a
* copy at https://developers.jibo.com/license.
*/
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.mainProcess=n()}}(function(){return function n(t,i,e){function o(r,u){if(!i[r]){if(!t[r]){var f="function"==typeof require&&require;if(!u&&f)return f(r,!0);if(s)return s(r,!0);var c=new Error("Cannot find module '"+r+"'");throw c.code="MODULE_NOT_FOUND",c}var a=i[r]={exports:{}};t[r][0].call(a.exports,function(n){var i=t[r][1][n];return o(i?i:n)},a,a.exports,n,t,i,e)}return i[r].exports}for(var s="function"==typeof require&&require,r=0;r<e.length;r++)o(e[r]);return o}({1:[function(n,t,i){"use strict";const e=n("jibo-service-framework"),o=n("http");class s{}class r extends e.HTTPClient{constructor(n,t,i){super(t,i),this.host=t,this.port=i,r._instance=this}static createInstance(n,t){return new r(new s,n,t)}static get instance(){return r._instance}get(n,t){let i=o.get("http://"+this.host+":"+this.port+n,n=>{let i="";n.on("data",n=>{i+=n.toString()}),n.on("end",()=>{if(200===n.statusCode)t(null,JSON.parse(i));else{let i="System Manager is unavailable";void 0!==n.statusMessage&&""!==n.statusMessage&&(i=n.statusMessage),t(new Error(i))}})});i.on("error",n=>{t(new Error(`Got error: ${n.message}`))})}sendRequest(n,t,i,e){let s={host:this.host,port:this.port,path:t,method:n,headers:{"Content-Type":"application/json","Content-Length":i.length}},r=o.request(s,n=>{n.setEncoding("utf8");let t="";n.on("data",n=>{t+=n.toString()}),n.on("end",()=>{if(204===n.statusCode)e(null);else if(200===n.statusCode)e(null,JSON.parse(t));else{let t="System Manager is unavailable";void 0!==n.statusMessage&&""!==n.statusMessage&&(t=n.statusMessage),e(new Error(t))}})});r.on("error",n=>{e(new Error("problem with request: "+n.message))}),r.write(i),r.end()}list(n){this.get("/skill/list",(t,i)=>{n(t,i.skills)})}getSkillRecordByName(n,t){this.list((i,e)=>{if(i)return t(i);for(let o=0;o<e.length;o++)if(e[o].name===n)return t(null,e[o]);return t(new Error(`Could not find skill with name ${n}`))})}launch(n,t){let i=JSON.stringify({name:n,context:"{}"});this.sendRequest("POST","/skill/launch",i,t)}terminate(n,t){let i=JSON.stringify({name:n});this.sendRequest("POST","/skill/terminate",i,t)}getMode(n){this.get("/mode",(t,i)=>{return t?n(t):void n(null,i.mode)})}syncTime(n){this.sendRequest("POST","/time/synchronize","",n)}setTimeZone(n,t){if(!n)return void t("No zone given");let i="";try{i=JSON.stringify({timezone:n})}catch(n){return void t("Timezone request is not valid JSON")}this.sendRequest("POST","/time/zone",i,t)}getCredentials(n){this.get("/credentials",(t,i)=>{return t?n(t):void n(null,i)})}sendWifiRequest(n,t,i,e){this.sendRequest(n,t,i,(n,t)=>{e(n,t?t.response:null)})}addNetwork(n){let t=JSON.stringify({command:"ADD_NETWORK"});this.sendWifiRequest("POST","/wifi/wpa",t,n)}removeNetwork(n,t){let i=JSON.stringify({command:"REMOVE_NETWORK "+n});this.sendWifiRequest("POST","/wifi/wpa",i,t)}saveConfig(n){let t=JSON.stringify({command:"SAVE_CONFIG"});this.sendWifiRequest("POST","/wifi/wpa",t,n)}disconnect(n){let t=JSON.stringify({command:"DISCONNECT"});this.sendWifiRequest("POST","/wifi/wpa",t,n)}signalPoll(n){let t=JSON.stringify({command:"SIGNAL_POLL"});this.sendWifiRequest("POST","/wifi/wpa",t,n)}setNetwork(n,t){let i=JSON.stringify({command:"SET_NETWORK "+n});this.sendWifiRequest("POST","/wifi/wpa",i,t)}selectNetwork(n,t){let i=JSON.stringify({command:"SELECT_NETWORK "+n});this.sendWifiRequest("POST","/wifi/wpa",i,t)}enableNetwork(n,t){let i=JSON.stringify({command:"ENABLE_NETWORK "+n});this.sendWifiRequest("POST","/wifi/wpa",i,t)}setInterface(n,t){let i=JSON.stringify({interface:n});this.sendWifiRequest("POST","/wifi/interface",i,t)}getInterface(n){this.get("/wifi/interface",(t,i)=>{return t?n(t):void n(null,i.interface)})}listNetworks(n){let t=JSON.stringify({command:"LIST_NETWORKS"});this.sendWifiRequest("POST","/wifi/wpa",t,n)}wifiStatus(n){let t=JSON.stringify({command:"STATUS-VERBOSE"})