import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var hX=function(){return!window.SmartLib||!window.GenericPlayerApi},iX=function(a,b){const c=b.analyticsAddress||null,d=b.nanoCDNHost||null,e=b.broadpeakDomainNames||"";b=b.uuid||null;a.h||(a.h=SmartLib.getInstance(),a.h.init(c,d,e),typeof b===_.Nf&&a.h.setUUID(b))},kX=function(a,b){b=b.customParameters||{};a.a=a.h.createStreamingSession();a.a.setOption(StreamingSessionOptions.SESSION_PRECACHE,!0);for(const c in b)a.a.setCustomParameter(c,b[c]);a.o.on(a.m,_.q,a.w.bind(a));a.l=jX(a.m);
a.a.attachPlayer(a.l)},lX=function(a,b){_.Dh(a.o);a.f&&(a.f.release(),a.f=null);a.a&&(a.a.stopStreamingSession(b),a.a=null)},mX=class{constructor(a,b){this.m=a;this.f=b;this.a=new _.Nt;this.h=!1}init(){const a=this.m,b=this.a;b.on(a,_.Kf,this.o.bind(this));b.on(a,_.Kc,this.j.bind(this));b.on(a,"seek",this.l.bind(this))}j(a){a=a.detail;typeof a.bandwidth===_.t&&this.f.notifyLayerSwitch(a.bandwidth/1E3)}o(a){const b=this.m,c=this.f;a=a.detail;const d=a.currentState;a.previousState===_.Po&&c.notifyStallEnd(!b.isPaused());
switch(d){case _.Po:c.notifyStallStart();break;case _.Wo:this.h?c.notifyResume():(c.notifyFirstImage(),this.h=!0);break;case _.Vo:c.notifyPause()}}l(){const a=1E3*this.m.getPosition();this.f.notifySeek(a)}release(){this.a&&(_.Dh(this.a),this.a=null)}};var jX=a=>{class b extends GenericPlayerApi{constructor(c){super();this.m=c;this.a=_.Tk()}getPlayerName(){return _.qa}getVersion(){return _.ea}getOSName(){return this.a.os}getDeviceVersion(){return this.a.osVersion.name}getDeviceType(){return"browser"}getTotalDuration(){return this.m.isLive()?0:1E3*this.m.getDuration()}getCurrentPosition(){return 1E3*this.m.getPosition()}getCurrentBitrate(){const c=this.m.getStats();return(c?c.streamBandwidth:0)/1E3}}return new b(a)};var nX=class extends _.Pv{constructor(){super();this.l=this.f=this.a=this.h=this.m=null;this.o=new _.Nt;this.j=!1}onPlayerCreated(a){this.m=a}onContentWillLoad(a,b){const c=a.getConfiguration().broadpeak;if(c){if(hX())return a.onError(new _.I(1,9,11E3));this.j=!0;iX(this,c);kX(this,c);return this.a.getURL(b.url).then(d=>{if(d.isError()){const e=d.getDetailedErrorCode();d=d.getDetailedErrorMessage();this.m.onError(new _.I(1,9,11001,{bpkErrorCode:e,message:d}));lX(this,void 0)}else b.url=d.getURL(),
this.f=new mX(this.m,this.l),this.f.init()})}}onContentLoaded(){!1!==this.j&&this.a.precacheEnded()}w(a){a=a.detail;if(7003===a.code)lX(this,SmartLib.BPFormatNotSupportedError);else if(a.severity===_.G)switch(a.category){case 3:lX(this,SmartLib.BPDecodingError);break;case 1:lX(this,SmartLib.BPNetworkingError);break;case 6:lX(this,SmartLib.BPAccessRightError);break;default:lX(this,SmartLib.BPUnspecifiedError)}}onPlayerWillRelease(){hX()||lX(this,SmartLib.BPSessionEndsNormally);this.j=!1}id(){return"broadpeak"}};
_.z("clpp.broadpeak.BroadpeakPlugin",nX);nX.isSdkMissing=hX;nX.Id="broadpeak";_.Ir(new class{create(){return new nX}});};f.call(g, window);