trtc-sdk-v5
Version:
Tencent Cloud RTC SDK for Web
4 lines (3 loc) • 8.03 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Watermark=t()}(this,function(){"use strict";function e(e,t,r,n,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,o)}function t(t){return function(){var r=this,n=arguments;return new Promise(function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)})}}function r(e,t,r){return t&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,i(n.key),n)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function n(){
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
var e,t,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",a=r.toStringTag||"@@toStringTag";function u(r,n,i,a){var u=n&&n.prototype instanceof s?n:s,f=Object.create(u.prototype);return o(f,"_invoke",function(r,n,o){var i,a,u,s=0,f=o||[],l=!1,p={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(t,r){return i=t,a=0,u=e,p.n=r,c}};function h(r,n){for(a=r,u=n,t=0;!l&&s&&!o&&t<f.length;t++){var o,i=f[t],h=p.p,m=i[2];r>3?(o=m===n)&&(u=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=h&&((o=r<2&&h<i[1])?(a=0,p.v=n,p.n=i[1]):h<m&&(o=r<3||i[0]>n||n>m)&&(i[4]=r,i[5]=n,p.n=m,a=0))}if(o||r>1)return c;throw l=!0,n}return function(o,f,m){if(s>1)throw TypeError("Generator is already running");for(l&&1===f&&h(f,m),a=f,u=m;(t=a<2?e:u)||!l;){i||(a?a<3?(a>1&&(p.n=-1),h(a,u)):p.n=u:p.v=u);try{if(s=2,i){if(a||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=e}else if((t=(l=p.n<0)?u:r.call(n,p))!==c)break}catch(t){i=e,a=1,u=t}finally{s=1}}return{value:t,done:l}}}(r,i,a),!0),f}var c={};function s(){}function f(){}function l(){}t=Object.getPrototypeOf;var p=[][i]?t(t([][i]())):(o(t={},i,function(){return this}),t),h=l.prototype=s.prototype=Object.create(p);function m(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,o(e,a,"GeneratorFunction")),e.prototype=Object.create(h),e}return f.prototype=l,o(h,"constructor",l),o(l,"constructor",f),f.displayName="GeneratorFunction",o(l,a,"GeneratorFunction"),o(h),o(h,a,"Generator"),o(h,i,function(){return this}),o(h,"toString",function(){return"[object Generator]"}),(n=function(){return{w:u,m:m}})()}function o(e,t,r,n){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}o=function(e,t,r,n){function a(t,r){o(e,t,function(e){return this._invoke(t,r,e)})}t?i?i(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(a("next",0),a("throw",1),a("return",2))},o(e,t,r,n)}function i(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:t+""}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}var u=Object.defineProperty,c=function(e,t,r){return function(e,t,r){return t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r}(e,"symbol"!==a(t)?t+"":t,r)};function s(e){return{name:"WatermarkOptions",type:"object",required:!0,allowEmpty:!1,properties:{imageUrl:{required:!0,type:"string"},x:{required:!1,type:"number"},y:{required:!1,type:"number"},size:{required:!1,type:["string","object","number"]}},validate:function(t,r,n,o){var i,a=e.errorModule,u=a.RtcError,c=a.ErrorCode,s=a.ErrorCodeDictionary;if(t){var f=t.imageUrl.split("?")[0].split(".").pop();if("jpg"!==f&&"jpeg"!==f||e.log.warn("The image format is not recommended to be jpg/jpeg, because the format does not support transparency."),!(null==(i=e.room.videoManager.cameraTrack)?void 0:i.mediaTrack))throw new u({code:c.INVALID_OPERATION,extraCode:s.INVALID_OPERATION_NEED_VIDEO,fnName:n});if(e.utils.isString(t.size)&&"contain"!==t.size&&"cover"!==t.size)throw new u({code:c.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The size parameter must be 'contain' or 'cover'",fnName:n});if(e.utils.isNumber(t.size)&&(t.size<=0||t.size>1))throw new u({code:c.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:n});if(e.utils.isObject(t.size)){if(!t.size.width||!t.size.height)throw new u({code:c.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_TYPE,message:"The size parameter must be an object with width and height properties",fnName:n});if(t.size.width<=0||t.size.height<=0)throw new u({code:c.INVALID_PARAMETER,extraCode:s.INVALID_PARAMETER_RANGE,message:"The size parameter must be greater than 0",fnName:n})}}}}}var f=0,l=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.core=t,c(this,"seq"),c(this,"_core"),c(this,"log"),c(this,"startResolve"),c(this,"startReject"),f+=1,this.seq=f,this._core=t,this.log=t.log.createChild({id:"".concat(this.getAlias()).concat(f)}),this.log.info("created")}return r(e,[{key:"getName",value:function(){return e.Name}},{key:"getAlias",value:function(){return"w"}},{key:"getValidateRule",value:function(e){switch(e){case"start":case"update":return s(this._core);case"stop":return this._core,{name:"StopWatermarkOptions",required:!1}}}},{key:"getGroup",value:function(){return"w"}},{key:"start",value:(l=t(n().m(function e(t){return n().w(function(e){for(;;)if(0===e.n)return e.a(2,this.doStart(t))},e,this)})),function(e){return l.apply(this,arguments)})},{key:"update",value:(u=t(n().m(function e(t){return n().w(function(e){for(;;)switch(e.n){case 0:this.doStart(t);case 1:return e.a(2)}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"stop",value:(a=t(n().m(function e(){return n().w(function(e){for(;;)if(0===e.n)return e.a(2,this._core.room.videoManager.deleteWatermark())},e,this)})),function(){return a.apply(this,arguments)})},{key:"doStart",value:(i=t(n().m(function e(t){var r,o,i,a,u;return n().w(function(e){for(;;)switch(e.n){case 0:return r=t.x,o=void 0===r?0:r,i=t.y,a=void 0===i?0:i,e.n=1,this.processWatermark(t);case 1:return u=e.v,e.a(2,this._core.room.videoManager.setWatermark({x:o,y:a,imageUrl:u}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"processWatermark",value:(o=t(n().m(function e(t){var r,o,i,a,u,c,s,f,l,p,h,m,d,y,v,g,b,w,E,A,_,T,R,I,N,j;return n().w(function(e){for(;;)switch(e.p=e.n){case 0:return r=t.imageUrl,o=t.x,i=void 0===o?0:o,a=t.y,u=void 0===a?0:a,c=t.size,s=void 0===c?"cover":c,f=this._core.room.videoManager.cameraTrack,l=f.settings,p=f.rotation,e.p=1,e.n=2,this._core.utils.loadImage(r);case 2:h=e.v,e.n=4;break;case 3:throw e.p=3,e.v,m=this.core.errorModule,d=m.RtcError,y=m.ErrorCode,new d({code:y.INVALID_PARAMETER,message:"load image failed, url: ".concat(r)});case 4:return v=l.width,g=l.height,w=(b=h).width,E=b.height,this._core.utils.isRotate90Or270(p)&&(v=(A=[g,v])[0],g=A[1]),_=w,T=E,this._core.utils.isObject(s)&&(_=(null==s?void 0:s.width)||_,T=(null==s?void 0:s.height)||T),this._core.utils.isNumber(s)&&(_=w*s,T=E*s),I=(R=w/E)>v/g,"contain"===s&&(I?(_=v,T=v/R):(_=g*R,T=g)),"cover"===s&&(I?(T=g,_=g*R):(_=v,T=v/R)),N=document.createElement("canvas"),j=N.getContext("2d"),N.width=Math.min(v-i,_),N.height=Math.min(g-u,T),null==j||j.drawImage(h,0,0,_,T),e.a(2,N.toDataURL("image/png"))}},e,this,[[1,3]])})),function(e){return o.apply(this,arguments)})}]);var o,i,a,u,l}();return c(l,"Name","Watermark"),l});