@polyv/answer-card-sdk 2.5.0-rc-20250904.4 → 2.5.0-rc-20250904.6

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.
package/index.cjs.js CHANGED
@@ -22,4 +22,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
22
22
  *
23
23
  * @author Feross Aboukhadijeh <https://feross.org>
24
24
  * @license MIT
25
- */d.exports=function(t){return t!=null&&(e(t)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&e(r.slice(0,0))}(t)||!!t._isBuffer)}},function(d,F,e){e.r(F),e.d(F,"ELog",function(){return p}),e.d(F,"ELogType",function(){return t}),e.d(F,"LogLevel",function(){return r});var t,r,n=e(1);(function(h){h.Log="log",h.Debug="debug",h.Info="info",h.Error="error",h.Warn="warn"})(t||(t={})),function(h){h[h.TRACE=0]="TRACE",h[h.DEBUG=1]="DEBUG",h[h.INFO=2]="INFO",h[h.WARN=3]="WARN",h[h.ERROR=4]="ERROR",h[h.NONE=5]="NONE"}(r||(r={}));var c=e(2),v=e.n(c);function g(h,E){E===void 0&&(E="polyv_sdk_api_innor");for(var y="",f=0,s=Object.keys(h).filter(function(A){return A!=="sign"}).sort();f<s.length;f++){var B=s[f];y+=""+B+h[B]}return v()(E+y+E).toLocaleUpperCase()}function o(h){return typeof h=="object"&&!Array.isArray(h)&&h!=null}var a=function(){function h(E){this.elog=E,this.queue=[]}return h.prototype.destroy=function(){this.clearTimer()},h.prototype.startTimer=function(){var E=this;this.timer||(this.timer=window.setInterval(function(){E.sendLogData()},this.elog.intervalTime))},h.prototype.clearTimer=function(){clearInterval(this.timer),this.timer=void 0},h.prototype.joinQueue=function(E){this.queue.push(E),this.queue.length>=this.elog.maxQueueNumber?this.sendLogData():this.startTimer()},h.prototype.getLogDataByLive=function(E,y){if(this.elog.channelId){var f=this.elog.channelId,s=Date.now(),B={timestamp:s,ltype:y,sign:g({channelId:f,ltype:y,timestamp:s}),log:E,channelId:f};return{url:this.elog.customLiveApiUrl?this.elog.customLiveApiUrl:this.elog.elogDomain+"/v4/live/save-elog",data:B}}},h.prototype.getLogDataByVod=function(E,y){if(this.elog.userId){var f=this.elog.userId,s=Date.now(),B={timestamp:s,ltype:y,sign:g({userId:f,ltype:y,timestamp:s}),log:E,userId:f};return{url:this.elog.customVodApiUrl?this.elog.customVodApiUrl:this.elog.elogDomain+"/v4/vod/save-elog",data:B}}},h.prototype.sendLogData=function(){if(this.queue.length!==0){if(this.elog.logEnabled)if(this.elog.ltype){var E=this.elog,y=E.ltype,f=E.sendLog,s=E.useType;try{var B=JSON.stringify(this.queue),A=void 0;switch(s){case"live":A=this.getLogDataByLive(B,y);break;case"vod":A=this.getLogDataByVod(B,y)}if(!A)return;var C=A.url,S=A.data;typeof f=="function"?f(C,S):function(I,D){var R=new FormData;for(var M in D)R.append(M,D[M]);var q=new XMLHttpRequest;q.open("post",I),q.send(R)}(C,S),this.queue=[],this.clearTimer()}catch(I){console.error(I)}}else console.error("sendLogData error, ltype is undefined")}else this.clearTimer()},h}(),w=function(){return(w=Object.assign||function(h){for(var E,y=1,f=arguments.length;y<f;y++)for(var s in E=arguments[y])Object.prototype.hasOwnProperty.call(E,s)&&(h[s]=E[s]);return h}).apply(this,arguments)},x=function(h,E){for(var y=0,f=E.length,s=h.length;y<f;y++,s++)h[s]=E[y];return h},u=Object(n.uuidV4)(),l=navigator.userAgent,p=function(){function h(E){var y,f,s,B,A,C,S,I;E===void 0&&(E={}),this.version="2.2.1",this.elogDomain=this.__getElogDomain(E.elogDomain),this.customLiveApiUrl=E.liveApiUrl,this.customVodApiUrl=E.vodApiUrl,this.useType=E.useType||"live",this.channelId=E.channelId,this.userId=E.userId,this.viewerInfo=E.viewerInfo,this.ltype=E.ltype,this.intervalTime=(y=E.intervalTime)!==null&&y!==void 0?y:5e3,this.maxQueueNumber=(f=E.maxQueueNumber)!==null&&f!==void 0?f:30,this.logEnabled=(s=E.logEnabled)===null||s===void 0||s,this.logLevel=(B=E.logLevel)!==null&&B!==void 0?B:r.TRACE,this.consoleEnabled=(A=E.consoleEnabled)===null||A===void 0||A,this.consoleLevel=(C=E.consoleLevel)!==null&&C!==void 0?C:r.TRACE,this.consolePrefix=(S=E.consolePrefix)!==null&&S!==void 0?S:[],this.globalLog=(I=E.globalLog)!==null&&I!==void 0?I:{},this.sendLog=E.sendLog,this.logQueue=new a(this),this.joinLogQueue(t.Info,["user-agent"],{userAgent:l})}return h.prototype.__getElogDomain=function(E){return E||window.PLV_GLOBAL_URL_ORIGIN&&window.PLV_GLOBAL_URL_ORIGIN.elogOrigin||"https://elog.polyv.net"},h.prototype.setChannelId=function(E){return this.channelId=E,this},h.prototype.setUserId=function(E){return this.userId=E,this},h.prototype.setViewerInfo=function(E){return this.viewerInfo=E,this},h.prototype.setLogEnabled=function(E){return E===void 0&&(E=!0),this.logEnabled=E,this},h.prototype.getMessages=function(){return this.logQueue.queue},h.prototype.getConsoleContent=function(E){return x(x([],this.consolePrefix),E)},h.prototype.compareConsoleLevel=function(E){return this.consoleEnabled&&E>=this.consoleLevel},h.prototype.compareLogLevel=function(E){return E>=this.logLevel},h.prototype.log=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.TRACE;return this.compareConsoleLevel(f)&&console.log.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Log,E),this},h.prototype.debug=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.DEBUG;return this.compareConsoleLevel(f)&&console.debug.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Debug,E),this},h.prototype.info=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.INFO;return this.compareConsoleLevel(f)&&console.info.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Info,E),this},h.prototype.warn=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.WARN;return this.compareConsoleLevel(f)&&console.warn.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Warn,E),this},h.prototype.error=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.ERROR;return this.compareConsoleLevel(f)&&console.error.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Error,E),this},h.prototype.joinLogQueue=function(E,y,f){f===void 0&&(f={});var s=y.length>1?y:y[0],B=this.buildLogData(E,s,f);B&&this.logQueue.joinQueue(B)},h.prototype.buildLogData=function(E,y,f){var s,B;if(f===void 0&&(f={}),this.ltype){var A=w({type:E,uauuid:u,time:Date.now(),ltype:this.ltype,logVersion:this.version,str:"",arr:[],obj:{}},f);!((s=this.viewerInfo)===null||s===void 0)&&s.viewerId&&(A.viewerId=this.viewerInfo.viewerId),!((B=this.viewerInfo)===null||B===void 0)&&B.viewerName&&(A.viewerName=this.viewerInfo.viewerName),["string","number","boolean","undefined"].includes(typeof y)?A.str=""+y:function(S){return Array.isArray(S)}(y)?A.arr=y:typeof y=="object"&&(A.obj=y);var C=this.getGlobalLog(A);return o(C)&&(A=w(w({},A),C)),A}},h.prototype.getGlobalLog=function(E){if(o(this.globalLog))return this.globalLog;if(typeof this.globalLog=="function"){var y=this.globalLog(E);if(o(y))return y}},h.prototype.destroy=function(){this.logQueue.destroy()},h.version="2.2.1",h}()}]);class Bi{constructor(F){ne(this,"__iarCore");ne(this,"iarCore");this.interactionCore=F,this.__iarCore=F,this.iarCore=F}}var Ce=(d=>(d.Quick="quick",d.Question="question",d))(Ce||{}),pe=(d=>(d.SubmitSuccess="SubmitSuccess",d.AnswerCardEnd="AnswerCardEnd",d.AnswerSubmitted="AnswerSubmitted",d.SubmitFailed="SubmitFailed",d))(pe||{}),Ae=(d=>(d.StartAnswerCard="StartAnswerCard",d.StopAnswerCard="StopAnswerCard",d.AnswerCardResult="AnswerCardResult",d))(Ae||{});function wr(d){const F={answerCardType:d.itemType===0?Ce.Question:Ce.Quick,question:{questionId:d.questionId,type:d.type,title:d.name,required:!0,options:Ai(d)}};return d.duration&&(F.duration=d.duration),F}function Ai(d){const F=[],e=Object.keys(d);let t=1;for(;e.includes(`option${t}`);){const r=d[`option${t}`];if(typeof r=="string"){const n={id:yt(t),content:r},c=d[`tips${t}`];c&&(n.tips=c),d.answer&&(n.isRight=d.answer.includes(n.id)),F.push(n)}t++}return F}class wi extends Bi{constructor(e){super(e);ne(this,"AnswerCardType",Ce);ne(this,"AnswerCardEvent",Ae);ne(this,"AnswerCardSubmitResult",pe);ne(this,"eventEmitter",new sn);ne(this,"__currentAnswerCard");ne(this,"__processSocketCache",()=>{const e=this.interactionCore.getSocketCache("answer-card");let t=[];e.forEach(r=>{const n=r.data;switch(n.EVENT){case"GET_TEST_QUESTION_CONTENT":t.push(n);break;case"STOP_TEST_QUESTION":t=t.filter(c=>c.questionId!==n.questionId);break}}),t.length&&this.__onStartAnswerCard(t[t.length-1])});ne(this,"__onStartAnswerCard",e=>ue(this,null,function*(){const t=wr(e);if(e.duration){const r=yield this.__getDuration();t.duration=r,this.__startPollingDuration()}this.__currentAnswerCard=t,this.eventEmitter.emit(Ae.StartAnswerCard,{answerCardData:t})}));ne(this,"__onStopAnswerCard",e=>ue(this,null,function*(){this.__currentAnswerCard=void 0,this.eventEmitter.emit(Ae.StopAnswerCard,{questionId:e.questionId})}));ne(this,"__onAnswerCardResult",e=>ue(this,null,function*(){const t=wr(e.content),r=yield this.__getUserAnswer(t.question.questionId),n=e.result.total;t.question.answerCount=n;const c=t.question.type===Q0.Scor;let v=0;e.result.singleResult.forEach((a,w)=>{const x=a,u=n?Number((a/n*100).toFixed(2)):0,l=t.question.options[w];l.answerCount=x,l.answerPercent=u,c&&(v+=Number(l.content)*x)});const g={answerCardData:t,userAnswer:cn(r,t.question.type),isRight:r===e.result.answer,isSubmitted:!!r},o=n?parseFloat((v/n).toFixed(4)):0;c&&(g.averageScore=o),this.eventEmitter.emit(Ae.AnswerCardResult,{answerCardResult:g})}));ne(this,"__pollingTimer");e.addSocketHandles("answer-card",{GET_TEST_QUESTION_CONTENT:this.__onStartAnswerCard,STOP_TEST_QUESTION:this.__onStopAnswerCard,GET_TEST_QUESTION_RESULT:this.__onAnswerCardResult}),this.__processSocketCache()}__getDuration(){return ue(this,null,function*(){return(yield this.interactionCore.emitSocket({EVENT:"GET_TEST_QUESTION_DURATION"})).time})}__startPollingDuration(){this.__stopPollingDuration(),this.__pollingTimer=window.setInterval(()=>ue(this,null,function*(){var e;if((e=this.__currentAnswerCard)!=null&&e.duration){const t=yield this.__getDuration();this.__currentAnswerCard.duration=t}else this.__stopPollingDuration()}),5e3)}__stopPollingDuration(){this.__pollingTimer&&(window.clearInterval(this.__pollingTimer),this.__pollingTimer=void 0)}__getUserAnswer(e){return ue(this,null,function*(){try{return(yield this.interactionCore.emitSocket({EVENT:"GET_ANSWER",questionId:e},"testQuestion")).answer.option}catch(t){return""}})}getCurrentAnswerCard(){return this.__currentAnswerCard}submitAnswerCard(e){return ue(this,null,function*(){const t=yield this.interactionCore.getChannelInfo(),r=yield this.interactionCore.getUserInfo(),n={EVENT:"ANSWER_TEST_QUESTION",roomId:t.channelId,userId:r.userId,avatar:r.pic,nick:r.nick,questionId:e.answer.questionId,option:un(e.answer)},c=yield this.interactionCore.emitSocket(n,"message",{checkCode:!1});let v=pe.SubmitFailed;switch(c.code){case 200:v=pe.SubmitSuccess;break;case 302:v=pe.AnswerCardEnd;break;case 303:v=pe.AnswerSubmitted;break}return v})}}exports.AnswerCard=wi;exports.AnswerCardSubmitResult=pe;exports.AnswerCardType=Ce;console.log("%c@polyv/answer-card-sdk","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.5.0-rc-20250904.4]","[buildTime: 2025-09-04 03:30:04]");
25
+ */d.exports=function(t){return t!=null&&(e(t)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&e(r.slice(0,0))}(t)||!!t._isBuffer)}},function(d,F,e){e.r(F),e.d(F,"ELog",function(){return p}),e.d(F,"ELogType",function(){return t}),e.d(F,"LogLevel",function(){return r});var t,r,n=e(1);(function(h){h.Log="log",h.Debug="debug",h.Info="info",h.Error="error",h.Warn="warn"})(t||(t={})),function(h){h[h.TRACE=0]="TRACE",h[h.DEBUG=1]="DEBUG",h[h.INFO=2]="INFO",h[h.WARN=3]="WARN",h[h.ERROR=4]="ERROR",h[h.NONE=5]="NONE"}(r||(r={}));var c=e(2),v=e.n(c);function g(h,E){E===void 0&&(E="polyv_sdk_api_innor");for(var y="",f=0,s=Object.keys(h).filter(function(A){return A!=="sign"}).sort();f<s.length;f++){var B=s[f];y+=""+B+h[B]}return v()(E+y+E).toLocaleUpperCase()}function o(h){return typeof h=="object"&&!Array.isArray(h)&&h!=null}var a=function(){function h(E){this.elog=E,this.queue=[]}return h.prototype.destroy=function(){this.clearTimer()},h.prototype.startTimer=function(){var E=this;this.timer||(this.timer=window.setInterval(function(){E.sendLogData()},this.elog.intervalTime))},h.prototype.clearTimer=function(){clearInterval(this.timer),this.timer=void 0},h.prototype.joinQueue=function(E){this.queue.push(E),this.queue.length>=this.elog.maxQueueNumber?this.sendLogData():this.startTimer()},h.prototype.getLogDataByLive=function(E,y){if(this.elog.channelId){var f=this.elog.channelId,s=Date.now(),B={timestamp:s,ltype:y,sign:g({channelId:f,ltype:y,timestamp:s}),log:E,channelId:f};return{url:this.elog.customLiveApiUrl?this.elog.customLiveApiUrl:this.elog.elogDomain+"/v4/live/save-elog",data:B}}},h.prototype.getLogDataByVod=function(E,y){if(this.elog.userId){var f=this.elog.userId,s=Date.now(),B={timestamp:s,ltype:y,sign:g({userId:f,ltype:y,timestamp:s}),log:E,userId:f};return{url:this.elog.customVodApiUrl?this.elog.customVodApiUrl:this.elog.elogDomain+"/v4/vod/save-elog",data:B}}},h.prototype.sendLogData=function(){if(this.queue.length!==0){if(this.elog.logEnabled)if(this.elog.ltype){var E=this.elog,y=E.ltype,f=E.sendLog,s=E.useType;try{var B=JSON.stringify(this.queue),A=void 0;switch(s){case"live":A=this.getLogDataByLive(B,y);break;case"vod":A=this.getLogDataByVod(B,y)}if(!A)return;var C=A.url,S=A.data;typeof f=="function"?f(C,S):function(I,D){var R=new FormData;for(var M in D)R.append(M,D[M]);var q=new XMLHttpRequest;q.open("post",I),q.send(R)}(C,S),this.queue=[],this.clearTimer()}catch(I){console.error(I)}}else console.error("sendLogData error, ltype is undefined")}else this.clearTimer()},h}(),w=function(){return(w=Object.assign||function(h){for(var E,y=1,f=arguments.length;y<f;y++)for(var s in E=arguments[y])Object.prototype.hasOwnProperty.call(E,s)&&(h[s]=E[s]);return h}).apply(this,arguments)},x=function(h,E){for(var y=0,f=E.length,s=h.length;y<f;y++,s++)h[s]=E[y];return h},u=Object(n.uuidV4)(),l=navigator.userAgent,p=function(){function h(E){var y,f,s,B,A,C,S,I;E===void 0&&(E={}),this.version="2.2.1",this.elogDomain=this.__getElogDomain(E.elogDomain),this.customLiveApiUrl=E.liveApiUrl,this.customVodApiUrl=E.vodApiUrl,this.useType=E.useType||"live",this.channelId=E.channelId,this.userId=E.userId,this.viewerInfo=E.viewerInfo,this.ltype=E.ltype,this.intervalTime=(y=E.intervalTime)!==null&&y!==void 0?y:5e3,this.maxQueueNumber=(f=E.maxQueueNumber)!==null&&f!==void 0?f:30,this.logEnabled=(s=E.logEnabled)===null||s===void 0||s,this.logLevel=(B=E.logLevel)!==null&&B!==void 0?B:r.TRACE,this.consoleEnabled=(A=E.consoleEnabled)===null||A===void 0||A,this.consoleLevel=(C=E.consoleLevel)!==null&&C!==void 0?C:r.TRACE,this.consolePrefix=(S=E.consolePrefix)!==null&&S!==void 0?S:[],this.globalLog=(I=E.globalLog)!==null&&I!==void 0?I:{},this.sendLog=E.sendLog,this.logQueue=new a(this),this.joinLogQueue(t.Info,["user-agent"],{userAgent:l})}return h.prototype.__getElogDomain=function(E){return E||window.PLV_GLOBAL_URL_ORIGIN&&window.PLV_GLOBAL_URL_ORIGIN.elogOrigin||"https://elog.polyv.net"},h.prototype.setChannelId=function(E){return this.channelId=E,this},h.prototype.setUserId=function(E){return this.userId=E,this},h.prototype.setViewerInfo=function(E){return this.viewerInfo=E,this},h.prototype.setLogEnabled=function(E){return E===void 0&&(E=!0),this.logEnabled=E,this},h.prototype.getMessages=function(){return this.logQueue.queue},h.prototype.getConsoleContent=function(E){return x(x([],this.consolePrefix),E)},h.prototype.compareConsoleLevel=function(E){return this.consoleEnabled&&E>=this.consoleLevel},h.prototype.compareLogLevel=function(E){return E>=this.logLevel},h.prototype.log=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.TRACE;return this.compareConsoleLevel(f)&&console.log.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Log,E),this},h.prototype.debug=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.DEBUG;return this.compareConsoleLevel(f)&&console.debug.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Debug,E),this},h.prototype.info=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.INFO;return this.compareConsoleLevel(f)&&console.info.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Info,E),this},h.prototype.warn=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.WARN;return this.compareConsoleLevel(f)&&console.warn.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Warn,E),this},h.prototype.error=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.ERROR;return this.compareConsoleLevel(f)&&console.error.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Error,E),this},h.prototype.joinLogQueue=function(E,y,f){f===void 0&&(f={});var s=y.length>1?y:y[0],B=this.buildLogData(E,s,f);B&&this.logQueue.joinQueue(B)},h.prototype.buildLogData=function(E,y,f){var s,B;if(f===void 0&&(f={}),this.ltype){var A=w({type:E,uauuid:u,time:Date.now(),ltype:this.ltype,logVersion:this.version,str:"",arr:[],obj:{}},f);!((s=this.viewerInfo)===null||s===void 0)&&s.viewerId&&(A.viewerId=this.viewerInfo.viewerId),!((B=this.viewerInfo)===null||B===void 0)&&B.viewerName&&(A.viewerName=this.viewerInfo.viewerName),["string","number","boolean","undefined"].includes(typeof y)?A.str=""+y:function(S){return Array.isArray(S)}(y)?A.arr=y:typeof y=="object"&&(A.obj=y);var C=this.getGlobalLog(A);return o(C)&&(A=w(w({},A),C)),A}},h.prototype.getGlobalLog=function(E){if(o(this.globalLog))return this.globalLog;if(typeof this.globalLog=="function"){var y=this.globalLog(E);if(o(y))return y}},h.prototype.destroy=function(){this.logQueue.destroy()},h.version="2.2.1",h}()}]);class Bi{constructor(F){ne(this,"__iarCore");ne(this,"iarCore");this.interactionCore=F,this.__iarCore=F,this.iarCore=F}}var Ce=(d=>(d.Quick="quick",d.Question="question",d))(Ce||{}),pe=(d=>(d.SubmitSuccess="SubmitSuccess",d.AnswerCardEnd="AnswerCardEnd",d.AnswerSubmitted="AnswerSubmitted",d.SubmitFailed="SubmitFailed",d))(pe||{}),Ae=(d=>(d.StartAnswerCard="StartAnswerCard",d.StopAnswerCard="StopAnswerCard",d.AnswerCardResult="AnswerCardResult",d))(Ae||{});function wr(d){const F={answerCardType:d.itemType===0?Ce.Question:Ce.Quick,question:{questionId:d.questionId,type:d.type,title:d.name,required:!0,options:Ai(d)}};return d.duration&&(F.duration=d.duration),F}function Ai(d){const F=[],e=Object.keys(d);let t=1;for(;e.includes(`option${t}`);){const r=d[`option${t}`];if(typeof r=="string"&&r){const n={id:yt(t),content:r},c=d[`tips${t}`];c&&(n.tips=c),d.answer&&(n.isRight=d.answer.includes(n.id)),F.push(n)}else break;t++}return F}class wi extends Bi{constructor(e){super(e);ne(this,"AnswerCardType",Ce);ne(this,"AnswerCardEvent",Ae);ne(this,"AnswerCardSubmitResult",pe);ne(this,"eventEmitter",new sn);ne(this,"__currentAnswerCard");ne(this,"__processSocketCache",()=>{const e=this.interactionCore.getSocketCache("answer-card");let t=[];e.forEach(r=>{const n=r.data;switch(n.EVENT){case"GET_TEST_QUESTION_CONTENT":t.push(n);break;case"STOP_TEST_QUESTION":t=t.filter(c=>c.questionId!==n.questionId);break}}),t.length&&this.__onStartAnswerCard(t[t.length-1])});ne(this,"__onStartAnswerCard",e=>ue(this,null,function*(){const t=wr(e);if(localStorage.getItem(`answer-card-${e.questionId}`)&&localStorage.removeItem(`answer-card-${e.questionId}`),e.duration){const n=yield this.__getDuration();t.duration=n,this.__startPollingDuration()}this.__currentAnswerCard=t,this.eventEmitter.emit(Ae.StartAnswerCard,{answerCardData:t})}));ne(this,"__onStopAnswerCard",e=>ue(this,null,function*(){this.__currentAnswerCard=void 0,this.eventEmitter.emit(Ae.StopAnswerCard,{questionId:e.questionId})}));ne(this,"__onAnswerCardResult",e=>ue(this,null,function*(){const t=wr(e.content),r=yield this.__getUserAnswer(t.question.questionId),n=e.result.total;t.question.answerCount=n;const c=t.question.type===Q0.Scor;let v=0;e.result.singleResult.forEach((a,w)=>{const x=a,u=n?Number((a/n*100).toFixed(2)):0,l=t.question.options[w];l.answerCount=x,l.answerPercent=u,c&&(v+=Number(l.content)*x)});const g={answerCardData:t,userAnswer:cn(r,t.question.type),isRight:r===e.result.answer,isSubmitted:!!r},o=n?parseFloat((v/n).toFixed(4)):0;c&&(g.averageScore=o),this.eventEmitter.emit(Ae.AnswerCardResult,{answerCardResult:g})}));ne(this,"__pollingTimer");e.addSocketHandles("answer-card",{GET_TEST_QUESTION_CONTENT:this.__onStartAnswerCard,STOP_TEST_QUESTION:this.__onStopAnswerCard,GET_TEST_QUESTION_RESULT:this.__onAnswerCardResult}),this.__processSocketCache()}__getDuration(){return ue(this,null,function*(){return(yield this.interactionCore.emitSocket({EVENT:"GET_TEST_QUESTION_DURATION"})).time})}__startPollingDuration(){this.__stopPollingDuration(),this.__pollingTimer=window.setInterval(()=>ue(this,null,function*(){var e;if((e=this.__currentAnswerCard)!=null&&e.duration){const t=yield this.__getDuration();this.__currentAnswerCard.duration=t}else this.__stopPollingDuration()}),5e3)}__stopPollingDuration(){this.__pollingTimer&&(window.clearInterval(this.__pollingTimer),this.__pollingTimer=void 0)}__getUserAnswer(e){return ue(this,null,function*(){try{const t=localStorage.getItem(`answer-card-${e}`);return t||(yield this.interactionCore.emitSocket({EVENT:"GET_ANSWER",questionId:e},"testQuestion")).answer.option}catch(t){return""}})}getCurrentAnswerCard(){return this.__currentAnswerCard}__saveAnswer(e,t){localStorage.setItem(`answer-card-${e}`,t)}submitAnswerCard(e){return ue(this,null,function*(){const t=yield this.interactionCore.getChannelInfo(),r=yield this.interactionCore.getUserInfo(),n=un(e.answer),c={EVENT:"ANSWER_TEST_QUESTION",roomId:t.channelId,userId:r.userId,avatar:r.pic,nick:r.nick,questionId:e.answer.questionId,option:n},v=yield this.interactionCore.emitSocket(c,"message",{checkCode:!1});let g=pe.SubmitFailed;switch(v.code){case 200:g=pe.SubmitSuccess,this.__saveAnswer(e.answer.questionId,n);break;case 302:g=pe.AnswerCardEnd;break;case 303:g=pe.AnswerSubmitted;break}return g})}}exports.AnswerCard=wi;exports.AnswerCardSubmitResult=pe;exports.AnswerCardType=Ce;console.log("%c@polyv/answer-card-sdk","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.5.0-rc-20250904.6]","[buildTime: 2025-09-04 12:57:12]");
package/index.es.d.ts CHANGED
@@ -32,6 +32,7 @@ export declare class AnswerCard extends InteractionBase {
32
32
  * 获取当前答题卡数据
33
33
  */
34
34
  getCurrentAnswerCard(): AnswerCardData | undefined;
35
+ private __saveAnswer;
35
36
  /**
36
37
  * 提交答题卡
37
38
  * @param options 提交答案数据
package/index.es.js CHANGED
@@ -11473,13 +11473,14 @@ function Ai(d) {
11473
11473
  let t = 1;
11474
11474
  for (; e.includes(`option${t}`); ) {
11475
11475
  const r = d[`option${t}`];
11476
- if (typeof r == "string") {
11476
+ if (typeof r == "string" && r) {
11477
11477
  const n = {
11478
11478
  id: yt(t),
11479
11479
  content: r
11480
11480
  }, c = d[`tips${t}`];
11481
11481
  c && (n.tips = c), d.answer && (n.isRight = d.answer.includes(n.id)), F.push(n);
11482
- }
11482
+ } else
11483
+ break;
11483
11484
  t++;
11484
11485
  }
11485
11486
  return F;
@@ -11509,9 +11510,9 @@ class Di extends Bi {
11509
11510
  });
11510
11511
  ne(this, "__onStartAnswerCard", (e) => ue(this, null, function* () {
11511
11512
  const t = wr(e);
11512
- if (e.duration) {
11513
- const r = yield this.__getDuration();
11514
- t.duration = r, this.__startPollingDuration();
11513
+ if (localStorage.getItem(`answer-card-${e.questionId}`) && localStorage.removeItem(`answer-card-${e.questionId}`), e.duration) {
11514
+ const n = yield this.__getDuration();
11515
+ t.duration = n, this.__startPollingDuration();
11515
11516
  }
11516
11517
  this.__currentAnswerCard = t, this.eventEmitter.emit(Ae.StartAnswerCard, {
11517
11518
  answerCardData: t
@@ -11579,7 +11580,8 @@ class Di extends Bi {
11579
11580
  __getUserAnswer(e) {
11580
11581
  return ue(this, null, function* () {
11581
11582
  try {
11582
- return (yield this.interactionCore.emitSocket({
11583
+ const t = localStorage.getItem(`answer-card-${e}`);
11584
+ return t || (yield this.interactionCore.emitSocket({
11583
11585
  EVENT: "GET_ANSWER",
11584
11586
  questionId: e
11585
11587
  }, "testQuestion")).answer.option;
@@ -11594,6 +11596,9 @@ class Di extends Bi {
11594
11596
  getCurrentAnswerCard() {
11595
11597
  return this.__currentAnswerCard;
11596
11598
  }
11599
+ __saveAnswer(e, t) {
11600
+ localStorage.setItem(`answer-card-${e}`, t);
11601
+ }
11597
11602
  /**
11598
11603
  * 提交答题卡
11599
11604
  * @param options 提交答案数据
@@ -11601,36 +11606,36 @@ class Di extends Bi {
11601
11606
  */
11602
11607
  submitAnswerCard(e) {
11603
11608
  return ue(this, null, function* () {
11604
- const t = yield this.interactionCore.getChannelInfo(), r = yield this.interactionCore.getUserInfo(), n = {
11609
+ const t = yield this.interactionCore.getChannelInfo(), r = yield this.interactionCore.getUserInfo(), n = un(e.answer), c = {
11605
11610
  EVENT: "ANSWER_TEST_QUESTION",
11606
11611
  roomId: t.channelId,
11607
11612
  userId: r.userId,
11608
11613
  avatar: r.pic,
11609
11614
  nick: r.nick,
11610
11615
  questionId: e.answer.questionId,
11611
- option: un(e.answer)
11612
- }, c = yield this.interactionCore.emitSocket(n, "message", { checkCode: !1 });
11613
- let v = ge.SubmitFailed;
11614
- switch (c.code) {
11616
+ option: n
11617
+ }, v = yield this.interactionCore.emitSocket(c, "message", { checkCode: !1 });
11618
+ let g = ge.SubmitFailed;
11619
+ switch (v.code) {
11615
11620
  case 200:
11616
- v = ge.SubmitSuccess;
11621
+ g = ge.SubmitSuccess, this.__saveAnswer(e.answer.questionId, n);
11617
11622
  break;
11618
11623
  case 302:
11619
- v = ge.AnswerCardEnd;
11624
+ g = ge.AnswerCardEnd;
11620
11625
  break;
11621
11626
  case 303:
11622
- v = ge.AnswerSubmitted;
11627
+ g = ge.AnswerSubmitted;
11623
11628
  break;
11624
11629
  }
11625
- return v;
11630
+ return g;
11626
11631
  });
11627
11632
  }
11628
11633
  }
11629
11634
  console.log(
11630
11635
  "%c@polyv/answer-card-sdk",
11631
11636
  "background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff",
11632
- "[version: 2.5.0-rc-20250904.4]",
11633
- "[buildTime: 2025-09-04 03:30:04]"
11637
+ "[version: 2.5.0-rc-20250904.6]",
11638
+ "[buildTime: 2025-09-04 12:57:11]"
11634
11639
  );
11635
11640
  export {
11636
11641
  Di as AnswerCard,
package/index.umd.js CHANGED
@@ -22,4 +22,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
22
22
  *
23
23
  * @author Feross Aboukhadijeh <https://feross.org>
24
24
  * @license MIT
25
- */h.exports=function(t){return t!=null&&(e(t)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&e(r.slice(0,0))}(t)||!!t._isBuffer)}},function(h,F,e){e.r(F),e.d(F,"ELog",function(){return p}),e.d(F,"ELogType",function(){return t}),e.d(F,"LogLevel",function(){return r});var t,r,n=e(1);(function(d){d.Log="log",d.Debug="debug",d.Info="info",d.Error="error",d.Warn="warn"})(t||(t={})),function(d){d[d.TRACE=0]="TRACE",d[d.DEBUG=1]="DEBUG",d[d.INFO=2]="INFO",d[d.WARN=3]="WARN",d[d.ERROR=4]="ERROR",d[d.NONE=5]="NONE"}(r||(r={}));var c=e(2),v=e.n(c);function g(d,E){E===void 0&&(E="polyv_sdk_api_innor");for(var y="",f=0,s=Object.keys(d).filter(function(A){return A!=="sign"}).sort();f<s.length;f++){var B=s[f];y+=""+B+d[B]}return v()(E+y+E).toLocaleUpperCase()}function a(d){return typeof d=="object"&&!Array.isArray(d)&&d!=null}var o=function(){function d(E){this.elog=E,this.queue=[]}return d.prototype.destroy=function(){this.clearTimer()},d.prototype.startTimer=function(){var E=this;this.timer||(this.timer=window.setInterval(function(){E.sendLogData()},this.elog.intervalTime))},d.prototype.clearTimer=function(){clearInterval(this.timer),this.timer=void 0},d.prototype.joinQueue=function(E){this.queue.push(E),this.queue.length>=this.elog.maxQueueNumber?this.sendLogData():this.startTimer()},d.prototype.getLogDataByLive=function(E,y){if(this.elog.channelId){var f=this.elog.channelId,s=Date.now(),B={timestamp:s,ltype:y,sign:g({channelId:f,ltype:y,timestamp:s}),log:E,channelId:f};return{url:this.elog.customLiveApiUrl?this.elog.customLiveApiUrl:this.elog.elogDomain+"/v4/live/save-elog",data:B}}},d.prototype.getLogDataByVod=function(E,y){if(this.elog.userId){var f=this.elog.userId,s=Date.now(),B={timestamp:s,ltype:y,sign:g({userId:f,ltype:y,timestamp:s}),log:E,userId:f};return{url:this.elog.customVodApiUrl?this.elog.customVodApiUrl:this.elog.elogDomain+"/v4/vod/save-elog",data:B}}},d.prototype.sendLogData=function(){if(this.queue.length!==0){if(this.elog.logEnabled)if(this.elog.ltype){var E=this.elog,y=E.ltype,f=E.sendLog,s=E.useType;try{var B=JSON.stringify(this.queue),A=void 0;switch(s){case"live":A=this.getLogDataByLive(B,y);break;case"vod":A=this.getLogDataByVod(B,y)}if(!A)return;var C=A.url,S=A.data;typeof f=="function"?f(C,S):function(I,D){var R=new FormData;for(var M in D)R.append(M,D[M]);var q=new XMLHttpRequest;q.open("post",I),q.send(R)}(C,S),this.queue=[],this.clearTimer()}catch(I){console.error(I)}}else console.error("sendLogData error, ltype is undefined")}else this.clearTimer()},d}(),w=function(){return(w=Object.assign||function(d){for(var E,y=1,f=arguments.length;y<f;y++)for(var s in E=arguments[y])Object.prototype.hasOwnProperty.call(E,s)&&(d[s]=E[s]);return d}).apply(this,arguments)},x=function(d,E){for(var y=0,f=E.length,s=d.length;y<f;y++,s++)d[s]=E[y];return d},u=Object(n.uuidV4)(),l=navigator.userAgent,p=function(){function d(E){var y,f,s,B,A,C,S,I;E===void 0&&(E={}),this.version="2.2.1",this.elogDomain=this.__getElogDomain(E.elogDomain),this.customLiveApiUrl=E.liveApiUrl,this.customVodApiUrl=E.vodApiUrl,this.useType=E.useType||"live",this.channelId=E.channelId,this.userId=E.userId,this.viewerInfo=E.viewerInfo,this.ltype=E.ltype,this.intervalTime=(y=E.intervalTime)!==null&&y!==void 0?y:5e3,this.maxQueueNumber=(f=E.maxQueueNumber)!==null&&f!==void 0?f:30,this.logEnabled=(s=E.logEnabled)===null||s===void 0||s,this.logLevel=(B=E.logLevel)!==null&&B!==void 0?B:r.TRACE,this.consoleEnabled=(A=E.consoleEnabled)===null||A===void 0||A,this.consoleLevel=(C=E.consoleLevel)!==null&&C!==void 0?C:r.TRACE,this.consolePrefix=(S=E.consolePrefix)!==null&&S!==void 0?S:[],this.globalLog=(I=E.globalLog)!==null&&I!==void 0?I:{},this.sendLog=E.sendLog,this.logQueue=new o(this),this.joinLogQueue(t.Info,["user-agent"],{userAgent:l})}return d.prototype.__getElogDomain=function(E){return E||window.PLV_GLOBAL_URL_ORIGIN&&window.PLV_GLOBAL_URL_ORIGIN.elogOrigin||"https://elog.polyv.net"},d.prototype.setChannelId=function(E){return this.channelId=E,this},d.prototype.setUserId=function(E){return this.userId=E,this},d.prototype.setViewerInfo=function(E){return this.viewerInfo=E,this},d.prototype.setLogEnabled=function(E){return E===void 0&&(E=!0),this.logEnabled=E,this},d.prototype.getMessages=function(){return this.logQueue.queue},d.prototype.getConsoleContent=function(E){return x(x([],this.consolePrefix),E)},d.prototype.compareConsoleLevel=function(E){return this.consoleEnabled&&E>=this.consoleLevel},d.prototype.compareLogLevel=function(E){return E>=this.logLevel},d.prototype.log=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.TRACE;return this.compareConsoleLevel(f)&&console.log.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Log,E),this},d.prototype.debug=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.DEBUG;return this.compareConsoleLevel(f)&&console.debug.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Debug,E),this},d.prototype.info=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.INFO;return this.compareConsoleLevel(f)&&console.info.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Info,E),this},d.prototype.warn=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.WARN;return this.compareConsoleLevel(f)&&console.warn.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Warn,E),this},d.prototype.error=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.ERROR;return this.compareConsoleLevel(f)&&console.error.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Error,E),this},d.prototype.joinLogQueue=function(E,y,f){f===void 0&&(f={});var s=y.length>1?y:y[0],B=this.buildLogData(E,s,f);B&&this.logQueue.joinQueue(B)},d.prototype.buildLogData=function(E,y,f){var s,B;if(f===void 0&&(f={}),this.ltype){var A=w({type:E,uauuid:u,time:Date.now(),ltype:this.ltype,logVersion:this.version,str:"",arr:[],obj:{}},f);!((s=this.viewerInfo)===null||s===void 0)&&s.viewerId&&(A.viewerId=this.viewerInfo.viewerId),!((B=this.viewerInfo)===null||B===void 0)&&B.viewerName&&(A.viewerName=this.viewerInfo.viewerName),["string","number","boolean","undefined"].includes(typeof y)?A.str=""+y:function(S){return Array.isArray(S)}(y)?A.arr=y:typeof y=="object"&&(A.obj=y);var C=this.getGlobalLog(A);return a(C)&&(A=w(w({},A),C)),A}},d.prototype.getGlobalLog=function(E){if(a(this.globalLog))return this.globalLog;if(typeof this.globalLog=="function"){var y=this.globalLog(E);if(a(y))return y}},d.prototype.destroy=function(){this.logQueue.destroy()},d.version="2.2.1",d}()}]);class Nn{constructor(F){oe(this,"__iarCore");oe(this,"iarCore");this.interactionCore=F,this.__iarCore=F,this.iarCore=F}}var De=(h=>(h.Quick="quick",h.Question="question",h))(De||{}),Be=(h=>(h.SubmitSuccess="SubmitSuccess",h.AnswerCardEnd="AnswerCardEnd",h.AnswerSubmitted="AnswerSubmitted",h.SubmitFailed="SubmitFailed",h))(Be||{}),Se=(h=>(h.StartAnswerCard="StartAnswerCard",h.StopAnswerCard="StopAnswerCard",h.AnswerCardResult="AnswerCardResult",h))(Se||{});function Tr(h){const F={answerCardType:h.itemType===0?De.Question:De.Quick,question:{questionId:h.questionId,type:h.type,title:h.name,required:!0,options:Hn(h)}};return h.duration&&(F.duration=h.duration),F}function Hn(h){const F=[],e=Object.keys(h);let t=1;for(;e.includes(`option${t}`);){const r=h[`option${t}`];if(typeof r=="string"){const n={id:Fe(t),content:r},c=h[`tips${t}`];c&&(n.tips=c),h.answer&&(n.isRight=h.answer.includes(n.id)),F.push(n)}t++}return F}class Un extends Nn{constructor(e){super(e);oe(this,"AnswerCardType",De);oe(this,"AnswerCardEvent",Se);oe(this,"AnswerCardSubmitResult",Be);oe(this,"eventEmitter",new J0);oe(this,"__currentAnswerCard");oe(this,"__processSocketCache",()=>{const e=this.interactionCore.getSocketCache("answer-card");let t=[];e.forEach(r=>{const n=r.data;switch(n.EVENT){case"GET_TEST_QUESTION_CONTENT":t.push(n);break;case"STOP_TEST_QUESTION":t=t.filter(c=>c.questionId!==n.questionId);break}}),t.length&&this.__onStartAnswerCard(t[t.length-1])});oe(this,"__onStartAnswerCard",e=>ve(this,null,function*(){const t=Tr(e);if(e.duration){const r=yield this.__getDuration();t.duration=r,this.__startPollingDuration()}this.__currentAnswerCard=t,this.eventEmitter.emit(Se.StartAnswerCard,{answerCardData:t})}));oe(this,"__onStopAnswerCard",e=>ve(this,null,function*(){this.__currentAnswerCard=void 0,this.eventEmitter.emit(Se.StopAnswerCard,{questionId:e.questionId})}));oe(this,"__onAnswerCardResult",e=>ve(this,null,function*(){const t=Tr(e.content),r=yield this.__getUserAnswer(t.question.questionId),n=e.result.total;t.question.answerCount=n;const c=t.question.type===j0.Scor;let v=0;e.result.singleResult.forEach((o,w)=>{const x=o,u=n?Number((o/n*100).toFixed(2)):0,l=t.question.options[w];l.answerCount=x,l.answerPercent=u,c&&(v+=Number(l.content)*x)});const g={answerCardData:t,userAnswer:je(r,t.question.type),isRight:r===e.result.answer,isSubmitted:!!r},a=n?parseFloat((v/n).toFixed(4)):0;c&&(g.averageScore=a),this.eventEmitter.emit(Se.AnswerCardResult,{answerCardResult:g})}));oe(this,"__pollingTimer");e.addSocketHandles("answer-card",{GET_TEST_QUESTION_CONTENT:this.__onStartAnswerCard,STOP_TEST_QUESTION:this.__onStopAnswerCard,GET_TEST_QUESTION_RESULT:this.__onAnswerCardResult}),this.__processSocketCache()}__getDuration(){return ve(this,null,function*(){return(yield this.interactionCore.emitSocket({EVENT:"GET_TEST_QUESTION_DURATION"})).time})}__startPollingDuration(){this.__stopPollingDuration(),this.__pollingTimer=window.setInterval(()=>ve(this,null,function*(){var e;if((e=this.__currentAnswerCard)!=null&&e.duration){const t=yield this.__getDuration();this.__currentAnswerCard.duration=t}else this.__stopPollingDuration()}),5e3)}__stopPollingDuration(){this.__pollingTimer&&(window.clearInterval(this.__pollingTimer),this.__pollingTimer=void 0)}__getUserAnswer(e){return ve(this,null,function*(){try{return(yield this.interactionCore.emitSocket({EVENT:"GET_ANSWER",questionId:e},"testQuestion")).answer.option}catch(t){return""}})}getCurrentAnswerCard(){return this.__currentAnswerCard}submitAnswerCard(e){return ve(this,null,function*(){const t=yield this.interactionCore.getChannelInfo(),r=yield this.interactionCore.getUserInfo(),n={EVENT:"ANSWER_TEST_QUESTION",roomId:t.channelId,userId:r.userId,avatar:r.pic,nick:r.nick,questionId:e.answer.questionId,option:Re(e.answer)},c=yield this.interactionCore.emitSocket(n,"message",{checkCode:!1});let v=Be.SubmitFailed;switch(c.code){case 200:v=Be.SubmitSuccess;break;case 302:v=Be.AnswerCardEnd;break;case 303:v=Be.AnswerSubmitted;break}return v})}}Y0.AnswerCard=Un,Y0.AnswerCardSubmitResult=Be,Y0.AnswerCardType=De,Object.defineProperty(Y0,Symbol.toStringTag,{value:"Module"})});console.log("%c@polyv/answer-card-sdk","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.5.0-rc-20250904.4]","[buildTime: 2025-09-04 03:29:59]");
25
+ */h.exports=function(t){return t!=null&&(e(t)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&e(r.slice(0,0))}(t)||!!t._isBuffer)}},function(h,F,e){e.r(F),e.d(F,"ELog",function(){return p}),e.d(F,"ELogType",function(){return t}),e.d(F,"LogLevel",function(){return r});var t,r,n=e(1);(function(d){d.Log="log",d.Debug="debug",d.Info="info",d.Error="error",d.Warn="warn"})(t||(t={})),function(d){d[d.TRACE=0]="TRACE",d[d.DEBUG=1]="DEBUG",d[d.INFO=2]="INFO",d[d.WARN=3]="WARN",d[d.ERROR=4]="ERROR",d[d.NONE=5]="NONE"}(r||(r={}));var c=e(2),v=e.n(c);function g(d,E){E===void 0&&(E="polyv_sdk_api_innor");for(var y="",f=0,s=Object.keys(d).filter(function(A){return A!=="sign"}).sort();f<s.length;f++){var B=s[f];y+=""+B+d[B]}return v()(E+y+E).toLocaleUpperCase()}function a(d){return typeof d=="object"&&!Array.isArray(d)&&d!=null}var o=function(){function d(E){this.elog=E,this.queue=[]}return d.prototype.destroy=function(){this.clearTimer()},d.prototype.startTimer=function(){var E=this;this.timer||(this.timer=window.setInterval(function(){E.sendLogData()},this.elog.intervalTime))},d.prototype.clearTimer=function(){clearInterval(this.timer),this.timer=void 0},d.prototype.joinQueue=function(E){this.queue.push(E),this.queue.length>=this.elog.maxQueueNumber?this.sendLogData():this.startTimer()},d.prototype.getLogDataByLive=function(E,y){if(this.elog.channelId){var f=this.elog.channelId,s=Date.now(),B={timestamp:s,ltype:y,sign:g({channelId:f,ltype:y,timestamp:s}),log:E,channelId:f};return{url:this.elog.customLiveApiUrl?this.elog.customLiveApiUrl:this.elog.elogDomain+"/v4/live/save-elog",data:B}}},d.prototype.getLogDataByVod=function(E,y){if(this.elog.userId){var f=this.elog.userId,s=Date.now(),B={timestamp:s,ltype:y,sign:g({userId:f,ltype:y,timestamp:s}),log:E,userId:f};return{url:this.elog.customVodApiUrl?this.elog.customVodApiUrl:this.elog.elogDomain+"/v4/vod/save-elog",data:B}}},d.prototype.sendLogData=function(){if(this.queue.length!==0){if(this.elog.logEnabled)if(this.elog.ltype){var E=this.elog,y=E.ltype,f=E.sendLog,s=E.useType;try{var B=JSON.stringify(this.queue),A=void 0;switch(s){case"live":A=this.getLogDataByLive(B,y);break;case"vod":A=this.getLogDataByVod(B,y)}if(!A)return;var C=A.url,S=A.data;typeof f=="function"?f(C,S):function(I,D){var R=new FormData;for(var M in D)R.append(M,D[M]);var q=new XMLHttpRequest;q.open("post",I),q.send(R)}(C,S),this.queue=[],this.clearTimer()}catch(I){console.error(I)}}else console.error("sendLogData error, ltype is undefined")}else this.clearTimer()},d}(),w=function(){return(w=Object.assign||function(d){for(var E,y=1,f=arguments.length;y<f;y++)for(var s in E=arguments[y])Object.prototype.hasOwnProperty.call(E,s)&&(d[s]=E[s]);return d}).apply(this,arguments)},x=function(d,E){for(var y=0,f=E.length,s=d.length;y<f;y++,s++)d[s]=E[y];return d},u=Object(n.uuidV4)(),l=navigator.userAgent,p=function(){function d(E){var y,f,s,B,A,C,S,I;E===void 0&&(E={}),this.version="2.2.1",this.elogDomain=this.__getElogDomain(E.elogDomain),this.customLiveApiUrl=E.liveApiUrl,this.customVodApiUrl=E.vodApiUrl,this.useType=E.useType||"live",this.channelId=E.channelId,this.userId=E.userId,this.viewerInfo=E.viewerInfo,this.ltype=E.ltype,this.intervalTime=(y=E.intervalTime)!==null&&y!==void 0?y:5e3,this.maxQueueNumber=(f=E.maxQueueNumber)!==null&&f!==void 0?f:30,this.logEnabled=(s=E.logEnabled)===null||s===void 0||s,this.logLevel=(B=E.logLevel)!==null&&B!==void 0?B:r.TRACE,this.consoleEnabled=(A=E.consoleEnabled)===null||A===void 0||A,this.consoleLevel=(C=E.consoleLevel)!==null&&C!==void 0?C:r.TRACE,this.consolePrefix=(S=E.consolePrefix)!==null&&S!==void 0?S:[],this.globalLog=(I=E.globalLog)!==null&&I!==void 0?I:{},this.sendLog=E.sendLog,this.logQueue=new o(this),this.joinLogQueue(t.Info,["user-agent"],{userAgent:l})}return d.prototype.__getElogDomain=function(E){return E||window.PLV_GLOBAL_URL_ORIGIN&&window.PLV_GLOBAL_URL_ORIGIN.elogOrigin||"https://elog.polyv.net"},d.prototype.setChannelId=function(E){return this.channelId=E,this},d.prototype.setUserId=function(E){return this.userId=E,this},d.prototype.setViewerInfo=function(E){return this.viewerInfo=E,this},d.prototype.setLogEnabled=function(E){return E===void 0&&(E=!0),this.logEnabled=E,this},d.prototype.getMessages=function(){return this.logQueue.queue},d.prototype.getConsoleContent=function(E){return x(x([],this.consolePrefix),E)},d.prototype.compareConsoleLevel=function(E){return this.consoleEnabled&&E>=this.consoleLevel},d.prototype.compareLogLevel=function(E){return E>=this.logLevel},d.prototype.log=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.TRACE;return this.compareConsoleLevel(f)&&console.log.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Log,E),this},d.prototype.debug=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.DEBUG;return this.compareConsoleLevel(f)&&console.debug.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Debug,E),this},d.prototype.info=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.INFO;return this.compareConsoleLevel(f)&&console.info.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Info,E),this},d.prototype.warn=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.WARN;return this.compareConsoleLevel(f)&&console.warn.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Warn,E),this},d.prototype.error=function(){for(var E=[],y=0;y<arguments.length;y++)E[y]=arguments[y];var f=r.ERROR;return this.compareConsoleLevel(f)&&console.error.apply(console,this.getConsoleContent(E)),this.compareLogLevel(f)&&this.joinLogQueue(t.Error,E),this},d.prototype.joinLogQueue=function(E,y,f){f===void 0&&(f={});var s=y.length>1?y:y[0],B=this.buildLogData(E,s,f);B&&this.logQueue.joinQueue(B)},d.prototype.buildLogData=function(E,y,f){var s,B;if(f===void 0&&(f={}),this.ltype){var A=w({type:E,uauuid:u,time:Date.now(),ltype:this.ltype,logVersion:this.version,str:"",arr:[],obj:{}},f);!((s=this.viewerInfo)===null||s===void 0)&&s.viewerId&&(A.viewerId=this.viewerInfo.viewerId),!((B=this.viewerInfo)===null||B===void 0)&&B.viewerName&&(A.viewerName=this.viewerInfo.viewerName),["string","number","boolean","undefined"].includes(typeof y)?A.str=""+y:function(S){return Array.isArray(S)}(y)?A.arr=y:typeof y=="object"&&(A.obj=y);var C=this.getGlobalLog(A);return a(C)&&(A=w(w({},A),C)),A}},d.prototype.getGlobalLog=function(E){if(a(this.globalLog))return this.globalLog;if(typeof this.globalLog=="function"){var y=this.globalLog(E);if(a(y))return y}},d.prototype.destroy=function(){this.logQueue.destroy()},d.version="2.2.1",d}()}]);class Nn{constructor(F){oe(this,"__iarCore");oe(this,"iarCore");this.interactionCore=F,this.__iarCore=F,this.iarCore=F}}var De=(h=>(h.Quick="quick",h.Question="question",h))(De||{}),Be=(h=>(h.SubmitSuccess="SubmitSuccess",h.AnswerCardEnd="AnswerCardEnd",h.AnswerSubmitted="AnswerSubmitted",h.SubmitFailed="SubmitFailed",h))(Be||{}),Se=(h=>(h.StartAnswerCard="StartAnswerCard",h.StopAnswerCard="StopAnswerCard",h.AnswerCardResult="AnswerCardResult",h))(Se||{});function Tr(h){const F={answerCardType:h.itemType===0?De.Question:De.Quick,question:{questionId:h.questionId,type:h.type,title:h.name,required:!0,options:Hn(h)}};return h.duration&&(F.duration=h.duration),F}function Hn(h){const F=[],e=Object.keys(h);let t=1;for(;e.includes(`option${t}`);){const r=h[`option${t}`];if(typeof r=="string"&&r){const n={id:Fe(t),content:r},c=h[`tips${t}`];c&&(n.tips=c),h.answer&&(n.isRight=h.answer.includes(n.id)),F.push(n)}else break;t++}return F}class Un extends Nn{constructor(e){super(e);oe(this,"AnswerCardType",De);oe(this,"AnswerCardEvent",Se);oe(this,"AnswerCardSubmitResult",Be);oe(this,"eventEmitter",new J0);oe(this,"__currentAnswerCard");oe(this,"__processSocketCache",()=>{const e=this.interactionCore.getSocketCache("answer-card");let t=[];e.forEach(r=>{const n=r.data;switch(n.EVENT){case"GET_TEST_QUESTION_CONTENT":t.push(n);break;case"STOP_TEST_QUESTION":t=t.filter(c=>c.questionId!==n.questionId);break}}),t.length&&this.__onStartAnswerCard(t[t.length-1])});oe(this,"__onStartAnswerCard",e=>ve(this,null,function*(){const t=Tr(e);if(localStorage.getItem(`answer-card-${e.questionId}`)&&localStorage.removeItem(`answer-card-${e.questionId}`),e.duration){const n=yield this.__getDuration();t.duration=n,this.__startPollingDuration()}this.__currentAnswerCard=t,this.eventEmitter.emit(Se.StartAnswerCard,{answerCardData:t})}));oe(this,"__onStopAnswerCard",e=>ve(this,null,function*(){this.__currentAnswerCard=void 0,this.eventEmitter.emit(Se.StopAnswerCard,{questionId:e.questionId})}));oe(this,"__onAnswerCardResult",e=>ve(this,null,function*(){const t=Tr(e.content),r=yield this.__getUserAnswer(t.question.questionId),n=e.result.total;t.question.answerCount=n;const c=t.question.type===j0.Scor;let v=0;e.result.singleResult.forEach((o,w)=>{const x=o,u=n?Number((o/n*100).toFixed(2)):0,l=t.question.options[w];l.answerCount=x,l.answerPercent=u,c&&(v+=Number(l.content)*x)});const g={answerCardData:t,userAnswer:je(r,t.question.type),isRight:r===e.result.answer,isSubmitted:!!r},a=n?parseFloat((v/n).toFixed(4)):0;c&&(g.averageScore=a),this.eventEmitter.emit(Se.AnswerCardResult,{answerCardResult:g})}));oe(this,"__pollingTimer");e.addSocketHandles("answer-card",{GET_TEST_QUESTION_CONTENT:this.__onStartAnswerCard,STOP_TEST_QUESTION:this.__onStopAnswerCard,GET_TEST_QUESTION_RESULT:this.__onAnswerCardResult}),this.__processSocketCache()}__getDuration(){return ve(this,null,function*(){return(yield this.interactionCore.emitSocket({EVENT:"GET_TEST_QUESTION_DURATION"})).time})}__startPollingDuration(){this.__stopPollingDuration(),this.__pollingTimer=window.setInterval(()=>ve(this,null,function*(){var e;if((e=this.__currentAnswerCard)!=null&&e.duration){const t=yield this.__getDuration();this.__currentAnswerCard.duration=t}else this.__stopPollingDuration()}),5e3)}__stopPollingDuration(){this.__pollingTimer&&(window.clearInterval(this.__pollingTimer),this.__pollingTimer=void 0)}__getUserAnswer(e){return ve(this,null,function*(){try{const t=localStorage.getItem(`answer-card-${e}`);return t||(yield this.interactionCore.emitSocket({EVENT:"GET_ANSWER",questionId:e},"testQuestion")).answer.option}catch(t){return""}})}getCurrentAnswerCard(){return this.__currentAnswerCard}__saveAnswer(e,t){localStorage.setItem(`answer-card-${e}`,t)}submitAnswerCard(e){return ve(this,null,function*(){const t=yield this.interactionCore.getChannelInfo(),r=yield this.interactionCore.getUserInfo(),n=Re(e.answer),c={EVENT:"ANSWER_TEST_QUESTION",roomId:t.channelId,userId:r.userId,avatar:r.pic,nick:r.nick,questionId:e.answer.questionId,option:n},v=yield this.interactionCore.emitSocket(c,"message",{checkCode:!1});let g=Be.SubmitFailed;switch(v.code){case 200:g=Be.SubmitSuccess,this.__saveAnswer(e.answer.questionId,n);break;case 302:g=Be.AnswerCardEnd;break;case 303:g=Be.AnswerSubmitted;break}return g})}}Y0.AnswerCard=Un,Y0.AnswerCardSubmitResult=Be,Y0.AnswerCardType=De,Object.defineProperty(Y0,Symbol.toStringTag,{value:"Module"})});console.log("%c@polyv/answer-card-sdk","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.5.0-rc-20250904.6]","[buildTime: 2025-09-04 12:57:07]");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/answer-card-sdk",
3
- "version": "2.5.0-rc-20250904.4",
3
+ "version": "2.5.0-rc-20250904.6",
4
4
  "main": "./index.es.js",
5
5
  "dependencies": {
6
6
  "@polyv/interaction-core": "*",