From a8fb8dc60747a264bce5224a33b79644029de05a Mon Sep 17 00:00:00 2001 From: Beate Jost Date: Thu, 25 Jul 2024 11:54:57 +0200 Subject: [PATCH] Issue #1632: improve RESTcall (integrate switch) for choosing correct url --- .../controller/connections/connections.js | 2 +- .../controller/connections/connections.ts | 38 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/OpenRobertaServer/staticResources/js/app/roberta/controller/connections/connections.js b/OpenRobertaServer/staticResources/js/app/roberta/controller/connections/connections.js index 99d054f186..b6dac9a1bb 100644 --- a/OpenRobertaServer/staticResources/js/app/roberta/controller/connections/connections.js +++ b/OpenRobertaServer/staticResources/js/app/roberta/controller/connections/connections.js @@ -1,3 +1,3 @@ -var __extends=this&&this.__extends||function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),__awaiter=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,o=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]this.maxProgramSize)throw new R(null,"BLE_ERROR_PROGRAM_SIZE",y.ALERT);return this.downloadInProgress||this.oldProgram!=t?[3,3]:(n(1),[4,this.stopProgram()]);case 1:return s.sent(),[4,this.startProgram()];case 2:return[2,s.sent()];case 3:return s.trys.push([3,9,10,11]),this.downloadInProgress=!0,[4,this.stopProgram()];case 4:return s.sent(),[4,this.invalidateProgram()];case 5:return s.sent(),[4,this.transferProgramAsChunks(o,r,n)];case 6:return s.sent(),[4,this.updateProgramSize(o.size)];case 7:return s.sent(),this.oldProgram=t,[4,this.startProgram()];case 8:return s.sent(),[3,11];case 9:throw i=s.sent(),this.oldProgram="",new R(i,"BLE_ERROR_COMMUNICATION",y.ALERT);case 10:return this.downloadInProgress=!1,[7];case 11:return[2]}}))}))},e.prototype.disconnect=function(){null!=this.gattServer&&this.gattServer.disconnect(),this.gattServer=null,this.bleDevice=null},e.prototype.isConnected=function(){return null!==this.gattServer&&this.gattServer.connected},e.prototype.assertWebBleAvailability=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:if(!s.isWebBleSupported())throw new R(null,"BLE_NOT_SUPPORTED",y.ALERT);if(void 0===navigator.bluetooth)throw new R(null,"BLE_FEATURE_DISABLED",y.ALERT);return[4,navigator.bluetooth.getAvailability()];case 1:if(!t.sent())throw new R(null,"BLE_ADAPTER_DISABLED",y.ALERT);return[2]}}))}))},e.prototype.requestDevice=function(){return __awaiter(this,void 0,void 0,(function(){var t,e;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=this,[4,navigator.bluetooth.requestDevice({filters:[{services:[g.PYBRICKS_SERVICE_UUID]}],optionalServices:[g.PYBRICKS_SERVICE_UUID,g.DEVICE_INFORMATION_SERVICE_UUID,g.NORDIC_UART_SERVICE_UUID]})];case 1:return t.bleDevice=n.sent(),[3,3];case 2:throw e=n.sent(),new R(e,"BLE_NO_DEVICE_SELECTED",y.ALERT);case 3:return[2]}}))}))},e.prototype.connectToGattServer=function(){return __awaiter(this,void 0,void 0,(function(){var t,e=this;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.bleDevice.gatt.connect().then((function(t){return e.gattServer=t}))];case 1:return n.sent(),[3,3];case 2:throw t=n.sent(),new R(t,"BLE_ERROR_DEVICE_BUSY",y.ALERT);case 3:return[2]}}))}))},e.prototype.getHubCapabilities=function(){return __awaiter(this,void 0,void 0,(function(){var t,e=this;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.gattServer.getPrimaryService(g.PYBRICKS_SERVICE_UUID).then((function(t){return __awaiter(e,void 0,void 0,(function(){var e=this;return __generator(this,(function(n){switch(n.label){case 0:return[4,t.getCharacteristic(g.PYBRICKS_HUB_CAPABILITIES_CHARACTERISTIC_UUID).then((function(t){return __awaiter(e,void 0,void 0,(function(){var e;return __generator(this,(function(n){switch(n.label){case 0:return[4,t.readValue()];case 1:return e=n.sent(),this.maxWriteSize=e.getUint16(0,!0),this.maxProgramSize=e.getUint32(6,!0),[2]}}))}))}))];case 1:return n.sent(),[2]}}))}))}))];case 1:return n.sent(),[3,3];case 2:throw t=n.sent(),new R(t,"BLE_ERROR_CAPABILITIES",y.ALERT);case 3:return[2]}}))}))},e.prototype.transferProgramAsChunks=function(t,e,n){return __awaiter(this,void 0,void 0,(function(){var o,r,i;return __generator(this,(function(s){switch(s.label){case 0:o=t.size>e?e:t.size,r=0,s.label=1;case 1:return r0},e.prototype.run=function(t){r.setState(t),a.displayInformation(t,t.message,t.message,t.programName||r.getProgramName(),r.getRobot()),"ok"==t.rc?d.Msg["MENU_ROBOT_STOP_HINT_"+r.getRobotGroup().toUpperCase()]&&a.displayMessage("MENU_ROBOT_STOP_HINT_"+r.getRobotGroup().toUpperCase(),"TOAST"):r.setConnectionState("error")},e.prototype.showConnectionModal=function(){o("#buttonCancelFirmwareUpdate").css("display","inline"),o("#buttonCancelFirmwareUpdateAndRun").css("display","none"),u.showSetTokenModal(8,8)},e.prototype.stopProgram=function(){i.stopProgram((function(){}))},e}(n.AbstractConnection),I=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.portList=[],e.vendorList=[],e.productList=[],e.robotList=[],e.agentPortList='[{"Name":"none","IdVendor":"none","IdProduct":"none"}]',e}return __extends(e,t),e.prototype.init=function(){var e=this;t.prototype.init.call(this);var n=v.getSocket();null!=n&&0!=v.getIsAgent()||(n=_("ws://127.0.0.1:8991/"),v.setSocket(n),v.setIsAgent(!0),o("#menuConnect").parent().addClass("disabled"),n.on("connect_error",(function(t){v.setIsAgent(!1)})),n.on("connect",(function(){n.emit("command","log on"),v.setIsAgent(!0),window.setInterval((function(){e.portList=[],e.vendorList=[],e.productList=[],e.robotList=[],n.emit("command","list")}),3e3)})),n.on("message",(function(t){if(t.includes('"Network": false'))(i=JSON.parse(t)).Ports.forEach((function(t){r.getVendor()===t.VendorID.toLowerCase()&&(e.portList.push(t.Name),e.vendorList.push(t.VendorID),e.productList.push(t.ProductID),e.robotList.push(r.getRobotRealName()))})),v.setIsAgent(!0),n.on("connect_error",(function(t){v.setIsAgent(!1),o("#menuConnect").parent().removeClass("disabled")})),e.portList.indexOf(r.getRobotPort())<0&&(r.getRobotPort(),r.setRobotPort("")),1==e.portList.length&&u.setPort(e.portList[0]),r.updateMenuStatus(e.getPortList().length);else if(t.includes("OS")){var i=JSON.parse(t);e.system=i.OS}})),n.on("disconnect",(function(){})),n.on("error",(function(t){}))),this.listRobotStart()},e.prototype.isRobotConnected=function(){return!0},e.prototype.terminate=function(){this.listRobotStop(),this.closeConnection(),t.prototype.terminate.call(this)},e.prototype.showConnectionModal=function(){if(1==v.getIsAgent()){var e=this.getPortList(),n=this.getRobotList();o("#singleModalListInput").empty();var r=0;e.forEach((function(t){o("#singleModalListInput").append('"),r++})),u.showListModal()}else t.prototype.showConnectionModal.call(this)},e.prototype.run=function(t){o("#menuRunProg").parent().addClass("disabled"),o("#head-navi-icon-robot").addClass("busy"),r.setState(t),"ok"==t.rc?(this.uploadProgram(t.compiledCode,r.getRobotPort()),setTimeout((function(){r.setConnectionState("error")}),5e3)):r.setConnectionState("error"),a.displayInformation(t,t.message,t.message,r.getProgramName())},e.prototype.setState=function(){!0!==v.getIsAgent()&&(o("#menuConnect").parent().removeClass("disabled"),"wait"===c.robot.state?(o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").addClass("wait"),r.setRunEnabled(!0),o("#runSourceCodeEditor").removeClass("disabled")):"busy"===c.robot.state?(o("#head-navi-icon-robot").removeClass("wait"),o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").addClass("busy"),r.setRunEnabled(!1),o("#runSourceCodeEditor").addClass("disabled")):(o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").removeClass("wait"),o("#head-navi-icon-robot").addClass("error"),r.setRunEnabled(!1),o("#runSourceCodeEditor").addClass("disabled")))},e.prototype.updateMenuStatus=function(t){switch(t){case 0:v.setIsAgent(!1);break;case 1:v.setIsAgent(!0),o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").addClass("wait"),r.setRunEnabled(!0),o("#runSourceCodeEditor").removeClass("disabled"),o("#menuConnect").parent().addClass("disabled");break;default:v.setIsAgent(!0),o("#menuConnect").parent().removeClass("disabled"),""==r.getRobotPort()?(o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").removeClass("wait"),r.setRunEnabled(!1)):(o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").addClass("wait"),r.setRunEnabled(!0),o("#runSourceCodeEditor").removeClass("disabled"))}},e.prototype.makeRequest=function(){var t=this;this.portList=[],this.vendorList=[],this.productList=[],this.robotList=[],m.listRobotsFromAgent((function(t){}),(function(e){t.agentPortList=e.responseText}),(function(){}));try{JSON.parse(this.agentPortList).forEach((function(e){r.getVendor()===e.IdVendor.toLowerCase()&&(t.portList.push(e.Name),t.vendorList.push(e.IdVendor),t.productList.push(e.IdProduct),t.robotList.push(r.getRobotRealName()))}))}catch(t){r.setRobotPort("")}this.portList.indexOf(r.getRobotPort())<0&&r.setRobotPort(""),1==this.portList.length&&u.setPort(this.portList[0]),r.updateMenuStatus(this.getPortList().length)},e.prototype.listRobotStart=function(){var t=this;o("#menuConnect").parent().addClass("disabled"),this.makeRequest(),this.timerId=window.setInterval((function(){t.makeRequest()}),3e3)},e.prototype.listRobotStop=function(){o("#menuConnect").parent().addClass("disabled"),window.clearInterval(this.timerId)},e.prototype.closeConnection=function(){var t=v.getSocket();null!=t&&(t.disconnect(),v.setSocket(null))},e.prototype.getPortList=function(){return this.portList},e.prototype.getRobotList=function(){return this.robotList},e.prototype.uploadProgram=function(t,e){m.sendProgramHexToAgent(t,e,r.getProgramName(),r.getSignature(),r.getCommandLine(),(function(){b.text("Create agent upload success"),o("#menuRunProg").parent().removeClass("disabled"),o("#runOnBrick").parent().removeClass("disabled")}))},e}(E),A=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){this.reset=!1,o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").removeClass("wait"),r.setRunEnabled(!1),o("#menuConnect").parent().removeClass("disabled"),r.inWebview()?o("#robotConnect").removeClass("disabled"):o("#robotConnect").addClass("disabled"),o("#runSourceCodeEditor").addClass("disabled"),r.setPingTime(r.LONG)},e.prototype.isRobotConnected=function(){return f.isRobotConnected()},e.prototype.run=function(t){if(a.displayInformation(t,t.message,t.message,r.getProgramName()),"ok"===t.rc){var e=t.compiledCode,n=JSON.parse(e);if(this.interpreter=f.getInterpreter(n),null!==this.interpreter){r.setConnectionState("busy"),r.getBlocklyWorkspace().robControls.switchToStop();try{this.runStepInterpreter()}catch(t){this.interpreter.terminate(),this.interpreter=null,alert(t)}}}},e.prototype.runStepInterpreter=function(){if(!this.interpreter.isTerminated()&&!this.reset){var t=(new Date).getTime()+100,e=Math.max(100,this.interpreter.run(t));this.timeout(this.runStepInterpreter,e)}},e.prototype.timeout=function(t,e){e>100?(e-=100,setTimeout(this.timeout,100,(function(){t()}),e)):setTimeout((function(){t()}),e)},e.prototype.setState=function(){},e.prototype.stopProgram=function(){null!==this.interpreter&&this.interpreter.terminate()},e.prototype.showConnectionModal=function(){u.showScanModal()},e}(n.AbstractConnection),T=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),this.shortFormForDownloadPopup="MINI"},e}(P),N=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(I);e.Bob3Connection=N;var O=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(I);e.BotnrollConnection=O;var D=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.FestobionicflowerConnection=D;var M=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.FestobionicConnection=M;var U=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.MbotConnection=U;var L=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.MegaConnection=L;var x=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.NanoConnection=x;var k=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Nano33bleConnection=k;var B=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(I);e.Rob3rtaConnection=B;var W=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),o("#robotWlan").removeClass("hidden")},e.prototype.terminate=function(){t.prototype.terminate.call(this),o("#robotWlan").addClass("hidden")},e}(P);e.SenseboxConnection=W;var F=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.UnoConnection=F;var V=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Unowifirev2Connection=V;var G=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Mbot2Connection=G;var H=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.run=function(t){if("ok"!==t.rc)r.setConnectionState("wait"),a.displayInformation(t,t.message,t.message,r.getProgramName(),r.getRobot());else{var n=e.API_URL+e.API_LONG;(s.isChromeOS()||s.isWindowsOS())&&(n=e.API_URL+e.API_SHORT),o("#changedDownloadFolder").addClass("hidden"),o("#OKButtonModalFooter").addClass("hidden");var c,u=o("#popupDownloadHeader").text();o("#popupDownloadHeader").text(u.replace("$",r.getRobotRealName().trim()));for(var l=1;d.Msg["POPUP_DOWNLOAD_STEP_"+l];l++){var p=o('
  • '),h=d.Msg["POPUP_DOWNLOAD_STEP_"+l+"_"+r.getRobotGroup().toUpperCase()]||d.Msg["POPUP_DOWNLOAD_STEP_"+l]||"POPUP_DOWNLOAD_STEP_"+l;p.html(''+h+""),o("#download-instructions").append(p)}o("#save-client-compiled-program").oneWrap("hidden.bs.modal",(function(t){r.setConnectionState("wait"),c&&!window.msCrypto&&(c.pause(),c.load()),f.clearDownloadModal()})),o("body>.pace").fadeIn();var f=this,m=function(t){r.setConnectionState("wait"),f.clearDownloadModal(),o("body>.pace").fadeOut(400,(function(){a.displayPopupMessage("ORA_PROGRAM_SAVE_AS_ERROR_PROGRAM_EXISTS",t,"OK")}))};i.externAPIRequest(n,t.compiledCode,(function(t){try{if("true"==t.compile){var e=t.wav;c=new Audio(e),f.createPlayButton(c),o("body>.pace").fadeOut(400,(function(){o("#save-client-compiled-program").modal("show")}))}else m("Compiler Error:
    "+t.message)}catch(t){m("API "+n+" usage error")}}),(function(t){m("Compiler "+n+" not available, please try it again later!")}))}},e.prototype.createPlayButton=function(t){var e;if("Blob"in window){(e=document.createElement("button")).setAttribute("type","button"),e.setAttribute("class","btn btn-primary");var n=!1;e.onclick=function(){0==n?(t.play(),r.setAttribute("class","typcn typcn-media-stop"),n=!0,t.addEventListener("ended",(function(){o("#save-client-compiled-program").modal("hide")}))):(r.setAttribute("class","typcn typcn-media-play"),t.pause(),t.load(),n=!1)};var r=document.createElement("span");r.setAttribute("class","typcn typcn-media-play"),r.setAttribute("style","color : #333333"),e.appendChild(r)}if(e){var i=document.createElement("div");i.setAttribute("id","programLink"),i.setAttribute("style","text-align: center;"),i.appendChild(document.createElement("br")),i.appendChild(e),e.setAttribute("style","font-size:36px"),o(i).appendTo("#downloadLink")}},e.prototype.setState=function(){},e.prototype.terminate=function(){t.prototype.terminate.call(this),this.clearDownloadModal()},e.API_URL="https://api.edisonrobotics.net/",e.API_LONG="ep/wav/long",e.API_SHORT="ep/wav/short",e}(n.AbstractPromptConnection);e.EdisonConnection=H;var K=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(P);e.Ev3c4ev3Connection=K;var Y=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Ev3devConnection=Y;var z=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Ev3lejosv0Connection=z;var j=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Ev3lejosv1Connection=j;var q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.XNNConnection=q;var J=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(T);e.Calliope2016Connection=J;var Z=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(T);e.Calliope2017Connection=Z;var $=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(T);e.Calliope2017NoBlueConnection=$;var X=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(P);e.JoycarConnection=X;var Q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(P);e.MicrobitConnection=Q;var tt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(P);e.Microbitv2Connection=tt;var et=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(P);e.Calliopev3Connection=et;var nt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.NaoConnection=nt;var ot=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.NxtConnection=ot;var rt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),o("#robotWlan").removeClass("hidden"),c.gui.blocklyWorkspace&&c.gui.blocklyWorkspace.robControls.showStopProgram()},e.prototype.terminate=function(){t.prototype.terminate.call(this),o("#robotWlan").addClass("hidden"),c.gui.blocklyWorkspace&&c.gui.blocklyWorkspace.robControls.hideStopProgram()},e}(E);e.RobotinoConnection=rt;var it=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),o("#robotWlan").removeClass("hidden")},e.prototype.terminate=function(){t.prototype.terminate.call(this),o("#robotWlan").addClass("hidden")},e}(E);e.RobotinoROSConnection=it;var st=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(S);e.SpikePybricksConnection=st;var at=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.SpikeConnection=at;var ct=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.showConnectionModal=function(){o("#buttonCancelFirmwareUpdate").css("display","inline"),o("#buttonCancelFirmwareUpdateAndRun").css("display","none"),u.showSetTokenModal(6,8)},e.prototype.init=function(){t.prototype.init.call(this),r.getBlocklyWorkspace().robControls.showStopProgram(),o("#stopProgram").addClass("disabled")},e.prototype.terminate=function(){t.prototype.terminate.call(this),o("#stopProgram").addClass("disabled"),r.getBlocklyWorkspace().robControls.hideStopProgram(),r.setRobotToken("")},e}(E);e.Txt4Connection=ct;var ut=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(w);e.ThymioConnection=ut;var lt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(A);e.WedoConnection=lt;var dt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){r.setConnectionState("wait"),o("#runSourceCodeEditor").removeClass("disabled"),o("#menuConnect").parent().addClass("disabled"),r.setPing(!1)},e.prototype.isRobotConnected=function(){return!0},e.prototype.run=function(t){var e=(t.programName||r.getProgramName())+"."+r.getBinaryFileExtension();"bin"!==r.getBinaryFileExtension()&&"uf2"!==r.getBinaryFileExtension()||(t.compiledCode=s.base64decode(t.compiledCode)),s.download(e,t.compiledCode),setTimeout((function(){r.setConnectionState("wait")}),5e3),a.displayInformation(t,t.message,t.message,r.getProgramName(),r.getRobot())},e.prototype.setState=function(){},e}(n.AbstractConnection);e.LocalConnection=dt})); +var __extends=this&&this.__extends||function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),__awaiter=this&&this.__awaiter||function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,o=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]this.maxProgramSize)throw new R(null,"BLE_ERROR_PROGRAM_SIZE",y.ALERT);return this.downloadInProgress||this.oldProgram!=t?[3,3]:(n(1),[4,this.stopProgram()]);case 1:return s.sent(),[4,this.startProgram()];case 2:return[2,s.sent()];case 3:return s.trys.push([3,9,10,11]),this.downloadInProgress=!0,[4,this.stopProgram()];case 4:return s.sent(),[4,this.invalidateProgram()];case 5:return s.sent(),[4,this.transferProgramAsChunks(o,r,n)];case 6:return s.sent(),[4,this.updateProgramSize(o.size)];case 7:return s.sent(),this.oldProgram=t,[4,this.startProgram()];case 8:return s.sent(),[3,11];case 9:throw i=s.sent(),this.oldProgram="",new R(i,"BLE_ERROR_COMMUNICATION",y.ALERT);case 10:return this.downloadInProgress=!1,[7];case 11:return[2]}}))}))},e.prototype.disconnect=function(){null!=this.gattServer&&this.gattServer.disconnect(),this.gattServer=null,this.bleDevice=null},e.prototype.isConnected=function(){return null!==this.gattServer&&this.gattServer.connected},e.prototype.assertWebBleAvailability=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:if(!s.isWebBleSupported())throw new R(null,"BLE_NOT_SUPPORTED",y.ALERT);if(void 0===navigator.bluetooth)throw new R(null,"BLE_FEATURE_DISABLED",y.ALERT);return[4,navigator.bluetooth.getAvailability()];case 1:if(!t.sent())throw new R(null,"BLE_ADAPTER_DISABLED",y.ALERT);return[2]}}))}))},e.prototype.requestDevice=function(){return __awaiter(this,void 0,void 0,(function(){var t,e;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=this,[4,navigator.bluetooth.requestDevice({filters:[{services:[v.PYBRICKS_SERVICE_UUID]}],optionalServices:[v.PYBRICKS_SERVICE_UUID,v.DEVICE_INFORMATION_SERVICE_UUID,v.NORDIC_UART_SERVICE_UUID]})];case 1:return t.bleDevice=n.sent(),[3,3];case 2:throw e=n.sent(),new R(e,"BLE_NO_DEVICE_SELECTED",y.ALERT);case 3:return[2]}}))}))},e.prototype.connectToGattServer=function(){return __awaiter(this,void 0,void 0,(function(){var t,e=this;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.bleDevice.gatt.connect().then((function(t){return e.gattServer=t}))];case 1:return n.sent(),[3,3];case 2:throw t=n.sent(),new R(t,"BLE_ERROR_DEVICE_BUSY",y.ALERT);case 3:return[2]}}))}))},e.prototype.getHubCapabilities=function(){return __awaiter(this,void 0,void 0,(function(){var t,e=this;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.gattServer.getPrimaryService(v.PYBRICKS_SERVICE_UUID).then((function(t){return __awaiter(e,void 0,void 0,(function(){var e=this;return __generator(this,(function(n){switch(n.label){case 0:return[4,t.getCharacteristic(v.PYBRICKS_HUB_CAPABILITIES_CHARACTERISTIC_UUID).then((function(t){return __awaiter(e,void 0,void 0,(function(){var e;return __generator(this,(function(n){switch(n.label){case 0:return[4,t.readValue()];case 1:return e=n.sent(),this.maxWriteSize=e.getUint16(0,!0),this.maxProgramSize=e.getUint32(6,!0),[2]}}))}))}))];case 1:return n.sent(),[2]}}))}))}))];case 1:return n.sent(),[3,3];case 2:throw t=n.sent(),new R(t,"BLE_ERROR_CAPABILITIES",y.ALERT);case 3:return[2]}}))}))},e.prototype.transferProgramAsChunks=function(t,e,n){return __awaiter(this,void 0,void 0,(function(){var o,r,i;return __generator(this,(function(s){switch(s.label){case 0:o=t.size>e?e:t.size,r=0,s.label=1;case 1:return r0},e.prototype.run=function(t){r.setState(t),a.displayInformation(t,t.message,t.message,t.programName||r.getProgramName(),r.getRobot()),"ok"==t.rc?d.Msg["MENU_ROBOT_STOP_HINT_"+r.getRobotGroup().toUpperCase()]&&a.displayMessage("MENU_ROBOT_STOP_HINT_"+r.getRobotGroup().toUpperCase(),"TOAST"):r.setConnectionState("error")},e.prototype.showConnectionModal=function(){o("#buttonCancelFirmwareUpdate").css("display","inline"),o("#buttonCancelFirmwareUpdateAndRun").css("display","none"),u.showSetTokenModal(8,8)},e.prototype.stopProgram=function(){i.stopProgram((function(){}))},e}(n.AbstractConnection),I=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.portList=[],e.vendorList=[],e.productList=[],e.robotList=[],e.agentPortList='[{"Name":"none","IdVendor":"none","IdProduct":"none"}]',e}return __extends(e,t),e.prototype.init=function(){var e=this;t.prototype.init.call(this);var n=g.getSocket();null!=n&&0!=g.getIsAgent()||(n=_("ws://127.0.0.1:8991/"),g.setSocket(n),g.setIsAgent(!0),o("#menuConnect").parent().addClass("disabled"),n.on("connect_error",(function(t){g.setIsAgent(!1)})),n.on("connect",(function(){n.emit("command","log on"),g.setIsAgent(!0),window.setInterval((function(){e.portList=[],e.vendorList=[],e.productList=[],e.robotList=[],n.emit("command","list")}),3e3)})),n.on("message",(function(t){if(t.includes('"Network": false'))(i=JSON.parse(t)).Ports.forEach((function(t){r.getVendor()===t.VendorID.toLowerCase()&&(e.portList.push(t.Name),e.vendorList.push(t.VendorID),e.productList.push(t.ProductID),e.robotList.push(r.getRobotRealName()))})),g.setIsAgent(!0),n.on("connect_error",(function(t){g.setIsAgent(!1),o("#menuConnect").parent().removeClass("disabled")})),e.portList.indexOf(r.getRobotPort())<0&&(r.getRobotPort(),r.setRobotPort("")),1==e.portList.length&&u.setPort(e.portList[0]),r.updateMenuStatus(e.getPortList().length);else if(t.includes("OS")){var i=JSON.parse(t);e.system=i.OS}})),n.on("disconnect",(function(){})),n.on("error",(function(t){}))),this.listRobotStart()},e.prototype.isRobotConnected=function(){return!0},e.prototype.terminate=function(){this.listRobotStop(),this.closeConnection(),t.prototype.terminate.call(this)},e.prototype.showConnectionModal=function(){if(1==g.getIsAgent()){var e=this.getPortList(),n=this.getRobotList();o("#singleModalListInput").empty();var r=0;e.forEach((function(t){o("#singleModalListInput").append('"),r++})),u.showListModal()}else t.prototype.showConnectionModal.call(this)},e.prototype.run=function(t){o("#menuRunProg").parent().addClass("disabled"),o("#head-navi-icon-robot").addClass("busy"),r.setState(t),"ok"==t.rc?(this.uploadProgram(t.compiledCode,r.getRobotPort()),setTimeout((function(){r.setConnectionState("error")}),5e3)):r.setConnectionState("error"),a.displayInformation(t,t.message,t.message,r.getProgramName())},e.prototype.setState=function(){!0!==g.getIsAgent()&&(o("#menuConnect").parent().removeClass("disabled"),"wait"===c.robot.state?(o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").addClass("wait"),r.setRunEnabled(!0),o("#runSourceCodeEditor").removeClass("disabled")):"busy"===c.robot.state?(o("#head-navi-icon-robot").removeClass("wait"),o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").addClass("busy"),r.setRunEnabled(!1),o("#runSourceCodeEditor").addClass("disabled")):(o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").removeClass("wait"),o("#head-navi-icon-robot").addClass("error"),r.setRunEnabled(!1),o("#runSourceCodeEditor").addClass("disabled")))},e.prototype.updateMenuStatus=function(t){switch(t){case 0:g.setIsAgent(!1);break;case 1:g.setIsAgent(!0),o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").addClass("wait"),r.setRunEnabled(!0),o("#runSourceCodeEditor").removeClass("disabled"),o("#menuConnect").parent().addClass("disabled");break;default:g.setIsAgent(!0),o("#menuConnect").parent().removeClass("disabled"),""==r.getRobotPort()?(o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").removeClass("wait"),r.setRunEnabled(!1)):(o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").addClass("wait"),r.setRunEnabled(!0),o("#runSourceCodeEditor").removeClass("disabled"))}},e.prototype.makeRequest=function(){var t=this;this.portList=[],this.vendorList=[],this.productList=[],this.robotList=[],m.listRobotsFromAgent((function(t){}),(function(e){t.agentPortList=e.responseText}),(function(){}));try{JSON.parse(this.agentPortList).forEach((function(e){r.getVendor()===e.IdVendor.toLowerCase()&&(t.portList.push(e.Name),t.vendorList.push(e.IdVendor),t.productList.push(e.IdProduct),t.robotList.push(r.getRobotRealName()))}))}catch(t){r.setRobotPort("")}this.portList.indexOf(r.getRobotPort())<0&&r.setRobotPort(""),1==this.portList.length&&u.setPort(this.portList[0]),r.updateMenuStatus(this.getPortList().length)},e.prototype.listRobotStart=function(){var t=this;o("#menuConnect").parent().addClass("disabled"),this.makeRequest(),this.timerId=window.setInterval((function(){t.makeRequest()}),3e3)},e.prototype.listRobotStop=function(){o("#menuConnect").parent().addClass("disabled"),window.clearInterval(this.timerId)},e.prototype.closeConnection=function(){var t=g.getSocket();null!=t&&(t.disconnect(),g.setSocket(null))},e.prototype.getPortList=function(){return this.portList},e.prototype.getRobotList=function(){return this.robotList},e.prototype.uploadProgram=function(t,e){m.sendProgramHexToAgent(t,e,r.getProgramName(),r.getSignature(),r.getCommandLine(),(function(){b.text("Create agent upload success"),o("#menuRunProg").parent().removeClass("disabled"),o("#runOnBrick").parent().removeClass("disabled")}))},e}(E),A=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){this.reset=!1,o("#head-navi-icon-robot").removeClass("error"),o("#head-navi-icon-robot").removeClass("busy"),o("#head-navi-icon-robot").removeClass("wait"),r.setRunEnabled(!1),o("#menuConnect").parent().removeClass("disabled"),r.inWebview()?o("#robotConnect").removeClass("disabled"):o("#robotConnect").addClass("disabled"),o("#runSourceCodeEditor").addClass("disabled"),r.setPingTime(r.LONG)},e.prototype.isRobotConnected=function(){return f.isRobotConnected()},e.prototype.run=function(t){if(a.displayInformation(t,t.message,t.message,r.getProgramName()),"ok"===t.rc){var e=t.compiledCode,n=JSON.parse(e);if(this.interpreter=f.getInterpreter(n),null!==this.interpreter){r.setConnectionState("busy"),r.getBlocklyWorkspace().robControls.switchToStop();try{this.runStepInterpreter()}catch(t){this.interpreter.terminate(),this.interpreter=null,alert(t)}}}},e.prototype.runStepInterpreter=function(){if(!this.interpreter.isTerminated()&&!this.reset){var t=(new Date).getTime()+100,e=Math.max(100,this.interpreter.run(t));this.timeout(this.runStepInterpreter,e)}},e.prototype.timeout=function(t,e){e>100?(e-=100,setTimeout(this.timeout,100,(function(){t()}),e)):setTimeout((function(){t()}),e)},e.prototype.setState=function(){},e.prototype.stopProgram=function(){null!==this.interpreter&&this.interpreter.terminate()},e.prototype.showConnectionModal=function(){u.showScanModal()},e}(n.AbstractConnection),T=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),this.shortFormForDownloadPopup="MINI"},e}(S),N=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(I);e.Bob3Connection=N;var O=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(I);e.BotnrollConnection=O;var D=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.FestobionicflowerConnection=D;var M=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.FestobionicConnection=M;var U=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.MbotConnection=U;var L=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.MegaConnection=L;var x=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.NanoConnection=x;var k=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Nano33bleConnection=k;var B=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(I);e.Rob3rtaConnection=B;var W=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),o("#robotWlan").removeClass("hidden")},e.prototype.terminate=function(){t.prototype.terminate.call(this),o("#robotWlan").addClass("hidden")},e}(S);e.SenseboxConnection=W;var F=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.UnoConnection=F;var V=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Unowifirev2Connection=V;var G=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Mbot2Connection=G;var H=function(t){function e(){var n=null!==t&&t.apply(this,arguments)||this;return n.switchedOnce=!1,n.shortLong="long",n.urlAPI=e.API_URL+e.API_LONG,n}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),(s.isChromeOS()||s.isWindowsOS())&&(this.urlAPI=e.API_URL+e.API_SHORT,this.shortLong="short")},e.prototype.run=function(t){if("ok"!==t.rc)r.setConnectionState("wait"),a.displayInformation(t,t.message,t.message,r.getProgramName(),r.getRobot());else{o("#changedDownloadFolder").addClass("hidden"),o("#OKButtonModalFooter").addClass("hidden");var n,s=o("#popupDownloadHeader").text();o("#popupDownloadHeader").text(s.replace("$",r.getRobotRealName().trim()));for(var c=1;d.Msg["POPUP_DOWNLOAD_STEP_"+c];c++){var u=o('
  • '),l=d.Msg["POPUP_DOWNLOAD_STEP_"+c+"_"+r.getRobotGroup().toUpperCase()]||d.Msg["POPUP_DOWNLOAD_STEP_"+c]||"POPUP_DOWNLOAD_STEP_"+c;u.html(''+l+""),o("#download-instructions").append(u)}o("#save-client-compiled-program").oneWrap("hidden.bs.modal",(function(t){r.setConnectionState("wait"),n&&!window.msCrypto&&(n.pause(),n.load()),p.clearDownloadModal()})),o("body>.pace").fadeIn();var p=this,h=function(t){r.setConnectionState("wait"),p.clearDownloadModal(),o("body>.pace").fadeOut(400,(function(){a.displayPopupMessage("ORA_PROGRAM_SAVE_AS_ERROR_PROGRAM_EXISTS",t,"OK")}))},f=function(r){try{if("true"==r.compile){var s=r.wav;n=new Audio(s),p.createPlayButton(n),o("body>.pace").fadeOut(400,(function(){o("#save-client-compiled-program").modal("show")}))}else{r.message.toLowerCase().indexOf("permission denied")>=0&&!p.switchedOnce?(p.switchedOnce=!0,"long"===p.shortLong?p.urlAPI=e.API_URL+e.API_SHORT:p.urlAPI=e.API_URL+e.API_LONG,i.externAPIRequest(p.urlAPI,t.compiledCode,f,m)):h("Compiler Error:
    "+r.message)}}catch(t){h("API "+p.urlAPI+" usage error")}},m=function(t){h("Compiler "+p.urlAPI+" not available, please try it again later!")};i.externAPIRequest(this.urlAPI,t.compiledCode,f,m)}},e.prototype.createPlayButton=function(t){var e;if("Blob"in window){(e=document.createElement("button")).setAttribute("type","button"),e.setAttribute("class","btn btn-primary");var n=!1;e.onclick=function(){0==n?(t.play(),r.setAttribute("class","typcn typcn-media-stop"),n=!0,t.addEventListener("ended",(function(){o("#save-client-compiled-program").modal("hide")}))):(r.setAttribute("class","typcn typcn-media-play"),t.pause(),t.load(),n=!1)};var r=document.createElement("span");r.setAttribute("class","typcn typcn-media-play"),r.setAttribute("style","color : #333333"),e.appendChild(r)}if(e){var i=document.createElement("div");i.setAttribute("id","programLink"),i.setAttribute("style","text-align: center;"),i.appendChild(document.createElement("br")),i.appendChild(e),e.setAttribute("style","font-size:36px"),o(i).appendTo("#downloadLink")}},e.prototype.setState=function(){},e.prototype.terminate=function(){t.prototype.terminate.call(this),this.clearDownloadModal()},e.API_URL="https://api.edisonrobotics.net/",e.API_LONG="ep/wav/long",e.API_SHORT="ep/wav/short",e}(n.AbstractPromptConnection);e.EdisonConnection=H;var K=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(S);e.Ev3c4ev3Connection=K;var Y=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Ev3devConnection=Y;var z=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Ev3lejosv0Connection=z;var q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.Ev3lejosv1Connection=q;var j=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.XNNConnection=j;var J=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(T);e.Calliope2016Connection=J;var Z=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(T);e.Calliope2017Connection=Z;var $=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(T);e.Calliope2017NoBlueConnection=$;var X=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(S);e.JoycarConnection=X;var Q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(S);e.MicrobitConnection=Q;var tt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(S);e.Microbitv2Connection=tt;var et=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(S);e.Calliopev3Connection=et;var nt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.NaoConnection=nt;var ot=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.NxtConnection=ot;var rt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),o("#robotWlan").removeClass("hidden"),c.gui.blocklyWorkspace&&c.gui.blocklyWorkspace.robControls.showStopProgram()},e.prototype.terminate=function(){t.prototype.terminate.call(this),o("#robotWlan").addClass("hidden"),c.gui.blocklyWorkspace&&c.gui.blocklyWorkspace.robControls.hideStopProgram()},e}(E);e.RobotinoConnection=rt;var it=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){t.prototype.init.call(this),o("#robotWlan").removeClass("hidden")},e.prototype.terminate=function(){t.prototype.terminate.call(this),o("#robotWlan").addClass("hidden")},e}(E);e.RobotinoROSConnection=it;var st=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(P);e.SpikePybricksConnection=st;var at=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(E);e.SpikeConnection=at;var ct=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.showConnectionModal=function(){o("#buttonCancelFirmwareUpdate").css("display","inline"),o("#buttonCancelFirmwareUpdateAndRun").css("display","none"),u.showSetTokenModal(6,8)},e.prototype.init=function(){t.prototype.init.call(this),r.getBlocklyWorkspace().robControls.showStopProgram(),o("#stopProgram").addClass("disabled")},e.prototype.terminate=function(){t.prototype.terminate.call(this),o("#stopProgram").addClass("disabled"),r.getBlocklyWorkspace().robControls.hideStopProgram(),r.setRobotToken("")},e}(E);e.Txt4Connection=ct;var ut=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(w);e.ThymioConnection=ut;var lt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(A);e.WedoConnection=lt;var dt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.init=function(){r.setConnectionState("wait"),o("#runSourceCodeEditor").removeClass("disabled"),o("#menuConnect").parent().addClass("disabled"),r.setPing(!1)},e.prototype.isRobotConnected=function(){return!0},e.prototype.run=function(t){var e=(t.programName||r.getProgramName())+"."+r.getBinaryFileExtension();"bin"!==r.getBinaryFileExtension()&&"uf2"!==r.getBinaryFileExtension()||(t.compiledCode=s.base64decode(t.compiledCode)),s.download(e,t.compiledCode),setTimeout((function(){r.setConnectionState("wait")}),5e3),a.displayInformation(t,t.message,t.message,r.getProgramName(),r.getRobot())},e.prototype.setState=function(){},e}(n.AbstractConnection);e.LocalConnection=dt})); //# sourceMappingURL=connections.js.map //# sourceMappingURL=connections.js.map diff --git a/OpenRobertaWeb/src/app/roberta/controller/connections/connections.ts b/OpenRobertaWeb/src/app/roberta/controller/connections/connections.ts index 73142eab8d..9101c4a74d 100644 --- a/OpenRobertaWeb/src/app/roberta/controller/connections/connections.ts +++ b/OpenRobertaWeb/src/app/roberta/controller/connections/connections.ts @@ -1277,6 +1277,17 @@ export class EdisonConnection extends AbstractPromptConnection { private static API_URL: string = 'https://api.edisonrobotics.net/'; private static API_LONG: string = 'ep/wav/long'; private static API_SHORT: string = 'ep/wav/short'; + private switchedOnce: boolean = false; + private shortLong: String = 'long'; + private urlAPI: string = EdisonConnection.API_URL + EdisonConnection.API_LONG; + + override init() { + super.init(); + if (UTIL.isChromeOS() || UTIL.isWindowsOS()) { + this.urlAPI = EdisonConnection.API_URL + EdisonConnection.API_SHORT; + this.shortLong = 'short'; + } + } /** * Creates the pop-up for robots that play sound inside the browser instead @@ -1296,21 +1307,17 @@ export class EdisonConnection extends AbstractPromptConnection { GUISTATE_C.setConnectionState('wait'); MSG.displayInformation(result, result.message, result.message, GUISTATE_C.getProgramName(), GUISTATE_C.getRobot()); } else { - let urlAPI = EdisonConnection.API_URL + EdisonConnection.API_LONG; - if (UTIL.isChromeOS() || UTIL.isWindowsOS()) { - urlAPI = EdisonConnection.API_URL + EdisonConnection.API_SHORT; - } $('#changedDownloadFolder').addClass('hidden'); $('#OKButtonModalFooter').addClass('hidden'); let textH = $('#popupDownloadHeader').text(); $('#popupDownloadHeader').text(textH.replace('$', GUISTATE_C.getRobotRealName().trim())); for (let i = 1; Blockly.Msg['POPUP_DOWNLOAD_STEP_' + i]; i++) { let step = $('
  • '); - let a = + let text = Blockly.Msg['POPUP_DOWNLOAD_STEP_' + i + '_' + GUISTATE_C.getRobotGroup().toUpperCase()] || Blockly.Msg['POPUP_DOWNLOAD_STEP_' + i] || 'POPUP_DOWNLOAD_STEP_' + i; - step.html('' + a + ''); + step.html('' + text + ''); $('#download-instructions').append(step); } $('#save-client-compiled-program').oneWrap('hidden.bs.modal', function (e) { @@ -1344,16 +1351,27 @@ export class EdisonConnection extends AbstractPromptConnection { $('#save-client-compiled-program').modal('show'); }); } else { - handleError('Compiler Error:
    ' + response.message); + let permissionDenied = response.message.toLowerCase().indexOf('permission denied') >= 0; + if (permissionDenied && !that.switchedOnce) { + that.switchedOnce = true; + if (that.shortLong === 'long') { + that.urlAPI = EdisonConnection.API_URL + EdisonConnection.API_SHORT; + } else { + that.urlAPI = EdisonConnection.API_URL + EdisonConnection.API_LONG; + } + PROGRAM.externAPIRequest(that.urlAPI, result.compiledCode, onload, onerror); + } else { + handleError('Compiler Error:
    ' + response.message); + } } } catch (error) { - handleError('API ' + urlAPI + ' usage error'); + handleError('API ' + that.urlAPI + ' usage error'); } }; const onerror = function (e) { - handleError('Compiler ' + urlAPI + ' not available, please try it again later!'); + handleError('Compiler ' + that.urlAPI + ' not available, please try it again later!'); }; - PROGRAM.externAPIRequest(urlAPI, result.compiledCode, onload, onerror); + PROGRAM.externAPIRequest(this.urlAPI, result.compiledCode, onload, onerror); } }