jZego-rtc.js 407 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462
  1. !function (e, t) {
  2. if ("object" == typeof exports && "object" == typeof module) module.exports = t(); else if ("function" == typeof define && define.amd) define([], t); else {
  3. var r = t();
  4. for (var i in r) ("object" == typeof exports ? exports : e)[i] = r[i]
  5. }
  6. }("undefined" != typeof self ? self : this, function () {
  7. return function (e) {
  8. var t = {};
  9. function r(i) {
  10. if (t[i]) return t[i].exports;
  11. var s = t[i] = {i: i, l: !1, exports: {}};
  12. return e[i].call(s.exports, s, s.exports, r), s.l = !0, s.exports
  13. }
  14. return r.m = e, r.c = t, r.d = function (e, t, i) {
  15. r.o(e, t) || Object.defineProperty(e, t, {enumerable: !0, get: i})
  16. }, r.r = function (e) {
  17. "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {value: "Module"}), Object.defineProperty(e, "__esModule", {value: !0})
  18. }, r.t = function (e, t) {
  19. if (1 & t && (e = r(e)), 8 & t) return e;
  20. if (4 & t && "object" == typeof e && e && e.__esModule) return e;
  21. var i = Object.create(null);
  22. if (r.r(i), Object.defineProperty(i, "default", {
  23. enumerable: !0,
  24. value: e
  25. }), 2 & t && "string" != typeof e) for (var s in e) r.d(i, s, function (t) {
  26. return e[t]
  27. }.bind(null, s));
  28. return i
  29. }, r.n = function (e) {
  30. var t = e && e.__esModule ? function () {
  31. return e.default
  32. } : function () {
  33. return e
  34. };
  35. return r.d(t, "a", t), t
  36. }, r.o = function (e, t) {
  37. return Object.prototype.hasOwnProperty.call(e, t)
  38. }, r.p = "", r(r.s = 5)
  39. }([function (e, t, r) {
  40. "use strict";
  41. Object.defineProperty(t, "__esModule", {value: !0}), t.PROTO_VERSION = "1.2.2", t.ROOMVERSION = "V1", function (e) {
  42. e[e.debug = 0] = "debug", e[e.info = 1] = "info", e[e.warn = 2] = "warn", e[e.error = 3] = "error", e[e.report = 99] = "report", e[e.disable = 100] = "disable"
  43. }(t.ENUM_LOG_LEVEL || (t.ENUM_LOG_LEVEL = {})), function (e) {
  44. e[e.disable = 0] = "disable", e[e.websocket = 1] = "websocket", e[e.https = 2] = "https"
  45. }(t.ENUM_REMOTE_TYPE || (t.ENUM_REMOTE_TYPE = {}));
  46. var i = function () {
  47. function e(e, t) {
  48. void 0 === e && (e = null), void 0 === t && (t = null), this._id = null, this.next = null, this.prev = null, this._id = e, this._data = t
  49. }
  50. return Object.defineProperty(e.prototype, "id", {
  51. get: function () {
  52. return this._id
  53. }, set: function (e) {
  54. this._id = e
  55. }, enumerable: !0, configurable: !0
  56. }), Object.defineProperty(e.prototype, "data", {
  57. get: function () {
  58. return this._data
  59. }, set: function (e) {
  60. this._data = e
  61. }, enumerable: !0, configurable: !0
  62. }), e.prototype.hasNext = function () {
  63. return this.next && this.next.id
  64. }, e.prototype.hasPrev = function () {
  65. return this.prev && this.prev.id
  66. }, e
  67. }();
  68. t.ListNode = i;
  69. var s = function () {
  70. function e() {
  71. this.start = new i, this.end = new i, this._idCounter = 0, this._numNodes = 0, this.start.next = this.end, this.start.prev = null, this.end.prev = this.start, this.end.next = null
  72. }
  73. return e.prototype.insertBefore = function (e, t) {
  74. var r = new i(this._idCounter, t);
  75. return r.next = e, r.prev = e.prev, e.prev.next = r, e.prev = r, ++this._idCounter, ++this._numNodes, r
  76. }, e.prototype.addLast = function (e) {
  77. return this.insertBefore(this.end, e)
  78. }, e.prototype.add = function (e) {
  79. return this.addLast(e)
  80. }, e.prototype.getFirst = function () {
  81. return 0 === this._numNodes ? null : this.start.next
  82. }, e.prototype.getLast = function () {
  83. return 0 === this._numNodes ? null : this.end.prev
  84. }, e.prototype.size = function () {
  85. return this._numNodes
  86. }, e.prototype.getFromFirst = function (e) {
  87. var t = 0, r = this.start.next;
  88. if (e >= 0) for (; t < e && null !== r;) r = r.next, ++t; else r = null;
  89. if (null === r) throw"Index out of bounds.";
  90. return r
  91. }, e.prototype.get = function (e) {
  92. return 0 === e ? this.getFirst() : e === this._numNodes - 1 ? this.getLast() : this.getFromFirst(e)
  93. }, e.prototype.remove = function (e) {
  94. return e.prev.next = e.next, e.next.prev = e.prev, --this._numNodes, e
  95. }, e.prototype.removeFirst = function () {
  96. var e = null;
  97. return this._numNodes > 0 && (e = this.remove(this.start.next)), e
  98. }, e.prototype.removeLast = function () {
  99. var e = null;
  100. return this._numNodes > 0 && (e = this.remove(this.end.prev)), e
  101. }, e.prototype.removeAll = function () {
  102. this.start.next = this.end, this.end.prev = this.start, this._numNodes = 0, this._idCounter = 0
  103. }, e.prototype.each = function (e) {
  104. for (var t = this.start; t.hasNext();) e(t = t.next)
  105. }, e.prototype.find = function (e) {
  106. for (var t = this.start, r = !1, i = null; t.hasNext() && !r;) e(t = t.next) && (i = t, r = !0);
  107. return i
  108. }, e.prototype.map = function (e) {
  109. for (var t = this.start, r = []; t.hasNext();) e(t = t.next) && r.push(t);
  110. return r
  111. }, e.prototype.push = function (e) {
  112. return this.addLast(e)
  113. }, e.prototype.unshift = function (e) {
  114. this._numNodes > 0 ? this.insertBefore(this.start.next, e) : this.insertBefore(this.end, e)
  115. }, e.prototype.pop = function () {
  116. return this.removeLast()
  117. }, e.prototype.shift = function () {
  118. return this.removeFirst()
  119. }, e
  120. }();
  121. t.LinkedList = s, t.sdkErrorList = {
  122. SUCCESS: {code: "ZegoClient.Success", msg: "success."},
  123. PARAM: {code: "ZegoClient.Error.Param", msg: "input error."},
  124. HEARTBEAT_TIMEOUT: {code: "ZegoClient.Error.Timeout", msg: "heartbeat timeout."},
  125. LOGIN_TIMEOUT: {code: "ZegoClient.Error.Timeout", msg: "login timeout."},
  126. SEND_MSG_TIMEOUT: {code: "ZegoClient.Error.Timeout", msg: "send customsg timeout."},
  127. RESET_QUEUE: {code: "ZegoClient.Error.Timeout", msg: "msg waiting ack is clear when reset."},
  128. LOGIN_DISCONNECT: {code: "ZegoClient.Error.Network", msg: "network is broken and login fail."},
  129. KICK_OUT: {code: "ZegoClient.Error.Kickout", msg: "kickout reason="},
  130. UNKNOWN: {code: "ZegoClient.Error.Unknown", msg: "unknown error."},
  131. FREQ_LIMITED: {code: "ZegoClient.Error.requencyLimited", msg: "Frequency Limited."}
  132. }, function (e) {
  133. e[e.disconnected = 0] = "disconnected", e[e.connecting = 1] = "connecting", e[e.connected = 2] = "connected"
  134. }(t.ENUM_SIGNAL_STATE || (t.ENUM_SIGNAL_STATE = {})), t.ENUM_RESOLUTION_TYPE = {
  135. LOW: {
  136. width: 240,
  137. height: 320,
  138. frameRate: 15,
  139. bitRate: 300
  140. },
  141. MEDIUM: {width: 480, height: 640, frameRate: 15, bitRate: 800},
  142. HIGH: {width: 720, height: 1280, frameRate: 20, bitRate: 1500}
  143. }, t.ENUM_RETRY_STATE = {didNotStart: 0, retrying: 1, finished: 2}, t.ENUM_PUBLISH_STATE = {
  144. start: 0,
  145. waitingSessionRsp: 1,
  146. waitingOffserRsp: 2,
  147. waitingServerAnswer: 3,
  148. waitingServerICE: 4,
  149. connecting: 5,
  150. publishing: 6,
  151. stop: 7,
  152. didNotStart: 8
  153. }, t.ENUM_PLAY_STATE = {
  154. start: 0,
  155. waitingSessionRsp: 1,
  156. waitingOffserRsp: 2,
  157. waitingServerAnswer: 3,
  158. waitingServerICE: 4,
  159. connecting: 5,
  160. playing: 6,
  161. stop: 7,
  162. didNotStart: 8
  163. }, t.ENUM_CONNECT_STATE = {
  164. disconnect: 0,
  165. connecting: 1,
  166. connected: 2
  167. }, t.MAX_TRY_CONNECT_COUNT = 3, t.SEND_MSG_RESET = 2, t.SEND_MSG_TIMEOUT = 1, t.MAX_TRY_HEARTBEAT_COUNT = 5, t.ENUM_PUBLISH_STREAM_STATE = {
  168. waiting_url: 1,
  169. tryPublish: 2,
  170. update_info: 3,
  171. publishing: 4,
  172. stop: 5
  173. }, t.ENUM_STREAM_SUB_CMD = {
  174. liveNone: 0,
  175. liveBegin: 2001,
  176. liveEnd: 2002,
  177. liveUpdate: 2003
  178. }, t.ENUM_STREAM_UPDATE_TYPE = {added: 0, deleted: 1}, function (e) {
  179. e[e.logout = 0] = "logout", e[e.trylogin = 1] = "trylogin", e[e.login = 2] = "login"
  180. }(t.ENUM_RUN_STATE || (t.ENUM_RUN_STATE = {})), t.ENUM_PUBLISH_STATE_UPDATE = {
  181. start: 0,
  182. error: 1,
  183. retry: 2
  184. }, t.ENUM_PLAY_STATE_UPDATE = {
  185. start: 0,
  186. error: 1,
  187. retry: 2
  188. }, t.MAX_TRY_LOGIN_COUNT = 5, t.TRY_LOGIN_INTERVAL = [2e3, 2e3, 3e3, 3e3, 4e3], t.MINIUM_HEARTBEAT_INTERVAL = 3e3, t.ENUM_STREAM_UPDATE_CMD = {
  189. added: 12001,
  190. deleted: 12002,
  191. updated: 12003
  192. }, t.SERVER_ERROR_CODE = 1e4, t.MIXSTREAM_ERROR_CODE = 1e4, function (e) {
  193. e[e.low = 1] = "low", e[e.stantard = 2] = "stantard", e[e.hight = 3] = "hight", e[e.custome = 4] = "custome"
  194. }(t.QUALITYLEVEL || (t.QUALITYLEVEL = {})), t.ENUM_SIGNAL_SUB_CMD = {
  195. none: 0,
  196. joinLiveRequest: 1001,
  197. joinLiveResult: 1002,
  198. joinLiveInvite: 1003,
  199. joinLiveStop: 1004
  200. }, t.ENUM_PUSH_SIGNAL_SUB_CMD = {
  201. none: 0,
  202. pushJoinLiveRequest: 11001,
  203. pushJoinLiveResult: 11002,
  204. pushJoinLiveInvite: 11003,
  205. pushJoinLiveStop: 11004
  206. }, function (e) {
  207. e[e.auto = 0] = "auto", e[e.ultra = 1] = "ultra"
  208. }(t.ENUM_PLAY_SOURCE_TYPE || (t.ENUM_PLAY_SOURCE_TYPE = {})), function (e) {
  209. e[e.cdn = 0] = "cdn", e[e.ultra = 1] = "ultra", e[e.customUrl = 2] = "customUrl"
  210. }(t.ENUM_DISPATCH_TYPE || (t.ENUM_DISPATCH_TYPE = {})), function (e) {
  211. e[e.ClientType_None = 0] = "ClientType_None", e[e.ClientType_H5 = 1] = "ClientType_H5", e[e.ClientType_SmallPragram = 2] = "ClientType_SmallPragram", e[e.ClientType_Webrtc = 3] = "ClientType_Webrtc"
  212. }(t.E_CLIENT_TYPE || (t.E_CLIENT_TYPE = {}))
  213. }, function (e, t, r) {
  214. "use strict";
  215. Object.defineProperty(t, "__esModule", {value: !0});
  216. var i = function () {
  217. function e() {
  218. }
  219. return e.checkConfigParam = function (e, t) {
  220. return e.appid && "number" == typeof e.appid ? e.server ? !(!e.idName || "string" != typeof e.idName) || (t.error("ccp.0 idName must be string and not empty"), !1) : (t.error("ccp.0 server must be string and not empty"), !1) : (t.error("ccp.0 appid must be number"), !1)
  221. }, e.checkLoginParam = function (e, t) {
  222. return !0
  223. }, e.registerCallback = function (e, t, r) {
  224. var i, s;
  225. t.success && (i = t.success), t.error && (s = t.error), r[e + "SuccessCallback"] = i, r[e + "ErrorCallback"] = s
  226. }, e.actionErrorCallback = function (e, t) {
  227. return t[e + "ErrorCallback"]
  228. }, e.actionSuccessCallback = function (e, t) {
  229. return t[e + "SuccessCallback"]
  230. }, e.getServerError = function (e) {
  231. var t = {
  232. 1: "parse json error.",
  233. 1001: "login is processing.",
  234. 1002: "liveroom request error.",
  235. 1003: "zpush connect fail.",
  236. 1004: "zpush handshake fail.",
  237. 1005: "zpush login fail.",
  238. 1006: "user login state is wrong.",
  239. 1007: "got no zpush addr",
  240. 1008: "token error",
  241. 1009: "dispatch error",
  242. 2002: "biz channel error",
  243. 1000000000: "liveroom cmd error, result="
  244. };
  245. if (0 === e) return {code: "ZegoClient.Success", msg: "success"};
  246. var r = {code: "ZegoClient.Error.Server", msg: ""};
  247. return r.msg = e > 1e9 ? t[1e9] + e : t[e] ? "unknown error code:" + e : t[e], r
  248. }, e.isKeepTryLogin = function (e) {
  249. switch (e) {
  250. case 1002:
  251. case 1003:
  252. return !0;
  253. default:
  254. return !1
  255. }
  256. }, e.mergeStreamList = function (e, t, r, i, s) {
  257. e.debug("msl.0 call");
  258. var n, o = [], a = [], c = [];
  259. i || (i = []);
  260. for (var l = 0; l < i.length; l++) if (i[l].anchor_id_name != t) {
  261. n = !1;
  262. for (var d = 0; d < r.length; d++) if (i[l].stream_id === r[d].stream_id) {
  263. i[l].extra_info !== r[d].extra_info && c.push(i[l]), n = !0;
  264. break
  265. }
  266. n || o.push(i[l])
  267. } else e.debug("msl.0 have self stream added");
  268. for (var h = 0; h < r.length; h++) {
  269. n = !1;
  270. for (var u = 0; u < i.length; u++) if (i[u].anchor_id_name != t) {
  271. if (r[h].stream_id === i[u].stream_id) {
  272. n = !0;
  273. break
  274. }
  275. } else e.debug("msl.0 have self stream deleted");
  276. n || a.push(r[h])
  277. }
  278. r.splice(0);
  279. for (l = 0; l < i.length; l++) r.push(i[l]);
  280. s(o, a, c), e.debug("msl.0 call success")
  281. }, e.checkCustomCommandParam = function (e) {
  282. return !0
  283. }, e.generateRandumNumber = function (e) {
  284. return parseInt(Math.random() * (e + 1) + "", 10)
  285. }, e.uuid = function (e, t) {
  286. var r, i = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), s = [];
  287. if (t = t || i.length, e) for (r = 0; r < e; r++) s[r] = i[0 | Math.random() * t]; else {
  288. var n = void 0;
  289. for (s[8] = s[13] = s[18] = s[23] = "-", s[14] = "4", r = 0; r < 36; r++) s[r] || (n = 0 | 16 * Math.random(), s[r] = i[19 == r ? 3 & n | 8 : n])
  290. }
  291. return s.join("")
  292. }, e.isSupportWebrtc = function () {
  293. var e = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection,
  294. t = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia || navigator.mozGetUserMedia || navigator.mediaDevices && navigator.mediaDevices.getUserMedia,
  295. r = window.WebSocket;
  296. return !!e && !!t && !!r
  297. }, e.isSupportH264 = function (e, t) {
  298. var r = !1;
  299. new RTCPeerConnection(null).createOffer({
  300. offerToReceiveAudio: 1,
  301. offerToReceiveVideo: 1
  302. }).then(function (t) {
  303. if (t && t.sdp) {
  304. r = !0, clearTimeout(i);
  305. var s = t.sdp.split("\r\n").some(function (e) {
  306. return e.startsWith("a=rtpmap:") && e.indexOf("H264/") > -1
  307. });
  308. e && e(s)
  309. }
  310. }, function (e) {
  311. r = !0, clearTimeout(i), t && t(e)
  312. });
  313. var i = setTimeout(function () {
  314. 0 == r && t(!1)
  315. }, 200)
  316. }, e.inlineWorker = function (e) {
  317. if (Worker) {
  318. var t = e.toString().trim().match(/^function\s*\w*\s*\([\w\s,]*\)\s*{([\w\W]*?)}$/)[1],
  319. r = URL.createObjectURL(new window.Blob([t], {type: "text/javascript"}));
  320. return new Worker(r)
  321. }
  322. return null
  323. }, e
  324. }();
  325. t.ClientUtil = i
  326. }, function (e, t, r) {
  327. "use strict";
  328. var i;
  329. Object.defineProperty(t, "__esModule", {value: !0}), t.playErrorList = {
  330. DISPATCH_ERROR: {code: "ZegoPlayWeb.Error.Dispatch", msg: "dispatch request error"},
  331. DISPATCH_TIMEOUT: {code: "ZegoPlayWeb.Timeout.Dispatch", msg: "dispatch request timeout"},
  332. TOKEN_ERROR: {code: "ZegoPlayWeb.Error.Token", msg: "login token error"},
  333. SEND_SESSION_TIMEOUT: {code: "ZegoPlayWeb.Timeout.Session", msg: "send session request timeout"},
  334. CREATE_SESSION_ERROR: {code: "ZegoPlayWeb.Error.Session", msg: "create session error"},
  335. CREATE_OFFER_ERROR: {code: "ZegoPublish.Error.CreateOffer", msg: "create offer error"},
  336. SERVER_MEDIA_DESC_TIMEOUT: {
  337. code: "ZegoPlayWeb.Timeout.RemoteOffer",
  338. msg: "wating server mediaDesc timeout"
  339. },
  340. SET_REMOTE_DESC_ERROR: {code: "ZegoPlayWeb.Error.RemoteOffer", msg: "other side offer error"},
  341. CREATE_ANSWER_ERROR: {code: "ZegoPlayWeb.Error.CreateAnswer", msg: "create offer error"},
  342. SET_LOCAL_DESC_ERROR: {code: "ZegoPlayWeb.Error.LocalDesc", msg: "setLocalDescription error"},
  343. SEND_MEDIA_DESC_TIMEOUT: {code: "ZegoPlayWeb.Timeout.Desc", msg: "send mediaDesc timeout"},
  344. SEND_CANDIDATE_ERROR: {code: "ZegoPlayWeb.Error.Candidate", msg: "send candidate error"},
  345. SEND_CANDIDATE_TIMEOUT: {code: "ZegoPlayWeb.Timeout.Candidate", msg: "send candidate timeout"},
  346. SERVER_CANDIDATE_TIMEOUT: {code: "ZegoPlayWeb.Timeout.ServerCandidate", msg: "waiting candidate timeout"},
  347. SERVER_CANDIDATE_ERROR: {code: "ZegoPlayWeb.Error.ServerCandidate", msg: "recv candidate error"},
  348. MEDIA_CONNECTION_FAILED: {code: "ZegoPlayWeb.Error.ConnectionFailed", msg: "ice Connection state failed"},
  349. MEDIA_CONNECTION_CLOSED: {code: "ZegoPlayWeb.Error.ConnectionClosed", msg: "ice connection state closed"},
  350. SESSION_CLOSED: {code: "ZegoPlayWeb.Error.SessionClosed", msg: "server session closed"},
  351. WEBSOCKET_ERROR: {code: "ZegoPlayWeb.Error.SocketError", msg: "network error"}
  352. }, t.publishErrorList = {
  353. DISPATCH_ERROR: {code: "ZegoPublish.Error.Dispatch", msg: "dispatch request error"},
  354. DISPATCH_TIMEOUT: {code: "ZegoPublish.Timeout.Dispatch", msg: "dispatch request timeout"},
  355. TOKEN_ERROR: {code: "ZegoPublish.Error.Token", msg: "login token error"},
  356. SEND_SESSION_TIMEOUT: {code: "ZegoPublish.Timeout.Session", msg: "send session request timeout"},
  357. CREATE_SESSION_ERROR: {code: "ZegoPublish.Error.Session", msg: "create session error"},
  358. CREATE_OFFER_ERROR: {code: "ZegoPublish.Error.CreateOffer", msg: "create offer error"},
  359. SET_LOCAL_DESC_ERROR: {code: "ZegoPublish.Error.LocalDesc", msg: "setLocalDescription error"},
  360. SEND_MEDIA_DESC_TIMEOUT: {code: "ZegoPublish.Timeout.Desc", msg: "send mediaDesc timeout"},
  361. SERVER_MEDIA_DESC_TIMEOUT: {
  362. code: "ZegoPublish.Timeout.ServerAnswer",
  363. msg: "waiting server mediaDesc timeout"
  364. },
  365. SERVER_MEDIA_DESC_ERROR: {code: "ZegoPublish.Error.ServerAnswer", msg: "server mediaDesc type error"},
  366. SET_REMOTE_DESC_ERROR: {code: "ZegoPublish.Error.RemoteDesc", msg: "other side offer error"},
  367. SEND_CANDIDATE_TIMEOUT: {code: "ZegoPublish.Timeout.Candidate", msg: "sendIceCandidate error"},
  368. SERVER_CANDIDATE_TIMEOUT: {code: "ZegoPublish.Timeout.ServerCandidate", msg: "waiting candidate timeout"},
  369. SERVER_CANDIDATE_ERROR: {code: "ZegoPublish.Error.ServerCandidate", msg: "recv candidate error"},
  370. SESSION_CLOSED: {code: "ZegoPublish.Error.SessionClosed", msg: "server session closed"},
  371. MEDIA_CONNECTION_FAILED: {code: "ZegoPublish.Error.IConnectionFailed", msg: "Iice Connection state failed"},
  372. MEDIA_CONNECTION_CLOSED: {code: "ZegoPublish.Error.ConnectionClosed", msg: "ice connection state closed"},
  373. WEBSOCKET_ERROR: {code: "ZegoPublish.Error.SocketError", msg: "network error"}
  374. }, t.ENUM_PUBLISH_STATE_UPDATE = {start: 0, error: 1, retry: 2}, t.ENUM_PLAY_STATE_UPDATE = {
  375. start: 0,
  376. error: 1,
  377. retry: 2,
  378. stop: 3
  379. }, t.ENUM_RETRY_STATE = {didNotStart: 0, retrying: 1, finished: 2}, t.getSeq = (i = 1, function () {
  380. return i++
  381. })
  382. }, function (e, t, r) {
  383. "use strict";
  384. Object.defineProperty(t, "__esModule", {value: !0});
  385. var i = function () {
  386. function e(e) {
  387. this.loop = !1, this.replace = !1, this.effectEndedCallBack = null, this.effectEndedListener = null, this.startTimes = 0, this.startOffset = 0, this.pauseTimes = 0, this.resumeOffset = 0, this.isMixAudio = !1, this.logger = e
  388. }
  389. return e.prototype.preloadEffect = function (e, t) {
  390. var r = this;
  391. this.logger.info("amu.pe.0 start preload effect");
  392. var i = new ("undefined" != typeof webkitAudioContext ? webkitAudioContext : AudioContext),
  393. s = new XMLHttpRequest;
  394. s.open("GET", e, !0), s.responseType = "arraybuffer", s.onload = function () {
  395. if (200 == s.status || 304 == s.status) {
  396. var e = s.response;
  397. i.decodeAudioData(e, function (e) {
  398. r.logger.info("amu.pe.0 effect preload success"), t("", e)
  399. }, function (e) {
  400. t(e)
  401. })
  402. } else {
  403. var n = s.statusText;
  404. t(n)
  405. }
  406. }, s.send()
  407. }, e.prototype.playEffect = function (e, t, r, i, s) {
  408. var n = this;
  409. !0 !== this.isMixAudio ? this.audioBuffer ? (this.startOffset = e || 0, this.loop = t || !1, this.replace = r || !1, this.effectEndedCallBack = s, this.mixEffect(this.audioBuffer, function () {
  410. n.buffSource.loop = !!t, e ? n.buffSource.start(0, e / 1e3) : n.buffSource.start(0), n.startTimes = Date.now(), n.effectEndedListener = n.effectEndedHandler.bind(n), n.buffSource.addEventListener("ended", n.effectEndedListener), i && i()
  411. })) : this.logger.error("amu.pe.1 no audio buffer found") : this.logger.error("amu.pe.1 audio is mixing")
  412. }, e.prototype.pauseEffect = function () {
  413. this.stopMixingAudio(), this.resumeOffset = (this.pauseTimes - this.startTimes + this.startOffset) % (1e3 * this.audioBuffer.duration)
  414. }, e.prototype.resumeEffect = function () {
  415. this.playEffect(this.resumeOffset, this.loop, this.replace, null, this.effectEndedCallBack), this.startOffset = this.resumeOffset
  416. }, e.prototype.mixEffect = function (e, t) {
  417. this.localStream ? (this.ac = new ("undefined" != typeof webkitAudioContext ? webkitAudioContext : AudioContext), this.gainNode = this.ac.createGain(), this.buffSource = this.ac.createBufferSource(), this.buffSource.buffer = e, this.buffSource.connect(this.gainNode), this.replaceTrack() && t()) : this.logger.error("amu.me.0 localStream can not be found")
  418. }, e.prototype.startMixingAudio = function (e, t) {
  419. return this.replace = t || !1, this.isMixAudio ? (this.logger.error("amu.sma.0 audio is mixing"), !1) : this.localStream ? (e.captureStream = e.captureStream || e.mozCaptureStream || e.webkitCaptureStream, this.ac = new ("undefined" != typeof webkitAudioContext ? webkitAudioContext : AudioContext), this.gainNode = this.ac.createGain(), this.mixAudio = this.ac.createMediaStreamSource(e.captureStream()), this.mixAudio.connect(this.gainNode), this.replaceTrack()) : (this.logger.error("amu.sma.0 localStream can not be found"), !1)
  420. }, e.prototype.replaceTrack = function () {
  421. this.streamSource = this.ac.createMediaStreamSource(this.localStream.clone()), this.destination = this.ac.createMediaStreamDestination(), !this.replace && this.streamSource.connect(this.destination), this.gainNode.connect(this.destination);
  422. var e = this.destination.stream.getAudioTracks()[0],
  423. t = this.peerConnection.getSenders().find(function (t) {
  424. return t.track.kind === e.kind
  425. });
  426. return t ? (this.micTrack = this.localStream.getAudioTracks()[0], t.replaceTrack(e), this.localStream.removeTrack(this.micTrack), this.localStream.addTrack(e), this.isMixAudio = !0, !0) : (this.logger.error("amu.rt.0 no sender"), !1)
  427. }, e.prototype.stopMixingAudio = function () {
  428. var e = this;
  429. return this.isMixAudio ? this.localStream ? (this.peerConnection.getSenders().find(function (t) {
  430. return t.track.kind === e.micTrack.kind
  431. }).replaceTrack(this.micTrack), this.localStream.removeTrack(this.localStream.getAudioTracks()[0]), this.localStream.addTrack(this.micTrack), this.mixAudio ? (this.mixAudio.disconnect(this.gainNode), this.mixAudio = null) : this.buffSource && (this.buffSource.removeEventListener("ended", this.effectEndedListener), this.buffSource.stop(), this.pauseTimes = Date.now(), this.buffSource.disconnect(this.gainNode), this.buffSource = null), this.gainNode.disconnect(this.destination), this.micTrack = null, this.ac = null, this.isMixAudio = !1, !0) : (this.logger.error("amu.sma.1 localStream can not be found"), !1) : (this.logger.error("amu.sma.1 no mixing audio found"), !1)
  432. }, e.prototype.setMixingAudioVolume = function (e) {
  433. if (!this.gainNode) return this.logger.error("amu.sma.2 no mixing audio found"), !1;
  434. this.gainNode.gain.value = e
  435. }, e.prototype.effectEndedHandler = function () {
  436. this.stopMixingAudio(), this.effectEndedCallBack && this.effectEndedCallBack()
  437. }, e
  438. }();
  439. t.audioMixUtil = i
  440. }, function (e, t, r) {
  441. "use strict";
  442. Object.defineProperty(t, "__esModule", {value: !0});
  443. var i = function () {
  444. function e() {
  445. }
  446. return e.zegoSdp = function (e) {
  447. var t = e.split("\r\n"), r = [], i = [];
  448. t.forEach(function (e) {
  449. var t = e.match(/a=rtpmap:(\d+)\s+((H264\/90000)|(opus\/48000\/2))/);
  450. t && t[1] && t[2] && ("H264/90000" === t[2] && r.push(t[1]), "opus/48000/2" === t[2] && i.push(t[1]))
  451. });
  452. var s = [];
  453. return t.map(function (e) {
  454. var t = !0, n = e.match(/((a=rtcp-fb:)|(a=rtpmap:)|(a=fmtp:))(\d+)/);
  455. if (n && n[5] && (r.concat(i).some(function (e) {
  456. return e == n[5]
  457. }) || (t = !1)), e.indexOf("m=video") > -1) {
  458. var o = e.split(" ");
  459. e = [o[0], o[1], o[2]].concat(r).join(" ")
  460. } else if (e.indexOf("m=audio") > -1) {
  461. o = e.split(" ");
  462. e = [o[0], o[1], o[2]].concat(i).join(" ")
  463. }
  464. t && s.push(e)
  465. }), s.join("\r\n")
  466. }, e.getSDPByVideDecodeType = function (e, t) {
  467. var r = {str: "", arr: [], obj: {H264: [], H265: [], VP8: [], VP9: [], OHTER: []}};
  468. if (!e.includes("m=video")) return e;
  469. var i = /m=video.+/.exec(e)[0];
  470. i = i.match(/[\s|\d]+/g)[1].replace(" ", ""), r.str = i, r.arr = r.str.split(" "), r.arr.forEach(function (t) {
  471. var i = new RegExp("a=rtpmap:" + t + ".+").exec(e)[0];
  472. i.includes("H264") ? r.obj.H264.push(t) : i.includes("H265") ? r.obj.H265.push(t) : i.includes("VP8") ? r.obj.VP8.push(t) : i.includes("VP9") ? r.obj.VP9.push(t) : r.obj.OHTER.push(t)
  473. }), r.obj.OHTER.forEach(function (t) {
  474. var i = new RegExp("a=fmtp:" + t + ".+apt=(\\d+)").exec(e), s = i && i[1];
  475. s && (r.obj.H264.includes(s) ? r.obj.H264.push(t) : r.obj.H265.includes(s) ? r.obj.H265.push(t) : r.obj.VP8.includes(s) ? r.obj.VP8.push(t) : r.obj.VP9.includes(s) && r.obj.VP9.push(t))
  476. });
  477. var s = [];
  478. return "VP9" === t ? s = r.obj.H265.concat(r.obj.H264, r.obj.VP8) : "VP8" === t ? s = r.obj.H265.concat(r.obj.H264, r.obj.VP9) : "H264" === t ? s = r.obj.H265.concat(r.obj.VP8, r.obj.VP9) : "H265" === t && (s = r.obj.VP8.concat(r.obj.H264, r.obj.VP9)), s.forEach(function (t) {
  479. var i = r.arr.indexOf(t);
  480. r.arr.splice(i, 1);
  481. var s = new RegExp("a=rtpmap:" + t + ".+\\s\\n", "g"),
  482. n = new RegExp("a=rtcp-fb:" + t + ".+\\s\\n", "g"),
  483. o = new RegExp("a=fmtp:" + t + ".+\\s\\n", "g");
  484. e = (e = (e = e.replace(s, "")).replace(n, "")).replace(o, "")
  485. }), e = e.replace(i, r.arr.join(" "))
  486. }, e
  487. }();
  488. t.sdpUtil = i
  489. }, function (e, t, r) {
  490. "use strict";
  491. var i,
  492. s = this && this.__extends || (i = Object.setPrototypeOf || {__proto__: []} instanceof Array && function (e, t) {
  493. e.__proto__ = t
  494. } || function (e, t) {
  495. for (var r in t) t.hasOwnProperty(r) && (e[r] = t[r])
  496. }, function (e, t) {
  497. function r() {
  498. this.constructor = e
  499. }
  500. i(e, t), e.prototype = null === t ? Object.create(t) : (r.prototype = t.prototype, new r)
  501. }), n = this && this.__assign || Object.assign || function (e) {
  502. for (var t, r = 1, i = arguments.length; r < i; r++) for (var s in t = arguments[r]) Object.prototype.hasOwnProperty.call(t, s) && (e[s] = t[s]);
  503. return e
  504. };
  505. Object.defineProperty(t, "__esModule", {value: !0});
  506. var o = r(0), a = r(2), c = r(6), l = r(8), d = r(1), h = r(3), u = r(16), p = r(24), g = r(25),
  507. f = function (e) {
  508. function t() {
  509. var t = this, r = new c.LoggerWeb, i = new p.StateCenter, s = new l.ZegoStreamCenterWeb(r, i);
  510. return (t = e.call(this) || this).streamCenter = s, t.logger = r, t.stateCenter = i, t.audioMixing = new h.audioMixUtil(r), t.init(), t.bindWindowListener(), t
  511. }
  512. return s(t, e), t.prototype.getSocket = function (e) {
  513. return new WebSocket(e)
  514. }, t.prototype.enableCamera = function (e, t) {
  515. return this.logger.debug("zc.p.ec.0 call"), "boolean" != typeof t ? (this.logger.error("zc.p.ec.0 argument is not bool"), !1) : this.streamCenter.enableCamera(e, t)
  516. }, t.prototype.enableMicrophone = function (e, t) {
  517. return this.logger.debug("zc.p.em.0 call"), "boolean" != typeof t ? (this.logger.error("zc.p.em.0 argument is not bool"), !1) : this.streamCenter.enableMicrophone(e, t)
  518. }, t.prototype.setLocalAudioOutput = function (e, t) {
  519. return this.logger.debug("zc.p.slao call"), "string" != typeof t ? (console.error("audiooutput is not string"), !1) : this.streamCenter.setStreamAudioOutput(e, t)
  520. }, t.prototype.setPlayAudioOutput = function (e, t) {
  521. return this.logger.debug("zc.p.spao call"), "string" != typeof t ? (console.error("audiooutput is not string"), !1) : this.streamCenter.setPlayStreamAudioOutput(e, t)
  522. }, t.prototype.setCustomSignalUrl = function (e) {
  523. return this.logger.debug("zc.p.scs.0 call: " + e), e && 0 != e.length ? 0 != e.indexOf("wss://") ? (this.logger.error("zc.p.scs.0 url is not correct"), !1) : void (this.stateCenter.customUrl = e) : (this.logger.error("zc.p.scs.0 param error"), !1)
  524. }, t.prototype.setQualityMonitorCycle = function (e) {
  525. "number" == typeof e && e >= 1e3 && this.streamCenter.setQualityMonitorCycle(e)
  526. }, t.prototype.startPlayingStream = function (e, t, r, i) {
  527. var s = this;
  528. if (this.logger.debug("zc.p.sps.0 call"), !e || "" === e) return this.logger.error("zc.p.sps.0 param error"), !1;
  529. if (!t) return this.logger.error("zc.p.sps.0 don't have remoteVideo"), !1;
  530. if (this.stateCenter.customUrl) return this.streamCenter.setPlayStateStart(e, t, r, i) ? this.streamCenter.startPlayingStream(e, [this.stateCenter.customUrl]) : (this.logger.error("zc.p.sps.0 cannot start play"), !1);
  531. if (!this.stateCenter.isLogin()) return this.logger.error("zc.p.sps.0 not login"), !1;
  532. for (var n = !1, c = 0; c < this.stateCenter.streamList.length; c++) if (this.stateCenter.streamList[c].stream_id === e) {
  533. n = !0;
  534. break
  535. }
  536. if (0 == n && this.logger.info("zc.p.sps.0 cannot find stream"), this.stateCenter.pullLimited || (e = NaN + e), !this.streamCenter.setPlayStateStart(e, t, r, i)) return this.logger.info("zc.p.sps.0 cannot start play"), !1;
  537. var l = {stream_id: e, ptype: "pull", signals: this.streamCenter.getAllInUseUrl()};
  538. return this.socketCenter.registerRouter("webrtc_url", function (e) {
  539. s.handleFetchWebRtcUrlRsp(e)
  540. }), this.socketCenter.sendMessage("webrtc_url", l, void 0, function (t, r) {
  541. t == o.sdkErrorList.SEND_MSG_TIMEOUT ? s.onPlayStateUpdate(o.ENUM_PLAY_STATE_UPDATE.error, e, a.playErrorList.DISPATCH_TIMEOUT) : s.onPlayStateUpdate(o.ENUM_PLAY_STATE_UPDATE.error, e, a.playErrorList.DISPATCH_ERROR), s.streamCenter.stopPlayingStream(e)
  542. }), !0
  543. }, t.prototype.stopPlayingStream = function (e) {
  544. if (this.logger.debug("zc.p.sps.1.0 call"), !e || "" === e) return this.logger.info("zc.p.sps.1.0 param error"), !1;
  545. for (var t in this.streamCenter.stopPlayingStream(e), this.stateCenter.streamUrlMap) if (this.stateCenter.streamUrlMap[t] === e) {
  546. delete this.stateCenter.streamUrlMap[t];
  547. break
  548. }
  549. return this.logger.debug("zc.p.sps.1.0 call success"), !0
  550. }, t.prototype.startPreview = function (e, t, r, i) {
  551. if (this.logger.debug("zc.p.sp.0 call"), !e) return this.logger.error("zc.p.sp.0 no localVideo"), !1;
  552. if (t.audioBitRate) {
  553. if ("number" != typeof t.audioBitRate) return void this.logger.error("zc.p.sp.0 audioBitRate must be number");
  554. if (t.audioBitRate < 48e3) return void this.logger.error("zc.p.sp.0 audioBitRate cannot less 48000");
  555. this.stateCenter.audioBitRate = t.audioBitRate
  556. }
  557. return this.streamCenter.startPreview(e, t, r, i)
  558. }, t.prototype.stopPreview = function (e) {
  559. return this.logger.debug("zc.p.sp.1 call"), e ? this.streamCenter.stopPreview(e) : (this.logger.info("zc.p.sp.1 param error"), !1)
  560. }, t.prototype.startPublishingStream = function (e, t, r, i) {
  561. var s = this;
  562. if (this.logger.debug("zc.p.sps.1 call"), !e) return this.logger.error("zc.p.sps.1 param error"), !1;
  563. if (i || (i = {}), i.audioBitRate = this.stateCenter.audioBitRate, this.stateCenter.customUrl && 0 != this.stateCenter.customUrl.length) return this.stateCenter.publishStreamList[e] = {
  564. state: o.ENUM_PUBLISH_STREAM_STATE.tryPublish,
  565. extra_info: r
  566. }, this.streamCenter.setPublishStateStart(e, t, i) ? this.streamCenter.startPublishingStream(e, [this.stateCenter.customUrl]) : (this.logger.info("zc.p.sps.1 cannot start publish"), !1);
  567. if (!this.stateCenter.isLogin()) return this.logger.error("zc.p.sps.1 not login"), !1;
  568. if (this.stateCenter.publishStreamList[e] = {
  569. state: o.ENUM_PUBLISH_STREAM_STATE.tryPublish,
  570. extra_info: r
  571. }, !this.streamCenter.setPublishStateStart(e, t, i)) return this.logger.error("zc.p.sps.1 cannot start publish"), !1;
  572. this.logger.info("zc.p.sps.1 start publish");
  573. var n = {
  574. stream_id: e,
  575. ptype: "push",
  576. signals: this.streamCenter.getAllInUseUrl(),
  577. header_kvs: [{key: "grpc-metadata-push", value: i && i.cdnUrl || ""}]
  578. };
  579. return this.socketCenter.registerRouter("webrtc_url", function (e) {
  580. s.handleFetchWebRtcUrlRsp(e)
  581. }), this.socketCenter.sendMessage("webrtc_url", n, void 0, function (t, r) {
  582. t == o.sdkErrorList.SEND_MSG_TIMEOUT ? s.onPublishStateUpdate(o.ENUM_PUBLISH_STATE_UPDATE.error, e, a.publishErrorList.DISPATCH_TIMEOUT) : s.onPublishStateUpdate(o.ENUM_PUBLISH_STATE_UPDATE.error, e, a.publishErrorList.DISPATCH_ERROR), s.streamCenter.stopPublishingStream(e)
  583. }), !0
  584. }, t.prototype.stopPublishingStream = function (e) {
  585. return this.logger.debug("zc.p.sps.1.1 call"), e ? (this.streamCenter.stopPublishingStream(e), this.stateCenter.publishStreamList[e] && (this.stateCenter.publishStreamList[e].state >= o.ENUM_PUBLISH_STREAM_STATE.update_info && this.streamHandler.updateStreamInfo(e, o.ENUM_STREAM_SUB_CMD.liveEnd), delete this.stateCenter.publishStreamList[e]), !0) : (this.logger.info("zc.p.sps.1.1 param error"), !1)
  586. }, t.prototype.preloadEffect = function (e, t, r) {
  587. var i = this;
  588. e && "number" == typeof e && t && "string" == typeof t ? this.stateCenter.audioEffectBuffer[e] ? this.logger.error("zc.pe.0 audio buffer already exists") : this.audioMixing.preloadEffect(t, function (t, s) {
  589. if (t) return i.logger.error("zc.pe.0 effect preload fail " + t), void (r && r(t));
  590. s && (i.stateCenter.audioEffectBuffer[e] = s, r && r())
  591. }) : this.logger.error("zc.pe.0 params error")
  592. }, t.prototype.playEffect = function (e, t, r) {
  593. if (e.streamId && "string" == typeof e.streamId && e.effectId && "number" == typeof e.effectId) if (this.stateCenter.audioEffectBuffer[e.effectId]) {
  594. var i = this.stateCenter.audioEffectBuffer[e.effectId], s = this.getPublisher(e.streamId);
  595. s ? i ? s.playEffect(e, i, t, r) : this.logger.error("zc.pe.1 no audio buffer found") : this.logger.error("zc.pe.1 publisher doesn't exist")
  596. } else this.logger.error("zc,pe.1 audio buffer dosesn't exists"); else this.logger.error("zc.pe.1 params error")
  597. }, t.prototype.pauseEffect = function (e) {
  598. if (e && "string" == typeof e) {
  599. var t = this.getPublisher(e);
  600. t ? t.pauseEffect() : this.logger.error("zc.pe.2 publisher doesn't exist")
  601. } else this.logger.error("zc.pe.2 streamid format error")
  602. }, t.prototype.resumeEffect = function (e) {
  603. if (e && "string" == typeof e) {
  604. var t = this.getPublisher(e);
  605. t ? t.resumeEffect() : this.logger.error("zc.re.0 publisher doesn't exist")
  606. } else this.logger.error("zc.re.0 streamid format error")
  607. }, t.prototype.unloadEffect = function (e) {
  608. return e && "number" == typeof e ? (delete this.stateCenter.audioEffectBuffer[e], !0) : (this.logger.error("zc.ue.0 params error"), !1)
  609. }, t.prototype.startMixingAudio = function (e, t, r) {
  610. if (this.logger.debug("zc.sma.0 call"), !e || "string" != typeof e) return this.logger.error("zc.sma.0 stream id error"), !1;
  611. if (!t) return this.logger.error("zc.sma.0 no audio"), !1;
  612. var i = this.getPublisher(e);
  613. return i ? i.startMixingAudio(t, r) : (this.logger.error("zc.sma.0 publisher doesn't exist"), !1)
  614. }, t.prototype.stopMixingAudio = function (e) {
  615. if (!e || "string" != typeof e) return this.logger.error("zc.sma.1 param streamid format error"), !1;
  616. var t = this.getPublisher(e);
  617. return t ? t.stopMixingAudio() : (this.logger.error("zc.sma.1 publisher doesn't exist"), !1)
  618. }, t.prototype.setMixingAudioVolume = function (e, t) {
  619. if (this.logger.debug("zc.sma.2 call"), !e || "string" != typeof e || "number" != typeof t || t < 0 || t > 100) return this.logger.error("zc.sma.2 param error"), !1;
  620. var r = this.getPublisher(e);
  621. return r ? r.audioMixing.setMixingAudioVolume(t / 100) : (this.logger.error("zc.sma.2 publisher doesn't exist"), !1)
  622. }, t.prototype.getPublisher = function (e) {
  623. var t = null, r = this.streamCenter.getTotalStreamId(e);
  624. return this.streamCenter.publisherList[r] && this.streamCenter.publisherList[r].publisher && (t = this.streamCenter.publisherList[r].publisher), t
  625. }, t.prototype.startScreenShotChrome = function (e) {
  626. if (!t.screenShotReady) return this.logger.error('zc.b.ss Please install the extension:1. Go to chrome://extensions 2. Check: "Enable Developer mode 3. Click: "Load the unpacked extension... 4. Choose "extension" folder from the repository 5. Reload this page'), !1;
  627. window.postMessage({
  628. type: "SS_UI_REQUEST",
  629. text: "start"
  630. }, "*"), d.ClientUtil.registerCallback("screenShare", {success: e}, this.stateCenter.callbackList)
  631. }, t.prototype.startScreenSharingChrome = function (e, t) {
  632. var r = this;
  633. "getDisplayMedia" in navigator.mediaDevices ? navigator.mediaDevices.getDisplayMedia({audio: e}).then(function (e) {
  634. r.stateCenter.screenShotStream = e, t(!0, e)
  635. }).catch(function (e) {
  636. r.logger.error("zc.b.sss " + e), t(!1, null, e)
  637. }) : this.logger.error("zc.b.sss brower does not support getDisplayMedia")
  638. }, t.prototype.startScreenShotFirFox = function (e, t, r) {
  639. var i = this, s = {video: {}, audio: t};
  640. s.video.mediaSource = e, navigator.mediaDevices.getUserMedia(s).then(function (e) {
  641. i.stateCenter.screenShotStream = e, r(!0, e)
  642. }).catch(function (e) {
  643. i.logger.error("zc.b.ssf " + e), r(!1, null)
  644. })
  645. }, t.prototype.stopScreenShot = function () {
  646. this.stateCenter.screenShotStream.getTracks().forEach(function (e) {
  647. e.stop()
  648. }), window.postMessage({type: "SS_UI_CANCEL", text: "start"}, "*")
  649. }, t.prototype.WebrtcOnPublishStateUpdateHandle = function (e, t, r) {
  650. this.stateCenter.publishStreamList[t].state == o.ENUM_PUBLISH_STREAM_STATE.publishing && this.onPublishStateUpdate(e, t, r)
  651. }, t.prototype.setCDNInfo = function (e, t) {
  652. e.urls_flv = t.urls_flv, e.urls_hls = t.urls_m3u8, e.urls_https_flv = t.urls_https_flv, e.urls_https_hls = t.urls_https_m3u8, e.urls_rtmp = t.urls_rtmp
  653. }, t.prototype.loginBodyData = function () {
  654. return {
  655. id_name: this.stateCenter.idName,
  656. nick_name: this.stateCenter.nickName,
  657. role: this.stateCenter.role,
  658. token: this.stateCenter.token,
  659. version: o.PROTO_VERSION,
  660. room_name: this.stateCenter.roomid,
  661. user_state_flag: this.stateCenter.userStateUpdate ? 1 : 0,
  662. room_create_flag: this.stateCenter.roomCreateFlag,
  663. client_type: o.E_CLIENT_TYPE.ClientType_Webrtc,
  664. third_token: this.stateCenter.third_token
  665. }
  666. }, t.prototype.screenStreamFrom = function (e, t, r) {
  667. var i = this, s = {};
  668. s.audio = {
  669. mandatory: {
  670. chromeMediaSource: "desktop",
  671. chromeMediaSourceId: e
  672. }
  673. }, s.video = {
  674. mandatory: {
  675. chromeMediaSource: "desktop",
  676. chromeMediaSourceId: e,
  677. maxWidth: window.screen.width,
  678. maxHeight: window.screen.height
  679. }
  680. }, !t && (s.audio = !1), navigator.mediaDevices.getUserMedia(s).then(function (e) {
  681. i.stateCenter.screenShotStream = e, r(!0, e)
  682. }).catch(function (e) {
  683. i.logger.error("zc.b.ssf " + e), r(!1, null, e)
  684. })
  685. }, t.prototype.filterStreamList = function (e) {
  686. var t = {}, r = {}, i = {}, s = [], n = 0;
  687. for (var o in this.stateCenter.streamList.forEach(function (t, r) {
  688. t.stream_id == e && (n = r)
  689. }), this.stateCenter.streamList[n]) "urls_flv" != o && "urls_https_flv" != o || (t[o] = this.stateCenter.streamList[n][o]), "urls_m3u8" != o && "urls_https_m3u8" != o || (r[o] = this.stateCenter.streamList[n][o]), "urls_rtmp" == o && (i[o] = this.stateCenter.streamList[n][o]);
  690. var a = window.location.protocol, c = window.navigator.userAgent;
  691. if (/Safari/.test(c) && !/Chrome/.test(c)) for (var o in r) r[o] && r[o].forEach(function (e) {
  692. -1 !== e.indexOf(a) && s.push(e)
  693. }); else if ("http:" == a) for (var o in t) t[o] && t[o].forEach(function (e) {
  694. -1 === e.indexOf("http") && -1 === e.indexOf("https") || s.push(e)
  695. }); else if ("https:" == a) for (var o in t) t[o] && t[o].forEach(function (e) {
  696. -1 !== e.indexOf(a) && s.push(e)
  697. }); else if ("rtmp:" == a) for (var o in i) i[o] && i[o].forEach(function (e) {
  698. -1 !== e.indexOf(a) && s.push(e)
  699. });
  700. return s.filter(function (e, t, r) {
  701. return r.indexOf(e) == t
  702. })
  703. }, t.isSupportWebrtc = function () {
  704. return d.ClientUtil.isSupportWebrtc()
  705. }, t.isSupportH264 = function (e, t) {
  706. d.ClientUtil.isSupportH264(e, t)
  707. }, t.prototype.enumDevices = function (e, r) {
  708. t.enumDevices(e, r)
  709. }, t.enumDevices = function (e, t) {
  710. void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.enumerateDevices ? navigator.mediaDevices.enumerateDevices().then(function (t) {
  711. for (var r = [], i = [], s = [], n = 0; n < t.length; n++) {
  712. var o = t[n];
  713. "audioinput" === o.kind && r.push({
  714. label: o.label,
  715. deviceId: o.deviceId
  716. }), "audiooutput" === o.kind && i.push({
  717. label: o.label,
  718. deviceId: o.deviceId
  719. }), "videoinput" === o.kind && s.push({label: o.label, deviceId: o.deviceId})
  720. }
  721. e && e({microphones: r, speakers: i, cameras: s})
  722. }).catch(function (e) {
  723. t && t(e)
  724. }) : t && t("browser don't support enumerate devices")
  725. }, t.getAudioInfo = function (e, t, r) {
  726. if (!e.srcObject) return console.error("srcObject is empty!"), !1;
  727. var i = n({}, r);
  728. return new g.MediaUtil(i).connectToSource(e.srcObject, function (e) {
  729. t(e)
  730. })
  731. }, t.handleDataAvailable = function (e) {
  732. e.data && e.data.size > 0 && t.recordedBlobs.push(e.data)
  733. }, t.startRecord = function (e) {
  734. var r = e.captureStream();
  735. t.recordedBlobs = [];
  736. var i = {mimeType: "video/webm;codecs=vp9"};
  737. MediaRecorder.isTypeSupported(i.mimeType) || (i = {mimeType: "video/webm;codecs=vp8"}, MediaRecorder.isTypeSupported(i.mimeType) || (i = {mimeType: "video/webm"}, MediaRecorder.isTypeSupported(i.mimeType) || (i = {mimeType: ""})));
  738. try {
  739. t.mediaRecorder = new MediaRecorder(r, i)
  740. } catch (e) {
  741. return void console.error("Exception while creating MediaRecorder:", e)
  742. }
  743. t.mediaRecorder.onstop = function (e) {
  744. console.log("Recorder stopped: ", e)
  745. }, t.mediaRecorder.ondataavailable = t.handleDataAvailable, t.mediaRecorder.start(10)
  746. }, t.stopRecord = function () {
  747. t.mediaRecorder ? t.mediaRecorder.stop() : console.warn("please invoke startRecord first")
  748. }, t.resumeRecord = function () {
  749. t.mediaRecorder ? t.mediaRecorder.resume() : console.warn("please invoke startRecord first")
  750. }, t.pauseRecord = function () {
  751. t.mediaRecorder ? t.mediaRecorder.pause() : console.warn("please invoke startRecord first")
  752. }, t.saveRecord = function (e) {
  753. if (t.mediaRecorder && t.recordedBlobs) {
  754. var r = new Blob(t.recordedBlobs, {type: "video/webm"}), i = window.URL.createObjectURL(r),
  755. s = document.createElement("a");
  756. s.style.display = "none", s.href = i, s.download = e + ".webm", document.body.appendChild(s), s.click(), setTimeout(function () {
  757. document.body.removeChild(s), window.URL.revokeObjectURL(i)
  758. }, 100)
  759. } else console.warn("please invoke startRecord first")
  760. }, t.takeSnapShot = function (e, t) {
  761. if (e && 0 !== e.videoHeight) {
  762. var r = document.createElement("canvas");
  763. r.width = e.videoWidth, r.height = e.videoHeight, r.getContext("2d").drawImage(e, 0, 0, r.width, r.height), t.src = r.toDataURL("image/jpeg")
  764. } else console.error("video can not empty")
  765. }, t.saveSnapShot = function (e, t) {
  766. if (e && 0 !== e.videoHeight) {
  767. var r = document.createElement("canvas");
  768. r.width = e.videoWidth, r.height = e.videoHeight, r.getContext("2d").drawImage(e, 0, 0, r.width, r.height), r.toBlob(function (e) {
  769. var r = window.URL.createObjectURL(e), i = document.createElement("a");
  770. i.style.display = "none", i.href = r, i.download = t + ".jpeg", document.body.appendChild(i), i.click(), setTimeout(function () {
  771. document.body.removeChild(i), window.URL.revokeObjectURL(r)
  772. }, 100)
  773. })
  774. } else console.error("video can not empty")
  775. }, t.prototype.bindWindowListener = function () {
  776. var e = this,
  777. t = navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i) ? "pagehide" : "beforeunload";
  778. window.addEventListener(t, function (t) {
  779. for (var r in window.event.cancelBubble = !0, e.streamCenter.publisherList) e.stopPublishingStream(r);
  780. for (var r in e.streamCenter.playerList) e.stopPublishingStream(r);
  781. console.log(e.streamCenter.playerList), console.log(e.streamCenter.publisherList), e.logout()
  782. }), window.addEventListener("message", function (t) {
  783. var r = t.data, i = r.type, s = r.streamId, n = r.canRequestAudioTrack;
  784. t.origin;
  785. "SS_DIALOG_SUCCESS" === i && e.screenStreamFrom(s, n, d.ClientUtil.actionSuccessCallback("screenShare", e.stateCenter.callbackList)), "SS_DIALOG_CANCEL" === i && (e.logger.error("zc.b.ss " + i), d.ClientUtil.actionSuccessCallback("screenShare", e.stateCenter.callbackList)(!1, null, i))
  786. })
  787. }, t.screenShotReady = !1, t
  788. }(u.BaseCenter);
  789. t.ZegoClient = f, window.addEventListener("message", function (e) {
  790. var t = e.data, r = t.type, i = (t.streamId, e.origin);
  791. i !== window.location.origin && console.warn("ScreenStream: you should discard foreign event from origin:", i), "SS_PING" === r && (f.screenShotReady = !0)
  792. })
  793. }, function (e, t, r) {
  794. "use strict";
  795. var i,
  796. s = this && this.__extends || (i = Object.setPrototypeOf || {__proto__: []} instanceof Array && function (e, t) {
  797. e.__proto__ = t
  798. } || function (e, t) {
  799. for (var r in t) t.hasOwnProperty(r) && (e[r] = t[r])
  800. }, function (e, t) {
  801. function r() {
  802. this.constructor = e
  803. }
  804. i(e, t), e.prototype = null === t ? Object.create(t) : (r.prototype = t.prototype, new r)
  805. });
  806. Object.defineProperty(t, "__esModule", {value: !0});
  807. var n = r(7), o = function (e) {
  808. function t() {
  809. return null !== e && e.apply(this, arguments) || this
  810. }
  811. return s(t, e), t.prototype.openWebSocketLogServer = function (e) {
  812. if (this.url != e) {
  813. if (this.url = e, !e) return;
  814. if (null != this.websocket && 2 != this.websocket.readyState && 3 != this.websocket.readyState) return;
  815. this.stopWebSocketServer(), this.websocket = new WebSocket(e), this.websocket.onopen = function (e) {
  816. }, this.websocket.onclose = function (e) {
  817. console.error("onclose websocket error:", e)
  818. }, this.websocket.onmessage = function (e) {
  819. }, this.websocket.onerror = function (e) {
  820. console.error("open log websocket error:" + e)
  821. }
  822. }
  823. }, t.prototype.SendHttpsLog = function () {
  824. var e = this;
  825. if (0 != this.logCacheSend.length) {
  826. var t = this.logCacheSend.join("\n"), r = new XMLHttpRequest;
  827. r.onreadystatechange = function () {
  828. if (4 == r.readyState) if (200 == r.status) {
  829. if (0 == r.responseText.length) return;
  830. try {
  831. var t = JSON.parse(r.responseText).interval;
  832. "number" == typeof t && e.logUploadInterval !== t && (e.timeInterval = t, e.openHttpsLogServer(e.url))
  833. } catch (e) {
  834. console.log("send result failed " + e)
  835. }
  836. } else console.log("send failed " + r.status)
  837. }, r.open("POST", this.url, !0), r.send(t), this.logCacheSend = []
  838. }
  839. }, t.prototype.logReportParamList = function (e, t) {
  840. var r = new Date, i = r.getFullYear() + "/";
  841. return i += (n.D[r.getMonth() + 1] || r.getMonth() + 1) + "/", i += (n.D[r.getDate()] || r.getDate()) + " ", i += (n.D[r.getHours()] || r.getHours()) + ":", i += (n.D[r.getMinutes()] || r.getMinutes()) + ":", i += n.D[r.getSeconds()] || r.getSeconds(), i += "." + r.getTime() % 1e3, t.time = i, t.level = e, t.console = "rtc", t.appid = this.appid, t.roomid = this.roomid, t.userid = this.userid, t.id_name = this.userid, t.userName = this.userName, t.sessionid = this.sessionid, t.version = this.version, [JSON.stringify(t)]
  842. }, t
  843. }(n.Logger);
  844. t.LoggerWeb = o
  845. }, function (e, t, r) {
  846. "use strict";
  847. Object.defineProperty(t, "__esModule", {value: !0});
  848. var i = r(0);
  849. t.D = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09"];
  850. var s = function () {
  851. function e() {
  852. this.logUploadTimer = null, this.logUploadInterval = 1e4, this.logCache = [], this.logCacheSend = [], this.logCacheMax = 100
  853. }
  854. return e.prototype.setLogLevel = function (e) {
  855. this.logLevel < i.ENUM_LOG_LEVEL.debug || this.logLevel > i.ENUM_LOG_LEVEL.report ? this.logLevel = i.ENUM_LOG_LEVEL.disable : this.logLevel = e
  856. }, e.prototype.setRemoteLogLevel = function (e) {
  857. this.logRemoteLevel < i.ENUM_LOG_LEVEL.debug || this.logRemoteLevel > i.ENUM_LOG_LEVEL.report ? this.logRemoteLevel = i.ENUM_LOG_LEVEL.disable : this.logRemoteLevel = e
  858. }, e.prototype.setSessionInfo = function (e, t, r, i, s, n) {
  859. this.appid = e, this.roomid = t, this.sessionid = r, this.userid = i, this.userName = s, this.version = n
  860. }, e.prototype.openLogServer = function (e) {
  861. try {
  862. e.startsWith("wss:") ? (this.logType = i.ENUM_REMOTE_TYPE.websocket, this.openWebSocketLogServer(e)) : e.startsWith("https:") ? (this.logType = i.ENUM_REMOTE_TYPE.https, this.openHttpsLogServer(e)) : this.logType = i.ENUM_REMOTE_TYPE.disable
  863. } catch (e) {
  864. this.error(JSON.stringify(e))
  865. }
  866. }, e.prototype.stopLogServer = function () {
  867. this.logType == i.ENUM_REMOTE_TYPE.websocket ? this.stopWebSocketServer() : this.logType == i.ENUM_REMOTE_TYPE.https && (this.SendHttpsLog(), this.stopHttpsServer()), this.logType = i.ENUM_REMOTE_TYPE.disable
  868. }, e.prototype.stopWebSocketServer = function () {
  869. this.websocket && (this.websocket.onclose = null, this.websocket.onerror = null, this.websocket.close(), this.websocket = null)
  870. }, e.prototype.openHttpsLogServer = function (e) {
  871. var t = this;
  872. this.url = e, e && (this.stopHttpsServer(), this.logUploadTimer || (this.logUploadTimer = setInterval(function () {
  873. t.SendHttpsLog()
  874. }, this.logUploadInterval)))
  875. }, e.prototype.stopHttpsServer = function () {
  876. this.logUploadTimer && (clearInterval(this.logUploadTimer), this.logUploadTimer = null)
  877. }, e.prototype.report = function (e) {
  878. var t = this.logReportParamList(i.ENUM_LOG_LEVEL.report, e);
  879. this.logLevel !== i.ENUM_LOG_LEVEL.disable && this.logLevel <= i.ENUM_LOG_LEVEL.report && console.debug.apply(console, t), this.RemoteLog(i.ENUM_LOG_LEVEL.report, t, !0)
  880. }, e.prototype.debug = function () {
  881. for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
  882. var r = this.logParamList(i.ENUM_LOG_LEVEL.debug, e.join(""));
  883. this.logLevel !== i.ENUM_LOG_LEVEL.disable && this.logLevel <= i.ENUM_LOG_LEVEL.debug && console.debug.apply(console, r), this.log(i.ENUM_LOG_LEVEL.debug, r)
  884. }, e.prototype.info = function () {
  885. for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
  886. var r = this.logParamList(i.ENUM_LOG_LEVEL.info, e.join(""));
  887. this.logLevel !== i.ENUM_LOG_LEVEL.disable && this.logLevel <= i.ENUM_LOG_LEVEL.info && console.info.apply(console, r), this.log(i.ENUM_LOG_LEVEL.info, r)
  888. }, e.prototype.warn = function () {
  889. for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
  890. var r = this.logParamList(i.ENUM_LOG_LEVEL.warn, e.join(""));
  891. this.logLevel !== i.ENUM_LOG_LEVEL.disable && this.logLevel <= i.ENUM_LOG_LEVEL.warn && console.warn.apply(console, r), this.log(i.ENUM_LOG_LEVEL.warn, r)
  892. }, e.prototype.error = function () {
  893. for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
  894. var r = this.logParamList(i.ENUM_LOG_LEVEL.error, e.join(""));
  895. this.logLevel !== i.ENUM_LOG_LEVEL.disable && this.logLevel <= i.ENUM_LOG_LEVEL.error && console.error.apply(console, r), this.log(i.ENUM_LOG_LEVEL.error, r)
  896. }, e.prototype.log = function (e, t) {
  897. this.logRemoteLevel !== i.ENUM_LOG_LEVEL.disable && this.logRemoteLevel <= e && this.RemoteLog(e, t)
  898. }, e.prototype.RemoteLog = function (e, t, r) {
  899. if (void 0 === r && (r = !1), "" != this.url) if (this.logType == i.ENUM_REMOTE_TYPE.websocket) this.RemoteWebSocketLog(e, t); else if (this.logType == i.ENUM_REMOTE_TYPE.https) this.RemoteHttpsLog(e, t, r); else if (this.logLevel !== i.ENUM_LOG_LEVEL.disable && this.logLevel <= e) for (this.logCacheSend.push(t); this.logCacheSend.length > this.logCacheMax;) this.logCacheSend.shift()
  900. }, e.prototype.RemoteWebSocketLog = function (e, t) {
  901. if (null == this.websocket || 2 == this.websocket.readyState || 3 == this.websocket.readyState) {
  902. var r = this.url;
  903. this.url = "", this.openLogServer(r), this.logCacheSend.length < this.logCacheMax && this.logCacheSend.push(t)
  904. } else if (0 == this.websocket.readyState) this.logCacheSend.length < this.logCacheMax && this.logCacheSend.push(t); else if (1 == this.websocket.readyState) if (this.logCacheSend.length > 0) {
  905. for (var i = "", s = 0; s < this.logCacheSend.length; s++) (i + this.logCacheSend[s]).length > 4e3 && (this.websocket.send(i), i = ""), i = i + this.logCacheSend[s] + "\n";
  906. t = i + t, this.logCacheSend = [], this.websocket.send(t)
  907. } else this.websocket.send(t); else console.warn("wrong socket state:" + this.websocket.readyState), this.logCacheSend.length < this.logCacheMax && this.logCacheSend.push(t)
  908. }, e.prototype.RemoteHttpsLog = function (e, t, r) {
  909. this.logCacheSend.push(t), (this.logCacheSend.length >= this.logCacheMax || !0 === r) && this.SendHttpsLog()
  910. }, e.prototype.logParamList = function (e, r) {
  911. var i = new Date, s = i.getFullYear() + "/";
  912. s += (t.D[i.getMonth() + 1] || i.getMonth() + 1) + "/", s += (t.D[i.getDate()] || i.getDate()) + " ", s += (t.D[i.getHours()] || i.getHours()) + ":", s += (t.D[i.getMinutes()] || i.getMinutes()) + ":", s += t.D[i.getSeconds()] || i.getSeconds(), s += "." + i.getTime() % 1e3;
  913. var n = r.substr(0, r.indexOf(" "));
  914. 0 == n.length && (n = r);
  915. var o = r.substr(r.indexOf(" ") + 1, 4500);
  916. 0 == o.length && (o = "");
  917. var a = {
  918. time: s,
  919. level: e,
  920. action: n,
  921. content: o,
  922. appid: this.appid,
  923. roomid: this.roomid,
  924. userid: this.userid,
  925. userName: this.userName,
  926. sessionid: this.sessionid
  927. };
  928. return [JSON.stringify(a)]
  929. }, e
  930. }();
  931. t.Logger = s
  932. }, function (e, t, r) {
  933. "use strict";
  934. var i,
  935. s = this && this.__extends || (i = Object.setPrototypeOf || {__proto__: []} instanceof Array && function (e, t) {
  936. e.__proto__ = t
  937. } || function (e, t) {
  938. for (var r in t) t.hasOwnProperty(r) && (e[r] = t[r])
  939. }, function (e, t) {
  940. function r() {
  941. this.constructor = e
  942. }
  943. i(e, t), e.prototype = null === t ? Object.create(t) : (r.prototype = t.prototype, new r)
  944. });
  945. Object.defineProperty(t, "__esModule", {value: !0});
  946. var n = r(9), o = r(10), a = r(11), c = r(2), l = r(0), d = r(13), h = r(14), u = function (e) {
  947. function t(t, r) {
  948. var i = e.call(this, t, r) || this;
  949. return i.testEnvironment = !1, i.heartbeatTimer = null, i.heartbeatInterval = 1e4, i.qualityTimerInterval = 3e3, i.maxRetryCount = 5, i.previewVideoList = [], i.signalList = {}, i.checkMessageTimeout = function () {
  950. for (var e in i.signalList) i.signalList[e].signal && i.signalList[e].signal.checkMessageTimeout()
  951. }, i.getAllInUseUrl = function () {
  952. var e = [];
  953. for (var t in i.signalList) e.push(t);
  954. return e
  955. }, i.onDisconnectHandle = function (e) {
  956. if (i.logger.info("zsc.od.0 call"), i.signalList[e]) {
  957. for (var t = i.signalList[e], r = 0; r < t.publishConnectedList.length; r++) {
  958. var s = i.publisherList[t.publishConnectedList[r]];
  959. s && s.publisher && s.publisher.onDisconnect()
  960. }
  961. for (r = 0; r < t.playConnectedList.length; r++) {
  962. var n = i.playerList[t.playConnectedList[r]];
  963. n && n.player && n.player.onDisconnect()
  964. }
  965. delete i.signalList[e], i.stopSignalHeartbeat()
  966. }
  967. }, i.logger = t, i.stateCenter = r, i.dataReport = new n.ZegoDataReport(i.logger), i
  968. }
  969. return s(t, e), t.prototype.onSignalDisconnected = function (e) {
  970. }, t.prototype.setQualityMonitorCycle = function (e) {
  971. this.logger.debug("zsc.qmc.0 timeInterval " + e), this.qualityTimerInterval = e
  972. }, t.prototype.setSessionInfo = function (e, t, r, i) {
  973. this.logger.debug("zsc.ssi.0 called"), this.appid = e, this.userid = t, this.token = r, this.testEnvironment = i
  974. }, t.prototype.onPlayStateUpdate = function (e, t, r) {
  975. }, t.prototype.onPlayQualityUpdate = function (e, t) {
  976. }, t.prototype.onPublishStateUpdate = function (e, t, r) {
  977. }, t.prototype.onPublishQualityUpdate = function (e, t) {
  978. }, t.prototype.onUpdateHeartBeartIntervalHandle = function (e) {
  979. e != this.heartbeatInterval && (this.logger.debug("zsc.uhb.0 update " + e), this.heartbeatTimer && (clearTimeout(this.heartbeatTimer), this.heartbeatTimer = null), this.heartbeatInterval = e, this.startSignalHeartbeat())
  980. }, t.prototype.enableMicrophone = function (e, t) {
  981. var r = this.checkPreview(e);
  982. return r ? r.enableMicrophone(t) : (this.logger.info("zsc.em.0 no preview"), !1)
  983. }, t.prototype.enableCamera = function (e, t) {
  984. var r = this.checkPreview(e);
  985. return r ? r.enableCamera(t) : (this.logger.error("zsc.ec.0 no preview"), !1)
  986. }, t.prototype.startPreview = function (e, t, r, i) {
  987. if (!e) return this.logger.error("zsc.sp.0 localVideo null"), !1;
  988. var s = this.checkPreview(e);
  989. return s ? (this.logger.warn("zsc.sp.0 localvideo already exist"), !0) : (s = new o.ZegoPreview(this.logger), this.previewVideoList.push(s), s.startPreview(e, t, r, i), this.logger.debug("zsc.sp.0 call success"), !0)
  990. }, t.prototype.stopPreview = function (e) {
  991. if (!e) return this.logger.warn("zsc.sp.0 localVideo null"), !1;
  992. for (var t in this.publisherList) this.publisherList[t].localVideo === e && (this.publisherList[t].localVideo = null);
  993. var r = this.checkPreview(e);
  994. return r ? (r.previewSuc && (r.stopPreview(), this.removePreview(r)), !0) : (this.logger.warn("zsc.sp.0 no preview"), !1)
  995. }, t.prototype.setPublishStateStart = function (e, t, r) {
  996. var i = this, s = this.getTotalStreamId(e);
  997. if (this.publisherList[s]) return this.logger.error("zsc.pss.0 publisher already exist"), !1;
  998. var n = new a.ZegoPublish(this.logger, null, this.dataReport, this.qualityTimerInterval);
  999. return n.onPublishStateUpdate = function (t, r, s) {
  1000. var n = i.publisherList[r];
  1001. n ? i.onPublishStateUpdate(t, n.streamId, s) : i.logger.error("zsc.psuh.0 cannot find publish " + e)
  1002. }, n.onPublishQualityUpdate = function (t, r) {
  1003. var s = i.publisherList[t];
  1004. s ? i.onPublishQualityUpdate(s.streamId, r) : i.logger.error("zsc.psuh.0 cannot find publish " + e)
  1005. }, this.publisherList[s] = {
  1006. localVideo: t,
  1007. publisher: n,
  1008. serverUrls: [],
  1009. retryCount: 0,
  1010. streamId: e,
  1011. playOption: r
  1012. }, this.dataReport.eventStart(n.reportSeq, "GetSignalUrl"), !0
  1013. }, t.prototype.getTotalStreamId = function (e) {
  1014. if (this.testEnvironment) {
  1015. var t = "zegotest-" + this.appid + "-" + e;
  1016. return this.logger.info("zsc.gts.0 test streamid " + t), t
  1017. }
  1018. return e
  1019. }, t.prototype.startPublishingStream = function (e, t, r) {
  1020. this.logger.info("zsc.sps.0 call");
  1021. var i = this.getTotalStreamId(e), s = this.publisherList[i];
  1022. if (!s) return this.logger.error("zsc.sps.0 publisher don't exist"), !1;
  1023. var n = s.publisher;
  1024. if (this.dataReport.eventEndWithMsg(n.reportSeq, "GetSignalUrl", {urls: t}), !t || 0 === t.length) return this.onPublishStateUpdate(c.ENUM_PUBLISH_STATE_UPDATE.error, e, c.publishErrorList.DISPATCH_ERROR), this.logger.info("zsc.sps.0 server don't have signal url"), !1;
  1025. var o = t[0];
  1026. return s.serverUrls = s.serverUrls.concat(t), this.connectPublishServer(i, o)
  1027. }, t.prototype.updateWaitingList = function (e, t, r, i, s) {
  1028. t ? e.publishWaitingList.push({
  1029. streamId: r,
  1030. success: i,
  1031. error: s
  1032. }) : e.playWaitingList.push({streamId: r, success: i, error: s})
  1033. }, t.prototype.publishStream = function (e) {
  1034. var t = this.publisherList[e].publisher;
  1035. if (t) {
  1036. var r = null, i = null, s = this.publisherList[e].playOption,
  1037. n = this.checkPreview(this.publisherList[e].localVideo);
  1038. n && (r = n.localStream, i = n.videoInfo), r || this.logger.info("zsc.ps.0 no localStream"), this.logger.debug("zsc.ps.0 call success"), t.startPublish(e, r, i, s)
  1039. } else this.logger.info("zsc.ps.0 publisher don't exist")
  1040. }, t.prototype.connectPublishServer = function (e, t) {
  1041. var r = this, i = this.publisherList[e];
  1042. return i ? (this.dataReport.eventStart(i.publisher.reportSeq, "ConnectServer"), this.connetWithReuseSignalServer(e, !0, t, function (e, i) {
  1043. var s = r.publisherList[e];
  1044. if (s) {
  1045. var n = s.publisher;
  1046. if (n) {
  1047. r.dataReport.eventEndWithMsg(n.reportSeq, "ConnectServer", {result: 0, server: t});
  1048. var o = i.tokenInfo;
  1049. r.logger.info("zsc.cps.0 update token success"), o && o.report && (n.qualityUpload = o.report, n.qualityUploadInterval = o.report_interval), n.signal = i.signal, s.retryCount = 0, r.publishStream(e), r.getTokenSuccess()
  1050. } else r.logger.info("zsc.cps.1 check publisher don't exist")
  1051. } else r.logger.info("zsc.cps.0 after connect publisher don't exist")
  1052. }, function (e, t) {
  1053. r.logger.error("zsc.cps.0 update token failed " + t);
  1054. var i = r.publisherList[e];
  1055. if (i) if (r.shouldRetry(i, t)) {
  1056. r.logger.info("zsc.cps.1 retry connect");
  1057. var s = i.serverUrls[0];
  1058. i.serverUrls.splice(0, 1), i.retryCount += 1, r.connectPublishServer(e, s)
  1059. } else r.onPublishStateUpdate(c.ENUM_PUBLISH_STATE_UPDATE.error, e, c.publishErrorList.TOKEN_ERROR); else r.logger.info("zsc.cps.0 after connect publisher don't exist")
  1060. }), !0) : (this.logger.error("zsc.cps.0 publisher don't exist"), !1)
  1061. }, t.prototype.shouldRetry = function (e, t) {
  1062. return 0 != e.serverUrls.length && (!(e.retryCount >= this.maxRetryCount) && 3 == t)
  1063. }, t.prototype.getTokenSuccess = function () {
  1064. this.logger.debug("zsc.gts.0 call")
  1065. }, t.prototype.stopPublishingStream = function (e) {
  1066. var t = this.getTotalStreamId(e), r = this.publisherList[t];
  1067. r ? (r.publisher && (r.publisher.stopPublish(), delete r.publisher), this.removeStreamFromSignal(!0, t), this.stopSignalHeartbeat(), delete this.publisherList[t], this.logger.debug("zsc.sps.0.1 call success")) : this.logger.warn("zsc.sps.0.1 publisher don't exist")
  1068. }, t.prototype.setPlayStreamAudioOutput = function (e, t) {
  1069. var r = this.getTotalStreamId(e);
  1070. if (null != t && 0 != t.length) {
  1071. this.logger.debug("zsc.psao.1 device " + t);
  1072. var i = this.playerList[r];
  1073. return i ? i.player ? i.player.setAudioDestination(t) : (this.logger.info("zsc.psao.1 player don't exist"), !1) : (this.logger.info("zsc.psao.1 play don't exist"), !1)
  1074. }
  1075. return !1
  1076. }, t.prototype.setStreamAudioOutput = function (e, t) {
  1077. var r = this;
  1078. return !(null == t || 0 == t.length || !e) && (this.logger.debug("zsc.ssao.0 device " + t), e ? "undefined" !== e.sinkId ? (e.setSinkId(t).then(function () {
  1079. r.logger.info("zsc.ssao.0 success device: " + t)
  1080. }).catch(function (e) {
  1081. r.logger.info("zsc.ssao.0 " + e.name)
  1082. }), !0) : (this.logger.error("zsc.ssao.0 browser does not suppport"), !1) : (this.logger.error("zsc.ssao.0 no localVideo"), !1))
  1083. }, t.prototype.connetWithReuseSignalServer = function (e, t, r, i, s) {
  1084. var n = this;
  1085. this.logger.info("zsc.crss.0 begin " + r);
  1086. var o = null;
  1087. if (this.signalList[r]) (o = this.signalList[r]).state == l.ENUM_SIGNAL_STATE.connected ? (this.logger.info("zsc.crss.0 already connected " + r + " streamId: " + e), t ? o.publishConnectedList.push(e) : o.playConnectedList.push(e), i(e, o)) : o.state == l.ENUM_SIGNAL_STATE.connecting && (this.logger.debug("zsc.crss.0 signal is connecting " + r + " streamId: " + e), this.updateWaitingList(o, t, e, i, s)); else {
  1088. this.logger.info("zsc.crss.0 new signal " + r + " streamId: " + e);
  1089. var a = new d.ZegoSignal(this.logger, this.stateCenter);
  1090. a.setSessionInfo(this.appid, this.userid), a.onUpdateHeartBeartInterval = this.onUpdateHeartBeartIntervalHandle, a.onDisconnect = this.onDisconnectHandle, this.signalList[r] = {
  1091. signal: a,
  1092. state: l.ENUM_SIGNAL_STATE.connecting,
  1093. publishWaitingList: [],
  1094. playWaitingList: [],
  1095. publishConnectedList: [],
  1096. playConnectedList: [],
  1097. tokenInfo: null
  1098. }, this.updateWaitingList(this.signalList[r], t, e, i, s), a.connectServer(this.token, r, function (e, t, i) {
  1099. o = n.signalList[r];
  1100. var s, a, c = 0;
  1101. if (0 != e) {
  1102. for (n.logger.debug("zsc.crss.0 connect failed " + t), c = 0; c < o.publishWaitingList.length; c++) (s = o.publishWaitingList[c]).error && s.error(s.streamId, e);
  1103. for (c = 0; c < o.playWaitingList.length; c++) (a = o.playWaitingList[c]).error && a.error(a.streamId, e);
  1104. delete n.signalList[r]
  1105. } else {
  1106. for (n.logger.debug("zsc.crss.0 connected success " + t), o.state = l.ENUM_SIGNAL_STATE.connected, o.tokenInfo = i, c = 0; c < o.publishWaitingList.length; c++) (s = o.publishWaitingList[c]).success && s.success(s.streamId, o), o.publishConnectedList.push(s.streamId);
  1107. for (c = 0; c < o.playWaitingList.length; c++) (a = o.playWaitingList[c]).success && a.success(a.streamId, o), o.playConnectedList.push(a.streamId);
  1108. o.publishWaitingList = [], o.playWaitingList = [], null == n.heartbeatTimer && n.startSignalHeartbeat()
  1109. }
  1110. })
  1111. }
  1112. }, t.prototype.setPlayStateStart = function (e, t, r, i) {
  1113. var s = this.getTotalStreamId(e);
  1114. if (this.playerList[s]) return this.logger.warn("zsc.pss.1 player already exist"), !1;
  1115. var n = new h.ZegoPlayWeb(this.logger, null, this.dataReport, this.qualityTimerInterval);
  1116. return n.onPlayStateUpdate = this.onPlayStateUpdate, n.onPlayQualityUpdate = this.onPlayQualityUpdate, n.onVideoSizeChanged = this.onVideoSizeChanged, this.playerList[s] = {
  1117. player: n,
  1118. remoteVideo: t,
  1119. audioOutput: r,
  1120. signal: null,
  1121. serverUrls: [],
  1122. retryCount: 0,
  1123. playOption: i
  1124. }, this.dataReport.eventStart(n.reportSeq, "GetSignalUrl"), !0
  1125. }, t.prototype.startPlayingStream = function (e, t, r) {
  1126. this.logger.info("zsc.sps.1 start play called");
  1127. var i = this.getTotalStreamId(e), s = this.playerList[i];
  1128. if (!s) return this.logger.error("zsc.sps.1 player don't exist"), !1;
  1129. var n = s.player;
  1130. return this.dataReport.eventEndWithMsg(n.reportSeq, "GetSignalUrl", {urls: t}), 0 == t.length ? (this.onPlayStateUpdate(c.ENUM_PLAY_STATE_UPDATE.error, e, c.playErrorList.DISPATCH_ERROR), this.logger.info("zsc.sps.1 server don't have signal url"), !1) : (s.serverUrls = s.serverUrls.concat(t), this.connectPlayServer(i, t[0]))
  1131. }, t.prototype.connectPlayServer = function (e, t) {
  1132. var r = this, i = this.playerList[e];
  1133. return i ? (this.dataReport.eventStart(i.player.reportSeq, "ConnectServer"), this.connetWithReuseSignalServer(e, !1, t, function (e, i) {
  1134. var s = r.playerList[e];
  1135. if (s) {
  1136. var n = s.player;
  1137. if (n) {
  1138. r.dataReport.eventEndWithMsg(n.reportSeq, "ConnectServer", {result: 0, server: t});
  1139. var o = i.tokenInfo;
  1140. r.logger.info("zsc.cps.1 update token success"), o && o.report && (n.qualityUpload = o.report, n.qualityUploadInterval = o.report_interval), n.signal = i.signal, s.retryCount = 0, r.playStream(e), r.getTokenSuccess()
  1141. } else r.logger.error("zsc.cps.1 checkplayer don't exist")
  1142. } else r.logger.error("zsc.cps.1 after connect player don't exist")
  1143. }, function (e, t) {
  1144. var i = r.playerList[e];
  1145. if (i) if (r.shouldRetry(i, t)) {
  1146. r.logger.info("zsc.cps.1 retry connect");
  1147. var s = i.serverUrls[0];
  1148. i.serverUrls.splice(0, 1), i.retryCount += 1, r.connectPlayServer(e, s)
  1149. } else r.onPlayStateUpdate(c.ENUM_PLAY_STATE_UPDATE.error, e, c.playErrorList.TOKEN_ERROR); else r.logger.error("zsc.cps.1 after connect player don't exist")
  1150. }), !0) : (this.logger.error("zsc.cps.1 player don't exist"), !1)
  1151. }, t.prototype.playStream = function (e) {
  1152. var t = this.playerList[e].player;
  1153. t ? (this.logger.info("zsc.ps.1 call success"), t.startPlay(e, this.playerList[e].remoteVideo, this.playerList[e].audioOutput, this.playerList[e].playOption)) : this.logger.warn("zsc.ps.1 player don't exist")
  1154. }, t.prototype.removeStreamFromSignal = function (e, t) {
  1155. var r = [];
  1156. for (var i in this.signalList) {
  1157. var s = this.signalList[i];
  1158. if (e) {
  1159. for (var n = 0; n < s.publishConnectedList.length; n++) if (s.publishConnectedList[n] === t) {
  1160. this.logger.debug("zsc.rsfs.0 found from publish"), s.publishConnectedList.splice(n, 1);
  1161. break
  1162. }
  1163. } else for (var o = 0; o < s.playConnectedList.length; o++) if (s.playConnectedList[o] === t) {
  1164. this.logger.debug("zsc.rsfs.0 found from play"), s.playConnectedList.splice(o, 1);
  1165. break
  1166. }
  1167. 0 == s.publishConnectedList.length && 0 == s.playConnectedList.length && (s.signal.disconnectServer(), r.push(i))
  1168. }
  1169. for (var a = 0; a < r.length; a++) delete this.signalList[r[a]]
  1170. }, t.prototype.stopSignalHeartbeat = function () {
  1171. this.logger.debug("zsc.ssh.1 call");
  1172. var e = 0;
  1173. for (var t in this.signalList) e += 1;
  1174. this.heartbeatTimer && 0 == e && (this.logger.info("zsc.ssh.1 stop"), clearTimeout(this.heartbeatTimer), this.heartbeatTimer = null)
  1175. }, t.prototype.stopPlayingStream = function (e) {
  1176. var t = this.getTotalStreamId(e), r = this.playerList[t];
  1177. r ? (r.player && (r.player.stopPlay(), delete r.player), this.removeStreamFromSignal(!1, t), this.stopSignalHeartbeat(), delete this.playerList[t], this.logger.debug("zsc.sps.1.1 call success")) : this.logger.info("zsc.sps.1.1 player don't exist")
  1178. }, t.prototype.reset = function () {
  1179. for (var e in this.publisherList) this.publisherList[e].publisher && this.publisherList[e].publisher.stopPublish();
  1180. for (var t in this.playerList) this.playerList[t].player && this.playerList[t].player.stopPlay();
  1181. for (var r in this.signalList) this.signalList[r].signal && this.signalList[r].signal.disconnectServer();
  1182. this.playerList = {}, this.publisherList = {}, this.signalList = {}, this.heartbeatTimer && (clearTimeout(this.heartbeatTimer), this.heartbeatTimer = null)
  1183. }, t.prototype.startSignalHeartbeat = function () {
  1184. var e = this;
  1185. this.logger.debug("zsc.ssh.0 call"), this.heartbeatTimer && (clearTimeout(this.heartbeatTimer), this.heartbeatTimer = null), this.heartbeatTimer = setTimeout(function () {
  1186. e.checkSignalHeartbeat()
  1187. }, this.heartbeatInterval)
  1188. }, t.prototype.checkSignalHeartbeat = function () {
  1189. for (var e in this.logger.debug("zsc.csh.0 call"), this.signalList) this.signalList[e].signal && this.signalList[e].signal.sendHeartbeat();
  1190. this.heartbeatTimer && this.startSignalHeartbeat()
  1191. }, t.prototype.checkPreview = function (e) {
  1192. for (var t = 0; t < this.previewVideoList.length; t++) if (this.previewVideoList[t].localVideo === e) return this.previewVideoList[t];
  1193. return null
  1194. }, t.prototype.removePreview = function (e) {
  1195. for (var t = 0; t < this.previewVideoList.length; t++) if (this.previewVideoList[t] === e) {
  1196. this.previewVideoList.splice(t, 1);
  1197. break
  1198. }
  1199. }, t.prototype.onPlayerStreamUrlUpdate = function (e, t, r) {
  1200. }, t.prototype.onVideoSizeChanged = function (e, t, r) {
  1201. }, t
  1202. }(r(15).ZegoStreamCenter);
  1203. t.ZegoStreamCenterWeb = u
  1204. }, function (e, t, r) {
  1205. "use strict";
  1206. var i = this && this.__assign || Object.assign || function (e) {
  1207. for (var t, r = 1, i = arguments.length; r < i; r++) for (var s in t = arguments[r]) Object.prototype.hasOwnProperty.call(t, s) && (e[s] = t[s]);
  1208. return e
  1209. };
  1210. Object.defineProperty(t, "__esModule", {value: !0});
  1211. var s = function () {
  1212. function e(e) {
  1213. this.log = e, this.dataStatistics = {}, this.logger = e
  1214. }
  1215. return e.prototype.newReport = function (e) {
  1216. this.dataStatistics[e] = {abs_time: Date.now(), time_consumed: 0, error: 0, events: []}
  1217. }, e.prototype.addMsgExt = function (e, t) {
  1218. this.dataStatistics[e] ? this.dataStatistics[e].msg_ext = t : console.warn(e + " not exist")
  1219. }, e.prototype.eventStart = function (e, t) {
  1220. this.dataStatistics[e] ? null != this.dataStatistics[e].events ? this.dataStatistics[e].events.push({
  1221. event: t,
  1222. abs_time: Date.now(),
  1223. time_consumed: 0
  1224. }) : this.logger.warn("zd.es.0 no events") : this.logger.warn("zd.es.0 no seq match")
  1225. }, e.prototype.eventEnd = function (e, t, r) {
  1226. if (this.dataStatistics[e]) {
  1227. var i = this.dataStatistics[e].events;
  1228. if (i && 0 !== i.length) {
  1229. for (var s = i.length - 1; s >= 0; s--) if (i[s].event == t && i[s].time_consumed) {
  1230. i[s].time_consumed = Date.now() - i[s].abs_time;
  1231. break
  1232. }
  1233. } else this.logger.info("zd.ee.0 no events")
  1234. } else this.logger.info("zd.ee.0 no seq match")
  1235. }, e.prototype.eventEndWithMsg = function (e, t, r) {
  1236. if (this.dataStatistics[e]) {
  1237. var s = this.dataStatistics[e].events;
  1238. if (s) {
  1239. for (var n = s.length - 1; n >= 0; n--) if (s[n].event == t && s[n].time_consumed) {
  1240. s[n].time_consumed = Date.now() - s[n].abs_time, null == s[n].msg_ext && (s[n].msg_ext = {}), s[n].msg_ext = i({}, r);
  1241. break
  1242. }
  1243. } else this.logger.warn("zd.ee.0 no events")
  1244. } else this.logger.warn("zd.ee.0 no seq match")
  1245. }, e.prototype.addEventInfo = function (e, t, r, i) {
  1246. if (this.dataStatistics[e]) {
  1247. var s = this.dataStatistics[e].events;
  1248. if (null != s) {
  1249. for (var n = s.length - 1; n >= 0; n--) if (s[n].event == t && null != s[n].time_consumed && s[n].event == t && null != s[n].time_consumed) {
  1250. null == s[n].msg_ext && (s[n].msg_ext = {}), s[n].msg_ext[r] = i;
  1251. break
  1252. }
  1253. } else this.logger.warn("zd.aei.0 no events")
  1254. } else this.logger.warn("zd.aei.0 no seq match")
  1255. }, e.prototype.addEvent = function (e, t, r) {
  1256. this.dataStatistics[e] ? this.dataStatistics[e].events && (r ? this.dataStatistics[e].events.push({
  1257. event: t,
  1258. abs_time: Date.now(),
  1259. msg_ext: r
  1260. }) : this.dataStatistics[e].events.push({
  1261. event: t,
  1262. abs_time: Date.now()
  1263. })) : this.logger.warn("zd.ae.0 no seq match")
  1264. }, e.prototype.uploadReport = function (e, t) {
  1265. var r = this.dataStatistics[e];
  1266. null != r && (r.itemtype = t, r.time_consumed = Date.now() - r.abs_time, this.logger.report(r), delete this.dataStatistics[e])
  1267. }, e
  1268. }();
  1269. t.ZegoDataReport = s
  1270. }, function (e, t, r) {
  1271. "use strict";
  1272. Object.defineProperty(t, "__esModule", {value: !0});
  1273. var i = r(0), s = function () {
  1274. function e(e) {
  1275. var t = this;
  1276. this.log = e, this.localVideo = null, this.localStream = null, this.videoInfo = {}, this.previewSuc = !1, this.enableMicrophone = function (e) {
  1277. return t.localStream ? (t.localStream.getAudioTracks().forEach(function (t) {
  1278. t.enabled = e
  1279. }), t.logger.debug("zp.em.2 call success"), !0) : (t.logger.error("zp.em.2 no localStream"), !1)
  1280. }, this.enableCamera = function (e) {
  1281. return t.localStream ? (t.localStream.getVideoTracks().forEach(function (t) {
  1282. t.enabled = e
  1283. }), t.logger.debug("zp.ec.2 call success"), !0) : (t.logger.error("zp.ec.2 no localStream"), !1)
  1284. }, this.setAudioDestination = function (e) {
  1285. return t.localVideo ? "undefined" !== t.localVideo.sinkId ? (t.localVideo.setSinkId(e).then(function () {
  1286. t.logger.info("zp.sad.2 success device: " + e)
  1287. }).catch(function (e) {
  1288. t.logger.info("zp.sad.2 " + e.name)
  1289. }), !0) : (t.logger.error("zp.sad.2 browser does not suppport"), !1) : (t.logger.error("zp.sad.2 no localVideo"), !1)
  1290. }, this.logger = e
  1291. }
  1292. return e.prototype.getMediaStreamConstraints = function (e) {
  1293. var t = {audio: null, video: null};
  1294. if (t.audio = !1, t.video = !1, console.log("mediaStreamConfig", e), e.audio && (void 0 === e.audioInput && void 0 === e.noiseSuppression && void 0 === e.autoGainControl && void 0 === e.echoCancellation ? t.audio = !0 : (t.audio = {}, void 0 !== e.audioInput && (t.audio.deviceId = e.audioInput), void 0 !== e.noiseSuppression && (t.audio.noiseSuppression = e.noiseSuppression), void 0 !== e.autoGainControl && (t.audio.autoGainControl = e.autoGainControl), void 0 !== e.echoCancellation && (t.audio.echoCancellation = e.echoCancellation))), e.video) {
  1295. var r = 640, s = 480, n = 15, o = 800;
  1296. if (1 === e.videoQuality ? (r = i.ENUM_RESOLUTION_TYPE.LOW.width, s = i.ENUM_RESOLUTION_TYPE.LOW.height, n = i.ENUM_RESOLUTION_TYPE.LOW.frameRate, o = i.ENUM_RESOLUTION_TYPE.LOW.bitRate) : 2 === e.videoQuality ? (r = i.ENUM_RESOLUTION_TYPE.MEDIUM.width, s = i.ENUM_RESOLUTION_TYPE.MEDIUM.height, n = i.ENUM_RESOLUTION_TYPE.MEDIUM.frameRate, o = i.ENUM_RESOLUTION_TYPE.MEDIUM.bitRate) : 3 === e.videoQuality ? (r = i.ENUM_RESOLUTION_TYPE.HIGH.width, s = i.ENUM_RESOLUTION_TYPE.HIGH.height, n = i.ENUM_RESOLUTION_TYPE.HIGH.frameRate, o = i.ENUM_RESOLUTION_TYPE.HIGH.bitRate) : 4 === e.videoQuality ? (r = e.width, s = e.height, n = e.frameRate, o = e.bitRate || 800) : this.logger.info("zp.gmsc.2 user default"), !0 === e.horizontal) {
  1297. var a = s;
  1298. s = r, r = a
  1299. }
  1300. t.video = {
  1301. width: r,
  1302. height: s,
  1303. frameRate: n,
  1304. bitRate: o
  1305. }, null != e.facingMode ? t.video.facingMode = e.facingMode : null != e.videoInput && (t.video.deviceId = {exact: e.videoInput}), this.logger.info("zp.gmsc.2 width: " + r + " height: " + s + " rate: " + n)
  1306. }
  1307. return t
  1308. }, e.prototype.startPreview = function (e, t, r, i) {
  1309. var s = this;
  1310. if (this.logger.debug("zp.sv.2 called"), this.localVideo = e, void 0 !== navigator.mediaDevices && null != navigator.mediaDevices.getUserMedia) {
  1311. if (t.externalMediaStream instanceof MediaStream) return this.logger.debug("zp.sv.2 use external media stream"), this.previewSuc = !0, this.localStream = t.externalMediaStream, this.videoInfo = {
  1312. width: t.width,
  1313. height: t.height,
  1314. frameRate: t.frameRate,
  1315. bitRate: t.bitRate
  1316. }, void (r && r());
  1317. if (t.externalCapture) this.captureStream(e) ? (this.previewSuc = !0, r && r()) : i && i("browser don't support"); else {
  1318. var n = this.getMediaStreamConstraints(t);
  1319. this.videoInfo = n.video, this.logger.info("zp.sv.2 ", JSON.stringify(n)), navigator.mediaDevices.getUserMedia(n).then(function (e) {
  1320. if (s.logger.info("zp.sv.2 success"), !s.localVideo) return s.logger.info("zp.sv.2 no localVideo"), void (i && i("no localVideo"));
  1321. s.localVideo.srcObject = e, s.localStream = e, s.previewSuc = !0, r && r()
  1322. }, function (e) {
  1323. s.logger.info("zp.sv.2 failed"), i && i(e.name)
  1324. })
  1325. }
  1326. } else i && i("browser don't support")
  1327. }, e.prototype.captureStream = function (e) {
  1328. if (!e) return this.logger.info("zp.cs.2 no local video"), !1;
  1329. if (e.captureStream) this.localStream = e.captureStream(), this.logger.debug("zp.cs.2 captureStream"); else {
  1330. if (!e.mozCaptureStream) return this.logger.info("zp.cs.2 don't support"), !1;
  1331. this.localStream = e.mozCaptureStream(), this.logger.debug("zp.cs.2 mozCaptureStream")
  1332. }
  1333. return this.videoInfo = {
  1334. width: e.videoWidth,
  1335. height: e.videoHeight,
  1336. frameRate: 0,
  1337. bitRate: 0
  1338. }, this.logger.debug("zp.cs.2 called success"), !0
  1339. }, e.prototype.stopPreview = function () {
  1340. if (this.logger.info("zp.sv.2.1 called"), this.localStream) {
  1341. var e = this.localStream.getTracks();
  1342. e.reverse(), e.forEach(function (e) {
  1343. e.stop()
  1344. }), this.localStream = null, this.localVideo.srcObject = null, this.localVideo = null, this.videoInfo = {}
  1345. }
  1346. }, e
  1347. }();
  1348. t.ZegoPreview = s
  1349. }, function (e, t, r) {
  1350. "use strict";
  1351. Object.defineProperty(t, "__esModule", {value: !0});
  1352. var i = r(0), s = r(2), n = r(12), o = r(3), a = r(4), c = function () {
  1353. function e(e, t, r, n) {
  1354. this.state = i.ENUM_PUBLISH_STATE.stop, this.sessionId = 0, this.waitingICETimeInterval = 5e3, this.waitingAnswerTimeInterval = 5e3, this.candidateInfo = [], this.waitingICETimer = null, this.waitingAnswerTimer = null, this.qualityTimer = null, this.publishQualityList = [], this.maxQualityListCount = 10, this.lastPublishStats = {}, this.reportSeq = s.getSeq(), this.qualityUpload = !1, this.qualityUploadInterval = 3e4, this.qualityUploadLastTime = 0, this.qualitySeq = 0, this.maxRetryCount = 3, this.currentRetryCount = 0, this.retryState = i.ENUM_RETRY_STATE.didNotStart, this.waitingServerTimerInterval = 3e3, this.waitingServerTimer = null, this.videoInfo = {
  1355. width: 0,
  1356. height: 0,
  1357. frameRate: 0,
  1358. bitRate: 0
  1359. }, this.offerSeq = 0, this.qualityCount = 0, this.closeSessionSignal = !1, this.audioBitRate = 48e3, this.localSdpRevert = !1, this.videoDecodeType = "H264", this.logger = e, this.signal = t, this.dataReport = r, this.qualityTimeInterval = n, this.audioMixing = new o.audioMixUtil(e), r.newReport(this.reportSeq)
  1360. }
  1361. return e.prototype.publishStateUpdateError = function (e) {
  1362. 0 != this.sessionId && this.shouldSendCloseSession(e) && (this.signal.sendCloseSession(s.getSeq(), this.sessionId, 1), this.closeSessionSignal = !0), this.state = i.ENUM_PUBLISH_STATE.stop, this.onPublishStateUpdate(s.ENUM_PUBLISH_STATE_UPDATE.error, this.streamId, e), this.resetPublish()
  1363. }, e.prototype.resetPublish = function () {
  1364. this.logger.info("zp.rp.0 call"), this.streamId = null, this.state = i.ENUM_PUBLISH_STATE.stop, null == this.peerConnection && null == this.peerConnection || (this.peerConnection.close(), this.peerConnection = null), null != this.waitingAnswerTimer && (clearTimeout(this.waitingAnswerTimer), this.waitingAnswerTimer = null), null != this.waitingICETimer && (clearTimeout(this.waitingICETimer), this.waitingICETimer = null), this.clearPublishQualityTimer(), this.signal && (this.signal.unregisterPushCallback("CandidateInfoPush", this.sessionId), this.signal.unregisterPushCallback("MediaDescPush", this.sessionId), this.signal.unregisterPushCallback("CloseSessionPush", this.sessionId)), this.sessionSeq = 0, this.offerSeq = 0, this.candidateInfo = [], this.publishQualityList = [], this.qualityUploadLastTime = 0, this.currentRetryCount = 0, this.retryState = i.ENUM_RETRY_STATE.didNotStart, this.clearTryPublishTimer()
  1365. }, e.prototype.clearTryPublishTimer = function () {
  1366. null != this.waitingServerTimer && (clearTimeout(this.waitingServerTimer), this.waitingServerTimer = null)
  1367. }, e.prototype.clearPublishQualityTimer = function () {
  1368. null != this.qualityTimer && (clearInterval(this.qualityTimer), this.qualityTimer = null), this.lastPublishStats = {}, this.qualityCount = 0
  1369. }, e.prototype.shouldSendCloseSession = function (e) {
  1370. return this.state != i.ENUM_PUBLISH_STATE.stop && this.state != i.ENUM_PUBLISH_STATE.waitingSessionRsp
  1371. }, e.prototype.startPublish = function (e, t, r, n) {
  1372. var o = this;
  1373. this.logger.info("zp.sp.0 called"), e ? (this.streamId = e, this.localStream = t, r && (this.videoInfo = r), n && n.audioBitRate && (this.audioBitRate = n.audioBitRate), n && n.videoDecodeType && (this.videoDecodeType = n.videoDecodeType), this.sessionSeq = s.getSeq(), this.dataReport.eventStart(this.reportSeq, "CreateSession"), this.signal.createSession(this.sessionSeq, 0, 0, e, n && n.streamParams, function (e, t, r) {
  1374. o.dataReport.eventEndWithMsg(o.reportSeq, "CreateSession", {sessionId: r.session_id}), o.logger.info("zp.sp.0 sessionId:" + r.session_id), o.sessionSeq == e ? 0 !== r.result ? (o.logger.error("zp.sp.0 create session failed " + r.result), o.publishStateUpdateError(s.publishErrorList.CREATE_SESSION_ERROR)) : (o.sessionId = r.session_id, o.logger.debug("zp.sp.0 create session success " + o.sessionId), o.onCreatePublishSessionSuccess(r)) : o.logger.error("zp.sp.0 seq is not match.")
  1375. }, function (e, t) {
  1376. o.dataReport.eventEndWithMsg(o.reportSeq, "CreateSession", {error: e}), o.publishStateUpdateError(s.publishErrorList.SEND_SESSION_TIMEOUT)
  1377. }), this.state = i.ENUM_PUBLISH_STATE.waitingSessionRsp, this.logger.debug("zp.sp.0 called success")) : this.logger.error("zp.sp.0 streamId is null")
  1378. }, e.prototype.onCreatePublishSessionSuccess = function (e) {
  1379. var t = this;
  1380. this.logger.info("zp.ops.0 called");
  1381. var r = [];
  1382. e.turn_server && r.push(e.turn_server), e.stun_server && r.push(e.stun_server);
  1383. var i = {
  1384. iceTransportPolicy: "relay",
  1385. iceServers: [{urls: r, username: e.turn_username, credential: e.turn_auth_key}]
  1386. };
  1387. this.logger.info("zp.ops.0 username: " + e.turn_username), this.logger.info("zp.ops.0 credential: " + e.turn_auth_key), this.peerConnection = new RTCPeerConnection(i), this.peerConnection.onicecandidate = function (e) {
  1388. t.onIceCandidate(e)
  1389. }, this.peerConnection.onsignalingstatechange = function (e) {
  1390. t.onConnectionStateChange(e)
  1391. }, this.peerConnection.oniceconnectionstatechange = function (e) {
  1392. t.onIceConnectionStateChange(e)
  1393. };
  1394. var n = [], o = [];
  1395. this.localStream && (this.localStream.getTracks().forEach(function (e) {
  1396. t.peerConnection.addTrack(e, t.localStream)
  1397. }), n = this.localStream.getVideoTracks(), o = this.localStream.getAudioTracks(), console.warn("getConstraints", o && o[0] && o[0].getConstraints && o[0].getConstraints()), n.length > 0 && this.logger.info("zp.ops.0 video device: " + n[0].label), o.length > 0 && this.logger.info("zp.ops.0 audio device: " + o[0].label));
  1398. var a = {offerToReceiveAudio: o.length > 0 ? 1 : 0, offerToReceiveVideo: n.length > 0 ? 1 : 0};
  1399. this.logger.info("zp.ops.0 createOffer: " + a), this.dataReport.eventStart(this.reportSeq, "CreateOffer"), this.peerConnection.createOffer(a).then(function (e) {
  1400. t.dataReport.eventEnd(t.reportSeq, "CreateOffer"), t.onCreateOfferSuccess(e)
  1401. }, function (e) {
  1402. t.dataReport.eventEndWithMsg(t.reportSeq, "CreateOffer", {error: e.toString()}), t.logger.error("zp.ops.0 create offer error " + e.toString()), t.publishStateUpdateError(s.publishErrorList.CREATE_OFFER_ERROR)
  1403. }), this.signal.registerPushCallback("CandidateInfoPush", this.sessionId, function (e, r, i) {
  1404. t.onRecvCandidateInfo(e, r, i)
  1405. }), this.signal.registerPushCallback("CloseSessionPush", this.sessionId, function (e, r, i) {
  1406. t.onRecvCloseSession(e, r, i)
  1407. }), this.signal.registerPushCallback("MediaDescPush", this.sessionId, function (e, r, i) {
  1408. t.onRecvMediaDescription(e, r, i)
  1409. }), this.signal.registerPushCallback("SessionResetPush", this.sessionId, function (e, r, i) {
  1410. t.onRecvResetSession(e, r, i)
  1411. }), this.logger.debug("zp.ops.0 call success")
  1412. }, e.prototype.onCreateOfferSuccess = function (e) {
  1413. var t = this;
  1414. 0 != this.videoInfo.bitRate && (e.sdp = this.updateBandwidthRestriction(e.sdp, this.videoInfo.bitRate)), e.sdp = e.sdp.replace(/sendrecv/g, "sendonly"), e.sdp = e.sdp.replace(/useinbandfec=\d+/, "maxaveragebitrate=" + this.audioBitRate), /m=video[\s\S]*m=audio/.test(e.sdp) && (this.localSdpRevert = !0), e.sdp = a.sdpUtil.getSDPByVideDecodeType(e.sdp, this.videoDecodeType), this.logger.info("zp.oco.0 localSdp1 " + e.sdp.substr(0, e.sdp.length / 2)), this.logger.info("zp.oco.0 localSdp2 " + e.sdp.substr(e.sdp.length / 2)), this.dataReport.eventStart(this.reportSeq, "SetLocalDescription"), this.peerConnection.setLocalDescription(e).then(function () {
  1415. t.dataReport.eventEnd(t.reportSeq, "SetLocalDescription"), t.onSetLocalDescriptionSuccess(e)
  1416. }, function (e) {
  1417. t.dataReport.eventEndWithMsg(t.reportSeq, "SetLocalDescription", {error: e.toString()}), t.logger.error("zp.oco.0 error " + e.toString()), t.publishStateUpdateError(s.publishErrorList.SET_LOCAL_DESC_ERROR)
  1418. })
  1419. }, e.prototype.updateBandwidthRestriction = function (e, t) {
  1420. var r = "AS";
  1421. return "firefox" === n.browserDetails.browser && (t = 1e3 * (t >>> 0), r = "TIAS"), e = -1 === e.indexOf("b=" + r + ":") ? (e = e.replace(/c=IN (.*)\r\n/g, "c=IN $1\r\nb=" + r + ":" + t + "\r\n")).replace("b=" + r + ":" + t + "\r\n", "") : (e = e.replace(new RegExp("b=" + r + ":.*\r\n", "g"), "b=" + r + ":" + t + "\r\n")).replace("b=" + r + ":" + t + "\r\n", "")
  1422. }, e.prototype.onSetLocalDescriptionSuccess = function (e) {
  1423. var t = this;
  1424. this.logger.info("zp.osd.0 success");
  1425. var r = {
  1426. sdp: e.sdp,
  1427. width: this.videoInfo.width,
  1428. height: this.videoInfo.height,
  1429. frameRate: this.videoInfo.frameRate,
  1430. video_min_kpbs: this.videoInfo.bitRate,
  1431. video_max_kpbs: this.videoInfo.bitRate,
  1432. audio_kpbs: 48
  1433. };
  1434. this.offerSeq = s.getSeq(), this.dataReport.eventStart(this.reportSeq, "SendMediaDesc"), this.signal.sendMediaDesc(this.offerSeq, this.sessionId, 0, r, function (e, r, n) {
  1435. t.offerSeq == e && t.sessionId == r ? (t.logger.info("zp.osd.0 send success"), t.dataReport.eventEnd(t.reportSeq, "SendMediaDesc"), t.waitingAnswerTimer = setTimeout(function () {
  1436. t.state == i.ENUM_PUBLISH_STATE.waitingServerAnswer && (t.logger.error("zp.osd.0 waiting timeout"), t.publishStateUpdateError(s.publishErrorList.SERVER_MEDIA_DESC_TIMEOUT))
  1437. }, t.waitingAnswerTimeInterval), t.state = i.ENUM_PUBLISH_STATE.waitingServerAnswer) : t.logger.error("zp.osd.0 seq or sessionId is not equal")
  1438. }, function (e, r) {
  1439. t.dataReport.eventEndWithMsg(t.reportSeq, "SendMediaDesc", {error: e}), t.publishStateUpdateError(s.publishErrorList.SEND_MEDIA_DESC_TIMEOUT)
  1440. }), this.state = i.ENUM_PUBLISH_STATE.waitingOffserRsp, this.logger.debug("zp.osd.0 call success")
  1441. }, e.prototype.onRecvMediaDescription = function (e, t, r) {
  1442. this.logger.info("zp.ormd.0 received"), this.state == i.ENUM_PUBLISH_STATE.waitingServerAnswer ? (null != this.waitingAnswerTimer && (clearTimeout(this.waitingAnswerTimer), this.waitingAnswerTimer = null), this.dataReport.addEvent(this.reportSeq, "RecvMediaDesc"), this.signal.sendMediaDescAck(e, this.sessionId, 0), 1 == r.type ? this.onGetRemoteOfferSucceses(r.sdp) : this.publishStateUpdateError(s.publishErrorList.SERVER_MEDIA_DESC_ERROR)) : this.logger.info("zp.ormd.0 current state " + this.state + " not allowed")
  1443. }, e.prototype.onGetRemoteOfferSucceses = function (e) {
  1444. var t = this;
  1445. if (48e3 !== this.audioBitRate && (e = e.replace(/maxaveragebitrate=(\d+)/, "maxaveragebitrate=" + this.audioBitRate)), this.localSdpRevert) {
  1446. var r = [/[\s\S]*m=audio/.exec(e)[0].replace("m=audio", ""), /m=video[\s\S]*/.exec(e)[0], /m=audio[\s\S]*m=video/.exec(e)[0].replace("m=video", "")],
  1447. n = r[0], o = r[1], a = r[2], c = /a=group:BUNDLE\s+(\w+)\s+(\w+)/.exec(n);
  1448. e = (n = n.replace(/a=group:BUNDLE\s+(\w+)\s+(\w+)/, "a=group:BUNDLE " + c[2] + " " + c[1])) + o + a
  1449. }
  1450. this.logger.info("zp.oro.0 remoteSdp:", e);
  1451. var l = {
  1452. type: "answer", sdp: e, toJSON: function () {
  1453. }
  1454. };
  1455. this.dataReport.eventStart(this.reportSeq, "SetRemoteDescription"), this.peerConnection.setRemoteDescription(new RTCSessionDescription(l)).then(function () {
  1456. t.logger.info("zp.oro.0 set success"), t.dataReport.eventEnd(t.reportSeq, "SetRemoteDescription")
  1457. }, function (e) {
  1458. t.logger.error("zp.oro.0 failed: " + e.toString()), t.dataReport.eventEndWithMsg(t.reportSeq, "SetRemoteDescription", {error: e.toString()}), t.publishStateUpdateError(s.publishErrorList.SET_REMOTE_DESC_ERROR)
  1459. }), this.sendCandidateInfo(this.candidateInfo), this.candidateInfo = [], this.state = i.ENUM_PUBLISH_STATE.waitingServerICE, this.waitingICETimer = setTimeout(function () {
  1460. t.state == i.ENUM_PUBLISH_STATE.waitingServerICE && (t.logger.error("zp.orod.0 waiting server timeout"), t.publishStateUpdateError(s.publishErrorList.SERVER_CANDIDATE_TIMEOUT))
  1461. }, this.waitingICETimeInterval), this.logger.debug("zp.oro.0 call success")
  1462. }, e.prototype.onIceConnectionStateChange = function (e) {
  1463. this.state != i.ENUM_PUBLISH_STATE.stop && null != this.peerConnection && (this.logger.info("zp.oics.0 stateChanged " + this.peerConnection.iceConnectionState), "connected" === this.peerConnection.iceConnectionState ? (this.logger.info("zp.oics.0 connected state " + this.state), this.dataReport.eventEnd(this.reportSeq, "IceConnected"), this.state != i.ENUM_PUBLISH_STATE.publishing && this.onPublishStateUpdate(s.ENUM_PUBLISH_STATE_UPDATE.start, this.streamId), this.state = i.ENUM_PUBLISH_STATE.publishing, this.retryState != i.ENUM_RETRY_STATE.didNotStart && (this.retryState = i.ENUM_RETRY_STATE.finished, this.currentRetryCount = 0), this.dataReport.eventStart(this.reportSeq, "PublishState"), this.setPublishQualityTimer()) : "closed" === this.peerConnection.iceConnectionState ? (this.dataReport.addEvent(this.reportSeq, "IceClosed"), this.checkPublishConnectionFailedState(this.peerConnection.iceConnectionState)) : "failed" === this.peerConnection.iceConnectionState && (this.dataReport.addEvent(this.reportSeq, "IceFailed"), this.checkPublishConnectionFailedState(this.peerConnection.iceConnectionState)))
  1464. }, e.prototype.onIceCandidate = function (e) {
  1465. if (this.logger.info("zp.oic.0 candidate" + e.candidate), e.candidate) if (this.logger.info("zp.oic.0 candidate" + e.candidate.candidate), this.state < i.ENUM_PUBLISH_STATE.waitingServerICE || this.state == i.ENUM_PUBLISH_STATE.stop) this.candidateInfo.push({
  1466. candidate: e.candidate.candidate,
  1467. sdpMid: e.candidate.sdpMid,
  1468. sdpMLineIndex: e.candidate.sdpMLineIndex
  1469. }); else {
  1470. var t = {
  1471. candidate: e.candidate.candidate,
  1472. sdpMid: e.candidate.sdpMid,
  1473. sdpMLineIndex: e.candidate.sdpMLineIndex
  1474. };
  1475. this.sendCandidateInfo([t])
  1476. }
  1477. }, e.prototype.sendCandidateInfo = function (e) {
  1478. var t = this;
  1479. this.logger.info("zp.sci.0 called"), !(e = e.filter(function (e) {
  1480. return e.candidate.indexOf("relay") > 0
  1481. })) || e.length < 1 ? this.logger.info("zp.sci.0 cancelled") : (this.dataReport.eventStart(this.reportSeq, "SendIceCandidate"), this.signal.sendCandidateInfo(s.getSeq(), this.sessionId, e, function (e, r, i) {
  1482. t.logger.debug("zp.sci.0 send success"), t.dataReport.eventEnd(t.reportSeq, "SendIceCandidate")
  1483. }, function (e, r) {
  1484. t.logger.error("zp.sci.0 failed to send: " + e.toString()), t.dataReport.eventEndWithMsg(t.reportSeq, "SendIceCandidate", {error: e}), t.publishStateUpdateError(s.publishErrorList.SEND_CANDIDATE_TIMEOUT)
  1485. }))
  1486. }, e.prototype.onConnectionStateChange = function (e) {
  1487. this.logger.info("zp.ocs.0 called " + e.target.signalingState)
  1488. }, e.prototype.onRecvCandidateInfo = function (e, t, r) {
  1489. var n = this;
  1490. if (this.logger.debug("zp.oci.0 received " + r.infos.length), this.state == i.ENUM_PUBLISH_STATE.waitingServerICE) {
  1491. null != this.waitingICETimer && (clearTimeout(this.waitingICETimer), this.waitingICETimer = null), this.dataReport.addEvent(this.reportSeq, "RecvIceCandidate"), this.signal.sendCandidateInfoAck(e, this.sessionId, 0);
  1492. for (var o = 0; o < r.infos.length; o++) {
  1493. var a = {
  1494. sdpMid: r.infos[o].sdpMid,
  1495. sdpMLineIndex: r.infos[o].sdpMLineIndex,
  1496. candidate: r.infos[o].candidate
  1497. };
  1498. this.logger.debug("zp.orci.0 candidate " + a.candidate), this.peerConnection.addIceCandidate(new RTCIceCandidate(a)).then(function () {
  1499. n.logger.debug("zp.oci.0 add success")
  1500. }, function (e) {
  1501. n.logger.error("zp.oci.0 add error " + e.toString()), n.publishStateUpdateError(s.publishErrorList.SERVER_CANDIDATE_ERROR)
  1502. })
  1503. }
  1504. this.state = i.ENUM_PUBLISH_STATE.connecting, this.dataReport.eventStart(this.reportSeq, "IceConnected")
  1505. } else this.logger.info("zp.oci.0 current state " + this.state + " not allowed")
  1506. }, e.prototype.onRecvCloseSession = function (e, t, r) {
  1507. this.logger.info("zp.orcs.0 reason: " + r.reason), this.dataReport.addEvent(this.reportSeq, "RecvCloseSession"), this.signal.sendCloseSessionAck(e, this.sessionId, 0);
  1508. var i = JSON.parse(JSON.stringify(s.publishErrorList.SESSION_CLOSED));
  1509. i.msg += r.reason, this.publishStateUpdateError(i)
  1510. }, e.prototype.onRecvResetSession = function (e, t, r) {
  1511. this.logger.info("zp.orrs.0 received "), t == this.sessionId ? (this.dataReport.addEvent(this.reportSeq, "RecvResetSession"), this.shouldRetryPublish() && this.startRetryPublish()) : this.logger.error("zp.orrs.0 cannot find session")
  1512. }, e.prototype.shouldRetryPublish = function () {
  1513. return this.retryState == i.ENUM_RETRY_STATE.didNotStart && this.state != i.ENUM_PUBLISH_STATE.publishing ? (this.logger.info("zp.srp.0.0 connection didn't success"), !1) : this.retryState == i.ENUM_RETRY_STATE.retrying ? (this.logger.info("zp.srp.0.0 already retrying"), !1) : this.currentRetryCount > this.maxRetryCount ? (this.logger.info("zp.srp.0.0 beyond max"), !1) : (this.logger.info("zp.srp.1.0 call success"), !0)
  1514. }, e.prototype.startRetryPublish = function () {
  1515. this.logger.info("zp.srp.0 call");
  1516. var e = this.streamId;
  1517. e ? (this.resetPublish(), this.tryStartPublish(e)) : this.logger.info("zp.srp.0 no streamid")
  1518. }, e.prototype.tryStartPublish = function (e) {
  1519. var t = this;
  1520. if (this.logger.info("zp.tsp.0 call"), this.clearTryPublishTimer(), this.streamId = e, this.currentRetryCount > this.maxRetryCount) return this.logger.info("zp.tsp.0 beyond max limit"), void this.publishStateUpdateError(s.publishErrorList.WEBSOCKET_ERROR);
  1521. this.retryState = i.ENUM_RETRY_STATE.retrying, this.currentRetryCount += 1, this.signal.isServerConnected() ? (this.logger.debug("zp.tsp.0 signal connected"), this.startPublish(e, this.localStream, this.videoInfo)) : (this.logger.debug("zp.tsp.0 signal server not connected"), this.waitingAnswerTimer = setTimeout(function () {
  1522. t.tryStartPublish(e)
  1523. }, this.waitingAnswerTimeInterval))
  1524. }, e.prototype.checkPublishConnectionFailedState = function (e) {
  1525. var t = null;
  1526. "failed" == e ? t = s.publishErrorList.MEDIA_CONNECTION_FAILED : "closed" == e && (t = s.publishErrorList.MEDIA_CONNECTION_CLOSED), null != t && (this.state != i.ENUM_PUBLISH_STATE.publishing && this.retryState == i.ENUM_PUBLISH_STATE.didNotStart ? (this.logger.info("zp.oics.0 state " + this.state + " retryState " + this.retryState + " connectionState " + e), this.publishStateUpdateError(t)) : this.shouldRetryPublish() ? (this.onPublishStateUpdate(s.ENUM_PUBLISH_STATE_UPDATE.retry, this.streamId), this.startRetryPublish()) : this.publishStateUpdateError(t))
  1527. }, e.prototype.setPublishQualityTimer = function () {
  1528. var e = this;
  1529. null == this.qualityTimer && (this.logger.debug("zp.spq.0 called"), this.clearPublishQualityTimer(), this.qualityTimer = setInterval(function () {
  1530. e.peerConnection && e.peerConnection.getStats(null).then(function (t) {
  1531. e.getPublishStats(t)
  1532. }, function (t) {
  1533. e.logger.info("zp.spq.0 getStats error " + t.toString())
  1534. })
  1535. }, this.qualityTimeInterval), this.lastPublishStats = {
  1536. time: 0,
  1537. audioBytesSent: 0,
  1538. videoBytesSent: 0,
  1539. framesEncoded: 0,
  1540. framesSent: 0
  1541. }, this.qualitySeq = s.getSeq(), this.qualityCount = 0, this.dataReport.newReport(this.qualitySeq))
  1542. }, e.prototype.getPublishStats = function (e) {
  1543. var t = this;
  1544. if (e) {
  1545. var r = {
  1546. audioBitrate: 0,
  1547. videoBitrate: 0,
  1548. videoFPS: 0,
  1549. nackCount: 0,
  1550. pliCount: 0,
  1551. sliCount: 0,
  1552. frameHeight: 0,
  1553. frameWidth: 0,
  1554. videoTransferFPS: 0,
  1555. totalRoundTripTime: 0,
  1556. currentRoundTripTime: 0
  1557. }, i = this.lastPublishStats.time;
  1558. e.forEach(function (e) {
  1559. ("outbound-rtp" == e.type || "ssrc" == e.type && null != e.bytesSent) && "audio" == e.mediaType ? (0 != i && (r.audioBitrate = 8 * (e.bytesSent - t.lastPublishStats.audioBytesSent) / (e.timestamp - i)), r.audioBitrate < 0 && (r.audioBitrate = 0), t.lastPublishStats.audioBytesSent = e.bytesSent, t.lastPublishStats.time = e.timestamp) : ("outbound-rtp" == e.type || "ssrc" == e.type && null != e.bytesSent) && "video" == e.mediaType ? (0 != i && (r.videoBitrate = 8 * (e.bytesSent - t.lastPublishStats.videoBytesSent) / (e.timestamp - i), r.videoFPS = 1e3 * (e.framesEncoded - t.lastPublishStats.framesEncoded) / (e.timestamp - i)), r.videoBitrate < 0 && (r.videoBitrate = 0), r.videoFPS < 0 && (r.videoFPS = 0), r.nackCount = e.nackCount, r.pliCount = e.pliCount, r.sliCount = e.sliCount, t.lastPublishStats.videoBytesSent = e.bytesSent, t.lastPublishStats.framesEncoded = e.framesEncoded, t.lastPublishStats.time = e.timestamp) : "track" == e.type && ("video" == e.kind || e.id.indexOf("video") >= 0) ? (r.frameHeight = e.frameHeight, r.frameWidth = e.frameWidth, 0 != i && (r.videoTransferFPS = 1e3 * (e.framesSent - t.lastPublishStats.framesSent) / (e.timestamp - i)), r.videoTransferFPS < 0 && (r.videoTransferFPS = 0), t.lastPublishStats.framesSent = e.framesSent) : "candidate-pair" == e.type && (null != e.totalRoundTripTime && (r.totalRoundTripTime = e.totalRoundTripTime), null != e.currentRoundTripTime && (r.currentRoundTripTime = e.currentRoundTripTime))
  1560. }), this.uploadPublishQuality(r), 0 != i && this.onPublishQualityUpdate(this.streamId, r)
  1561. }
  1562. }, e.prototype.uploadPublishQuality = function (e) {
  1563. var t = this;
  1564. if (this.qualityUpload) {
  1565. var r = Date.parse(new Date + "");
  1566. (0 == this.qualityUploadLastTime || r - this.qualityUploadLastTime >= this.qualityUploadInterval) && (this.logger.debug("zp.upq.0 upload"), e.stream_type = "publish", e.stream_id = this.streamId, e.timeStamp = r / 1e3, this.signal.QualityReport(s.getSeq(), this.sessionId, e, function (e, r, i) {
  1567. void 0 !== i.report && (t.qualityUpload = i.report, t.qualityUploadInterval = i.report_interval_ms)
  1568. }, function (e, r) {
  1569. t.logger.info("zp.upq.0 upload failed " + e)
  1570. }), this.qualityUploadLastTime = r)
  1571. }
  1572. }, e.prototype.stopPublish = function () {
  1573. this.logger.debug("zp.sp.0.1 called"), this.sessionId && !this.closeSessionSignal && this.signal.sendCloseSession(s.getSeq(), this.sessionId, 0), this.dataReport.eventEndWithMsg(this.reportSeq, "PublishState", {state: this.state + ""}), this.dataReport.addEvent(this.reportSeq, "StopPublish"), this.dataReport.addMsgExt(this.reportSeq, {
  1574. stream: this.streamId,
  1575. sessionId: this.sessionId
  1576. }), this.dataReport.uploadReport(this.reportSeq, "RTCPublishStream"), this.resetPublish()
  1577. }, e.prototype.onPublishStateUpdate = function (e, t, r) {
  1578. }, e.prototype.onPublishQualityUpdate = function (e, t) {
  1579. }, e.prototype.onDisconnect = function () {
  1580. this.logger.info("zp.od.0 call"), this.logger.info("zp.od.0 websocket disconnect"), this.dataReport.addEvent(this.reportSeq, "OnDisconnect"), this.publishStateUpdateError(s.publishErrorList.WEBSOCKET_ERROR)
  1581. }, e.prototype.playEffect = function (e, t, r, i) {
  1582. this.audioMixing.localStream = this.localStream, this.audioMixing.peerConnection = this.peerConnection, this.audioMixing.audioBuffer = t, this.audioMixing.playEffect(e.playTime, e.loop, e.replace, r, i)
  1583. }, e.prototype.pauseEffect = function () {
  1584. this.audioMixing.pauseEffect()
  1585. }, e.prototype.resumeEffect = function () {
  1586. this.audioMixing.resumeEffect()
  1587. }, e.prototype.startMixingAudio = function (e, t) {
  1588. return this.audioMixing.localStream = this.localStream, this.audioMixing.peerConnection = this.peerConnection, this.audioMixing.startMixingAudio(e, t)
  1589. }, e.prototype.stopMixingAudio = function () {
  1590. return this.audioMixing.stopMixingAudio()
  1591. }, e
  1592. }();
  1593. t.ZegoPublish = c
  1594. }, function (e, t, r) {
  1595. var i;
  1596. e.exports = function e(t, r, s) {
  1597. function n(a, c) {
  1598. if (!r[a]) {
  1599. if (!t[a]) {
  1600. var l = "function" == typeof i && i;
  1601. if (!c && l) return i(a, !0);
  1602. if (o) return o(a, !0);
  1603. var d = new Error("Cannot find module '" + a + "'");
  1604. throw d.code = "MODULE_NOT_FOUND", d
  1605. }
  1606. var h = r[a] = {exports: {}};
  1607. t[a][0].call(h.exports, function (e) {
  1608. var r = t[a][1][e];
  1609. return n(r || e)
  1610. }, h, h.exports, e, t, r, s)
  1611. }
  1612. return r[a].exports
  1613. }
  1614. for (var o = "function" == typeof i && i, a = 0; a < s.length; a++) n(s[a]);
  1615. return n
  1616. }({
  1617. 1: [function (e, t, r) {
  1618. "use strict";
  1619. var i = e("./adapter_factory.js"), s = (0, i.adapterFactory)({window: window});
  1620. t.exports = s
  1621. }, {"./adapter_factory.js": 2}], 2: [function (e, t, r) {
  1622. "use strict";
  1623. Object.defineProperty(r, "__esModule", {value: !0}), r.adapterFactory = function () {
  1624. var e = (arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}).window,
  1625. t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {
  1626. shimChrome: !0,
  1627. shimFirefox: !0,
  1628. shimEdge: !0,
  1629. shimSafari: !0
  1630. }, r = s.log, i = s.detectBrowser(e), n = {
  1631. browserDetails: i,
  1632. commonShim: g,
  1633. extractVersion: s.extractVersion,
  1634. disableLog: s.disableLog,
  1635. disableWarnings: s.disableWarnings
  1636. };
  1637. switch (i.browser) {
  1638. case"chrome":
  1639. if (!o || !o.shimPeerConnection || !t.shimChrome) return r("Chrome shim is not included in this adapter release."), n;
  1640. r("adapter.js shimming chrome."), n.browserShim = o, o.shimGetUserMedia(e), o.shimMediaStream(e), o.shimPeerConnection(e), o.shimOnTrack(e), o.shimAddTrackRemoveTrack(e), o.shimGetSendersWithDtmf(e), o.shimGetStats(e), o.shimSenderReceiverGetStats(e), o.fixNegotiationNeeded(e), g.shimRTCIceCandidate(e), g.shimConnectionState(e), g.shimMaxMessageSize(e), g.shimSendThrowTypeError(e), g.removeAllowExtmapMixed(e);
  1641. break;
  1642. case"firefox":
  1643. if (!d || !d.shimPeerConnection || !t.shimFirefox) return r("Firefox shim is not included in this adapter release."), n;
  1644. r("adapter.js shimming firefox."), n.browserShim = d, d.shimGetUserMedia(e), d.shimPeerConnection(e), d.shimOnTrack(e), d.shimRemoveStream(e), d.shimSenderGetStats(e), d.shimReceiverGetStats(e), d.shimRTCDataChannel(e), g.shimRTCIceCandidate(e), g.shimConnectionState(e), g.shimMaxMessageSize(e), g.shimSendThrowTypeError(e);
  1645. break;
  1646. case"edge":
  1647. if (!c || !c.shimPeerConnection || !t.shimEdge) return r("MS edge shim is not included in this adapter release."), n;
  1648. r("adapter.js shimming edge."), n.browserShim = c, c.shimGetUserMedia(e), c.shimGetDisplayMedia(e), c.shimPeerConnection(e), c.shimReplaceTrack(e), g.shimMaxMessageSize(e), g.shimSendThrowTypeError(e);
  1649. break;
  1650. case"safari":
  1651. if (!u || !t.shimSafari) return r("Safari shim is not included in this adapter release."), n;
  1652. r("adapter.js shimming safari."), n.browserShim = u, u.shimRTCIceServerUrls(e), u.shimCreateOfferLegacy(e), u.shimCallbacksAPI(e), u.shimLocalStreamsAPI(e), u.shimRemoteStreamsAPI(e), u.shimTrackEventTransceiver(e), u.shimGetUserMedia(e), g.shimRTCIceCandidate(e), g.shimMaxMessageSize(e), g.shimSendThrowTypeError(e), g.removeAllowExtmapMixed(e);
  1653. break;
  1654. default:
  1655. r("Unsupported browser!")
  1656. }
  1657. return n
  1658. };
  1659. var i = e("./utils"), s = f(i), n = e("./chrome/chrome_shim"), o = f(n), a = e("./edge/edge_shim"),
  1660. c = f(a), l = e("./firefox/firefox_shim"), d = f(l), h = e("./safari/safari_shim"), u = f(h),
  1661. p = e("./common_shim"), g = f(p);
  1662. function f(e) {
  1663. if (e && e.__esModule) return e;
  1664. var t = {};
  1665. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  1666. return t.default = e, t
  1667. }
  1668. }, {
  1669. "./chrome/chrome_shim": 3,
  1670. "./common_shim": 6,
  1671. "./edge/edge_shim": 7,
  1672. "./firefox/firefox_shim": 11,
  1673. "./safari/safari_shim": 14,
  1674. "./utils": 15
  1675. }], 3: [function (e, t, r) {
  1676. "use strict";
  1677. Object.defineProperty(r, "__esModule", {value: !0}), r.shimGetDisplayMedia = r.shimGetUserMedia = void 0;
  1678. var i = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  1679. return typeof e
  1680. } : function (e) {
  1681. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  1682. }, s = e("./getusermedia");
  1683. Object.defineProperty(r, "shimGetUserMedia", {
  1684. enumerable: !0, get: function () {
  1685. return s.shimGetUserMedia
  1686. }
  1687. });
  1688. var n = e("./getdisplaymedia");
  1689. Object.defineProperty(r, "shimGetDisplayMedia", {
  1690. enumerable: !0, get: function () {
  1691. return n.shimGetDisplayMedia
  1692. }
  1693. }), r.shimMediaStream = function (e) {
  1694. e.MediaStream = e.MediaStream || e.webkitMediaStream
  1695. }, r.shimOnTrack = function (e) {
  1696. if ("object" !== (void 0 === e ? "undefined" : i(e)) || !e.RTCPeerConnection || "ontrack" in e.RTCPeerConnection.prototype) a.wrapPeerConnectionEvent(e, "track", function (e) {
  1697. return e.transceiver || Object.defineProperty(e, "transceiver", {value: {receiver: e.receiver}}), e
  1698. }); else {
  1699. Object.defineProperty(e.RTCPeerConnection.prototype, "ontrack", {
  1700. get: function () {
  1701. return this._ontrack
  1702. }, set: function (e) {
  1703. this._ontrack && this.removeEventListener("track", this._ontrack), this.addEventListener("track", this._ontrack = e)
  1704. }, enumerable: !0, configurable: !0
  1705. });
  1706. var t = e.RTCPeerConnection.prototype.setRemoteDescription;
  1707. e.RTCPeerConnection.prototype.setRemoteDescription = function () {
  1708. var r = this;
  1709. return this._ontrackpoly || (this._ontrackpoly = function (t) {
  1710. t.stream.addEventListener("addtrack", function (i) {
  1711. var s = void 0;
  1712. s = e.RTCPeerConnection.prototype.getReceivers ? r.getReceivers().find(function (e) {
  1713. return e.track && e.track.id === i.track.id
  1714. }) : {track: i.track};
  1715. var n = new Event("track");
  1716. n.track = i.track, n.receiver = s, n.transceiver = {receiver: s}, n.streams = [t.stream], r.dispatchEvent(n)
  1717. }), t.stream.getTracks().forEach(function (i) {
  1718. var s = void 0;
  1719. s = e.RTCPeerConnection.prototype.getReceivers ? r.getReceivers().find(function (e) {
  1720. return e.track && e.track.id === i.id
  1721. }) : {track: i};
  1722. var n = new Event("track");
  1723. n.track = i, n.receiver = s, n.transceiver = {receiver: s}, n.streams = [t.stream], r.dispatchEvent(n)
  1724. })
  1725. }, this.addEventListener("addstream", this._ontrackpoly)), t.apply(this, arguments)
  1726. }
  1727. }
  1728. }, r.shimGetSendersWithDtmf = function (e) {
  1729. if ("object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection && !("getSenders" in e.RTCPeerConnection.prototype) && "createDTMFSender" in e.RTCPeerConnection.prototype) {
  1730. var t = function (e, t) {
  1731. return {
  1732. track: t, get dtmf() {
  1733. return void 0 === this._dtmf && ("audio" === t.kind ? this._dtmf = e.createDTMFSender(t) : this._dtmf = null), this._dtmf
  1734. }, _pc: e
  1735. }
  1736. };
  1737. if (!e.RTCPeerConnection.prototype.getSenders) {
  1738. e.RTCPeerConnection.prototype.getSenders = function () {
  1739. return this._senders = this._senders || [], this._senders.slice()
  1740. };
  1741. var r = e.RTCPeerConnection.prototype.addTrack;
  1742. e.RTCPeerConnection.prototype.addTrack = function (e, i) {
  1743. var s = r.apply(this, arguments);
  1744. return s || (s = t(this, e), this._senders.push(s)), s
  1745. };
  1746. var s = e.RTCPeerConnection.prototype.removeTrack;
  1747. e.RTCPeerConnection.prototype.removeTrack = function (e) {
  1748. s.apply(this, arguments);
  1749. var t = this._senders.indexOf(e);
  1750. -1 !== t && this._senders.splice(t, 1)
  1751. }
  1752. }
  1753. var n = e.RTCPeerConnection.prototype.addStream;
  1754. e.RTCPeerConnection.prototype.addStream = function (e) {
  1755. var r = this;
  1756. this._senders = this._senders || [], n.apply(this, [e]), e.getTracks().forEach(function (e) {
  1757. r._senders.push(t(r, e))
  1758. })
  1759. };
  1760. var o = e.RTCPeerConnection.prototype.removeStream;
  1761. e.RTCPeerConnection.prototype.removeStream = function (e) {
  1762. var t = this;
  1763. this._senders = this._senders || [], o.apply(this, [e]), e.getTracks().forEach(function (e) {
  1764. var r = t._senders.find(function (t) {
  1765. return t.track === e
  1766. });
  1767. r && t._senders.splice(t._senders.indexOf(r), 1)
  1768. })
  1769. }
  1770. } else if ("object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection && "getSenders" in e.RTCPeerConnection.prototype && "createDTMFSender" in e.RTCPeerConnection.prototype && e.RTCRtpSender && !("dtmf" in e.RTCRtpSender.prototype)) {
  1771. var a = e.RTCPeerConnection.prototype.getSenders;
  1772. e.RTCPeerConnection.prototype.getSenders = function () {
  1773. var e = this, t = a.apply(this, []);
  1774. return t.forEach(function (t) {
  1775. return t._pc = e
  1776. }), t
  1777. }, Object.defineProperty(e.RTCRtpSender.prototype, "dtmf", {
  1778. get: function () {
  1779. return void 0 === this._dtmf && ("audio" === this.track.kind ? this._dtmf = this._pc.createDTMFSender(this.track) : this._dtmf = null), this._dtmf
  1780. }
  1781. })
  1782. }
  1783. }, r.shimGetStats = function (e) {
  1784. if (e.RTCPeerConnection) {
  1785. var t = e.RTCPeerConnection.prototype.getStats;
  1786. e.RTCPeerConnection.prototype.getStats = function (e, r, i) {
  1787. var s = this, n = arguments;
  1788. if (arguments.length > 0 && "function" == typeof e) return t.apply(this, arguments);
  1789. if (0 === t.length && (0 === arguments.length || "function" != typeof arguments[0])) return t.apply(this, []);
  1790. var o = function (e) {
  1791. var t = {}, r = e.result();
  1792. return r.forEach(function (e) {
  1793. var r = {
  1794. id: e.id,
  1795. timestamp: e.timestamp,
  1796. type: {
  1797. localcandidate: "local-candidate",
  1798. remotecandidate: "remote-candidate"
  1799. }[e.type] || e.type
  1800. };
  1801. e.names().forEach(function (t) {
  1802. r[t] = e.stat(t)
  1803. }), t[r.id] = r
  1804. }), t
  1805. }, a = function (e) {
  1806. return new Map(Object.keys(e).map(function (t) {
  1807. return [t, e[t]]
  1808. }))
  1809. };
  1810. return arguments.length >= 2 ? t.apply(this, [function (e) {
  1811. n[1](a(o(e)))
  1812. }, arguments[0]]) : new Promise(function (e, r) {
  1813. t.apply(s, [function (t) {
  1814. e(a(o(t)))
  1815. }, r])
  1816. }).then(r, i)
  1817. }
  1818. }
  1819. }, r.shimSenderReceiverGetStats = function (e) {
  1820. if ("object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection && e.RTCRtpSender && e.RTCRtpReceiver) {
  1821. if (!("getStats" in e.RTCRtpSender.prototype)) {
  1822. var t = e.RTCPeerConnection.prototype.getSenders;
  1823. t && (e.RTCPeerConnection.prototype.getSenders = function () {
  1824. var e = this, r = t.apply(this, []);
  1825. return r.forEach(function (t) {
  1826. return t._pc = e
  1827. }), r
  1828. });
  1829. var r = e.RTCPeerConnection.prototype.addTrack;
  1830. r && (e.RTCPeerConnection.prototype.addTrack = function () {
  1831. var e = r.apply(this, arguments);
  1832. return e._pc = this, e
  1833. }), e.RTCRtpSender.prototype.getStats = function () {
  1834. var e = this;
  1835. return this._pc.getStats().then(function (t) {
  1836. return a.filterStats(t, e.track, !0)
  1837. })
  1838. }
  1839. }
  1840. if (!("getStats" in e.RTCRtpReceiver.prototype)) {
  1841. var s = e.RTCPeerConnection.prototype.getReceivers;
  1842. s && (e.RTCPeerConnection.prototype.getReceivers = function () {
  1843. var e = this, t = s.apply(this, []);
  1844. return t.forEach(function (t) {
  1845. return t._pc = e
  1846. }), t
  1847. }), a.wrapPeerConnectionEvent(e, "track", function (e) {
  1848. return e.receiver._pc = e.srcElement, e
  1849. }), e.RTCRtpReceiver.prototype.getStats = function () {
  1850. var e = this;
  1851. return this._pc.getStats().then(function (t) {
  1852. return a.filterStats(t, e.track, !1)
  1853. })
  1854. }
  1855. }
  1856. if ("getStats" in e.RTCRtpSender.prototype && "getStats" in e.RTCRtpReceiver.prototype) {
  1857. var n = e.RTCPeerConnection.prototype.getStats;
  1858. e.RTCPeerConnection.prototype.getStats = function () {
  1859. if (arguments.length > 0 && arguments[0] instanceof e.MediaStreamTrack) {
  1860. var t = arguments[0], r = void 0, i = void 0, s = void 0;
  1861. return this.getSenders().forEach(function (e) {
  1862. e.track === t && (r ? s = !0 : r = e)
  1863. }), this.getReceivers().forEach(function (e) {
  1864. return e.track === t && (i ? s = !0 : i = e), e.track === t
  1865. }), s || r && i ? Promise.reject(new DOMException("There are more than one sender or receiver for the track.", "InvalidAccessError")) : r ? r.getStats() : i ? i.getStats() : Promise.reject(new DOMException("There is no sender or receiver for the track.", "InvalidAccessError"))
  1866. }
  1867. return n.apply(this, arguments)
  1868. }
  1869. }
  1870. }
  1871. }, r.shimAddTrackRemoveTrackWithNative = c, r.shimAddTrackRemoveTrack = function (e) {
  1872. if (e.RTCPeerConnection) {
  1873. var t = a.detectBrowser(e);
  1874. if (e.RTCPeerConnection.prototype.addTrack && t.version >= 65) return c(e);
  1875. var r = e.RTCPeerConnection.prototype.getLocalStreams;
  1876. e.RTCPeerConnection.prototype.getLocalStreams = function () {
  1877. var e = this, t = r.apply(this);
  1878. return this._reverseStreams = this._reverseStreams || {}, t.map(function (t) {
  1879. return e._reverseStreams[t.id]
  1880. })
  1881. };
  1882. var i = e.RTCPeerConnection.prototype.addStream;
  1883. e.RTCPeerConnection.prototype.addStream = function (t) {
  1884. var r = this;
  1885. if (this._streams = this._streams || {}, this._reverseStreams = this._reverseStreams || {}, t.getTracks().forEach(function (e) {
  1886. var t = r.getSenders().find(function (t) {
  1887. return t.track === e
  1888. });
  1889. if (t) throw new DOMException("Track already exists.", "InvalidAccessError")
  1890. }), !this._reverseStreams[t.id]) {
  1891. var s = new e.MediaStream(t.getTracks());
  1892. this._streams[t.id] = s, this._reverseStreams[s.id] = t, t = s
  1893. }
  1894. i.apply(this, [t])
  1895. };
  1896. var s = e.RTCPeerConnection.prototype.removeStream;
  1897. e.RTCPeerConnection.prototype.removeStream = function (e) {
  1898. this._streams = this._streams || {}, this._reverseStreams = this._reverseStreams || {}, s.apply(this, [this._streams[e.id] || e]), delete this._reverseStreams[this._streams[e.id] ? this._streams[e.id].id : e.id], delete this._streams[e.id]
  1899. }, e.RTCPeerConnection.prototype.addTrack = function (t, r) {
  1900. var i = this;
  1901. if ("closed" === this.signalingState) throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.", "InvalidStateError");
  1902. var s = [].slice.call(arguments, 1);
  1903. if (1 !== s.length || !s[0].getTracks().find(function (e) {
  1904. return e === t
  1905. })) throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.", "NotSupportedError");
  1906. var n = this.getSenders().find(function (e) {
  1907. return e.track === t
  1908. });
  1909. if (n) throw new DOMException("Track already exists.", "InvalidAccessError");
  1910. this._streams = this._streams || {}, this._reverseStreams = this._reverseStreams || {};
  1911. var o = this._streams[r.id];
  1912. if (o) o.addTrack(t), Promise.resolve().then(function () {
  1913. i.dispatchEvent(new Event("negotiationneeded"))
  1914. }); else {
  1915. var a = new e.MediaStream([t]);
  1916. this._streams[r.id] = a, this._reverseStreams[a.id] = r, this.addStream(a)
  1917. }
  1918. return this.getSenders().find(function (e) {
  1919. return e.track === t
  1920. })
  1921. }, ["createOffer", "createAnswer"].forEach(function (t) {
  1922. var r = e.RTCPeerConnection.prototype[t];
  1923. e.RTCPeerConnection.prototype[t] = function () {
  1924. var e = this, t = arguments, i = arguments.length && "function" == typeof arguments[0];
  1925. return i ? r.apply(this, [function (r) {
  1926. var i = l(e, r);
  1927. t[0].apply(null, [i])
  1928. }, function (e) {
  1929. t[1] && t[1].apply(null, e)
  1930. }, arguments[2]]) : r.apply(this, arguments).then(function (t) {
  1931. return l(e, t)
  1932. })
  1933. }
  1934. });
  1935. var n = e.RTCPeerConnection.prototype.setLocalDescription;
  1936. e.RTCPeerConnection.prototype.setLocalDescription = function () {
  1937. return arguments.length && arguments[0].type ? (arguments[0] = (e = this, t = arguments[0], r = t.sdp, Object.keys(e._reverseStreams || []).forEach(function (t) {
  1938. var i = e._reverseStreams[t], s = e._streams[i.id];
  1939. r = r.replace(new RegExp(i.id, "g"), s.id)
  1940. }), new RTCSessionDescription({
  1941. type: t.type,
  1942. sdp: r
  1943. })), n.apply(this, arguments)) : n.apply(this, arguments);
  1944. var e, t, r
  1945. };
  1946. var o = Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype, "localDescription");
  1947. Object.defineProperty(e.RTCPeerConnection.prototype, "localDescription", {
  1948. get: function () {
  1949. var e = o.get.apply(this);
  1950. return "" === e.type ? e : l(this, e)
  1951. }
  1952. }), e.RTCPeerConnection.prototype.removeTrack = function (e) {
  1953. var t = this;
  1954. if ("closed" === this.signalingState) throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.", "InvalidStateError");
  1955. if (!e._pc) throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.", "TypeError");
  1956. var r = e._pc === this;
  1957. if (!r) throw new DOMException("Sender was not created by this connection.", "InvalidAccessError");
  1958. this._streams = this._streams || {};
  1959. var i = void 0;
  1960. Object.keys(this._streams).forEach(function (r) {
  1961. var s = t._streams[r].getTracks().find(function (t) {
  1962. return e.track === t
  1963. });
  1964. s && (i = t._streams[r])
  1965. }), i && (1 === i.getTracks().length ? this.removeStream(this._reverseStreams[i.id]) : i.removeTrack(e.track), this.dispatchEvent(new Event("negotiationneeded")))
  1966. }
  1967. }
  1968. function l(e, t) {
  1969. var r = t.sdp;
  1970. return Object.keys(e._reverseStreams || []).forEach(function (t) {
  1971. var i = e._reverseStreams[t], s = e._streams[i.id];
  1972. r = r.replace(new RegExp(s.id, "g"), i.id)
  1973. }), new RTCSessionDescription({type: t.type, sdp: r})
  1974. }
  1975. }, r.shimPeerConnection = function (e) {
  1976. if (!e.RTCPeerConnection && e.webkitRTCPeerConnection && (e.RTCPeerConnection = e.webkitRTCPeerConnection), e.RTCPeerConnection) {
  1977. ["setLocalDescription", "setRemoteDescription", "addIceCandidate"].forEach(function (t) {
  1978. var r = e.RTCPeerConnection.prototype[t];
  1979. e.RTCPeerConnection.prototype[t] = function () {
  1980. return arguments[0] = new ("addIceCandidate" === t ? e.RTCIceCandidate : e.RTCSessionDescription)(arguments[0]), r.apply(this, arguments)
  1981. }
  1982. });
  1983. var t = e.RTCPeerConnection.prototype.addIceCandidate;
  1984. e.RTCPeerConnection.prototype.addIceCandidate = function () {
  1985. return arguments[0] ? t.apply(this, arguments) : (arguments[1] && arguments[1].apply(null), Promise.resolve())
  1986. }
  1987. }
  1988. }, r.fixNegotiationNeeded = function (e) {
  1989. a.wrapPeerConnectionEvent(e, "negotiationneeded", function (e) {
  1990. var t = e.target;
  1991. if ("stable" === t.signalingState) return e
  1992. })
  1993. };
  1994. var o = e("../utils.js"), a = function (e) {
  1995. if (e && e.__esModule) return e;
  1996. var t = {};
  1997. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  1998. return t.default = e, t
  1999. }(o);
  2000. function c(e) {
  2001. e.RTCPeerConnection.prototype.getLocalStreams = function () {
  2002. var e = this;
  2003. return this._shimmedLocalStreams = this._shimmedLocalStreams || {}, Object.keys(this._shimmedLocalStreams).map(function (t) {
  2004. return e._shimmedLocalStreams[t][0]
  2005. })
  2006. };
  2007. var t = e.RTCPeerConnection.prototype.addTrack;
  2008. e.RTCPeerConnection.prototype.addTrack = function (e, r) {
  2009. if (!r) return t.apply(this, arguments);
  2010. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  2011. var i = t.apply(this, arguments);
  2012. return this._shimmedLocalStreams[r.id] ? -1 === this._shimmedLocalStreams[r.id].indexOf(i) && this._shimmedLocalStreams[r.id].push(i) : this._shimmedLocalStreams[r.id] = [r, i], i
  2013. };
  2014. var r = e.RTCPeerConnection.prototype.addStream;
  2015. e.RTCPeerConnection.prototype.addStream = function (e) {
  2016. var t = this;
  2017. this._shimmedLocalStreams = this._shimmedLocalStreams || {}, e.getTracks().forEach(function (e) {
  2018. var r = t.getSenders().find(function (t) {
  2019. return t.track === e
  2020. });
  2021. if (r) throw new DOMException("Track already exists.", "InvalidAccessError")
  2022. });
  2023. var i = this.getSenders();
  2024. r.apply(this, arguments);
  2025. var s = this.getSenders().filter(function (e) {
  2026. return -1 === i.indexOf(e)
  2027. });
  2028. this._shimmedLocalStreams[e.id] = [e].concat(s)
  2029. };
  2030. var i = e.RTCPeerConnection.prototype.removeStream;
  2031. e.RTCPeerConnection.prototype.removeStream = function (e) {
  2032. return this._shimmedLocalStreams = this._shimmedLocalStreams || {}, delete this._shimmedLocalStreams[e.id], i.apply(this, arguments)
  2033. };
  2034. var s = e.RTCPeerConnection.prototype.removeTrack;
  2035. e.RTCPeerConnection.prototype.removeTrack = function (e) {
  2036. var t = this;
  2037. return this._shimmedLocalStreams = this._shimmedLocalStreams || {}, e && Object.keys(this._shimmedLocalStreams).forEach(function (r) {
  2038. var i = t._shimmedLocalStreams[r].indexOf(e);
  2039. -1 !== i && t._shimmedLocalStreams[r].splice(i, 1), 1 === t._shimmedLocalStreams[r].length && delete t._shimmedLocalStreams[r]
  2040. }), s.apply(this, arguments)
  2041. }
  2042. }
  2043. }, {"../utils.js": 15, "./getdisplaymedia": 4, "./getusermedia": 5}], 4: [function (e, t, r) {
  2044. "use strict";
  2045. Object.defineProperty(r, "__esModule", {value: !0}), r.shimGetDisplayMedia = function (e, t) {
  2046. e.navigator.mediaDevices && "getDisplayMedia" in e.navigator.mediaDevices || e.navigator.mediaDevices && ("function" == typeof t ? e.navigator.mediaDevices.getDisplayMedia = function (r) {
  2047. return t(r).then(function (t) {
  2048. var i = r.video && r.video.width, s = r.video && r.video.height,
  2049. n = r.video && r.video.frameRate;
  2050. return r.video = {
  2051. mandatory: {
  2052. chromeMediaSource: "desktop",
  2053. chromeMediaSourceId: t,
  2054. maxFrameRate: n || 3
  2055. }
  2056. }, i && (r.video.mandatory.maxWidth = i), s && (r.video.mandatory.maxHeight = s), e.navigator.mediaDevices.getUserMedia(r)
  2057. })
  2058. } : console.error("shimGetDisplayMedia: getSourceId argument is not a function"))
  2059. }
  2060. }, {}], 5: [function (e, t, r) {
  2061. "use strict";
  2062. Object.defineProperty(r, "__esModule", {value: !0});
  2063. var i = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  2064. return typeof e
  2065. } : function (e) {
  2066. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  2067. };
  2068. r.shimGetUserMedia = function (e) {
  2069. var t = e && e.navigator;
  2070. if (t.mediaDevices) {
  2071. var r = n.detectBrowser(e), s = function (e) {
  2072. if ("object" !== (void 0 === e ? "undefined" : i(e)) || e.mandatory || e.optional) return e;
  2073. var t = {};
  2074. return Object.keys(e).forEach(function (r) {
  2075. if ("require" !== r && "advanced" !== r && "mediaSource" !== r) {
  2076. var s = "object" === i(e[r]) ? e[r] : {ideal: e[r]};
  2077. void 0 !== s.exact && "number" == typeof s.exact && (s.min = s.max = s.exact);
  2078. var n = function (e, t) {
  2079. return e ? e + t.charAt(0).toUpperCase() + t.slice(1) : "deviceId" === t ? "sourceId" : t
  2080. };
  2081. if (void 0 !== s.ideal) {
  2082. t.optional = t.optional || [];
  2083. var o = {};
  2084. "number" == typeof s.ideal ? (o[n("min", r)] = s.ideal, t.optional.push(o), (o = {})[n("max", r)] = s.ideal, t.optional.push(o)) : (o[n("", r)] = s.ideal, t.optional.push(o))
  2085. }
  2086. void 0 !== s.exact && "number" != typeof s.exact ? (t.mandatory = t.mandatory || {}, t.mandatory[n("", r)] = s.exact) : ["min", "max"].forEach(function (e) {
  2087. void 0 !== s[e] && (t.mandatory = t.mandatory || {}, t.mandatory[n(e, r)] = s[e])
  2088. })
  2089. }
  2090. }), e.advanced && (t.optional = (t.optional || []).concat(e.advanced)), t
  2091. }, a = function (e, n) {
  2092. if (r.version >= 61) return n(e);
  2093. if ((e = JSON.parse(JSON.stringify(e))) && "object" === i(e.audio)) {
  2094. var a = function (e, t, r) {
  2095. t in e && !(r in e) && (e[r] = e[t], delete e[t])
  2096. };
  2097. e = JSON.parse(JSON.stringify(e)), a(e.audio, "autoGainControl", "googAutoGainControl"), a(e.audio, "noiseSuppression", "googNoiseSuppression"), e.audio = s(e.audio)
  2098. }
  2099. if (e && "object" === i(e.video)) {
  2100. var c = e.video.facingMode;
  2101. c = c && ("object" === (void 0 === c ? "undefined" : i(c)) ? c : {ideal: c});
  2102. var l = r.version < 66;
  2103. if (c && ("user" === c.exact || "environment" === c.exact || "user" === c.ideal || "environment" === c.ideal) && (!t.mediaDevices.getSupportedConstraints || !t.mediaDevices.getSupportedConstraints().facingMode || l)) {
  2104. delete e.video.facingMode;
  2105. var d = void 0;
  2106. if ("environment" === c.exact || "environment" === c.ideal ? d = ["back", "rear"] : "user" !== c.exact && "user" !== c.ideal || (d = ["front"]), d) return t.mediaDevices.enumerateDevices().then(function (t) {
  2107. var r = (t = t.filter(function (e) {
  2108. return "videoinput" === e.kind
  2109. })).find(function (e) {
  2110. return d.some(function (t) {
  2111. return e.label.toLowerCase().includes(t)
  2112. })
  2113. });
  2114. return !r && t.length && d.includes("back") && (r = t[t.length - 1]), r && (e.video.deviceId = c.exact ? {exact: r.deviceId} : {ideal: r.deviceId}), e.video = s(e.video), o("chrome: " + JSON.stringify(e)), n(e)
  2115. })
  2116. }
  2117. e.video = s(e.video)
  2118. }
  2119. return o("chrome: " + JSON.stringify(e)), n(e)
  2120. }, c = function (e) {
  2121. return r.version >= 64 ? e : {
  2122. name: {
  2123. PermissionDeniedError: "NotAllowedError",
  2124. PermissionDismissedError: "NotAllowedError",
  2125. InvalidStateError: "NotAllowedError",
  2126. DevicesNotFoundError: "NotFoundError",
  2127. ConstraintNotSatisfiedError: "OverconstrainedError",
  2128. TrackStartError: "NotReadableError",
  2129. MediaDeviceFailedDueToShutdown: "NotAllowedError",
  2130. MediaDeviceKillSwitchOn: "NotAllowedError",
  2131. TabCaptureError: "AbortError",
  2132. ScreenCaptureError: "AbortError",
  2133. DeviceCaptureError: "AbortError"
  2134. }[e.name] || e.name,
  2135. message: e.message,
  2136. constraint: e.constraint || e.constraintName,
  2137. toString: function () {
  2138. return this.name + (this.message && ": ") + this.message
  2139. }
  2140. }
  2141. };
  2142. if (t.getUserMedia = function (e, r, i) {
  2143. a(e, function (e) {
  2144. t.webkitGetUserMedia(e, r, function (e) {
  2145. i && i(c(e))
  2146. })
  2147. })
  2148. }.bind(t), t.mediaDevices.getUserMedia) {
  2149. var l = t.mediaDevices.getUserMedia.bind(t.mediaDevices);
  2150. t.mediaDevices.getUserMedia = function (e) {
  2151. return a(e, function (e) {
  2152. return l(e).then(function (t) {
  2153. if (e.audio && !t.getAudioTracks().length || e.video && !t.getVideoTracks().length) throw t.getTracks().forEach(function (e) {
  2154. e.stop()
  2155. }), new DOMException("", "NotFoundError");
  2156. return t
  2157. }, function (e) {
  2158. return Promise.reject(c(e))
  2159. })
  2160. })
  2161. }
  2162. }
  2163. }
  2164. };
  2165. var s = e("../utils.js"), n = function (e) {
  2166. if (e && e.__esModule) return e;
  2167. var t = {};
  2168. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  2169. return t.default = e, t
  2170. }(s), o = n.log
  2171. }, {"../utils.js": 15}], 6: [function (e, t, r) {
  2172. "use strict";
  2173. Object.defineProperty(r, "__esModule", {value: !0});
  2174. var i = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  2175. return typeof e
  2176. } : function (e) {
  2177. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  2178. };
  2179. r.shimRTCIceCandidate = function (e) {
  2180. if (e.RTCIceCandidate && !(e.RTCIceCandidate && "foundation" in e.RTCIceCandidate.prototype)) {
  2181. var t = e.RTCIceCandidate;
  2182. e.RTCIceCandidate = function (e) {
  2183. if ("object" === (void 0 === e ? "undefined" : i(e)) && e.candidate && 0 === e.candidate.indexOf("a=") && ((e = JSON.parse(JSON.stringify(e))).candidate = e.candidate.substr(2)), e.candidate && e.candidate.length) {
  2184. var r = new t(e), s = o.default.parseCandidate(e.candidate), n = Object.assign(r, s);
  2185. return n.toJSON = function () {
  2186. return {
  2187. candidate: n.candidate,
  2188. sdpMid: n.sdpMid,
  2189. sdpMLineIndex: n.sdpMLineIndex,
  2190. usernameFragment: n.usernameFragment
  2191. }
  2192. }, n
  2193. }
  2194. return new t(e)
  2195. }, e.RTCIceCandidate.prototype = t.prototype, c.wrapPeerConnectionEvent(e, "icecandidate", function (t) {
  2196. return t.candidate && Object.defineProperty(t, "candidate", {
  2197. value: new e.RTCIceCandidate(t.candidate),
  2198. writable: "false"
  2199. }), t
  2200. })
  2201. }
  2202. }, r.shimMaxMessageSize = function (e) {
  2203. if (!e.RTCSctpTransport && e.RTCPeerConnection) {
  2204. var t = c.detectBrowser(e);
  2205. "sctp" in e.RTCPeerConnection.prototype || Object.defineProperty(e.RTCPeerConnection.prototype, "sctp", {
  2206. get: function () {
  2207. return void 0 === this._sctp ? null : this._sctp
  2208. }
  2209. });
  2210. var r = e.RTCPeerConnection.prototype.setRemoteDescription;
  2211. e.RTCPeerConnection.prototype.setRemoteDescription = function () {
  2212. if (this._sctp = null, function (e) {
  2213. if (!e || !e.sdp) return !1;
  2214. var t = o.default.splitSections(e.sdp);
  2215. return t.shift(), t.some(function (e) {
  2216. var t = o.default.parseMLine(e);
  2217. return t && "application" === t.kind && -1 !== t.protocol.indexOf("SCTP")
  2218. })
  2219. }(arguments[0])) {
  2220. var e = function (e) {
  2221. var t = e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);
  2222. if (null === t || t.length < 2) return -1;
  2223. var r = parseInt(t[1], 10);
  2224. return r != r ? -1 : r
  2225. }(arguments[0]),
  2226. i = (c = e, l = 65536, "firefox" === t.browser && (l = t.version < 57 ? -1 === c ? 16384 : 2147483637 : t.version < 60 ? 57 === t.version ? 65535 : 65536 : 2147483637), l),
  2227. s = function (e, r) {
  2228. var i = 65536;
  2229. "firefox" === t.browser && 57 === t.version && (i = 65535);
  2230. var s = o.default.matchPrefix(e.sdp, "a=max-message-size:");
  2231. return s.length > 0 ? i = parseInt(s[0].substr(19), 10) : "firefox" === t.browser && -1 !== r && (i = 2147483637), i
  2232. }(arguments[0], e), n = void 0;
  2233. n = 0 === i && 0 === s ? Number.POSITIVE_INFINITY : 0 === i || 0 === s ? Math.max(i, s) : Math.min(i, s);
  2234. var a = {};
  2235. Object.defineProperty(a, "maxMessageSize", {
  2236. get: function () {
  2237. return n
  2238. }
  2239. }), this._sctp = a
  2240. }
  2241. var c, l;
  2242. return r.apply(this, arguments)
  2243. }
  2244. }
  2245. }, r.shimSendThrowTypeError = function (e) {
  2246. if (e.RTCPeerConnection && "createDataChannel" in e.RTCPeerConnection.prototype) {
  2247. var t = e.RTCPeerConnection.prototype.createDataChannel;
  2248. e.RTCPeerConnection.prototype.createDataChannel = function () {
  2249. var e = t.apply(this, arguments);
  2250. return r(e, this), e
  2251. }, c.wrapPeerConnectionEvent(e, "datachannel", function (e) {
  2252. return r(e.channel, e.target), e
  2253. })
  2254. }
  2255. function r(e, t) {
  2256. var r = e.send;
  2257. e.send = function () {
  2258. var i = arguments[0], s = i.length || i.size || i.byteLength;
  2259. if ("open" === e.readyState && t.sctp && s > t.sctp.maxMessageSize) throw new TypeError("Message too large (can send a maximum of " + t.sctp.maxMessageSize + " bytes)");
  2260. return r.apply(e, arguments)
  2261. }
  2262. }
  2263. }, r.shimConnectionState = function (e) {
  2264. if (e.RTCPeerConnection && !("connectionState" in e.RTCPeerConnection.prototype)) {
  2265. var t = e.RTCPeerConnection.prototype;
  2266. Object.defineProperty(t, "connectionState", {
  2267. get: function () {
  2268. return {
  2269. completed: "connected",
  2270. checking: "connecting"
  2271. }[this.iceConnectionState] || this.iceConnectionState
  2272. }, enumerable: !0, configurable: !0
  2273. }), Object.defineProperty(t, "onconnectionstatechange", {
  2274. get: function () {
  2275. return this._onconnectionstatechange || null
  2276. }, set: function (e) {
  2277. this._onconnectionstatechange && (this.removeEventListener("connectionstatechange", this._onconnectionstatechange), delete this._onconnectionstatechange), e && this.addEventListener("connectionstatechange", this._onconnectionstatechange = e)
  2278. }, enumerable: !0, configurable: !0
  2279. }), ["setLocalDescription", "setRemoteDescription"].forEach(function (e) {
  2280. var r = t[e];
  2281. t[e] = function () {
  2282. return this._connectionstatechangepoly || (this._connectionstatechangepoly = function (e) {
  2283. var t = e.target;
  2284. if (t._lastConnectionState !== t.connectionState) {
  2285. t._lastConnectionState = t.connectionState;
  2286. var r = new Event("connectionstatechange", e);
  2287. t.dispatchEvent(r)
  2288. }
  2289. return e
  2290. }, this.addEventListener("iceconnectionstatechange", this._connectionstatechangepoly)), r.apply(this, arguments)
  2291. }
  2292. })
  2293. }
  2294. }, r.removeAllowExtmapMixed = function (e) {
  2295. if (e.RTCPeerConnection) {
  2296. var t = c.detectBrowser(e);
  2297. if (!("chrome" === t.browser && t.version >= 71)) {
  2298. var r = e.RTCPeerConnection.prototype.setRemoteDescription;
  2299. e.RTCPeerConnection.prototype.setRemoteDescription = function (e) {
  2300. return e && e.sdp && -1 !== e.sdp.indexOf("\na=extmap-allow-mixed") && (e.sdp = e.sdp.split("\n").filter(function (e) {
  2301. return "a=extmap-allow-mixed" !== e.trim()
  2302. }).join("\n")), r.apply(this, arguments)
  2303. }
  2304. }
  2305. }
  2306. };
  2307. var s, n = e("sdp"), o = (s = n) && s.__esModule ? s : {default: s}, a = e("./utils"),
  2308. c = function (e) {
  2309. if (e && e.__esModule) return e;
  2310. var t = {};
  2311. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  2312. return t.default = e, t
  2313. }(a)
  2314. }, {"./utils": 15, sdp: 17}], 7: [function (e, t, r) {
  2315. "use strict";
  2316. Object.defineProperty(r, "__esModule", {value: !0}), r.shimGetDisplayMedia = r.shimGetUserMedia = void 0;
  2317. var i = e("./getusermedia");
  2318. Object.defineProperty(r, "shimGetUserMedia", {
  2319. enumerable: !0, get: function () {
  2320. return i.shimGetUserMedia
  2321. }
  2322. });
  2323. var s = e("./getdisplaymedia");
  2324. Object.defineProperty(r, "shimGetDisplayMedia", {
  2325. enumerable: !0, get: function () {
  2326. return s.shimGetDisplayMedia
  2327. }
  2328. }), r.shimPeerConnection = function (e) {
  2329. var t = a.detectBrowser(e);
  2330. if (e.RTCIceGatherer && (e.RTCIceCandidate || (e.RTCIceCandidate = function (e) {
  2331. return e
  2332. }), e.RTCSessionDescription || (e.RTCSessionDescription = function (e) {
  2333. return e
  2334. }), t.version < 15025)) {
  2335. var r = Object.getOwnPropertyDescriptor(e.MediaStreamTrack.prototype, "enabled");
  2336. Object.defineProperty(e.MediaStreamTrack.prototype, "enabled", {
  2337. set: function (e) {
  2338. r.set.call(this, e);
  2339. var t = new Event("enabled");
  2340. t.enabled = e, this.dispatchEvent(t)
  2341. }
  2342. })
  2343. }
  2344. !e.RTCRtpSender || "dtmf" in e.RTCRtpSender.prototype || Object.defineProperty(e.RTCRtpSender.prototype, "dtmf", {
  2345. get: function () {
  2346. return void 0 === this._dtmf && ("audio" === this.track.kind ? this._dtmf = new e.RTCDtmfSender(this) : "video" === this.track.kind && (this._dtmf = null)), this._dtmf
  2347. }
  2348. }), e.RTCDtmfSender && !e.RTCDTMFSender && (e.RTCDTMFSender = e.RTCDtmfSender);
  2349. var i = (0, d.default)(e, t.version);
  2350. e.RTCPeerConnection = function (e) {
  2351. return e && e.iceServers && (e.iceServers = (0, c.filterIceServers)(e.iceServers, t.version), a.log("ICE servers after filtering:", e.iceServers)), new i(e)
  2352. }, e.RTCPeerConnection.prototype = i.prototype
  2353. }, r.shimReplaceTrack = function (e) {
  2354. !e.RTCRtpSender || "replaceTrack" in e.RTCRtpSender.prototype || (e.RTCRtpSender.prototype.replaceTrack = e.RTCRtpSender.prototype.setTrack)
  2355. };
  2356. var n, o = e("../utils"), a = function (e) {
  2357. if (e && e.__esModule) return e;
  2358. var t = {};
  2359. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  2360. return t.default = e, t
  2361. }(o), c = e("./filtericeservers"), l = e("rtcpeerconnection-shim"),
  2362. d = (n = l) && n.__esModule ? n : {default: n}
  2363. }, {
  2364. "../utils": 15,
  2365. "./filtericeservers": 8,
  2366. "./getdisplaymedia": 9,
  2367. "./getusermedia": 10,
  2368. "rtcpeerconnection-shim": 16
  2369. }], 8: [function (e, t, r) {
  2370. "use strict";
  2371. Object.defineProperty(r, "__esModule", {value: !0}), r.filterIceServers = function (e, t) {
  2372. var r = !1;
  2373. return (e = JSON.parse(JSON.stringify(e))).filter(function (e) {
  2374. if (e && (e.urls || e.url)) {
  2375. var t = e.urls || e.url;
  2376. e.url && !e.urls && s.deprecated("RTCIceServer.url", "RTCIceServer.urls");
  2377. var i = "string" == typeof t;
  2378. return i && (t = [t]), t = t.filter(function (e) {
  2379. if (0 === e.indexOf("stun:")) return !1;
  2380. var t = e.startsWith("turn") && !e.startsWith("turn:[") && e.includes("transport=udp");
  2381. return t && !r ? (r = !0, !0) : t && !r
  2382. }), delete e.url, e.urls = i ? t[0] : t, !!t.length
  2383. }
  2384. })
  2385. };
  2386. var i = e("../utils"), s = function (e) {
  2387. if (e && e.__esModule) return e;
  2388. var t = {};
  2389. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  2390. return t.default = e, t
  2391. }(i)
  2392. }, {"../utils": 15}], 9: [function (e, t, r) {
  2393. "use strict";
  2394. Object.defineProperty(r, "__esModule", {value: !0}), r.shimGetDisplayMedia = function (e) {
  2395. "getDisplayMedia" in e.navigator && e.navigator.mediaDevices && (e.navigator.mediaDevices && "getDisplayMedia" in e.navigator.mediaDevices || (e.navigator.mediaDevices.getDisplayMedia = e.navigator.getDisplayMedia.bind(e.navigator)))
  2396. }
  2397. }, {}], 10: [function (e, t, r) {
  2398. "use strict";
  2399. Object.defineProperty(r, "__esModule", {value: !0}), r.shimGetUserMedia = function (e) {
  2400. var t = e && e.navigator, r = t.mediaDevices.getUserMedia.bind(t.mediaDevices);
  2401. t.mediaDevices.getUserMedia = function (e) {
  2402. return r(e).catch(function (e) {
  2403. return Promise.reject(function (e) {
  2404. return {
  2405. name: {PermissionDeniedError: "NotAllowedError"}[e.name] || e.name,
  2406. message: e.message,
  2407. constraint: e.constraint,
  2408. toString: function () {
  2409. return this.name
  2410. }
  2411. }
  2412. }(e))
  2413. })
  2414. }
  2415. }
  2416. }, {}], 11: [function (e, t, r) {
  2417. "use strict";
  2418. Object.defineProperty(r, "__esModule", {value: !0}), r.shimGetDisplayMedia = r.shimGetUserMedia = void 0;
  2419. var i = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  2420. return typeof e
  2421. } : function (e) {
  2422. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  2423. }, s = e("./getusermedia");
  2424. Object.defineProperty(r, "shimGetUserMedia", {
  2425. enumerable: !0, get: function () {
  2426. return s.shimGetUserMedia
  2427. }
  2428. });
  2429. var n = e("./getdisplaymedia");
  2430. Object.defineProperty(r, "shimGetDisplayMedia", {
  2431. enumerable: !0, get: function () {
  2432. return n.shimGetDisplayMedia
  2433. }
  2434. }), r.shimOnTrack = function (e) {
  2435. "object" === (void 0 === e ? "undefined" : i(e)) && e.RTCTrackEvent && "receiver" in e.RTCTrackEvent.prototype && !("transceiver" in e.RTCTrackEvent.prototype) && Object.defineProperty(e.RTCTrackEvent.prototype, "transceiver", {
  2436. get: function () {
  2437. return {receiver: this.receiver}
  2438. }
  2439. })
  2440. }, r.shimPeerConnection = function (e) {
  2441. var t = a.detectBrowser(e);
  2442. if ("object" === (void 0 === e ? "undefined" : i(e)) && (e.RTCPeerConnection || e.mozRTCPeerConnection)) {
  2443. !e.RTCPeerConnection && e.mozRTCPeerConnection && (e.RTCPeerConnection = e.mozRTCPeerConnection), ["setLocalDescription", "setRemoteDescription", "addIceCandidate"].forEach(function (t) {
  2444. var r = e.RTCPeerConnection.prototype[t];
  2445. e.RTCPeerConnection.prototype[t] = function () {
  2446. return arguments[0] = new ("addIceCandidate" === t ? e.RTCIceCandidate : e.RTCSessionDescription)(arguments[0]), r.apply(this, arguments)
  2447. }
  2448. });
  2449. var r = e.RTCPeerConnection.prototype.addIceCandidate;
  2450. e.RTCPeerConnection.prototype.addIceCandidate = function () {
  2451. return arguments[0] ? r.apply(this, arguments) : (arguments[1] && arguments[1].apply(null), Promise.resolve())
  2452. };
  2453. var s = {
  2454. inboundrtp: "inbound-rtp",
  2455. outboundrtp: "outbound-rtp",
  2456. candidatepair: "candidate-pair",
  2457. localcandidate: "local-candidate",
  2458. remotecandidate: "remote-candidate"
  2459. }, n = e.RTCPeerConnection.prototype.getStats;
  2460. e.RTCPeerConnection.prototype.getStats = function (e, r, i) {
  2461. return n.apply(this, [e || null]).then(function (e) {
  2462. if (t.version < 53 && !r) try {
  2463. e.forEach(function (e) {
  2464. e.type = s[e.type] || e.type
  2465. })
  2466. } catch (t) {
  2467. if ("TypeError" !== t.name) throw t;
  2468. e.forEach(function (t, r) {
  2469. e.set(r, Object.assign({}, t, {type: s[t.type] || t.type}))
  2470. })
  2471. }
  2472. return e
  2473. }).then(r, i)
  2474. }
  2475. }
  2476. }, r.shimSenderGetStats = function (e) {
  2477. if ("object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection && e.RTCRtpSender && !(e.RTCRtpSender && "getStats" in e.RTCRtpSender.prototype)) {
  2478. var t = e.RTCPeerConnection.prototype.getSenders;
  2479. t && (e.RTCPeerConnection.prototype.getSenders = function () {
  2480. var e = this, r = t.apply(this, []);
  2481. return r.forEach(function (t) {
  2482. return t._pc = e
  2483. }), r
  2484. });
  2485. var r = e.RTCPeerConnection.prototype.addTrack;
  2486. r && (e.RTCPeerConnection.prototype.addTrack = function () {
  2487. var e = r.apply(this, arguments);
  2488. return e._pc = this, e
  2489. }), e.RTCRtpSender.prototype.getStats = function () {
  2490. return this.track ? this._pc.getStats(this.track) : Promise.resolve(new Map)
  2491. }
  2492. }
  2493. }, r.shimReceiverGetStats = function (e) {
  2494. if ("object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection && e.RTCRtpSender && !(e.RTCRtpSender && "getStats" in e.RTCRtpReceiver.prototype)) {
  2495. var t = e.RTCPeerConnection.prototype.getReceivers;
  2496. t && (e.RTCPeerConnection.prototype.getReceivers = function () {
  2497. var e = this, r = t.apply(this, []);
  2498. return r.forEach(function (t) {
  2499. return t._pc = e
  2500. }), r
  2501. }), a.wrapPeerConnectionEvent(e, "track", function (e) {
  2502. return e.receiver._pc = e.srcElement, e
  2503. }), e.RTCRtpReceiver.prototype.getStats = function () {
  2504. return this._pc.getStats(this.track)
  2505. }
  2506. }
  2507. }, r.shimRemoveStream = function (e) {
  2508. !e.RTCPeerConnection || "removeStream" in e.RTCPeerConnection.prototype || (e.RTCPeerConnection.prototype.removeStream = function (e) {
  2509. var t = this;
  2510. a.deprecated("removeStream", "removeTrack"), this.getSenders().forEach(function (r) {
  2511. r.track && e.getTracks().includes(r.track) && t.removeTrack(r)
  2512. })
  2513. })
  2514. }, r.shimRTCDataChannel = function (e) {
  2515. e.DataChannel && !e.RTCDataChannel && (e.RTCDataChannel = e.DataChannel)
  2516. };
  2517. var o = e("../utils"), a = function (e) {
  2518. if (e && e.__esModule) return e;
  2519. var t = {};
  2520. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  2521. return t.default = e, t
  2522. }(o)
  2523. }, {"../utils": 15, "./getdisplaymedia": 12, "./getusermedia": 13}], 12: [function (e, t, r) {
  2524. "use strict";
  2525. Object.defineProperty(r, "__esModule", {value: !0}), r.shimGetDisplayMedia = function (e, t) {
  2526. e.navigator.mediaDevices && "getDisplayMedia" in e.navigator.mediaDevices || e.navigator.mediaDevices && (e.navigator.mediaDevices.getDisplayMedia = function (r) {
  2527. if (!r || !r.video) {
  2528. var i = new DOMException("getDisplayMedia without video constraints is undefined");
  2529. return i.name = "NotFoundError", i.code = 8, Promise.reject(i)
  2530. }
  2531. return !0 === r.video ? r.video = {mediaSource: t} : r.video.mediaSource = t, e.navigator.mediaDevices.getUserMedia(r)
  2532. })
  2533. }
  2534. }, {}], 13: [function (e, t, r) {
  2535. "use strict";
  2536. Object.defineProperty(r, "__esModule", {value: !0});
  2537. var i = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  2538. return typeof e
  2539. } : function (e) {
  2540. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  2541. };
  2542. r.shimGetUserMedia = function (e) {
  2543. var t = n.detectBrowser(e), r = e && e.navigator, s = e && e.MediaStreamTrack;
  2544. if (r.getUserMedia = function (e, t, i) {
  2545. n.deprecated("navigator.getUserMedia", "navigator.mediaDevices.getUserMedia"), r.mediaDevices.getUserMedia(e).then(t, i)
  2546. }, !(t.version > 55 && "autoGainControl" in r.mediaDevices.getSupportedConstraints())) {
  2547. var o = function (e, t, r) {
  2548. t in e && !(r in e) && (e[r] = e[t], delete e[t])
  2549. }, a = r.mediaDevices.getUserMedia.bind(r.mediaDevices);
  2550. if (r.mediaDevices.getUserMedia = function (e) {
  2551. return "object" === (void 0 === e ? "undefined" : i(e)) && "object" === i(e.audio) && (e = JSON.parse(JSON.stringify(e)), o(e.audio, "autoGainControl", "mozAutoGainControl"), o(e.audio, "noiseSuppression", "mozNoiseSuppression")), a(e)
  2552. }, s && s.prototype.getSettings) {
  2553. var c = s.prototype.getSettings;
  2554. s.prototype.getSettings = function () {
  2555. var e = c.apply(this, arguments);
  2556. return o(e, "mozAutoGainControl", "autoGainControl"), o(e, "mozNoiseSuppression", "noiseSuppression"), e
  2557. }
  2558. }
  2559. if (s && s.prototype.applyConstraints) {
  2560. var l = s.prototype.applyConstraints;
  2561. s.prototype.applyConstraints = function (e) {
  2562. return "audio" === this.kind && "object" === (void 0 === e ? "undefined" : i(e)) && (e = JSON.parse(JSON.stringify(e)), o(e, "autoGainControl", "mozAutoGainControl"), o(e, "noiseSuppression", "mozNoiseSuppression")), l.apply(this, [e])
  2563. }
  2564. }
  2565. }
  2566. };
  2567. var s = e("../utils"), n = function (e) {
  2568. if (e && e.__esModule) return e;
  2569. var t = {};
  2570. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  2571. return t.default = e, t
  2572. }(s)
  2573. }, {"../utils": 15}], 14: [function (e, t, r) {
  2574. "use strict";
  2575. Object.defineProperty(r, "__esModule", {value: !0});
  2576. var i = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  2577. return typeof e
  2578. } : function (e) {
  2579. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  2580. };
  2581. r.shimLocalStreamsAPI = function (e) {
  2582. if ("object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection) {
  2583. if ("getLocalStreams" in e.RTCPeerConnection.prototype || (e.RTCPeerConnection.prototype.getLocalStreams = function () {
  2584. return this._localStreams || (this._localStreams = []), this._localStreams
  2585. }), !("addStream" in e.RTCPeerConnection.prototype)) {
  2586. var t = e.RTCPeerConnection.prototype.addTrack;
  2587. e.RTCPeerConnection.prototype.addStream = function (e) {
  2588. var r = this;
  2589. this._localStreams || (this._localStreams = []), this._localStreams.includes(e) || this._localStreams.push(e), e.getTracks().forEach(function (i) {
  2590. return t.call(r, i, e)
  2591. })
  2592. }, e.RTCPeerConnection.prototype.addTrack = function (e, r) {
  2593. return r && (this._localStreams ? this._localStreams.includes(r) || this._localStreams.push(r) : this._localStreams = [r]), t.call(this, e, r)
  2594. }
  2595. }
  2596. "removeStream" in e.RTCPeerConnection.prototype || (e.RTCPeerConnection.prototype.removeStream = function (e) {
  2597. var t = this;
  2598. this._localStreams || (this._localStreams = []);
  2599. var r = this._localStreams.indexOf(e);
  2600. if (-1 !== r) {
  2601. this._localStreams.splice(r, 1);
  2602. var i = e.getTracks();
  2603. this.getSenders().forEach(function (e) {
  2604. i.includes(e.track) && t.removeTrack(e)
  2605. })
  2606. }
  2607. })
  2608. }
  2609. }, r.shimRemoteStreamsAPI = function (e) {
  2610. if ("object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection && ("getRemoteStreams" in e.RTCPeerConnection.prototype || (e.RTCPeerConnection.prototype.getRemoteStreams = function () {
  2611. return this._remoteStreams ? this._remoteStreams : []
  2612. }), !("onaddstream" in e.RTCPeerConnection.prototype))) {
  2613. Object.defineProperty(e.RTCPeerConnection.prototype, "onaddstream", {
  2614. get: function () {
  2615. return this._onaddstream
  2616. }, set: function (e) {
  2617. var t = this;
  2618. this._onaddstream && (this.removeEventListener("addstream", this._onaddstream), this.removeEventListener("track", this._onaddstreampoly)), this.addEventListener("addstream", this._onaddstream = e), this.addEventListener("track", this._onaddstreampoly = function (e) {
  2619. e.streams.forEach(function (e) {
  2620. if (t._remoteStreams || (t._remoteStreams = []), !t._remoteStreams.includes(e)) {
  2621. t._remoteStreams.push(e);
  2622. var r = new Event("addstream");
  2623. r.stream = e, t.dispatchEvent(r)
  2624. }
  2625. })
  2626. })
  2627. }
  2628. });
  2629. var t = e.RTCPeerConnection.prototype.setRemoteDescription;
  2630. e.RTCPeerConnection.prototype.setRemoteDescription = function () {
  2631. var e = this;
  2632. return this._onaddstreampoly || this.addEventListener("track", this._onaddstreampoly = function (t) {
  2633. t.streams.forEach(function (t) {
  2634. if (e._remoteStreams || (e._remoteStreams = []), !(e._remoteStreams.indexOf(t) >= 0)) {
  2635. e._remoteStreams.push(t);
  2636. var r = new Event("addstream");
  2637. r.stream = t, e.dispatchEvent(r)
  2638. }
  2639. })
  2640. }), t.apply(e, arguments)
  2641. }
  2642. }
  2643. }, r.shimCallbacksAPI = function (e) {
  2644. if ("object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection) {
  2645. var t = e.RTCPeerConnection.prototype, r = t.createOffer, s = t.createAnswer,
  2646. n = t.setLocalDescription, o = t.setRemoteDescription, a = t.addIceCandidate;
  2647. t.createOffer = function (e, t) {
  2648. var i = arguments.length >= 2 ? arguments[2] : arguments[0], s = r.apply(this, [i]);
  2649. return t ? (s.then(e, t), Promise.resolve()) : s
  2650. }, t.createAnswer = function (e, t) {
  2651. var r = arguments.length >= 2 ? arguments[2] : arguments[0], i = s.apply(this, [r]);
  2652. return t ? (i.then(e, t), Promise.resolve()) : i
  2653. };
  2654. var c = function (e, t, r) {
  2655. var i = n.apply(this, [e]);
  2656. return r ? (i.then(t, r), Promise.resolve()) : i
  2657. };
  2658. t.setLocalDescription = c, c = function (e, t, r) {
  2659. var i = o.apply(this, [e]);
  2660. return r ? (i.then(t, r), Promise.resolve()) : i
  2661. }, t.setRemoteDescription = c, c = function (e, t, r) {
  2662. var i = a.apply(this, [e]);
  2663. return r ? (i.then(t, r), Promise.resolve()) : i
  2664. }, t.addIceCandidate = c
  2665. }
  2666. }, r.shimGetUserMedia = function (e) {
  2667. var t = e && e.navigator;
  2668. if (t.mediaDevices && t.mediaDevices.getUserMedia) {
  2669. var r = t.mediaDevices, i = r.getUserMedia.bind(r);
  2670. t.mediaDevices.getUserMedia = function (e) {
  2671. return i(o(e))
  2672. }
  2673. }
  2674. !t.getUserMedia && t.mediaDevices && t.mediaDevices.getUserMedia && (t.getUserMedia = function (e, r, i) {
  2675. t.mediaDevices.getUserMedia(e).then(r, i)
  2676. }.bind(t))
  2677. }, r.shimConstraints = o, r.shimRTCIceServerUrls = function (e) {
  2678. var t = e.RTCPeerConnection;
  2679. e.RTCPeerConnection = function (e, r) {
  2680. if (e && e.iceServers) {
  2681. for (var i = [], s = 0; s < e.iceServers.length; s++) {
  2682. var o = e.iceServers[s];
  2683. !o.hasOwnProperty("urls") && o.hasOwnProperty("url") ? (n.deprecated("RTCIceServer.url", "RTCIceServer.urls"), (o = JSON.parse(JSON.stringify(o))).urls = o.url, delete o.url, i.push(o)) : i.push(e.iceServers[s])
  2684. }
  2685. e.iceServers = i
  2686. }
  2687. return new t(e, r)
  2688. }, e.RTCPeerConnection.prototype = t.prototype, "generateCertificate" in e.RTCPeerConnection && Object.defineProperty(e.RTCPeerConnection, "generateCertificate", {
  2689. get: function () {
  2690. return t.generateCertificate
  2691. }
  2692. })
  2693. }, r.shimTrackEventTransceiver = function (e) {
  2694. "object" === (void 0 === e ? "undefined" : i(e)) && e.RTCPeerConnection && "receiver" in e.RTCTrackEvent.prototype && !e.RTCTransceiver && Object.defineProperty(e.RTCTrackEvent.prototype, "transceiver", {
  2695. get: function () {
  2696. return {receiver: this.receiver}
  2697. }
  2698. })
  2699. }, r.shimCreateOfferLegacy = function (e) {
  2700. var t = e.RTCPeerConnection.prototype.createOffer;
  2701. e.RTCPeerConnection.prototype.createOffer = function (e) {
  2702. if (e) {
  2703. void 0 !== e.offerToReceiveAudio && (e.offerToReceiveAudio = !!e.offerToReceiveAudio);
  2704. var r = this.getTransceivers().find(function (e) {
  2705. return "audio" === e.receiver.track.kind
  2706. });
  2707. !1 === e.offerToReceiveAudio && r ? "sendrecv" === r.direction ? r.setDirection ? r.setDirection("sendonly") : r.direction = "sendonly" : "recvonly" === r.direction && (r.setDirection ? r.setDirection("inactive") : r.direction = "inactive") : !0 !== e.offerToReceiveAudio || r || this.addTransceiver("audio"), void 0 !== e.offerToReceiveVideo && (e.offerToReceiveVideo = !!e.offerToReceiveVideo);
  2708. var i = this.getTransceivers().find(function (e) {
  2709. return "video" === e.receiver.track.kind
  2710. });
  2711. !1 === e.offerToReceiveVideo && i ? "sendrecv" === i.direction ? i.setDirection ? i.setDirection("sendonly") : i.direction = "sendonly" : "recvonly" === i.direction && (i.setDirection ? i.setDirection("inactive") : i.direction = "inactive") : !0 !== e.offerToReceiveVideo || i || this.addTransceiver("video")
  2712. }
  2713. return t.apply(this, arguments)
  2714. }
  2715. };
  2716. var s = e("../utils"), n = function (e) {
  2717. if (e && e.__esModule) return e;
  2718. var t = {};
  2719. if (null != e) for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]);
  2720. return t.default = e, t
  2721. }(s);
  2722. function o(e) {
  2723. return e && void 0 !== e.video ? Object.assign({}, e, {video: n.compactObject(e.video)}) : e
  2724. }
  2725. }, {"../utils": 15}], 15: [function (e, t, r) {
  2726. "use strict";
  2727. Object.defineProperty(r, "__esModule", {value: !0});
  2728. var i = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  2729. return typeof e
  2730. } : function (e) {
  2731. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  2732. };
  2733. r.extractVersion = o, r.wrapPeerConnectionEvent = function (e, t, r) {
  2734. if (e.RTCPeerConnection) {
  2735. var i = e.RTCPeerConnection.prototype, s = i.addEventListener;
  2736. i.addEventListener = function (e, i) {
  2737. if (e !== t) return s.apply(this, arguments);
  2738. var n = function (e) {
  2739. var t = r(e);
  2740. t && i(t)
  2741. };
  2742. return this._eventMap = this._eventMap || {}, this._eventMap[i] = n, s.apply(this, [e, n])
  2743. };
  2744. var n = i.removeEventListener;
  2745. i.removeEventListener = function (e, r) {
  2746. if (e !== t || !this._eventMap || !this._eventMap[r]) return n.apply(this, arguments);
  2747. var i = this._eventMap[r];
  2748. return delete this._eventMap[r], n.apply(this, [e, i])
  2749. }, Object.defineProperty(i, "on" + t, {
  2750. get: function () {
  2751. return this["_on" + t]
  2752. }, set: function (e) {
  2753. this["_on" + t] && (this.removeEventListener(t, this["_on" + t]), delete this["_on" + t]), e && this.addEventListener(t, this["_on" + t] = e)
  2754. }, enumerable: !0, configurable: !0
  2755. })
  2756. }
  2757. }, r.disableLog = function (e) {
  2758. return "boolean" != typeof e ? new Error("Argument type: " + (void 0 === e ? "undefined" : i(e)) + ". Please use a boolean.") : (s = e, e ? "adapter.js logging disabled" : "adapter.js logging enabled")
  2759. }, r.disableWarnings = function (e) {
  2760. return "boolean" != typeof e ? new Error("Argument type: " + (void 0 === e ? "undefined" : i(e)) + ". Please use a boolean.") : (n = !e, "adapter.js deprecation warnings " + (e ? "disabled" : "enabled"))
  2761. }, r.log = function () {
  2762. if ("object" === ("undefined" == typeof window ? "undefined" : i(window))) {
  2763. if (s) return;
  2764. "undefined" != typeof console && "function" == typeof console.log && console.log.apply(console, arguments)
  2765. }
  2766. }, r.deprecated = function (e, t) {
  2767. n && console.warn(e + " is deprecated, please use " + t + " instead.")
  2768. }, r.detectBrowser = function (e) {
  2769. var t = e.navigator, r = {browser: null, version: null};
  2770. if (void 0 === e || !e.navigator) return r.browser = "Not a browser.", r;
  2771. if (t.mozGetUserMedia) r.browser = "firefox", r.version = o(t.userAgent, /Firefox\/(\d+)\./, 1); else if (t.webkitGetUserMedia || !1 === e.isSecureContext && e.webkitRTCPeerConnection && !e.RTCIceGatherer) r.browser = "chrome", r.version = o(t.userAgent, /Chrom(e|ium)\/(\d+)\./, 2); else if (t.mediaDevices && t.userAgent.match(/Edge\/(\d+).(\d+)$/)) r.browser = "edge", r.version = o(t.userAgent, /Edge\/(\d+).(\d+)$/, 2); else {
  2772. if (!e.RTCPeerConnection || !t.userAgent.match(/AppleWebKit\/(\d+)\./)) return r.browser = "Not a supported browser.", r;
  2773. r.browser = "safari", r.version = o(t.userAgent, /AppleWebKit\/(\d+)\./, 1)
  2774. }
  2775. return r
  2776. }, r.compactObject = function e(t) {
  2777. return "object" !== (void 0 === t ? "undefined" : i(t)) ? t : Object.keys(t).reduce(function (r, s) {
  2778. var n = "object" === i(t[s]), o = n ? e(t[s]) : t[s], a = n && !Object.keys(o).length;
  2779. return void 0 === o || a ? r : Object.assign(r, function (e, t, r) {
  2780. return t in e ? Object.defineProperty(e, t, {
  2781. value: r,
  2782. enumerable: !0,
  2783. configurable: !0,
  2784. writable: !0
  2785. }) : e[t] = r, e
  2786. }({}, s, o))
  2787. }, {})
  2788. }, r.walkStats = a, r.filterStats = function (e, t, r) {
  2789. var i = r ? "outbound-rtp" : "inbound-rtp", s = new Map;
  2790. if (null === t) return s;
  2791. var n = [];
  2792. return e.forEach(function (e) {
  2793. "track" === e.type && e.trackIdentifier === t.id && n.push(e)
  2794. }), n.forEach(function (t) {
  2795. e.forEach(function (r) {
  2796. r.type === i && r.trackId === t.id && a(e, r, s)
  2797. })
  2798. }), s
  2799. };
  2800. var s = !0, n = !0;
  2801. function o(e, t, r) {
  2802. var i = e.match(t);
  2803. return i && i.length >= r && parseInt(i[r], 10)
  2804. }
  2805. function a(e, t, r) {
  2806. t && !r.has(t.id) && (r.set(t.id, t), Object.keys(t).forEach(function (i) {
  2807. i.endsWith("Id") ? a(e, e.get(t[i]), r) : i.endsWith("Ids") && t[i].forEach(function (t) {
  2808. a(e, e.get(t), r)
  2809. })
  2810. }))
  2811. }
  2812. }, {}], 16: [function (e, t, r) {
  2813. "use strict";
  2814. var i = e("sdp");
  2815. function s(e, t, r, s, n) {
  2816. var o = i.writeRtpDescription(e.kind, t);
  2817. if (o += i.writeIceParameters(e.iceGatherer.getLocalParameters()), o += i.writeDtlsParameters(e.dtlsTransport.getLocalParameters(), "offer" === r ? "actpass" : n || "active"), o += "a=mid:" + e.mid + "\r\n", e.rtpSender && e.rtpReceiver ? o += "a=sendrecv\r\n" : e.rtpSender ? o += "a=sendonly\r\n" : e.rtpReceiver ? o += "a=recvonly\r\n" : o += "a=inactive\r\n", e.rtpSender) {
  2818. var a = e.rtpSender._initialTrackId || e.rtpSender.track.id;
  2819. e.rtpSender._initialTrackId = a;
  2820. var c = "msid:" + (s ? s.id : "-") + " " + a + "\r\n";
  2821. o += "a=" + c, o += "a=ssrc:" + e.sendEncodingParameters[0].ssrc + " " + c, e.sendEncodingParameters[0].rtx && (o += "a=ssrc:" + e.sendEncodingParameters[0].rtx.ssrc + " " + c, o += "a=ssrc-group:FID " + e.sendEncodingParameters[0].ssrc + " " + e.sendEncodingParameters[0].rtx.ssrc + "\r\n")
  2822. }
  2823. return o += "a=ssrc:" + e.sendEncodingParameters[0].ssrc + " cname:" + i.localCName + "\r\n", e.rtpSender && e.sendEncodingParameters[0].rtx && (o += "a=ssrc:" + e.sendEncodingParameters[0].rtx.ssrc + " cname:" + i.localCName + "\r\n"), o
  2824. }
  2825. function n(e, t) {
  2826. var r = {codecs: [], headerExtensions: [], fecMechanisms: []}, i = function (e, t) {
  2827. e = parseInt(e, 10);
  2828. for (var r = 0; r < t.length; r++) if (t[r].payloadType === e || t[r].preferredPayloadType === e) return t[r]
  2829. }, s = function (e, t, r, s) {
  2830. var n = i(e.parameters.apt, r), o = i(t.parameters.apt, s);
  2831. return n && o && n.name.toLowerCase() === o.name.toLowerCase()
  2832. };
  2833. return e.codecs.forEach(function (i) {
  2834. for (var n = 0; n < t.codecs.length; n++) {
  2835. var o = t.codecs[n];
  2836. if (i.name.toLowerCase() === o.name.toLowerCase() && i.clockRate === o.clockRate) {
  2837. if ("rtx" === i.name.toLowerCase() && i.parameters && o.parameters.apt && !s(i, o, e.codecs, t.codecs)) continue;
  2838. (o = JSON.parse(JSON.stringify(o))).numChannels = Math.min(i.numChannels, o.numChannels), r.codecs.push(o), o.rtcpFeedback = o.rtcpFeedback.filter(function (e) {
  2839. for (var t = 0; t < i.rtcpFeedback.length; t++) if (i.rtcpFeedback[t].type === e.type && i.rtcpFeedback[t].parameter === e.parameter) return !0;
  2840. return !1
  2841. });
  2842. break
  2843. }
  2844. }
  2845. }), e.headerExtensions.forEach(function (e) {
  2846. for (var i = 0; i < t.headerExtensions.length; i++) {
  2847. var s = t.headerExtensions[i];
  2848. if (e.uri === s.uri) {
  2849. r.headerExtensions.push(s);
  2850. break
  2851. }
  2852. }
  2853. }), r
  2854. }
  2855. function o(e, t, r) {
  2856. return -1 !== {
  2857. offer: {
  2858. setLocalDescription: ["stable", "have-local-offer"],
  2859. setRemoteDescription: ["stable", "have-remote-offer"]
  2860. },
  2861. answer: {
  2862. setLocalDescription: ["have-remote-offer", "have-local-pranswer"],
  2863. setRemoteDescription: ["have-local-offer", "have-remote-pranswer"]
  2864. }
  2865. }[t][e].indexOf(r)
  2866. }
  2867. function a(e, t) {
  2868. var r = e.getRemoteCandidates().find(function (e) {
  2869. return t.foundation === e.foundation && t.ip === e.ip && t.port === e.port && t.priority === e.priority && t.protocol === e.protocol && t.type === e.type
  2870. });
  2871. return r || e.addRemoteCandidate(t), !r
  2872. }
  2873. function c(e, t) {
  2874. var r = new Error(t);
  2875. return r.name = e, r.code = {
  2876. NotSupportedError: 9,
  2877. InvalidStateError: 11,
  2878. InvalidAccessError: 15,
  2879. TypeError: void 0,
  2880. OperationError: void 0
  2881. }[e], r
  2882. }
  2883. t.exports = function (e, t) {
  2884. function r(t, r) {
  2885. r.addTrack(t), r.dispatchEvent(new e.MediaStreamTrackEvent("addtrack", {track: t}))
  2886. }
  2887. function l(t, r, i, s) {
  2888. var n = new Event("track");
  2889. n.track = r, n.receiver = i, n.transceiver = {receiver: i}, n.streams = s, e.setTimeout(function () {
  2890. t._dispatchEvent("track", n)
  2891. })
  2892. }
  2893. var d = function (r) {
  2894. var s = this, n = document.createDocumentFragment();
  2895. if (["addEventListener", "removeEventListener", "dispatchEvent"].forEach(function (e) {
  2896. s[e] = n[e].bind(n)
  2897. }), this.canTrickleIceCandidates = null, this.needNegotiation = !1, this.localStreams = [], this.remoteStreams = [], this._localDescription = null, this._remoteDescription = null, this.signalingState = "stable", this.iceConnectionState = "new", this.connectionState = "new", this.iceGatheringState = "new", r = JSON.parse(JSON.stringify(r || {})), this.usingBundle = "max-bundle" === r.bundlePolicy, "negotiate" === r.rtcpMuxPolicy) throw c("NotSupportedError", "rtcpMuxPolicy 'negotiate' is not supported");
  2898. switch (r.rtcpMuxPolicy || (r.rtcpMuxPolicy = "require"), r.iceTransportPolicy) {
  2899. case"all":
  2900. case"relay":
  2901. break;
  2902. default:
  2903. r.iceTransportPolicy = "all"
  2904. }
  2905. switch (r.bundlePolicy) {
  2906. case"balanced":
  2907. case"max-compat":
  2908. case"max-bundle":
  2909. break;
  2910. default:
  2911. r.bundlePolicy = "balanced"
  2912. }
  2913. if (r.iceServers = function (e, t) {
  2914. var r = !1;
  2915. return (e = JSON.parse(JSON.stringify(e))).filter(function (e) {
  2916. if (e && (e.urls || e.url)) {
  2917. var i = e.urls || e.url;
  2918. e.url && !e.urls && console.warn("RTCIceServer.url is deprecated! Use urls instead.");
  2919. var s = "string" == typeof i;
  2920. return s && (i = [i]), i = i.filter(function (e) {
  2921. return 0 !== e.indexOf("turn:") || -1 === e.indexOf("transport=udp") || -1 !== e.indexOf("turn:[") || r ? 0 === e.indexOf("stun:") && t >= 14393 && -1 === e.indexOf("?transport=udp") : (r = !0, !0)
  2922. }), delete e.url, e.urls = s ? i[0] : i, !!i.length
  2923. }
  2924. })
  2925. }(r.iceServers || [], t), this._iceGatherers = [], r.iceCandidatePoolSize) for (var o = r.iceCandidatePoolSize; o > 0; o--) this._iceGatherers.push(new e.RTCIceGatherer({
  2926. iceServers: r.iceServers,
  2927. gatherPolicy: r.iceTransportPolicy
  2928. })); else r.iceCandidatePoolSize = 0;
  2929. this._config = r, this.transceivers = [], this._sdpSessionId = i.generateSessionId(), this._sdpSessionVersion = 0, this._dtlsRole = void 0, this._isClosed = !1
  2930. };
  2931. Object.defineProperty(d.prototype, "localDescription", {
  2932. configurable: !0, get: function () {
  2933. return this._localDescription
  2934. }
  2935. }), Object.defineProperty(d.prototype, "remoteDescription", {
  2936. configurable: !0, get: function () {
  2937. return this._remoteDescription
  2938. }
  2939. }), d.prototype.onicecandidate = null, d.prototype.onaddstream = null, d.prototype.ontrack = null, d.prototype.onremovestream = null, d.prototype.onsignalingstatechange = null, d.prototype.oniceconnectionstatechange = null, d.prototype.onconnectionstatechange = null, d.prototype.onicegatheringstatechange = null, d.prototype.onnegotiationneeded = null, d.prototype.ondatachannel = null, d.prototype._dispatchEvent = function (e, t) {
  2940. this._isClosed || (this.dispatchEvent(t), "function" == typeof this["on" + e] && this["on" + e](t))
  2941. }, d.prototype._emitGatheringStateChange = function () {
  2942. var e = new Event("icegatheringstatechange");
  2943. this._dispatchEvent("icegatheringstatechange", e)
  2944. }, d.prototype.getConfiguration = function () {
  2945. return this._config
  2946. }, d.prototype.getLocalStreams = function () {
  2947. return this.localStreams
  2948. }, d.prototype.getRemoteStreams = function () {
  2949. return this.remoteStreams
  2950. }, d.prototype._createTransceiver = function (e, t) {
  2951. var r = this.transceivers.length > 0, i = {
  2952. track: null,
  2953. iceGatherer: null,
  2954. iceTransport: null,
  2955. dtlsTransport: null,
  2956. localCapabilities: null,
  2957. remoteCapabilities: null,
  2958. rtpSender: null,
  2959. rtpReceiver: null,
  2960. kind: e,
  2961. mid: null,
  2962. sendEncodingParameters: null,
  2963. recvEncodingParameters: null,
  2964. stream: null,
  2965. associatedRemoteMediaStreams: [],
  2966. wantReceive: !0
  2967. };
  2968. if (this.usingBundle && r) i.iceTransport = this.transceivers[0].iceTransport, i.dtlsTransport = this.transceivers[0].dtlsTransport; else {
  2969. var s = this._createIceAndDtlsTransports();
  2970. i.iceTransport = s.iceTransport, i.dtlsTransport = s.dtlsTransport
  2971. }
  2972. return t || this.transceivers.push(i), i
  2973. }, d.prototype.addTrack = function (t, r) {
  2974. if (this._isClosed) throw c("InvalidStateError", "Attempted to call addTrack on a closed peerconnection.");
  2975. var i, s = this.transceivers.find(function (e) {
  2976. return e.track === t
  2977. });
  2978. if (s) throw c("InvalidAccessError", "Track already exists.");
  2979. for (var n = 0; n < this.transceivers.length; n++) this.transceivers[n].track || this.transceivers[n].kind !== t.kind || (i = this.transceivers[n]);
  2980. return i || (i = this._createTransceiver(t.kind)), this._maybeFireNegotiationNeeded(), -1 === this.localStreams.indexOf(r) && this.localStreams.push(r), i.track = t, i.stream = r, i.rtpSender = new e.RTCRtpSender(t, i.dtlsTransport), i.rtpSender
  2981. }, d.prototype.addStream = function (e) {
  2982. var r = this;
  2983. if (t >= 15025) e.getTracks().forEach(function (t) {
  2984. r.addTrack(t, e)
  2985. }); else {
  2986. var i = e.clone();
  2987. e.getTracks().forEach(function (e, t) {
  2988. var r = i.getTracks()[t];
  2989. e.addEventListener("enabled", function (e) {
  2990. r.enabled = e.enabled
  2991. })
  2992. }), i.getTracks().forEach(function (e) {
  2993. r.addTrack(e, i)
  2994. })
  2995. }
  2996. }, d.prototype.removeTrack = function (t) {
  2997. if (this._isClosed) throw c("InvalidStateError", "Attempted to call removeTrack on a closed peerconnection.");
  2998. if (!(t instanceof e.RTCRtpSender)) throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");
  2999. var r = this.transceivers.find(function (e) {
  3000. return e.rtpSender === t
  3001. });
  3002. if (!r) throw c("InvalidAccessError", "Sender was not created by this connection.");
  3003. var i = r.stream;
  3004. r.rtpSender.stop(), r.rtpSender = null, r.track = null, r.stream = null;
  3005. var s = this.transceivers.map(function (e) {
  3006. return e.stream
  3007. });
  3008. -1 === s.indexOf(i) && this.localStreams.indexOf(i) > -1 && this.localStreams.splice(this.localStreams.indexOf(i), 1), this._maybeFireNegotiationNeeded()
  3009. }, d.prototype.removeStream = function (e) {
  3010. var t = this;
  3011. e.getTracks().forEach(function (e) {
  3012. var r = t.getSenders().find(function (t) {
  3013. return t.track === e
  3014. });
  3015. r && t.removeTrack(r)
  3016. })
  3017. }, d.prototype.getSenders = function () {
  3018. return this.transceivers.filter(function (e) {
  3019. return !!e.rtpSender
  3020. }).map(function (e) {
  3021. return e.rtpSender
  3022. })
  3023. }, d.prototype.getReceivers = function () {
  3024. return this.transceivers.filter(function (e) {
  3025. return !!e.rtpReceiver
  3026. }).map(function (e) {
  3027. return e.rtpReceiver
  3028. })
  3029. }, d.prototype._createIceGatherer = function (t, r) {
  3030. var i = this;
  3031. if (r && t > 0) return this.transceivers[0].iceGatherer;
  3032. if (this._iceGatherers.length) return this._iceGatherers.shift();
  3033. var s = new e.RTCIceGatherer({
  3034. iceServers: this._config.iceServers,
  3035. gatherPolicy: this._config.iceTransportPolicy
  3036. });
  3037. return Object.defineProperty(s, "state", {
  3038. value: "new",
  3039. writable: !0
  3040. }), this.transceivers[t].bufferedCandidateEvents = [], this.transceivers[t].bufferCandidates = function (e) {
  3041. var r = !e.candidate || 0 === Object.keys(e.candidate).length;
  3042. s.state = r ? "completed" : "gathering", null !== i.transceivers[t].bufferedCandidateEvents && i.transceivers[t].bufferedCandidateEvents.push(e)
  3043. }, s.addEventListener("localcandidate", this.transceivers[t].bufferCandidates), s
  3044. }, d.prototype._gather = function (t, r) {
  3045. var s = this, n = this.transceivers[r].iceGatherer;
  3046. if (!n.onlocalcandidate) {
  3047. var o = this.transceivers[r].bufferedCandidateEvents;
  3048. this.transceivers[r].bufferedCandidateEvents = null, n.removeEventListener("localcandidate", this.transceivers[r].bufferCandidates), n.onlocalcandidate = function (e) {
  3049. if (!(s.usingBundle && r > 0)) {
  3050. var o = new Event("icecandidate");
  3051. o.candidate = {sdpMid: t, sdpMLineIndex: r};
  3052. var a = e.candidate, c = !a || 0 === Object.keys(a).length;
  3053. if (c) "new" !== n.state && "gathering" !== n.state || (n.state = "completed"); else {
  3054. "new" === n.state && (n.state = "gathering"), a.component = 1, a.ufrag = n.getLocalParameters().usernameFragment;
  3055. var l = i.writeCandidate(a);
  3056. o.candidate = Object.assign(o.candidate, i.parseCandidate(l)), o.candidate.candidate = l, o.candidate.toJSON = function () {
  3057. return {
  3058. candidate: o.candidate.candidate,
  3059. sdpMid: o.candidate.sdpMid,
  3060. sdpMLineIndex: o.candidate.sdpMLineIndex,
  3061. usernameFragment: o.candidate.usernameFragment
  3062. }
  3063. }
  3064. }
  3065. var d = i.getMediaSections(s._localDescription.sdp);
  3066. d[o.candidate.sdpMLineIndex] += c ? "a=end-of-candidates\r\n" : "a=" + o.candidate.candidate + "\r\n", s._localDescription.sdp = i.getDescription(s._localDescription.sdp) + d.join("");
  3067. var h = s.transceivers.every(function (e) {
  3068. return e.iceGatherer && "completed" === e.iceGatherer.state
  3069. });
  3070. "gathering" !== s.iceGatheringState && (s.iceGatheringState = "gathering", s._emitGatheringStateChange()), c || s._dispatchEvent("icecandidate", o), h && (s._dispatchEvent("icecandidate", new Event("icecandidate")), s.iceGatheringState = "complete", s._emitGatheringStateChange())
  3071. }
  3072. }, e.setTimeout(function () {
  3073. o.forEach(function (e) {
  3074. n.onlocalcandidate(e)
  3075. })
  3076. }, 0)
  3077. }
  3078. }, d.prototype._createIceAndDtlsTransports = function () {
  3079. var t = this, r = new e.RTCIceTransport(null);
  3080. r.onicestatechange = function () {
  3081. t._updateIceConnectionState(), t._updateConnectionState()
  3082. };
  3083. var i = new e.RTCDtlsTransport(r);
  3084. return i.ondtlsstatechange = function () {
  3085. t._updateConnectionState()
  3086. }, i.onerror = function () {
  3087. Object.defineProperty(i, "state", {
  3088. value: "failed",
  3089. writable: !0
  3090. }), t._updateConnectionState()
  3091. }, {iceTransport: r, dtlsTransport: i}
  3092. }, d.prototype._disposeIceAndDtlsTransports = function (e) {
  3093. var t = this.transceivers[e].iceGatherer;
  3094. t && (delete t.onlocalcandidate, delete this.transceivers[e].iceGatherer);
  3095. var r = this.transceivers[e].iceTransport;
  3096. r && (delete r.onicestatechange, delete this.transceivers[e].iceTransport);
  3097. var i = this.transceivers[e].dtlsTransport;
  3098. i && (delete i.ondtlsstatechange, delete i.onerror, delete this.transceivers[e].dtlsTransport)
  3099. }, d.prototype._transceive = function (e, r, s) {
  3100. var o = n(e.localCapabilities, e.remoteCapabilities);
  3101. r && e.rtpSender && (o.encodings = e.sendEncodingParameters, o.rtcp = {
  3102. cname: i.localCName,
  3103. compound: e.rtcpParameters.compound
  3104. }, e.recvEncodingParameters.length && (o.rtcp.ssrc = e.recvEncodingParameters[0].ssrc), e.rtpSender.send(o)), s && e.rtpReceiver && o.codecs.length > 0 && ("video" === e.kind && e.recvEncodingParameters && t < 15019 && e.recvEncodingParameters.forEach(function (e) {
  3105. delete e.rtx
  3106. }), e.recvEncodingParameters.length ? o.encodings = e.recvEncodingParameters : o.encodings = [{}], o.rtcp = {compound: e.rtcpParameters.compound}, e.rtcpParameters.cname && (o.rtcp.cname = e.rtcpParameters.cname), e.sendEncodingParameters.length && (o.rtcp.ssrc = e.sendEncodingParameters[0].ssrc), e.rtpReceiver.receive(o))
  3107. }, d.prototype.setLocalDescription = function (e) {
  3108. var t, r, s = this;
  3109. if (-1 === ["offer", "answer"].indexOf(e.type)) return Promise.reject(c("TypeError", 'Unsupported type "' + e.type + '"'));
  3110. if (!o("setLocalDescription", e.type, s.signalingState) || s._isClosed) return Promise.reject(c("InvalidStateError", "Can not set local " + e.type + " in state " + s.signalingState));
  3111. if ("offer" === e.type) t = i.splitSections(e.sdp), r = t.shift(), t.forEach(function (e, t) {
  3112. var r = i.parseRtpParameters(e);
  3113. s.transceivers[t].localCapabilities = r
  3114. }), s.transceivers.forEach(function (e, t) {
  3115. s._gather(e.mid, t)
  3116. }); else if ("answer" === e.type) {
  3117. t = i.splitSections(s._remoteDescription.sdp), r = t.shift();
  3118. var a = i.matchPrefix(r, "a=ice-lite").length > 0;
  3119. t.forEach(function (e, t) {
  3120. var o = s.transceivers[t], c = o.iceGatherer, l = o.iceTransport, d = o.dtlsTransport,
  3121. h = o.localCapabilities, u = o.remoteCapabilities,
  3122. p = i.isRejected(e) && 0 === i.matchPrefix(e, "a=bundle-only").length;
  3123. if (!p && !o.rejected) {
  3124. var g = i.getIceParameters(e, r), f = i.getDtlsParameters(e, r);
  3125. a && (f.role = "server"), s.usingBundle && 0 !== t || (s._gather(o.mid, t), "new" === l.state && l.start(c, g, a ? "controlling" : "controlled"), "new" === d.state && d.start(f));
  3126. var m = n(h, u);
  3127. s._transceive(o, m.codecs.length > 0, !1)
  3128. }
  3129. })
  3130. }
  3131. return s._localDescription = {
  3132. type: e.type,
  3133. sdp: e.sdp
  3134. }, "offer" === e.type ? s._updateSignalingState("have-local-offer") : s._updateSignalingState("stable"), Promise.resolve()
  3135. }, d.prototype.setRemoteDescription = function (s) {
  3136. var d = this;
  3137. if (-1 === ["offer", "answer"].indexOf(s.type)) return Promise.reject(c("TypeError", 'Unsupported type "' + s.type + '"'));
  3138. if (!o("setRemoteDescription", s.type, d.signalingState) || d._isClosed) return Promise.reject(c("InvalidStateError", "Can not set remote " + s.type + " in state " + d.signalingState));
  3139. var h = {};
  3140. d.remoteStreams.forEach(function (e) {
  3141. h[e.id] = e
  3142. });
  3143. var u = [], p = i.splitSections(s.sdp), g = p.shift(),
  3144. f = i.matchPrefix(g, "a=ice-lite").length > 0,
  3145. m = i.matchPrefix(g, "a=group:BUNDLE ").length > 0;
  3146. d.usingBundle = m;
  3147. var v = i.matchPrefix(g, "a=ice-options:")[0];
  3148. return d.canTrickleIceCandidates = !!v && v.substr(14).split(" ").indexOf("trickle") >= 0, p.forEach(function (o, c) {
  3149. var l = i.splitLines(o), p = i.getKind(o),
  3150. v = i.isRejected(o) && 0 === i.matchPrefix(o, "a=bundle-only").length,
  3151. S = l[0].substr(2).split(" ")[2], y = i.getDirection(o, g), b = i.parseMsid(o),
  3152. C = i.getMid(o) || i.generateIdentifier();
  3153. if (v || "application" === p && ("DTLS/SCTP" === S || "UDP/DTLS/SCTP" === S)) d.transceivers[c] = {
  3154. mid: C,
  3155. kind: p,
  3156. protocol: S,
  3157. rejected: !0
  3158. }; else {
  3159. var _, T, E, R, M, P, L, k, w;
  3160. !v && d.transceivers[c] && d.transceivers[c].rejected && (d.transceivers[c] = d._createTransceiver(p, !0));
  3161. var I, U, O = i.parseRtpParameters(o);
  3162. v || (I = i.getIceParameters(o, g), (U = i.getDtlsParameters(o, g)).role = "client"), L = i.parseRtpEncodingParameters(o);
  3163. var D = i.parseRtcpParameters(o),
  3164. z = i.matchPrefix(o, "a=end-of-candidates", g).length > 0,
  3165. N = i.matchPrefix(o, "a=candidate:").map(function (e) {
  3166. return i.parseCandidate(e)
  3167. }).filter(function (e) {
  3168. return 1 === e.component
  3169. });
  3170. if (("offer" === s.type || "answer" === s.type) && !v && m && c > 0 && d.transceivers[c] && (d._disposeIceAndDtlsTransports(c), d.transceivers[c].iceGatherer = d.transceivers[0].iceGatherer, d.transceivers[c].iceTransport = d.transceivers[0].iceTransport, d.transceivers[c].dtlsTransport = d.transceivers[0].dtlsTransport, d.transceivers[c].rtpSender && d.transceivers[c].rtpSender.setTransport(d.transceivers[0].dtlsTransport), d.transceivers[c].rtpReceiver && d.transceivers[c].rtpReceiver.setTransport(d.transceivers[0].dtlsTransport)), "offer" !== s.type || v) {
  3171. if ("answer" === s.type && !v) {
  3172. _ = d.transceivers[c], T = _.iceGatherer, E = _.iceTransport, R = _.dtlsTransport, M = _.rtpReceiver, P = _.sendEncodingParameters, k = _.localCapabilities, d.transceivers[c].recvEncodingParameters = L, d.transceivers[c].remoteCapabilities = O, d.transceivers[c].rtcpParameters = D, N.length && "new" === E.state && (!f && !z || m && 0 !== c ? N.forEach(function (e) {
  3173. a(_.iceTransport, e)
  3174. }) : E.setRemoteCandidates(N)), m && 0 !== c || ("new" === E.state && E.start(T, I, "controlling"), "new" === R.state && R.start(U));
  3175. var A = n(_.localCapabilities, _.remoteCapabilities),
  3176. x = A.codecs.filter(function (e) {
  3177. return "rtx" === e.name.toLowerCase()
  3178. }).length;
  3179. !x && _.sendEncodingParameters[0].rtx && delete _.sendEncodingParameters[0].rtx, d._transceive(_, "sendrecv" === y || "recvonly" === y, "sendrecv" === y || "sendonly" === y), !M || "sendrecv" !== y && "sendonly" !== y ? delete _.rtpReceiver : (w = M.track, b ? (h[b.stream] || (h[b.stream] = new e.MediaStream), r(w, h[b.stream]), u.push([w, M, h[b.stream]])) : (h.default || (h.default = new e.MediaStream), r(w, h.default), u.push([w, M, h.default])))
  3180. }
  3181. } else {
  3182. (_ = d.transceivers[c] || d._createTransceiver(p)).mid = C, _.iceGatherer || (_.iceGatherer = d._createIceGatherer(c, m)), N.length && "new" === _.iceTransport.state && (!z || m && 0 !== c ? N.forEach(function (e) {
  3183. a(_.iceTransport, e)
  3184. }) : _.iceTransport.setRemoteCandidates(N)), k = e.RTCRtpReceiver.getCapabilities(p), t < 15019 && (k.codecs = k.codecs.filter(function (e) {
  3185. return "rtx" !== e.name
  3186. })), P = _.sendEncodingParameters || [{ssrc: 1001 * (2 * c + 2)}];
  3187. var q, H = !1;
  3188. "sendrecv" === y || "sendonly" === y ? (H = !_.rtpReceiver, M = _.rtpReceiver || new e.RTCRtpReceiver(_.dtlsTransport, p), H && (w = M.track, b && "-" === b.stream || (b ? (h[b.stream] || (h[b.stream] = new e.MediaStream, Object.defineProperty(h[b.stream], "id", {
  3189. get: function () {
  3190. return b.stream
  3191. }
  3192. })), Object.defineProperty(w, "id", {
  3193. get: function () {
  3194. return b.track
  3195. }
  3196. }), q = h[b.stream]) : (h.default || (h.default = new e.MediaStream), q = h.default)), q && (r(w, q), _.associatedRemoteMediaStreams.push(q)), u.push([w, M, q]))) : _.rtpReceiver && _.rtpReceiver.track && (_.associatedRemoteMediaStreams.forEach(function (t) {
  3197. var r = t.getTracks().find(function (e) {
  3198. return e.id === _.rtpReceiver.track.id
  3199. });
  3200. r && function (t, r) {
  3201. r.removeTrack(t), r.dispatchEvent(new e.MediaStreamTrackEvent("removetrack", {track: t}))
  3202. }(r, t)
  3203. }), _.associatedRemoteMediaStreams = []), _.localCapabilities = k, _.remoteCapabilities = O, _.rtpReceiver = M, _.rtcpParameters = D, _.sendEncodingParameters = P, _.recvEncodingParameters = L, d._transceive(d.transceivers[c], !1, H)
  3204. }
  3205. }
  3206. }), void 0 === d._dtlsRole && (d._dtlsRole = "offer" === s.type ? "active" : "passive"), d._remoteDescription = {
  3207. type: s.type,
  3208. sdp: s.sdp
  3209. }, "offer" === s.type ? d._updateSignalingState("have-remote-offer") : d._updateSignalingState("stable"), Object.keys(h).forEach(function (t) {
  3210. var r = h[t];
  3211. if (r.getTracks().length) {
  3212. if (-1 === d.remoteStreams.indexOf(r)) {
  3213. d.remoteStreams.push(r);
  3214. var i = new Event("addstream");
  3215. i.stream = r, e.setTimeout(function () {
  3216. d._dispatchEvent("addstream", i)
  3217. })
  3218. }
  3219. u.forEach(function (e) {
  3220. var t = e[0], i = e[1];
  3221. r.id === e[2].id && l(d, t, i, [r])
  3222. })
  3223. }
  3224. }), u.forEach(function (e) {
  3225. e[2] || l(d, e[0], e[1], [])
  3226. }), e.setTimeout(function () {
  3227. d && d.transceivers && d.transceivers.forEach(function (e) {
  3228. e.iceTransport && "new" === e.iceTransport.state && e.iceTransport.getRemoteCandidates().length > 0 && (console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"), e.iceTransport.addRemoteCandidate({}))
  3229. })
  3230. }, 4e3), Promise.resolve()
  3231. }, d.prototype.close = function () {
  3232. this.transceivers.forEach(function (e) {
  3233. e.iceTransport && e.iceTransport.stop(), e.dtlsTransport && e.dtlsTransport.stop(), e.rtpSender && e.rtpSender.stop(), e.rtpReceiver && e.rtpReceiver.stop()
  3234. }), this._isClosed = !0, this._updateSignalingState("closed")
  3235. }, d.prototype._updateSignalingState = function (e) {
  3236. this.signalingState = e;
  3237. var t = new Event("signalingstatechange");
  3238. this._dispatchEvent("signalingstatechange", t)
  3239. }, d.prototype._maybeFireNegotiationNeeded = function () {
  3240. var t = this;
  3241. "stable" === this.signalingState && !0 !== this.needNegotiation && (this.needNegotiation = !0, e.setTimeout(function () {
  3242. if (t.needNegotiation) {
  3243. t.needNegotiation = !1;
  3244. var e = new Event("negotiationneeded");
  3245. t._dispatchEvent("negotiationneeded", e)
  3246. }
  3247. }, 0))
  3248. }, d.prototype._updateIceConnectionState = function () {
  3249. var e, t = {
  3250. new: 0,
  3251. closed: 0,
  3252. checking: 0,
  3253. connected: 0,
  3254. completed: 0,
  3255. disconnected: 0,
  3256. failed: 0
  3257. };
  3258. if (this.transceivers.forEach(function (e) {
  3259. e.iceTransport && !e.rejected && t[e.iceTransport.state]++
  3260. }), e = "new", t.failed > 0 ? e = "failed" : t.checking > 0 ? e = "checking" : t.disconnected > 0 ? e = "disconnected" : t.new > 0 ? e = "new" : t.connected > 0 ? e = "connected" : t.completed > 0 && (e = "completed"), e !== this.iceConnectionState) {
  3261. this.iceConnectionState = e;
  3262. var r = new Event("iceconnectionstatechange");
  3263. this._dispatchEvent("iceconnectionstatechange", r)
  3264. }
  3265. }, d.prototype._updateConnectionState = function () {
  3266. var e, t = {
  3267. new: 0,
  3268. closed: 0,
  3269. connecting: 0,
  3270. connected: 0,
  3271. completed: 0,
  3272. disconnected: 0,
  3273. failed: 0
  3274. };
  3275. if (this.transceivers.forEach(function (e) {
  3276. e.iceTransport && e.dtlsTransport && !e.rejected && (t[e.iceTransport.state]++, t[e.dtlsTransport.state]++)
  3277. }), t.connected += t.completed, e = "new", t.failed > 0 ? e = "failed" : t.connecting > 0 ? e = "connecting" : t.disconnected > 0 ? e = "disconnected" : t.new > 0 ? e = "new" : t.connected > 0 && (e = "connected"), e !== this.connectionState) {
  3278. this.connectionState = e;
  3279. var r = new Event("connectionstatechange");
  3280. this._dispatchEvent("connectionstatechange", r)
  3281. }
  3282. }, d.prototype.createOffer = function () {
  3283. var r = this;
  3284. if (r._isClosed) return Promise.reject(c("InvalidStateError", "Can not call createOffer after close"));
  3285. var n = r.transceivers.filter(function (e) {
  3286. return "audio" === e.kind
  3287. }).length, o = r.transceivers.filter(function (e) {
  3288. return "video" === e.kind
  3289. }).length, a = arguments[0];
  3290. if (a) {
  3291. if (a.mandatory || a.optional) throw new TypeError("Legacy mandatory/optional constraints not supported.");
  3292. void 0 !== a.offerToReceiveAudio && (n = !0 === a.offerToReceiveAudio ? 1 : !1 === a.offerToReceiveAudio ? 0 : a.offerToReceiveAudio), void 0 !== a.offerToReceiveVideo && (o = !0 === a.offerToReceiveVideo ? 1 : !1 === a.offerToReceiveVideo ? 0 : a.offerToReceiveVideo)
  3293. }
  3294. for (r.transceivers.forEach(function (e) {
  3295. "audio" === e.kind ? --n < 0 && (e.wantReceive = !1) : "video" === e.kind && --o < 0 && (e.wantReceive = !1)
  3296. }); n > 0 || o > 0;) n > 0 && (r._createTransceiver("audio"), n--), o > 0 && (r._createTransceiver("video"), o--);
  3297. var l = i.writeSessionBoilerplate(r._sdpSessionId, r._sdpSessionVersion++);
  3298. r.transceivers.forEach(function (s, n) {
  3299. var o = s.track, a = s.kind, c = s.mid || i.generateIdentifier();
  3300. s.mid = c, s.iceGatherer || (s.iceGatherer = r._createIceGatherer(n, r.usingBundle));
  3301. var l = e.RTCRtpSender.getCapabilities(a);
  3302. t < 15019 && (l.codecs = l.codecs.filter(function (e) {
  3303. return "rtx" !== e.name
  3304. })), l.codecs.forEach(function (e) {
  3305. "H264" === e.name && void 0 === e.parameters["level-asymmetry-allowed"] && (e.parameters["level-asymmetry-allowed"] = "1"), s.remoteCapabilities && s.remoteCapabilities.codecs && s.remoteCapabilities.codecs.forEach(function (t) {
  3306. e.name.toLowerCase() === t.name.toLowerCase() && e.clockRate === t.clockRate && (e.preferredPayloadType = t.payloadType)
  3307. })
  3308. }), l.headerExtensions.forEach(function (e) {
  3309. var t = s.remoteCapabilities && s.remoteCapabilities.headerExtensions || [];
  3310. t.forEach(function (t) {
  3311. e.uri === t.uri && (e.id = t.id)
  3312. })
  3313. });
  3314. var d = s.sendEncodingParameters || [{ssrc: 1001 * (2 * n + 1)}];
  3315. o && t >= 15019 && "video" === a && !d[0].rtx && (d[0].rtx = {ssrc: d[0].ssrc + 1}), s.wantReceive && (s.rtpReceiver = new e.RTCRtpReceiver(s.dtlsTransport, a)), s.localCapabilities = l, s.sendEncodingParameters = d
  3316. }), "max-compat" !== r._config.bundlePolicy && (l += "a=group:BUNDLE " + r.transceivers.map(function (e) {
  3317. return e.mid
  3318. }).join(" ") + "\r\n"), l += "a=ice-options:trickle\r\n", r.transceivers.forEach(function (e, t) {
  3319. l += s(e, e.localCapabilities, "offer", e.stream, r._dtlsRole), l += "a=rtcp-rsize\r\n", !e.iceGatherer || "new" === r.iceGatheringState || 0 !== t && r.usingBundle || (e.iceGatherer.getLocalCandidates().forEach(function (e) {
  3320. e.component = 1, l += "a=" + i.writeCandidate(e) + "\r\n"
  3321. }), "completed" === e.iceGatherer.state && (l += "a=end-of-candidates\r\n"))
  3322. });
  3323. var d = new e.RTCSessionDescription({type: "offer", sdp: l});
  3324. return Promise.resolve(d)
  3325. }, d.prototype.createAnswer = function () {
  3326. var r = this;
  3327. if (r._isClosed) return Promise.reject(c("InvalidStateError", "Can not call createAnswer after close"));
  3328. if ("have-remote-offer" !== r.signalingState && "have-local-pranswer" !== r.signalingState) return Promise.reject(c("InvalidStateError", "Can not call createAnswer in signalingState " + r.signalingState));
  3329. var o = i.writeSessionBoilerplate(r._sdpSessionId, r._sdpSessionVersion++);
  3330. r.usingBundle && (o += "a=group:BUNDLE " + r.transceivers.map(function (e) {
  3331. return e.mid
  3332. }).join(" ") + "\r\n"), o += "a=ice-options:trickle\r\n";
  3333. var a = i.getMediaSections(r._remoteDescription.sdp).length;
  3334. r.transceivers.forEach(function (e, i) {
  3335. if (!(i + 1 > a)) {
  3336. if (e.rejected) return "application" === e.kind ? "DTLS/SCTP" === e.protocol ? o += "m=application 0 DTLS/SCTP 5000\r\n" : o += "m=application 0 " + e.protocol + " webrtc-datachannel\r\n" : "audio" === e.kind ? o += "m=audio 0 UDP/TLS/RTP/SAVPF 0\r\na=rtpmap:0 PCMU/8000\r\n" : "video" === e.kind && (o += "m=video 0 UDP/TLS/RTP/SAVPF 120\r\na=rtpmap:120 VP8/90000\r\n"), void (o += "c=IN IP4 0.0.0.0\r\na=inactive\r\na=mid:" + e.mid + "\r\n");
  3337. var c;
  3338. e.stream && ("audio" === e.kind ? c = e.stream.getAudioTracks()[0] : "video" === e.kind && (c = e.stream.getVideoTracks()[0]), c && t >= 15019 && "video" === e.kind && !e.sendEncodingParameters[0].rtx && (e.sendEncodingParameters[0].rtx = {ssrc: e.sendEncodingParameters[0].ssrc + 1}));
  3339. var l = n(e.localCapabilities, e.remoteCapabilities), d = l.codecs.filter(function (e) {
  3340. return "rtx" === e.name.toLowerCase()
  3341. }).length;
  3342. !d && e.sendEncodingParameters[0].rtx && delete e.sendEncodingParameters[0].rtx, o += s(e, l, "answer", e.stream, r._dtlsRole), e.rtcpParameters && e.rtcpParameters.reducedSize && (o += "a=rtcp-rsize\r\n")
  3343. }
  3344. });
  3345. var l = new e.RTCSessionDescription({type: "answer", sdp: o});
  3346. return Promise.resolve(l)
  3347. }, d.prototype.addIceCandidate = function (e) {
  3348. var t, r = this;
  3349. return e && void 0 === e.sdpMLineIndex && !e.sdpMid ? Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")) : new Promise(function (s, n) {
  3350. if (!r._remoteDescription) return n(c("InvalidStateError", "Can not add ICE candidate without a remote description"));
  3351. if (e && "" !== e.candidate) {
  3352. var o = e.sdpMLineIndex;
  3353. if (e.sdpMid) for (var l = 0; l < r.transceivers.length; l++) if (r.transceivers[l].mid === e.sdpMid) {
  3354. o = l;
  3355. break
  3356. }
  3357. var d = r.transceivers[o];
  3358. if (!d) return n(c("OperationError", "Can not add ICE candidate"));
  3359. if (d.rejected) return s();
  3360. var h = Object.keys(e.candidate).length > 0 ? i.parseCandidate(e.candidate) : {};
  3361. if ("tcp" === h.protocol && (0 === h.port || 9 === h.port)) return s();
  3362. if (h.component && 1 !== h.component) return s();
  3363. if ((0 === o || o > 0 && d.iceTransport !== r.transceivers[0].iceTransport) && !a(d.iceTransport, h)) return n(c("OperationError", "Can not add ICE candidate"));
  3364. var u = e.candidate.trim();
  3365. 0 === u.indexOf("a=") && (u = u.substr(2)), (t = i.getMediaSections(r._remoteDescription.sdp))[o] += "a=" + (h.type ? u : "end-of-candidates") + "\r\n", r._remoteDescription.sdp = i.getDescription(r._remoteDescription.sdp) + t.join("")
  3366. } else for (var p = 0; p < r.transceivers.length && (r.transceivers[p].rejected || (r.transceivers[p].iceTransport.addRemoteCandidate({}), (t = i.getMediaSections(r._remoteDescription.sdp))[p] += "a=end-of-candidates\r\n", r._remoteDescription.sdp = i.getDescription(r._remoteDescription.sdp) + t.join(""), !r.usingBundle)); p++) ;
  3367. s()
  3368. })
  3369. }, d.prototype.getStats = function (t) {
  3370. if (t && t instanceof e.MediaStreamTrack) {
  3371. var r = null;
  3372. if (this.transceivers.forEach(function (e) {
  3373. e.rtpSender && e.rtpSender.track === t ? r = e.rtpSender : e.rtpReceiver && e.rtpReceiver.track === t && (r = e.rtpReceiver)
  3374. }), !r) throw c("InvalidAccessError", "Invalid selector.");
  3375. return r.getStats()
  3376. }
  3377. var i = [];
  3378. return this.transceivers.forEach(function (e) {
  3379. ["rtpSender", "rtpReceiver", "iceGatherer", "iceTransport", "dtlsTransport"].forEach(function (t) {
  3380. e[t] && i.push(e[t].getStats())
  3381. })
  3382. }), Promise.all(i).then(function (e) {
  3383. var t = new Map;
  3384. return e.forEach(function (e) {
  3385. e.forEach(function (e) {
  3386. t.set(e.id, e)
  3387. })
  3388. }), t
  3389. })
  3390. }, ["RTCRtpSender", "RTCRtpReceiver", "RTCIceGatherer", "RTCIceTransport", "RTCDtlsTransport"].forEach(function (t) {
  3391. var r = e[t];
  3392. if (r && r.prototype && r.prototype.getStats) {
  3393. var i = r.prototype.getStats;
  3394. r.prototype.getStats = function () {
  3395. return i.apply(this).then(function (e) {
  3396. var t = new Map;
  3397. return Object.keys(e).forEach(function (r) {
  3398. var i;
  3399. e[r].type = {
  3400. inboundrtp: "inbound-rtp",
  3401. outboundrtp: "outbound-rtp",
  3402. candidatepair: "candidate-pair",
  3403. localcandidate: "local-candidate",
  3404. remotecandidate: "remote-candidate"
  3405. }[(i = e[r]).type] || i.type, t.set(r, e[r])
  3406. }), t
  3407. })
  3408. }
  3409. }
  3410. });
  3411. var h = ["createOffer", "createAnswer"];
  3412. return h.forEach(function (e) {
  3413. var t = d.prototype[e];
  3414. d.prototype[e] = function () {
  3415. var e = arguments;
  3416. return "function" == typeof e[0] || "function" == typeof e[1] ? t.apply(this, [arguments[2]]).then(function (t) {
  3417. "function" == typeof e[0] && e[0].apply(null, [t])
  3418. }, function (t) {
  3419. "function" == typeof e[1] && e[1].apply(null, [t])
  3420. }) : t.apply(this, arguments)
  3421. }
  3422. }), (h = ["setLocalDescription", "setRemoteDescription", "addIceCandidate"]).forEach(function (e) {
  3423. var t = d.prototype[e];
  3424. d.prototype[e] = function () {
  3425. var e = arguments;
  3426. return "function" == typeof e[1] || "function" == typeof e[2] ? t.apply(this, arguments).then(function () {
  3427. "function" == typeof e[1] && e[1].apply(null)
  3428. }, function (t) {
  3429. "function" == typeof e[2] && e[2].apply(null, [t])
  3430. }) : t.apply(this, arguments)
  3431. }
  3432. }), ["getStats"].forEach(function (e) {
  3433. var t = d.prototype[e];
  3434. d.prototype[e] = function () {
  3435. var e = arguments;
  3436. return "function" == typeof e[1] ? t.apply(this, arguments).then(function () {
  3437. "function" == typeof e[1] && e[1].apply(null)
  3438. }) : t.apply(this, arguments)
  3439. }
  3440. }), d
  3441. }
  3442. }, {sdp: 17}], 17: [function (e, t, r) {
  3443. "use strict";
  3444. var i = {
  3445. generateIdentifier: function () {
  3446. return Math.random().toString(36).substr(2, 10)
  3447. }
  3448. };
  3449. i.localCName = i.generateIdentifier(), i.splitLines = function (e) {
  3450. return e.trim().split("\n").map(function (e) {
  3451. return e.trim()
  3452. })
  3453. }, i.splitSections = function (e) {
  3454. var t = e.split("\nm=");
  3455. return t.map(function (e, t) {
  3456. return (t > 0 ? "m=" + e : e).trim() + "\r\n"
  3457. })
  3458. }, i.getDescription = function (e) {
  3459. var t = i.splitSections(e);
  3460. return t && t[0]
  3461. }, i.getMediaSections = function (e) {
  3462. var t = i.splitSections(e);
  3463. return t.shift(), t
  3464. }, i.matchPrefix = function (e, t) {
  3465. return i.splitLines(e).filter(function (e) {
  3466. return 0 === e.indexOf(t)
  3467. })
  3468. }, i.parseCandidate = function (e) {
  3469. for (var t, r = {
  3470. foundation: (t = 0 === e.indexOf("a=candidate:") ? e.substring(12).split(" ") : e.substring(10).split(" "))[0],
  3471. component: parseInt(t[1], 10),
  3472. protocol: t[2].toLowerCase(),
  3473. priority: parseInt(t[3], 10),
  3474. ip: t[4],
  3475. address: t[4],
  3476. port: parseInt(t[5], 10),
  3477. type: t[7]
  3478. }, i = 8; i < t.length; i += 2) switch (t[i]) {
  3479. case"raddr":
  3480. r.relatedAddress = t[i + 1];
  3481. break;
  3482. case"rport":
  3483. r.relatedPort = parseInt(t[i + 1], 10);
  3484. break;
  3485. case"tcptype":
  3486. r.tcpType = t[i + 1];
  3487. break;
  3488. case"ufrag":
  3489. r.ufrag = t[i + 1], r.usernameFragment = t[i + 1];
  3490. break;
  3491. default:
  3492. r[t[i]] = t[i + 1]
  3493. }
  3494. return r
  3495. }, i.writeCandidate = function (e) {
  3496. var t = [];
  3497. t.push(e.foundation), t.push(e.component), t.push(e.protocol.toUpperCase()), t.push(e.priority), t.push(e.address || e.ip), t.push(e.port);
  3498. var r = e.type;
  3499. return t.push("typ"), t.push(r), "host" !== r && e.relatedAddress && e.relatedPort && (t.push("raddr"), t.push(e.relatedAddress), t.push("rport"), t.push(e.relatedPort)), e.tcpType && "tcp" === e.protocol.toLowerCase() && (t.push("tcptype"), t.push(e.tcpType)), (e.usernameFragment || e.ufrag) && (t.push("ufrag"), t.push(e.usernameFragment || e.ufrag)), "candidate:" + t.join(" ")
  3500. }, i.parseIceOptions = function (e) {
  3501. return e.substr(14).split(" ")
  3502. }, i.parseRtpMap = function (e) {
  3503. var t = e.substr(9).split(" "), r = {payloadType: parseInt(t.shift(), 10)};
  3504. return t = t[0].split("/"), r.name = t[0], r.clockRate = parseInt(t[1], 10), r.channels = 3 === t.length ? parseInt(t[2], 10) : 1, r.numChannels = r.channels, r
  3505. }, i.writeRtpMap = function (e) {
  3506. var t = e.payloadType;
  3507. void 0 !== e.preferredPayloadType && (t = e.preferredPayloadType);
  3508. var r = e.channels || e.numChannels || 1;
  3509. return "a=rtpmap:" + t + " " + e.name + "/" + e.clockRate + (1 !== r ? "/" + r : "") + "\r\n"
  3510. }, i.parseExtmap = function (e) {
  3511. var t = e.substr(9).split(" ");
  3512. return {
  3513. id: parseInt(t[0], 10),
  3514. direction: t[0].indexOf("/") > 0 ? t[0].split("/")[1] : "sendrecv",
  3515. uri: t[1]
  3516. }
  3517. }, i.writeExtmap = function (e) {
  3518. return "a=extmap:" + (e.id || e.preferredId) + (e.direction && "sendrecv" !== e.direction ? "/" + e.direction : "") + " " + e.uri + "\r\n"
  3519. }, i.parseFmtp = function (e) {
  3520. for (var t, r = {}, i = e.substr(e.indexOf(" ") + 1).split(";"), s = 0; s < i.length; s++) t = i[s].trim().split("="), r[t[0].trim()] = t[1];
  3521. return r
  3522. }, i.writeFmtp = function (e) {
  3523. var t = "", r = e.payloadType;
  3524. if (void 0 !== e.preferredPayloadType && (r = e.preferredPayloadType), e.parameters && Object.keys(e.parameters).length) {
  3525. var i = [];
  3526. Object.keys(e.parameters).forEach(function (t) {
  3527. e.parameters[t] ? i.push(t + "=" + e.parameters[t]) : i.push(t)
  3528. }), t += "a=fmtp:" + r + " " + i.join(";") + "\r\n"
  3529. }
  3530. return t
  3531. }, i.parseRtcpFb = function (e) {
  3532. var t = e.substr(e.indexOf(" ") + 1).split(" ");
  3533. return {type: t.shift(), parameter: t.join(" ")}
  3534. }, i.writeRtcpFb = function (e) {
  3535. var t = "", r = e.payloadType;
  3536. return void 0 !== e.preferredPayloadType && (r = e.preferredPayloadType), e.rtcpFeedback && e.rtcpFeedback.length && e.rtcpFeedback.forEach(function (e) {
  3537. t += "a=rtcp-fb:" + r + " " + e.type + (e.parameter && e.parameter.length ? " " + e.parameter : "") + "\r\n"
  3538. }), t
  3539. }, i.parseSsrcMedia = function (e) {
  3540. var t = e.indexOf(" "), r = {ssrc: parseInt(e.substr(7, t - 7), 10)}, i = e.indexOf(":", t);
  3541. return i > -1 ? (r.attribute = e.substr(t + 1, i - t - 1), r.value = e.substr(i + 1)) : r.attribute = e.substr(t + 1), r
  3542. }, i.parseSsrcGroup = function (e) {
  3543. var t = e.substr(13).split(" ");
  3544. return {
  3545. semantics: t.shift(), ssrcs: t.map(function (e) {
  3546. return parseInt(e, 10)
  3547. })
  3548. }
  3549. }, i.getMid = function (e) {
  3550. var t = i.matchPrefix(e, "a=mid:")[0];
  3551. if (t) return t.substr(6)
  3552. }, i.parseFingerprint = function (e) {
  3553. var t = e.substr(14).split(" ");
  3554. return {algorithm: t[0].toLowerCase(), value: t[1]}
  3555. }, i.getDtlsParameters = function (e, t) {
  3556. var r = i.matchPrefix(e + t, "a=fingerprint:");
  3557. return {role: "auto", fingerprints: r.map(i.parseFingerprint)}
  3558. }, i.writeDtlsParameters = function (e, t) {
  3559. var r = "a=setup:" + t + "\r\n";
  3560. return e.fingerprints.forEach(function (e) {
  3561. r += "a=fingerprint:" + e.algorithm + " " + e.value + "\r\n"
  3562. }), r
  3563. }, i.getIceParameters = function (e, t) {
  3564. var r = i.splitLines(e), s = {
  3565. usernameFragment: (r = r.concat(i.splitLines(t))).filter(function (e) {
  3566. return 0 === e.indexOf("a=ice-ufrag:")
  3567. })[0].substr(12), password: r.filter(function (e) {
  3568. return 0 === e.indexOf("a=ice-pwd:")
  3569. })[0].substr(10)
  3570. };
  3571. return s
  3572. }, i.writeIceParameters = function (e) {
  3573. return "a=ice-ufrag:" + e.usernameFragment + "\r\na=ice-pwd:" + e.password + "\r\n"
  3574. }, i.parseRtpParameters = function (e) {
  3575. for (var t = {
  3576. codecs: [],
  3577. headerExtensions: [],
  3578. fecMechanisms: [],
  3579. rtcp: []
  3580. }, r = i.splitLines(e), s = r[0].split(" "), n = 3; n < s.length; n++) {
  3581. var o = s[n], a = i.matchPrefix(e, "a=rtpmap:" + o + " ")[0];
  3582. if (a) {
  3583. var c = i.parseRtpMap(a), l = i.matchPrefix(e, "a=fmtp:" + o + " ");
  3584. switch (c.parameters = l.length ? i.parseFmtp(l[0]) : {}, c.rtcpFeedback = i.matchPrefix(e, "a=rtcp-fb:" + o + " ").map(i.parseRtcpFb), t.codecs.push(c), c.name.toUpperCase()) {
  3585. case"RED":
  3586. case"ULPFEC":
  3587. t.fecMechanisms.push(c.name.toUpperCase())
  3588. }
  3589. }
  3590. }
  3591. return i.matchPrefix(e, "a=extmap:").forEach(function (e) {
  3592. t.headerExtensions.push(i.parseExtmap(e))
  3593. }), t
  3594. }, i.writeRtpDescription = function (e, t) {
  3595. var r = "";
  3596. r += "m=" + e + " ", r += t.codecs.length > 0 ? "9" : "0", r += " UDP/TLS/RTP/SAVPF ", r += t.codecs.map(function (e) {
  3597. return void 0 !== e.preferredPayloadType ? e.preferredPayloadType : e.payloadType
  3598. }).join(" ") + "\r\n", r += "c=IN IP4 0.0.0.0\r\n", r += "a=rtcp:9 IN IP4 0.0.0.0\r\n", t.codecs.forEach(function (e) {
  3599. r += i.writeRtpMap(e), r += i.writeFmtp(e), r += i.writeRtcpFb(e)
  3600. });
  3601. var s = 0;
  3602. return t.codecs.forEach(function (e) {
  3603. e.maxptime > s && (s = e.maxptime)
  3604. }), s > 0 && (r += "a=maxptime:" + s + "\r\n"), r += "a=rtcp-mux\r\n", t.headerExtensions && t.headerExtensions.forEach(function (e) {
  3605. r += i.writeExtmap(e)
  3606. }), r
  3607. }, i.parseRtpEncodingParameters = function (e) {
  3608. var t, r = [], s = i.parseRtpParameters(e), n = -1 !== s.fecMechanisms.indexOf("RED"),
  3609. o = -1 !== s.fecMechanisms.indexOf("ULPFEC"), a = i.matchPrefix(e, "a=ssrc:").map(function (e) {
  3610. return i.parseSsrcMedia(e)
  3611. }).filter(function (e) {
  3612. return "cname" === e.attribute
  3613. }), c = a.length > 0 && a[0].ssrc, l = i.matchPrefix(e, "a=ssrc-group:FID").map(function (e) {
  3614. var t = e.substr(17).split(" ");
  3615. return t.map(function (e) {
  3616. return parseInt(e, 10)
  3617. })
  3618. });
  3619. l.length > 0 && l[0].length > 1 && l[0][0] === c && (t = l[0][1]), s.codecs.forEach(function (e) {
  3620. if ("RTX" === e.name.toUpperCase() && e.parameters.apt) {
  3621. var i = {ssrc: c, codecPayloadType: parseInt(e.parameters.apt, 10)};
  3622. c && t && (i.rtx = {ssrc: t}), r.push(i), n && ((i = JSON.parse(JSON.stringify(i))).fec = {
  3623. ssrc: c,
  3624. mechanism: o ? "red+ulpfec" : "red"
  3625. }, r.push(i))
  3626. }
  3627. }), 0 === r.length && c && r.push({ssrc: c});
  3628. var d = i.matchPrefix(e, "b=");
  3629. return d.length && (d = 0 === d[0].indexOf("b=TIAS:") ? parseInt(d[0].substr(7), 10) : 0 === d[0].indexOf("b=AS:") ? 1e3 * parseInt(d[0].substr(5), 10) * .95 - 16e3 : void 0, r.forEach(function (e) {
  3630. e.maxBitrate = d
  3631. })), r
  3632. }, i.parseRtcpParameters = function (e) {
  3633. var t = {}, r = i.matchPrefix(e, "a=ssrc:").map(function (e) {
  3634. return i.parseSsrcMedia(e)
  3635. }).filter(function (e) {
  3636. return "cname" === e.attribute
  3637. })[0];
  3638. r && (t.cname = r.value, t.ssrc = r.ssrc);
  3639. var s = i.matchPrefix(e, "a=rtcp-rsize");
  3640. t.reducedSize = s.length > 0, t.compound = 0 === s.length;
  3641. var n = i.matchPrefix(e, "a=rtcp-mux");
  3642. return t.mux = n.length > 0, t
  3643. }, i.parseMsid = function (e) {
  3644. var t, r = i.matchPrefix(e, "a=msid:");
  3645. if (1 === r.length) return {stream: (t = r[0].substr(7).split(" "))[0], track: t[1]};
  3646. var s = i.matchPrefix(e, "a=ssrc:").map(function (e) {
  3647. return i.parseSsrcMedia(e)
  3648. }).filter(function (e) {
  3649. return "msid" === e.attribute
  3650. });
  3651. return s.length > 0 ? {stream: (t = s[0].value.split(" "))[0], track: t[1]} : void 0
  3652. }, i.generateSessionId = function () {
  3653. return Math.random().toString().substr(2, 21)
  3654. }, i.writeSessionBoilerplate = function (e, t, r) {
  3655. var s, n = void 0 !== t ? t : 2;
  3656. s = e || i.generateSessionId();
  3657. var o = r || "thisisadapterortc";
  3658. return "v=0\r\no=" + o + " " + s + " " + n + " IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"
  3659. }, i.writeMediaSection = function (e, t, r, s) {
  3660. var n = i.writeRtpDescription(e.kind, t);
  3661. if (n += i.writeIceParameters(e.iceGatherer.getLocalParameters()), n += i.writeDtlsParameters(e.dtlsTransport.getLocalParameters(), "offer" === r ? "actpass" : "active"), n += "a=mid:" + e.mid + "\r\n", e.direction ? n += "a=" + e.direction + "\r\n" : e.rtpSender && e.rtpReceiver ? n += "a=sendrecv\r\n" : e.rtpSender ? n += "a=sendonly\r\n" : e.rtpReceiver ? n += "a=recvonly\r\n" : n += "a=inactive\r\n", e.rtpSender) {
  3662. var o = "msid:" + s.id + " " + e.rtpSender.track.id + "\r\n";
  3663. n += "a=" + o, n += "a=ssrc:" + e.sendEncodingParameters[0].ssrc + " " + o, e.sendEncodingParameters[0].rtx && (n += "a=ssrc:" + e.sendEncodingParameters[0].rtx.ssrc + " " + o, n += "a=ssrc-group:FID " + e.sendEncodingParameters[0].ssrc + " " + e.sendEncodingParameters[0].rtx.ssrc + "\r\n")
  3664. }
  3665. return n += "a=ssrc:" + e.sendEncodingParameters[0].ssrc + " cname:" + i.localCName + "\r\n", e.rtpSender && e.sendEncodingParameters[0].rtx && (n += "a=ssrc:" + e.sendEncodingParameters[0].rtx.ssrc + " cname:" + i.localCName + "\r\n"), n
  3666. }, i.getDirection = function (e, t) {
  3667. for (var r = i.splitLines(e), s = 0; s < r.length; s++) switch (r[s]) {
  3668. case"a=sendrecv":
  3669. case"a=sendonly":
  3670. case"a=recvonly":
  3671. case"a=inactive":
  3672. return r[s].substr(2)
  3673. }
  3674. return t ? i.getDirection(t) : "sendrecv"
  3675. }, i.getKind = function (e) {
  3676. var t = i.splitLines(e), r = t[0].split(" ");
  3677. return r[0].substr(2)
  3678. }, i.isRejected = function (e) {
  3679. return "0" === e.split(" ", 2)[1]
  3680. }, i.parseMLine = function (e) {
  3681. var t = i.splitLines(e), r = t[0].substr(2).split(" ");
  3682. return {kind: r[0], port: parseInt(r[1], 10), protocol: r[2], fmt: r.slice(3).join(" ")}
  3683. }, i.parseOLine = function (e) {
  3684. var t = i.matchPrefix(e, "o=")[0], r = t.substr(2).split(" ");
  3685. return {
  3686. username: r[0],
  3687. sessionId: r[1],
  3688. sessionVersion: parseInt(r[2], 10),
  3689. netType: r[3],
  3690. addressType: r[4],
  3691. address: r[5]
  3692. }
  3693. }, i.isValidSDP = function (e) {
  3694. if ("string" != typeof e || 0 === e.length) return !1;
  3695. for (var t = i.splitLines(e), r = 0; r < t.length; r++) if (t[r].length < 2 || "=" !== t[r].charAt(1)) return !1;
  3696. return !0
  3697. }, "object" == typeof t && (t.exports = i)
  3698. }, {}]
  3699. }, {}, [1])(1)
  3700. }, function (e, t, r) {
  3701. "use strict";
  3702. var i = this && this.__assign || Object.assign || function (e) {
  3703. for (var t, r = 1, i = arguments.length; r < i; r++) for (var s in t = arguments[r]) Object.prototype.hasOwnProperty.call(t, s) && (e[s] = t[s]);
  3704. return e
  3705. };
  3706. Object.defineProperty(t, "__esModule", {value: !0});
  3707. var s = r(0), n = r(2), o = function () {
  3708. function e(e, t) {
  3709. this.sendDataMap = {}, this.sendDataList = new s.LinkedList, this.sendDataCheckOnceCount = 100, this.signalSeq = 0, this.pushCallback = {}, this.sessionInfos = {}, this.tryHeartbeatCount = 0, this.heartbeatInterval = 1e4, this.sendDataTimeout = 5e3, this.sendDataDropTimeout = 1e4, this.tryConnectCount = 1, this.tryConnectTimer = null, this.tryConnectInterval = 3e3, this.state = s.ENUM_CONNECT_STATE.disconnect, this.tokenType = 0, this.browser = this.getBrowserAndVersion(), this.platform = navigator.platform, this.logger = e, this.stateCenter = t
  3710. }
  3711. return e.prototype.getBrowserAndVersion = function () {
  3712. var e, t = navigator.userAgent,
  3713. r = t.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*([\d\.]+)/i) || [];
  3714. return /trident/i.test(r[1]) ? {
  3715. name: "IE",
  3716. version: (e = /\brv[ :]+([\d\.]+)/g.exec(t) || [])[1] || ""
  3717. } : "Chrome" === r[1] && null != (e = t.match(/\bOPR|Edge\/([\d\.]+)/)) ? {
  3718. name: "Opera",
  3719. version: e[1]
  3720. } : (r = r[2] ? [r[1], r[2]] : [navigator.appName, navigator.appVersion, "-?"], null != (e = t.match(/version\/([\d+\.]+)/i)) && r.splice(1, 1, e[1]), {
  3721. name: r[0],
  3722. version: r[1]
  3723. })
  3724. }, e.prototype.setSessionInfo = function (e, t) {
  3725. this.logger.debug("zs.ssi.0 call"), this.appid = e + "", this.userid = t
  3726. }, e.prototype.onDisconnect = function (e) {
  3727. }, e.prototype.onUpdateHeartBeartInterval = function (e) {
  3728. }, e.prototype.resetConnectTimer = function () {
  3729. this.logger.info("zs.rct.0 call"), clearTimeout(this.tryConnectTimer), this.tryConnectTimer = null, this.tryConnectCount = 0
  3730. }, e.prototype.bindWebSocketHandle = function () {
  3731. var e = this;
  3732. this.websocket.onmessage = function (t) {
  3733. var r = JSON.parse(t.data);
  3734. e.logger.debug("zs.bsh.0 signmsg= ", r.header.cmd), r.header.appid == e.appid && r.header.user_id === e.userid ? e.handleServerPush(r) : e.logger.warn("zs.bsh.0 check header failed")
  3735. }, this.websocket.onclose = function (t) {
  3736. e.logger.info("zs.bsh.0 close msg = " + JSON.stringify(t)), e.state != s.ENUM_CONNECT_STATE.disconnect && (e.resetConnectTimer(), e.startConnectTimer(), e.resetCheckMessage())
  3737. }, this.websocket.onerror = function (t) {
  3738. e.logger.error("zs.bsh.0 msg = " + JSON.stringify(t))
  3739. }
  3740. }, e.prototype.resetCheckMessage = function () {
  3741. this.logger.debug("zs.rcm.0 call");
  3742. for (var e = this.sendDataList.getFirst(); null != e;) this.sendDataList.remove(e), e._data.error && e._data.error(s.SEND_MSG_RESET, e._data.seq), e = this.sendDataList.getFirst();
  3743. this.sendDataMap = {}
  3744. }, e.prototype.handleServerPush = function (e) {
  3745. switch (e.header.cmd) {
  3746. case"LoginRsp":
  3747. this.handleRespondData("LoginReq", e);
  3748. break;
  3749. case"CreateSessionRsp":
  3750. this.handleRespondData("CreateSessionReq", e), 0 === e.body.result && this.addSession(e.header.session_id, e.body.session_token);
  3751. break;
  3752. case"MediaDescRsp":
  3753. this.handleRespondData("MediaDescReq", e);
  3754. break;
  3755. case"CandidateInfoRsp":
  3756. this.handleRespondData("CandidateInfoReq", e);
  3757. break;
  3758. case"CloseSessionRsp":
  3759. this.handleRespondData("CloseSessionReq", e), this.removeSession(e.header.session_id);
  3760. break;
  3761. case"ClientHBRsp":
  3762. this.handleRespondData("ClientHBReq", e);
  3763. break;
  3764. case"MediaDescPush":
  3765. case"CandidateInfoPush":
  3766. this.handlePushData(e);
  3767. break;
  3768. case"CloseSessionPush":
  3769. this.handlePushData(e), this.removeSession(e.header.session_id);
  3770. break;
  3771. case"QualityReportRsp":
  3772. this.handleRespondData("QualityReportReq", e);
  3773. break;
  3774. case"SessionResetPush":
  3775. this.handlePushResetSessionData(e)
  3776. }
  3777. }, e.prototype.disconnectCallback = function () {
  3778. this.connectCallback && (this.connectCallback(-1, this.server, void 0), this.connectCallback = null);
  3779. var e = this.server;
  3780. this.disconnectServer(), this.onDisconnect(e)
  3781. }, e.prototype.updateToken = function () {
  3782. var e = this;
  3783. this.logger.info("zs.ut.0 call");
  3784. var t = {
  3785. token: this.token,
  3786. tokenType: this.tokenType,
  3787. roomid: this.stateCenter.roomid,
  3788. anchorname: this.stateCenter.anchor_info.anchor_id,
  3789. sdkversion: s.PROTO_VERSION,
  3790. osinfo: navigator.appVersion
  3791. };
  3792. if (0 != Object.keys(this.sessionInfos).length) {
  3793. var r = [];
  3794. for (var i in this.sessionInfos) {
  3795. var o = parseInt(i);
  3796. r.push({session_id: o, session_token: this.sessionInfos[o].token})
  3797. }
  3798. t.sessions = r
  3799. }
  3800. this.sendMessageWithCallback("LoginReq", n.getSeq(), 0, t, function (t, r, i) {
  3801. if (0 == i.result) {
  3802. e.token = i.token, e.tokenType = i.tokenType;
  3803. var s = {report: i.report, report_interval: i.report_interval_ms};
  3804. null != e.connectCallback && (e.connectCallback(0, e.server, s), e.connectCallback = null)
  3805. } else {
  3806. var n = {error: i.strError};
  3807. null != e.connectCallback && (e.connectCallback(i.result, e.server, n), e.connectCallback = null)
  3808. }
  3809. }, function (t, r) {
  3810. null != e.connectCallback && (e.connectCallback(-1, e.server, void 0), e.connectCallback = null)
  3811. })
  3812. }, e.prototype.sendMessageWithCallback = function (e, t, r, i, n, o) {
  3813. if (this.logger.debug("zs.smwc.0 call " + e), !this.websocket || 1 !== this.websocket.readyState) return this.logger.error("zs.smwc.0 connect not establish"), void (o && o(s.SEND_MSG_TIMEOUT, t));
  3814. var a = {header: this.getHeader(e, t, r), body: i};
  3815. null == n && (n = null), null == o && (o = null);
  3816. var c = {seq: t, deleted: !1, cmd: e, time: Date.parse(new Date + ""), success: n, error: o},
  3817. l = this.sendDataList.push(c);
  3818. this.sendDataMap[c.seq] = l;
  3819. var d = JSON.stringify(a);
  3820. this.websocket.send(d), this.logger.debug("zs.smwc.0 success")
  3821. }, e.prototype.getHeader = function (e, t, r) {
  3822. return this.globalHeader = {
  3823. version: "1.0.1",
  3824. cmd: e,
  3825. appid: this.appid + "",
  3826. seq: t,
  3827. user_id: this.userid,
  3828. session_id: r
  3829. }, this.globalHeader
  3830. }, e.prototype.connectServer = function (e, t, r) {
  3831. var i = this;
  3832. if (this.token = e, this.server = t, this.state = s.ENUM_CONNECT_STATE.connecting, this.connectCallback = r, this.websocket && 1 === this.websocket.readyState) this.resetConnectTimer(), this.state = s.ENUM_CONNECT_STATE.connected; else {
  3833. this.logger.debug("zs.cs.0 need new websocket");
  3834. try {
  3835. this.websocket && (this.logger.warn("zs.cs.0 close error websocket"), this.websocket.onclose = null, this.websocket.onerror = null, this.websocket.close(), this.websocket = null), this.websocket = new WebSocket(this.server), this.websocket.onopen = function () {
  3836. i.resetConnectTimer(), i.logger.info("zs.cs.0 websocket open call"), i.bindWebSocketHandle(), i.updateToken(), i.state = s.ENUM_CONNECT_STATE.connected
  3837. }
  3838. } catch (e) {
  3839. this.logger.error("zs.cs.0 websocket error " + e)
  3840. }
  3841. }
  3842. this.tryConnectTimer = setTimeout(function () {
  3843. i.startConnectTimer(r)
  3844. }, this.tryConnectInterval)
  3845. }, e.prototype.startConnectTimer = function (e) {
  3846. if (this.logger.info("zs.sct.0 call"), this.tryConnectCount >= s.MAX_TRY_CONNECT_COUNT) return this.logger.error("zs.sct.0 beyond max limit"), void this.disconnectCallback();
  3847. this.websocket && 1 === this.websocket.readyState ? this.resetConnectTimer() : (this.tryConnectCount += 1, this.connectServer(this.token, this.server, e))
  3848. }, e.prototype.disconnectServer = function () {
  3849. this.logger.debug("zs.ds.0 call"), this.server = null, this.connectCallback = null, this.resetCheckMessage(), this.resetConnectTimer(), this.websocket && (this.websocket.onclose = null, this.websocket.onerror = null, this.websocket.close(), this.websocket = null), this.token = "", this.sessionInfos = {}, this.tokenType = 0, this.tryHeartbeatCount = 0, this.tryConnectCount = 0, this.state = s.ENUM_CONNECT_STATE.disconnect
  3850. }, e.prototype.isServerConnected = function () {
  3851. return !(!this.websocket || 1 !== this.websocket.readyState)
  3852. }, e.prototype.createSession = function (e, t, r, i, s, n, o) {
  3853. void 0 === s && (s = ""), this.logger.debug("zs.cs.1 call: ", i);
  3854. var a = {
  3855. type: t,
  3856. stream_id: i,
  3857. platform: this.platform,
  3858. browser: this.browser.name,
  3859. version: this.browser.version,
  3860. app_id: this.appid,
  3861. negotiate_mode: r,
  3862. strAuthParam: s
  3863. };
  3864. this.sendMessageWithCallback("CreateSessionReq", e, 0, a, n, o)
  3865. }, e.prototype.removeSession = function (e) {
  3866. this.logger.info("zs.rs.0 call"), this.sessionInfos[e] && delete this.sessionInfos[e]
  3867. }, e.prototype.sendCloseSession = function (e, t, r, i, s) {
  3868. this.logger.debug("zs.scs.0 call: ", t);
  3869. var n = {reason: r};
  3870. this.removeSession(t), this.sendMessageWithCallback("CloseSessionReq", e, t, n, i, s)
  3871. }, e.prototype.sendMessage = function (e, t, r, i) {
  3872. if (this.logger.debug("zs.sm.0 call " + e), this.websocket && 1 === this.websocket.readyState) {
  3873. var s = {header: this.getHeader(e, t, r), body: i}, n = JSON.stringify(s);
  3874. this.websocket.send(n), this.logger.debug("zs.sm.0 success")
  3875. } else this.logger.error("zs.sm.0 connect not establish")
  3876. }, e.prototype.handleRespondData = function (e, t) {
  3877. this.logger.debug("zs.hrd.0 call");
  3878. var r = this.sendDataMap[t.header.seq];
  3879. if (null != r) {
  3880. var i = r._data;
  3881. i.cmd !== e ? this.logger.error("sz.hrd.0 command is not match") : i.success && i.success(t.header.seq, t.header.session_id, t.body), delete this.sendDataMap[t.header.seq], this.sendDataList.remove(r)
  3882. } else {
  3883. if ("CloseSessionRsp" == t.header.cmd) return;
  3884. this.logger.error("zs.hrd.0 cannot find data " + e)
  3885. }
  3886. }, e.prototype.addSession = function (e, t) {
  3887. this.logger.info("zs.as.0 call"), this.sessionInfos[e] = {token: t}
  3888. }, e.prototype.handlePushData = function (e) {
  3889. this.logger.debug("zs.hpd.0 call " + e.header.cmd + " session " + e.header.session_id);
  3890. var t = this.pushCallback[e.header.cmd + e.header.session_id];
  3891. t ? t.callback && t.callback(e.header.seq, e.header.session_id, e.body) : this.logger.info("zs.hpd.0 no callbackData " + e.header.cmd + " session: " + e.header.session_id)
  3892. }, e.prototype.handlePushResetSessionData = function (e) {
  3893. this.logger.debug("zs.hprsd.0 call ");
  3894. var t = [];
  3895. if (0 == e.body.cResetType) t = Object.keys(this.sessionInfos); else if (1 == e.body.cResetType) for (var r = 0; r < e.body.session_ids.length; r++) t.push(e.body.session_ids[r]);
  3896. if (this.sendResetSessionAck(e.header.seq, 0, 0), 0 != t.length) for (var i = 0; i < t.length; i++) {
  3897. var s = this.pushCallback[e.header.cmd + t[i]];
  3898. null == s ? this.logger.info("zs.hprsd.0 no callbackData " + t[i]) : s.callback && s.callback(s.object, e.header.seq, t[i], e.body)
  3899. } else this.logger.info("zs.hprsd.0 no session to callback")
  3900. }, e.prototype.sendMediaDesc = function (e, t, r, i, s, n) {
  3901. this.logger.debug("zs.smd.0 call: ", t);
  3902. var o = {type: r, sdp: i.sdp};
  3903. null != i.width && (o.width = i.width), null != i.height && (o.height = i.height), null != i.frameRate && (o.framerate = i.frameRate), null != i.video_min_kpbs && (o.video_min_kpbs = i.video_min_kpbs), null != i.video_max_kpbs && (o.video_max_kpbs = i.video_max_kpbs), null != i.audio_kpbs && (o.audio_kpbs = i.audio_kpbs), this.sendMessageWithCallback("MediaDescReq", e, t, o, s, n)
  3904. }, e.prototype.sendCandidateInfo = function (e, t, r, i, s) {
  3905. this.logger.debug("zs.sci.0 call: ", t);
  3906. for (var n = [], o = 0; o < r.length; o++) {
  3907. var a = {candidate: r[o].candidate, sdpMid: r[o].sdpMid, sdpMLineIndex: r[o].sdpMLineIndex};
  3908. n.push(a)
  3909. }
  3910. var c = {infos: n};
  3911. this.sendMessageWithCallback("CandidateInfoReq", e, t, c, i, s)
  3912. }, e.prototype.sendMediaDescAck = function (e, t, r) {
  3913. this.logger.debug("zs.smda.0 call: ", t);
  3914. var i = {result: r};
  3915. this.sendMessage("MediaDescAck", e, t, i)
  3916. }, e.prototype.sendCandidateInfoAck = function (e, t, r) {
  3917. this.logger.debug("zs.scia.0 call: ", t);
  3918. var i = {result: r};
  3919. this.sendMessage("CandidateInfoAck", e, t, i)
  3920. }, e.prototype.sendCloseSessionAck = function (e, t, r) {
  3921. this.logger.debug("zs.scsa.0 call: ", t);
  3922. var i = {result: r};
  3923. this.sendMessage("CloseSessionAck", e, t, i)
  3924. }, e.prototype.sendResetSessionAck = function (e, t, r) {
  3925. this.logger.debug("zs.ssra.0 call: ", t);
  3926. var i = {result: r};
  3927. this.sendMessage("SessionResetAck", e, t, i)
  3928. }, e.prototype.registerPushCallback = function (e, t, r) {
  3929. r && "function" == typeof r && (this.logger.debug("zs.rpc.0 setcallback"), this.pushCallback[e + t] = {callback: r})
  3930. }, e.prototype.unregisterPushCallback = function (e, t) {
  3931. delete this.pushCallback[e + t]
  3932. }, e.prototype.checkMessageTimeout = function () {
  3933. for (var e = this.sendDataList.getFirst(), t = Date.parse(new Date + ""), r = 0, i = 0, n = 0; !(null == e || e._data.time + this.sendDataTimeout > t || (delete this.sendDataMap[e._data.seq], this.sendDataList.remove(e), ++i, null == e._data.error || this.sendDataDropTimeout > 0 && e._data.time + this.sendDataDropTimeout < t ? ++n : e._data.error && e._data.error(s.SEND_MSG_TIMEOUT, e._data.seq), ++r >= this.sendDataCheckOnceCount));) e = this.sendDataList.getFirst();
  3934. 0 == i && 0 == n || this.logger.debug("zs.cmt.0 call success, state: timeout=", i, " drop=", n)
  3935. }, e.prototype.sendHeartbeat = function () {
  3936. var e = this;
  3937. if (this.logger.debug("zs.shb.0 call"), 0 != Object.keys(this.sessionInfos).length) {
  3938. if (++this.tryHeartbeatCount > s.MAX_TRY_HEARTBEAT_COUNT) return this.logger.error("zs.shb.0 heartbeat try limit"), void this.disconnectCallback();
  3939. var t = [];
  3940. for (var r in this.sessionInfos) t.push(parseInt(r));
  3941. var i = {session_ids: t};
  3942. this.sendMessageWithCallback("ClientHBReq", n.getSeq(), 0, i, function (t, r, i) {
  3943. e.heartbeatInterval != i.hb_interval && (e.heartbeatInterval = i.hb_interval, e.onUpdateHeartBeartInterval(i.hb_interval)), e.tryHeartbeatCount = 0
  3944. }, function (t, r) {
  3945. e.tryHeartbeatCount += 1
  3946. })
  3947. } else this.logger.info("zs.shb.0 no need to heartbeat")
  3948. }, e.prototype.QualityReport = function (e, t, r, s, n) {
  3949. this.logger.debug("zs.qr.0 call");
  3950. var o = {streams: [i({}, r, {aid: t})]};
  3951. this.sendMessageWithCallback("QualityReportReq", e, t, o, s, n)
  3952. }, e
  3953. }();
  3954. t.ZegoSignal = o
  3955. }, function (e, t, r) {
  3956. "use strict";
  3957. Object.defineProperty(t, "__esModule", {value: !0});
  3958. var i = r(0), s = r(2), n = r(4), o = function () {
  3959. function e(e, t, r, n) {
  3960. this.state = i.ENUM_PLAY_STATE.stop, this.candidateInfo = [], this.waitICETimer = null, this.waitingICETimeInterval = 5e3, this.waitingOfferTimer = null, this.waitingOfferTimeInterval = 5e3, this.waitingServerTimer = null, this.waitingServerTimerInterval = 3e3, this.qualityTimer = null, this.playQualityList = [], this.maxQualityListCount = 10, this.lastPlayStats = {
  3961. time: 0,
  3962. audioBytesReceived: 0,
  3963. videoBytesReceived: 0,
  3964. framesDecoded: 0,
  3965. framesReceived: 0,
  3966. framesDropped: 0
  3967. }, this.reportSeq = s.getSeq(), this.videoSizeCallback = !1, this.qualityUpload = !1, this.qualityUploadInterval = 3e4, this.qualityUploadLastTime = 0, this.maxRetryCount = 3, this.currentRetryCount = 0, this.retryState = i.ENUM_RETRY_STATE.didNotStart, this.closeSessionSignal = !1, this.logger = e, this.signal = t, this.dataReport = r, this.qualityTimeInterval = n, r.newReport(this.reportSeq)
  3968. }
  3969. return e.prototype.setAudioDestination = function (e) {
  3970. var t = this;
  3971. return this.remoteVideo ? "undefined" !== this.remoteVideo.sinkId ? (this.remoteVideo.setSinkId(e).then(function () {
  3972. t.logger.info("zp.sad.1 success device: " + e)
  3973. }).catch(function (e) {
  3974. t.logger.info("zp.sad.1 " + e.name)
  3975. }), !0) : (this.logger.error("zp.sad.1 browser does not suppport"), !1) : (this.logger.info("zp.sad.1 no remoteVideo"), !1)
  3976. }, e.prototype.startPlay = function (e, t, r, n) {
  3977. var o = this;
  3978. this.logger.info("zp.sp.1 called ", e), e ? (this.streamId = e, this.remoteVideo = t, this.audioOutput = r, this.playOption = n || {}, n && n.videoDecodeType && (this.playOption.videoDecodeType = n.videoDecodeType), this.sessionSeq = s.getSeq(), this.dataReport.eventStart(this.reportSeq, "CreateSession"), this.signal.createSession(this.sessionSeq, 1, 0, e, n && n.streamParams, function (e, t, r) {
  3979. o.dataReport.eventEndWithMsg(o.reportSeq, "CreateSession", {sessionId: r.session_id}), o.logger.info("zp.sp.1 sessionId:" + r.session_id), o.sessionSeq == e ? 0 !== r.result ? (o.logger.error("zp.sp.1 create error"), o.playStateUpdateError(s.playErrorList.CREATE_SESSION_ERROR)) : (o.sessionId = r.session_id, o.onCreatePlaySessionSuccess(r)) : o.logger.error("zp.sp.1 seq is not match.")
  3980. }, function (e, t) {
  3981. o.dataReport.eventEndWithMsg(o.reportSeq, "CreateSession", {error: e}), o.playStateUpdateError(s.playErrorList.SEND_SESSION_TIMEOUT)
  3982. }), this.state = i.ENUM_PLAY_STATE.waitingSessionRsp, this.logger.debug("zp.sp.1 called success")) : this.logger.warn("zp.sp.1 streamId is null")
  3983. }, e.prototype.onCreatePlaySessionSuccess = function (e) {
  3984. var t = this;
  3985. this.logger.info("zp.ops.1 success");
  3986. var r = [];
  3987. e.turn_server && r.push(e.turn_server), e.stun_server && r.push(e.stun_server);
  3988. var i = {
  3989. iceTransportPolicy: "relay",
  3990. iceServers: [{urls: r, username: e.turn_username, credential: e.turn_auth_key}]
  3991. };
  3992. this.logger.info("zp.ops.1 username: " + e.turn_username), this.logger.info("zp.ops.1 credential: " + e.turn_auth_key), this.peerConnection = new RTCPeerConnection(i), this.peerConnection.onicecandidate = function (e) {
  3993. t.onIceCandidate(e)
  3994. }, this.peerConnection.onsignalingstatechange = function (e) {
  3995. t.onConnectionStateChange(e)
  3996. }, this.peerConnection.oniceconnectionstatechange = function (e) {
  3997. t.onIceConnectionStateChange(e)
  3998. }, this.peerConnection.ontrack = function (e) {
  3999. t.onGotRemoteStream(e.streams[0])
  4000. }, this.remoteVideo.oncanplay = function () {
  4001. t.logger.debug("zp.ops.1 " + t.remoteVideo.videoWidth + " X " + t.remoteVideo.videoHeight), t.videoSizeCallback || (t.logger.debug("zp.ops.1 onresize callback"), t.onVideoSizeChanged(t.streamId, t.remoteVideo.videoWidth, t.remoteVideo.videoHeight), t.videoSizeCallback = !0)
  4002. };
  4003. var n = {offerToReceiveAudio: 1, offerToReceiveVideo: 1};
  4004. this.playOption && "audio" === this.playOption.playType && (n.offerToReceiveVideo = 0), this.playOption && "video" === this.playOption.playType && (n.offerToReceiveAudio = 0), this.logger.info("zp.ops.1 createOffer: " + n), this.dataReport.eventStart(this.reportSeq, "CreateOffer"), this.peerConnection.createOffer(n).then(function (e) {
  4005. t.dataReport.eventEnd(t.reportSeq, "CreateOffer"), t.onCreateOfferSuccess(e)
  4006. }, function (e) {
  4007. t.dataReport.eventEndWithMsg(t.reportSeq, "CreateOffer", {error: e.toString()}), t.logger.error("zp.ops.0 create offer error " + e.toString()), t.playStateUpdateError(s.playErrorList.CREATE_OFFER_ERROR)
  4008. }), this.signal.registerPushCallback("MediaDescPush", this.sessionId, function (e, r, i) {
  4009. t.onRecvMediaDesc(e, r, i)
  4010. }), this.signal.registerPushCallback("CandidateInfoPush", this.sessionId, function (e, r, i) {
  4011. t.onRecvCandidateInfo(e, r, i)
  4012. }), this.signal.registerPushCallback("CloseSessionPush", this.sessionId, function (e, r, i) {
  4013. t.onRecvCloseSession(e, r, i)
  4014. }), this.signal.registerPushCallback("SessionResetPush", this.sessionId, function (e, r, i) {
  4015. t.onRecvResetSession(e, r, i)
  4016. }), this.logger.debug("zp.ops.1 call success")
  4017. }, e.prototype.onCreateOfferSuccess = function (e) {
  4018. var t = this;
  4019. this.logger.info("zp.oco.1 localSdp1 " + e.sdp.substr(0, e.sdp.length / 2)), this.logger.info("zp.oco.1 localSdp2 " + e.sdp.substr(e.sdp.length / 2)), e.sdp = e.sdp.replace(/sendrecv/g, "recvonly"), this.playOption.videoDecodeType && (e.sdp = n.sdpUtil.getSDPByVideDecodeType(e.sdp, this.playOption.videoDecodeType)), this.dataReport.eventStart(this.reportSeq, "SetLocalDescription"), this.peerConnection.setLocalDescription(e).then(function () {
  4020. t.dataReport.eventEnd(t.reportSeq, "SetLocalDescription"), t.onSetLocalDescriptionSuccess(e)
  4021. }, function (e) {
  4022. t.logger.error("zp.oca.1 set error " + e.toString()), t.dataReport.eventEnd(t.reportSeq, "SetLocalDescription", {error: e.toString()}), t.playStateUpdateError(s.playErrorList.SET_LOCAL_DESC_ERROR)
  4023. })
  4024. }, e.prototype.onSetLocalDescriptionSuccess = function (e) {
  4025. var t = this;
  4026. this.logger.info("zp.osd.1 success");
  4027. var r = {sdp: e.sdp};
  4028. this.answerSeq = s.getSeq(), this.dataReport.eventStart(this.reportSeq, "SendMediaDesc"), this.signal.sendMediaDesc(this.answerSeq, this.sessionId, 0, r, function (e, r, n) {
  4029. t.answerSeq == e && t.sessionId == r ? (t.logger.info("zp.osd.1 send success"), t.dataReport.eventEnd(t.reportSeq, "SendMediaDesc"), t.waitingOfferTimer = setTimeout(function () {
  4030. t.state == i.ENUM_PLAY_STATE.waitingOffserRsp && (t.logger.error("zp.osd.1 waiting timeout"), t.playStateUpdateError(s.playErrorList.SERVER_CANDIDATE_TIMEOUT))
  4031. }, t.waitingOfferTimeInterval), t.state = i.ENUM_PLAY_STATE.waitingServerAnswer) : t.logger.error("zp.osd.1 seq or sessionId is not equal " + t.answerSeq + " " + e, 0 + t.sessionId + " " + r)
  4032. }, function (e, r) {
  4033. t.logger.error("zp.osd.1 failed to send " + e), t.dataReport.eventEndWithMsg(t.reportSeq, "SendMediaDesc", {error: e}), t.playStateUpdateError(s.playErrorList.SEND_MEDIA_DESC_TIMEOUT)
  4034. }), this.state = i.ENUM_PLAY_STATE.waitingOffserRsp
  4035. }, e.prototype.onRecvMediaDesc = function (e, t, r) {
  4036. var n = this;
  4037. if (this.logger.info("zp.orm.1 received ", r), this.state === i.ENUM_PLAY_STATE.waitingServerAnswer) {
  4038. null != this.waitingOfferTimer && (clearTimeout(this.waitingOfferTimer), this.waitingOfferTimer = null), this.dataReport.addEvent(this.reportSeq, "RecvMediaDesc"), this.signal.sendMediaDescAck(e, this.sessionId, 0);
  4039. var o = {
  4040. type: "answer", sdp: r.sdp, toJSON: function () {
  4041. }
  4042. };
  4043. this.dataReport.eventStart(this.reportSeq, "SetRemoteDescription"), this.logger.info("zp.orm.1 remoteSdp ", o.sdp), this.peerConnection.setRemoteDescription(new RTCSessionDescription(o)).then(function () {
  4044. n.dataReport.eventEnd(n.reportSeq, "SetRemoteDescription"), n.logger.info("zp.orm.1 set success")
  4045. }, function (e) {
  4046. n.logger.error("zp.orm.1 set remote error " + e.toString()), n.dataReport.eventEndWithMsg(n.reportSeq, "SetRemoteDescription", {error: e.toString()}), n.playStateUpdateError(s.playErrorList.SET_REMOTE_DESC_ERROR)
  4047. }), this.sendCandidateInfo(this.candidateInfo), this.candidateInfo = [], this.waitICETimer = setTimeout(function () {
  4048. n.state == i.ENUM_PLAY_STATE.waitingServerICE && (n.logger.error("zp.orm.1 waiting server timeout"), n.playStateUpdateError(s.playErrorList.SERVER_CANDIDATE_TIMEOUT))
  4049. }, this.waitingICETimeInterval), this.state = i.ENUM_PLAY_STATE.waitingServerICE, this.logger.debug("zp.orm.1 call success")
  4050. } else this.logger.error("zp.orm.1 current state " + this.state + " not allowed")
  4051. }, e.prototype.onRecvCandidateInfo = function (e, t, r) {
  4052. var n = this;
  4053. if (this.logger.debug("zp.orci.1 received "), this.state == i.ENUM_PLAY_STATE.waitingServerICE) {
  4054. null != this.waitICETimer && (clearTimeout(this.waitICETimer), this.waitICETimer = null), this.dataReport.addEvent(this.reportSeq, "RecvIceCandidate"), this.signal.sendCandidateInfoAck(e, this.sessionId, 0);
  4055. for (var o = 0; o < r.infos.length; o++) {
  4056. var a = {
  4057. sdpMid: r.infos[o].sdpMid,
  4058. sdpMLineIndex: r.infos[o].sdpMLineIndex,
  4059. candidate: r.infos[o].candidate
  4060. };
  4061. this.logger.debug("zp.orci.1 candidate " + a.candidate), this.peerConnection.addIceCandidate(new RTCIceCandidate(a)).then(function () {
  4062. n.logger.debug("zp.orci.1 add success")
  4063. }, function (e) {
  4064. n.logger.error("zp.orci.1 add error " + e.toString()), n.playStateUpdateError(s.playErrorList.SERVER_CANDIDATE_ERROR)
  4065. })
  4066. }
  4067. this.state = i.ENUM_PLAY_STATE.connecting, this.logger.debug("zp.orci.1 call success")
  4068. } else this.logger.warn("zp.orci.1 current state " + this.state + " not allowed")
  4069. }, e.prototype.onIceCandidate = function (e) {
  4070. if (this.logger.info("zp.oic.1 called"), null != e.candidate) if (this.logger.debug("zp.oic.1 candidate " + e.candidate.candidate), this.state < i.ENUM_PLAY_STATE.waitingServerICE || this.state == i.ENUM_PLAY_STATE.stop) this.logger.debug("zp.oic.1 cached"), this.candidateInfo.push({
  4071. candidate: e.candidate.candidate,
  4072. sdpMid: e.candidate.sdpMid,
  4073. sdpMLineIndex: e.candidate.sdpMLineIndex
  4074. }); else {
  4075. this.logger.debug("zp.oic.1 send");
  4076. var t = {
  4077. candidate: e.candidate.candidate,
  4078. sdpMid: e.candidate.sdpMid,
  4079. sdpMLineIndex: e.candidate.sdpMLineIndex
  4080. };
  4081. this.sendCandidateInfo([t])
  4082. }
  4083. }, e.prototype.onConnectionStateChange = function (e) {
  4084. this.logger.info("zp.oisc.1 called " + e.target.signalingState)
  4085. }, e.prototype.onIceConnectionStateChange = function (e) {
  4086. this.state != i.ENUM_PLAY_STATE.stop && null != this.peerConnection && (this.logger.info("zp.oisc.1 stateChanged " + this.peerConnection.iceConnectionState), "connected" === this.peerConnection.iceConnectionState ? (this.dataReport.addEvent(this.reportSeq, "IceConnected"), this.state != i.ENUM_PLAY_STATE.playing && this.onPlayStateUpdate(s.ENUM_PLAY_STATE_UPDATE.start, this.streamId), this.state = i.ENUM_PLAY_STATE.playing, this.retryState != i.ENUM_RETRY_STATE.didNotStart && (this.retryState = i.ENUM_RETRY_STATE.finished, this.currentRetryCount = 0), this.dataReport.eventStart(this.reportSeq, "PlayState"), this.setPlayQualityTimer()) : "closed" === this.peerConnection.iceConnectionState ? (this.dataReport.addEvent(this.reportSeq, "IceClosed"), this.checkPlayConnectionFailedState(this.peerConnection.iceConnectionState)) : "failed" === this.peerConnection.iceConnectionState && (this.dataReport.addEvent(this.reportSeq, "IceFailed"), this.checkPlayConnectionFailedState(this.peerConnection.iceConnectionState)))
  4087. }, e.prototype.checkPlayConnectionFailedState = function (e) {
  4088. var t = null;
  4089. "failed" == e ? t = s.playErrorList.MEDIA_CONNECTION_FAILED : "closed" == e && (t = s.playErrorList.MEDIA_CONNECTION_CLOSED), null != t && (this.state != i.ENUM_PLAY_STATE.playing && this.retryState == i.ENUM_PLAY_STATE.didNotStart ? (this.logger.info("zp.oics.1 state " + this.state + " retryState " + this.retryState + " connectionState " + e), this.playStateUpdateError(t)) : this.shouldRetryPlay() ? (this.onPlayStateUpdate(s.ENUM_PLAY_STATE_UPDATE.retry, this.streamId), this.startRetryPlay()) : this.playStateUpdateError(t))
  4090. }, e.prototype.shouldRetryPlay = function () {
  4091. return this.retryState == i.ENUM_RETRY_STATE.didNotStart && this.state != i.ENUM_PLAY_STATE.playing ? (this.logger.info("zp.srp.1.0 connection didn't success"), !1) : this.retryState == i.ENUM_RETRY_STATE.retrying ? (this.logger.info("zp.srp.0.0 already retrying"), !1) : this.currentRetryCount > this.maxRetryCount ? (this.logger.info("zp.srp.1.0 beyond max"), !1) : (this.logger.debug("zp.srp.1.0 call success"), !0)
  4092. }, e.prototype.startRetryPlay = function () {
  4093. this.logger.debug("zp.srp.0 call");
  4094. var e = this.streamId, t = this.remoteVideo, r = this.audioOutput;
  4095. this.resetPlay(), this.tryStartPlay(e, t, r)
  4096. }, e.prototype.clearTryPlayTimer = function () {
  4097. null != this.waitingServerTimer && (clearTimeout(this.waitingServerTimer), this.waitingServerTimer = null)
  4098. }, e.prototype.tryStartPlay = function (e, t, r) {
  4099. var n = this;
  4100. if (this.logger.debug("zp.tsp.1 call"), this.clearTryPlayTimer(), this.streamId = e, this.remoteVideo = t, this.audioOutput = r, this.currentRetryCount > this.maxRetryCount) return this.logger.error("zp.tsp.1 beyond max limit"), void this.playStateUpdateError(s.playErrorList.WEBSOCKET_ERROR);
  4101. this.retryState = i.ENUM_RETRY_STATE.retrying, this.currentRetryCount += 1, this.signal.isServerConnected() ? (this.logger.debug("zp.tsp.1 signal connected"), this.startPlay(e, this.remoteVideo, this.audioOputput)) : (this.logger.debug("zp.tsp.1 signal server not connected"), this.waitingServerTimer = setTimeout(function () {
  4102. n.tryStartPlay(e, n.remoteVideo, n.audioOputput)
  4103. }, this.waitingServerTimerInterval))
  4104. }, e.prototype.clearPlayQualityTimer = function () {
  4105. null != this.qualityTimer && (clearInterval(this.qualityTimer), this.qualityTimer = null), this.lastPlayStats = {
  4106. time: null,
  4107. audioBytesReceived: null,
  4108. videoBytesReceived: null,
  4109. framesDecoded: null,
  4110. framesDropped: null,
  4111. framesReceived: null
  4112. }
  4113. }, e.prototype.resetPlay = function () {
  4114. this.logger.info("zp.rp.1 call"), this.streamId = null, this.state = i.ENUM_PLAY_STATE.stop, null != this.peerConnection && (this.peerConnection.close(), this.peerConnection = null), null != this.waitingOfferTimer && (clearTimeout(this.waitingOfferTimer), this.waitingOfferTimer = null), null != this.waitICETimer && (clearTimeout(this.waitICETimer), this.waitICETimer = null), this.clearPlayQualityTimer(), this.remoteVideo && (this.remoteVideo.srcObject = null, this.remoteVideo.oncanplay = null, this.remoteVideo = null), this.audioOputput = null, this.signal && (this.signal.unregisterPushCallback("MediaDescPush", this.sessionId), this.signal.unregisterPushCallback("CandidateInfoPush", this.sessionId), this.signal.unregisterPushCallback("CloseSessionPush", this.sessionId)), this.sessionSeq = 0, this.answerSeq = 0, this.videoSizeCallback = !1, this.currentRetryCount = 0, this.retryState = i.ENUM_RETRY_STATE.didNotStart, this.clearTryPlayTimer()
  4115. }, e.prototype.setPlayQualityTimer = function () {
  4116. var e = this;
  4117. null == this.qualityTimer && (this.logger.debug("zp.spq.1 startTimer"), this.clearPlayQualityTimer(), this.qualityTimer = setInterval(function () {
  4118. e.peerConnection && e.peerConnection.getStats(null).then(function (t) {
  4119. e.getPlayStats(t)
  4120. }, function (t) {
  4121. e.logger.info("zp.spq.1 getStats error " + t.toString())
  4122. })
  4123. }, this.qualityTimeInterval), this.lastPlayStats = {
  4124. time: 0,
  4125. audioBytesReceived: 0,
  4126. videoBytesReceived: 0,
  4127. framesDecoded: 0,
  4128. framesReceived: 0,
  4129. framesDropped: 0
  4130. })
  4131. }, e.prototype.getPlayStats = function (e) {
  4132. var t = this;
  4133. if (null != e) {
  4134. var r = {
  4135. audioFractionLost: 0,
  4136. audioPacketsLost: 0,
  4137. audioBitrate: 0,
  4138. videoBitrate: 0,
  4139. videoFPS: 0,
  4140. playData: 0,
  4141. nackCount: 0,
  4142. pliCount: 0,
  4143. sliCount: 0,
  4144. videoFractionLos: 0,
  4145. audioJitter: 0,
  4146. videoFractionLost: null,
  4147. videoFramesDecoded: 0,
  4148. frameHeight: 0,
  4149. frameWidth: 0,
  4150. videoTransferFPS: 0,
  4151. videoFramesDropped: 0,
  4152. totalRoundTripTime: 0,
  4153. currentRoundTripTime: 0
  4154. }, i = this.lastPlayStats.time;
  4155. e.forEach(function (e) {
  4156. ("inbound-rtp" == e.type || "ssrc" == e.type && null != e.bytesReceived) && ("audio" == e.mediaType || e.id.indexOf("AudioStream") >= 0) ? (0 != i && (r.audioBitrate = 8 * (e.bytesReceived - t.lastPlayStats.audioBytesReceived) / (e.timestamp - i)), r.audioBitrate < 0 && (r.audioBitrate = 0), r.audioJitter = e.jitter, r.audioPacketsLost = e.packetsLost, r.audioFractionLost = e.fractionLost, t.lastPlayStats.audioBytesReceived = e.bytesReceived, t.lastPlayStats.time = e.timestamp) : ("inbound-rtp" == e.type || "ssrc" == e.type && null != e.bytesReceived) && ("video" == e.mediaType || e.id.indexOf("VideoStream") >= 0) ? (0 != i && (r.videoBitrate = 8 * (e.bytesReceived - t.lastPlayStats.videoBytesReceived) / (e.timestamp - i), r.videoFPS = 1e3 * (e.framesDecoded - t.lastPlayStats.framesDecoded) / (e.timestamp - i)), r.videoBitrate < 0 && (r.videoBitrate = 0), r.videoFPS < 0 && (r.videoFPS = 0), r.nackCount = e.nackCount, r.pliCount = e.pliCount, r.sliCount = e.sliCount, r.videoFractionLost = e.fractionLost, r.videoFramesDecoded = e.framesDecoded, t.lastPlayStats.videoBytesReceived = e.bytesReceived, t.lastPlayStats.framesDecoded = e.framesDecoded, t.lastPlayStats.time = e.timestamp) : "track" == e.type && ("video" == e.kind || e.id.indexOf("video") >= 0) ? (r.frameHeight = e.frameHeight, r.frameWidth = e.frameWidth, 0 != i && (r.videoTransferFPS = 1e3 * (e.framesReceived - t.lastPlayStats.framesReceived) / (e.timestamp - i), r.videoFramesDropped = e.framesDropped - t.lastPlayStats.framesDropped), r.videoTransferFPS < 0 && (r.videoTransferFPS = 0), r.videoFramesDropped < 0 && (r.videoFramesDropped = 0), t.lastPlayStats.framesReceived = e.framesReceived, t.lastPlayStats.framesDropped = e.framesDropped) : "candidate-pair" == e.type && (null != e.totalRoundTripTime && (r.totalRoundTripTime = e.totalRoundTripTime), null != e.currentRoundTripTime && (r.currentRoundTripTime = e.currentRoundTripTime))
  4157. }), this.uploadPlayQuality(r), 0 != i && this.onPlayQualityUpdate(this.streamId, r)
  4158. }
  4159. }, e.prototype.uploadPlayQuality = function (e) {
  4160. var t = this;
  4161. if (this.qualityUpload) {
  4162. var r = Date.parse(new Date + "");
  4163. (0 == this.qualityUploadLastTime || r - this.qualityUploadLastTime >= this.qualityUploadInterval) && (this.logger.debug("zp.upq.1 upload"), e.stream_type = "play", e.stream_id = this.streamId, e.timeStamp = r / 1e3, this.signal.QualityReport(s.getSeq(), this.sessionId, e, function (e, r, i) {
  4164. void 0 !== i.report && (t.qualityUpload = i.report, t.qualityUploadInterval = i.report_interval_ms)
  4165. }, function (e, r) {
  4166. t.logger.info("zp.upq.1 upload failed " + e)
  4167. }), this.qualityUploadLastTime = r)
  4168. }
  4169. }, e.prototype.onRecvResetSession = function (e, t, r) {
  4170. this.logger.info("zp.orrs.1 received "), t == this.sessionId ? (this.dataReport.addEvent(this.reportSeq, "RecvResetSession"), this.shouldRetryPlay() && this.startRetryPlay()) : this.logger.info("zp.orrs.1 cannot find session")
  4171. }, e.prototype.onRecvCloseSession = function (e, t, r) {
  4172. this.logger.info("zp.orcs.1 reason: " + r.reason), this.dataReport.addEvent(this.reportSeq, "RecvCloseSession"), this.signal.sendCloseSessionAck(e, this.sessionId, 0);
  4173. var i = JSON.parse(JSON.stringify(s.playErrorList.SESSION_CLOSED));
  4174. i.msg += r.reason, 24 === r.reason ? this.startRetryPlay() : this.playStateUpdateError(i)
  4175. }, e.prototype.onGotRemoteStream = function (e) {
  4176. this.logger.info("zp.ogrs.0 called " + e), this.remoteVideo ? (this.remoteVideo.srcObject = e, this.audioOputput && this.setAudioDestination(this.audioOputput), this.dataReport.addEvent(this.reportSeq, "GetRemoteStream")) : this.logger.error("zp.ogrs.0 no remoteVideo")
  4177. }, e.prototype.sendCandidateInfo = function (e) {
  4178. var t = this;
  4179. this.logger.debug("zp.sci.1 called"), !(e = e.filter(function (e) {
  4180. return !(e.candidate.indexOf("tcp") > 0)
  4181. })) || e.length < 1 ? this.logger.info("zp.sci.1 cancelled") : (this.dataReport.eventStart(this.reportSeq, "SendIceCandidate"), this.signal.sendCandidateInfo(s.getSeq(), this.sessionId, e, function (e, r, i) {
  4182. t.logger.debug("zp.sci.1 send success"), t.dataReport.eventEnd(t.reportSeq, "SendIceCandidate")
  4183. }, function (e, r) {
  4184. t.logger.error("zp.sci.1 failed to send: " + e.toString()), t.dataReport.eventEndWithMsg(t.reportSeq, "SendIceCandidate", {error: e}), t.playStateUpdateError(s.playErrorList.SEND_CANDIDATE_ERROR)
  4185. }))
  4186. }, e.prototype.shouldSendCloseSession = function (e) {
  4187. return this.state != s.ENUM_PLAY_STATE_UPDATE.stop && this.state != i.ENUM_PLAY_STATE.waitingSessionRsp
  4188. }, e.prototype.playStateUpdateError = function (e) {
  4189. this.logger.debug("zp.psue.1 called ", e.code), 0 != this.sessionId && this.shouldSendCloseSession(e) && (this.signal.sendCloseSession(s.getSeq(), this.sessionId, 1), this.closeSessionSignal = !0), this.state = i.ENUM_PLAY_STATE.stop, this.onPlayStateUpdate(s.ENUM_PLAY_STATE_UPDATE.error, this.streamId, e), this.resetPlay()
  4190. }, e.prototype.onPlayStateUpdate = function (e, t, r) {
  4191. }, e.prototype.onPlayQualityUpdate = function (e, t) {
  4192. }, e.prototype.onVideoSizeChanged = function (e, t, r) {
  4193. }, e.prototype.stopPlay = function () {
  4194. this.logger.debug("zp.sp.1.1 called"), this.sessionId && !this.closeSessionSignal && this.signal.sendCloseSession(s.getSeq(), this.sessionId, 0), this.dataReport.eventEndWithMsg(this.reportSeq, "PlayState", {state: this.state + ""}), this.dataReport.addEvent(this.reportSeq, "StopPlay"), this.dataReport.addMsgExt(this.reportSeq, {
  4195. stream: this.streamId,
  4196. sessionId: this.sessionId
  4197. }), this.dataReport.uploadReport(this.reportSeq, "RTCPlayStream"), this.resetPlay()
  4198. }, e.prototype.onDisconnect = function () {
  4199. this.logger.info("zp.od.1 call"), this.logger.info("zp.od.1 websocket disconnect"), this.dataReport.addEvent(this.reportSeq, "OnDisconnect"), this.playStateUpdateError(s.playErrorList.WEBSOCKET_ERROR)
  4200. }, e
  4201. }();
  4202. t.ZegoPlayWeb = o
  4203. }, function (e, t, r) {
  4204. "use strict";
  4205. Object.defineProperty(t, "__esModule", {value: !0});
  4206. var i = function () {
  4207. function e(e, t) {
  4208. this.playerList = {}, this.publisherList = {}
  4209. }
  4210. return e.prototype.setSessionInfo = function (e, t, r, i) {
  4211. }, e
  4212. }();
  4213. t.ZegoStreamCenter = i
  4214. }, function (e, t, r) {
  4215. "use strict";
  4216. var i,
  4217. s = this && this.__extends || (i = Object.setPrototypeOf || {__proto__: []} instanceof Array && function (e, t) {
  4218. e.__proto__ = t
  4219. } || function (e, t) {
  4220. for (var r in t) t.hasOwnProperty(r) && (e[r] = t[r])
  4221. }, function (e, t) {
  4222. function r() {
  4223. this.constructor = e
  4224. }
  4225. i(e, t), e.prototype = null === t ? Object.create(t) : (r.prototype = t.prototype, new r)
  4226. });
  4227. Object.defineProperty(t, "__esModule", {value: !0});
  4228. var n = r(17), o = r(0), a = r(1), c = r(18), l = r(19), d = r(20), h = r(21), u = r(22), p = r(23),
  4229. g = function (e) {
  4230. function t() {
  4231. return e.call(this) || this
  4232. }
  4233. return s(t, e), t.prototype.init = function () {
  4234. this.bindSocketHandler(), this.bindStreamHandler(), this.bindHeatBeatHandler(), this.bindRoomHandler(), this.bindMessageHandler(), this.bindLiveHandler(), this.bindStreamCenterHandler()
  4235. }, t.prototype.bindSocketHandler = function () {
  4236. var e = this;
  4237. this.socketCenter = new c.SocketCenter(this.logger, this.stateCenter), this.socketCenter.registerRouter("push_signal", function (t) {
  4238. e.liveHandler.handlePushSignalMsg(t)
  4239. }), this.socketCenter.getSocket = function (t) {
  4240. return e.getSocket(t)
  4241. }, this.socketCenter.handlePushKickout = function (t) {
  4242. e.logger.info("zb.cm.bsh.0 call hpk"), e.roomHandler.setRunState(o.ENUM_RUN_STATE.logout), e.roomHandler.resetRoom(), e.onKickOut({
  4243. code: o.sdkErrorList.KICK_OUT.code,
  4244. msg: o.sdkErrorList.KICK_OUT.msg + t.body.reason
  4245. }), e.logger.debug("zb.cm.bsh.0 call hpk success")
  4246. }, this.socketCenter.handlePushCustomMsg = function (t) {
  4247. e.messageHandler.handlePushCustomMsg(t)
  4248. }, this.socketCenter.handlePushUserStateUpdateMsg = function (t) {
  4249. e.roomHandler.handlePushUserStateUpdateMsg(t)
  4250. }, this.socketCenter.handlePushRoomMsg = function (t) {
  4251. e.onRecvRoomMsg(t.body.chat_data, t.body.server_msg_id, t.body.ret_msg_id)
  4252. }, this.socketCenter.handlePushMergeMsg = function (t) {
  4253. e.messageHandler.handlePushMergeMsg(t)
  4254. }, this.socketCenter.handlePushTransMsg = function (t) {
  4255. e.messageHandler.handlePushTransMsg(t)
  4256. }, this.socketCenter.handleBigImMsgRsp = function (t) {
  4257. e.messageHandler.handleBigImMsgRsp(t)
  4258. }
  4259. }, t.prototype.bindStreamHandler = function () {
  4260. var e = this;
  4261. this.streamHandler = new d.StreamHandler(this.logger, this.stateCenter, this.socketCenter), this.streamHandler.onStreamUpdated = function (t, r) {
  4262. e.onStreamUpdated(t, r)
  4263. }, this.streamHandler.onPublishStateUpdate = function (t, r, i) {
  4264. e.onPublishStateUpdate(t, r, i)
  4265. }, this.streamHandler.onStreamExtraInfoUpdated = function (t) {
  4266. e.onStreamExtraInfoUpdated(t)
  4267. }, this.streamHandler.setCDNInfo = function (t, r) {
  4268. e.setCDNInfo(t, r)
  4269. }
  4270. }, t.prototype.bindHeatBeatHandler = function () {
  4271. var e = this;
  4272. this.heartBeatHandler = new h.HeartBeatHandler(this.logger, this.stateCenter, this.socketCenter), this.heartBeatHandler.onRecvReliableMessage = function (t, r, i) {
  4273. e.onRecvReliableMessage(t, r, i)
  4274. }, this.heartBeatHandler.handleFetchStreamListRsp = function (t) {
  4275. e.streamHandler.handleFetchStreamListRsp(t)
  4276. }, this.heartBeatHandler.fetchUserList = function () {
  4277. e.roomHandler.fetchUserList()
  4278. }, this.heartBeatHandler.onUpdateOnlineCount = function (t, r) {
  4279. e.onUpdateOnlineCount(t, r)
  4280. }, this.heartBeatHandler.updateStreamInfo = function (t, r, i, s) {
  4281. void 0 === i && (i = ""), e.streamHandler.updateStreamInfo(t, r, i, s)
  4282. }, this.heartBeatHandler.hbLogout = function (t) {
  4283. e.onDisconnect(t)
  4284. }
  4285. }, t.prototype.bindRoomHandler = function () {
  4286. var e = this;
  4287. this.roomHandler = new l.RoomHandler(this.logger, this.stateCenter, this.socketCenter), this.roomHandler.loginSuccessCallBack = function (t, r) {
  4288. var i = r.body.hearbeat_interval < o.MINIUM_HEARTBEAT_INTERVAL ? o.MINIUM_HEARTBEAT_INTERVAL : r.body.hearbeat_interval;
  4289. e.heartBeatHandler.start(i), e.heartBeatHandler.resetCheckMessage(), e.heartBeatHandler.startCheckMessageTimeout(), e.streamCenter.setSessionInfo(e.stateCenter.appid, e.stateCenter.idName, e.stateCenter.token, e.stateCenter.testEnvironment), r.body.anchor_info && e.onGetAnchorInfo(r.body.anchor_info.anchor_id_name, r.body.anchor_info.anchor_nick_name), r.body.online_count && e.onUpdateOnlineCount(e.stateCenter.roomid, r.body.online_count), e.logger.info("zb.cm.brh hls userStateUpdate " + e.stateCenter.userStateUpdate), e.stateCenter.userStateUpdate && (e.logger.info("zb.cm.brh hls fetch all new userlist"), e.roomHandler.fetchUserList()), e.streamHandler.handleStreamStart(t, r)
  4290. }, this.roomHandler.onGetTotalUserList = function (t, r) {
  4291. e.onGetTotalUserList(t, r)
  4292. }, this.roomHandler.resetRoomCallBack = function () {
  4293. e.heartBeatHandler.resetHeartbeat(), e.heartBeatHandler.resetCheckMessage(), e.resetStreamCenter()
  4294. }, this.roomHandler.onUserStateUpdate = function (t, r) {
  4295. e.onUserStateUpdate(t, r)
  4296. }, this.roomHandler.onDisconnect = function (t) {
  4297. e.onDisconnect(t)
  4298. }, this.roomHandler.loginBodyData = function () {
  4299. return e.loginBodyData()
  4300. }
  4301. }, t.prototype.bindMessageHandler = function () {
  4302. var e = this;
  4303. this.messageHandler = new u.MessageHandler(this.logger, this.stateCenter, this.socketCenter), this.messageHandler.onRecvCustomCommand = function (t, r, i) {
  4304. e.onRecvCustomCommand(t, r, i)
  4305. }, this.messageHandler.onRecvBigRoomMessage = function (t, r) {
  4306. e.onRecvBigRoomMessage(t, r)
  4307. }, this.messageHandler.onRecvReliableMessage = function (t, r, i) {
  4308. e.onRecvReliableMessage(t, r, i)
  4309. }
  4310. }, t.prototype.bindLiveHandler = function () {
  4311. var e = this;
  4312. this.liveHandler = new p.LiveHandler(this.logger, this.stateCenter, this.socketCenter), this.liveHandler.onRecvEndJoinLiveCommand = function (t, r, i, s) {
  4313. e.onRecvEndJoinLiveCommand(t, r, i, s)
  4314. }, this.liveHandler.onRecvInviteJoinLiveRequest = function (t, r, i, s) {
  4315. e.onRecvInviteJoinLiveRequest(t, r, i, s)
  4316. }, this.liveHandler.onRecvJoinLiveRequest = function (t, r, i, s) {
  4317. e.onRecvJoinLiveRequest(t, r, i, s)
  4318. }
  4319. }, t.prototype.bindStreamCenterHandler = function () {
  4320. var e = this;
  4321. this.streamCenter.onPlayStateUpdate = function (t, r, i) {
  4322. e.onPlayStateUpdateHandle(t, r, i)
  4323. }, this.streamCenter.onPlayQualityUpdate = function (t, r) {
  4324. e.onPlayQualityUpdate(t, r)
  4325. }, this.streamCenter.onPublishStateUpdate = function (t, r, i) {
  4326. e.onPublishStateUpdateHandle(t, r, i)
  4327. }, this.streamCenter.onPublishQualityUpdate = function (t, r) {
  4328. e.onPublishQualityUpdate(t, r)
  4329. }, this.streamCenter.onPlayerStreamUrlUpdate = function (t, r, i) {
  4330. e.onStreamUrlUpdate(t, r, i)
  4331. }, this.streamCenter.onVideoSizeChanged = function (t, r, i) {
  4332. e.onVideoSizeChanged(t, r, i)
  4333. }
  4334. }, t.prototype.config = function (e) {
  4335. return this.logger.debug("zb.cm.cf call"), a.ClientUtil.checkConfigParam(e, this.logger) ? (this.stateCenter.appid = e.appid, this.stateCenter.server = e.server, this.stateCenter.idName = e.idName, this.stateCenter.nickName = e.nickName, "boolean" == typeof e.testEnvironment && (this.stateCenter.testEnvironment = e.testEnvironment), this.logger.setLogLevel(e.logLevel), !1 === e.audienceCreateRoom && (this.stateCenter.roomCreateFlag = 0), e.remoteLogLevel ? this.logger.setRemoteLogLevel(e.remoteLogLevel) : this.logger.setRemoteLogLevel(0), this.logger.setSessionInfo(e.appid, "", "", e.idName, "", o.PROTO_VERSION), e.logUrl && this.logger.openLogServer(e.logUrl), -1 == this.stateCenter.server.indexOf("test2-wsliveroom-api.zego.im") && -1 == this.stateCenter.server.indexOf("wsliveroom-test.zegocloud.com") && -1 == this.stateCenter.server.indexOf("wsliveroom-test.zego.im") || (this.stateCenter.testEnvironment = !0), this.stateCenter.configOK = !0, this.logger.debug("zb.cm.cf call success"), !0) : (this.logger.error("zb.cm.cf param error"), !1)
  4336. }, t.prototype.login = function (e, t, r, i, s) {
  4337. "string" != typeof e || "string" != typeof r || 1 !== t && 2 !== t ? this.logger.error("zb.rh.lg params error") : this.roomHandler.login(e, t, r, null, i, s)
  4338. }, t.prototype.loginWithAuthor = function (e, t, r, i, s, n) {
  4339. "string" != typeof e || "string" != typeof r || "string" != typeof i || 1 !== t && 2 !== t ? this.logger.error("zb.rh.lg params error") : this.roomHandler.login(e, t, r, i, s, n)
  4340. }, t.prototype.logout = function () {
  4341. return this.roomHandler.logout()
  4342. }, t.prototype.setUserStateUpdate = function (e) {
  4343. "boolean" == typeof e ? this.roomHandler.setUserStateUpdate(e) : console.error("setUserStateUpdate param error")
  4344. }, t.prototype.onUserStateUpdate = function (e, t) {
  4345. }, t.prototype.onGetTotalUserList = function (e, t) {
  4346. }, t.prototype.onUpdateOnlineCount = function (e, t) {
  4347. }, t.prototype.onGetAnchorInfo = function (e, t) {
  4348. }, t.prototype.release = function () {
  4349. this.logger.debug("zb.cm.rl call"), this.roomHandler.setRunState(o.ENUM_RUN_STATE.logout), this.roomHandler.resetRoom(), this.logger.stopLogServer(), this.logger.debug("zb.cm.rl call success")
  4350. }, t.prototype.sendCustomCommand = function (e, t, r, i) {
  4351. return "string" != typeof t && "object" != typeof t ? (this.logger.error("zb.mh.scc params error"), !1) : this.messageHandler.sendCustomCommand(e, t, r, i)
  4352. }, t.prototype.onRecvCustomCommand = function (e, t, r) {
  4353. }, t.prototype.sendRoomMsg = function (e, t, r, i, s) {
  4354. this.messageHandler.sendRoomMsg(e, t, r, i, s)
  4355. }, t.prototype.onRecvRoomMsg = function (e, t, r) {
  4356. }, t.prototype.sendReliableMessage = function (e, t, r, i) {
  4357. this.messageHandler.sendReliableMessage(e, t, r, i)
  4358. }, t.prototype.onRecvReliableMessage = function (e, t, r) {
  4359. }, t.prototype.sendBigRoomMessage = function (e, t, r, i, s) {
  4360. this.messageHandler.sendBigRoomMessage(e, t, r, i, s)
  4361. }, t.prototype.onRecvBigRoomMessage = function (e, t) {
  4362. }, t.prototype.sendRelayMessage = function (e, t, r, i) {
  4363. this.messageHandler.sendRelayMessage(e, t, r, i)
  4364. }, t.prototype.requestJoinLive = function (e, t, r, i) {
  4365. return this.liveHandler.requestJoinLive(e, t, r, i)
  4366. }, t.prototype.onRecvJoinLiveRequest = function (e, t, r, i) {
  4367. }, t.prototype.inviteJoinLive = function (e, t, r, i) {
  4368. return this.liveHandler.inviteJoinLive(e, t, r, i)
  4369. }, t.prototype.onRecvInviteJoinLiveRequest = function (e, t, r, i) {
  4370. }, t.prototype.endJoinLive = function (e, t, r) {
  4371. return this.liveHandler.endJoinLive(e, t, r)
  4372. }, t.prototype.onRecvEndJoinLiveCommand = function (e, t, r, i) {
  4373. }, t.prototype.respondJoinLive = function (e, t, r, i) {
  4374. return this.liveHandler.respondJoinLive(e, t, r, i)
  4375. }, t.prototype.updateMixStream = function (e, t, r) {
  4376. return this.streamHandler.updateMixStream(e, t, r)
  4377. }, t.prototype.stopMixStream = function (e, t, r) {
  4378. return this.streamHandler.stopMixStream(e, t, r)
  4379. }, t.prototype.updateStreamExtraInfo = function (e, t) {
  4380. return this.streamHandler.updateStreamExtraInfo(e, t)
  4381. }, t.prototype.onStreamUrlUpdate = function (e, t, r) {
  4382. }, t.prototype.onStreamUpdated = function (e, t) {
  4383. }, t.prototype.onStreamExtraInfoUpdated = function (e) {
  4384. }, t.prototype.onPlayStateUpdate = function (e, t, r) {
  4385. }, t.prototype.onVideoSizeChanged = function (e, t, r) {
  4386. }, t.prototype.onPlayQualityUpdate = function (e, t) {
  4387. }, t.prototype.onPublishStateUpdate = function (e, t, r) {
  4388. }, t.prototype.onPublishQualityUpdate = function (e, t) {
  4389. }, t.prototype.onDisconnect = function (e) {
  4390. }, t.prototype.onKickOut = function (e) {
  4391. }, t.getCurrentVersion = function () {
  4392. return o.PROTO_VERSION
  4393. }, t
  4394. }(n.Common);
  4395. t.BaseCenter = g
  4396. }, function (e, t, r) {
  4397. "use strict";
  4398. Object.defineProperty(t, "__esModule", {value: !0});
  4399. var i = r(0), s = function () {
  4400. function e() {
  4401. }
  4402. return e.prototype.onPlayStateUpdateHandle = function (e, t, r) {
  4403. 1 == e && this.stopPlayingStream(t), this.onPlayStateUpdate(e, t, r)
  4404. }, e.prototype.onPublishStateUpdateHandle = function (e, t, r) {
  4405. var s = this;
  4406. 0 == e ? this.stateCenter.publishStreamList[t] && (this.stateCenter.publishStreamList[t].state == i.ENUM_PUBLISH_STREAM_STATE.tryPublish ? (this.stateCenter.publishStreamList[t].state = i.ENUM_PUBLISH_STREAM_STATE.update_info, this.streamHandler.updateStreamInfo(t, i.ENUM_STREAM_SUB_CMD.liveBegin, this.stateCenter.publishStreamList[t].extra_info, function (e) {
  4407. s.stateCenter.publishStreamList[t] && s.stateCenter.publishStreamList[t].state == i.ENUM_PUBLISH_STREAM_STATE.update_info && (s.stateCenter.publishStreamList[t].state = i.ENUM_PUBLISH_STREAM_STATE.stop, s.onPublishStateUpdate(1, t, e), s.streamCenter.stopPlayingStream(t))
  4408. })) : this.WebrtcOnPublishStateUpdateHandle(e, t, r)) : (this.onPublishStateUpdate(e, t, r), 1 == e && this.stopPublishingStream(t))
  4409. }, e.prototype.resetStreamCenter = function () {
  4410. if (this.stateCenter.customUrl && (this.stateCenter.customUrl = null), this.streamCenter.reset(), !this.socketCenter.isDisConnect()) for (var e in this.stateCenter.publishStreamList) this.stateCenter.publishStreamList[e].state == i.ENUM_PUBLISH_STREAM_STATE.publishing && this.streamHandler.updateStreamInfo(e, i.ENUM_STREAM_SUB_CMD.liveEnd, this.stateCenter.publishStreamList[e].extra_info)
  4411. }, e.prototype.handleFetchWebRtcUrlRsp = function (e) {
  4412. var t = e.body.stream_id;
  4413. if ("push" === e.body.ptype) this.stateCenter.publishStreamList[t] ? this.streamCenter.startPublishingStream(t, e.body.urls) : this.logger.error("cb.cm.hfwur no streamid to publish"); else if ("pull" == e.body.ptype) {
  4414. for (var r = !1, i = 0; i < this.stateCenter.streamList.length; i++) if (this.stateCenter.streamList[i].stream_id === t) {
  4415. r = !0;
  4416. break
  4417. }
  4418. 0 == r && this.logger.warn("cb.cm.hfwur cannot find stream, continue to play"), this.streamCenter.startPlayingStream(t, e.body.urls)
  4419. }
  4420. }, e
  4421. }();
  4422. t.Common = s
  4423. }, function (e, t, r) {
  4424. "use strict";
  4425. Object.defineProperty(t, "__esModule", {value: !0});
  4426. var i = r(0), s = r(1), n = function () {
  4427. function e(e, t) {
  4428. var r = this;
  4429. this.cmdSeq = 0, this.responseRouters = {}, this.logger = e, this.stateCenter = t, this.responseRouters = {
  4430. push_kickout: function (e) {
  4431. r.handlePushKickout(e)
  4432. }, push_custommsg: function (e) {
  4433. r.handlePushCustomMsg(e)
  4434. }, push_im_chat: function (e) {
  4435. r.handlePushRoomMsg(e)
  4436. }, push_userlist_update: function (e) {
  4437. r.handlePushUserStateUpdateMsg(e)
  4438. }, push_merge_message: function (e) {
  4439. r.handlePushMergeMsg(e)
  4440. }, trans: function (e) {
  4441. r.handleTransRsp(e)
  4442. }, push_trans: function (e) {
  4443. r.handlePushTransMsg(e)
  4444. }
  4445. }
  4446. }
  4447. return e.prototype.handlePushKickout = function (e) {
  4448. }, e.prototype.handlePushCustomMsg = function (e) {
  4449. }, e.prototype.handlePushRoomMsg = function (e) {
  4450. }, e.prototype.handlePushUserStateUpdateMsg = function (e) {
  4451. }, e.prototype.handlePushMergeMsg = function (e) {
  4452. }, e.prototype.handlePushTransMsg = function (e) {
  4453. }, e.prototype.handleBigImMsgRsp = function (e) {
  4454. }, e.prototype.handleTransRsp = function (e) {
  4455. if (this.stateCenter.isLogin()) if (0 == e.body.err_code) {
  4456. var t = e.body.trans_type;
  4457. this.stateCenter.transSeqMap[t] ? (this.stateCenter.transSeqMap[t].seq = e.body.trans_seq, this.logger.debug("zb.sc.htr trans " + t + " seq " + e.body.trans_seq)) : this.logger.error("zb.sc.htr cannot match send info")
  4458. } else this.logger.error("zb.sc.htr trans send error " + e.body.err_code); else this.logger.error("zb.sc.htr not login")
  4459. }, e.prototype.handleBizChannelRspCallback = function (e, t) {
  4460. 0 === e.body.err_code ? null != t.success && t.success(e.header.seq, e.body.cmd, e.body.rsp_body) : null != t.error && t.error(e.body.err_code, e.header.seq, e.body.rsp_body)
  4461. }, e.prototype.registerRouter = function (e, t) {
  4462. this.responseRouters[e] = t
  4463. }, e.prototype.getSocket = function (e) {
  4464. return null
  4465. }, e.prototype.getHeaderV2 = function (e) {
  4466. return {
  4467. Protocol: "req_v2",
  4468. cmd: e,
  4469. appid: this.stateCenter.appid,
  4470. seq: ++this.cmdSeq,
  4471. user_id: this.stateCenter.userid,
  4472. session_id: this.stateCenter.sessionid || "",
  4473. room_id: this.stateCenter.roomid || ""
  4474. }
  4475. }, e.prototype.getHeader = function (e) {
  4476. return {
  4477. Protocol: "req",
  4478. cmd: e,
  4479. appid: this.stateCenter.appid,
  4480. seq: ++this.cmdSeq,
  4481. user_id: this.stateCenter.userid,
  4482. session_id: this.stateCenter.sessionid || "",
  4483. room_id: this.stateCenter.roomid || ""
  4484. }
  4485. }, e.prototype.sendMessage = function (e, t, r, s) {
  4486. if (this.logger.debug("zb.sc.sm call " + e), this.isDisConnect()) return this.logger.error("zb.sc.sm error " + e), -1;
  4487. var n = "V1" === i.ROOMVERSION ? this.getHeader(e) : this.getHeaderV2(e), o = {header: n, body: t};
  4488. if (null == r && (r = null), null == s && (s = null), null != r || null != s) {
  4489. var a = {data: o, seq: n.seq, deleted: !1, time: Date.parse(new Date + ""), success: r, error: s},
  4490. c = this.stateCenter.sendCommandList.push(a);
  4491. this.stateCenter.sendCommandMap[a.seq] = c
  4492. }
  4493. return this.websocket.send(JSON.stringify(o)), this.logger.debug("zb.sc.sm success"), n.seq
  4494. }, e.prototype.sendCustomMessage = function (e, t, r, s) {
  4495. if (this.logger.debug("zb.sc.scm call"), this.isDisConnect()) return this.logger.error("zb.sc.scm error"), !1;
  4496. var n = "V1" === i.ROOMVERSION ? this.getHeader(e) : this.getHeaderV2(e), o = {header: n, body: t},
  4497. a = JSON.stringify(o);
  4498. null == r && (r = null), null == s && (s = null);
  4499. var c = {data: o, seq: n.seq, deleted: !1, time: Date.parse(new Date + ""), success: r, error: s},
  4500. l = this.stateCenter.sendDataList.push(c);
  4501. return this.stateCenter.sendDataMap[c.seq] = l, this.websocket.send(a), this.logger.debug("zb.sc.scm success seq: ", n.seq), !0
  4502. }, e.prototype.isDisConnect = function () {
  4503. return !this.websocket || 1 !== this.websocket.readyState
  4504. }, e.prototype.closeSocket = function () {
  4505. this.websocket && (this.logger.info("zb.sc.cs close websocket"), this.websocket.onclose = null, this.websocket.onerror = null, this.websocket.close(), this.websocket = null)
  4506. }, e.prototype.createSocket = function (e) {
  4507. this.websocket = this.getSocket(e)
  4508. }, e.prototype.openHandler = function (e) {
  4509. this.websocket.onopen = e
  4510. }, e.prototype.closeHandler = function (e) {
  4511. this.websocket.onclose = e
  4512. }, e.prototype.errorHandler = function () {
  4513. var e = this;
  4514. this.websocket.onerror = function (t) {
  4515. e.logger.error("zb.sc.oe msg=" + JSON.stringify(t))
  4516. }
  4517. }, e.prototype.checkResponse = function (e) {
  4518. return (e.header.appid !== this.stateCenter.appid || e.header.session_id !== this.stateCenter.sessionid || e.header.user_id !== this.stateCenter.userid || e.header.room_id !== this.stateCenter.roomid || this.stateCenter.runState !== i.ENUM_RUN_STATE.login) && (this.logger.error("zb.sc.crp check session fail."), !0)
  4519. }, e.prototype.responseHandler = function () {
  4520. var e = this;
  4521. this.websocket.onmessage = function (t) {
  4522. var r = JSON.parse(t.data);
  4523. e.logger.info("zb.sc.ws.rph jsonmsg= ", r.header.cmd), e.logger.info("zb.sc.ws.rph jsonmsg= ", t.data), "login" !== r.header.cmd ? "logout" !== r.header.cmd ? e.stateCenter.isLogin() ? e.checkResponse(r) ? e.logger.error("zb.sc.ws.rph check session fail.") : (e.handleSendCommandMsgRsp(r), e.logger.info("zb.sc.ws.rph cmd=" + r.header.cmd + ",function=" + !!e.responseRouters[r.header.cmd]), e.responseRouters[r.header.cmd] && e.responseRouters[r.header.cmd](r)) : e.logger.warn("zb.sc.ws.rph already logout") : e.responseRouters.logout(r, e.cmdSeq) : e.responseRouters.login(r, e.cmdSeq)
  4524. }
  4525. }, e.prototype.handleSendCommandMsgRsp = function (e) {
  4526. this.logger.debug("zb.sc.hscmr call");
  4527. var t, r = this.stateCenter.sendCommandMap[e.header.seq];
  4528. null != r && ("login" == (t = r._data).data.header.cmd ? this.logger.debug("zb.sc.hscmr don't check " + t.data.header.cmd) : "relay" == t.data.header.cmd ? this.handleRelayRspCallback(e, t) : "bigim_chat" == t.data.header.cmd ? this.handleBigImRspCallback(e, t) : "biz_channel" == t.data.header.cmd ? this.handleBizChannelRspCallback(e, t) : 0 === e.body.err_code ? null != t.success && t.success(e.header.seq) : null != t.error && t.error(s.ClientUtil.getServerError(e.body.err_code), e.header.seq), delete this.stateCenter.sendCommandMap[e.header.seq], this.stateCenter.sendCommandList.remove(r)), this.logger.debug("zb.sc.hscmr call success")
  4529. }, e.prototype.handleRelayRspCallback = function (e, t) {
  4530. 0 === e.body.err_code ? null != t.success && t.success(e.header.seq, e.body.relay_result) : null != t.error && t.error(s.ClientUtil.getServerError(e.body.err_code), e.header.seq)
  4531. }, e.prototype.handleBigImRspCallback = function (e, t) {
  4532. 0 === e.body.err_code ? null != t.success && this.handleBigImMsgRsp(e) : null != t.error && t.error(s.ClientUtil.getServerError(e.body.err_code), e.header.seq)
  4533. }, e
  4534. }();
  4535. t.SocketCenter = n
  4536. }, function (e, t, r) {
  4537. "use strict";
  4538. Object.defineProperty(t, "__esModule", {value: !0});
  4539. var i = r(0), s = r(1), n = function () {
  4540. function e(e, t, r) {
  4541. this.logger = e, this.socketCenter = r, this.stateCenter = t
  4542. }
  4543. return e.prototype.setRunState = function (e) {
  4544. this.logger.debug("zb.rh.srs old=" + this.stateCenter.runState + ", new=" + e), this.stateCenter.lastRunState = this.stateCenter.runState, this.stateCenter.runState = e
  4545. }, e.prototype.resetTryLogin = function () {
  4546. this.logger.debug("zb.rh.rtl call"), clearTimeout(this.stateCenter.tryLoginTimer), this.stateCenter.tryLoginTimer = null, this.stateCenter.tryLoginCount = 0, this.logger.debug("zb.rh.rtl call success")
  4547. }, e.prototype.resetBigRoomInfo = function () {
  4548. this.stateCenter.transSeqMap = {}, this.stateCenter.realyMessageList = [], this.stateCenter.relayTimer && (clearTimeout(this.stateCenter.relayTimer), this.stateCenter.relayTimer = null), this.stateCenter.bigImLastTimeIndex = 0, this.stateCenter.bigIMmessageList = [], this.stateCenter.bigImCallbackMap = {}, this.stateCenter.bigImTimer && (clearTimeout(this.stateCenter.bigImTimer), this.stateCenter.bigImTimer = null), this.stateCenter.serverTimeOffset = 0, this.stateCenter.datiTimeWindow = 0, this.stateCenter.bigimTimeWindow = 0
  4549. }, e.prototype.resetRoom = function () {
  4550. var e = this;
  4551. if (this.logger.debug("zb.rh.rr call"), this.resetTryLogin(), this.resetRoomCallBack(), this.stateCenter.streamList = [], this.stateCenter.streamQuerying = !1, this.stateCenter.publishStreamList = {}, this.stateCenter.joinLiveCallbackMap = {}, this.stateCenter.joinLiveRequestMap = {}, this.stateCenter.streamUrlMap = {}, this.resetBigRoomInfo(), this.stateCenter.cmdCallback = {}, this.logger.debug("zb.rh.rr call send logout=", this.stateCenter.sessionid), "0" !== this.stateCenter.sessionid) {
  4552. this.socketCenter.registerRouter("logout", function (t) {
  4553. e.handleLogoutRsp(t)
  4554. }), this.socketCenter.sendMessage("logout", {reserve: 0})
  4555. }
  4556. this.socketCenter.closeSocket(), this.setRunState(i.ENUM_RUN_STATE.logout), this.stateCenter.userid = "", this.stateCenter.sessionid = "", this.logger.setSessionInfo(this.stateCenter.appid, this.stateCenter.roomid, this.stateCenter.userid, this.stateCenter.idName, this.stateCenter.sessionid, i.PROTO_VERSION), this.logger.debug("zb.rh.rr call success")
  4557. }, e.prototype.resetRoomCallBack = function () {
  4558. }, e.prototype.onDisconnect = function (e) {
  4559. }, e.prototype.loginSuccessCallBack = function (e, t) {
  4560. }, e.prototype.onGetTotalUserList = function (e, t) {
  4561. }, e.prototype.login = function (e, t, r, n, o, a) {
  4562. if (this.logger.setSessionInfo(this.stateCenter.appid, e, "", this.stateCenter.idName, "", i.PROTO_VERSION), this.logger.info("zb.rh.lg call:", e, r), n && (this.stateCenter.third_token = n), !this.stateCenter.configOK || !s.ClientUtil.checkLoginParam(e, r)) return this.logger.error("zb.rh.lg param error"), void a({
  4563. code: "",
  4564. msg: "param error"
  4565. });
  4566. this.stateCenter.runState !== i.ENUM_RUN_STATE.logout && (this.logger.debug("zb.rh.lg reset"), this.setRunState(i.ENUM_RUN_STATE.logout), this.resetRoom()), this.logger.debug("zb.rh.lg begin"), this.setRunState(i.ENUM_RUN_STATE.trylogin), this.stateCenter.roomid = e, this.stateCenter.token = r, this.stateCenter.role = t, s.ClientUtil.registerCallback("login", {
  4567. success: o,
  4568. error: a
  4569. }, this.stateCenter.callbackList), this.resetTryLogin(), this.tryLogin(), this.logger.info("zb.rh.lg call success")
  4570. }, e.prototype.loginBodyData = function () {
  4571. return null
  4572. }, e.prototype.tryLogin = function () {
  4573. var e = this;
  4574. if (this.logger.debug("zb.rh.tl call"), this.stateCenter.runState === i.ENUM_RUN_STATE.trylogin) {
  4575. if (++this.stateCenter.tryLoginCount > i.MAX_TRY_LOGIN_COUNT) {
  4576. this.logger.error("zb.rh.tl fail times limit");
  4577. var t = this.stateCenter.lastRunState;
  4578. return this.setRunState(i.ENUM_RUN_STATE.logout), this.resetRoom(), void (t == i.ENUM_RUN_STATE.login ? (this.logger.error("zb.rh.tl fail and disconnect"), this.onDisconnect(i.sdkErrorList.LOGIN_DISCONNECT)) : (this.logger.info("zb.rh.tl fail and callback user"), s.ClientUtil.actionErrorCallback("login", this.stateCenter.callbackList)(i.sdkErrorList.LOGIN_TIMEOUT)))
  4579. }
  4580. if (this.stateCenter.startConnceTime = (new Date).getTime(), console.warn("start connect", this.stateCenter.startConnceTime), this.socketCenter.isDisConnect()) {
  4581. this.logger.debug("zb.rh.tl need new websocket");
  4582. try {
  4583. this.socketCenter.closeSocket(), this.logger.debug("zb.rh.tl new websocket"), this.socketCenter.createSocket(this.stateCenter.server), this.socketCenter.registerRouter("login", function (t, r) {
  4584. e.handleLoginRsp(t, r)
  4585. }), this.socketCenter.closeHandler(function (t) {
  4586. e.socketCenter.closeSocket(), e.closeHandler(t)
  4587. }), this.socketCenter.openHandler(function () {
  4588. e.openHandler()
  4589. })
  4590. } catch (e) {
  4591. this.logger.error("zb.rh.tl websocket err:" + e)
  4592. }
  4593. } else {
  4594. var r = this.loginBodyData();
  4595. this.logger.info("zb.rh.tl use current websocket and sent login"), this.socketCenter.sendMessage("login", r)
  4596. }
  4597. this.stateCenter.tryLoginTimer = setTimeout(function () {
  4598. e.tryLogin()
  4599. }, i.TRY_LOGIN_INTERVAL[this.stateCenter.tryLoginCount % i.MAX_TRY_LOGIN_COUNT]), this.logger.info("zb.rh.tl call success")
  4600. } else this.logger.error("zb.rh.tl state error")
  4601. }, e.prototype.handleLoginRsp = function (e, t) {
  4602. if (this.logger.debug("zb.rh.hlr call"), this.stateCenter.runState === i.ENUM_RUN_STATE.trylogin) {
  4603. if (e.header.seq === t) return 0 !== e.body.err_code ? (this.handleLoginFail(e), void this.logger.error("zb.rh.hlr server error=", e.body.err_code)) : (this.handleLoginSuccess(e), void this.logger.info("zb.rh.hlr call success."));
  4604. this.logger.error("zb.rh.hlr in wrong seq, local=", t, ",recv=", e.header.seq)
  4605. } else this.logger.error("zb.rh.hlr state error")
  4606. }, e.prototype.handleLoginFail = function (e) {
  4607. if (this.logger.debug("zb.rh.hlf call"), s.ClientUtil.isKeepTryLogin(e.body.err_code)) this.logger.warn("zb.rh.hlf KeepTry true"); else {
  4608. var t = this.stateCenter.lastRunState;
  4609. this.setRunState(i.ENUM_RUN_STATE.logout), this.resetRoom();
  4610. var r = s.ClientUtil.getServerError(e.body.err_code);
  4611. t === i.ENUM_RUN_STATE.login ? (this.logger.info("zb.rh.hlf callback disconnect"), this.onDisconnect(r)) : (this.logger.info("zb.rh.hlf callback error"), s.ClientUtil.actionErrorCallback("login", this.stateCenter.callbackList)(r)), this.logger.debug("zb.rh.hlf call success")
  4612. }
  4613. }, e.prototype.handleLoginSuccess = function (e) {
  4614. this.stateCenter.startloginSucTime = (new Date).getTime(), console.warn("login suc", this.stateCenter.startloginSucTime, this.stateCenter.startloginSucTime - this.stateCenter.startloginTime, this.stateCenter.startloginSucTime - this.stateCenter.startConnceTime), this.logger.info("zb.rh.hls call");
  4615. var t = this.stateCenter.lastRunState;
  4616. if (this.setRunState(i.ENUM_RUN_STATE.login), this.stateCenter.userid = e.body.user_id, this.stateCenter.sessionid = e.body.session_id, this.stateCenter.anchor_info = e.body.anchor_info || this.stateCenter.anchor_info, this.logger.setSessionInfo(this.stateCenter.appid, this.stateCenter.roomid, this.stateCenter.userid, this.stateCenter.idName, this.stateCenter.sessionid, i.PROTO_VERSION), e.body.config_info && (this.logger.setRemoteLogLevel(e.body.config_info.log_level), "" != e.body.config_info.log_url && this.logger.openLogServer(e.body.config_info.log_url)), null != e.body.ret_timestamp && "string" == typeof e.body.ret_timestamp) {
  4617. var r = parseFloat(e.body.ret_timestamp);
  4618. this.stateCenter.serverTimeOffset = 0 == r ? 0 : e.body.ret_timestamp - (new Date).getTime()
  4619. }
  4620. e.body.bigim_time_window && "number" == typeof e.body.bigim_time_window && (this.stateCenter.bigimTimeWindow = e.body.bigim_time_window), e.body.dati_time_window && "number" == typeof e.body.dati_time_window && (this.stateCenter.datiTimeWindow = e.body.dati_time_window), this.resetTryLogin(), this.loginSuccessCallBack(t, e)
  4621. }, e.prototype.openHandler = function () {
  4622. this.logger.info("zb.rh.oh websocket.onpen call"), this.socketCenter.responseHandler();
  4623. var e = this.loginBodyData();
  4624. this.logger.info("zb.rh.oh websocket.onpen send login"), this.stateCenter.startloginTime = (new Date).getTime(), console.warn("start login", this.stateCenter.startloginTime, this.stateCenter.startloginTime - this.stateCenter.startConnceTime), this.socketCenter.sendMessage("login", e), this.logger.debug("zb.rh.oh websocket.onpen call success")
  4625. }, e.prototype.closeHandler = function (e) {
  4626. this.logger.info("zb.rh.ws.oc msg=" + JSON.stringify(e)), this.stateCenter.runState !== i.ENUM_RUN_STATE.logout ? this.stateCenter.runState === i.ENUM_RUN_STATE.trylogin && this.stateCenter.tryLoginCount <= i.MAX_TRY_LOGIN_COUNT ? this.logger.info("zb.rh.ws.oc is called because of try login") : this.stateCenter.runState === i.ENUM_RUN_STATE.login ? (this.logger.info("zb.rh.ws.oc is called because of network broken, try again"), this.setRunState(i.ENUM_RUN_STATE.trylogin), this.resetTryLogin(), this.tryLogin()) : (this.logger.error("zb.rh.ws.oc out of think!!!"), this.setRunState(i.ENUM_RUN_STATE.logout), this.resetRoom(), this.onDisconnect(i.sdkErrorList.UNKNOWN)) : this.logger.info("zb.rh.ws.oc onclose logout flow call websocket.close")
  4627. }, e.prototype.logout = function () {
  4628. return this.logger.debug("zb.rh.lo call"), this.stateCenter.runState === i.ENUM_RUN_STATE.logout ? (this.logger.warn("zb.rh.lo at logout"), !1) : (this.resetRoom(), this.logger.info("zb.rh.lo call success"), !0)
  4629. }, e.prototype.setUserStateUpdate = function (e) {
  4630. return this.logger.debug("zb.rh.su call"), "boolean" != typeof e ? (this.logger.info("zb.rh.su param error"), !1) : (this.stateCenter.userStateUpdate = e, this.logger.info("zb.rh.su call success " + e), !0)
  4631. }, e.prototype.fetchUserList = function () {
  4632. this.logger.debug("zb.rh.ful call"), this.stateCenter.userQuerying ? this.logger.warn("zb.rh.ful is already querying") : (this.stateCenter.userQuerying = !0, this.stateCenter.userTempList = [], "V1" === i.ROOMVERSION ? this.fetchUserListWithPage(0) : this.fetchUserListWithPageV2(0), this.logger.info("zb.rh.ful the first time call"))
  4633. }, e.prototype.fetchUserListWithPageV2 = function (e) {
  4634. var t = this;
  4635. this.logger.debug("zb.rh.fulwp call"), this.socketCenter.registerRouter("user_list_v2", function (r) {
  4636. t.handleFetchUserListRspV2(e, r)
  4637. }), this.socketCenter.sendMessage("user_list_v2", {
  4638. marker: 0 === e ? "" : e + "",
  4639. mode: 0,
  4640. limit: 100
  4641. }), this.logger.info("zb.rh.fulwp call success")
  4642. }, e.prototype.fetchUserListWithPage = function (e) {
  4643. var t = this;
  4644. this.logger.debug("zb.rh.fulwp call"), this.socketCenter.registerRouter("user_list", function (e) {
  4645. t.handleFetchUserListRsp(e)
  4646. }), this.socketCenter.sendMessage("user_list", {
  4647. user_index: e,
  4648. sort_type: 0
  4649. }), this.logger.info("zb.rh.fulwp call success")
  4650. }, e.prototype.handleFetchUserListRspV2 = function (e, t) {
  4651. if (this.logger.debug("zb.rh.hfulr call"), 0 != t.body.err_code) return this.stateCenter.userQuerying = !1, void this.logger.info("zb.rh.hfulr fetch error " + t.body.err_code);
  4652. if (this.stateCenter.userStateUpdate) {
  4653. if (this.stateCenter.userTempList = this.stateCenter.userTempList.concat(t.body.user_baseinfos), e != t.body.marker) return this.logger.warn("zb.rh.hfulr fetch another page"), void this.fetchUserListWithPageV2(e + 1);
  4654. this.stateCenter.userSeq = t.body.server_user_seq, this.logger.info("zb.rh.hfulr set user Seq " + this.stateCenter.userSeq);
  4655. for (var r = [], i = 0; i < this.stateCenter.userTempList.length; i++) {
  4656. var s = {
  4657. idName: this.stateCenter.userTempList[i].id_name,
  4658. nickName: this.stateCenter.userTempList[i].nick_name,
  4659. role: this.stateCenter.userTempList[i].role
  4660. };
  4661. r.push(s)
  4662. }
  4663. this.stateCenter.userQuerying = !1, this.onGetTotalUserList(this.stateCenter.roomid, r), this.stateCenter.userTempList = [], this.logger.info("zb.rh.hfulr call success user_list " + r + " count " + r.length)
  4664. }
  4665. }, e.prototype.handleFetchUserListRsp = function (e) {
  4666. if (this.logger.debug("zb.rh.hfulr call"), 0 != e.body.err_code) return this.stateCenter.userQuerying = !1, void this.logger.info("zb.rh.hfulr fetch error " + e.body.err_code);
  4667. if (this.stateCenter.userStateUpdate) {
  4668. this.stateCenter.userTempList = this.stateCenter.userTempList.concat(e.body.user_baseinfos);
  4669. var t = e.body.ret_user_index;
  4670. if (t != e.body.server_user_index) return this.logger.warn("zb.rh.hfulr fetch another page"), void this.fetchUserListWithPage(t + 1);
  4671. this.stateCenter.userSeq = e.body.server_user_seq, this.logger.info("zb.rh.hfulr set user Seq " + this.stateCenter.userSeq);
  4672. for (var r = [], i = 0; i < this.stateCenter.userTempList.length; i++) {
  4673. var s = {
  4674. idName: this.stateCenter.userTempList[i].id_name,
  4675. nickName: this.stateCenter.userTempList[i].nick_name,
  4676. role: this.stateCenter.userTempList[i].role
  4677. };
  4678. r.push(s)
  4679. }
  4680. this.stateCenter.userQuerying = !1, this.onGetTotalUserList(this.stateCenter.roomid, r), this.stateCenter.userTempList = [], this.logger.info("zb.rh.hfulr call success user_list " + r + " count " + r.length)
  4681. }
  4682. }, e.prototype.handleLogoutRsp = function (e) {
  4683. this.logger.debug("zb.rh.hlor result=", e.body.err_code)
  4684. }, e.prototype.handlePushUserStateUpdateMsg = function (e) {
  4685. if (this.logger.info("zb.rh.hpus call"), this.stateCenter.isLogin()) if (this.stateCenter.userStateUpdate) {
  4686. if (this.stateCenter.userSeq + e.body.user_actions.length !== e.body.user_list_seq) return this.logger.warn("zb.rh.hpus fetch new userlist " + this.stateCenter.userSeq, NaN + e.body.user_list_seq), void this.fetchUserList();
  4687. this.stateCenter.userSeq = e.body.user_list_seq, this.logger.debug("zb.rh.hpus push userSeq " + this.stateCenter.userSeq);
  4688. for (var t = [], r = 0; r < e.body.user_actions.length; r++) {
  4689. var i = {
  4690. action: e.body.user_actions[r].Action,
  4691. idName: e.body.user_actions[r].IdName,
  4692. nickName: e.body.user_actions[r].NickName,
  4693. role: e.body.user_actions[r].Role,
  4694. loginTime: e.body.user_actions[r].LoginTime
  4695. };
  4696. t.push(i)
  4697. }
  4698. this.onUserStateUpdate(e.body.room_id, t), this.logger.info("zb.rh.hpus call success")
  4699. } else this.logger.error("zb.rh.hpus no userStateUpdate flag"); else this.logger.error("zb.rh.hpus not login")
  4700. }, e.prototype.onUserStateUpdate = function (e, t) {
  4701. }, e
  4702. }();
  4703. t.RoomHandler = n
  4704. }, function (e, t, r) {
  4705. "use strict";
  4706. Object.defineProperty(t, "__esModule", {value: !0});
  4707. var i = r(0), s = r(1), n = function () {
  4708. function e(e, t, r) {
  4709. this.logger = e, this.socketCenter = r, this.stateCenter = t
  4710. }
  4711. return e.prototype.setCDNInfo = function (e, t) {
  4712. }, e.prototype.onStreamUpdated = function (e, t) {
  4713. }, e.prototype.onStreamExtraInfoUpdated = function (e) {
  4714. }, e.prototype.handleStreamStart = function (e, t) {
  4715. var r = this;
  4716. if (this.stateCenter.streamQuerying = !1, this.socketCenter.registerRouter("stream", function (e) {
  4717. r.handleStreamUpdateRsp(e)
  4718. }), this.socketCenter.registerRouter("push_stream_update", function (e) {
  4719. r.handlePushStreamUpdateMsg(e)
  4720. }), e == i.ENUM_RUN_STATE.login) this.logger.info("zb.sh.hss recover from disconnect so call streamupdate"), this.handleFullUpdateStream(t.body.stream_seq, t.body.stream_info || []); else {
  4721. this.logger.info("zb.sh.hss success callback user"), this.stateCenter.streamList = t.body.stream_info || [], this.stateCenter.streamSeq = t.body.stream_seq;
  4722. for (var n = 0; n < this.stateCenter.streamList.length; n++) this.stateCenter.streamList[n].anchor_id_name == this.stateCenter.idName && (this.updateStreamInfo(this.stateCenter.streamList[n].stream_id, i.ENUM_STREAM_SUB_CMD.liveEnd), this.stateCenter.streamList.splice(n, 1));
  4723. var o = this.makeCallbackStreamList(this.stateCenter.streamList);
  4724. s.ClientUtil.actionSuccessCallback("login", this.stateCenter.callbackList)(o)
  4725. }
  4726. }, e.prototype.onPublishStateUpdate = function (e, t, r) {
  4727. }, e.prototype.updateStreamInfo = function (e, t, r, i) {
  4728. var s = this;
  4729. void 0 === r && (r = ""), this.logger.debug("zb.sh.usi call");
  4730. var n = {stream_id: e, extra_info: r}, o = {sub_cmd: t, stream_msg: JSON.stringify(n)};
  4731. this.socketCenter.registerRouter("stream", function (e) {
  4732. s.handleStreamUpdateRsp(e)
  4733. }), this.socketCenter.sendMessage("stream", o, void 0, i), this.logger.info("zb.sh.usi call success cmd " + t)
  4734. }, e.prototype.handleStreamUpdateRsp = function (e) {
  4735. if (this.stateCenter.isLogin()) if (0 == e.body.err_code) {
  4736. this.logger.info("zb.sh.hsur stream seq " + this.stateCenter.streamSeq + " server seq " + e.body.stream_seq), this.stateCenter.streamSeq = e.body.stream_seq;
  4737. for (var t = 0; t < e.body.stream_info.length; t++) {
  4738. var r = e.body.stream_info[t].stream_id;
  4739. if (!this.stateCenter.publishStreamList[r]) return void this.logger.info("hsur.0 stream is not exist");
  4740. this.stateCenter.publishStreamList[r].state == i.ENUM_PUBLISH_STREAM_STATE.update_info && (this.stateCenter.publishStreamList[r].state = i.ENUM_PUBLISH_STREAM_STATE.publishing, this.onPublishStateUpdate(0, r, 0))
  4741. }
  4742. } else this.logger.error("zb.sh.hsur stream update error " + e.body.err_code); else this.logger.error("zb.sh.hsur not login")
  4743. }, e.prototype.handleFetchStreamListRsp = function (e) {
  4744. this.logger.info("zb.sh.hfslr call"), this.stateCenter.streamQuerying = !1, 0 === e.body.err_code ? this.stateCenter.streamSeq !== e.body.stream_seq ? (this.handleFullUpdateStream(e.body.stream_seq, e.body.stream_info), this.logger.debug("zb.sh.hfslr call success")) : this.logger.info("zb.sh.hfslr same seq") : this.logger.info("zb.sh.hfslr server error=", e.body.err_code)
  4745. }, e.prototype.handleFullUpdateStream = function (e, t) {
  4746. var r = this;
  4747. this.logger.debug("zb.sh.hfus call"), this.stateCenter.streamSeq = e, this.logger.debug("zb.sh.hfus server seq " + this.stateCenter.streamSeq), s.ClientUtil.mergeStreamList(this.logger, this.stateCenter.idName, this.stateCenter.streamList, t, function (e, t, s) {
  4748. 0 !== e.length && (r.logger.debug("zb.sh.hfus callback addstream"), r.onStreamUpdated(i.ENUM_STREAM_UPDATE_TYPE.added, r.makeCallbackStreamList(e))), 0 !== t.length && (r.logger.debug("zb.sh.hfus callback delstream"), r.onStreamUpdated(i.ENUM_STREAM_UPDATE_TYPE.deleted, r.makeCallbackStreamList(t))), 0 !== s.length && (r.logger.debug("zb.sh.hfus callback updatestream"), r.onStreamExtraInfoUpdated(r.makeCallbackStreamList(s)))
  4749. }), this.logger.info("zb.sh.hfus call success")
  4750. }, e.prototype.handlePushStreamUpdateMsg = function (e) {
  4751. if (this.logger.info("zb.sh.hpsum call"), e.body.stream_info && 0 !== e.body.stream_info.length) {
  4752. if (e.body.stream_info.length + this.stateCenter.streamSeq !== e.body.stream_seq) return this.logger.info("zb.sh.hpsum call updatestream"), void this.fetchStreamList();
  4753. switch (this.stateCenter.streamSeq = e.body.stream_seq, e.body.stream_cmd) {
  4754. case i.ENUM_STREAM_UPDATE_CMD.added:
  4755. this.handleAddedStreamList(e.body.stream_info);
  4756. break;
  4757. case i.ENUM_STREAM_UPDATE_CMD.deleted:
  4758. this.handleDeletedStreamList(e.body.stream_info);
  4759. break;
  4760. case i.ENUM_STREAM_UPDATE_CMD.updated:
  4761. this.handleUpdatedStreamList(e.body.stream_info)
  4762. }
  4763. this.logger.info("zb.sh.hpsum call success")
  4764. } else this.logger.info("zb.sh.hpsum, emtpy list")
  4765. }, e.prototype.handleAddedStreamList = function (e) {
  4766. this.logger.debug("zb.sh.hasl call");
  4767. for (var t, r = [], s = 0; s < e.length; s++) if (e[s].anchor_id_name != this.stateCenter.idName) {
  4768. t = !1;
  4769. for (var n = 0; n < this.stateCenter.streamList.length; n++) if (e[s].stream_id === this.stateCenter.streamList[n].stream_id) {
  4770. t = !0;
  4771. break
  4772. }
  4773. t || r.push(e[s])
  4774. } else this.logger.debug("hdsl.0 have self stream added");
  4775. if (0 !== r.length) {
  4776. this.logger.debug("zb.sh.hasl callback addstream");
  4777. for (var o = 0; o < r.length; o++) this.stateCenter.streamList.push(r[o]);
  4778. this.onStreamUpdated(i.ENUM_STREAM_UPDATE_TYPE.added, this.makeCallbackStreamList(r))
  4779. }
  4780. this.logger.info("zb.sh.hasl call success")
  4781. }, e.prototype.handleDeletedStreamList = function (e) {
  4782. this.logger.debug("zb.sh.hdsl call");
  4783. for (var t = [], r = 0; r < e.length; r++) if (e[r].anchor_id_name != this.stateCenter.idName) {
  4784. for (var s = this.stateCenter.streamList.length - 1; s >= 0; s--) if (e[r].stream_id === this.stateCenter.streamList[s].stream_id) {
  4785. this.stateCenter.streamList.splice(s, 1), t.push(e[r]);
  4786. break
  4787. }
  4788. } else this.logger.debug("zb.sh.hdsl have self stream deleted");
  4789. 0 !== t.length && (this.logger.debug("zb.sh.hdsl callback delstream"), this.onStreamUpdated(i.ENUM_STREAM_UPDATE_TYPE.deleted, this.makeCallbackStreamList(t))), this.logger.info("zb.sh.hdsl call")
  4790. }, e.prototype.handleUpdatedStreamList = function (e) {
  4791. this.logger.debug("zb.sh.husl call");
  4792. for (var t = [], r = 0; r < e.length; r++) if (e[r].anchor_id_name != this.stateCenter.idName) {
  4793. for (var i = 0; i < this.stateCenter.streamList.length; i++) if (e[r].stream_id === this.stateCenter.streamList[i].stream_id) {
  4794. e[r].extra_info !== this.stateCenter.streamList[i].extra_info && (this.stateCenter.streamList[i] = e[r], t.push(e[r]));
  4795. break
  4796. }
  4797. } else this.logger.debug("hsul.0 have self stream updated");
  4798. 0 !== t.length && (this.logger.debug("zb.sh.husl callback updatestream"), this.onStreamExtraInfoUpdated(this.makeCallbackStreamList(t))), this.logger.info("zb.sh.husl call success")
  4799. }, e.prototype.fetchStreamList = function () {
  4800. if (this.logger.info("zb.sh.fsl call"), this.stateCenter.isLogin()) this.logger.info("zb.sh.fsl state error"); else if (this.stateCenter.streamQuerying) this.logger.info("zb.sh.fsl already doing"); else {
  4801. this.stateCenter.streamQuerying = !0, this.logger.debug("zb.sh.fsl send fetch request");
  4802. this.socketCenter.registerRouter("stream_info", this.handleFetchStreamListRsp), this.socketCenter.sendMessage("stream_info", {reserve: 0}), this.logger.debug("zb.sh.fsl call success")
  4803. }
  4804. }, e.prototype.makeCallbackStreamList = function (e) {
  4805. var t = [];
  4806. if (e && e.length > 0) for (var r = 0; r < e.length; r++) {
  4807. var i = {
  4808. anchor_id_name: e[r].anchor_id_name,
  4809. stream_gid: e[r].stream_gid,
  4810. anchor_nick_name: e[r].anchor_nick_name,
  4811. extra_info: e[r].extra_info,
  4812. stream_id: e[r].stream_id,
  4813. urls_flv: "",
  4814. urls_rtmp: "",
  4815. urls_hls: "",
  4816. urls_https_flv: "",
  4817. urls_https_hls: ""
  4818. };
  4819. this.setCDNInfo(i, e[r]), t.push(i)
  4820. }
  4821. return t
  4822. }, e.prototype.updateMixStream = function (e, t, r) {
  4823. var n = this;
  4824. if (this.logger.info("zb.sh.ums call"), null == e.outputStreamId && null == e.outputUrl) return this.logger.error("zb.sh.ums no mix stream info"), !1;
  4825. if (0 == e.streamList.length) return this.logger.error("zb.sh.ums no input stream"), !1;
  4826. var o = {
  4827. id_name: this.stateCenter.idName,
  4828. live_channel: this.stateCenter.roomid,
  4829. appid: this.stateCenter.appid,
  4830. version: i.PROTO_VERSION
  4831. };
  4832. "string" == typeof e.userData && e.userData.length <= 1e4 && (o.UserData = e.userData);
  4833. for (var a = [], c = 0; c < e.streamList.length; c++) {
  4834. var l = e.streamList[c], d = l.streamId;
  4835. this.stateCenter.testEnvironment && (d = "zegotest-" + this.stateCenter.appid + "-" + l.streamId), a.push({
  4836. stream_id: d,
  4837. rect: {layer: c, top: l.top, left: l.left, bottom: l.bottom, right: l.right}
  4838. })
  4839. }
  4840. o.MixInput = a;
  4841. var h = {};
  4842. if (null != e.outputStreamId ? this.stateCenter.testEnvironment ? h.stream_id = "zegotest-" + this.stateCenter.appid + "-" + e.outputStreamId : h.stream_id = e.outputStreamId : null != e.outputUrl && (h.mixurl = e.outputUrl), !e.outputBitrate) return this.logger.error("zb.sh.ums no bitrate param"), !1;
  4843. if (h.bitrate = e.outputBitrate, !e.outputFps) return this.logger.error("zb.sh.ums no fps param"), !1;
  4844. if (h.fps = e.outputFps, !e.outputWidth) return this.logger.error("zb.sh.ums no width param"), !1;
  4845. if (h.width = e.outputWidth, !e.outputHeight) return this.logger.error("zb.sh.ums no height param"), !1;
  4846. if (h.height = e.outputHeight, e.outputAudioConfig && (h.audio_enc_id = e.outputAudioConfig), e.outputAudioBitrate && (h.audio_bitrate = e.outputAudioBitrate), e.outputAudioChannels && (h.audio_channel_cnt = e.outputAudioChannels), e.outputBgColor) {
  4847. if ("string" != typeof e.outputBgColor) return this.logger.error("zb.sh.ums param outputBgImage error"), !1;
  4848. o.output_bg_color = e.outputBgColor
  4849. }
  4850. if (e.outputBgImage) {
  4851. if ("string" != typeof e.outputBgImage || !e.outputBgImage.startsWith("preset-id://")) return this.logger.error("zb.sh.ums param outputBgImage error"), !1;
  4852. o.output_bg_image = e.outputBgImage
  4853. }
  4854. this.stateCenter.testEnvironment ? h.testenv = 1 : h.testenv = 0, o.MixOutput = [h];
  4855. var u = {channel: "zeus", cmd: "start_mix", req_body: JSON.stringify(o)};
  4856. return this.logger.debug("zb.sh.ums send command"), this.socketCenter.sendMessage("biz_channel", u, function (o, a, c) {
  4857. n.logger.debug("zb.sh.ums receive message");
  4858. var l = "zegotest-" + n.stateCenter.appid + "-";
  4859. if (0 != c.length) {
  4860. for (var d = JSON.parse(c), h = [], u = e.outputStreamId, p = 0; p < d.play.length; p++) {
  4861. var g = {rtmpUrls: null, hlsUrls: null, flvUrls: null};
  4862. n.stateCenter.testEnvironment && u && u.startsWith(l) && (u = u.slice(l.length)), d.play[p].rtmp_url && d.play[p].rtmp_url.length > 0 && (g.rtmpUrls = [d.play[p].rtmp_url]), d.play[p].hls_url && d.play[p].hls_url.length > 0 && (g.hlsUrls = [d.play[p].hls_url]), d.play[p].hdl_url && d.play[p].hdl_url.length > 0 && (g.flvUrls = [d.play[p].hdl_url]), h.push(g)
  4863. }
  4864. t && t(u, h)
  4865. } else r && r(s.ClientUtil.getServerError(i.MIXSTREAM_ERROR_CODE + 1))
  4866. }, function (e, t, o) {
  4867. if ("number" == typeof e) {
  4868. n.logger.debug("zb.sh.ums error: " + e);
  4869. var a = [];
  4870. if (1000000150 == e && 0 != o.length) for (var c = JSON.parse(o), l = "zegotest-" + n.stateCenter.appid + "-", d = 0; d < c.non_exist_streams.length; d++) {
  4871. var h = c.non_exist_streams[d];
  4872. n.stateCenter.testEnvironment && h.startsWith(l) ? a.push(h.slice(l.length)) : a.push(h)
  4873. }
  4874. r && r(s.ClientUtil.getServerError(i.MIXSTREAM_ERROR_CODE + e), a)
  4875. } else n.logger.debug("zb.sh.ums error code " + e.code), r && r(e)
  4876. }), !0
  4877. }, e.prototype.stopMixStream = function (e, t, r) {
  4878. if (this.logger.info("zb.sh.sms call"), null == e.outputStreamId && null == e.outputUrl) return this.logger.error("zb.sh.sms no mix stream info"), !1;
  4879. var n = {
  4880. id_name: this.stateCenter.idName,
  4881. live_channel: this.stateCenter.roomid,
  4882. appid: this.stateCenter.appid,
  4883. version: i.PROTO_VERSION
  4884. };
  4885. null != e.outputStreamId ? this.stateCenter.testEnvironment ? n.stream_id = "zegotest-" + this.stateCenter.appid + "-" + e.outputStreamId : n.stream_id = e.outputStreamId : null != e.outputUrl && (n.mixurl = e.outputUrl);
  4886. var o = {channel: "zeus", cmd: "stop_mix", req_body: JSON.stringify(n)};
  4887. return this.socketCenter.sendMessage("biz_channel", o, function (e, r) {
  4888. t && t()
  4889. }, function (e, t) {
  4890. "number" == typeof e ? r && r(s.ClientUtil.getServerError(i.MIXSTREAM_ERROR_CODE + e)) : r && r(e)
  4891. }), !0
  4892. }, e.prototype.updateStreamExtraInfo = function (e, t) {
  4893. return this.logger.info("zb.sh.usei call"), e ? "string" == typeof t && (this.stateCenter.publishStreamList[e] && (this.stateCenter.publishStreamList[e].extra_info = t, this.stateCenter.publishStreamList[e].state >= i.ENUM_PUBLISH_STREAM_STATE.update_info && this.updateStreamInfo(e, i.ENUM_STREAM_SUB_CMD.liveUpdate, t)), !0) : (this.logger.error("zb.sh.usei param error"), !1)
  4894. }, e
  4895. }();
  4896. t.StreamHandler = n
  4897. }, function (e, t, r) {
  4898. "use strict";
  4899. Object.defineProperty(t, "__esModule", {value: !0});
  4900. var i = r(0), s = r(1), n = function () {
  4901. function e(e, t, r) {
  4902. this.logger = e, this.socketCenter = r, this.stateCenter = t
  4903. }
  4904. return e.prototype.resetHeartbeat = function () {
  4905. this.logger.debug("zb.hb.rht call"), clearTimeout(this.stateCenter.heartbeatTimer), this.stateCenter.heartbeatTimer = null, this.stateCenter.tryHeartbeatCount = 0, this.logger.debug("zb.hb.rht call success")
  4906. }, e.prototype.hbLogout = function (e) {
  4907. }, e.prototype.start = function (e) {
  4908. var t = this;
  4909. if (this.logger.debug("zb.hb.sht call"), this.stateCenter.isLogin()) {
  4910. if (++this.stateCenter.tryHeartbeatCount > 3) return this.logger.error("zb.hb.sht come to try limit"), void this.hbLogout(i.sdkErrorList.HEARTBEAT_TIMEOUT);
  4911. this.logger.debug("zb.hb.sht send packet");
  4912. this.socketCenter.registerRouter("hb", function (e) {
  4913. t.handleHeartbeatRsp(e)
  4914. }), this.socketCenter.sendMessage("hb", {reserve: 0}), this.logger.debug("zb.hb.sht call success"), this.stateCenter.heartbeatInterval = e, this.stateCenter.heartbeatTimer = setTimeout(function () {
  4915. t.start(t.stateCenter.heartbeatInterval)
  4916. }, this.stateCenter.heartbeatInterval)
  4917. } else this.logger.error("zb.hb.sht state error")
  4918. }, e.prototype.handleHeartbeatRsp = function (e) {
  4919. if (this.logger.debug("zb.hb.hhbr call"), 0 !== e.body.err_code) return this.logger.error("zb.hb.hhbr call disconnect, server error=", e.body.err_code), void this.hbLogout(s.ClientUtil.getServerError(e.body.err_code));
  4920. for (var t in this.stateCenter.tryHeartbeatCount = 0, this.stateCenter.heartbeatInterval = e.body.hearbeat_interval, this.stateCenter.heartbeatInterval < i.MINIUM_HEARTBEAT_INTERVAL && (this.stateCenter.heartbeatInterval = i.MINIUM_HEARTBEAT_INTERVAL), e.body.bigim_time_window && "number" == typeof e.body.bigim_time_window && (this.stateCenter.bigimTimeWindow = e.body.bigim_time_window), e.body.dati_time_window && "number" == typeof e.body.dati_time_window && (this.stateCenter.datiTimeWindow = e.body.dati_time_window), this.ReliableMessageHandler(e), this.fetchStreamList(e), e.body.server_user_seq !== this.stateCenter.userSeq && this.stateCenter.userStateUpdate && (this.logger.info("zb.hb.hhbr call update user " + e.body.server_user_seq, this.stateCenter.userSeq), this.fetchUserList()), this.stateCenter.publishStreamList) this.stateCenter.publishStreamList[t].state == i.ENUM_PUBLISH_STREAM_STATE.update_info && (this.logger.info("zb.hb.hhbr try to update stream info"), this.updateStreamInfo(t, i.ENUM_STREAM_SUB_CMD.liveBegin, this.stateCenter.publishStreamList[t].extra_info));
  4921. null != e.body.online_count && 0 != e.body.online_count && this.onUpdateOnlineCount(this.stateCenter.roomid, e.body.online_count), this.logger.debug("zb.hb.hhbr call success")
  4922. }, e.prototype.ReliableMessageHandler = function (e) {
  4923. var t = this;
  4924. if (e.body.trans_seqs) for (var r = 0; r < e.body.trans_seqs.length; r++) {
  4925. var i = e.body.trans_seqs[r].trans_channel, s = e.body.trans_seqs[r].trans_seq_array;
  4926. (s = s.filter(function (e) {
  4927. var r = e.trans_type, i = e.trans_seq;
  4928. return !t.stateCenter.transSeqMap[r] || t.stateCenter.transSeqMap[r].seq !== i
  4929. })).length > 0 && this.fetchReliableMessage(i, s)
  4930. }
  4931. }, e.prototype.fetchReliableMessage = function (e, t) {
  4932. var r = this;
  4933. this.logger.debug("zb.hb.frm call");
  4934. var i = {trans_channel: e, fetch_array: t};
  4935. this.socketCenter.registerRouter("trans_fetch", function (e) {
  4936. r.handleFetchTransRsp(e)
  4937. }), this.socketCenter.sendMessage("trans_fetch", i), this.logger.debug("zb.hb.frm call success")
  4938. }, e.prototype.handleFetchTransRsp = function (e) {
  4939. var t = this;
  4940. this.stateCenter.isLogin() ? 0 == e.body.err_code ? e.body.trans_fetch_results.forEach(function (r) {
  4941. var i = r.trans_type, s = r.trans_seq;
  4942. t.stateCenter.transSeqMap[i] = {seq: s}, e.body.trans_user_idname != t.stateCenter.idName && t.onRecvReliableMessage(i, s, r.trans_data), t.logger.debug("zb.hb.hftr trans " + i + " seq " + s)
  4943. }) : this.logger.error("zb.hb.hftr trans send error " + e.body.err_code) : this.logger.error("zb.hb.hftr not login")
  4944. }, e.prototype.fetchStreamList = function (e) {
  4945. var t = this;
  4946. e.body.stream_seq !== this.stateCenter.streamSeq && (this.logger.debug("zb.hb.fsl current seq " + this.stateCenter.streamSeq + " server Seq " + e.body.stream_seq), this.logger.debug("zb.hb.fsl call"), this.stateCenter.isLogin() ? this.stateCenter.streamQuerying ? this.logger.warn("zb.hb.fsl already doing") : (this.stateCenter.streamQuerying = !0, this.logger.debug("zb.hb.fsl send fetch request"), this.socketCenter.registerRouter("stream_info", function (e) {
  4947. t.handleFetchStreamListRsp(e)
  4948. }), this.socketCenter.sendMessage("stream_info", {reserve: 0}), this.logger.debug("zb.hb.fsl call success")) : this.logger.error("zb.hb.fsl state error"))
  4949. }, e.prototype.handleFetchStreamListRsp = function (e) {
  4950. }, e.prototype.fetchUserList = function () {
  4951. }, e.prototype.updateStreamInfo = function (e, t, r, i) {
  4952. void 0 === r && (r = "")
  4953. }, e.prototype.onUpdateOnlineCount = function (e, t) {
  4954. }, e.prototype.onRecvReliableMessage = function (e, t, r) {
  4955. }, e.prototype.resetCheckMessage = function () {
  4956. this.logger.debug("zb.hb.rcm call"), clearTimeout(this.stateCenter.sendDataCheckTimer), this.stateCenter.sendDataCheckTimer = null, this.checkSendMessageList(this.stateCenter.sendDataList), this.checkSendMessageList(this.stateCenter.sendCommandList), this.stateCenter.sendDataMap = {}, this.stateCenter.sendCommandMap = {}, this.logger.debug("zb.hb.rcm call success")
  4957. }, e.prototype.checkSendMessageList = function (e) {
  4958. for (var t = e.getFirst(); null != t;) e.remove(t), t._data.error && (t._data.data.body.custom_msg ? t._data.error(i.sdkErrorList.SEND_MSG_TIMEOUT, t._data.data.header.seq, t._data.data.body.custom_msg) : t._data.error(i.sdkErrorList.SEND_MSG_TIMEOUT, t._data.data.header.seq)), t = e.getFirst()
  4959. }, e.prototype.checkMessageListTimeout = function (e, t) {
  4960. for (var r = e.getFirst(), s = Date.parse(new Date + ""), n = 0, o = 0, a = 0; !(null == r || r._data.time + this.stateCenter.sendDataTimeout > s || (delete t[r._data.data.header.seq], e.remove(r), ++o, null == r._data.error || this.stateCenter.sendDataDropTimeout > 0 && r._data.time + this.stateCenter.sendDataDropTimeout < s ? ++a : r._data.data.body.custom_msg ? r._data.error(i.sdkErrorList.SEND_MSG_TIMEOUT, r._data.data.header.seq, r._data.data.body.custom_msg) : r._data.error(i.sdkErrorList.SEND_MSG_TIMEOUT, r._data.data.header.seq), ++n >= this.stateCenter.sendDataCheckOnceCount));) r = e.getFirst();
  4961. 0 == o && 0 == a || this.logger.debug("zb.hb.cmt call success, stat: timeout=", o, "drop=", a)
  4962. }, e.prototype.startCheckMessageTimeout = function () {
  4963. var e = this;
  4964. this.stateCenter.isLogin() ? (this.checkMessageListTimeout(this.stateCenter.sendDataList, this.stateCenter.sendDataMap), this.checkMessageListTimeout(this.stateCenter.sendCommandList, this.stateCenter.sendCommandMap), this.stateCenter.sendDataCheckTimer = setTimeout(function () {
  4965. e.startCheckMessageTimeout()
  4966. }, this.stateCenter.sendDataCheckInterval)) : this.logger.error("zb.hb.scmt state error")
  4967. }, e
  4968. }();
  4969. t.HeartBeatHandler = n
  4970. }, function (e, t, r) {
  4971. "use strict";
  4972. Object.defineProperty(t, "__esModule", {value: !0});
  4973. var i = r(0), s = r(1), n = function () {
  4974. function e(e, t, r) {
  4975. this.logger = e, this.socketCenter = r, this.stateCenter = t
  4976. }
  4977. return e.prototype.sendCustomCommand = function (e, t, r, i) {
  4978. var n = this;
  4979. if (this.logger.debug("zb.mh.scc call"), !this.stateCenter.isLogin()) return this.logger.error("zb.mh.scc state error"), !1;
  4980. if (!e || 0 == e.length) return this.logger.error("zb.mh.scc dstMembers error"), !1;
  4981. var o = {
  4982. from_userid: this.stateCenter.idName,
  4983. from_username: this.stateCenter.nickName,
  4984. request_id: this.stateCenter.getRequestId(),
  4985. custom_content: t || "",
  4986. room_id: this.stateCenter.roomid
  4987. }, a = {dest_id_name: e, custom_msg: JSON.stringify(o)};
  4988. return s.ClientUtil.checkCustomCommandParam(a) ? (this.socketCenter.registerRouter("custommsg", function (e) {
  4989. n.handleSendCustomMsgRsp(e)
  4990. }), this.socketCenter.sendCustomMessage("custommsg", a, r, i), this.logger.info("zb.mh.scc call success"), !0) : (this.logger.info("zb.mh.scc param error"), !1)
  4991. }, e.prototype.handleSendCustomMsgRsp = function (e) {
  4992. this.logger.debug("zb.mh.hscmrcall");
  4993. var t, r = this.stateCenter.sendDataMap[e.header.seq];
  4994. null != r ? ("custommsg" != (t = r._data).data.header.cmd ? this.logger.error("zb.mh.hscmrcmd wrong" + t.data.header.cmd) : 0 === e.body.err_code ? null != t.success && t.success(e.header.seq, t.data.body.custom_msg) : null != t.error && t.error(s.ClientUtil.getServerError(e.body.err_code), e.header.seq, t.data.body.custom_msg), delete this.stateCenter.sendDataMap[e.header.seq], this.stateCenter.sendDataList.remove(r)) : this.logger.error("zb.mh.hscmrno found seq=" + e.header.seq), this.logger.debug("zb.mh.hscmr call success")
  4995. }, e.prototype.handlePushCustomMsg = function (e) {
  4996. var t = JSON.parse(e.body.custommsg);
  4997. this.logger.debug("zb.mh.hpcm submsg=", t), this.onRecvCustomCommand(t.from_userid, t.from_username, t.custom_content)
  4998. }, e.prototype.onRecvCustomCommand = function (e, t, r) {
  4999. }, e.prototype.sendRoomMsg = function (e, t, r, s, n) {
  5000. var o = this;
  5001. if (this.logger.debug("zb.mh.srm call"), this.stateCenter.isLogin()) {
  5002. var a = Date.parse(new Date + "");
  5003. if (this.stateCenter.sendRoomMsgTime > 0 && this.stateCenter.sendRoomMsgTime + this.stateCenter.SendRoomMsgInterval > a) return this.logger.info("zb.mh.srm freq error"), void (n && n(i.sdkErrorList.FREQ_LIMITED, 0, e, t, r));
  5004. this.stateCenter.sendRoomMsgTime = a, this.logger.debug("zb.mh.srm send fetch request");
  5005. var c = {msg_category: e, msg_type: t, msg_content: r};
  5006. this.socketCenter.registerRouter("im_chat", function (e) {
  5007. o.handleSendRoomMsgRsp(e)
  5008. }), this.socketCenter.sendCustomMessage("im_chat", c, s, n), this.logger.info("zb.mh.srm call success")
  5009. } else this.logger.error("zb.mh.srm state error")
  5010. }, e.prototype.handleSendRoomMsgRsp = function (e) {
  5011. this.logger.debug("zb.mh.hsrmr call");
  5012. var t, r = this.stateCenter.sendDataMap[e.header.seq];
  5013. null != r ? ("im_chat" != (t = r._data).data.header.cmd ? this.logger.error("zb.mh.hsrmr cmd wrong" + t.data.header.cmd) : 0 === e.body.err_code ? t.success && t.success(e.header.seq, e.body.msg_id, t.data.body.msg_category, t.data.body.msg_type, t.data.body.msg_content) : t.error && t.error(s.ClientUtil.getServerError(e.body.err_code), e.header.seq, t.data.body.msg_category, t.data.body.msg_type, t.data.body.msg_content), delete this.stateCenter.sendDataMap[e.header.seq], this.stateCenter.sendDataList.remove(r)) : this.logger.error("hzb.mh.hsrmr no found seq=" + e.header.seq), this.logger.info("zb.mh.hsrmr call success")
  5014. }, e.prototype.onRecvRoomMsg = function (e, t, r) {
  5015. }, e.prototype.sendReliableMessage = function (e, t, r, i) {
  5016. this.logger.debug("zb.mh.srirm call"), this.stateCenter.transSeqMap[e] || (this.stateCenter.transSeqMap[e] = {seq: 0});
  5017. var s = {
  5018. trans_type: e,
  5019. trans_data: t,
  5020. trans_local_seq: this.stateCenter.transSeqMap[e].seq,
  5021. trans_channel: "clt"
  5022. };
  5023. this.socketCenter.sendMessage("trans", s, r, i)
  5024. }, e.prototype.sendBigRoomMessage = function (e, t, r, i, s) {
  5025. var n = this;
  5026. this.logger.debug("zb.mh.sbim call");
  5027. var o = this.stateCenter.bigimTimeWindow, a = this.stateCenter.serverTimeOffset,
  5028. c = (new Date).getTime() + a, l = (++this.stateCenter.cmdSeq).toString();
  5029. if (null == i && (i = null), null == s && (s = null), this.stateCenter.bigImCallbackMap[l] = {
  5030. success: i,
  5031. error: s
  5032. }, 0 == o) {
  5033. var d = {msg_category: e, msg_type: t, msg_content: r, bigmsg_client_id: l};
  5034. this.logger.debug("zb.mh.sbim no time window"), this.sendBigRoomMessageInternal([d], function (e) {
  5035. n.handleBigImMsgRsp(e)
  5036. }, s)
  5037. } else {
  5038. var h = Math.floor(c / o);
  5039. if (this.logger.debug("currentIndex " + h + " lastTimeIndex " + this.stateCenter.bigImLastTimeIndex), this.stateCenter.bigImLastTimeIndex < h && 0 == this.stateCenter.bigImMessageList.length) {
  5040. this.stateCenter.bigImLastTimeIndex = h;
  5041. var u = {msg_category: e, msg_type: t, msg_content: r, bigmsg_client_id: l};
  5042. this.sendBigRoomMessageInternal([u], function (e) {
  5043. n.handleBigImMsgRsp(e)
  5044. }, s)
  5045. } else this.stateCenter.bigImMessageList.push({
  5046. msg_category: e,
  5047. msg_type: t,
  5048. msg_content: r,
  5049. bigmsg_client_id: l
  5050. }), 1 == this.stateCenter.bigImMessageList.length && this.setBigImTimer(a, o)
  5051. }
  5052. }, e.prototype.handlePushMergeMsg = function (e) {
  5053. if (this.stateCenter.isLogin()) {
  5054. for (var t = 0; t < e.body.messages.length; t++) 14001 === e.body.messages[t].sub_cmd && this.handlePushBigRooMsg(e.body.messages[t].msg_body);
  5055. this.logger.debug("zb.mh.hpmm call success")
  5056. } else this.logger.error("zb.mh.hpmmnot login")
  5057. }, e.prototype.handlePushBigRooMsg = function (e) {
  5058. var t;
  5059. try {
  5060. t = JSON.parse(e)
  5061. } catch (e) {
  5062. return void this.logger.warn("zb.mh.hpbrm parse json error")
  5063. }
  5064. if (t) {
  5065. for (var r = t.room_id, i = [], s = 0; s < t.msg_data.length; s++) {
  5066. var n = t.msg_data[s];
  5067. n.id_name != this.stateCenter.idName ? i.push({
  5068. idName: n.id_name,
  5069. nickName: n.nick_name,
  5070. messageId: n.bigmsg_id,
  5071. category: n.msg_category,
  5072. type: n.msg_type,
  5073. content: n.msg_content,
  5074. time: n.send_time
  5075. }) : this.logger.debug("zb.mh.hpbrm self message")
  5076. }
  5077. 0 == i.length ? this.logger.debug("zb.mh.hpbrm no other pushData except self") : this.onRecvBigRoomMessage(i, r), this.logger.debug("zb.mh.hpbrm call success")
  5078. } else this.logger.warn("zb.mh.hpbrm cann't find message body")
  5079. }, e.prototype.onRecvBigRoomMessage = function (e, t) {
  5080. }, e.prototype.sendBigRoomMessageInternal = function (e, t, r) {
  5081. this.logger.debug("zb.mh.sbim call");
  5082. var i = {msgs: e};
  5083. this.socketCenter.sendMessage("bigim_chat", i, t, r)
  5084. }, e.prototype.handleBigImMsgRsp = function (e) {
  5085. if (this.stateCenter.isLogin()) {
  5086. this.stateCenter.bigimTimeWindow != e.body.bigim_time_window && (this.stateCenter.bigimTimeWindow = e.body.bigim_time_window);
  5087. for (var t = 0; t < e.body.msgs.length; t++) {
  5088. var r = e.body.msgs[t].bigmsg_client_id, i = e.body.msgs[t].bigmsg_id;
  5089. if (this.stateCenter.bigImCallbackMap[r]) {
  5090. var s = this.stateCenter.bigImCallbackMap[r].success;
  5091. null != s && s(e.header.seq, i), delete this.stateCenter.bigImCallbackMap[r]
  5092. }
  5093. }
  5094. } else this.logger.info("zb.mh.hbmr not login")
  5095. }, e.prototype.setBigImTimer = function (e, t) {
  5096. var r = this, i = t - ((new Date).getTime() + e) % t, n = s.ClientUtil.generateRandumNumber(t) + i;
  5097. this.logger.info("zb.mh.sbt setTimer " + n), this.stateCenter.bigImTimer = setTimeout(function () {
  5098. r.onBigImTimer()
  5099. }, n)
  5100. }, e.prototype.onBigImTimer = function () {
  5101. var e = this, t = (new Date).getTime() + this.stateCenter.serverTimeOffset;
  5102. this.stateCenter.bigImLastTimeIndex = Math.floor(t / this.stateCenter.bigimTimeWindow);
  5103. for (var r = [], i = [], s = 0; s < this.stateCenter.bigImMessageList.length && !(s >= 20); s++) {
  5104. var n = this.stateCenter.bigImMessageList[s];
  5105. r.push({
  5106. msg_category: n.msg_category,
  5107. msg_type: n.msg_type,
  5108. msg_content: n.msg_content,
  5109. bigmsg_client_id: n.bigmsg_client_id
  5110. }), i.push(n.bigmsg_client_id)
  5111. }
  5112. this.stateCenter.bigImMessageList.length > 20 ? this.stateCenter.bigImMessageList.splice(0, 20) : this.stateCenter.bigImMessageList = [], this.sendBigRoomMessageInternal(r, function (t) {
  5113. e.handleBigImMsgRsp(t)
  5114. }, function (t, r) {
  5115. for (var s = 0; s < i.length; s++) {
  5116. var n = i[s], o = e.stateCenter.bigImCallbackMap[n];
  5117. o && (null != o.error && o.error(t, r), delete e.stateCenter.bigImCallbackMap[n])
  5118. }
  5119. }), clearTimeout(this.stateCenter.bigImTimer), this.stateCenter.bigImTimer = null, this.stateCenter.bigImMessageList.length > 0 && this.setBigImTimer(this.stateCenter.serverTimeOffset, this.stateCenter.bigimTimeWindow)
  5120. }, e.prototype.sendRelayMessage = function (e, t, r, i) {
  5121. this.logger.debug("zb.mh.srm call");
  5122. var s = this.stateCenter.datiTimeWindow, n = this.stateCenter.serverTimeOffset;
  5123. s > 0 ? (this.stateCenter.realyMessageList.push({
  5124. type: e,
  5125. data: t,
  5126. success: r,
  5127. error: i
  5128. }), 1 == this.stateCenter.realyMessageList.length && this.setRelayTimer(n, s)) : this.sendRelayMessageInternal(e, t, r, i)
  5129. }, e.prototype.sendRelayMessageInternal = function (e, t, r, i) {
  5130. this.logger.debug("zb.mh.srmi call");
  5131. var s = {relay_type: e, relay_data: t};
  5132. this.socketCenter.sendMessage("relay", s, r, i)
  5133. }, e.prototype.setRelayTimer = function (e, t) {
  5134. var r = this, i = 2 * t - ((new Date).getTime() + e) % t, n = s.ClientUtil.generateRandumNumber(i);
  5135. this.logger.info("zb.mh.srt setTimer " + n), this.stateCenter.relayTimer = setTimeout(function () {
  5136. r.onRelayTimer()
  5137. }, n)
  5138. }, e.prototype.onRelayTimer = function () {
  5139. if (0 != this.stateCenter.realyMessageList.length) {
  5140. var e = this.stateCenter.realyMessageList[0];
  5141. this.sendRelayMessageInternal(e.type, e.data, e.success, e.error), clearTimeout(this.stateCenter.relayTimer), this.stateCenter.relayTimer = null, this.stateCenter.realyMessageList.splice(0, 1), this.stateCenter.realyMessageList.length > 0 && this.setRelayTimer(this.stateCenter.serverTimeOffset, this.stateCenter.datiTimeWindow)
  5142. } else this.logger.info("zb.mh.ort no relay data")
  5143. }, e.prototype.handlePushTransMsg = function (e) {
  5144. if (this.stateCenter.isLogin()) {
  5145. var t = e.body.trans_type, r = e.body.trans_seq;
  5146. this.stateCenter.transSeqMap[t] ? this.stateCenter.transSeqMap[t].seq = r : this.stateCenter.transSeqMap[t] = {seq: r}, e.body.trans_user_idname != this.stateCenter.idName ? this.onRecvReliableMessage(t, r, e.body.trans_data) : this.logger.debug("zb.mh.hptr receive self trans message"), this.logger.info("zb.mh.hptr trans " + t + " seq " + r)
  5147. } else this.logger.error("zb.mh.hptr not login")
  5148. }, e.prototype.onRecvReliableMessage = function (e, t, r) {
  5149. }, e
  5150. }();
  5151. t.MessageHandler = n
  5152. }, function (e, t, r) {
  5153. "use strict";
  5154. Object.defineProperty(t, "__esModule", {value: !0});
  5155. var i = r(0), s = function () {
  5156. function e(e, t, r) {
  5157. this.logger = e, this.socketCenter = r, this.stateCenter = t
  5158. }
  5159. return e.prototype.requestJoinLive = function (e, t, r, s) {
  5160. this.logger.debug("zb.lh.rjl call");
  5161. var n = this.stateCenter.getRequestId(), o = this.stateCenter.getSignalCmdContent(n, e);
  5162. return null != s && (this.stateCenter.joinLiveCallbackMap[n] = s, this.sendSignalCmd(i.ENUM_SIGNAL_SUB_CMD.joinLiveRequest, o, e, t, r), !0)
  5163. }, e.prototype.inviteJoinLive = function (e, t, r, s) {
  5164. this.logger.debug("zb.lh.ijl call");
  5165. var n = this.stateCenter.getRequestId(), o = this.stateCenter.getSignalCmdContent(n, e);
  5166. return null != s && (this.stateCenter.joinLiveCallbackMap[n] = s, this.sendSignalCmd(i.ENUM_SIGNAL_SUB_CMD.joinLiveInvite, o, e, t, r), !0)
  5167. }, e.prototype.endJoinLive = function (e, t, r) {
  5168. this.logger.debug("zb.lh.ejl call");
  5169. var s = this.stateCenter.getRequestId(), n = this.stateCenter.getSignalCmdContent(s, e);
  5170. return this.sendSignalCmd(i.ENUM_SIGNAL_SUB_CMD.joinLiveStop, n, e, t, r), !0
  5171. }, e.prototype.respondJoinLive = function (e, t, r, s) {
  5172. this.logger.debug("zb.lh.rpjl call");
  5173. var n = this.stateCenter.joinLiveRequestMap[e];
  5174. if (!n) return this.logger.info("zb.lh.rpjl no dest id name"), !1;
  5175. var o = 0;
  5176. !0 === t && (o = 1);
  5177. var a = this.stateCenter.getSignalCmdContent(e, n, o);
  5178. return this.sendSignalCmd(i.ENUM_SIGNAL_SUB_CMD.joinLiveResult, a, n, r, s), delete this.stateCenter.joinLiveRequestMap[e], !0
  5179. }, e.prototype.sendSignalCmd = function (e, t, r, i, s) {
  5180. if (this.logger.debug("zb.lh.ssc call"), this.stateCenter.isLogin()) {
  5181. this.logger.debug("zb.lh.ssc send signal cmd " + e);
  5182. var n = {sub_cmd: e, signal_msg: t, dest_id_name: [r]};
  5183. this.socketCenter.sendMessage("signal", n, i, s), this.logger.info("zb.lh.ssc call success")
  5184. } else this.logger.error("zb.lh.ssc state error")
  5185. }, e.prototype.handlePushSignalMsg = function (e) {
  5186. if (this.stateCenter.isLogin()) {
  5187. var t = JSON.parse(e.body.signal_msg);
  5188. switch (this.logger.debug("zb.lh.hpcm hpsm= ", t), e.body.sub_cmd) {
  5189. case i.ENUM_PUSH_SIGNAL_SUB_CMD.pushJoinLiveRequest:
  5190. this.handlePushJoinLiveRequestMsg(t);
  5191. break;
  5192. case i.ENUM_PUSH_SIGNAL_SUB_CMD.pushJoinLiveResult:
  5193. this.handlePushJoinLiveResultMsg(t);
  5194. break;
  5195. case i.ENUM_PUSH_SIGNAL_SUB_CMD.pushJoinLiveInvite:
  5196. this.handlePushJoinLiveInviteMsg(t);
  5197. break;
  5198. case i.ENUM_PUSH_SIGNAL_SUB_CMD.pushJoinLiveStop:
  5199. this.handlePushJoinLiveStopMsg(t)
  5200. }
  5201. this.logger.debug("zb.lh.hpsm call end")
  5202. } else this.logger.warn("zb.lh.hpsm not login")
  5203. }, e.prototype.handlePushJoinLiveRequestMsg = function (e) {
  5204. var t = e.request_id;
  5205. if ("string" == typeof t) {
  5206. var r = e.from_userid;
  5207. "string" == typeof r ? (this.stateCenter.joinLiveRequestMap[t] = r, this.logger.info("zb.lh.hpjlrm onRecvJoinLiveRequest " + r), this.onRecvJoinLiveRequest(t, e.from_userid, e.from_username, e.room_id)) : this.logger.error("zb.lh.hpjlrm no from user")
  5208. } else this.logger.error("zb.lh.hpjlrm no requestId")
  5209. }, e.prototype.onRecvJoinLiveRequest = function (e, t, r, i) {
  5210. }, e.prototype.handlePushJoinLiveInviteMsg = function (e) {
  5211. var t = e.request_id;
  5212. if ("string" == typeof t) {
  5213. var r = e.from_userid;
  5214. "string" == typeof r ? (this.stateCenter.joinLiveRequestMap[t] = r, this.logger.info("zb.lh.hpjlim onRecvInviteJoinLiveRequest " + r), this.onRecvInviteJoinLiveRequest(t, e.from_userid, e.from_username, e.room_id)) : this.logger.error("zb.lh.hpjlim no from user")
  5215. } else this.logger.error("zb.lh.hpjlim no requestId")
  5216. }, e.prototype.onRecvInviteJoinLiveRequest = function (e, t, r, i) {
  5217. }, e.prototype.handlePushJoinLiveResultMsg = function (e) {
  5218. var t = e.request_id;
  5219. if ("string" == typeof t) {
  5220. var r = e.result;
  5221. if (null != r) {
  5222. var i = 1 == r;
  5223. if (this.stateCenter.joinLiveCallbackMap[t]) {
  5224. var s = this.stateCenter.joinLiveCallbackMap[t];
  5225. if (!s) return void this.logger.info("hpjlrm.o no callback");
  5226. this.logger.info("zb.lh.hpjlrm joinLiveRequest/invite result " + i), delete this.stateCenter.joinLiveCallbackMap[t], s(i, e.from_userid, e.from_username)
  5227. }
  5228. } else this.logger.info("zb.lh.hpjlrm no result")
  5229. } else this.logger.error("zb.lh.hpjlrm no requestId")
  5230. }, e.prototype.handlePushJoinLiveStopMsg = function (e) {
  5231. var t = e.request_id;
  5232. "string" == typeof t ? (this.logger.info("zb.lh.hpjlsm onRecvEndJoinLiveCommand " + e.from_userid), this.onRecvEndJoinLiveCommand(t, e.from_userid, e.from_username, e.room_id)) : this.logger.error("zb.lh.hpjlsm no requestId")
  5233. }, e.prototype.onRecvEndJoinLiveCommand = function (e, t, r, i) {
  5234. }, e
  5235. }();
  5236. t.LiveHandler = s
  5237. }, function (e, t, r) {
  5238. "use strict";
  5239. Object.defineProperty(t, "__esModule", {value: !0});
  5240. var i = r(0), s = r(2), n = function () {
  5241. function e() {
  5242. this.testEnvironment = !1, this.third_token = "", this.pullLimited = !0, this.configOK = !1, this.roomCreateFlag = 1, this.runState = i.ENUM_RUN_STATE.logout, this.lastRunState = i.ENUM_RUN_STATE.logout, this.callbackList = {}, this.streamList = [], this.publishStreamList = {}, this.userQuerying = !1, this.userTempList = [], this.userSeq = 0, this.anchor_info = {
  5243. anchor_id: "",
  5244. anchor_id_name: "",
  5245. anchor_nick_name: ""
  5246. }, this.sendCommandMap = {}, this.sendCommandList = new i.LinkedList, this.sendDataMap = {}, this.sendDataList = new i.LinkedList, this.joinLiveCallbackMap = {}, this.joinLiveRequestMap = {}, this.streamUrlMap = {}, this.cmdCallback = {}, this.transSeqMap = {}, this.realyMessageList = [], this.relayTimer = null, this.bigImLastTimeIndex = 0, this.bigIMmessageList = [], this.bigImCallbackMap = {}, this.bigImTimer = null, this.serverTimeOffset = 0, this.datiTimeWindow = 0, this.bigimTimeWindow = 0, this.bigImMessageList = [], this.tryLoginCount = 0, this.tryLoginTimer = null, this.heartbeatTimer = null, this.sendDataCheckTimer = null, this.sendDataCheckInterval = 2e3, this.sendDataTimeout = 5e3, this.sendDataDropTimeout = 1e4, this.sendDataCheckOnceCount = 100, this.sendRoomMsgTime = 0, this.SendRoomMsgInterval = 500, this.cmdSeq = 0, this.audioEffectBuffer = {}, this.audioBitRate = 48e3
  5247. }
  5248. return e.prototype.isLogin = function () {
  5249. return this.runState === i.ENUM_RUN_STATE.login
  5250. }, e.prototype.getRequestId = function () {
  5251. return this.idName + "-" + s.getSeq()
  5252. }, e.prototype.getSignalCmdContent = function (e, t, r) {
  5253. var i = {
  5254. request_id: e,
  5255. room_id: this.roomid,
  5256. from_userid: this.idName,
  5257. from_username: this.nickName,
  5258. to_userid: t
  5259. };
  5260. return null != r && (i.result = r), JSON.stringify(i)
  5261. }, e
  5262. }();
  5263. t.StateCenter = n
  5264. }, function (e, t, r) {
  5265. "use strict";
  5266. Object.defineProperty(t, "__esModule", {value: !0});
  5267. var i = r(1), s = function () {
  5268. function e(e) {
  5269. var t = e.type, r = e.channels, i = void 0 === r ? 1 : r, s = e.bufferSize, n = void 0 === s ? 0 : s,
  5270. o = e.sampleBit, a = void 0 === o ? 16 : o, c = e.sampleRate, l = void 0 === c ? 44100 : c,
  5271. d = this;
  5272. this.instant = 0, this.slow = 0, this.clip = 0;
  5273. var h = new ("undefined" != typeof webkitAudioContext ? webkitAudioContext : AudioContext);
  5274. this.context = h, this.type = t, this.channels = i, this.bufferSize = n, this.sampleBit = a, this.sampleRate = l, this.script = h.createScriptProcessor(n, i, i);
  5275. (new Date).getTime();
  5276. this.script.addEventListener("audioprocess", function (e) {
  5277. var r, i = e.inputBuffer.getChannelData(0), s = 0, n = 0;
  5278. for (r = 0; r < i.length; ++r) s += i[r] * i[r], Math.abs(i[r]) > .99 && (n += 1);
  5279. if (d.instant = Math.sqrt(s / i.length), d.slow = .95 * d.slow + .05 * d.instant, d.clip = n / i.length, "pcm" === t || "wav" === t) {
  5280. for (var o = [], a = 0; a < d.channels; a++) o.push(e.inputBuffer.getChannelData(a));
  5281. d.recorderBuffer(o)
  5282. }
  5283. }), "pcm" !== t && "wav" !== t || this.initRecorderBuffer(t)
  5284. }
  5285. return e.prototype.connectToSource = function (e, t) {
  5286. console.log("SoundMeter connecting");
  5287. try {
  5288. this.mic = this.context.createMediaStreamSource(e), this.mic.connect(this.script), this.script.connect(this.context.destination), void 0 !== t && t(null)
  5289. } catch (e) {
  5290. console.error(e), void 0 !== t && t(e)
  5291. }
  5292. return this
  5293. }, e.prototype.recorderBuffer = function (e) {
  5294. this.worker.postMessage({command: "record", val: e})
  5295. }, e.prototype.initRecorderBuffer = function (e) {
  5296. var t = this;
  5297. this.worker = i.ClientUtil.inlineWorker(function () {
  5298. var e, t, r, i, s, n, o = [], a = this;
  5299. function c(t) {
  5300. var r, i;
  5301. if (1 == e) r = d(o[0], s, o), 1 != t && (i = l(t, r)); else if (2 == e) {
  5302. var n = d(o[0], s, o), a = d(o[1], s, o);
  5303. 1 != t ? i = h(l(t, n), l(t, a)) : r = h(n, a)
  5304. }
  5305. return 1 != t ? i : r
  5306. }
  5307. function l(e, t) {
  5308. for (var r = new Float32Array(t.length / e), i = 0, s = 0; i < r.length;) r[i] = t[s], s += e, i++;
  5309. return r
  5310. }
  5311. function d(e, t, r) {
  5312. for (var i = new Float32Array(t * e.length), s = 0, n = 0; n < r[0].length; n++) i.set(r[0][n], s), s += r[0][n].length;
  5313. return i
  5314. }
  5315. function h(e, t) {
  5316. for (var r = new Float32Array(e.length + t.length), i = 0; i < e.length + t.length; i += 2) r[i] = e[i / 2 >> 0], r[i + 1] = t[i / 2 >> 0];
  5317. return r
  5318. }
  5319. function u(e, t, r) {
  5320. for (var i = 0; i < r.length; i++) e.setUint8(t + i, r.charCodeAt(i))
  5321. }
  5322. function p(e, t, r) {
  5323. for (var i = 0; i < r.length; i++, t += 2) {
  5324. var s = Math.max(-1, Math.min(1, r[i]));
  5325. e.setInt16(t, s < 0 ? 32768 * s : 32767 * s, !0)
  5326. }
  5327. }
  5328. function g(e, t, r) {
  5329. for (var i = 0; i < r.length; i++, t++) {
  5330. var s = Math.max(-1, Math.min(1, r[i])), n = s < 0 ? 128 * s : 127 * s;
  5331. n += 128, e.setInt8(t, n)
  5332. }
  5333. }
  5334. this.onmessage = function (l) {
  5335. switch (l.data.command) {
  5336. case"init":
  5337. d = l.data.val, e = d.sampleChannel, t = d.sampleBit, r = d.sampleRate, i = d.oldSampleRate, s = d.bufferSize, n = d.type;
  5338. break;
  5339. case"record":
  5340. !function (s) {
  5341. for (var l = 0; l < e; l++) o[l] || (o[l] = []), o[l].push(s[l]);
  5342. var d = Math.round(i / r);
  5343. "pcm" === n ? function (e) {
  5344. var r = function (e, r) {
  5345. var i;
  5346. 8 == r ? i = e.length : 16 == r && (i = e.length, i *= 2);
  5347. var s = new ArrayBuffer(i), n = new DataView(s);
  5348. 8 == r ? g(n, 0, e) : 16 == t && p(n, 0, e);
  5349. return n
  5350. }(c(e), t);
  5351. a.postMessage({command: "exportPcmLive", val: r})
  5352. }(d) : "wav" === n && function (i) {
  5353. var s = function (i, s) {
  5354. var n;
  5355. 8 == s ? n = i.length : 16 == t && (n = i.length, n *= 2);
  5356. var o = new ArrayBuffer(n + 44), a = new DataView(o), c = r, l = t, d = e;
  5357. u(a, 0, "RIFF"), a.setUint32(4, 36 + n, !0), u(a, 8, "WAVE"), u(a, 12, "fmt "), a.setUint32(16, 16, !0), a.setUint16(20, 1, !0), a.setUint16(22, d, !0), a.setUint32(24, c, !0), a.setUint32(28, c * d * (l / 8), !0), a.setUint16(32, d * (l / 8), !0), a.setUint16(34, l, !0), u(a, 36, "data"), a.setUint32(40, n, !0), 8 == t ? g(a, 44, i) : 16 == t && p(a, 44, i);
  5358. return a
  5359. }(c(i), t);
  5360. a.postMessage({command: "exportWav", val: s})
  5361. }(d);
  5362. o = []
  5363. }(l.data.val)
  5364. }
  5365. var d
  5366. }
  5367. }), this.worker.postMessage({
  5368. command: "init",
  5369. val: {
  5370. sampleChannel: this.channels,
  5371. sampleBit: this.sampleBit,
  5372. sampleRate: this.sampleRate,
  5373. oldSampleRate: this.context.sampleRate,
  5374. bufferSize: this.bufferSize,
  5375. type: e
  5376. }
  5377. }), this.worker.onmessage = function (e) {
  5378. switch (e.data.command) {
  5379. case"exportPcmLive":
  5380. t.onReceiveBuffer(e.data.val);
  5381. break;
  5382. case"exportWav":
  5383. t.onReceiveWav(e.data.val)
  5384. }
  5385. }
  5386. }, e.prototype.onReceiveBuffer = function (e) {
  5387. }, e.prototype.onReceiveWav = function (e) {
  5388. }, e.prototype.writeString = function (e, t, r) {
  5389. for (var i = 0; i < r.length; i++) e.setUint8(t + i, r.charCodeAt(i))
  5390. }, e.prototype.writeBuffer = function (e, t, r) {
  5391. for (var i = 0; i < r.byteLength; i++) e.setUint8(t + i, r[i])
  5392. }, e.prototype.concatenation = function (e) {
  5393. for (var t = 0, r = 0; r < e.length; ++r) t += e[r].buffer.byteLength;
  5394. var i = new Uint8Array(t), s = 0;
  5395. for (r = 0; r < e.length; ++r) i.set(new Uint8Array(e[r].buffer), s), s += e[r].buffer.byteLength;
  5396. return i
  5397. }, e.prototype.encodeWave = function (e) {
  5398. var t = this.concatenation(e), r = t.byteLength, i = new ArrayBuffer(r + 44), s = new DataView(i),
  5399. n = this.sampleRate, o = this.sampleBit, a = this.channels;
  5400. return this.writeString(s, 0, "RIFF"), s.setUint32(4, 36 + r, !0), this.writeString(s, 8, "WAVE"), this.writeString(s, 12, "fmt "), s.setUint32(16, 16, !0), s.setUint16(20, 1, !0), s.setUint16(22, a, !0), s.setUint32(24, n, !0), s.setUint32(28, n * a * (o / 8), !0), s.setUint16(32, a * (o / 8), !0), s.setUint16(34, o, !0), this.writeString(s, 36, "data"), s.setUint32(40, r, !0), this.writeBuffer(s, 44, t), s
  5401. }, e.prototype.stop = function () {
  5402. this.mic.disconnect(), this.script.disconnect()
  5403. }, e
  5404. }();
  5405. t.MediaUtil = s
  5406. }])
  5407. });