@polyv/chat 2.6.0-rc-20260205.2 → 2.7.0-rc-20260312.1
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 +1 -1
- package/index.es.js +2 -2
- package/index.umd.js +1 -1
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
18
18
|
* @license MIT
|
|
19
|
-
*/o.exports=function(e){return e!=null&&(t(e)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&t(r.slice(0,0))}(e)||!!e._isBuffer)}},function(o,a,t){t.r(a),t.d(a,"ChatImageUpload",function(){return ct}),t.d(a,"defaultConfig",function(){return ht}),t.d(a,"allowAccept",function(){return Et}),t.d(a,"allowFileExtension",function(){return gt}),t.d(a,"FailError",function(){return ot}),t.d(a,"FailCode",function(){return H}),t.d(a,"ChatImage",function(){return xt}),t.d(a,"ImageStatus",function(){return nt}),t(127),t(92),t(63),t(35),t(67),t(135),t(136),t(73);var e=Object.prototype.hasOwnProperty;function r(C,I){return e.call(C,I)}function n(C){if(C==null)throw new TypeError("Cannot convert undefined or null to object");for(var I=0;I<(arguments.length<=1?0:arguments.length-1);I++){var k=I+1<1||arguments.length<=I+1?void 0:arguments[I+1];if(k!=null)for(var M in k)M!=="__proto__"&&r(k,M)&&(C[M]=k[M])}return C}var i=Object.prototype.toString;t(74),t(53),t(151),t(152),t(154);function s(C,I){var k,M,x=n({encode:encodeURIComponent},I),$=[];function j(Q,J){J==null&&(J=""),J===""&&x.ignoreEmpty||(typeof x.encode=="function"&&(Q=x.encode(Q),J=x.encode(String(J))),$.push(Q+"="+J))}function K(Q){j(k,Q)}for(k in C)r(C,k)&&(M=C[k],Array.isArray(M)?M.forEach(K):j(k,M));return $.join("&")}t(116),t(155);function c(C,I,k){if(C==null||I==null)return C;var M=(C=String(C)).indexOf("#"),x="";return M!==-1&&(x=C.substring(M,C.length),C=C.substring(0,M)),(C=C.replace(/[?&]$/,""))+((I=typeof I!="string"?s(I,k):I.replace(/^[?&]/,""))?(C.indexOf("?")!==-1?"&":"?")+I:"")+x}t(157),t(159),t(117),t(160),t(161),t(162),t(163),t(164),t(120),t(167),t(173),t(174),t(175),t(176),t(178),t(179);function l(C){return(l=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(I){return typeof I}:function(I){return I&&typeof Symbol=="function"&&I.constructor===Symbol&&I!==Symbol.prototype?"symbol":typeof I})(C)}function u(C,I){if(I&&(l(I)==="object"||typeof I=="function"))return I;if(I!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return function(k){if(k===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return k}(C)}function d(C){var I=typeof Map=="function"?new Map:void 0;return(d=function(k){if(k===null||(M=k,Function.toString.call(M).indexOf("[native code]")===-1))return k;var M;if(typeof k!="function")throw new TypeError("Super expression must either be null or a function");if(I!==void 0){if(I.has(k))return I.get(k);I.set(k,x)}function x(){return p(k,arguments,g(this).constructor)}return x.prototype=Object.create(k.prototype,{constructor:{value:x,enumerable:!1,writable:!0,configurable:!0}}),h(x,k)})(C)}function p(C,I,k){return(p=f()?Reflect.construct:function(M,x,$){var j=[null];j.push.apply(j,x);var K=new(Function.bind.apply(M,j));return $&&h(K,$.prototype),K}).apply(null,arguments)}function f(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(C){return!1}}function h(C,I){return(h=Object.setPrototypeOf||function(k,M){return k.__proto__=M,k})(C,I)}function g(C){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(I){return I.__proto__||Object.getPrototypeOf(I)})(C)}var v=function(C){(function(j,K){if(typeof K!="function"&&K!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(K&&K.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),K&&h(j,K)})($,C);var I,k,M,x=(I=$,k=f(),function(){var j,K=g(I);if(k){var Q=g(this).constructor;j=Reflect.construct(K,arguments,Q)}else j=K.apply(this,arguments);return u(this,j)});function $(j){var K;return function(Q,J){if(!(Q instanceof J))throw new TypeError("Cannot call a class as a function")}(this,$),(K=x.call(this,j)).name="AJAXError",K}return M=$,Object.defineProperty(M,"prototype",{writable:!1}),M}(d(Error)),y=/(?:^|;\s*)(?:application|text)\/([a-z]+)/i;t(180),t(182),t(183);function b(C,I,k,M){return function(){var x,$,j,K=(C.responseText||"").trim();switch(I.responseType||((j=C.getResponseHeader("Content-Type"))&&y.test(j)?RegExp.$1.toLowerCase():"")){case"json":if(K)try{x=JSON.parse(K)}catch(st){$="Invalid JSON structure"}break;case"xml":(x=C.responseXML)&&x.documentElement||($="Invalid XML format");break;default:x=K}var Q,J={xhr:C,options:I,data:x},N=C.status;(function(st){return!(st===void 0||st>=200&&st<300||st===1223||st===304)})(N)?(Q=new v("Error (HTTP status code: "+N+")")).code=N:$&&(Q=new v($)),Q?M(n(Q,J)):k(J)}}var m=Object.create(null),w=0;function _(C,I,k,M){C.onload=b(C,I,k,M),C.ontimeout=function(){var $;M((($=new v("Request timeout")).isTimeout=!0,$))},C.onerror=function(){M(new v("Network error"))},I.onDownloadProgress&&C.addEventListener("progress",I.onDownloadProgress),I.onUploadProgress&&C.upload&&C.upload.addEventListener("progress",I.onUploadProgress),w===Number.MAX_SAFE_INTEGER&&(w=0);var x=++w;return m[x]={xhr:C,options:I,resolve:k,reject:M},x}function S(C){delete m[C]}function E(C,I,k,M,x){return C&&/MSIE\s+(\d+)/.test(navigator.userAgent)&&parseInt(RegExp.$1)<10&&window.XDomainRequest&&(I==="get"||I==="post")&&!k&&!x&&function($){if($!=null){if(Array.isArray($))return!$.length;for(var j in $)if(r($,j))return!1}return!0}(M)?new window.XDomainRequest:new window.XMLHttpRequest}function O(C,I,k,M){var x,$,j;if(k!=null&&C!=="get")return M==="json"?(x=JSON.stringify(k),$="application/json; charset=utf-8"):(j=k,typeof(x=i.call(j)==="[object Object]"?s(k,{ignoreEmpty:!1}):k)=="string"&&($="application/x-www-form-urlencoded; charset=utf-8")),I["Content-Type"]=I["Content-Type"]||$,x}function T(C,I){var k=0;return new Promise(function(M,x){(I=n({},I)).method=I.method||"get",I.requestType=I.requestType||"",I.responseType=I.responseType||"json",I.timeout=I.timeout||0;var $=I.method.toLowerCase(),j=I.requestType.toLowerCase(),K=I.headers||{},Q=function(st){var R=document.createElement("div");R.innerHTML='<a href="'+st+'"></a>';var G=R.firstChild,W=G.host!==location.host;return R=null,G=null,W}(C=function(st,R,G){return R!=null&&(st=c(st,R,{ignoreEmpty:!1})),G&&(st=c(st,{_:Date.now()})),st}(C,I.params,I.preventCaching)),J=E(Q,$,j,K,I.withCredentials);k=_(J,I,function(st){S(k),M(st)},function(st){S(k),x(st)}),J.open($,C,!0,I.username,I.password);var N=O($,K,I.data,j);(function(st,R,G,W){R.timeout&&(st.timeout=R.timeout),G&&R.withCredentials!=null&&(st.withCredentials=!!R.withCredentials),G||W["X-Request-With"]!=null||(W["X-Request-With"]="XMLHttpRequest"),Object.keys(W).forEach(function(X){W[X]!=null&&st.setRequestHeader(X,String(W[X]))})})(J,I,Q,K),typeof I.beforeSend=="function"&&I.beforeSend.call(window,J),J.send(N||""),typeof I.receiveCancelId=="function"&&I.receiveCancelId(k)})}var A=t(82),U=t.n(A);function V(C){return C.name.toLowerCase().split(".").pop()||""}function F(C){var I=new FormData;for(var k in C)I.append(k,C[k]);return I}function z(C,I,k){k===void 0&&(k=!1);for(var M=C.split(","),x=/:(.*?);/.exec(M[0]),$=x?x[1]:"image/jpeg",j=window.atob(M[1]),K=j.length,Q=new Uint8Array(K);K--;)Q[K]=j.charCodeAt(K);return k?new Blob([Q],{type:$}):new File([Q],I,{type:$})}function B(C){return new Promise(function(I,k){var M=new Image;M.onload=function(){I({width:M.width,height:M.height,imageTarget:M})},M.onerror=function(){k(new Error("获取图片尺寸失败"))};var x="";x=typeof C=="string"?C:L(C),M.src=x})}function L(C){return(window.URL||window.webkitURL).createObjectURL(C)}var P,D,H,Z=(P=function(C,I){return(P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(k,M){k.__proto__=M}||function(k,M){for(var x in M)Object.prototype.hasOwnProperty.call(M,x)&&(k[x]=M[x])})(C,I)},function(C,I){if(typeof I!="function"&&I!==null)throw new TypeError("Class extends value "+String(I)+" is not a constructor or null");function k(){this.constructor=C}P(C,I),C.prototype=I===null?Object.create(I):(k.prototype=I.prototype,new k)});(function(C){C.EMPTY_FILE="empty file",C.FILE_SIZE_TOO_LARGE="file size too large",C.FILE_TYPE_NOT_ALLOW="file type not allow",C.FILE_EXTENSION_NOT_ALLOW="file extension not allow",C.GET_UPLOAD_TOKEN_ERROR="get upload token error",C.UPLOAD_IMAGE_ERROR="upload image error",C.PORN_IDENTIFY_ERROR="porn identify error"})(H||(H={}));var nt,ot=function(C){function I(k){var M=C.call(this,k)||this,x=I.getFailErrorData(k);return M.failCode=x.failCode,M.failMessage=x.failMessage,M}return Z(I,C),I.getFailErrorData=function(k){return{failCode:k,failMessage:I.failMessageVal[k]}},I.failMessageVal=((D={})[H.EMPTY_FILE]="请勿上传空文件",D[H.FILE_SIZE_TOO_LARGE]="文件大小超出限制",D[H.FILE_TYPE_NOT_ALLOW]="该文件类型不支持",D[H.FILE_EXTENSION_NOT_ALLOW]="该文件扩展名不支持",D[H.GET_UPLOAD_TOKEN_ERROR]="获取上传图片 token 失败",D[H.UPLOAD_IMAGE_ERROR]="上传图片失败",D[H.PORN_IDENTIFY_ERROR]="图片鉴黄失败",D),I}(Error),rt=function(){return(rt=Object.assign||function(C){for(var I,k=1,M=arguments.length;k<M;k++)for(var x in I=arguments[k])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},Y=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},dt=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},pt=function(){function C(I){this.uploadCtx=I.uploadCtx}return C.prototype.getUploadToken=function(I){return Y(this,void 0,void 0,function(){var k,M,x,$,j;return dt(this,function(K){switch(K.label){case 0:return k=Date.now(),M=U()("upload_token_live"+I.channelId+k),x={channelId:I.channelId,ts:k,hash:M,bucket:I.bucket},I.userId&&(x.userId=I.userId),[4,T("https://"+this.uploadCtx.apiHost+"/live/upload/token/image/get-token",{params:x})];case 1:return($=K.sent()).data?(j=$.data).code!==200?[2,Promise.reject(new ot(H.GET_UPLOAD_TOKEN_ERROR))]:[2,j.data]:[2,Promise.reject(new ot(H.GET_UPLOAD_TOKEN_ERROR))]}})})},C.prototype.uploadImage=function(I){return Y(this,void 0,void 0,function(){var k,M,x,$,j,K;return dt(this,function(Q){switch(Q.label){case 0:k={key:""+I.dir+I.fileName,policy:I.policy,OSSAccessKeyId:I.accessid,signature:I.signature,success_action_status:200,callback:I.encodedCallback,file:I.file},Q.label=1;case 1:return Q.trys.push([1,3,,4]),[4,T("https://"+I.host,{method:"post",data:F(k),onUploadProgress:function(J){var N,st,R=I.onUploadProgress;typeof R=="function"&&R((N=J.loaded/J.total,st=2,Number(N.toFixed(st||0))))}})];case 2:return(M=Q.sent()).data?(x=M.data).code!==200?[2,Promise.reject(new ot(H.UPLOAD_IMAGE_ERROR))]:[2,x.data]:[2,Promise.reject(new ot(H.UPLOAD_IMAGE_ERROR))];case 3:return Q.sent(),$=I.currentReuploadTime,(j=$===void 0?0:$)&&j>=this.uploadCtx.reUploadTimes?[2,Promise.reject(new ot(H.UPLOAD_IMAGE_ERROR))]:(j+=1,K=Object.assign({},I,{currentReuploadTime:j}),[2,this.uploadImage(K)]);case 4:return[2]}})})},C.prototype.createSign=function(I,k,M){var x=I;Object.keys(k).sort().forEach(function(j){k[j]&&(x+=j+String(k[j]))}),x+=I;var $=U()(x);return M==="lower"?$:$.toLocaleUpperCase()},C.prototype.pornIdentify=function(I){return Y(this,void 0,void 0,function(){var k,M,x;return dt(this,function($){switch($.label){case 0:k=rt(rt({},I),{timestamp:Date.now()}),$.label=1;case 1:return $.trys.push([1,3,,4]),[4,T("https://"+this.uploadCtx.apiHost+"/live/inner/v3/chat/image/porn-identify",{method:"post",data:rt(rt({},k),{sign:this.createSign("polyv_chat_api_innor",k)})})];case 2:return(M=$.sent()).data?M.data.code!==200?[2,Promise.reject(new ot(H.PORN_IDENTIFY_ERROR))]:[2,!0]:[2,Promise.reject(new ot(H.PORN_IDENTIFY_ERROR))];case 3:return x=$.sent(),[2,Promise.reject(x)];case 4:return[2]}})})},C}();(function(C){C.WAIT_UPLOAD="waitUpload",C.UPLOADING="uploading",C.UPLOAD_SUCCESS="uploadSuccess",C.UPLOAD_FAIL="uploadFail",C.UPLOAD_FORBID="forbid"})(nt||(nt={}));var It=function(){return(It=Object.assign||function(C){for(var I,k=1,M=arguments.length;k<M;k++)for(var x in I=arguments[k])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},bt=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ut=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ft={width:500,height:500},xt=function(){function C(I){var k=I.callbackChange,M=k===void 0||k;this.imageId=I.imageId,this.uploadCtx=I.uploadCtx,this.file=I.file,this._status=I.status||nt.WAIT_UPLOAD,this.callbackChange=M,this.fileUrl=void 0,this.uploadProgress=void 0,this.previewSrc=L(this.file),this.uploadCtx.recordChatImage(this),this.triggerChange()}return C.prototype.upload=function(I){return I===void 0&&(I={}),bt(this,void 0,void 0,function(){var k,M,x,$,j,K,Q,J,N,st,R,G,W,X=this;return ut(this,function(at){switch(at.label){case 0:return k=this.uploadCtx,M=k.channelId,x=k.userId,$=k.bucket,this.status=nt.UPLOADING,[4,k.uploadApi.getUploadToken({channelId:M,userId:x,bucket:$})];case 1:if(j=at.sent(),!((K=this.file).size>1024*k.compressSizeLimit))return[3,5];at.label=2;case 2:return at.trys.push([2,4,,5]),[4,this.compressImage({file:this.file,fileName:this.fileName})];case 3:return Q=at.sent(),K=Q,[3,5];case 4:return at.sent(),console.warn("图片压缩失败",K,this.imageId),[3,5];case 5:return at.trys.push([5,7,,8]),[4,B(K)];case 6:return J=at.sent(),N=J.width,st=J.height,this.size={width:N,height:st},[3,8];case 7:return at.sent(),console.warn("获取图片尺寸失败"),[3,8];case 8:this.size||(this.size=ft),this.uploadProgress=0,R="",at.label=9;case 9:return at.trys.push([9,13,,14]),[4,k.uploadApi.uploadImage(It(It({},j),{file:K,fileName:this.fileName,onUploadProgress:function(Ot){X.uploadProgress=Ot,X.triggerChange()}}))];case 10:return R=at.sent(),this.fileUrl=R,k.enablePornChecking?[4,k.uploadApi.pornIdentify({channelId:M,url:"https:"+R})]:[3,12];case 11:at.sent(),at.label=12;case 12:return this.status=nt.UPLOAD_SUCCESS,[3,14];case 13:return G=at.sent(),this.status=G.failCode===H.PORN_IDENTIFY_ERROR?nt.UPLOAD_FORBID:nt.UPLOAD_FAIL,I.error,[2,Promise.reject(G)];case 14:return typeof(W=I.success)=="function"&&W(R),[2,R]}})})},C.prototype.compressImage=function(I){return bt(this,void 0,void 0,function(){var k,M,x,$,j,K,Q,J,N,st;return ut(this,function(R){switch(R.label){case 0:return k=I.file,M=I.fileName,x=I.quality,$=x===void 0?.7:x,[4,B(k)];case 1:return j=R.sent(),K=j.width,Q=j.height,J=j.imageTarget,(N=document.createElement("canvas")).setAttribute("width",""+K),N.setAttribute("height",""+Q),(st=N.getContext("2d"))?(st.drawImage(J,0,0,K,Q),[2,z(N.toDataURL("image/jpeg",$),M)]):[2,Promise.reject(new Error("create canvas error"))]}})})},C.prototype.triggerChange=function(){if(this.callbackChange){var I=this.uploadCtx.onChange;typeof I=="function"&&I(this)}},Object.defineProperty(C.prototype,"fileName",{get:function(){var I=V(this.file);return this.imageId+"."+(I||"png")},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"status",{get:function(){return this._status},set:function(I){this._status=I,this.triggerChange()},enumerable:!1,configurable:!0}),C}(),wt=function(){function C(I){this.uploadCtx=I.uploadCtx,this.uploadingList=[],this.waitQueue=[]}return C.prototype.joinWaitQueue=function(I){this.isExistQueue(I,this.waitQueue)||(this.waitQueue.push(I),this.checkQueue())},C.prototype.checkQueue=function(){var I=this;if(!(this.uploadingList.length>=this.uploadCtx.maxUploadNumber)&&this.waitQueue.length!==0)for(var k=this.uploadCtx.maxUploadNumber-this.uploadingList.length,M=function(j){var K=x.waitQueue.shift();K&&(K.upload({success:function(){I.handleImageUploadSuccess(K)}}),x.uploadingList.push(K))},x=this,$=0;$<k;$++)M()},C.prototype.handleImageUploadSuccess=function(I){this.uploadingList=this.uploadingList.filter(function(k){return k.imageId!==I.imageId}),this.checkQueue()},C.prototype.isExistQueue=function(I,k){return k.findIndex(function(M){return M.imageId===I.imageId})!==-1},C}(),Et=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/bmp","image/tiff","image/tifa"],gt=["png","bmp","webp","tiff","tif","jpeg","jpg","gif"],ht={channelId:"",userId:"",sizeLimit:81920,compressSizeLimit:2048,limit:9,maxWidth:700,reUploadTimes:3,source:"chat_img",bucket:"liveimages",useBlobByCompress:!1,allowAccept:Et,allowFileExtension:gt,maxUploadNumber:3,enablePornChecking:!1,apiHost:"api.polyv.net"},St=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},q=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ct=function(){function C(I){I===void 0&&(I={});var k=I.channelId,M=k===void 0?ht.channelId:k,x=I.userId,$=x===void 0?ht.userId:x,j=I.sizeLimit,K=j===void 0?ht.sizeLimit:j,Q=I.compressSizeLimit,J=Q===void 0?ht.compressSizeLimit:Q,N=I.limit,st=N===void 0?ht.limit:N,R=I.maxWidth,G=R===void 0?ht.maxWidth:R,W=I.reUploadTimes,X=W===void 0?ht.reUploadTimes:W,at=I.source,Ot=at===void 0?ht.source:at,Tt=I.bucket,Pt=Tt===void 0?ht.bucket:Tt,Ut=I.useBlobByCompress,it=Ut===void 0?ht.useBlobByCompress:Ut,lt=I.allowAccept,mt=lt===void 0?ht.allowAccept:lt,_t=I.allowFileExtension,Ct=_t===void 0?ht.allowFileExtension:_t,Ht=I.maxUploadNumber,Bt=Ht===void 0?ht.maxUploadNumber:Ht,ee=I.apiHost,ve=ee===void 0?ht.apiHost:ee,me=I.onChange,ye=I.beforeStart;this.channelId=M,this.userId=$,this.sizeLimit=K,this.compressSizeLimit=J,this.limit=st,this.maxWidth=G,this.reUploadTimes=X,this.source=Ot,this.bucket=Pt,this.useBlobByCompress=!!it,this.allowAccept=mt,this.allowFileExtension=Ct,this.maxUploadNumber=Bt,this.onChange=me,this.beforeStart=ye,this.enablePornChecking=I.enablePornChecking===!0,this.apiHost=ve,this.uploadQueue=new wt({uploadCtx:this}),this.uploadApi=new pt({uploadCtx:this}),this.chatImageStore={}}return C.prototype.choiceImageFile=function(I){var k=this;I===void 0&&(I={});var M=this.getAccept(),x=document.createElement("input");return x.setAttribute("id","polyv-upload-chat-image-input-id"),x.setAttribute("type","file"),x.setAttribute("accept",M),x.setAttribute("style","visibility: hidden;position: fixed;bottom: -100%;z-index: -1;"),this.limit>1&&x.setAttribute("multiple","multiple"),x.addEventListener("change",function(){document.body.removeChild(x),I&&x.files&&x.files.length!==0&&k.handleFileList(I,x.files)}),document.body.appendChild(x),x.click(),this},C.prototype.handleFileList=function(I,k){this.beforeStart&&this.beforeStart();for(var M,x=I.fail,$=I.success,j=I.callbackChange,K=k.length<this.limit?k.length:this.limit,Q=0;Q<K;Q++){var J=k[Q],N=this.checkFile(J);if(N)return M=N,void(typeof x=="function"&&x(M))}var st=[];for(Q=0;Q<K;Q++){J=k[Q];var R=this.buildImageId(Q),G=new xt({imageId:R,uploadCtx:this,file:J,callbackChange:j});st.push(G)}typeof $=="function"&&$(st)},C.prototype.getAccept=function(){var I=[];return I.push.apply(I,this.allowFileExtension.map(function(k){return"."+k})),I.push.apply(I,this.allowAccept),I.join(",")},C.prototype.joinWaitQueue=function(I){var k=this;if(Array.isArray(I))return I.forEach(function(x){k.joinWaitQueue(x)}),this;var M=void 0;return typeof I=="string"?M=this.getChatImageById(I):I instanceof xt&&(M=I),M&&this.uploadQueue.joinWaitQueue(M),this},C.prototype.getUploadImageUrl=function(){var I=this;return new Promise(function(k,M){I.choiceImageFile({callbackChange:!1,success:function(x){return St(I,void 0,void 0,function(){var $;return q(this,function(j){switch(j.label){case 0:return[4,($=x[0]).upload()];case 1:return j.sent(),$.fileUrl?k($):M(new ot(H.UPLOAD_IMAGE_ERROR)),[2]}})})},fail:function(x){M(x)}})})},C.prototype.callbackUploadImage=function(){var I=this;this.choiceImageFile({success:function(k){I.joinWaitQueue(k)}})},C.prototype.uploadImageFile=function(I){return St(this,void 0,void 0,function(){var k;return q(this,function(M){switch(M.label){case 0:if(k=this.checkFile(I))throw new Error(k.failMessage);return[4,new xt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:!1}).upload()];case 1:return[2,M.sent()]}})})},C.prototype.uploadImage=function(I,k){return St(this,void 0,void 0,function(){var M,x;return q(this,function($){switch($.label){case 0:if(M=this.checkFile(I))throw new Error(M.failMessage);return[4,(x=new xt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:k!==!1})).upload()];case 1:return $.sent(),[2,x]}})})},C.prototype.reUploadImage=function(I){return St(this,void 0,void 0,function(){var k,M;return q(this,function(x){switch(x.label){case 0:if(!(k=this.getChatImageById(I)))return[2,Promise.reject(new Error("图片不存在"))];x.label=1;case 1:return x.trys.push([1,3,,4]),[4,k.upload()];case 2:return x.sent(),[2,k];case 3:return M=x.sent(),[2,Promise.reject(M)];case 4:return[2]}})})},C.prototype.getChatImageById=function(I){return this.chatImageStore[I]},C.prototype.recordChatImage=function(I){this.chatImageStore[I.imageId]=I},C.prototype.checkFile=function(I){if(!I.size)return ot.getFailErrorData(H.EMPTY_FILE);if(I.size>1024*this.sizeLimit)return ot.getFailErrorData(H.FILE_SIZE_TOO_LARGE);if(!this.allowAccept.includes(I.type))return ot.getFailErrorData(H.FILE_TYPE_NOT_ALLOW);var k=V(I);return this.allowFileExtension.includes(k)?void 0:ot.getFailErrorData(H.FILE_EXTENSION_NOT_ALLOW)},C.prototype.buildImageId=function(I){var k=[];this.source&&k.push(this.source),this.channelId&&k.push(this.channelId),this.userId&&k.push(this.userId);var M=I!==void 0?"_"+I:"";return k.join("_")+"_"+Date.now()+"_"+Math.random().toString().substring(2,10)+M},C}()}]);class qe extends jt{constructor(t){super(t);vt(this,"__uploadImgCtrl");vt(this,"__svgaMap",{coffee:"coffee.svga",like:"like.svga",handclap:"handclap.svga",666:"666.svga",star:"star.svga",diamond:"diamond.svga",car:"car.svga",rocket:"rocket.svga",bear:"bear.svga",crown:"crown.svga",cup:"cup.svga",microphone:"microphone.svga",villa:"villa.svga",house:"villa.svga"});this.__uploadImgCtrl=new Ye.ChatImageUpload({enablePornChecking:!0})}__setUploadImgChannelId(){return tt(this,null,function*(){const t=yield this._plvSocket.channel.getChannelInfo();this.__uploadImgCtrl.channelId=t.channelId})}uploadMultiImage(t){return tt(this,null,function*(){yield this.__setUploadImgChannelId();const e=(t==null?void 0:t.maxLimit)||9,r=typeof(t==null?void 0:t.ready)=="function"?t.ready:()=>{},n=typeof(t==null?void 0:t.success)=="function"?t.success:()=>{},i=typeof(t==null?void 0:t.fail)=="function"?t.fail:()=>{},s=[],c=[];return new Promise((l,u)=>{this.__uploadImgCtrl.choiceImageFile({callbackChange:!1,success:d=>tt(this,null,function*(){d=d.slice(0,e),yield Promise.all(d.map(v=>new Promise(y=>{const b=URL.createObjectURL(v.file),m=new Image;m.onload=()=>{v.size={width:m.width,height:m.height},URL.revokeObjectURL(b),y()},m.src=b}))),d.forEach(v=>{r({imageId:v.imageId,previewSrc:v.previewSrc||"",size:v.size})});try{for(var p=oe(d),f,h,g;f=!(h=yield p.next()).done;f=!1){const v=h.value;try{const y=yield v.upload();if(!y)throw new Error("upload Image Error");const b={imageId:v.imageId,imageUrl:y,size:v.size};s.push(b),n(b)}catch(y){const b=y,m={imageId:v.imageId,previewSrc:v.previewSrc||""};c.push(m),console.error("[util-module][uploadMultiImage] ",b.message,m),i(b,m)}}}catch(h){g=[h]}finally{try{f&&(h=p.return)&&(yield h.call(p))}finally{if(g)throw g[0]}}return l({successUploadImages:s,failUploadImages:c})}),fail:d=>{console.error("[util-module][uploadMultiImage] ",d),u(new Error(d.failMessage))}})})})}directUploadImage(t){return tt(this,null,function*(){if(!t)throw new Error("file is null");yield this.__setUploadImgChannelId();const e=yield this.__uploadImgCtrl.uploadImage(t);if(!e.fileUrl)throw new Error("upload fail");return{imageId:e.imageId,imageUrl:e.fileUrl,size:e.size}})}translateText(t){return tt(this,null,function*(){const e=this._plvSocket.getUserInfo(),r=yield this._plvSocket.polyvApi.getTokenFieldByUserType();return(yield this._plvSocket.polyvApi.post("/live/v4/channel/translate",{},{params:{query:t,viewerId:e.userId},tokenInfo:{tokenField:r}}))[0]})}__genResourceUrl(t){return`https://s1.videocc.net${t}`}getDefaultResource(){return{defaultViewerAvatar:this.__genResourceUrl("/default-img/avatar/viewer.png")}}getDefaultDonateSvgaUrl(t){return tt(this,null,function*(){const e=t.gimg,r=this.__svgaMap,n=document.createElement("a");n.href=e;const i=n.pathname.split("/"),s=i[i.length-1].split(".")[0];if(r[s])return this.__genResourceUrl(`/default-img/donate-svga/${r[s]}`)})}}class Qe{constructor(a,t={}){vt(this,"PolyvChatEvent",yt);vt(this,"ChatMsgSource",et);vt(this,"DonateType",Ft);vt(this,"RedpackType",Jt);vt(this,"SystemMsgType",Vt);vt(this,"ChatRequestHistoryMode",Dt);vt(this,"ManageFailReason",Nt);vt(this,"TranslateLanguage",te);vt(this,"QuickReplyType",$t);vt(this,"EmotionalFeedbackType",Zt);vt(this,"eventEmitter",new xe);vt(this,"__socketFilter");vt(this,"__socketHandler");vt(this,"emotion");vt(this,"history");vt(this,"message");vt(this,"status");vt(this,"utils");vt(this,"sender");vt(this,"manage");vt(this,"online");vt(this,"download");vt(this,"like");vt(this,"ask");vt(this,"emotionalFeedback");vt(this,"file");vt(this,"setuped",!1);this.plvSocket=a,this.config=t,this.emotion=new Ue(this),this.history=new Be(this),this.message=new Ve(this),this.status=new We(this),this.utils=new qe(this),this.sender=new Ke(this),this.manage=new He(this),this.online=new $e(this),this.download=new Ne(this),this.like=new ze(this),this.ask=new Pe(this),this.emotionalFeedback=new Fe(this),this.file=new De(this),this.__socketFilter=new Me(this),this.__socketHandler=new Ae(this)}setup(){return tt(this,null,function*(){this.setuped=!0})}destroy(){return tt(this,null,function*(){this.plvSocket.clearSocketHandles(Mt)})}}const Je="PolyvChat";exports.ChatMsgSource=et;exports.ChatRequestHistoryMode=Dt;exports.DonateType=Ft;exports.EmotionalFeedbackType=Zt;exports.GlobalVariable=Je;exports.ManageFailReason=Nt;exports.MotivationLikeType=Xt;exports.PolyvChat=Qe;exports.PolyvChatEvent=yt;exports.QuickReplyType=$t;exports.RedpackType=Jt;exports.SystemMsgType=Vt;exports.TranslateLanguage=te;exports.canQuoteMsgSource=ge;exports.canTopMsgSource=he;exports.isServiceMsgMap=de;console.log("%c@polyv/chat","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.6.0-rc-20260205.2]","[buildTime: 2026-02-05 10:05:11]");
|
|
19
|
+
*/o.exports=function(e){return e!=null&&(t(e)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&t(r.slice(0,0))}(e)||!!e._isBuffer)}},function(o,a,t){t.r(a),t.d(a,"ChatImageUpload",function(){return ct}),t.d(a,"defaultConfig",function(){return ht}),t.d(a,"allowAccept",function(){return Et}),t.d(a,"allowFileExtension",function(){return gt}),t.d(a,"FailError",function(){return ot}),t.d(a,"FailCode",function(){return H}),t.d(a,"ChatImage",function(){return xt}),t.d(a,"ImageStatus",function(){return nt}),t(127),t(92),t(63),t(35),t(67),t(135),t(136),t(73);var e=Object.prototype.hasOwnProperty;function r(C,I){return e.call(C,I)}function n(C){if(C==null)throw new TypeError("Cannot convert undefined or null to object");for(var I=0;I<(arguments.length<=1?0:arguments.length-1);I++){var k=I+1<1||arguments.length<=I+1?void 0:arguments[I+1];if(k!=null)for(var M in k)M!=="__proto__"&&r(k,M)&&(C[M]=k[M])}return C}var i=Object.prototype.toString;t(74),t(53),t(151),t(152),t(154);function s(C,I){var k,M,x=n({encode:encodeURIComponent},I),$=[];function j(Q,J){J==null&&(J=""),J===""&&x.ignoreEmpty||(typeof x.encode=="function"&&(Q=x.encode(Q),J=x.encode(String(J))),$.push(Q+"="+J))}function K(Q){j(k,Q)}for(k in C)r(C,k)&&(M=C[k],Array.isArray(M)?M.forEach(K):j(k,M));return $.join("&")}t(116),t(155);function c(C,I,k){if(C==null||I==null)return C;var M=(C=String(C)).indexOf("#"),x="";return M!==-1&&(x=C.substring(M,C.length),C=C.substring(0,M)),(C=C.replace(/[?&]$/,""))+((I=typeof I!="string"?s(I,k):I.replace(/^[?&]/,""))?(C.indexOf("?")!==-1?"&":"?")+I:"")+x}t(157),t(159),t(117),t(160),t(161),t(162),t(163),t(164),t(120),t(167),t(173),t(174),t(175),t(176),t(178),t(179);function l(C){return(l=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(I){return typeof I}:function(I){return I&&typeof Symbol=="function"&&I.constructor===Symbol&&I!==Symbol.prototype?"symbol":typeof I})(C)}function u(C,I){if(I&&(l(I)==="object"||typeof I=="function"))return I;if(I!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return function(k){if(k===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return k}(C)}function d(C){var I=typeof Map=="function"?new Map:void 0;return(d=function(k){if(k===null||(M=k,Function.toString.call(M).indexOf("[native code]")===-1))return k;var M;if(typeof k!="function")throw new TypeError("Super expression must either be null or a function");if(I!==void 0){if(I.has(k))return I.get(k);I.set(k,x)}function x(){return p(k,arguments,g(this).constructor)}return x.prototype=Object.create(k.prototype,{constructor:{value:x,enumerable:!1,writable:!0,configurable:!0}}),h(x,k)})(C)}function p(C,I,k){return(p=f()?Reflect.construct:function(M,x,$){var j=[null];j.push.apply(j,x);var K=new(Function.bind.apply(M,j));return $&&h(K,$.prototype),K}).apply(null,arguments)}function f(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(C){return!1}}function h(C,I){return(h=Object.setPrototypeOf||function(k,M){return k.__proto__=M,k})(C,I)}function g(C){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(I){return I.__proto__||Object.getPrototypeOf(I)})(C)}var v=function(C){(function(j,K){if(typeof K!="function"&&K!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(K&&K.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),K&&h(j,K)})($,C);var I,k,M,x=(I=$,k=f(),function(){var j,K=g(I);if(k){var Q=g(this).constructor;j=Reflect.construct(K,arguments,Q)}else j=K.apply(this,arguments);return u(this,j)});function $(j){var K;return function(Q,J){if(!(Q instanceof J))throw new TypeError("Cannot call a class as a function")}(this,$),(K=x.call(this,j)).name="AJAXError",K}return M=$,Object.defineProperty(M,"prototype",{writable:!1}),M}(d(Error)),y=/(?:^|;\s*)(?:application|text)\/([a-z]+)/i;t(180),t(182),t(183);function b(C,I,k,M){return function(){var x,$,j,K=(C.responseText||"").trim();switch(I.responseType||((j=C.getResponseHeader("Content-Type"))&&y.test(j)?RegExp.$1.toLowerCase():"")){case"json":if(K)try{x=JSON.parse(K)}catch(st){$="Invalid JSON structure"}break;case"xml":(x=C.responseXML)&&x.documentElement||($="Invalid XML format");break;default:x=K}var Q,J={xhr:C,options:I,data:x},N=C.status;(function(st){return!(st===void 0||st>=200&&st<300||st===1223||st===304)})(N)?(Q=new v("Error (HTTP status code: "+N+")")).code=N:$&&(Q=new v($)),Q?M(n(Q,J)):k(J)}}var m=Object.create(null),w=0;function _(C,I,k,M){C.onload=b(C,I,k,M),C.ontimeout=function(){var $;M((($=new v("Request timeout")).isTimeout=!0,$))},C.onerror=function(){M(new v("Network error"))},I.onDownloadProgress&&C.addEventListener("progress",I.onDownloadProgress),I.onUploadProgress&&C.upload&&C.upload.addEventListener("progress",I.onUploadProgress),w===Number.MAX_SAFE_INTEGER&&(w=0);var x=++w;return m[x]={xhr:C,options:I,resolve:k,reject:M},x}function S(C){delete m[C]}function E(C,I,k,M,x){return C&&/MSIE\s+(\d+)/.test(navigator.userAgent)&&parseInt(RegExp.$1)<10&&window.XDomainRequest&&(I==="get"||I==="post")&&!k&&!x&&function($){if($!=null){if(Array.isArray($))return!$.length;for(var j in $)if(r($,j))return!1}return!0}(M)?new window.XDomainRequest:new window.XMLHttpRequest}function O(C,I,k,M){var x,$,j;if(k!=null&&C!=="get")return M==="json"?(x=JSON.stringify(k),$="application/json; charset=utf-8"):(j=k,typeof(x=i.call(j)==="[object Object]"?s(k,{ignoreEmpty:!1}):k)=="string"&&($="application/x-www-form-urlencoded; charset=utf-8")),I["Content-Type"]=I["Content-Type"]||$,x}function T(C,I){var k=0;return new Promise(function(M,x){(I=n({},I)).method=I.method||"get",I.requestType=I.requestType||"",I.responseType=I.responseType||"json",I.timeout=I.timeout||0;var $=I.method.toLowerCase(),j=I.requestType.toLowerCase(),K=I.headers||{},Q=function(st){var R=document.createElement("div");R.innerHTML='<a href="'+st+'"></a>';var G=R.firstChild,W=G.host!==location.host;return R=null,G=null,W}(C=function(st,R,G){return R!=null&&(st=c(st,R,{ignoreEmpty:!1})),G&&(st=c(st,{_:Date.now()})),st}(C,I.params,I.preventCaching)),J=E(Q,$,j,K,I.withCredentials);k=_(J,I,function(st){S(k),M(st)},function(st){S(k),x(st)}),J.open($,C,!0,I.username,I.password);var N=O($,K,I.data,j);(function(st,R,G,W){R.timeout&&(st.timeout=R.timeout),G&&R.withCredentials!=null&&(st.withCredentials=!!R.withCredentials),G||W["X-Request-With"]!=null||(W["X-Request-With"]="XMLHttpRequest"),Object.keys(W).forEach(function(X){W[X]!=null&&st.setRequestHeader(X,String(W[X]))})})(J,I,Q,K),typeof I.beforeSend=="function"&&I.beforeSend.call(window,J),J.send(N||""),typeof I.receiveCancelId=="function"&&I.receiveCancelId(k)})}var A=t(82),U=t.n(A);function V(C){return C.name.toLowerCase().split(".").pop()||""}function F(C){var I=new FormData;for(var k in C)I.append(k,C[k]);return I}function z(C,I,k){k===void 0&&(k=!1);for(var M=C.split(","),x=/:(.*?);/.exec(M[0]),$=x?x[1]:"image/jpeg",j=window.atob(M[1]),K=j.length,Q=new Uint8Array(K);K--;)Q[K]=j.charCodeAt(K);return k?new Blob([Q],{type:$}):new File([Q],I,{type:$})}function B(C){return new Promise(function(I,k){var M=new Image;M.onload=function(){I({width:M.width,height:M.height,imageTarget:M})},M.onerror=function(){k(new Error("获取图片尺寸失败"))};var x="";x=typeof C=="string"?C:L(C),M.src=x})}function L(C){return(window.URL||window.webkitURL).createObjectURL(C)}var P,D,H,Z=(P=function(C,I){return(P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(k,M){k.__proto__=M}||function(k,M){for(var x in M)Object.prototype.hasOwnProperty.call(M,x)&&(k[x]=M[x])})(C,I)},function(C,I){if(typeof I!="function"&&I!==null)throw new TypeError("Class extends value "+String(I)+" is not a constructor or null");function k(){this.constructor=C}P(C,I),C.prototype=I===null?Object.create(I):(k.prototype=I.prototype,new k)});(function(C){C.EMPTY_FILE="empty file",C.FILE_SIZE_TOO_LARGE="file size too large",C.FILE_TYPE_NOT_ALLOW="file type not allow",C.FILE_EXTENSION_NOT_ALLOW="file extension not allow",C.GET_UPLOAD_TOKEN_ERROR="get upload token error",C.UPLOAD_IMAGE_ERROR="upload image error",C.PORN_IDENTIFY_ERROR="porn identify error"})(H||(H={}));var nt,ot=function(C){function I(k){var M=C.call(this,k)||this,x=I.getFailErrorData(k);return M.failCode=x.failCode,M.failMessage=x.failMessage,M}return Z(I,C),I.getFailErrorData=function(k){return{failCode:k,failMessage:I.failMessageVal[k]}},I.failMessageVal=((D={})[H.EMPTY_FILE]="请勿上传空文件",D[H.FILE_SIZE_TOO_LARGE]="文件大小超出限制",D[H.FILE_TYPE_NOT_ALLOW]="该文件类型不支持",D[H.FILE_EXTENSION_NOT_ALLOW]="该文件扩展名不支持",D[H.GET_UPLOAD_TOKEN_ERROR]="获取上传图片 token 失败",D[H.UPLOAD_IMAGE_ERROR]="上传图片失败",D[H.PORN_IDENTIFY_ERROR]="图片鉴黄失败",D),I}(Error),rt=function(){return(rt=Object.assign||function(C){for(var I,k=1,M=arguments.length;k<M;k++)for(var x in I=arguments[k])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},Y=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},dt=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},pt=function(){function C(I){this.uploadCtx=I.uploadCtx}return C.prototype.getUploadToken=function(I){return Y(this,void 0,void 0,function(){var k,M,x,$,j;return dt(this,function(K){switch(K.label){case 0:return k=Date.now(),M=U()("upload_token_live"+I.channelId+k),x={channelId:I.channelId,ts:k,hash:M,bucket:I.bucket},I.userId&&(x.userId=I.userId),[4,T("https://"+this.uploadCtx.apiHost+"/live/upload/token/image/get-token",{params:x})];case 1:return($=K.sent()).data?(j=$.data).code!==200?[2,Promise.reject(new ot(H.GET_UPLOAD_TOKEN_ERROR))]:[2,j.data]:[2,Promise.reject(new ot(H.GET_UPLOAD_TOKEN_ERROR))]}})})},C.prototype.uploadImage=function(I){return Y(this,void 0,void 0,function(){var k,M,x,$,j,K;return dt(this,function(Q){switch(Q.label){case 0:k={key:""+I.dir+I.fileName,policy:I.policy,OSSAccessKeyId:I.accessid,signature:I.signature,success_action_status:200,callback:I.encodedCallback,file:I.file},Q.label=1;case 1:return Q.trys.push([1,3,,4]),[4,T("https://"+I.host,{method:"post",data:F(k),onUploadProgress:function(J){var N,st,R=I.onUploadProgress;typeof R=="function"&&R((N=J.loaded/J.total,st=2,Number(N.toFixed(st||0))))}})];case 2:return(M=Q.sent()).data?(x=M.data).code!==200?[2,Promise.reject(new ot(H.UPLOAD_IMAGE_ERROR))]:[2,x.data]:[2,Promise.reject(new ot(H.UPLOAD_IMAGE_ERROR))];case 3:return Q.sent(),$=I.currentReuploadTime,(j=$===void 0?0:$)&&j>=this.uploadCtx.reUploadTimes?[2,Promise.reject(new ot(H.UPLOAD_IMAGE_ERROR))]:(j+=1,K=Object.assign({},I,{currentReuploadTime:j}),[2,this.uploadImage(K)]);case 4:return[2]}})})},C.prototype.createSign=function(I,k,M){var x=I;Object.keys(k).sort().forEach(function(j){k[j]&&(x+=j+String(k[j]))}),x+=I;var $=U()(x);return M==="lower"?$:$.toLocaleUpperCase()},C.prototype.pornIdentify=function(I){return Y(this,void 0,void 0,function(){var k,M,x;return dt(this,function($){switch($.label){case 0:k=rt(rt({},I),{timestamp:Date.now()}),$.label=1;case 1:return $.trys.push([1,3,,4]),[4,T("https://"+this.uploadCtx.apiHost+"/live/inner/v3/chat/image/porn-identify",{method:"post",data:rt(rt({},k),{sign:this.createSign("polyv_chat_api_innor",k)})})];case 2:return(M=$.sent()).data?M.data.code!==200?[2,Promise.reject(new ot(H.PORN_IDENTIFY_ERROR))]:[2,!0]:[2,Promise.reject(new ot(H.PORN_IDENTIFY_ERROR))];case 3:return x=$.sent(),[2,Promise.reject(x)];case 4:return[2]}})})},C}();(function(C){C.WAIT_UPLOAD="waitUpload",C.UPLOADING="uploading",C.UPLOAD_SUCCESS="uploadSuccess",C.UPLOAD_FAIL="uploadFail",C.UPLOAD_FORBID="forbid"})(nt||(nt={}));var It=function(){return(It=Object.assign||function(C){for(var I,k=1,M=arguments.length;k<M;k++)for(var x in I=arguments[k])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},bt=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ut=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ft={width:500,height:500},xt=function(){function C(I){var k=I.callbackChange,M=k===void 0||k;this.imageId=I.imageId,this.uploadCtx=I.uploadCtx,this.file=I.file,this._status=I.status||nt.WAIT_UPLOAD,this.callbackChange=M,this.fileUrl=void 0,this.uploadProgress=void 0,this.previewSrc=L(this.file),this.uploadCtx.recordChatImage(this),this.triggerChange()}return C.prototype.upload=function(I){return I===void 0&&(I={}),bt(this,void 0,void 0,function(){var k,M,x,$,j,K,Q,J,N,st,R,G,W,X=this;return ut(this,function(at){switch(at.label){case 0:return k=this.uploadCtx,M=k.channelId,x=k.userId,$=k.bucket,this.status=nt.UPLOADING,[4,k.uploadApi.getUploadToken({channelId:M,userId:x,bucket:$})];case 1:if(j=at.sent(),!((K=this.file).size>1024*k.compressSizeLimit))return[3,5];at.label=2;case 2:return at.trys.push([2,4,,5]),[4,this.compressImage({file:this.file,fileName:this.fileName})];case 3:return Q=at.sent(),K=Q,[3,5];case 4:return at.sent(),console.warn("图片压缩失败",K,this.imageId),[3,5];case 5:return at.trys.push([5,7,,8]),[4,B(K)];case 6:return J=at.sent(),N=J.width,st=J.height,this.size={width:N,height:st},[3,8];case 7:return at.sent(),console.warn("获取图片尺寸失败"),[3,8];case 8:this.size||(this.size=ft),this.uploadProgress=0,R="",at.label=9;case 9:return at.trys.push([9,13,,14]),[4,k.uploadApi.uploadImage(It(It({},j),{file:K,fileName:this.fileName,onUploadProgress:function(Ot){X.uploadProgress=Ot,X.triggerChange()}}))];case 10:return R=at.sent(),this.fileUrl=R,k.enablePornChecking?[4,k.uploadApi.pornIdentify({channelId:M,url:"https:"+R})]:[3,12];case 11:at.sent(),at.label=12;case 12:return this.status=nt.UPLOAD_SUCCESS,[3,14];case 13:return G=at.sent(),this.status=G.failCode===H.PORN_IDENTIFY_ERROR?nt.UPLOAD_FORBID:nt.UPLOAD_FAIL,I.error,[2,Promise.reject(G)];case 14:return typeof(W=I.success)=="function"&&W(R),[2,R]}})})},C.prototype.compressImage=function(I){return bt(this,void 0,void 0,function(){var k,M,x,$,j,K,Q,J,N,st;return ut(this,function(R){switch(R.label){case 0:return k=I.file,M=I.fileName,x=I.quality,$=x===void 0?.7:x,[4,B(k)];case 1:return j=R.sent(),K=j.width,Q=j.height,J=j.imageTarget,(N=document.createElement("canvas")).setAttribute("width",""+K),N.setAttribute("height",""+Q),(st=N.getContext("2d"))?(st.drawImage(J,0,0,K,Q),[2,z(N.toDataURL("image/jpeg",$),M)]):[2,Promise.reject(new Error("create canvas error"))]}})})},C.prototype.triggerChange=function(){if(this.callbackChange){var I=this.uploadCtx.onChange;typeof I=="function"&&I(this)}},Object.defineProperty(C.prototype,"fileName",{get:function(){var I=V(this.file);return this.imageId+"."+(I||"png")},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"status",{get:function(){return this._status},set:function(I){this._status=I,this.triggerChange()},enumerable:!1,configurable:!0}),C}(),wt=function(){function C(I){this.uploadCtx=I.uploadCtx,this.uploadingList=[],this.waitQueue=[]}return C.prototype.joinWaitQueue=function(I){this.isExistQueue(I,this.waitQueue)||(this.waitQueue.push(I),this.checkQueue())},C.prototype.checkQueue=function(){var I=this;if(!(this.uploadingList.length>=this.uploadCtx.maxUploadNumber)&&this.waitQueue.length!==0)for(var k=this.uploadCtx.maxUploadNumber-this.uploadingList.length,M=function(j){var K=x.waitQueue.shift();K&&(K.upload({success:function(){I.handleImageUploadSuccess(K)}}),x.uploadingList.push(K))},x=this,$=0;$<k;$++)M()},C.prototype.handleImageUploadSuccess=function(I){this.uploadingList=this.uploadingList.filter(function(k){return k.imageId!==I.imageId}),this.checkQueue()},C.prototype.isExistQueue=function(I,k){return k.findIndex(function(M){return M.imageId===I.imageId})!==-1},C}(),Et=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/bmp","image/tiff","image/tifa"],gt=["png","bmp","webp","tiff","tif","jpeg","jpg","gif"],ht={channelId:"",userId:"",sizeLimit:81920,compressSizeLimit:2048,limit:9,maxWidth:700,reUploadTimes:3,source:"chat_img",bucket:"liveimages",useBlobByCompress:!1,allowAccept:Et,allowFileExtension:gt,maxUploadNumber:3,enablePornChecking:!1,apiHost:"api.polyv.net"},St=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(st){st(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},q=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(st){N=[6,st],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ct=function(){function C(I){I===void 0&&(I={});var k=I.channelId,M=k===void 0?ht.channelId:k,x=I.userId,$=x===void 0?ht.userId:x,j=I.sizeLimit,K=j===void 0?ht.sizeLimit:j,Q=I.compressSizeLimit,J=Q===void 0?ht.compressSizeLimit:Q,N=I.limit,st=N===void 0?ht.limit:N,R=I.maxWidth,G=R===void 0?ht.maxWidth:R,W=I.reUploadTimes,X=W===void 0?ht.reUploadTimes:W,at=I.source,Ot=at===void 0?ht.source:at,Tt=I.bucket,Pt=Tt===void 0?ht.bucket:Tt,Ut=I.useBlobByCompress,it=Ut===void 0?ht.useBlobByCompress:Ut,lt=I.allowAccept,mt=lt===void 0?ht.allowAccept:lt,_t=I.allowFileExtension,Ct=_t===void 0?ht.allowFileExtension:_t,Ht=I.maxUploadNumber,Bt=Ht===void 0?ht.maxUploadNumber:Ht,ee=I.apiHost,ve=ee===void 0?ht.apiHost:ee,me=I.onChange,ye=I.beforeStart;this.channelId=M,this.userId=$,this.sizeLimit=K,this.compressSizeLimit=J,this.limit=st,this.maxWidth=G,this.reUploadTimes=X,this.source=Ot,this.bucket=Pt,this.useBlobByCompress=!!it,this.allowAccept=mt,this.allowFileExtension=Ct,this.maxUploadNumber=Bt,this.onChange=me,this.beforeStart=ye,this.enablePornChecking=I.enablePornChecking===!0,this.apiHost=ve,this.uploadQueue=new wt({uploadCtx:this}),this.uploadApi=new pt({uploadCtx:this}),this.chatImageStore={}}return C.prototype.choiceImageFile=function(I){var k=this;I===void 0&&(I={});var M=this.getAccept(),x=document.createElement("input");return x.setAttribute("id","polyv-upload-chat-image-input-id"),x.setAttribute("type","file"),x.setAttribute("accept",M),x.setAttribute("style","visibility: hidden;position: fixed;bottom: -100%;z-index: -1;"),this.limit>1&&x.setAttribute("multiple","multiple"),x.addEventListener("change",function(){document.body.removeChild(x),I&&x.files&&x.files.length!==0&&k.handleFileList(I,x.files)}),document.body.appendChild(x),x.click(),this},C.prototype.handleFileList=function(I,k){this.beforeStart&&this.beforeStart();for(var M,x=I.fail,$=I.success,j=I.callbackChange,K=k.length<this.limit?k.length:this.limit,Q=0;Q<K;Q++){var J=k[Q],N=this.checkFile(J);if(N)return M=N,void(typeof x=="function"&&x(M))}var st=[];for(Q=0;Q<K;Q++){J=k[Q];var R=this.buildImageId(Q),G=new xt({imageId:R,uploadCtx:this,file:J,callbackChange:j});st.push(G)}typeof $=="function"&&$(st)},C.prototype.getAccept=function(){var I=[];return I.push.apply(I,this.allowFileExtension.map(function(k){return"."+k})),I.push.apply(I,this.allowAccept),I.join(",")},C.prototype.joinWaitQueue=function(I){var k=this;if(Array.isArray(I))return I.forEach(function(x){k.joinWaitQueue(x)}),this;var M=void 0;return typeof I=="string"?M=this.getChatImageById(I):I instanceof xt&&(M=I),M&&this.uploadQueue.joinWaitQueue(M),this},C.prototype.getUploadImageUrl=function(){var I=this;return new Promise(function(k,M){I.choiceImageFile({callbackChange:!1,success:function(x){return St(I,void 0,void 0,function(){var $;return q(this,function(j){switch(j.label){case 0:return[4,($=x[0]).upload()];case 1:return j.sent(),$.fileUrl?k($):M(new ot(H.UPLOAD_IMAGE_ERROR)),[2]}})})},fail:function(x){M(x)}})})},C.prototype.callbackUploadImage=function(){var I=this;this.choiceImageFile({success:function(k){I.joinWaitQueue(k)}})},C.prototype.uploadImageFile=function(I){return St(this,void 0,void 0,function(){var k;return q(this,function(M){switch(M.label){case 0:if(k=this.checkFile(I))throw new Error(k.failMessage);return[4,new xt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:!1}).upload()];case 1:return[2,M.sent()]}})})},C.prototype.uploadImage=function(I,k){return St(this,void 0,void 0,function(){var M,x;return q(this,function($){switch($.label){case 0:if(M=this.checkFile(I))throw new Error(M.failMessage);return[4,(x=new xt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:k!==!1})).upload()];case 1:return $.sent(),[2,x]}})})},C.prototype.reUploadImage=function(I){return St(this,void 0,void 0,function(){var k,M;return q(this,function(x){switch(x.label){case 0:if(!(k=this.getChatImageById(I)))return[2,Promise.reject(new Error("图片不存在"))];x.label=1;case 1:return x.trys.push([1,3,,4]),[4,k.upload()];case 2:return x.sent(),[2,k];case 3:return M=x.sent(),[2,Promise.reject(M)];case 4:return[2]}})})},C.prototype.getChatImageById=function(I){return this.chatImageStore[I]},C.prototype.recordChatImage=function(I){this.chatImageStore[I.imageId]=I},C.prototype.checkFile=function(I){if(!I.size)return ot.getFailErrorData(H.EMPTY_FILE);if(I.size>1024*this.sizeLimit)return ot.getFailErrorData(H.FILE_SIZE_TOO_LARGE);if(!this.allowAccept.includes(I.type))return ot.getFailErrorData(H.FILE_TYPE_NOT_ALLOW);var k=V(I);return this.allowFileExtension.includes(k)?void 0:ot.getFailErrorData(H.FILE_EXTENSION_NOT_ALLOW)},C.prototype.buildImageId=function(I){var k=[];this.source&&k.push(this.source),this.channelId&&k.push(this.channelId),this.userId&&k.push(this.userId);var M=I!==void 0?"_"+I:"";return k.join("_")+"_"+Date.now()+"_"+Math.random().toString().substring(2,10)+M},C}()}]);class qe extends jt{constructor(t){super(t);vt(this,"__uploadImgCtrl");vt(this,"__svgaMap",{coffee:"coffee.svga",like:"like.svga",handclap:"handclap.svga",666:"666.svga",star:"star.svga",diamond:"diamond.svga",car:"car.svga",rocket:"rocket.svga",bear:"bear.svga",crown:"crown.svga",cup:"cup.svga",microphone:"microphone.svga",villa:"villa.svga",house:"villa.svga"});this.__uploadImgCtrl=new Ye.ChatImageUpload({enablePornChecking:!0})}__setUploadImgChannelId(){return tt(this,null,function*(){const t=yield this._plvSocket.channel.getChannelInfo();this.__uploadImgCtrl.channelId=t.channelId})}uploadMultiImage(t){return tt(this,null,function*(){yield this.__setUploadImgChannelId();const e=(t==null?void 0:t.maxLimit)||9,r=typeof(t==null?void 0:t.ready)=="function"?t.ready:()=>{},n=typeof(t==null?void 0:t.success)=="function"?t.success:()=>{},i=typeof(t==null?void 0:t.fail)=="function"?t.fail:()=>{},s=[],c=[];return new Promise((l,u)=>{this.__uploadImgCtrl.choiceImageFile({callbackChange:!1,success:d=>tt(this,null,function*(){d=d.slice(0,e),yield Promise.all(d.map(v=>new Promise(y=>{const b=URL.createObjectURL(v.file),m=new Image;m.onload=()=>{v.size={width:m.width,height:m.height},URL.revokeObjectURL(b),y()},m.src=b}))),d.forEach(v=>{r({imageId:v.imageId,previewSrc:v.previewSrc||"",size:v.size})});try{for(var p=oe(d),f,h,g;f=!(h=yield p.next()).done;f=!1){const v=h.value;try{const y=yield v.upload();if(!y)throw new Error("upload Image Error");const b={imageId:v.imageId,imageUrl:y,size:v.size};s.push(b),n(b)}catch(y){const b=y,m={imageId:v.imageId,previewSrc:v.previewSrc||""};c.push(m),console.error("[util-module][uploadMultiImage] ",b.message,m),i(b,m)}}}catch(h){g=[h]}finally{try{f&&(h=p.return)&&(yield h.call(p))}finally{if(g)throw g[0]}}return l({successUploadImages:s,failUploadImages:c})}),fail:d=>{console.error("[util-module][uploadMultiImage] ",d),u(new Error(d.failMessage))}})})})}directUploadImage(t){return tt(this,null,function*(){if(!t)throw new Error("file is null");yield this.__setUploadImgChannelId();const e=yield this.__uploadImgCtrl.uploadImage(t);if(!e.fileUrl)throw new Error("upload fail");return{imageId:e.imageId,imageUrl:e.fileUrl,size:e.size}})}translateText(t){return tt(this,null,function*(){const e=this._plvSocket.getUserInfo(),r=yield this._plvSocket.polyvApi.getTokenFieldByUserType();return(yield this._plvSocket.polyvApi.post("/live/v4/channel/translate",{},{params:{query:t,viewerId:e.userId},tokenInfo:{tokenField:r}}))[0]})}__genResourceUrl(t){return`https://s1.videocc.net${t}`}getDefaultResource(){return{defaultViewerAvatar:this.__genResourceUrl("/default-img/avatar/viewer.png")}}getDefaultDonateSvgaUrl(t){return tt(this,null,function*(){const e=t.gimg,r=this.__svgaMap,n=document.createElement("a");n.href=e;const i=n.pathname.split("/"),s=i[i.length-1].split(".")[0];if(r[s])return this.__genResourceUrl(`/default-img/donate-svga/${r[s]}`)})}}class Qe{constructor(a,t={}){vt(this,"PolyvChatEvent",yt);vt(this,"ChatMsgSource",et);vt(this,"DonateType",Ft);vt(this,"RedpackType",Jt);vt(this,"SystemMsgType",Vt);vt(this,"ChatRequestHistoryMode",Dt);vt(this,"ManageFailReason",Nt);vt(this,"TranslateLanguage",te);vt(this,"QuickReplyType",$t);vt(this,"EmotionalFeedbackType",Zt);vt(this,"eventEmitter",new xe);vt(this,"__socketFilter");vt(this,"__socketHandler");vt(this,"emotion");vt(this,"history");vt(this,"message");vt(this,"status");vt(this,"utils");vt(this,"sender");vt(this,"manage");vt(this,"online");vt(this,"download");vt(this,"like");vt(this,"ask");vt(this,"emotionalFeedback");vt(this,"file");vt(this,"setuped",!1);this.plvSocket=a,this.config=t,this.emotion=new Ue(this),this.history=new Be(this),this.message=new Ve(this),this.status=new We(this),this.utils=new qe(this),this.sender=new Ke(this),this.manage=new He(this),this.online=new $e(this),this.download=new Ne(this),this.like=new ze(this),this.ask=new Pe(this),this.emotionalFeedback=new Fe(this),this.file=new De(this),this.__socketFilter=new Me(this),this.__socketHandler=new Ae(this)}setup(){return tt(this,null,function*(){this.setuped=!0})}destroy(){return tt(this,null,function*(){this.plvSocket.clearSocketHandles(Mt)})}}const Je="PolyvChat";exports.ChatMsgSource=et;exports.ChatRequestHistoryMode=Dt;exports.DonateType=Ft;exports.EmotionalFeedbackType=Zt;exports.GlobalVariable=Je;exports.ManageFailReason=Nt;exports.MotivationLikeType=Xt;exports.PolyvChat=Qe;exports.PolyvChatEvent=yt;exports.QuickReplyType=$t;exports.RedpackType=Jt;exports.SystemMsgType=Vt;exports.TranslateLanguage=te;exports.canQuoteMsgSource=ge;exports.canTopMsgSource=he;exports.isServiceMsgMap=de;console.log("%c@polyv/chat","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.7.0-rc-20260312.1]","[buildTime: 2026-03-11 03:19:47]");
|
package/index.es.js
CHANGED
|
@@ -7598,8 +7598,8 @@ const Xe = "PolyvChat";
|
|
|
7598
7598
|
console.log(
|
|
7599
7599
|
"%c@polyv/chat",
|
|
7600
7600
|
"background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff",
|
|
7601
|
-
"[version: 2.
|
|
7602
|
-
"[buildTime: 2026-
|
|
7601
|
+
"[version: 2.7.0-rc-20260312.1]",
|
|
7602
|
+
"[buildTime: 2026-03-11 03:19:47]"
|
|
7603
7603
|
);
|
|
7604
7604
|
export {
|
|
7605
7605
|
rt as ChatMsgSource,
|
package/index.umd.js
CHANGED
|
@@ -16,4 +16,4 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
18
18
|
* @license MIT
|
|
19
|
-
*/o.exports=function(e){return e!=null&&(t(e)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&t(r.slice(0,0))}(e)||!!e._isBuffer)}},function(o,s,t){t.r(s),t.d(s,"ChatImageUpload",function(){return ut}),t.d(s,"defaultConfig",function(){return gt}),t.d(s,"allowAccept",function(){return Ot}),t.d(s,"allowFileExtension",function(){return vt}),t.d(s,"FailError",function(){return it}),t.d(s,"FailCode",function(){return H}),t.d(s,"ChatImage",function(){return kt}),t.d(s,"ImageStatus",function(){return ot}),t(127),t(92),t(63),t(35),t(67),t(135),t(136),t(73);var e=Object.prototype.hasOwnProperty;function r(C,I){return e.call(C,I)}function n(C){if(C==null)throw new TypeError("Cannot convert undefined or null to object");for(var I=0;I<(arguments.length<=1?0:arguments.length-1);I++){var k=I+1<1||arguments.length<=I+1?void 0:arguments[I+1];if(k!=null)for(var M in k)M!=="__proto__"&&r(k,M)&&(C[M]=k[M])}return C}var i=Object.prototype.toString;t(74),t(53),t(151),t(152),t(154);function a(C,I){var k,M,x=n({encode:encodeURIComponent},I),$=[];function j(Q,J){J==null&&(J=""),J===""&&x.ignoreEmpty||(typeof x.encode=="function"&&(Q=x.encode(Q),J=x.encode(String(J))),$.push(Q+"="+J))}function K(Q){j(k,Q)}for(k in C)r(C,k)&&(M=C[k],Array.isArray(M)?M.forEach(K):j(k,M));return $.join("&")}t(116),t(155);function c(C,I,k){if(C==null||I==null)return C;var M=(C=String(C)).indexOf("#"),x="";return M!==-1&&(x=C.substring(M,C.length),C=C.substring(0,M)),(C=C.replace(/[?&]$/,""))+((I=typeof I!="string"?a(I,k):I.replace(/^[?&]/,""))?(C.indexOf("?")!==-1?"&":"?")+I:"")+x}t(157),t(159),t(117),t(160),t(161),t(162),t(163),t(164),t(120),t(167),t(173),t(174),t(175),t(176),t(178),t(179);function f(C){return(f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(I){return typeof I}:function(I){return I&&typeof Symbol=="function"&&I.constructor===Symbol&&I!==Symbol.prototype?"symbol":typeof I})(C)}function u(C,I){if(I&&(f(I)==="object"||typeof I=="function"))return I;if(I!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return function(k){if(k===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return k}(C)}function d(C){var I=typeof Map=="function"?new Map:void 0;return(d=function(k){if(k===null||(M=k,Function.toString.call(M).indexOf("[native code]")===-1))return k;var M;if(typeof k!="function")throw new TypeError("Super expression must either be null or a function");if(I!==void 0){if(I.has(k))return I.get(k);I.set(k,x)}function x(){return p(k,arguments,g(this).constructor)}return x.prototype=Object.create(k.prototype,{constructor:{value:x,enumerable:!1,writable:!0,configurable:!0}}),h(x,k)})(C)}function p(C,I,k){return(p=l()?Reflect.construct:function(M,x,$){var j=[null];j.push.apply(j,x);var K=new(Function.bind.apply(M,j));return $&&h(K,$.prototype),K}).apply(null,arguments)}function l(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(C){return!1}}function h(C,I){return(h=Object.setPrototypeOf||function(k,M){return k.__proto__=M,k})(C,I)}function g(C){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(I){return I.__proto__||Object.getPrototypeOf(I)})(C)}var v=function(C){(function(j,K){if(typeof K!="function"&&K!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(K&&K.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),K&&h(j,K)})($,C);var I,k,M,x=(I=$,k=l(),function(){var j,K=g(I);if(k){var Q=g(this).constructor;j=Reflect.construct(K,arguments,Q)}else j=K.apply(this,arguments);return u(this,j)});function $(j){var K;return function(Q,J){if(!(Q instanceof J))throw new TypeError("Cannot call a class as a function")}(this,$),(K=x.call(this,j)).name="AJAXError",K}return M=$,Object.defineProperty(M,"prototype",{writable:!1}),M}(d(Error)),y=/(?:^|;\s*)(?:application|text)\/([a-z]+)/i;t(180),t(182),t(183);function b(C,I,k,M){return function(){var x,$,j,K=(C.responseText||"").trim();switch(I.responseType||((j=C.getResponseHeader("Content-Type"))&&y.test(j)?RegExp.$1.toLowerCase():"")){case"json":if(K)try{x=JSON.parse(K)}catch(ct){$="Invalid JSON structure"}break;case"xml":(x=C.responseXML)&&x.documentElement||($="Invalid XML format");break;default:x=K}var Q,J={xhr:C,options:I,data:x},N=C.status;(function(ct){return!(ct===void 0||ct>=200&&ct<300||ct===1223||ct===304)})(N)?(Q=new v("Error (HTTP status code: "+N+")")).code=N:$&&(Q=new v($)),Q?M(n(Q,J)):k(J)}}var m=Object.create(null),w=0;function _(C,I,k,M){C.onload=b(C,I,k,M),C.ontimeout=function(){var $;M((($=new v("Request timeout")).isTimeout=!0,$))},C.onerror=function(){M(new v("Network error"))},I.onDownloadProgress&&C.addEventListener("progress",I.onDownloadProgress),I.onUploadProgress&&C.upload&&C.upload.addEventListener("progress",I.onUploadProgress),w===Number.MAX_SAFE_INTEGER&&(w=0);var x=++w;return m[x]={xhr:C,options:I,resolve:k,reject:M},x}function S(C){delete m[C]}function E(C,I,k,M,x){return C&&/MSIE\s+(\d+)/.test(navigator.userAgent)&&parseInt(RegExp.$1)<10&&window.XDomainRequest&&(I==="get"||I==="post")&&!k&&!x&&function($){if($!=null){if(Array.isArray($))return!$.length;for(var j in $)if(r($,j))return!1}return!0}(M)?new window.XDomainRequest:new window.XMLHttpRequest}function O(C,I,k,M){var x,$,j;if(k!=null&&C!=="get")return M==="json"?(x=JSON.stringify(k),$="application/json; charset=utf-8"):(j=k,typeof(x=i.call(j)==="[object Object]"?a(k,{ignoreEmpty:!1}):k)=="string"&&($="application/x-www-form-urlencoded; charset=utf-8")),I["Content-Type"]=I["Content-Type"]||$,x}function T(C,I){var k=0;return new Promise(function(M,x){(I=n({},I)).method=I.method||"get",I.requestType=I.requestType||"",I.responseType=I.responseType||"json",I.timeout=I.timeout||0;var $=I.method.toLowerCase(),j=I.requestType.toLowerCase(),K=I.headers||{},Q=function(ct){var R=document.createElement("div");R.innerHTML='<a href="'+ct+'"></a>';var G=R.firstChild,W=G.host!==location.host;return R=null,G=null,W}(C=function(ct,R,G){return R!=null&&(ct=c(ct,R,{ignoreEmpty:!1})),G&&(ct=c(ct,{_:Date.now()})),ct}(C,I.params,I.preventCaching)),J=E(Q,$,j,K,I.withCredentials);k=_(J,I,function(ct){S(k),M(ct)},function(ct){S(k),x(ct)}),J.open($,C,!0,I.username,I.password);var N=O($,K,I.data,j);(function(ct,R,G,W){R.timeout&&(ct.timeout=R.timeout),G&&R.withCredentials!=null&&(ct.withCredentials=!!R.withCredentials),G||W["X-Request-With"]!=null||(W["X-Request-With"]="XMLHttpRequest"),Object.keys(W).forEach(function(X){W[X]!=null&&ct.setRequestHeader(X,String(W[X]))})})(J,I,Q,K),typeof I.beforeSend=="function"&&I.beforeSend.call(window,J),J.send(N||""),typeof I.receiveCancelId=="function"&&I.receiveCancelId(k)})}var A=t(82),U=t.n(A);function V(C){return C.name.toLowerCase().split(".").pop()||""}function F(C){var I=new FormData;for(var k in C)I.append(k,C[k]);return I}function z(C,I,k){k===void 0&&(k=!1);for(var M=C.split(","),x=/:(.*?);/.exec(M[0]),$=x?x[1]:"image/jpeg",j=window.atob(M[1]),K=j.length,Q=new Uint8Array(K);K--;)Q[K]=j.charCodeAt(K);return k?new Blob([Q],{type:$}):new File([Q],I,{type:$})}function B(C){return new Promise(function(I,k){var M=new Image;M.onload=function(){I({width:M.width,height:M.height,imageTarget:M})},M.onerror=function(){k(new Error("获取图片尺寸失败"))};var x="";x=typeof C=="string"?C:L(C),M.src=x})}function L(C){return(window.URL||window.webkitURL).createObjectURL(C)}var P,D,H,Z=(P=function(C,I){return(P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(k,M){k.__proto__=M}||function(k,M){for(var x in M)Object.prototype.hasOwnProperty.call(M,x)&&(k[x]=M[x])})(C,I)},function(C,I){if(typeof I!="function"&&I!==null)throw new TypeError("Class extends value "+String(I)+" is not a constructor or null");function k(){this.constructor=C}P(C,I),C.prototype=I===null?Object.create(I):(k.prototype=I.prototype,new k)});(function(C){C.EMPTY_FILE="empty file",C.FILE_SIZE_TOO_LARGE="file size too large",C.FILE_TYPE_NOT_ALLOW="file type not allow",C.FILE_EXTENSION_NOT_ALLOW="file extension not allow",C.GET_UPLOAD_TOKEN_ERROR="get upload token error",C.UPLOAD_IMAGE_ERROR="upload image error",C.PORN_IDENTIFY_ERROR="porn identify error"})(H||(H={}));var ot,it=function(C){function I(k){var M=C.call(this,k)||this,x=I.getFailErrorData(k);return M.failCode=x.failCode,M.failMessage=x.failMessage,M}return Z(I,C),I.getFailErrorData=function(k){return{failCode:k,failMessage:I.failMessageVal[k]}},I.failMessageVal=((D={})[H.EMPTY_FILE]="请勿上传空文件",D[H.FILE_SIZE_TOO_LARGE]="文件大小超出限制",D[H.FILE_TYPE_NOT_ALLOW]="该文件类型不支持",D[H.FILE_EXTENSION_NOT_ALLOW]="该文件扩展名不支持",D[H.GET_UPLOAD_TOKEN_ERROR]="获取上传图片 token 失败",D[H.UPLOAD_IMAGE_ERROR]="上传图片失败",D[H.PORN_IDENTIFY_ERROR]="图片鉴黄失败",D),I}(Error),nt=function(){return(nt=Object.assign||function(C){for(var I,k=1,M=arguments.length;k<M;k++)for(var x in I=arguments[k])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},Y=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(ct){ct(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ht=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ct){N=[6,ct],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},dt=function(){function C(I){this.uploadCtx=I.uploadCtx}return C.prototype.getUploadToken=function(I){return Y(this,void 0,void 0,function(){var k,M,x,$,j;return ht(this,function(K){switch(K.label){case 0:return k=Date.now(),M=U()("upload_token_live"+I.channelId+k),x={channelId:I.channelId,ts:k,hash:M,bucket:I.bucket},I.userId&&(x.userId=I.userId),[4,T("https://"+this.uploadCtx.apiHost+"/live/upload/token/image/get-token",{params:x})];case 1:return($=K.sent()).data?(j=$.data).code!==200?[2,Promise.reject(new it(H.GET_UPLOAD_TOKEN_ERROR))]:[2,j.data]:[2,Promise.reject(new it(H.GET_UPLOAD_TOKEN_ERROR))]}})})},C.prototype.uploadImage=function(I){return Y(this,void 0,void 0,function(){var k,M,x,$,j,K;return ht(this,function(Q){switch(Q.label){case 0:k={key:""+I.dir+I.fileName,policy:I.policy,OSSAccessKeyId:I.accessid,signature:I.signature,success_action_status:200,callback:I.encodedCallback,file:I.file},Q.label=1;case 1:return Q.trys.push([1,3,,4]),[4,T("https://"+I.host,{method:"post",data:F(k),onUploadProgress:function(J){var N,ct,R=I.onUploadProgress;typeof R=="function"&&R((N=J.loaded/J.total,ct=2,Number(N.toFixed(ct||0))))}})];case 2:return(M=Q.sent()).data?(x=M.data).code!==200?[2,Promise.reject(new it(H.UPLOAD_IMAGE_ERROR))]:[2,x.data]:[2,Promise.reject(new it(H.UPLOAD_IMAGE_ERROR))];case 3:return Q.sent(),$=I.currentReuploadTime,(j=$===void 0?0:$)&&j>=this.uploadCtx.reUploadTimes?[2,Promise.reject(new it(H.UPLOAD_IMAGE_ERROR))]:(j+=1,K=Object.assign({},I,{currentReuploadTime:j}),[2,this.uploadImage(K)]);case 4:return[2]}})})},C.prototype.createSign=function(I,k,M){var x=I;Object.keys(k).sort().forEach(function(j){k[j]&&(x+=j+String(k[j]))}),x+=I;var $=U()(x);return M==="lower"?$:$.toLocaleUpperCase()},C.prototype.pornIdentify=function(I){return Y(this,void 0,void 0,function(){var k,M,x;return ht(this,function($){switch($.label){case 0:k=nt(nt({},I),{timestamp:Date.now()}),$.label=1;case 1:return $.trys.push([1,3,,4]),[4,T("https://"+this.uploadCtx.apiHost+"/live/inner/v3/chat/image/porn-identify",{method:"post",data:nt(nt({},k),{sign:this.createSign("polyv_chat_api_innor",k)})})];case 2:return(M=$.sent()).data?M.data.code!==200?[2,Promise.reject(new it(H.PORN_IDENTIFY_ERROR))]:[2,!0]:[2,Promise.reject(new it(H.PORN_IDENTIFY_ERROR))];case 3:return x=$.sent(),[2,Promise.reject(x)];case 4:return[2]}})})},C}();(function(C){C.WAIT_UPLOAD="waitUpload",C.UPLOADING="uploading",C.UPLOAD_SUCCESS="uploadSuccess",C.UPLOAD_FAIL="uploadFail",C.UPLOAD_FORBID="forbid"})(ot||(ot={}));var _t=function(){return(_t=Object.assign||function(C){for(var I,k=1,M=arguments.length;k<M;k++)for(var x in I=arguments[k])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},It=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(ct){ct(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ft=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ct){N=[6,ct],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},pt={width:500,height:500},kt=function(){function C(I){var k=I.callbackChange,M=k===void 0||k;this.imageId=I.imageId,this.uploadCtx=I.uploadCtx,this.file=I.file,this._status=I.status||ot.WAIT_UPLOAD,this.callbackChange=M,this.fileUrl=void 0,this.uploadProgress=void 0,this.previewSrc=L(this.file),this.uploadCtx.recordChatImage(this),this.triggerChange()}return C.prototype.upload=function(I){return I===void 0&&(I={}),It(this,void 0,void 0,function(){var k,M,x,$,j,K,Q,J,N,ct,R,G,W,X=this;return ft(this,function(st){switch(st.label){case 0:return k=this.uploadCtx,M=k.channelId,x=k.userId,$=k.bucket,this.status=ot.UPLOADING,[4,k.uploadApi.getUploadToken({channelId:M,userId:x,bucket:$})];case 1:if(j=st.sent(),!((K=this.file).size>1024*k.compressSizeLimit))return[3,5];st.label=2;case 2:return st.trys.push([2,4,,5]),[4,this.compressImage({file:this.file,fileName:this.fileName})];case 3:return Q=st.sent(),K=Q,[3,5];case 4:return st.sent(),console.warn("图片压缩失败",K,this.imageId),[3,5];case 5:return st.trys.push([5,7,,8]),[4,B(K)];case 6:return J=st.sent(),N=J.width,ct=J.height,this.size={width:N,height:ct},[3,8];case 7:return st.sent(),console.warn("获取图片尺寸失败"),[3,8];case 8:this.size||(this.size=pt),this.uploadProgress=0,R="",st.label=9;case 9:return st.trys.push([9,13,,14]),[4,k.uploadApi.uploadImage(_t(_t({},j),{file:K,fileName:this.fileName,onUploadProgress:function(At){X.uploadProgress=At,X.triggerChange()}}))];case 10:return R=st.sent(),this.fileUrl=R,k.enablePornChecking?[4,k.uploadApi.pornIdentify({channelId:M,url:"https:"+R})]:[3,12];case 11:st.sent(),st.label=12;case 12:return this.status=ot.UPLOAD_SUCCESS,[3,14];case 13:return G=st.sent(),this.status=G.failCode===H.PORN_IDENTIFY_ERROR?ot.UPLOAD_FORBID:ot.UPLOAD_FAIL,I.error,[2,Promise.reject(G)];case 14:return typeof(W=I.success)=="function"&&W(R),[2,R]}})})},C.prototype.compressImage=function(I){return It(this,void 0,void 0,function(){var k,M,x,$,j,K,Q,J,N,ct;return ft(this,function(R){switch(R.label){case 0:return k=I.file,M=I.fileName,x=I.quality,$=x===void 0?.7:x,[4,B(k)];case 1:return j=R.sent(),K=j.width,Q=j.height,J=j.imageTarget,(N=document.createElement("canvas")).setAttribute("width",""+K),N.setAttribute("height",""+Q),(ct=N.getContext("2d"))?(ct.drawImage(J,0,0,K,Q),[2,z(N.toDataURL("image/jpeg",$),M)]):[2,Promise.reject(new Error("create canvas error"))]}})})},C.prototype.triggerChange=function(){if(this.callbackChange){var I=this.uploadCtx.onChange;typeof I=="function"&&I(this)}},Object.defineProperty(C.prototype,"fileName",{get:function(){var I=V(this.file);return this.imageId+"."+(I||"png")},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"status",{get:function(){return this._status},set:function(I){this._status=I,this.triggerChange()},enumerable:!1,configurable:!0}),C}(),Et=function(){function C(I){this.uploadCtx=I.uploadCtx,this.uploadingList=[],this.waitQueue=[]}return C.prototype.joinWaitQueue=function(I){this.isExistQueue(I,this.waitQueue)||(this.waitQueue.push(I),this.checkQueue())},C.prototype.checkQueue=function(){var I=this;if(!(this.uploadingList.length>=this.uploadCtx.maxUploadNumber)&&this.waitQueue.length!==0)for(var k=this.uploadCtx.maxUploadNumber-this.uploadingList.length,M=function(j){var K=x.waitQueue.shift();K&&(K.upload({success:function(){I.handleImageUploadSuccess(K)}}),x.uploadingList.push(K))},x=this,$=0;$<k;$++)M()},C.prototype.handleImageUploadSuccess=function(I){this.uploadingList=this.uploadingList.filter(function(k){return k.imageId!==I.imageId}),this.checkQueue()},C.prototype.isExistQueue=function(I,k){return k.findIndex(function(M){return M.imageId===I.imageId})!==-1},C}(),Ot=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/bmp","image/tiff","image/tifa"],vt=["png","bmp","webp","tiff","tif","jpeg","jpg","gif"],gt={channelId:"",userId:"",sizeLimit:81920,compressSizeLimit:2048,limit:9,maxWidth:700,reUploadTimes:3,source:"chat_img",bucket:"liveimages",useBlobByCompress:!1,allowAccept:Ot,allowFileExtension:vt,maxUploadNumber:3,enablePornChecking:!1,apiHost:"api.polyv.net"},xt=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(ct){ct(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},q=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ct){N=[6,ct],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ut=function(){function C(I){I===void 0&&(I={});var k=I.channelId,M=k===void 0?gt.channelId:k,x=I.userId,$=x===void 0?gt.userId:x,j=I.sizeLimit,K=j===void 0?gt.sizeLimit:j,Q=I.compressSizeLimit,J=Q===void 0?gt.compressSizeLimit:Q,N=I.limit,ct=N===void 0?gt.limit:N,R=I.maxWidth,G=R===void 0?gt.maxWidth:R,W=I.reUploadTimes,X=W===void 0?gt.reUploadTimes:W,st=I.source,At=st===void 0?gt.source:st,Pt=I.bucket,Ut=Pt===void 0?gt.bucket:Pt,zt=I.useBlobByCompress,at=zt===void 0?gt.useBlobByCompress:zt,lt=I.allowAccept,bt=lt===void 0?gt.allowAccept:lt,St=I.allowFileExtension,Rt=St===void 0?gt.allowFileExtension:St,Jt=I.maxUploadNumber,Wt=Jt===void 0?gt.maxUploadNumber:Jt,ge=I.apiHost,$e=ge===void 0?gt.apiHost:ge,Ke=I.onChange,We=I.beforeStart;this.channelId=M,this.userId=$,this.sizeLimit=K,this.compressSizeLimit=J,this.limit=ct,this.maxWidth=G,this.reUploadTimes=X,this.source=At,this.bucket=Ut,this.useBlobByCompress=!!at,this.allowAccept=bt,this.allowFileExtension=Rt,this.maxUploadNumber=Wt,this.onChange=Ke,this.beforeStart=We,this.enablePornChecking=I.enablePornChecking===!0,this.apiHost=$e,this.uploadQueue=new Et({uploadCtx:this}),this.uploadApi=new dt({uploadCtx:this}),this.chatImageStore={}}return C.prototype.choiceImageFile=function(I){var k=this;I===void 0&&(I={});var M=this.getAccept(),x=document.createElement("input");return x.setAttribute("id","polyv-upload-chat-image-input-id"),x.setAttribute("type","file"),x.setAttribute("accept",M),x.setAttribute("style","visibility: hidden;position: fixed;bottom: -100%;z-index: -1;"),this.limit>1&&x.setAttribute("multiple","multiple"),x.addEventListener("change",function(){document.body.removeChild(x),I&&x.files&&x.files.length!==0&&k.handleFileList(I,x.files)}),document.body.appendChild(x),x.click(),this},C.prototype.handleFileList=function(I,k){this.beforeStart&&this.beforeStart();for(var M,x=I.fail,$=I.success,j=I.callbackChange,K=k.length<this.limit?k.length:this.limit,Q=0;Q<K;Q++){var J=k[Q],N=this.checkFile(J);if(N)return M=N,void(typeof x=="function"&&x(M))}var ct=[];for(Q=0;Q<K;Q++){J=k[Q];var R=this.buildImageId(Q),G=new kt({imageId:R,uploadCtx:this,file:J,callbackChange:j});ct.push(G)}typeof $=="function"&&$(ct)},C.prototype.getAccept=function(){var I=[];return I.push.apply(I,this.allowFileExtension.map(function(k){return"."+k})),I.push.apply(I,this.allowAccept),I.join(",")},C.prototype.joinWaitQueue=function(I){var k=this;if(Array.isArray(I))return I.forEach(function(x){k.joinWaitQueue(x)}),this;var M=void 0;return typeof I=="string"?M=this.getChatImageById(I):I instanceof kt&&(M=I),M&&this.uploadQueue.joinWaitQueue(M),this},C.prototype.getUploadImageUrl=function(){var I=this;return new Promise(function(k,M){I.choiceImageFile({callbackChange:!1,success:function(x){return xt(I,void 0,void 0,function(){var $;return q(this,function(j){switch(j.label){case 0:return[4,($=x[0]).upload()];case 1:return j.sent(),$.fileUrl?k($):M(new it(H.UPLOAD_IMAGE_ERROR)),[2]}})})},fail:function(x){M(x)}})})},C.prototype.callbackUploadImage=function(){var I=this;this.choiceImageFile({success:function(k){I.joinWaitQueue(k)}})},C.prototype.uploadImageFile=function(I){return xt(this,void 0,void 0,function(){var k;return q(this,function(M){switch(M.label){case 0:if(k=this.checkFile(I))throw new Error(k.failMessage);return[4,new kt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:!1}).upload()];case 1:return[2,M.sent()]}})})},C.prototype.uploadImage=function(I,k){return xt(this,void 0,void 0,function(){var M,x;return q(this,function($){switch($.label){case 0:if(M=this.checkFile(I))throw new Error(M.failMessage);return[4,(x=new kt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:k!==!1})).upload()];case 1:return $.sent(),[2,x]}})})},C.prototype.reUploadImage=function(I){return xt(this,void 0,void 0,function(){var k,M;return q(this,function(x){switch(x.label){case 0:if(!(k=this.getChatImageById(I)))return[2,Promise.reject(new Error("图片不存在"))];x.label=1;case 1:return x.trys.push([1,3,,4]),[4,k.upload()];case 2:return x.sent(),[2,k];case 3:return M=x.sent(),[2,Promise.reject(M)];case 4:return[2]}})})},C.prototype.getChatImageById=function(I){return this.chatImageStore[I]},C.prototype.recordChatImage=function(I){this.chatImageStore[I.imageId]=I},C.prototype.checkFile=function(I){if(!I.size)return it.getFailErrorData(H.EMPTY_FILE);if(I.size>1024*this.sizeLimit)return it.getFailErrorData(H.FILE_SIZE_TOO_LARGE);if(!this.allowAccept.includes(I.type))return it.getFailErrorData(H.FILE_TYPE_NOT_ALLOW);var k=V(I);return this.allowFileExtension.includes(k)?void 0:it.getFailErrorData(H.FILE_EXTENSION_NOT_ALLOW)},C.prototype.buildImageId=function(I){var k=[];this.source&&k.push(this.source),this.channelId&&k.push(this.channelId),this.userId&&k.push(this.userId);var M=I!==void 0?"_"+I:"";return k.join("_")+"_"+Date.now()+"_"+Math.random().toString().substring(2,10)+M},C}()}]);class He extends Nt{constructor(t){super(t);mt(this,"__uploadImgCtrl");mt(this,"__svgaMap",{coffee:"coffee.svga",like:"like.svga",handclap:"handclap.svga",666:"666.svga",star:"star.svga",diamond:"diamond.svga",car:"car.svga",rocket:"rocket.svga",bear:"bear.svga",crown:"crown.svga",cup:"cup.svga",microphone:"microphone.svga",villa:"villa.svga",house:"villa.svga"});this.__uploadImgCtrl=new ze.ChatImageUpload({enablePornChecking:!0})}__setUploadImgChannelId(){return rt(this,null,function*(){const t=yield this._plvSocket.channel.getChannelInfo();this.__uploadImgCtrl.channelId=t.channelId})}uploadMultiImage(t){return rt(this,null,function*(){yield this.__setUploadImgChannelId();const e=(t==null?void 0:t.maxLimit)||9,r=typeof(t==null?void 0:t.ready)=="function"?t.ready:()=>{},n=typeof(t==null?void 0:t.success)=="function"?t.success:()=>{},i=typeof(t==null?void 0:t.fail)=="function"?t.fail:()=>{},a=[],c=[];return new Promise((f,u)=>{this.__uploadImgCtrl.choiceImageFile({callbackChange:!1,success:d=>rt(this,null,function*(){d=d.slice(0,e),yield Promise.all(d.map(v=>new Promise(y=>{const b=URL.createObjectURL(v.file),m=new Image;m.onload=()=>{v.size={width:m.width,height:m.height},URL.revokeObjectURL(b),y()},m.src=b}))),d.forEach(v=>{r({imageId:v.imageId,previewSrc:v.previewSrc||"",size:v.size})});try{for(var p=ye(d),l,h,g;l=!(h=yield p.next()).done;l=!1){const v=h.value;try{const y=yield v.upload();if(!y)throw new Error("upload Image Error");const b={imageId:v.imageId,imageUrl:y,size:v.size};a.push(b),n(b)}catch(y){const b=y,m={imageId:v.imageId,previewSrc:v.previewSrc||""};c.push(m),console.error("[util-module][uploadMultiImage] ",b.message,m),i(b,m)}}}catch(h){g=[h]}finally{try{l&&(h=p.return)&&(yield h.call(p))}finally{if(g)throw g[0]}}return f({successUploadImages:a,failUploadImages:c})}),fail:d=>{console.error("[util-module][uploadMultiImage] ",d),u(new Error(d.failMessage))}})})})}directUploadImage(t){return rt(this,null,function*(){if(!t)throw new Error("file is null");yield this.__setUploadImgChannelId();const e=yield this.__uploadImgCtrl.uploadImage(t);if(!e.fileUrl)throw new Error("upload fail");return{imageId:e.imageId,imageUrl:e.fileUrl,size:e.size}})}translateText(t){return rt(this,null,function*(){const e=this._plvSocket.getUserInfo(),r=yield this._plvSocket.polyvApi.getTokenFieldByUserType();return(yield this._plvSocket.polyvApi.post("/live/v4/channel/translate",{},{params:{query:t,viewerId:e.userId},tokenInfo:{tokenField:r}}))[0]})}__genResourceUrl(t){return`https://s1.videocc.net${t}`}getDefaultResource(){return{defaultViewerAvatar:this.__genResourceUrl("/default-img/avatar/viewer.png")}}getDefaultDonateSvgaUrl(t){return rt(this,null,function*(){const e=t.gimg,r=this.__svgaMap,n=document.createElement("a");n.href=e;const i=n.pathname.split("/"),a=i[i.length-1].split(".")[0];if(r[a])return this.__genResourceUrl(`/default-img/donate-svga/${r[a]}`)})}}class Ge{constructor(s,t={}){mt(this,"PolyvChatEvent",tt);mt(this,"ChatMsgSource",et);mt(this,"DonateType",Bt);mt(this,"RedpackType",Zt);mt(this,"SystemMsgType",qt);mt(this,"ChatRequestHistoryMode",Ht);mt(this,"ManageFailReason",wt);mt(this,"TranslateLanguage",re);mt(this,"QuickReplyType",Qt);mt(this,"EmotionalFeedbackType",ee);mt(this,"eventEmitter",new Vt);mt(this,"__socketFilter");mt(this,"__socketHandler");mt(this,"emotion");mt(this,"history");mt(this,"message");mt(this,"status");mt(this,"utils");mt(this,"sender");mt(this,"manage");mt(this,"online");mt(this,"download");mt(this,"like");mt(this,"ask");mt(this,"emotionalFeedback");mt(this,"file");mt(this,"setuped",!1);this.plvSocket=s,this.config=t,this.emotion=new Me(this),this.history=new Pe(this),this.message=new Ue(this),this.status=new Be(this),this.utils=new He(this),this.sender=new De(this),this.manage=new je(this),this.online=new Fe(this),this.download=new Te(this),this.like=new Le(this),this.ask=new ke(this),this.emotionalFeedback=new Ae(this),this.file=new Re(this),this.__socketFilter=new we(this),this.__socketHandler=new xe(this)}setup(){return rt(this,null,function*(){this.setuped=!0})}destroy(){return rt(this,null,function*(){this.plvSocket.clearSocketHandles(Tt)})}}const Ve="PolyvChat";yt.ChatMsgSource=et,yt.ChatRequestHistoryMode=Ht,yt.DonateType=Bt,yt.EmotionalFeedbackType=ee,yt.GlobalVariable=Ve,yt.ManageFailReason=wt,yt.MotivationLikeType=te,yt.PolyvChat=Ge,yt.PolyvChatEvent=tt,yt.QuickReplyType=Qt,yt.RedpackType=Zt,yt.SystemMsgType=qt,yt.TranslateLanguage=re,yt.canQuoteMsgSource=he,yt.canTopMsgSource=de,yt.isServiceMsgMap=pe,Object.defineProperty(yt,Symbol.toStringTag,{value:"Module"})});console.log("%c@polyv/chat","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.6.0-rc-20260205.2]","[buildTime: 2026-02-05 10:05:07]");
|
|
19
|
+
*/o.exports=function(e){return e!=null&&(t(e)||function(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&t(r.slice(0,0))}(e)||!!e._isBuffer)}},function(o,s,t){t.r(s),t.d(s,"ChatImageUpload",function(){return ut}),t.d(s,"defaultConfig",function(){return gt}),t.d(s,"allowAccept",function(){return Ot}),t.d(s,"allowFileExtension",function(){return vt}),t.d(s,"FailError",function(){return it}),t.d(s,"FailCode",function(){return H}),t.d(s,"ChatImage",function(){return kt}),t.d(s,"ImageStatus",function(){return ot}),t(127),t(92),t(63),t(35),t(67),t(135),t(136),t(73);var e=Object.prototype.hasOwnProperty;function r(C,I){return e.call(C,I)}function n(C){if(C==null)throw new TypeError("Cannot convert undefined or null to object");for(var I=0;I<(arguments.length<=1?0:arguments.length-1);I++){var k=I+1<1||arguments.length<=I+1?void 0:arguments[I+1];if(k!=null)for(var M in k)M!=="__proto__"&&r(k,M)&&(C[M]=k[M])}return C}var i=Object.prototype.toString;t(74),t(53),t(151),t(152),t(154);function a(C,I){var k,M,x=n({encode:encodeURIComponent},I),$=[];function j(Q,J){J==null&&(J=""),J===""&&x.ignoreEmpty||(typeof x.encode=="function"&&(Q=x.encode(Q),J=x.encode(String(J))),$.push(Q+"="+J))}function K(Q){j(k,Q)}for(k in C)r(C,k)&&(M=C[k],Array.isArray(M)?M.forEach(K):j(k,M));return $.join("&")}t(116),t(155);function c(C,I,k){if(C==null||I==null)return C;var M=(C=String(C)).indexOf("#"),x="";return M!==-1&&(x=C.substring(M,C.length),C=C.substring(0,M)),(C=C.replace(/[?&]$/,""))+((I=typeof I!="string"?a(I,k):I.replace(/^[?&]/,""))?(C.indexOf("?")!==-1?"&":"?")+I:"")+x}t(157),t(159),t(117),t(160),t(161),t(162),t(163),t(164),t(120),t(167),t(173),t(174),t(175),t(176),t(178),t(179);function f(C){return(f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(I){return typeof I}:function(I){return I&&typeof Symbol=="function"&&I.constructor===Symbol&&I!==Symbol.prototype?"symbol":typeof I})(C)}function u(C,I){if(I&&(f(I)==="object"||typeof I=="function"))return I;if(I!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return function(k){if(k===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return k}(C)}function d(C){var I=typeof Map=="function"?new Map:void 0;return(d=function(k){if(k===null||(M=k,Function.toString.call(M).indexOf("[native code]")===-1))return k;var M;if(typeof k!="function")throw new TypeError("Super expression must either be null or a function");if(I!==void 0){if(I.has(k))return I.get(k);I.set(k,x)}function x(){return p(k,arguments,g(this).constructor)}return x.prototype=Object.create(k.prototype,{constructor:{value:x,enumerable:!1,writable:!0,configurable:!0}}),h(x,k)})(C)}function p(C,I,k){return(p=l()?Reflect.construct:function(M,x,$){var j=[null];j.push.apply(j,x);var K=new(Function.bind.apply(M,j));return $&&h(K,$.prototype),K}).apply(null,arguments)}function l(){if(typeof Reflect=="undefined"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(C){return!1}}function h(C,I){return(h=Object.setPrototypeOf||function(k,M){return k.__proto__=M,k})(C,I)}function g(C){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(I){return I.__proto__||Object.getPrototypeOf(I)})(C)}var v=function(C){(function(j,K){if(typeof K!="function"&&K!==null)throw new TypeError("Super expression must either be null or a function");j.prototype=Object.create(K&&K.prototype,{constructor:{value:j,writable:!0,configurable:!0}}),Object.defineProperty(j,"prototype",{writable:!1}),K&&h(j,K)})($,C);var I,k,M,x=(I=$,k=l(),function(){var j,K=g(I);if(k){var Q=g(this).constructor;j=Reflect.construct(K,arguments,Q)}else j=K.apply(this,arguments);return u(this,j)});function $(j){var K;return function(Q,J){if(!(Q instanceof J))throw new TypeError("Cannot call a class as a function")}(this,$),(K=x.call(this,j)).name="AJAXError",K}return M=$,Object.defineProperty(M,"prototype",{writable:!1}),M}(d(Error)),y=/(?:^|;\s*)(?:application|text)\/([a-z]+)/i;t(180),t(182),t(183);function b(C,I,k,M){return function(){var x,$,j,K=(C.responseText||"").trim();switch(I.responseType||((j=C.getResponseHeader("Content-Type"))&&y.test(j)?RegExp.$1.toLowerCase():"")){case"json":if(K)try{x=JSON.parse(K)}catch(ct){$="Invalid JSON structure"}break;case"xml":(x=C.responseXML)&&x.documentElement||($="Invalid XML format");break;default:x=K}var Q,J={xhr:C,options:I,data:x},N=C.status;(function(ct){return!(ct===void 0||ct>=200&&ct<300||ct===1223||ct===304)})(N)?(Q=new v("Error (HTTP status code: "+N+")")).code=N:$&&(Q=new v($)),Q?M(n(Q,J)):k(J)}}var m=Object.create(null),w=0;function _(C,I,k,M){C.onload=b(C,I,k,M),C.ontimeout=function(){var $;M((($=new v("Request timeout")).isTimeout=!0,$))},C.onerror=function(){M(new v("Network error"))},I.onDownloadProgress&&C.addEventListener("progress",I.onDownloadProgress),I.onUploadProgress&&C.upload&&C.upload.addEventListener("progress",I.onUploadProgress),w===Number.MAX_SAFE_INTEGER&&(w=0);var x=++w;return m[x]={xhr:C,options:I,resolve:k,reject:M},x}function S(C){delete m[C]}function E(C,I,k,M,x){return C&&/MSIE\s+(\d+)/.test(navigator.userAgent)&&parseInt(RegExp.$1)<10&&window.XDomainRequest&&(I==="get"||I==="post")&&!k&&!x&&function($){if($!=null){if(Array.isArray($))return!$.length;for(var j in $)if(r($,j))return!1}return!0}(M)?new window.XDomainRequest:new window.XMLHttpRequest}function O(C,I,k,M){var x,$,j;if(k!=null&&C!=="get")return M==="json"?(x=JSON.stringify(k),$="application/json; charset=utf-8"):(j=k,typeof(x=i.call(j)==="[object Object]"?a(k,{ignoreEmpty:!1}):k)=="string"&&($="application/x-www-form-urlencoded; charset=utf-8")),I["Content-Type"]=I["Content-Type"]||$,x}function T(C,I){var k=0;return new Promise(function(M,x){(I=n({},I)).method=I.method||"get",I.requestType=I.requestType||"",I.responseType=I.responseType||"json",I.timeout=I.timeout||0;var $=I.method.toLowerCase(),j=I.requestType.toLowerCase(),K=I.headers||{},Q=function(ct){var R=document.createElement("div");R.innerHTML='<a href="'+ct+'"></a>';var G=R.firstChild,W=G.host!==location.host;return R=null,G=null,W}(C=function(ct,R,G){return R!=null&&(ct=c(ct,R,{ignoreEmpty:!1})),G&&(ct=c(ct,{_:Date.now()})),ct}(C,I.params,I.preventCaching)),J=E(Q,$,j,K,I.withCredentials);k=_(J,I,function(ct){S(k),M(ct)},function(ct){S(k),x(ct)}),J.open($,C,!0,I.username,I.password);var N=O($,K,I.data,j);(function(ct,R,G,W){R.timeout&&(ct.timeout=R.timeout),G&&R.withCredentials!=null&&(ct.withCredentials=!!R.withCredentials),G||W["X-Request-With"]!=null||(W["X-Request-With"]="XMLHttpRequest"),Object.keys(W).forEach(function(X){W[X]!=null&&ct.setRequestHeader(X,String(W[X]))})})(J,I,Q,K),typeof I.beforeSend=="function"&&I.beforeSend.call(window,J),J.send(N||""),typeof I.receiveCancelId=="function"&&I.receiveCancelId(k)})}var A=t(82),U=t.n(A);function V(C){return C.name.toLowerCase().split(".").pop()||""}function F(C){var I=new FormData;for(var k in C)I.append(k,C[k]);return I}function z(C,I,k){k===void 0&&(k=!1);for(var M=C.split(","),x=/:(.*?);/.exec(M[0]),$=x?x[1]:"image/jpeg",j=window.atob(M[1]),K=j.length,Q=new Uint8Array(K);K--;)Q[K]=j.charCodeAt(K);return k?new Blob([Q],{type:$}):new File([Q],I,{type:$})}function B(C){return new Promise(function(I,k){var M=new Image;M.onload=function(){I({width:M.width,height:M.height,imageTarget:M})},M.onerror=function(){k(new Error("获取图片尺寸失败"))};var x="";x=typeof C=="string"?C:L(C),M.src=x})}function L(C){return(window.URL||window.webkitURL).createObjectURL(C)}var P,D,H,Z=(P=function(C,I){return(P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(k,M){k.__proto__=M}||function(k,M){for(var x in M)Object.prototype.hasOwnProperty.call(M,x)&&(k[x]=M[x])})(C,I)},function(C,I){if(typeof I!="function"&&I!==null)throw new TypeError("Class extends value "+String(I)+" is not a constructor or null");function k(){this.constructor=C}P(C,I),C.prototype=I===null?Object.create(I):(k.prototype=I.prototype,new k)});(function(C){C.EMPTY_FILE="empty file",C.FILE_SIZE_TOO_LARGE="file size too large",C.FILE_TYPE_NOT_ALLOW="file type not allow",C.FILE_EXTENSION_NOT_ALLOW="file extension not allow",C.GET_UPLOAD_TOKEN_ERROR="get upload token error",C.UPLOAD_IMAGE_ERROR="upload image error",C.PORN_IDENTIFY_ERROR="porn identify error"})(H||(H={}));var ot,it=function(C){function I(k){var M=C.call(this,k)||this,x=I.getFailErrorData(k);return M.failCode=x.failCode,M.failMessage=x.failMessage,M}return Z(I,C),I.getFailErrorData=function(k){return{failCode:k,failMessage:I.failMessageVal[k]}},I.failMessageVal=((D={})[H.EMPTY_FILE]="请勿上传空文件",D[H.FILE_SIZE_TOO_LARGE]="文件大小超出限制",D[H.FILE_TYPE_NOT_ALLOW]="该文件类型不支持",D[H.FILE_EXTENSION_NOT_ALLOW]="该文件扩展名不支持",D[H.GET_UPLOAD_TOKEN_ERROR]="获取上传图片 token 失败",D[H.UPLOAD_IMAGE_ERROR]="上传图片失败",D[H.PORN_IDENTIFY_ERROR]="图片鉴黄失败",D),I}(Error),nt=function(){return(nt=Object.assign||function(C){for(var I,k=1,M=arguments.length;k<M;k++)for(var x in I=arguments[k])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},Y=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(ct){ct(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ht=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ct){N=[6,ct],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},dt=function(){function C(I){this.uploadCtx=I.uploadCtx}return C.prototype.getUploadToken=function(I){return Y(this,void 0,void 0,function(){var k,M,x,$,j;return ht(this,function(K){switch(K.label){case 0:return k=Date.now(),M=U()("upload_token_live"+I.channelId+k),x={channelId:I.channelId,ts:k,hash:M,bucket:I.bucket},I.userId&&(x.userId=I.userId),[4,T("https://"+this.uploadCtx.apiHost+"/live/upload/token/image/get-token",{params:x})];case 1:return($=K.sent()).data?(j=$.data).code!==200?[2,Promise.reject(new it(H.GET_UPLOAD_TOKEN_ERROR))]:[2,j.data]:[2,Promise.reject(new it(H.GET_UPLOAD_TOKEN_ERROR))]}})})},C.prototype.uploadImage=function(I){return Y(this,void 0,void 0,function(){var k,M,x,$,j,K;return ht(this,function(Q){switch(Q.label){case 0:k={key:""+I.dir+I.fileName,policy:I.policy,OSSAccessKeyId:I.accessid,signature:I.signature,success_action_status:200,callback:I.encodedCallback,file:I.file},Q.label=1;case 1:return Q.trys.push([1,3,,4]),[4,T("https://"+I.host,{method:"post",data:F(k),onUploadProgress:function(J){var N,ct,R=I.onUploadProgress;typeof R=="function"&&R((N=J.loaded/J.total,ct=2,Number(N.toFixed(ct||0))))}})];case 2:return(M=Q.sent()).data?(x=M.data).code!==200?[2,Promise.reject(new it(H.UPLOAD_IMAGE_ERROR))]:[2,x.data]:[2,Promise.reject(new it(H.UPLOAD_IMAGE_ERROR))];case 3:return Q.sent(),$=I.currentReuploadTime,(j=$===void 0?0:$)&&j>=this.uploadCtx.reUploadTimes?[2,Promise.reject(new it(H.UPLOAD_IMAGE_ERROR))]:(j+=1,K=Object.assign({},I,{currentReuploadTime:j}),[2,this.uploadImage(K)]);case 4:return[2]}})})},C.prototype.createSign=function(I,k,M){var x=I;Object.keys(k).sort().forEach(function(j){k[j]&&(x+=j+String(k[j]))}),x+=I;var $=U()(x);return M==="lower"?$:$.toLocaleUpperCase()},C.prototype.pornIdentify=function(I){return Y(this,void 0,void 0,function(){var k,M,x;return ht(this,function($){switch($.label){case 0:k=nt(nt({},I),{timestamp:Date.now()}),$.label=1;case 1:return $.trys.push([1,3,,4]),[4,T("https://"+this.uploadCtx.apiHost+"/live/inner/v3/chat/image/porn-identify",{method:"post",data:nt(nt({},k),{sign:this.createSign("polyv_chat_api_innor",k)})})];case 2:return(M=$.sent()).data?M.data.code!==200?[2,Promise.reject(new it(H.PORN_IDENTIFY_ERROR))]:[2,!0]:[2,Promise.reject(new it(H.PORN_IDENTIFY_ERROR))];case 3:return x=$.sent(),[2,Promise.reject(x)];case 4:return[2]}})})},C}();(function(C){C.WAIT_UPLOAD="waitUpload",C.UPLOADING="uploading",C.UPLOAD_SUCCESS="uploadSuccess",C.UPLOAD_FAIL="uploadFail",C.UPLOAD_FORBID="forbid"})(ot||(ot={}));var _t=function(){return(_t=Object.assign||function(C){for(var I,k=1,M=arguments.length;k<M;k++)for(var x in I=arguments[k])Object.prototype.hasOwnProperty.call(I,x)&&(C[x]=I[x]);return C}).apply(this,arguments)},It=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(ct){ct(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},ft=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ct){N=[6,ct],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},pt={width:500,height:500},kt=function(){function C(I){var k=I.callbackChange,M=k===void 0||k;this.imageId=I.imageId,this.uploadCtx=I.uploadCtx,this.file=I.file,this._status=I.status||ot.WAIT_UPLOAD,this.callbackChange=M,this.fileUrl=void 0,this.uploadProgress=void 0,this.previewSrc=L(this.file),this.uploadCtx.recordChatImage(this),this.triggerChange()}return C.prototype.upload=function(I){return I===void 0&&(I={}),It(this,void 0,void 0,function(){var k,M,x,$,j,K,Q,J,N,ct,R,G,W,X=this;return ft(this,function(st){switch(st.label){case 0:return k=this.uploadCtx,M=k.channelId,x=k.userId,$=k.bucket,this.status=ot.UPLOADING,[4,k.uploadApi.getUploadToken({channelId:M,userId:x,bucket:$})];case 1:if(j=st.sent(),!((K=this.file).size>1024*k.compressSizeLimit))return[3,5];st.label=2;case 2:return st.trys.push([2,4,,5]),[4,this.compressImage({file:this.file,fileName:this.fileName})];case 3:return Q=st.sent(),K=Q,[3,5];case 4:return st.sent(),console.warn("图片压缩失败",K,this.imageId),[3,5];case 5:return st.trys.push([5,7,,8]),[4,B(K)];case 6:return J=st.sent(),N=J.width,ct=J.height,this.size={width:N,height:ct},[3,8];case 7:return st.sent(),console.warn("获取图片尺寸失败"),[3,8];case 8:this.size||(this.size=pt),this.uploadProgress=0,R="",st.label=9;case 9:return st.trys.push([9,13,,14]),[4,k.uploadApi.uploadImage(_t(_t({},j),{file:K,fileName:this.fileName,onUploadProgress:function(At){X.uploadProgress=At,X.triggerChange()}}))];case 10:return R=st.sent(),this.fileUrl=R,k.enablePornChecking?[4,k.uploadApi.pornIdentify({channelId:M,url:"https:"+R})]:[3,12];case 11:st.sent(),st.label=12;case 12:return this.status=ot.UPLOAD_SUCCESS,[3,14];case 13:return G=st.sent(),this.status=G.failCode===H.PORN_IDENTIFY_ERROR?ot.UPLOAD_FORBID:ot.UPLOAD_FAIL,I.error,[2,Promise.reject(G)];case 14:return typeof(W=I.success)=="function"&&W(R),[2,R]}})})},C.prototype.compressImage=function(I){return It(this,void 0,void 0,function(){var k,M,x,$,j,K,Q,J,N,ct;return ft(this,function(R){switch(R.label){case 0:return k=I.file,M=I.fileName,x=I.quality,$=x===void 0?.7:x,[4,B(k)];case 1:return j=R.sent(),K=j.width,Q=j.height,J=j.imageTarget,(N=document.createElement("canvas")).setAttribute("width",""+K),N.setAttribute("height",""+Q),(ct=N.getContext("2d"))?(ct.drawImage(J,0,0,K,Q),[2,z(N.toDataURL("image/jpeg",$),M)]):[2,Promise.reject(new Error("create canvas error"))]}})})},C.prototype.triggerChange=function(){if(this.callbackChange){var I=this.uploadCtx.onChange;typeof I=="function"&&I(this)}},Object.defineProperty(C.prototype,"fileName",{get:function(){var I=V(this.file);return this.imageId+"."+(I||"png")},enumerable:!1,configurable:!0}),Object.defineProperty(C.prototype,"status",{get:function(){return this._status},set:function(I){this._status=I,this.triggerChange()},enumerable:!1,configurable:!0}),C}(),Et=function(){function C(I){this.uploadCtx=I.uploadCtx,this.uploadingList=[],this.waitQueue=[]}return C.prototype.joinWaitQueue=function(I){this.isExistQueue(I,this.waitQueue)||(this.waitQueue.push(I),this.checkQueue())},C.prototype.checkQueue=function(){var I=this;if(!(this.uploadingList.length>=this.uploadCtx.maxUploadNumber)&&this.waitQueue.length!==0)for(var k=this.uploadCtx.maxUploadNumber-this.uploadingList.length,M=function(j){var K=x.waitQueue.shift();K&&(K.upload({success:function(){I.handleImageUploadSuccess(K)}}),x.uploadingList.push(K))},x=this,$=0;$<k;$++)M()},C.prototype.handleImageUploadSuccess=function(I){this.uploadingList=this.uploadingList.filter(function(k){return k.imageId!==I.imageId}),this.checkQueue()},C.prototype.isExistQueue=function(I,k){return k.findIndex(function(M){return M.imageId===I.imageId})!==-1},C}(),Ot=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/bmp","image/tiff","image/tifa"],vt=["png","bmp","webp","tiff","tif","jpeg","jpg","gif"],gt={channelId:"",userId:"",sizeLimit:81920,compressSizeLimit:2048,limit:9,maxWidth:700,reUploadTimes:3,source:"chat_img",bucket:"liveimages",useBlobByCompress:!1,allowAccept:Ot,allowFileExtension:vt,maxUploadNumber:3,enablePornChecking:!1,apiHost:"api.polyv.net"},xt=function(C,I,k,M){return new(k||(k=Promise))(function(x,$){function j(J){try{Q(M.next(J))}catch(N){$(N)}}function K(J){try{Q(M.throw(J))}catch(N){$(N)}}function Q(J){var N;J.done?x(J.value):(N=J.value,N instanceof k?N:new k(function(ct){ct(N)})).then(j,K)}Q((M=M.apply(C,[])).next())})},q=function(C,I){var k,M,x,$,j={label:0,sent:function(){if(1&x[0])throw x[1];return x[1]},trys:[],ops:[]};return $={next:K(0),throw:K(1),return:K(2)},typeof Symbol=="function"&&($[Symbol.iterator]=function(){return this}),$;function K(Q){return function(J){return function(N){if(k)throw new TypeError("Generator is already executing.");for(;j;)try{if(k=1,M&&(x=2&N[0]?M.return:N[0]?M.throw||((x=M.return)&&x.call(M),0):M.next)&&!(x=x.call(M,N[1])).done)return x;switch(M=0,x&&(N=[2&N[0],x.value]),N[0]){case 0:case 1:x=N;break;case 4:return j.label++,{value:N[1],done:!1};case 5:j.label++,M=N[1],N=[0];continue;case 7:N=j.ops.pop(),j.trys.pop();continue;default:if(x=j.trys,!((x=x.length>0&&x[x.length-1])||N[0]!==6&&N[0]!==2)){j=0;continue}if(N[0]===3&&(!x||N[1]>x[0]&&N[1]<x[3])){j.label=N[1];break}if(N[0]===6&&j.label<x[1]){j.label=x[1],x=N;break}if(x&&j.label<x[2]){j.label=x[2],j.ops.push(N);break}x[2]&&j.ops.pop(),j.trys.pop();continue}N=I.call(C,j)}catch(ct){N=[6,ct],M=0}finally{k=x=0}if(5&N[0])throw N[1];return{value:N[0]?N[1]:void 0,done:!0}}([Q,J])}}},ut=function(){function C(I){I===void 0&&(I={});var k=I.channelId,M=k===void 0?gt.channelId:k,x=I.userId,$=x===void 0?gt.userId:x,j=I.sizeLimit,K=j===void 0?gt.sizeLimit:j,Q=I.compressSizeLimit,J=Q===void 0?gt.compressSizeLimit:Q,N=I.limit,ct=N===void 0?gt.limit:N,R=I.maxWidth,G=R===void 0?gt.maxWidth:R,W=I.reUploadTimes,X=W===void 0?gt.reUploadTimes:W,st=I.source,At=st===void 0?gt.source:st,Pt=I.bucket,Ut=Pt===void 0?gt.bucket:Pt,zt=I.useBlobByCompress,at=zt===void 0?gt.useBlobByCompress:zt,lt=I.allowAccept,bt=lt===void 0?gt.allowAccept:lt,St=I.allowFileExtension,Rt=St===void 0?gt.allowFileExtension:St,Jt=I.maxUploadNumber,Wt=Jt===void 0?gt.maxUploadNumber:Jt,ge=I.apiHost,$e=ge===void 0?gt.apiHost:ge,Ke=I.onChange,We=I.beforeStart;this.channelId=M,this.userId=$,this.sizeLimit=K,this.compressSizeLimit=J,this.limit=ct,this.maxWidth=G,this.reUploadTimes=X,this.source=At,this.bucket=Ut,this.useBlobByCompress=!!at,this.allowAccept=bt,this.allowFileExtension=Rt,this.maxUploadNumber=Wt,this.onChange=Ke,this.beforeStart=We,this.enablePornChecking=I.enablePornChecking===!0,this.apiHost=$e,this.uploadQueue=new Et({uploadCtx:this}),this.uploadApi=new dt({uploadCtx:this}),this.chatImageStore={}}return C.prototype.choiceImageFile=function(I){var k=this;I===void 0&&(I={});var M=this.getAccept(),x=document.createElement("input");return x.setAttribute("id","polyv-upload-chat-image-input-id"),x.setAttribute("type","file"),x.setAttribute("accept",M),x.setAttribute("style","visibility: hidden;position: fixed;bottom: -100%;z-index: -1;"),this.limit>1&&x.setAttribute("multiple","multiple"),x.addEventListener("change",function(){document.body.removeChild(x),I&&x.files&&x.files.length!==0&&k.handleFileList(I,x.files)}),document.body.appendChild(x),x.click(),this},C.prototype.handleFileList=function(I,k){this.beforeStart&&this.beforeStart();for(var M,x=I.fail,$=I.success,j=I.callbackChange,K=k.length<this.limit?k.length:this.limit,Q=0;Q<K;Q++){var J=k[Q],N=this.checkFile(J);if(N)return M=N,void(typeof x=="function"&&x(M))}var ct=[];for(Q=0;Q<K;Q++){J=k[Q];var R=this.buildImageId(Q),G=new kt({imageId:R,uploadCtx:this,file:J,callbackChange:j});ct.push(G)}typeof $=="function"&&$(ct)},C.prototype.getAccept=function(){var I=[];return I.push.apply(I,this.allowFileExtension.map(function(k){return"."+k})),I.push.apply(I,this.allowAccept),I.join(",")},C.prototype.joinWaitQueue=function(I){var k=this;if(Array.isArray(I))return I.forEach(function(x){k.joinWaitQueue(x)}),this;var M=void 0;return typeof I=="string"?M=this.getChatImageById(I):I instanceof kt&&(M=I),M&&this.uploadQueue.joinWaitQueue(M),this},C.prototype.getUploadImageUrl=function(){var I=this;return new Promise(function(k,M){I.choiceImageFile({callbackChange:!1,success:function(x){return xt(I,void 0,void 0,function(){var $;return q(this,function(j){switch(j.label){case 0:return[4,($=x[0]).upload()];case 1:return j.sent(),$.fileUrl?k($):M(new it(H.UPLOAD_IMAGE_ERROR)),[2]}})})},fail:function(x){M(x)}})})},C.prototype.callbackUploadImage=function(){var I=this;this.choiceImageFile({success:function(k){I.joinWaitQueue(k)}})},C.prototype.uploadImageFile=function(I){return xt(this,void 0,void 0,function(){var k;return q(this,function(M){switch(M.label){case 0:if(k=this.checkFile(I))throw new Error(k.failMessage);return[4,new kt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:!1}).upload()];case 1:return[2,M.sent()]}})})},C.prototype.uploadImage=function(I,k){return xt(this,void 0,void 0,function(){var M,x;return q(this,function($){switch($.label){case 0:if(M=this.checkFile(I))throw new Error(M.failMessage);return[4,(x=new kt({imageId:this.buildImageId(),file:I,uploadCtx:this,callbackChange:k!==!1})).upload()];case 1:return $.sent(),[2,x]}})})},C.prototype.reUploadImage=function(I){return xt(this,void 0,void 0,function(){var k,M;return q(this,function(x){switch(x.label){case 0:if(!(k=this.getChatImageById(I)))return[2,Promise.reject(new Error("图片不存在"))];x.label=1;case 1:return x.trys.push([1,3,,4]),[4,k.upload()];case 2:return x.sent(),[2,k];case 3:return M=x.sent(),[2,Promise.reject(M)];case 4:return[2]}})})},C.prototype.getChatImageById=function(I){return this.chatImageStore[I]},C.prototype.recordChatImage=function(I){this.chatImageStore[I.imageId]=I},C.prototype.checkFile=function(I){if(!I.size)return it.getFailErrorData(H.EMPTY_FILE);if(I.size>1024*this.sizeLimit)return it.getFailErrorData(H.FILE_SIZE_TOO_LARGE);if(!this.allowAccept.includes(I.type))return it.getFailErrorData(H.FILE_TYPE_NOT_ALLOW);var k=V(I);return this.allowFileExtension.includes(k)?void 0:it.getFailErrorData(H.FILE_EXTENSION_NOT_ALLOW)},C.prototype.buildImageId=function(I){var k=[];this.source&&k.push(this.source),this.channelId&&k.push(this.channelId),this.userId&&k.push(this.userId);var M=I!==void 0?"_"+I:"";return k.join("_")+"_"+Date.now()+"_"+Math.random().toString().substring(2,10)+M},C}()}]);class He extends Nt{constructor(t){super(t);mt(this,"__uploadImgCtrl");mt(this,"__svgaMap",{coffee:"coffee.svga",like:"like.svga",handclap:"handclap.svga",666:"666.svga",star:"star.svga",diamond:"diamond.svga",car:"car.svga",rocket:"rocket.svga",bear:"bear.svga",crown:"crown.svga",cup:"cup.svga",microphone:"microphone.svga",villa:"villa.svga",house:"villa.svga"});this.__uploadImgCtrl=new ze.ChatImageUpload({enablePornChecking:!0})}__setUploadImgChannelId(){return rt(this,null,function*(){const t=yield this._plvSocket.channel.getChannelInfo();this.__uploadImgCtrl.channelId=t.channelId})}uploadMultiImage(t){return rt(this,null,function*(){yield this.__setUploadImgChannelId();const e=(t==null?void 0:t.maxLimit)||9,r=typeof(t==null?void 0:t.ready)=="function"?t.ready:()=>{},n=typeof(t==null?void 0:t.success)=="function"?t.success:()=>{},i=typeof(t==null?void 0:t.fail)=="function"?t.fail:()=>{},a=[],c=[];return new Promise((f,u)=>{this.__uploadImgCtrl.choiceImageFile({callbackChange:!1,success:d=>rt(this,null,function*(){d=d.slice(0,e),yield Promise.all(d.map(v=>new Promise(y=>{const b=URL.createObjectURL(v.file),m=new Image;m.onload=()=>{v.size={width:m.width,height:m.height},URL.revokeObjectURL(b),y()},m.src=b}))),d.forEach(v=>{r({imageId:v.imageId,previewSrc:v.previewSrc||"",size:v.size})});try{for(var p=ye(d),l,h,g;l=!(h=yield p.next()).done;l=!1){const v=h.value;try{const y=yield v.upload();if(!y)throw new Error("upload Image Error");const b={imageId:v.imageId,imageUrl:y,size:v.size};a.push(b),n(b)}catch(y){const b=y,m={imageId:v.imageId,previewSrc:v.previewSrc||""};c.push(m),console.error("[util-module][uploadMultiImage] ",b.message,m),i(b,m)}}}catch(h){g=[h]}finally{try{l&&(h=p.return)&&(yield h.call(p))}finally{if(g)throw g[0]}}return f({successUploadImages:a,failUploadImages:c})}),fail:d=>{console.error("[util-module][uploadMultiImage] ",d),u(new Error(d.failMessage))}})})})}directUploadImage(t){return rt(this,null,function*(){if(!t)throw new Error("file is null");yield this.__setUploadImgChannelId();const e=yield this.__uploadImgCtrl.uploadImage(t);if(!e.fileUrl)throw new Error("upload fail");return{imageId:e.imageId,imageUrl:e.fileUrl,size:e.size}})}translateText(t){return rt(this,null,function*(){const e=this._plvSocket.getUserInfo(),r=yield this._plvSocket.polyvApi.getTokenFieldByUserType();return(yield this._plvSocket.polyvApi.post("/live/v4/channel/translate",{},{params:{query:t,viewerId:e.userId},tokenInfo:{tokenField:r}}))[0]})}__genResourceUrl(t){return`https://s1.videocc.net${t}`}getDefaultResource(){return{defaultViewerAvatar:this.__genResourceUrl("/default-img/avatar/viewer.png")}}getDefaultDonateSvgaUrl(t){return rt(this,null,function*(){const e=t.gimg,r=this.__svgaMap,n=document.createElement("a");n.href=e;const i=n.pathname.split("/"),a=i[i.length-1].split(".")[0];if(r[a])return this.__genResourceUrl(`/default-img/donate-svga/${r[a]}`)})}}class Ge{constructor(s,t={}){mt(this,"PolyvChatEvent",tt);mt(this,"ChatMsgSource",et);mt(this,"DonateType",Bt);mt(this,"RedpackType",Zt);mt(this,"SystemMsgType",qt);mt(this,"ChatRequestHistoryMode",Ht);mt(this,"ManageFailReason",wt);mt(this,"TranslateLanguage",re);mt(this,"QuickReplyType",Qt);mt(this,"EmotionalFeedbackType",ee);mt(this,"eventEmitter",new Vt);mt(this,"__socketFilter");mt(this,"__socketHandler");mt(this,"emotion");mt(this,"history");mt(this,"message");mt(this,"status");mt(this,"utils");mt(this,"sender");mt(this,"manage");mt(this,"online");mt(this,"download");mt(this,"like");mt(this,"ask");mt(this,"emotionalFeedback");mt(this,"file");mt(this,"setuped",!1);this.plvSocket=s,this.config=t,this.emotion=new Me(this),this.history=new Pe(this),this.message=new Ue(this),this.status=new Be(this),this.utils=new He(this),this.sender=new De(this),this.manage=new je(this),this.online=new Fe(this),this.download=new Te(this),this.like=new Le(this),this.ask=new ke(this),this.emotionalFeedback=new Ae(this),this.file=new Re(this),this.__socketFilter=new we(this),this.__socketHandler=new xe(this)}setup(){return rt(this,null,function*(){this.setuped=!0})}destroy(){return rt(this,null,function*(){this.plvSocket.clearSocketHandles(Tt)})}}const Ve="PolyvChat";yt.ChatMsgSource=et,yt.ChatRequestHistoryMode=Ht,yt.DonateType=Bt,yt.EmotionalFeedbackType=ee,yt.GlobalVariable=Ve,yt.ManageFailReason=wt,yt.MotivationLikeType=te,yt.PolyvChat=Ge,yt.PolyvChatEvent=tt,yt.QuickReplyType=Qt,yt.RedpackType=Zt,yt.SystemMsgType=qt,yt.TranslateLanguage=re,yt.canQuoteMsgSource=he,yt.canTopMsgSource=de,yt.isServiceMsgMap=pe,Object.defineProperty(yt,Symbol.toStringTag,{value:"Module"})});console.log("%c@polyv/chat","background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff","[version: 2.7.0-rc-20260312.1]","[buildTime: 2026-03-11 03:19:43]");
|