(self.webpackChunkbeyondwords_wordpress_plugin=self.webpackChunkbeyondwords_wordpress_plugin||[]).push([[968],{8131:function(t,n,e){"use strict";e.d(n,{a:function(){return s},e:function(){return i},g:function(){return r}});var o=e(614);const i=(0,o.e)(o.g.processed),s=(0,o.e)(o.g.processing),r=t=>t?new Date(t).valueOf():0},2968:function(t,n,e){"use strict";e.r(n),e.d(n,{getMiddleware:function(){return l}});var o=e(614),i=(e(1978),e(8392)),s=e.n(i),r=e(8131);const c=(0,o.c)((t=>JSON.parse(t||'{"exp": 0}')),(([,t])=>{try{const n=window.atob(t||"");return/^\{.*exp.*}$/i.test(n)?n:null}catch(t){return null}}),(t=>t.split(".")||[]),String),u=t=>c(t).exp>(0,o.p)(Date.now()/1e3),l=({appReady:t,setParams:n,updatePlaylist:e,appDestroy:i})=>{let c,l=o.j;const a=t=>(i,s)=>{const{app:{podcasts:c}}=s(),u=(0,o.i)(t.media)&&t.media.length;if((0,r.e)(t.state)&&u){const n=(0,o.m)((0,o.o)(["media"],(0,o.h)(c)||{}),{media:[].concat(t.media),state:t.state,processing_at:t.processing_at});i(e([n]))}i(n({useStatusBox:(0,o.n)((0,r.e)(t.state)),podcastState:t.state}))},p=(t,n)=>async({error:e,result:i})=>{if(e)return;const{app:{podcasts:s}}=n(),c=(0,o.h)(s||[])||{};if((0,o.e)(c.podcast_id,i.podcast_id)&&(0,r.g)(i.updated_at)>(0,r.g)(c.processing_at)){if((0,r.e)(i.state))return t(a(await l()));t(a({state:i.state}))}},h=async(t,e,{getState:i,dispatch:h})=>{const{app:{apiKey:d,skBackendApi:f,initParams:g,wsToken:y,apiWriteKey:m,useStatusBox:v,podcastState:b}}=i(),{projectId:S,podcastId:w,externalId:A}=g;l=(({apiKey:t,skBackendApi:n,projectId:e,podcastId:i})=>async()=>{const{data:s}=await(0,o.k)({apiKey:t,skBackendApi:n,projectId:e,podcastId:i});return s})({apiKey:d,skBackendApi:f,projectId:S,podcastId:w||A}),!(0,r.e)(b)&&b||!(0,o.n)(v)||h(a(await l()));let k=y;if((0,o.n)(k)&&(0,o.n)(u(k))){const{data:t}=await(0,o.r)({skBackendApi:f,writeKey:m});k=t.token}k&&u(k)&&(0,o.n)((0,o.e)(k,y))&&h(n({wsToken:k})),c||(c=s().createConsumer(`wss://${(0,o.b)(f)}/cable?token=${k}`),c.subscriptions.create({channel:"Api::V1::ProjectChannel",id:S},{received:h(p),disconnected:()=>{c&&(0,o.d)(c.disconnect)&&(c.disconnect(),c=null)}}))};return(0,o.a)({[t]:h,[n]:async(t,n,e,i)=>{if((0,o.f)("useStatusBox",t)&&t.useStatusBox){if(i.app.useStatusBox)return;return h.apply(null,[(0,o.m)(t,{podcastState:o.g.processing}),n,e,i])}},[i]:()=>{c&&(0,o.d)(c.disconnect)&&(c.disconnect(),c=null)}})}},8392:function(t,n,e){var o,i;(function(){(function(){(function(){var t=[].slice;this.ActionCable={INTERNAL:{message_types:{welcome:"welcome",ping:"ping",confirmation:"confirm_subscription",rejection:"reject_subscription"},default_mount_path:"/cable",protocols:["actioncable-v1-json","actioncable-unsupported"]},WebSocket:window.WebSocket,logger:window.console,createConsumer:function(t){var n;return null==t&&(t=null!=(n=this.getConfig("url"))?n:this.INTERNAL.default_mount_path),new s.Consumer(this.createWebSocketURL(t))},getConfig:function(t){var n;return null!=(n=document.head.querySelector("meta[name='action-cable-"+t+"']"))?n.getAttribute("content"):void 0},createWebSocketURL:function(t){var n;return t&&!/^wss?:/i.test(t)?((n=document.createElement("a")).href=t,n.href=n.href,n.protocol=n.protocol.replace("http","ws"),n.href):t},startDebugging:function(){return this.debugging=!0},stopDebugging:function(){return this.debugging=null},log:function(){var n,e;if(n=1<=arguments.length?t.call(arguments,0):[],this.debugging)return n.push(Date.now()),(e=this.logger).log.apply(e,["[ActionCable]"].concat(t.call(n)))}}}).call(this)}).call(this);var s=this.ActionCable;(function(){(function(){s.ConnectionMonitor=function(){var t,n,e;function o(t){var n,e;this.connection=t,this.visibilityDidChange=(n=this.visibilityDidChange,e=this,function(){return n.apply(e,arguments)}),this.reconnectAttempts=0}return o.pollInterval={min:3,max:30},o.staleThreshold=6,o.prototype.start=function(){if(!this.isRunning())return this.startedAt=n(),delete this.stoppedAt,this.startPolling(),document.addEventListener("visibilitychange",this.visibilityDidChange),s.log("ConnectionMonitor started. pollInterval = "+this.getPollInterval()+" ms")},o.prototype.stop=function(){if(this.isRunning())return this.stoppedAt=n(),this.stopPolling(),document.removeEventListener("visibilitychange",this.visibilityDidChange),s.log("ConnectionMonitor stopped")},o.prototype.isRunning=function(){return null!=this.startedAt&&null==this.stoppedAt},o.prototype.recordPing=function(){return this.pingedAt=n()},o.prototype.recordConnect=function(){return this.reconnectAttempts=0,this.recordPing(),delete this.disconnectedAt,s.log("ConnectionMonitor recorded connect")},o.prototype.recordDisconnect=function(){return this.disconnectedAt=n(),s.log("ConnectionMonitor recorded disconnect")},o.prototype.startPolling=function(){return this.stopPolling(),this.poll()},o.prototype.stopPolling=function(){return clearTimeout(this.pollTimeout)},o.prototype.poll=function(){return this.pollTimeout=setTimeout((t=this,function(){return t.reconnectIfStale(),t.poll()}),this.getPollInterval());var t},o.prototype.getPollInterval=function(){var n,e,o,i;return o=(i=this.constructor.pollInterval).min,e=i.max,n=5*Math.log(this.reconnectAttempts+1),Math.round(1e3*t(n,o,e))},o.prototype.reconnectIfStale=function(){if(this.connectionIsStale())return s.log("ConnectionMonitor detected stale connection. reconnectAttempts = "+this.reconnectAttempts+", pollInterval = "+this.getPollInterval()+" ms, time disconnected = "+e(this.disconnectedAt)+" s, stale threshold = "+this.constructor.staleThreshold+" s"),this.reconnectAttempts++,this.disconnectedRecently()?s.log("ConnectionMonitor skipping reopening recent disconnect"):(s.log("ConnectionMonitor reopening"),this.connection.reopen())},o.prototype.connectionIsStale=function(){var t;return e(null!=(t=this.pingedAt)?t:this.startedAt)>this.constructor.staleThreshold},o.prototype.disconnectedRecently=function(){return this.disconnectedAt&&e(this.disconnectedAt)=0},t.prototype.isState=function(){var t,n;return n=1<=arguments.length?r.call(arguments,0):[],t=this.getState(),c.call(n,t)>=0},t.prototype.getState=function(){var t,n;for(n in WebSocket)if(WebSocket[n]===(null!=(t=this.webSocket)?t.readyState:void 0))return n.toLowerCase();return null},t.prototype.installEventHandlers=function(){var t,n;for(t in this.events)n=this.events[t].bind(this),this.webSocket["on"+t]=n},t.prototype.uninstallEventHandlers=function(){var t;for(t in this.events)this.webSocket["on"+t]=function(){}},t.prototype.events={message:function(t){var e,o,i;if(this.isProtocolSupported())switch(e=(i=JSON.parse(t.data)).identifier,o=i.message,i.type){case n.welcome:return this.monitor.recordConnect(),this.subscriptions.reload();case n.ping:return this.monitor.recordPing();case n.confirmation:return this.subscriptions.notify(e,"connected");case n.rejection:return this.subscriptions.reject(e);default:return this.subscriptions.notify(e,"received",o)}},open:function(){if(s.log("WebSocket onopen event, using '"+this.getProtocol()+"' subprotocol"),this.disconnected=!1,!this.isProtocolSupported())return s.log("Protocol is unsupported. Stopping monitor and disconnecting."),this.close({allowReconnect:!1})},close:function(t){if(s.log("WebSocket onclose event"),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll("disconnected",{willAttemptReconnect:this.monitor.isRunning()})},error:function(){return s.log("WebSocket onerror event")}},t}()}.call(this),function(){var t=[].slice;s.Subscriptions=function(){function n(t){this.consumer=t,this.subscriptions=[]}return n.prototype.create=function(t,n){var e,o,i;return o="object"==typeof(e=t)?e:{channel:e},i=new s.Subscription(this.consumer,o,n),this.add(i)},n.prototype.add=function(t){return this.subscriptions.push(t),this.consumer.ensureActiveConnection(),this.notify(t,"initialized"),this.sendCommand(t,"subscribe"),t},n.prototype.remove=function(t){return this.forget(t),this.findAll(t.identifier).length||this.sendCommand(t,"unsubscribe"),t},n.prototype.reject=function(t){var n,e,o,i,s;for(i=[],n=0,e=(o=this.findAll(t)).length;n