@slashedcloud/player
Version:
A media player application utilizing Shaka Player for adaptive video streaming, capable of playing HLS, MPD and plain HTTP video streams.
6 lines (5 loc) • 3.71 kB
JavaScript
var b=Object.defineProperty,$=Object.defineProperties;var k=Object.getOwnPropertyDescriptors;var E=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var I=r=>{throw TypeError(r)};var f=(r,e,s)=>e in r?b(r,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[e]=s,R=(r,e)=>{for(var s in e||(e={}))F.call(e,s)&&f(r,s,e[s]);if(E)for(var s of E(e))G.call(e,s)&&f(r,s,e[s]);return r},O=(r,e)=>$(r,k(e));var o=(r,e,s)=>f(r,typeof e!="symbol"?e+"":e,s),L=(r,e,s)=>e.has(r)||I("Cannot "+s);var y=(r,e,s)=>e.has(r)?I("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,s);var w=(r,e,s)=>(L(r,e,"access private method"),s);var A=(r,e,s)=>new Promise((u,h)=>{var p=t=>{try{m(s.next(t))}catch(l){h(l)}},d=t=>{try{m(s.throw(t))}catch(l){h(l)}},m=t=>t.done?u(t.value):Promise.resolve(t.value).then(p,d);m((s=s.apply(r,e)).next())});/*!
* SlashedCloud v0.1.2 (https://github.com/SlashedCloud/player#readme)
* Copyright 2024-2024 rogerio.jardim@fedrax.pt
* Licensed under Apache (https://github.com/SlashedCloud/player/blob/develop/LICENSE)
*/this.SlashedCloudPlayer=this.SlashedCloudPlayer||{};this.SlashedCloudPlayer.Analytics=function(){"use strict";var h,v,d,N;class r{constructor(l){o(this,"player");this.player=l}}var e=(t=>(t[t.INFO=0]="INFO",t[t.WARNING=1]="WARNING",t[t.ERROR=2]="ERROR",t[t.CRITICAL=3]="CRITICAL",t[t.FATAL=4]="FATAL",t))(e||{});class s extends Error{constructor(a,n,c,i){super(c);y(this,h);o(this,"name");o(this,"message");o(this,"severity");o(this,"code");o(this,"description");o(this,"reason");this.name=a,this.message=c,this.severity=n,this.code=i==null?void 0:i.code,this.description=i==null?void 0:i.description,this.reason=i==null?void 0:i.reason,w(this,h,v).call(this)}get severityString(){switch(this.severity){case 3:return"CRITICAL";case 2:return"ERROR";case 1:return"WARNING";case 0:default:return"INFO"}}toObject(){return{errorName:this.name,errorMessage:this.message,errorSeverity:this.severityString,errorCode:this.code,errorDescription:this.description,errorReason:this.reason}}}h=new WeakSet,v=function(){var n,c,i;let a=`${this.severityString}: ${this.name} | ${this.message}`;switch(this.description&&(a+=` | ${this.description}`),this.code&&(a+=` [${this.code}]`),this.severity){case 0:console.info(a,(n=this.reason)!=null?n:"");break;case 1:console.warn(a,(c=this.reason)!=null?c:"");break;case 2:case 3:case 4:default:console.error(a,(i=this.reason)!=null?i:"");break}};class u extends r{constructor(a,n){super(a);y(this,d);o(this,"name","AnalyticsPlugin");o(this,"params",{});o(this,"options");this.options=n}setup(){return A(this,null,function*(){for(const a of this.options)w(this,d,N).call(this,a)})}sendEvent(a,n,c){return A(this,null,function*(){let i="Analytics",g;switch(a){case"google":i="Google analytics",g=O(R(R({},this.params[a]),c),{type:n}),window.gtag("event",this.player.elementId,R({},g));break;default:throw new s(this.name,e.ERROR,"Provider is not defined")}this.player.options.debug&&(console.log(`======= ${i} event debug =======`),console.log(`Event sent: ${n} with options:`,R({},g)))})}}return d=new WeakSet,N=function(a){const n=a.provider;switch(n){case"google":if(!window.gtag)throw new s(this.name,e.ERROR,"Google tag is not loaded");break;default:throw new s(this.name,e.ERROR,"Provider is not defined")}if(!Array.isArray(a.events)||!a.events.length)throw new s(this.name,e.ERROR,"Events are not defined");a.params&&(this.params[n]=a.params),this.player.on(a.events,(c,i)=>{if(c==="error"&&i.errorReason){const{code:g,message:C,name:P}=i.errorReason;i.errorReason=JSON.stringify({code:g,message:C,name:P})}this.sendEvent(n,c,R({},i))})},u}();