vhall-mini-sdk 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(){var e={338:function(e,t){var r;r=function(e){e.version="1.2.2";var t=function signed_crc_table(){for(var e=0,t=new Array(256),r=0;256!=r;++r)e=1&(e=1&(e=1&(e=1&(e=1&(e=1&(e=1&(e=1&(e=r)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1,t[r]=e;return"undefined"!=typeof Int32Array?new Int32Array(t):t}(),r=function slice_by_16_tables(e){var t=0,r=0,i=0,n="undefined"!=typeof Int32Array?new Int32Array(4096):new Array(4096);for(i=0;256!=i;++i)n[i]=e[i];for(i=0;256!=i;++i)for(r=e[i],t=256+i;t<4096;t+=256)r=n[t]=r>>>8^e[255&r];var o=[];for(i=1;16!=i;++i)o[i-1]="undefined"!=typeof Int32Array?n.subarray(256*i,256*i+256):n.slice(256*i,256*i+256);return o}(t),i=r[0],n=r[1],o=r[2],a=r[3],s=r[4],l=r[5],u=r[6],c=r[7],p=r[8],d=r[9],h=r[10],f=r[11],_=r[12],g=r[13],y=r[14];e.table=t,e.bstr=function crc32_bstr(e,r){for(var i=~r,n=0,o=e.length;n<o;)i=i>>>8^t[255&(i^e.charCodeAt(n++))];return~i},e.buf=function crc32_buf(e,r){for(var v=~r,b=e.length-15,m=0;m<b;)v=y[e[m++]^255&v]^g[e[m++]^v>>8&255]^_[e[m++]^v>>16&255]^f[e[m++]^v>>>24]^h[e[m++]]^d[e[m++]]^p[e[m++]]^c[e[m++]]^u[e[m++]]^l[e[m++]]^s[e[m++]]^a[e[m++]]^o[e[m++]]^n[e[m++]]^i[e[m++]]^t[e[m++]];for(b+=15;m<b;)v=v>>>8^t[255&(v^e[m++])];return~v},e.str=function crc32_str(e,r){for(var i=~r,n=0,o=e.length,a=0,s=0;n<o;)(a=e.charCodeAt(n++))<128?i=i>>>8^t[255&(i^a)]:a<2048?i=(i=i>>>8^t[255&(i^(192|a>>6&31))])>>>8^t[255&(i^(128|63&a))]:a>=55296&&a<57344?(a=64+(1023&a),s=1023&e.charCodeAt(n++),i=(i=(i=(i=i>>>8^t[255&(i^(240|a>>8&7))])>>>8^t[255&(i^(128|a>>2&63))])>>>8^t[255&(i^(128|s>>6&15|(3&a)<<4))])>>>8^t[255&(i^(128|63&s))]):i=(i=(i=i>>>8^t[255&(i^(224|a>>12&15))])>>>8^t[255&(i^(128|a>>6&63))])>>>8^t[255&(i^(128|63&a))];return~i}},"undefined"==typeof DO_NOT_EXPORT_CRC?r(t):r({})},547:function(e,t,r){"use strict";r.d(t,{envConfig:function(){return i}});const i={production:{BASE_URL:"https://open-api.vhall.com",VHALLYUN_API_BASE:"https://api.vhallyun.com",LOG_REPORT_BASE_URL:"https://dc.e.vhall.com/login",PUBLIC_KEY:"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0eUJFtW3vryA2NXx4M4f\n1w7dg3PHwOCA6Kx7JVfD/9eBGfqLhqsp+pg4AXG4PhuQx8EsV+sncQIiQO5J2//T\n3pO8LftDtCQztLnxnhq+BjhbFeswgfez2CwV2YKLTX2zyZ69T1Vu/M4H4gWSLeiV\n1FcH6xycA2+jG+EvOxSSItCKYT9EkB9BZSKf5RU7gM+qPtzdPtJP5vlsMCa0WnpY\nI6Qrmu/w9CZkL0397gUek9nBpPHkyPYg7ZijF3Gj8EqCMCVVTYpX96k4dd/Rz1em\ns4OSPF5jDsYZi58p+LmTcc3g7W9bD3QWWxzn47ie/Dh9LbnWfCqpGjUaHd3d42vR\ncQIDAQAB\n-----END PUBLIC KEY-----"},test:{BASE_URL:"https://test01-open-api.vhou.tv",VHALLYUN_API_BASE:"https://test01-api.vhallyun.com",LOG_REPORT_BASE_URL:"https://t-dc.e.vhall.com/login",PUBLIC_KEY:"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxWGCgHz2NLdVNa91CsNX\nFfCsxfgkTx738t3yMpuPYLL/5wwuWRrX7hBfNsfC+R5BW5b13ISzD001NNt+BWGK\np3V5fdWO18j9M/AhaTV2Ao/IpdP5huvVoNFVWPUQvX70FHu0sPVTev8ycAZHUpKx\n+mm83wxOpWBN5vAMJYx75pRCQfidb73XbOm6JXLJlxN91TUTrTiblxBhRwH0AQyr\ns9dUr+IJUZ1ea2uU3fkB4uYh7V/cHuNDMsJowfLtEU2+9IqEuJY4OwqX0qdfPF72\nsGMjCgghgL0z/7kv7Qe1+tOkJTBQTzODXBheGTVbF7hH2+5XuZsK2TfgBIew0I4k\n1wIDAQAB\n-----END PUBLIC KEY-----"}}}},t={};function __webpack_require__(r){var i=t[r];if(void 0!==i)return i.exports;var n=t[r]={exports:{}};return e[r](n,n.exports,__webpack_require__),n.exports}__webpack_require__.d=function(e,t){for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};!function(){"use strict";__webpack_require__.r(r),__webpack_require__.d(r,{default:function(){return VhallPlayerCore}});class WxHttp{constructor(e){this.store=e}request(e,t={},r="POST"){return new Promise(((i,n)=>{const o={url:e,method:r,data:t,header:{"Content-Type":"application/x-www-form-urlencoded"},success:e=>this._handleSuccess(e,i,n),fail:e=>this._handleFail(e,n)};wx.request(o)}))}_handleSuccess(e,t,r){if(200!==e.statusCode)return r({code:e.statusCode,msg:"网络请求失败"});const i=e.data||{};200==+i.code?t(i.data):r(i)}_handleFail(e,t){t({code:-1,msg:"网络连接失败",errMsg:e.errMsg})}}const e="/v3/interacts/union/player-config",t="/sdk/v2/init/start",i="/sdk/v2/room/get-watch-info",n="/sdk/v2/demand/get-record-watch-info",o="/api/dispatch_play",a="/api/dispatch_replay";function safeUrlJoin(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}var s=__webpack_require__(547);class WxApi{constructor(e){this.currentEnvConfig=e?.env&&s.envConfig[e.env]?s.envConfig[e.env]:s.envConfig.production,this.http=new WxHttp(e)}initVhallPlayerConfig(t){const r=safeUrlJoin(this.currentEnvConfig.BASE_URL,e),i={webinar_id:t,tags:["basic-config","definition","screen-config","water-mark"]};return this.http.request(r,i)}initVhallyun(){const e=safeUrlJoin(this.currentEnvConfig.VHALLYUN_API_BASE,t);return this.http.request(e)}requestVhallyunLive(e){const t=safeUrlJoin(this.currentEnvConfig.VHALLYUN_API_BASE,i);return this.http.request(t,{...e,client:"pc_browser",package_check:"peter"})}requestGslbLive(e,t){const r=safeUrlJoin(e,o);return this.http.request(r,{...t,bu:1})}requestVhallyunVod(e){const t=safeUrlJoin(this.currentEnvConfig.VHALLYUN_API_BASE,n);return this.http.request(t,{...e,client:"pc_browser",package_check:"peter"})}requestGslbVod(e,t){const r=safeUrlJoin(e,a);return this.http.request(r,{...t,bu:1})}}const l={trace:0,debug:1,info:2,log:2,warn:3,error:4,silent:5};let u=l.info;function createLogger(e=""){const t=e?`[${e}]`:"",r="[vhall-mp]",enabled=e=>e>=u;return{trace:function trace(...e){enabled(l.trace)&&console.trace(`${r}${t}`,...e)},debug:function debug(...e){enabled(l.debug)&&console.debug(`${r}${t}`,...e)},info:function info(...e){enabled(l.info)&&console.info(`${r}${t}`,...e)},log:function log(...e){enabled(l.log)&&console.log(`${r}${t}`,...e)},warn:function warn(...e){enabled(l.warn)&&console.warn(`${r}${t}`,...e)},error:function error(...e){enabled(l.error)&&console.error(`${r}${t}`,...e)}}}var c=createLogger;const p=__webpack_require__(338),d=c("playerCore_scheduler"),h=["same","origin","720p","720sp","480p","480sp","360p","360sp","a"];class Scheduler{constructor(e){this.option=e,this.audioMode=!1,this.hideSameQuality=!1,this.api=new WxApi(e)}static _getRandom(){return 1e8+(899999999*Math.random()|0)}static _createPlayToken(e){const t=e.split("_")[0],r=e.split("_")[1],i=t.split("").reverse().join("");return`${(p.str(i)>>>0).toString(16).toUpperCase()}_${r}`}static _decideCurrentQuality=function(e,t){let r=null;if(0==t.length)log.error("调度无法获取点播播放地址!");else if(1==t.length)r=t[0];else if(t.indexOf(e)>=0)r=e;else{let e=t.filter((e=>"same"!==e&&"a"!==e));r=e.length>0?e[0]:t[0]}return r};async initVhallPlayerConfig(e){return this.api.initVhallPlayerConfig(e)}initForLive(){return new Promise(((e,t)=>{this.api.requestVhallyunLive({app_id:this.option.paasAppId,room_id:this.option.paasRoomId,third_party_user_id:this.option.uid,access_token:this.option.paasAccessToken}).then((t=>{d.debug("vhallyun直播接口成功: ",t);var r=(e=>{const{dispatch_server:t,live_delay:r,live_subtitle_mps:i,log_info:n}=e;return{log_info:n,uid:n.uid,dispatch_server:t,subtitles:(i||"").split(",").map((e=>e.trim())).filter((e=>e.length>0)),live_delay:r}})(t);this.vhallyunLiveData=r,e(r)})).catch((e=>{d.error("初始化失败",e),t(e)}))}))}initGslbLive(){const _parseGslbLive=e=>{const{dispatch_urls_v2:t,token:r}=e,{stream_id:i,quality:n,multi_lang_subtitle:o,rtmp_urls:a}=t;let s,l=t.httpflv_urls;if(this.audioMode)s=["same"];else if(s=n.sort(((e,t)=>{const r=h.indexOf(e),i=h.indexOf(t);return-1===r&&-1===i?0:-1===r?1:-1===i?-1:r-i})),this.hideSameQuality){s.some((e=>"same"!==e&&"a"!==e))&&(s=s.filter((e=>"same"!==e)))}const u=this.vhallyunLiveData.subtitles;u.length>0&&(l=l.filter((e=>"tx"===e.cdn_name)));const c=[];l.forEach((e=>{c.push(e.cdn_name)})),d.debug("优先清晰度: ",this.option.defaultDefinition),d.debug("全部清晰度: ",s),d.debug("全部字幕: ",u),d.debug("全部线路: ",c);const p=this.option.defaultDefinition;let f=u.length>0?u[0]:"",_=Scheduler._decideCurrentQuality(p,s);if(!_)return log.error("无法获取有效的直播播放地址!"),null;d.debug("选择清晰度: ",_),d.debug("选择字幕: ",f),d.debug("选择线路: ",0);const g=Scheduler._createPlayToken(r),y=l[0].url,v=l[0].app;return{httpflv_urls:l,stream_id:i,newToken:g,lines:c,currentLines:0,videoSrc:`${y}/${v}/${i}${""==f?"":`_${f}`}${"same"==_?"":`_${_}`}.flv?token=${g}`,qualitys:s,currentQuality:_,subtitles:u,currentSubtitle:f}};return new Promise(((e,t)=>{this.api.requestGslbLive(this.vhallyunLiveData.dispatch_server,{app_id:this.option.paasAppId,webinar_id:this.option.paasRoomId,uid:this.option.uid,rand:Scheduler._getRandom()}).then((t=>{d.debug("GSLB直播接口成功: ",t);const r=_parseGslbLive(t);this.livePlayInfo=r,e(r)})).catch((e=>{d.error("初始化失败",e),t(e)}))}))}initForVod(){return new Promise(((e,t)=>{this.api.requestVhallyunVod({app_id:this.option.paasAppId,record_id:this.option.paasVodId,third_party_user_id:this.option.uid,access_token:this.option.paasAccessToken}).then((t=>{d.debug("vhallyun点播接口成功: ",t);var r=(e=>{const{cue_point:t,default_server:r,definition:i,dispatch_server:n,log_info:o,safe_server:a,subtitle_info:s,watermark:l}=e,u=a.hasOwnProperty("cipher_key"),c=r.uri,p=r.rand,d=o.uid;return i.sort(((e,t)=>{const r=h.indexOf(e),i=h.indexOf(t);return-1===r&&-1===i?0:-1===r?1:-1===i?-1:r-i})),{log_info:o,uid:d,rand:p,vodEncrypted:u,cue_point:t,videoUri:c,definition:i,dispatch_server:n,subtitle_info:s,watermark:l}})(t);this.vhallyunVodData=r,e(r)})).catch((e=>{d.error("初始化失败",e),t(e)}))}))}initGslbVod(){const _parseGslbVod=e=>{const{hls_domainnames:t,token:r}=e;let i;i=this.audioMode?["same"]:this.vhallyunVodData.definition;const n=i.indexOf("same")>=0?"same":i[0],o=[];t[n].forEach((e=>{o.push(e.cdn_name)})),d.debug("优先清晰度: ",this.option.defaultDefinition),d.debug("全部清晰度: ",i),d.debug("全部线路: ",o);const a=this.option.defaultDefinition;let s=Scheduler._decideCurrentQuality(a,i);if(!s)return log.error("无法获取有效的点播播放地址!"),null;d.debug("选择清晰度: ",s),d.debug("选择线路: ",0);const l=Scheduler._createPlayToken(r),u=t[s][0].hls_domainname;return{hls_domainnames:t,newToken:l,lines:o,currentLines:0,videoSrc:`${u}?token=${l}`,qualitys:i,currentQuality:s}};return new Promise(((e,t)=>{this.api.requestGslbVod(this.vhallyunVodData.dispatch_server,{app_id:this.option.paasAppId,webinar_id:this.option.paasVodId,uid:this.vhallyunVodData.uid,rand:this.vhallyunVodData.rand,uri:this.vhallyunVodData.videoUri,quality:`["${this.vhallyunVodData.definition.join('","')}"]`}).then((t=>{d.debug("GSLB点播接口成功: ",t);const r=_parseGslbVod(t);this.vodPlayInfo=r,e(r)})).catch((e=>{d.error("初始化失败",e),t(e)}))}))}getVideoSrc(e,t){if("vod"==this.option.type){const t=this.vodPlayInfo.newToken;return`${this.vodPlayInfo.hls_domainnames[e][this.vodPlayInfo.currentLines].hls_domainname}?token=${t}`}{const r=this.livePlayInfo.newToken,i="same"==e?"":`_${e}`,n=""==t?"":`_${t}`;return`${this.livePlayInfo.httpflv_urls[this.livePlayInfo.currentLines].url}/${this.livePlayInfo.httpflv_urls[this.livePlayInfo.currentLines].app}/${this.livePlayInfo.stream_id}${n}${i}.flv?token=${r}`}}}const f="function"==typeof Buffer,_=("function"==typeof TextDecoder&&new TextDecoder,"function"==typeof TextEncoder?new TextEncoder:void 0),g=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),y=(e=>{let t={};return e.forEach(((e,r)=>t[e]=r)),t})(g),v=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,b=String.fromCharCode.bind(String),m=("function"==typeof Uint8Array.from&&Uint8Array.from.bind(Uint8Array),e=>e.replace(/=/g,"").replace(/[+\/]/g,(e=>"+"==e?"-":"_"))),_tidyB64=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),btoaPolyfill=e=>{let t,r,i,n,o="";const a=e.length%3;for(let a=0;a<e.length;){if((r=e.charCodeAt(a++))>255||(i=e.charCodeAt(a++))>255||(n=e.charCodeAt(a++))>255)throw new TypeError("invalid character found");t=r<<16|i<<8|n,o+=g[t>>18&63]+g[t>>12&63]+g[t>>6&63]+g[63&t]}return a?o.slice(0,a-3)+"===".substring(a):o},w="function"==typeof btoa?e=>btoa(e):f?e=>Buffer.from(e,"binary").toString("base64"):btoaPolyfill,A=f?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let r=0,i=e.length;r<i;r+=4096)t.push(b.apply(null,e.subarray(r,r+4096)));return w(t.join(""))},cb_utob=e=>{if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?b(192|t>>>6)+b(128|63&t):b(224|t>>>12&15)+b(128|t>>>6&63)+b(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return b(240|t>>>18&7)+b(128|t>>>12&63)+b(128|t>>>6&63)+b(128|63&t)},C=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,utob=e=>e.replace(C,cb_utob),I=f?e=>Buffer.from(e,"utf8").toString("base64"):_?e=>A(_.encode(e)):e=>w(utob(e)),encode=(e,t=!1)=>t?m(I(e)):I(e),atobPolyfill=e=>{if(e=e.replace(/\s+/g,""),!v.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let t,r,i,n="";for(let o=0;o<e.length;)t=y[e.charAt(o++)]<<18|y[e.charAt(o++)]<<12|(r=y[e.charAt(o++)])<<6|(i=y[e.charAt(o++)]),n+=64===r?b(t>>16&255):64===i?b(t>>16&255,t>>8&255):b(t>>16&255,t>>8&255,255&t);return n},P=encode;function guid(){return"xxxxxxxx-xxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))}function formatTimestamp(e,t="YYYY-MM-DD HH:mm:ss"){const r=10===e.toString().length?1e3*e:e,i=new Date(r),n=i.getFullYear(),o=String(i.getMonth()+1).padStart(2,"0"),a=String(i.getDate()).padStart(2,"0"),s=String(i.getHours()).padStart(2,"0"),l=String(i.getMinutes()).padStart(2,"0"),u=String(i.getSeconds()).padStart(2,"0");return t?t.replaceAll("YYYY",n).replaceAll("MM",o).replaceAll("DD",a).replaceAll("HH",s).replaceAll("mm",l).replaceAll("ss",u):`${n}-${o}-${a} ${s}:${l}:${u}`}const k=c("playerCore_logReport"),R=getApp(),x="wxminiprogram",S=102001,T=102002,D=92001,L=92005;class LogReport{constructor(e){const t=e?.env&&s.envConfig[e.env]?s.envConfig[e.env]:s.envConfig.production;this.logReportBaseUrl=t.LOG_REPORT_BASE_URL,this.option=e,this._infoPackInterval=void 0,this.infoPackIntervalMs=3e4,this.body={},this.uuid=void 0}justUpdateData(e){this.option=e,this.initReportConfig()}init(){k.debug("init() exec!"),!1!==this.option.enable&&(this.uuid=guid(),this.initReportConfig())}initReportConfig(){const e=this.uuid?this.uuid:guid();this.body={ver:this.option.componetVersion,bu:1,flow_type:2,vtype:"",topic:"",webUrl:"",pf:9,df:x,ua:x,browser_name:x,osv:x,ndi:x,uid:this.option.uid||"",_uuid:e,s:e,app_id:"",p:"",aid:"",biz_id:"",guid:"",vid:"",vfid:"",videoWidth:0,videoHeight:0,protocol:"live"===this.option.type?"flv":"hls",picture_quality:"",sd:"",fd:"",tt:this.infoPackIntervalMs,bc:0,bt:0,tf:0,errcode:0,pushTime:Date.now(),reportTime:Date.now()},Object.assign(this.body,this.option.otherOption)}updateReportConfig(e){Object.assign(this.body,e)}start(){k.debug("start() exec"),this.startPack(),this.resume()}resume(){k.debug("resume() call"),this._clearTimer(),this._infoPackInterval=setInterval(this.infoPack.bind(this),this.infoPackIntervalMs),R.globalData?.playerReportTimer||(R.globalData.playerReportTimer=[]),R.globalData.playerReportTimer.push(this._infoPackInterval)}startPack(){if(Date.now()-R.globalData.playerReportStartTs<1e3)return void(R.globalData.playerReportStartTs=Date.now());R.globalData.playerReportStartTs=Date.now();const e="live"===this.option.type?S:D;this._report(e),k.debug(`startPack() call:, ${formatTimestamp(Date.now())}, ${e}: `,this.body)}infoPack(){const e="live"===this.option.type?T:L;this._report(e),k.debug(`infoPack() call: timerId=${this._infoPackInterval}, ${formatTimestamp(Date.now())}, ${e}: `,this.body)}_stringToBase64(e){let t=function stringToUtf8ArrayBuffer(e){let t=[];for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);i<128?t.push(i):i<2048?t.push(192|i>>6,128|63&i):i<55296||i>=57344?t.push(224|i>>12,128|i>>6&63,128|63&i):(r++,i=65536+((1023&i)<<10|1023&e.charCodeAt(r)),t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return new Uint8Array(t)}(e);return wx.arrayBufferToBase64(t)}_report(e){this.body.reportTime=Date.now();const t={k:e,id:Date.now(),token:P(JSON.stringify(this.body))};wx.request({url:this.logReportBaseUrl,method:"GET",data:t,success(e){}})}_clearTimer(){if(this._infoPackInterval&&(clearInterval(this._infoPackInterval),this._infoPackInterval=void 0),R.globalData?.playerReportTimer){for(const e of R.globalData.playerReportTimer)clearInterval(e);R.globalData.playerReportTimer=[]}}destroy(){k.debug("destroy() call"),this._clearTimer()}}const B=c("playerCore");class VhallPlayerCore{constructor(){}init(e){this.option=e,this.scheduler=new Scheduler(e),this.logReporter&&this.logReporter._infoPackInterval>0?(B.debug("LogReport justUpdateData"),this.logReporter.justUpdateData(e)):(this.logReporter=new LogReport(e),this.logReporter.init())}async initVhallPlayer(){try{const e=this.option.watchInitData,t=e.webinar.id,r=e.join_info.third_party_user_id,i=e.join_info.nickname,n=await this.scheduler.initVhallPlayerConfig(t),o=e.webinar.type;let a="";1==o?a="live":2==o&&e.warmup&&e.warmup.warmup_paas_record_id||4!=o&&5!=o||(a="vod");const s=e.interact.paas_app_id,l=e.interact.room_id,u=e.paas_record_id,c=e.interact.paas_access_token,p=Boolean(1==parseInt(e.webinar.mode));this.scheduler.audioMode=p;const d=Boolean(0==e.webinar.webinar_show_type),h=1==e.webinar.no_delay_webinar?"RTC":"live",f=1==n["basic-config"].data.autoplay,_=1==n["basic-config"].data.progress_bar,g=n.definition.data.default_definition,y=this.option.permissionValue,v=Boolean("1"==y?.live_hidden_same);this.scheduler.hideSameQuality=v;let b=e.webinar.img_url;d&&e.webinar.vertical_img_url&&(b=e.webinar.vertical_img_url);let m={};b.length>0&&(m={enable:!0,url:b});const w=n["water-mark"].data;let A={};if(1==w.watermark_open&&w.img_url.length>0){const e=["tl","tr","bl","br"][w.img_position-1],t=[["12%","12%"],["10%","10%"],["8%","8%"]][w.img_size-1];A={enable:!0,url:w.img_url,align:e,position:["20px","20px"],size:t,alpha:w.img_alpha}}const C=n["screen-config"].data;let I={};if(1==C.scrolling_open){const e=C.scroll_type-1,t=C.alpha,n=C.size,o=C.color,a=C.speed,s=C.interval,l=C.position;I={enable:!0,displayType:e,text:1==C.text_type?C.text:`${r}-${i}`,alpha:t,size:n,color:o,interval:s,speed:a,position:l}}return Object.assign(this.scheduler.option,{uid:r,type:a,paasAppId:s,paasRoomId:l,paasVodId:u,paasAccessToken:c,defaultDefinition:g}),this.logReporter.updateReportConfig(e.report_data),this.logReporter.option.type=a,this.logReporter.updateReportConfig({app_id:s,aid:"live"==a?l:u,p:"live"==a?l:u,uid:r}),{type:a,paasAppId:s,paasRoomId:l,paasVodId:u,paasAccessToken:c,audioMode:p,liveDelayMode:h,verticalMode:d,autoplay:f,showProgress:_,defaultDefinition:g,posterOption:m,watermarkOption:A,marqueeOption:I}}catch(e){throw B.error("初始化失败",e),e}}initVhallyunLive(){return new Promise(((e,t)=>{this.scheduler.initForLive().then((r=>{this.logReporter.updateReportConfig({s:r.log_info.session_id}),this.scheduler.initGslbLive(r).then((t=>{this.logReporter.updateReportConfig({picture_quality:t.currentQuality,s:r.log_info.session_id}),this.logReporter.start(),e(t)})).catch((e=>{t(e)}))})).catch((e=>{t(e)}))}))}async initVhallyunVod(){return new Promise(((e,t)=>{this.scheduler.initForVod().then((r=>{this.logReporter.updateReportConfig({s:r.log_info.session_id}),this.scheduler.initGslbVod(r).then((t=>{this.logReporter.updateReportConfig({picture_quality:t.currentQuality,s:r.log_info.session_id}),this.logReporter.start(),e(t)})).catch((e=>{t(e)}))})).catch((e=>{t(e)}))}))}getVideoSrc(e,t){return this.logReporter.updateReportConfig({picture_quality:e}),this.scheduler.getVideoSrc(e,t)}resume(){this.logReporter?.resume()}destroy(){this.logReporter?.destroy()}}}(),module.exports=r}();
1
+ !function(){var e={338:function(e,t){var r;r=function(e){e.version="1.2.2";var t=function signed_crc_table(){for(var e=0,t=new Array(256),r=0;256!=r;++r)e=1&(e=1&(e=1&(e=1&(e=1&(e=1&(e=1&(e=1&(e=r)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1)?-306674912^e>>>1:e>>>1,t[r]=e;return"undefined"!=typeof Int32Array?new Int32Array(t):t}(),r=function slice_by_16_tables(e){var t=0,r=0,i=0,n="undefined"!=typeof Int32Array?new Int32Array(4096):new Array(4096);for(i=0;256!=i;++i)n[i]=e[i];for(i=0;256!=i;++i)for(r=e[i],t=256+i;t<4096;t+=256)r=n[t]=r>>>8^e[255&r];var o=[];for(i=1;16!=i;++i)o[i-1]="undefined"!=typeof Int32Array?n.subarray(256*i,256*i+256):n.slice(256*i,256*i+256);return o}(t),i=r[0],n=r[1],o=r[2],a=r[3],s=r[4],l=r[5],u=r[6],c=r[7],p=r[8],d=r[9],h=r[10],f=r[11],_=r[12],g=r[13],y=r[14];e.table=t,e.bstr=function crc32_bstr(e,r){for(var i=~r,n=0,o=e.length;n<o;)i=i>>>8^t[255&(i^e.charCodeAt(n++))];return~i},e.buf=function crc32_buf(e,r){for(var v=~r,m=e.length-15,b=0;b<m;)v=y[e[b++]^255&v]^g[e[b++]^v>>8&255]^_[e[b++]^v>>16&255]^f[e[b++]^v>>>24]^h[e[b++]]^d[e[b++]]^p[e[b++]]^c[e[b++]]^u[e[b++]]^l[e[b++]]^s[e[b++]]^a[e[b++]]^o[e[b++]]^n[e[b++]]^i[e[b++]]^t[e[b++]];for(m+=15;b<m;)v=v>>>8^t[255&(v^e[b++])];return~v},e.str=function crc32_str(e,r){for(var i=~r,n=0,o=e.length,a=0,s=0;n<o;)(a=e.charCodeAt(n++))<128?i=i>>>8^t[255&(i^a)]:a<2048?i=(i=i>>>8^t[255&(i^(192|a>>6&31))])>>>8^t[255&(i^(128|63&a))]:a>=55296&&a<57344?(a=64+(1023&a),s=1023&e.charCodeAt(n++),i=(i=(i=(i=i>>>8^t[255&(i^(240|a>>8&7))])>>>8^t[255&(i^(128|a>>2&63))])>>>8^t[255&(i^(128|s>>6&15|(3&a)<<4))])>>>8^t[255&(i^(128|63&s))]):i=(i=(i=i>>>8^t[255&(i^(224|a>>12&15))])>>>8^t[255&(i^(128|a>>6&63))])>>>8^t[255&(i^(128|63&a))];return~i}},"undefined"==typeof DO_NOT_EXPORT_CRC?r(t):r({})},547:function(e,t,r){"use strict";r.d(t,{envConfig:function(){return i}});const i={production:{BASE_URL:"https://open-api.vhall.com",VHALLYUN_API_BASE:"https://api.vhallyun.com",LOG_REPORT_BASE_URL:"https://dc.e.vhall.com/login",PUBLIC_KEY:"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0eUJFtW3vryA2NXx4M4f\n1w7dg3PHwOCA6Kx7JVfD/9eBGfqLhqsp+pg4AXG4PhuQx8EsV+sncQIiQO5J2//T\n3pO8LftDtCQztLnxnhq+BjhbFeswgfez2CwV2YKLTX2zyZ69T1Vu/M4H4gWSLeiV\n1FcH6xycA2+jG+EvOxSSItCKYT9EkB9BZSKf5RU7gM+qPtzdPtJP5vlsMCa0WnpY\nI6Qrmu/w9CZkL0397gUek9nBpPHkyPYg7ZijF3Gj8EqCMCVVTYpX96k4dd/Rz1em\ns4OSPF5jDsYZi58p+LmTcc3g7W9bD3QWWxzn47ie/Dh9LbnWfCqpGjUaHd3d42vR\ncQIDAQAB\n-----END PUBLIC KEY-----"},test:{BASE_URL:"https://test01-open-api.vhou.tv",VHALLYUN_API_BASE:"https://test01-api.vhallyun.com",LOG_REPORT_BASE_URL:"https://t-dc.e.vhall.com/login",PUBLIC_KEY:"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxWGCgHz2NLdVNa91CsNX\nFfCsxfgkTx738t3yMpuPYLL/5wwuWRrX7hBfNsfC+R5BW5b13ISzD001NNt+BWGK\np3V5fdWO18j9M/AhaTV2Ao/IpdP5huvVoNFVWPUQvX70FHu0sPVTev8ycAZHUpKx\n+mm83wxOpWBN5vAMJYx75pRCQfidb73XbOm6JXLJlxN91TUTrTiblxBhRwH0AQyr\ns9dUr+IJUZ1ea2uU3fkB4uYh7V/cHuNDMsJowfLtEU2+9IqEuJY4OwqX0qdfPF72\nsGMjCgghgL0z/7kv7Qe1+tOkJTBQTzODXBheGTVbF7hH2+5XuZsK2TfgBIew0I4k\n1wIDAQAB\n-----END PUBLIC KEY-----"}}}},t={};function __webpack_require__(r){var i=t[r];if(void 0!==i)return i.exports;var n=t[r]={exports:{}};return e[r](n,n.exports,__webpack_require__),n.exports}__webpack_require__.d=function(e,t){for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};!function(){"use strict";__webpack_require__.r(r),__webpack_require__.d(r,{default:function(){return VhallPlayerCore}});class WxHttp{constructor(e){this.store=e}request(e,t={},r="POST"){return new Promise(((i,n)=>{const o={url:e,method:r,data:t,header:{"Content-Type":"application/x-www-form-urlencoded"},success:e=>this._handleSuccess(e,i,n),fail:e=>this._handleFail(e,n)};wx.request(o)}))}_handleSuccess(e,t,r){if(200!==e.statusCode)return r({code:e.statusCode,msg:"网络请求失败"});const i=e.data||{};200==+i.code?t(i.data):r(i)}_handleFail(e,t){t({code:-1,msg:"网络连接失败",errMsg:e.errMsg})}}const e="/v3/interacts/union/player-config",t="/sdk/v2/init/start",i="/sdk/v2/room/get-watch-info",n="/sdk/v2/demand/get-record-watch-info",o="/api/dispatch_play",a="/api/dispatch_replay";function safeUrlJoin(e,t){return`${e.replace(/\/$/,"")}/${t.replace(/^\//,"")}`}var s=__webpack_require__(547);class WxApi{constructor(e){this.currentEnvConfig=e?.env&&s.envConfig[e.env]?s.envConfig[e.env]:s.envConfig.production,this.http=new WxHttp(e)}initVhallPlayerConfig(t){const r=safeUrlJoin(this.currentEnvConfig.BASE_URL,e),i={webinar_id:t,tags:["basic-config","definition","screen-config","water-mark"]};return this.http.request(r,i)}initVhallyun(){const e=safeUrlJoin(this.currentEnvConfig.VHALLYUN_API_BASE,t);return this.http.request(e)}requestVhallyunLive(e){const t=safeUrlJoin(this.currentEnvConfig.VHALLYUN_API_BASE,i);return this.http.request(t,{...e,client:"pc_browser",package_check:"peter"})}requestGslbLive(e,t){const r=safeUrlJoin(e,o);return this.http.request(r,{...t,bu:1})}requestVhallyunVod(e){const t=safeUrlJoin(this.currentEnvConfig.VHALLYUN_API_BASE,n);return this.http.request(t,{...e,client:"pc_browser",package_check:"peter"})}requestGslbVod(e,t){const r=safeUrlJoin(e,a);return this.http.request(r,{...t,bu:1})}}const l={trace:0,debug:1,info:2,log:2,warn:3,error:4,silent:5};let u=l.info;function formatTime(){const e=new Date,pad=(e,t=2)=>String(e).padStart(t,"0");return`${pad(e.getHours())}:${pad(e.getMinutes())}:${pad(e.getSeconds())}:${pad(e.getMilliseconds(),3)}`}function createLogger(e=""){const t=e?`[${e}]`:"",r="VhallMiniSDK",enabled=e=>e>=u;return{trace:function trace(...e){enabled(l.trace)&&console.trace(`${r} [${formatTime()}] <TRACE> ${t} `,...e)},debug:function debug(...e){enabled(l.debug)&&console.debug(`${r} [${formatTime()}] <DEBUG> ${t} `,...e)},info:function info(...e){enabled(l.info)&&console.info(`${r} [${formatTime()}] <INFO> ${t}`,...e)},log:function log(...e){enabled(l.log)&&console.log(`${r} [${formatTime()}] <LOG> ${t}`,...e)},warn:function warn(...e){enabled(l.warn)&&console.warn(`${r} [${formatTime()}] <WARN> ${t}`,...e)},error:function error(...e){enabled(l.error)&&console.error(`${r} [${formatTime()}] <ERROR> ${t}`,...e)}}}var c=createLogger;const p=__webpack_require__(338),d=c("playerCore_scheduler"),h=["same","origin","720p","720sp","480p","480sp","360p","360sp","a"];class Scheduler{constructor(e){this.option=e,this.audioMode=!1,this.hideSameQuality=!1,this.api=new WxApi(e)}static _getRandom(){return 1e8+(899999999*Math.random()|0)}static _createPlayToken(e){const t=e.split("_")[0],r=e.split("_")[1],i=t.split("").reverse().join("");return`${(p.str(i)>>>0).toString(16).toUpperCase()}_${r}`}static _decideCurrentQuality=function(e,t){let r=null;if(0==t.length)log.error("调度无法获取点播播放地址!");else if(1==t.length)r=t[0];else if(t.indexOf(e)>=0)r=e;else{let e=t.filter((e=>"same"!==e&&"a"!==e));r=e.length>0?e[0]:t[0]}return r};async initVhallPlayerConfig(e){return this.api.initVhallPlayerConfig(e)}initForLive(){return new Promise(((e,t)=>{this.api.requestVhallyunLive({app_id:this.option.paasAppId,room_id:this.option.paasRoomId,third_party_user_id:this.option.uid,access_token:this.option.paasAccessToken}).then((t=>{d.debug("vhallyun直播接口成功: ",t);var r=(e=>{const{dispatch_server:t,live_delay:r,live_subtitle_mps:i,log_info:n}=e;return{log_info:n,uid:n.uid,dispatch_server:t,subtitles:(i||"").split(",").map((e=>e.trim())).filter((e=>e.length>0)),live_delay:r}})(t);this.vhallyunLiveData=r,e(r)})).catch((e=>{d.error("初始化失败",e),t(e)}))}))}initGslbLive(){const _parseGslbLive=e=>{const{dispatch_urls_v2:t,token:r}=e,{stream_id:i,quality:n,multi_lang_subtitle:o,rtmp_urls:a}=t;let s,l=t.httpflv_urls;if(this.audioMode)s=["same"];else if(s=n.sort(((e,t)=>{const r=h.indexOf(e),i=h.indexOf(t);return-1===r&&-1===i?0:-1===r?1:-1===i?-1:r-i})),this.hideSameQuality){s.some((e=>"same"!==e&&"a"!==e))&&(s=s.filter((e=>"same"!==e)))}const u=this.vhallyunLiveData.subtitles;u.length>0&&(l=l.filter((e=>"tx"===e.cdn_name)));const c=[];l.forEach((e=>{c.push(e.cdn_name)})),d.debug("优先清晰度: ",this.option.defaultDefinition),d.debug("全部清晰度: ",s),d.debug("全部字幕: ",u),d.debug("全部线路: ",c);const p=this.option.defaultDefinition;let f=u.length>0?u[0]:"",_=Scheduler._decideCurrentQuality(p,s);if(!_)return log.error("无法获取有效的直播播放地址!"),null;d.debug("选择清晰度: ",_),d.debug("选择字幕: ",f),d.debug("选择线路: ",0);const g=Scheduler._createPlayToken(r),y=l[0].url,v=l[0].app;return{httpflv_urls:l,stream_id:i,newToken:g,lines:c,currentLines:0,videoSrc:`${y}/${v}/${i}${""==f?"":`_${f}`}${"same"==_?"":`_${_}`}.flv?token=${g}`,qualitys:s,currentQuality:_,subtitles:u,currentSubtitle:f}};return new Promise(((e,t)=>{this.api.requestGslbLive(this.vhallyunLiveData.dispatch_server,{app_id:this.option.paasAppId,webinar_id:this.option.paasRoomId,uid:this.option.uid,rand:Scheduler._getRandom()}).then((t=>{d.debug("GSLB直播接口成功: ",t);const r=_parseGslbLive(t);this.livePlayInfo=r,e(r)})).catch((e=>{d.error("初始化失败",e),t(e)}))}))}initForVod(){return new Promise(((e,t)=>{this.api.requestVhallyunVod({app_id:this.option.paasAppId,record_id:this.option.paasVodId,third_party_user_id:this.option.uid,access_token:this.option.paasAccessToken}).then((t=>{d.debug("vhallyun点播接口成功: ",t);var r=(e=>{const{cue_point:t,default_server:r,definition:i,dispatch_server:n,log_info:o,safe_server:a,subtitle_info:s,watermark:l}=e,u=a.hasOwnProperty("cipher_key"),c=r.uri,p=r.rand,d=o.uid;return i.sort(((e,t)=>{const r=h.indexOf(e),i=h.indexOf(t);return-1===r&&-1===i?0:-1===r?1:-1===i?-1:r-i})),{log_info:o,uid:d,rand:p,vodEncrypted:u,cue_point:t,videoUri:c,definition:i,dispatch_server:n,subtitle_info:s,watermark:l}})(t);this.vhallyunVodData=r,e(r)})).catch((e=>{d.error("初始化失败",e),t(e)}))}))}initGslbVod(){const _parseGslbVod=e=>{const{hls_domainnames:t,token:r}=e;let i;i=this.audioMode?["same"]:this.vhallyunVodData.definition;const n=i.indexOf("same")>=0?"same":i[0],o=[];t[n].forEach((e=>{o.push(e.cdn_name)})),d.debug("优先清晰度: ",this.option.defaultDefinition),d.debug("全部清晰度: ",i),d.debug("全部线路: ",o);const a=this.option.defaultDefinition;let s=Scheduler._decideCurrentQuality(a,i);if(!s)return log.error("无法获取有效的点播播放地址!"),null;d.debug("选择清晰度: ",s),d.debug("选择线路: ",0);const l=Scheduler._createPlayToken(r),u=t[s][0].hls_domainname;return{hls_domainnames:t,newToken:l,lines:o,currentLines:0,videoSrc:`${u}?token=${l}`,qualitys:i,currentQuality:s}};return new Promise(((e,t)=>{this.api.requestGslbVod(this.vhallyunVodData.dispatch_server,{app_id:this.option.paasAppId,webinar_id:this.option.paasVodId,uid:this.vhallyunVodData.uid,rand:this.vhallyunVodData.rand,uri:this.vhallyunVodData.videoUri,quality:`["${this.vhallyunVodData.definition.join('","')}"]`}).then((t=>{d.debug("GSLB点播接口成功: ",t);const r=_parseGslbVod(t);this.vodPlayInfo=r,e(r)})).catch((e=>{d.error("初始化失败",e),t(e)}))}))}getVideoSrc(e,t){if("vod"==this.option.type){const t=this.vodPlayInfo.newToken;return`${this.vodPlayInfo.hls_domainnames[e][this.vodPlayInfo.currentLines].hls_domainname}?token=${t}`}{const r=this.livePlayInfo.newToken,i="same"==e?"":`_${e}`,n=""==t?"":`_${t}`;return`${this.livePlayInfo.httpflv_urls[this.livePlayInfo.currentLines].url}/${this.livePlayInfo.httpflv_urls[this.livePlayInfo.currentLines].app}/${this.livePlayInfo.stream_id}${n}${i}.flv?token=${r}`}}}const f="function"==typeof Buffer,_=("function"==typeof TextDecoder&&new TextDecoder,"function"==typeof TextEncoder?new TextEncoder:void 0),g=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),y=(e=>{let t={};return e.forEach(((e,r)=>t[e]=r)),t})(g),v=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,m=String.fromCharCode.bind(String),b=("function"==typeof Uint8Array.from&&Uint8Array.from.bind(Uint8Array),e=>e.replace(/=/g,"").replace(/[+\/]/g,(e=>"+"==e?"-":"_"))),_tidyB64=e=>e.replace(/[^A-Za-z0-9\+\/]/g,""),btoaPolyfill=e=>{let t,r,i,n,o="";const a=e.length%3;for(let a=0;a<e.length;){if((r=e.charCodeAt(a++))>255||(i=e.charCodeAt(a++))>255||(n=e.charCodeAt(a++))>255)throw new TypeError("invalid character found");t=r<<16|i<<8|n,o+=g[t>>18&63]+g[t>>12&63]+g[t>>6&63]+g[63&t]}return a?o.slice(0,a-3)+"===".substring(a):o},w="function"==typeof btoa?e=>btoa(e):f?e=>Buffer.from(e,"binary").toString("base64"):btoaPolyfill,A=f?e=>Buffer.from(e).toString("base64"):e=>{let t=[];for(let r=0,i=e.length;r<i;r+=4096)t.push(m.apply(null,e.subarray(r,r+4096)));return w(t.join(""))},cb_utob=e=>{if(e.length<2)return(t=e.charCodeAt(0))<128?e:t<2048?m(192|t>>>6)+m(128|63&t):m(224|t>>>12&15)+m(128|t>>>6&63)+m(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return m(240|t>>>18&7)+m(128|t>>>12&63)+m(128|t>>>6&63)+m(128|63&t)},C=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,utob=e=>e.replace(C,cb_utob),I=f?e=>Buffer.from(e,"utf8").toString("base64"):_?e=>A(_.encode(e)):e=>w(utob(e)),encode=(e,t=!1)=>t?b(I(e)):I(e),atobPolyfill=e=>{if(e=e.replace(/\s+/g,""),!v.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(3&e.length));let t,r,i,n="";for(let o=0;o<e.length;)t=y[e.charAt(o++)]<<18|y[e.charAt(o++)]<<12|(r=y[e.charAt(o++)])<<6|(i=y[e.charAt(o++)]),n+=64===r?m(t>>16&255):64===i?m(t>>16&255,t>>8&255):m(t>>16&255,t>>8&255,255&t);return n},P=encode;function guid(){return"xxxxxxxx-xxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))}function formatTimestamp(e,t="YYYY-MM-DD HH:mm:ss"){const r=10===e.toString().length?1e3*e:e,i=new Date(r),n=i.getFullYear(),o=String(i.getMonth()+1).padStart(2,"0"),a=String(i.getDate()).padStart(2,"0"),s=String(i.getHours()).padStart(2,"0"),l=String(i.getMinutes()).padStart(2,"0"),u=String(i.getSeconds()).padStart(2,"0");return t?t.replaceAll("YYYY",n).replaceAll("MM",o).replaceAll("DD",a).replaceAll("HH",s).replaceAll("mm",l).replaceAll("ss",u):`${n}-${o}-${a} ${s}:${l}:${u}`}const k=c("playerCore_logReport"),R=getApp(),T="wxminiprogram",S=102001,x=102002,D=92001,L=92005;class LogReport{constructor(e){const t=e?.env&&s.envConfig[e.env]?s.envConfig[e.env]:s.envConfig.production;this.logReportBaseUrl=t.LOG_REPORT_BASE_URL,this.option=e,this._infoPackInterval=void 0,this.infoPackIntervalMs=3e4,this.body={},this.uuid=void 0}justUpdateData(e){this.option=e,this.initReportConfig()}init(){k.debug("init() exec!"),!1!==this.option.enable&&(this.uuid=guid(),this.initReportConfig())}initReportConfig(){const e=this.uuid?this.uuid:guid();this.body={ver:this.option.componetVersion,bu:1,flow_type:2,vtype:"",topic:"",webUrl:"",pf:9,df:T,ua:T,browser_name:T,osv:T,ndi:T,uid:this.option.uid||"",_uuid:e,s:e,app_id:"",p:"",aid:"",biz_id:"",guid:"",vid:"",vfid:"",videoWidth:0,videoHeight:0,protocol:"live"===this.option.type?"flv":"hls",picture_quality:"",sd:"",fd:"",tt:this.infoPackIntervalMs,bc:0,bt:0,tf:0,errcode:0,pushTime:Date.now(),reportTime:Date.now()},Object.assign(this.body,this.option.otherOption)}updateReportConfig(e){Object.assign(this.body,e)}start(){k.debug("start() exec"),this.startPack(),this.resume()}resume(){k.debug("resume() call"),this._clearTimer(),this._infoPackInterval=setInterval(this.infoPack.bind(this),this.infoPackIntervalMs),R.globalData?.playerReportTimer||(R.globalData.playerReportTimer=[]),R.globalData.playerReportTimer.push(this._infoPackInterval)}startPack(){if(Date.now()-R.globalData.playerReportStartTs<1e3)return void(R.globalData.playerReportStartTs=Date.now());R.globalData.playerReportStartTs=Date.now();const e="live"===this.option.type?S:D;this._report(e),k.debug(`startPack() call:, ${formatTimestamp(Date.now())}, ${e}: `,this.body)}infoPack(){const e="live"===this.option.type?x:L;this._report(e),k.debug(`infoPack() call: timerId=${this._infoPackInterval}, ${formatTimestamp(Date.now())}, ${e}: `,this.body)}_stringToBase64(e){let t=function stringToUtf8ArrayBuffer(e){let t=[];for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);i<128?t.push(i):i<2048?t.push(192|i>>6,128|63&i):i<55296||i>=57344?t.push(224|i>>12,128|i>>6&63,128|63&i):(r++,i=65536+((1023&i)<<10|1023&e.charCodeAt(r)),t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return new Uint8Array(t)}(e);return wx.arrayBufferToBase64(t)}_report(e){this.body.reportTime=Date.now();const t={k:e,id:Date.now(),token:P(JSON.stringify(this.body))};wx.request({url:this.logReportBaseUrl,method:"GET",data:t,success(e){}})}_clearTimer(){if(this._infoPackInterval&&(clearInterval(this._infoPackInterval),this._infoPackInterval=void 0),R.globalData?.playerReportTimer){for(const e of R.globalData.playerReportTimer)clearInterval(e);R.globalData.playerReportTimer=[]}}destroy(){k.debug("destroy() call"),this._clearTimer()}}const $=c("playerCore");class VhallPlayerCore{constructor(){}init(e){this.option=e,this.scheduler=new Scheduler(e),this.logReporter&&this.logReporter._infoPackInterval>0?($.debug("LogReport justUpdateData"),this.logReporter.justUpdateData(e)):(this.logReporter=new LogReport(e),this.logReporter.init())}async initVhallPlayer(){try{const e=this.option.watchInitData,t=e.webinar.id,r=e.join_info.third_party_user_id,i=e.join_info.nickname,n=await this.scheduler.initVhallPlayerConfig(t),o=e.webinar.type;let a="";1==o?a="live":2==o&&e.warmup&&e.warmup.warmup_paas_record_id||4!=o&&5!=o||(a="vod");const s=e.interact.paas_app_id,l=e.interact.room_id,u=e.paas_record_id,c=e.interact.paas_access_token,p=Boolean(1==parseInt(e.webinar.mode));this.scheduler.audioMode=p;const d=Boolean(0==e.webinar.webinar_show_type),h=1==e.webinar.no_delay_webinar?"RTC":"live",f=1==n["basic-config"].data.autoplay,_=1==n["basic-config"].data.progress_bar,g=n.definition.data.default_definition,y=this.option.permissionValue,v=Boolean("1"==y?.live_hidden_same);this.scheduler.hideSameQuality=v;let m=e.webinar.img_url;d&&e.webinar.vertical_img_url&&(m=e.webinar.vertical_img_url);let b={};m.length>0&&(b={enable:!0,url:m});const w=n["water-mark"].data;let A={};if(1==w.watermark_open&&w.img_url.length>0){const e=["tl","tr","bl","br"][w.img_position-1],t=[["12%","12%"],["10%","10%"],["8%","8%"]][w.img_size-1];A={enable:!0,url:w.img_url,align:e,position:["20px","20px"],size:t,alpha:w.img_alpha}}const C=n["screen-config"].data;let I={};if(1==C.scrolling_open){const e=C.scroll_type-1,t=C.alpha,n=C.size,o=C.color,a=C.speed,s=C.interval,l=C.position;I={enable:!0,displayType:e,text:1==C.text_type?C.text:`${r}-${i}`,alpha:t,size:n,color:o,interval:s,speed:a,position:l}}return Object.assign(this.scheduler.option,{uid:r,type:a,paasAppId:s,paasRoomId:l,paasVodId:u,paasAccessToken:c,defaultDefinition:g}),this.logReporter.updateReportConfig(e.report_data),this.logReporter.option.type=a,this.logReporter.updateReportConfig({app_id:s,aid:"live"==a?l:u,p:"live"==a?l:u,uid:r}),{type:a,paasAppId:s,paasRoomId:l,paasVodId:u,paasAccessToken:c,audioMode:p,liveDelayMode:h,verticalMode:d,autoplay:f,showProgress:_,defaultDefinition:g,posterOption:b,watermarkOption:A,marqueeOption:I}}catch(e){throw $.error("初始化失败",e),e}}initVhallyunLive(){return new Promise(((e,t)=>{this.scheduler.initForLive().then((r=>{this.logReporter.updateReportConfig({s:r.log_info.session_id}),this.scheduler.initGslbLive(r).then((t=>{this.logReporter.updateReportConfig({picture_quality:t.currentQuality,s:r.log_info.session_id}),this.logReporter.start(),e(t)})).catch((e=>{t(e)}))})).catch((e=>{t(e)}))}))}async initVhallyunVod(){return new Promise(((e,t)=>{this.scheduler.initForVod().then((r=>{this.logReporter.updateReportConfig({s:r.log_info.session_id}),this.scheduler.initGslbVod(r).then((t=>{this.logReporter.updateReportConfig({picture_quality:t.currentQuality,s:r.log_info.session_id}),this.logReporter.start(),e(t)})).catch((e=>{t(e)}))})).catch((e=>{t(e)}))}))}getVideoSrc(e,t){return this.logReporter.updateReportConfig({picture_quality:e}),this.scheduler.getVideoSrc(e,t)}resume(){this.logReporter?.resume()}destroy(){this.logReporter?.destroy()}}}(),module.exports=r}();
@@ -1 +1 @@
1
- !function(){"use strict";var e={d:function(t,n){for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{InviteCardServer:function(){return InviteCardServer},default:function(){return s}});const n="sdkStateReady";wx.getAccountInfoSync();const i={trace:0,debug:1,info:2,log:2,warn:3,error:4,silent:5};let a=i.info;function createLogger(e=""){const t=e?`[${e}]`:"",n="[vhall-mp]",enabled=e=>e>=a;return{trace:function trace(...e){enabled(i.trace)&&console.trace(`${n}${t}`,...e)},debug:function debug(...e){enabled(i.debug)&&console.debug(`${n}${t}`,...e)},info:function info(...e){enabled(i.info)&&console.info(`${n}${t}`,...e)},log:function log(...e){enabled(i.log)&&console.log(`${n}${t}`,...e)},warn:function warn(...e){enabled(i.warn)&&console.warn(`${n}${t}`,...e)},error:function error(...e){enabled(i.error)&&console.error(`${n}${t}`,...e)}}}const r=createLogger("InviteCardServer");class InviteCardServer{static name="InviteCardServer";constructor(e){this.sdkInstance=e,this.wxApi=this.sdkInstance.wxApi,this.initEvents()}initEvents(){this.sdkInstance.on(n,(()=>{1==this.sdkInstance.store.get("inviteCardStatus").status&&this.getInviteCode()}))}_parseReqParams(e,t){const n=this.sdkInstance.store.get("watchInitData");let i=this.sdkInstance.store.get("user").user_id;const a={source_id:n?.webinar?.id,source_type:1};if("relationship"===t?(a.be_invite_id=i,a.be_invite_id_type=1):(a.invite_id=i,a.invite_id_type=1),Array.isArray(e))for(const t of e)switch(t){case"language_type":a[t]=0;break;case"channel":a[t]="main";break;case"visitor_id":a[t]=n?.visitor_id||"";break;case"business_uid":a[t]=n?.webinar.userinfo.user_id;break;case"invite_type":a[t]=5}return a}async getInviteCode(){const e=this._parseReqParams(["language_type","channel","business_uid","visitor_id"]);try{const t=await this.wxApi.sendPost("/v1/marketing/app/invite/card/my-invite-card",e);return t&&200===t.code&&t.data?.invite_code?(this.sdkInstance.store.set("invite_code",t.data.invite_code),t.data.invite_code):null}catch(e){return r.error("获取邀请卡信息出现异常,error:",e),null}}async bindInviteRelation(e,t){if(!e||!t)return;const n={invite_code:e,wechat_open_id:t,...this._parseReqParams(["business_uid","invite_type","channel","visitor_id"],"relationship")};r.debug("bindInviteRelation reqParam:",JSON.stringify(n));try{const e=await this.wxApi.sendPost("/v1/marketing/app/invite/card/create-invite-other-relation",n);return e&&e.code,r.debug("bindInviteRelation res:",e),e}catch(e){return r.error("绑定邀约关系出现异常,error:",e),null}}async getInviteCardInfo(){const e=this._parseReqParams(["language_type","channel","business_uid"]),t=await this.wxApi.sendPost("/v1/marketing/app/invite/card/init-invite-card",e);return t&&200===t.code&&t.data&&(this.sdkInstance.store.set("inviteCardInfo",t.data),t.data.invite_code&&this.sdkInstance.store.set("invite_code",t.data.invite_code)),t?.data||null}async getInviteRankList(){const e={pos:0,limit:200,...this._parseReqParams()},t=await this.wxApi.sendPost("/v1/marketing/app/invite/stat/get-top-list",e);return t&&200===t.code&&t.data?t.data:null}async getMyInviteDetails(){const e=this._parseReqParams(["business_uid"]),t=await this.wxApi.sendPost("/v1/marketing/app/invite/stat/my-invite-details",e);return t&&200===t.code&&t.data?t.data:null}async getMyInviteDetailsUrl(){const e=this._parseReqParams(["business_uid"]),t=await this.wxApi.sendPost("/v1/marketing/app/invite/stat/my-invite-details-url",e);return t&&200===t.code&&t.data?t.data:null}}var s=InviteCardServer;module.exports=t}();
1
+ !function(){"use strict";var e={d:function(t,i){for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{InviteCardServer:function(){return InviteCardServer},default:function(){return s}});const i="sdkStateReady";wx.getAccountInfoSync();const n={trace:0,debug:1,info:2,log:2,warn:3,error:4,silent:5};let a=n.info;function formatTime(){const e=new Date,pad=(e,t=2)=>String(e).padStart(t,"0");return`${pad(e.getHours())}:${pad(e.getMinutes())}:${pad(e.getSeconds())}:${pad(e.getMilliseconds(),3)}`}function createLogger(e=""){const t=e?`[${e}]`:"",i="VhallMiniSDK",enabled=e=>e>=a;return{trace:function trace(...e){enabled(n.trace)&&console.trace(`${i} [${formatTime()}] <TRACE> ${t} `,...e)},debug:function debug(...e){enabled(n.debug)&&console.debug(`${i} [${formatTime()}] <DEBUG> ${t} `,...e)},info:function info(...e){enabled(n.info)&&console.info(`${i} [${formatTime()}] <INFO> ${t}`,...e)},log:function log(...e){enabled(n.log)&&console.log(`${i} [${formatTime()}] <LOG> ${t}`,...e)},warn:function warn(...e){enabled(n.warn)&&console.warn(`${i} [${formatTime()}] <WARN> ${t}`,...e)},error:function error(...e){enabled(n.error)&&console.error(`${i} [${formatTime()}] <ERROR> ${t}`,...e)}}}const r=createLogger("InviteCardServer");class InviteCardServer{static name="InviteCardServer";constructor(e){this.sdkInstance=e,this.wxApi=this.sdkInstance.wxApi,this.initEvents()}initEvents(){this.sdkInstance.on(i,(()=>{1==this.sdkInstance.store.get("inviteCardStatus").status&&this.getInviteCode()}))}_parseReqParams(e,t){const i=this.sdkInstance.store.get("watchInitData");let n=this.sdkInstance.store.get("user").user_id;const a={source_id:i?.webinar?.id,source_type:1};if("relationship"===t?(a.be_invite_id=n,a.be_invite_id_type=1):(a.invite_id=n,a.invite_id_type=1),Array.isArray(e))for(const t of e)switch(t){case"language_type":a[t]=0;break;case"channel":a[t]="main";break;case"visitor_id":a[t]=i?.visitor_id||"";break;case"business_uid":a[t]=i?.webinar.userinfo.user_id;break;case"invite_type":a[t]=5}return a}async getInviteCode(){const e=this._parseReqParams(["language_type","channel","business_uid","visitor_id"]);try{const t=await this.wxApi.sendPost("/v1/marketing/app/invite/card/my-invite-card",e);return t&&200===t.code&&t.data?.invite_code?(this.sdkInstance.store.set("invite_code",t.data.invite_code),t.data.invite_code):null}catch(e){return r.error("获取邀请卡信息出现异常,error:",e),null}}async bindInviteRelation(e,t){if(!e||!t)return;const i={invite_code:e,wechat_open_id:t,...this._parseReqParams(["business_uid","invite_type","channel","visitor_id"],"relationship")};r.debug("bindInviteRelation reqParam:",JSON.stringify(i));try{const e=await this.wxApi.sendPost("/v1/marketing/app/invite/card/create-invite-other-relation",i);return e&&e.code,r.debug("bindInviteRelation res:",e),e}catch(e){return r.error("绑定邀约关系出现异常,error:",e),null}}async getInviteCardInfo(){const e=this._parseReqParams(["language_type","channel","business_uid"]),t=await this.wxApi.sendPost("/v1/marketing/app/invite/card/init-invite-card",e);return t&&200===t.code&&t.data&&(this.sdkInstance.store.set("inviteCardInfo",t.data),t.data.invite_code&&this.sdkInstance.store.set("invite_code",t.data.invite_code)),t?.data||null}async getInviteRankList(){const e={pos:0,limit:200,...this._parseReqParams()},t=await this.wxApi.sendPost("/v1/marketing/app/invite/stat/get-top-list",e);return t&&200===t.code&&t.data?t.data:null}async getMyInviteDetails(){const e=this._parseReqParams(["business_uid"]),t=await this.wxApi.sendPost("/v1/marketing/app/invite/stat/my-invite-details",e);return t&&200===t.code&&t.data?t.data:null}async getMyInviteDetailsUrl(){const e=this._parseReqParams(["business_uid"]),t=await this.wxApi.sendPost("/v1/marketing/app/invite/stat/my-invite-details-url",e);return t&&200===t.code&&t.data?t.data:null}}var s=InviteCardServer;module.exports=t}();
@@ -1 +1 @@
1
- !function(){"use strict";var e={d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{MallRewardServer:function(){return MallRewardServer},default:function(){return s}});class BaseServer{constructor(){this.handlers=Object.create(null)}on=(e,t)=>{const r=[];if("object"==typeof e&&null!==e)Object.entries(e).forEach((([e,t])=>{this._validateParams(e,t),this._addHandler(e,t),r.push({type:e,handler:t})}));else{if("string"!=typeof e||"function"!=typeof t)throw new Error("参数格式错误,支持:$on(事件名, 处理函数) 或 $on({事件名: 处理函数, ...})");this._validateParams(e,t),this._addHandler(e,t),r.push({type:e,handler:t})}return()=>{r.forEach((({type:e,handler:t})=>{if(!this.handlers[e])return;const r=this.handlers[e].findIndex((e=>e===t));-1!==r&&(this.handlers[e].splice(r,1),0===this.handlers[e].length&&delete this.handlers[e])}))}};emit=(e,...t)=>{this.handlers[e]&&[...this.handlers[e]].forEach((e=>{e(...t)}))};off=(e,t)=>{if(!this.handlers[e])throw new Error(`不存在事件: ${e}`);if(t){const r=this.handlers[e].findIndex((e=>e===t));this.handlers[e].splice(r,1),0===this.handlers[e].length&&delete this.handlers[e]}else delete this.handlers[e]};_validateParams(e,t){if("string"!=typeof e)throw new Error("事件名必须为字符串");if("function"!=typeof t)throw new Error("事件处理函数必须为函数")}_addHandler(e,t){this.handlers[e]||(this.handlers[e]=[]),this.handlers[e].includes(t)||this.handlers[e].push(t)}}const r={trace:0,debug:1,info:2,log:2,warn:3,error:4,silent:5};let n=r.info;function createLogger(e=""){const t=e?`[${e}]`:"",a="[vhall-mp]",enabled=e=>e>=n;return{trace:function trace(...e){enabled(r.trace)&&console.trace(`${a}${t}`,...e)},debug:function debug(...e){enabled(r.debug)&&console.debug(`${a}${t}`,...e)},info:function info(...e){enabled(r.info)&&console.info(`${a}${t}`,...e)},log:function log(...e){enabled(r.log)&&console.log(`${a}${t}`,...e)},warn:function warn(...e){enabled(r.warn)&&console.warn(`${a}${t}`,...e)},error:function error(...e){enabled(r.error)&&console.error(`${a}${t}`,...e)}}}const a=createLogger("MallRewardServer");class MallRewardServer extends BaseServer{static name="MallRewardServer";constructor(e){super(),this.sdkInstance=e,this.wxApi=e.wxApi}async getValidList(){console.log("mall-reward 获取商城奖励列表");const e=this.sdkInstance.store.get("watchInitData"),t={webinar_id:this.sdkInstance.webinarId,sence_type:5==e?.webinar?.type?1:0,switch_id:e?.switch?.switch_id};try{const e=await this.wxApi.sendPost("/v3/vss/mall-reward/get-valid-list",t,{headers:{"Content-Type":"application/x-www-form-urlencoded"}});return e&&200===e.code&&e.data&&(Array.isArray(e.data.list)&&e.data.list.forEach((e=>{e.tip_setting=function(e){const t=Object.prototype.toString.call(e);if(["[object Array]","[object Object]","[object Null]"].includes(t))return e;try{return JSON.parse(e)}catch(e){return null}}(e.tip_setting)})),this.sdkInstance.store.set("mallRewardInfo",e?.data||null),this.updateActiveMallReward()),e?.data||null}catch(e){return a.error("获取商城奖励列表出现异常,error:",e),null}}updateActiveMallReward(){const e=this.sdkInstance.store.get("mallRewardInfo");if(!e||!e.list||0===e.list.length)return null;let t,r=-1;for(let n=0;n<e.list.length;n++){let a=e.list[n];if(0===a.claim_status&&0===a.viewing_minutes&&1===a.status&&a.remaining_quota>0){r=n;break}0===a.claim_status&&a.viewing_minutes>0&&0===a.status&&a.remaining_quota>0&&(void 0===t||a.watch_minute<t)&&(t=a.viewing_minutes,r=n)}return r>-1?e.list[r]:null}async claimMallReward(e){const t=this.sdkInstance.store.get("watchInitData"),r={reward_id:e,webinar_id:this.sdkInstance.webinarId,sence_type:5==t?.webinar?.type?1:0,switch_id:t?.switch?.switch_id};try{return await this.wxApi.sendPost("/v3/vss/mall-reward/receive",r,{headers:{"Content-Type":"application/x-www-form-urlencoded"}})}catch(e){return a.error("领取商城奖励出现异常,error:",e),e}}}var s=MallRewardServer;module.exports=t}();
1
+ !function(){"use strict";var e={d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{MallRewardServer:function(){return MallRewardServer},default:function(){return i}});class BaseServer{constructor(){this.handlers=Object.create(null)}on=(e,t)=>{const r=[];if("object"==typeof e&&null!==e)Object.entries(e).forEach((([e,t])=>{this._validateParams(e,t),this._addHandler(e,t),r.push({type:e,handler:t})}));else{if("string"!=typeof e||"function"!=typeof t)throw new Error("参数格式错误,支持:$on(事件名, 处理函数) 或 $on({事件名: 处理函数, ...})");this._validateParams(e,t),this._addHandler(e,t),r.push({type:e,handler:t})}return()=>{r.forEach((({type:e,handler:t})=>{if(!this.handlers[e])return;const r=this.handlers[e].findIndex((e=>e===t));-1!==r&&(this.handlers[e].splice(r,1),0===this.handlers[e].length&&delete this.handlers[e])}))}};emit=(e,...t)=>{this.handlers[e]&&[...this.handlers[e]].forEach((e=>{e(...t)}))};off=(e,t)=>{if(!this.handlers[e])throw new Error(`不存在事件: ${e}`);if(t){const r=this.handlers[e].findIndex((e=>e===t));this.handlers[e].splice(r,1),0===this.handlers[e].length&&delete this.handlers[e]}else delete this.handlers[e]};_validateParams(e,t){if("string"!=typeof e)throw new Error("事件名必须为字符串");if("function"!=typeof t)throw new Error("事件处理函数必须为函数")}_addHandler(e,t){this.handlers[e]||(this.handlers[e]=[]),this.handlers[e].includes(t)||this.handlers[e].push(t)}}const r={trace:0,debug:1,info:2,log:2,warn:3,error:4,silent:5};let n=r.info;function formatTime(){const e=new Date,pad=(e,t=2)=>String(e).padStart(t,"0");return`${pad(e.getHours())}:${pad(e.getMinutes())}:${pad(e.getSeconds())}:${pad(e.getMilliseconds(),3)}`}function createLogger(e=""){const t=e?`[${e}]`:"",a="VhallMiniSDK",enabled=e=>e>=n;return{trace:function trace(...e){enabled(r.trace)&&console.trace(`${a} [${formatTime()}] <TRACE> ${t} `,...e)},debug:function debug(...e){enabled(r.debug)&&console.debug(`${a} [${formatTime()}] <DEBUG> ${t} `,...e)},info:function info(...e){enabled(r.info)&&console.info(`${a} [${formatTime()}] <INFO> ${t}`,...e)},log:function log(...e){enabled(r.log)&&console.log(`${a} [${formatTime()}] <LOG> ${t}`,...e)},warn:function warn(...e){enabled(r.warn)&&console.warn(`${a} [${formatTime()}] <WARN> ${t}`,...e)},error:function error(...e){enabled(r.error)&&console.error(`${a} [${formatTime()}] <ERROR> ${t}`,...e)}}}const a=createLogger("MallRewardServer");class MallRewardServer extends BaseServer{static name="MallRewardServer";constructor(e){super(),this.sdkInstance=e,this.wxApi=e.wxApi}async getValidList(){console.log("mall-reward 获取商城奖励列表");const e=this.sdkInstance.store.get("watchInitData"),t={webinar_id:this.sdkInstance.webinarId,sence_type:5==e?.webinar?.type?1:0,switch_id:e?.switch?.switch_id};try{const e=await this.wxApi.sendPost("/v3/vss/mall-reward/get-valid-list",t,{headers:{"Content-Type":"application/x-www-form-urlencoded"}});return e&&200===e.code&&e.data&&(Array.isArray(e.data.list)&&e.data.list.forEach((e=>{e.tip_setting=function(e){const t=Object.prototype.toString.call(e);if(["[object Array]","[object Object]","[object Null]"].includes(t))return e;try{return JSON.parse(e)}catch(e){return null}}(e.tip_setting)})),this.sdkInstance.store.set("mallRewardInfo",e?.data||null),this.updateActiveMallReward()),e?.data||null}catch(e){return a.error("获取商城奖励列表出现异常,error:",e),null}}updateActiveMallReward(){const e=this.sdkInstance.store.get("mallRewardInfo");if(!e||!e.list||0===e.list.length)return null;let t,r=-1;for(let n=0;n<e.list.length;n++){let a=e.list[n];if(0===a.claim_status&&0===a.viewing_minutes&&1===a.status&&a.remaining_quota>0){r=n;break}0===a.claim_status&&a.viewing_minutes>0&&0===a.status&&a.remaining_quota>0&&(void 0===t||a.watch_minute<t)&&(t=a.viewing_minutes,r=n)}return r>-1?e.list[r]:null}async claimMallReward(e){const t=this.sdkInstance.store.get("watchInitData"),r={reward_id:e,webinar_id:this.sdkInstance.webinarId,sence_type:5==t?.webinar?.type?1:0,switch_id:t?.switch?.switch_id};try{return await this.wxApi.sendPost("/v3/vss/mall-reward/receive",r,{headers:{"Content-Type":"application/x-www-form-urlencoded"}})}catch(e){return a.error("领取商城奖励出现异常,error:",e),e}}}var i=MallRewardServer;module.exports=t}();
@@ -1 +1 @@
1
- !function(){"use strict";var t={d:function(e,s){for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{ProductServer:function(){return ProductServer},default:function(){return s}});class BaseServer{constructor(){this.handlers=Object.create(null)}on=(t,e)=>{const s=[];if("object"==typeof t&&null!==t)Object.entries(t).forEach((([t,e])=>{this._validateParams(t,e),this._addHandler(t,e),s.push({type:t,handler:e})}));else{if("string"!=typeof t||"function"!=typeof e)throw new Error("参数格式错误,支持:$on(事件名, 处理函数) 或 $on({事件名: 处理函数, ...})");this._validateParams(t,e),this._addHandler(t,e),s.push({type:t,handler:e})}return()=>{s.forEach((({type:t,handler:e})=>{if(!this.handlers[t])return;const s=this.handlers[t].findIndex((t=>t===e));-1!==s&&(this.handlers[t].splice(s,1),0===this.handlers[t].length&&delete this.handlers[t])}))}};emit=(t,...e)=>{this.handlers[t]&&[...this.handlers[t]].forEach((t=>{t(...e)}))};off=(t,e)=>{if(!this.handlers[t])throw new Error(`不存在事件: ${t}`);if(e){const s=this.handlers[t].findIndex((t=>t===e));this.handlers[t].splice(s,1),0===this.handlers[t].length&&delete this.handlers[t]}else delete this.handlers[t]};_validateParams(t,e){if("string"!=typeof t)throw new Error("事件名必须为字符串");if("function"!=typeof e)throw new Error("事件处理函数必须为函数")}_addHandler(t,e){this.handlers[t]||(this.handlers[t]=[]),this.handlers[t].includes(e)||this.handlers[t].push(e)}}class ProductServer extends BaseServer{static name="ProductServer";constructor(t){super(),this.sdkInstance=t,this.wxApi=t.wxApi,this.productList=[],this.lastMsgTime="",this.listenerEvent(),this.sdkInstance.on(this.sdkInstance.EVENT.FOREGROUND_REFRESH,((...t)=>this.onForeground(...t)))}async getProductList(t){return this.wxApi.sendGet("/v3/goods/webinar/get-online-goods",{...t}).then((t=>(200==t.code&&(t.data=t.data.filter((t=>1==t.status)).map((t=>this._getCurClientBuyTypeInfo(t))),this.productList=t.data,this.sdkInstance.store.set("productList",t.data)),t)))}onForeground=({gap:t})=>{this.getProductList({}).catch((t=>console.error("ProductServer.onForeground refresh failed:",t)))};listenerEvent(){this.sdkInstance.on(this.sdkInstance.EVENT.CUSTOM_MSG,(t=>{["goods_update_info","push_goods_change"].includes(t.data.type)&&t.date_time>this.lastMsgTime&&(this._getProductListByCdn(t.data),this.sdkInstance.BRSAgent?.customLog("product:update"),this.lastMsgTime=t.date_time)}))}async _getProductListByCdn(t){try{const e=await this.wxApi.sendGet(t.cdn_url,{},{timeout:5e3});return this.productList=e.filter((t=>1==t.status)).map((t=>this._getCurClientBuyTypeInfo(t))),this.sdkInstance.store.set("productList",this.productList),e}catch(e){if(console.error("请求 cdn_url 失败:",e),!t.access_url)throw e;try{const e=await this.wxApi.sendGet(t.access_url);return this.productList=e.filter((t=>1==t.status)).map((t=>this._getCurClientBuyTypeInfo(t))),this.sdkInstance.store.set("productList",this.productList),e}catch(t){throw console.error("请求 access_url 也失败:",t),t}}}_getCurClientBuyTypeInfo(t){if(0==t.enable_multi_config)return t;{let e,s,r,n;t.sku.forEach((t=>{const i=Object(t,t.sku_conf);1==i.buy_type?e=i:2==i.buy_type?s=i:3==i.buy_type?r=i:4==i.buy_type&&(n=i)}));const i=e||n||s||r;return Object.assign(t,i,{mini_program_config:n})}}}var s=ProductServer;module.exports=e}();
1
+ !function(){"use strict";var t={d:function(e,s){for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{ProductServer:function(){return ProductServer},default:function(){return s}});class BaseServer{constructor(){this.handlers=Object.create(null)}on=(t,e)=>{const s=[];if("object"==typeof t&&null!==t)Object.entries(t).forEach((([t,e])=>{this._validateParams(t,e),this._addHandler(t,e),s.push({type:t,handler:e})}));else{if("string"!=typeof t||"function"!=typeof e)throw new Error("参数格式错误,支持:$on(事件名, 处理函数) 或 $on({事件名: 处理函数, ...})");this._validateParams(t,e),this._addHandler(t,e),s.push({type:t,handler:e})}return()=>{s.forEach((({type:t,handler:e})=>{if(!this.handlers[t])return;const s=this.handlers[t].findIndex((t=>t===e));-1!==s&&(this.handlers[t].splice(s,1),0===this.handlers[t].length&&delete this.handlers[t])}))}};emit=(t,...e)=>{this.handlers[t]&&[...this.handlers[t]].forEach((t=>{t(...e)}))};off=(t,e)=>{if(!this.handlers[t])throw new Error(`不存在事件: ${t}`);if(e){const s=this.handlers[t].findIndex((t=>t===e));this.handlers[t].splice(s,1),0===this.handlers[t].length&&delete this.handlers[t]}else delete this.handlers[t]};_validateParams(t,e){if("string"!=typeof t)throw new Error("事件名必须为字符串");if("function"!=typeof e)throw new Error("事件处理函数必须为函数")}_addHandler(t,e){this.handlers[t]||(this.handlers[t]=[]),this.handlers[t].includes(e)||this.handlers[t].push(e)}}class ProductServer extends BaseServer{static name="ProductServer";constructor(t){super(),this.sdkInstance=t,this.wxApi=t.wxApi,this.productList=[],this.lastMsgTime="",this.listenerEvent(),this.sdkInstance.on(this.sdkInstance.EVENT.FOREGROUND_REFRESH,((...t)=>this.onForeground(...t)))}async getProductList(t){return this.wxApi.sendGet("/v3/goods/webinar/get-online-goods",{...t}).then((t=>(200==t.code&&(t.data=t.data.filter((t=>1==t.status)).map((t=>this._getCurClientBuyTypeInfo(t))),this.productList=t.data,this.sdkInstance.store.set("productList",t.data)),t)))}onForeground=({gap:t})=>{this.getProductList({}).catch((t=>console.error("ProductServer.onForeground refresh failed:",t)))};listenerEvent(){this.sdkInstance.on(this.sdkInstance.EVENT.CUSTOM_MSG,(t=>{["goods_update_info","push_goods_change"].includes(t.data.type)&&(this.sdkInstance.get("logReportServer").report("116999",{stage:t.data.type,logData:t}),t.date_time>this.lastMsgTime&&(this._getProductListByCdn(t.data),this.sdkInstance.BRSAgent?.customLog("product:update"),this.lastMsgTime=t.date_time))}))}async _getProductListByCdn(t){try{const e=await this.wxApi.sendGet(t.cdn_url,{},{timeout:5e3});return this.sdkInstance.get("logReportServer").report("116999",{stage:"getProductListByCdn",logData:e}),this.productList=e.filter((t=>1==t.status)).map((t=>this._getCurClientBuyTypeInfo(t))),this.sdkInstance.store.set("productList",this.productList),e}catch(e){if(console.error("请求 cdn_url 失败:",e),!t.access_url)throw e;try{const e=await this.wxApi.sendGet(t.access_url);return this.sdkInstance.get("logReportServer").report("116999",{stage:"getProductListByCdn2",logData:e}),this.productList=e.filter((t=>1==t.status)).map((t=>this._getCurClientBuyTypeInfo(t))),this.sdkInstance.store.set("productList",this.productList),e}catch(t){throw console.error("请求 access_url 也失败:",t),t}}}_getCurClientBuyTypeInfo(t){if(0==t.enable_multi_config)return t;{let e,s,r,n;t.sku.forEach((t=>{const o=Object(t,t.sku_conf);1==o.buy_type?e=o:2==o.buy_type?s=o:3==o.buy_type?r=o:4==o.buy_type&&(n=o)}));const o=e||n||s||r;return Object.assign(t,o,{mini_program_config:n})}}}var s=ProductServer;module.exports=e}();
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _utils=require("./utils");class RequestUtil{constructor(e={}){this.baseUrl=e?.baseUrl,this.headers=Object.assign({Accept:"*/*","Content-Type":"application/json","Accept-Language":"zh-CN,zh;q=0.8",platform:e?.platform},e?.headers),this._intercept={config:(e={})=>(e.url=(0,_utils.safeUrlJoin)(this.baseUrl,e.url),e),success:e=>e,fail:e=>e,complete:e=>{}}}setCommonHeaders=function(e,t){this.headers[e]=t};request=function(e){const t=this,s=t._intercept.config(e),r=Object.assign({},t.headers,s.headers);return new Promise((function(e,i){wx.request({url:s.url,data:s.data,header:r,method:s.method||"GET",success:s=>{const r=t._intercept.success(s);e(r.data)},fail:e=>{const s=t._intercept.fail(e);i(s)},complete:e=>{t._intercept.complete(e)}})}))};sendGet=function(e,t,s){return this.request({url:e,method:"GET",data:t,...s})};sendPost=function(e,t,s){return this.request({url:e,method:"POST",data:t,...s})}}exports.default=RequestUtil;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _utils=require("./utils");class RequestUtil{constructor(e={}){this.baseUrl=e?.baseUrl,this.headers=Object.assign({Accept:"*/*","Content-Type":"application/json","Accept-Language":"zh-CN,zh;q=0.8",platform:e?.platform},e?.headers),this._intercept={config:(e={})=>(e.url=(0,_utils.safeUrlJoin)(this.baseUrl,e.url),e),success:e=>e,fail:e=>e,complete:e=>{}}}setCommonHeaders=function(e,t){this.headers[e]=t};request=function(e){const t=this,s=t._intercept.config(e),r=Object.assign({},t.headers,s.headers);return new Promise((function(e,i){wx.request({url:s.url,data:s.data,header:r,method:s.method||"GET",timeout:s.timeout,success:s=>{const r=t._intercept.success(s);e(r.data)},fail:e=>{const s=t._intercept.fail(e);i(s)},complete:e=>{t._intercept.complete(e)}})}))};sendGet=function(e,t,s){return this.request({url:e,method:"GET",data:t,...s})};sendPost=function(e,t,s){return this.request({url:e,method:"POST",data:t,...s})}}exports.default=RequestUtil;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.LOG_LEVEL=void 0,exports.getLogLevel=getLogLevel,exports.log=void 0,exports.setLogLevel=setLogLevel;const LOG_LEVEL=exports.LOG_LEVEL={trace:0,debug:1,info:2,log:2,warn:3,error:4,silent:5};let _logLevel=LOG_LEVEL.info;function setLogLevel(e){"number"!=typeof e?"string"==typeof e&&void 0!==LOG_LEVEL[e.toLowerCase()]&&(_logLevel=LOG_LEVEL[e.toLowerCase()]):_logLevel=e}function getLogLevel(){return _logLevel}function createLogger(e=""){const o=e?`[${e}]`:"",L="[vhall-mp]",enabled=e=>e>=_logLevel;return{trace:function trace(...e){enabled(LOG_LEVEL.trace)&&console.trace(`${L}${o}`,...e)},debug:function debug(...e){enabled(LOG_LEVEL.debug)&&console.debug(`${L}${o}`,...e)},info:function info(...e){enabled(LOG_LEVEL.info)&&console.info(`${L}${o}`,...e)},log:function log(...e){enabled(LOG_LEVEL.log)&&console.log(`${L}${o}`,...e)},warn:function warn(...e){enabled(LOG_LEVEL.warn)&&console.warn(`${L}${o}`,...e)},error:function error(...e){enabled(LOG_LEVEL.error)&&console.error(`${L}${o}`,...e)}}}const log=exports.log={createLogger:createLogger,setLogLevel:setLogLevel,getLogLevel:getLogLevel};var _default=exports.default=createLogger;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.LOG_LEVEL=void 0,exports.formatTime=formatTime,exports.getLogLevel=getLogLevel,exports.log=void 0,exports.setLogLevel=setLogLevel;const LOG_LEVEL=exports.LOG_LEVEL={trace:0,debug:1,info:2,log:2,warn:3,error:4,silent:5};let _logLevel=LOG_LEVEL.info;function setLogLevel(e){if("number"!=typeof e){if("string"==typeof e){const o=e.toLowerCase();if(void 0!==LOG_LEVEL[o])return void(_logLevel=LOG_LEVEL[o]);const t=Number(e);if(Number.isFinite(t))return void(_logLevel=t)}}else _logLevel=e}function getLogLevel(){return _logLevel}function formatTime(){const e=new Date,pad=(e,o=2)=>String(e).padStart(o,"0");return`${pad(e.getHours())}:${pad(e.getMinutes())}:${pad(e.getSeconds())}:${pad(e.getMilliseconds(),3)}`}function createLogger(e=""){const o=e?`[${e}]`:"",t="VhallMiniSDK",enabled=e=>e>=_logLevel;return{trace:function trace(...e){enabled(LOG_LEVEL.trace)&&console.trace(`${t} [${formatTime()}] <TRACE> ${o} `,...e)},debug:function debug(...e){enabled(LOG_LEVEL.debug)&&console.debug(`${t} [${formatTime()}] <DEBUG> ${o} `,...e)},info:function info(...e){enabled(LOG_LEVEL.info)&&console.info(`${t} [${formatTime()}] <INFO> ${o}`,...e)},log:function log(...e){enabled(LOG_LEVEL.log)&&console.log(`${t} [${formatTime()}] <LOG> ${o}`,...e)},warn:function warn(...e){enabled(LOG_LEVEL.warn)&&console.warn(`${t} [${formatTime()}] <WARN> ${o}`,...e)},error:function error(...e){enabled(LOG_LEVEL.error)&&console.error(`${t} [${formatTime()}] <ERROR> ${o}`,...e)}}}const log=exports.log={createLogger:createLogger,setLogLevel:setLogLevel,getLogLevel:getLogLevel};var _default=exports.default=createLogger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vhall-mini-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "author": "vhall",
5
5
  "license": "MIT",
6
6
  "miniprogram": "lib",