UNPKG

zego-express-engine-webrtc

Version:

zego webrtc express sdk

1 lines 26.6 kB
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("long"),require("protobufjs/minimal"));else if("function"==typeof define&&define.amd)define(["long","protobufjs/minimal"],t);else{var r="object"==typeof exports?t(require("long"),require("protobufjs/minimal")):t(e.long,e["protobufjs/minimal"]);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}("undefined"!=typeof self?self:this,(function(e,t){return function(){"use strict";var r={1290:function(e,t,r){r.d(t,{RnN:function(){return u},nkr:function(){return i},v$W:function(){return n},zUi:function(){return o},zub:function(){return s}});var n="zc.crh.a.0",i="zc.ctcc.a.0",o="zc.hrh.smt.0",s="zc.hrh.smt.1",u="zc.hrh.grdbc"},4908:function(e,t,r){r.d(t,{Of:function(){return s},iJ:function(){return u},ns:function(){return c},pO:function(){return o}});var n=r(8627),i=r(5095),o={event:"/sdk/start_publish",error:{t:n.LLz,i:n.Q9p,u:n.xfZ,l:n.gSF,m:n.PA0,p:n.fzq,v:n.f43,_:n.qvY,k:n.S4u,S:n.SRE,q:n.Xxx,O:n.g9p,P:n.jZ$,j:n.$wo,N:n.SmZ,C:n.VU9,D:n.MrD,T:n.ZpF,R:n.iei,J:n.aa2,B:n.HCP,U:n.dg1,Z:n._68,F:n.kbF,W:n.kOd,K:n.WP4,X:n.JDv,G:n.Q3v,V:n.RBR,Y:n.NCg,ee:n.xbZ,te:n.OdW,re:n.sJH,ne:n.MrS},urls:i.yp,is_center:i.yS,server_url:i.tK,publish_option:i.Gq,message:i.tK,stream_id:i.tK,stream_sid:i.Tr,room_id:i.tK,video_en_codec_id:i.Tr,cap_w:i.Tr,cap_h:i.Tr,w:i.Tr,h:i.Tr,video_en_fps:i.Tr,video_en_bps:i.Tr,audio_c_channel_count:i.Tr,audio_en_bps:i.Tr,aec_level:i.Tr,ans_level:i.Tr,agc:i.yS,traffic_control_min_video_bitrate:{bitrate:i.Tr,mode:i.Tr},cap_volume:i.Tr,enable_camera:i.yS,enable_mic:i.yS,video_activate:i.yS,audio_activate:i.yS,gw_version:i.Tr,use_na:i.Tr,is_dual_stream:i.Tr,is_mini:i.yS,is_peer:i.yS},s={event:"/sdk/publish_target",error:{ie:n.ZEp,oe:n.xU2,se:n.S4u,ue:n.I7C,ce:n.HO9,ae:n.aUw,fe:n.Oy0}},u={event:"/mss/pushadd",error:{ie:n.ZEp},stream_id:i.tK,url:i.tK},c={event:"/mss/pushdel",error:{ie:n.ZEp},stream_id:i.tK,url:i.tK}},5095:function(e,t,r){r.d(t,{Gq:function(){return n},Tr:function(){return s},tK:function(){return i},yS:function(){return u},yp:function(){return o}});var n=function(e){return e},i=function(e){return e},o=function(e){return e},s=function(e){return e},u=function(e){return e}},8627:function(e,t,r){r.d(t,{$wo:function(){return B},Arx:function(){return we},B3d:function(){return _e},Be2:function(){return ie},FB3:function(){return K},HCP:function(){return F},HO9:function(){return v},I4J:function(){return De},I7C:function(){return re},J79:function(){return c},JDv:function(){return se},JSm:function(){return oe},L8E:function(){return A},LLz:function(){return q},MK1:function(){return le},MrD:function(){return Y},MrS:function(){return E},MuX:function(){return Ce},NCg:function(){return Je},OdW:function(){return Te},OrZ:function(){return O},Oy0:function(){return l},PA0:function(){return a},PTE:function(){return w},Q3v:function(){return ue},Q9p:function(){return h},RBR:function(){return ae},RZs:function(){return je},RfS:function(){return Z},S4u:function(){return o},S5f:function(){return f},SB8:function(){return ke},SRE:function(){return W},SmZ:function(){return D},T_8:function(){return de},Tij:function(){return Ee},V2t:function(){return S},VU9:function(){return T},WP4:function(){return V},XHx:function(){return ze},Xxx:function(){return y},ZEp:function(){return d},ZpF:function(){return C},Zws:function(){return be},_68:function(){return R},_HD:function(){return m},aUw:function(){return b},aa2:function(){return J},ann:function(){return he},b1q:function(){return Pe},cMG:function(){return Ne},ckD:function(){return Me},ckg:function(){return Ie},clM:function(){return s},d49:function(){return u},dXc:function(){return Oe},dg1:function(){return M},dqB:function(){return me},ekj:function(){return ye},f43:function(){return U},fzq:function(){return H},g9p:function(){return g},gHA:function(){return pe},gSF:function(){return p},hYx:function(){return $e},hje:function(){return ve},iei:function(){return $},jZ$:function(){return I},jut:function(){return j},kOd:function(){return Q},kbF:function(){return G},lgu:function(){return Se},m6U:function(){return te},mrK:function(){return ee},pWJ:function(){return xe},qvY:function(){return ce},rBJ:function(){return Re},sJH:function(){return N},sVF:function(){return k},s_m:function(){return P},t85:function(){return L},wxm:function(){return ge},xU2:function(){return X},xbZ:function(){return fe},xfZ:function(){return _},yK:function(){return x},yTe:function(){return z},zML:function(){return qe},zs3:function(){return ne}});var n=r(8866),i="the user cancels the stream request.",o={code:1000002,message:"not login room"},s={code:1000014,message:"stream ID is too long"},u={code:1000015,message:"streamID is empty"},c={code:1000016,message:"stream ID contains illegal characters"},a={code:1000017,message:n.Rl},f={code:1000018,message:n.qC},d={code:1100001,message:n.dO},h={code:1100002,message:"network timeout."},l={code:1100999,message:"unknown server error"},m={code:1101005,message:"signal hb fail"},p={code:1102017,message:"dispatch error"},g={code:1102018,message:"token expired"},v={code:1102021,message:"biz channel error."},_={code:1102022,message:"dispatch request timeout"},b={code:1102024,message:"invalid channel"},k={code:1102026,msg:n.fT},y={code:1003025,message:"stream is forbided by media server"},z={code:1003040,message:"Pushing CDN status failed. It may be an error in the CDN url"},w={code:1003050,message:"the extra info of the stream is null"},S={code:1003051,message:"the extra info of the stream is too long"},E={code:1003080,message:"browser does not support the codec"},q={code:1103001,message:n.dO},O={code:1103002,message:"browser do not support"},x={code:1103010,message:"screen fail"},P={code:1103011,message:"enumerate devices fail"},j={code:1103012,message:"use camera device fail"},N={code:1103019,message:"publish streams auth fail"},C={code:1103021,message:"session request fail"},D={code:1103022,message:"create offer error"},T={code:1103023,message:"setLocalDescription error"},M={code:1103024,message:"mediaDesc error"},$={code:1103025,message:"other side offer error"},R={code:1103026,message:"candidate error"},I={code:1103027,message:"server session closed"},J={code:1103028,message:"ice connection error"},B={code:1103030,message:"negotiation timeout"},L={code:1103042,message:"screen canceled"},A={code:1103043,message:"screen not support"},H={code:1103044,message:n.aw},U={code:1103099,message:"stream is not capturing"},Z={code:1103049,message:"repeated pull same stream"},F={code:1103050,message:"websocket disconnected"},W={code:1103051,message:"publisher retry timeout"},K={code:1103053,message:"https is required"},X={code:1103055,message:n.Wk},G={code:1103056,message:"publish is publishing"},Q={code:1103058,message:"client ip changed"},V={code:1103059,message:"ttl over time"},Y={code:1103060,message:"session request timeout"},ee={code:1103061,message:"get media fail"},te={code:1103062,message:"update stream info fail"},re={code:1103063,message:"publish target no response"},ne={code:1103064,message:"get device not allowed"},ie={code:1103065,message:"device is not readable"},oe={code:1103066,message:"device does not meet constraints"},se={code:1103067,message:"update sdp time out"},ue={code:1103068,message:"update sdp fail"},ce={code:1103073,message:"video effect is starting, please operate after video effect is started"},ae={code:1103078,message:"publish stream poor and net probe poor"},fe={code:1103089,message:i},de={code:1004099,message:"internal exeception"},he={code:1104001,message:"input parm error"},le={code:1104021,message:"session request fail"},me={code:1104022,message:"create offer error"},pe={code:1104023,message:"setLocalDescription error"},ge={code:1104024,message:"mediaDesc error"},ve={code:1104025,message:"other side offer error"},_e={code:1104026,message:"candidate error"},be={code:1104028,message:"ice connection error"},ke={code:1104029,message:"websocket disconnected"},ye={code:1104030,message:"negotiation timeout"},ze={code:1104031,message:"player retry timeout"},we={code:1104032,message:"player is playing"},Se={code:1104033,message:"client ip changed"},Ee={code:1104034,message:"ttl is over time"},qe={code:1104035,message:"reset session push"},Oe={code:1104036,message:"session request timeout"},xe={code:1104037,message:"probe time out"},Pe={code:1104038,message:"resource mode is not supported"},je={code:1104039,message:"play stream not found"},Ne={code:1004020,message:"play stream interrupted"},Ce={code:1104041,message:"stream quality poor and net probe poor"},De={code:1104042,message:i},Te={code:1104043,message:"mini sdp error"},Me={code:1104045,message:"play streams is out limit"},$e={code:1104046,message:"play streams auth fail"},Re={code:1103052,message:"publisher cdn push error"},Ie={code:1103048,message:n.pt},Je={code:1103100,message:"background process is start, but not subscribe yet"}},8866:function(e,t,r){r.d(t,{Rl:function(){return d},UY:function(){return h},Wk:function(){return f},aw:function(){return s},dO:function(){return u},fT:function(){return i},h2:function(){return a},l3:function(){return n},pt:function(){return o},qC:function(){return c}});r(7202),r(8627);var n=Promise;var i="room not exist",o="device is not found",s="stream is not from zego",u="input param error",c="local stream wrong",a="no preview",f="publish stream no found",d="network is broken";var h=function(){return new Promise((function(e,t){e(Math.random())}))}},7202:function(e,t,r){var n=r(6994);t.A=n.default||n},4872:function(e,t,r){function n(e){return"string"==typeof e}r.d(t,{QP:function(){return n}})},6994:function(t){t.exports=e},3788:function(e){e.exports=t}},n={};function i(e){var t=n[e];if(void 0!==t)return t.exports;var o=n[e]={exports:{}};return r[e](o,o.exports,i),o.exports}i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,{a:t}),t},i.d=function(e,t){for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};i.r(o),i.d(o,{StreamCDN:function(){return J}});var s,u=i(8627),c=i(4908),a=i(4872),f=i(1290),d=i(8866),h=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function u(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}c((n=n.apply(e,t||[])).next())}))},l=function(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(c){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,n=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){s.label=u[1];break}if(6===u[0]&&s.label<i[1]){s.label=i[1],i=u;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(u);break}i[2]&&s.ops.pop(),s.trys.pop();continue}u=t.call(e,s)}catch(e){u=[6,e],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},m=function(){function e(e,t){this.de=e,this.he=t,this.attempt=0,this.le=.3,this.me=4.8,this.pe=0,this.retryTimer=null,this.maxTimer=null,this.isOverTime=!1,this.RETRY_MAX_TIME=60}return e.prototype.setRetryRule=function(e){switch(this.pe=e,e){case 1:this.le=.3,this.me=32;break;case 0:this.le=.3,this.me=4.8}},e.prototype.getRetryDelayByCount=function(e){return h(this,void 0,void 0,(function(){var t,r,n,i;return l(this,(function(o){switch(o.label){case 0:return t=1===this.pe?e+2:e<2?0:e,r=Math.min(this.me,this.le*Math.pow(2,t)),[4,(0,d.UY)()];case 1:return n=o.sent(),i=Math.floor(n*(1e3*r+1)),this.de.info("".concat(f.RnN," ").concat(this.attempt," ").concat(r," ").concat(i)),[2,i]}}))}))},e.prototype.initCallback=function(e,t){this.sucCallBack=e,this.failCallBack=t},e.prototype.startMaxTime=function(){var e,t=this;this.de.info("".concat(f.zUi," ").concat(null===(e=this.requestInfo)||void 0===e?void 0:e.streamID," call")),this.maxTimer?this.de.warn("".concat(f.zUi," max timer")):(this.maxTimer=setTimeout((function(){var e;t.de.warn("".concat(f.zUi," ").concat(null===(e=t.requestInfo)||void 0===e?void 0:e.streamID," over max time ").concat(t.RETRY_MAX_TIME,"s, stop retry")),t.isOverTime=!0,t.requestFail(t._err)}),1e3*this.RETRY_MAX_TIME),this.de.info("".concat(f.zUi," maxTimer=").concat(this.maxTimer)))},e.prototype.invalid=function(){this.clearRetryTimer(),this.attempt=0},e.prototype.clearRetryTimer=function(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)},e.prototype.requestFail=function(e){this.invalid(),this.stopMaxTime(),this.failCallBack&&(this.failCallBack(e),this.resetCallback())},e.prototype.stopMaxTime=function(){this.de.info("".concat(f.zub," stop max timer")),this.maxTimer&&clearTimeout(this.maxTimer),this.maxTimer=null},e.prototype.resetCallback=function(){this.sucCallBack=void 0,this.failCallBack=void 0},e}(),p=(s=function(e,t){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},s(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),g=function(e){function t(t,r,n){var i=e.call(this,t,r)||this;return i.de=t,i.he=r,i.ge=n,i.RETRY_MAX_TIME=8,i}return p(t,e),t.prototype.initReqParams=function(e,t){this.streamId=e,this.cdnPushConfig=t},t.prototype.active=function(e){var t=this;if(void 0===e&&(e=!1),this.retryTimer)this.de.warn("".concat(f.v$W," was actived, ignore"));else if(this.isOverTime)this.de.warn("".concat(f.v$W," retry over time, stop retry"));else{var r=function(){t.clearRetryTimer(),t.ge.sendCDNRequest(t.streamId,t.cdnPushConfig,(function(e,r){var n=e.body;t.invalid(),t.stopMaxTime(),t.sucCallBack&&(t.sucCallBack&&t.sucCallBack(n,r),t.resetCallback())}),(function(e){t._err=e;var r=e.status_code;t.isOverTime?t.requestFail(e):((429===r||r>=500&&r<600)&&t.setRetryRule(1),t.active())})),e||t.attempt++};e?r():this.getRetryDelayByCount(this.attempt).then((function(e){t.retryTimer=setTimeout(r,e)}))}},t}(m),v=i(3788);const _=i(6994);(v=v.default||v).util.Long=_.default||_,v.util.Long.fromBits=v.util.Long.fromBits||function(){return 0};for(var b=v.roots,k=v.types?v.types.basic:{double:1,float:5,int32:0,uint32:0,sint32:0,fixed32:5,sfixed32:5,int64:0,uint64:0,sint64:0,fixed64:1,sfixed64:1,bool:0,string:2,bytes:2},y=v.types?v.types.packed:{double:1,float:5,int32:0,uint32:0,sint32:0,fixed32:5,sfixed32:5,int64:0,uint64:0,sint64:0,fixed64:1,sfixed64:1,bool:0},z=Object.keys(k),w={$:function(e){return w[e]?w[e].call(this):b[e].decode?b[e].decode(this,this.uint32()):w.$.call(this,"int32")}},S={$:function(e,t,r){var n=k[e];return void 0===n?b[e].encode?(this.uint32(r<<3|2).fork(),b[e].encode(t,this).ldelim()):S.$.call(this,"int32",t,r):S[e].call(this.uint32(r<<3|n),t)}},E=0;E<z.length;E++)w[z[E]]=v.Reader.prototype[z[E]],S[z[E]]=v.Writer.prototype[z[E]];!function e(t,r,n,i){for(var o=0,s=Object.keys(t);o<s.length;o++){var u=s[o];if(t[u].$m&&Object.keys(t[u].$m).every((function(e){return Number(e)}))){if(n[u])throw Error(`nested type ${n}.${u} has already exist`);n[u]=function(t,n){function i(e){for(var r in t){var n=t[r];"{"===n[1].charAt(0)?this[n[0]]={}:"["!==n[1].charAt(0)&&"<"!==n[1].charAt(0)||(this[n[0]]=[])}if(e)for(var i=Object.keys(e),o=0;o<i.length;++o)null!=e[i[o]]&&(this[i[o]]=e[i[o]])}var o={};for(var s in t){var u=t[s],c=u[1];"{"===c.charAt(0)?(i.prototype[u[0]]=v.util.emptyObject,o[c]={$m:c.substring(1).split(",").map((function(e,t){return[`$${t+1}`,e,null]})).reduce((function(e,t,r){return e[r+1]=t,e}),{})}):i.prototype[u[0]]="["===c.charAt(0)||"<"===c.charAt(0)?v.util.emptyArray:"bytes"===c?v.util.newBuffer([]):u[2]&&u[2].hasOwnProperty("low")&&u[2].hasOwnProperty("high")?v.util.Long.fromBits(u[2].low,u[2].high,u[2].unsigned):u[2]}return i.create=function(e){return new i(e)},i.decode=function(e,r){e instanceof v.Reader||(e=v.Reader.create(e));for(var n=void 0===r?e.len:e.pos+r,o=new i;e.pos<n;){var s=e.uint32(),u=s>>>3;if(u>0&&t[u]){var c=t[u][0],a=t[u][1];if("{"===a.charAt(0)){o[c]===v.util.emptyObject&&(o[c]={});var f=i.$namespace[a].decode(e,e.uint32());o[c][f.$1]=f.$2}else if("["===a.charAt(0)||"<"===a.charAt(0)){a=a.substring(1),o[c]&&o[c].length||(o[c]=[]);if(void 0!==y[a=!w[a]&&!b[a].decode?"int32":a]&&2==(7&s))for(var d=e.uint32()+e.pos;e.pos<d;)o[c].push(w.$.call(e,a));else o[c].push(w.$.call(e,a))}else o[c]=w.$.call(e,a)}else e.skipType(7&s)}return o},i.encode=function(e,r){for(var n in r||(r=v.Writer.create()),t){var o=t[n][0],s=t[n][1];if("{"===s.charAt(0)){if(null!=e[o]&&e.hasOwnProperty(o))for(var u=0,c=Object.keys(e[o]);u<c.length;++u)r.uint32(n<<3|2).fork(),i.$namespace[s].encode({$1:c[u],$2:e[o][c[u]]},r).ldelim()}else if("["===s.charAt(0)||"<"===s.charAt(0)){var a="<"===s.charAt(0);s=s.substring(1);var f=e[o];if(null!=f&&f.length){if(s=void 0===k[s]&&!b[s].encode?"int32":s,a&&void 0!==y[s]){r.uint32(n<<3|2).fork();for(u=0;u<f.length;u++)S[s].call(r,f[u]);r.ldelim()}else for(u=0;u<f.length;u++)S.$.call(r,s,f[u],n)}}else null!=e[o]&&e.hasOwnProperty(o)&&S.$.call(r,s,e[o],n)}return r},Object.keys(o).length&&(i.$namespace=e(o,r+"."+n,i.$namespace||{},!0)),i}(t[u].$m,u)}else t[u].$s?n[u]=function(e,t){function n(e,t,r){v.rpc.Service.call(this,e,t,r)}return(n.prototype=Object.create(v.rpc.Service.prototype)).constructor=n,n.create=function(e,t,r){return new n(e,t,r)},Object.keys(e).forEach((function(i){var o=e[i];function s(e,t){return this.rpcCall(s,b[o[0]],b[o[1]],e,t)}Object.defineProperty(s,"name",{value:i}),Object.defineProperty(s,"path",{value:`${r}.${t}`}),n.prototype[i]=s})),n}(t[u].$s,u):t[u].$e&&Object.values(t[u].$e).every((function(e){return Number(e)===e}))&&(n[u]=function(e){for(var t=Object.keys(e),r={},n=0;n<t.length;n++)r[r[t[n]]=e[t[n]]]=t[n];return r}(t[u].$e));n[u]&&!i&&(b[`${r}.${u}`]=n[u]),delete t[u].$m,delete t[u].$s,delete t[u].$e,n[u]=e(t[u],Boolean(r)?`${r}.${u}`:u,n[u]||{})}return n}({media:{proto_media:{MediaServerCommonResponse:{$m:{1:["code","uint32",0],2:["message","string",""]}},NotifySdkNeedStreamRequest:{$m:{1:["request_seq","uint32",0],2:["stream_id","string",""],3:["playAddr","string",""],4:["transCodecId","int32",0],5:["transCodecSuffix","string",""],6:["cdnType","int32",0],7:["retry","int32",0]}},NotifySdkNeedStreamResponse:{$m:{1:["request_seq","uint32",0],2:["response","media.proto_media.MediaServerCommonResponse",null],3:["transCodecSuffix","string",""],4:["action","int32",0],5:["action_delay","int32",0],6:["ttl","int32",0]}},RelayPublishCdnRequest:{$m:{1:["request_seq","uint32",0],2:["request_cmd","int32",0],3:["streamid","string",""],4:["cdn_server","string",""],5:["publish_timeout","uint32",0],6:["request_seq_v2","uint64",{low:0,high:0,unsigned:!0}]}},RelayPublishCdnResponse:{$m:{1:["request_seq","uint32",0],2:["response","media.proto_media.MediaServerCommonResponse",null],3:["request_seq_v2","uint64",{low:0,high:0,unsigned:!0}]}}}}},"",b,!1);var q=b.media,O=i(3788),x=i.n(O),P=i(7202);x().util.Long=P.A,x().configure();var j,N,C=q.proto_media,D=function(){function e(){}return e.prototype.encodeRelayPublishCdnReq=function(e){var t=C.RelayPublishCdnRequest.create(e);return C.RelayPublishCdnRequest.encode(t).finish()},e.prototype.decodeRelayPublishCdnRsp=function(e){var t=C.RelayPublishCdnResponse.decode(e);return t.request_seq_v2&&P.A.isLong(t.request_seq_v2)&&(t.request_seq_v2=t.request_seq_v2.toNumber()),t},e.prototype.encodeNotifySdkNeedStreamReq=function(e){var t=C.NotifySdkNeedStreamRequest.create(e);return C.NotifySdkNeedStreamRequest.encode(t).finish()},e.prototype.decodeNotifySdkNeedStreamRsp=function(e){return C.NotifySdkNeedStreamResponse.decode(e)},e}(),T=function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),M=function(e){function t(t,r,n){var i=e.call(this,t,r)||this;return i.de=t,i.he=r,i.ge=n,i.RETRY_MAX_TIME=90,i}return T(t,e),t.prototype.initReqParams=function(e,t){this.streamID=e,this.transCodecConfig=t},t.prototype.active=function(e){var t=this;if(void 0===e&&(e=!1),this.de.info("".concat(f.nkr," call")),this.retryTimer)this.de.warn("".concat(f.nkr," was active, ignore"));else if(this.isOverTime)this.de.warn("".concat(f.nkr," retry over time, stop retry"));else{var r=function(){t.clearRetryTimer(),t.ge.sendNotifySdkNeedStreamHttpRes(t.streamID,t.transCodecConfig,(function(e,r){var n=e.body;t.invalid(),t.stopMaxTime(),t.sucCallBack&&(t.sucCallBack&&t.sucCallBack(n,r),t.resetCallback())}),(function(e){t._err=e;var r=e.status_code;t.isOverTime?t.requestFail(e):((429===r||r>=500&&r<600)&&t.setRetryRule(1),t.active())})),e||t.attempt++};e?r():this.getRetryDelayByCount(this.attempt).then((function(e){t.retryTimer=setTimeout(r,e)}))}},t}(m);(N=j||(j={}))[N.I=0]="I",N[N.H=10]="H",N[N.M=100]="M",N[N.L=1e3]="L";var $={},R={_sendCDNPublishByAccessHub:function(e,t,r,n){var i=this;this.mediaProtoBuf||(this.mediaProtoBuf=new D);var o=new g(this.logger,this.stateCenter,this);o.initReqParams(e,t);var s=function(e,t){try{var r=i.mediaProtoBuf.decodeRelayPublishCdnRsp(e);i.logger.info("zb.sh.pt rsp decode ".concat(JSON.stringify(r)));var n=(null==r?void 0:r.response)||{};return{code:n.code,msg:n.message}}catch(e){return{code:-1}}};o.initCallback((function(e,o){var c=s(e),a=c.code,f=c.msg;a&&0!=a?(i.logger.error("zb.sh.pt "+t.type+" error code: "+a+" "+f),n(5004===a?u.yTe:u.Oy0," cmd: ".concat(t.type," ").concat(a," ").concat(f))):(i.logger.info("zb.sh.pt "+t.type+" success"),r&&r({errorCode:0,extendedData:""}))}),(function(e){var r=e.status_code,o=e.body,u=e.code,f=e.msg,d=JSON.parse(JSON.stringify(c.Of.error.fe)),h="";if(u)d={code:u,msg:f},h=f;else if(200===r)i.logger.info("zb.sh.pt error: "),d=c.Of.error.fe,h="cmd: ".concat(t.type);else{var l="";if((0,a.QP)(o))l=o;else{var m=s(o);l=m.code+" "+m.msg}h="request media server fail, error: "+r+" "+l}i.logger.error("zb.sh.pt "+h),n&&n(d,h)})),o.startMaxTime(),o.active(!0)},sendCDNRequest:function(e,t,r,n){var i=this,o="addpush"===t.type?1:2,s={request_seq:this.stateCenter.cdnSeq++,request_cmd:o,streamid:e,cdn_server:t.pushUrl,request_seq_v2:this.stateCenter.cdnSeqV2++};this.logger.info("zb.sh.scpba "+JSON.stringify(s));var u=this.mediaProtoBuf.encodeRelayPublishCdnReq(s);this.sendHttpPBRequest({interfaceID:6,resID:this.stateCenter.appid+"/"+e},u,(function(e,t){i.logger.info("zb.sh.pt receive message "+(null==e?void 0:e.status_code)),r&&r(e,t)}),(function(e){n&&n(e)}),{timeout:4e3})},_publishTarget:function(e,t,r){this.logger.info("zb.sh.pt call");var n=e.streamID;this.stateCenter.testEnvironment&&(n="zegotest-"+this.stateCenter.appid+"-"+e.streamID),this._sendCDNPublishByAccessHub(n,e,t,r)},notifySdkNeedStream:function(e,t,r,n){var i=this;this.mediaProtoBuf||(this.mediaProtoBuf=new D);var o=new M(this.logger,this.stateCenter,this);return o.initReqParams(e,t),o.initCallback((function(e){try{var t=i.mediaProtoBuf.decodeNotifySdkNeedStreamRsp(e);i.logger.info("zb.sh.nsns receive message:"+JSON.stringify(t));var o=(null==t?void 0:t.response)||{},s=o.code;s&&0!=s?n({code:s,message:o.message||""},t):r&&r(t)}catch(e){e({code:-1})}}),(function(e){i.logger.error("zb.sh.nsns err:"+JSON.stringify(e)),n&&n(e)})),o.startMaxTime(),o.active(!0),o},sendNotifySdkNeedStreamHttpRes:function(e,t,r,n){this.mediaProtoBuf||(this.mediaProtoBuf=new D);var i=t.playAddr,o=t.transCodecID,s=t.transCodecSuffix,u=t.retry,c={request_seq:this.stateCenter.cdnSeq++,stream_id:e,playAddr:i,transCodecId:o,transCodecSuffix:s,cdnType:0,retry:u};this.logger.info("zb.sh.nsns request body:"+JSON.stringify(c));var a=this.mediaProtoBuf.encodeNotifySdkNeedStreamReq(c);this.sendHttpPBRequest({interfaceID:19,resID:this.stateCenter.appid+"/"+e},a,(function(e,t){r&&r(e,t)}),(function(e){n&&n(e)}),{timeout:4e3})}},I=function(){function e(e,t,r,n){this.de=e,this.dataReport=t,this.ve=r,this.he=n,this.screenShotReady=!1}return Object.defineProperty(e.prototype,"_e",{get:function(){return this.he.reporter},enumerable:!1,configurable:!0}),e.prototype.publishTarget=function(e){var t=this,r="";switch(e.type){case"addpush":r=c.iJ.event;break;case"delpush":case"clearpush":r=c.ns.event}var n=this._e.createSpan(j.H,{key:c.pO.event,par:e.streamID},{key:""},r);return n.setAttributes({url:c.ns.url(e.pushUrl)}),new d.l3((function(r,i){var o=function(e,r){t.de.error("zb.pt "+(r||e.message)),t._e.setError(n,e,r),i({errorCode:e.code,extendedData:e.message+(r?" "+r:"")})};if(-1==["addpush","delpush","clearpush"].indexOf(e.type))return t.de.error("zb.sh.pt cdn push type error"),void o(u.rBJ,"type error");if(e.streamID&&(0,a.QP)(e.streamID))if(e.pushUrl&&(0,a.QP)(e.pushUrl))if(t.he.publishStreamList[e.streamID]){var s=t.ve.getRoomByStreamID(e.streamID);if(s){s.streamHandler._publishTarget(e,(function(e){n.end(),r(e)}),o)}else o(c.Of.error.se)}else o(c.Of.error.oe);else o(c.Of.error.ie,"push url error");else o(c.Of.error.ie,"stream id type error")}))},e}(),J={type:"StreamCDN",install:function(e,t,r){for(var n in Object.defineProperty(t.prototype,"initStreamCDN",{value:function(){this.streamCDNModule=new I(this.logger,this.dataReport,this.streamCenter,this.stateCenter)},writable:!1}),$)Object.defineProperty(e.prototype,n,{value:$[n],writable:!1});for(var n in R)Object.defineProperty(r.prototype,n,{value:R[n],writable:!1})}};return o}()}));