@polyv/vote-sdk 2.1.0-rc-20260312.1 → 2.1.0

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
- */y.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(y,C,e){e.r(C),e.d(C,"ELog",function(){return l}),e.d(C,"ELogType",function(){return t}),e.d(C,"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),p=e.n(c);function g(d,E){E===void 0&&(E="polyv_sdk_api_innor");for(var b="",f=0,s=Object.keys(d).filter(function(A){return A!=="sign"}).sort();f<s.length;f++){var B=s[f];b+=""+B+d[B]}return p()(E+b+E).toLocaleUpperCase()}function o(d){return typeof d=="object"&&!Array.isArray(d)&&d!=null}var a=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,b){if(this.elog.channelId){var f=this.elog.channelId,s=Date.now(),B={timestamp:s,ltype:b,sign:g({channelId:f,ltype:b,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,b){if(this.elog.userId){var f=this.elog.userId,s=Date.now(),B={timestamp:s,ltype:b,sign:g({userId:f,ltype:b,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,b=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,b);break;case"vod":A=this.getLogDataByVod(B,b)}if(!A)return;var F=A.url,T=A.data;typeof f=="function"?f(F,T):function(O,D){var R=new FormData;for(var M in D)R.append(M,D[M]);var L=new XMLHttpRequest;L.open("post",O),L.send(R)}(F,T),this.queue=[],this.clearTimer()}catch(O){console.error(O)}}else console.error("sendLogData error, ltype is undefined")}else this.clearTimer()},d}(),w=function(){return(w=Object.assign||function(d){for(var E,b=1,f=arguments.length;b<f;b++)for(var s in E=arguments[b])Object.prototype.hasOwnProperty.call(E,s)&&(d[s]=E[s]);return d}).apply(this,arguments)},x=function(d,E){for(var b=0,f=E.length,s=d.length;b<f;b++,s++)d[s]=E[b];return d},u=Object(n.uuidV4)(),h=navigator.userAgent,l=function(){function d(E){var b,f,s,B,A,F,T,O;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=(b=E.intervalTime)!==null&&b!==void 0?b: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=(F=E.consoleLevel)!==null&&F!==void 0?F:r.TRACE,this.consolePrefix=(T=E.consolePrefix)!==null&&T!==void 0?T:[],this.globalLog=(O=E.globalLog)!==null&&O!==void 0?O:{},this.sendLog=E.sendLog,this.logQueue=new a(this),this.joinLogQueue(t.Info,["user-agent"],{userAgent:h})}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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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,b,f){f===void 0&&(f={});var s=b.length>1?b:b[0],B=this.buildLogData(E,s,f);B&&this.logQueue.joinQueue(B)},d.prototype.buildLogData=function(E,b,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 b)?A.str=""+b:function(T){return Array.isArray(T)}(b)?A.arr=b:typeof b=="object"&&(A.obj=b);var F=this.getGlobalLog(A);return o(F)&&(A=w(w({},A),F)),A}},d.prototype.getGlobalLog=function(E){if(o(this.globalLog))return this.globalLog;if(typeof this.globalLog=="function"){var b=this.globalLog(E);if(o(b))return b}},d.prototype.destroy=function(){this.logQueue.destroy()},d.version="2.2.1",d}()}]);class Bi{constructor(C){$0(this,"__iarCore");$0(this,"iarCore");this.interactionCore=C,this.__iarCore=C,this.iarCore=C}}var xe=(y=>(y.UpdateVotedList="UpdateVotedList",y.Start="Start",y.Stop="Stop",y.VoteResult="VoteResult",y.DeleteAll="DeleteAll",y.Delete="Delete",y.UpdateVoteOrder="UpdateVoteOrder",y))(xe||{});const ye=class ye extends Bi{constructor(e){super(e);$0(this,"VoteEvent",xe);$0(this,"eventEmitter",new Ei);$0(this,"__curVotedList",[]);$0(this,"__votingList",{});$0(this,"__cachedVoteResult",null);$0(this,"__processSocketCache",()=>{this.interactionCore.getSocketCache(ye.appName).forEach(t=>{var r;if(t.event==="onSliceID"){const n=t.data;(r=n.data)!=null&&r.voteList&&(this.__curVotedList=n.data.voteList)}else t.event==="VOTE_RESULT"&&this.__onVoteResult(t.data)})});$0(this,"__onSliceID",e=>{e.data.voteList&&(this.__curVotedList=e.data.voteList,this.eventEmitter.emit(xe.UpdateVotedList,{curVotedList:this.__curVotedList}))});$0(this,"__onVoteStart",e=>{const t={id:e.id,name:e.name,status:"Y",showVoteCount:!1,voteCount:0,voteCoverImage:e.voteCoverImage||e.coverUrl,voteOrder:Number(e.voteOrder)||0};this.__votingList[e.id]=t,this.eventEmitter.emit(xe.Start,{voteData:t})});$0(this,"__onVoteStop",e=>{delete this.__votingList[e.id],this.eventEmitter.emit(xe.Stop,{id:e.id})});$0(this,"__onVoteResult",e=>{this.__cachedVoteResult=e.list,this.eventEmitter.emit(xe.VoteResult,{voteCount:e.voteCount,list:e.list})});$0(this,"__onVoteDeleteAll",()=>{this.eventEmitter.emit(xe.DeleteAll,null)});$0(this,"__onVoteDelete",e=>{this.eventEmitter.emit(xe.Delete,{id:e.id})});$0(this,"__onVoteChangeOrder",e=>{this.eventEmitter.emit(xe.UpdateVoteOrder,{id:e.id,oldOrder:e.oldOrder,newOrder:e.newOrder})});e.addSocketHandles(ye.appName,{onSliceID:this.__onSliceID},"message"),e.addSocketHandles(ye.appName,{START:this.__onVoteStart,STOP:this.__onVoteStop,VOTE_RESULT:this.__onVoteResult,DELETE_ALL:this.__onVoteDeleteAll,DELETE:this.__onVoteDelete,UPDATE_VOTE_ORDER:this.__onVoteChangeOrder},"vote"),this.__processSocketCache()}toVote(e){return Ce(this,null,function*(){if(!e||!this.__votingList[e])return Promise.reject(new Error("Vote id does not exist"));const t={EVENT:"TO_VOTE",id:e};return new Promise(r=>{Ce(this,null,function*(){try{const n=yield this.interactionCore.getSocket();if(!n)return r({code:500,message:"Socket not available"});n.emit("vote",JSON.stringify(t),c=>{try{const p=JSON.parse(c);r(p)}catch(p){r({code:500,message:"Parse response error"})}})}catch(n){r({code:n.code||500,message:n.message||"Vote failed"})}})})})}getVotedList(){return this.__curVotedList}pushVotedList(e){this.__curVotedList.indexOf(e)===-1&&(this.__curVotedList.push(e),this.eventEmitter.emit(xe.UpdateVotedList,{curVotedList:this.__curVotedList}))}getVoteList(){return Ce(this,null,function*(){var e;try{const t=yield this.interactionCore.getChannelInfo(),r=this.interactionCore.getDomainInfo(),n=yield this.interactionCore.staticApi.get(`${r.staticDomain}/vote/${t.channelId}/lastest.json`,{ran:Math.floor(Math.random()*1e6)},{responseType:"json"});return(e=n==null?void 0:n.data)!=null&&e.list&&(n.data.list.forEach((c,p)=>{c.status==="Y"&&(this.__votingList[c.id]=c)}),this.__cachedVoteResult&&this.__applyVoteResult(n.data.list)),n}catch(t){console.error("Get vote list error:",t);return}})}__applyVoteResult(e){this.__cachedVoteResult&&this.__cachedVoteResult.forEach(t=>{const r=e.find(n=>n.id===t.id);r&&(r.showVoteCount=!0,r.voteCount=t.times)})}getCachedVoteResult(){return this.__cachedVoteResult}getVotingList(){return Tt({},this.__votingList)}};$0(ye,"appName","vote");let yt=ye;exports.Vote=yt;exports.VoteEvent=xe;console.log("%c@polyv/vote-sdk","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.1.0-rc-20260312.1]","[buildTime: 2026-03-11 10:13:00]");
25
+ */y.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(y,C,e){e.r(C),e.d(C,"ELog",function(){return l}),e.d(C,"ELogType",function(){return t}),e.d(C,"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),p=e.n(c);function g(d,E){E===void 0&&(E="polyv_sdk_api_innor");for(var b="",f=0,s=Object.keys(d).filter(function(A){return A!=="sign"}).sort();f<s.length;f++){var B=s[f];b+=""+B+d[B]}return p()(E+b+E).toLocaleUpperCase()}function o(d){return typeof d=="object"&&!Array.isArray(d)&&d!=null}var a=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,b){if(this.elog.channelId){var f=this.elog.channelId,s=Date.now(),B={timestamp:s,ltype:b,sign:g({channelId:f,ltype:b,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,b){if(this.elog.userId){var f=this.elog.userId,s=Date.now(),B={timestamp:s,ltype:b,sign:g({userId:f,ltype:b,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,b=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,b);break;case"vod":A=this.getLogDataByVod(B,b)}if(!A)return;var F=A.url,T=A.data;typeof f=="function"?f(F,T):function(O,D){var R=new FormData;for(var M in D)R.append(M,D[M]);var L=new XMLHttpRequest;L.open("post",O),L.send(R)}(F,T),this.queue=[],this.clearTimer()}catch(O){console.error(O)}}else console.error("sendLogData error, ltype is undefined")}else this.clearTimer()},d}(),w=function(){return(w=Object.assign||function(d){for(var E,b=1,f=arguments.length;b<f;b++)for(var s in E=arguments[b])Object.prototype.hasOwnProperty.call(E,s)&&(d[s]=E[s]);return d}).apply(this,arguments)},x=function(d,E){for(var b=0,f=E.length,s=d.length;b<f;b++,s++)d[s]=E[b];return d},u=Object(n.uuidV4)(),h=navigator.userAgent,l=function(){function d(E){var b,f,s,B,A,F,T,O;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=(b=E.intervalTime)!==null&&b!==void 0?b: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=(F=E.consoleLevel)!==null&&F!==void 0?F:r.TRACE,this.consolePrefix=(T=E.consolePrefix)!==null&&T!==void 0?T:[],this.globalLog=(O=E.globalLog)!==null&&O!==void 0?O:{},this.sendLog=E.sendLog,this.logQueue=new a(this),this.joinLogQueue(t.Info,["user-agent"],{userAgent:h})}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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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,b,f){f===void 0&&(f={});var s=b.length>1?b:b[0],B=this.buildLogData(E,s,f);B&&this.logQueue.joinQueue(B)},d.prototype.buildLogData=function(E,b,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 b)?A.str=""+b:function(T){return Array.isArray(T)}(b)?A.arr=b:typeof b=="object"&&(A.obj=b);var F=this.getGlobalLog(A);return o(F)&&(A=w(w({},A),F)),A}},d.prototype.getGlobalLog=function(E){if(o(this.globalLog))return this.globalLog;if(typeof this.globalLog=="function"){var b=this.globalLog(E);if(o(b))return b}},d.prototype.destroy=function(){this.logQueue.destroy()},d.version="2.2.1",d}()}]);class Bi{constructor(C){$0(this,"__iarCore");$0(this,"iarCore");this.interactionCore=C,this.__iarCore=C,this.iarCore=C}}var xe=(y=>(y.UpdateVotedList="UpdateVotedList",y.Start="Start",y.Stop="Stop",y.VoteResult="VoteResult",y.DeleteAll="DeleteAll",y.Delete="Delete",y.UpdateVoteOrder="UpdateVoteOrder",y))(xe||{});const ye=class ye extends Bi{constructor(e){super(e);$0(this,"VoteEvent",xe);$0(this,"eventEmitter",new Ei);$0(this,"__curVotedList",[]);$0(this,"__votingList",{});$0(this,"__cachedVoteResult",null);$0(this,"__processSocketCache",()=>{this.interactionCore.getSocketCache(ye.appName).forEach(t=>{var r;if(t.event==="onSliceID"){const n=t.data;(r=n.data)!=null&&r.voteList&&(this.__curVotedList=n.data.voteList)}else t.event==="VOTE_RESULT"&&this.__onVoteResult(t.data)})});$0(this,"__onSliceID",e=>{e.data.voteList&&(this.__curVotedList=e.data.voteList,this.eventEmitter.emit(xe.UpdateVotedList,{curVotedList:this.__curVotedList}))});$0(this,"__onVoteStart",e=>{const t={id:e.id,name:e.name,status:"Y",showVoteCount:!1,voteCount:0,voteCoverImage:e.voteCoverImage||e.coverUrl,voteOrder:Number(e.voteOrder)||0};this.__votingList[e.id]=t,this.eventEmitter.emit(xe.Start,{voteData:t})});$0(this,"__onVoteStop",e=>{delete this.__votingList[e.id],this.eventEmitter.emit(xe.Stop,{id:e.id})});$0(this,"__onVoteResult",e=>{this.__cachedVoteResult=e.list,this.eventEmitter.emit(xe.VoteResult,{voteCount:e.voteCount,list:e.list})});$0(this,"__onVoteDeleteAll",()=>{this.eventEmitter.emit(xe.DeleteAll,null)});$0(this,"__onVoteDelete",e=>{this.eventEmitter.emit(xe.Delete,{id:e.id})});$0(this,"__onVoteChangeOrder",e=>{this.eventEmitter.emit(xe.UpdateVoteOrder,{id:e.id,oldOrder:e.oldOrder,newOrder:e.newOrder})});e.addSocketHandles(ye.appName,{onSliceID:this.__onSliceID},"message"),e.addSocketHandles(ye.appName,{START:this.__onVoteStart,STOP:this.__onVoteStop,VOTE_RESULT:this.__onVoteResult,DELETE_ALL:this.__onVoteDeleteAll,DELETE:this.__onVoteDelete,UPDATE_VOTE_ORDER:this.__onVoteChangeOrder},"vote"),this.__processSocketCache()}toVote(e){return Ce(this,null,function*(){if(!e||!this.__votingList[e])return Promise.reject(new Error("Vote id does not exist"));const t={EVENT:"TO_VOTE",id:e};return new Promise(r=>{Ce(this,null,function*(){try{const n=yield this.interactionCore.getSocket();if(!n)return r({code:500,message:"Socket not available"});n.emit("vote",JSON.stringify(t),c=>{try{const p=JSON.parse(c);r(p)}catch(p){r({code:500,message:"Parse response error"})}})}catch(n){r({code:n.code||500,message:n.message||"Vote failed"})}})})})}getVotedList(){return this.__curVotedList}pushVotedList(e){this.__curVotedList.indexOf(e)===-1&&(this.__curVotedList.push(e),this.eventEmitter.emit(xe.UpdateVotedList,{curVotedList:this.__curVotedList}))}getVoteList(){return Ce(this,null,function*(){var e;try{const t=yield this.interactionCore.getChannelInfo(),r=this.interactionCore.getDomainInfo(),n=yield this.interactionCore.staticApi.get(`${r.staticDomain}/vote/${t.channelId}/lastest.json`,{ran:Math.floor(Math.random()*1e6)},{responseType:"json"});return(e=n==null?void 0:n.data)!=null&&e.list&&(n.data.list.forEach((c,p)=>{c.status==="Y"&&(this.__votingList[c.id]=c)}),this.__cachedVoteResult&&this.__applyVoteResult(n.data.list)),n}catch(t){console.error("Get vote list error:",t);return}})}__applyVoteResult(e){this.__cachedVoteResult&&this.__cachedVoteResult.forEach(t=>{const r=e.find(n=>n.id===t.id);r&&(r.showVoteCount=!0,r.voteCount=t.times)})}getCachedVoteResult(){return this.__cachedVoteResult}getVotingList(){return Tt({},this.__votingList)}};$0(ye,"appName","vote");let yt=ye;exports.Vote=yt;exports.VoteEvent=xe;console.log("%c@polyv/vote-sdk","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.1.0]","[buildTime: 2026-03-13 02:44:49]");
package/index.es.js CHANGED
@@ -11656,8 +11656,8 @@ let Fr = ye;
11656
11656
  console.log(
11657
11657
  "%c@polyv/vote-sdk",
11658
11658
  "background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff",
11659
- "[version: 2.1.0-rc-20260312.1]",
11660
- "[buildTime: 2026-03-11 10:13:00]"
11659
+ "[version: 2.1.0]",
11660
+ "[buildTime: 2026-03-13 02:44:49]"
11661
11661
  );
11662
11662
  export {
11663
11663
  Fr as Vote,
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
- */y.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(y,C,e){e.r(C),e.d(C,"ELog",function(){return l}),e.d(C,"ELogType",function(){return t}),e.d(C,"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),p=e.n(c);function g(d,E){E===void 0&&(E="polyv_sdk_api_innor");for(var b="",f=0,s=Object.keys(d).filter(function(A){return A!=="sign"}).sort();f<s.length;f++){var B=s[f];b+=""+B+d[B]}return p()(E+b+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,b){if(this.elog.channelId){var f=this.elog.channelId,s=Date.now(),B={timestamp:s,ltype:b,sign:g({channelId:f,ltype:b,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,b){if(this.elog.userId){var f=this.elog.userId,s=Date.now(),B={timestamp:s,ltype:b,sign:g({userId:f,ltype:b,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,b=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,b);break;case"vod":A=this.getLogDataByVod(B,b)}if(!A)return;var F=A.url,T=A.data;typeof f=="function"?f(F,T):function(O,D){var R=new FormData;for(var M in D)R.append(M,D[M]);var L=new XMLHttpRequest;L.open("post",O),L.send(R)}(F,T),this.queue=[],this.clearTimer()}catch(O){console.error(O)}}else console.error("sendLogData error, ltype is undefined")}else this.clearTimer()},d}(),w=function(){return(w=Object.assign||function(d){for(var E,b=1,f=arguments.length;b<f;b++)for(var s in E=arguments[b])Object.prototype.hasOwnProperty.call(E,s)&&(d[s]=E[s]);return d}).apply(this,arguments)},x=function(d,E){for(var b=0,f=E.length,s=d.length;b<f;b++,s++)d[s]=E[b];return d},u=Object(n.uuidV4)(),h=navigator.userAgent,l=function(){function d(E){var b,f,s,B,A,F,T,O;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=(b=E.intervalTime)!==null&&b!==void 0?b: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=(F=E.consoleLevel)!==null&&F!==void 0?F:r.TRACE,this.consolePrefix=(T=E.consolePrefix)!==null&&T!==void 0?T:[],this.globalLog=(O=E.globalLog)!==null&&O!==void 0?O:{},this.sendLog=E.sendLog,this.logQueue=new o(this),this.joinLogQueue(t.Info,["user-agent"],{userAgent:h})}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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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,b,f){f===void 0&&(f={});var s=b.length>1?b:b[0],B=this.buildLogData(E,s,f);B&&this.logQueue.joinQueue(B)},d.prototype.buildLogData=function(E,b,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 b)?A.str=""+b:function(T){return Array.isArray(T)}(b)?A.arr=b:typeof b=="object"&&(A.obj=b);var F=this.getGlobalLog(A);return a(F)&&(A=w(w({},A),F)),A}},d.prototype.getGlobalLog=function(E){if(a(this.globalLog))return this.globalLog;if(typeof this.globalLog=="function"){var b=this.globalLog(E);if(a(b))return b}},d.prototype.destroy=function(){this.logQueue.destroy()},d.version="2.2.1",d}()}]);class jn{constructor(C){ee(this,"__iarCore");ee(this,"iarCore");this.interactionCore=C,this.__iarCore=C,this.iarCore=C}}var se=(y=>(y.UpdateVotedList="UpdateVotedList",y.Start="Start",y.Stop="Stop",y.VoteResult="VoteResult",y.DeleteAll="DeleteAll",y.Delete="Delete",y.UpdateVoteOrder="UpdateVoteOrder",y))(se||{});const Ce=class Ce extends jn{constructor(e){super(e);ee(this,"VoteEvent",se);ee(this,"eventEmitter",new zn);ee(this,"__curVotedList",[]);ee(this,"__votingList",{});ee(this,"__cachedVoteResult",null);ee(this,"__processSocketCache",()=>{this.interactionCore.getSocketCache(Ce.appName).forEach(t=>{var r;if(t.event==="onSliceID"){const n=t.data;(r=n.data)!=null&&r.voteList&&(this.__curVotedList=n.data.voteList)}else t.event==="VOTE_RESULT"&&this.__onVoteResult(t.data)})});ee(this,"__onSliceID",e=>{e.data.voteList&&(this.__curVotedList=e.data.voteList,this.eventEmitter.emit(se.UpdateVotedList,{curVotedList:this.__curVotedList}))});ee(this,"__onVoteStart",e=>{const t={id:e.id,name:e.name,status:"Y",showVoteCount:!1,voteCount:0,voteCoverImage:e.voteCoverImage||e.coverUrl,voteOrder:Number(e.voteOrder)||0};this.__votingList[e.id]=t,this.eventEmitter.emit(se.Start,{voteData:t})});ee(this,"__onVoteStop",e=>{delete this.__votingList[e.id],this.eventEmitter.emit(se.Stop,{id:e.id})});ee(this,"__onVoteResult",e=>{this.__cachedVoteResult=e.list,this.eventEmitter.emit(se.VoteResult,{voteCount:e.voteCount,list:e.list})});ee(this,"__onVoteDeleteAll",()=>{this.eventEmitter.emit(se.DeleteAll,null)});ee(this,"__onVoteDelete",e=>{this.eventEmitter.emit(se.Delete,{id:e.id})});ee(this,"__onVoteChangeOrder",e=>{this.eventEmitter.emit(se.UpdateVoteOrder,{id:e.id,oldOrder:e.oldOrder,newOrder:e.newOrder})});e.addSocketHandles(Ce.appName,{onSliceID:this.__onSliceID},"message"),e.addSocketHandles(Ce.appName,{START:this.__onVoteStart,STOP:this.__onVoteStop,VOTE_RESULT:this.__onVoteResult,DELETE_ALL:this.__onVoteDeleteAll,DELETE:this.__onVoteDelete,UPDATE_VOTE_ORDER:this.__onVoteChangeOrder},"vote"),this.__processSocketCache()}toVote(e){return Pe(this,null,function*(){if(!e||!this.__votingList[e])return Promise.reject(new Error("Vote id does not exist"));const t={EVENT:"TO_VOTE",id:e};return new Promise(r=>{Pe(this,null,function*(){try{const n=yield this.interactionCore.getSocket();if(!n)return r({code:500,message:"Socket not available"});n.emit("vote",JSON.stringify(t),c=>{try{const p=JSON.parse(c);r(p)}catch(p){r({code:500,message:"Parse response error"})}})}catch(n){r({code:n.code||500,message:n.message||"Vote failed"})}})})})}getVotedList(){return this.__curVotedList}pushVotedList(e){this.__curVotedList.indexOf(e)===-1&&(this.__curVotedList.push(e),this.eventEmitter.emit(se.UpdateVotedList,{curVotedList:this.__curVotedList}))}getVoteList(){return Pe(this,null,function*(){var e;try{const t=yield this.interactionCore.getChannelInfo(),r=this.interactionCore.getDomainInfo(),n=yield this.interactionCore.staticApi.get(`${r.staticDomain}/vote/${t.channelId}/lastest.json`,{ran:Math.floor(Math.random()*1e6)},{responseType:"json"});return(e=n==null?void 0:n.data)!=null&&e.list&&(n.data.list.forEach((c,p)=>{c.status==="Y"&&(this.__votingList[c.id]=c)}),this.__cachedVoteResult&&this.__applyVoteResult(n.data.list)),n}catch(t){console.error("Get vote list error:",t);return}})}__applyVoteResult(e){this.__cachedVoteResult&&this.__cachedVoteResult.forEach(t=>{const r=e.find(n=>n.id===t.id);r&&(r.showVoteCount=!0,r.voteCount=t.times)})}getCachedVoteResult(){return this.__cachedVoteResult}getVotingList(){return Pr({},this.__votingList)}};ee(Ce,"appName","vote");let wt=Ce;X0.Vote=wt,X0.VoteEvent=se,Object.defineProperty(X0,Symbol.toStringTag,{value:"Module"})});console.log("%c@polyv/vote-sdk","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.1.0-rc-20260312.1]","[buildTime: 2026-03-11 10:12:56]");
25
+ */y.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(y,C,e){e.r(C),e.d(C,"ELog",function(){return l}),e.d(C,"ELogType",function(){return t}),e.d(C,"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),p=e.n(c);function g(d,E){E===void 0&&(E="polyv_sdk_api_innor");for(var b="",f=0,s=Object.keys(d).filter(function(A){return A!=="sign"}).sort();f<s.length;f++){var B=s[f];b+=""+B+d[B]}return p()(E+b+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,b){if(this.elog.channelId){var f=this.elog.channelId,s=Date.now(),B={timestamp:s,ltype:b,sign:g({channelId:f,ltype:b,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,b){if(this.elog.userId){var f=this.elog.userId,s=Date.now(),B={timestamp:s,ltype:b,sign:g({userId:f,ltype:b,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,b=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,b);break;case"vod":A=this.getLogDataByVod(B,b)}if(!A)return;var F=A.url,T=A.data;typeof f=="function"?f(F,T):function(O,D){var R=new FormData;for(var M in D)R.append(M,D[M]);var L=new XMLHttpRequest;L.open("post",O),L.send(R)}(F,T),this.queue=[],this.clearTimer()}catch(O){console.error(O)}}else console.error("sendLogData error, ltype is undefined")}else this.clearTimer()},d}(),w=function(){return(w=Object.assign||function(d){for(var E,b=1,f=arguments.length;b<f;b++)for(var s in E=arguments[b])Object.prototype.hasOwnProperty.call(E,s)&&(d[s]=E[s]);return d}).apply(this,arguments)},x=function(d,E){for(var b=0,f=E.length,s=d.length;b<f;b++,s++)d[s]=E[b];return d},u=Object(n.uuidV4)(),h=navigator.userAgent,l=function(){function d(E){var b,f,s,B,A,F,T,O;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=(b=E.intervalTime)!==null&&b!==void 0?b: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=(F=E.consoleLevel)!==null&&F!==void 0?F:r.TRACE,this.consolePrefix=(T=E.consolePrefix)!==null&&T!==void 0?T:[],this.globalLog=(O=E.globalLog)!==null&&O!==void 0?O:{},this.sendLog=E.sendLog,this.logQueue=new o(this),this.joinLogQueue(t.Info,["user-agent"],{userAgent:h})}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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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=[],b=0;b<arguments.length;b++)E[b]=arguments[b];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,b,f){f===void 0&&(f={});var s=b.length>1?b:b[0],B=this.buildLogData(E,s,f);B&&this.logQueue.joinQueue(B)},d.prototype.buildLogData=function(E,b,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 b)?A.str=""+b:function(T){return Array.isArray(T)}(b)?A.arr=b:typeof b=="object"&&(A.obj=b);var F=this.getGlobalLog(A);return a(F)&&(A=w(w({},A),F)),A}},d.prototype.getGlobalLog=function(E){if(a(this.globalLog))return this.globalLog;if(typeof this.globalLog=="function"){var b=this.globalLog(E);if(a(b))return b}},d.prototype.destroy=function(){this.logQueue.destroy()},d.version="2.2.1",d}()}]);class jn{constructor(C){ee(this,"__iarCore");ee(this,"iarCore");this.interactionCore=C,this.__iarCore=C,this.iarCore=C}}var se=(y=>(y.UpdateVotedList="UpdateVotedList",y.Start="Start",y.Stop="Stop",y.VoteResult="VoteResult",y.DeleteAll="DeleteAll",y.Delete="Delete",y.UpdateVoteOrder="UpdateVoteOrder",y))(se||{});const Ce=class Ce extends jn{constructor(e){super(e);ee(this,"VoteEvent",se);ee(this,"eventEmitter",new zn);ee(this,"__curVotedList",[]);ee(this,"__votingList",{});ee(this,"__cachedVoteResult",null);ee(this,"__processSocketCache",()=>{this.interactionCore.getSocketCache(Ce.appName).forEach(t=>{var r;if(t.event==="onSliceID"){const n=t.data;(r=n.data)!=null&&r.voteList&&(this.__curVotedList=n.data.voteList)}else t.event==="VOTE_RESULT"&&this.__onVoteResult(t.data)})});ee(this,"__onSliceID",e=>{e.data.voteList&&(this.__curVotedList=e.data.voteList,this.eventEmitter.emit(se.UpdateVotedList,{curVotedList:this.__curVotedList}))});ee(this,"__onVoteStart",e=>{const t={id:e.id,name:e.name,status:"Y",showVoteCount:!1,voteCount:0,voteCoverImage:e.voteCoverImage||e.coverUrl,voteOrder:Number(e.voteOrder)||0};this.__votingList[e.id]=t,this.eventEmitter.emit(se.Start,{voteData:t})});ee(this,"__onVoteStop",e=>{delete this.__votingList[e.id],this.eventEmitter.emit(se.Stop,{id:e.id})});ee(this,"__onVoteResult",e=>{this.__cachedVoteResult=e.list,this.eventEmitter.emit(se.VoteResult,{voteCount:e.voteCount,list:e.list})});ee(this,"__onVoteDeleteAll",()=>{this.eventEmitter.emit(se.DeleteAll,null)});ee(this,"__onVoteDelete",e=>{this.eventEmitter.emit(se.Delete,{id:e.id})});ee(this,"__onVoteChangeOrder",e=>{this.eventEmitter.emit(se.UpdateVoteOrder,{id:e.id,oldOrder:e.oldOrder,newOrder:e.newOrder})});e.addSocketHandles(Ce.appName,{onSliceID:this.__onSliceID},"message"),e.addSocketHandles(Ce.appName,{START:this.__onVoteStart,STOP:this.__onVoteStop,VOTE_RESULT:this.__onVoteResult,DELETE_ALL:this.__onVoteDeleteAll,DELETE:this.__onVoteDelete,UPDATE_VOTE_ORDER:this.__onVoteChangeOrder},"vote"),this.__processSocketCache()}toVote(e){return Pe(this,null,function*(){if(!e||!this.__votingList[e])return Promise.reject(new Error("Vote id does not exist"));const t={EVENT:"TO_VOTE",id:e};return new Promise(r=>{Pe(this,null,function*(){try{const n=yield this.interactionCore.getSocket();if(!n)return r({code:500,message:"Socket not available"});n.emit("vote",JSON.stringify(t),c=>{try{const p=JSON.parse(c);r(p)}catch(p){r({code:500,message:"Parse response error"})}})}catch(n){r({code:n.code||500,message:n.message||"Vote failed"})}})})})}getVotedList(){return this.__curVotedList}pushVotedList(e){this.__curVotedList.indexOf(e)===-1&&(this.__curVotedList.push(e),this.eventEmitter.emit(se.UpdateVotedList,{curVotedList:this.__curVotedList}))}getVoteList(){return Pe(this,null,function*(){var e;try{const t=yield this.interactionCore.getChannelInfo(),r=this.interactionCore.getDomainInfo(),n=yield this.interactionCore.staticApi.get(`${r.staticDomain}/vote/${t.channelId}/lastest.json`,{ran:Math.floor(Math.random()*1e6)},{responseType:"json"});return(e=n==null?void 0:n.data)!=null&&e.list&&(n.data.list.forEach((c,p)=>{c.status==="Y"&&(this.__votingList[c.id]=c)}),this.__cachedVoteResult&&this.__applyVoteResult(n.data.list)),n}catch(t){console.error("Get vote list error:",t);return}})}__applyVoteResult(e){this.__cachedVoteResult&&this.__cachedVoteResult.forEach(t=>{const r=e.find(n=>n.id===t.id);r&&(r.showVoteCount=!0,r.voteCount=t.times)})}getCachedVoteResult(){return this.__cachedVoteResult}getVotingList(){return Pr({},this.__votingList)}};ee(Ce,"appName","vote");let wt=Ce;X0.Vote=wt,X0.VoteEvent=se,Object.defineProperty(X0,Symbol.toStringTag,{value:"Module"})});console.log("%c@polyv/vote-sdk","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.1.0]","[buildTime: 2026-03-13 02:44:45]");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/vote-sdk",
3
- "version": "2.1.0-rc-20260312.1",
3
+ "version": "2.1.0",
4
4
  "main": "./index.es.js",
5
5
  "dependencies": {
6
6
  "@polyv/interaction-core": "*"