UNPKG

ocearo-ui

Version:

Ocean Robot UI: Sailing made smarter

1 lines 289 kB
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[746],{35323:function(t,e,r){"use strict";e.default=void 0;var n=i(r(48595)),o=i(r(95193));function i(t){return t&&t.__esModule?t:{default:t}}n.default,o.default;var s=n.default;e.default=s},17970:function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0,r(51887),r(79310),r(84134),r(34125),r(42344);class n{constructor(t){this.connection=t,this.selfMRN=this.connection.self}get(t){return t.includes(".")&&(t=t.replace(/\./g,"/")),("string"!=typeof t||""===t.trim())&&(t="/"),"/"!==t.charAt(0)&&(t="/".concat(t)),this.connection.fetch(t)}put(t,e){return t.includes(".")&&(t=t.replace(/\./g,"/")),("string"!=typeof t||""===t.trim())&&(t="/"),"/"!==t.charAt(0)&&(t="/".concat(t)),this.connection.fetch(t,{method:"PUT",mode:"cors",body:e&&"object"==typeof e?JSON.stringify(e):e})}getMeta(t){return this.get(t).then(t=>t&&"object"==typeof t&&t.hasOwnProperty("meta")?t.meta:null)}sources(){return this.get("/sources")}resources(){return this.get("/resources")}mrn(){return this.get("/self")}vessels(){return this.get("/vessels")}aircraft(){return this.get("/aircraft")}aton(){return this.get("/aton")}sar(){return this.get("/sar")}version(){return this.get("/version")}self(t){return("string"!=typeof t||"/"!==t.charAt(0))&&(t=""),this.connection.fetch("/vessels/self".concat(t))}vessel(t,e){return("string"!=typeof e||"/"!==e.charAt(0))&&(e=""),this.connection.fetch("/vessels/".concat(t).concat(e))}name(){return this.self("/name")}getGroup(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"self";return(("string"!=typeof e||"/"!==e.charAt(0))&&(e=""),"self"===r)?this.self("/".concat(t).concat(e)):this.vessel(r,"/".concat(t).concat(e))}communication(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("communication",t,e)}design(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("design",t,e)}electrical(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("electrical",t,e)}environment(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("environment",t,e)}navigation(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("navigation",t,e)}notifications(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("notifications",t,e)}performance(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("performance",t,e)}propulsion(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("propulsion",t,e)}sails(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("sails",t,e)}sensors(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("sensors",t,e)}steering(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("steering",t,e)}tanks(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self";return this.getGroup("tanks",t,e)}}e.default=n},48595:function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.PERMISSIONS_READWRITE=e.PERMISSIONS_READONLY=e.PERMISSIONS_DENY=e.AUTHENTICATION_REQUEST=void 0,r(53147),r(97940),r(51887),r(79310),r(84134),r(34125),r(80329);var n=c(r(77625)),o=c(r(75178)),i=c(r(11981)),s=c(r(17970)),a=c(r(31464)),u=r(24536);function c(t){return t&&t.__esModule?t:{default:t}}function f(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function l(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?f(Object(r),!0).forEach(function(e){var n;n=r[e],e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}let h=(0,a.default)("signalk-js-sdk/Client"),p="__AUTHENTICATION_REQUEST__";e.AUTHENTICATION_REQUEST=p,e.PERMISSIONS_READWRITE="readwrite",e.PERMISSIONS_READONLY="readonly",e.PERMISSIONS_DENY="denied";class d extends n.default{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};super(),this.options=l({hostname:"localhost",port:3e3,useTLS:!0,useAuthentication:!1,notifications:!0,version:"v1",autoConnect:!1,reconnect:!0,maxRetries:1/0,maxTimeBetweenRetries:2500,mdns:null,username:null,password:null,deltaStreamBehaviour:"none",subscriptions:[],wsKeepaliveInterval:0},t),this.api=null,this.connection=null,this.services=[],this.notifications={},this.requests={},this.fetchReady=null,Array.isArray(this.options.subscriptions)&&(this.subscribeCommands=this.options.subscriptions.filter(t=>g(t))),!0===this.options.notifications&&this.subscribeCommands.push({context:"vessels.self",subscribe:[{path:"notifications.*",policy:"instant"}]}),!0===this.options.autoConnect&&this.connect().catch(t=>this.emit("error",t))}get self(){return null===this.connection?null:this.connection.self}set(t,e){return this.options[t]=e,this}get(t){return this.options[t]||null}get retries(){return null===this.connection?0:this.connection.retries}requestDeviceAccess(t,e){let r="string"==typeof e?e:(0,u.v4)();return this.connection.fetch("/access/requests",{method:"POST",mode:"cors",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({clientId:r,description:t})}).then(t=>({clientId:r,response:t}))}respondToAccessRequest(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"1y";return this.connection.fetch("/security/access/requests/".concat(t,"/").concat("denied"===e?"denied":"approved"),{method:"PUT",mode:"cors",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({expiration:r,permissions:e})})}authenticate(t,e){let r=this.request(p,{login:{username:t,password:e}});r.on("response",t=>{if(200===t.statusCode&&t.hasOwnProperty("login")&&"object"==typeof t.login&&t.login.hasOwnProperty("token"))return this.connection.setAuthenticated(t.login.token),this.emit("authenticated",{token:t.login.token});this.emit("error",Error("Error authenticating: status ".concat(t.statusCode)))}),r.send()}request(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.requests.hasOwnProperty(t)||(this.requests[t]=new i.default(this.connection,t,e),h('Registered request "'.concat(t,'" with ID ').concat(this.requests[t].getRequestId()))),this.requests[t]}subscribe(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(null===this.connection)throw Error("Not connected");t&&!Array.isArray(t)&&"object"==typeof t&&t.hasOwnProperty("subscribe")&&(t=[t]),(t=t.filter(t=>g(t))).forEach(t=>{this.subscribeCommands.push(t)}),this.connection.subscribe(t)}unsubscribe(){if(null===this.connection)throw Error("Not connected");let{notifications:t}=this.options;this.subscribeCommands=!0===t?[{context:"vessels.self",subscribe:[{path:"notifications.*",policy:"instant"}]}]:[],this.connection.unsubscribe(),this.subscribeCommands.length>0&&this.connection.subscribe(this.subscribeCommands)}connect(){return null!==this.connection?(this.connection.reconnect(!0),Promise.resolve(this.connection)):new Promise((t,e)=>{this.connection=new o.default(this.options,this.subscribeCommands),this.connection.on("disconnect",t=>this.emit("disconnect",t)),this.connection.on("message",t=>this.processWSMessage(t)),this.connection.on("connectionInfo",t=>this.emit("connectionInfo",t)),this.connection.on("self",t=>this.emit("self",t)),this.connection.on("hitMaxRetries",()=>this.emit("hitMaxRetries")),this.connection.on("backOffBeforeReconnect",t=>this.emit("backOffBeforeReconnect",t)),this.connection.on("connect",()=>{this.getInitialNotifications(),this.emit("connect"),t(this.connection)}),this.connection.on("fetchReady",()=>{this.fetchReady=!0}),this.connection.on("error",t=>{this.emit("error",t),e(t)})})}disconnect(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return(null!==this.connection?(this.connection.on("disconnect",()=>{this.cleanupListeners(),this.connection=null}),this.connection.unsubscribe(),this.connection.disconnect()):this.cleanupListeners(),null!==this.api&&(this.api=null),!0===t)?Promise.resolve(this):this}cleanupListeners(){this.removeAllListeners("self"),this.removeAllListeners("connectionInfo"),this.removeAllListeners("message"),this.removeAllListeners("delta"),this.removeAllListeners("connect"),this.removeAllListeners("error"),this.removeAllListeners("hitMaxRetries"),this.removeAllListeners("backOffBeforeReconnect"),this.removeAllListeners("disconnect"),this.removeAllListeners("unsubscribe"),this.removeAllListeners("subscribe")}API(){return null===this.connection?Promise.reject(Error("There are no available connections. Please connect before you use the REST API.")):null!==this.api?Promise.resolve(this.api):new Promise(t=>{if(this.api=new s.default(this.connection),!0===this.fetchReady||!1===this.options.useAuthentication)return t(this.api);this.connection.on("fetchReady",()=>{t(this.api)})})}processWSMessage(t){this.emit("message",t),t&&"object"==typeof t&&t.hasOwnProperty("updates")&&(this.checkAndEmitNotificationsInDelta(t),this.emit("delta",t))}checkAndEmitNotificationsInDelta(t){if(!1===this.options.notifications||!t||"object"!=typeof t||!Array.isArray(t.updates))return;let e={};t.updates.forEach(t=>{(t.values||[]).forEach(t=>{"string"==typeof t.path&&t.path.includes("notifications.")&&(e[t.path.replace("notifications.","")]=l({},t.value))})}),Object.keys(e).forEach(t=>{if(!this.notifications.hasOwnProperty(t)||this.notifications[t].timestamp!==e[t].timestamp){this.notifications[t]=l({},e[t]);let r=l({path:t},this.notifications[t]);h("[checkAndEmitNotificationsInDelta] emitting notification: ".concat(JSON.stringify(r,null,2))),this.emit("notification",r)}})}getInitialNotifications(){!1!==this.options.notifications&&null!==this.connection&&(null===this.api&&(this.api=new s.default(this.connection)),this.api.notifications().then(t=>(this.notifications=l(l({},this.notifications),y(t)),Object.keys(this.notifications).forEach(t=>{let e=l({path:t},this.notifications[t]);h("[getInitialNotifications] emitting notification: ".concat(JSON.stringify(e,null,2))),this.emit("notification",e)}),this.notifications)).catch(t=>{console.error("[getInitialNotifications] error getting notifications: ".concat(t.message))}))}}e.default=d;let y=t=>{let e={},r=t,n="",o=t=>{n+="".concat(""===n?"":".").concat(t),(r=r[t])&&"object"==typeof r&&(r&&"object"==typeof r&&r.hasOwnProperty("value")?e[n]=Object.assign({},r.value):Object.keys(r).forEach(o))};return Object.keys(r).forEach(t=>o(t)),e},g=t=>!!(t&&"object"==typeof t&&t.hasOwnProperty("context")&&Array.isArray(t.subscribe))},75178:function(t,e,r){"use strict";var n=r(40257);Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.SUPPORTED_STREAM_BEHAVIOUR=e.SUPPORTED_SEND_META=void 0,r(42344),r(53147),r(51887),r(79310),r(84134),r(34125),r(87042);var o=c(r(77625)),i=c(r(63819)),s=c(r(80751)),a=c(r(31464)),u=c(r(51983));function c(t){return t&&t.__esModule?t:{default:t}}function f(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function l(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?f(Object(r),!0).forEach(function(e){var n;n=r[e],e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}let h=(0,a.default)("signalk-js-sdk/Connection"),p=void 0!==n&&null!=n.versions&&null!=n.versions.node,d={self:"self",all:"all",none:"none"};e.SUPPORTED_STREAM_BEHAVIOUR=d;let y={all:"all"};e.SUPPORTED_SEND_META=y;class g extends o.default{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];super(),this.options=t,this.httpURI=this.buildURI("http"),this.wsURI=this.buildURI("ws"),this.shouldDisconnect=!1,this.connected=!1,this.socket=null,this.lastMessage=-1,this.isConnecting=!1,this.wsKeepaliveIntervalMs=1e3*this.options.wsKeepaliveInterval,this._fetchReady=!1,this._bearerTokenPrefix=this.options.bearerTokenPrefix||"Bearer",this._authenticated=!1,this._retries=0,this._connection=null,this._self="",this._subscriptions=e,this.sendKeepaliveWithReschedule=this.sendKeepaliveWithReschedule.bind(this),this.onWSMessage=this._onWSMessage.bind(this),this.onWSOpen=this._onWSOpen.bind(this),this.onWSClose=this._onWSClose.bind(this),this.onWSError=this._onWSError.bind(this),this._token={kind:"",token:""},this.reconnect(!0)}get retries(){return this._retries}set self(t){null!==t&&this.emit("self",t),this._self=t}get self(){return this._self}set connectionInfo(t){null!==t&&this.emit("connectionInfo",t),this._connection=t,this.self=t.self}get connectionInfo(){return this._connection}buildURI(t){let{useTLS:e,hostname:r,port:n,version:o,deltaStreamBehaviour:i,sendMeta:s}=this.options,a=!0===e?"".concat(t,"s://"):"".concat(t,"://");if(a+=r+(80===n?"":":".concat(n))+"/signalk/"+o,"ws"===t){a+="/stream";let t=[];i&&d.hasOwnProperty(i)&&""!==d[i]&&t.push("subscribe=".concat(d[i])),s&&y.hasOwnProperty(s)&&""!==y[s]&&t.push("sendMeta=".concat(y[s])),t&&(a+="?"+t.join("&"))}return"http"===t&&(a+="/api"),a}state(){return{connecting:this.isConnecting,connected:this.connected,ready:this.fetchReady}}disconnect(){h("[disconnect] called"),this.shouldDisconnect=!0,this.reconnect()}backOffAndReconnect(){if(!0===this.isConnecting)return;let{maxTimeBetweenRetries:t}=this.options,e=this._retries<Math.round(t/250)?250*this._retries:t;if(0===e)return this.reconnect();this.emit("backOffBeforeReconnect",e),h("[backOffAndReconnect] waiting ".concat(e," ms before reconnecting")),setTimeout(()=>this.reconnect(),e)}reconnect(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(!0===this.isConnecting)return;if(null!==this.socket){h("[reconnect] closing socket"),this.socket.close();return}if(!1===t&&(this._retries+=1),!0!==t&&this._retries===this.options.maxRetries){this.emit("hitMaxRetries"),this.cleanupListeners();return}if(!0!==t&&!1===this.options.reconnect){h("[reconnect] Not reconnecting, for reconnect is false"),this.cleanupListeners();return}if(!0!==t&&!0===this.shouldDisconnect){h("[reconnect] not reconnecting, shouldDisconnect is true"),this.cleanupListeners();return}if(h("[reconnect] socket is ".concat(null===this.socket?"":"not ","NULL")),this._fetchReady=!1,this.shouldDisconnect=!1,this.isConnecting=!0,!1===this.options.useAuthentication){this._fetchReady=!0,this.emit("fetchReady"),this.initiateSocket();return}let e={method:"POST",mode:"cors",credentials:"same-origin",body:JSON.stringify({username:String(this.options.username||""),password:String(this.options.password||"")})};return this.fetch("/auth/login",e).then(t=>{if(!t||"object"!=typeof t||!t.hasOwnProperty("token"))throw Error("Unexpected response from auth endpoint: ".concat(JSON.stringify(t)));h("[reconnect] successful auth request: ".concat(JSON.stringify(t,null,2))),this._authenticated=!0,this._token={kind:"string"==typeof t.type&&""!==t.type.trim()?t.type:this._bearerTokenPrefix,token:t.token},this._fetchReady=!0,this.emit("fetchReady"),this.initiateSocket()}).catch(t=>(h("[reconnect] error logging in: ".concat(t.message,", reconnecting")),this.emit("error",t),this._retries+=1,this.isConnecting=!1,this.backOffAndReconnect()))}setAuthenticated(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"JWT";this.emit("fetchReady"),this._authenticated=!0,this._token={kind:e,token:t}}initiateSocket(){p&&this.options.useTLS&&!1===this.options.rejectUnauthorized?this.socket=new i.default(this.wsURI,{rejectUnauthorized:!1}):this.socket=new i.default(this.wsURI),this.socket.addEventListener("message",this.onWSMessage),this.socket.addEventListener("open",this.onWSOpen),this.socket.addEventListener("error",this.onWSError),this.socket.addEventListener("close",this.onWSClose)}cleanupListeners(){h("[cleanupListeners] resetting auth and removing listeners"),this._authenticated=!1,this._token={kind:"",token:""},this.removeAllListeners()}sendKeepaliveWithReschedule(){!0===this.connected&&(this.lastMessage<Date.now()-this.wsKeepaliveIntervalMs&&this.socket.send("{}"),setTimeout(this.sendKeepaliveWithReschedule,this.wsKeepaliveIntervalMs))}_onWSMessage(t){this.lastMessage=Date.now();let e=t.data;try{"string"==typeof e&&(e=JSON.parse(e))}catch(t){console.error("[Connection: ".concat(this.options.hostname,"] Error parsing data: ").concat(t.message))}e&&"object"==typeof e&&e.hasOwnProperty("name")&&e.hasOwnProperty("version")&&e.hasOwnProperty("roles")&&(this.connectionInfo=e),this.emit("message",e)}_onWSOpen(){if(this.connected=!0,this.isConnecting=!1,this._subscriptions.length>0){let t=b(this._subscriptions);this.subscribe(t)}this._retries=0,this.options.wsKeepaliveInterval>0&&this.sendKeepaliveWithReschedule(),this.emit("connect")}_onWSError(t){h("[_onWSError] WS error",t.message||""),this.emit("error",t),this.backOffAndReconnect()}_onWSClose(t){h("[_onWSClose] called with wsURI:",this.wsURI),this.socket.removeEventListener("message",this.onWSMessage),this.socket.removeEventListener("open",this.onWSOpen),this.socket.removeEventListener("error",this.onWSError),this.socket.removeEventListener("close",this.onWSClose),this.connected=!1,this.isConnecting=!1,this.socket=null,this.emit("disconnect",t),this.backOffAndReconnect()}unsubscribe(){if(!0!==this.connected||null===this.socket){h("Not connected to socket");return}this.send(JSON.stringify({context:"*",unsubscribe:[{path:"*"}]}))}subscribe(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];!Array.isArray(t)&&t&&"object"==typeof t&&t.hasOwnProperty("subscribe")&&(t=[t]),t.forEach(t=>{this.send(JSON.stringify(t))})}send(t){if(!0!==this.connected||null===this.socket)return Promise.reject(Error("Not connected to WebSocket"));if("string"==typeof t)try{t=JSON.parse(t)}catch(t){h("[send] data is string but not valid JSON: ".concat(t.message))}let e=t&&"object"==typeof t;try{e&&(t=JSON.stringify(t))}catch(t){return Promise.reject(t)}return h("Sending data to socket: ".concat(t)),Promise.resolve(this.socket.send(t))}fetch(t,e){"/"!==t.charAt(0)&&(t="/".concat(t)),e&&"object"==typeof e||(e={method:"GET"}),e.headers&&"object"==typeof e.headers||(e.headers={Accept:"application/json","Content-Type":"application/json"}),!0!==this._authenticated||t.includes("auth/login")||(e.headers=l(l({},e.headers),{},{Authorization:"".concat(this._token.kind," ").concat(this._token.token)}),e.credentials="same-origin",e.mode="cors",h("[fetch] enriching fetch options with in-memory token")),p&&this.options.useTLS&&!1===this.options.rejectUnauthorized&&(e.agent=new u.default.Agent({rejectUnauthorized:!1}));let r="".concat(this.httpURI).concat(t);return r.includes("/api/auth/login")&&(r=r.replace("/api/auth/login","/auth/login")),r.includes("/api/access/requests")&&(r=r.replace("/api/access/requests","/access/requests")),r.includes("/signalk/v1/api/security")&&(r=r.replace("/signalk/v1/api/security","/security")),h("[fetch] ".concat(e.method||"GET"," ").concat(r," ").concat(JSON.stringify(e,null,2))),(0,s.default)(r,e).then(t=>{if(!t.ok)throw Error("Error fetching ".concat(r,": ").concat(t.status," ").concat(t.statusText));return t.headers.get("content-type").includes("application/json")?t.json():t.text()})}}e.default=g;let b=t=>{let e={};return t.forEach(t=>{Array.isArray(e[t.context])||(e[t.context]=[]),e[t.context]=e[t.context].concat(t.subscribe)}),Object.keys(e).map(t=>{let r={context:t,subscribe:e[t]};if(r.subscribe.length>0){let t=[];r.subscribe=r.subscribe.reduce((e,r)=>{if(t.includes(r.path)){let t=e.findIndex(t=>t.path===r.path);-1!==t&&e.splice(t,1)}else t.push(r.path);return e.push(r),e},[])}return r})}},95193:function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.SKServer=void 0,r(51887),r(79310),r(10127),r(35998),r(84134),r(73602),r(42344),r(87042);var n=i(r(77625)),o=i(r(48595));function i(t){return t&&t.__esModule?t:{default:t}}function s(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?s(Object(r),!0).forEach(function(e){var n;n=r[e],e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}class u{constructor(t){this._roles=t.roles||["master","main"],this._self=t.self||"",this._version=t.version||"0.0.0",this._hostname=t.hostname,this._port=t.port}get roles(){return this._roles}get self(){return this._self}get version(){return this._version}get hostname(){return this._hostname}get port(){return this._port}isMain(){return this._roles.includes("main")}isMaster(){return this._roles.includes("master")}createClient(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new o.default(a(a({},t),{},{hostname:this._hostname,port:this._port}))}}e.SKServer=u;class c extends n.default{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6e4;if(super(),this.found=[],!t||"object"!=typeof t)throw Error("No mDNS provider given");if(Object.keys(t).join(",").startsWith("_server,_registry"))return this.discoverWithBonjour(t,e);if(Object.keys(t).join(",").startsWith("dns_sd,Advertisement,createAdvertisement,Browser"))return this.discoverWithMdns(t,e);throw Error("Unrecognized mDNS provider given")}discoverWithBonjour(t,e){let r=t.find({type:"signalk-http"});r.on("up",t=>this.handleDiscoveredService(t,a(a({},t.txt),{},{name:t.name||"",hostname:t.host||"",port:parseInt(t.port,10),provider:"bonjour"}))),setTimeout(()=>{0===this.found.length&&this.emit("timeout"),r.stop()},e),r.start()}discoverWithMdns(t,e){let r=t.createBrowser(t.tcp("_signalk-http"));r.on("serviceUp",t=>this.handleDiscoveredService(t,a(a({},t.txtRecord),{},{hostname:t.host||"",port:parseInt(t.port,10),provider:"mdns"}))),r.on("error",t=>this.handleDiscoveryError(t)),setTimeout(()=>{0===this.found.length&&this.emit("timeout"),r.stop()},e),r.start()}handleDiscoveryError(t){console.error("Error during discovery: ".concat(t.message))}handleDiscoveredService(t,e){"string"==typeof e.roles&&(e.roles=e.roles.split(",").map(t=>t.trim().toLowerCase())),e.roles=Array.isArray(e.roles)?e.roles:[];let r=e.hostname;Array.isArray(t.addresses)&&(r=t.addresses.reduce((t,e)=>(e&&"string"==typeof e&&e.includes(".")&&(t=e),t),e.hostname)),""!==r.trim()&&(e.hostname=r);let n=new u(e);this.found.push(n),this.emit("found",n)}}e.default=c},11981:function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=s(r(77625)),o=s(r(31464)),i=r(24536);function s(t){return t&&t.__esModule?t:{default:t}}function a(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?a(Object(r),!0).forEach(function(e){var n;n=r[e],e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}let c=(0,o.default)("signalk-js-sdk/Request");class f extends n.default{constructor(t,e,r){super(),this.connection=t,this.requestId=(0,i.v4)(),this.name=e,this.body=r,this.responses=[],this.sent=!1,this.connection.on("message",t=>{t&&"object"==typeof t&&t.hasOwnProperty("requestId")&&t.requestId===this.requestId&&this.addResponse(t)})}query(){let t={requestId:this.requestId,query:!0};c("Sending query: ".concat(JSON.stringify(t,null,2))),this.connection.send(t)}send(){if(!0===this.sent)return;let t=u({requestId:this.requestId},this.body);c("Sending request: ".concat(JSON.stringify(t,null,2))),this.connection.send(t)}addResponse(t){c('Got response for request "'.concat(this.name,'": ').concat(JSON.stringify(t,null,2)));let e=new Date().toISOString();this.responses.push({response:t,receivedAt:e}),this.emit("response",u(u({},t),{},{request:{receivedAt:e,name:this.name,requestId:this.requestId}}))}getRequestId(){return this.requestId}}e.default=f},14578:function(t,e,r){t.exports=r(35323)},59196:function(t,e){"use strict";e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return(r+n)*3/4-n},e.toByteArray=function(t){var e,r,i=u(t),s=i[0],a=i[1],c=new o((s+a)*3/4-a),f=0,l=a>0?s-4:s;for(r=0;r<l;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],c[f++]=e>>16&255,c[f++]=e>>8&255,c[f++]=255&e;return 2===a&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,c[f++]=255&e),1===a&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,c[f++]=e>>8&255,c[f++]=255&e),c},e.fromByteArray=function(t){for(var e,n=t.length,o=n%3,i=[],s=0,a=n-o;s<a;s+=16383)i.push(function(t,e,n){for(var o,i=[],s=e;s<n;s+=3)i.push(r[(o=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]))>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return i.join("")}(t,s,s+16383>a?a:s+16383));return 1===o?i.push(r[(e=t[n-1])>>2]+r[e<<4&63]+"=="):2===o&&i.push(r[(e=(t[n-2]<<8)+t[n-1])>>10]+r[e>>4&63]+r[e<<2&63]+"="),i.join("")};for(var r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,a=i.length;s<a;++s)r[s]=i[s],n[i.charCodeAt(s)]=s;function u(t){var e=t.length;if(e%4>0)throw Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");-1===r&&(r=e);var n=r===e?0:4-r%4;return[r,n]}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},82957:function(t,e,r){"use strict";let n=r(59196),o=r(68848),i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;function s(t){if(t>2147483647)throw RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,a.prototype),e}function a(t,e,r){if("number"==typeof t){if("string"==typeof e)throw TypeError('The "string" argument must be of type string. Received type number');return f(t)}return u(t,e,r)}function u(t,e,r){if("string"==typeof t)return function(t,e){if(("string"!=typeof e||""===e)&&(e="utf8"),!a.isEncoding(e))throw TypeError("Unknown encoding: "+e);let r=0|d(t,e),n=s(r),o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(N(t,Uint8Array)){let e=new Uint8Array(t);return h(e.buffer,e.byteOffset,e.byteLength)}return l(t)}(t);if(null==t)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(N(t,ArrayBuffer)||t&&N(t.buffer,ArrayBuffer)||"undefined"!=typeof SharedArrayBuffer&&(N(t,SharedArrayBuffer)||t&&N(t.buffer,SharedArrayBuffer)))return h(t,e,r);if("number"==typeof t)throw TypeError('The "value" argument must not be of type number. Received type number');let n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return a.from(n,e,r);let o=function(t){var e;if(a.isBuffer(t)){let e=0|p(t.length),r=s(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||(e=t.length)!=e?s(0):l(t):"Buffer"===t.type&&Array.isArray(t.data)?l(t.data):void 0}(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return a.from(t[Symbol.toPrimitive]("string"),e,r);throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function c(t){if("number"!=typeof t)throw TypeError('"size" argument must be of type number');if(t<0)throw RangeError('The value "'+t+'" is invalid for option "size"')}function f(t){return c(t),s(t<0?0:0|p(t))}function l(t){let e=t.length<0?0:0|p(t.length),r=s(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function h(t,e,r){let n;if(e<0||t.byteLength<e)throw RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw RangeError('"length" is outside of buffer bounds');return Object.setPrototypeOf(n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),a.prototype),n}function p(t){if(t>=2147483647)throw RangeError("Attempt to allocate Buffer larger than maximum size: 0x7fffffff bytes");return 0|t}function d(t,e){if(a.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||N(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let o=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return I(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return D(t).length;default:if(o)return n?-1:I(t).length;e=(""+e).toLowerCase(),o=!0}}function y(t,e,r){let o=!1;if((void 0===e||e<0)&&(e=0),e>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0||(r>>>=0)<=(e>>>=0)))return"";for(t||(t="utf8");;)switch(t){case"hex":return function(t,e,r){let n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let o="";for(let n=e;n<r;++n)o+=U[t[n]];return o}(this,e,r);case"utf8":case"utf-8":return m(this,e,r);case"ascii":return function(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}(this,e,r);case"latin1":case"binary":return function(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}(this,e,r);case"base64":var i,s;return i=e,s=r,0===i&&s===this.length?n.fromByteArray(this):n.fromByteArray(this.slice(i,s));case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return function(t,e,r){let n=t.slice(e,r),o="";for(let t=0;t<n.length-1;t+=2)o+=String.fromCharCode(n[t]+256*n[t+1]);return o}(this,e,r);default:if(o)throw TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),o=!0}}function g(t,e,r){let n=t[e];t[e]=t[r],t[r]=n}function b(t,e,r,n,o){var i;if(0===t.length)return -1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),(i=r=+r)!=i&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return -1;r=t.length-1}else if(r<0){if(!o)return -1;r=0}if("string"==typeof e&&(e=a.from(e,n)),a.isBuffer(e))return 0===e.length?-1:v(t,e,r,n,o);if("number"==typeof e)return(e&=255,"function"==typeof Uint8Array.prototype.indexOf)?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):v(t,[e],r,n,o);throw TypeError("val must be string, number or Buffer")}function v(t,e,r,n,o){let i,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return -1;s=2,a/=2,u/=2,r/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){let n=-1;for(i=r;i<a;i++)if(c(t,i)===c(e,-1===n?0:i-n)){if(-1===n&&(n=i),i-n+1===u)return n*s}else -1!==n&&(i-=i-n),n=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){let r=!0;for(let n=0;n<u;n++)if(c(t,i+n)!==c(e,n)){r=!1;break}if(r)return i}return -1}function m(t,e,r){r=Math.min(t.length,r);let n=[],o=e;for(;o<r;){let e=t[o],i=null,s=e>239?4:e>223?3:e>191?2:1;if(o+s<=r){let r,n,a,u;switch(s){case 1:e<128&&(i=e);break;case 2:(192&(r=t[o+1]))==128&&(u=(31&e)<<6|63&r)>127&&(i=u);break;case 3:r=t[o+1],n=t[o+2],(192&r)==128&&(192&n)==128&&(u=(15&e)<<12|(63&r)<<6|63&n)>2047&&(u<55296||u>57343)&&(i=u);break;case 4:r=t[o+1],n=t[o+2],a=t[o+3],(192&r)==128&&(192&n)==128&&(192&a)==128&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&a)>65535&&u<1114112&&(i=u)}}null===i?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|1023&i),n.push(i),o+=s}return function(t){let e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return r}(n)}function w(t,e,r){if(t%1!=0||t<0)throw RangeError("offset is not uint");if(t+e>r)throw RangeError("Trying to access beyond buffer length")}function S(t,e,r,n,o,i){if(!a.isBuffer(t))throw TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw RangeError('"value" argument is out of bounds');if(r+n>t.length)throw RangeError("Index out of range")}function _(t,e,r,n,o){j(e,n,o,t,r,7);let i=Number(e&BigInt(4294967295));t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,r}function E(t,e,r,n,o){j(e,n,o,t,r,7);let i=Number(e&BigInt(4294967295));t[r+7]=i,i>>=8,t[r+6]=i,i>>=8,t[r+5]=i,i>>=8,t[r+4]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s>>=8,t[r+2]=s,s>>=8,t[r+1]=s,s>>=8,t[r]=s,r+8}function O(t,e,r,n,o,i){if(r+n>t.length||r<0)throw RangeError("Index out of range")}function x(t,e,r,n,i){return e=+e,r>>>=0,i||O(t,e,r,4,34028234663852886e22,-34028234663852886e22),o.write(t,e,r,n,23,4),r+4}function A(t,e,r,n,i){return e=+e,r>>>=0,i||O(t,e,r,8,17976931348623157e292,-17976931348623157e292),o.write(t,e,r,n,52,8),r+8}e.Buffer=a,e.SlowBuffer=function(t){return+t!=t&&(t=0),a.alloc(+t)},e.INSPECT_MAX_BYTES=50,e.kMaxLength=2147483647,a.TYPED_ARRAY_SUPPORT=function(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),a.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}}),a.poolSize=8192,a.from=function(t,e,r){return u(t,e,r)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array),a.alloc=function(t,e,r){return(c(t),t<=0)?s(t):void 0!==e?"string"==typeof r?s(t).fill(e,r):s(t).fill(e):s(t)},a.allocUnsafe=function(t){return f(t)},a.allocUnsafeSlow=function(t){return f(t)},a.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==a.prototype},a.compare=function(t,e){if(N(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),N(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(t)||!a.isBuffer(e))throw TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,e){let r;if(!Array.isArray(t))throw TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return a.alloc(0);if(void 0===e)for(r=0,e=0;r<t.length;++r)e+=t[r].length;let n=a.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){let e=t[r];if(N(e,Uint8Array))o+e.length>n.length?(a.isBuffer(e)||(e=a.from(e)),e.copy(n,o)):Uint8Array.prototype.set.call(n,e,o);else if(a.isBuffer(e))e.copy(n,o);else throw TypeError('"list" argument must be an Array of Buffers');o+=e.length}return n},a.byteLength=d,a.prototype._isBuffer=!0,a.prototype.swap16=function(){let t=this.length;if(t%2!=0)throw RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},a.prototype.swap32=function(){let t=this.length;if(t%4!=0)throw RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},a.prototype.swap64=function(){let t=this.length;if(t%8!=0)throw RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},a.prototype.toString=function(){let t=this.length;return 0===t?"":0==arguments.length?m(this,0,t):y.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(t){if(!a.isBuffer(t))throw TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){let t="",r=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},i&&(a.prototype[i]=a.prototype.inspect),a.prototype.compare=function(t,e,r,n,o){if(N(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(t))throw TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return -1;if(e>=r)return 1;if(e>>>=0,r>>>=0,n>>>=0,o>>>=0,this===t)return 0;let i=o-n,s=r-e,u=Math.min(i,s),c=this.slice(n,o),f=t.slice(e,r);for(let t=0;t<u;++t)if(c[t]!==f[t]){i=c[t],s=f[t];break}return i<s?-1:s<i?1:0},a.prototype.includes=function(t,e,r){return -1!==this.indexOf(t,e,r)},a.prototype.indexOf=function(t,e,r){return b(this,t,e,r,!0)},a.prototype.lastIndexOf=function(t,e,r){return b(this,t,e,r,!1)},a.prototype.write=function(t,e,r,n){var o,i,s,a,u,c,f,l;if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else if(isFinite(e))e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0);else throw Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let h=this.length-e;if((void 0===r||r>h)&&(r=h),t.length>0&&(r<0||e<0)||e>this.length)throw RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let p=!1;for(;;)switch(n){case"hex":return function(t,e,r,n){let o;r=Number(r)||0;let i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;let s=e.length;for(n>s/2&&(n=s/2),o=0;o<n;++o){let n=parseInt(e.substr(2*o,2),16);if(n!=n)break;t[r+o]=n}return o}(this,t,e,r);case"utf8":case"utf-8":return o=e,i=r,L(I(t,this.length-o),this,o,i);case"ascii":case"latin1":case"binary":return s=e,a=r,L(function(t){let e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(t),this,s,a);case"base64":return u=e,c=r,L(D(t),this,u,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return f=e,l=r,L(function(t,e){let r,n;let o=[];for(let i=0;i<t.length&&!((e-=2)<0);++i)n=(r=t.charCodeAt(i))>>8,o.push(r%256),o.push(n);return o}(t,this.length-f),this,f,l);default:if(p)throw TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),p=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},a.prototype.slice=function(t,e){let r=this.length;t=~~t,e=void 0===e?r:~~e,t<0?(t+=r)<0&&(t=0):t>r&&(t=r),e<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);let n=this.subarray(t,e);return Object.setPrototypeOf(n,a.prototype),n},a.prototype.readUintLE=a.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||w(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return n},a.prototype.readUintBE=a.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||w(t,e,this.length);let n=this[t+--e],o=1;for(;e>0&&(o*=256);)n+=this[t+--e]*o;return n},a.prototype.readUint8=a.prototype.readUInt8=function(t,e){return t>>>=0,e||w(t,1,this.length),this[t]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(t,e){return t>>>=0,e||w(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(t,e){return t>>>=0,e||w(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(t,e){return t>>>=0,e||w(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(t,e){return t>>>=0,e||w(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readBigUInt64LE=B(function(t){C(t>>>=0,"offset");let e=this[t],r=this[t+7];(void 0===e||void 0===r)&&k(t,this.length-8);let n=e+256*this[++t]+65536*this[++t]+16777216*this[++t],o=this[++t]+256*this[++t]+65536*this[++t]+16777216*r;return BigInt(n)+(BigInt(o)<<BigInt(32))}),a.prototype.readBigUInt64BE=B(function(t){C(t>>>=0,"offset");let e=this[t],r=this[t+7];(void 0===e||void 0===r)&&k(t,this.length-8);let n=16777216*e+65536*this[++t]+256*this[++t]+this[++t],o=16777216*this[++t]+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(o)}),a.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||w(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},a.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||w(t,e,this.length);let n=e,o=1,i=this[t+--n];for(;n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},a.prototype.readInt8=function(t,e){return(t>>>=0,e||w(t,1,this.length),128&this[t])?-((255-this[t]+1)*1):this[t]},a.prototype.readInt16LE=function(t,e){t>>>=0,e||w(t,2,this.length);let r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt16BE=function(t,e){t>>>=0,e||w(t,2,this.length);let r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt32LE=function(t,e){return t>>>=0,e||w(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,e){return t>>>=0,e||w(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readBigInt64LE=B(function(t){C(t>>>=0,"offset");let e=this[t],r=this[t+7];return(void 0===e||void 0===r)&&k(t,this.length-8),(BigInt(this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24))<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+16777216*this[++t])}),a.prototype.readBigInt64BE=B(function(t){C(t>>>=0,"offset");let e=this[t],r=this[t+7];return(void 0===e||void 0===r)&&k(t,this.length-8),(BigInt((e<<24)+65536*this[++t]+256*this[++t]+this[++t])<<BigInt(32))+BigInt(16777216*this[++t]+65536*this[++t]+256*this[++t]+r)}),a.prototype.readFloatLE=function(t,e){return t>>>=0,e||w(t,4,this.length),o.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,e){return t>>>=0,e||w(t,4,this.length),o.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,e){return t>>>=0,e||w(t,8,this.length),o.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,e){return t>>>=0,e||w(t,8,this.length),o.read(this,t,!1,52,8)},a.prototype.writeUintLE=a.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){let n=Math.pow(2,8*r)-1;S(this,t,e,r,n,0)}let o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){let n=Math.pow(2,8*r)-1;S(this,t,e,r,n,0)}let o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},a.prototype.writeUint8=a.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,1,255,0),this[e]=255&t,e+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},a.prototype.writeBigUInt64LE=B(function(t,e=0){return _(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=B(function(t,e=0){return E(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){let n=Math.pow(2,8*r-1);S(this,t,e,r,n-1,-n)}let o=0,i=1,s=0;for(this[e]=255&t;++o<r&&(i*=256);)t<0&&0===s&&0!==this[e+o-1]&&(s=1),this[e+o]=(t/i>>0)-s&255;return e+r},a.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){let n=Math.pow(2,8*r-1);S(this,t,e,r,n-1,-n)}let o=r-1,i=1,s=0;for(this[e+o]=255&t;--o>=0&&(i*=256);)t<0&&0===s&&0!==this[e+o+1]&&(s=1),this[e+o]=(t/i>>0)-s&255;return e+r},a.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},a.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},a.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},a.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},a.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||S(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},a.prototype.writeBigInt64LE=B(function(t,e=0){return _(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=B(function(t,e=0){return E(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeFloatLE=function(t,e,r){return x(this,t,e,!0,r)},a.prototype.writeFloatBE=function(t,e,r){return x(this,t,e,!1,r)},a.prototype.writeDoubleLE=function(t,e,r){return A(this,t,e,!0,r)},a.prototype.writeDoubleBE=function(t,e,r){return A(this,t,e,!1,r)},a.prototype.copy=function(t,e,r,n){if(!a.isBuffer(t))throw TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r||0===t.length||0===this.length)return 0;if(e<0)throw RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw RangeError("Index out of range");if(n<0)throw RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);let o=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),o},a.prototype.fill=function(t,e,r,n){let o;if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw TypeError("encoding must be a string");if("string"==typeof n&&!a.isEncoding(n))throw TypeError("Unknown encoding: "+n);if(1===t.length){let e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw RangeError("Out of range index");if(r<=e)return this;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{let i=a.isBuffer(t)?t:a.from(t,n),s=i.length;if(0===s)throw TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<r-e;++o)this[o+e]=i[o%s]}return this};let R={};function P(t,e,r){R[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function T(t){let e="",r=t.length,n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function j(t,e,r,n,o,i){if(t>r||t<e){let n;let o="bigint"==typeof e?"n":"";throw n=i>3?0===e||e===BigInt(0)?`>= 0${o} and < 2${o} ** ${(i+1)*8}${o}`:`>= -(2${o} ** ${(i+1)*8-1}${o}) and < 2 ** ${(i+1)*8-1}${o}`:`>= ${e}${o} and <= ${r}${o}`,new R.ERR_OUT_OF_RANGE("value",n,t)}C(o,"offset"),(void 0===n[o]||void 0===n[o+i])&&k(o,n.length-(i+1))}function C(t,e){if("number"!=typeof t)throw new R.ERR_INVALID_ARG_TYPE(e,"number",t)}function k(t,e,r){if(Math.floor(t)!==t)throw C(t,r),new R.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new R.ERR_BUFFER_OUT_OF_BOUNDS;throw