"use strict";(globalThis.webpackChunk_plex_client_qt=globalThis.webpackChunk_plex_client_qt||[]).push([["initializers_qtChannelInitializer_ts"],{24042:(e,r,t)=>{t.d(r,{default:()=>c});t(9053);var s=t(1137),o=t(35162);const n=/^(storage|user)\.(get|set)/,l="QWebChannel";function i(){return s.log.level===s.in.Debug||s.log.level===s.in.Log}function a(e){return`[${l}(${e})]`}function d(e,r){try{return r.split(".").reduce(((e,r)=>e[r]),e)}catch(e){throw new Error(`Unable to resolve "${r}"`)}}const u=class{constructor(){this.name=l,this._deferredResponseCallbacks={},this._earlyDeferredValues={}}async initialize(e){const r=await new Promise((e=>{new window.QWebChannel(window.qt.webChannelTransport,e)}));return this.objects=r.objects,this.connect("system.onDeferredReturnValueAvailable",((e,r)=>{this._deferredResponseCallbacks.hasOwnProperty(e)?(this._deferredResponseCallbacks[e](r),delete this._deferredResponseCallbacks[e]):this._earlyDeferredValues[e]=r})),this}async get(e,r){return await this._invokeAttribute(`${e}.get`,r)}async set(e,r){return await this._invokeAttribute(`${e}.set`,r)}send(e,...r){const t=i()&&!n.test(e);t&&s.log.debug(`${a(e)} sending: ${JSON.stringify(r)}`);return this._invoke(e,...r).then((r=>(t&&s.log.debug(`${a(e)} response: ${JSON.stringify(r)}`),r.result)),(r=>{throw t&&s.log.error(`${a(e)} error: %o`,r),r.errorCode||o.Z.UnknownError}))}connect(e,r){const t=d(this.objects,e);i()&&s.log.debug(`${a(e)} connecting`),t.connect(r);let o=!0;return()=>{o&&(t.disconnect(r),i()&&s.log.debug(`${a(e)} disconnected`),o=!1)}}_setupDeferredResponse(e,r){this._earlyDeferredValues.hasOwnProperty(e)?(r(this._earlyDeferredValues[e]),delete this._earlyDeferredValues[e]):this._deferredResponseCallbacks[e]=r}async _invoke(e,...r){const t=d(this.objects,e);return new Promise(((e,s)=>{const n=r=>{r.errorCode===o.Z.DeferredReturnValue?this._setupDeferredResponse(r.result.deferred.index,n):r.errorCode===o.Z.Success?e(r):s(r)};t(...r,n)}))}async _invokeAttribute(e,...r){const t=d(this.objects,e);return new Promise(((l,d)=>{const u=t=>{if(t.errorCode===o.Z.DeferredReturnValue)return void this._setupDeferredResponse(t.result.deferred.index,u);const c={},b={};for(const e in t.result){const r=t.result[e];r.errorCode===o.Z.Success?c[e]=r.result:b[e]=r.errorCode}if(i()){const o=/\.set/.test(e)?Object.keys(r[0]):r;n.test(e)?s.log.debug(`${a(e)} ${o}`):s.log.debug(`${a(e)} ${o}: ${JSON.stringify(t)}`)}t.errorCode===o.Z.Success?l({success:c}):d({failure:b,success:c})};t(...r,u)}))}};async function c(){const e=new u;return await e.initialize(),e}},35162:(e,r,t)=>{var s;t.d(r,{Z:()=>o}),function(e){e[e.UnknownError=-1]="UnknownError",e[e.Success=0]="Success",e[e.GenericError=1]="GenericError",e[e.FailedToParseValue=2]="FailedToParseValue",e[e.DeferredReturnValue=3]="DeferredReturnValue",e[e.AttributeNotRegistered=51]="AttributeNotRegistered",e[e.AttributeNotImplemented=52]="AttributeNotImplemented",e[e.AttributeFailedToGetValue=53]="AttributeFailedToGetValue",e[e.AttributeFailedToSetValue=54]="AttributeFailedToSetValue",e[e.AttributeReadOnly=55]="AttributeReadOnly",e[e.AttributeWriteOnly=56]="AttributeWriteOnly",e[e.PlayerNotAvailable=1001]="PlayerNotAvailable",e[e.PlayerFailedToLoad=1002]="PlayerFailedToLoad",e[e.PlayerUrlNotSpecified=1003]="PlayerUrlNotSpecified",e[e.PlayerFailedToResume=1004]="PlayerFailedToResume",e[e.PlayerFailedToPause=1005]="PlayerFailedToPause",e[e.PlayerFailedToSeek=1006]="PlayerFailedToSeek",e[e.PlayerFailedToStop=1007]="PlayerFailedToStop",e[e.PlayerFailedToDownloadCodec=1008]="PlayerFailedToDownloadCodec",e[e.PlayerFailedToTeardown=1009]="PlayerFailedToTeardown",e[e.PlayerFailedToExecute=1010]="PlayerFailedToExecute"}(s||(s={}));const o=s}}]);