9 lines
10 KiB
JavaScript
9 lines
10 KiB
JavaScript
/**
|
|
* 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"});this.sendWifiRequest("POST","/wifi/wpa",t,n)}scan(n){let t=JSON.stringify({command:"SCAN"});this.sendWifiRequest("POST","/wifi/wpa",t,n)}scanResults(n){let t=JSON.stringify({command:"SCAN_RESULTS"});this.sendWifiRequest("POST","/wifi/wpa",t,n)}}r.NAME="system-manager",Object.defineProperty(i,"__esModule",{value:!0}),i.default=r},{http:void 0,"jibo-service-framework":void 0}],2:[function(n,t,i){"use strict";function e(){return new d}const o=n("path"),s=n("electron"),r=n("find-root"),u=n("events"),f=n("jibo-log"),c=n("../clients/SystemManagerClient");let a=new f("ssm-main-process");a.toSyslog();class d extends u.EventEmitter{constructor(){super(),c.default.createInstance("127.0.0.1",8585),a.debug("SSM Started"),this.onReady=this.onReady.bind(this),this.onCrashed=this.onCrashed.bind(this),this.onShow=this.onShow.bind(this),this.onHide=this.onHide.bind(this),this.onGetPid=this.onGetPid.bind(this),s.app.isReady()?this.onReady():s.app.on("ready",this.onReady),s.ipcMain.on("show",this.onShow),s.ipcMain.on("hide",this.onHide),s.ipcMain.on("get-pid",this.onGetPid),s.ipcMain.on("cleanedup",()=>{s.app.quit()})}onShow(){this.skillWindow.show(),this.skillWindow.focus(),this.skillWindow.setPosition(0,0)}onHide(){this.skillWindow.hide()}onCrashed(){a.error("SSM Renderer Process Crashed"),a.error("Checking for running skills"),c.default.instance.list((n,t)=>{if(n)return a.error("System Manager error. Restarting SSM.",n),this.onReady();for(let i=0;i<t.length;i++)if(t[i].running)return a.error("Terminating ",t[i].name),void c.default.instance.terminate(t[i].name,n=>{a.error("Restarting SSM renderer process"),this.skillWindow.reload()});a.error("No skill to shut down. Restarting SSM renderer process"),this.onReady()})}onReady(){this.skillWindow=new s.BrowserWindow({x:0,y:0,show:!1,width:d.WIDTH,height:d.HEIGHT,backgroundColor:"#000000",frame:!1}),this.skillWindow.on("closed",this.onSkillWindowClosed),this.skillWindow.webContents.on("crashed",this.onCrashed);let n=o.join(r(__dirname),"index.html");console.log("onReady",n),this.skillWindow.loadURL("file://"+n),this.skillWindow.webContents.once("did-finish-load",()=>{this.skillWindow.show()})}onSkillWindowClosed(){this.skillWindow=null}onGetPid(n){n.sender.send("set-pid",process.pid)}}d.WIDTH=1280,d.HEIGHT=720,Object.defineProperty(i,"__esModule",{value:!0}),i.default=e},{"../clients/SystemManagerClient":1,electron:void 0,events:void 0,"find-root":void 0,"jibo-log":void 0,path:void 0}],3:[function(n,t,i){"use strict";var e=this&&this.__awaiter||function(n,t,i,e){return new(i||(i=Promise))(function(o,s){function r(n){try{f(e.next(n))}catch(n){s(n)}}function u(n){try{f(e.throw(n))}catch(n){s(n)}}function f(n){n.done?o(n.value):new i(function(t){t(n.value)}).then(r,u)}f((e=e.apply(n,t||[])).next())})};const o=n("path"),s=n("jibo-service-framework"),r=n("fs"),u=n("../../utils/Async"),f=n("jibo-service-framework"),c=["electron","jibo","pulseaudio"],a="/var/log",d=o.join(a,"monitoring.log");class l extends s.HTTPService{constructor(n,t){super("monitor-reporter",n,t),this.stopped=!1,this.initialized=!1,l._instance=this,this.addReport=this.addReport.bind(this)}static createInstance(n,t){return new l(n,t)}static get instance(){return l._instance}init(n){const t=n=>super[n];return e(this,void 0,void 0,function*(){f.RegistryClient.createInstance("127.0.0.1",8181),yield u.default.get(n=>t("init").call(this,n)),this.client=new s.WSClient(`ws://127.0.0.1:4111/info/process`),this.initialized=!0;const i=o.join(a,`monitoring-${Date.now()}.log`),e=yield u.default.get2(n=>r.exists(d,n));e&&(yield u.default.get(n=>r.rename(d,i,n))),n(),this.start()})}routes(n){super.routes(n),n.post("/report",this.addReport)}addReport(n,t){return e(this,void 0,void 0,function*(){const t=yield this.parseRequest(n);yield u.default.get(n=>r.appendFile(d,JSON.stringify(t)+"\n",n))})}addEvent(n){return e(this,void 0,void 0,function*(){if(this.initialized){const t={type:"event",ts:Date.now(),data:n};yield u.default.get(n=>r.appendFile(d,JSON.stringify(t)+"\n",n))}})}stop(){this.stopped=!0}start(){return e(this,void 0,void 0,function*(){for(;!this.stopped;){const n=yield u.default.get2(n=>this.client.once("message",n)),t={type:"processes",ts:Date.now(),total_cpu_jiffies:n.total_cpu_jiffies,data:[]};for(let i=0;i<n.processes.length;i++){const e=n.processes[i];for(let o=0;o<c.length;o++)e.name.indexOf(c[o])>=0&&t.data.push(e)}yield u.default.get(n=>r.appendFile(d,JSON.stringify(t)+"\n",n))}})}parseRequest(n){return new Promise((t,i)=>{let e="";n.on("data",n=>{e+=n}),n.on("end",()=>{let n;try{n=JSON.parse(e),t(n)}catch(n){i(n)}})})}}Object.defineProperty(i,"__esModule",{value:!0}),i.default=l},{"../../utils/Async":5,fs:void 0,"jibo-service-framework":void 0,path:void 0}],4:[function(n,t,i){"use strict";function e(){return o(this,void 0,void 0,function*(){"--reporter"===process.argv[3]&&(r.default.createInstance({port:10101},"reporter-service"),yield u.default.get(n=>r.default.instance.init(n))),console.log("pre create main"),s.default()})}var o=this&&this.__awaiter||function(n,t,i,e){return new(i||(i=Promise))(function(o,s){function r(n){try{f(e.next(n))}catch(n){s(n)}}function u(n){try{f(e.throw(n))}catch(n){s(n)}}function f(n){n.done?o(n.value):new i(function(t){t(n.value)}).then(r,u)}f((e=e.apply(n,t||[])).next())})};const s=n("./MainProcess"),r=n("./reporter/ReporterService"),u=n("../utils/Async");e()},{"../utils/Async":5,"./MainProcess":2,"./reporter/ReporterService":3}],5:[function(n,t,i){"use strict";var e=this&&this.__awaiter||function(n,t,i,e){return new(i||(i=Promise))(function(o,s){function r(n){try{f(e.next(n))}catch(n){s(n)}}function u(n){try{f(e.throw(n))}catch(n){s(n)}}function f(n){n.done?o(n.value):new i(function(t){t(n.value)}).then(r,u)}f((e=e.apply(n,t||[])).next())})};class o{static get(n){return e(this,void 0,void 0,function*(){return new Promise((t,i)=>{n((n,e)=>{return n?i(n):void t(e)})})})}static get2(n){return e(this,void 0,void 0,function*(){return new Promise(t=>{n(n=>{t(n)})})})}static all(n,t){return e(this,void 0,void 0,function*(){let i=[];for(;n.length>0;){const e=yield Promise.all(n.splice(0,t));i=i.concat(e)}return i})}}Object.defineProperty(i,"__esModule",{value:!0}),i.default=o},{}]},{},[4])(4)}); |