Files
JiboSDK/node_modules/jibo-tools/lib/simulator/services/lps-service.js
2026-03-22 03:21:45 +02:00

1 line
3.6 KiB
JavaScript

"use strict";var t=function(t){return t&&t.__esModule?t["default"]:t},e=function(){function t(t,e){for(var i in e){var n=e[i];n.configurable=!0,n.value&&(n.writable=!0)}Object.defineProperties(t,e)}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),i=function l(t,e,i){var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var o=Object.getPrototypeOf(t);return null===o?void 0:l(o,e,i)}if("value"in n&&n.writable)return n.value;var r=n.get;if(void 0!==r)return r.call(i)},n=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(t.__proto__=e)},o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},r=t(require("http")),s=require("websocket").server,a=t(require("./entity")),u=t(require("./audio-entity")),c=t(require("events")),d=function(t){function c(){o(this,c),i(Object.getPrototypeOf(c.prototype),"constructor",this).call(this),this.port=12476,this.cameras=[],this.entities=[],this.audioEntities=[],this.visualState={cameras:this.cameras,entities:this.entities},this.audioState={entities:this.audioEntities},this.connectionHandlers={"/visual_awareness":this.onVisualAwareness.bind(this),"/audible_awareness":this.onAudibleAwareness.bind(this)},this.httpHandlers={"/photo":this.onPhoto.bind(this),"/barcode":this.onBarcode.bind(this)},setInterval(this.update.bind(this),100)}return n(c,t),e(c,{init:{value:function(t){var e=this;this.httpServer=r.createServer(),this.httpServer.on("listening",function(){e.wsServer=new s({httpServer:e.httpServer,autoAcceptConnections:!1}),e.wsServer.on("request",function(t){var i=t.accept(null,t.origin);e.connectionHandlers[t.resource]?e.connectionHandlers[t.resource](i):console.warn("No simulator handler found for",t.resource)}),t()}),this.httpServer.on("request",function(t,i){"POST"===t.method&&(e.httpHandlers[t.url]?e.httpHandlers[t.url](t,i):(i.writeHead(200,{"Content-Type":"text/plain"}),i.end()))}),this.httpServer.listen(this.port)}},onPhoto:{value:function(t,e){e.writeHead(404,{"Content-Type":"text/plain"}),e.end()}},onBarcode:{value:function(t,e){e.writeHead(200,{"Content-Type":"text/plain"}),e.end()}},onVisualAwareness:{value:function(t){this.visualSocket=t}},onAudibleAwareness:{value:function(t){this.audibleSocket=t}},updateTrackingState:{value:function(t){this.visualState=t}},getAudioEntityFromId:{value:function(t){var e=void 0;return this.audioEntities.forEach(function(i){i.id==t&&(e=i)}),e}},getVisualEntityFromId:{value:function(t){var e=void 0;return this.entities.forEach(function(i){i.id==t&&(e=i)}),e}},onAudio:{value:function(t){var e=this.getVisualEntityFromId(t),i=this.getAudioEntityFromId(t);if(i||(i=new u,i.updateId(t),i.updateConfidence(100),i.updatePosition(0,0,0),this.audioEntities.push(i)),e){var n=e.parts[0].value.rays[0].dir;i.updatePosition(n)}this.audioState.entities=this.audioEntities,this.update()}},setTargetId:{value:function(t,e){this.entities.forEach(function(i){i.id===t&&(i.id=e)})}},getEntities:{value:function(){return this.entities}},updateTarget:{value:function(t){var e=this.getVisualEntityFromId(t.id);e||(e=new a(t.id),this.entities.push(e)),e.updatePosition(t),this.update(),this.emit("update",t)}},addEntity:{value:function(){}},update:{value:function(){this.visualSocket&&this.visualSocket.connected&&this.visualSocket.send(JSON.stringify(this.visualState)),this.audibleSocket&&this.audibleSocket.connected&&this.audibleSocket.send(JSON.stringify(this.audioState))}}}),c}(c);module.exports=new d;