@transitive-sdk/utils-web 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils-web.js +1 -1
- package/hooks.jsx +23 -5
- package/package.json +1 -1
package/dist/utils-web.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e={720:(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}function c(e,t){return function(e,t){return t.get?t.get.call(e):t.value}(e,s(e,t,"get"))}function u(e,t,n){return function(e,t,n){if(t.set)t.set.call(e,n);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=n}}(e,s(e,t,"set"),n),n}function s(e,t,n){if(!t.has(e))throw new TypeError("attempted to "+n+" private field on non-instance");return t.get(e)}var l={get:n(712),set:n(298),unset:n(305),forEach:n(848),map:n(707),isEmpty:n(699),eq:n(113),isPlainObject:n(452),merge:n(831)},f=n(362),h=f.topicToPath,p=f.pathToTopic,d=f.toFlatObject,b=f.topicMatch,y=f.forMatchIterator,v=function e(t,n){if(n&&0!=n.length){l.unset(t,n);var r=n.slice(0,-1),o=0==r.length?t:l.get(t,r);return l.isEmpty(o)?e(t,r):n}},g=function e(t,n){if(0!=n.length){var r=n[0];if(r)for(var o in t)o==r||"*"==r||r.startsWith("+")?e(t[o],n.slice(1)):delete t[o]}},m=new WeakMap,w=new WeakMap,O=new WeakMap,S=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,e),a(this,m,{writable:!0,value:{}}),a(this,w,{writable:!0,value:[]}),a(this,O,{writable:!0,value:[]}),u(this,m,t)}var t,n;return t=e,n=[{key:"updateFromArray",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=l.get(c(this,m),e);if(null==t){if(null==o)return{};v(c(this,m),e)}else{if(l.eq(o,t))return{};l.set(c(this,m),e,t)}var i,a=p(e),u=r({},a,t);if(t instanceof Object){var s=d(t);i={},l.forEach(s,(function(e,t){i["".concat(a).concat(t)]=e}))}else i=u;return c(this,w).forEach((function(e){return e(u,n)})),c(this,O).forEach((function(e){return e(i,n)})),i}},{key:"update",value:function(e,t,n){if("string"==typeof e)return this.updateFromTopic(e,t,n);if(e instanceof Array)return this.updateFromArray(e,t,n);throw new Error("unrecognized path expression")}},{key:"updateFromTopic",value:function(e,t,n){return this.updateFromArray(h(e),t,n)}},{key:"updateFromModifier",value:function(e,t){var n=this;return l.map(e,(function(e,r){return n.updateFromTopic(r,e,t)}))}},{key:"subscribe",value:function(e){e instanceof Function?c(this,w).push(e):console.warn("DataCache.subscribe expects a function as argument. Did you mean to use subscribePath?")}},{key:"subscribePath",value:function(e,t){c(this,w).push((function(n,r){l.forEach(n,(function(n,o){var i=b(e,o);i&&t(n,o,i,r)}))}))}},{key:"subscribePathFlat",value:function(e,t){c(this,O).push((function(n,r){l.forEach(n,(function(n,o){var i=b(e,o);i&&t(n,o,i,r)}))}))}},{key:"unsubscribe",value:function(e){u(this,w,c(this,w).filter((function(t){return t!=e})))}},{key:"get",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return 0==e.length?c(this,m):l.get(c(this,m),e)}},{key:"getByTopic",value:function(e){return this.get(h(e))}},{key:"filter",value:function(e){var t=JSON.parse(JSON.stringify(this.get()));return g(t,e),t}},{key:"filterByTopic",value:function(e){return this.filter(h(e))}},{key:"forMatch",value:function(e,t){var n=h(e);this.forPathMatch(n,t)}},{key:"forPathMatch",value:function(e,t){y(this.get(),e,t)}}],n&&i(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();e.exports={DataCache:S,updateObject:function(e,t){return l.forEach(t,(function(t,n){var r=h(n);null==t?v(e,r):l.set(e,r,t)})),e}}},890:(e,t,n)=>{"use strict";function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}var c=n(362),u=c.mqttParsePayload,s=c.topicMatch,l=c.topicToPath,f=c.pathToTopic,h=c.toFlatObject,p=c.getLogger,d=c.mergeVersions,b=c.parseMQTTTopic,y=c.isSubTopicOf,v=c.versionCompare,g=c.encodeTopicElement,m=n(720).DataCache,w=n(517),O=p("MqttSync"),S="$SYS/broker/uptime",k=function(){},E=function(e){return e.endsWith("/#")?e:e.endsWith("/")?e.concat("#"):e.concat("/#")},C=function(e){return e.replace(/\/\//g,"/")},T=function(){function e(t){var n=this,r=t.mqttClient,o=t.onChange,a=t.ignoreRetain,c=t.migrate,s=t.onReady,h=t.sliceTopic;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i(this,"data",new m),i(this,"subscribedPaths",{}),i(this,"publishedPaths",{}),i(this,"publishedMessages",{}),i(this,"publishQueue",new Map),i(this,"heartbeatWaitersOnce",[]),i(this,"heartbeats",0),i(this,"beforeDisconnectHooks",[]),this.mqtt=r,this.mqtt.on("message",(function(e,t,r){var i=t&&t.toString();if(O.debug("got message",e,i.slice(0,180),i.length>180?"... (".concat(i.length," bytes)"):"",r.retain),e==S)n.heartbeats>0&&(n.heartbeatWaitersOnce.forEach((function(e){return e()})),n.heartbeatWaitersOnce=[]),1==n.heartbeats&&!c&&s&&s(),n.heartbeats++;else if(r.retain||a){O.debug("processing message",e),h&&(e=f(l(e).slice(h)));var p=u(t);if(n.isPublished(e))n.publishedMessages[e]=p,n.data.update(e,p,{external:!0});else if(n.isSubscribed(e)){O.debug("applying received update",e);var d=n.data.update(e,p);o&&Object.keys(d).length>0&&o(d)}}})),this.mqtt.subscribe(S,{rap:!0},O.debug),(null==c?void 0:c.length)>0&&this.migrate(c,(function(){O.debug("done migrating",s),s&&n.waitForHeartbeatOnce(s)}))}var t,n;return t=e,n=[{key:"publishAtLevel",value:function(e,t,n){var r=this;O.debug("publishingAtLevel ".concat(n),e,t),n>0?w.forEach(t,(function(t,o){var i="".concat(e,"/").concat(g(o));O.debug("publishing ".concat(i)),r.publishAtLevel(i,t,n-1)})):this.mqtt.publish(e,JSON.stringify(t),{retain:!0},(function(e){e&&O.warn("Error when publishing migration result",e)}))}},{key:"migrate",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=e.length;if(0!=r){var o=function(){return 0==--r&&n&&n()};e.forEach((function(e){var n=e.topic,r=e.newVersion,i=e.transform,a=void 0===i?void 0:i,c=e.flat,u=void 0!==c&&c,s=e.level,p=void 0===s?0:s;O.debug("migrating",n,r);var y=b(n),g=y.organization,m=y.device,S=y.capability,k=y.sub,E="/".concat(g,"/").concat(m,"/").concat(S),T=0==k.length?"/#":f(k),j="".concat(E,"/+").concat(T);t.subscribe(j,(function(e){if(e)return O.warn("Error during migration",e),void o();t.waitForHeartbeatOnce((function(){O.debug("got heartbeat",n,j);var e=t.data.getByTopic(E);if(!e)return t.unsubscribe(j),void o();var i=d(e,T,{maxVersion:r}),c=w.get(i,l(T)),s=a?a(c):c,b=C("".concat(E,"/").concat(r,"/").concat(T));if(O.debug("publishing merged",b),u){var y=h(s),g=l(b);w.forEach(y,(function(e,n){var r=f(g.concat(l(n)));t.mqtt.publish(r,JSON.stringify(e),{retain:!0},(function(e){e&&O.warn("Error when publishing migration result for ".concat(n),e)}))}))}else t.publishAtLevel(b,s,p);t.unsubscribe(j),t.waitForHeartbeatOnce((function(){var n=Object.keys(e).filter((function(e){return v(e,r)<0})).map((function(e){return C("".concat(E,"/").concat(e,"/").concat(T))}));O.debug({prefixesToClear:n}),t.clear(n),o()}))}))}))}))}else n&&n()}},{key:"clear",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=[],i=function(t){e.forEach((function(e){return s("".concat(e,"/#"),t)&&(!r.filter||r.filter(t))&&o.push(t)}))};this.mqtt.on("message",i),e.forEach((function(e){"string"==typeof e?t.mqtt.subscribe("".concat(e,"/#")):O.warn("Ignoring",e,"since it is not a string.")}));var a="undefined"!=typeof Buffer?Buffer.alloc(0):null;this.waitForHeartbeatOnce((function(){t.mqtt.removeListener("message",i),e.forEach((function(e){return t.mqtt.unsubscribe("".concat(e,"/#"))}));var r=o.length;O.debug("clearing ".concat(r," retained messages from ").concat(e)),o.forEach((function(e){t.mqtt.publish(e,a,{retain:!0})})),n&&n(r)}))}},{key:"waitForHeartbeatOnce",value:function(e){var t=this;setTimeout((function(){return t.heartbeatWaitersOnce.push(e)}),1)}},{key:"isSubscribed",value:function(e){return Object.keys(this.subscribedPaths).some((function(t){return s(t,e)}))}},{key:"isPublished",value:function(e){var t=this;return Object.keys(this.publishedPaths).some((function(n){return s(n,e)&&!t.publishedPaths[n].atomic}))}},{key:"subscribe",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;if(e=E(e),this.subscribedPaths[e])return O.debug("already subscribed to",e),void n();this.mqtt.subscribe(e,{rap:!0},(function(r,o){O.debug("subscribe",e,"granted:",o),o&&o.some((function(t){return t.topic==e&&t.qos<128}))?(t.subscribedPaths[e]=1,n(null)):n("not permitted to subscribe to topic ".concat(e,", ").concat(JSON.stringify(o)))}))}},{key:"unsubscribe",value:function(e){this.subscribedPaths[e]&&(this.mqtt.unsubscribe(e),delete this.subscribedPaths[e])}},{key:"_actuallyPublish",value:function(e,t){return this.mqtt.connected?(O.debug("actually publishing",e),this.mqtt.publish(e,null==t?null:JSON.stringify(t),{retain:!0}),!0):(O.warn("not connected, not publishing",e),!1)}},{key:"_processQueue_rec",value:function(e){var t=this;if(this.publishQueue.size>0){var n=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(this.publishQueue.entries().next().value,2),o=n[0],i=n[1];this._actuallyPublish(o,i)?(this.publishQueue.delete(o),this._processQueue_rec(e)):setTimeout((function(){return t._processQueue_rec(e)}),5e3)}else e()}},{key:"_processQueue",value:function(){var e=this;this._processing||(this._processing=!0,this._processQueue_rec((function(){return e._processing=!1})))}},{key:"setThrottle",value:function(e){this._processQueueThrottled=w.throttle(this._processQueue.bind(this),e)}},{key:"clearThrottle",value:function(){delete this._processQueueThrottled}},{key:"addToQueue",value:function(e,t){this.publishQueue.set(e,t)}},{key:"_enqueue",value:function(e,t){var n;O.debug("enqueuing",e),this.addToQueue(e,t),this._processQueueThrottled?this._processQueueThrottled():this._processQueue(),null==t?delete this.publishedMessages[e]:this.publishedMessages[e]="object"==a(n=t)?JSON.parse(JSON.stringify(n)):n}},{key:"publish",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{atomic:!1};return e=E(e),!w.isEqual(this.publishedPaths[e],n)&&(this.publishedPaths[e]=n,n.atomic?(this.data.subscribePath(e,(function(n,r,o,i){if(null==i||!i.external){O.debug("processing change (atomic)",r,e);var a=e.slice(0,e.length-2),c=f(l(r).slice(0,l(a).length));t._enqueue(c,t.data.getByTopic(c))}})),!0):(this.mqtt.subscribe(e),void this.data.subscribePath(e,(function(e,n,r,o){if(null==o||!o.external)return O.debug("processing change",n),w.each(t.publishedMessages,(function(e,r){if(O.trace("oldKey",r),r==n)return!0;if(y(r,n)&&t._enqueue(r,null),y(n,r)){t._enqueue(r,null);var o=h(e);w.each(o,(function(e,n){var o="".concat(r).concat(n);t._enqueue(o,e)}))}})),t._enqueue(n,e),!0}))))}},{key:"beforeDisconnect",value:function(){var e=this;this.beforeDisconnectHooks.forEach((function(t){return t(e)}))}},{key:"onBeforeDisconnect",value:function(e){this.beforeDisconnectHooks.push(e)}}],n&&o(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();e.exports=T},362:(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=n(13),i=n(84),a={get:n(712),set:n(298),unset:n(305),forEach:n(848),map:n(707),isEmpty:n(699),eq:n(113),isPlainObject:n(452),merge:n(831)},c=n(316),u=n(22),s=n(499);c.setAll=function(e){return Object.values(c.getLoggers()).forEach((function(t){return t.setLevel(e)}))};var l={warn:u.yellow,error:u.red,info:u.green,debug:u.gray},f=c.methodFactory;c.methodFactory=function(e,t,n){var r=f(e,t,n);if("undefined"!=typeof window){var o="".concat(n," ").concat(e);return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.apply(void 0,["[".concat(o,"]")].concat(t))}}var i,a="".concat(n," ").concat(l[i=e]?l[i](i):i);return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.apply(void 0,["[".concat(u.blue((new Date).toISOString())," ").concat(a,"]")].concat(t))}};var h=c.getLogger,p=function(e){return e.replace(/%/g,"%25").replace(/\//g,"%2F")},d=function(e){return e.replace(/%25/g,"%").replace(/%2F/g,"/")},b=function(e){return"/".concat(e.map((function(e){return e.startsWith("+")?"+":e})).map(p).join("/"))},y=function(e){var t=e.split("/").map(d);return t.length>0&&0==t[0].length&&t.shift(),t.length>0&&0==t.at(-1).length&&t.pop(),t},v=function(e,t){return function e(t,n){if(0==t.length)return!0;if("#"==t[0][0])return!0;if(0==n.length)return!0;if(t[0]==n[0])return e(t.slice(1),n.slice(1));if("+"==t[0][0]){var o=e(t.slice(1),n.slice(1));return o&&Object.assign(r({},t[0].slice(1),n[0]),o)}return!1}(y(e),y(t))},g=function e(t,n){return 0==t.length||t[0]==n[0]&&e(t.slice(1),n.slice(1))},m=function(e,t){return o(i(e),i(t))},w=["major","minor","patch"],O=["B","KB","MB","GB","TB"];e.exports={parseMQTTUsername:function(e){var t=e.split(":");return{organization:t[0],client:t[1],sub:t.slice(2)}},parseMQTTTopic:function(e){var t=y(e);return{organization:t[0],device:t[1],capabilityScope:t[2],capabilityName:t[3],capability:"".concat(t[2],"/").concat(t[3]),version:t[4],sub:t.slice(5)}},pathToTopic:b,topicToPath:y,toFlatObject:function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return a.forEach(t,(function(t,o){var i=n.concat(String(o));(a.isPlainObject(t)||t instanceof Array)&&null!==t?e(t,i,r):r[b(i)]=t})),r},topicMatch:v,mqttParsePayload:function(e){return 0==e.length?null:JSON.parse(e.toString("utf-8"))},getRandomId:function(){return Math.random().toString(36).slice(2)},versionCompare:m,getPackageVersionNamespace:function(){var e,t=w.indexOf(process.env.npm_package_config_versionNamespace||"patch");return t<0&&(t=2),null===(e=process.env.npm_package_version)||void 0===e?void 0:e.split(".").slice(0,t+1).join(".")},loglevel:c,getLogger:h,mergeVersions:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e)return t?a.set({},t,e):e;var r=Object.keys(e).filter((function(e){return(!n.maxVersion||m(e,n.maxVersion)<=0)&&(!n.minVersion||m(n.minVersion,e)<=0)})).sort(m),o={},i=t&&y(t);return r.forEach((function(t){var n=i?a.get(e[t],i):e[t];a.merge(o,n)})),i?a.set({},i,o):o},mqttClearRetained:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e3,o=[],i=function(e){t.forEach((function(t){return v("".concat(t,"/#"),e)&&o.push(e)}))};e.on("message",i),t.forEach((function(t){"string"==typeof t?e.subscribe("".concat(t,"/#")):console.warn("Ignoring",t,"since it is not a string.")}));var a="undefined"!=typeof Buffer?Buffer.alloc(0):null;setTimeout((function(){e.removeListener("message",i),t.forEach((function(t){return e.unsubscribe("".concat(t,"/#"))}));var r=o.length;console.log("clearing ".concat(r," retained messages from ").concat(t)),o.forEach((function(t){e.publish(t,a,{retain:!0})})),n&&n(r)}),r)},isSubTopicOf:function(e,t){var n=y(t),r=y(e);return g(n,r)&&n.length<r.length},clone:function(e){return JSON.parse(JSON.stringify(e))},setFromPath:function e(t,n,r){if(0==n.length)return t;var o=n.shift();0==n.length?t[o]=r:(t[o]||(t[o]={}),e(t[o],n,r))},forMatchIterator:function e(t,n,o){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};if(0!=n.length&&"#"!=n[0]){var c=n[0];if(c)for(var u in t)if(u==c||"*"==c||c.startsWith("+")){var s=c.startsWith("+")&&c.length>1?Object.assign({},a,r({},c.slice(1),u)):a;e(t[u],n.slice(1),o,i.concat([u]),s)}}else o(t,i,a)},encodeTopicElement:p,decodeTopicElement:d,constants:s,visit:function e(t,n,r){var o;t&&(r(t),null===(o=t[n])||void 0===o||o.forEach((function(t){return e(t,n,r)})))},wait:function(e){return new Promise((function(t){setTimeout(t,e)}))},formatBytes:function(e){if(!e)return"--";for(var t=0;e>1024;)e/=1024,t++;return"".concat(e.toFixed(2)," ").concat(O[t])},formatDuration:function(e){if(!e)return"--";var t={};e>3600&&(t.h=Math.floor(e/3600),e%=3600),e>60&&(t.m=Math.floor(e/60),e%=60),t.s=Math.floor(e);var n="";return t.h>0&&(n+="".concat(t.h,"h ")),t.m>0&&(n+="".concat(t.m,"m ")),!t.h&&(n+="".concat(t.s,"s")),n.trim()},tryJSONParse:function(e){try{return JSON.parse(e)}catch(e){return null}}}},499:e=>{e.exports={rosReleases:{kinetic:{rosVersion:1,ubuntuCodename:"xenial"},melodic:{rosVersion:1,ubuntuCodename:"bionic"},noetic:{rosVersion:1,ubuntuCodename:"focal"},dashing:{rosVersion:2},eloquent:{rosVersion:2},foxy:{rosVersion:2},galactic:{rosVersion:2},humble:{rosVersion:2},iron:{rosVersion:2},rolling:{rosVersion:2}}}},368:(e,t,n)=>{"use strict";n.r(t),n.d(t,{MqttSync:()=>u,decodeJWT:()=>s,fetchJson:()=>f,parseCookie:()=>l});var r=n(362),o={};for(const e in r)["default","MqttSync","decodeJWT","parseCookie","fetchJson"].indexOf(e)<0&&(o[e]=()=>r[e]);n.d(t,o);var i=n(890),a=n.n(i),c=n(720);o={};for(const e in c)["default","MqttSync","decodeJWT","parseCookie","fetchJson"].indexOf(e)<0&&(o[e]=()=>c[e]);n.d(t,o);var u=a(),s=function(e){return JSON.parse(atob(e.split(".")[1]))},l=function(e){return e.split(";").map((function(e){return e.split("=")})).reduce((function(e,t){return e[decodeURIComponent(t[0].trim())]=t[1]&&decodeURIComponent(t[1].trim()),e}),{})},f=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};fetch(e,{method:n.method||(n.body?"post":"get"),mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"},redirect:"follow",referrerPolicy:"no-referrer",body:n.body?JSON.stringify(n.body):void 0}).then((function(n){var r=!n.ok&&"fetching ".concat(e," failed: ").concat(n.status," ").concat(n.statusText);n.json().then((function(e){return t(r,e)})).catch((function(e){throw new Error(e)}))})).catch((function(e){return t("error: ".concat(e))}))}},442:(e,t,n)=>{"use strict";n.d(t,{H:()=>d});var r=n(689),o=n.n(r),i=n(368),a=n(517),c=n.n(a);const u=require("mqtt-browser");var s=n.n(u);function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?f(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var h=n(890),p=(0,i.getLogger)("utils-web/hooks");p.setLevel("info");var d=function(e){var t=e.jwt,n=e.id,a=e.mqttUrl,u=l((0,r.useState)("connecting"),2),f=u[0],d=u[1],b=l((0,r.useState)(),2),y=b[0],v=b[1],g=l((0,r.useState)({}),2),m=g[0],w=g[1];return(0,r.useEffect)((function(){var e=(0,i.decodeJWT)(t),r=s().connect(a,{username:JSON.stringify({id:n,payload:e}),password:t});return r.on("connect",(function(){p.debug("connected");var e=new h({mqttClient:r,ignoreRetain:!0});v(e),d("connected"),e.data.subscribe(c().debounce((function(){return w((0,i.clone)(e.data.get()))}),100))})),r.on("error",(function(e){p.error(e),d("error: ".concat(e))})),function(){p.info("cleaning up useMQTTSync"),y&&y.beforeDisconnect?(y.beforeDisconnect(),y.waitForHeartbeatOnce((function(){return r.end()}))):r.end()}}),[t,n]),{status:f,ready:"connected"==f,StatusComponent:function(){return o().createElement("div",null,f)},mqttSync:y,data:m}}},335:e=>{function t(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}e.exports=function(e){if(!e.attributes)return{};var r,o,i,a={},c=(i=e.attributes,function(e){if(Array.isArray(e))return n(e)}(i)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(i)||t(i)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){return function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}({},e.name,e.value)})),u=function(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=t(e))){r&&(e=r);var o=0,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return c=e.done,e},e:function(e){u=!0,a=e},f:function(){try{c||null==r.return||r.return()}finally{if(u)throw a}}}}(c);try{for(u.s();!(o=u.n()).done;){r=o.value;var s=Object.keys(r)[0];a[s.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}))]=r[s]}}catch(e){u.e(e)}finally{u.f()}return a}},899:(e,t,n)=>{e.exports=function(){try{return n(962).styleElements}catch(e){return[]}}},271:(e,t,n)=>{function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}function u(e){var t=p();return function(){var n,r=b(e);if(t){var o=b(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return s(this,n)}}function s(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return l(e)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e){var t="function"==typeof Map?new Map:void 0;return f=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return h(e,arguments,b(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)},f(e)}function h(e,t,n){return h=p()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&d(o,n.prototype),o},h.apply(null,arguments)}function p(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function b(e){return b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},b(e)}function y(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var v=n(689),g=n(405),m=n(430),w=n(899),O=n(335);n(622),n(268);var S={attachedCallback:"webComponentAttached",connectedCallback:"webComponentConnected",disconnectedCallback:"webComponentDisconnected",attributeChangedCallback:"webComponentAttributeChanged",adoptedCallback:"webComponentAdopted"};e.exports={create:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=function(t){c(f,t);var s=u(f);function f(){var e;o(this,f);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return y(l(e=s.call.apply(s,[this].concat(n))),"instance",null),e}return a(f,[{key:"callConstructorHook",value:function(){this.instance.webComponentConstructed&&this.instance.webComponentConstructed.apply(this.instance,[this])}},{key:"callLifeCycleHook",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=S[e];n&&this.instance&&this.instance[n]&&this.instance[n].apply(this.instance,t)}},{key:"connectedCallback",value:function(){var t=this,r=t;if(n){var o=t.attachShadow({mode:"open"});r=document.createElement("div"),w().forEach((function(e){o.appendChild(e.cloneNode(o))})),o.appendChild(r),m(o)}g.render(v.createElement(e,O(t)),r,(function(){t.instance=this,t.callConstructorHook(),t.callLifeCycleHook("connectedCallback")}))}},{key:"disconnectedCallback",value:function(){this.callLifeCycleHook("disconnectedCallback")}},{key:"attributeChangedCallback",value:function(e,t,n,r){this.callLifeCycleHook("attributeChangedCallback",[e,t,n,r])}},{key:"adoptedCallback",value:function(e,t){this.callLifeCycleHook("adoptedCallback",[e,t])}},{key:"call",value:function(e,t){var n,r;return null==i||null===(n=i.current)||void 0===n||null===(r=n[e])||void 0===r?void 0:r.call(null==i?void 0:i.current,t)}},{key:"getConfig",value:function(){return this.instance.state.config}}],[{key:"observedAttributes",get:function(){return r}}]),f}(f(HTMLElement));customElements.define(t,s)}}},11:(e,t,n)=>{"use strict";n.d(t,{EK:()=>C,SV:()=>q,ZM:()=>T,U5:()=>E,B7:()=>P,ax:()=>x,eZ:()=>M});var r=n(689),o=n.n(r);const i=require("react-bootstrap");var a=n(271),c=n.n(a);function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function s(){return s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s.apply(this,arguments)}function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function p(e,t,n){return t&&h(e.prototype,t),n&&h(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&b(e,t)}function b(e,t){return b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},b(e,t)}function y(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=m(e);if(t){var o=m(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return v(this,n)}}function v(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return g(e)}function g(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function w(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return O(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?O(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}n(368);var S={badge:{width:"4em"},code:{color:"#700",borderLeft:"3px solid #aaa",padding:"0.5em 0px 0.5em 2em",backgroundColor:"#f0f0f0",borderRadius:"4px",marginTop:"0.5em"},inlineCode:{color:"#700",margin:"0px 0.5em 0px 0.5em"}},k=[o().createElement(i.Badge,{bg:"success",style:S.badge},"OK"),o().createElement(i.Badge,{bg:"warning",style:S.badge},"Warn"),o().createElement(i.Badge,{bg:"danger",style:S.badge},"Error"),o().createElement(i.Badge,{bg:"secondary",style:S.badge},"Stale")],E=function(e){var t=e.level;return k[t]||o().createElement("span",null,t)},C=function(e){var t=e.children;return o().createElement("pre",{style:S.code},t)},T=function(e){var t=e.children;return o().createElement("tt",{style:S.inlineCode},t)},j={},x=o().createContext({}),P=function(e){var t=e.duration,n=e.onTimeout,a=e.onStart,c=e.setOnDisconnect,u=e.children;t=t||60;var s=w((0,r.useState)(t),2),l=s[0],f=s[1],h=w((0,r.useState)(!1),2),p=h[0],d=h[1],b=(0,r.useMemo)((function(){return Math.random().toString(36).slice(2)}),[]),y=function(){console.log("stopping timer for",b),n&&setTimeout(n,1),clearInterval(j[b]),j[b]=null,d(!1)};(0,r.useEffect)((function(){var e;l>0&&!p&&(e=j[b],console.log(e,j,l),!e&&l>0&&(d(!0),j[b]=setInterval((function(){return f((function(e){if(--e>0)return e;y()}))}),1e3),a&&setTimeout(a,1)))}),[l]),(0,r.useEffect)((function(){return y}),[]),c&&c((function(){y()}));var v=function(){return f(t)};return o().createElement(x.Provider,{value:{reset:v,duration:t,timer:l}},l>0?o().createElement("div",null,u,l<60&&o().createElement("div",null,"Timeout in: ",l," seconds")):o().createElement("div",null,"Timed out. ",o().createElement(i.Button,{onClick:v},"Resume")))},q=function(e){d(n,e);var t=y(n);function n(e){var r;return f(this,n),(r=t.call(this,e)).state={hasError:!1},r}return p(n,[{key:"componentDidCatch",value:function(e,t){console.warn("ErrorBoundary caught:",e,t)}},{key:"render",value:function(){return this.state.hasError?o().createElement("div",null,this.props.message||"Something went wrong here."):this.props.children}}],[{key:"getDerivedStateFromError",value:function(e){return{hasError:!0}}}]),n}(o().Component),_=function(e){var t;return e.$$typeof==Symbol.for("react.forward_ref")||(null===(t=e.prototype)||void 0===t?void 0:t.render)},M=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"0.0.0",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},a=_(e)?o().createRef():null,u=function(n){d(u,n);var c=y(u);function u(){var e;f(this,u);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return l(g(e=c.call.apply(c,[this].concat(n))),"onDisconnect",null),l(g(e),"state",{}),e}return p(u,[{key:"setOnDisconnect",value:function(e){this.onDisconnect=e}},{key:"webComponentDisconnected",value:function(){this.setState({_disconnected:!0});try{this.onDisconnect&&this.onDisconnect()}catch(e){console.log("Error during onDisconnect of web-component",e)}}},{key:"webComponentAttributeChanged",value:function(e,t,n){var r=this.state;r[e]=n,this.setState(r)}},{key:"setConfig",value:function(e){this.setState({config:e})}},{key:"render",value:function(){var n=i.stylesheets||["https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"];return o().createElement("div",{id:"cap-".concat(t,"-").concat(r)},o().createElement("style",null,n.map((function(e){return"@import url(".concat(e,");")}))),!this.state._disconnected&&o().createElement(e,s({ref:a},this.state,this.props,{setOnDisconnect:this.setOnDisconnect.bind(this),setConfig:this.setConfig.bind(this)})))}}]),u}(o().Component);c().create(u,t,i.shadowDOM||!1,n,a)}},268:e=>{"use strict";e.exports=require("@webcomponents/custom-elements")},622:e=>{"use strict";e.exports=require("@webcomponents/shadydom")},22:e=>{"use strict";e.exports=require("chalk")},517:e=>{"use strict";e.exports=require("lodash")},848:e=>{"use strict";e.exports=require("lodash/forEach")},712:e=>{"use strict";e.exports=require("lodash/get")},699:e=>{"use strict";e.exports=require("lodash/isEmpty")},113:e=>{"use strict";e.exports=require("lodash/isEqual")},452:e=>{"use strict";e.exports=require("lodash/isPlainObject")},707:e=>{"use strict";e.exports=require("lodash/map")},831:e=>{"use strict";e.exports=require("lodash/merge")},298:e=>{"use strict";e.exports=require("lodash/set")},305:e=>{"use strict";e.exports=require("lodash/unset")},316:e=>{"use strict";e.exports=require("loglevel")},689:e=>{"use strict";e.exports=require("react")},405:e=>{"use strict";e.exports=require("react-dom")},430:e=>{"use strict";e.exports=require("react-shadow-dom-retarget-events")},962:e=>{"use strict";e.exports=require("react-web-component-style-loader/exports")},13:e=>{"use strict";e.exports=require("semver/functions/compare")},84:e=>{"use strict";e.exports=require("semver/ranges/min-version")}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{Code:()=>e.EK,ErrorBoundary:()=>e.SV,InlineCode:()=>e.ZM,LevelBadge:()=>e.U5,Timer:()=>e.B7,TimerContext:()=>e.ax,createWebComponent:()=>e.eZ,useMqttSync:()=>t.H});var e=n(11),t=n(442),o=n(368),i={};for(const e in o)["default","Code","ErrorBoundary","InlineCode","LevelBadge","Timer","TimerContext","createWebComponent","useMqttSync"].indexOf(e)<0&&(i[e]=()=>o[e]);n.d(r,i)})();var o=exports;for(var i in r)o[i]=r[i];r.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
|
|
1
|
+
(()=>{var e={720:(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.set(e,n)}function c(e,t){return function(e,t){return t.get?t.get.call(e):t.value}(e,s(e,t,"get"))}function u(e,t,n){return function(e,t,n){if(t.set)t.set.call(e,n);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=n}}(e,s(e,t,"set"),n),n}function s(e,t,n){if(!t.has(e))throw new TypeError("attempted to "+n+" private field on non-instance");return t.get(e)}var l={get:n(712),set:n(298),unset:n(305),forEach:n(848),map:n(707),isEmpty:n(699),eq:n(113),isPlainObject:n(452),merge:n(831)},f=n(362),p=f.topicToPath,h=f.pathToTopic,d=f.toFlatObject,b=f.topicMatch,y=f.forMatchIterator,v=function e(t,n){if(n&&0!=n.length){l.unset(t,n);var r=n.slice(0,-1),o=0==r.length?t:l.get(t,r);return l.isEmpty(o)?e(t,r):n}},g=function e(t,n){if(0!=n.length){var r=n[0];if(r)for(var o in t)o==r||"*"==r||r.startsWith("+")?e(t[o],n.slice(1)):delete t[o]}},m=new WeakMap,w=new WeakMap,O=new WeakMap,S=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,e),a(this,m,{writable:!0,value:{}}),a(this,w,{writable:!0,value:[]}),a(this,O,{writable:!0,value:[]}),u(this,m,t)}var t,n;return t=e,n=[{key:"updateFromArray",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=l.get(c(this,m),e);if(null==t){if(null==o)return{};v(c(this,m),e)}else{if(l.eq(o,t))return{};l.set(c(this,m),e,t)}var i,a=h(e),u=r({},a,t);if(t instanceof Object){var s=d(t);i={},l.forEach(s,(function(e,t){i["".concat(a).concat(t)]=e}))}else i=u;return c(this,w).forEach((function(e){return e(u,n)})),c(this,O).forEach((function(e){return e(i,n)})),i}},{key:"update",value:function(e,t,n){if("string"==typeof e)return this.updateFromTopic(e,t,n);if(e instanceof Array)return this.updateFromArray(e,t,n);throw new Error("unrecognized path expression")}},{key:"updateFromTopic",value:function(e,t,n){return this.updateFromArray(p(e),t,n)}},{key:"updateFromModifier",value:function(e,t){var n=this;return l.map(e,(function(e,r){return n.updateFromTopic(r,e,t)}))}},{key:"subscribe",value:function(e){e instanceof Function?c(this,w).push(e):console.warn("DataCache.subscribe expects a function as argument. Did you mean to use subscribePath?")}},{key:"subscribePath",value:function(e,t){c(this,w).push((function(n,r){l.forEach(n,(function(n,o){var i=b(e,o);i&&t(n,o,i,r)}))}))}},{key:"subscribePathFlat",value:function(e,t){c(this,O).push((function(n,r){l.forEach(n,(function(n,o){var i=b(e,o);i&&t(n,o,i,r)}))}))}},{key:"unsubscribe",value:function(e){u(this,w,c(this,w).filter((function(t){return t!=e})))}},{key:"get",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return 0==e.length?c(this,m):l.get(c(this,m),e)}},{key:"getByTopic",value:function(e){return this.get(p(e))}},{key:"filter",value:function(e){var t=JSON.parse(JSON.stringify(this.get()));return g(t,e),t}},{key:"filterByTopic",value:function(e){return this.filter(p(e))}},{key:"forMatch",value:function(e,t){var n=p(e);this.forPathMatch(n,t)}},{key:"forPathMatch",value:function(e,t){y(this.get(),e,t)}}],n&&i(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();e.exports={DataCache:S,updateObject:function(e,t){return l.forEach(t,(function(t,n){var r=p(n);null==t?v(e,r):l.set(e,r,t)})),e}}},890:(e,t,n)=>{"use strict";function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}var c=n(362),u=c.mqttParsePayload,s=c.topicMatch,l=c.topicToPath,f=c.pathToTopic,p=c.toFlatObject,h=c.getLogger,d=c.mergeVersions,b=c.parseMQTTTopic,y=c.isSubTopicOf,v=c.versionCompare,g=c.encodeTopicElement,m=n(720).DataCache,w=n(517),O=h("MqttSync"),S="$SYS/broker/uptime",E=function(){},k=function(e){return e.endsWith("/#")?e:e.endsWith("/")?e.concat("#"):e.concat("/#")},j=function(e){return e.replace(/\/\//g,"/")},C=function(){function e(t){var n=this,r=t.mqttClient,o=t.onChange,a=t.ignoreRetain,c=t.migrate,s=t.onReady,p=t.sliceTopic;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),i(this,"data",new m),i(this,"subscribedPaths",{}),i(this,"publishedPaths",{}),i(this,"publishedMessages",{}),i(this,"publishQueue",new Map),i(this,"heartbeatWaitersOnce",[]),i(this,"heartbeats",0),i(this,"beforeDisconnectHooks",[]),this.mqtt=r,this.mqtt.on("message",(function(e,t,r){var i=t&&t.toString();if(O.debug("got message",e,i.slice(0,180),i.length>180?"... (".concat(i.length," bytes)"):"",r.retain),e==S)n.heartbeats>0&&(n.heartbeatWaitersOnce.forEach((function(e){return e()})),n.heartbeatWaitersOnce=[]),1==n.heartbeats&&!c&&s&&s(),n.heartbeats++;else if(r.retain||a){O.debug("processing message",e),p&&(e=f(l(e).slice(p)));var h=u(t);if(n.isPublished(e))n.publishedMessages[e]=h,n.data.update(e,h,{external:!0});else if(n.isSubscribed(e)){O.debug("applying received update",e);var d=n.data.update(e,h);o&&Object.keys(d).length>0&&o(d)}}})),this.mqtt.subscribe(S,{rap:!0},O.debug),(null==c?void 0:c.length)>0&&this.migrate(c,(function(){O.debug("done migrating",s),s&&n.waitForHeartbeatOnce(s)}))}var t,n;return t=e,n=[{key:"publishAtLevel",value:function(e,t,n){var r=this;O.debug("publishingAtLevel ".concat(n),e,t),n>0?w.forEach(t,(function(t,o){var i="".concat(e,"/").concat(g(o));O.debug("publishing ".concat(i)),r.publishAtLevel(i,t,n-1)})):this.mqtt.publish(e,JSON.stringify(t),{retain:!0},(function(e){e&&O.warn("Error when publishing migration result",e)}))}},{key:"migrate",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=e.length;if(0!=r){var o=function(){return 0==--r&&n&&n()};e.forEach((function(e){var n=e.topic,r=e.newVersion,i=e.transform,a=void 0===i?void 0:i,c=e.flat,u=void 0!==c&&c,s=e.level,h=void 0===s?0:s;O.debug("migrating",n,r);var y=b(n),g=y.organization,m=y.device,S=y.capability,E=y.sub,k="/".concat(g,"/").concat(m,"/").concat(S),C=0==E.length?"/#":f(E),T="".concat(k,"/+").concat(C);t.subscribe(T,(function(e){if(e)return O.warn("Error during migration",e),void o();t.waitForHeartbeatOnce((function(){O.debug("got heartbeat",n,T);var e=t.data.getByTopic(k);if(!e)return t.unsubscribe(T),void o();var i=d(e,C,{maxVersion:r}),c=w.get(i,l(C)),s=a?a(c):c,b=j("".concat(k,"/").concat(r,"/").concat(C));if(O.debug("publishing merged",b),u){var y=p(s),g=l(b);w.forEach(y,(function(e,n){var r=f(g.concat(l(n)));t.mqtt.publish(r,JSON.stringify(e),{retain:!0},(function(e){e&&O.warn("Error when publishing migration result for ".concat(n),e)}))}))}else t.publishAtLevel(b,s,h);t.unsubscribe(T),t.waitForHeartbeatOnce((function(){var n=Object.keys(e).filter((function(e){return v(e,r)<0})).map((function(e){return j("".concat(k,"/").concat(e,"/").concat(C))}));O.debug({prefixesToClear:n}),t.clear(n),o()}))}))}))}))}else n&&n()}},{key:"clear",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=[],i=function(t){e.forEach((function(e){return s("".concat(e,"/#"),t)&&(!r.filter||r.filter(t))&&o.push(t)}))};this.mqtt.on("message",i),e.forEach((function(e){"string"==typeof e?t.mqtt.subscribe("".concat(e,"/#")):O.warn("Ignoring",e,"since it is not a string.")}));var a="undefined"!=typeof Buffer?Buffer.alloc(0):null;this.waitForHeartbeatOnce((function(){t.mqtt.removeListener("message",i),e.forEach((function(e){return t.mqtt.unsubscribe("".concat(e,"/#"))}));var r=o.length;O.debug("clearing ".concat(r," retained messages from ").concat(e)),o.forEach((function(e){t.mqtt.publish(e,a,{retain:!0})})),n&&n(r)}))}},{key:"waitForHeartbeatOnce",value:function(e){var t=this;setTimeout((function(){return t.heartbeatWaitersOnce.push(e)}),1)}},{key:"isSubscribed",value:function(e){return Object.keys(this.subscribedPaths).some((function(t){return s(t,e)}))}},{key:"isPublished",value:function(e){var t=this;return Object.keys(this.publishedPaths).some((function(n){return s(n,e)&&!t.publishedPaths[n].atomic}))}},{key:"subscribe",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:E;if(e=k(e),this.subscribedPaths[e])return O.debug("already subscribed to",e),void n();this.mqtt.subscribe(e,{rap:!0},(function(r,o){O.debug("subscribe",e,"granted:",o),o&&o.some((function(t){return t.topic==e&&t.qos<128}))?(t.subscribedPaths[e]=1,n(null)):n("not permitted to subscribe to topic ".concat(e,", ").concat(JSON.stringify(o)))}))}},{key:"unsubscribe",value:function(e){this.subscribedPaths[e]&&(this.mqtt.unsubscribe(e),delete this.subscribedPaths[e])}},{key:"_actuallyPublish",value:function(e,t){return this.mqtt.connected?(O.debug("actually publishing",e),this.mqtt.publish(e,null==t?null:JSON.stringify(t),{retain:!0}),!0):(O.warn("not connected, not publishing",e),!1)}},{key:"_processQueue_rec",value:function(e){var t=this;if(this.publishQueue.size>0){var n=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(this.publishQueue.entries().next().value,2),o=n[0],i=n[1];this._actuallyPublish(o,i)?(this.publishQueue.delete(o),this._processQueue_rec(e)):setTimeout((function(){return t._processQueue_rec(e)}),5e3)}else e()}},{key:"_processQueue",value:function(){var e=this;this._processing||(this._processing=!0,this._processQueue_rec((function(){return e._processing=!1})))}},{key:"setThrottle",value:function(e){this._processQueueThrottled=w.throttle(this._processQueue.bind(this),e)}},{key:"clearThrottle",value:function(){delete this._processQueueThrottled}},{key:"addToQueue",value:function(e,t){this.publishQueue.set(e,t)}},{key:"_enqueue",value:function(e,t){var n;O.debug("enqueuing",e),this.addToQueue(e,t),this._processQueueThrottled?this._processQueueThrottled():this._processQueue(),null==t?delete this.publishedMessages[e]:this.publishedMessages[e]="object"==a(n=t)?JSON.parse(JSON.stringify(n)):n}},{key:"publish",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{atomic:!1};return e=k(e),!w.isEqual(this.publishedPaths[e],n)&&(this.publishedPaths[e]=n,n.atomic?(this.data.subscribePath(e,(function(n,r,o,i){if(null==i||!i.external){O.debug("processing change (atomic)",r,e);var a=e.slice(0,e.length-2),c=f(l(r).slice(0,l(a).length));t._enqueue(c,t.data.getByTopic(c))}})),!0):(this.mqtt.subscribe(e),void this.data.subscribePath(e,(function(e,n,r,o){if(null==o||!o.external)return O.debug("processing change",n),w.each(t.publishedMessages,(function(e,r){if(O.trace("oldKey",r),r==n)return!0;if(y(r,n)&&t._enqueue(r,null),y(n,r)){t._enqueue(r,null);var o=p(e);w.each(o,(function(e,n){var o="".concat(r).concat(n);t._enqueue(o,e)}))}})),t._enqueue(n,e),!0}))))}},{key:"beforeDisconnect",value:function(){var e=this;this.beforeDisconnectHooks.forEach((function(t){return t(e)}))}},{key:"onBeforeDisconnect",value:function(e){this.beforeDisconnectHooks.push(e)}}],n&&o(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();e.exports=C},362:(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=n(13),i=n(84),a={get:n(712),set:n(298),unset:n(305),forEach:n(848),map:n(707),isEmpty:n(699),eq:n(113),isPlainObject:n(452),merge:n(831)},c=n(316),u=n(22),s=n(499);c.setAll=function(e){return Object.values(c.getLoggers()).forEach((function(t){return t.setLevel(e)}))};var l={warn:u.yellow,error:u.red,info:u.green,debug:u.gray},f=c.methodFactory;c.methodFactory=function(e,t,n){var r=f(e,t,n);if("undefined"!=typeof window){var o="".concat(n," ").concat(e);return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.apply(void 0,["[".concat(o,"]")].concat(t))}}var i,a="".concat(n," ").concat(l[i=e]?l[i](i):i);return function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r.apply(void 0,["[".concat(u.blue((new Date).toISOString())," ").concat(a,"]")].concat(t))}};var p=c.getLogger,h=function(e){return e.replace(/%/g,"%25").replace(/\//g,"%2F")},d=function(e){return e.replace(/%25/g,"%").replace(/%2F/g,"/")},b=function(e){return"/".concat(e.map((function(e){return e.startsWith("+")?"+":e})).map(h).join("/"))},y=function(e){var t=e.split("/").map(d);return t.length>0&&0==t[0].length&&t.shift(),t.length>0&&0==t.at(-1).length&&t.pop(),t},v=function(e,t){return function e(t,n){if(0==t.length)return!0;if("#"==t[0][0])return!0;if(0==n.length)return!0;if(t[0]==n[0])return e(t.slice(1),n.slice(1));if("+"==t[0][0]){var o=e(t.slice(1),n.slice(1));return o&&Object.assign(r({},t[0].slice(1),n[0]),o)}return!1}(y(e),y(t))},g=function e(t,n){return 0==t.length||t[0]==n[0]&&e(t.slice(1),n.slice(1))},m=function(e,t){return o(i(e),i(t))},w=["B","KB","MB","GB","TB"];e.exports={parseMQTTUsername:function(e){var t=e.split(":");return{organization:t[0],client:t[1],sub:t.slice(2)}},parseMQTTTopic:function(e){var t=y(e);return{organization:t[0],device:t[1],capabilityScope:t[2],capabilityName:t[3],capability:"".concat(t[2],"/").concat(t[3]),version:t[4],sub:t.slice(5)}},pathToTopic:b,topicToPath:y,toFlatObject:function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return a.forEach(t,(function(t,o){var i=n.concat(String(o));(a.isPlainObject(t)||t instanceof Array)&&null!==t?e(t,i,r):r[b(i)]=t})),r},topicMatch:v,mqttParsePayload:function(e){return 0==e.length?null:JSON.parse(e.toString("utf-8"))},getRandomId:function(){return Math.random().toString(36).slice(2)},versionCompare:m,loglevel:c,getLogger:p,mergeVersions:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e)return t?a.set({},t,e):e;var r=Object.keys(e).filter((function(e){return(!n.maxVersion||m(e,n.maxVersion)<=0)&&(!n.minVersion||m(n.minVersion,e)<=0)})).sort(m),o={},i=t&&y(t);return r.forEach((function(t){var n=i?a.get(e[t],i):e[t];a.merge(o,n)})),i?a.set({},i,o):o},mqttClearRetained:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e3,o=[],i=function(e){t.forEach((function(t){return v("".concat(t,"/#"),e)&&o.push(e)}))};e.on("message",i),t.forEach((function(t){"string"==typeof t?e.subscribe("".concat(t,"/#")):console.warn("Ignoring",t,"since it is not a string.")}));var a="undefined"!=typeof Buffer?Buffer.alloc(0):null;setTimeout((function(){e.removeListener("message",i),t.forEach((function(t){return e.unsubscribe("".concat(t,"/#"))}));var r=o.length;console.log("clearing ".concat(r," retained messages from ").concat(t)),o.forEach((function(t){e.publish(t,a,{retain:!0})})),n&&n(r)}),r)},isSubTopicOf:function(e,t){var n=y(t),r=y(e);return g(n,r)&&n.length<r.length},clone:function(e){return JSON.parse(JSON.stringify(e))},setFromPath:function e(t,n,r){if(0==n.length)return t;var o=n.shift();0==n.length?t[o]=r:(t[o]||(t[o]={}),e(t[o],n,r))},forMatchIterator:function e(t,n,o){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};if(0!=n.length&&"#"!=n[0]){var c=n[0];if(c)for(var u in t)if(u==c||"*"==c||c.startsWith("+")){var s=c.startsWith("+")&&c.length>1?Object.assign({},a,r({},c.slice(1),u)):a;e(t[u],n.slice(1),o,i.concat([u]),s)}}else o(t,i,a)},encodeTopicElement:h,decodeTopicElement:d,constants:s,visit:function e(t,n,r){var o;t&&(r(t),null===(o=t[n])||void 0===o||o.forEach((function(t){return e(t,n,r)})))},wait:function(e){return new Promise((function(t){setTimeout(t,e)}))},formatBytes:function(e){if(!e)return"--";for(var t=0;e>1024;)e/=1024,t++;return"".concat(e.toFixed(2)," ").concat(w[t])},formatDuration:function(e){if(!e)return"--";var t={};e>3600&&(t.h=Math.floor(e/3600),e%=3600),e>60&&(t.m=Math.floor(e/60),e%=60),t.s=Math.floor(e);var n="";return t.h>0&&(n+="".concat(t.h,"h ")),t.m>0&&(n+="".concat(t.m,"m ")),!t.h&&(n+="".concat(t.s,"s")),n.trim()},tryJSONParse:function(e){try{return JSON.parse(e)}catch(e){return null}}}},499:e=>{e.exports={rosReleases:{kinetic:{rosVersion:1,ubuntuCodename:"xenial"},melodic:{rosVersion:1,ubuntuCodename:"bionic"},noetic:{rosVersion:1,ubuntuCodename:"focal"},dashing:{rosVersion:2},eloquent:{rosVersion:2},foxy:{rosVersion:2},galactic:{rosVersion:2},humble:{rosVersion:2},iron:{rosVersion:2},rolling:{rosVersion:2}}}},368:(e,t,n)=>{"use strict";n.r(t),n.d(t,{MqttSync:()=>u,decodeJWT:()=>s,fetchJson:()=>f,parseCookie:()=>l});var r=n(362),o={};for(const e in r)["default","MqttSync","decodeJWT","parseCookie","fetchJson"].indexOf(e)<0&&(o[e]=()=>r[e]);n.d(t,o);var i=n(890),a=n.n(i),c=n(720);o={};for(const e in c)["default","MqttSync","decodeJWT","parseCookie","fetchJson"].indexOf(e)<0&&(o[e]=()=>c[e]);n.d(t,o);var u=a(),s=function(e){return JSON.parse(atob(e.split(".")[1]))},l=function(e){return e.split(";").map((function(e){return e.split("=")})).reduce((function(e,t){return e[decodeURIComponent(t[0].trim())]=t[1]&&decodeURIComponent(t[1].trim()),e}),{})},f=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};fetch(e,{method:n.method||(n.body?"post":"get"),mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"},redirect:"follow",referrerPolicy:"no-referrer",body:n.body?JSON.stringify(n.body):void 0}).then((function(n){var r=!n.ok&&"fetching ".concat(e," failed: ").concat(n.status," ").concat(n.statusText);n.json().then((function(e){return t(r,e)})).catch((function(e){throw new Error(e)}))})).catch((function(e){return t("error: ".concat(e))}))}},442:(e,t,n)=>{"use strict";n.d(t,{H:()=>v,D:()=>g});var r=n(689),o=n.n(r),i=n(517),a=n.n(i);const c=require("mqtt-browser");var u=n.n(c),s=n(368);function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function f(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){p(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var b=n(890),y=(0,s.getLogger)("utils-web/hooks");y.setLevel("info");var v=function(e){var t=e.jwt,n=e.id,i=e.mqttUrl,c=h((0,r.useState)("connecting"),2),l=c[0],f=c[1],p=h((0,r.useState)(),2),d=p[0],v=p[1],g=h((0,r.useState)({}),2),m=g[0],w=g[1];return(0,r.useEffect)((function(){var e=(0,s.decodeJWT)(t),r=u().connect(i,{username:JSON.stringify({id:n,payload:e}),password:t});return r.on("connect",(function(){y.debug("connected");var e=new b({mqttClient:r,ignoreRetain:!0});v(e),f("connected"),e.data.subscribe(a().debounce((function(){return w((0,s.clone)(e.data.get()))}),100))})),r.on("error",(function(e){y.error(e),f("error: ".concat(e))})),function(){y.info("cleaning up useMQTTSync"),d&&d.beforeDisconnect?(d.beforeDisconnect(),d.waitForHeartbeatOnce((function(){return r.end()}))):r.end()}}),[t,n]),{status:l,ready:"connected"==l,StatusComponent:function(){return o().createElement("div",null,l)},mqttSync:d,data:m}},g=function(e){var t=e.jwt,n=e.id,r=e.host,o=e.ssl,i=e.capability,a=e.versionNS,c=h(i.split("/"),2),u=c[0],l=c[1],p=(0,s.decodeJWT)(t).device,d=[n,p,u,l],b=(0,s.pathToTopic)(d),y=[].concat(d,[a]),g=(0,s.pathToTopic)(y),m="".concat(o&&JSON.parse(o)?"wss":"ws","://mqtt.").concat(r);return f(f({},v({jwt:t,id:n,mqttUrl:m})),{},{device:p,prefixPath:d,prefix:b,prefixPathVersion:y,prefixVersion:g})}},335:e=>{function t(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}e.exports=function(e){if(!e.attributes)return{};var r,o,i,a={},c=(i=e.attributes,function(e){if(Array.isArray(e))return n(e)}(i)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(i)||t(i)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){return function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}({},e.name,e.value)})),u=function(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=t(e))){r&&(e=r);var o=0,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return c=e.done,e},e:function(e){u=!0,a=e},f:function(){try{c||null==r.return||r.return()}finally{if(u)throw a}}}}(c);try{for(u.s();!(o=u.n()).done;){r=o.value;var s=Object.keys(r)[0];a[s.replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}))]=r[s]}}catch(e){u.e(e)}finally{u.f()}return a}},899:(e,t,n)=>{e.exports=function(){try{return n(962).styleElements}catch(e){return[]}}},271:(e,t,n)=>{function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}function u(e){var t=h();return function(){var n,r=b(e);if(t){var o=b(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return s(this,n)}}function s(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return l(e)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e){var t="function"==typeof Map?new Map:void 0;return f=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return p(e,arguments,b(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)},f(e)}function p(e,t,n){return p=h()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&d(o,n.prototype),o},p.apply(null,arguments)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function b(e){return b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},b(e)}function y(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var v=n(689),g=n(405),m=n(430),w=n(899),O=n(335);n(622),n(268);var S={attachedCallback:"webComponentAttached",connectedCallback:"webComponentConnected",disconnectedCallback:"webComponentDisconnected",attributeChangedCallback:"webComponentAttributeChanged",adoptedCallback:"webComponentAdopted"};e.exports={create:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0,s=function(t){c(f,t);var s=u(f);function f(){var e;o(this,f);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return y(l(e=s.call.apply(s,[this].concat(n))),"instance",null),e}return a(f,[{key:"callConstructorHook",value:function(){this.instance.webComponentConstructed&&this.instance.webComponentConstructed.apply(this.instance,[this])}},{key:"callLifeCycleHook",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=S[e];n&&this.instance&&this.instance[n]&&this.instance[n].apply(this.instance,t)}},{key:"connectedCallback",value:function(){var t=this,r=t;if(n){var o=t.attachShadow({mode:"open"});r=document.createElement("div"),w().forEach((function(e){o.appendChild(e.cloneNode(o))})),o.appendChild(r),m(o)}g.render(v.createElement(e,O(t)),r,(function(){t.instance=this,t.callConstructorHook(),t.callLifeCycleHook("connectedCallback")}))}},{key:"disconnectedCallback",value:function(){this.callLifeCycleHook("disconnectedCallback")}},{key:"attributeChangedCallback",value:function(e,t,n,r){this.callLifeCycleHook("attributeChangedCallback",[e,t,n,r])}},{key:"adoptedCallback",value:function(e,t){this.callLifeCycleHook("adoptedCallback",[e,t])}},{key:"call",value:function(e,t){var n,r;return null==i||null===(n=i.current)||void 0===n||null===(r=n[e])||void 0===r?void 0:r.call(null==i?void 0:i.current,t)}},{key:"getConfig",value:function(){return this.instance.state.config}}],[{key:"observedAttributes",get:function(){return r}}]),f}(f(HTMLElement));customElements.define(t,s)}}},11:(e,t,n)=>{"use strict";n.d(t,{EK:()=>j,SV:()=>q,ZM:()=>C,U5:()=>k,B7:()=>x,ax:()=>P,eZ:()=>M});var r=n(689),o=n.n(r);const i=require("react-bootstrap");var a=n(271),c=n.n(a);function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function s(){return s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s.apply(this,arguments)}function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function h(e,t,n){return t&&p(e.prototype,t),n&&p(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&b(e,t)}function b(e,t){return b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},b(e,t)}function y(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=m(e);if(t){var o=m(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return v(this,n)}}function v(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return g(e)}function g(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function w(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return O(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?O(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}n(368);var S={badge:{width:"4em"},code:{color:"#700",borderLeft:"3px solid #aaa",padding:"0.5em 0px 0.5em 2em",backgroundColor:"#f0f0f0",borderRadius:"4px",marginTop:"0.5em"},inlineCode:{color:"#700",margin:"0px 0.5em 0px 0.5em"}},E=[o().createElement(i.Badge,{bg:"success",style:S.badge},"OK"),o().createElement(i.Badge,{bg:"warning",style:S.badge},"Warn"),o().createElement(i.Badge,{bg:"danger",style:S.badge},"Error"),o().createElement(i.Badge,{bg:"secondary",style:S.badge},"Stale")],k=function(e){var t=e.level;return E[t]||o().createElement("span",null,t)},j=function(e){var t=e.children;return o().createElement("pre",{style:S.code},t)},C=function(e){var t=e.children;return o().createElement("tt",{style:S.inlineCode},t)},T={},P=o().createContext({}),x=function(e){var t=e.duration,n=e.onTimeout,a=e.onStart,c=e.setOnDisconnect,u=e.children;t=t||60;var s=w((0,r.useState)(t),2),l=s[0],f=s[1],p=w((0,r.useState)(!1),2),h=p[0],d=p[1],b=(0,r.useMemo)((function(){return Math.random().toString(36).slice(2)}),[]),y=function(){console.log("stopping timer for",b),n&&setTimeout(n,1),clearInterval(T[b]),T[b]=null,d(!1)};(0,r.useEffect)((function(){var e;l>0&&!h&&(e=T[b],console.log(e,T,l),!e&&l>0&&(d(!0),T[b]=setInterval((function(){return f((function(e){if(--e>0)return e;y()}))}),1e3),a&&setTimeout(a,1)))}),[l]),(0,r.useEffect)((function(){return y}),[]),c&&c((function(){y()}));var v=function(){return f(t)};return o().createElement(P.Provider,{value:{reset:v,duration:t,timer:l}},l>0?o().createElement("div",null,u,l<60&&o().createElement("div",null,"Timeout in: ",l," seconds")):o().createElement("div",null,"Timed out. ",o().createElement(i.Button,{onClick:v},"Resume")))},q=function(e){d(n,e);var t=y(n);function n(e){var r;return f(this,n),(r=t.call(this,e)).state={hasError:!1},r}return h(n,[{key:"componentDidCatch",value:function(e,t){console.warn("ErrorBoundary caught:",e,t)}},{key:"render",value:function(){return this.state.hasError?o().createElement("div",null,this.props.message||"Something went wrong here."):this.props.children}}],[{key:"getDerivedStateFromError",value:function(e){return{hasError:!0}}}]),n}(o().Component),_=function(e){var t;return e.$$typeof==Symbol.for("react.forward_ref")||(null===(t=e.prototype)||void 0===t?void 0:t.render)},M=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"0.0.0",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},a=_(e)?o().createRef():null,u=function(n){d(u,n);var c=y(u);function u(){var e;f(this,u);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return l(g(e=c.call.apply(c,[this].concat(n))),"onDisconnect",null),l(g(e),"state",{}),e}return h(u,[{key:"setOnDisconnect",value:function(e){this.onDisconnect=e}},{key:"webComponentDisconnected",value:function(){this.setState({_disconnected:!0});try{this.onDisconnect&&this.onDisconnect()}catch(e){console.log("Error during onDisconnect of web-component",e)}}},{key:"webComponentAttributeChanged",value:function(e,t,n){var r=this.state;r[e]=n,this.setState(r)}},{key:"setConfig",value:function(e){this.setState({config:e})}},{key:"render",value:function(){var n=i.stylesheets||["https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"];return o().createElement("div",{id:"cap-".concat(t,"-").concat(r)},o().createElement("style",null,n.map((function(e){return"@import url(".concat(e,");")}))),!this.state._disconnected&&o().createElement(e,s({ref:a},this.state,this.props,{setOnDisconnect:this.setOnDisconnect.bind(this),setConfig:this.setConfig.bind(this)})))}}]),u}(o().Component);c().create(u,t,i.shadowDOM||!1,n,a)}},268:e=>{"use strict";e.exports=require("@webcomponents/custom-elements")},622:e=>{"use strict";e.exports=require("@webcomponents/shadydom")},22:e=>{"use strict";e.exports=require("chalk")},517:e=>{"use strict";e.exports=require("lodash")},848:e=>{"use strict";e.exports=require("lodash/forEach")},712:e=>{"use strict";e.exports=require("lodash/get")},699:e=>{"use strict";e.exports=require("lodash/isEmpty")},113:e=>{"use strict";e.exports=require("lodash/isEqual")},452:e=>{"use strict";e.exports=require("lodash/isPlainObject")},707:e=>{"use strict";e.exports=require("lodash/map")},831:e=>{"use strict";e.exports=require("lodash/merge")},298:e=>{"use strict";e.exports=require("lodash/set")},305:e=>{"use strict";e.exports=require("lodash/unset")},316:e=>{"use strict";e.exports=require("loglevel")},689:e=>{"use strict";e.exports=require("react")},405:e=>{"use strict";e.exports=require("react-dom")},430:e=>{"use strict";e.exports=require("react-shadow-dom-retarget-events")},962:e=>{"use strict";e.exports=require("react-web-component-style-loader/exports")},13:e=>{"use strict";e.exports=require("semver/functions/compare")},84:e=>{"use strict";e.exports=require("semver/ranges/min-version")}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{Code:()=>e.EK,ErrorBoundary:()=>e.SV,InlineCode:()=>e.ZM,LevelBadge:()=>e.U5,Timer:()=>e.B7,TimerContext:()=>e.ax,createWebComponent:()=>e.eZ,useMqttSync:()=>t.H,useTransitive:()=>t.D});var e=n(11),t=n(442),o=n(368),i={};for(const e in o)["default","Code","ErrorBoundary","InlineCode","LevelBadge","Timer","TimerContext","createWebComponent","useMqttSync","useTransitive"].indexOf(e)<0&&(i[e]=()=>o[e]);n.d(r,i)})();var o=exports;for(var i in r)o[i]=r[i];r.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
|
package/hooks.jsx
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import React, { useState, useEffect, useMemo } from 'react';
|
|
2
|
-
import { decodeJWT, getLogger, clone } from './client';
|
|
3
2
|
import _ from 'lodash';
|
|
4
|
-
|
|
5
|
-
// import MqttSync from '../MqttSync';
|
|
6
|
-
const MqttSync = require('../common/MqttSync');
|
|
7
3
|
import mqtt from 'mqtt-browser';
|
|
4
|
+
import { decodeJWT, getLogger, clone, pathToTopic } from './client';
|
|
5
|
+
const MqttSync = require('../common/MqttSync');
|
|
6
|
+
|
|
8
7
|
const log = getLogger('utils-web/hooks');
|
|
9
8
|
log.setLevel('info');
|
|
10
9
|
|
|
11
|
-
/** hook for using MqttSync in
|
|
10
|
+
/** hook for using MqttSync in React */
|
|
12
11
|
export const useMqttSync = ({jwt, id, mqttUrl}) => {
|
|
13
12
|
const [status, setStatus] = useState('connecting');
|
|
14
13
|
const [mqttSync, setMqttSync] = useState();
|
|
@@ -59,3 +58,22 @@ export const useMqttSync = ({jwt, id, mqttUrl}) => {
|
|
|
59
58
|
data, // This is a reactive data-source (to use meteor terminology).
|
|
60
59
|
};
|
|
61
60
|
};
|
|
61
|
+
|
|
62
|
+
/** Hook for using Transitive in React. Connects to MQTT, establishes sync, and
|
|
63
|
+
exposes reactive `data` state variable. */
|
|
64
|
+
export const useTransitive = ({jwt, id, host, ssl, capability, versionNS}) => {
|
|
65
|
+
|
|
66
|
+
const [scope, capabilityName] = capability.split('/');
|
|
67
|
+
|
|
68
|
+
const { device } = decodeJWT(jwt);
|
|
69
|
+
const prefixPath = [id, device, scope, capabilityName];
|
|
70
|
+
const prefix = pathToTopic(prefixPath);
|
|
71
|
+
const prefixPathVersion = [...prefixPath, versionNS];
|
|
72
|
+
const prefixVersion = pathToTopic(prefixPathVersion);
|
|
73
|
+
|
|
74
|
+
const mqttUrl = `${ssl && JSON.parse(ssl) ? 'wss' : 'ws'}://mqtt.${host}`;
|
|
75
|
+
const fromMqttSync = useMqttSync({ jwt, id, mqttUrl });
|
|
76
|
+
|
|
77
|
+
return {...fromMqttSync, device, prefixPath, prefix, prefixPathVersion,
|
|
78
|
+
prefixVersion};
|
|
79
|
+
};
|