(self.webpackJsonp=self.webpackJsonp||[]).push([[56],{202:function(e,t,n){"use strict";n.r(t);var s=n(117);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class r{constructor(){a(this,"commands",{}),a(this,"cache",{}),a(this,"msgId",0)}attach(){var e;e=this,window.addEventListener("connection-status",t=>e.fireMessage({type:"connection-status",payload:{event:t.detail}})),(e=>{window.addEventListener("haptic",t=>e.fireMessage({type:"haptic",payload:{hapticType:t.detail}}))})(this),window.externalBus=e=>this.receiveMessage(e)}sendMessage(e){const t=++this.msgId;return e.id=t,this.fireMessage(e),new Promise((e,n)=>{this.commands[t]={resolve:e,reject:n}})}fireMessage(e){e.id||(e.id=++this.msgId),this._sendExternal(e)}receiveMessage(e){const t=this.commands[e.id];t?"result"===e.type&&(e.success?t.resolve(e.result):t.reject(e.error)):console.warn("Received unknown msg ID",e.id)}_sendExternal(e){window.externalApp?window.externalApp.externalBus(JSON.stringify(e)):window.webkit.messageHandlers.externalBus.postMessage(e)}}n.d(t,"ExternalAuth",(function(){return i})),n.d(t,"createExternalAuth",(function(){return o}));if(!window.externalApp&&!window.webkit)throw new Error("External auth requires either externalApp or webkit defined on Window object.");class i extends s.a{constructor(e){var t,n,s;super({hassUrl:e,clientId:"",refresh_token:"",access_token:"",expires_in:0,expires:0}),s=void 0,(n="external")in(t=this)?Object.defineProperty(t,n,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[n]=s}async refreshAccessToken(e){const t={callback:"externalAuthSetToken"};e&&(t.force=!0);const n=new Promise((e,t)=>{window.externalAuthSetToken=(n,s)=>n?e(s):t(s)});await 0,window.externalApp?window.externalApp.getExternalAuth(JSON.stringify(t)):window.webkit.messageHandlers.getExternalAuth.postMessage(t);const s=await n;this.data.access_token=s.access_token,this.data.expires=1e3*s.expires_in+Date.now()}async revoke(){const e={callback:"externalAuthRevokeToken"},t=new Promise((e,t)=>{window.externalAuthRevokeToken=(n,s)=>n?e(s):t(s)});await 0,window.externalApp?window.externalApp.revokeExternalAuth(JSON.stringify(e)):window.webkit.messageHandlers.revokeExternalAuth.postMessage(e),await t}}const o=e=>{const t=new i(e);return(window.externalApp&&window.externalApp.externalBus||window.webkit&&window.webkit.messageHandlers.externalBus)&&(t.external=new r,t.external.attach()),t}}}]);
//# sourceMappingURL=chunk.670663c49370b7ded695.js.map