phone.js 1.4 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["PhoneJs"] = factory();
  8. else
  9. root["PhoneJs"] = factory();
  10. })(typeof self !== 'undefined' ? self : this, function() {
  11. return (function(modules) { // webpackBootstrap
  12. // The module cache
  13. var installedModules = {};
  14. // The require function
  15. function __webpack_require__(moduleId) {
  16. // Check if module is in cache
  17. if(installedModules[moduleId]) {
  18. return installedModules[moduleId].exports;
  19. }
  20. // Create a new module (and put it into the cache)
  21. var module = installedModules[moduleId] = {
  22. i: moduleId,
  23. l: false,
  24. exports: {}
  25. };
  26. // Execute the module function
  27. modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  28. // Flag the module as loaded
  29. module.l = true;
  30. // Return the exports of the module
  31. return module.exports;
  32. }
  33. // expose the modules object (__webpack_modules__)
  34. __webpack_require__.m = modules;
  35. // expose the module cache
  36. __webpack_require__.c = installedModules;
  37. // define getter function for harmony exports
  38. __webpack_require__.d = function(exports, name, getter) {
  39. if(!__webpack_require__.o(exports, name)) {
  40. Object.defineProperty(exports, name, {
  41. configurable: false,
  42. enumerable: true,
  43. get: getter
  44. });
  45. }
  46. };
  47. // getDefaultExport function for compatibility with non-harmony modules
  48. __webpack_require__.n = function(module) {
  49. var getter = module && module.__esModule ?
  50. function getDefault() { return module['default']; } :
  51. function getModuleExports() { return module; };
  52. __webpack_require__.d(getter, 'a', getter);
  53. return getter;
  54. };
  55. // Object.prototype.hasOwnProperty.call
  56. __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  57. // __webpack_public_path__
  58. __webpack_require__.p = "";
  59. // Load entry module and return exports
  60. return __webpack_require__(__webpack_require__.s = 23);
  61. })
  62. /************************************************************************/
  63. ([
  64. /* 0 */
  65. (function(module, exports, __webpack_require__) {
  66. /* WEBPACK VAR INJECTION */(function(process) {/* eslint-env browser */
  67. /**
  68. * This is the web browser implementation of `debug()`.
  69. */
  70. exports.log = log;
  71. exports.formatArgs = formatArgs;
  72. exports.save = save;
  73. exports.load = load;
  74. exports.useColors = useColors;
  75. exports.storage = localstorage();
  76. /**
  77. * Colors.
  78. */
  79. exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
  80. /**
  81. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  82. * and the Firebug extension (any Firefox version) are known
  83. * to support "%c" CSS customizations.
  84. *
  85. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  86. */
  87. // eslint-disable-next-line complexity
  88. function useColors() {
  89. // NB: In an Electron preload script, document will be defined but not fully
  90. // initialized. Since we know we're in Chrome, we'll just detect this case
  91. // explicitly
  92. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  93. return true;
  94. } // Internet Explorer and Edge do not support colors.
  95. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  96. return false;
  97. } // Is webkit? http://stackoverflow.com/a/16459606/376773
  98. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  99. return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
  100. typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
  101. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  102. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
  103. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
  104. }
  105. /**
  106. * Colorize log arguments if enabled.
  107. *
  108. * @api public
  109. */
  110. function formatArgs(args) {
  111. args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
  112. if (!this.useColors) {
  113. return;
  114. }
  115. const c = 'color: ' + this.color;
  116. args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other
  117. // arguments passed either before or after the %c, so we need to
  118. // figure out the correct index to insert the CSS into
  119. let index = 0;
  120. let lastC = 0;
  121. args[0].replace(/%[a-zA-Z%]/g, match => {
  122. if (match === '%%') {
  123. return;
  124. }
  125. index++;
  126. if (match === '%c') {
  127. // We only are interested in the *last* %c
  128. // (the user may have provided their own)
  129. lastC = index;
  130. }
  131. });
  132. args.splice(lastC, 0, c);
  133. }
  134. /**
  135. * Invokes `console.log()` when available.
  136. * No-op when `console.log` is not a "function".
  137. *
  138. * @api public
  139. */
  140. function log(...args) {
  141. // This hackery is required for IE8/9, where
  142. // the `console.log` function doesn't have 'apply'
  143. return typeof console === 'object' && console.log && console.log(...args);
  144. }
  145. /**
  146. * Save `namespaces`.
  147. *
  148. * @param {String} namespaces
  149. * @api private
  150. */
  151. function save(namespaces) {
  152. try {
  153. if (namespaces) {
  154. exports.storage.setItem('debug', namespaces);
  155. } else {
  156. exports.storage.removeItem('debug');
  157. }
  158. } catch (error) {// Swallow
  159. // XXX (@Qix-) should we be logging these?
  160. }
  161. }
  162. /**
  163. * Load `namespaces`.
  164. *
  165. * @return {String} returns the previously persisted debug modes
  166. * @api private
  167. */
  168. function load() {
  169. let r;
  170. try {
  171. r = exports.storage.getItem('debug');
  172. } catch (error) {} // Swallow
  173. // XXX (@Qix-) should we be logging these?
  174. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  175. if (!r && typeof process !== 'undefined' && 'env' in process) {
  176. r = process.env.DEBUG;
  177. }
  178. return r;
  179. }
  180. /**
  181. * Localstorage attempts to return the localstorage.
  182. *
  183. * This is necessary because safari throws
  184. * when a user disables cookies/localstorage
  185. * and you attempt to access it.
  186. *
  187. * @return {LocalStorage}
  188. * @api private
  189. */
  190. function localstorage() {
  191. try {
  192. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  193. // The Browser also has localStorage in the global context.
  194. return localStorage;
  195. } catch (error) {// Swallow
  196. // XXX (@Qix-) should we be logging these?
  197. }
  198. }
  199. module.exports = __webpack_require__(29)(exports);
  200. const {
  201. formatters
  202. } = module.exports;
  203. /**
  204. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  205. */
  206. formatters.j = function (v) {
  207. try {
  208. return JSON.stringify(v);
  209. } catch (error) {
  210. return '[UnexpectedJSONParseError]: ' + error.message;
  211. }
  212. };
  213. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15)))
  214. }),
  215. /* 1 */
  216. (function(module, exports, __webpack_require__) {
  217. "use strict";
  218. var pkg = __webpack_require__(12);
  219. module.exports = {
  220. USER_AGENT: "".concat(pkg.title, " ").concat(pkg.version),
  221. // SIP scheme.
  222. SIP: 'sip',
  223. SIPS: 'sips',
  224. // End and Failure causes.
  225. causes: {
  226. // Generic error causes.
  227. CONNECTION_ERROR: 'Connection Error',
  228. REQUEST_TIMEOUT: 'Request Timeout',
  229. SIP_FAILURE_CODE: 'SIP Failure Code',
  230. INTERNAL_ERROR: 'Internal Error',
  231. // SIP error causes.
  232. BUSY: 'Busy',
  233. REJECTED: 'Rejected',
  234. REDIRECTED: 'Redirected',
  235. UNAVAILABLE: 'Unavailable',
  236. NOT_FOUND: 'Not Found',
  237. ADDRESS_INCOMPLETE: 'Address Incomplete',
  238. INCOMPATIBLE_SDP: 'Incompatible SDP',
  239. MISSING_SDP: 'Missing SDP',
  240. AUTHENTICATION_ERROR: 'Authentication Error',
  241. // Session error causes.
  242. BYE: 'Terminated',
  243. WEBRTC_ERROR: 'WebRTC Error',
  244. CANCELED: 'Canceled',
  245. NO_ANSWER: 'No Answer',
  246. EXPIRES: 'Expires',
  247. NO_ACK: 'No ACK',
  248. DIALOG_ERROR: 'Dialog Error',
  249. USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access',
  250. BAD_MEDIA_DESCRIPTION: 'Bad Media Description',
  251. RTP_TIMEOUT: 'RTP Timeout'
  252. },
  253. SIP_ERROR_CAUSES: {
  254. REDIRECTED: [300, 301, 302, 305, 380],
  255. BUSY: [486, 600],
  256. REJECTED: [403, 603],
  257. NOT_FOUND: [404, 604],
  258. UNAVAILABLE: [480, 410, 408, 430],
  259. ADDRESS_INCOMPLETE: [484, 424],
  260. INCOMPATIBLE_SDP: [488, 606],
  261. AUTHENTICATION_ERROR: [401, 407]
  262. },
  263. // SIP Methods.
  264. ACK: 'ACK',
  265. BYE: 'BYE',
  266. CANCEL: 'CANCEL',
  267. INFO: 'INFO',
  268. INVITE: 'INVITE',
  269. MESSAGE: 'MESSAGE',
  270. NOTIFY: 'NOTIFY',
  271. OPTIONS: 'OPTIONS',
  272. REGISTER: 'REGISTER',
  273. REFER: 'REFER',
  274. UPDATE: 'UPDATE',
  275. SUBSCRIBE: 'SUBSCRIBE',
  276. /* SIP Response Reasons
  277. * DOC: https://www.iana.org/assignments/sip-parameters
  278. * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7
  279. */
  280. REASON_PHRASE: {
  281. 100: 'Trying',
  282. 180: 'Ringing',
  283. 181: 'Call Is Being Forwarded',
  284. 182: 'Queued',
  285. 183: 'Session Progress',
  286. 199: 'Early Dialog Terminated',
  287. // draft-ietf-sipcore-199
  288. 200: 'OK',
  289. 202: 'Accepted',
  290. // RFC 3265
  291. 204: 'No Notification',
  292. // RFC 5839
  293. 300: 'Multiple Choices',
  294. 301: 'Moved Permanently',
  295. 302: 'Moved Temporarily',
  296. 305: 'Use Proxy',
  297. 380: 'Alternative Service',
  298. 400: 'Bad Request',
  299. 401: 'Unauthorized',
  300. 402: 'Payment Required',
  301. 403: 'Forbidden',
  302. 404: 'Not Found',
  303. 405: 'Method Not Allowed',
  304. 406: 'Not Acceptable',
  305. 407: 'Proxy Authentication Required',
  306. 408: 'Request Timeout',
  307. 410: 'Gone',
  308. 412: 'Conditional Request Failed',
  309. // RFC 3903
  310. 413: 'Request Entity Too Large',
  311. 414: 'Request-URI Too Long',
  312. 415: 'Unsupported Media Type',
  313. 416: 'Unsupported URI Scheme',
  314. 417: 'Unknown Resource-Priority',
  315. // RFC 4412
  316. 420: 'Bad Extension',
  317. 421: 'Extension Required',
  318. 422: 'Session Interval Too Small',
  319. // RFC 4028
  320. 423: 'Interval Too Brief',
  321. 424: 'Bad Location Information',
  322. // RFC 6442
  323. 428: 'Use Identity Header',
  324. // RFC 4474
  325. 429: 'Provide Referrer Identity',
  326. // RFC 3892
  327. 430: 'Flow Failed',
  328. // RFC 5626
  329. 433: 'Anonymity Disallowed',
  330. // RFC 5079
  331. 436: 'Bad Identity-Info',
  332. // RFC 4474
  333. 437: 'Unsupported Certificate',
  334. // RFC 4744
  335. 438: 'Invalid Identity Header',
  336. // RFC 4744
  337. 439: 'First Hop Lacks Outbound Support',
  338. // RFC 5626
  339. 440: 'Max-Breadth Exceeded',
  340. // RFC 5393
  341. 469: 'Bad Info Package',
  342. // draft-ietf-sipcore-info-events
  343. 470: 'Consent Needed',
  344. // RFC 5360
  345. 478: 'Unresolvable Destination',
  346. // Custom code copied from Kamailio.
  347. 480: 'Temporarily Unavailable',
  348. 481: 'Call/Transaction Does Not Exist',
  349. 482: 'Loop Detected',
  350. 483: 'Too Many Hops',
  351. 484: 'Address Incomplete',
  352. 485: 'Ambiguous',
  353. 486: 'Busy Here',
  354. 487: 'Request Terminated',
  355. 488: 'Not Acceptable Here',
  356. 489: 'Bad Event',
  357. // RFC 3265
  358. 491: 'Request Pending',
  359. 493: 'Undecipherable',
  360. 494: 'Security Agreement Required',
  361. // RFC 3329
  362. 500: 'JsSIP Internal Error',
  363. 501: 'Not Implemented',
  364. 502: 'Bad Gateway',
  365. 503: 'Service Unavailable',
  366. 504: 'Server Time-out',
  367. 505: 'Version Not Supported',
  368. 513: 'Message Too Large',
  369. 580: 'Precondition Failure',
  370. // RFC 3312
  371. 600: 'Busy Everywhere',
  372. 603: 'Decline',
  373. 604: 'Does Not Exist Anywhere',
  374. 606: 'Not Acceptable'
  375. },
  376. ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO',
  377. ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay',
  378. MAX_FORWARDS: 69,
  379. SESSION_EXPIRES: 90,
  380. MIN_SESSION_EXPIRES: 60
  381. };
  382. }),
  383. (function(module, exports, __webpack_require__) {
  384. "use strict";
  385. function _typeof(obj) {
  386. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  387. _typeof = function _typeof(obj) {
  388. return typeof obj;
  389. };
  390. } else {
  391. _typeof = function _typeof(obj) {
  392. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  393. };
  394. }
  395. return _typeof(obj);
  396. }
  397. var JsSIP_C = __webpack_require__(1);
  398. var URI = __webpack_require__(8);
  399. var Grammar = __webpack_require__(3);
  400. exports.str_utf8_length = function (string) {
  401. return unescape(encodeURIComponent(string)).length;
  402. }; // Used by 'hasMethods'.
  403. var isFunction = exports.isFunction = function (fn) {
  404. if (fn !== undefined) {
  405. return Object.prototype.toString.call(fn) === '[object Function]' ? true : false;
  406. } else {
  407. return false;
  408. }
  409. };
  410. exports.isString = function (str) {
  411. if (str !== undefined) {
  412. return Object.prototype.toString.call(str) === '[object String]' ? true : false;
  413. } else {
  414. return false;
  415. }
  416. };
  417. exports.isDecimal = function (num) {
  418. return !isNaN(num) && parseFloat(num) === parseInt(num, 10);
  419. };
  420. exports.isEmpty = function (value) {
  421. return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value);
  422. };
  423. exports.hasMethods = function (obj) {
  424. for (var _len = arguments.length, methodNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  425. methodNames[_key - 1] = arguments[_key];
  426. }
  427. for (var _i = 0; _i < methodNames.length; _i++) {
  428. var methodName = methodNames[_i];
  429. if (isFunction(obj[methodName])) {
  430. return false;
  431. }
  432. }
  433. return true;
  434. }; // Used by 'newTag'.
  435. var createRandomToken = exports.createRandomToken = function (size) {
  436. var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32;
  437. var i,
  438. r,
  439. token = '';
  440. for (i = 0; i < size; i++) {
  441. r = Math.random() * base | 0;
  442. token += r.toString(base);
  443. }
  444. return token;
  445. };
  446. exports.newTag = function () {
  447. return createRandomToken(10);
  448. }; // https://stackoverflow.com/users/109538/broofa.
  449. exports.newUUID = function () {
  450. var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  451. var r = Math.random() * 16 | 0,
  452. v = c === 'x' ? r : r & 0x3 | 0x8;
  453. return v.toString(16);
  454. });
  455. return UUID;
  456. };
  457. exports.hostType = function (host) {
  458. if (!host) {
  459. return;
  460. } else {
  461. host = Grammar.parse(host, 'host');
  462. if (host !== -1) {
  463. return host.host_type;
  464. }
  465. }
  466. };
  467. /**
  468. * Hex-escape a SIP URI user.
  469. * Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F).
  470. *
  471. * Used by 'normalizeTarget'.
  472. */
  473. var escapeUser = exports.escapeUser = function (user) {
  474. return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/');
  475. };
  476. /**
  477. * Normalize SIP URI.
  478. * NOTE: It does not allow a SIP URI without username.
  479. * Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'.
  480. * Detects the domain part (if given) and properly hex-escapes the user portion.
  481. * If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators.
  482. */
  483. exports.normalizeTarget = function (target, domain) {
  484. // If no target is given then raise an error.
  485. if (!target) {
  486. return; // If a URI instance is given then return it.
  487. } else if (target instanceof URI) {
  488. return target; // If a string is given split it by '@':
  489. // - Last fragment is the desired domain.
  490. // - Otherwise append the given domain argument.
  491. } else if (typeof target === 'string') {
  492. var target_array = target.split('@');
  493. var target_user;
  494. var target_domain;
  495. switch (target_array.length) {
  496. case 1:
  497. if (!domain) {
  498. return;
  499. }
  500. target_user = target;
  501. target_domain = domain;
  502. break;
  503. case 2:
  504. target_user = target_array[0];
  505. target_domain = target_array[1];
  506. break;
  507. default:
  508. target_user = target_array.slice(0, target_array.length - 1).join('@');
  509. target_domain = target_array[target_array.length - 1];
  510. } // Remove the URI scheme (if present).
  511. target_user = target_user.replace(/^(sips?|tel):/i, ''); // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols.
  512. if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) {
  513. target_user = target_user.replace(/[-.()]/g, '');
  514. } // Build the complete SIP URI.
  515. target = "".concat(JsSIP_C.SIP, ":").concat(escapeUser(target_user), "@").concat(target_domain); // Finally parse the resulting URI.
  516. var uri;
  517. if (uri = URI.parse(target)) {
  518. return uri;
  519. } else {
  520. return;
  521. }
  522. } else {
  523. return;
  524. }
  525. };
  526. exports.headerize = function (string) {
  527. var exceptions = {
  528. 'Call-Id': 'Call-ID',
  529. 'Cseq': 'CSeq',
  530. 'Www-Authenticate': 'WWW-Authenticate'
  531. };
  532. var name = string.toLowerCase().replace(/_/g, '-').split('-');
  533. var hname = '';
  534. var parts = name.length;
  535. var part;
  536. for (part = 0; part < parts; part++) {
  537. if (part !== 0) {
  538. hname += '-';
  539. }
  540. hname += name[part].charAt(0).toUpperCase() + name[part].substring(1);
  541. }
  542. if (exceptions[hname]) {
  543. hname = exceptions[hname];
  544. }
  545. return hname;
  546. };
  547. exports.sipErrorCause = function (status_code) {
  548. for (var cause in JsSIP_C.SIP_ERROR_CAUSES) {
  549. if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) {
  550. return JsSIP_C.causes[cause];
  551. }
  552. }
  553. return JsSIP_C.causes.SIP_FAILURE_CODE;
  554. };
  555. /**
  556. * Generate a random Test-Net IP (https://tools.ietf.org/html/rfc5735)
  557. */
  558. exports.getRandomTestNetIP = function () {
  559. function getOctet(from, to) {
  560. return Math.floor(Math.random() * (to - from + 1) + from);
  561. }
  562. return "192.0.2.".concat(getOctet(1, 254));
  563. }; // MD5 (Message-Digest Algorithm) https://www.webtoolkit.info.
  564. exports.calculateMD5 = function (string) {
  565. function rotateLeft(lValue, iShiftBits) {
  566. return lValue << iShiftBits | lValue >>> 32 - iShiftBits;
  567. }
  568. function addUnsigned(lX, lY) {
  569. var lX8 = lX & 0x80000000;
  570. var lY8 = lY & 0x80000000;
  571. var lX4 = lX & 0x40000000;
  572. var lY4 = lY & 0x40000000;
  573. var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
  574. if (lX4 & lY4) {
  575. return lResult ^ 0x80000000 ^ lX8 ^ lY8;
  576. }
  577. if (lX4 | lY4) {
  578. if (lResult & 0x40000000) {
  579. return lResult ^ 0xC0000000 ^ lX8 ^ lY8;
  580. } else {
  581. return lResult ^ 0x40000000 ^ lX8 ^ lY8;
  582. }
  583. } else {
  584. return lResult ^ lX8 ^ lY8;
  585. }
  586. }
  587. function doF(x, y, z) {
  588. return x & y | ~x & z;
  589. }
  590. function doG(x, y, z) {
  591. return x & z | y & ~z;
  592. }
  593. function doH(x, y, z) {
  594. return x ^ y ^ z;
  595. }
  596. function doI(x, y, z) {
  597. return y ^ (x | ~z);
  598. }
  599. function doFF(a, b, c, d, x, s, ac) {
  600. a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac));
  601. return addUnsigned(rotateLeft(a, s), b);
  602. }
  603. function doGG(a, b, c, d, x, s, ac) {
  604. a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac));
  605. return addUnsigned(rotateLeft(a, s), b);
  606. }
  607. function doHH(a, b, c, d, x, s, ac) {
  608. a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac));
  609. return addUnsigned(rotateLeft(a, s), b);
  610. }
  611. function doII(a, b, c, d, x, s, ac) {
  612. a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac));
  613. return addUnsigned(rotateLeft(a, s), b);
  614. }
  615. function convertToWordArray(str) {
  616. var lWordCount;
  617. var lMessageLength = str.length;
  618. var lNumberOfWords_temp1 = lMessageLength + 8;
  619. var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64;
  620. var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
  621. var lWordArray = new Array(lNumberOfWords - 1);
  622. var lBytePosition = 0;
  623. var lByteCount = 0;
  624. while (lByteCount < lMessageLength) {
  625. lWordCount = (lByteCount - lByteCount % 4) / 4;
  626. lBytePosition = lByteCount % 4 * 8;
  627. lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition;
  628. lByteCount++;
  629. }
  630. lWordCount = (lByteCount - lByteCount % 4) / 4;
  631. lBytePosition = lByteCount % 4 * 8;
  632. lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition;
  633. lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
  634. lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
  635. return lWordArray;
  636. }
  637. function wordToHex(lValue) {
  638. var wordToHexValue = '',
  639. wordToHexValue_temp = '',
  640. lByte,
  641. lCount;
  642. for (lCount = 0; lCount <= 3; lCount++) {
  643. lByte = lValue >>> lCount * 8 & 255;
  644. wordToHexValue_temp = "0".concat(lByte.toString(16));
  645. wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2);
  646. }
  647. return wordToHexValue;
  648. }
  649. function utf8Encode(str) {
  650. str = str.replace(/\r\n/g, '\n');
  651. var utftext = '';
  652. for (var n = 0; n < str.length; n++) {
  653. var _c = str.charCodeAt(n);
  654. if (_c < 128) {
  655. utftext += String.fromCharCode(_c);
  656. } else if (_c > 127 && _c < 2048) {
  657. utftext += String.fromCharCode(_c >> 6 | 192);
  658. utftext += String.fromCharCode(_c & 63 | 128);
  659. } else {
  660. utftext += String.fromCharCode(_c >> 12 | 224);
  661. utftext += String.fromCharCode(_c >> 6 & 63 | 128);
  662. utftext += String.fromCharCode(_c & 63 | 128);
  663. }
  664. }
  665. return utftext;
  666. }
  667. var x = [];
  668. var k, AA, BB, CC, DD, a, b, c, d;
  669. var S11 = 7,
  670. S12 = 12,
  671. S13 = 17,
  672. S14 = 22;
  673. var S21 = 5,
  674. S22 = 9,
  675. S23 = 14,
  676. S24 = 20;
  677. var S31 = 4,
  678. S32 = 11,
  679. S33 = 16,
  680. S34 = 23;
  681. var S41 = 6,
  682. S42 = 10,
  683. S43 = 15,
  684. S44 = 21;
  685. string = utf8Encode(string);
  686. x = convertToWordArray(string);
  687. a = 0x67452301;
  688. b = 0xEFCDAB89;
  689. c = 0x98BADCFE;
  690. d = 0x10325476;
  691. for (k = 0; k < x.length; k += 16) {
  692. AA = a;
  693. BB = b;
  694. CC = c;
  695. DD = d;
  696. a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
  697. d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
  698. c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB);
  699. b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
  700. a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
  701. d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
  702. c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613);
  703. b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501);
  704. a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8);
  705. d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
  706. c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
  707. b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
  708. a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122);
  709. d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193);
  710. c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E);
  711. b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821);
  712. a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
  713. d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340);
  714. c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
  715. b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
  716. a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
  717. d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453);
  718. c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
  719. b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
  720. a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
  721. d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
  722. c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
  723. b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
  724. a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
  725. d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
  726. c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
  727. b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
  728. a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
  729. d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681);
  730. c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
  731. b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
  732. a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
  733. d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
  734. c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
  735. b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
  736. a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
  737. d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
  738. c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
  739. b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05);
  740. a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
  741. d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
  742. c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
  743. b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
  744. a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244);
  745. d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97);
  746. c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
  747. b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039);
  748. a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3);
  749. d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
  750. c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
  751. b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1);
  752. a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
  753. d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
  754. c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314);
  755. b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
  756. a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82);
  757. d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
  758. c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
  759. b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391);
  760. a = addUnsigned(a, AA);
  761. b = addUnsigned(b, BB);
  762. c = addUnsigned(c, CC);
  763. d = addUnsigned(d, DD);
  764. }
  765. var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
  766. return temp.toLowerCase();
  767. };
  768. exports.closeMediaStream = function (stream) {
  769. if (!stream) {
  770. return;
  771. } // Latest spec states that MediaStream has no stop() method and instead must
  772. // call stop() on every MediaStreamTrack.
  773. try {
  774. var tracks;
  775. if (stream.getTracks) {
  776. tracks = stream.getTracks();
  777. var _iteratorNormalCompletion = true;
  778. var _didIteratorError = false;
  779. var _iteratorError = undefined;
  780. try {
  781. for (var _iterator = tracks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  782. var track = _step.value;
  783. track.stop();
  784. }
  785. } catch (err) {
  786. _didIteratorError = true;
  787. _iteratorError = err;
  788. } finally {
  789. try {
  790. if (!_iteratorNormalCompletion && _iterator.return != null) {
  791. _iterator.return();
  792. }
  793. } finally {
  794. if (_didIteratorError) {
  795. throw _iteratorError;
  796. }
  797. }
  798. }
  799. } else {
  800. tracks = stream.getAudioTracks();
  801. var _iteratorNormalCompletion2 = true;
  802. var _didIteratorError2 = false;
  803. var _iteratorError2 = undefined;
  804. try {
  805. for (var _iterator2 = tracks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  806. var _track = _step2.value;
  807. _track.stop();
  808. }
  809. } catch (err) {
  810. _didIteratorError2 = true;
  811. _iteratorError2 = err;
  812. } finally {
  813. try {
  814. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  815. _iterator2.return();
  816. }
  817. } finally {
  818. if (_didIteratorError2) {
  819. throw _iteratorError2;
  820. }
  821. }
  822. }
  823. tracks = stream.getVideoTracks();
  824. var _iteratorNormalCompletion3 = true;
  825. var _didIteratorError3 = false;
  826. var _iteratorError3 = undefined;
  827. try {
  828. for (var _iterator3 = tracks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  829. var _track2 = _step3.value;
  830. _track2.stop();
  831. }
  832. } catch (err) {
  833. _didIteratorError3 = true;
  834. _iteratorError3 = err;
  835. } finally {
  836. try {
  837. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  838. _iterator3.return();
  839. }
  840. } finally {
  841. if (_didIteratorError3) {
  842. throw _iteratorError3;
  843. }
  844. }
  845. }
  846. }
  847. } catch (error) {
  848. // Deprecated by the spec, but still in use.
  849. // NOTE: In Temasys IE plugin stream.stop is a callable 'object'.
  850. if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') {
  851. stream.stop();
  852. }
  853. }
  854. };
  855. exports.cloneArray = function (array) {
  856. return array && array.slice() || [];
  857. };
  858. }),
  859. /* 3 */
  860. (function(module, exports, __webpack_require__) {
  861. "use strict";
  862. module.exports = function () {
  863. /*
  864. * Generated by PEG.js 0.7.0.
  865. *
  866. * http://pegjs.majda.cz/
  867. */
  868. function quote(s) {
  869. /*
  870. * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
  871. * string literal except for the closing quote character, backslash,
  872. * carriage return, line separator, paragraph separator, and line feed.
  873. * Any character may appear in the form of an escape sequence.
  874. *
  875. * For portability, we also escape escape all control and non-ASCII
  876. * characters. Note that "\0" and "\v" escape sequences are not used
  877. * because JSHint does not like the first and IE the second.
  878. */
  879. return '"' + s.replace(/\\/g, '\\\\') // backslash
  880. .replace(/"/g, '\\"') // closing quote character
  881. .replace(/\x08/g, '\\b') // backspace
  882. .replace(/\t/g, '\\t') // horizontal tab
  883. .replace(/\n/g, '\\n') // line feed
  884. .replace(/\f/g, '\\f') // form feed
  885. .replace(/\r/g, '\\r') // carriage return
  886. .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"';
  887. }
  888. var result = {
  889. /*
  890. * Parses the input with a generated parser. If the parsing is successfull,
  891. * returns a value explicitly or implicitly specified by the grammar from
  892. * which the parser was generated (see |PEG.buildParser|). If the parsing is
  893. * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
  894. */
  895. parse: function parse(input, startRule) {
  896. var parseFunctions = {
  897. "CRLF": parse_CRLF,
  898. "DIGIT": parse_DIGIT,
  899. "ALPHA": parse_ALPHA,
  900. "HEXDIG": parse_HEXDIG,
  901. "WSP": parse_WSP,
  902. "OCTET": parse_OCTET,
  903. "DQUOTE": parse_DQUOTE,
  904. "SP": parse_SP,
  905. "HTAB": parse_HTAB,
  906. "alphanum": parse_alphanum,
  907. "reserved": parse_reserved,
  908. "unreserved": parse_unreserved,
  909. "mark": parse_mark,
  910. "escaped": parse_escaped,
  911. "LWS": parse_LWS,
  912. "SWS": parse_SWS,
  913. "HCOLON": parse_HCOLON,
  914. "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM,
  915. "TEXT_UTF8char": parse_TEXT_UTF8char,
  916. "UTF8_NONASCII": parse_UTF8_NONASCII,
  917. "UTF8_CONT": parse_UTF8_CONT,
  918. "LHEX": parse_LHEX,
  919. "token": parse_token,
  920. "token_nodot": parse_token_nodot,
  921. "separators": parse_separators,
  922. "word": parse_word,
  923. "STAR": parse_STAR,
  924. "SLASH": parse_SLASH,
  925. "EQUAL": parse_EQUAL,
  926. "LPAREN": parse_LPAREN,
  927. "RPAREN": parse_RPAREN,
  928. "RAQUOT": parse_RAQUOT,
  929. "LAQUOT": parse_LAQUOT,
  930. "COMMA": parse_COMMA,
  931. "SEMI": parse_SEMI,
  932. "COLON": parse_COLON,
  933. "LDQUOT": parse_LDQUOT,
  934. "RDQUOT": parse_RDQUOT,
  935. "comment": parse_comment,
  936. "ctext": parse_ctext,
  937. "quoted_string": parse_quoted_string,
  938. "quoted_string_clean": parse_quoted_string_clean,
  939. "qdtext": parse_qdtext,
  940. "quoted_pair": parse_quoted_pair,
  941. "SIP_URI_noparams": parse_SIP_URI_noparams,
  942. "SIP_URI": parse_SIP_URI,
  943. "uri_scheme": parse_uri_scheme,
  944. "uri_scheme_sips": parse_uri_scheme_sips,
  945. "uri_scheme_sip": parse_uri_scheme_sip,
  946. "userinfo": parse_userinfo,
  947. "user": parse_user,
  948. "user_unreserved": parse_user_unreserved,
  949. "password": parse_password,
  950. "hostport": parse_hostport,
  951. "host": parse_host,
  952. "hostname": parse_hostname,
  953. "domainlabel": parse_domainlabel,
  954. "toplabel": parse_toplabel,
  955. "IPv6reference": parse_IPv6reference,
  956. "IPv6address": parse_IPv6address,
  957. "h16": parse_h16,
  958. "ls32": parse_ls32,
  959. "IPv4address": parse_IPv4address,
  960. "dec_octet": parse_dec_octet,
  961. "port": parse_port,
  962. "uri_parameters": parse_uri_parameters,
  963. "uri_parameter": parse_uri_parameter,
  964. "transport_param": parse_transport_param,
  965. "user_param": parse_user_param,
  966. "method_param": parse_method_param,
  967. "ttl_param": parse_ttl_param,
  968. "maddr_param": parse_maddr_param,
  969. "lr_param": parse_lr_param,
  970. "other_param": parse_other_param,
  971. "pname": parse_pname,
  972. "pvalue": parse_pvalue,
  973. "paramchar": parse_paramchar,
  974. "param_unreserved": parse_param_unreserved,
  975. "headers": parse_headers,
  976. "header": parse_header,
  977. "hname": parse_hname,
  978. "hvalue": parse_hvalue,
  979. "hnv_unreserved": parse_hnv_unreserved,
  980. "Request_Response": parse_Request_Response,
  981. "Request_Line": parse_Request_Line,
  982. "Request_URI": parse_Request_URI,
  983. "absoluteURI": parse_absoluteURI,
  984. "hier_part": parse_hier_part,
  985. "net_path": parse_net_path,
  986. "abs_path": parse_abs_path,
  987. "opaque_part": parse_opaque_part,
  988. "uric": parse_uric,
  989. "uric_no_slash": parse_uric_no_slash,
  990. "path_segments": parse_path_segments,
  991. "segment": parse_segment,
  992. "param": parse_param,
  993. "pchar": parse_pchar,
  994. "scheme": parse_scheme,
  995. "authority": parse_authority,
  996. "srvr": parse_srvr,
  997. "reg_name": parse_reg_name,
  998. "query": parse_query,
  999. "SIP_Version": parse_SIP_Version,
  1000. "INVITEm": parse_INVITEm,
  1001. "ACKm": parse_ACKm,
  1002. "OPTIONSm": parse_OPTIONSm,
  1003. "BYEm": parse_BYEm,
  1004. "CANCELm": parse_CANCELm,
  1005. "REGISTERm": parse_REGISTERm,
  1006. "SUBSCRIBEm": parse_SUBSCRIBEm,
  1007. "NOTIFYm": parse_NOTIFYm,
  1008. "REFERm": parse_REFERm,
  1009. "Method": parse_Method,
  1010. "Status_Line": parse_Status_Line,
  1011. "Status_Code": parse_Status_Code,
  1012. "extension_code": parse_extension_code,
  1013. "Reason_Phrase": parse_Reason_Phrase,
  1014. "Allow_Events": parse_Allow_Events,
  1015. "Call_ID": parse_Call_ID,
  1016. "Contact": parse_Contact,
  1017. "contact_param": parse_contact_param,
  1018. "name_addr": parse_name_addr,
  1019. "display_name": parse_display_name,
  1020. "contact_params": parse_contact_params,
  1021. "c_p_q": parse_c_p_q,
  1022. "c_p_expires": parse_c_p_expires,
  1023. "delta_seconds": parse_delta_seconds,
  1024. "qvalue": parse_qvalue,
  1025. "generic_param": parse_generic_param,
  1026. "gen_value": parse_gen_value,
  1027. "Content_Disposition": parse_Content_Disposition,
  1028. "disp_type": parse_disp_type,
  1029. "disp_param": parse_disp_param,
  1030. "handling_param": parse_handling_param,
  1031. "Content_Encoding": parse_Content_Encoding,
  1032. "Content_Length": parse_Content_Length,
  1033. "Content_Type": parse_Content_Type,
  1034. "media_type": parse_media_type,
  1035. "m_type": parse_m_type,
  1036. "discrete_type": parse_discrete_type,
  1037. "composite_type": parse_composite_type,
  1038. "extension_token": parse_extension_token,
  1039. "x_token": parse_x_token,
  1040. "m_subtype": parse_m_subtype,
  1041. "m_parameter": parse_m_parameter,
  1042. "m_value": parse_m_value,
  1043. "CSeq": parse_CSeq,
  1044. "CSeq_value": parse_CSeq_value,
  1045. "Expires": parse_Expires,
  1046. "Event": parse_Event,
  1047. "event_type": parse_event_type,
  1048. "From": parse_From,
  1049. "from_param": parse_from_param,
  1050. "tag_param": parse_tag_param,
  1051. "Max_Forwards": parse_Max_Forwards,
  1052. "Min_Expires": parse_Min_Expires,
  1053. "Name_Addr_Header": parse_Name_Addr_Header,
  1054. "Proxy_Authenticate": parse_Proxy_Authenticate,
  1055. "challenge": parse_challenge,
  1056. "other_challenge": parse_other_challenge,
  1057. "auth_param": parse_auth_param,
  1058. "digest_cln": parse_digest_cln,
  1059. "realm": parse_realm,
  1060. "realm_value": parse_realm_value,
  1061. "domain": parse_domain,
  1062. "URI": parse_URI,
  1063. "nonce": parse_nonce,
  1064. "nonce_value": parse_nonce_value,
  1065. "opaque": parse_opaque,
  1066. "stale": parse_stale,
  1067. "algorithm": parse_algorithm,
  1068. "qop_options": parse_qop_options,
  1069. "qop_value": parse_qop_value,
  1070. "Proxy_Require": parse_Proxy_Require,
  1071. "Record_Route": parse_Record_Route,
  1072. "rec_route": parse_rec_route,
  1073. "Reason": parse_Reason,
  1074. "reason_param": parse_reason_param,
  1075. "reason_cause": parse_reason_cause,
  1076. "Require": parse_Require,
  1077. "Route": parse_Route,
  1078. "route_param": parse_route_param,
  1079. "Subscription_State": parse_Subscription_State,
  1080. "substate_value": parse_substate_value,
  1081. "subexp_params": parse_subexp_params,
  1082. "event_reason_value": parse_event_reason_value,
  1083. "Subject": parse_Subject,
  1084. "Supported": parse_Supported,
  1085. "To": parse_To,
  1086. "to_param": parse_to_param,
  1087. "Via": parse_Via,
  1088. "via_param": parse_via_param,
  1089. "via_params": parse_via_params,
  1090. "via_ttl": parse_via_ttl,
  1091. "via_maddr": parse_via_maddr,
  1092. "via_received": parse_via_received,
  1093. "via_branch": parse_via_branch,
  1094. "response_port": parse_response_port,
  1095. "sent_protocol": parse_sent_protocol,
  1096. "protocol_name": parse_protocol_name,
  1097. "transport": parse_transport,
  1098. "sent_by": parse_sent_by,
  1099. "via_host": parse_via_host,
  1100. "via_port": parse_via_port,
  1101. "ttl": parse_ttl,
  1102. "WWW_Authenticate": parse_WWW_Authenticate,
  1103. "Session_Expires": parse_Session_Expires,
  1104. "s_e_expires": parse_s_e_expires,
  1105. "s_e_params": parse_s_e_params,
  1106. "s_e_refresher": parse_s_e_refresher,
  1107. "extension_header": parse_extension_header,
  1108. "header_value": parse_header_value,
  1109. "message_body": parse_message_body,
  1110. "uuid_URI": parse_uuid_URI,
  1111. "uuid": parse_uuid,
  1112. "hex4": parse_hex4,
  1113. "hex8": parse_hex8,
  1114. "hex12": parse_hex12,
  1115. "Refer_To": parse_Refer_To,
  1116. "Replaces": parse_Replaces,
  1117. "call_id": parse_call_id,
  1118. "replaces_param": parse_replaces_param,
  1119. "to_tag": parse_to_tag,
  1120. "from_tag": parse_from_tag,
  1121. "early_flag": parse_early_flag
  1122. };
  1123. if (startRule !== undefined) {
  1124. if (parseFunctions[startRule] === undefined) {
  1125. throw new Error("Invalid rule name: " + quote(startRule) + ".");
  1126. }
  1127. } else {
  1128. startRule = "CRLF";
  1129. }
  1130. var pos = 0;
  1131. var reportFailures = 0;
  1132. var rightmostFailuresPos = 0;
  1133. var rightmostFailuresExpected = [];
  1134. function padLeft(input, padding, length) {
  1135. var result = input;
  1136. var padLength = length - input.length;
  1137. for (var i = 0; i < padLength; i++) {
  1138. result = padding + result;
  1139. }
  1140. return result;
  1141. }
  1142. function escape(ch) {
  1143. var charCode = ch.charCodeAt(0);
  1144. var escapeChar;
  1145. var length;
  1146. if (charCode <= 0xFF) {
  1147. escapeChar = 'x';
  1148. length = 2;
  1149. } else {
  1150. escapeChar = 'u';
  1151. length = 4;
  1152. }
  1153. return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
  1154. }
  1155. function matchFailed(failure) {
  1156. if (pos < rightmostFailuresPos) {
  1157. return;
  1158. }
  1159. if (pos > rightmostFailuresPos) {
  1160. rightmostFailuresPos = pos;
  1161. rightmostFailuresExpected = [];
  1162. }
  1163. rightmostFailuresExpected.push(failure);
  1164. }
  1165. function parse_CRLF() {
  1166. var result0;
  1167. if (input.substr(pos, 2) === "\r\n") {
  1168. result0 = "\r\n";
  1169. pos += 2;
  1170. } else {
  1171. result0 = null;
  1172. if (reportFailures === 0) {
  1173. matchFailed("\"\\r\\n\"");
  1174. }
  1175. }
  1176. return result0;
  1177. }
  1178. function parse_DIGIT() {
  1179. var result0;
  1180. if (/^[0-9]/.test(input.charAt(pos))) {
  1181. result0 = input.charAt(pos);
  1182. pos++;
  1183. } else {
  1184. result0 = null;
  1185. if (reportFailures === 0) {
  1186. matchFailed("[0-9]");
  1187. }
  1188. }
  1189. return result0;
  1190. }
  1191. function parse_ALPHA() {
  1192. var result0;
  1193. if (/^[a-zA-Z]/.test(input.charAt(pos))) {
  1194. result0 = input.charAt(pos);
  1195. pos++;
  1196. } else {
  1197. result0 = null;
  1198. if (reportFailures === 0) {
  1199. matchFailed("[a-zA-Z]");
  1200. }
  1201. }
  1202. return result0;
  1203. }
  1204. function parse_HEXDIG() {
  1205. var result0;
  1206. if (/^[0-9a-fA-F]/.test(input.charAt(pos))) {
  1207. result0 = input.charAt(pos);
  1208. pos++;
  1209. } else {
  1210. result0 = null;
  1211. if (reportFailures === 0) {
  1212. matchFailed("[0-9a-fA-F]");
  1213. }
  1214. }
  1215. return result0;
  1216. }
  1217. function parse_WSP() {
  1218. var result0;
  1219. result0 = parse_SP();
  1220. if (result0 === null) {
  1221. result0 = parse_HTAB();
  1222. }
  1223. return result0;
  1224. }
  1225. function parse_OCTET() {
  1226. var result0;
  1227. if (/^[\0-\xFF]/.test(input.charAt(pos))) {
  1228. result0 = input.charAt(pos);
  1229. pos++;
  1230. } else {
  1231. result0 = null;
  1232. if (reportFailures === 0) {
  1233. matchFailed("[\\0-\\xFF]");
  1234. }
  1235. }
  1236. return result0;
  1237. }
  1238. function parse_DQUOTE() {
  1239. var result0;
  1240. if (/^["]/.test(input.charAt(pos))) {
  1241. result0 = input.charAt(pos);
  1242. pos++;
  1243. } else {
  1244. result0 = null;
  1245. if (reportFailures === 0) {
  1246. matchFailed("[\"]");
  1247. }
  1248. }
  1249. return result0;
  1250. }
  1251. function parse_SP() {
  1252. var result0;
  1253. if (input.charCodeAt(pos) === 32) {
  1254. result0 = " ";
  1255. pos++;
  1256. } else {
  1257. result0 = null;
  1258. if (reportFailures === 0) {
  1259. matchFailed("\" \"");
  1260. }
  1261. }
  1262. return result0;
  1263. }
  1264. function parse_HTAB() {
  1265. var result0;
  1266. if (input.charCodeAt(pos) === 9) {
  1267. result0 = "\t";
  1268. pos++;
  1269. } else {
  1270. result0 = null;
  1271. if (reportFailures === 0) {
  1272. matchFailed("\"\\t\"");
  1273. }
  1274. }
  1275. return result0;
  1276. }
  1277. function parse_alphanum() {
  1278. var result0;
  1279. if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) {
  1280. result0 = input.charAt(pos);
  1281. pos++;
  1282. } else {
  1283. result0 = null;
  1284. if (reportFailures === 0) {
  1285. matchFailed("[a-zA-Z0-9]");
  1286. }
  1287. }
  1288. return result0;
  1289. }
  1290. function parse_reserved() {
  1291. var result0;
  1292. if (input.charCodeAt(pos) === 59) {
  1293. result0 = ";";
  1294. pos++;
  1295. } else {
  1296. result0 = null;
  1297. if (reportFailures === 0) {
  1298. matchFailed("\";\"");
  1299. }
  1300. }
  1301. if (result0 === null) {
  1302. if (input.charCodeAt(pos) === 47) {
  1303. result0 = "/";
  1304. pos++;
  1305. } else {
  1306. result0 = null;
  1307. if (reportFailures === 0) {
  1308. matchFailed("\"/\"");
  1309. }
  1310. }
  1311. if (result0 === null) {
  1312. if (input.charCodeAt(pos) === 63) {
  1313. result0 = "?";
  1314. pos++;
  1315. } else {
  1316. result0 = null;
  1317. if (reportFailures === 0) {
  1318. matchFailed("\"?\"");
  1319. }
  1320. }
  1321. if (result0 === null) {
  1322. if (input.charCodeAt(pos) === 58) {
  1323. result0 = ":";
  1324. pos++;
  1325. } else {
  1326. result0 = null;
  1327. if (reportFailures === 0) {
  1328. matchFailed("\":\"");
  1329. }
  1330. }
  1331. if (result0 === null) {
  1332. if (input.charCodeAt(pos) === 64) {
  1333. result0 = "@";
  1334. pos++;
  1335. } else {
  1336. result0 = null;
  1337. if (reportFailures === 0) {
  1338. matchFailed("\"@\"");
  1339. }
  1340. }
  1341. if (result0 === null) {
  1342. if (input.charCodeAt(pos) === 38) {
  1343. result0 = "&";
  1344. pos++;
  1345. } else {
  1346. result0 = null;
  1347. if (reportFailures === 0) {
  1348. matchFailed("\"&\"");
  1349. }
  1350. }
  1351. if (result0 === null) {
  1352. if (input.charCodeAt(pos) === 61) {
  1353. result0 = "=";
  1354. pos++;
  1355. } else {
  1356. result0 = null;
  1357. if (reportFailures === 0) {
  1358. matchFailed("\"=\"");
  1359. }
  1360. }
  1361. if (result0 === null) {
  1362. if (input.charCodeAt(pos) === 43) {
  1363. result0 = "+";
  1364. pos++;
  1365. } else {
  1366. result0 = null;
  1367. if (reportFailures === 0) {
  1368. matchFailed("\"+\"");
  1369. }
  1370. }
  1371. if (result0 === null) {
  1372. if (input.charCodeAt(pos) === 36) {
  1373. result0 = "$";
  1374. pos++;
  1375. } else {
  1376. result0 = null;
  1377. if (reportFailures === 0) {
  1378. matchFailed("\"$\"");
  1379. }
  1380. }
  1381. if (result0 === null) {
  1382. if (input.charCodeAt(pos) === 44) {
  1383. result0 = ",";
  1384. pos++;
  1385. } else {
  1386. result0 = null;
  1387. if (reportFailures === 0) {
  1388. matchFailed("\",\"");
  1389. }
  1390. }
  1391. }
  1392. }
  1393. }
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. return result0;
  1401. }
  1402. function parse_unreserved() {
  1403. var result0;
  1404. result0 = parse_alphanum();
  1405. if (result0 === null) {
  1406. result0 = parse_mark();
  1407. }
  1408. return result0;
  1409. }
  1410. function parse_mark() {
  1411. var result0;
  1412. if (input.charCodeAt(pos) === 45) {
  1413. result0 = "-";
  1414. pos++;
  1415. } else {
  1416. result0 = null;
  1417. if (reportFailures === 0) {
  1418. matchFailed("\"-\"");
  1419. }
  1420. }
  1421. if (result0 === null) {
  1422. if (input.charCodeAt(pos) === 95) {
  1423. result0 = "_";
  1424. pos++;
  1425. } else {
  1426. result0 = null;
  1427. if (reportFailures === 0) {
  1428. matchFailed("\"_\"");
  1429. }
  1430. }
  1431. if (result0 === null) {
  1432. if (input.charCodeAt(pos) === 46) {
  1433. result0 = ".";
  1434. pos++;
  1435. } else {
  1436. result0 = null;
  1437. if (reportFailures === 0) {
  1438. matchFailed("\".\"");
  1439. }
  1440. }
  1441. if (result0 === null) {
  1442. if (input.charCodeAt(pos) === 33) {
  1443. result0 = "!";
  1444. pos++;
  1445. } else {
  1446. result0 = null;
  1447. if (reportFailures === 0) {
  1448. matchFailed("\"!\"");
  1449. }
  1450. }
  1451. if (result0 === null) {
  1452. if (input.charCodeAt(pos) === 126) {
  1453. result0 = "~";
  1454. pos++;
  1455. } else {
  1456. result0 = null;
  1457. if (reportFailures === 0) {
  1458. matchFailed("\"~\"");
  1459. }
  1460. }
  1461. if (result0 === null) {
  1462. if (input.charCodeAt(pos) === 42) {
  1463. result0 = "*";
  1464. pos++;
  1465. } else {
  1466. result0 = null;
  1467. if (reportFailures === 0) {
  1468. matchFailed("\"*\"");
  1469. }
  1470. }
  1471. if (result0 === null) {
  1472. if (input.charCodeAt(pos) === 39) {
  1473. result0 = "'";
  1474. pos++;
  1475. } else {
  1476. result0 = null;
  1477. if (reportFailures === 0) {
  1478. matchFailed("\"'\"");
  1479. }
  1480. }
  1481. if (result0 === null) {
  1482. if (input.charCodeAt(pos) === 40) {
  1483. result0 = "(";
  1484. pos++;
  1485. } else {
  1486. result0 = null;
  1487. if (reportFailures === 0) {
  1488. matchFailed("\"(\"");
  1489. }
  1490. }
  1491. if (result0 === null) {
  1492. if (input.charCodeAt(pos) === 41) {
  1493. result0 = ")";
  1494. pos++;
  1495. } else {
  1496. result0 = null;
  1497. if (reportFailures === 0) {
  1498. matchFailed("\")\"");
  1499. }
  1500. }
  1501. }
  1502. }
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509. return result0;
  1510. }
  1511. function parse_escaped() {
  1512. var result0, result1, result2;
  1513. var pos0, pos1;
  1514. pos0 = pos;
  1515. pos1 = pos;
  1516. if (input.charCodeAt(pos) === 37) {
  1517. result0 = "%";
  1518. pos++;
  1519. } else {
  1520. result0 = null;
  1521. if (reportFailures === 0) {
  1522. matchFailed("\"%\"");
  1523. }
  1524. }
  1525. if (result0 !== null) {
  1526. result1 = parse_HEXDIG();
  1527. if (result1 !== null) {
  1528. result2 = parse_HEXDIG();
  1529. if (result2 !== null) {
  1530. result0 = [result0, result1, result2];
  1531. } else {
  1532. result0 = null;
  1533. pos = pos1;
  1534. }
  1535. } else {
  1536. result0 = null;
  1537. pos = pos1;
  1538. }
  1539. } else {
  1540. result0 = null;
  1541. pos = pos1;
  1542. }
  1543. if (result0 !== null) {
  1544. result0 = function (offset, escaped) {
  1545. return escaped.join('');
  1546. }(pos0, result0);
  1547. }
  1548. if (result0 === null) {
  1549. pos = pos0;
  1550. }
  1551. return result0;
  1552. }
  1553. function parse_LWS() {
  1554. var result0, result1, result2;
  1555. var pos0, pos1, pos2;
  1556. pos0 = pos;
  1557. pos1 = pos;
  1558. pos2 = pos;
  1559. result0 = [];
  1560. result1 = parse_WSP();
  1561. while (result1 !== null) {
  1562. result0.push(result1);
  1563. result1 = parse_WSP();
  1564. }
  1565. if (result0 !== null) {
  1566. result1 = parse_CRLF();
  1567. if (result1 !== null) {
  1568. result0 = [result0, result1];
  1569. } else {
  1570. result0 = null;
  1571. pos = pos2;
  1572. }
  1573. } else {
  1574. result0 = null;
  1575. pos = pos2;
  1576. }
  1577. result0 = result0 !== null ? result0 : "";
  1578. if (result0 !== null) {
  1579. result2 = parse_WSP();
  1580. if (result2 !== null) {
  1581. result1 = [];
  1582. while (result2 !== null) {
  1583. result1.push(result2);
  1584. result2 = parse_WSP();
  1585. }
  1586. } else {
  1587. result1 = null;
  1588. }
  1589. if (result1 !== null) {
  1590. result0 = [result0, result1];
  1591. } else {
  1592. result0 = null;
  1593. pos = pos1;
  1594. }
  1595. } else {
  1596. result0 = null;
  1597. pos = pos1;
  1598. }
  1599. if (result0 !== null) {
  1600. result0 = function (offset) {
  1601. return " ";
  1602. }(pos0);
  1603. }
  1604. if (result0 === null) {
  1605. pos = pos0;
  1606. }
  1607. return result0;
  1608. }
  1609. function parse_SWS() {
  1610. var result0;
  1611. result0 = parse_LWS();
  1612. result0 = result0 !== null ? result0 : "";
  1613. return result0;
  1614. }
  1615. function parse_HCOLON() {
  1616. var result0, result1, result2;
  1617. var pos0, pos1;
  1618. pos0 = pos;
  1619. pos1 = pos;
  1620. result0 = [];
  1621. result1 = parse_SP();
  1622. if (result1 === null) {
  1623. result1 = parse_HTAB();
  1624. }
  1625. while (result1 !== null) {
  1626. result0.push(result1);
  1627. result1 = parse_SP();
  1628. if (result1 === null) {
  1629. result1 = parse_HTAB();
  1630. }
  1631. }
  1632. if (result0 !== null) {
  1633. if (input.charCodeAt(pos) === 58) {
  1634. result1 = ":";
  1635. pos++;
  1636. } else {
  1637. result1 = null;
  1638. if (reportFailures === 0) {
  1639. matchFailed("\":\"");
  1640. }
  1641. }
  1642. if (result1 !== null) {
  1643. result2 = parse_SWS();
  1644. if (result2 !== null) {
  1645. result0 = [result0, result1, result2];
  1646. } else {
  1647. result0 = null;
  1648. pos = pos1;
  1649. }
  1650. } else {
  1651. result0 = null;
  1652. pos = pos1;
  1653. }
  1654. } else {
  1655. result0 = null;
  1656. pos = pos1;
  1657. }
  1658. if (result0 !== null) {
  1659. result0 = function (offset) {
  1660. return ':';
  1661. }(pos0);
  1662. }
  1663. if (result0 === null) {
  1664. pos = pos0;
  1665. }
  1666. return result0;
  1667. }
  1668. function parse_TEXT_UTF8_TRIM() {
  1669. var result0, result1, result2, result3;
  1670. var pos0, pos1, pos2;
  1671. pos0 = pos;
  1672. pos1 = pos;
  1673. result1 = parse_TEXT_UTF8char();
  1674. if (result1 !== null) {
  1675. result0 = [];
  1676. while (result1 !== null) {
  1677. result0.push(result1);
  1678. result1 = parse_TEXT_UTF8char();
  1679. }
  1680. } else {
  1681. result0 = null;
  1682. }
  1683. if (result0 !== null) {
  1684. result1 = [];
  1685. pos2 = pos;
  1686. result2 = [];
  1687. result3 = parse_LWS();
  1688. while (result3 !== null) {
  1689. result2.push(result3);
  1690. result3 = parse_LWS();
  1691. }
  1692. if (result2 !== null) {
  1693. result3 = parse_TEXT_UTF8char();
  1694. if (result3 !== null) {
  1695. result2 = [result2, result3];
  1696. } else {
  1697. result2 = null;
  1698. pos = pos2;
  1699. }
  1700. } else {
  1701. result2 = null;
  1702. pos = pos2;
  1703. }
  1704. while (result2 !== null) {
  1705. result1.push(result2);
  1706. pos2 = pos;
  1707. result2 = [];
  1708. result3 = parse_LWS();
  1709. while (result3 !== null) {
  1710. result2.push(result3);
  1711. result3 = parse_LWS();
  1712. }
  1713. if (result2 !== null) {
  1714. result3 = parse_TEXT_UTF8char();
  1715. if (result3 !== null) {
  1716. result2 = [result2, result3];
  1717. } else {
  1718. result2 = null;
  1719. pos = pos2;
  1720. }
  1721. } else {
  1722. result2 = null;
  1723. pos = pos2;
  1724. }
  1725. }
  1726. if (result1 !== null) {
  1727. result0 = [result0, result1];
  1728. } else {
  1729. result0 = null;
  1730. pos = pos1;
  1731. }
  1732. } else {
  1733. result0 = null;
  1734. pos = pos1;
  1735. }
  1736. if (result0 !== null) {
  1737. result0 = function (offset) {
  1738. return input.substring(pos, offset);
  1739. }(pos0);
  1740. }
  1741. if (result0 === null) {
  1742. pos = pos0;
  1743. }
  1744. return result0;
  1745. }
  1746. function parse_TEXT_UTF8char() {
  1747. var result0;
  1748. if (/^[!-~]/.test(input.charAt(pos))) {
  1749. result0 = input.charAt(pos);
  1750. pos++;
  1751. } else {
  1752. result0 = null;
  1753. if (reportFailures === 0) {
  1754. matchFailed("[!-~]");
  1755. }
  1756. }
  1757. if (result0 === null) {
  1758. result0 = parse_UTF8_NONASCII();
  1759. }
  1760. return result0;
  1761. }
  1762. function parse_UTF8_NONASCII() {
  1763. var result0;
  1764. if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) {
  1765. result0 = input.charAt(pos);
  1766. pos++;
  1767. } else {
  1768. result0 = null;
  1769. if (reportFailures === 0) {
  1770. matchFailed("[\\x80-\\uFFFF]");
  1771. }
  1772. }
  1773. return result0;
  1774. }
  1775. function parse_UTF8_CONT() {
  1776. var result0;
  1777. if (/^[\x80-\xBF]/.test(input.charAt(pos))) {
  1778. result0 = input.charAt(pos);
  1779. pos++;
  1780. } else {
  1781. result0 = null;
  1782. if (reportFailures === 0) {
  1783. matchFailed("[\\x80-\\xBF]");
  1784. }
  1785. }
  1786. return result0;
  1787. }
  1788. function parse_LHEX() {
  1789. var result0;
  1790. result0 = parse_DIGIT();
  1791. if (result0 === null) {
  1792. if (/^[a-f]/.test(input.charAt(pos))) {
  1793. result0 = input.charAt(pos);
  1794. pos++;
  1795. } else {
  1796. result0 = null;
  1797. if (reportFailures === 0) {
  1798. matchFailed("[a-f]");
  1799. }
  1800. }
  1801. }
  1802. return result0;
  1803. }
  1804. function parse_token() {
  1805. var result0, result1;
  1806. var pos0;
  1807. pos0 = pos;
  1808. result1 = parse_alphanum();
  1809. if (result1 === null) {
  1810. if (input.charCodeAt(pos) === 45) {
  1811. result1 = "-";
  1812. pos++;
  1813. } else {
  1814. result1 = null;
  1815. if (reportFailures === 0) {
  1816. matchFailed("\"-\"");
  1817. }
  1818. }
  1819. if (result1 === null) {
  1820. if (input.charCodeAt(pos) === 46) {
  1821. result1 = ".";
  1822. pos++;
  1823. } else {
  1824. result1 = null;
  1825. if (reportFailures === 0) {
  1826. matchFailed("\".\"");
  1827. }
  1828. }
  1829. if (result1 === null) {
  1830. if (input.charCodeAt(pos) === 33) {
  1831. result1 = "!";
  1832. pos++;
  1833. } else {
  1834. result1 = null;
  1835. if (reportFailures === 0) {
  1836. matchFailed("\"!\"");
  1837. }
  1838. }
  1839. if (result1 === null) {
  1840. if (input.charCodeAt(pos) === 37) {
  1841. result1 = "%";
  1842. pos++;
  1843. } else {
  1844. result1 = null;
  1845. if (reportFailures === 0) {
  1846. matchFailed("\"%\"");
  1847. }
  1848. }
  1849. if (result1 === null) {
  1850. if (input.charCodeAt(pos) === 42) {
  1851. result1 = "*";
  1852. pos++;
  1853. } else {
  1854. result1 = null;
  1855. if (reportFailures === 0) {
  1856. matchFailed("\"*\"");
  1857. }
  1858. }
  1859. if (result1 === null) {
  1860. if (input.charCodeAt(pos) === 95) {
  1861. result1 = "_";
  1862. pos++;
  1863. } else {
  1864. result1 = null;
  1865. if (reportFailures === 0) {
  1866. matchFailed("\"_\"");
  1867. }
  1868. }
  1869. if (result1 === null) {
  1870. if (input.charCodeAt(pos) === 43) {
  1871. result1 = "+";
  1872. pos++;
  1873. } else {
  1874. result1 = null;
  1875. if (reportFailures === 0) {
  1876. matchFailed("\"+\"");
  1877. }
  1878. }
  1879. if (result1 === null) {
  1880. if (input.charCodeAt(pos) === 96) {
  1881. result1 = "`";
  1882. pos++;
  1883. } else {
  1884. result1 = null;
  1885. if (reportFailures === 0) {
  1886. matchFailed("\"`\"");
  1887. }
  1888. }
  1889. if (result1 === null) {
  1890. if (input.charCodeAt(pos) === 39) {
  1891. result1 = "'";
  1892. pos++;
  1893. } else {
  1894. result1 = null;
  1895. if (reportFailures === 0) {
  1896. matchFailed("\"'\"");
  1897. }
  1898. }
  1899. if (result1 === null) {
  1900. if (input.charCodeAt(pos) === 126) {
  1901. result1 = "~";
  1902. pos++;
  1903. } else {
  1904. result1 = null;
  1905. if (reportFailures === 0) {
  1906. matchFailed("\"~\"");
  1907. }
  1908. }
  1909. }
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }
  1917. }
  1918. }
  1919. if (result1 !== null) {
  1920. result0 = [];
  1921. while (result1 !== null) {
  1922. result0.push(result1);
  1923. result1 = parse_alphanum();
  1924. if (result1 === null) {
  1925. if (input.charCodeAt(pos) === 45) {
  1926. result1 = "-";
  1927. pos++;
  1928. } else {
  1929. result1 = null;
  1930. if (reportFailures === 0) {
  1931. matchFailed("\"-\"");
  1932. }
  1933. }
  1934. if (result1 === null) {
  1935. if (input.charCodeAt(pos) === 46) {
  1936. result1 = ".";
  1937. pos++;
  1938. } else {
  1939. result1 = null;
  1940. if (reportFailures === 0) {
  1941. matchFailed("\".\"");
  1942. }
  1943. }
  1944. if (result1 === null) {
  1945. if (input.charCodeAt(pos) === 33) {
  1946. result1 = "!";
  1947. pos++;
  1948. } else {
  1949. result1 = null;
  1950. if (reportFailures === 0) {
  1951. matchFailed("\"!\"");
  1952. }
  1953. }
  1954. if (result1 === null) {
  1955. if (input.charCodeAt(pos) === 37) {
  1956. result1 = "%";
  1957. pos++;
  1958. } else {
  1959. result1 = null;
  1960. if (reportFailures === 0) {
  1961. matchFailed("\"%\"");
  1962. }
  1963. }
  1964. if (result1 === null) {
  1965. if (input.charCodeAt(pos) === 42) {
  1966. result1 = "*";
  1967. pos++;
  1968. } else {
  1969. result1 = null;
  1970. if (reportFailures === 0) {
  1971. matchFailed("\"*\"");
  1972. }
  1973. }
  1974. if (result1 === null) {
  1975. if (input.charCodeAt(pos) === 95) {
  1976. result1 = "_";
  1977. pos++;
  1978. } else {
  1979. result1 = null;
  1980. if (reportFailures === 0) {
  1981. matchFailed("\"_\"");
  1982. }
  1983. }
  1984. if (result1 === null) {
  1985. if (input.charCodeAt(pos) === 43) {
  1986. result1 = "+";
  1987. pos++;
  1988. } else {
  1989. result1 = null;
  1990. if (reportFailures === 0) {
  1991. matchFailed("\"+\"");
  1992. }
  1993. }
  1994. if (result1 === null) {
  1995. if (input.charCodeAt(pos) === 96) {
  1996. result1 = "`";
  1997. pos++;
  1998. } else {
  1999. result1 = null;
  2000. if (reportFailures === 0) {
  2001. matchFailed("\"`\"");
  2002. }
  2003. }
  2004. if (result1 === null) {
  2005. if (input.charCodeAt(pos) === 39) {
  2006. result1 = "'";
  2007. pos++;
  2008. } else {
  2009. result1 = null;
  2010. if (reportFailures === 0) {
  2011. matchFailed("\"'\"");
  2012. }
  2013. }
  2014. if (result1 === null) {
  2015. if (input.charCodeAt(pos) === 126) {
  2016. result1 = "~";
  2017. pos++;
  2018. } else {
  2019. result1 = null;
  2020. if (reportFailures === 0) {
  2021. matchFailed("\"~\"");
  2022. }
  2023. }
  2024. }
  2025. }
  2026. }
  2027. }
  2028. }
  2029. }
  2030. }
  2031. }
  2032. }
  2033. }
  2034. }
  2035. } else {
  2036. result0 = null;
  2037. }
  2038. if (result0 !== null) {
  2039. result0 = function (offset) {
  2040. return input.substring(pos, offset);
  2041. }(pos0);
  2042. }
  2043. if (result0 === null) {
  2044. pos = pos0;
  2045. }
  2046. return result0;
  2047. }
  2048. function parse_token_nodot() {
  2049. var result0, result1;
  2050. var pos0;
  2051. pos0 = pos;
  2052. result1 = parse_alphanum();
  2053. if (result1 === null) {
  2054. if (input.charCodeAt(pos) === 45) {
  2055. result1 = "-";
  2056. pos++;
  2057. } else {
  2058. result1 = null;
  2059. if (reportFailures === 0) {
  2060. matchFailed("\"-\"");
  2061. }
  2062. }
  2063. if (result1 === null) {
  2064. if (input.charCodeAt(pos) === 33) {
  2065. result1 = "!";
  2066. pos++;
  2067. } else {
  2068. result1 = null;
  2069. if (reportFailures === 0) {
  2070. matchFailed("\"!\"");
  2071. }
  2072. }
  2073. if (result1 === null) {
  2074. if (input.charCodeAt(pos) === 37) {
  2075. result1 = "%";
  2076. pos++;
  2077. } else {
  2078. result1 = null;
  2079. if (reportFailures === 0) {
  2080. matchFailed("\"%\"");
  2081. }
  2082. }
  2083. if (result1 === null) {
  2084. if (input.charCodeAt(pos) === 42) {
  2085. result1 = "*";
  2086. pos++;
  2087. } else {
  2088. result1 = null;
  2089. if (reportFailures === 0) {
  2090. matchFailed("\"*\"");
  2091. }
  2092. }
  2093. if (result1 === null) {
  2094. if (input.charCodeAt(pos) === 95) {
  2095. result1 = "_";
  2096. pos++;
  2097. } else {
  2098. result1 = null;
  2099. if (reportFailures === 0) {
  2100. matchFailed("\"_\"");
  2101. }
  2102. }
  2103. if (result1 === null) {
  2104. if (input.charCodeAt(pos) === 43) {
  2105. result1 = "+";
  2106. pos++;
  2107. } else {
  2108. result1 = null;
  2109. if (reportFailures === 0) {
  2110. matchFailed("\"+\"");
  2111. }
  2112. }
  2113. if (result1 === null) {
  2114. if (input.charCodeAt(pos) === 96) {
  2115. result1 = "`";
  2116. pos++;
  2117. } else {
  2118. result1 = null;
  2119. if (reportFailures === 0) {
  2120. matchFailed("\"`\"");
  2121. }
  2122. }
  2123. if (result1 === null) {
  2124. if (input.charCodeAt(pos) === 39) {
  2125. result1 = "'";
  2126. pos++;
  2127. } else {
  2128. result1 = null;
  2129. if (reportFailures === 0) {
  2130. matchFailed("\"'\"");
  2131. }
  2132. }
  2133. if (result1 === null) {
  2134. if (input.charCodeAt(pos) === 126) {
  2135. result1 = "~";
  2136. pos++;
  2137. } else {
  2138. result1 = null;
  2139. if (reportFailures === 0) {
  2140. matchFailed("\"~\"");
  2141. }
  2142. }
  2143. }
  2144. }
  2145. }
  2146. }
  2147. }
  2148. }
  2149. }
  2150. }
  2151. }
  2152. if (result1 !== null) {
  2153. result0 = [];
  2154. while (result1 !== null) {
  2155. result0.push(result1);
  2156. result1 = parse_alphanum();
  2157. if (result1 === null) {
  2158. if (input.charCodeAt(pos) === 45) {
  2159. result1 = "-";
  2160. pos++;
  2161. } else {
  2162. result1 = null;
  2163. if (reportFailures === 0) {
  2164. matchFailed("\"-\"");
  2165. }
  2166. }
  2167. if (result1 === null) {
  2168. if (input.charCodeAt(pos) === 33) {
  2169. result1 = "!";
  2170. pos++;
  2171. } else {
  2172. result1 = null;
  2173. if (reportFailures === 0) {
  2174. matchFailed("\"!\"");
  2175. }
  2176. }
  2177. if (result1 === null) {
  2178. if (input.charCodeAt(pos) === 37) {
  2179. result1 = "%";
  2180. pos++;
  2181. } else {
  2182. result1 = null;
  2183. if (reportFailures === 0) {
  2184. matchFailed("\"%\"");
  2185. }
  2186. }
  2187. if (result1 === null) {
  2188. if (input.charCodeAt(pos) === 42) {
  2189. result1 = "*";
  2190. pos++;
  2191. } else {
  2192. result1 = null;
  2193. if (reportFailures === 0) {
  2194. matchFailed("\"*\"");
  2195. }
  2196. }
  2197. if (result1 === null) {
  2198. if (input.charCodeAt(pos) === 95) {
  2199. result1 = "_";
  2200. pos++;
  2201. } else {
  2202. result1 = null;
  2203. if (reportFailures === 0) {
  2204. matchFailed("\"_\"");
  2205. }
  2206. }
  2207. if (result1 === null) {
  2208. if (input.charCodeAt(pos) === 43) {
  2209. result1 = "+";
  2210. pos++;
  2211. } else {
  2212. result1 = null;
  2213. if (reportFailures === 0) {
  2214. matchFailed("\"+\"");
  2215. }
  2216. }
  2217. if (result1 === null) {
  2218. if (input.charCodeAt(pos) === 96) {
  2219. result1 = "`";
  2220. pos++;
  2221. } else {
  2222. result1 = null;
  2223. if (reportFailures === 0) {
  2224. matchFailed("\"`\"");
  2225. }
  2226. }
  2227. if (result1 === null) {
  2228. if (input.charCodeAt(pos) === 39) {
  2229. result1 = "'";
  2230. pos++;
  2231. } else {
  2232. result1 = null;
  2233. if (reportFailures === 0) {
  2234. matchFailed("\"'\"");
  2235. }
  2236. }
  2237. if (result1 === null) {
  2238. if (input.charCodeAt(pos) === 126) {
  2239. result1 = "~";
  2240. pos++;
  2241. } else {
  2242. result1 = null;
  2243. if (reportFailures === 0) {
  2244. matchFailed("\"~\"");
  2245. }
  2246. }
  2247. }
  2248. }
  2249. }
  2250. }
  2251. }
  2252. }
  2253. }
  2254. }
  2255. }
  2256. }
  2257. } else {
  2258. result0 = null;
  2259. }
  2260. if (result0 !== null) {
  2261. result0 = function (offset) {
  2262. return input.substring(pos, offset);
  2263. }(pos0);
  2264. }
  2265. if (result0 === null) {
  2266. pos = pos0;
  2267. }
  2268. return result0;
  2269. }
  2270. function parse_separators() {
  2271. var result0;
  2272. if (input.charCodeAt(pos) === 40) {
  2273. result0 = "(";
  2274. pos++;
  2275. } else {
  2276. result0 = null;
  2277. if (reportFailures === 0) {
  2278. matchFailed("\"(\"");
  2279. }
  2280. }
  2281. if (result0 === null) {
  2282. if (input.charCodeAt(pos) === 41) {
  2283. result0 = ")";
  2284. pos++;
  2285. } else {
  2286. result0 = null;
  2287. if (reportFailures === 0) {
  2288. matchFailed("\")\"");
  2289. }
  2290. }
  2291. if (result0 === null) {
  2292. if (input.charCodeAt(pos) === 60) {
  2293. result0 = "<";
  2294. pos++;
  2295. } else {
  2296. result0 = null;
  2297. if (reportFailures === 0) {
  2298. matchFailed("\"<\"");
  2299. }
  2300. }
  2301. if (result0 === null) {
  2302. if (input.charCodeAt(pos) === 62) {
  2303. result0 = ">";
  2304. pos++;
  2305. } else {
  2306. result0 = null;
  2307. if (reportFailures === 0) {
  2308. matchFailed("\">\"");
  2309. }
  2310. }
  2311. if (result0 === null) {
  2312. if (input.charCodeAt(pos) === 64) {
  2313. result0 = "@";
  2314. pos++;
  2315. } else {
  2316. result0 = null;
  2317. if (reportFailures === 0) {
  2318. matchFailed("\"@\"");
  2319. }
  2320. }
  2321. if (result0 === null) {
  2322. if (input.charCodeAt(pos) === 44) {
  2323. result0 = ",";
  2324. pos++;
  2325. } else {
  2326. result0 = null;
  2327. if (reportFailures === 0) {
  2328. matchFailed("\",\"");
  2329. }
  2330. }
  2331. if (result0 === null) {
  2332. if (input.charCodeAt(pos) === 59) {
  2333. result0 = ";";
  2334. pos++;
  2335. } else {
  2336. result0 = null;
  2337. if (reportFailures === 0) {
  2338. matchFailed("\";\"");
  2339. }
  2340. }
  2341. if (result0 === null) {
  2342. if (input.charCodeAt(pos) === 58) {
  2343. result0 = ":";
  2344. pos++;
  2345. } else {
  2346. result0 = null;
  2347. if (reportFailures === 0) {
  2348. matchFailed("\":\"");
  2349. }
  2350. }
  2351. if (result0 === null) {
  2352. if (input.charCodeAt(pos) === 92) {
  2353. result0 = "\\";
  2354. pos++;
  2355. } else {
  2356. result0 = null;
  2357. if (reportFailures === 0) {
  2358. matchFailed("\"\\\\\"");
  2359. }
  2360. }
  2361. if (result0 === null) {
  2362. result0 = parse_DQUOTE();
  2363. if (result0 === null) {
  2364. if (input.charCodeAt(pos) === 47) {
  2365. result0 = "/";
  2366. pos++;
  2367. } else {
  2368. result0 = null;
  2369. if (reportFailures === 0) {
  2370. matchFailed("\"/\"");
  2371. }
  2372. }
  2373. if (result0 === null) {
  2374. if (input.charCodeAt(pos) === 91) {
  2375. result0 = "[";
  2376. pos++;
  2377. } else {
  2378. result0 = null;
  2379. if (reportFailures === 0) {
  2380. matchFailed("\"[\"");
  2381. }
  2382. }
  2383. if (result0 === null) {
  2384. if (input.charCodeAt(pos) === 93) {
  2385. result0 = "]";
  2386. pos++;
  2387. } else {
  2388. result0 = null;
  2389. if (reportFailures === 0) {
  2390. matchFailed("\"]\"");
  2391. }
  2392. }
  2393. if (result0 === null) {
  2394. if (input.charCodeAt(pos) === 63) {
  2395. result0 = "?";
  2396. pos++;
  2397. } else {
  2398. result0 = null;
  2399. if (reportFailures === 0) {
  2400. matchFailed("\"?\"");
  2401. }
  2402. }
  2403. if (result0 === null) {
  2404. if (input.charCodeAt(pos) === 61) {
  2405. result0 = "=";
  2406. pos++;
  2407. } else {
  2408. result0 = null;
  2409. if (reportFailures === 0) {
  2410. matchFailed("\"=\"");
  2411. }
  2412. }
  2413. if (result0 === null) {
  2414. if (input.charCodeAt(pos) === 123) {
  2415. result0 = "{";
  2416. pos++;
  2417. } else {
  2418. result0 = null;
  2419. if (reportFailures === 0) {
  2420. matchFailed("\"{\"");
  2421. }
  2422. }
  2423. if (result0 === null) {
  2424. if (input.charCodeAt(pos) === 125) {
  2425. result0 = "}";
  2426. pos++;
  2427. } else {
  2428. result0 = null;
  2429. if (reportFailures === 0) {
  2430. matchFailed("\"}\"");
  2431. }
  2432. }
  2433. if (result0 === null) {
  2434. result0 = parse_SP();
  2435. if (result0 === null) {
  2436. result0 = parse_HTAB();
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. }
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. }
  2453. }
  2454. }
  2455. return result0;
  2456. }
  2457. function parse_word() {
  2458. var result0, result1;
  2459. var pos0;
  2460. pos0 = pos;
  2461. result1 = parse_alphanum();
  2462. if (result1 === null) {
  2463. if (input.charCodeAt(pos) === 45) {
  2464. result1 = "-";
  2465. pos++;
  2466. } else {
  2467. result1 = null;
  2468. if (reportFailures === 0) {
  2469. matchFailed("\"-\"");
  2470. }
  2471. }
  2472. if (result1 === null) {
  2473. if (input.charCodeAt(pos) === 46) {
  2474. result1 = ".";
  2475. pos++;
  2476. } else {
  2477. result1 = null;
  2478. if (reportFailures === 0) {
  2479. matchFailed("\".\"");
  2480. }
  2481. }
  2482. if (result1 === null) {
  2483. if (input.charCodeAt(pos) === 33) {
  2484. result1 = "!";
  2485. pos++;
  2486. } else {
  2487. result1 = null;
  2488. if (reportFailures === 0) {
  2489. matchFailed("\"!\"");
  2490. }
  2491. }
  2492. if (result1 === null) {
  2493. if (input.charCodeAt(pos) === 37) {
  2494. result1 = "%";
  2495. pos++;
  2496. } else {
  2497. result1 = null;
  2498. if (reportFailures === 0) {
  2499. matchFailed("\"%\"");
  2500. }
  2501. }
  2502. if (result1 === null) {
  2503. if (input.charCodeAt(pos) === 42) {
  2504. result1 = "*";
  2505. pos++;
  2506. } else {
  2507. result1 = null;
  2508. if (reportFailures === 0) {
  2509. matchFailed("\"*\"");
  2510. }
  2511. }
  2512. if (result1 === null) {
  2513. if (input.charCodeAt(pos) === 95) {
  2514. result1 = "_";
  2515. pos++;
  2516. } else {
  2517. result1 = null;
  2518. if (reportFailures === 0) {
  2519. matchFailed("\"_\"");
  2520. }
  2521. }
  2522. if (result1 === null) {
  2523. if (input.charCodeAt(pos) === 43) {
  2524. result1 = "+";
  2525. pos++;
  2526. } else {
  2527. result1 = null;
  2528. if (reportFailures === 0) {
  2529. matchFailed("\"+\"");
  2530. }
  2531. }
  2532. if (result1 === null) {
  2533. if (input.charCodeAt(pos) === 96) {
  2534. result1 = "`";
  2535. pos++;
  2536. } else {
  2537. result1 = null;
  2538. if (reportFailures === 0) {
  2539. matchFailed("\"`\"");
  2540. }
  2541. }
  2542. if (result1 === null) {
  2543. if (input.charCodeAt(pos) === 39) {
  2544. result1 = "'";
  2545. pos++;
  2546. } else {
  2547. result1 = null;
  2548. if (reportFailures === 0) {
  2549. matchFailed("\"'\"");
  2550. }
  2551. }
  2552. if (result1 === null) {
  2553. if (input.charCodeAt(pos) === 126) {
  2554. result1 = "~";
  2555. pos++;
  2556. } else {
  2557. result1 = null;
  2558. if (reportFailures === 0) {
  2559. matchFailed("\"~\"");
  2560. }
  2561. }
  2562. if (result1 === null) {
  2563. if (input.charCodeAt(pos) === 40) {
  2564. result1 = "(";
  2565. pos++;
  2566. } else {
  2567. result1 = null;
  2568. if (reportFailures === 0) {
  2569. matchFailed("\"(\"");
  2570. }
  2571. }
  2572. if (result1 === null) {
  2573. if (input.charCodeAt(pos) === 41) {
  2574. result1 = ")";
  2575. pos++;
  2576. } else {
  2577. result1 = null;
  2578. if (reportFailures === 0) {
  2579. matchFailed("\")\"");
  2580. }
  2581. }
  2582. if (result1 === null) {
  2583. if (input.charCodeAt(pos) === 60) {
  2584. result1 = "<";
  2585. pos++;
  2586. } else {
  2587. result1 = null;
  2588. if (reportFailures === 0) {
  2589. matchFailed("\"<\"");
  2590. }
  2591. }
  2592. if (result1 === null) {
  2593. if (input.charCodeAt(pos) === 62) {
  2594. result1 = ">";
  2595. pos++;
  2596. } else {
  2597. result1 = null;
  2598. if (reportFailures === 0) {
  2599. matchFailed("\">\"");
  2600. }
  2601. }
  2602. if (result1 === null) {
  2603. if (input.charCodeAt(pos) === 58) {
  2604. result1 = ":";
  2605. pos++;
  2606. } else {
  2607. result1 = null;
  2608. if (reportFailures === 0) {
  2609. matchFailed("\":\"");
  2610. }
  2611. }
  2612. if (result1 === null) {
  2613. if (input.charCodeAt(pos) === 92) {
  2614. result1 = "\\";
  2615. pos++;
  2616. } else {
  2617. result1 = null;
  2618. if (reportFailures === 0) {
  2619. matchFailed("\"\\\\\"");
  2620. }
  2621. }
  2622. if (result1 === null) {
  2623. result1 = parse_DQUOTE();
  2624. if (result1 === null) {
  2625. if (input.charCodeAt(pos) === 47) {
  2626. result1 = "/";
  2627. pos++;
  2628. } else {
  2629. result1 = null;
  2630. if (reportFailures === 0) {
  2631. matchFailed("\"/\"");
  2632. }
  2633. }
  2634. if (result1 === null) {
  2635. if (input.charCodeAt(pos) === 91) {
  2636. result1 = "[";
  2637. pos++;
  2638. } else {
  2639. result1 = null;
  2640. if (reportFailures === 0) {
  2641. matchFailed("\"[\"");
  2642. }
  2643. }
  2644. if (result1 === null) {
  2645. if (input.charCodeAt(pos) === 93) {
  2646. result1 = "]";
  2647. pos++;
  2648. } else {
  2649. result1 = null;
  2650. if (reportFailures === 0) {
  2651. matchFailed("\"]\"");
  2652. }
  2653. }
  2654. if (result1 === null) {
  2655. if (input.charCodeAt(pos) === 63) {
  2656. result1 = "?";
  2657. pos++;
  2658. } else {
  2659. result1 = null;
  2660. if (reportFailures === 0) {
  2661. matchFailed("\"?\"");
  2662. }
  2663. }
  2664. if (result1 === null) {
  2665. if (input.charCodeAt(pos) === 123) {
  2666. result1 = "{";
  2667. pos++;
  2668. } else {
  2669. result1 = null;
  2670. if (reportFailures === 0) {
  2671. matchFailed("\"{\"");
  2672. }
  2673. }
  2674. if (result1 === null) {
  2675. if (input.charCodeAt(pos) === 125) {
  2676. result1 = "}";
  2677. pos++;
  2678. } else {
  2679. result1 = null;
  2680. if (reportFailures === 0) {
  2681. matchFailed("\"}\"");
  2682. }
  2683. }
  2684. }
  2685. }
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. }
  2696. }
  2697. }
  2698. }
  2699. }
  2700. }
  2701. }
  2702. }
  2703. }
  2704. }
  2705. }
  2706. }
  2707. if (result1 !== null) {
  2708. result0 = [];
  2709. while (result1 !== null) {
  2710. result0.push(result1);
  2711. result1 = parse_alphanum();
  2712. if (result1 === null) {
  2713. if (input.charCodeAt(pos) === 45) {
  2714. result1 = "-";
  2715. pos++;
  2716. } else {
  2717. result1 = null;
  2718. if (reportFailures === 0) {
  2719. matchFailed("\"-\"");
  2720. }
  2721. }
  2722. if (result1 === null) {
  2723. if (input.charCodeAt(pos) === 46) {
  2724. result1 = ".";
  2725. pos++;
  2726. } else {
  2727. result1 = null;
  2728. if (reportFailures === 0) {
  2729. matchFailed("\".\"");
  2730. }
  2731. }
  2732. if (result1 === null) {
  2733. if (input.charCodeAt(pos) === 33) {
  2734. result1 = "!";
  2735. pos++;
  2736. } else {
  2737. result1 = null;
  2738. if (reportFailures === 0) {
  2739. matchFailed("\"!\"");
  2740. }
  2741. }
  2742. if (result1 === null) {
  2743. if (input.charCodeAt(pos) === 37) {
  2744. result1 = "%";
  2745. pos++;
  2746. } else {
  2747. result1 = null;
  2748. if (reportFailures === 0) {
  2749. matchFailed("\"%\"");
  2750. }
  2751. }
  2752. if (result1 === null) {
  2753. if (input.charCodeAt(pos) === 42) {
  2754. result1 = "*";
  2755. pos++;
  2756. } else {
  2757. result1 = null;
  2758. if (reportFailures === 0) {
  2759. matchFailed("\"*\"");
  2760. }
  2761. }
  2762. if (result1 === null) {
  2763. if (input.charCodeAt(pos) === 95) {
  2764. result1 = "_";
  2765. pos++;
  2766. } else {
  2767. result1 = null;
  2768. if (reportFailures === 0) {
  2769. matchFailed("\"_\"");
  2770. }
  2771. }
  2772. if (result1 === null) {
  2773. if (input.charCodeAt(pos) === 43) {
  2774. result1 = "+";
  2775. pos++;
  2776. } else {
  2777. result1 = null;
  2778. if (reportFailures === 0) {
  2779. matchFailed("\"+\"");
  2780. }
  2781. }
  2782. if (result1 === null) {
  2783. if (input.charCodeAt(pos) === 96) {
  2784. result1 = "`";
  2785. pos++;
  2786. } else {
  2787. result1 = null;
  2788. if (reportFailures === 0) {
  2789. matchFailed("\"`\"");
  2790. }
  2791. }
  2792. if (result1 === null) {
  2793. if (input.charCodeAt(pos) === 39) {
  2794. result1 = "'";
  2795. pos++;
  2796. } else {
  2797. result1 = null;
  2798. if (reportFailures === 0) {
  2799. matchFailed("\"'\"");
  2800. }
  2801. }
  2802. if (result1 === null) {
  2803. if (input.charCodeAt(pos) === 126) {
  2804. result1 = "~";
  2805. pos++;
  2806. } else {
  2807. result1 = null;
  2808. if (reportFailures === 0) {
  2809. matchFailed("\"~\"");
  2810. }
  2811. }
  2812. if (result1 === null) {
  2813. if (input.charCodeAt(pos) === 40) {
  2814. result1 = "(";
  2815. pos++;
  2816. } else {
  2817. result1 = null;
  2818. if (reportFailures === 0) {
  2819. matchFailed("\"(\"");
  2820. }
  2821. }
  2822. if (result1 === null) {
  2823. if (input.charCodeAt(pos) === 41) {
  2824. result1 = ")";
  2825. pos++;
  2826. } else {
  2827. result1 = null;
  2828. if (reportFailures === 0) {
  2829. matchFailed("\")\"");
  2830. }
  2831. }
  2832. if (result1 === null) {
  2833. if (input.charCodeAt(pos) === 60) {
  2834. result1 = "<";
  2835. pos++;
  2836. } else {
  2837. result1 = null;
  2838. if (reportFailures === 0) {
  2839. matchFailed("\"<\"");
  2840. }
  2841. }
  2842. if (result1 === null) {
  2843. if (input.charCodeAt(pos) === 62) {
  2844. result1 = ">";
  2845. pos++;
  2846. } else {
  2847. result1 = null;
  2848. if (reportFailures === 0) {
  2849. matchFailed("\">\"");
  2850. }
  2851. }
  2852. if (result1 === null) {
  2853. if (input.charCodeAt(pos) === 58) {
  2854. result1 = ":";
  2855. pos++;
  2856. } else {
  2857. result1 = null;
  2858. if (reportFailures === 0) {
  2859. matchFailed("\":\"");
  2860. }
  2861. }
  2862. if (result1 === null) {
  2863. if (input.charCodeAt(pos) === 92) {
  2864. result1 = "\\";
  2865. pos++;
  2866. } else {
  2867. result1 = null;
  2868. if (reportFailures === 0) {
  2869. matchFailed("\"\\\\\"");
  2870. }
  2871. }
  2872. if (result1 === null) {
  2873. result1 = parse_DQUOTE();
  2874. if (result1 === null) {
  2875. if (input.charCodeAt(pos) === 47) {
  2876. result1 = "/";
  2877. pos++;
  2878. } else {
  2879. result1 = null;
  2880. if (reportFailures === 0) {
  2881. matchFailed("\"/\"");
  2882. }
  2883. }
  2884. if (result1 === null) {
  2885. if (input.charCodeAt(pos) === 91) {
  2886. result1 = "[";
  2887. pos++;
  2888. } else {
  2889. result1 = null;
  2890. if (reportFailures === 0) {
  2891. matchFailed("\"[\"");
  2892. }
  2893. }
  2894. if (result1 === null) {
  2895. if (input.charCodeAt(pos) === 93) {
  2896. result1 = "]";
  2897. pos++;
  2898. } else {
  2899. result1 = null;
  2900. if (reportFailures === 0) {
  2901. matchFailed("\"]\"");
  2902. }
  2903. }
  2904. if (result1 === null) {
  2905. if (input.charCodeAt(pos) === 63) {
  2906. result1 = "?";
  2907. pos++;
  2908. } else {
  2909. result1 = null;
  2910. if (reportFailures === 0) {
  2911. matchFailed("\"?\"");
  2912. }
  2913. }
  2914. if (result1 === null) {
  2915. if (input.charCodeAt(pos) === 123) {
  2916. result1 = "{";
  2917. pos++;
  2918. } else {
  2919. result1 = null;
  2920. if (reportFailures === 0) {
  2921. matchFailed("\"{\"");
  2922. }
  2923. }
  2924. if (result1 === null) {
  2925. if (input.charCodeAt(pos) === 125) {
  2926. result1 = "}";
  2927. pos++;
  2928. } else {
  2929. result1 = null;
  2930. if (reportFailures === 0) {
  2931. matchFailed("\"}\"");
  2932. }
  2933. }
  2934. }
  2935. }
  2936. }
  2937. }
  2938. }
  2939. }
  2940. }
  2941. }
  2942. }
  2943. }
  2944. }
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. }
  2951. }
  2952. }
  2953. }
  2954. }
  2955. }
  2956. }
  2957. }
  2958. } else {
  2959. result0 = null;
  2960. }
  2961. if (result0 !== null) {
  2962. result0 = function (offset) {
  2963. return input.substring(pos, offset);
  2964. }(pos0);
  2965. }
  2966. if (result0 === null) {
  2967. pos = pos0;
  2968. }
  2969. return result0;
  2970. }
  2971. function parse_STAR() {
  2972. var result0, result1, result2;
  2973. var pos0, pos1;
  2974. pos0 = pos;
  2975. pos1 = pos;
  2976. result0 = parse_SWS();
  2977. if (result0 !== null) {
  2978. if (input.charCodeAt(pos) === 42) {
  2979. result1 = "*";
  2980. pos++;
  2981. } else {
  2982. result1 = null;
  2983. if (reportFailures === 0) {
  2984. matchFailed("\"*\"");
  2985. }
  2986. }
  2987. if (result1 !== null) {
  2988. result2 = parse_SWS();
  2989. if (result2 !== null) {
  2990. result0 = [result0, result1, result2];
  2991. } else {
  2992. result0 = null;
  2993. pos = pos1;
  2994. }
  2995. } else {
  2996. result0 = null;
  2997. pos = pos1;
  2998. }
  2999. } else {
  3000. result0 = null;
  3001. pos = pos1;
  3002. }
  3003. if (result0 !== null) {
  3004. result0 = function (offset) {
  3005. return "*";
  3006. }(pos0);
  3007. }
  3008. if (result0 === null) {
  3009. pos = pos0;
  3010. }
  3011. return result0;
  3012. }
  3013. function parse_SLASH() {
  3014. var result0, result1, result2;
  3015. var pos0, pos1;
  3016. pos0 = pos;
  3017. pos1 = pos;
  3018. result0 = parse_SWS();
  3019. if (result0 !== null) {
  3020. if (input.charCodeAt(pos) === 47) {
  3021. result1 = "/";
  3022. pos++;
  3023. } else {
  3024. result1 = null;
  3025. if (reportFailures === 0) {
  3026. matchFailed("\"/\"");
  3027. }
  3028. }
  3029. if (result1 !== null) {
  3030. result2 = parse_SWS();
  3031. if (result2 !== null) {
  3032. result0 = [result0, result1, result2];
  3033. } else {
  3034. result0 = null;
  3035. pos = pos1;
  3036. }
  3037. } else {
  3038. result0 = null;
  3039. pos = pos1;
  3040. }
  3041. } else {
  3042. result0 = null;
  3043. pos = pos1;
  3044. }
  3045. if (result0 !== null) {
  3046. result0 = function (offset) {
  3047. return "/";
  3048. }(pos0);
  3049. }
  3050. if (result0 === null) {
  3051. pos = pos0;
  3052. }
  3053. return result0;
  3054. }
  3055. function parse_EQUAL() {
  3056. var result0, result1, result2;
  3057. var pos0, pos1;
  3058. pos0 = pos;
  3059. pos1 = pos;
  3060. result0 = parse_SWS();
  3061. if (result0 !== null) {
  3062. if (input.charCodeAt(pos) === 61) {
  3063. result1 = "=";
  3064. pos++;
  3065. } else {
  3066. result1 = null;
  3067. if (reportFailures === 0) {
  3068. matchFailed("\"=\"");
  3069. }
  3070. }
  3071. if (result1 !== null) {
  3072. result2 = parse_SWS();
  3073. if (result2 !== null) {
  3074. result0 = [result0, result1, result2];
  3075. } else {
  3076. result0 = null;
  3077. pos = pos1;
  3078. }
  3079. } else {
  3080. result0 = null;
  3081. pos = pos1;
  3082. }
  3083. } else {
  3084. result0 = null;
  3085. pos = pos1;
  3086. }
  3087. if (result0 !== null) {
  3088. result0 = function (offset) {
  3089. return "=";
  3090. }(pos0);
  3091. }
  3092. if (result0 === null) {
  3093. pos = pos0;
  3094. }
  3095. return result0;
  3096. }
  3097. function parse_LPAREN() {
  3098. var result0, result1, result2;
  3099. var pos0, pos1;
  3100. pos0 = pos;
  3101. pos1 = pos;
  3102. result0 = parse_SWS();
  3103. if (result0 !== null) {
  3104. if (input.charCodeAt(pos) === 40) {
  3105. result1 = "(";
  3106. pos++;
  3107. } else {
  3108. result1 = null;
  3109. if (reportFailures === 0) {
  3110. matchFailed("\"(\"");
  3111. }
  3112. }
  3113. if (result1 !== null) {
  3114. result2 = parse_SWS();
  3115. if (result2 !== null) {
  3116. result0 = [result0, result1, result2];
  3117. } else {
  3118. result0 = null;
  3119. pos = pos1;
  3120. }
  3121. } else {
  3122. result0 = null;
  3123. pos = pos1;
  3124. }
  3125. } else {
  3126. result0 = null;
  3127. pos = pos1;
  3128. }
  3129. if (result0 !== null) {
  3130. result0 = function (offset) {
  3131. return "(";
  3132. }(pos0);
  3133. }
  3134. if (result0 === null) {
  3135. pos = pos0;
  3136. }
  3137. return result0;
  3138. }
  3139. function parse_RPAREN() {
  3140. var result0, result1, result2;
  3141. var pos0, pos1;
  3142. pos0 = pos;
  3143. pos1 = pos;
  3144. result0 = parse_SWS();
  3145. if (result0 !== null) {
  3146. if (input.charCodeAt(pos) === 41) {
  3147. result1 = ")";
  3148. pos++;
  3149. } else {
  3150. result1 = null;
  3151. if (reportFailures === 0) {
  3152. matchFailed("\")\"");
  3153. }
  3154. }
  3155. if (result1 !== null) {
  3156. result2 = parse_SWS();
  3157. if (result2 !== null) {
  3158. result0 = [result0, result1, result2];
  3159. } else {
  3160. result0 = null;
  3161. pos = pos1;
  3162. }
  3163. } else {
  3164. result0 = null;
  3165. pos = pos1;
  3166. }
  3167. } else {
  3168. result0 = null;
  3169. pos = pos1;
  3170. }
  3171. if (result0 !== null) {
  3172. result0 = function (offset) {
  3173. return ")";
  3174. }(pos0);
  3175. }
  3176. if (result0 === null) {
  3177. pos = pos0;
  3178. }
  3179. return result0;
  3180. }
  3181. function parse_RAQUOT() {
  3182. var result0, result1;
  3183. var pos0, pos1;
  3184. pos0 = pos;
  3185. pos1 = pos;
  3186. if (input.charCodeAt(pos) === 62) {
  3187. result0 = ">";
  3188. pos++;
  3189. } else {
  3190. result0 = null;
  3191. if (reportFailures === 0) {
  3192. matchFailed("\">\"");
  3193. }
  3194. }
  3195. if (result0 !== null) {
  3196. result1 = parse_SWS();
  3197. if (result1 !== null) {
  3198. result0 = [result0, result1];
  3199. } else {
  3200. result0 = null;
  3201. pos = pos1;
  3202. }
  3203. } else {
  3204. result0 = null;
  3205. pos = pos1;
  3206. }
  3207. if (result0 !== null) {
  3208. result0 = function (offset) {
  3209. return ">";
  3210. }(pos0);
  3211. }
  3212. if (result0 === null) {
  3213. pos = pos0;
  3214. }
  3215. return result0;
  3216. }
  3217. function parse_LAQUOT() {
  3218. var result0, result1;
  3219. var pos0, pos1;
  3220. pos0 = pos;
  3221. pos1 = pos;
  3222. result0 = parse_SWS();
  3223. if (result0 !== null) {
  3224. if (input.charCodeAt(pos) === 60) {
  3225. result1 = "<";
  3226. pos++;
  3227. } else {
  3228. result1 = null;
  3229. if (reportFailures === 0) {
  3230. matchFailed("\"<\"");
  3231. }
  3232. }
  3233. if (result1 !== null) {
  3234. result0 = [result0, result1];
  3235. } else {
  3236. result0 = null;
  3237. pos = pos1;
  3238. }
  3239. } else {
  3240. result0 = null;
  3241. pos = pos1;
  3242. }
  3243. if (result0 !== null) {
  3244. result0 = function (offset) {
  3245. return "<";
  3246. }(pos0);
  3247. }
  3248. if (result0 === null) {
  3249. pos = pos0;
  3250. }
  3251. return result0;
  3252. }
  3253. function parse_COMMA() {
  3254. var result0, result1, result2;
  3255. var pos0, pos1;
  3256. pos0 = pos;
  3257. pos1 = pos;
  3258. result0 = parse_SWS();
  3259. if (result0 !== null) {
  3260. if (input.charCodeAt(pos) === 44) {
  3261. result1 = ",";
  3262. pos++;
  3263. } else {
  3264. result1 = null;
  3265. if (reportFailures === 0) {
  3266. matchFailed("\",\"");
  3267. }
  3268. }
  3269. if (result1 !== null) {
  3270. result2 = parse_SWS();
  3271. if (result2 !== null) {
  3272. result0 = [result0, result1, result2];
  3273. } else {
  3274. result0 = null;
  3275. pos = pos1;
  3276. }
  3277. } else {
  3278. result0 = null;
  3279. pos = pos1;
  3280. }
  3281. } else {
  3282. result0 = null;
  3283. pos = pos1;
  3284. }
  3285. if (result0 !== null) {
  3286. result0 = function (offset) {
  3287. return ",";
  3288. }(pos0);
  3289. }
  3290. if (result0 === null) {
  3291. pos = pos0;
  3292. }
  3293. return result0;
  3294. }
  3295. function parse_SEMI() {
  3296. var result0, result1, result2;
  3297. var pos0, pos1;
  3298. pos0 = pos;
  3299. pos1 = pos;
  3300. result0 = parse_SWS();
  3301. if (result0 !== null) {
  3302. if (input.charCodeAt(pos) === 59) {
  3303. result1 = ";";
  3304. pos++;
  3305. } else {
  3306. result1 = null;
  3307. if (reportFailures === 0) {
  3308. matchFailed("\";\"");
  3309. }
  3310. }
  3311. if (result1 !== null) {
  3312. result2 = parse_SWS();
  3313. if (result2 !== null) {
  3314. result0 = [result0, result1, result2];
  3315. } else {
  3316. result0 = null;
  3317. pos = pos1;
  3318. }
  3319. } else {
  3320. result0 = null;
  3321. pos = pos1;
  3322. }
  3323. } else {
  3324. result0 = null;
  3325. pos = pos1;
  3326. }
  3327. if (result0 !== null) {
  3328. result0 = function (offset) {
  3329. return ";";
  3330. }(pos0);
  3331. }
  3332. if (result0 === null) {
  3333. pos = pos0;
  3334. }
  3335. return result0;
  3336. }
  3337. function parse_COLON() {
  3338. var result0, result1, result2;
  3339. var pos0, pos1;
  3340. pos0 = pos;
  3341. pos1 = pos;
  3342. result0 = parse_SWS();
  3343. if (result0 !== null) {
  3344. if (input.charCodeAt(pos) === 58) {
  3345. result1 = ":";
  3346. pos++;
  3347. } else {
  3348. result1 = null;
  3349. if (reportFailures === 0) {
  3350. matchFailed("\":\"");
  3351. }
  3352. }
  3353. if (result1 !== null) {
  3354. result2 = parse_SWS();
  3355. if (result2 !== null) {
  3356. result0 = [result0, result1, result2];
  3357. } else {
  3358. result0 = null;
  3359. pos = pos1;
  3360. }
  3361. } else {
  3362. result0 = null;
  3363. pos = pos1;
  3364. }
  3365. } else {
  3366. result0 = null;
  3367. pos = pos1;
  3368. }
  3369. if (result0 !== null) {
  3370. result0 = function (offset) {
  3371. return ":";
  3372. }(pos0);
  3373. }
  3374. if (result0 === null) {
  3375. pos = pos0;
  3376. }
  3377. return result0;
  3378. }
  3379. function parse_LDQUOT() {
  3380. var result0, result1;
  3381. var pos0, pos1;
  3382. pos0 = pos;
  3383. pos1 = pos;
  3384. result0 = parse_SWS();
  3385. if (result0 !== null) {
  3386. result1 = parse_DQUOTE();
  3387. if (result1 !== null) {
  3388. result0 = [result0, result1];
  3389. } else {
  3390. result0 = null;
  3391. pos = pos1;
  3392. }
  3393. } else {
  3394. result0 = null;
  3395. pos = pos1;
  3396. }
  3397. if (result0 !== null) {
  3398. result0 = function (offset) {
  3399. return "\"";
  3400. }(pos0);
  3401. }
  3402. if (result0 === null) {
  3403. pos = pos0;
  3404. }
  3405. return result0;
  3406. }
  3407. function parse_RDQUOT() {
  3408. var result0, result1;
  3409. var pos0, pos1;
  3410. pos0 = pos;
  3411. pos1 = pos;
  3412. result0 = parse_DQUOTE();
  3413. if (result0 !== null) {
  3414. result1 = parse_SWS();
  3415. if (result1 !== null) {
  3416. result0 = [result0, result1];
  3417. } else {
  3418. result0 = null;
  3419. pos = pos1;
  3420. }
  3421. } else {
  3422. result0 = null;
  3423. pos = pos1;
  3424. }
  3425. if (result0 !== null) {
  3426. result0 = function (offset) {
  3427. return "\"";
  3428. }(pos0);
  3429. }
  3430. if (result0 === null) {
  3431. pos = pos0;
  3432. }
  3433. return result0;
  3434. }
  3435. function parse_comment() {
  3436. var result0, result1, result2;
  3437. var pos0;
  3438. pos0 = pos;
  3439. result0 = parse_LPAREN();
  3440. if (result0 !== null) {
  3441. result1 = [];
  3442. result2 = parse_ctext();
  3443. if (result2 === null) {
  3444. result2 = parse_quoted_pair();
  3445. if (result2 === null) {
  3446. result2 = parse_comment();
  3447. }
  3448. }
  3449. while (result2 !== null) {
  3450. result1.push(result2);
  3451. result2 = parse_ctext();
  3452. if (result2 === null) {
  3453. result2 = parse_quoted_pair();
  3454. if (result2 === null) {
  3455. result2 = parse_comment();
  3456. }
  3457. }
  3458. }
  3459. if (result1 !== null) {
  3460. result2 = parse_RPAREN();
  3461. if (result2 !== null) {
  3462. result0 = [result0, result1, result2];
  3463. } else {
  3464. result0 = null;
  3465. pos = pos0;
  3466. }
  3467. } else {
  3468. result0 = null;
  3469. pos = pos0;
  3470. }
  3471. } else {
  3472. result0 = null;
  3473. pos = pos0;
  3474. }
  3475. return result0;
  3476. }
  3477. function parse_ctext() {
  3478. var result0;
  3479. if (/^[!-']/.test(input.charAt(pos))) {
  3480. result0 = input.charAt(pos);
  3481. pos++;
  3482. } else {
  3483. result0 = null;
  3484. if (reportFailures === 0) {
  3485. matchFailed("[!-']");
  3486. }
  3487. }
  3488. if (result0 === null) {
  3489. if (/^[*-[]/.test(input.charAt(pos))) {
  3490. result0 = input.charAt(pos);
  3491. pos++;
  3492. } else {
  3493. result0 = null;
  3494. if (reportFailures === 0) {
  3495. matchFailed("[*-[]");
  3496. }
  3497. }
  3498. if (result0 === null) {
  3499. if (/^[\]-~]/.test(input.charAt(pos))) {
  3500. result0 = input.charAt(pos);
  3501. pos++;
  3502. } else {
  3503. result0 = null;
  3504. if (reportFailures === 0) {
  3505. matchFailed("[\\]-~]");
  3506. }
  3507. }
  3508. if (result0 === null) {
  3509. result0 = parse_UTF8_NONASCII();
  3510. if (result0 === null) {
  3511. result0 = parse_LWS();
  3512. }
  3513. }
  3514. }
  3515. }
  3516. return result0;
  3517. }
  3518. function parse_quoted_string() {
  3519. var result0, result1, result2, result3;
  3520. var pos0, pos1;
  3521. pos0 = pos;
  3522. pos1 = pos;
  3523. result0 = parse_SWS();
  3524. if (result0 !== null) {
  3525. result1 = parse_DQUOTE();
  3526. if (result1 !== null) {
  3527. result2 = [];
  3528. result3 = parse_qdtext();
  3529. if (result3 === null) {
  3530. result3 = parse_quoted_pair();
  3531. }
  3532. while (result3 !== null) {
  3533. result2.push(result3);
  3534. result3 = parse_qdtext();
  3535. if (result3 === null) {
  3536. result3 = parse_quoted_pair();
  3537. }
  3538. }
  3539. if (result2 !== null) {
  3540. result3 = parse_DQUOTE();
  3541. if (result3 !== null) {
  3542. result0 = [result0, result1, result2, result3];
  3543. } else {
  3544. result0 = null;
  3545. pos = pos1;
  3546. }
  3547. } else {
  3548. result0 = null;
  3549. pos = pos1;
  3550. }
  3551. } else {
  3552. result0 = null;
  3553. pos = pos1;
  3554. }
  3555. } else {
  3556. result0 = null;
  3557. pos = pos1;
  3558. }
  3559. if (result0 !== null) {
  3560. result0 = function (offset) {
  3561. return input.substring(pos, offset);
  3562. }(pos0);
  3563. }
  3564. if (result0 === null) {
  3565. pos = pos0;
  3566. }
  3567. return result0;
  3568. }
  3569. function parse_quoted_string_clean() {
  3570. var result0, result1, result2, result3;
  3571. var pos0, pos1;
  3572. pos0 = pos;
  3573. pos1 = pos;
  3574. result0 = parse_SWS();
  3575. if (result0 !== null) {
  3576. result1 = parse_DQUOTE();
  3577. if (result1 !== null) {
  3578. result2 = [];
  3579. result3 = parse_qdtext();
  3580. if (result3 === null) {
  3581. result3 = parse_quoted_pair();
  3582. }
  3583. while (result3 !== null) {
  3584. result2.push(result3);
  3585. result3 = parse_qdtext();
  3586. if (result3 === null) {
  3587. result3 = parse_quoted_pair();
  3588. }
  3589. }
  3590. if (result2 !== null) {
  3591. result3 = parse_DQUOTE();
  3592. if (result3 !== null) {
  3593. result0 = [result0, result1, result2, result3];
  3594. } else {
  3595. result0 = null;
  3596. pos = pos1;
  3597. }
  3598. } else {
  3599. result0 = null;
  3600. pos = pos1;
  3601. }
  3602. } else {
  3603. result0 = null;
  3604. pos = pos1;
  3605. }
  3606. } else {
  3607. result0 = null;
  3608. pos = pos1;
  3609. }
  3610. if (result0 !== null) {
  3611. result0 = function (offset) {
  3612. return input.substring(pos - 1, offset + 1);
  3613. }(pos0);
  3614. }
  3615. if (result0 === null) {
  3616. pos = pos0;
  3617. }
  3618. return result0;
  3619. }
  3620. function parse_qdtext() {
  3621. var result0;
  3622. result0 = parse_LWS();
  3623. if (result0 === null) {
  3624. if (input.charCodeAt(pos) === 33) {
  3625. result0 = "!";
  3626. pos++;
  3627. } else {
  3628. result0 = null;
  3629. if (reportFailures === 0) {
  3630. matchFailed("\"!\"");
  3631. }
  3632. }
  3633. if (result0 === null) {
  3634. if (/^[#-[]/.test(input.charAt(pos))) {
  3635. result0 = input.charAt(pos);
  3636. pos++;
  3637. } else {
  3638. result0 = null;
  3639. if (reportFailures === 0) {
  3640. matchFailed("[#-[]");
  3641. }
  3642. }
  3643. if (result0 === null) {
  3644. if (/^[\]-~]/.test(input.charAt(pos))) {
  3645. result0 = input.charAt(pos);
  3646. pos++;
  3647. } else {
  3648. result0 = null;
  3649. if (reportFailures === 0) {
  3650. matchFailed("[\\]-~]");
  3651. }
  3652. }
  3653. if (result0 === null) {
  3654. result0 = parse_UTF8_NONASCII();
  3655. }
  3656. }
  3657. }
  3658. }
  3659. return result0;
  3660. }
  3661. function parse_quoted_pair() {
  3662. var result0, result1;
  3663. var pos0;
  3664. pos0 = pos;
  3665. if (input.charCodeAt(pos) === 92) {
  3666. result0 = "\\";
  3667. pos++;
  3668. } else {
  3669. result0 = null;
  3670. if (reportFailures === 0) {
  3671. matchFailed("\"\\\\\"");
  3672. }
  3673. }
  3674. if (result0 !== null) {
  3675. if (/^[\0-\t]/.test(input.charAt(pos))) {
  3676. result1 = input.charAt(pos);
  3677. pos++;
  3678. } else {
  3679. result1 = null;
  3680. if (reportFailures === 0) {
  3681. matchFailed("[\\0-\\t]");
  3682. }
  3683. }
  3684. if (result1 === null) {
  3685. if (/^[\x0B-\f]/.test(input.charAt(pos))) {
  3686. result1 = input.charAt(pos);
  3687. pos++;
  3688. } else {
  3689. result1 = null;
  3690. if (reportFailures === 0) {
  3691. matchFailed("[\\x0B-\\f]");
  3692. }
  3693. }
  3694. if (result1 === null) {
  3695. if (/^[\x0E-]/.test(input.charAt(pos))) {
  3696. result1 = input.charAt(pos);
  3697. pos++;
  3698. } else {
  3699. result1 = null;
  3700. if (reportFailures === 0) {
  3701. matchFailed("[\\x0E-]");
  3702. }
  3703. }
  3704. }
  3705. }
  3706. if (result1 !== null) {
  3707. result0 = [result0, result1];
  3708. } else {
  3709. result0 = null;
  3710. pos = pos0;
  3711. }
  3712. } else {
  3713. result0 = null;
  3714. pos = pos0;
  3715. }
  3716. return result0;
  3717. }
  3718. function parse_SIP_URI_noparams() {
  3719. var result0, result1, result2, result3;
  3720. var pos0, pos1;
  3721. pos0 = pos;
  3722. pos1 = pos;
  3723. result0 = parse_uri_scheme();
  3724. if (result0 !== null) {
  3725. if (input.charCodeAt(pos) === 58) {
  3726. result1 = ":";
  3727. pos++;
  3728. } else {
  3729. result1 = null;
  3730. if (reportFailures === 0) {
  3731. matchFailed("\":\"");
  3732. }
  3733. }
  3734. if (result1 !== null) {
  3735. result2 = parse_userinfo();
  3736. result2 = result2 !== null ? result2 : "";
  3737. if (result2 !== null) {
  3738. result3 = parse_hostport();
  3739. if (result3 !== null) {
  3740. result0 = [result0, result1, result2, result3];
  3741. } else {
  3742. result0 = null;
  3743. pos = pos1;
  3744. }
  3745. } else {
  3746. result0 = null;
  3747. pos = pos1;
  3748. }
  3749. } else {
  3750. result0 = null;
  3751. pos = pos1;
  3752. }
  3753. } else {
  3754. result0 = null;
  3755. pos = pos1;
  3756. }
  3757. if (result0 !== null) {
  3758. result0 = function (offset) {
  3759. try {
  3760. data.uri = new URI(data.scheme, data.user, data.host, data.port);
  3761. delete data.scheme;
  3762. delete data.user;
  3763. delete data.host;
  3764. delete data.host_type;
  3765. delete data.port;
  3766. } catch (e) {
  3767. data = -1;
  3768. }
  3769. }(pos0);
  3770. }
  3771. if (result0 === null) {
  3772. pos = pos0;
  3773. }
  3774. return result0;
  3775. }
  3776. function parse_SIP_URI() {
  3777. var result0, result1, result2, result3, result4, result5;
  3778. var pos0, pos1;
  3779. pos0 = pos;
  3780. pos1 = pos;
  3781. result0 = parse_uri_scheme();
  3782. if (result0 !== null) {
  3783. if (input.charCodeAt(pos) === 58) {
  3784. result1 = ":";
  3785. pos++;
  3786. } else {
  3787. result1 = null;
  3788. if (reportFailures === 0) {
  3789. matchFailed("\":\"");
  3790. }
  3791. }
  3792. if (result1 !== null) {
  3793. result2 = parse_userinfo();
  3794. result2 = result2 !== null ? result2 : "";
  3795. if (result2 !== null) {
  3796. result3 = parse_hostport();
  3797. if (result3 !== null) {
  3798. result4 = parse_uri_parameters();
  3799. if (result4 !== null) {
  3800. result5 = parse_headers();
  3801. result5 = result5 !== null ? result5 : "";
  3802. if (result5 !== null) {
  3803. result0 = [result0, result1, result2, result3, result4, result5];
  3804. } else {
  3805. result0 = null;
  3806. pos = pos1;
  3807. }
  3808. } else {
  3809. result0 = null;
  3810. pos = pos1;
  3811. }
  3812. } else {
  3813. result0 = null;
  3814. pos = pos1;
  3815. }
  3816. } else {
  3817. result0 = null;
  3818. pos = pos1;
  3819. }
  3820. } else {
  3821. result0 = null;
  3822. pos = pos1;
  3823. }
  3824. } else {
  3825. result0 = null;
  3826. pos = pos1;
  3827. }
  3828. if (result0 !== null) {
  3829. result0 = function (offset) {
  3830. var header;
  3831. try {
  3832. data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers);
  3833. delete data.scheme;
  3834. delete data.user;
  3835. delete data.host;
  3836. delete data.host_type;
  3837. delete data.port;
  3838. delete data.uri_params;
  3839. if (startRule === 'SIP_URI') {
  3840. data = data.uri;
  3841. }
  3842. } catch (e) {
  3843. data = -1;
  3844. }
  3845. }(pos0);
  3846. }
  3847. if (result0 === null) {
  3848. pos = pos0;
  3849. }
  3850. return result0;
  3851. }
  3852. function parse_uri_scheme() {
  3853. var result0;
  3854. result0 = parse_uri_scheme_sips();
  3855. if (result0 === null) {
  3856. result0 = parse_uri_scheme_sip();
  3857. }
  3858. return result0;
  3859. }
  3860. function parse_uri_scheme_sips() {
  3861. var result0;
  3862. var pos0;
  3863. pos0 = pos;
  3864. if (input.substr(pos, 4).toLowerCase() === "sips") {
  3865. result0 = input.substr(pos, 4);
  3866. pos += 4;
  3867. } else {
  3868. result0 = null;
  3869. if (reportFailures === 0) {
  3870. matchFailed("\"sips\"");
  3871. }
  3872. }
  3873. if (result0 !== null) {
  3874. result0 = function (offset, scheme) {
  3875. data.scheme = scheme.toLowerCase();
  3876. }(pos0, result0);
  3877. }
  3878. if (result0 === null) {
  3879. pos = pos0;
  3880. }
  3881. return result0;
  3882. }
  3883. function parse_uri_scheme_sip() {
  3884. var result0;
  3885. var pos0;
  3886. pos0 = pos;
  3887. if (input.substr(pos, 3).toLowerCase() === "sip") {
  3888. result0 = input.substr(pos, 3);
  3889. pos += 3;
  3890. } else {
  3891. result0 = null;
  3892. if (reportFailures === 0) {
  3893. matchFailed("\"sip\"");
  3894. }
  3895. }
  3896. if (result0 !== null) {
  3897. result0 = function (offset, scheme) {
  3898. data.scheme = scheme.toLowerCase();
  3899. }(pos0, result0);
  3900. }
  3901. if (result0 === null) {
  3902. pos = pos0;
  3903. }
  3904. return result0;
  3905. }
  3906. function parse_userinfo() {
  3907. var result0, result1, result2;
  3908. var pos0, pos1, pos2;
  3909. pos0 = pos;
  3910. pos1 = pos;
  3911. result0 = parse_user();
  3912. if (result0 !== null) {
  3913. pos2 = pos;
  3914. if (input.charCodeAt(pos) === 58) {
  3915. result1 = ":";
  3916. pos++;
  3917. } else {
  3918. result1 = null;
  3919. if (reportFailures === 0) {
  3920. matchFailed("\":\"");
  3921. }
  3922. }
  3923. if (result1 !== null) {
  3924. result2 = parse_password();
  3925. if (result2 !== null) {
  3926. result1 = [result1, result2];
  3927. } else {
  3928. result1 = null;
  3929. pos = pos2;
  3930. }
  3931. } else {
  3932. result1 = null;
  3933. pos = pos2;
  3934. }
  3935. result1 = result1 !== null ? result1 : "";
  3936. if (result1 !== null) {
  3937. if (input.charCodeAt(pos) === 64) {
  3938. result2 = "@";
  3939. pos++;
  3940. } else {
  3941. result2 = null;
  3942. if (reportFailures === 0) {
  3943. matchFailed("\"@\"");
  3944. }
  3945. }
  3946. if (result2 !== null) {
  3947. result0 = [result0, result1, result2];
  3948. } else {
  3949. result0 = null;
  3950. pos = pos1;
  3951. }
  3952. } else {
  3953. result0 = null;
  3954. pos = pos1;
  3955. }
  3956. } else {
  3957. result0 = null;
  3958. pos = pos1;
  3959. }
  3960. if (result0 !== null) {
  3961. result0 = function (offset) {
  3962. data.user = decodeURIComponent(input.substring(pos - 1, offset));
  3963. }(pos0);
  3964. }
  3965. if (result0 === null) {
  3966. pos = pos0;
  3967. }
  3968. return result0;
  3969. }
  3970. function parse_user() {
  3971. var result0, result1;
  3972. result1 = parse_unreserved();
  3973. if (result1 === null) {
  3974. result1 = parse_escaped();
  3975. if (result1 === null) {
  3976. result1 = parse_user_unreserved();
  3977. }
  3978. }
  3979. if (result1 !== null) {
  3980. result0 = [];
  3981. while (result1 !== null) {
  3982. result0.push(result1);
  3983. result1 = parse_unreserved();
  3984. if (result1 === null) {
  3985. result1 = parse_escaped();
  3986. if (result1 === null) {
  3987. result1 = parse_user_unreserved();
  3988. }
  3989. }
  3990. }
  3991. } else {
  3992. result0 = null;
  3993. }
  3994. return result0;
  3995. }
  3996. function parse_user_unreserved() {
  3997. var result0;
  3998. if (input.charCodeAt(pos) === 38) {
  3999. result0 = "&";
  4000. pos++;
  4001. } else {
  4002. result0 = null;
  4003. if (reportFailures === 0) {
  4004. matchFailed("\"&\"");
  4005. }
  4006. }
  4007. if (result0 === null) {
  4008. if (input.charCodeAt(pos) === 61) {
  4009. result0 = "=";
  4010. pos++;
  4011. } else {
  4012. result0 = null;
  4013. if (reportFailures === 0) {
  4014. matchFailed("\"=\"");
  4015. }
  4016. }
  4017. if (result0 === null) {
  4018. if (input.charCodeAt(pos) === 43) {
  4019. result0 = "+";
  4020. pos++;
  4021. } else {
  4022. result0 = null;
  4023. if (reportFailures === 0) {
  4024. matchFailed("\"+\"");
  4025. }
  4026. }
  4027. if (result0 === null) {
  4028. if (input.charCodeAt(pos) === 36) {
  4029. result0 = "$";
  4030. pos++;
  4031. } else {
  4032. result0 = null;
  4033. if (reportFailures === 0) {
  4034. matchFailed("\"$\"");
  4035. }
  4036. }
  4037. if (result0 === null) {
  4038. if (input.charCodeAt(pos) === 44) {
  4039. result0 = ",";
  4040. pos++;
  4041. } else {
  4042. result0 = null;
  4043. if (reportFailures === 0) {
  4044. matchFailed("\",\"");
  4045. }
  4046. }
  4047. if (result0 === null) {
  4048. if (input.charCodeAt(pos) === 59) {
  4049. result0 = ";";
  4050. pos++;
  4051. } else {
  4052. result0 = null;
  4053. if (reportFailures === 0) {
  4054. matchFailed("\";\"");
  4055. }
  4056. }
  4057. if (result0 === null) {
  4058. if (input.charCodeAt(pos) === 63) {
  4059. result0 = "?";
  4060. pos++;
  4061. } else {
  4062. result0 = null;
  4063. if (reportFailures === 0) {
  4064. matchFailed("\"?\"");
  4065. }
  4066. }
  4067. if (result0 === null) {
  4068. if (input.charCodeAt(pos) === 47) {
  4069. result0 = "/";
  4070. pos++;
  4071. } else {
  4072. result0 = null;
  4073. if (reportFailures === 0) {
  4074. matchFailed("\"/\"");
  4075. }
  4076. }
  4077. }
  4078. }
  4079. }
  4080. }
  4081. }
  4082. }
  4083. }
  4084. return result0;
  4085. }
  4086. function parse_password() {
  4087. var result0, result1;
  4088. var pos0;
  4089. pos0 = pos;
  4090. result0 = [];
  4091. result1 = parse_unreserved();
  4092. if (result1 === null) {
  4093. result1 = parse_escaped();
  4094. if (result1 === null) {
  4095. if (input.charCodeAt(pos) === 38) {
  4096. result1 = "&";
  4097. pos++;
  4098. } else {
  4099. result1 = null;
  4100. if (reportFailures === 0) {
  4101. matchFailed("\"&\"");
  4102. }
  4103. }
  4104. if (result1 === null) {
  4105. if (input.charCodeAt(pos) === 61) {
  4106. result1 = "=";
  4107. pos++;
  4108. } else {
  4109. result1 = null;
  4110. if (reportFailures === 0) {
  4111. matchFailed("\"=\"");
  4112. }
  4113. }
  4114. if (result1 === null) {
  4115. if (input.charCodeAt(pos) === 43) {
  4116. result1 = "+";
  4117. pos++;
  4118. } else {
  4119. result1 = null;
  4120. if (reportFailures === 0) {
  4121. matchFailed("\"+\"");
  4122. }
  4123. }
  4124. if (result1 === null) {
  4125. if (input.charCodeAt(pos) === 36) {
  4126. result1 = "$";
  4127. pos++;
  4128. } else {
  4129. result1 = null;
  4130. if (reportFailures === 0) {
  4131. matchFailed("\"$\"");
  4132. }
  4133. }
  4134. if (result1 === null) {
  4135. if (input.charCodeAt(pos) === 44) {
  4136. result1 = ",";
  4137. pos++;
  4138. } else {
  4139. result1 = null;
  4140. if (reportFailures === 0) {
  4141. matchFailed("\",\"");
  4142. }
  4143. }
  4144. }
  4145. }
  4146. }
  4147. }
  4148. }
  4149. }
  4150. while (result1 !== null) {
  4151. result0.push(result1);
  4152. result1 = parse_unreserved();
  4153. if (result1 === null) {
  4154. result1 = parse_escaped();
  4155. if (result1 === null) {
  4156. if (input.charCodeAt(pos) === 38) {
  4157. result1 = "&";
  4158. pos++;
  4159. } else {
  4160. result1 = null;
  4161. if (reportFailures === 0) {
  4162. matchFailed("\"&\"");
  4163. }
  4164. }
  4165. if (result1 === null) {
  4166. if (input.charCodeAt(pos) === 61) {
  4167. result1 = "=";
  4168. pos++;
  4169. } else {
  4170. result1 = null;
  4171. if (reportFailures === 0) {
  4172. matchFailed("\"=\"");
  4173. }
  4174. }
  4175. if (result1 === null) {
  4176. if (input.charCodeAt(pos) === 43) {
  4177. result1 = "+";
  4178. pos++;
  4179. } else {
  4180. result1 = null;
  4181. if (reportFailures === 0) {
  4182. matchFailed("\"+\"");
  4183. }
  4184. }
  4185. if (result1 === null) {
  4186. if (input.charCodeAt(pos) === 36) {
  4187. result1 = "$";
  4188. pos++;
  4189. } else {
  4190. result1 = null;
  4191. if (reportFailures === 0) {
  4192. matchFailed("\"$\"");
  4193. }
  4194. }
  4195. if (result1 === null) {
  4196. if (input.charCodeAt(pos) === 44) {
  4197. result1 = ",";
  4198. pos++;
  4199. } else {
  4200. result1 = null;
  4201. if (reportFailures === 0) {
  4202. matchFailed("\",\"");
  4203. }
  4204. }
  4205. }
  4206. }
  4207. }
  4208. }
  4209. }
  4210. }
  4211. }
  4212. if (result0 !== null) {
  4213. result0 = function (offset) {
  4214. data.password = input.substring(pos, offset);
  4215. }(pos0);
  4216. }
  4217. if (result0 === null) {
  4218. pos = pos0;
  4219. }
  4220. return result0;
  4221. }
  4222. function parse_hostport() {
  4223. var result0, result1, result2;
  4224. var pos0, pos1;
  4225. pos0 = pos;
  4226. result0 = parse_host();
  4227. if (result0 !== null) {
  4228. pos1 = pos;
  4229. if (input.charCodeAt(pos) === 58) {
  4230. result1 = ":";
  4231. pos++;
  4232. } else {
  4233. result1 = null;
  4234. if (reportFailures === 0) {
  4235. matchFailed("\":\"");
  4236. }
  4237. }
  4238. if (result1 !== null) {
  4239. result2 = parse_port();
  4240. if (result2 !== null) {
  4241. result1 = [result1, result2];
  4242. } else {
  4243. result1 = null;
  4244. pos = pos1;
  4245. }
  4246. } else {
  4247. result1 = null;
  4248. pos = pos1;
  4249. }
  4250. result1 = result1 !== null ? result1 : "";
  4251. if (result1 !== null) {
  4252. result0 = [result0, result1];
  4253. } else {
  4254. result0 = null;
  4255. pos = pos0;
  4256. }
  4257. } else {
  4258. result0 = null;
  4259. pos = pos0;
  4260. }
  4261. return result0;
  4262. }
  4263. function parse_host() {
  4264. var result0;
  4265. var pos0;
  4266. pos0 = pos;
  4267. result0 = parse_hostname();
  4268. if (result0 === null) {
  4269. result0 = parse_IPv4address();
  4270. if (result0 === null) {
  4271. result0 = parse_IPv6reference();
  4272. }
  4273. }
  4274. if (result0 !== null) {
  4275. result0 = function (offset) {
  4276. data.host = input.substring(pos, offset).toLowerCase();
  4277. return data.host;
  4278. }(pos0);
  4279. }
  4280. if (result0 === null) {
  4281. pos = pos0;
  4282. }
  4283. return result0;
  4284. }
  4285. function parse_hostname() {
  4286. var result0, result1, result2;
  4287. var pos0, pos1, pos2;
  4288. pos0 = pos;
  4289. pos1 = pos;
  4290. result0 = [];
  4291. pos2 = pos;
  4292. result1 = parse_domainlabel();
  4293. if (result1 !== null) {
  4294. if (input.charCodeAt(pos) === 46) {
  4295. result2 = ".";
  4296. pos++;
  4297. } else {
  4298. result2 = null;
  4299. if (reportFailures === 0) {
  4300. matchFailed("\".\"");
  4301. }
  4302. }
  4303. if (result2 !== null) {
  4304. result1 = [result1, result2];
  4305. } else {
  4306. result1 = null;
  4307. pos = pos2;
  4308. }
  4309. } else {
  4310. result1 = null;
  4311. pos = pos2;
  4312. }
  4313. while (result1 !== null) {
  4314. result0.push(result1);
  4315. pos2 = pos;
  4316. result1 = parse_domainlabel();
  4317. if (result1 !== null) {
  4318. if (input.charCodeAt(pos) === 46) {
  4319. result2 = ".";
  4320. pos++;
  4321. } else {
  4322. result2 = null;
  4323. if (reportFailures === 0) {
  4324. matchFailed("\".\"");
  4325. }
  4326. }
  4327. if (result2 !== null) {
  4328. result1 = [result1, result2];
  4329. } else {
  4330. result1 = null;
  4331. pos = pos2;
  4332. }
  4333. } else {
  4334. result1 = null;
  4335. pos = pos2;
  4336. }
  4337. }
  4338. if (result0 !== null) {
  4339. result1 = parse_toplabel();
  4340. if (result1 !== null) {
  4341. if (input.charCodeAt(pos) === 46) {
  4342. result2 = ".";
  4343. pos++;
  4344. } else {
  4345. result2 = null;
  4346. if (reportFailures === 0) {
  4347. matchFailed("\".\"");
  4348. }
  4349. }
  4350. result2 = result2 !== null ? result2 : "";
  4351. if (result2 !== null) {
  4352. result0 = [result0, result1, result2];
  4353. } else {
  4354. result0 = null;
  4355. pos = pos1;
  4356. }
  4357. } else {
  4358. result0 = null;
  4359. pos = pos1;
  4360. }
  4361. } else {
  4362. result0 = null;
  4363. pos = pos1;
  4364. }
  4365. if (result0 !== null) {
  4366. result0 = function (offset) {
  4367. data.host_type = 'domain';
  4368. return input.substring(pos, offset);
  4369. }(pos0);
  4370. }
  4371. if (result0 === null) {
  4372. pos = pos0;
  4373. }
  4374. return result0;
  4375. }
  4376. function parse_domainlabel() {
  4377. var result0, result1, result2;
  4378. var pos0;
  4379. pos0 = pos;
  4380. result0 = parse_alphanum();
  4381. if (result0 !== null) {
  4382. result1 = [];
  4383. result2 = parse_alphanum();
  4384. if (result2 === null) {
  4385. if (input.charCodeAt(pos) === 45) {
  4386. result2 = "-";
  4387. pos++;
  4388. } else {
  4389. result2 = null;
  4390. if (reportFailures === 0) {
  4391. matchFailed("\"-\"");
  4392. }
  4393. }
  4394. if (result2 === null) {
  4395. if (input.charCodeAt(pos) === 95) {
  4396. result2 = "_";
  4397. pos++;
  4398. } else {
  4399. result2 = null;
  4400. if (reportFailures === 0) {
  4401. matchFailed("\"_\"");
  4402. }
  4403. }
  4404. }
  4405. }
  4406. while (result2 !== null) {
  4407. result1.push(result2);
  4408. result2 = parse_alphanum();
  4409. if (result2 === null) {
  4410. if (input.charCodeAt(pos) === 45) {
  4411. result2 = "-";
  4412. pos++;
  4413. } else {
  4414. result2 = null;
  4415. if (reportFailures === 0) {
  4416. matchFailed("\"-\"");
  4417. }
  4418. }
  4419. if (result2 === null) {
  4420. if (input.charCodeAt(pos) === 95) {
  4421. result2 = "_";
  4422. pos++;
  4423. } else {
  4424. result2 = null;
  4425. if (reportFailures === 0) {
  4426. matchFailed("\"_\"");
  4427. }
  4428. }
  4429. }
  4430. }
  4431. }
  4432. if (result1 !== null) {
  4433. result0 = [result0, result1];
  4434. } else {
  4435. result0 = null;
  4436. pos = pos0;
  4437. }
  4438. } else {
  4439. result0 = null;
  4440. pos = pos0;
  4441. }
  4442. return result0;
  4443. }
  4444. function parse_toplabel() {
  4445. var result0, result1, result2;
  4446. var pos0;
  4447. pos0 = pos;
  4448. result0 = parse_ALPHA();
  4449. if (result0 !== null) {
  4450. result1 = [];
  4451. result2 = parse_alphanum();
  4452. if (result2 === null) {
  4453. if (input.charCodeAt(pos) === 45) {
  4454. result2 = "-";
  4455. pos++;
  4456. } else {
  4457. result2 = null;
  4458. if (reportFailures === 0) {
  4459. matchFailed("\"-\"");
  4460. }
  4461. }
  4462. if (result2 === null) {
  4463. if (input.charCodeAt(pos) === 95) {
  4464. result2 = "_";
  4465. pos++;
  4466. } else {
  4467. result2 = null;
  4468. if (reportFailures === 0) {
  4469. matchFailed("\"_\"");
  4470. }
  4471. }
  4472. }
  4473. }
  4474. while (result2 !== null) {
  4475. result1.push(result2);
  4476. result2 = parse_alphanum();
  4477. if (result2 === null) {
  4478. if (input.charCodeAt(pos) === 45) {
  4479. result2 = "-";
  4480. pos++;
  4481. } else {
  4482. result2 = null;
  4483. if (reportFailures === 0) {
  4484. matchFailed("\"-\"");
  4485. }
  4486. }
  4487. if (result2 === null) {
  4488. if (input.charCodeAt(pos) === 95) {
  4489. result2 = "_";
  4490. pos++;
  4491. } else {
  4492. result2 = null;
  4493. if (reportFailures === 0) {
  4494. matchFailed("\"_\"");
  4495. }
  4496. }
  4497. }
  4498. }
  4499. }
  4500. if (result1 !== null) {
  4501. result0 = [result0, result1];
  4502. } else {
  4503. result0 = null;
  4504. pos = pos0;
  4505. }
  4506. } else {
  4507. result0 = null;
  4508. pos = pos0;
  4509. }
  4510. return result0;
  4511. }
  4512. function parse_IPv6reference() {
  4513. var result0, result1, result2;
  4514. var pos0, pos1;
  4515. pos0 = pos;
  4516. pos1 = pos;
  4517. if (input.charCodeAt(pos) === 91) {
  4518. result0 = "[";
  4519. pos++;
  4520. } else {
  4521. result0 = null;
  4522. if (reportFailures === 0) {
  4523. matchFailed("\"[\"");
  4524. }
  4525. }
  4526. if (result0 !== null) {
  4527. result1 = parse_IPv6address();
  4528. if (result1 !== null) {
  4529. if (input.charCodeAt(pos) === 93) {
  4530. result2 = "]";
  4531. pos++;
  4532. } else {
  4533. result2 = null;
  4534. if (reportFailures === 0) {
  4535. matchFailed("\"]\"");
  4536. }
  4537. }
  4538. if (result2 !== null) {
  4539. result0 = [result0, result1, result2];
  4540. } else {
  4541. result0 = null;
  4542. pos = pos1;
  4543. }
  4544. } else {
  4545. result0 = null;
  4546. pos = pos1;
  4547. }
  4548. } else {
  4549. result0 = null;
  4550. pos = pos1;
  4551. }
  4552. if (result0 !== null) {
  4553. result0 = function (offset) {
  4554. data.host_type = 'IPv6';
  4555. return input.substring(pos, offset);
  4556. }(pos0);
  4557. }
  4558. if (result0 === null) {
  4559. pos = pos0;
  4560. }
  4561. return result0;
  4562. }
  4563. function parse_IPv6address() {
  4564. var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12;
  4565. var pos0, pos1, pos2;
  4566. pos0 = pos;
  4567. pos1 = pos;
  4568. result0 = parse_h16();
  4569. if (result0 !== null) {
  4570. if (input.charCodeAt(pos) === 58) {
  4571. result1 = ":";
  4572. pos++;
  4573. } else {
  4574. result1 = null;
  4575. if (reportFailures === 0) {
  4576. matchFailed("\":\"");
  4577. }
  4578. }
  4579. if (result1 !== null) {
  4580. result2 = parse_h16();
  4581. if (result2 !== null) {
  4582. if (input.charCodeAt(pos) === 58) {
  4583. result3 = ":";
  4584. pos++;
  4585. } else {
  4586. result3 = null;
  4587. if (reportFailures === 0) {
  4588. matchFailed("\":\"");
  4589. }
  4590. }
  4591. if (result3 !== null) {
  4592. result4 = parse_h16();
  4593. if (result4 !== null) {
  4594. if (input.charCodeAt(pos) === 58) {
  4595. result5 = ":";
  4596. pos++;
  4597. } else {
  4598. result5 = null;
  4599. if (reportFailures === 0) {
  4600. matchFailed("\":\"");
  4601. }
  4602. }
  4603. if (result5 !== null) {
  4604. result6 = parse_h16();
  4605. if (result6 !== null) {
  4606. if (input.charCodeAt(pos) === 58) {
  4607. result7 = ":";
  4608. pos++;
  4609. } else {
  4610. result7 = null;
  4611. if (reportFailures === 0) {
  4612. matchFailed("\":\"");
  4613. }
  4614. }
  4615. if (result7 !== null) {
  4616. result8 = parse_h16();
  4617. if (result8 !== null) {
  4618. if (input.charCodeAt(pos) === 58) {
  4619. result9 = ":";
  4620. pos++;
  4621. } else {
  4622. result9 = null;
  4623. if (reportFailures === 0) {
  4624. matchFailed("\":\"");
  4625. }
  4626. }
  4627. if (result9 !== null) {
  4628. result10 = parse_h16();
  4629. if (result10 !== null) {
  4630. if (input.charCodeAt(pos) === 58) {
  4631. result11 = ":";
  4632. pos++;
  4633. } else {
  4634. result11 = null;
  4635. if (reportFailures === 0) {
  4636. matchFailed("\":\"");
  4637. }
  4638. }
  4639. if (result11 !== null) {
  4640. result12 = parse_ls32();
  4641. if (result12 !== null) {
  4642. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
  4643. } else {
  4644. result0 = null;
  4645. pos = pos1;
  4646. }
  4647. } else {
  4648. result0 = null;
  4649. pos = pos1;
  4650. }
  4651. } else {
  4652. result0 = null;
  4653. pos = pos1;
  4654. }
  4655. } else {
  4656. result0 = null;
  4657. pos = pos1;
  4658. }
  4659. } else {
  4660. result0 = null;
  4661. pos = pos1;
  4662. }
  4663. } else {
  4664. result0 = null;
  4665. pos = pos1;
  4666. }
  4667. } else {
  4668. result0 = null;
  4669. pos = pos1;
  4670. }
  4671. } else {
  4672. result0 = null;
  4673. pos = pos1;
  4674. }
  4675. } else {
  4676. result0 = null;
  4677. pos = pos1;
  4678. }
  4679. } else {
  4680. result0 = null;
  4681. pos = pos1;
  4682. }
  4683. } else {
  4684. result0 = null;
  4685. pos = pos1;
  4686. }
  4687. } else {
  4688. result0 = null;
  4689. pos = pos1;
  4690. }
  4691. } else {
  4692. result0 = null;
  4693. pos = pos1;
  4694. }
  4695. if (result0 === null) {
  4696. pos1 = pos;
  4697. if (input.substr(pos, 2) === "::") {
  4698. result0 = "::";
  4699. pos += 2;
  4700. } else {
  4701. result0 = null;
  4702. if (reportFailures === 0) {
  4703. matchFailed("\"::\"");
  4704. }
  4705. }
  4706. if (result0 !== null) {
  4707. result1 = parse_h16();
  4708. if (result1 !== null) {
  4709. if (input.charCodeAt(pos) === 58) {
  4710. result2 = ":";
  4711. pos++;
  4712. } else {
  4713. result2 = null;
  4714. if (reportFailures === 0) {
  4715. matchFailed("\":\"");
  4716. }
  4717. }
  4718. if (result2 !== null) {
  4719. result3 = parse_h16();
  4720. if (result3 !== null) {
  4721. if (input.charCodeAt(pos) === 58) {
  4722. result4 = ":";
  4723. pos++;
  4724. } else {
  4725. result4 = null;
  4726. if (reportFailures === 0) {
  4727. matchFailed("\":\"");
  4728. }
  4729. }
  4730. if (result4 !== null) {
  4731. result5 = parse_h16();
  4732. if (result5 !== null) {
  4733. if (input.charCodeAt(pos) === 58) {
  4734. result6 = ":";
  4735. pos++;
  4736. } else {
  4737. result6 = null;
  4738. if (reportFailures === 0) {
  4739. matchFailed("\":\"");
  4740. }
  4741. }
  4742. if (result6 !== null) {
  4743. result7 = parse_h16();
  4744. if (result7 !== null) {
  4745. if (input.charCodeAt(pos) === 58) {
  4746. result8 = ":";
  4747. pos++;
  4748. } else {
  4749. result8 = null;
  4750. if (reportFailures === 0) {
  4751. matchFailed("\":\"");
  4752. }
  4753. }
  4754. if (result8 !== null) {
  4755. result9 = parse_h16();
  4756. if (result9 !== null) {
  4757. if (input.charCodeAt(pos) === 58) {
  4758. result10 = ":";
  4759. pos++;
  4760. } else {
  4761. result10 = null;
  4762. if (reportFailures === 0) {
  4763. matchFailed("\":\"");
  4764. }
  4765. }
  4766. if (result10 !== null) {
  4767. result11 = parse_ls32();
  4768. if (result11 !== null) {
  4769. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11];
  4770. } else {
  4771. result0 = null;
  4772. pos = pos1;
  4773. }
  4774. } else {
  4775. result0 = null;
  4776. pos = pos1;
  4777. }
  4778. } else {
  4779. result0 = null;
  4780. pos = pos1;
  4781. }
  4782. } else {
  4783. result0 = null;
  4784. pos = pos1;
  4785. }
  4786. } else {
  4787. result0 = null;
  4788. pos = pos1;
  4789. }
  4790. } else {
  4791. result0 = null;
  4792. pos = pos1;
  4793. }
  4794. } else {
  4795. result0 = null;
  4796. pos = pos1;
  4797. }
  4798. } else {
  4799. result0 = null;
  4800. pos = pos1;
  4801. }
  4802. } else {
  4803. result0 = null;
  4804. pos = pos1;
  4805. }
  4806. } else {
  4807. result0 = null;
  4808. pos = pos1;
  4809. }
  4810. } else {
  4811. result0 = null;
  4812. pos = pos1;
  4813. }
  4814. } else {
  4815. result0 = null;
  4816. pos = pos1;
  4817. }
  4818. if (result0 === null) {
  4819. pos1 = pos;
  4820. if (input.substr(pos, 2) === "::") {
  4821. result0 = "::";
  4822. pos += 2;
  4823. } else {
  4824. result0 = null;
  4825. if (reportFailures === 0) {
  4826. matchFailed("\"::\"");
  4827. }
  4828. }
  4829. if (result0 !== null) {
  4830. result1 = parse_h16();
  4831. if (result1 !== null) {
  4832. if (input.charCodeAt(pos) === 58) {
  4833. result2 = ":";
  4834. pos++;
  4835. } else {
  4836. result2 = null;
  4837. if (reportFailures === 0) {
  4838. matchFailed("\":\"");
  4839. }
  4840. }
  4841. if (result2 !== null) {
  4842. result3 = parse_h16();
  4843. if (result3 !== null) {
  4844. if (input.charCodeAt(pos) === 58) {
  4845. result4 = ":";
  4846. pos++;
  4847. } else {
  4848. result4 = null;
  4849. if (reportFailures === 0) {
  4850. matchFailed("\":\"");
  4851. }
  4852. }
  4853. if (result4 !== null) {
  4854. result5 = parse_h16();
  4855. if (result5 !== null) {
  4856. if (input.charCodeAt(pos) === 58) {
  4857. result6 = ":";
  4858. pos++;
  4859. } else {
  4860. result6 = null;
  4861. if (reportFailures === 0) {
  4862. matchFailed("\":\"");
  4863. }
  4864. }
  4865. if (result6 !== null) {
  4866. result7 = parse_h16();
  4867. if (result7 !== null) {
  4868. if (input.charCodeAt(pos) === 58) {
  4869. result8 = ":";
  4870. pos++;
  4871. } else {
  4872. result8 = null;
  4873. if (reportFailures === 0) {
  4874. matchFailed("\":\"");
  4875. }
  4876. }
  4877. if (result8 !== null) {
  4878. result9 = parse_ls32();
  4879. if (result9 !== null) {
  4880. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  4881. } else {
  4882. result0 = null;
  4883. pos = pos1;
  4884. }
  4885. } else {
  4886. result0 = null;
  4887. pos = pos1;
  4888. }
  4889. } else {
  4890. result0 = null;
  4891. pos = pos1;
  4892. }
  4893. } else {
  4894. result0 = null;
  4895. pos = pos1;
  4896. }
  4897. } else {
  4898. result0 = null;
  4899. pos = pos1;
  4900. }
  4901. } else {
  4902. result0 = null;
  4903. pos = pos1;
  4904. }
  4905. } else {
  4906. result0 = null;
  4907. pos = pos1;
  4908. }
  4909. } else {
  4910. result0 = null;
  4911. pos = pos1;
  4912. }
  4913. } else {
  4914. result0 = null;
  4915. pos = pos1;
  4916. }
  4917. } else {
  4918. result0 = null;
  4919. pos = pos1;
  4920. }
  4921. if (result0 === null) {
  4922. pos1 = pos;
  4923. if (input.substr(pos, 2) === "::") {
  4924. result0 = "::";
  4925. pos += 2;
  4926. } else {
  4927. result0 = null;
  4928. if (reportFailures === 0) {
  4929. matchFailed("\"::\"");
  4930. }
  4931. }
  4932. if (result0 !== null) {
  4933. result1 = parse_h16();
  4934. if (result1 !== null) {
  4935. if (input.charCodeAt(pos) === 58) {
  4936. result2 = ":";
  4937. pos++;
  4938. } else {
  4939. result2 = null;
  4940. if (reportFailures === 0) {
  4941. matchFailed("\":\"");
  4942. }
  4943. }
  4944. if (result2 !== null) {
  4945. result3 = parse_h16();
  4946. if (result3 !== null) {
  4947. if (input.charCodeAt(pos) === 58) {
  4948. result4 = ":";
  4949. pos++;
  4950. } else {
  4951. result4 = null;
  4952. if (reportFailures === 0) {
  4953. matchFailed("\":\"");
  4954. }
  4955. }
  4956. if (result4 !== null) {
  4957. result5 = parse_h16();
  4958. if (result5 !== null) {
  4959. if (input.charCodeAt(pos) === 58) {
  4960. result6 = ":";
  4961. pos++;
  4962. } else {
  4963. result6 = null;
  4964. if (reportFailures === 0) {
  4965. matchFailed("\":\"");
  4966. }
  4967. }
  4968. if (result6 !== null) {
  4969. result7 = parse_ls32();
  4970. if (result7 !== null) {
  4971. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  4972. } else {
  4973. result0 = null;
  4974. pos = pos1;
  4975. }
  4976. } else {
  4977. result0 = null;
  4978. pos = pos1;
  4979. }
  4980. } else {
  4981. result0 = null;
  4982. pos = pos1;
  4983. }
  4984. } else {
  4985. result0 = null;
  4986. pos = pos1;
  4987. }
  4988. } else {
  4989. result0 = null;
  4990. pos = pos1;
  4991. }
  4992. } else {
  4993. result0 = null;
  4994. pos = pos1;
  4995. }
  4996. } else {
  4997. result0 = null;
  4998. pos = pos1;
  4999. }
  5000. } else {
  5001. result0 = null;
  5002. pos = pos1;
  5003. }
  5004. if (result0 === null) {
  5005. pos1 = pos;
  5006. if (input.substr(pos, 2) === "::") {
  5007. result0 = "::";
  5008. pos += 2;
  5009. } else {
  5010. result0 = null;
  5011. if (reportFailures === 0) {
  5012. matchFailed("\"::\"");
  5013. }
  5014. }
  5015. if (result0 !== null) {
  5016. result1 = parse_h16();
  5017. if (result1 !== null) {
  5018. if (input.charCodeAt(pos) === 58) {
  5019. result2 = ":";
  5020. pos++;
  5021. } else {
  5022. result2 = null;
  5023. if (reportFailures === 0) {
  5024. matchFailed("\":\"");
  5025. }
  5026. }
  5027. if (result2 !== null) {
  5028. result3 = parse_h16();
  5029. if (result3 !== null) {
  5030. if (input.charCodeAt(pos) === 58) {
  5031. result4 = ":";
  5032. pos++;
  5033. } else {
  5034. result4 = null;
  5035. if (reportFailures === 0) {
  5036. matchFailed("\":\"");
  5037. }
  5038. }
  5039. if (result4 !== null) {
  5040. result5 = parse_ls32();
  5041. if (result5 !== null) {
  5042. result0 = [result0, result1, result2, result3, result4, result5];
  5043. } else {
  5044. result0 = null;
  5045. pos = pos1;
  5046. }
  5047. } else {
  5048. result0 = null;
  5049. pos = pos1;
  5050. }
  5051. } else {
  5052. result0 = null;
  5053. pos = pos1;
  5054. }
  5055. } else {
  5056. result0 = null;
  5057. pos = pos1;
  5058. }
  5059. } else {
  5060. result0 = null;
  5061. pos = pos1;
  5062. }
  5063. } else {
  5064. result0 = null;
  5065. pos = pos1;
  5066. }
  5067. if (result0 === null) {
  5068. pos1 = pos;
  5069. if (input.substr(pos, 2) === "::") {
  5070. result0 = "::";
  5071. pos += 2;
  5072. } else {
  5073. result0 = null;
  5074. if (reportFailures === 0) {
  5075. matchFailed("\"::\"");
  5076. }
  5077. }
  5078. if (result0 !== null) {
  5079. result1 = parse_h16();
  5080. if (result1 !== null) {
  5081. if (input.charCodeAt(pos) === 58) {
  5082. result2 = ":";
  5083. pos++;
  5084. } else {
  5085. result2 = null;
  5086. if (reportFailures === 0) {
  5087. matchFailed("\":\"");
  5088. }
  5089. }
  5090. if (result2 !== null) {
  5091. result3 = parse_ls32();
  5092. if (result3 !== null) {
  5093. result0 = [result0, result1, result2, result3];
  5094. } else {
  5095. result0 = null;
  5096. pos = pos1;
  5097. }
  5098. } else {
  5099. result0 = null;
  5100. pos = pos1;
  5101. }
  5102. } else {
  5103. result0 = null;
  5104. pos = pos1;
  5105. }
  5106. } else {
  5107. result0 = null;
  5108. pos = pos1;
  5109. }
  5110. if (result0 === null) {
  5111. pos1 = pos;
  5112. if (input.substr(pos, 2) === "::") {
  5113. result0 = "::";
  5114. pos += 2;
  5115. } else {
  5116. result0 = null;
  5117. if (reportFailures === 0) {
  5118. matchFailed("\"::\"");
  5119. }
  5120. }
  5121. if (result0 !== null) {
  5122. result1 = parse_ls32();
  5123. if (result1 !== null) {
  5124. result0 = [result0, result1];
  5125. } else {
  5126. result0 = null;
  5127. pos = pos1;
  5128. }
  5129. } else {
  5130. result0 = null;
  5131. pos = pos1;
  5132. }
  5133. if (result0 === null) {
  5134. pos1 = pos;
  5135. if (input.substr(pos, 2) === "::") {
  5136. result0 = "::";
  5137. pos += 2;
  5138. } else {
  5139. result0 = null;
  5140. if (reportFailures === 0) {
  5141. matchFailed("\"::\"");
  5142. }
  5143. }
  5144. if (result0 !== null) {
  5145. result1 = parse_h16();
  5146. if (result1 !== null) {
  5147. result0 = [result0, result1];
  5148. } else {
  5149. result0 = null;
  5150. pos = pos1;
  5151. }
  5152. } else {
  5153. result0 = null;
  5154. pos = pos1;
  5155. }
  5156. if (result0 === null) {
  5157. pos1 = pos;
  5158. result0 = parse_h16();
  5159. if (result0 !== null) {
  5160. if (input.substr(pos, 2) === "::") {
  5161. result1 = "::";
  5162. pos += 2;
  5163. } else {
  5164. result1 = null;
  5165. if (reportFailures === 0) {
  5166. matchFailed("\"::\"");
  5167. }
  5168. }
  5169. if (result1 !== null) {
  5170. result2 = parse_h16();
  5171. if (result2 !== null) {
  5172. if (input.charCodeAt(pos) === 58) {
  5173. result3 = ":";
  5174. pos++;
  5175. } else {
  5176. result3 = null;
  5177. if (reportFailures === 0) {
  5178. matchFailed("\":\"");
  5179. }
  5180. }
  5181. if (result3 !== null) {
  5182. result4 = parse_h16();
  5183. if (result4 !== null) {
  5184. if (input.charCodeAt(pos) === 58) {
  5185. result5 = ":";
  5186. pos++;
  5187. } else {
  5188. result5 = null;
  5189. if (reportFailures === 0) {
  5190. matchFailed("\":\"");
  5191. }
  5192. }
  5193. if (result5 !== null) {
  5194. result6 = parse_h16();
  5195. if (result6 !== null) {
  5196. if (input.charCodeAt(pos) === 58) {
  5197. result7 = ":";
  5198. pos++;
  5199. } else {
  5200. result7 = null;
  5201. if (reportFailures === 0) {
  5202. matchFailed("\":\"");
  5203. }
  5204. }
  5205. if (result7 !== null) {
  5206. result8 = parse_h16();
  5207. if (result8 !== null) {
  5208. if (input.charCodeAt(pos) === 58) {
  5209. result9 = ":";
  5210. pos++;
  5211. } else {
  5212. result9 = null;
  5213. if (reportFailures === 0) {
  5214. matchFailed("\":\"");
  5215. }
  5216. }
  5217. if (result9 !== null) {
  5218. result10 = parse_ls32();
  5219. if (result10 !== null) {
  5220. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10];
  5221. } else {
  5222. result0 = null;
  5223. pos = pos1;
  5224. }
  5225. } else {
  5226. result0 = null;
  5227. pos = pos1;
  5228. }
  5229. } else {
  5230. result0 = null;
  5231. pos = pos1;
  5232. }
  5233. } else {
  5234. result0 = null;
  5235. pos = pos1;
  5236. }
  5237. } else {
  5238. result0 = null;
  5239. pos = pos1;
  5240. }
  5241. } else {
  5242. result0 = null;
  5243. pos = pos1;
  5244. }
  5245. } else {
  5246. result0 = null;
  5247. pos = pos1;
  5248. }
  5249. } else {
  5250. result0 = null;
  5251. pos = pos1;
  5252. }
  5253. } else {
  5254. result0 = null;
  5255. pos = pos1;
  5256. }
  5257. } else {
  5258. result0 = null;
  5259. pos = pos1;
  5260. }
  5261. } else {
  5262. result0 = null;
  5263. pos = pos1;
  5264. }
  5265. if (result0 === null) {
  5266. pos1 = pos;
  5267. result0 = parse_h16();
  5268. if (result0 !== null) {
  5269. pos2 = pos;
  5270. if (input.charCodeAt(pos) === 58) {
  5271. result1 = ":";
  5272. pos++;
  5273. } else {
  5274. result1 = null;
  5275. if (reportFailures === 0) {
  5276. matchFailed("\":\"");
  5277. }
  5278. }
  5279. if (result1 !== null) {
  5280. result2 = parse_h16();
  5281. if (result2 !== null) {
  5282. result1 = [result1, result2];
  5283. } else {
  5284. result1 = null;
  5285. pos = pos2;
  5286. }
  5287. } else {
  5288. result1 = null;
  5289. pos = pos2;
  5290. }
  5291. result1 = result1 !== null ? result1 : "";
  5292. if (result1 !== null) {
  5293. if (input.substr(pos, 2) === "::") {
  5294. result2 = "::";
  5295. pos += 2;
  5296. } else {
  5297. result2 = null;
  5298. if (reportFailures === 0) {
  5299. matchFailed("\"::\"");
  5300. }
  5301. }
  5302. if (result2 !== null) {
  5303. result3 = parse_h16();
  5304. if (result3 !== null) {
  5305. if (input.charCodeAt(pos) === 58) {
  5306. result4 = ":";
  5307. pos++;
  5308. } else {
  5309. result4 = null;
  5310. if (reportFailures === 0) {
  5311. matchFailed("\":\"");
  5312. }
  5313. }
  5314. if (result4 !== null) {
  5315. result5 = parse_h16();
  5316. if (result5 !== null) {
  5317. if (input.charCodeAt(pos) === 58) {
  5318. result6 = ":";
  5319. pos++;
  5320. } else {
  5321. result6 = null;
  5322. if (reportFailures === 0) {
  5323. matchFailed("\":\"");
  5324. }
  5325. }
  5326. if (result6 !== null) {
  5327. result7 = parse_h16();
  5328. if (result7 !== null) {
  5329. if (input.charCodeAt(pos) === 58) {
  5330. result8 = ":";
  5331. pos++;
  5332. } else {
  5333. result8 = null;
  5334. if (reportFailures === 0) {
  5335. matchFailed("\":\"");
  5336. }
  5337. }
  5338. if (result8 !== null) {
  5339. result9 = parse_ls32();
  5340. if (result9 !== null) {
  5341. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  5342. } else {
  5343. result0 = null;
  5344. pos = pos1;
  5345. }
  5346. } else {
  5347. result0 = null;
  5348. pos = pos1;
  5349. }
  5350. } else {
  5351. result0 = null;
  5352. pos = pos1;
  5353. }
  5354. } else {
  5355. result0 = null;
  5356. pos = pos1;
  5357. }
  5358. } else {
  5359. result0 = null;
  5360. pos = pos1;
  5361. }
  5362. } else {
  5363. result0 = null;
  5364. pos = pos1;
  5365. }
  5366. } else {
  5367. result0 = null;
  5368. pos = pos1;
  5369. }
  5370. } else {
  5371. result0 = null;
  5372. pos = pos1;
  5373. }
  5374. } else {
  5375. result0 = null;
  5376. pos = pos1;
  5377. }
  5378. } else {
  5379. result0 = null;
  5380. pos = pos1;
  5381. }
  5382. if (result0 === null) {
  5383. pos1 = pos;
  5384. result0 = parse_h16();
  5385. if (result0 !== null) {
  5386. pos2 = pos;
  5387. if (input.charCodeAt(pos) === 58) {
  5388. result1 = ":";
  5389. pos++;
  5390. } else {
  5391. result1 = null;
  5392. if (reportFailures === 0) {
  5393. matchFailed("\":\"");
  5394. }
  5395. }
  5396. if (result1 !== null) {
  5397. result2 = parse_h16();
  5398. if (result2 !== null) {
  5399. result1 = [result1, result2];
  5400. } else {
  5401. result1 = null;
  5402. pos = pos2;
  5403. }
  5404. } else {
  5405. result1 = null;
  5406. pos = pos2;
  5407. }
  5408. result1 = result1 !== null ? result1 : "";
  5409. if (result1 !== null) {
  5410. pos2 = pos;
  5411. if (input.charCodeAt(pos) === 58) {
  5412. result2 = ":";
  5413. pos++;
  5414. } else {
  5415. result2 = null;
  5416. if (reportFailures === 0) {
  5417. matchFailed("\":\"");
  5418. }
  5419. }
  5420. if (result2 !== null) {
  5421. result3 = parse_h16();
  5422. if (result3 !== null) {
  5423. result2 = [result2, result3];
  5424. } else {
  5425. result2 = null;
  5426. pos = pos2;
  5427. }
  5428. } else {
  5429. result2 = null;
  5430. pos = pos2;
  5431. }
  5432. result2 = result2 !== null ? result2 : "";
  5433. if (result2 !== null) {
  5434. if (input.substr(pos, 2) === "::") {
  5435. result3 = "::";
  5436. pos += 2;
  5437. } else {
  5438. result3 = null;
  5439. if (reportFailures === 0) {
  5440. matchFailed("\"::\"");
  5441. }
  5442. }
  5443. if (result3 !== null) {
  5444. result4 = parse_h16();
  5445. if (result4 !== null) {
  5446. if (input.charCodeAt(pos) === 58) {
  5447. result5 = ":";
  5448. pos++;
  5449. } else {
  5450. result5 = null;
  5451. if (reportFailures === 0) {
  5452. matchFailed("\":\"");
  5453. }
  5454. }
  5455. if (result5 !== null) {
  5456. result6 = parse_h16();
  5457. if (result6 !== null) {
  5458. if (input.charCodeAt(pos) === 58) {
  5459. result7 = ":";
  5460. pos++;
  5461. } else {
  5462. result7 = null;
  5463. if (reportFailures === 0) {
  5464. matchFailed("\":\"");
  5465. }
  5466. }
  5467. if (result7 !== null) {
  5468. result8 = parse_ls32();
  5469. if (result8 !== null) {
  5470. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  5471. } else {
  5472. result0 = null;
  5473. pos = pos1;
  5474. }
  5475. } else {
  5476. result0 = null;
  5477. pos = pos1;
  5478. }
  5479. } else {
  5480. result0 = null;
  5481. pos = pos1;
  5482. }
  5483. } else {
  5484. result0 = null;
  5485. pos = pos1;
  5486. }
  5487. } else {
  5488. result0 = null;
  5489. pos = pos1;
  5490. }
  5491. } else {
  5492. result0 = null;
  5493. pos = pos1;
  5494. }
  5495. } else {
  5496. result0 = null;
  5497. pos = pos1;
  5498. }
  5499. } else {
  5500. result0 = null;
  5501. pos = pos1;
  5502. }
  5503. } else {
  5504. result0 = null;
  5505. pos = pos1;
  5506. }
  5507. if (result0 === null) {
  5508. pos1 = pos;
  5509. result0 = parse_h16();
  5510. if (result0 !== null) {
  5511. pos2 = pos;
  5512. if (input.charCodeAt(pos) === 58) {
  5513. result1 = ":";
  5514. pos++;
  5515. } else {
  5516. result1 = null;
  5517. if (reportFailures === 0) {
  5518. matchFailed("\":\"");
  5519. }
  5520. }
  5521. if (result1 !== null) {
  5522. result2 = parse_h16();
  5523. if (result2 !== null) {
  5524. result1 = [result1, result2];
  5525. } else {
  5526. result1 = null;
  5527. pos = pos2;
  5528. }
  5529. } else {
  5530. result1 = null;
  5531. pos = pos2;
  5532. }
  5533. result1 = result1 !== null ? result1 : "";
  5534. if (result1 !== null) {
  5535. pos2 = pos;
  5536. if (input.charCodeAt(pos) === 58) {
  5537. result2 = ":";
  5538. pos++;
  5539. } else {
  5540. result2 = null;
  5541. if (reportFailures === 0) {
  5542. matchFailed("\":\"");
  5543. }
  5544. }
  5545. if (result2 !== null) {
  5546. result3 = parse_h16();
  5547. if (result3 !== null) {
  5548. result2 = [result2, result3];
  5549. } else {
  5550. result2 = null;
  5551. pos = pos2;
  5552. }
  5553. } else {
  5554. result2 = null;
  5555. pos = pos2;
  5556. }
  5557. result2 = result2 !== null ? result2 : "";
  5558. if (result2 !== null) {
  5559. pos2 = pos;
  5560. if (input.charCodeAt(pos) === 58) {
  5561. result3 = ":";
  5562. pos++;
  5563. } else {
  5564. result3 = null;
  5565. if (reportFailures === 0) {
  5566. matchFailed("\":\"");
  5567. }
  5568. }
  5569. if (result3 !== null) {
  5570. result4 = parse_h16();
  5571. if (result4 !== null) {
  5572. result3 = [result3, result4];
  5573. } else {
  5574. result3 = null;
  5575. pos = pos2;
  5576. }
  5577. } else {
  5578. result3 = null;
  5579. pos = pos2;
  5580. }
  5581. result3 = result3 !== null ? result3 : "";
  5582. if (result3 !== null) {
  5583. if (input.substr(pos, 2) === "::") {
  5584. result4 = "::";
  5585. pos += 2;
  5586. } else {
  5587. result4 = null;
  5588. if (reportFailures === 0) {
  5589. matchFailed("\"::\"");
  5590. }
  5591. }
  5592. if (result4 !== null) {
  5593. result5 = parse_h16();
  5594. if (result5 !== null) {
  5595. if (input.charCodeAt(pos) === 58) {
  5596. result6 = ":";
  5597. pos++;
  5598. } else {
  5599. result6 = null;
  5600. if (reportFailures === 0) {
  5601. matchFailed("\":\"");
  5602. }
  5603. }
  5604. if (result6 !== null) {
  5605. result7 = parse_ls32();
  5606. if (result7 !== null) {
  5607. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5608. } else {
  5609. result0 = null;
  5610. pos = pos1;
  5611. }
  5612. } else {
  5613. result0 = null;
  5614. pos = pos1;
  5615. }
  5616. } else {
  5617. result0 = null;
  5618. pos = pos1;
  5619. }
  5620. } else {
  5621. result0 = null;
  5622. pos = pos1;
  5623. }
  5624. } else {
  5625. result0 = null;
  5626. pos = pos1;
  5627. }
  5628. } else {
  5629. result0 = null;
  5630. pos = pos1;
  5631. }
  5632. } else {
  5633. result0 = null;
  5634. pos = pos1;
  5635. }
  5636. } else {
  5637. result0 = null;
  5638. pos = pos1;
  5639. }
  5640. if (result0 === null) {
  5641. pos1 = pos;
  5642. result0 = parse_h16();
  5643. if (result0 !== null) {
  5644. pos2 = pos;
  5645. if (input.charCodeAt(pos) === 58) {
  5646. result1 = ":";
  5647. pos++;
  5648. } else {
  5649. result1 = null;
  5650. if (reportFailures === 0) {
  5651. matchFailed("\":\"");
  5652. }
  5653. }
  5654. if (result1 !== null) {
  5655. result2 = parse_h16();
  5656. if (result2 !== null) {
  5657. result1 = [result1, result2];
  5658. } else {
  5659. result1 = null;
  5660. pos = pos2;
  5661. }
  5662. } else {
  5663. result1 = null;
  5664. pos = pos2;
  5665. }
  5666. result1 = result1 !== null ? result1 : "";
  5667. if (result1 !== null) {
  5668. pos2 = pos;
  5669. if (input.charCodeAt(pos) === 58) {
  5670. result2 = ":";
  5671. pos++;
  5672. } else {
  5673. result2 = null;
  5674. if (reportFailures === 0) {
  5675. matchFailed("\":\"");
  5676. }
  5677. }
  5678. if (result2 !== null) {
  5679. result3 = parse_h16();
  5680. if (result3 !== null) {
  5681. result2 = [result2, result3];
  5682. } else {
  5683. result2 = null;
  5684. pos = pos2;
  5685. }
  5686. } else {
  5687. result2 = null;
  5688. pos = pos2;
  5689. }
  5690. result2 = result2 !== null ? result2 : "";
  5691. if (result2 !== null) {
  5692. pos2 = pos;
  5693. if (input.charCodeAt(pos) === 58) {
  5694. result3 = ":";
  5695. pos++;
  5696. } else {
  5697. result3 = null;
  5698. if (reportFailures === 0) {
  5699. matchFailed("\":\"");
  5700. }
  5701. }
  5702. if (result3 !== null) {
  5703. result4 = parse_h16();
  5704. if (result4 !== null) {
  5705. result3 = [result3, result4];
  5706. } else {
  5707. result3 = null;
  5708. pos = pos2;
  5709. }
  5710. } else {
  5711. result3 = null;
  5712. pos = pos2;
  5713. }
  5714. result3 = result3 !== null ? result3 : "";
  5715. if (result3 !== null) {
  5716. pos2 = pos;
  5717. if (input.charCodeAt(pos) === 58) {
  5718. result4 = ":";
  5719. pos++;
  5720. } else {
  5721. result4 = null;
  5722. if (reportFailures === 0) {
  5723. matchFailed("\":\"");
  5724. }
  5725. }
  5726. if (result4 !== null) {
  5727. result5 = parse_h16();
  5728. if (result5 !== null) {
  5729. result4 = [result4, result5];
  5730. } else {
  5731. result4 = null;
  5732. pos = pos2;
  5733. }
  5734. } else {
  5735. result4 = null;
  5736. pos = pos2;
  5737. }
  5738. result4 = result4 !== null ? result4 : "";
  5739. if (result4 !== null) {
  5740. if (input.substr(pos, 2) === "::") {
  5741. result5 = "::";
  5742. pos += 2;
  5743. } else {
  5744. result5 = null;
  5745. if (reportFailures === 0) {
  5746. matchFailed("\"::\"");
  5747. }
  5748. }
  5749. if (result5 !== null) {
  5750. result6 = parse_ls32();
  5751. if (result6 !== null) {
  5752. result0 = [result0, result1, result2, result3, result4, result5, result6];
  5753. } else {
  5754. result0 = null;
  5755. pos = pos1;
  5756. }
  5757. } else {
  5758. result0 = null;
  5759. pos = pos1;
  5760. }
  5761. } else {
  5762. result0 = null;
  5763. pos = pos1;
  5764. }
  5765. } else {
  5766. result0 = null;
  5767. pos = pos1;
  5768. }
  5769. } else {
  5770. result0 = null;
  5771. pos = pos1;
  5772. }
  5773. } else {
  5774. result0 = null;
  5775. pos = pos1;
  5776. }
  5777. } else {
  5778. result0 = null;
  5779. pos = pos1;
  5780. }
  5781. if (result0 === null) {
  5782. pos1 = pos;
  5783. result0 = parse_h16();
  5784. if (result0 !== null) {
  5785. pos2 = pos;
  5786. if (input.charCodeAt(pos) === 58) {
  5787. result1 = ":";
  5788. pos++;
  5789. } else {
  5790. result1 = null;
  5791. if (reportFailures === 0) {
  5792. matchFailed("\":\"");
  5793. }
  5794. }
  5795. if (result1 !== null) {
  5796. result2 = parse_h16();
  5797. if (result2 !== null) {
  5798. result1 = [result1, result2];
  5799. } else {
  5800. result1 = null;
  5801. pos = pos2;
  5802. }
  5803. } else {
  5804. result1 = null;
  5805. pos = pos2;
  5806. }
  5807. result1 = result1 !== null ? result1 : "";
  5808. if (result1 !== null) {
  5809. pos2 = pos;
  5810. if (input.charCodeAt(pos) === 58) {
  5811. result2 = ":";
  5812. pos++;
  5813. } else {
  5814. result2 = null;
  5815. if (reportFailures === 0) {
  5816. matchFailed("\":\"");
  5817. }
  5818. }
  5819. if (result2 !== null) {
  5820. result3 = parse_h16();
  5821. if (result3 !== null) {
  5822. result2 = [result2, result3];
  5823. } else {
  5824. result2 = null;
  5825. pos = pos2;
  5826. }
  5827. } else {
  5828. result2 = null;
  5829. pos = pos2;
  5830. }
  5831. result2 = result2 !== null ? result2 : "";
  5832. if (result2 !== null) {
  5833. pos2 = pos;
  5834. if (input.charCodeAt(pos) === 58) {
  5835. result3 = ":";
  5836. pos++;
  5837. } else {
  5838. result3 = null;
  5839. if (reportFailures === 0) {
  5840. matchFailed("\":\"");
  5841. }
  5842. }
  5843. if (result3 !== null) {
  5844. result4 = parse_h16();
  5845. if (result4 !== null) {
  5846. result3 = [result3, result4];
  5847. } else {
  5848. result3 = null;
  5849. pos = pos2;
  5850. }
  5851. } else {
  5852. result3 = null;
  5853. pos = pos2;
  5854. }
  5855. result3 = result3 !== null ? result3 : "";
  5856. if (result3 !== null) {
  5857. pos2 = pos;
  5858. if (input.charCodeAt(pos) === 58) {
  5859. result4 = ":";
  5860. pos++;
  5861. } else {
  5862. result4 = null;
  5863. if (reportFailures === 0) {
  5864. matchFailed("\":\"");
  5865. }
  5866. }
  5867. if (result4 !== null) {
  5868. result5 = parse_h16();
  5869. if (result5 !== null) {
  5870. result4 = [result4, result5];
  5871. } else {
  5872. result4 = null;
  5873. pos = pos2;
  5874. }
  5875. } else {
  5876. result4 = null;
  5877. pos = pos2;
  5878. }
  5879. result4 = result4 !== null ? result4 : "";
  5880. if (result4 !== null) {
  5881. pos2 = pos;
  5882. if (input.charCodeAt(pos) === 58) {
  5883. result5 = ":";
  5884. pos++;
  5885. } else {
  5886. result5 = null;
  5887. if (reportFailures === 0) {
  5888. matchFailed("\":\"");
  5889. }
  5890. }
  5891. if (result5 !== null) {
  5892. result6 = parse_h16();
  5893. if (result6 !== null) {
  5894. result5 = [result5, result6];
  5895. } else {
  5896. result5 = null;
  5897. pos = pos2;
  5898. }
  5899. } else {
  5900. result5 = null;
  5901. pos = pos2;
  5902. }
  5903. result5 = result5 !== null ? result5 : "";
  5904. if (result5 !== null) {
  5905. if (input.substr(pos, 2) === "::") {
  5906. result6 = "::";
  5907. pos += 2;
  5908. } else {
  5909. result6 = null;
  5910. if (reportFailures === 0) {
  5911. matchFailed("\"::\"");
  5912. }
  5913. }
  5914. if (result6 !== null) {
  5915. result7 = parse_h16();
  5916. if (result7 !== null) {
  5917. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5918. } else {
  5919. result0 = null;
  5920. pos = pos1;
  5921. }
  5922. } else {
  5923. result0 = null;
  5924. pos = pos1;
  5925. }
  5926. } else {
  5927. result0 = null;
  5928. pos = pos1;
  5929. }
  5930. } else {
  5931. result0 = null;
  5932. pos = pos1;
  5933. }
  5934. } else {
  5935. result0 = null;
  5936. pos = pos1;
  5937. }
  5938. } else {
  5939. result0 = null;
  5940. pos = pos1;
  5941. }
  5942. } else {
  5943. result0 = null;
  5944. pos = pos1;
  5945. }
  5946. } else {
  5947. result0 = null;
  5948. pos = pos1;
  5949. }
  5950. if (result0 === null) {
  5951. pos1 = pos;
  5952. result0 = parse_h16();
  5953. if (result0 !== null) {
  5954. pos2 = pos;
  5955. if (input.charCodeAt(pos) === 58) {
  5956. result1 = ":";
  5957. pos++;
  5958. } else {
  5959. result1 = null;
  5960. if (reportFailures === 0) {
  5961. matchFailed("\":\"");
  5962. }
  5963. }
  5964. if (result1 !== null) {
  5965. result2 = parse_h16();
  5966. if (result2 !== null) {
  5967. result1 = [result1, result2];
  5968. } else {
  5969. result1 = null;
  5970. pos = pos2;
  5971. }
  5972. } else {
  5973. result1 = null;
  5974. pos = pos2;
  5975. }
  5976. result1 = result1 !== null ? result1 : "";
  5977. if (result1 !== null) {
  5978. pos2 = pos;
  5979. if (input.charCodeAt(pos) === 58) {
  5980. result2 = ":";
  5981. pos++;
  5982. } else {
  5983. result2 = null;
  5984. if (reportFailures === 0) {
  5985. matchFailed("\":\"");
  5986. }
  5987. }
  5988. if (result2 !== null) {
  5989. result3 = parse_h16();
  5990. if (result3 !== null) {
  5991. result2 = [result2, result3];
  5992. } else {
  5993. result2 = null;
  5994. pos = pos2;
  5995. }
  5996. } else {
  5997. result2 = null;
  5998. pos = pos2;
  5999. }
  6000. result2 = result2 !== null ? result2 : "";
  6001. if (result2 !== null) {
  6002. pos2 = pos;
  6003. if (input.charCodeAt(pos) === 58) {
  6004. result3 = ":";
  6005. pos++;
  6006. } else {
  6007. result3 = null;
  6008. if (reportFailures === 0) {
  6009. matchFailed("\":\"");
  6010. }
  6011. }
  6012. if (result3 !== null) {
  6013. result4 = parse_h16();
  6014. if (result4 !== null) {
  6015. result3 = [result3, result4];
  6016. } else {
  6017. result3 = null;
  6018. pos = pos2;
  6019. }
  6020. } else {
  6021. result3 = null;
  6022. pos = pos2;
  6023. }
  6024. result3 = result3 !== null ? result3 : "";
  6025. if (result3 !== null) {
  6026. pos2 = pos;
  6027. if (input.charCodeAt(pos) === 58) {
  6028. result4 = ":";
  6029. pos++;
  6030. } else {
  6031. result4 = null;
  6032. if (reportFailures === 0) {
  6033. matchFailed("\":\"");
  6034. }
  6035. }
  6036. if (result4 !== null) {
  6037. result5 = parse_h16();
  6038. if (result5 !== null) {
  6039. result4 = [result4, result5];
  6040. } else {
  6041. result4 = null;
  6042. pos = pos2;
  6043. }
  6044. } else {
  6045. result4 = null;
  6046. pos = pos2;
  6047. }
  6048. result4 = result4 !== null ? result4 : "";
  6049. if (result4 !== null) {
  6050. pos2 = pos;
  6051. if (input.charCodeAt(pos) === 58) {
  6052. result5 = ":";
  6053. pos++;
  6054. } else {
  6055. result5 = null;
  6056. if (reportFailures === 0) {
  6057. matchFailed("\":\"");
  6058. }
  6059. }
  6060. if (result5 !== null) {
  6061. result6 = parse_h16();
  6062. if (result6 !== null) {
  6063. result5 = [result5, result6];
  6064. } else {
  6065. result5 = null;
  6066. pos = pos2;
  6067. }
  6068. } else {
  6069. result5 = null;
  6070. pos = pos2;
  6071. }
  6072. result5 = result5 !== null ? result5 : "";
  6073. if (result5 !== null) {
  6074. pos2 = pos;
  6075. if (input.charCodeAt(pos) === 58) {
  6076. result6 = ":";
  6077. pos++;
  6078. } else {
  6079. result6 = null;
  6080. if (reportFailures === 0) {
  6081. matchFailed("\":\"");
  6082. }
  6083. }
  6084. if (result6 !== null) {
  6085. result7 = parse_h16();
  6086. if (result7 !== null) {
  6087. result6 = [result6, result7];
  6088. } else {
  6089. result6 = null;
  6090. pos = pos2;
  6091. }
  6092. } else {
  6093. result6 = null;
  6094. pos = pos2;
  6095. }
  6096. result6 = result6 !== null ? result6 : "";
  6097. if (result6 !== null) {
  6098. if (input.substr(pos, 2) === "::") {
  6099. result7 = "::";
  6100. pos += 2;
  6101. } else {
  6102. result7 = null;
  6103. if (reportFailures === 0) {
  6104. matchFailed("\"::\"");
  6105. }
  6106. }
  6107. if (result7 !== null) {
  6108. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  6109. } else {
  6110. result0 = null;
  6111. pos = pos1;
  6112. }
  6113. } else {
  6114. result0 = null;
  6115. pos = pos1;
  6116. }
  6117. } else {
  6118. result0 = null;
  6119. pos = pos1;
  6120. }
  6121. } else {
  6122. result0 = null;
  6123. pos = pos1;
  6124. }
  6125. } else {
  6126. result0 = null;
  6127. pos = pos1;
  6128. }
  6129. } else {
  6130. result0 = null;
  6131. pos = pos1;
  6132. }
  6133. } else {
  6134. result0 = null;
  6135. pos = pos1;
  6136. }
  6137. } else {
  6138. result0 = null;
  6139. pos = pos1;
  6140. }
  6141. }
  6142. }
  6143. }
  6144. }
  6145. }
  6146. }
  6147. }
  6148. }
  6149. }
  6150. }
  6151. }
  6152. }
  6153. }
  6154. }
  6155. if (result0 !== null) {
  6156. result0 = function (offset) {
  6157. data.host_type = 'IPv6';
  6158. return input.substring(pos, offset);
  6159. }(pos0);
  6160. }
  6161. if (result0 === null) {
  6162. pos = pos0;
  6163. }
  6164. return result0;
  6165. }
  6166. function parse_h16() {
  6167. var result0, result1, result2, result3;
  6168. var pos0;
  6169. pos0 = pos;
  6170. result0 = parse_HEXDIG();
  6171. if (result0 !== null) {
  6172. result1 = parse_HEXDIG();
  6173. result1 = result1 !== null ? result1 : "";
  6174. if (result1 !== null) {
  6175. result2 = parse_HEXDIG();
  6176. result2 = result2 !== null ? result2 : "";
  6177. if (result2 !== null) {
  6178. result3 = parse_HEXDIG();
  6179. result3 = result3 !== null ? result3 : "";
  6180. if (result3 !== null) {
  6181. result0 = [result0, result1, result2, result3];
  6182. } else {
  6183. result0 = null;
  6184. pos = pos0;
  6185. }
  6186. } else {
  6187. result0 = null;
  6188. pos = pos0;
  6189. }
  6190. } else {
  6191. result0 = null;
  6192. pos = pos0;
  6193. }
  6194. } else {
  6195. result0 = null;
  6196. pos = pos0;
  6197. }
  6198. return result0;
  6199. }
  6200. function parse_ls32() {
  6201. var result0, result1, result2;
  6202. var pos0;
  6203. pos0 = pos;
  6204. result0 = parse_h16();
  6205. if (result0 !== null) {
  6206. if (input.charCodeAt(pos) === 58) {
  6207. result1 = ":";
  6208. pos++;
  6209. } else {
  6210. result1 = null;
  6211. if (reportFailures === 0) {
  6212. matchFailed("\":\"");
  6213. }
  6214. }
  6215. if (result1 !== null) {
  6216. result2 = parse_h16();
  6217. if (result2 !== null) {
  6218. result0 = [result0, result1, result2];
  6219. } else {
  6220. result0 = null;
  6221. pos = pos0;
  6222. }
  6223. } else {
  6224. result0 = null;
  6225. pos = pos0;
  6226. }
  6227. } else {
  6228. result0 = null;
  6229. pos = pos0;
  6230. }
  6231. if (result0 === null) {
  6232. result0 = parse_IPv4address();
  6233. }
  6234. return result0;
  6235. }
  6236. function parse_IPv4address() {
  6237. var result0, result1, result2, result3, result4, result5, result6;
  6238. var pos0, pos1;
  6239. pos0 = pos;
  6240. pos1 = pos;
  6241. result0 = parse_dec_octet();
  6242. if (result0 !== null) {
  6243. if (input.charCodeAt(pos) === 46) {
  6244. result1 = ".";
  6245. pos++;
  6246. } else {
  6247. result1 = null;
  6248. if (reportFailures === 0) {
  6249. matchFailed("\".\"");
  6250. }
  6251. }
  6252. if (result1 !== null) {
  6253. result2 = parse_dec_octet();
  6254. if (result2 !== null) {
  6255. if (input.charCodeAt(pos) === 46) {
  6256. result3 = ".";
  6257. pos++;
  6258. } else {
  6259. result3 = null;
  6260. if (reportFailures === 0) {
  6261. matchFailed("\".\"");
  6262. }
  6263. }
  6264. if (result3 !== null) {
  6265. result4 = parse_dec_octet();
  6266. if (result4 !== null) {
  6267. if (input.charCodeAt(pos) === 46) {
  6268. result5 = ".";
  6269. pos++;
  6270. } else {
  6271. result5 = null;
  6272. if (reportFailures === 0) {
  6273. matchFailed("\".\"");
  6274. }
  6275. }
  6276. if (result5 !== null) {
  6277. result6 = parse_dec_octet();
  6278. if (result6 !== null) {
  6279. result0 = [result0, result1, result2, result3, result4, result5, result6];
  6280. } else {
  6281. result0 = null;
  6282. pos = pos1;
  6283. }
  6284. } else {
  6285. result0 = null;
  6286. pos = pos1;
  6287. }
  6288. } else {
  6289. result0 = null;
  6290. pos = pos1;
  6291. }
  6292. } else {
  6293. result0 = null;
  6294. pos = pos1;
  6295. }
  6296. } else {
  6297. result0 = null;
  6298. pos = pos1;
  6299. }
  6300. } else {
  6301. result0 = null;
  6302. pos = pos1;
  6303. }
  6304. } else {
  6305. result0 = null;
  6306. pos = pos1;
  6307. }
  6308. if (result0 !== null) {
  6309. result0 = function (offset) {
  6310. data.host_type = 'IPv4';
  6311. return input.substring(pos, offset);
  6312. }(pos0);
  6313. }
  6314. if (result0 === null) {
  6315. pos = pos0;
  6316. }
  6317. return result0;
  6318. }
  6319. function parse_dec_octet() {
  6320. var result0, result1, result2;
  6321. var pos0;
  6322. pos0 = pos;
  6323. if (input.substr(pos, 2) === "25") {
  6324. result0 = "25";
  6325. pos += 2;
  6326. } else {
  6327. result0 = null;
  6328. if (reportFailures === 0) {
  6329. matchFailed("\"25\"");
  6330. }
  6331. }
  6332. if (result0 !== null) {
  6333. if (/^[0-5]/.test(input.charAt(pos))) {
  6334. result1 = input.charAt(pos);
  6335. pos++;
  6336. } else {
  6337. result1 = null;
  6338. if (reportFailures === 0) {
  6339. matchFailed("[0-5]");
  6340. }
  6341. }
  6342. if (result1 !== null) {
  6343. result0 = [result0, result1];
  6344. } else {
  6345. result0 = null;
  6346. pos = pos0;
  6347. }
  6348. } else {
  6349. result0 = null;
  6350. pos = pos0;
  6351. }
  6352. if (result0 === null) {
  6353. pos0 = pos;
  6354. if (input.charCodeAt(pos) === 50) {
  6355. result0 = "2";
  6356. pos++;
  6357. } else {
  6358. result0 = null;
  6359. if (reportFailures === 0) {
  6360. matchFailed("\"2\"");
  6361. }
  6362. }
  6363. if (result0 !== null) {
  6364. if (/^[0-4]/.test(input.charAt(pos))) {
  6365. result1 = input.charAt(pos);
  6366. pos++;
  6367. } else {
  6368. result1 = null;
  6369. if (reportFailures === 0) {
  6370. matchFailed("[0-4]");
  6371. }
  6372. }
  6373. if (result1 !== null) {
  6374. result2 = parse_DIGIT();
  6375. if (result2 !== null) {
  6376. result0 = [result0, result1, result2];
  6377. } else {
  6378. result0 = null;
  6379. pos = pos0;
  6380. }
  6381. } else {
  6382. result0 = null;
  6383. pos = pos0;
  6384. }
  6385. } else {
  6386. result0 = null;
  6387. pos = pos0;
  6388. }
  6389. if (result0 === null) {
  6390. pos0 = pos;
  6391. if (input.charCodeAt(pos) === 49) {
  6392. result0 = "1";
  6393. pos++;
  6394. } else {
  6395. result0 = null;
  6396. if (reportFailures === 0) {
  6397. matchFailed("\"1\"");
  6398. }
  6399. }
  6400. if (result0 !== null) {
  6401. result1 = parse_DIGIT();
  6402. if (result1 !== null) {
  6403. result2 = parse_DIGIT();
  6404. if (result2 !== null) {
  6405. result0 = [result0, result1, result2];
  6406. } else {
  6407. result0 = null;
  6408. pos = pos0;
  6409. }
  6410. } else {
  6411. result0 = null;
  6412. pos = pos0;
  6413. }
  6414. } else {
  6415. result0 = null;
  6416. pos = pos0;
  6417. }
  6418. if (result0 === null) {
  6419. pos0 = pos;
  6420. if (/^[1-9]/.test(input.charAt(pos))) {
  6421. result0 = input.charAt(pos);
  6422. pos++;
  6423. } else {
  6424. result0 = null;
  6425. if (reportFailures === 0) {
  6426. matchFailed("[1-9]");
  6427. }
  6428. }
  6429. if (result0 !== null) {
  6430. result1 = parse_DIGIT();
  6431. if (result1 !== null) {
  6432. result0 = [result0, result1];
  6433. } else {
  6434. result0 = null;
  6435. pos = pos0;
  6436. }
  6437. } else {
  6438. result0 = null;
  6439. pos = pos0;
  6440. }
  6441. if (result0 === null) {
  6442. result0 = parse_DIGIT();
  6443. }
  6444. }
  6445. }
  6446. }
  6447. return result0;
  6448. }
  6449. function parse_port() {
  6450. var result0, result1, result2, result3, result4;
  6451. var pos0, pos1;
  6452. pos0 = pos;
  6453. pos1 = pos;
  6454. result0 = parse_DIGIT();
  6455. result0 = result0 !== null ? result0 : "";
  6456. if (result0 !== null) {
  6457. result1 = parse_DIGIT();
  6458. result1 = result1 !== null ? result1 : "";
  6459. if (result1 !== null) {
  6460. result2 = parse_DIGIT();
  6461. result2 = result2 !== null ? result2 : "";
  6462. if (result2 !== null) {
  6463. result3 = parse_DIGIT();
  6464. result3 = result3 !== null ? result3 : "";
  6465. if (result3 !== null) {
  6466. result4 = parse_DIGIT();
  6467. result4 = result4 !== null ? result4 : "";
  6468. if (result4 !== null) {
  6469. result0 = [result0, result1, result2, result3, result4];
  6470. } else {
  6471. result0 = null;
  6472. pos = pos1;
  6473. }
  6474. } else {
  6475. result0 = null;
  6476. pos = pos1;
  6477. }
  6478. } else {
  6479. result0 = null;
  6480. pos = pos1;
  6481. }
  6482. } else {
  6483. result0 = null;
  6484. pos = pos1;
  6485. }
  6486. } else {
  6487. result0 = null;
  6488. pos = pos1;
  6489. }
  6490. if (result0 !== null) {
  6491. result0 = function (offset, port) {
  6492. port = parseInt(port.join(''));
  6493. data.port = port;
  6494. return port;
  6495. }(pos0, result0);
  6496. }
  6497. if (result0 === null) {
  6498. pos = pos0;
  6499. }
  6500. return result0;
  6501. }
  6502. function parse_uri_parameters() {
  6503. var result0, result1, result2;
  6504. var pos0;
  6505. result0 = [];
  6506. pos0 = pos;
  6507. if (input.charCodeAt(pos) === 59) {
  6508. result1 = ";";
  6509. pos++;
  6510. } else {
  6511. result1 = null;
  6512. if (reportFailures === 0) {
  6513. matchFailed("\";\"");
  6514. }
  6515. }
  6516. if (result1 !== null) {
  6517. result2 = parse_uri_parameter();
  6518. if (result2 !== null) {
  6519. result1 = [result1, result2];
  6520. } else {
  6521. result1 = null;
  6522. pos = pos0;
  6523. }
  6524. } else {
  6525. result1 = null;
  6526. pos = pos0;
  6527. }
  6528. while (result1 !== null) {
  6529. result0.push(result1);
  6530. pos0 = pos;
  6531. if (input.charCodeAt(pos) === 59) {
  6532. result1 = ";";
  6533. pos++;
  6534. } else {
  6535. result1 = null;
  6536. if (reportFailures === 0) {
  6537. matchFailed("\";\"");
  6538. }
  6539. }
  6540. if (result1 !== null) {
  6541. result2 = parse_uri_parameter();
  6542. if (result2 !== null) {
  6543. result1 = [result1, result2];
  6544. } else {
  6545. result1 = null;
  6546. pos = pos0;
  6547. }
  6548. } else {
  6549. result1 = null;
  6550. pos = pos0;
  6551. }
  6552. }
  6553. return result0;
  6554. }
  6555. function parse_uri_parameter() {
  6556. var result0;
  6557. result0 = parse_transport_param();
  6558. if (result0 === null) {
  6559. result0 = parse_user_param();
  6560. if (result0 === null) {
  6561. result0 = parse_method_param();
  6562. if (result0 === null) {
  6563. result0 = parse_ttl_param();
  6564. if (result0 === null) {
  6565. result0 = parse_maddr_param();
  6566. if (result0 === null) {
  6567. result0 = parse_lr_param();
  6568. if (result0 === null) {
  6569. result0 = parse_other_param();
  6570. }
  6571. }
  6572. }
  6573. }
  6574. }
  6575. }
  6576. return result0;
  6577. }
  6578. function parse_transport_param() {
  6579. var result0, result1;
  6580. var pos0, pos1;
  6581. pos0 = pos;
  6582. pos1 = pos;
  6583. if (input.substr(pos, 10).toLowerCase() === "transport=") {
  6584. result0 = input.substr(pos, 10);
  6585. pos += 10;
  6586. } else {
  6587. result0 = null;
  6588. if (reportFailures === 0) {
  6589. matchFailed("\"transport=\"");
  6590. }
  6591. }
  6592. if (result0 !== null) {
  6593. if (input.substr(pos, 3).toLowerCase() === "udp") {
  6594. result1 = input.substr(pos, 3);
  6595. pos += 3;
  6596. } else {
  6597. result1 = null;
  6598. if (reportFailures === 0) {
  6599. matchFailed("\"udp\"");
  6600. }
  6601. }
  6602. if (result1 === null) {
  6603. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  6604. result1 = input.substr(pos, 3);
  6605. pos += 3;
  6606. } else {
  6607. result1 = null;
  6608. if (reportFailures === 0) {
  6609. matchFailed("\"tcp\"");
  6610. }
  6611. }
  6612. if (result1 === null) {
  6613. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  6614. result1 = input.substr(pos, 4);
  6615. pos += 4;
  6616. } else {
  6617. result1 = null;
  6618. if (reportFailures === 0) {
  6619. matchFailed("\"sctp\"");
  6620. }
  6621. }
  6622. if (result1 === null) {
  6623. if (input.substr(pos, 3).toLowerCase() === "tls") {
  6624. result1 = input.substr(pos, 3);
  6625. pos += 3;
  6626. } else {
  6627. result1 = null;
  6628. if (reportFailures === 0) {
  6629. matchFailed("\"tls\"");
  6630. }
  6631. }
  6632. if (result1 === null) {
  6633. result1 = parse_token();
  6634. }
  6635. }
  6636. }
  6637. }
  6638. if (result1 !== null) {
  6639. result0 = [result0, result1];
  6640. } else {
  6641. result0 = null;
  6642. pos = pos1;
  6643. }
  6644. } else {
  6645. result0 = null;
  6646. pos = pos1;
  6647. }
  6648. if (result0 !== null) {
  6649. result0 = function (offset, transport) {
  6650. if (!data.uri_params) data.uri_params = {};
  6651. data.uri_params['transport'] = transport.toLowerCase();
  6652. }(pos0, result0[1]);
  6653. }
  6654. if (result0 === null) {
  6655. pos = pos0;
  6656. }
  6657. return result0;
  6658. }
  6659. function parse_user_param() {
  6660. var result0, result1;
  6661. var pos0, pos1;
  6662. pos0 = pos;
  6663. pos1 = pos;
  6664. if (input.substr(pos, 5).toLowerCase() === "user=") {
  6665. result0 = input.substr(pos, 5);
  6666. pos += 5;
  6667. } else {
  6668. result0 = null;
  6669. if (reportFailures === 0) {
  6670. matchFailed("\"user=\"");
  6671. }
  6672. }
  6673. if (result0 !== null) {
  6674. if (input.substr(pos, 5).toLowerCase() === "phone") {
  6675. result1 = input.substr(pos, 5);
  6676. pos += 5;
  6677. } else {
  6678. result1 = null;
  6679. if (reportFailures === 0) {
  6680. matchFailed("\"phone\"");
  6681. }
  6682. }
  6683. if (result1 === null) {
  6684. if (input.substr(pos, 2).toLowerCase() === "ip") {
  6685. result1 = input.substr(pos, 2);
  6686. pos += 2;
  6687. } else {
  6688. result1 = null;
  6689. if (reportFailures === 0) {
  6690. matchFailed("\"ip\"");
  6691. }
  6692. }
  6693. if (result1 === null) {
  6694. result1 = parse_token();
  6695. }
  6696. }
  6697. if (result1 !== null) {
  6698. result0 = [result0, result1];
  6699. } else {
  6700. result0 = null;
  6701. pos = pos1;
  6702. }
  6703. } else {
  6704. result0 = null;
  6705. pos = pos1;
  6706. }
  6707. if (result0 !== null) {
  6708. result0 = function (offset, user) {
  6709. if (!data.uri_params) data.uri_params = {};
  6710. data.uri_params['user'] = user.toLowerCase();
  6711. }(pos0, result0[1]);
  6712. }
  6713. if (result0 === null) {
  6714. pos = pos0;
  6715. }
  6716. return result0;
  6717. }
  6718. function parse_method_param() {
  6719. var result0, result1;
  6720. var pos0, pos1;
  6721. pos0 = pos;
  6722. pos1 = pos;
  6723. if (input.substr(pos, 7).toLowerCase() === "method=") {
  6724. result0 = input.substr(pos, 7);
  6725. pos += 7;
  6726. } else {
  6727. result0 = null;
  6728. if (reportFailures === 0) {
  6729. matchFailed("\"method=\"");
  6730. }
  6731. }
  6732. if (result0 !== null) {
  6733. result1 = parse_Method();
  6734. if (result1 !== null) {
  6735. result0 = [result0, result1];
  6736. } else {
  6737. result0 = null;
  6738. pos = pos1;
  6739. }
  6740. } else {
  6741. result0 = null;
  6742. pos = pos1;
  6743. }
  6744. if (result0 !== null) {
  6745. result0 = function (offset, method) {
  6746. if (!data.uri_params) data.uri_params = {};
  6747. data.uri_params['method'] = method;
  6748. }(pos0, result0[1]);
  6749. }
  6750. if (result0 === null) {
  6751. pos = pos0;
  6752. }
  6753. return result0;
  6754. }
  6755. function parse_ttl_param() {
  6756. var result0, result1;
  6757. var pos0, pos1;
  6758. pos0 = pos;
  6759. pos1 = pos;
  6760. if (input.substr(pos, 4).toLowerCase() === "ttl=") {
  6761. result0 = input.substr(pos, 4);
  6762. pos += 4;
  6763. } else {
  6764. result0 = null;
  6765. if (reportFailures === 0) {
  6766. matchFailed("\"ttl=\"");
  6767. }
  6768. }
  6769. if (result0 !== null) {
  6770. result1 = parse_ttl();
  6771. if (result1 !== null) {
  6772. result0 = [result0, result1];
  6773. } else {
  6774. result0 = null;
  6775. pos = pos1;
  6776. }
  6777. } else {
  6778. result0 = null;
  6779. pos = pos1;
  6780. }
  6781. if (result0 !== null) {
  6782. result0 = function (offset, ttl) {
  6783. if (!data.params) data.params = {};
  6784. data.params['ttl'] = ttl;
  6785. }(pos0, result0[1]);
  6786. }
  6787. if (result0 === null) {
  6788. pos = pos0;
  6789. }
  6790. return result0;
  6791. }
  6792. function parse_maddr_param() {
  6793. var result0, result1;
  6794. var pos0, pos1;
  6795. pos0 = pos;
  6796. pos1 = pos;
  6797. if (input.substr(pos, 6).toLowerCase() === "maddr=") {
  6798. result0 = input.substr(pos, 6);
  6799. pos += 6;
  6800. } else {
  6801. result0 = null;
  6802. if (reportFailures === 0) {
  6803. matchFailed("\"maddr=\"");
  6804. }
  6805. }
  6806. if (result0 !== null) {
  6807. result1 = parse_host();
  6808. if (result1 !== null) {
  6809. result0 = [result0, result1];
  6810. } else {
  6811. result0 = null;
  6812. pos = pos1;
  6813. }
  6814. } else {
  6815. result0 = null;
  6816. pos = pos1;
  6817. }
  6818. if (result0 !== null) {
  6819. result0 = function (offset, maddr) {
  6820. if (!data.uri_params) data.uri_params = {};
  6821. data.uri_params['maddr'] = maddr;
  6822. }(pos0, result0[1]);
  6823. }
  6824. if (result0 === null) {
  6825. pos = pos0;
  6826. }
  6827. return result0;
  6828. }
  6829. function parse_lr_param() {
  6830. var result0, result1, result2;
  6831. var pos0, pos1, pos2;
  6832. pos0 = pos;
  6833. pos1 = pos;
  6834. if (input.substr(pos, 2).toLowerCase() === "lr") {
  6835. result0 = input.substr(pos, 2);
  6836. pos += 2;
  6837. } else {
  6838. result0 = null;
  6839. if (reportFailures === 0) {
  6840. matchFailed("\"lr\"");
  6841. }
  6842. }
  6843. if (result0 !== null) {
  6844. pos2 = pos;
  6845. if (input.charCodeAt(pos) === 61) {
  6846. result1 = "=";
  6847. pos++;
  6848. } else {
  6849. result1 = null;
  6850. if (reportFailures === 0) {
  6851. matchFailed("\"=\"");
  6852. }
  6853. }
  6854. if (result1 !== null) {
  6855. result2 = parse_token();
  6856. if (result2 !== null) {
  6857. result1 = [result1, result2];
  6858. } else {
  6859. result1 = null;
  6860. pos = pos2;
  6861. }
  6862. } else {
  6863. result1 = null;
  6864. pos = pos2;
  6865. }
  6866. result1 = result1 !== null ? result1 : "";
  6867. if (result1 !== null) {
  6868. result0 = [result0, result1];
  6869. } else {
  6870. result0 = null;
  6871. pos = pos1;
  6872. }
  6873. } else {
  6874. result0 = null;
  6875. pos = pos1;
  6876. }
  6877. if (result0 !== null) {
  6878. result0 = function (offset) {
  6879. if (!data.uri_params) data.uri_params = {};
  6880. data.uri_params['lr'] = undefined;
  6881. }(pos0);
  6882. }
  6883. if (result0 === null) {
  6884. pos = pos0;
  6885. }
  6886. return result0;
  6887. }
  6888. function parse_other_param() {
  6889. var result0, result1, result2;
  6890. var pos0, pos1, pos2;
  6891. pos0 = pos;
  6892. pos1 = pos;
  6893. result0 = parse_pname();
  6894. if (result0 !== null) {
  6895. pos2 = pos;
  6896. if (input.charCodeAt(pos) === 61) {
  6897. result1 = "=";
  6898. pos++;
  6899. } else {
  6900. result1 = null;
  6901. if (reportFailures === 0) {
  6902. matchFailed("\"=\"");
  6903. }
  6904. }
  6905. if (result1 !== null) {
  6906. result2 = parse_pvalue();
  6907. if (result2 !== null) {
  6908. result1 = [result1, result2];
  6909. } else {
  6910. result1 = null;
  6911. pos = pos2;
  6912. }
  6913. } else {
  6914. result1 = null;
  6915. pos = pos2;
  6916. }
  6917. result1 = result1 !== null ? result1 : "";
  6918. if (result1 !== null) {
  6919. result0 = [result0, result1];
  6920. } else {
  6921. result0 = null;
  6922. pos = pos1;
  6923. }
  6924. } else {
  6925. result0 = null;
  6926. pos = pos1;
  6927. }
  6928. if (result0 !== null) {
  6929. result0 = function (offset, param, value) {
  6930. if (!data.uri_params) data.uri_params = {};
  6931. if (typeof value === 'undefined') {
  6932. value = undefined;
  6933. } else {
  6934. value = value[1];
  6935. }
  6936. data.uri_params[param.toLowerCase()] = value;
  6937. }(pos0, result0[0], result0[1]);
  6938. }
  6939. if (result0 === null) {
  6940. pos = pos0;
  6941. }
  6942. return result0;
  6943. }
  6944. function parse_pname() {
  6945. var result0, result1;
  6946. var pos0;
  6947. pos0 = pos;
  6948. result1 = parse_paramchar();
  6949. if (result1 !== null) {
  6950. result0 = [];
  6951. while (result1 !== null) {
  6952. result0.push(result1);
  6953. result1 = parse_paramchar();
  6954. }
  6955. } else {
  6956. result0 = null;
  6957. }
  6958. if (result0 !== null) {
  6959. result0 = function (offset, pname) {
  6960. return pname.join('');
  6961. }(pos0, result0);
  6962. }
  6963. if (result0 === null) {
  6964. pos = pos0;
  6965. }
  6966. return result0;
  6967. }
  6968. function parse_pvalue() {
  6969. var result0, result1;
  6970. var pos0;
  6971. pos0 = pos;
  6972. result1 = parse_paramchar();
  6973. if (result1 !== null) {
  6974. result0 = [];
  6975. while (result1 !== null) {
  6976. result0.push(result1);
  6977. result1 = parse_paramchar();
  6978. }
  6979. } else {
  6980. result0 = null;
  6981. }
  6982. if (result0 !== null) {
  6983. result0 = function (offset, pvalue) {
  6984. return pvalue.join('');
  6985. }(pos0, result0);
  6986. }
  6987. if (result0 === null) {
  6988. pos = pos0;
  6989. }
  6990. return result0;
  6991. }
  6992. function parse_paramchar() {
  6993. var result0;
  6994. result0 = parse_param_unreserved();
  6995. if (result0 === null) {
  6996. result0 = parse_unreserved();
  6997. if (result0 === null) {
  6998. result0 = parse_escaped();
  6999. }
  7000. }
  7001. return result0;
  7002. }
  7003. function parse_param_unreserved() {
  7004. var result0;
  7005. if (input.charCodeAt(pos) === 91) {
  7006. result0 = "[";
  7007. pos++;
  7008. } else {
  7009. result0 = null;
  7010. if (reportFailures === 0) {
  7011. matchFailed("\"[\"");
  7012. }
  7013. }
  7014. if (result0 === null) {
  7015. if (input.charCodeAt(pos) === 93) {
  7016. result0 = "]";
  7017. pos++;
  7018. } else {
  7019. result0 = null;
  7020. if (reportFailures === 0) {
  7021. matchFailed("\"]\"");
  7022. }
  7023. }
  7024. if (result0 === null) {
  7025. if (input.charCodeAt(pos) === 47) {
  7026. result0 = "/";
  7027. pos++;
  7028. } else {
  7029. result0 = null;
  7030. if (reportFailures === 0) {
  7031. matchFailed("\"/\"");
  7032. }
  7033. }
  7034. if (result0 === null) {
  7035. if (input.charCodeAt(pos) === 58) {
  7036. result0 = ":";
  7037. pos++;
  7038. } else {
  7039. result0 = null;
  7040. if (reportFailures === 0) {
  7041. matchFailed("\":\"");
  7042. }
  7043. }
  7044. if (result0 === null) {
  7045. if (input.charCodeAt(pos) === 38) {
  7046. result0 = "&";
  7047. pos++;
  7048. } else {
  7049. result0 = null;
  7050. if (reportFailures === 0) {
  7051. matchFailed("\"&\"");
  7052. }
  7053. }
  7054. if (result0 === null) {
  7055. if (input.charCodeAt(pos) === 43) {
  7056. result0 = "+";
  7057. pos++;
  7058. } else {
  7059. result0 = null;
  7060. if (reportFailures === 0) {
  7061. matchFailed("\"+\"");
  7062. }
  7063. }
  7064. if (result0 === null) {
  7065. if (input.charCodeAt(pos) === 36) {
  7066. result0 = "$";
  7067. pos++;
  7068. } else {
  7069. result0 = null;
  7070. if (reportFailures === 0) {
  7071. matchFailed("\"$\"");
  7072. }
  7073. }
  7074. }
  7075. }
  7076. }
  7077. }
  7078. }
  7079. }
  7080. return result0;
  7081. }
  7082. function parse_headers() {
  7083. var result0, result1, result2, result3, result4;
  7084. var pos0, pos1;
  7085. pos0 = pos;
  7086. if (input.charCodeAt(pos) === 63) {
  7087. result0 = "?";
  7088. pos++;
  7089. } else {
  7090. result0 = null;
  7091. if (reportFailures === 0) {
  7092. matchFailed("\"?\"");
  7093. }
  7094. }
  7095. if (result0 !== null) {
  7096. result1 = parse_header();
  7097. if (result1 !== null) {
  7098. result2 = [];
  7099. pos1 = pos;
  7100. if (input.charCodeAt(pos) === 38) {
  7101. result3 = "&";
  7102. pos++;
  7103. } else {
  7104. result3 = null;
  7105. if (reportFailures === 0) {
  7106. matchFailed("\"&\"");
  7107. }
  7108. }
  7109. if (result3 !== null) {
  7110. result4 = parse_header();
  7111. if (result4 !== null) {
  7112. result3 = [result3, result4];
  7113. } else {
  7114. result3 = null;
  7115. pos = pos1;
  7116. }
  7117. } else {
  7118. result3 = null;
  7119. pos = pos1;
  7120. }
  7121. while (result3 !== null) {
  7122. result2.push(result3);
  7123. pos1 = pos;
  7124. if (input.charCodeAt(pos) === 38) {
  7125. result3 = "&";
  7126. pos++;
  7127. } else {
  7128. result3 = null;
  7129. if (reportFailures === 0) {
  7130. matchFailed("\"&\"");
  7131. }
  7132. }
  7133. if (result3 !== null) {
  7134. result4 = parse_header();
  7135. if (result4 !== null) {
  7136. result3 = [result3, result4];
  7137. } else {
  7138. result3 = null;
  7139. pos = pos1;
  7140. }
  7141. } else {
  7142. result3 = null;
  7143. pos = pos1;
  7144. }
  7145. }
  7146. if (result2 !== null) {
  7147. result0 = [result0, result1, result2];
  7148. } else {
  7149. result0 = null;
  7150. pos = pos0;
  7151. }
  7152. } else {
  7153. result0 = null;
  7154. pos = pos0;
  7155. }
  7156. } else {
  7157. result0 = null;
  7158. pos = pos0;
  7159. }
  7160. return result0;
  7161. }
  7162. function parse_header() {
  7163. var result0, result1, result2;
  7164. var pos0, pos1;
  7165. pos0 = pos;
  7166. pos1 = pos;
  7167. result0 = parse_hname();
  7168. if (result0 !== null) {
  7169. if (input.charCodeAt(pos) === 61) {
  7170. result1 = "=";
  7171. pos++;
  7172. } else {
  7173. result1 = null;
  7174. if (reportFailures === 0) {
  7175. matchFailed("\"=\"");
  7176. }
  7177. }
  7178. if (result1 !== null) {
  7179. result2 = parse_hvalue();
  7180. if (result2 !== null) {
  7181. result0 = [result0, result1, result2];
  7182. } else {
  7183. result0 = null;
  7184. pos = pos1;
  7185. }
  7186. } else {
  7187. result0 = null;
  7188. pos = pos1;
  7189. }
  7190. } else {
  7191. result0 = null;
  7192. pos = pos1;
  7193. }
  7194. if (result0 !== null) {
  7195. result0 = function (offset, hname, hvalue) {
  7196. hname = hname.join('').toLowerCase();
  7197. hvalue = hvalue.join('');
  7198. if (!data.uri_headers) data.uri_headers = {};
  7199. if (!data.uri_headers[hname]) {
  7200. data.uri_headers[hname] = [hvalue];
  7201. } else {
  7202. data.uri_headers[hname].push(hvalue);
  7203. }
  7204. }(pos0, result0[0], result0[2]);
  7205. }
  7206. if (result0 === null) {
  7207. pos = pos0;
  7208. }
  7209. return result0;
  7210. }
  7211. function parse_hname() {
  7212. var result0, result1;
  7213. result1 = parse_hnv_unreserved();
  7214. if (result1 === null) {
  7215. result1 = parse_unreserved();
  7216. if (result1 === null) {
  7217. result1 = parse_escaped();
  7218. }
  7219. }
  7220. if (result1 !== null) {
  7221. result0 = [];
  7222. while (result1 !== null) {
  7223. result0.push(result1);
  7224. result1 = parse_hnv_unreserved();
  7225. if (result1 === null) {
  7226. result1 = parse_unreserved();
  7227. if (result1 === null) {
  7228. result1 = parse_escaped();
  7229. }
  7230. }
  7231. }
  7232. } else {
  7233. result0 = null;
  7234. }
  7235. return result0;
  7236. }
  7237. function parse_hvalue() {
  7238. var result0, result1;
  7239. result0 = [];
  7240. result1 = parse_hnv_unreserved();
  7241. if (result1 === null) {
  7242. result1 = parse_unreserved();
  7243. if (result1 === null) {
  7244. result1 = parse_escaped();
  7245. }
  7246. }
  7247. while (result1 !== null) {
  7248. result0.push(result1);
  7249. result1 = parse_hnv_unreserved();
  7250. if (result1 === null) {
  7251. result1 = parse_unreserved();
  7252. if (result1 === null) {
  7253. result1 = parse_escaped();
  7254. }
  7255. }
  7256. }
  7257. return result0;
  7258. }
  7259. function parse_hnv_unreserved() {
  7260. var result0;
  7261. if (input.charCodeAt(pos) === 91) {
  7262. result0 = "[";
  7263. pos++;
  7264. } else {
  7265. result0 = null;
  7266. if (reportFailures === 0) {
  7267. matchFailed("\"[\"");
  7268. }
  7269. }
  7270. if (result0 === null) {
  7271. if (input.charCodeAt(pos) === 93) {
  7272. result0 = "]";
  7273. pos++;
  7274. } else {
  7275. result0 = null;
  7276. if (reportFailures === 0) {
  7277. matchFailed("\"]\"");
  7278. }
  7279. }
  7280. if (result0 === null) {
  7281. if (input.charCodeAt(pos) === 47) {
  7282. result0 = "/";
  7283. pos++;
  7284. } else {
  7285. result0 = null;
  7286. if (reportFailures === 0) {
  7287. matchFailed("\"/\"");
  7288. }
  7289. }
  7290. if (result0 === null) {
  7291. if (input.charCodeAt(pos) === 63) {
  7292. result0 = "?";
  7293. pos++;
  7294. } else {
  7295. result0 = null;
  7296. if (reportFailures === 0) {
  7297. matchFailed("\"?\"");
  7298. }
  7299. }
  7300. if (result0 === null) {
  7301. if (input.charCodeAt(pos) === 58) {
  7302. result0 = ":";
  7303. pos++;
  7304. } else {
  7305. result0 = null;
  7306. if (reportFailures === 0) {
  7307. matchFailed("\":\"");
  7308. }
  7309. }
  7310. if (result0 === null) {
  7311. if (input.charCodeAt(pos) === 43) {
  7312. result0 = "+";
  7313. pos++;
  7314. } else {
  7315. result0 = null;
  7316. if (reportFailures === 0) {
  7317. matchFailed("\"+\"");
  7318. }
  7319. }
  7320. if (result0 === null) {
  7321. if (input.charCodeAt(pos) === 36) {
  7322. result0 = "$";
  7323. pos++;
  7324. } else {
  7325. result0 = null;
  7326. if (reportFailures === 0) {
  7327. matchFailed("\"$\"");
  7328. }
  7329. }
  7330. }
  7331. }
  7332. }
  7333. }
  7334. }
  7335. }
  7336. return result0;
  7337. }
  7338. function parse_Request_Response() {
  7339. var result0;
  7340. result0 = parse_Status_Line();
  7341. if (result0 === null) {
  7342. result0 = parse_Request_Line();
  7343. }
  7344. return result0;
  7345. }
  7346. function parse_Request_Line() {
  7347. var result0, result1, result2, result3, result4;
  7348. var pos0;
  7349. pos0 = pos;
  7350. result0 = parse_Method();
  7351. if (result0 !== null) {
  7352. result1 = parse_SP();
  7353. if (result1 !== null) {
  7354. result2 = parse_Request_URI();
  7355. if (result2 !== null) {
  7356. result3 = parse_SP();
  7357. if (result3 !== null) {
  7358. result4 = parse_SIP_Version();
  7359. if (result4 !== null) {
  7360. result0 = [result0, result1, result2, result3, result4];
  7361. } else {
  7362. result0 = null;
  7363. pos = pos0;
  7364. }
  7365. } else {
  7366. result0 = null;
  7367. pos = pos0;
  7368. }
  7369. } else {
  7370. result0 = null;
  7371. pos = pos0;
  7372. }
  7373. } else {
  7374. result0 = null;
  7375. pos = pos0;
  7376. }
  7377. } else {
  7378. result0 = null;
  7379. pos = pos0;
  7380. }
  7381. return result0;
  7382. }
  7383. function parse_Request_URI() {
  7384. var result0;
  7385. result0 = parse_SIP_URI();
  7386. if (result0 === null) {
  7387. result0 = parse_absoluteURI();
  7388. }
  7389. return result0;
  7390. }
  7391. function parse_absoluteURI() {
  7392. var result0, result1, result2;
  7393. var pos0;
  7394. pos0 = pos;
  7395. result0 = parse_scheme();
  7396. if (result0 !== null) {
  7397. if (input.charCodeAt(pos) === 58) {
  7398. result1 = ":";
  7399. pos++;
  7400. } else {
  7401. result1 = null;
  7402. if (reportFailures === 0) {
  7403. matchFailed("\":\"");
  7404. }
  7405. }
  7406. if (result1 !== null) {
  7407. result2 = parse_hier_part();
  7408. if (result2 === null) {
  7409. result2 = parse_opaque_part();
  7410. }
  7411. if (result2 !== null) {
  7412. result0 = [result0, result1, result2];
  7413. } else {
  7414. result0 = null;
  7415. pos = pos0;
  7416. }
  7417. } else {
  7418. result0 = null;
  7419. pos = pos0;
  7420. }
  7421. } else {
  7422. result0 = null;
  7423. pos = pos0;
  7424. }
  7425. return result0;
  7426. }
  7427. function parse_hier_part() {
  7428. var result0, result1, result2;
  7429. var pos0, pos1;
  7430. pos0 = pos;
  7431. result0 = parse_net_path();
  7432. if (result0 === null) {
  7433. result0 = parse_abs_path();
  7434. }
  7435. if (result0 !== null) {
  7436. pos1 = pos;
  7437. if (input.charCodeAt(pos) === 63) {
  7438. result1 = "?";
  7439. pos++;
  7440. } else {
  7441. result1 = null;
  7442. if (reportFailures === 0) {
  7443. matchFailed("\"?\"");
  7444. }
  7445. }
  7446. if (result1 !== null) {
  7447. result2 = parse_query();
  7448. if (result2 !== null) {
  7449. result1 = [result1, result2];
  7450. } else {
  7451. result1 = null;
  7452. pos = pos1;
  7453. }
  7454. } else {
  7455. result1 = null;
  7456. pos = pos1;
  7457. }
  7458. result1 = result1 !== null ? result1 : "";
  7459. if (result1 !== null) {
  7460. result0 = [result0, result1];
  7461. } else {
  7462. result0 = null;
  7463. pos = pos0;
  7464. }
  7465. } else {
  7466. result0 = null;
  7467. pos = pos0;
  7468. }
  7469. return result0;
  7470. }
  7471. function parse_net_path() {
  7472. var result0, result1, result2;
  7473. var pos0;
  7474. pos0 = pos;
  7475. if (input.substr(pos, 2) === "//") {
  7476. result0 = "//";
  7477. pos += 2;
  7478. } else {
  7479. result0 = null;
  7480. if (reportFailures === 0) {
  7481. matchFailed("\"//\"");
  7482. }
  7483. }
  7484. if (result0 !== null) {
  7485. result1 = parse_authority();
  7486. if (result1 !== null) {
  7487. result2 = parse_abs_path();
  7488. result2 = result2 !== null ? result2 : "";
  7489. if (result2 !== null) {
  7490. result0 = [result0, result1, result2];
  7491. } else {
  7492. result0 = null;
  7493. pos = pos0;
  7494. }
  7495. } else {
  7496. result0 = null;
  7497. pos = pos0;
  7498. }
  7499. } else {
  7500. result0 = null;
  7501. pos = pos0;
  7502. }
  7503. return result0;
  7504. }
  7505. function parse_abs_path() {
  7506. var result0, result1;
  7507. var pos0;
  7508. pos0 = pos;
  7509. if (input.charCodeAt(pos) === 47) {
  7510. result0 = "/";
  7511. pos++;
  7512. } else {
  7513. result0 = null;
  7514. if (reportFailures === 0) {
  7515. matchFailed("\"/\"");
  7516. }
  7517. }
  7518. if (result0 !== null) {
  7519. result1 = parse_path_segments();
  7520. if (result1 !== null) {
  7521. result0 = [result0, result1];
  7522. } else {
  7523. result0 = null;
  7524. pos = pos0;
  7525. }
  7526. } else {
  7527. result0 = null;
  7528. pos = pos0;
  7529. }
  7530. return result0;
  7531. }
  7532. function parse_opaque_part() {
  7533. var result0, result1, result2;
  7534. var pos0;
  7535. pos0 = pos;
  7536. result0 = parse_uric_no_slash();
  7537. if (result0 !== null) {
  7538. result1 = [];
  7539. result2 = parse_uric();
  7540. while (result2 !== null) {
  7541. result1.push(result2);
  7542. result2 = parse_uric();
  7543. }
  7544. if (result1 !== null) {
  7545. result0 = [result0, result1];
  7546. } else {
  7547. result0 = null;
  7548. pos = pos0;
  7549. }
  7550. } else {
  7551. result0 = null;
  7552. pos = pos0;
  7553. }
  7554. return result0;
  7555. }
  7556. function parse_uric() {
  7557. var result0;
  7558. result0 = parse_reserved();
  7559. if (result0 === null) {
  7560. result0 = parse_unreserved();
  7561. if (result0 === null) {
  7562. result0 = parse_escaped();
  7563. }
  7564. }
  7565. return result0;
  7566. }
  7567. function parse_uric_no_slash() {
  7568. var result0;
  7569. result0 = parse_unreserved();
  7570. if (result0 === null) {
  7571. result0 = parse_escaped();
  7572. if (result0 === null) {
  7573. if (input.charCodeAt(pos) === 59) {
  7574. result0 = ";";
  7575. pos++;
  7576. } else {
  7577. result0 = null;
  7578. if (reportFailures === 0) {
  7579. matchFailed("\";\"");
  7580. }
  7581. }
  7582. if (result0 === null) {
  7583. if (input.charCodeAt(pos) === 63) {
  7584. result0 = "?";
  7585. pos++;
  7586. } else {
  7587. result0 = null;
  7588. if (reportFailures === 0) {
  7589. matchFailed("\"?\"");
  7590. }
  7591. }
  7592. if (result0 === null) {
  7593. if (input.charCodeAt(pos) === 58) {
  7594. result0 = ":";
  7595. pos++;
  7596. } else {
  7597. result0 = null;
  7598. if (reportFailures === 0) {
  7599. matchFailed("\":\"");
  7600. }
  7601. }
  7602. if (result0 === null) {
  7603. if (input.charCodeAt(pos) === 64) {
  7604. result0 = "@";
  7605. pos++;
  7606. } else {
  7607. result0 = null;
  7608. if (reportFailures === 0) {
  7609. matchFailed("\"@\"");
  7610. }
  7611. }
  7612. if (result0 === null) {
  7613. if (input.charCodeAt(pos) === 38) {
  7614. result0 = "&";
  7615. pos++;
  7616. } else {
  7617. result0 = null;
  7618. if (reportFailures === 0) {
  7619. matchFailed("\"&\"");
  7620. }
  7621. }
  7622. if (result0 === null) {
  7623. if (input.charCodeAt(pos) === 61) {
  7624. result0 = "=";
  7625. pos++;
  7626. } else {
  7627. result0 = null;
  7628. if (reportFailures === 0) {
  7629. matchFailed("\"=\"");
  7630. }
  7631. }
  7632. if (result0 === null) {
  7633. if (input.charCodeAt(pos) === 43) {
  7634. result0 = "+";
  7635. pos++;
  7636. } else {
  7637. result0 = null;
  7638. if (reportFailures === 0) {
  7639. matchFailed("\"+\"");
  7640. }
  7641. }
  7642. if (result0 === null) {
  7643. if (input.charCodeAt(pos) === 36) {
  7644. result0 = "$";
  7645. pos++;
  7646. } else {
  7647. result0 = null;
  7648. if (reportFailures === 0) {
  7649. matchFailed("\"$\"");
  7650. }
  7651. }
  7652. if (result0 === null) {
  7653. if (input.charCodeAt(pos) === 44) {
  7654. result0 = ",";
  7655. pos++;
  7656. } else {
  7657. result0 = null;
  7658. if (reportFailures === 0) {
  7659. matchFailed("\",\"");
  7660. }
  7661. }
  7662. }
  7663. }
  7664. }
  7665. }
  7666. }
  7667. }
  7668. }
  7669. }
  7670. }
  7671. }
  7672. return result0;
  7673. }
  7674. function parse_path_segments() {
  7675. var result0, result1, result2, result3;
  7676. var pos0, pos1;
  7677. pos0 = pos;
  7678. result0 = parse_segment();
  7679. if (result0 !== null) {
  7680. result1 = [];
  7681. pos1 = pos;
  7682. if (input.charCodeAt(pos) === 47) {
  7683. result2 = "/";
  7684. pos++;
  7685. } else {
  7686. result2 = null;
  7687. if (reportFailures === 0) {
  7688. matchFailed("\"/\"");
  7689. }
  7690. }
  7691. if (result2 !== null) {
  7692. result3 = parse_segment();
  7693. if (result3 !== null) {
  7694. result2 = [result2, result3];
  7695. } else {
  7696. result2 = null;
  7697. pos = pos1;
  7698. }
  7699. } else {
  7700. result2 = null;
  7701. pos = pos1;
  7702. }
  7703. while (result2 !== null) {
  7704. result1.push(result2);
  7705. pos1 = pos;
  7706. if (input.charCodeAt(pos) === 47) {
  7707. result2 = "/";
  7708. pos++;
  7709. } else {
  7710. result2 = null;
  7711. if (reportFailures === 0) {
  7712. matchFailed("\"/\"");
  7713. }
  7714. }
  7715. if (result2 !== null) {
  7716. result3 = parse_segment();
  7717. if (result3 !== null) {
  7718. result2 = [result2, result3];
  7719. } else {
  7720. result2 = null;
  7721. pos = pos1;
  7722. }
  7723. } else {
  7724. result2 = null;
  7725. pos = pos1;
  7726. }
  7727. }
  7728. if (result1 !== null) {
  7729. result0 = [result0, result1];
  7730. } else {
  7731. result0 = null;
  7732. pos = pos0;
  7733. }
  7734. } else {
  7735. result0 = null;
  7736. pos = pos0;
  7737. }
  7738. return result0;
  7739. }
  7740. function parse_segment() {
  7741. var result0, result1, result2, result3;
  7742. var pos0, pos1;
  7743. pos0 = pos;
  7744. result0 = [];
  7745. result1 = parse_pchar();
  7746. while (result1 !== null) {
  7747. result0.push(result1);
  7748. result1 = parse_pchar();
  7749. }
  7750. if (result0 !== null) {
  7751. result1 = [];
  7752. pos1 = pos;
  7753. if (input.charCodeAt(pos) === 59) {
  7754. result2 = ";";
  7755. pos++;
  7756. } else {
  7757. result2 = null;
  7758. if (reportFailures === 0) {
  7759. matchFailed("\";\"");
  7760. }
  7761. }
  7762. if (result2 !== null) {
  7763. result3 = parse_param();
  7764. if (result3 !== null) {
  7765. result2 = [result2, result3];
  7766. } else {
  7767. result2 = null;
  7768. pos = pos1;
  7769. }
  7770. } else {
  7771. result2 = null;
  7772. pos = pos1;
  7773. }
  7774. while (result2 !== null) {
  7775. result1.push(result2);
  7776. pos1 = pos;
  7777. if (input.charCodeAt(pos) === 59) {
  7778. result2 = ";";
  7779. pos++;
  7780. } else {
  7781. result2 = null;
  7782. if (reportFailures === 0) {
  7783. matchFailed("\";\"");
  7784. }
  7785. }
  7786. if (result2 !== null) {
  7787. result3 = parse_param();
  7788. if (result3 !== null) {
  7789. result2 = [result2, result3];
  7790. } else {
  7791. result2 = null;
  7792. pos = pos1;
  7793. }
  7794. } else {
  7795. result2 = null;
  7796. pos = pos1;
  7797. }
  7798. }
  7799. if (result1 !== null) {
  7800. result0 = [result0, result1];
  7801. } else {
  7802. result0 = null;
  7803. pos = pos0;
  7804. }
  7805. } else {
  7806. result0 = null;
  7807. pos = pos0;
  7808. }
  7809. return result0;
  7810. }
  7811. function parse_param() {
  7812. var result0, result1;
  7813. result0 = [];
  7814. result1 = parse_pchar();
  7815. while (result1 !== null) {
  7816. result0.push(result1);
  7817. result1 = parse_pchar();
  7818. }
  7819. return result0;
  7820. }
  7821. function parse_pchar() {
  7822. var result0;
  7823. result0 = parse_unreserved();
  7824. if (result0 === null) {
  7825. result0 = parse_escaped();
  7826. if (result0 === null) {
  7827. if (input.charCodeAt(pos) === 58) {
  7828. result0 = ":";
  7829. pos++;
  7830. } else {
  7831. result0 = null;
  7832. if (reportFailures === 0) {
  7833. matchFailed("\":\"");
  7834. }
  7835. }
  7836. if (result0 === null) {
  7837. if (input.charCodeAt(pos) === 64) {
  7838. result0 = "@";
  7839. pos++;
  7840. } else {
  7841. result0 = null;
  7842. if (reportFailures === 0) {
  7843. matchFailed("\"@\"");
  7844. }
  7845. }
  7846. if (result0 === null) {
  7847. if (input.charCodeAt(pos) === 38) {
  7848. result0 = "&";
  7849. pos++;
  7850. } else {
  7851. result0 = null;
  7852. if (reportFailures === 0) {
  7853. matchFailed("\"&\"");
  7854. }
  7855. }
  7856. if (result0 === null) {
  7857. if (input.charCodeAt(pos) === 61) {
  7858. result0 = "=";
  7859. pos++;
  7860. } else {
  7861. result0 = null;
  7862. if (reportFailures === 0) {
  7863. matchFailed("\"=\"");
  7864. }
  7865. }
  7866. if (result0 === null) {
  7867. if (input.charCodeAt(pos) === 43) {
  7868. result0 = "+";
  7869. pos++;
  7870. } else {
  7871. result0 = null;
  7872. if (reportFailures === 0) {
  7873. matchFailed("\"+\"");
  7874. }
  7875. }
  7876. if (result0 === null) {
  7877. if (input.charCodeAt(pos) === 36) {
  7878. result0 = "$";
  7879. pos++;
  7880. } else {
  7881. result0 = null;
  7882. if (reportFailures === 0) {
  7883. matchFailed("\"$\"");
  7884. }
  7885. }
  7886. if (result0 === null) {
  7887. if (input.charCodeAt(pos) === 44) {
  7888. result0 = ",";
  7889. pos++;
  7890. } else {
  7891. result0 = null;
  7892. if (reportFailures === 0) {
  7893. matchFailed("\",\"");
  7894. }
  7895. }
  7896. }
  7897. }
  7898. }
  7899. }
  7900. }
  7901. }
  7902. }
  7903. }
  7904. return result0;
  7905. }
  7906. function parse_scheme() {
  7907. var result0, result1, result2;
  7908. var pos0, pos1;
  7909. pos0 = pos;
  7910. pos1 = pos;
  7911. result0 = parse_ALPHA();
  7912. if (result0 !== null) {
  7913. result1 = [];
  7914. result2 = parse_ALPHA();
  7915. if (result2 === null) {
  7916. result2 = parse_DIGIT();
  7917. if (result2 === null) {
  7918. if (input.charCodeAt(pos) === 43) {
  7919. result2 = "+";
  7920. pos++;
  7921. } else {
  7922. result2 = null;
  7923. if (reportFailures === 0) {
  7924. matchFailed("\"+\"");
  7925. }
  7926. }
  7927. if (result2 === null) {
  7928. if (input.charCodeAt(pos) === 45) {
  7929. result2 = "-";
  7930. pos++;
  7931. } else {
  7932. result2 = null;
  7933. if (reportFailures === 0) {
  7934. matchFailed("\"-\"");
  7935. }
  7936. }
  7937. if (result2 === null) {
  7938. if (input.charCodeAt(pos) === 46) {
  7939. result2 = ".";
  7940. pos++;
  7941. } else {
  7942. result2 = null;
  7943. if (reportFailures === 0) {
  7944. matchFailed("\".\"");
  7945. }
  7946. }
  7947. }
  7948. }
  7949. }
  7950. }
  7951. while (result2 !== null) {
  7952. result1.push(result2);
  7953. result2 = parse_ALPHA();
  7954. if (result2 === null) {
  7955. result2 = parse_DIGIT();
  7956. if (result2 === null) {
  7957. if (input.charCodeAt(pos) === 43) {
  7958. result2 = "+";
  7959. pos++;
  7960. } else {
  7961. result2 = null;
  7962. if (reportFailures === 0) {
  7963. matchFailed("\"+\"");
  7964. }
  7965. }
  7966. if (result2 === null) {
  7967. if (input.charCodeAt(pos) === 45) {
  7968. result2 = "-";
  7969. pos++;
  7970. } else {
  7971. result2 = null;
  7972. if (reportFailures === 0) {
  7973. matchFailed("\"-\"");
  7974. }
  7975. }
  7976. if (result2 === null) {
  7977. if (input.charCodeAt(pos) === 46) {
  7978. result2 = ".";
  7979. pos++;
  7980. } else {
  7981. result2 = null;
  7982. if (reportFailures === 0) {
  7983. matchFailed("\".\"");
  7984. }
  7985. }
  7986. }
  7987. }
  7988. }
  7989. }
  7990. }
  7991. if (result1 !== null) {
  7992. result0 = [result0, result1];
  7993. } else {
  7994. result0 = null;
  7995. pos = pos1;
  7996. }
  7997. } else {
  7998. result0 = null;
  7999. pos = pos1;
  8000. }
  8001. if (result0 !== null) {
  8002. result0 = function (offset) {
  8003. data.scheme = input.substring(pos, offset);
  8004. }(pos0);
  8005. }
  8006. if (result0 === null) {
  8007. pos = pos0;
  8008. }
  8009. return result0;
  8010. }
  8011. function parse_authority() {
  8012. var result0;
  8013. result0 = parse_srvr();
  8014. if (result0 === null) {
  8015. result0 = parse_reg_name();
  8016. }
  8017. return result0;
  8018. }
  8019. function parse_srvr() {
  8020. var result0, result1;
  8021. var pos0, pos1;
  8022. pos0 = pos;
  8023. pos1 = pos;
  8024. result0 = parse_userinfo();
  8025. if (result0 !== null) {
  8026. if (input.charCodeAt(pos) === 64) {
  8027. result1 = "@";
  8028. pos++;
  8029. } else {
  8030. result1 = null;
  8031. if (reportFailures === 0) {
  8032. matchFailed("\"@\"");
  8033. }
  8034. }
  8035. if (result1 !== null) {
  8036. result0 = [result0, result1];
  8037. } else {
  8038. result0 = null;
  8039. pos = pos1;
  8040. }
  8041. } else {
  8042. result0 = null;
  8043. pos = pos1;
  8044. }
  8045. result0 = result0 !== null ? result0 : "";
  8046. if (result0 !== null) {
  8047. result1 = parse_hostport();
  8048. if (result1 !== null) {
  8049. result0 = [result0, result1];
  8050. } else {
  8051. result0 = null;
  8052. pos = pos0;
  8053. }
  8054. } else {
  8055. result0 = null;
  8056. pos = pos0;
  8057. }
  8058. result0 = result0 !== null ? result0 : "";
  8059. return result0;
  8060. }
  8061. function parse_reg_name() {
  8062. var result0, result1;
  8063. result1 = parse_unreserved();
  8064. if (result1 === null) {
  8065. result1 = parse_escaped();
  8066. if (result1 === null) {
  8067. if (input.charCodeAt(pos) === 36) {
  8068. result1 = "$";
  8069. pos++;
  8070. } else {
  8071. result1 = null;
  8072. if (reportFailures === 0) {
  8073. matchFailed("\"$\"");
  8074. }
  8075. }
  8076. if (result1 === null) {
  8077. if (input.charCodeAt(pos) === 44) {
  8078. result1 = ",";
  8079. pos++;
  8080. } else {
  8081. result1 = null;
  8082. if (reportFailures === 0) {
  8083. matchFailed("\",\"");
  8084. }
  8085. }
  8086. if (result1 === null) {
  8087. if (input.charCodeAt(pos) === 59) {
  8088. result1 = ";";
  8089. pos++;
  8090. } else {
  8091. result1 = null;
  8092. if (reportFailures === 0) {
  8093. matchFailed("\";\"");
  8094. }
  8095. }
  8096. if (result1 === null) {
  8097. if (input.charCodeAt(pos) === 58) {
  8098. result1 = ":";
  8099. pos++;
  8100. } else {
  8101. result1 = null;
  8102. if (reportFailures === 0) {
  8103. matchFailed("\":\"");
  8104. }
  8105. }
  8106. if (result1 === null) {
  8107. if (input.charCodeAt(pos) === 64) {
  8108. result1 = "@";
  8109. pos++;
  8110. } else {
  8111. result1 = null;
  8112. if (reportFailures === 0) {
  8113. matchFailed("\"@\"");
  8114. }
  8115. }
  8116. if (result1 === null) {
  8117. if (input.charCodeAt(pos) === 38) {
  8118. result1 = "&";
  8119. pos++;
  8120. } else {
  8121. result1 = null;
  8122. if (reportFailures === 0) {
  8123. matchFailed("\"&\"");
  8124. }
  8125. }
  8126. if (result1 === null) {
  8127. if (input.charCodeAt(pos) === 61) {
  8128. result1 = "=";
  8129. pos++;
  8130. } else {
  8131. result1 = null;
  8132. if (reportFailures === 0) {
  8133. matchFailed("\"=\"");
  8134. }
  8135. }
  8136. if (result1 === null) {
  8137. if (input.charCodeAt(pos) === 43) {
  8138. result1 = "+";
  8139. pos++;
  8140. } else {
  8141. result1 = null;
  8142. if (reportFailures === 0) {
  8143. matchFailed("\"+\"");
  8144. }
  8145. }
  8146. }
  8147. }
  8148. }
  8149. }
  8150. }
  8151. }
  8152. }
  8153. }
  8154. }
  8155. if (result1 !== null) {
  8156. result0 = [];
  8157. while (result1 !== null) {
  8158. result0.push(result1);
  8159. result1 = parse_unreserved();
  8160. if (result1 === null) {
  8161. result1 = parse_escaped();
  8162. if (result1 === null) {
  8163. if (input.charCodeAt(pos) === 36) {
  8164. result1 = "$";
  8165. pos++;
  8166. } else {
  8167. result1 = null;
  8168. if (reportFailures === 0) {
  8169. matchFailed("\"$\"");
  8170. }
  8171. }
  8172. if (result1 === null) {
  8173. if (input.charCodeAt(pos) === 44) {
  8174. result1 = ",";
  8175. pos++;
  8176. } else {
  8177. result1 = null;
  8178. if (reportFailures === 0) {
  8179. matchFailed("\",\"");
  8180. }
  8181. }
  8182. if (result1 === null) {
  8183. if (input.charCodeAt(pos) === 59) {
  8184. result1 = ";";
  8185. pos++;
  8186. } else {
  8187. result1 = null;
  8188. if (reportFailures === 0) {
  8189. matchFailed("\";\"");
  8190. }
  8191. }
  8192. if (result1 === null) {
  8193. if (input.charCodeAt(pos) === 58) {
  8194. result1 = ":";
  8195. pos++;
  8196. } else {
  8197. result1 = null;
  8198. if (reportFailures === 0) {
  8199. matchFailed("\":\"");
  8200. }
  8201. }
  8202. if (result1 === null) {
  8203. if (input.charCodeAt(pos) === 64) {
  8204. result1 = "@";
  8205. pos++;
  8206. } else {
  8207. result1 = null;
  8208. if (reportFailures === 0) {
  8209. matchFailed("\"@\"");
  8210. }
  8211. }
  8212. if (result1 === null) {
  8213. if (input.charCodeAt(pos) === 38) {
  8214. result1 = "&";
  8215. pos++;
  8216. } else {
  8217. result1 = null;
  8218. if (reportFailures === 0) {
  8219. matchFailed("\"&\"");
  8220. }
  8221. }
  8222. if (result1 === null) {
  8223. if (input.charCodeAt(pos) === 61) {
  8224. result1 = "=";
  8225. pos++;
  8226. } else {
  8227. result1 = null;
  8228. if (reportFailures === 0) {
  8229. matchFailed("\"=\"");
  8230. }
  8231. }
  8232. if (result1 === null) {
  8233. if (input.charCodeAt(pos) === 43) {
  8234. result1 = "+";
  8235. pos++;
  8236. } else {
  8237. result1 = null;
  8238. if (reportFailures === 0) {
  8239. matchFailed("\"+\"");
  8240. }
  8241. }
  8242. }
  8243. }
  8244. }
  8245. }
  8246. }
  8247. }
  8248. }
  8249. }
  8250. }
  8251. }
  8252. } else {
  8253. result0 = null;
  8254. }
  8255. return result0;
  8256. }
  8257. function parse_query() {
  8258. var result0, result1;
  8259. result0 = [];
  8260. result1 = parse_uric();
  8261. while (result1 !== null) {
  8262. result0.push(result1);
  8263. result1 = parse_uric();
  8264. }
  8265. return result0;
  8266. }
  8267. function parse_SIP_Version() {
  8268. var result0, result1, result2, result3, result4, result5;
  8269. var pos0, pos1;
  8270. pos0 = pos;
  8271. pos1 = pos;
  8272. if (input.substr(pos, 3).toLowerCase() === "sip") {
  8273. result0 = input.substr(pos, 3);
  8274. pos += 3;
  8275. } else {
  8276. result0 = null;
  8277. if (reportFailures === 0) {
  8278. matchFailed("\"SIP\"");
  8279. }
  8280. }
  8281. if (result0 !== null) {
  8282. if (input.charCodeAt(pos) === 47) {
  8283. result1 = "/";
  8284. pos++;
  8285. } else {
  8286. result1 = null;
  8287. if (reportFailures === 0) {
  8288. matchFailed("\"/\"");
  8289. }
  8290. }
  8291. if (result1 !== null) {
  8292. result3 = parse_DIGIT();
  8293. if (result3 !== null) {
  8294. result2 = [];
  8295. while (result3 !== null) {
  8296. result2.push(result3);
  8297. result3 = parse_DIGIT();
  8298. }
  8299. } else {
  8300. result2 = null;
  8301. }
  8302. if (result2 !== null) {
  8303. if (input.charCodeAt(pos) === 46) {
  8304. result3 = ".";
  8305. pos++;
  8306. } else {
  8307. result3 = null;
  8308. if (reportFailures === 0) {
  8309. matchFailed("\".\"");
  8310. }
  8311. }
  8312. if (result3 !== null) {
  8313. result5 = parse_DIGIT();
  8314. if (result5 !== null) {
  8315. result4 = [];
  8316. while (result5 !== null) {
  8317. result4.push(result5);
  8318. result5 = parse_DIGIT();
  8319. }
  8320. } else {
  8321. result4 = null;
  8322. }
  8323. if (result4 !== null) {
  8324. result0 = [result0, result1, result2, result3, result4];
  8325. } else {
  8326. result0 = null;
  8327. pos = pos1;
  8328. }
  8329. } else {
  8330. result0 = null;
  8331. pos = pos1;
  8332. }
  8333. } else {
  8334. result0 = null;
  8335. pos = pos1;
  8336. }
  8337. } else {
  8338. result0 = null;
  8339. pos = pos1;
  8340. }
  8341. } else {
  8342. result0 = null;
  8343. pos = pos1;
  8344. }
  8345. if (result0 !== null) {
  8346. result0 = function (offset) {
  8347. data.sip_version = input.substring(pos, offset);
  8348. }(pos0);
  8349. }
  8350. if (result0 === null) {
  8351. pos = pos0;
  8352. }
  8353. return result0;
  8354. }
  8355. function parse_INVITEm() {
  8356. var result0;
  8357. if (input.substr(pos, 6) === "INVITE") {
  8358. result0 = "INVITE";
  8359. pos += 6;
  8360. } else {
  8361. result0 = null;
  8362. if (reportFailures === 0) {
  8363. matchFailed("\"INVITE\"");
  8364. }
  8365. }
  8366. return result0;
  8367. }
  8368. function parse_ACKm() {
  8369. var result0;
  8370. if (input.substr(pos, 3) === "ACK") {
  8371. result0 = "ACK";
  8372. pos += 3;
  8373. } else {
  8374. result0 = null;
  8375. if (reportFailures === 0) {
  8376. matchFailed("\"ACK\"");
  8377. }
  8378. }
  8379. return result0;
  8380. }
  8381. function parse_OPTIONSm() {
  8382. var result0;
  8383. if (input.substr(pos, 7) === "OPTIONS") {
  8384. result0 = "OPTIONS";
  8385. pos += 7;
  8386. } else {
  8387. result0 = null;
  8388. if (reportFailures === 0) {
  8389. matchFailed("\"OPTIONS\"");
  8390. }
  8391. }
  8392. return result0;
  8393. }
  8394. function parse_BYEm() {
  8395. var result0;
  8396. if (input.substr(pos, 3) === "BYE") {
  8397. result0 = "BYE";
  8398. pos += 3;
  8399. } else {
  8400. result0 = null;
  8401. if (reportFailures === 0) {
  8402. matchFailed("\"BYE\"");
  8403. }
  8404. }
  8405. return result0;
  8406. }
  8407. function parse_CANCELm() {
  8408. var result0;
  8409. if (input.substr(pos, 6) === "CANCEL") {
  8410. result0 = "CANCEL";
  8411. pos += 6;
  8412. } else {
  8413. result0 = null;
  8414. if (reportFailures === 0) {
  8415. matchFailed("\"CANCEL\"");
  8416. }
  8417. }
  8418. return result0;
  8419. }
  8420. function parse_REGISTERm() {
  8421. var result0;
  8422. if (input.substr(pos, 8) === "REGISTER") {
  8423. result0 = "REGISTER";
  8424. pos += 8;
  8425. } else {
  8426. result0 = null;
  8427. if (reportFailures === 0) {
  8428. matchFailed("\"REGISTER\"");
  8429. }
  8430. }
  8431. return result0;
  8432. }
  8433. function parse_SUBSCRIBEm() {
  8434. var result0;
  8435. if (input.substr(pos, 9) === "SUBSCRIBE") {
  8436. result0 = "SUBSCRIBE";
  8437. pos += 9;
  8438. } else {
  8439. result0 = null;
  8440. if (reportFailures === 0) {
  8441. matchFailed("\"SUBSCRIBE\"");
  8442. }
  8443. }
  8444. return result0;
  8445. }
  8446. function parse_NOTIFYm() {
  8447. var result0;
  8448. if (input.substr(pos, 6) === "NOTIFY") {
  8449. result0 = "NOTIFY";
  8450. pos += 6;
  8451. } else {
  8452. result0 = null;
  8453. if (reportFailures === 0) {
  8454. matchFailed("\"NOTIFY\"");
  8455. }
  8456. }
  8457. return result0;
  8458. }
  8459. function parse_REFERm() {
  8460. var result0;
  8461. if (input.substr(pos, 5) === "REFER") {
  8462. result0 = "REFER";
  8463. pos += 5;
  8464. } else {
  8465. result0 = null;
  8466. if (reportFailures === 0) {
  8467. matchFailed("\"REFER\"");
  8468. }
  8469. }
  8470. return result0;
  8471. }
  8472. function parse_Method() {
  8473. var result0;
  8474. var pos0;
  8475. pos0 = pos;
  8476. result0 = parse_INVITEm();
  8477. if (result0 === null) {
  8478. result0 = parse_ACKm();
  8479. if (result0 === null) {
  8480. result0 = parse_OPTIONSm();
  8481. if (result0 === null) {
  8482. result0 = parse_BYEm();
  8483. if (result0 === null) {
  8484. result0 = parse_CANCELm();
  8485. if (result0 === null) {
  8486. result0 = parse_REGISTERm();
  8487. if (result0 === null) {
  8488. result0 = parse_SUBSCRIBEm();
  8489. if (result0 === null) {
  8490. result0 = parse_NOTIFYm();
  8491. if (result0 === null) {
  8492. result0 = parse_REFERm();
  8493. if (result0 === null) {
  8494. result0 = parse_token();
  8495. }
  8496. }
  8497. }
  8498. }
  8499. }
  8500. }
  8501. }
  8502. }
  8503. }
  8504. if (result0 !== null) {
  8505. result0 = function (offset) {
  8506. data.method = input.substring(pos, offset);
  8507. return data.method;
  8508. }(pos0);
  8509. }
  8510. if (result0 === null) {
  8511. pos = pos0;
  8512. }
  8513. return result0;
  8514. }
  8515. function parse_Status_Line() {
  8516. var result0, result1, result2, result3, result4;
  8517. var pos0;
  8518. pos0 = pos;
  8519. result0 = parse_SIP_Version();
  8520. if (result0 !== null) {
  8521. result1 = parse_SP();
  8522. if (result1 !== null) {
  8523. result2 = parse_Status_Code();
  8524. if (result2 !== null) {
  8525. result3 = parse_SP();
  8526. if (result3 !== null) {
  8527. result4 = parse_Reason_Phrase();
  8528. if (result4 !== null) {
  8529. result0 = [result0, result1, result2, result3, result4];
  8530. } else {
  8531. result0 = null;
  8532. pos = pos0;
  8533. }
  8534. } else {
  8535. result0 = null;
  8536. pos = pos0;
  8537. }
  8538. } else {
  8539. result0 = null;
  8540. pos = pos0;
  8541. }
  8542. } else {
  8543. result0 = null;
  8544. pos = pos0;
  8545. }
  8546. } else {
  8547. result0 = null;
  8548. pos = pos0;
  8549. }
  8550. return result0;
  8551. }
  8552. function parse_Status_Code() {
  8553. var result0;
  8554. var pos0;
  8555. pos0 = pos;
  8556. result0 = parse_extension_code();
  8557. if (result0 !== null) {
  8558. result0 = function (offset, status_code) {
  8559. data.status_code = parseInt(status_code.join(''));
  8560. }(pos0, result0);
  8561. }
  8562. if (result0 === null) {
  8563. pos = pos0;
  8564. }
  8565. return result0;
  8566. }
  8567. function parse_extension_code() {
  8568. var result0, result1, result2;
  8569. var pos0;
  8570. pos0 = pos;
  8571. result0 = parse_DIGIT();
  8572. if (result0 !== null) {
  8573. result1 = parse_DIGIT();
  8574. if (result1 !== null) {
  8575. result2 = parse_DIGIT();
  8576. if (result2 !== null) {
  8577. result0 = [result0, result1, result2];
  8578. } else {
  8579. result0 = null;
  8580. pos = pos0;
  8581. }
  8582. } else {
  8583. result0 = null;
  8584. pos = pos0;
  8585. }
  8586. } else {
  8587. result0 = null;
  8588. pos = pos0;
  8589. }
  8590. return result0;
  8591. }
  8592. function parse_Reason_Phrase() {
  8593. var result0, result1;
  8594. var pos0;
  8595. pos0 = pos;
  8596. result0 = [];
  8597. result1 = parse_reserved();
  8598. if (result1 === null) {
  8599. result1 = parse_unreserved();
  8600. if (result1 === null) {
  8601. result1 = parse_escaped();
  8602. if (result1 === null) {
  8603. result1 = parse_UTF8_NONASCII();
  8604. if (result1 === null) {
  8605. result1 = parse_UTF8_CONT();
  8606. if (result1 === null) {
  8607. result1 = parse_SP();
  8608. if (result1 === null) {
  8609. result1 = parse_HTAB();
  8610. }
  8611. }
  8612. }
  8613. }
  8614. }
  8615. }
  8616. while (result1 !== null) {
  8617. result0.push(result1);
  8618. result1 = parse_reserved();
  8619. if (result1 === null) {
  8620. result1 = parse_unreserved();
  8621. if (result1 === null) {
  8622. result1 = parse_escaped();
  8623. if (result1 === null) {
  8624. result1 = parse_UTF8_NONASCII();
  8625. if (result1 === null) {
  8626. result1 = parse_UTF8_CONT();
  8627. if (result1 === null) {
  8628. result1 = parse_SP();
  8629. if (result1 === null) {
  8630. result1 = parse_HTAB();
  8631. }
  8632. }
  8633. }
  8634. }
  8635. }
  8636. }
  8637. }
  8638. if (result0 !== null) {
  8639. result0 = function (offset) {
  8640. data.reason_phrase = input.substring(pos, offset);
  8641. }(pos0);
  8642. }
  8643. if (result0 === null) {
  8644. pos = pos0;
  8645. }
  8646. return result0;
  8647. }
  8648. function parse_Allow_Events() {
  8649. var result0, result1, result2, result3;
  8650. var pos0, pos1;
  8651. pos0 = pos;
  8652. result0 = parse_event_type();
  8653. if (result0 !== null) {
  8654. result1 = [];
  8655. pos1 = pos;
  8656. result2 = parse_COMMA();
  8657. if (result2 !== null) {
  8658. result3 = parse_event_type();
  8659. if (result3 !== null) {
  8660. result2 = [result2, result3];
  8661. } else {
  8662. result2 = null;
  8663. pos = pos1;
  8664. }
  8665. } else {
  8666. result2 = null;
  8667. pos = pos1;
  8668. }
  8669. while (result2 !== null) {
  8670. result1.push(result2);
  8671. pos1 = pos;
  8672. result2 = parse_COMMA();
  8673. if (result2 !== null) {
  8674. result3 = parse_event_type();
  8675. if (result3 !== null) {
  8676. result2 = [result2, result3];
  8677. } else {
  8678. result2 = null;
  8679. pos = pos1;
  8680. }
  8681. } else {
  8682. result2 = null;
  8683. pos = pos1;
  8684. }
  8685. }
  8686. if (result1 !== null) {
  8687. result0 = [result0, result1];
  8688. } else {
  8689. result0 = null;
  8690. pos = pos0;
  8691. }
  8692. } else {
  8693. result0 = null;
  8694. pos = pos0;
  8695. }
  8696. return result0;
  8697. }
  8698. function parse_Call_ID() {
  8699. var result0, result1, result2;
  8700. var pos0, pos1, pos2;
  8701. pos0 = pos;
  8702. pos1 = pos;
  8703. result0 = parse_word();
  8704. if (result0 !== null) {
  8705. pos2 = pos;
  8706. if (input.charCodeAt(pos) === 64) {
  8707. result1 = "@";
  8708. pos++;
  8709. } else {
  8710. result1 = null;
  8711. if (reportFailures === 0) {
  8712. matchFailed("\"@\"");
  8713. }
  8714. }
  8715. if (result1 !== null) {
  8716. result2 = parse_word();
  8717. if (result2 !== null) {
  8718. result1 = [result1, result2];
  8719. } else {
  8720. result1 = null;
  8721. pos = pos2;
  8722. }
  8723. } else {
  8724. result1 = null;
  8725. pos = pos2;
  8726. }
  8727. result1 = result1 !== null ? result1 : "";
  8728. if (result1 !== null) {
  8729. result0 = [result0, result1];
  8730. } else {
  8731. result0 = null;
  8732. pos = pos1;
  8733. }
  8734. } else {
  8735. result0 = null;
  8736. pos = pos1;
  8737. }
  8738. if (result0 !== null) {
  8739. result0 = function (offset) {
  8740. data = input.substring(pos, offset);
  8741. }(pos0);
  8742. }
  8743. if (result0 === null) {
  8744. pos = pos0;
  8745. }
  8746. return result0;
  8747. }
  8748. function parse_Contact() {
  8749. var result0, result1, result2, result3;
  8750. var pos0, pos1, pos2;
  8751. pos0 = pos;
  8752. result0 = parse_STAR();
  8753. if (result0 === null) {
  8754. pos1 = pos;
  8755. result0 = parse_contact_param();
  8756. if (result0 !== null) {
  8757. result1 = [];
  8758. pos2 = pos;
  8759. result2 = parse_COMMA();
  8760. if (result2 !== null) {
  8761. result3 = parse_contact_param();
  8762. if (result3 !== null) {
  8763. result2 = [result2, result3];
  8764. } else {
  8765. result2 = null;
  8766. pos = pos2;
  8767. }
  8768. } else {
  8769. result2 = null;
  8770. pos = pos2;
  8771. }
  8772. while (result2 !== null) {
  8773. result1.push(result2);
  8774. pos2 = pos;
  8775. result2 = parse_COMMA();
  8776. if (result2 !== null) {
  8777. result3 = parse_contact_param();
  8778. if (result3 !== null) {
  8779. result2 = [result2, result3];
  8780. } else {
  8781. result2 = null;
  8782. pos = pos2;
  8783. }
  8784. } else {
  8785. result2 = null;
  8786. pos = pos2;
  8787. }
  8788. }
  8789. if (result1 !== null) {
  8790. result0 = [result0, result1];
  8791. } else {
  8792. result0 = null;
  8793. pos = pos1;
  8794. }
  8795. } else {
  8796. result0 = null;
  8797. pos = pos1;
  8798. }
  8799. }
  8800. if (result0 !== null) {
  8801. result0 = function (offset) {
  8802. var idx, length;
  8803. length = data.multi_header.length;
  8804. for (idx = 0; idx < length; idx++) {
  8805. if (data.multi_header[idx].parsed === null) {
  8806. data = null;
  8807. break;
  8808. }
  8809. }
  8810. if (data !== null) {
  8811. data = data.multi_header;
  8812. } else {
  8813. data = -1;
  8814. }
  8815. }(pos0);
  8816. }
  8817. if (result0 === null) {
  8818. pos = pos0;
  8819. }
  8820. return result0;
  8821. }
  8822. function parse_contact_param() {
  8823. var result0, result1, result2, result3;
  8824. var pos0, pos1, pos2;
  8825. pos0 = pos;
  8826. pos1 = pos;
  8827. result0 = parse_SIP_URI_noparams();
  8828. if (result0 === null) {
  8829. result0 = parse_name_addr();
  8830. }
  8831. if (result0 !== null) {
  8832. result1 = [];
  8833. pos2 = pos;
  8834. result2 = parse_SEMI();
  8835. if (result2 !== null) {
  8836. result3 = parse_contact_params();
  8837. if (result3 !== null) {
  8838. result2 = [result2, result3];
  8839. } else {
  8840. result2 = null;
  8841. pos = pos2;
  8842. }
  8843. } else {
  8844. result2 = null;
  8845. pos = pos2;
  8846. }
  8847. while (result2 !== null) {
  8848. result1.push(result2);
  8849. pos2 = pos;
  8850. result2 = parse_SEMI();
  8851. if (result2 !== null) {
  8852. result3 = parse_contact_params();
  8853. if (result3 !== null) {
  8854. result2 = [result2, result3];
  8855. } else {
  8856. result2 = null;
  8857. pos = pos2;
  8858. }
  8859. } else {
  8860. result2 = null;
  8861. pos = pos2;
  8862. }
  8863. }
  8864. if (result1 !== null) {
  8865. result0 = [result0, result1];
  8866. } else {
  8867. result0 = null;
  8868. pos = pos1;
  8869. }
  8870. } else {
  8871. result0 = null;
  8872. pos = pos1;
  8873. }
  8874. if (result0 !== null) {
  8875. result0 = function (offset) {
  8876. var header;
  8877. if (!data.multi_header) data.multi_header = [];
  8878. try {
  8879. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  8880. delete data.uri;
  8881. delete data.display_name;
  8882. delete data.params;
  8883. } catch (e) {
  8884. header = null;
  8885. }
  8886. data.multi_header.push({
  8887. 'possition': pos,
  8888. 'offset': offset,
  8889. 'parsed': header
  8890. });
  8891. }(pos0);
  8892. }
  8893. if (result0 === null) {
  8894. pos = pos0;
  8895. }
  8896. return result0;
  8897. }
  8898. function parse_name_addr() {
  8899. var result0, result1, result2, result3;
  8900. var pos0;
  8901. pos0 = pos;
  8902. result0 = parse_display_name();
  8903. result0 = result0 !== null ? result0 : "";
  8904. if (result0 !== null) {
  8905. result1 = parse_LAQUOT();
  8906. if (result1 !== null) {
  8907. result2 = parse_SIP_URI();
  8908. if (result2 !== null) {
  8909. result3 = parse_RAQUOT();
  8910. if (result3 !== null) {
  8911. result0 = [result0, result1, result2, result3];
  8912. } else {
  8913. result0 = null;
  8914. pos = pos0;
  8915. }
  8916. } else {
  8917. result0 = null;
  8918. pos = pos0;
  8919. }
  8920. } else {
  8921. result0 = null;
  8922. pos = pos0;
  8923. }
  8924. } else {
  8925. result0 = null;
  8926. pos = pos0;
  8927. }
  8928. return result0;
  8929. }
  8930. function parse_display_name() {
  8931. var result0, result1, result2, result3;
  8932. var pos0, pos1, pos2;
  8933. pos0 = pos;
  8934. pos1 = pos;
  8935. result0 = parse_token();
  8936. if (result0 !== null) {
  8937. result1 = [];
  8938. pos2 = pos;
  8939. result2 = parse_LWS();
  8940. if (result2 !== null) {
  8941. result3 = parse_token();
  8942. if (result3 !== null) {
  8943. result2 = [result2, result3];
  8944. } else {
  8945. result2 = null;
  8946. pos = pos2;
  8947. }
  8948. } else {
  8949. result2 = null;
  8950. pos = pos2;
  8951. }
  8952. while (result2 !== null) {
  8953. result1.push(result2);
  8954. pos2 = pos;
  8955. result2 = parse_LWS();
  8956. if (result2 !== null) {
  8957. result3 = parse_token();
  8958. if (result3 !== null) {
  8959. result2 = [result2, result3];
  8960. } else {
  8961. result2 = null;
  8962. pos = pos2;
  8963. }
  8964. } else {
  8965. result2 = null;
  8966. pos = pos2;
  8967. }
  8968. }
  8969. if (result1 !== null) {
  8970. result0 = [result0, result1];
  8971. } else {
  8972. result0 = null;
  8973. pos = pos1;
  8974. }
  8975. } else {
  8976. result0 = null;
  8977. pos = pos1;
  8978. }
  8979. if (result0 === null) {
  8980. result0 = parse_quoted_string();
  8981. }
  8982. if (result0 !== null) {
  8983. result0 = function (offset, display_name) {
  8984. display_name = input.substring(pos, offset).trim();
  8985. if (display_name[0] === '\"') {
  8986. display_name = display_name.substring(1, display_name.length - 1);
  8987. }
  8988. data.display_name = display_name;
  8989. }(pos0, result0);
  8990. }
  8991. if (result0 === null) {
  8992. pos = pos0;
  8993. }
  8994. return result0;
  8995. }
  8996. function parse_contact_params() {
  8997. var result0;
  8998. result0 = parse_c_p_q();
  8999. if (result0 === null) {
  9000. result0 = parse_c_p_expires();
  9001. if (result0 === null) {
  9002. result0 = parse_generic_param();
  9003. }
  9004. }
  9005. return result0;
  9006. }
  9007. function parse_c_p_q() {
  9008. var result0, result1, result2;
  9009. var pos0, pos1;
  9010. pos0 = pos;
  9011. pos1 = pos;
  9012. if (input.substr(pos, 1).toLowerCase() === "q") {
  9013. result0 = input.substr(pos, 1);
  9014. pos++;
  9015. } else {
  9016. result0 = null;
  9017. if (reportFailures === 0) {
  9018. matchFailed("\"q\"");
  9019. }
  9020. }
  9021. if (result0 !== null) {
  9022. result1 = parse_EQUAL();
  9023. if (result1 !== null) {
  9024. result2 = parse_qvalue();
  9025. if (result2 !== null) {
  9026. result0 = [result0, result1, result2];
  9027. } else {
  9028. result0 = null;
  9029. pos = pos1;
  9030. }
  9031. } else {
  9032. result0 = null;
  9033. pos = pos1;
  9034. }
  9035. } else {
  9036. result0 = null;
  9037. pos = pos1;
  9038. }
  9039. if (result0 !== null) {
  9040. result0 = function (offset, q) {
  9041. if (!data.params) data.params = {};
  9042. data.params['q'] = q;
  9043. }(pos0, result0[2]);
  9044. }
  9045. if (result0 === null) {
  9046. pos = pos0;
  9047. }
  9048. return result0;
  9049. }
  9050. function parse_c_p_expires() {
  9051. var result0, result1, result2;
  9052. var pos0, pos1;
  9053. pos0 = pos;
  9054. pos1 = pos;
  9055. if (input.substr(pos, 7).toLowerCase() === "expires") {
  9056. result0 = input.substr(pos, 7);
  9057. pos += 7;
  9058. } else {
  9059. result0 = null;
  9060. if (reportFailures === 0) {
  9061. matchFailed("\"expires\"");
  9062. }
  9063. }
  9064. if (result0 !== null) {
  9065. result1 = parse_EQUAL();
  9066. if (result1 !== null) {
  9067. result2 = parse_delta_seconds();
  9068. if (result2 !== null) {
  9069. result0 = [result0, result1, result2];
  9070. } else {
  9071. result0 = null;
  9072. pos = pos1;
  9073. }
  9074. } else {
  9075. result0 = null;
  9076. pos = pos1;
  9077. }
  9078. } else {
  9079. result0 = null;
  9080. pos = pos1;
  9081. }
  9082. if (result0 !== null) {
  9083. result0 = function (offset, expires) {
  9084. if (!data.params) data.params = {};
  9085. data.params['expires'] = expires;
  9086. }(pos0, result0[2]);
  9087. }
  9088. if (result0 === null) {
  9089. pos = pos0;
  9090. }
  9091. return result0;
  9092. }
  9093. function parse_delta_seconds() {
  9094. var result0, result1;
  9095. var pos0;
  9096. pos0 = pos;
  9097. result1 = parse_DIGIT();
  9098. if (result1 !== null) {
  9099. result0 = [];
  9100. while (result1 !== null) {
  9101. result0.push(result1);
  9102. result1 = parse_DIGIT();
  9103. }
  9104. } else {
  9105. result0 = null;
  9106. }
  9107. if (result0 !== null) {
  9108. result0 = function (offset, delta_seconds) {
  9109. return parseInt(delta_seconds.join(''));
  9110. }(pos0, result0);
  9111. }
  9112. if (result0 === null) {
  9113. pos = pos0;
  9114. }
  9115. return result0;
  9116. }
  9117. function parse_qvalue() {
  9118. var result0, result1, result2, result3, result4;
  9119. var pos0, pos1, pos2;
  9120. pos0 = pos;
  9121. pos1 = pos;
  9122. if (input.charCodeAt(pos) === 48) {
  9123. result0 = "0";
  9124. pos++;
  9125. } else {
  9126. result0 = null;
  9127. if (reportFailures === 0) {
  9128. matchFailed("\"0\"");
  9129. }
  9130. }
  9131. if (result0 !== null) {
  9132. pos2 = pos;
  9133. if (input.charCodeAt(pos) === 46) {
  9134. result1 = ".";
  9135. pos++;
  9136. } else {
  9137. result1 = null;
  9138. if (reportFailures === 0) {
  9139. matchFailed("\".\"");
  9140. }
  9141. }
  9142. if (result1 !== null) {
  9143. result2 = parse_DIGIT();
  9144. result2 = result2 !== null ? result2 : "";
  9145. if (result2 !== null) {
  9146. result3 = parse_DIGIT();
  9147. result3 = result3 !== null ? result3 : "";
  9148. if (result3 !== null) {
  9149. result4 = parse_DIGIT();
  9150. result4 = result4 !== null ? result4 : "";
  9151. if (result4 !== null) {
  9152. result1 = [result1, result2, result3, result4];
  9153. } else {
  9154. result1 = null;
  9155. pos = pos2;
  9156. }
  9157. } else {
  9158. result1 = null;
  9159. pos = pos2;
  9160. }
  9161. } else {
  9162. result1 = null;
  9163. pos = pos2;
  9164. }
  9165. } else {
  9166. result1 = null;
  9167. pos = pos2;
  9168. }
  9169. result1 = result1 !== null ? result1 : "";
  9170. if (result1 !== null) {
  9171. result0 = [result0, result1];
  9172. } else {
  9173. result0 = null;
  9174. pos = pos1;
  9175. }
  9176. } else {
  9177. result0 = null;
  9178. pos = pos1;
  9179. }
  9180. if (result0 !== null) {
  9181. result0 = function (offset) {
  9182. return parseFloat(input.substring(pos, offset));
  9183. }(pos0);
  9184. }
  9185. if (result0 === null) {
  9186. pos = pos0;
  9187. }
  9188. return result0;
  9189. }
  9190. function parse_generic_param() {
  9191. var result0, result1, result2;
  9192. var pos0, pos1, pos2;
  9193. pos0 = pos;
  9194. pos1 = pos;
  9195. result0 = parse_token();
  9196. if (result0 !== null) {
  9197. pos2 = pos;
  9198. result1 = parse_EQUAL();
  9199. if (result1 !== null) {
  9200. result2 = parse_gen_value();
  9201. if (result2 !== null) {
  9202. result1 = [result1, result2];
  9203. } else {
  9204. result1 = null;
  9205. pos = pos2;
  9206. }
  9207. } else {
  9208. result1 = null;
  9209. pos = pos2;
  9210. }
  9211. result1 = result1 !== null ? result1 : "";
  9212. if (result1 !== null) {
  9213. result0 = [result0, result1];
  9214. } else {
  9215. result0 = null;
  9216. pos = pos1;
  9217. }
  9218. } else {
  9219. result0 = null;
  9220. pos = pos1;
  9221. }
  9222. if (result0 !== null) {
  9223. result0 = function (offset, param, value) {
  9224. if (!data.params) data.params = {};
  9225. if (typeof value === 'undefined') {
  9226. value = undefined;
  9227. } else {
  9228. value = value[1];
  9229. }
  9230. data.params[param.toLowerCase()] = value;
  9231. }(pos0, result0[0], result0[1]);
  9232. }
  9233. if (result0 === null) {
  9234. pos = pos0;
  9235. }
  9236. return result0;
  9237. }
  9238. function parse_gen_value() {
  9239. var result0;
  9240. result0 = parse_token();
  9241. if (result0 === null) {
  9242. result0 = parse_host();
  9243. if (result0 === null) {
  9244. result0 = parse_quoted_string();
  9245. }
  9246. }
  9247. return result0;
  9248. }
  9249. function parse_Content_Disposition() {
  9250. var result0, result1, result2, result3;
  9251. var pos0, pos1;
  9252. pos0 = pos;
  9253. result0 = parse_disp_type();
  9254. if (result0 !== null) {
  9255. result1 = [];
  9256. pos1 = pos;
  9257. result2 = parse_SEMI();
  9258. if (result2 !== null) {
  9259. result3 = parse_disp_param();
  9260. if (result3 !== null) {
  9261. result2 = [result2, result3];
  9262. } else {
  9263. result2 = null;
  9264. pos = pos1;
  9265. }
  9266. } else {
  9267. result2 = null;
  9268. pos = pos1;
  9269. }
  9270. while (result2 !== null) {
  9271. result1.push(result2);
  9272. pos1 = pos;
  9273. result2 = parse_SEMI();
  9274. if (result2 !== null) {
  9275. result3 = parse_disp_param();
  9276. if (result3 !== null) {
  9277. result2 = [result2, result3];
  9278. } else {
  9279. result2 = null;
  9280. pos = pos1;
  9281. }
  9282. } else {
  9283. result2 = null;
  9284. pos = pos1;
  9285. }
  9286. }
  9287. if (result1 !== null) {
  9288. result0 = [result0, result1];
  9289. } else {
  9290. result0 = null;
  9291. pos = pos0;
  9292. }
  9293. } else {
  9294. result0 = null;
  9295. pos = pos0;
  9296. }
  9297. return result0;
  9298. }
  9299. function parse_disp_type() {
  9300. var result0;
  9301. if (input.substr(pos, 6).toLowerCase() === "render") {
  9302. result0 = input.substr(pos, 6);
  9303. pos += 6;
  9304. } else {
  9305. result0 = null;
  9306. if (reportFailures === 0) {
  9307. matchFailed("\"render\"");
  9308. }
  9309. }
  9310. if (result0 === null) {
  9311. if (input.substr(pos, 7).toLowerCase() === "session") {
  9312. result0 = input.substr(pos, 7);
  9313. pos += 7;
  9314. } else {
  9315. result0 = null;
  9316. if (reportFailures === 0) {
  9317. matchFailed("\"session\"");
  9318. }
  9319. }
  9320. if (result0 === null) {
  9321. if (input.substr(pos, 4).toLowerCase() === "icon") {
  9322. result0 = input.substr(pos, 4);
  9323. pos += 4;
  9324. } else {
  9325. result0 = null;
  9326. if (reportFailures === 0) {
  9327. matchFailed("\"icon\"");
  9328. }
  9329. }
  9330. if (result0 === null) {
  9331. if (input.substr(pos, 5).toLowerCase() === "alert") {
  9332. result0 = input.substr(pos, 5);
  9333. pos += 5;
  9334. } else {
  9335. result0 = null;
  9336. if (reportFailures === 0) {
  9337. matchFailed("\"alert\"");
  9338. }
  9339. }
  9340. if (result0 === null) {
  9341. result0 = parse_token();
  9342. }
  9343. }
  9344. }
  9345. }
  9346. return result0;
  9347. }
  9348. function parse_disp_param() {
  9349. var result0;
  9350. result0 = parse_handling_param();
  9351. if (result0 === null) {
  9352. result0 = parse_generic_param();
  9353. }
  9354. return result0;
  9355. }
  9356. function parse_handling_param() {
  9357. var result0, result1, result2;
  9358. var pos0;
  9359. pos0 = pos;
  9360. if (input.substr(pos, 8).toLowerCase() === "handling") {
  9361. result0 = input.substr(pos, 8);
  9362. pos += 8;
  9363. } else {
  9364. result0 = null;
  9365. if (reportFailures === 0) {
  9366. matchFailed("\"handling\"");
  9367. }
  9368. }
  9369. if (result0 !== null) {
  9370. result1 = parse_EQUAL();
  9371. if (result1 !== null) {
  9372. if (input.substr(pos, 8).toLowerCase() === "optional") {
  9373. result2 = input.substr(pos, 8);
  9374. pos += 8;
  9375. } else {
  9376. result2 = null;
  9377. if (reportFailures === 0) {
  9378. matchFailed("\"optional\"");
  9379. }
  9380. }
  9381. if (result2 === null) {
  9382. if (input.substr(pos, 8).toLowerCase() === "required") {
  9383. result2 = input.substr(pos, 8);
  9384. pos += 8;
  9385. } else {
  9386. result2 = null;
  9387. if (reportFailures === 0) {
  9388. matchFailed("\"required\"");
  9389. }
  9390. }
  9391. if (result2 === null) {
  9392. result2 = parse_token();
  9393. }
  9394. }
  9395. if (result2 !== null) {
  9396. result0 = [result0, result1, result2];
  9397. } else {
  9398. result0 = null;
  9399. pos = pos0;
  9400. }
  9401. } else {
  9402. result0 = null;
  9403. pos = pos0;
  9404. }
  9405. } else {
  9406. result0 = null;
  9407. pos = pos0;
  9408. }
  9409. return result0;
  9410. }
  9411. function parse_Content_Encoding() {
  9412. var result0, result1, result2, result3;
  9413. var pos0, pos1;
  9414. pos0 = pos;
  9415. result0 = parse_token();
  9416. if (result0 !== null) {
  9417. result1 = [];
  9418. pos1 = pos;
  9419. result2 = parse_COMMA();
  9420. if (result2 !== null) {
  9421. result3 = parse_token();
  9422. if (result3 !== null) {
  9423. result2 = [result2, result3];
  9424. } else {
  9425. result2 = null;
  9426. pos = pos1;
  9427. }
  9428. } else {
  9429. result2 = null;
  9430. pos = pos1;
  9431. }
  9432. while (result2 !== null) {
  9433. result1.push(result2);
  9434. pos1 = pos;
  9435. result2 = parse_COMMA();
  9436. if (result2 !== null) {
  9437. result3 = parse_token();
  9438. if (result3 !== null) {
  9439. result2 = [result2, result3];
  9440. } else {
  9441. result2 = null;
  9442. pos = pos1;
  9443. }
  9444. } else {
  9445. result2 = null;
  9446. pos = pos1;
  9447. }
  9448. }
  9449. if (result1 !== null) {
  9450. result0 = [result0, result1];
  9451. } else {
  9452. result0 = null;
  9453. pos = pos0;
  9454. }
  9455. } else {
  9456. result0 = null;
  9457. pos = pos0;
  9458. }
  9459. return result0;
  9460. }
  9461. function parse_Content_Length() {
  9462. var result0, result1;
  9463. var pos0;
  9464. pos0 = pos;
  9465. result1 = parse_DIGIT();
  9466. if (result1 !== null) {
  9467. result0 = [];
  9468. while (result1 !== null) {
  9469. result0.push(result1);
  9470. result1 = parse_DIGIT();
  9471. }
  9472. } else {
  9473. result0 = null;
  9474. }
  9475. if (result0 !== null) {
  9476. result0 = function (offset, length) {
  9477. data = parseInt(length.join(''));
  9478. }(pos0, result0);
  9479. }
  9480. if (result0 === null) {
  9481. pos = pos0;
  9482. }
  9483. return result0;
  9484. }
  9485. function parse_Content_Type() {
  9486. var result0;
  9487. var pos0;
  9488. pos0 = pos;
  9489. result0 = parse_media_type();
  9490. if (result0 !== null) {
  9491. result0 = function (offset) {
  9492. data = input.substring(pos, offset);
  9493. }(pos0);
  9494. }
  9495. if (result0 === null) {
  9496. pos = pos0;
  9497. }
  9498. return result0;
  9499. }
  9500. function parse_media_type() {
  9501. var result0, result1, result2, result3, result4, result5;
  9502. var pos0, pos1;
  9503. pos0 = pos;
  9504. result0 = parse_m_type();
  9505. if (result0 !== null) {
  9506. result1 = parse_SLASH();
  9507. if (result1 !== null) {
  9508. result2 = parse_m_subtype();
  9509. if (result2 !== null) {
  9510. result3 = [];
  9511. pos1 = pos;
  9512. result4 = parse_SEMI();
  9513. if (result4 !== null) {
  9514. result5 = parse_m_parameter();
  9515. if (result5 !== null) {
  9516. result4 = [result4, result5];
  9517. } else {
  9518. result4 = null;
  9519. pos = pos1;
  9520. }
  9521. } else {
  9522. result4 = null;
  9523. pos = pos1;
  9524. }
  9525. while (result4 !== null) {
  9526. result3.push(result4);
  9527. pos1 = pos;
  9528. result4 = parse_SEMI();
  9529. if (result4 !== null) {
  9530. result5 = parse_m_parameter();
  9531. if (result5 !== null) {
  9532. result4 = [result4, result5];
  9533. } else {
  9534. result4 = null;
  9535. pos = pos1;
  9536. }
  9537. } else {
  9538. result4 = null;
  9539. pos = pos1;
  9540. }
  9541. }
  9542. if (result3 !== null) {
  9543. result0 = [result0, result1, result2, result3];
  9544. } else {
  9545. result0 = null;
  9546. pos = pos0;
  9547. }
  9548. } else {
  9549. result0 = null;
  9550. pos = pos0;
  9551. }
  9552. } else {
  9553. result0 = null;
  9554. pos = pos0;
  9555. }
  9556. } else {
  9557. result0 = null;
  9558. pos = pos0;
  9559. }
  9560. return result0;
  9561. }
  9562. function parse_m_type() {
  9563. var result0;
  9564. result0 = parse_discrete_type();
  9565. if (result0 === null) {
  9566. result0 = parse_composite_type();
  9567. }
  9568. return result0;
  9569. }
  9570. function parse_discrete_type() {
  9571. var result0;
  9572. if (input.substr(pos, 4).toLowerCase() === "text") {
  9573. result0 = input.substr(pos, 4);
  9574. pos += 4;
  9575. } else {
  9576. result0 = null;
  9577. if (reportFailures === 0) {
  9578. matchFailed("\"text\"");
  9579. }
  9580. }
  9581. if (result0 === null) {
  9582. if (input.substr(pos, 5).toLowerCase() === "image") {
  9583. result0 = input.substr(pos, 5);
  9584. pos += 5;
  9585. } else {
  9586. result0 = null;
  9587. if (reportFailures === 0) {
  9588. matchFailed("\"image\"");
  9589. }
  9590. }
  9591. if (result0 === null) {
  9592. if (input.substr(pos, 5).toLowerCase() === "audio") {
  9593. result0 = input.substr(pos, 5);
  9594. pos += 5;
  9595. } else {
  9596. result0 = null;
  9597. if (reportFailures === 0) {
  9598. matchFailed("\"audio\"");
  9599. }
  9600. }
  9601. if (result0 === null) {
  9602. if (input.substr(pos, 5).toLowerCase() === "video") {
  9603. result0 = input.substr(pos, 5);
  9604. pos += 5;
  9605. } else {
  9606. result0 = null;
  9607. if (reportFailures === 0) {
  9608. matchFailed("\"video\"");
  9609. }
  9610. }
  9611. if (result0 === null) {
  9612. if (input.substr(pos, 11).toLowerCase() === "application") {
  9613. result0 = input.substr(pos, 11);
  9614. pos += 11;
  9615. } else {
  9616. result0 = null;
  9617. if (reportFailures === 0) {
  9618. matchFailed("\"application\"");
  9619. }
  9620. }
  9621. if (result0 === null) {
  9622. result0 = parse_extension_token();
  9623. }
  9624. }
  9625. }
  9626. }
  9627. }
  9628. return result0;
  9629. }
  9630. function parse_composite_type() {
  9631. var result0;
  9632. if (input.substr(pos, 7).toLowerCase() === "message") {
  9633. result0 = input.substr(pos, 7);
  9634. pos += 7;
  9635. } else {
  9636. result0 = null;
  9637. if (reportFailures === 0) {
  9638. matchFailed("\"message\"");
  9639. }
  9640. }
  9641. if (result0 === null) {
  9642. if (input.substr(pos, 9).toLowerCase() === "multipart") {
  9643. result0 = input.substr(pos, 9);
  9644. pos += 9;
  9645. } else {
  9646. result0 = null;
  9647. if (reportFailures === 0) {
  9648. matchFailed("\"multipart\"");
  9649. }
  9650. }
  9651. if (result0 === null) {
  9652. result0 = parse_extension_token();
  9653. }
  9654. }
  9655. return result0;
  9656. }
  9657. function parse_extension_token() {
  9658. var result0;
  9659. result0 = parse_token();
  9660. if (result0 === null) {
  9661. result0 = parse_x_token();
  9662. }
  9663. return result0;
  9664. }
  9665. function parse_x_token() {
  9666. var result0, result1;
  9667. var pos0;
  9668. pos0 = pos;
  9669. if (input.substr(pos, 2).toLowerCase() === "x-") {
  9670. result0 = input.substr(pos, 2);
  9671. pos += 2;
  9672. } else {
  9673. result0 = null;
  9674. if (reportFailures === 0) {
  9675. matchFailed("\"x-\"");
  9676. }
  9677. }
  9678. if (result0 !== null) {
  9679. result1 = parse_token();
  9680. if (result1 !== null) {
  9681. result0 = [result0, result1];
  9682. } else {
  9683. result0 = null;
  9684. pos = pos0;
  9685. }
  9686. } else {
  9687. result0 = null;
  9688. pos = pos0;
  9689. }
  9690. return result0;
  9691. }
  9692. function parse_m_subtype() {
  9693. var result0;
  9694. result0 = parse_extension_token();
  9695. if (result0 === null) {
  9696. result0 = parse_token();
  9697. }
  9698. return result0;
  9699. }
  9700. function parse_m_parameter() {
  9701. var result0, result1, result2;
  9702. var pos0;
  9703. pos0 = pos;
  9704. result0 = parse_token();
  9705. if (result0 !== null) {
  9706. result1 = parse_EQUAL();
  9707. if (result1 !== null) {
  9708. result2 = parse_m_value();
  9709. if (result2 !== null) {
  9710. result0 = [result0, result1, result2];
  9711. } else {
  9712. result0 = null;
  9713. pos = pos0;
  9714. }
  9715. } else {
  9716. result0 = null;
  9717. pos = pos0;
  9718. }
  9719. } else {
  9720. result0 = null;
  9721. pos = pos0;
  9722. }
  9723. return result0;
  9724. }
  9725. function parse_m_value() {
  9726. var result0;
  9727. result0 = parse_token();
  9728. if (result0 === null) {
  9729. result0 = parse_quoted_string();
  9730. }
  9731. return result0;
  9732. }
  9733. function parse_CSeq() {
  9734. var result0, result1, result2;
  9735. var pos0;
  9736. pos0 = pos;
  9737. result0 = parse_CSeq_value();
  9738. if (result0 !== null) {
  9739. result1 = parse_LWS();
  9740. if (result1 !== null) {
  9741. result2 = parse_Method();
  9742. if (result2 !== null) {
  9743. result0 = [result0, result1, result2];
  9744. } else {
  9745. result0 = null;
  9746. pos = pos0;
  9747. }
  9748. } else {
  9749. result0 = null;
  9750. pos = pos0;
  9751. }
  9752. } else {
  9753. result0 = null;
  9754. pos = pos0;
  9755. }
  9756. return result0;
  9757. }
  9758. function parse_CSeq_value() {
  9759. var result0, result1;
  9760. var pos0;
  9761. pos0 = pos;
  9762. result1 = parse_DIGIT();
  9763. if (result1 !== null) {
  9764. result0 = [];
  9765. while (result1 !== null) {
  9766. result0.push(result1);
  9767. result1 = parse_DIGIT();
  9768. }
  9769. } else {
  9770. result0 = null;
  9771. }
  9772. if (result0 !== null) {
  9773. result0 = function (offset, cseq_value) {
  9774. data.value = parseInt(cseq_value.join(''));
  9775. }(pos0, result0);
  9776. }
  9777. if (result0 === null) {
  9778. pos = pos0;
  9779. }
  9780. return result0;
  9781. }
  9782. function parse_Expires() {
  9783. var result0;
  9784. var pos0;
  9785. pos0 = pos;
  9786. result0 = parse_delta_seconds();
  9787. if (result0 !== null) {
  9788. result0 = function (offset, expires) {
  9789. data = expires;
  9790. }(pos0, result0);
  9791. }
  9792. if (result0 === null) {
  9793. pos = pos0;
  9794. }
  9795. return result0;
  9796. }
  9797. function parse_Event() {
  9798. var result0, result1, result2, result3;
  9799. var pos0, pos1, pos2;
  9800. pos0 = pos;
  9801. pos1 = pos;
  9802. result0 = parse_event_type();
  9803. if (result0 !== null) {
  9804. result1 = [];
  9805. pos2 = pos;
  9806. result2 = parse_SEMI();
  9807. if (result2 !== null) {
  9808. result3 = parse_generic_param();
  9809. if (result3 !== null) {
  9810. result2 = [result2, result3];
  9811. } else {
  9812. result2 = null;
  9813. pos = pos2;
  9814. }
  9815. } else {
  9816. result2 = null;
  9817. pos = pos2;
  9818. }
  9819. while (result2 !== null) {
  9820. result1.push(result2);
  9821. pos2 = pos;
  9822. result2 = parse_SEMI();
  9823. if (result2 !== null) {
  9824. result3 = parse_generic_param();
  9825. if (result3 !== null) {
  9826. result2 = [result2, result3];
  9827. } else {
  9828. result2 = null;
  9829. pos = pos2;
  9830. }
  9831. } else {
  9832. result2 = null;
  9833. pos = pos2;
  9834. }
  9835. }
  9836. if (result1 !== null) {
  9837. result0 = [result0, result1];
  9838. } else {
  9839. result0 = null;
  9840. pos = pos1;
  9841. }
  9842. } else {
  9843. result0 = null;
  9844. pos = pos1;
  9845. }
  9846. if (result0 !== null) {
  9847. result0 = function (offset, event_type) {
  9848. data.event = event_type.join('').toLowerCase();
  9849. }(pos0, result0[0]);
  9850. }
  9851. if (result0 === null) {
  9852. pos = pos0;
  9853. }
  9854. return result0;
  9855. }
  9856. function parse_event_type() {
  9857. var result0, result1, result2, result3;
  9858. var pos0, pos1;
  9859. pos0 = pos;
  9860. result0 = parse_token_nodot();
  9861. if (result0 !== null) {
  9862. result1 = [];
  9863. pos1 = pos;
  9864. if (input.charCodeAt(pos) === 46) {
  9865. result2 = ".";
  9866. pos++;
  9867. } else {
  9868. result2 = null;
  9869. if (reportFailures === 0) {
  9870. matchFailed("\".\"");
  9871. }
  9872. }
  9873. if (result2 !== null) {
  9874. result3 = parse_token_nodot();
  9875. if (result3 !== null) {
  9876. result2 = [result2, result3];
  9877. } else {
  9878. result2 = null;
  9879. pos = pos1;
  9880. }
  9881. } else {
  9882. result2 = null;
  9883. pos = pos1;
  9884. }
  9885. while (result2 !== null) {
  9886. result1.push(result2);
  9887. pos1 = pos;
  9888. if (input.charCodeAt(pos) === 46) {
  9889. result2 = ".";
  9890. pos++;
  9891. } else {
  9892. result2 = null;
  9893. if (reportFailures === 0) {
  9894. matchFailed("\".\"");
  9895. }
  9896. }
  9897. if (result2 !== null) {
  9898. result3 = parse_token_nodot();
  9899. if (result3 !== null) {
  9900. result2 = [result2, result3];
  9901. } else {
  9902. result2 = null;
  9903. pos = pos1;
  9904. }
  9905. } else {
  9906. result2 = null;
  9907. pos = pos1;
  9908. }
  9909. }
  9910. if (result1 !== null) {
  9911. result0 = [result0, result1];
  9912. } else {
  9913. result0 = null;
  9914. pos = pos0;
  9915. }
  9916. } else {
  9917. result0 = null;
  9918. pos = pos0;
  9919. }
  9920. return result0;
  9921. }
  9922. function parse_From() {
  9923. var result0, result1, result2, result3;
  9924. var pos0, pos1, pos2;
  9925. pos0 = pos;
  9926. pos1 = pos;
  9927. result0 = parse_SIP_URI_noparams();
  9928. if (result0 === null) {
  9929. result0 = parse_name_addr();
  9930. }
  9931. if (result0 !== null) {
  9932. result1 = [];
  9933. pos2 = pos;
  9934. result2 = parse_SEMI();
  9935. if (result2 !== null) {
  9936. result3 = parse_from_param();
  9937. if (result3 !== null) {
  9938. result2 = [result2, result3];
  9939. } else {
  9940. result2 = null;
  9941. pos = pos2;
  9942. }
  9943. } else {
  9944. result2 = null;
  9945. pos = pos2;
  9946. }
  9947. while (result2 !== null) {
  9948. result1.push(result2);
  9949. pos2 = pos;
  9950. result2 = parse_SEMI();
  9951. if (result2 !== null) {
  9952. result3 = parse_from_param();
  9953. if (result3 !== null) {
  9954. result2 = [result2, result3];
  9955. } else {
  9956. result2 = null;
  9957. pos = pos2;
  9958. }
  9959. } else {
  9960. result2 = null;
  9961. pos = pos2;
  9962. }
  9963. }
  9964. if (result1 !== null) {
  9965. result0 = [result0, result1];
  9966. } else {
  9967. result0 = null;
  9968. pos = pos1;
  9969. }
  9970. } else {
  9971. result0 = null;
  9972. pos = pos1;
  9973. }
  9974. if (result0 !== null) {
  9975. result0 = function (offset) {
  9976. var tag = data.tag;
  9977. try {
  9978. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  9979. if (tag) {
  9980. data.setParam('tag', tag);
  9981. }
  9982. } catch (e) {
  9983. data = -1;
  9984. }
  9985. }(pos0);
  9986. }
  9987. if (result0 === null) {
  9988. pos = pos0;
  9989. }
  9990. return result0;
  9991. }
  9992. function parse_from_param() {
  9993. var result0;
  9994. result0 = parse_tag_param();
  9995. if (result0 === null) {
  9996. result0 = parse_generic_param();
  9997. }
  9998. return result0;
  9999. }
  10000. function parse_tag_param() {
  10001. var result0, result1, result2;
  10002. var pos0, pos1;
  10003. pos0 = pos;
  10004. pos1 = pos;
  10005. if (input.substr(pos, 3).toLowerCase() === "tag") {
  10006. result0 = input.substr(pos, 3);
  10007. pos += 3;
  10008. } else {
  10009. result0 = null;
  10010. if (reportFailures === 0) {
  10011. matchFailed("\"tag\"");
  10012. }
  10013. }
  10014. if (result0 !== null) {
  10015. result1 = parse_EQUAL();
  10016. if (result1 !== null) {
  10017. result2 = parse_token();
  10018. if (result2 !== null) {
  10019. result0 = [result0, result1, result2];
  10020. } else {
  10021. result0 = null;
  10022. pos = pos1;
  10023. }
  10024. } else {
  10025. result0 = null;
  10026. pos = pos1;
  10027. }
  10028. } else {
  10029. result0 = null;
  10030. pos = pos1;
  10031. }
  10032. if (result0 !== null) {
  10033. result0 = function (offset, tag) {
  10034. data.tag = tag;
  10035. }(pos0, result0[2]);
  10036. }
  10037. if (result0 === null) {
  10038. pos = pos0;
  10039. }
  10040. return result0;
  10041. }
  10042. function parse_Max_Forwards() {
  10043. var result0, result1;
  10044. var pos0;
  10045. pos0 = pos;
  10046. result1 = parse_DIGIT();
  10047. if (result1 !== null) {
  10048. result0 = [];
  10049. while (result1 !== null) {
  10050. result0.push(result1);
  10051. result1 = parse_DIGIT();
  10052. }
  10053. } else {
  10054. result0 = null;
  10055. }
  10056. if (result0 !== null) {
  10057. result0 = function (offset, forwards) {
  10058. data = parseInt(forwards.join(''));
  10059. }(pos0, result0);
  10060. }
  10061. if (result0 === null) {
  10062. pos = pos0;
  10063. }
  10064. return result0;
  10065. }
  10066. function parse_Min_Expires() {
  10067. var result0;
  10068. var pos0;
  10069. pos0 = pos;
  10070. result0 = parse_delta_seconds();
  10071. if (result0 !== null) {
  10072. result0 = function (offset, min_expires) {
  10073. data = min_expires;
  10074. }(pos0, result0);
  10075. }
  10076. if (result0 === null) {
  10077. pos = pos0;
  10078. }
  10079. return result0;
  10080. }
  10081. function parse_Name_Addr_Header() {
  10082. var result0, result1, result2, result3, result4, result5, result6;
  10083. var pos0, pos1, pos2;
  10084. pos0 = pos;
  10085. pos1 = pos;
  10086. result0 = [];
  10087. result1 = parse_display_name();
  10088. while (result1 !== null) {
  10089. result0.push(result1);
  10090. result1 = parse_display_name();
  10091. }
  10092. if (result0 !== null) {
  10093. result1 = parse_LAQUOT();
  10094. if (result1 !== null) {
  10095. result2 = parse_SIP_URI();
  10096. if (result2 !== null) {
  10097. result3 = parse_RAQUOT();
  10098. if (result3 !== null) {
  10099. result4 = [];
  10100. pos2 = pos;
  10101. result5 = parse_SEMI();
  10102. if (result5 !== null) {
  10103. result6 = parse_generic_param();
  10104. if (result6 !== null) {
  10105. result5 = [result5, result6];
  10106. } else {
  10107. result5 = null;
  10108. pos = pos2;
  10109. }
  10110. } else {
  10111. result5 = null;
  10112. pos = pos2;
  10113. }
  10114. while (result5 !== null) {
  10115. result4.push(result5);
  10116. pos2 = pos;
  10117. result5 = parse_SEMI();
  10118. if (result5 !== null) {
  10119. result6 = parse_generic_param();
  10120. if (result6 !== null) {
  10121. result5 = [result5, result6];
  10122. } else {
  10123. result5 = null;
  10124. pos = pos2;
  10125. }
  10126. } else {
  10127. result5 = null;
  10128. pos = pos2;
  10129. }
  10130. }
  10131. if (result4 !== null) {
  10132. result0 = [result0, result1, result2, result3, result4];
  10133. } else {
  10134. result0 = null;
  10135. pos = pos1;
  10136. }
  10137. } else {
  10138. result0 = null;
  10139. pos = pos1;
  10140. }
  10141. } else {
  10142. result0 = null;
  10143. pos = pos1;
  10144. }
  10145. } else {
  10146. result0 = null;
  10147. pos = pos1;
  10148. }
  10149. } else {
  10150. result0 = null;
  10151. pos = pos1;
  10152. }
  10153. if (result0 !== null) {
  10154. result0 = function (offset) {
  10155. try {
  10156. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  10157. } catch (e) {
  10158. data = -1;
  10159. }
  10160. }(pos0);
  10161. }
  10162. if (result0 === null) {
  10163. pos = pos0;
  10164. }
  10165. return result0;
  10166. }
  10167. function parse_Proxy_Authenticate() {
  10168. var result0;
  10169. result0 = parse_challenge();
  10170. return result0;
  10171. }
  10172. function parse_challenge() {
  10173. var result0, result1, result2, result3, result4, result5;
  10174. var pos0, pos1;
  10175. pos0 = pos;
  10176. if (input.substr(pos, 6).toLowerCase() === "digest") {
  10177. result0 = input.substr(pos, 6);
  10178. pos += 6;
  10179. } else {
  10180. result0 = null;
  10181. if (reportFailures === 0) {
  10182. matchFailed("\"Digest\"");
  10183. }
  10184. }
  10185. if (result0 !== null) {
  10186. result1 = parse_LWS();
  10187. if (result1 !== null) {
  10188. result2 = parse_digest_cln();
  10189. if (result2 !== null) {
  10190. result3 = [];
  10191. pos1 = pos;
  10192. result4 = parse_COMMA();
  10193. if (result4 !== null) {
  10194. result5 = parse_digest_cln();
  10195. if (result5 !== null) {
  10196. result4 = [result4, result5];
  10197. } else {
  10198. result4 = null;
  10199. pos = pos1;
  10200. }
  10201. } else {
  10202. result4 = null;
  10203. pos = pos1;
  10204. }
  10205. while (result4 !== null) {
  10206. result3.push(result4);
  10207. pos1 = pos;
  10208. result4 = parse_COMMA();
  10209. if (result4 !== null) {
  10210. result5 = parse_digest_cln();
  10211. if (result5 !== null) {
  10212. result4 = [result4, result5];
  10213. } else {
  10214. result4 = null;
  10215. pos = pos1;
  10216. }
  10217. } else {
  10218. result4 = null;
  10219. pos = pos1;
  10220. }
  10221. }
  10222. if (result3 !== null) {
  10223. result0 = [result0, result1, result2, result3];
  10224. } else {
  10225. result0 = null;
  10226. pos = pos0;
  10227. }
  10228. } else {
  10229. result0 = null;
  10230. pos = pos0;
  10231. }
  10232. } else {
  10233. result0 = null;
  10234. pos = pos0;
  10235. }
  10236. } else {
  10237. result0 = null;
  10238. pos = pos0;
  10239. }
  10240. if (result0 === null) {
  10241. result0 = parse_other_challenge();
  10242. }
  10243. return result0;
  10244. }
  10245. function parse_other_challenge() {
  10246. var result0, result1, result2, result3, result4, result5;
  10247. var pos0, pos1;
  10248. pos0 = pos;
  10249. result0 = parse_token();
  10250. if (result0 !== null) {
  10251. result1 = parse_LWS();
  10252. if (result1 !== null) {
  10253. result2 = parse_auth_param();
  10254. if (result2 !== null) {
  10255. result3 = [];
  10256. pos1 = pos;
  10257. result4 = parse_COMMA();
  10258. if (result4 !== null) {
  10259. result5 = parse_auth_param();
  10260. if (result5 !== null) {
  10261. result4 = [result4, result5];
  10262. } else {
  10263. result4 = null;
  10264. pos = pos1;
  10265. }
  10266. } else {
  10267. result4 = null;
  10268. pos = pos1;
  10269. }
  10270. while (result4 !== null) {
  10271. result3.push(result4);
  10272. pos1 = pos;
  10273. result4 = parse_COMMA();
  10274. if (result4 !== null) {
  10275. result5 = parse_auth_param();
  10276. if (result5 !== null) {
  10277. result4 = [result4, result5];
  10278. } else {
  10279. result4 = null;
  10280. pos = pos1;
  10281. }
  10282. } else {
  10283. result4 = null;
  10284. pos = pos1;
  10285. }
  10286. }
  10287. if (result3 !== null) {
  10288. result0 = [result0, result1, result2, result3];
  10289. } else {
  10290. result0 = null;
  10291. pos = pos0;
  10292. }
  10293. } else {
  10294. result0 = null;
  10295. pos = pos0;
  10296. }
  10297. } else {
  10298. result0 = null;
  10299. pos = pos0;
  10300. }
  10301. } else {
  10302. result0 = null;
  10303. pos = pos0;
  10304. }
  10305. return result0;
  10306. }
  10307. function parse_auth_param() {
  10308. var result0, result1, result2;
  10309. var pos0;
  10310. pos0 = pos;
  10311. result0 = parse_token();
  10312. if (result0 !== null) {
  10313. result1 = parse_EQUAL();
  10314. if (result1 !== null) {
  10315. result2 = parse_token();
  10316. if (result2 === null) {
  10317. result2 = parse_quoted_string();
  10318. }
  10319. if (result2 !== null) {
  10320. result0 = [result0, result1, result2];
  10321. } else {
  10322. result0 = null;
  10323. pos = pos0;
  10324. }
  10325. } else {
  10326. result0 = null;
  10327. pos = pos0;
  10328. }
  10329. } else {
  10330. result0 = null;
  10331. pos = pos0;
  10332. }
  10333. return result0;
  10334. }
  10335. function parse_digest_cln() {
  10336. var result0;
  10337. result0 = parse_realm();
  10338. if (result0 === null) {
  10339. result0 = parse_domain();
  10340. if (result0 === null) {
  10341. result0 = parse_nonce();
  10342. if (result0 === null) {
  10343. result0 = parse_opaque();
  10344. if (result0 === null) {
  10345. result0 = parse_stale();
  10346. if (result0 === null) {
  10347. result0 = parse_algorithm();
  10348. if (result0 === null) {
  10349. result0 = parse_qop_options();
  10350. if (result0 === null) {
  10351. result0 = parse_auth_param();
  10352. }
  10353. }
  10354. }
  10355. }
  10356. }
  10357. }
  10358. }
  10359. return result0;
  10360. }
  10361. function parse_realm() {
  10362. var result0, result1, result2;
  10363. var pos0;
  10364. pos0 = pos;
  10365. if (input.substr(pos, 5).toLowerCase() === "realm") {
  10366. result0 = input.substr(pos, 5);
  10367. pos += 5;
  10368. } else {
  10369. result0 = null;
  10370. if (reportFailures === 0) {
  10371. matchFailed("\"realm\"");
  10372. }
  10373. }
  10374. if (result0 !== null) {
  10375. result1 = parse_EQUAL();
  10376. if (result1 !== null) {
  10377. result2 = parse_realm_value();
  10378. if (result2 !== null) {
  10379. result0 = [result0, result1, result2];
  10380. } else {
  10381. result0 = null;
  10382. pos = pos0;
  10383. }
  10384. } else {
  10385. result0 = null;
  10386. pos = pos0;
  10387. }
  10388. } else {
  10389. result0 = null;
  10390. pos = pos0;
  10391. }
  10392. return result0;
  10393. }
  10394. function parse_realm_value() {
  10395. var result0;
  10396. var pos0;
  10397. pos0 = pos;
  10398. result0 = parse_quoted_string_clean();
  10399. if (result0 !== null) {
  10400. result0 = function (offset, realm) {
  10401. data.realm = realm;
  10402. }(pos0, result0);
  10403. }
  10404. if (result0 === null) {
  10405. pos = pos0;
  10406. }
  10407. return result0;
  10408. }
  10409. function parse_domain() {
  10410. var result0, result1, result2, result3, result4, result5, result6;
  10411. var pos0, pos1;
  10412. pos0 = pos;
  10413. if (input.substr(pos, 6).toLowerCase() === "domain") {
  10414. result0 = input.substr(pos, 6);
  10415. pos += 6;
  10416. } else {
  10417. result0 = null;
  10418. if (reportFailures === 0) {
  10419. matchFailed("\"domain\"");
  10420. }
  10421. }
  10422. if (result0 !== null) {
  10423. result1 = parse_EQUAL();
  10424. if (result1 !== null) {
  10425. result2 = parse_LDQUOT();
  10426. if (result2 !== null) {
  10427. result3 = parse_URI();
  10428. if (result3 !== null) {
  10429. result4 = [];
  10430. pos1 = pos;
  10431. result6 = parse_SP();
  10432. if (result6 !== null) {
  10433. result5 = [];
  10434. while (result6 !== null) {
  10435. result5.push(result6);
  10436. result6 = parse_SP();
  10437. }
  10438. } else {
  10439. result5 = null;
  10440. }
  10441. if (result5 !== null) {
  10442. result6 = parse_URI();
  10443. if (result6 !== null) {
  10444. result5 = [result5, result6];
  10445. } else {
  10446. result5 = null;
  10447. pos = pos1;
  10448. }
  10449. } else {
  10450. result5 = null;
  10451. pos = pos1;
  10452. }
  10453. while (result5 !== null) {
  10454. result4.push(result5);
  10455. pos1 = pos;
  10456. result6 = parse_SP();
  10457. if (result6 !== null) {
  10458. result5 = [];
  10459. while (result6 !== null) {
  10460. result5.push(result6);
  10461. result6 = parse_SP();
  10462. }
  10463. } else {
  10464. result5 = null;
  10465. }
  10466. if (result5 !== null) {
  10467. result6 = parse_URI();
  10468. if (result6 !== null) {
  10469. result5 = [result5, result6];
  10470. } else {
  10471. result5 = null;
  10472. pos = pos1;
  10473. }
  10474. } else {
  10475. result5 = null;
  10476. pos = pos1;
  10477. }
  10478. }
  10479. if (result4 !== null) {
  10480. result5 = parse_RDQUOT();
  10481. if (result5 !== null) {
  10482. result0 = [result0, result1, result2, result3, result4, result5];
  10483. } else {
  10484. result0 = null;
  10485. pos = pos0;
  10486. }
  10487. } else {
  10488. result0 = null;
  10489. pos = pos0;
  10490. }
  10491. } else {
  10492. result0 = null;
  10493. pos = pos0;
  10494. }
  10495. } else {
  10496. result0 = null;
  10497. pos = pos0;
  10498. }
  10499. } else {
  10500. result0 = null;
  10501. pos = pos0;
  10502. }
  10503. } else {
  10504. result0 = null;
  10505. pos = pos0;
  10506. }
  10507. return result0;
  10508. }
  10509. function parse_URI() {
  10510. var result0;
  10511. result0 = parse_absoluteURI();
  10512. if (result0 === null) {
  10513. result0 = parse_abs_path();
  10514. }
  10515. return result0;
  10516. }
  10517. function parse_nonce() {
  10518. var result0, result1, result2;
  10519. var pos0;
  10520. pos0 = pos;
  10521. if (input.substr(pos, 5).toLowerCase() === "nonce") {
  10522. result0 = input.substr(pos, 5);
  10523. pos += 5;
  10524. } else {
  10525. result0 = null;
  10526. if (reportFailures === 0) {
  10527. matchFailed("\"nonce\"");
  10528. }
  10529. }
  10530. if (result0 !== null) {
  10531. result1 = parse_EQUAL();
  10532. if (result1 !== null) {
  10533. result2 = parse_nonce_value();
  10534. if (result2 !== null) {
  10535. result0 = [result0, result1, result2];
  10536. } else {
  10537. result0 = null;
  10538. pos = pos0;
  10539. }
  10540. } else {
  10541. result0 = null;
  10542. pos = pos0;
  10543. }
  10544. } else {
  10545. result0 = null;
  10546. pos = pos0;
  10547. }
  10548. return result0;
  10549. }
  10550. function parse_nonce_value() {
  10551. var result0;
  10552. var pos0;
  10553. pos0 = pos;
  10554. result0 = parse_quoted_string_clean();
  10555. if (result0 !== null) {
  10556. result0 = function (offset, nonce) {
  10557. data.nonce = nonce;
  10558. }(pos0, result0);
  10559. }
  10560. if (result0 === null) {
  10561. pos = pos0;
  10562. }
  10563. return result0;
  10564. }
  10565. function parse_opaque() {
  10566. var result0, result1, result2;
  10567. var pos0, pos1;
  10568. pos0 = pos;
  10569. pos1 = pos;
  10570. if (input.substr(pos, 6).toLowerCase() === "opaque") {
  10571. result0 = input.substr(pos, 6);
  10572. pos += 6;
  10573. } else {
  10574. result0 = null;
  10575. if (reportFailures === 0) {
  10576. matchFailed("\"opaque\"");
  10577. }
  10578. }
  10579. if (result0 !== null) {
  10580. result1 = parse_EQUAL();
  10581. if (result1 !== null) {
  10582. result2 = parse_quoted_string_clean();
  10583. if (result2 !== null) {
  10584. result0 = [result0, result1, result2];
  10585. } else {
  10586. result0 = null;
  10587. pos = pos1;
  10588. }
  10589. } else {
  10590. result0 = null;
  10591. pos = pos1;
  10592. }
  10593. } else {
  10594. result0 = null;
  10595. pos = pos1;
  10596. }
  10597. if (result0 !== null) {
  10598. result0 = function (offset, opaque) {
  10599. data.opaque = opaque;
  10600. }(pos0, result0[2]);
  10601. }
  10602. if (result0 === null) {
  10603. pos = pos0;
  10604. }
  10605. return result0;
  10606. }
  10607. function parse_stale() {
  10608. var result0, result1, result2;
  10609. var pos0, pos1;
  10610. pos0 = pos;
  10611. if (input.substr(pos, 5).toLowerCase() === "stale") {
  10612. result0 = input.substr(pos, 5);
  10613. pos += 5;
  10614. } else {
  10615. result0 = null;
  10616. if (reportFailures === 0) {
  10617. matchFailed("\"stale\"");
  10618. }
  10619. }
  10620. if (result0 !== null) {
  10621. result1 = parse_EQUAL();
  10622. if (result1 !== null) {
  10623. pos1 = pos;
  10624. if (input.substr(pos, 4).toLowerCase() === "true") {
  10625. result2 = input.substr(pos, 4);
  10626. pos += 4;
  10627. } else {
  10628. result2 = null;
  10629. if (reportFailures === 0) {
  10630. matchFailed("\"true\"");
  10631. }
  10632. }
  10633. if (result2 !== null) {
  10634. result2 = function (offset) {
  10635. data.stale = true;
  10636. }(pos1);
  10637. }
  10638. if (result2 === null) {
  10639. pos = pos1;
  10640. }
  10641. if (result2 === null) {
  10642. pos1 = pos;
  10643. if (input.substr(pos, 5).toLowerCase() === "false") {
  10644. result2 = input.substr(pos, 5);
  10645. pos += 5;
  10646. } else {
  10647. result2 = null;
  10648. if (reportFailures === 0) {
  10649. matchFailed("\"false\"");
  10650. }
  10651. }
  10652. if (result2 !== null) {
  10653. result2 = function (offset) {
  10654. data.stale = false;
  10655. }(pos1);
  10656. }
  10657. if (result2 === null) {
  10658. pos = pos1;
  10659. }
  10660. }
  10661. if (result2 !== null) {
  10662. result0 = [result0, result1, result2];
  10663. } else {
  10664. result0 = null;
  10665. pos = pos0;
  10666. }
  10667. } else {
  10668. result0 = null;
  10669. pos = pos0;
  10670. }
  10671. } else {
  10672. result0 = null;
  10673. pos = pos0;
  10674. }
  10675. return result0;
  10676. }
  10677. function parse_algorithm() {
  10678. var result0, result1, result2;
  10679. var pos0, pos1;
  10680. pos0 = pos;
  10681. pos1 = pos;
  10682. if (input.substr(pos, 9).toLowerCase() === "algorithm") {
  10683. result0 = input.substr(pos, 9);
  10684. pos += 9;
  10685. } else {
  10686. result0 = null;
  10687. if (reportFailures === 0) {
  10688. matchFailed("\"algorithm\"");
  10689. }
  10690. }
  10691. if (result0 !== null) {
  10692. result1 = parse_EQUAL();
  10693. if (result1 !== null) {
  10694. if (input.substr(pos, 3).toLowerCase() === "md5") {
  10695. result2 = input.substr(pos, 3);
  10696. pos += 3;
  10697. } else {
  10698. result2 = null;
  10699. if (reportFailures === 0) {
  10700. matchFailed("\"MD5\"");
  10701. }
  10702. }
  10703. if (result2 === null) {
  10704. if (input.substr(pos, 8).toLowerCase() === "md5-sess") {
  10705. result2 = input.substr(pos, 8);
  10706. pos += 8;
  10707. } else {
  10708. result2 = null;
  10709. if (reportFailures === 0) {
  10710. matchFailed("\"MD5-sess\"");
  10711. }
  10712. }
  10713. if (result2 === null) {
  10714. result2 = parse_token();
  10715. }
  10716. }
  10717. if (result2 !== null) {
  10718. result0 = [result0, result1, result2];
  10719. } else {
  10720. result0 = null;
  10721. pos = pos1;
  10722. }
  10723. } else {
  10724. result0 = null;
  10725. pos = pos1;
  10726. }
  10727. } else {
  10728. result0 = null;
  10729. pos = pos1;
  10730. }
  10731. if (result0 !== null) {
  10732. result0 = function (offset, algorithm) {
  10733. data.algorithm = algorithm.toUpperCase();
  10734. }(pos0, result0[2]);
  10735. }
  10736. if (result0 === null) {
  10737. pos = pos0;
  10738. }
  10739. return result0;
  10740. }
  10741. function parse_qop_options() {
  10742. var result0, result1, result2, result3, result4, result5, result6;
  10743. var pos0, pos1, pos2;
  10744. pos0 = pos;
  10745. if (input.substr(pos, 3).toLowerCase() === "qop") {
  10746. result0 = input.substr(pos, 3);
  10747. pos += 3;
  10748. } else {
  10749. result0 = null;
  10750. if (reportFailures === 0) {
  10751. matchFailed("\"qop\"");
  10752. }
  10753. }
  10754. if (result0 !== null) {
  10755. result1 = parse_EQUAL();
  10756. if (result1 !== null) {
  10757. result2 = parse_LDQUOT();
  10758. if (result2 !== null) {
  10759. pos1 = pos;
  10760. result3 = parse_qop_value();
  10761. if (result3 !== null) {
  10762. result4 = [];
  10763. pos2 = pos;
  10764. if (input.charCodeAt(pos) === 44) {
  10765. result5 = ",";
  10766. pos++;
  10767. } else {
  10768. result5 = null;
  10769. if (reportFailures === 0) {
  10770. matchFailed("\",\"");
  10771. }
  10772. }
  10773. if (result5 !== null) {
  10774. result6 = parse_qop_value();
  10775. if (result6 !== null) {
  10776. result5 = [result5, result6];
  10777. } else {
  10778. result5 = null;
  10779. pos = pos2;
  10780. }
  10781. } else {
  10782. result5 = null;
  10783. pos = pos2;
  10784. }
  10785. while (result5 !== null) {
  10786. result4.push(result5);
  10787. pos2 = pos;
  10788. if (input.charCodeAt(pos) === 44) {
  10789. result5 = ",";
  10790. pos++;
  10791. } else {
  10792. result5 = null;
  10793. if (reportFailures === 0) {
  10794. matchFailed("\",\"");
  10795. }
  10796. }
  10797. if (result5 !== null) {
  10798. result6 = parse_qop_value();
  10799. if (result6 !== null) {
  10800. result5 = [result5, result6];
  10801. } else {
  10802. result5 = null;
  10803. pos = pos2;
  10804. }
  10805. } else {
  10806. result5 = null;
  10807. pos = pos2;
  10808. }
  10809. }
  10810. if (result4 !== null) {
  10811. result3 = [result3, result4];
  10812. } else {
  10813. result3 = null;
  10814. pos = pos1;
  10815. }
  10816. } else {
  10817. result3 = null;
  10818. pos = pos1;
  10819. }
  10820. if (result3 !== null) {
  10821. result4 = parse_RDQUOT();
  10822. if (result4 !== null) {
  10823. result0 = [result0, result1, result2, result3, result4];
  10824. } else {
  10825. result0 = null;
  10826. pos = pos0;
  10827. }
  10828. } else {
  10829. result0 = null;
  10830. pos = pos0;
  10831. }
  10832. } else {
  10833. result0 = null;
  10834. pos = pos0;
  10835. }
  10836. } else {
  10837. result0 = null;
  10838. pos = pos0;
  10839. }
  10840. } else {
  10841. result0 = null;
  10842. pos = pos0;
  10843. }
  10844. return result0;
  10845. }
  10846. function parse_qop_value() {
  10847. var result0;
  10848. var pos0;
  10849. pos0 = pos;
  10850. if (input.substr(pos, 8).toLowerCase() === "auth-int") {
  10851. result0 = input.substr(pos, 8);
  10852. pos += 8;
  10853. } else {
  10854. result0 = null;
  10855. if (reportFailures === 0) {
  10856. matchFailed("\"auth-int\"");
  10857. }
  10858. }
  10859. if (result0 === null) {
  10860. if (input.substr(pos, 4).toLowerCase() === "auth") {
  10861. result0 = input.substr(pos, 4);
  10862. pos += 4;
  10863. } else {
  10864. result0 = null;
  10865. if (reportFailures === 0) {
  10866. matchFailed("\"auth\"");
  10867. }
  10868. }
  10869. if (result0 === null) {
  10870. result0 = parse_token();
  10871. }
  10872. }
  10873. if (result0 !== null) {
  10874. result0 = function (offset, qop_value) {
  10875. data.qop || (data.qop = []);
  10876. data.qop.push(qop_value.toLowerCase());
  10877. }(pos0, result0);
  10878. }
  10879. if (result0 === null) {
  10880. pos = pos0;
  10881. }
  10882. return result0;
  10883. }
  10884. function parse_Proxy_Require() {
  10885. var result0, result1, result2, result3;
  10886. var pos0, pos1;
  10887. pos0 = pos;
  10888. result0 = parse_token();
  10889. if (result0 !== null) {
  10890. result1 = [];
  10891. pos1 = pos;
  10892. result2 = parse_COMMA();
  10893. if (result2 !== null) {
  10894. result3 = parse_token();
  10895. if (result3 !== null) {
  10896. result2 = [result2, result3];
  10897. } else {
  10898. result2 = null;
  10899. pos = pos1;
  10900. }
  10901. } else {
  10902. result2 = null;
  10903. pos = pos1;
  10904. }
  10905. while (result2 !== null) {
  10906. result1.push(result2);
  10907. pos1 = pos;
  10908. result2 = parse_COMMA();
  10909. if (result2 !== null) {
  10910. result3 = parse_token();
  10911. if (result3 !== null) {
  10912. result2 = [result2, result3];
  10913. } else {
  10914. result2 = null;
  10915. pos = pos1;
  10916. }
  10917. } else {
  10918. result2 = null;
  10919. pos = pos1;
  10920. }
  10921. }
  10922. if (result1 !== null) {
  10923. result0 = [result0, result1];
  10924. } else {
  10925. result0 = null;
  10926. pos = pos0;
  10927. }
  10928. } else {
  10929. result0 = null;
  10930. pos = pos0;
  10931. }
  10932. return result0;
  10933. }
  10934. function parse_Record_Route() {
  10935. var result0, result1, result2, result3;
  10936. var pos0, pos1, pos2;
  10937. pos0 = pos;
  10938. pos1 = pos;
  10939. result0 = parse_rec_route();
  10940. if (result0 !== null) {
  10941. result1 = [];
  10942. pos2 = pos;
  10943. result2 = parse_COMMA();
  10944. if (result2 !== null) {
  10945. result3 = parse_rec_route();
  10946. if (result3 !== null) {
  10947. result2 = [result2, result3];
  10948. } else {
  10949. result2 = null;
  10950. pos = pos2;
  10951. }
  10952. } else {
  10953. result2 = null;
  10954. pos = pos2;
  10955. }
  10956. while (result2 !== null) {
  10957. result1.push(result2);
  10958. pos2 = pos;
  10959. result2 = parse_COMMA();
  10960. if (result2 !== null) {
  10961. result3 = parse_rec_route();
  10962. if (result3 !== null) {
  10963. result2 = [result2, result3];
  10964. } else {
  10965. result2 = null;
  10966. pos = pos2;
  10967. }
  10968. } else {
  10969. result2 = null;
  10970. pos = pos2;
  10971. }
  10972. }
  10973. if (result1 !== null) {
  10974. result0 = [result0, result1];
  10975. } else {
  10976. result0 = null;
  10977. pos = pos1;
  10978. }
  10979. } else {
  10980. result0 = null;
  10981. pos = pos1;
  10982. }
  10983. if (result0 !== null) {
  10984. result0 = function (offset) {
  10985. var idx, length;
  10986. length = data.multi_header.length;
  10987. for (idx = 0; idx < length; idx++) {
  10988. if (data.multi_header[idx].parsed === null) {
  10989. data = null;
  10990. break;
  10991. }
  10992. }
  10993. if (data !== null) {
  10994. data = data.multi_header;
  10995. } else {
  10996. data = -1;
  10997. }
  10998. }(pos0);
  10999. }
  11000. if (result0 === null) {
  11001. pos = pos0;
  11002. }
  11003. return result0;
  11004. }
  11005. function parse_rec_route() {
  11006. var result0, result1, result2, result3;
  11007. var pos0, pos1, pos2;
  11008. pos0 = pos;
  11009. pos1 = pos;
  11010. result0 = parse_name_addr();
  11011. if (result0 !== null) {
  11012. result1 = [];
  11013. pos2 = pos;
  11014. result2 = parse_SEMI();
  11015. if (result2 !== null) {
  11016. result3 = parse_generic_param();
  11017. if (result3 !== null) {
  11018. result2 = [result2, result3];
  11019. } else {
  11020. result2 = null;
  11021. pos = pos2;
  11022. }
  11023. } else {
  11024. result2 = null;
  11025. pos = pos2;
  11026. }
  11027. while (result2 !== null) {
  11028. result1.push(result2);
  11029. pos2 = pos;
  11030. result2 = parse_SEMI();
  11031. if (result2 !== null) {
  11032. result3 = parse_generic_param();
  11033. if (result3 !== null) {
  11034. result2 = [result2, result3];
  11035. } else {
  11036. result2 = null;
  11037. pos = pos2;
  11038. }
  11039. } else {
  11040. result2 = null;
  11041. pos = pos2;
  11042. }
  11043. }
  11044. if (result1 !== null) {
  11045. result0 = [result0, result1];
  11046. } else {
  11047. result0 = null;
  11048. pos = pos1;
  11049. }
  11050. } else {
  11051. result0 = null;
  11052. pos = pos1;
  11053. }
  11054. if (result0 !== null) {
  11055. result0 = function (offset) {
  11056. var header;
  11057. if (!data.multi_header) data.multi_header = [];
  11058. try {
  11059. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  11060. delete data.uri;
  11061. delete data.display_name;
  11062. delete data.params;
  11063. } catch (e) {
  11064. header = null;
  11065. }
  11066. data.multi_header.push({
  11067. 'possition': pos,
  11068. 'offset': offset,
  11069. 'parsed': header
  11070. });
  11071. }(pos0);
  11072. }
  11073. if (result0 === null) {
  11074. pos = pos0;
  11075. }
  11076. return result0;
  11077. }
  11078. function parse_Reason() {
  11079. var result0, result1, result2, result3;
  11080. var pos0, pos1, pos2;
  11081. pos0 = pos;
  11082. pos1 = pos;
  11083. if (input.substr(pos, 3).toLowerCase() === "sip") {
  11084. result0 = input.substr(pos, 3);
  11085. pos += 3;
  11086. } else {
  11087. result0 = null;
  11088. if (reportFailures === 0) {
  11089. matchFailed("\"SIP\"");
  11090. }
  11091. }
  11092. if (result0 === null) {
  11093. result0 = parse_token();
  11094. }
  11095. if (result0 !== null) {
  11096. result1 = [];
  11097. pos2 = pos;
  11098. result2 = parse_SEMI();
  11099. if (result2 !== null) {
  11100. result3 = parse_reason_param();
  11101. if (result3 !== null) {
  11102. result2 = [result2, result3];
  11103. } else {
  11104. result2 = null;
  11105. pos = pos2;
  11106. }
  11107. } else {
  11108. result2 = null;
  11109. pos = pos2;
  11110. }
  11111. while (result2 !== null) {
  11112. result1.push(result2);
  11113. pos2 = pos;
  11114. result2 = parse_SEMI();
  11115. if (result2 !== null) {
  11116. result3 = parse_reason_param();
  11117. if (result3 !== null) {
  11118. result2 = [result2, result3];
  11119. } else {
  11120. result2 = null;
  11121. pos = pos2;
  11122. }
  11123. } else {
  11124. result2 = null;
  11125. pos = pos2;
  11126. }
  11127. }
  11128. if (result1 !== null) {
  11129. result0 = [result0, result1];
  11130. } else {
  11131. result0 = null;
  11132. pos = pos1;
  11133. }
  11134. } else {
  11135. result0 = null;
  11136. pos = pos1;
  11137. }
  11138. if (result0 !== null) {
  11139. result0 = function (offset, protocol) {
  11140. data.protocol = protocol.toLowerCase();
  11141. if (!data.params) data.params = {};
  11142. if (data.params.text && data.params.text[0] === '"') {
  11143. var text = data.params.text;
  11144. data.text = text.substring(1, text.length - 1);
  11145. delete data.params.text;
  11146. }
  11147. }(pos0, result0[0]);
  11148. }
  11149. if (result0 === null) {
  11150. pos = pos0;
  11151. }
  11152. return result0;
  11153. }
  11154. function parse_reason_param() {
  11155. var result0;
  11156. result0 = parse_reason_cause();
  11157. if (result0 === null) {
  11158. result0 = parse_generic_param();
  11159. }
  11160. return result0;
  11161. }
  11162. function parse_reason_cause() {
  11163. var result0, result1, result2, result3;
  11164. var pos0, pos1;
  11165. pos0 = pos;
  11166. pos1 = pos;
  11167. if (input.substr(pos, 5).toLowerCase() === "cause") {
  11168. result0 = input.substr(pos, 5);
  11169. pos += 5;
  11170. } else {
  11171. result0 = null;
  11172. if (reportFailures === 0) {
  11173. matchFailed("\"cause\"");
  11174. }
  11175. }
  11176. if (result0 !== null) {
  11177. result1 = parse_EQUAL();
  11178. if (result1 !== null) {
  11179. result3 = parse_DIGIT();
  11180. if (result3 !== null) {
  11181. result2 = [];
  11182. while (result3 !== null) {
  11183. result2.push(result3);
  11184. result3 = parse_DIGIT();
  11185. }
  11186. } else {
  11187. result2 = null;
  11188. }
  11189. if (result2 !== null) {
  11190. result0 = [result0, result1, result2];
  11191. } else {
  11192. result0 = null;
  11193. pos = pos1;
  11194. }
  11195. } else {
  11196. result0 = null;
  11197. pos = pos1;
  11198. }
  11199. } else {
  11200. result0 = null;
  11201. pos = pos1;
  11202. }
  11203. if (result0 !== null) {
  11204. result0 = function (offset, cause) {
  11205. data.cause = parseInt(cause.join(''));
  11206. }(pos0, result0[2]);
  11207. }
  11208. if (result0 === null) {
  11209. pos = pos0;
  11210. }
  11211. return result0;
  11212. }
  11213. function parse_Require() {
  11214. var result0, result1, result2, result3;
  11215. var pos0, pos1;
  11216. pos0 = pos;
  11217. result0 = parse_token();
  11218. if (result0 !== null) {
  11219. result1 = [];
  11220. pos1 = pos;
  11221. result2 = parse_COMMA();
  11222. if (result2 !== null) {
  11223. result3 = parse_token();
  11224. if (result3 !== null) {
  11225. result2 = [result2, result3];
  11226. } else {
  11227. result2 = null;
  11228. pos = pos1;
  11229. }
  11230. } else {
  11231. result2 = null;
  11232. pos = pos1;
  11233. }
  11234. while (result2 !== null) {
  11235. result1.push(result2);
  11236. pos1 = pos;
  11237. result2 = parse_COMMA();
  11238. if (result2 !== null) {
  11239. result3 = parse_token();
  11240. if (result3 !== null) {
  11241. result2 = [result2, result3];
  11242. } else {
  11243. result2 = null;
  11244. pos = pos1;
  11245. }
  11246. } else {
  11247. result2 = null;
  11248. pos = pos1;
  11249. }
  11250. }
  11251. if (result1 !== null) {
  11252. result0 = [result0, result1];
  11253. } else {
  11254. result0 = null;
  11255. pos = pos0;
  11256. }
  11257. } else {
  11258. result0 = null;
  11259. pos = pos0;
  11260. }
  11261. return result0;
  11262. }
  11263. function parse_Route() {
  11264. var result0, result1, result2, result3;
  11265. var pos0, pos1;
  11266. pos0 = pos;
  11267. result0 = parse_route_param();
  11268. if (result0 !== null) {
  11269. result1 = [];
  11270. pos1 = pos;
  11271. result2 = parse_COMMA();
  11272. if (result2 !== null) {
  11273. result3 = parse_route_param();
  11274. if (result3 !== null) {
  11275. result2 = [result2, result3];
  11276. } else {
  11277. result2 = null;
  11278. pos = pos1;
  11279. }
  11280. } else {
  11281. result2 = null;
  11282. pos = pos1;
  11283. }
  11284. while (result2 !== null) {
  11285. result1.push(result2);
  11286. pos1 = pos;
  11287. result2 = parse_COMMA();
  11288. if (result2 !== null) {
  11289. result3 = parse_route_param();
  11290. if (result3 !== null) {
  11291. result2 = [result2, result3];
  11292. } else {
  11293. result2 = null;
  11294. pos = pos1;
  11295. }
  11296. } else {
  11297. result2 = null;
  11298. pos = pos1;
  11299. }
  11300. }
  11301. if (result1 !== null) {
  11302. result0 = [result0, result1];
  11303. } else {
  11304. result0 = null;
  11305. pos = pos0;
  11306. }
  11307. } else {
  11308. result0 = null;
  11309. pos = pos0;
  11310. }
  11311. return result0;
  11312. }
  11313. function parse_route_param() {
  11314. var result0, result1, result2, result3;
  11315. var pos0, pos1;
  11316. pos0 = pos;
  11317. result0 = parse_name_addr();
  11318. if (result0 !== null) {
  11319. result1 = [];
  11320. pos1 = pos;
  11321. result2 = parse_SEMI();
  11322. if (result2 !== null) {
  11323. result3 = parse_generic_param();
  11324. if (result3 !== null) {
  11325. result2 = [result2, result3];
  11326. } else {
  11327. result2 = null;
  11328. pos = pos1;
  11329. }
  11330. } else {
  11331. result2 = null;
  11332. pos = pos1;
  11333. }
  11334. while (result2 !== null) {
  11335. result1.push(result2);
  11336. pos1 = pos;
  11337. result2 = parse_SEMI();
  11338. if (result2 !== null) {
  11339. result3 = parse_generic_param();
  11340. if (result3 !== null) {
  11341. result2 = [result2, result3];
  11342. } else {
  11343. result2 = null;
  11344. pos = pos1;
  11345. }
  11346. } else {
  11347. result2 = null;
  11348. pos = pos1;
  11349. }
  11350. }
  11351. if (result1 !== null) {
  11352. result0 = [result0, result1];
  11353. } else {
  11354. result0 = null;
  11355. pos = pos0;
  11356. }
  11357. } else {
  11358. result0 = null;
  11359. pos = pos0;
  11360. }
  11361. return result0;
  11362. }
  11363. function parse_Subscription_State() {
  11364. var result0, result1, result2, result3;
  11365. var pos0, pos1;
  11366. pos0 = pos;
  11367. result0 = parse_substate_value();
  11368. if (result0 !== null) {
  11369. result1 = [];
  11370. pos1 = pos;
  11371. result2 = parse_SEMI();
  11372. if (result2 !== null) {
  11373. result3 = parse_subexp_params();
  11374. if (result3 !== null) {
  11375. result2 = [result2, result3];
  11376. } else {
  11377. result2 = null;
  11378. pos = pos1;
  11379. }
  11380. } else {
  11381. result2 = null;
  11382. pos = pos1;
  11383. }
  11384. while (result2 !== null) {
  11385. result1.push(result2);
  11386. pos1 = pos;
  11387. result2 = parse_SEMI();
  11388. if (result2 !== null) {
  11389. result3 = parse_subexp_params();
  11390. if (result3 !== null) {
  11391. result2 = [result2, result3];
  11392. } else {
  11393. result2 = null;
  11394. pos = pos1;
  11395. }
  11396. } else {
  11397. result2 = null;
  11398. pos = pos1;
  11399. }
  11400. }
  11401. if (result1 !== null) {
  11402. result0 = [result0, result1];
  11403. } else {
  11404. result0 = null;
  11405. pos = pos0;
  11406. }
  11407. } else {
  11408. result0 = null;
  11409. pos = pos0;
  11410. }
  11411. return result0;
  11412. }
  11413. function parse_substate_value() {
  11414. var result0;
  11415. var pos0;
  11416. pos0 = pos;
  11417. if (input.substr(pos, 6).toLowerCase() === "active") {
  11418. result0 = input.substr(pos, 6);
  11419. pos += 6;
  11420. } else {
  11421. result0 = null;
  11422. if (reportFailures === 0) {
  11423. matchFailed("\"active\"");
  11424. }
  11425. }
  11426. if (result0 === null) {
  11427. if (input.substr(pos, 7).toLowerCase() === "pending") {
  11428. result0 = input.substr(pos, 7);
  11429. pos += 7;
  11430. } else {
  11431. result0 = null;
  11432. if (reportFailures === 0) {
  11433. matchFailed("\"pending\"");
  11434. }
  11435. }
  11436. if (result0 === null) {
  11437. if (input.substr(pos, 10).toLowerCase() === "terminated") {
  11438. result0 = input.substr(pos, 10);
  11439. pos += 10;
  11440. } else {
  11441. result0 = null;
  11442. if (reportFailures === 0) {
  11443. matchFailed("\"terminated\"");
  11444. }
  11445. }
  11446. if (result0 === null) {
  11447. result0 = parse_token();
  11448. }
  11449. }
  11450. }
  11451. if (result0 !== null) {
  11452. result0 = function (offset) {
  11453. data.state = input.substring(pos, offset);
  11454. }(pos0);
  11455. }
  11456. if (result0 === null) {
  11457. pos = pos0;
  11458. }
  11459. return result0;
  11460. }
  11461. function parse_subexp_params() {
  11462. var result0, result1, result2;
  11463. var pos0, pos1;
  11464. pos0 = pos;
  11465. pos1 = pos;
  11466. if (input.substr(pos, 6).toLowerCase() === "reason") {
  11467. result0 = input.substr(pos, 6);
  11468. pos += 6;
  11469. } else {
  11470. result0 = null;
  11471. if (reportFailures === 0) {
  11472. matchFailed("\"reason\"");
  11473. }
  11474. }
  11475. if (result0 !== null) {
  11476. result1 = parse_EQUAL();
  11477. if (result1 !== null) {
  11478. result2 = parse_event_reason_value();
  11479. if (result2 !== null) {
  11480. result0 = [result0, result1, result2];
  11481. } else {
  11482. result0 = null;
  11483. pos = pos1;
  11484. }
  11485. } else {
  11486. result0 = null;
  11487. pos = pos1;
  11488. }
  11489. } else {
  11490. result0 = null;
  11491. pos = pos1;
  11492. }
  11493. if (result0 !== null) {
  11494. result0 = function (offset, reason) {
  11495. if (typeof reason !== 'undefined') data.reason = reason;
  11496. }(pos0, result0[2]);
  11497. }
  11498. if (result0 === null) {
  11499. pos = pos0;
  11500. }
  11501. if (result0 === null) {
  11502. pos0 = pos;
  11503. pos1 = pos;
  11504. if (input.substr(pos, 7).toLowerCase() === "expires") {
  11505. result0 = input.substr(pos, 7);
  11506. pos += 7;
  11507. } else {
  11508. result0 = null;
  11509. if (reportFailures === 0) {
  11510. matchFailed("\"expires\"");
  11511. }
  11512. }
  11513. if (result0 !== null) {
  11514. result1 = parse_EQUAL();
  11515. if (result1 !== null) {
  11516. result2 = parse_delta_seconds();
  11517. if (result2 !== null) {
  11518. result0 = [result0, result1, result2];
  11519. } else {
  11520. result0 = null;
  11521. pos = pos1;
  11522. }
  11523. } else {
  11524. result0 = null;
  11525. pos = pos1;
  11526. }
  11527. } else {
  11528. result0 = null;
  11529. pos = pos1;
  11530. }
  11531. if (result0 !== null) {
  11532. result0 = function (offset, expires) {
  11533. if (typeof expires !== 'undefined') data.expires = expires;
  11534. }(pos0, result0[2]);
  11535. }
  11536. if (result0 === null) {
  11537. pos = pos0;
  11538. }
  11539. if (result0 === null) {
  11540. pos0 = pos;
  11541. pos1 = pos;
  11542. if (input.substr(pos, 11).toLowerCase() === "retry_after") {
  11543. result0 = input.substr(pos, 11);
  11544. pos += 11;
  11545. } else {
  11546. result0 = null;
  11547. if (reportFailures === 0) {
  11548. matchFailed("\"retry_after\"");
  11549. }
  11550. }
  11551. if (result0 !== null) {
  11552. result1 = parse_EQUAL();
  11553. if (result1 !== null) {
  11554. result2 = parse_delta_seconds();
  11555. if (result2 !== null) {
  11556. result0 = [result0, result1, result2];
  11557. } else {
  11558. result0 = null;
  11559. pos = pos1;
  11560. }
  11561. } else {
  11562. result0 = null;
  11563. pos = pos1;
  11564. }
  11565. } else {
  11566. result0 = null;
  11567. pos = pos1;
  11568. }
  11569. if (result0 !== null) {
  11570. result0 = function (offset, retry_after) {
  11571. if (typeof retry_after !== 'undefined') data.retry_after = retry_after;
  11572. }(pos0, result0[2]);
  11573. }
  11574. if (result0 === null) {
  11575. pos = pos0;
  11576. }
  11577. if (result0 === null) {
  11578. result0 = parse_generic_param();
  11579. }
  11580. }
  11581. }
  11582. return result0;
  11583. }
  11584. function parse_event_reason_value() {
  11585. var result0;
  11586. if (input.substr(pos, 11).toLowerCase() === "deactivated") {
  11587. result0 = input.substr(pos, 11);
  11588. pos += 11;
  11589. } else {
  11590. result0 = null;
  11591. if (reportFailures === 0) {
  11592. matchFailed("\"deactivated\"");
  11593. }
  11594. }
  11595. if (result0 === null) {
  11596. if (input.substr(pos, 9).toLowerCase() === "probation") {
  11597. result0 = input.substr(pos, 9);
  11598. pos += 9;
  11599. } else {
  11600. result0 = null;
  11601. if (reportFailures === 0) {
  11602. matchFailed("\"probation\"");
  11603. }
  11604. }
  11605. if (result0 === null) {
  11606. if (input.substr(pos, 8).toLowerCase() === "rejected") {
  11607. result0 = input.substr(pos, 8);
  11608. pos += 8;
  11609. } else {
  11610. result0 = null;
  11611. if (reportFailures === 0) {
  11612. matchFailed("\"rejected\"");
  11613. }
  11614. }
  11615. if (result0 === null) {
  11616. if (input.substr(pos, 7).toLowerCase() === "timeout") {
  11617. result0 = input.substr(pos, 7);
  11618. pos += 7;
  11619. } else {
  11620. result0 = null;
  11621. if (reportFailures === 0) {
  11622. matchFailed("\"timeout\"");
  11623. }
  11624. }
  11625. if (result0 === null) {
  11626. if (input.substr(pos, 6).toLowerCase() === "giveup") {
  11627. result0 = input.substr(pos, 6);
  11628. pos += 6;
  11629. } else {
  11630. result0 = null;
  11631. if (reportFailures === 0) {
  11632. matchFailed("\"giveup\"");
  11633. }
  11634. }
  11635. if (result0 === null) {
  11636. if (input.substr(pos, 10).toLowerCase() === "noresource") {
  11637. result0 = input.substr(pos, 10);
  11638. pos += 10;
  11639. } else {
  11640. result0 = null;
  11641. if (reportFailures === 0) {
  11642. matchFailed("\"noresource\"");
  11643. }
  11644. }
  11645. if (result0 === null) {
  11646. if (input.substr(pos, 9).toLowerCase() === "invariant") {
  11647. result0 = input.substr(pos, 9);
  11648. pos += 9;
  11649. } else {
  11650. result0 = null;
  11651. if (reportFailures === 0) {
  11652. matchFailed("\"invariant\"");
  11653. }
  11654. }
  11655. if (result0 === null) {
  11656. result0 = parse_token();
  11657. }
  11658. }
  11659. }
  11660. }
  11661. }
  11662. }
  11663. }
  11664. return result0;
  11665. }
  11666. function parse_Subject() {
  11667. var result0;
  11668. result0 = parse_TEXT_UTF8_TRIM();
  11669. result0 = result0 !== null ? result0 : "";
  11670. return result0;
  11671. }
  11672. function parse_Supported() {
  11673. var result0, result1, result2, result3;
  11674. var pos0, pos1;
  11675. pos0 = pos;
  11676. result0 = parse_token();
  11677. if (result0 !== null) {
  11678. result1 = [];
  11679. pos1 = pos;
  11680. result2 = parse_COMMA();
  11681. if (result2 !== null) {
  11682. result3 = parse_token();
  11683. if (result3 !== null) {
  11684. result2 = [result2, result3];
  11685. } else {
  11686. result2 = null;
  11687. pos = pos1;
  11688. }
  11689. } else {
  11690. result2 = null;
  11691. pos = pos1;
  11692. }
  11693. while (result2 !== null) {
  11694. result1.push(result2);
  11695. pos1 = pos;
  11696. result2 = parse_COMMA();
  11697. if (result2 !== null) {
  11698. result3 = parse_token();
  11699. if (result3 !== null) {
  11700. result2 = [result2, result3];
  11701. } else {
  11702. result2 = null;
  11703. pos = pos1;
  11704. }
  11705. } else {
  11706. result2 = null;
  11707. pos = pos1;
  11708. }
  11709. }
  11710. if (result1 !== null) {
  11711. result0 = [result0, result1];
  11712. } else {
  11713. result0 = null;
  11714. pos = pos0;
  11715. }
  11716. } else {
  11717. result0 = null;
  11718. pos = pos0;
  11719. }
  11720. result0 = result0 !== null ? result0 : "";
  11721. return result0;
  11722. }
  11723. function parse_To() {
  11724. var result0, result1, result2, result3;
  11725. var pos0, pos1, pos2;
  11726. pos0 = pos;
  11727. pos1 = pos;
  11728. result0 = parse_SIP_URI_noparams();
  11729. if (result0 === null) {
  11730. result0 = parse_name_addr();
  11731. }
  11732. if (result0 !== null) {
  11733. result1 = [];
  11734. pos2 = pos;
  11735. result2 = parse_SEMI();
  11736. if (result2 !== null) {
  11737. result3 = parse_to_param();
  11738. if (result3 !== null) {
  11739. result2 = [result2, result3];
  11740. } else {
  11741. result2 = null;
  11742. pos = pos2;
  11743. }
  11744. } else {
  11745. result2 = null;
  11746. pos = pos2;
  11747. }
  11748. while (result2 !== null) {
  11749. result1.push(result2);
  11750. pos2 = pos;
  11751. result2 = parse_SEMI();
  11752. if (result2 !== null) {
  11753. result3 = parse_to_param();
  11754. if (result3 !== null) {
  11755. result2 = [result2, result3];
  11756. } else {
  11757. result2 = null;
  11758. pos = pos2;
  11759. }
  11760. } else {
  11761. result2 = null;
  11762. pos = pos2;
  11763. }
  11764. }
  11765. if (result1 !== null) {
  11766. result0 = [result0, result1];
  11767. } else {
  11768. result0 = null;
  11769. pos = pos1;
  11770. }
  11771. } else {
  11772. result0 = null;
  11773. pos = pos1;
  11774. }
  11775. if (result0 !== null) {
  11776. result0 = function (offset) {
  11777. var tag = data.tag;
  11778. try {
  11779. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  11780. if (tag) {
  11781. data.setParam('tag', tag);
  11782. }
  11783. } catch (e) {
  11784. data = -1;
  11785. }
  11786. }(pos0);
  11787. }
  11788. if (result0 === null) {
  11789. pos = pos0;
  11790. }
  11791. return result0;
  11792. }
  11793. function parse_to_param() {
  11794. var result0;
  11795. result0 = parse_tag_param();
  11796. if (result0 === null) {
  11797. result0 = parse_generic_param();
  11798. }
  11799. return result0;
  11800. }
  11801. function parse_Via() {
  11802. var result0, result1, result2, result3;
  11803. var pos0, pos1;
  11804. pos0 = pos;
  11805. result0 = parse_via_param();
  11806. if (result0 !== null) {
  11807. result1 = [];
  11808. pos1 = pos;
  11809. result2 = parse_COMMA();
  11810. if (result2 !== null) {
  11811. result3 = parse_via_param();
  11812. if (result3 !== null) {
  11813. result2 = [result2, result3];
  11814. } else {
  11815. result2 = null;
  11816. pos = pos1;
  11817. }
  11818. } else {
  11819. result2 = null;
  11820. pos = pos1;
  11821. }
  11822. while (result2 !== null) {
  11823. result1.push(result2);
  11824. pos1 = pos;
  11825. result2 = parse_COMMA();
  11826. if (result2 !== null) {
  11827. result3 = parse_via_param();
  11828. if (result3 !== null) {
  11829. result2 = [result2, result3];
  11830. } else {
  11831. result2 = null;
  11832. pos = pos1;
  11833. }
  11834. } else {
  11835. result2 = null;
  11836. pos = pos1;
  11837. }
  11838. }
  11839. if (result1 !== null) {
  11840. result0 = [result0, result1];
  11841. } else {
  11842. result0 = null;
  11843. pos = pos0;
  11844. }
  11845. } else {
  11846. result0 = null;
  11847. pos = pos0;
  11848. }
  11849. return result0;
  11850. }
  11851. function parse_via_param() {
  11852. var result0, result1, result2, result3, result4, result5;
  11853. var pos0, pos1;
  11854. pos0 = pos;
  11855. result0 = parse_sent_protocol();
  11856. if (result0 !== null) {
  11857. result1 = parse_LWS();
  11858. if (result1 !== null) {
  11859. result2 = parse_sent_by();
  11860. if (result2 !== null) {
  11861. result3 = [];
  11862. pos1 = pos;
  11863. result4 = parse_SEMI();
  11864. if (result4 !== null) {
  11865. result5 = parse_via_params();
  11866. if (result5 !== null) {
  11867. result4 = [result4, result5];
  11868. } else {
  11869. result4 = null;
  11870. pos = pos1;
  11871. }
  11872. } else {
  11873. result4 = null;
  11874. pos = pos1;
  11875. }
  11876. while (result4 !== null) {
  11877. result3.push(result4);
  11878. pos1 = pos;
  11879. result4 = parse_SEMI();
  11880. if (result4 !== null) {
  11881. result5 = parse_via_params();
  11882. if (result5 !== null) {
  11883. result4 = [result4, result5];
  11884. } else {
  11885. result4 = null;
  11886. pos = pos1;
  11887. }
  11888. } else {
  11889. result4 = null;
  11890. pos = pos1;
  11891. }
  11892. }
  11893. if (result3 !== null) {
  11894. result0 = [result0, result1, result2, result3];
  11895. } else {
  11896. result0 = null;
  11897. pos = pos0;
  11898. }
  11899. } else {
  11900. result0 = null;
  11901. pos = pos0;
  11902. }
  11903. } else {
  11904. result0 = null;
  11905. pos = pos0;
  11906. }
  11907. } else {
  11908. result0 = null;
  11909. pos = pos0;
  11910. }
  11911. return result0;
  11912. }
  11913. function parse_via_params() {
  11914. var result0;
  11915. result0 = parse_via_ttl();
  11916. if (result0 === null) {
  11917. result0 = parse_via_maddr();
  11918. if (result0 === null) {
  11919. result0 = parse_via_received();
  11920. if (result0 === null) {
  11921. result0 = parse_via_branch();
  11922. if (result0 === null) {
  11923. result0 = parse_response_port();
  11924. if (result0 === null) {
  11925. result0 = parse_generic_param();
  11926. }
  11927. }
  11928. }
  11929. }
  11930. }
  11931. return result0;
  11932. }
  11933. function parse_via_ttl() {
  11934. var result0, result1, result2;
  11935. var pos0, pos1;
  11936. pos0 = pos;
  11937. pos1 = pos;
  11938. if (input.substr(pos, 3).toLowerCase() === "ttl") {
  11939. result0 = input.substr(pos, 3);
  11940. pos += 3;
  11941. } else {
  11942. result0 = null;
  11943. if (reportFailures === 0) {
  11944. matchFailed("\"ttl\"");
  11945. }
  11946. }
  11947. if (result0 !== null) {
  11948. result1 = parse_EQUAL();
  11949. if (result1 !== null) {
  11950. result2 = parse_ttl();
  11951. if (result2 !== null) {
  11952. result0 = [result0, result1, result2];
  11953. } else {
  11954. result0 = null;
  11955. pos = pos1;
  11956. }
  11957. } else {
  11958. result0 = null;
  11959. pos = pos1;
  11960. }
  11961. } else {
  11962. result0 = null;
  11963. pos = pos1;
  11964. }
  11965. if (result0 !== null) {
  11966. result0 = function (offset, via_ttl_value) {
  11967. data.ttl = via_ttl_value;
  11968. }(pos0, result0[2]);
  11969. }
  11970. if (result0 === null) {
  11971. pos = pos0;
  11972. }
  11973. return result0;
  11974. }
  11975. function parse_via_maddr() {
  11976. var result0, result1, result2;
  11977. var pos0, pos1;
  11978. pos0 = pos;
  11979. pos1 = pos;
  11980. if (input.substr(pos, 5).toLowerCase() === "maddr") {
  11981. result0 = input.substr(pos, 5);
  11982. pos += 5;
  11983. } else {
  11984. result0 = null;
  11985. if (reportFailures === 0) {
  11986. matchFailed("\"maddr\"");
  11987. }
  11988. }
  11989. if (result0 !== null) {
  11990. result1 = parse_EQUAL();
  11991. if (result1 !== null) {
  11992. result2 = parse_host();
  11993. if (result2 !== null) {
  11994. result0 = [result0, result1, result2];
  11995. } else {
  11996. result0 = null;
  11997. pos = pos1;
  11998. }
  11999. } else {
  12000. result0 = null;
  12001. pos = pos1;
  12002. }
  12003. } else {
  12004. result0 = null;
  12005. pos = pos1;
  12006. }
  12007. if (result0 !== null) {
  12008. result0 = function (offset, via_maddr) {
  12009. data.maddr = via_maddr;
  12010. }(pos0, result0[2]);
  12011. }
  12012. if (result0 === null) {
  12013. pos = pos0;
  12014. }
  12015. return result0;
  12016. }
  12017. function parse_via_received() {
  12018. var result0, result1, result2;
  12019. var pos0, pos1;
  12020. pos0 = pos;
  12021. pos1 = pos;
  12022. if (input.substr(pos, 8).toLowerCase() === "received") {
  12023. result0 = input.substr(pos, 8);
  12024. pos += 8;
  12025. } else {
  12026. result0 = null;
  12027. if (reportFailures === 0) {
  12028. matchFailed("\"received\"");
  12029. }
  12030. }
  12031. if (result0 !== null) {
  12032. result1 = parse_EQUAL();
  12033. if (result1 !== null) {
  12034. result2 = parse_IPv4address();
  12035. if (result2 === null) {
  12036. result2 = parse_IPv6address();
  12037. }
  12038. if (result2 !== null) {
  12039. result0 = [result0, result1, result2];
  12040. } else {
  12041. result0 = null;
  12042. pos = pos1;
  12043. }
  12044. } else {
  12045. result0 = null;
  12046. pos = pos1;
  12047. }
  12048. } else {
  12049. result0 = null;
  12050. pos = pos1;
  12051. }
  12052. if (result0 !== null) {
  12053. result0 = function (offset, via_received) {
  12054. data.received = via_received;
  12055. }(pos0, result0[2]);
  12056. }
  12057. if (result0 === null) {
  12058. pos = pos0;
  12059. }
  12060. return result0;
  12061. }
  12062. function parse_via_branch() {
  12063. var result0, result1, result2;
  12064. var pos0, pos1;
  12065. pos0 = pos;
  12066. pos1 = pos;
  12067. if (input.substr(pos, 6).toLowerCase() === "branch") {
  12068. result0 = input.substr(pos, 6);
  12069. pos += 6;
  12070. } else {
  12071. result0 = null;
  12072. if (reportFailures === 0) {
  12073. matchFailed("\"branch\"");
  12074. }
  12075. }
  12076. if (result0 !== null) {
  12077. result1 = parse_EQUAL();
  12078. if (result1 !== null) {
  12079. result2 = parse_token();
  12080. if (result2 !== null) {
  12081. result0 = [result0, result1, result2];
  12082. } else {
  12083. result0 = null;
  12084. pos = pos1;
  12085. }
  12086. } else {
  12087. result0 = null;
  12088. pos = pos1;
  12089. }
  12090. } else {
  12091. result0 = null;
  12092. pos = pos1;
  12093. }
  12094. if (result0 !== null) {
  12095. result0 = function (offset, via_branch) {
  12096. data.branch = via_branch;
  12097. }(pos0, result0[2]);
  12098. }
  12099. if (result0 === null) {
  12100. pos = pos0;
  12101. }
  12102. return result0;
  12103. }
  12104. function parse_response_port() {
  12105. var result0, result1, result2, result3;
  12106. var pos0, pos1, pos2;
  12107. pos0 = pos;
  12108. pos1 = pos;
  12109. if (input.substr(pos, 5).toLowerCase() === "rport") {
  12110. result0 = input.substr(pos, 5);
  12111. pos += 5;
  12112. } else {
  12113. result0 = null;
  12114. if (reportFailures === 0) {
  12115. matchFailed("\"rport\"");
  12116. }
  12117. }
  12118. if (result0 !== null) {
  12119. pos2 = pos;
  12120. result1 = parse_EQUAL();
  12121. if (result1 !== null) {
  12122. result2 = [];
  12123. result3 = parse_DIGIT();
  12124. while (result3 !== null) {
  12125. result2.push(result3);
  12126. result3 = parse_DIGIT();
  12127. }
  12128. if (result2 !== null) {
  12129. result1 = [result1, result2];
  12130. } else {
  12131. result1 = null;
  12132. pos = pos2;
  12133. }
  12134. } else {
  12135. result1 = null;
  12136. pos = pos2;
  12137. }
  12138. result1 = result1 !== null ? result1 : "";
  12139. if (result1 !== null) {
  12140. result0 = [result0, result1];
  12141. } else {
  12142. result0 = null;
  12143. pos = pos1;
  12144. }
  12145. } else {
  12146. result0 = null;
  12147. pos = pos1;
  12148. }
  12149. if (result0 !== null) {
  12150. result0 = function (offset) {
  12151. if (typeof response_port !== 'undefined') data.rport = response_port.join('');
  12152. }(pos0);
  12153. }
  12154. if (result0 === null) {
  12155. pos = pos0;
  12156. }
  12157. return result0;
  12158. }
  12159. function parse_sent_protocol() {
  12160. var result0, result1, result2, result3, result4;
  12161. var pos0;
  12162. pos0 = pos;
  12163. result0 = parse_protocol_name();
  12164. if (result0 !== null) {
  12165. result1 = parse_SLASH();
  12166. if (result1 !== null) {
  12167. result2 = parse_token();
  12168. if (result2 !== null) {
  12169. result3 = parse_SLASH();
  12170. if (result3 !== null) {
  12171. result4 = parse_transport();
  12172. if (result4 !== null) {
  12173. result0 = [result0, result1, result2, result3, result4];
  12174. } else {
  12175. result0 = null;
  12176. pos = pos0;
  12177. }
  12178. } else {
  12179. result0 = null;
  12180. pos = pos0;
  12181. }
  12182. } else {
  12183. result0 = null;
  12184. pos = pos0;
  12185. }
  12186. } else {
  12187. result0 = null;
  12188. pos = pos0;
  12189. }
  12190. } else {
  12191. result0 = null;
  12192. pos = pos0;
  12193. }
  12194. return result0;
  12195. }
  12196. function parse_protocol_name() {
  12197. var result0;
  12198. var pos0;
  12199. pos0 = pos;
  12200. if (input.substr(pos, 3).toLowerCase() === "sip") {
  12201. result0 = input.substr(pos, 3);
  12202. pos += 3;
  12203. } else {
  12204. result0 = null;
  12205. if (reportFailures === 0) {
  12206. matchFailed("\"SIP\"");
  12207. }
  12208. }
  12209. if (result0 === null) {
  12210. result0 = parse_token();
  12211. }
  12212. if (result0 !== null) {
  12213. result0 = function (offset, via_protocol) {
  12214. data.protocol = via_protocol;
  12215. }(pos0, result0);
  12216. }
  12217. if (result0 === null) {
  12218. pos = pos0;
  12219. }
  12220. return result0;
  12221. }
  12222. function parse_transport() {
  12223. var result0;
  12224. var pos0;
  12225. pos0 = pos;
  12226. if (input.substr(pos, 3).toLowerCase() === "udp") {
  12227. result0 = input.substr(pos, 3);
  12228. pos += 3;
  12229. } else {
  12230. result0 = null;
  12231. if (reportFailures === 0) {
  12232. matchFailed("\"UDP\"");
  12233. }
  12234. }
  12235. if (result0 === null) {
  12236. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  12237. result0 = input.substr(pos, 3);
  12238. pos += 3;
  12239. } else {
  12240. result0 = null;
  12241. if (reportFailures === 0) {
  12242. matchFailed("\"TCP\"");
  12243. }
  12244. }
  12245. if (result0 === null) {
  12246. if (input.substr(pos, 3).toLowerCase() === "tls") {
  12247. result0 = input.substr(pos, 3);
  12248. pos += 3;
  12249. } else {
  12250. result0 = null;
  12251. if (reportFailures === 0) {
  12252. matchFailed("\"TLS\"");
  12253. }
  12254. }
  12255. if (result0 === null) {
  12256. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  12257. result0 = input.substr(pos, 4);
  12258. pos += 4;
  12259. } else {
  12260. result0 = null;
  12261. if (reportFailures === 0) {
  12262. matchFailed("\"SCTP\"");
  12263. }
  12264. }
  12265. if (result0 === null) {
  12266. result0 = parse_token();
  12267. }
  12268. }
  12269. }
  12270. }
  12271. if (result0 !== null) {
  12272. result0 = function (offset, via_transport) {
  12273. data.transport = via_transport;
  12274. }(pos0, result0);
  12275. }
  12276. if (result0 === null) {
  12277. pos = pos0;
  12278. }
  12279. return result0;
  12280. }
  12281. function parse_sent_by() {
  12282. var result0, result1, result2;
  12283. var pos0, pos1;
  12284. pos0 = pos;
  12285. result0 = parse_via_host();
  12286. if (result0 !== null) {
  12287. pos1 = pos;
  12288. result1 = parse_COLON();
  12289. if (result1 !== null) {
  12290. result2 = parse_via_port();
  12291. if (result2 !== null) {
  12292. result1 = [result1, result2];
  12293. } else {
  12294. result1 = null;
  12295. pos = pos1;
  12296. }
  12297. } else {
  12298. result1 = null;
  12299. pos = pos1;
  12300. }
  12301. result1 = result1 !== null ? result1 : "";
  12302. if (result1 !== null) {
  12303. result0 = [result0, result1];
  12304. } else {
  12305. result0 = null;
  12306. pos = pos0;
  12307. }
  12308. } else {
  12309. result0 = null;
  12310. pos = pos0;
  12311. }
  12312. return result0;
  12313. }
  12314. function parse_via_host() {
  12315. var result0;
  12316. var pos0;
  12317. pos0 = pos;
  12318. result0 = parse_IPv4address();
  12319. if (result0 === null) {
  12320. result0 = parse_IPv6reference();
  12321. if (result0 === null) {
  12322. result0 = parse_hostname();
  12323. }
  12324. }
  12325. if (result0 !== null) {
  12326. result0 = function (offset) {
  12327. data.host = input.substring(pos, offset);
  12328. }(pos0);
  12329. }
  12330. if (result0 === null) {
  12331. pos = pos0;
  12332. }
  12333. return result0;
  12334. }
  12335. function parse_via_port() {
  12336. var result0, result1, result2, result3, result4;
  12337. var pos0, pos1;
  12338. pos0 = pos;
  12339. pos1 = pos;
  12340. result0 = parse_DIGIT();
  12341. result0 = result0 !== null ? result0 : "";
  12342. if (result0 !== null) {
  12343. result1 = parse_DIGIT();
  12344. result1 = result1 !== null ? result1 : "";
  12345. if (result1 !== null) {
  12346. result2 = parse_DIGIT();
  12347. result2 = result2 !== null ? result2 : "";
  12348. if (result2 !== null) {
  12349. result3 = parse_DIGIT();
  12350. result3 = result3 !== null ? result3 : "";
  12351. if (result3 !== null) {
  12352. result4 = parse_DIGIT();
  12353. result4 = result4 !== null ? result4 : "";
  12354. if (result4 !== null) {
  12355. result0 = [result0, result1, result2, result3, result4];
  12356. } else {
  12357. result0 = null;
  12358. pos = pos1;
  12359. }
  12360. } else {
  12361. result0 = null;
  12362. pos = pos1;
  12363. }
  12364. } else {
  12365. result0 = null;
  12366. pos = pos1;
  12367. }
  12368. } else {
  12369. result0 = null;
  12370. pos = pos1;
  12371. }
  12372. } else {
  12373. result0 = null;
  12374. pos = pos1;
  12375. }
  12376. if (result0 !== null) {
  12377. result0 = function (offset, via_sent_by_port) {
  12378. data.port = parseInt(via_sent_by_port.join(''));
  12379. }(pos0, result0);
  12380. }
  12381. if (result0 === null) {
  12382. pos = pos0;
  12383. }
  12384. return result0;
  12385. }
  12386. function parse_ttl() {
  12387. var result0, result1, result2;
  12388. var pos0, pos1;
  12389. pos0 = pos;
  12390. pos1 = pos;
  12391. result0 = parse_DIGIT();
  12392. if (result0 !== null) {
  12393. result1 = parse_DIGIT();
  12394. result1 = result1 !== null ? result1 : "";
  12395. if (result1 !== null) {
  12396. result2 = parse_DIGIT();
  12397. result2 = result2 !== null ? result2 : "";
  12398. if (result2 !== null) {
  12399. result0 = [result0, result1, result2];
  12400. } else {
  12401. result0 = null;
  12402. pos = pos1;
  12403. }
  12404. } else {
  12405. result0 = null;
  12406. pos = pos1;
  12407. }
  12408. } else {
  12409. result0 = null;
  12410. pos = pos1;
  12411. }
  12412. if (result0 !== null) {
  12413. result0 = function (offset, ttl) {
  12414. return parseInt(ttl.join(''));
  12415. }(pos0, result0);
  12416. }
  12417. if (result0 === null) {
  12418. pos = pos0;
  12419. }
  12420. return result0;
  12421. }
  12422. function parse_WWW_Authenticate() {
  12423. var result0;
  12424. result0 = parse_challenge();
  12425. return result0;
  12426. }
  12427. function parse_Session_Expires() {
  12428. var result0, result1, result2, result3;
  12429. var pos0, pos1;
  12430. pos0 = pos;
  12431. result0 = parse_s_e_expires();
  12432. if (result0 !== null) {
  12433. result1 = [];
  12434. pos1 = pos;
  12435. result2 = parse_SEMI();
  12436. if (result2 !== null) {
  12437. result3 = parse_s_e_params();
  12438. if (result3 !== null) {
  12439. result2 = [result2, result3];
  12440. } else {
  12441. result2 = null;
  12442. pos = pos1;
  12443. }
  12444. } else {
  12445. result2 = null;
  12446. pos = pos1;
  12447. }
  12448. while (result2 !== null) {
  12449. result1.push(result2);
  12450. pos1 = pos;
  12451. result2 = parse_SEMI();
  12452. if (result2 !== null) {
  12453. result3 = parse_s_e_params();
  12454. if (result3 !== null) {
  12455. result2 = [result2, result3];
  12456. } else {
  12457. result2 = null;
  12458. pos = pos1;
  12459. }
  12460. } else {
  12461. result2 = null;
  12462. pos = pos1;
  12463. }
  12464. }
  12465. if (result1 !== null) {
  12466. result0 = [result0, result1];
  12467. } else {
  12468. result0 = null;
  12469. pos = pos0;
  12470. }
  12471. } else {
  12472. result0 = null;
  12473. pos = pos0;
  12474. }
  12475. return result0;
  12476. }
  12477. function parse_s_e_expires() {
  12478. var result0;
  12479. var pos0;
  12480. pos0 = pos;
  12481. result0 = parse_delta_seconds();
  12482. if (result0 !== null) {
  12483. result0 = function (offset, expires) {
  12484. data.expires = expires;
  12485. }(pos0, result0);
  12486. }
  12487. if (result0 === null) {
  12488. pos = pos0;
  12489. }
  12490. return result0;
  12491. }
  12492. function parse_s_e_params() {
  12493. var result0;
  12494. result0 = parse_s_e_refresher();
  12495. if (result0 === null) {
  12496. result0 = parse_generic_param();
  12497. }
  12498. return result0;
  12499. }
  12500. function parse_s_e_refresher() {
  12501. var result0, result1, result2;
  12502. var pos0, pos1;
  12503. pos0 = pos;
  12504. pos1 = pos;
  12505. if (input.substr(pos, 9).toLowerCase() === "refresher") {
  12506. result0 = input.substr(pos, 9);
  12507. pos += 9;
  12508. } else {
  12509. result0 = null;
  12510. if (reportFailures === 0) {
  12511. matchFailed("\"refresher\"");
  12512. }
  12513. }
  12514. if (result0 !== null) {
  12515. result1 = parse_EQUAL();
  12516. if (result1 !== null) {
  12517. if (input.substr(pos, 3).toLowerCase() === "uac") {
  12518. result2 = input.substr(pos, 3);
  12519. pos += 3;
  12520. } else {
  12521. result2 = null;
  12522. if (reportFailures === 0) {
  12523. matchFailed("\"uac\"");
  12524. }
  12525. }
  12526. if (result2 === null) {
  12527. if (input.substr(pos, 3).toLowerCase() === "uas") {
  12528. result2 = input.substr(pos, 3);
  12529. pos += 3;
  12530. } else {
  12531. result2 = null;
  12532. if (reportFailures === 0) {
  12533. matchFailed("\"uas\"");
  12534. }
  12535. }
  12536. }
  12537. if (result2 !== null) {
  12538. result0 = [result0, result1, result2];
  12539. } else {
  12540. result0 = null;
  12541. pos = pos1;
  12542. }
  12543. } else {
  12544. result0 = null;
  12545. pos = pos1;
  12546. }
  12547. } else {
  12548. result0 = null;
  12549. pos = pos1;
  12550. }
  12551. if (result0 !== null) {
  12552. result0 = function (offset, s_e_refresher_value) {
  12553. data.refresher = s_e_refresher_value.toLowerCase();
  12554. }(pos0, result0[2]);
  12555. }
  12556. if (result0 === null) {
  12557. pos = pos0;
  12558. }
  12559. return result0;
  12560. }
  12561. function parse_extension_header() {
  12562. var result0, result1, result2;
  12563. var pos0;
  12564. pos0 = pos;
  12565. result0 = parse_token();
  12566. if (result0 !== null) {
  12567. result1 = parse_HCOLON();
  12568. if (result1 !== null) {
  12569. result2 = parse_header_value();
  12570. if (result2 !== null) {
  12571. result0 = [result0, result1, result2];
  12572. } else {
  12573. result0 = null;
  12574. pos = pos0;
  12575. }
  12576. } else {
  12577. result0 = null;
  12578. pos = pos0;
  12579. }
  12580. } else {
  12581. result0 = null;
  12582. pos = pos0;
  12583. }
  12584. return result0;
  12585. }
  12586. function parse_header_value() {
  12587. var result0, result1;
  12588. result0 = [];
  12589. result1 = parse_TEXT_UTF8char();
  12590. if (result1 === null) {
  12591. result1 = parse_UTF8_CONT();
  12592. if (result1 === null) {
  12593. result1 = parse_LWS();
  12594. }
  12595. }
  12596. while (result1 !== null) {
  12597. result0.push(result1);
  12598. result1 = parse_TEXT_UTF8char();
  12599. if (result1 === null) {
  12600. result1 = parse_UTF8_CONT();
  12601. if (result1 === null) {
  12602. result1 = parse_LWS();
  12603. }
  12604. }
  12605. }
  12606. return result0;
  12607. }
  12608. function parse_message_body() {
  12609. var result0, result1;
  12610. result0 = [];
  12611. result1 = parse_OCTET();
  12612. while (result1 !== null) {
  12613. result0.push(result1);
  12614. result1 = parse_OCTET();
  12615. }
  12616. return result0;
  12617. }
  12618. function parse_uuid_URI() {
  12619. var result0, result1;
  12620. var pos0;
  12621. pos0 = pos;
  12622. if (input.substr(pos, 5) === "uuid:") {
  12623. result0 = "uuid:";
  12624. pos += 5;
  12625. } else {
  12626. result0 = null;
  12627. if (reportFailures === 0) {
  12628. matchFailed("\"uuid:\"");
  12629. }
  12630. }
  12631. if (result0 !== null) {
  12632. result1 = parse_uuid();
  12633. if (result1 !== null) {
  12634. result0 = [result0, result1];
  12635. } else {
  12636. result0 = null;
  12637. pos = pos0;
  12638. }
  12639. } else {
  12640. result0 = null;
  12641. pos = pos0;
  12642. }
  12643. return result0;
  12644. }
  12645. function parse_uuid() {
  12646. var result0, result1, result2, result3, result4, result5, result6, result7, result8;
  12647. var pos0, pos1;
  12648. pos0 = pos;
  12649. pos1 = pos;
  12650. result0 = parse_hex8();
  12651. if (result0 !== null) {
  12652. if (input.charCodeAt(pos) === 45) {
  12653. result1 = "-";
  12654. pos++;
  12655. } else {
  12656. result1 = null;
  12657. if (reportFailures === 0) {
  12658. matchFailed("\"-\"");
  12659. }
  12660. }
  12661. if (result1 !== null) {
  12662. result2 = parse_hex4();
  12663. if (result2 !== null) {
  12664. if (input.charCodeAt(pos) === 45) {
  12665. result3 = "-";
  12666. pos++;
  12667. } else {
  12668. result3 = null;
  12669. if (reportFailures === 0) {
  12670. matchFailed("\"-\"");
  12671. }
  12672. }
  12673. if (result3 !== null) {
  12674. result4 = parse_hex4();
  12675. if (result4 !== null) {
  12676. if (input.charCodeAt(pos) === 45) {
  12677. result5 = "-";
  12678. pos++;
  12679. } else {
  12680. result5 = null;
  12681. if (reportFailures === 0) {
  12682. matchFailed("\"-\"");
  12683. }
  12684. }
  12685. if (result5 !== null) {
  12686. result6 = parse_hex4();
  12687. if (result6 !== null) {
  12688. if (input.charCodeAt(pos) === 45) {
  12689. result7 = "-";
  12690. pos++;
  12691. } else {
  12692. result7 = null;
  12693. if (reportFailures === 0) {
  12694. matchFailed("\"-\"");
  12695. }
  12696. }
  12697. if (result7 !== null) {
  12698. result8 = parse_hex12();
  12699. if (result8 !== null) {
  12700. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  12701. } else {
  12702. result0 = null;
  12703. pos = pos1;
  12704. }
  12705. } else {
  12706. result0 = null;
  12707. pos = pos1;
  12708. }
  12709. } else {
  12710. result0 = null;
  12711. pos = pos1;
  12712. }
  12713. } else {
  12714. result0 = null;
  12715. pos = pos1;
  12716. }
  12717. } else {
  12718. result0 = null;
  12719. pos = pos1;
  12720. }
  12721. } else {
  12722. result0 = null;
  12723. pos = pos1;
  12724. }
  12725. } else {
  12726. result0 = null;
  12727. pos = pos1;
  12728. }
  12729. } else {
  12730. result0 = null;
  12731. pos = pos1;
  12732. }
  12733. } else {
  12734. result0 = null;
  12735. pos = pos1;
  12736. }
  12737. if (result0 !== null) {
  12738. result0 = function (offset, uuid) {
  12739. data = input.substring(pos + 5, offset);
  12740. }(pos0, result0[0]);
  12741. }
  12742. if (result0 === null) {
  12743. pos = pos0;
  12744. }
  12745. return result0;
  12746. }
  12747. function parse_hex4() {
  12748. var result0, result1, result2, result3;
  12749. var pos0;
  12750. pos0 = pos;
  12751. result0 = parse_HEXDIG();
  12752. if (result0 !== null) {
  12753. result1 = parse_HEXDIG();
  12754. if (result1 !== null) {
  12755. result2 = parse_HEXDIG();
  12756. if (result2 !== null) {
  12757. result3 = parse_HEXDIG();
  12758. if (result3 !== null) {
  12759. result0 = [result0, result1, result2, result3];
  12760. } else {
  12761. result0 = null;
  12762. pos = pos0;
  12763. }
  12764. } else {
  12765. result0 = null;
  12766. pos = pos0;
  12767. }
  12768. } else {
  12769. result0 = null;
  12770. pos = pos0;
  12771. }
  12772. } else {
  12773. result0 = null;
  12774. pos = pos0;
  12775. }
  12776. return result0;
  12777. }
  12778. function parse_hex8() {
  12779. var result0, result1;
  12780. var pos0;
  12781. pos0 = pos;
  12782. result0 = parse_hex4();
  12783. if (result0 !== null) {
  12784. result1 = parse_hex4();
  12785. if (result1 !== null) {
  12786. result0 = [result0, result1];
  12787. } else {
  12788. result0 = null;
  12789. pos = pos0;
  12790. }
  12791. } else {
  12792. result0 = null;
  12793. pos = pos0;
  12794. }
  12795. return result0;
  12796. }
  12797. function parse_hex12() {
  12798. var result0, result1, result2;
  12799. var pos0;
  12800. pos0 = pos;
  12801. result0 = parse_hex4();
  12802. if (result0 !== null) {
  12803. result1 = parse_hex4();
  12804. if (result1 !== null) {
  12805. result2 = parse_hex4();
  12806. if (result2 !== null) {
  12807. result0 = [result0, result1, result2];
  12808. } else {
  12809. result0 = null;
  12810. pos = pos0;
  12811. }
  12812. } else {
  12813. result0 = null;
  12814. pos = pos0;
  12815. }
  12816. } else {
  12817. result0 = null;
  12818. pos = pos0;
  12819. }
  12820. return result0;
  12821. }
  12822. function parse_Refer_To() {
  12823. var result0, result1, result2, result3;
  12824. var pos0, pos1, pos2;
  12825. pos0 = pos;
  12826. pos1 = pos;
  12827. result0 = parse_SIP_URI_noparams();
  12828. if (result0 === null) {
  12829. result0 = parse_name_addr();
  12830. }
  12831. if (result0 !== null) {
  12832. result1 = [];
  12833. pos2 = pos;
  12834. result2 = parse_SEMI();
  12835. if (result2 !== null) {
  12836. result3 = parse_generic_param();
  12837. if (result3 !== null) {
  12838. result2 = [result2, result3];
  12839. } else {
  12840. result2 = null;
  12841. pos = pos2;
  12842. }
  12843. } else {
  12844. result2 = null;
  12845. pos = pos2;
  12846. }
  12847. while (result2 !== null) {
  12848. result1.push(result2);
  12849. pos2 = pos;
  12850. result2 = parse_SEMI();
  12851. if (result2 !== null) {
  12852. result3 = parse_generic_param();
  12853. if (result3 !== null) {
  12854. result2 = [result2, result3];
  12855. } else {
  12856. result2 = null;
  12857. pos = pos2;
  12858. }
  12859. } else {
  12860. result2 = null;
  12861. pos = pos2;
  12862. }
  12863. }
  12864. if (result1 !== null) {
  12865. result0 = [result0, result1];
  12866. } else {
  12867. result0 = null;
  12868. pos = pos1;
  12869. }
  12870. } else {
  12871. result0 = null;
  12872. pos = pos1;
  12873. }
  12874. if (result0 !== null) {
  12875. result0 = function (offset) {
  12876. try {
  12877. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  12878. } catch (e) {
  12879. data = -1;
  12880. }
  12881. }(pos0);
  12882. }
  12883. if (result0 === null) {
  12884. pos = pos0;
  12885. }
  12886. return result0;
  12887. }
  12888. function parse_Replaces() {
  12889. var result0, result1, result2, result3;
  12890. var pos0, pos1;
  12891. pos0 = pos;
  12892. result0 = parse_call_id();
  12893. if (result0 !== null) {
  12894. result1 = [];
  12895. pos1 = pos;
  12896. result2 = parse_SEMI();
  12897. if (result2 !== null) {
  12898. result3 = parse_replaces_param();
  12899. if (result3 !== null) {
  12900. result2 = [result2, result3];
  12901. } else {
  12902. result2 = null;
  12903. pos = pos1;
  12904. }
  12905. } else {
  12906. result2 = null;
  12907. pos = pos1;
  12908. }
  12909. while (result2 !== null) {
  12910. result1.push(result2);
  12911. pos1 = pos;
  12912. result2 = parse_SEMI();
  12913. if (result2 !== null) {
  12914. result3 = parse_replaces_param();
  12915. if (result3 !== null) {
  12916. result2 = [result2, result3];
  12917. } else {
  12918. result2 = null;
  12919. pos = pos1;
  12920. }
  12921. } else {
  12922. result2 = null;
  12923. pos = pos1;
  12924. }
  12925. }
  12926. if (result1 !== null) {
  12927. result0 = [result0, result1];
  12928. } else {
  12929. result0 = null;
  12930. pos = pos0;
  12931. }
  12932. } else {
  12933. result0 = null;
  12934. pos = pos0;
  12935. }
  12936. return result0;
  12937. }
  12938. function parse_call_id() {
  12939. var result0, result1, result2;
  12940. var pos0, pos1, pos2;
  12941. pos0 = pos;
  12942. pos1 = pos;
  12943. result0 = parse_word();
  12944. if (result0 !== null) {
  12945. pos2 = pos;
  12946. if (input.charCodeAt(pos) === 64) {
  12947. result1 = "@";
  12948. pos++;
  12949. } else {
  12950. result1 = null;
  12951. if (reportFailures === 0) {
  12952. matchFailed("\"@\"");
  12953. }
  12954. }
  12955. if (result1 !== null) {
  12956. result2 = parse_word();
  12957. if (result2 !== null) {
  12958. result1 = [result1, result2];
  12959. } else {
  12960. result1 = null;
  12961. pos = pos2;
  12962. }
  12963. } else {
  12964. result1 = null;
  12965. pos = pos2;
  12966. }
  12967. result1 = result1 !== null ? result1 : "";
  12968. if (result1 !== null) {
  12969. result0 = [result0, result1];
  12970. } else {
  12971. result0 = null;
  12972. pos = pos1;
  12973. }
  12974. } else {
  12975. result0 = null;
  12976. pos = pos1;
  12977. }
  12978. if (result0 !== null) {
  12979. result0 = function (offset) {
  12980. data.call_id = input.substring(pos, offset);
  12981. }(pos0);
  12982. }
  12983. if (result0 === null) {
  12984. pos = pos0;
  12985. }
  12986. return result0;
  12987. }
  12988. function parse_replaces_param() {
  12989. var result0;
  12990. result0 = parse_to_tag();
  12991. if (result0 === null) {
  12992. result0 = parse_from_tag();
  12993. if (result0 === null) {
  12994. result0 = parse_early_flag();
  12995. if (result0 === null) {
  12996. result0 = parse_generic_param();
  12997. }
  12998. }
  12999. }
  13000. return result0;
  13001. }
  13002. function parse_to_tag() {
  13003. var result0, result1, result2;
  13004. var pos0, pos1;
  13005. pos0 = pos;
  13006. pos1 = pos;
  13007. if (input.substr(pos, 6) === "to-tag") {
  13008. result0 = "to-tag";
  13009. pos += 6;
  13010. } else {
  13011. result0 = null;
  13012. if (reportFailures === 0) {
  13013. matchFailed("\"to-tag\"");
  13014. }
  13015. }
  13016. if (result0 !== null) {
  13017. result1 = parse_EQUAL();
  13018. if (result1 !== null) {
  13019. result2 = parse_token();
  13020. if (result2 !== null) {
  13021. result0 = [result0, result1, result2];
  13022. } else {
  13023. result0 = null;
  13024. pos = pos1;
  13025. }
  13026. } else {
  13027. result0 = null;
  13028. pos = pos1;
  13029. }
  13030. } else {
  13031. result0 = null;
  13032. pos = pos1;
  13033. }
  13034. if (result0 !== null) {
  13035. result0 = function (offset, to_tag) {
  13036. data.to_tag = to_tag;
  13037. }(pos0, result0[2]);
  13038. }
  13039. if (result0 === null) {
  13040. pos = pos0;
  13041. }
  13042. return result0;
  13043. }
  13044. function parse_from_tag() {
  13045. var result0, result1, result2;
  13046. var pos0, pos1;
  13047. pos0 = pos;
  13048. pos1 = pos;
  13049. if (input.substr(pos, 8) === "from-tag") {
  13050. result0 = "from-tag";
  13051. pos += 8;
  13052. } else {
  13053. result0 = null;
  13054. if (reportFailures === 0) {
  13055. matchFailed("\"from-tag\"");
  13056. }
  13057. }
  13058. if (result0 !== null) {
  13059. result1 = parse_EQUAL();
  13060. if (result1 !== null) {
  13061. result2 = parse_token();
  13062. if (result2 !== null) {
  13063. result0 = [result0, result1, result2];
  13064. } else {
  13065. result0 = null;
  13066. pos = pos1;
  13067. }
  13068. } else {
  13069. result0 = null;
  13070. pos = pos1;
  13071. }
  13072. } else {
  13073. result0 = null;
  13074. pos = pos1;
  13075. }
  13076. if (result0 !== null) {
  13077. result0 = function (offset, from_tag) {
  13078. data.from_tag = from_tag;
  13079. }(pos0, result0[2]);
  13080. }
  13081. if (result0 === null) {
  13082. pos = pos0;
  13083. }
  13084. return result0;
  13085. }
  13086. function parse_early_flag() {
  13087. var result0;
  13088. var pos0;
  13089. pos0 = pos;
  13090. if (input.substr(pos, 10) === "early-only") {
  13091. result0 = "early-only";
  13092. pos += 10;
  13093. } else {
  13094. result0 = null;
  13095. if (reportFailures === 0) {
  13096. matchFailed("\"early-only\"");
  13097. }
  13098. }
  13099. if (result0 !== null) {
  13100. result0 = function (offset) {
  13101. data.early_only = true;
  13102. }(pos0);
  13103. }
  13104. if (result0 === null) {
  13105. pos = pos0;
  13106. }
  13107. return result0;
  13108. }
  13109. function cleanupExpected(expected) {
  13110. expected.sort();
  13111. var lastExpected = null;
  13112. var cleanExpected = [];
  13113. for (var i = 0; i < expected.length; i++) {
  13114. if (expected[i] !== lastExpected) {
  13115. cleanExpected.push(expected[i]);
  13116. lastExpected = expected[i];
  13117. }
  13118. }
  13119. return cleanExpected;
  13120. }
  13121. function computeErrorPosition() {
  13122. /*
  13123. * The first idea was to use |String.split| to break the input up to the
  13124. * error position along newlines and derive the line and column from
  13125. * there. However IE's |split| implementation is so broken that it was
  13126. * enough to prevent it.
  13127. */
  13128. var line = 1;
  13129. var column = 1;
  13130. var seenCR = false;
  13131. for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
  13132. var ch = input.charAt(i);
  13133. if (ch === "\n") {
  13134. if (!seenCR) {
  13135. line++;
  13136. }
  13137. column = 1;
  13138. seenCR = false;
  13139. } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
  13140. line++;
  13141. column = 1;
  13142. seenCR = true;
  13143. } else {
  13144. column++;
  13145. seenCR = false;
  13146. }
  13147. }
  13148. return {
  13149. line: line,
  13150. column: column
  13151. };
  13152. }
  13153. var URI = __webpack_require__(8);
  13154. var NameAddrHeader = __webpack_require__(11);
  13155. var data = {};
  13156. var result = parseFunctions[startRule]();
  13157. /*
  13158. * The parser is now in one of the following three states:
  13159. *
  13160. * 1. The parser successfully parsed the whole input.
  13161. *
  13162. * - |result !== null|
  13163. * - |pos === input.length|
  13164. * - |rightmostFailuresExpected| may or may not contain something
  13165. *
  13166. * 2. The parser successfully parsed only a part of the input.
  13167. *
  13168. * - |result !== null|
  13169. * - |pos < input.length|
  13170. * - |rightmostFailuresExpected| may or may not contain something
  13171. *
  13172. * 3. The parser did not successfully parse any part of the input.
  13173. *
  13174. * - |result === null|
  13175. * - |pos === 0|
  13176. * - |rightmostFailuresExpected| contains at least one failure
  13177. *
  13178. * All code following this comment (including called functions) must
  13179. * handle these states.
  13180. */
  13181. if (result === null || pos !== input.length) {
  13182. var offset = Math.max(pos, rightmostFailuresPos);
  13183. var found = offset < input.length ? input.charAt(offset) : null;
  13184. var errorPosition = computeErrorPosition();
  13185. new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
  13186. return -1;
  13187. }
  13188. return data;
  13189. },
  13190. /* Returns the parser source code. */
  13191. toSource: function toSource() {
  13192. return this._source;
  13193. }
  13194. };
  13195. /* Thrown when a parser encounters a syntax error. */
  13196. result.SyntaxError = function (expected, found, offset, line, column) {
  13197. function buildMessage(expected, found) {
  13198. var expectedHumanized, foundHumanized;
  13199. switch (expected.length) {
  13200. case 0:
  13201. expectedHumanized = "end of input";
  13202. break;
  13203. case 1:
  13204. expectedHumanized = expected[0];
  13205. break;
  13206. default:
  13207. expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
  13208. }
  13209. foundHumanized = found ? quote(found) : "end of input";
  13210. return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
  13211. }
  13212. this.name = "SyntaxError";
  13213. this.expected = expected;
  13214. this.found = found;
  13215. this.message = buildMessage(expected, found);
  13216. this.offset = offset;
  13217. this.line = line;
  13218. this.column = column;
  13219. };
  13220. result.SyntaxError.prototype = Error.prototype;
  13221. return result;
  13222. }();
  13223. }),
  13224. /* 4 */
  13225. (function(module, __webpack_exports__, __webpack_require__) {
  13226. "use strict";
  13227. /* harmony export (immutable) */ __webpack_exports__["e"] = extractVersion;
  13228. /* harmony export (immutable) */ __webpack_exports__["g"] = wrapPeerConnectionEvent;
  13229. /* harmony export (immutable) */ __webpack_exports__["c"] = disableLog;
  13230. /* harmony export (immutable) */ __webpack_exports__["d"] = disableWarnings;
  13231. /* harmony export (immutable) */ __webpack_exports__["f"] = log;
  13232. /* harmony export (immutable) */ __webpack_exports__["a"] = deprecated;
  13233. /* harmony export (immutable) */ __webpack_exports__["b"] = detectBrowser;
  13234. /*
  13235. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  13236. *
  13237. * Use of this source code is governed by a BSD-style license
  13238. * that can be found in the LICENSE file in the root of the source
  13239. * tree.
  13240. */
  13241. /* eslint-env node */
  13242. let logDisabled_ = true;
  13243. let deprecationWarnings_ = true;
  13244. /**
  13245. * Extract browser version out of the provided user agent string.
  13246. *
  13247. * @param {!string} uastring userAgent string.
  13248. * @param {!string} expr Regular expression used as match criteria.
  13249. * @param {!number} pos position in the version string to be returned.
  13250. * @return {!number} browser version.
  13251. */
  13252. function extractVersion(uastring, expr, pos) {
  13253. const match = uastring.match(expr);
  13254. return match && match.length >= pos && parseInt(match[pos], 10);
  13255. } // Wraps the peerconnection event eventNameToWrap in a function
  13256. // which returns the modified event object (or false to prevent
  13257. // the event).
  13258. function wrapPeerConnectionEvent(window, eventNameToWrap, wrapper) {
  13259. if (!window.RTCPeerConnection) {
  13260. return;
  13261. }
  13262. const proto = window.RTCPeerConnection.prototype;
  13263. const nativeAddEventListener = proto.addEventListener;
  13264. proto.addEventListener = function (nativeEventName, cb) {
  13265. if (nativeEventName !== eventNameToWrap) {
  13266. return nativeAddEventListener.apply(this, arguments);
  13267. }
  13268. const wrappedCallback = e => {
  13269. const modifiedEvent = wrapper(e);
  13270. if (modifiedEvent) {
  13271. cb(modifiedEvent);
  13272. }
  13273. };
  13274. this._eventMap = this._eventMap || {};
  13275. this._eventMap[cb] = wrappedCallback;
  13276. return nativeAddEventListener.apply(this, [nativeEventName, wrappedCallback]);
  13277. };
  13278. const nativeRemoveEventListener = proto.removeEventListener;
  13279. proto.removeEventListener = function (nativeEventName, cb) {
  13280. if (nativeEventName !== eventNameToWrap || !this._eventMap || !this._eventMap[cb]) {
  13281. return nativeRemoveEventListener.apply(this, arguments);
  13282. }
  13283. const unwrappedCb = this._eventMap[cb];
  13284. delete this._eventMap[cb];
  13285. return nativeRemoveEventListener.apply(this, [nativeEventName, unwrappedCb]);
  13286. };
  13287. Object.defineProperty(proto, 'on' + eventNameToWrap, {
  13288. get() {
  13289. return this['_on' + eventNameToWrap];
  13290. },
  13291. set(cb) {
  13292. if (this['_on' + eventNameToWrap]) {
  13293. this.removeEventListener(eventNameToWrap, this['_on' + eventNameToWrap]);
  13294. delete this['_on' + eventNameToWrap];
  13295. }
  13296. if (cb) {
  13297. this.addEventListener(eventNameToWrap, this['_on' + eventNameToWrap] = cb);
  13298. }
  13299. },
  13300. enumerable: true,
  13301. configurable: true
  13302. });
  13303. }
  13304. function disableLog(bool) {
  13305. if (typeof bool !== 'boolean') {
  13306. return new Error('Argument type: ' + typeof bool + '. Please use a boolean.');
  13307. }
  13308. logDisabled_ = bool;
  13309. return bool ? 'adapter.js logging disabled' : 'adapter.js logging enabled';
  13310. }
  13311. /**
  13312. * Disable or enable deprecation warnings
  13313. * @param {!boolean} bool set to true to disable warnings.
  13314. */
  13315. function disableWarnings(bool) {
  13316. if (typeof bool !== 'boolean') {
  13317. return new Error('Argument type: ' + typeof bool + '. Please use a boolean.');
  13318. }
  13319. deprecationWarnings_ = !bool;
  13320. return 'adapter.js deprecation warnings ' + (bool ? 'disabled' : 'enabled');
  13321. }
  13322. function log() {
  13323. if (typeof window === 'object') {
  13324. if (logDisabled_) {
  13325. return;
  13326. }
  13327. if (typeof console !== 'undefined' && typeof console.log === 'function') {
  13328. console.log.apply(console, arguments);
  13329. }
  13330. }
  13331. }
  13332. /**
  13333. * Shows a deprecation warning suggesting the modern and spec-compatible API.
  13334. */
  13335. function deprecated(oldMethod, newMethod) {
  13336. if (!deprecationWarnings_) {
  13337. return;
  13338. }
  13339. console.warn(oldMethod + ' is deprecated, please use ' + newMethod + ' instead.');
  13340. }
  13341. /**
  13342. * Browser detector.
  13343. *
  13344. * @return {object} result containing browser and version
  13345. * properties.
  13346. */
  13347. function detectBrowser(window) {
  13348. const {
  13349. navigator
  13350. } = window; // Returned result object.
  13351. const result = {
  13352. browser: null,
  13353. version: null
  13354. }; // Fail early if it's not a browser
  13355. if (typeof window === 'undefined' || !window.navigator) {
  13356. result.browser = 'Not a browser.';
  13357. return result;
  13358. }
  13359. if (navigator.mozGetUserMedia) {
  13360. // Firefox.
  13361. result.browser = 'firefox';
  13362. result.version = extractVersion(navigator.userAgent, /Firefox\/(\d+)\./, 1);
  13363. } else if (navigator.webkitGetUserMedia) {
  13364. // Chrome, Chromium, Webview, Opera.
  13365. // Version matches Chrome/WebRTC version.
  13366. result.browser = 'chrome';
  13367. result.version = extractVersion(navigator.userAgent, /Chrom(e|ium)\/(\d+)\./, 2);
  13368. } else if (navigator.mediaDevices && navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) {
  13369. // Edge.
  13370. result.browser = 'edge';
  13371. result.version = extractVersion(navigator.userAgent, /Edge\/(\d+).(\d+)$/, 2);
  13372. } else if (window.RTCPeerConnection && navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) {
  13373. // Safari.
  13374. result.browser = 'safari';
  13375. result.version = extractVersion(navigator.userAgent, /AppleWebKit\/(\d+)\./, 1);
  13376. } else {
  13377. // Default fallthrough: not supported.
  13378. result.browser = 'Not a supported browser.';
  13379. return result;
  13380. }
  13381. return result;
  13382. }
  13383. }),
  13384. /* 5 */
  13385. (function(module, exports, __webpack_require__) {
  13386. "use strict";
  13387. function _typeof(obj) {
  13388. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  13389. _typeof = function _typeof(obj) {
  13390. return typeof obj;
  13391. };
  13392. } else {
  13393. _typeof = function _typeof(obj) {
  13394. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  13395. };
  13396. }
  13397. return _typeof(obj);
  13398. }
  13399. function _possibleConstructorReturn(self, call) {
  13400. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  13401. return call;
  13402. }
  13403. return _assertThisInitialized(self);
  13404. }
  13405. function _assertThisInitialized(self) {
  13406. if (self === void 0) {
  13407. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  13408. }
  13409. return self;
  13410. }
  13411. function _getPrototypeOf(o) {
  13412. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  13413. return o.__proto__ || Object.getPrototypeOf(o);
  13414. };
  13415. return _getPrototypeOf(o);
  13416. }
  13417. function _inherits(subClass, superClass) {
  13418. if (typeof superClass !== "function" && superClass !== null) {
  13419. throw new TypeError("Super expression must either be null or a function");
  13420. }
  13421. subClass.prototype = Object.create(superClass && superClass.prototype, {
  13422. constructor: {
  13423. value: subClass,
  13424. writable: true,
  13425. configurable: true
  13426. }
  13427. });
  13428. if (superClass) _setPrototypeOf(subClass, superClass);
  13429. }
  13430. function _setPrototypeOf(o, p) {
  13431. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  13432. o.__proto__ = p;
  13433. return o;
  13434. };
  13435. return _setPrototypeOf(o, p);
  13436. }
  13437. function _classCallCheck(instance, Constructor) {
  13438. if (!(instance instanceof Constructor)) {
  13439. throw new TypeError("Cannot call a class as a function");
  13440. }
  13441. }
  13442. function _defineProperties(target, props) {
  13443. for (var i = 0; i < props.length; i++) {
  13444. var descriptor = props[i];
  13445. descriptor.enumerable = descriptor.enumerable || false;
  13446. descriptor.configurable = true;
  13447. if ("value" in descriptor) descriptor.writable = true;
  13448. Object.defineProperty(target, descriptor.key, descriptor);
  13449. }
  13450. }
  13451. function _createClass(Constructor, protoProps, staticProps) {
  13452. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  13453. if (staticProps) _defineProperties(Constructor, staticProps);
  13454. return Constructor;
  13455. }
  13456. var sdp_transform = __webpack_require__(13);
  13457. var JsSIP_C = __webpack_require__(1);
  13458. var Utils = __webpack_require__(2);
  13459. var NameAddrHeader = __webpack_require__(11);
  13460. var Grammar = __webpack_require__(3);
  13461. var debug = __webpack_require__(0)('JsSIP:SIPMessage');
  13462. /**
  13463. * -param {String} method request method
  13464. * -param {String} ruri request uri
  13465. * -param {UA} ua
  13466. * -param {Object} params parameters that will have priority over ua.configuration parameters:
  13467. * <br>
  13468. * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set
  13469. * -param {Object} [headers] extra headers
  13470. * -param {String} [body]
  13471. */
  13472. var OutgoingRequest =
  13473. /*#__PURE__*/
  13474. function () {
  13475. function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) {
  13476. _classCallCheck(this, OutgoingRequest); // Mandatory parameters check.
  13477. if (!method || !ruri || !ua) {
  13478. return null;
  13479. }
  13480. params = params || {};
  13481. this.ua = ua;
  13482. this.headers = {};
  13483. this.method = method;
  13484. this.ruri = ruri;
  13485. this.body = body;
  13486. this.extraHeaders = Utils.cloneArray(extraHeaders); // Fill the Common SIP Request Headers.
  13487. // Route.
  13488. if (params.route_set) {
  13489. this.setHeader('route', params.route_set);
  13490. } else if (ua.configuration.use_preloaded_route) {
  13491. this.setHeader('route', "<".concat(ua.transport.sip_uri, ";lr>"));
  13492. } // Via.
  13493. // Empty Via header. Will be filled by the client transaction.
  13494. this.setHeader('via', ''); // Max-Forwards.
  13495. this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS); // To
  13496. var to = params.to_display_name || params.to_display_name === 0 ? "\"".concat(params.to_display_name, "\" ") : '';
  13497. to += "<".concat(params.to_uri || ruri, ">");
  13498. to += params.to_tag ? ";tag=".concat(params.to_tag) : '';
  13499. this.to = NameAddrHeader.parse(to);
  13500. this.setHeader('to', to); // From.
  13501. var from;
  13502. if (params.from_display_name || params.from_display_name === 0) {
  13503. from = "\"".concat(params.from_display_name, "\" ");
  13504. } else if (ua.configuration.display_name) {
  13505. from = "\"".concat(ua.configuration.display_name, "\" ");
  13506. } else {
  13507. from = '';
  13508. }
  13509. from += "<".concat(params.from_uri || ua.configuration.uri, ">;tag=");
  13510. from += params.from_tag || Utils.newTag();
  13511. this.from = NameAddrHeader.parse(from);
  13512. this.setHeader('from', from); // Call-ID.
  13513. var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15);
  13514. this.call_id = call_id;
  13515. this.setHeader('call-id', call_id); // CSeq.
  13516. var cseq = params.cseq || Math.floor(Math.random() * 10000);
  13517. this.cseq = cseq;
  13518. this.setHeader('cseq', "".concat(cseq, " ").concat(method));
  13519. }
  13520. /**
  13521. * Replace the the given header by the given value.
  13522. * -param {String} name header name
  13523. * -param {String | Array} value header value
  13524. */
  13525. _createClass(OutgoingRequest, [{
  13526. key: "setHeader",
  13527. value: function setHeader(name, value) {
  13528. // Remove the header from extraHeaders if present.
  13529. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  13530. for (var idx = 0; idx < this.extraHeaders.length; idx++) {
  13531. if (regexp.test(this.extraHeaders[idx])) {
  13532. this.extraHeaders.splice(idx, 1);
  13533. }
  13534. }
  13535. this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
  13536. }
  13537. /**
  13538. * Get the value of the given header name at the given position.
  13539. * -param {String} name header name
  13540. * -returns {String|undefined} Returns the specified header, null if header doesn't exist.
  13541. */
  13542. }, {
  13543. key: "getHeader",
  13544. value: function getHeader(name) {
  13545. var headers = this.headers[Utils.headerize(name)];
  13546. if (headers) {
  13547. if (headers[0]) {
  13548. return headers[0];
  13549. }
  13550. } else {
  13551. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  13552. var _iteratorNormalCompletion = true;
  13553. var _didIteratorError = false;
  13554. var _iteratorError = undefined;
  13555. try {
  13556. for (var _iterator = this.extraHeaders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  13557. var header = _step.value;
  13558. if (regexp.test(header)) {
  13559. return header.substring(header.indexOf(':') + 1).trim();
  13560. }
  13561. }
  13562. } catch (err) {
  13563. _didIteratorError = true;
  13564. _iteratorError = err;
  13565. } finally {
  13566. try {
  13567. if (!_iteratorNormalCompletion && _iterator.return != null) {
  13568. _iterator.return();
  13569. }
  13570. } finally {
  13571. if (_didIteratorError) {
  13572. throw _iteratorError;
  13573. }
  13574. }
  13575. }
  13576. }
  13577. return;
  13578. }
  13579. /**
  13580. * Get the header/s of the given name.
  13581. * -param {String} name header name
  13582. * -returns {Array} Array with all the headers of the specified name.
  13583. */
  13584. }, {
  13585. key: "getHeaders",
  13586. value: function getHeaders(name) {
  13587. var headers = this.headers[Utils.headerize(name)];
  13588. var result = [];
  13589. if (headers) {
  13590. var _iteratorNormalCompletion2 = true;
  13591. var _didIteratorError2 = false;
  13592. var _iteratorError2 = undefined;
  13593. try {
  13594. for (var _iterator2 = headers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  13595. var header = _step2.value;
  13596. result.push(header);
  13597. }
  13598. } catch (err) {
  13599. _didIteratorError2 = true;
  13600. _iteratorError2 = err;
  13601. } finally {
  13602. try {
  13603. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  13604. _iterator2.return();
  13605. }
  13606. } finally {
  13607. if (_didIteratorError2) {
  13608. throw _iteratorError2;
  13609. }
  13610. }
  13611. }
  13612. return result;
  13613. } else {
  13614. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  13615. var _iteratorNormalCompletion3 = true;
  13616. var _didIteratorError3 = false;
  13617. var _iteratorError3 = undefined;
  13618. try {
  13619. for (var _iterator3 = this.extraHeaders[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  13620. var _header = _step3.value;
  13621. if (regexp.test(_header)) {
  13622. result.push(_header.substring(_header.indexOf(':') + 1).trim());
  13623. }
  13624. }
  13625. } catch (err) {
  13626. _didIteratorError3 = true;
  13627. _iteratorError3 = err;
  13628. } finally {
  13629. try {
  13630. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  13631. _iterator3.return();
  13632. }
  13633. } finally {
  13634. if (_didIteratorError3) {
  13635. throw _iteratorError3;
  13636. }
  13637. }
  13638. }
  13639. return result;
  13640. }
  13641. }
  13642. /**
  13643. * Verify the existence of the given header.
  13644. * -param {String} name header name
  13645. * -returns {boolean} true if header with given name exists, false otherwise
  13646. */
  13647. }, {
  13648. key: "hasHeader",
  13649. value: function hasHeader(name) {
  13650. if (this.headers[Utils.headerize(name)]) {
  13651. return true;
  13652. } else {
  13653. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  13654. var _iteratorNormalCompletion4 = true;
  13655. var _didIteratorError4 = false;
  13656. var _iteratorError4 = undefined;
  13657. try {
  13658. for (var _iterator4 = this.extraHeaders[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  13659. var header = _step4.value;
  13660. if (regexp.test(header)) {
  13661. return true;
  13662. }
  13663. }
  13664. } catch (err) {
  13665. _didIteratorError4 = true;
  13666. _iteratorError4 = err;
  13667. } finally {
  13668. try {
  13669. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  13670. _iterator4.return();
  13671. }
  13672. } finally {
  13673. if (_didIteratorError4) {
  13674. throw _iteratorError4;
  13675. }
  13676. }
  13677. }
  13678. }
  13679. return false;
  13680. }
  13681. /**
  13682. * Parse the current body as a SDP and store the resulting object
  13683. * into this.sdp.
  13684. * -param {Boolean} force: Parse even if this.sdp already exists.
  13685. *
  13686. * Returns this.sdp.
  13687. */
  13688. }, {
  13689. key: "parseSDP",
  13690. value: function parseSDP(force) {
  13691. if (!force && this.sdp) {
  13692. return this.sdp;
  13693. } else {
  13694. this.sdp = sdp_transform.parse(this.body || '');
  13695. return this.sdp;
  13696. }
  13697. }
  13698. }, {
  13699. key: "toString",
  13700. value: function toString() {
  13701. var msg = "".concat(this.method, " ").concat(this.ruri, " SIP/2.0\r\n");
  13702. for (var headerName in this.headers) {
  13703. if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) {
  13704. var _iteratorNormalCompletion5 = true;
  13705. var _didIteratorError5 = false;
  13706. var _iteratorError5 = undefined;
  13707. try {
  13708. for (var _iterator5 = this.headers[headerName][Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  13709. var headerValue = _step5.value;
  13710. msg += "".concat(headerName, ": ").concat(headerValue, "\r\n");
  13711. }
  13712. } catch (err) {
  13713. _didIteratorError5 = true;
  13714. _iteratorError5 = err;
  13715. } finally {
  13716. try {
  13717. if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
  13718. _iterator5.return();
  13719. }
  13720. } finally {
  13721. if (_didIteratorError5) {
  13722. throw _iteratorError5;
  13723. }
  13724. }
  13725. }
  13726. }
  13727. }
  13728. var _iteratorNormalCompletion6 = true;
  13729. var _didIteratorError6 = false;
  13730. var _iteratorError6 = undefined;
  13731. try {
  13732. for (var _iterator6 = this.extraHeaders[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
  13733. var header = _step6.value;
  13734. msg += "".concat(header.trim(), "\r\n");
  13735. } // Supported.
  13736. } catch (err) {
  13737. _didIteratorError6 = true;
  13738. _iteratorError6 = err;
  13739. } finally {
  13740. try {
  13741. if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
  13742. _iterator6.return();
  13743. }
  13744. } finally {
  13745. if (_didIteratorError6) {
  13746. throw _iteratorError6;
  13747. }
  13748. }
  13749. }
  13750. var supported = [];
  13751. switch (this.method) {
  13752. case JsSIP_C.REGISTER:
  13753. supported.push('path', 'gruu');
  13754. break;
  13755. case JsSIP_C.INVITE:
  13756. if (this.ua.configuration.session_timers) {
  13757. supported.push('timer');
  13758. }
  13759. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  13760. supported.push('gruu');
  13761. }
  13762. supported.push('ice', 'replaces');
  13763. break;
  13764. case JsSIP_C.UPDATE:
  13765. if (this.ua.configuration.session_timers) {
  13766. supported.push('timer');
  13767. }
  13768. supported.push('ice');
  13769. break;
  13770. }
  13771. supported.push('outbound');
  13772. var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT; // Allow.
  13773. msg += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  13774. msg += "Supported: ".concat(supported, "\r\n");
  13775. msg += "User-Agent: ".concat(userAgent, "\r\n");
  13776. if (this.body) {
  13777. var length = Utils.str_utf8_length(this.body);
  13778. msg += "Content-Length: ".concat(length, "\r\n\r\n");
  13779. msg += this.body;
  13780. } else {
  13781. msg += 'Content-Length: 0\r\n\r\n';
  13782. }
  13783. return msg;
  13784. }
  13785. }, {
  13786. key: "clone",
  13787. value: function clone() {
  13788. var request = new OutgoingRequest(this.method, this.ruri, this.ua);
  13789. Object.keys(this.headers).forEach(function (name) {
  13790. request.headers[name] = this.headers[name].slice();
  13791. }, this);
  13792. request.body = this.body;
  13793. request.extraHeaders = Utils.cloneArray(this.extraHeaders);
  13794. request.to = this.to;
  13795. request.from = this.from;
  13796. request.call_id = this.call_id;
  13797. request.cseq = this.cseq;
  13798. return request;
  13799. }
  13800. }]);
  13801. return OutgoingRequest;
  13802. }();
  13803. var InitialOutgoingInviteRequest =
  13804. /*#__PURE__*/
  13805. function (_OutgoingRequest) {
  13806. _inherits(InitialOutgoingInviteRequest, _OutgoingRequest);
  13807. function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) {
  13808. var _this;
  13809. _classCallCheck(this, InitialOutgoingInviteRequest);
  13810. _this = _possibleConstructorReturn(this, _getPrototypeOf(InitialOutgoingInviteRequest).call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body));
  13811. _this.transaction = null;
  13812. return _this;
  13813. }
  13814. _createClass(InitialOutgoingInviteRequest, [{
  13815. key: "cancel",
  13816. value: function cancel(reason) {
  13817. this.transaction.cancel(reason);
  13818. }
  13819. }, {
  13820. key: "clone",
  13821. value: function clone() {
  13822. var request = new InitialOutgoingInviteRequest(this.ruri, this.ua);
  13823. Object.keys(this.headers).forEach(function (name) {
  13824. request.headers[name] = this.headers[name].slice();
  13825. }, this);
  13826. request.body = this.body;
  13827. request.extraHeaders = Utils.cloneArray(this.extraHeaders);
  13828. request.to = this.to;
  13829. request.from = this.from;
  13830. request.call_id = this.call_id;
  13831. request.cseq = this.cseq;
  13832. request.transaction = this.transaction;
  13833. return request;
  13834. }
  13835. }]);
  13836. return InitialOutgoingInviteRequest;
  13837. }(OutgoingRequest);
  13838. var IncomingMessage =
  13839. /*#__PURE__*/
  13840. function () {
  13841. function IncomingMessage() {
  13842. _classCallCheck(this, IncomingMessage);
  13843. this.data = null;
  13844. this.headers = null;
  13845. this.method = null;
  13846. this.via = null;
  13847. this.via_branch = null;
  13848. this.call_id = null;
  13849. this.cseq = null;
  13850. this.from = null;
  13851. this.from_tag = null;
  13852. this.to = null;
  13853. this.to_tag = null;
  13854. this.body = null;
  13855. this.sdp = null;
  13856. }
  13857. /**
  13858. * Insert a header of the given name and value into the last position of the
  13859. * header array.
  13860. */
  13861. _createClass(IncomingMessage, [{
  13862. key: "addHeader",
  13863. value: function addHeader(name, value) {
  13864. var header = {
  13865. raw: value
  13866. };
  13867. name = Utils.headerize(name);
  13868. if (this.headers[name]) {
  13869. this.headers[name].push(header);
  13870. } else {
  13871. this.headers[name] = [header];
  13872. }
  13873. }
  13874. /**
  13875. * Get the value of the given header name at the given position.
  13876. */
  13877. }, {
  13878. key: "getHeader",
  13879. value: function getHeader(name) {
  13880. var header = this.headers[Utils.headerize(name)];
  13881. if (header) {
  13882. if (header[0]) {
  13883. return header[0].raw;
  13884. }
  13885. } else {
  13886. return;
  13887. }
  13888. }
  13889. /**
  13890. * Get the header/s of the given name.
  13891. */
  13892. }, {
  13893. key: "getHeaders",
  13894. value: function getHeaders(name) {
  13895. var headers = this.headers[Utils.headerize(name)];
  13896. var result = [];
  13897. if (!headers) {
  13898. return [];
  13899. }
  13900. var _iteratorNormalCompletion7 = true;
  13901. var _didIteratorError7 = false;
  13902. var _iteratorError7 = undefined;
  13903. try {
  13904. for (var _iterator7 = headers[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
  13905. var header = _step7.value;
  13906. result.push(header.raw);
  13907. }
  13908. } catch (err) {
  13909. _didIteratorError7 = true;
  13910. _iteratorError7 = err;
  13911. } finally {
  13912. try {
  13913. if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
  13914. _iterator7.return();
  13915. }
  13916. } finally {
  13917. if (_didIteratorError7) {
  13918. throw _iteratorError7;
  13919. }
  13920. }
  13921. }
  13922. return result;
  13923. }
  13924. /**
  13925. * Verify the existence of the given header.
  13926. */
  13927. }, {
  13928. key: "hasHeader",
  13929. value: function hasHeader(name) {
  13930. return this.headers[Utils.headerize(name)] ? true : false;
  13931. }
  13932. /**
  13933. * Parse the given header on the given index.
  13934. * -param {String} name header name
  13935. * -param {Number} [idx=0] header index
  13936. * -returns {Object|undefined} Parsed header object, undefined if the header
  13937. * is not present or in case of a parsing error.
  13938. */
  13939. }, {
  13940. key: "parseHeader",
  13941. value: function parseHeader(name) {
  13942. var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  13943. name = Utils.headerize(name);
  13944. if (!this.headers[name]) {
  13945. debug("header \"".concat(name, "\" not present"));
  13946. return;
  13947. } else if (idx >= this.headers[name].length) {
  13948. debug("not so many \"".concat(name, "\" headers present"));
  13949. return;
  13950. }
  13951. var header = this.headers[name][idx];
  13952. var value = header.raw;
  13953. if (header.parsed) {
  13954. return header.parsed;
  13955. } // Substitute '-' by '_' for grammar rule matching.
  13956. var parsed = Grammar.parse(value, name.replace(/-/g, '_'));
  13957. if (parsed === -1) {
  13958. this.headers[name].splice(idx, 1); // delete from headers
  13959. debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\""));
  13960. return;
  13961. } else {
  13962. header.parsed = parsed;
  13963. return parsed;
  13964. }
  13965. }
  13966. /**
  13967. * Message Header attribute selector. Alias of parseHeader.
  13968. * -param {String} name header name
  13969. * -param {Number} [idx=0] header index
  13970. * -returns {Object|undefined} Parsed header object, undefined if the header
  13971. * is not present or in case of a parsing error.
  13972. *
  13973. * -example
  13974. * message.s('via',3).port
  13975. */
  13976. }, {
  13977. key: "s",
  13978. value: function s(name, idx) {
  13979. return this.parseHeader(name, idx);
  13980. }
  13981. /**
  13982. * Replace the value of the given header by the value.
  13983. * -param {String} name header name
  13984. * -param {String} value header value
  13985. */
  13986. }, {
  13987. key: "setHeader",
  13988. value: function setHeader(name, value) {
  13989. var header = {
  13990. raw: value
  13991. };
  13992. this.headers[Utils.headerize(name)] = [header];
  13993. }
  13994. /**
  13995. * Parse the current body as a SDP and store the resulting object
  13996. * into this.sdp.
  13997. * -param {Boolean} force: Parse even if this.sdp already exists.
  13998. *
  13999. * Returns this.sdp.
  14000. */
  14001. }, {
  14002. key: "parseSDP",
  14003. value: function parseSDP(force) {
  14004. if (!force && this.sdp) {
  14005. return this.sdp;
  14006. } else {
  14007. this.sdp = sdp_transform.parse(this.body || '');
  14008. return this.sdp;
  14009. }
  14010. }
  14011. }, {
  14012. key: "toString",
  14013. value: function toString() {
  14014. return this.data;
  14015. }
  14016. }]);
  14017. return IncomingMessage;
  14018. }();
  14019. var IncomingRequest =
  14020. /*#__PURE__*/
  14021. function (_IncomingMessage) {
  14022. _inherits(IncomingRequest, _IncomingMessage);
  14023. function IncomingRequest(ua) {
  14024. var _this2;
  14025. _classCallCheck(this, IncomingRequest);
  14026. _this2 = _possibleConstructorReturn(this, _getPrototypeOf(IncomingRequest).call(this));
  14027. _this2.ua = ua;
  14028. _this2.headers = {};
  14029. _this2.ruri = null;
  14030. _this2.transport = null;
  14031. _this2.server_transaction = null;
  14032. return _this2;
  14033. }
  14034. /**
  14035. * Stateful reply.
  14036. * -param {Number} code status code
  14037. * -param {String} reason reason phrase
  14038. * -param {Object} headers extra headers
  14039. * -param {String} body body
  14040. * -param {Function} [onSuccess] onSuccess callback
  14041. * -param {Function} [onFailure] onFailure callback
  14042. */
  14043. _createClass(IncomingRequest, [{
  14044. key: "reply",
  14045. value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) {
  14046. var supported = [];
  14047. var to = this.getHeader('To');
  14048. code = code || null;
  14049. reason = reason || null; // Validate code and reason values.
  14050. if (!code || code < 100 || code > 699) {
  14051. throw new TypeError("Invalid status_code: ".concat(code));
  14052. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  14053. throw new TypeError("Invalid reason_phrase: ".concat(reason));
  14054. }
  14055. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  14056. extraHeaders = Utils.cloneArray(extraHeaders);
  14057. var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n");
  14058. if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) {
  14059. var headers = this.getHeaders('record-route');
  14060. var _iteratorNormalCompletion8 = true;
  14061. var _didIteratorError8 = false;
  14062. var _iteratorError8 = undefined;
  14063. try {
  14064. for (var _iterator8 = headers[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
  14065. var header = _step8.value;
  14066. response += "Record-Route: ".concat(header, "\r\n");
  14067. }
  14068. } catch (err) {
  14069. _didIteratorError8 = true;
  14070. _iteratorError8 = err;
  14071. } finally {
  14072. try {
  14073. if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
  14074. _iterator8.return();
  14075. }
  14076. } finally {
  14077. if (_didIteratorError8) {
  14078. throw _iteratorError8;
  14079. }
  14080. }
  14081. }
  14082. }
  14083. var vias = this.getHeaders('via');
  14084. var _iteratorNormalCompletion9 = true;
  14085. var _didIteratorError9 = false;
  14086. var _iteratorError9 = undefined;
  14087. try {
  14088. for (var _iterator9 = vias[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
  14089. var via = _step9.value;
  14090. response += "Via: ".concat(via, "\r\n");
  14091. }
  14092. } catch (err) {
  14093. _didIteratorError9 = true;
  14094. _iteratorError9 = err;
  14095. } finally {
  14096. try {
  14097. if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
  14098. _iterator9.return();
  14099. }
  14100. } finally {
  14101. if (_didIteratorError9) {
  14102. throw _iteratorError9;
  14103. }
  14104. }
  14105. }
  14106. if (!this.to_tag && code > 100) {
  14107. to += ";tag=".concat(Utils.newTag());
  14108. } else if (this.to_tag && !this.s('to').hasParam('tag')) {
  14109. to += ";tag=".concat(this.to_tag);
  14110. }
  14111. response += "To: ".concat(to, "\r\n");
  14112. response += "From: ".concat(this.getHeader('From'), "\r\n");
  14113. response += "Call-ID: ".concat(this.call_id, "\r\n");
  14114. response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n");
  14115. var _iteratorNormalCompletion10 = true;
  14116. var _didIteratorError10 = false;
  14117. var _iteratorError10 = undefined;
  14118. try {
  14119. for (var _iterator10 = extraHeaders[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
  14120. var _header2 = _step10.value;
  14121. response += "".concat(_header2.trim(), "\r\n");
  14122. } // Supported.
  14123. } catch (err) {
  14124. _didIteratorError10 = true;
  14125. _iteratorError10 = err;
  14126. } finally {
  14127. try {
  14128. if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
  14129. _iterator10.return();
  14130. }
  14131. } finally {
  14132. if (_didIteratorError10) {
  14133. throw _iteratorError10;
  14134. }
  14135. }
  14136. }
  14137. switch (this.method) {
  14138. case JsSIP_C.INVITE:
  14139. if (this.ua.configuration.session_timers) {
  14140. supported.push('timer');
  14141. }
  14142. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  14143. supported.push('gruu');
  14144. }
  14145. supported.push('ice', 'replaces');
  14146. break;
  14147. case JsSIP_C.UPDATE:
  14148. if (this.ua.configuration.session_timers) {
  14149. supported.push('timer');
  14150. }
  14151. if (body) {
  14152. supported.push('ice');
  14153. }
  14154. supported.push('replaces');
  14155. }
  14156. supported.push('outbound'); // Allow and Accept.
  14157. if (this.method === JsSIP_C.OPTIONS) {
  14158. response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  14159. response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n");
  14160. } else if (code === 405) {
  14161. response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  14162. } else if (code === 415) {
  14163. response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n");
  14164. }
  14165. response += "Supported: ".concat(supported, "\r\n");
  14166. if (body) {
  14167. var length = Utils.str_utf8_length(body);
  14168. response += 'Content-Type: application/sdp\r\n';
  14169. response += "Content-Length: ".concat(length, "\r\n\r\n");
  14170. response += body;
  14171. } else {
  14172. response += "Content-Length: ".concat(0, "\r\n\r\n");
  14173. }
  14174. this.server_transaction.receiveResponse(code, response, onSuccess, onFailure);
  14175. }
  14176. /**
  14177. * Stateless reply.
  14178. * -param {Number} code status code
  14179. * -param {String} reason reason phrase
  14180. */
  14181. }, {
  14182. key: "reply_sl",
  14183. value: function reply_sl() {
  14184. var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  14185. var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  14186. var vias = this.getHeaders('via'); // Validate code and reason values.
  14187. if (!code || code < 100 || code > 699) {
  14188. throw new TypeError("Invalid status_code: ".concat(code));
  14189. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  14190. throw new TypeError("Invalid reason_phrase: ".concat(reason));
  14191. }
  14192. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  14193. var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n");
  14194. var _iteratorNormalCompletion11 = true;
  14195. var _didIteratorError11 = false;
  14196. var _iteratorError11 = undefined;
  14197. try {
  14198. for (var _iterator11 = vias[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
  14199. var via = _step11.value;
  14200. response += "Via: ".concat(via, "\r\n");
  14201. }
  14202. } catch (err) {
  14203. _didIteratorError11 = true;
  14204. _iteratorError11 = err;
  14205. } finally {
  14206. try {
  14207. if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
  14208. _iterator11.return();
  14209. }
  14210. } finally {
  14211. if (_didIteratorError11) {
  14212. throw _iteratorError11;
  14213. }
  14214. }
  14215. }
  14216. var to = this.getHeader('To');
  14217. if (!this.to_tag && code > 100) {
  14218. to += ";tag=".concat(Utils.newTag());
  14219. } else if (this.to_tag && !this.s('to').hasParam('tag')) {
  14220. to += ";tag=".concat(this.to_tag);
  14221. }
  14222. response += "To: ".concat(to, "\r\n");
  14223. response += "From: ".concat(this.getHeader('From'), "\r\n");
  14224. response += "Call-ID: ".concat(this.call_id, "\r\n");
  14225. response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n");
  14226. response += "Content-Length: ".concat(0, "\r\n\r\n");
  14227. this.transport.send(response);
  14228. }
  14229. }]);
  14230. return IncomingRequest;
  14231. }(IncomingMessage);
  14232. var IncomingResponse =
  14233. /*#__PURE__*/
  14234. function (_IncomingMessage2) {
  14235. _inherits(IncomingResponse, _IncomingMessage2);
  14236. function IncomingResponse() {
  14237. var _this3;
  14238. _classCallCheck(this, IncomingResponse);
  14239. _this3 = _possibleConstructorReturn(this, _getPrototypeOf(IncomingResponse).call(this));
  14240. _this3.headers = {};
  14241. _this3.status_code = null;
  14242. _this3.reason_phrase = null;
  14243. return _this3;
  14244. }
  14245. return IncomingResponse;
  14246. }(IncomingMessage);
  14247. module.exports = {
  14248. OutgoingRequest: OutgoingRequest,
  14249. InitialOutgoingInviteRequest: InitialOutgoingInviteRequest,
  14250. IncomingRequest: IncomingRequest,
  14251. IncomingResponse: IncomingResponse
  14252. };
  14253. }),
  14254. /* 6 */
  14255. (function(module, exports, __webpack_require__) {
  14256. "use strict";
  14257. function _typeof(obj) {
  14258. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  14259. _typeof = function _typeof(obj) {
  14260. return typeof obj;
  14261. };
  14262. } else {
  14263. _typeof = function _typeof(obj) {
  14264. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  14265. };
  14266. }
  14267. return _typeof(obj);
  14268. }
  14269. function _classCallCheck(instance, Constructor) {
  14270. if (!(instance instanceof Constructor)) {
  14271. throw new TypeError("Cannot call a class as a function");
  14272. }
  14273. }
  14274. function _possibleConstructorReturn(self, call) {
  14275. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  14276. return call;
  14277. }
  14278. return _assertThisInitialized(self);
  14279. }
  14280. function _assertThisInitialized(self) {
  14281. if (self === void 0) {
  14282. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  14283. }
  14284. return self;
  14285. }
  14286. function _inherits(subClass, superClass) {
  14287. if (typeof superClass !== "function" && superClass !== null) {
  14288. throw new TypeError("Super expression must either be null or a function");
  14289. }
  14290. subClass.prototype = Object.create(superClass && superClass.prototype, {
  14291. constructor: {
  14292. value: subClass,
  14293. writable: true,
  14294. configurable: true
  14295. }
  14296. });
  14297. if (superClass) _setPrototypeOf(subClass, superClass);
  14298. }
  14299. function _wrapNativeSuper(Class) {
  14300. var _cache = typeof Map === "function" ? new Map() : undefined;
  14301. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  14302. if (Class === null || !_isNativeFunction(Class)) return Class;
  14303. if (typeof Class !== "function") {
  14304. throw new TypeError("Super expression must either be null or a function");
  14305. }
  14306. if (typeof _cache !== "undefined") {
  14307. if (_cache.has(Class)) return _cache.get(Class);
  14308. _cache.set(Class, Wrapper);
  14309. }
  14310. function Wrapper() {
  14311. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  14312. }
  14313. Wrapper.prototype = Object.create(Class.prototype, {
  14314. constructor: {
  14315. value: Wrapper,
  14316. enumerable: false,
  14317. writable: true,
  14318. configurable: true
  14319. }
  14320. });
  14321. return _setPrototypeOf(Wrapper, Class);
  14322. };
  14323. return _wrapNativeSuper(Class);
  14324. }
  14325. function isNativeReflectConstruct() {
  14326. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  14327. if (Reflect.construct.sham) return false;
  14328. if (typeof Proxy === "function") return true;
  14329. try {
  14330. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  14331. return true;
  14332. } catch (e) {
  14333. return false;
  14334. }
  14335. }
  14336. function _construct(Parent, args, Class) {
  14337. if (isNativeReflectConstruct()) {
  14338. _construct = Reflect.construct;
  14339. } else {
  14340. _construct = function _construct(Parent, args, Class) {
  14341. var a = [null];
  14342. a.push.apply(a, args);
  14343. var Constructor = Function.bind.apply(Parent, a);
  14344. var instance = new Constructor();
  14345. if (Class) _setPrototypeOf(instance, Class.prototype);
  14346. return instance;
  14347. };
  14348. }
  14349. return _construct.apply(null, arguments);
  14350. }
  14351. function _isNativeFunction(fn) {
  14352. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  14353. }
  14354. function _setPrototypeOf(o, p) {
  14355. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  14356. o.__proto__ = p;
  14357. return o;
  14358. };
  14359. return _setPrototypeOf(o, p);
  14360. }
  14361. function _getPrototypeOf(o) {
  14362. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  14363. return o.__proto__ || Object.getPrototypeOf(o);
  14364. };
  14365. return _getPrototypeOf(o);
  14366. }
  14367. var ConfigurationError =
  14368. /*#__PURE__*/
  14369. function (_Error) {
  14370. _inherits(ConfigurationError, _Error);
  14371. function ConfigurationError(parameter, value) {
  14372. var _this;
  14373. _classCallCheck(this, ConfigurationError);
  14374. _this = _possibleConstructorReturn(this, _getPrototypeOf(ConfigurationError).call(this));
  14375. _this.code = 1;
  14376. _this.name = 'CONFIGURATION_ERROR';
  14377. _this.parameter = parameter;
  14378. _this.value = value;
  14379. _this.message = !_this.value ? "Missing parameter: ".concat(_this.parameter) : "Invalid value ".concat(JSON.stringify(_this.value), " for parameter \"").concat(_this.parameter, "\"");
  14380. return _this;
  14381. }
  14382. return ConfigurationError;
  14383. }(_wrapNativeSuper(Error));
  14384. var InvalidStateError =
  14385. /*#__PURE__*/
  14386. function (_Error2) {
  14387. _inherits(InvalidStateError, _Error2);
  14388. function InvalidStateError(status) {
  14389. var _this2;
  14390. _classCallCheck(this, InvalidStateError);
  14391. _this2 = _possibleConstructorReturn(this, _getPrototypeOf(InvalidStateError).call(this));
  14392. _this2.code = 2;
  14393. _this2.name = 'INVALID_STATE_ERROR';
  14394. _this2.status = status;
  14395. _this2.message = "Invalid status: ".concat(status);
  14396. return _this2;
  14397. }
  14398. return InvalidStateError;
  14399. }(_wrapNativeSuper(Error));
  14400. var NotSupportedError =
  14401. /*#__PURE__*/
  14402. function (_Error3) {
  14403. _inherits(NotSupportedError, _Error3);
  14404. function NotSupportedError(message) {
  14405. var _this3;
  14406. _classCallCheck(this, NotSupportedError);
  14407. _this3 = _possibleConstructorReturn(this, _getPrototypeOf(NotSupportedError).call(this));
  14408. _this3.code = 3;
  14409. _this3.name = 'NOT_SUPPORTED_ERROR';
  14410. _this3.message = message;
  14411. return _this3;
  14412. }
  14413. return NotSupportedError;
  14414. }(_wrapNativeSuper(Error));
  14415. var NotReadyError =
  14416. /*#__PURE__*/
  14417. function (_Error4) {
  14418. _inherits(NotReadyError, _Error4);
  14419. function NotReadyError(message) {
  14420. var _this4;
  14421. _classCallCheck(this, NotReadyError);
  14422. _this4 = _possibleConstructorReturn(this, _getPrototypeOf(NotReadyError).call(this));
  14423. _this4.code = 4;
  14424. _this4.name = 'NOT_READY_ERROR';
  14425. _this4.message = message;
  14426. return _this4;
  14427. }
  14428. return NotReadyError;
  14429. }(_wrapNativeSuper(Error));
  14430. module.exports = {
  14431. ConfigurationError: ConfigurationError,
  14432. InvalidStateError: InvalidStateError,
  14433. NotSupportedError: NotSupportedError,
  14434. NotReadyError: NotReadyError
  14435. };
  14436. }),
  14437. /* 7 */
  14438. (function(module, exports) {
  14439. // Copyright Joyent, Inc. and other Node contributors.
  14440. //
  14441. // Permission is hereby granted, free of charge, to any person obtaining a
  14442. // copy of this software and associated documentation files (the
  14443. // "Software"), to deal in the Software without restriction, including
  14444. // without limitation the rights to use, copy, modify, merge, publish,
  14445. // distribute, sublicense, and/or sell copies of the Software, and to permit
  14446. // persons to whom the Software is furnished to do so, subject to the
  14447. // following conditions:
  14448. //
  14449. // The above copyright notice and this permission notice shall be included
  14450. // in all copies or substantial portions of the Software.
  14451. //
  14452. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14453. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14454. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  14455. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  14456. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  14457. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  14458. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  14459. function EventEmitter() {
  14460. this._events = this._events || {};
  14461. this._maxListeners = this._maxListeners || undefined;
  14462. }
  14463. module.exports = EventEmitter; // Backwards-compat with node 0.10.x
  14464. EventEmitter.EventEmitter = EventEmitter;
  14465. EventEmitter.prototype._events = undefined;
  14466. EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are
  14467. // added to it. This is a useful default which helps finding memory leaks.
  14468. EventEmitter.defaultMaxListeners = 10; // Obviously not all Emitters should be limited to 10. This function allows
  14469. // that to be increased. Set to zero for unlimited.
  14470. EventEmitter.prototype.setMaxListeners = function (n) {
  14471. if (!isNumber(n) || n < 0 || isNaN(n)) throw TypeError('n must be a positive number');
  14472. this._maxListeners = n;
  14473. return this;
  14474. };
  14475. EventEmitter.prototype.emit = function (type) {
  14476. var er, handler, len, args, i, listeners;
  14477. if (!this._events) this._events = {}; // If there is no 'error' event listener then throw.
  14478. if (type === 'error') {
  14479. if (!this._events.error || isObject(this._events.error) && !this._events.error.length) {
  14480. er = arguments[1];
  14481. if (er instanceof Error) {
  14482. throw er; // Unhandled 'error' event
  14483. } else {
  14484. // At least give some kind of context to the user
  14485. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  14486. err.context = er;
  14487. throw err;
  14488. }
  14489. }
  14490. }
  14491. handler = this._events[type];
  14492. if (isUndefined(handler)) return false;
  14493. if (isFunction(handler)) {
  14494. switch (arguments.length) {
  14495. // fast cases
  14496. case 1:
  14497. handler.call(this);
  14498. break;
  14499. case 2:
  14500. handler.call(this, arguments[1]);
  14501. break;
  14502. case 3:
  14503. handler.call(this, arguments[1], arguments[2]);
  14504. break;
  14505. // slower
  14506. default:
  14507. args = Array.prototype.slice.call(arguments, 1);
  14508. handler.apply(this, args);
  14509. }
  14510. } else if (isObject(handler)) {
  14511. args = Array.prototype.slice.call(arguments, 1);
  14512. listeners = handler.slice();
  14513. len = listeners.length;
  14514. for (i = 0; i < len; i++) listeners[i].apply(this, args);
  14515. }
  14516. return true;
  14517. };
  14518. EventEmitter.prototype.addListener = function (type, listener) {
  14519. var m;
  14520. if (!isFunction(listener)) throw TypeError('listener must be a function');
  14521. if (!this._events) this._events = {}; // To avoid recursion in the case that type === "newListener"! Before
  14522. // adding it to the listeners, first emit "newListener".
  14523. if (this._events.newListener) this.emit('newListener', type, isFunction(listener.listener) ? listener.listener : listener);
  14524. if (!this._events[type]) // Optimize the case of one listener. Don't need the extra array object.
  14525. this._events[type] = listener;else if (isObject(this._events[type])) // If we've already got an array, just append.
  14526. this._events[type].push(listener);else // Adding the second element, need to change to array.
  14527. this._events[type] = [this._events[type], listener]; // Check for listener leak
  14528. if (isObject(this._events[type]) && !this._events[type].warned) {
  14529. if (!isUndefined(this._maxListeners)) {
  14530. m = this._maxListeners;
  14531. } else {
  14532. m = EventEmitter.defaultMaxListeners;
  14533. }
  14534. if (m && m > 0 && this._events[type].length > m) {
  14535. this._events[type].warned = true;
  14536. console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length);
  14537. if (typeof console.trace === 'function') {
  14538. // not supported in IE 10
  14539. console.trace();
  14540. }
  14541. }
  14542. }
  14543. return this;
  14544. };
  14545. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  14546. EventEmitter.prototype.once = function (type, listener) {
  14547. if (!isFunction(listener)) throw TypeError('listener must be a function');
  14548. var fired = false;
  14549. function g() {
  14550. this.removeListener(type, g);
  14551. if (!fired) {
  14552. fired = true;
  14553. listener.apply(this, arguments);
  14554. }
  14555. }
  14556. g.listener = listener;
  14557. this.on(type, g);
  14558. return this;
  14559. }; // emits a 'removeListener' event iff the listener was removed
  14560. EventEmitter.prototype.removeListener = function (type, listener) {
  14561. var list, position, length, i;
  14562. if (!isFunction(listener)) throw TypeError('listener must be a function');
  14563. if (!this._events || !this._events[type]) return this;
  14564. list = this._events[type];
  14565. length = list.length;
  14566. position = -1;
  14567. if (list === listener || isFunction(list.listener) && list.listener === listener) {
  14568. delete this._events[type];
  14569. if (this._events.removeListener) this.emit('removeListener', type, listener);
  14570. } else if (isObject(list)) {
  14571. for (i = length; i-- > 0;) {
  14572. if (list[i] === listener || list[i].listener && list[i].listener === listener) {
  14573. position = i;
  14574. break;
  14575. }
  14576. }
  14577. if (position < 0) return this;
  14578. if (list.length === 1) {
  14579. list.length = 0;
  14580. delete this._events[type];
  14581. } else {
  14582. list.splice(position, 1);
  14583. }
  14584. if (this._events.removeListener) this.emit('removeListener', type, listener);
  14585. }
  14586. return this;
  14587. };
  14588. EventEmitter.prototype.removeAllListeners = function (type) {
  14589. var key, listeners;
  14590. if (!this._events) return this; // not listening for removeListener, no need to emit
  14591. if (!this._events.removeListener) {
  14592. if (arguments.length === 0) this._events = {};else if (this._events[type]) delete this._events[type];
  14593. return this;
  14594. } // emit removeListener for all listeners on all events
  14595. if (arguments.length === 0) {
  14596. for (key in this._events) {
  14597. if (key === 'removeListener') continue;
  14598. this.removeAllListeners(key);
  14599. }
  14600. this.removeAllListeners('removeListener');
  14601. this._events = {};
  14602. return this;
  14603. }
  14604. listeners = this._events[type];
  14605. if (isFunction(listeners)) {
  14606. this.removeListener(type, listeners);
  14607. } else if (listeners) {
  14608. // LIFO order
  14609. while (listeners.length) this.removeListener(type, listeners[listeners.length - 1]);
  14610. }
  14611. delete this._events[type];
  14612. return this;
  14613. };
  14614. EventEmitter.prototype.listeners = function (type) {
  14615. var ret;
  14616. if (!this._events || !this._events[type]) ret = [];else if (isFunction(this._events[type])) ret = [this._events[type]];else ret = this._events[type].slice();
  14617. return ret;
  14618. };
  14619. EventEmitter.prototype.listenerCount = function (type) {
  14620. if (this._events) {
  14621. var evlistener = this._events[type];
  14622. if (isFunction(evlistener)) return 1;else if (evlistener) return evlistener.length;
  14623. }
  14624. return 0;
  14625. };
  14626. EventEmitter.listenerCount = function (emitter, type) {
  14627. return emitter.listenerCount(type);
  14628. };
  14629. function isFunction(arg) {
  14630. return typeof arg === 'function';
  14631. }
  14632. function isNumber(arg) {
  14633. return typeof arg === 'number';
  14634. }
  14635. function isObject(arg) {
  14636. return typeof arg === 'object' && arg !== null;
  14637. }
  14638. function isUndefined(arg) {
  14639. return arg === void 0;
  14640. }
  14641. }),
  14642. /* 8 */
  14643. (function(module, exports, __webpack_require__) {
  14644. "use strict";
  14645. function _classCallCheck(instance, Constructor) {
  14646. if (!(instance instanceof Constructor)) {
  14647. throw new TypeError("Cannot call a class as a function");
  14648. }
  14649. }
  14650. function _defineProperties(target, props) {
  14651. for (var i = 0; i < props.length; i++) {
  14652. var descriptor = props[i];
  14653. descriptor.enumerable = descriptor.enumerable || false;
  14654. descriptor.configurable = true;
  14655. if ("value" in descriptor) descriptor.writable = true;
  14656. Object.defineProperty(target, descriptor.key, descriptor);
  14657. }
  14658. }
  14659. function _createClass(Constructor, protoProps, staticProps) {
  14660. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  14661. if (staticProps) _defineProperties(Constructor, staticProps);
  14662. return Constructor;
  14663. }
  14664. var JsSIP_C = __webpack_require__(1);
  14665. var Utils = __webpack_require__(2);
  14666. var Grammar = __webpack_require__(3);
  14667. /**
  14668. * -param {String} [scheme]
  14669. * -param {String} [user]
  14670. * -param {String} host
  14671. * -param {String} [port]
  14672. * -param {Object} [parameters]
  14673. * -param {Object} [headers]
  14674. *
  14675. */
  14676. module.exports =
  14677. /*#__PURE__*/
  14678. function () {
  14679. _createClass(URI, null, [{
  14680. key: "parse",
  14681. /**
  14682. * Parse the given string and returns a JsSIP.URI instance or undefined if
  14683. * it is an invalid URI.
  14684. */
  14685. value: function parse(uri) {
  14686. uri = Grammar.parse(uri, 'SIP_URI');
  14687. if (uri !== -1) {
  14688. return uri;
  14689. } else {
  14690. return undefined;
  14691. }
  14692. }
  14693. }]);
  14694. function URI(scheme, user, host, port) {
  14695. var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  14696. var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
  14697. _classCallCheck(this, URI); // Checks.
  14698. if (!host) {
  14699. throw new TypeError('missing or invalid "host" parameter');
  14700. } // Initialize parameters.
  14701. this._parameters = {};
  14702. this._headers = {};
  14703. this._scheme = scheme || JsSIP_C.SIP;
  14704. this._user = user;
  14705. this._host = host;
  14706. this._port = port;
  14707. for (var param in parameters) {
  14708. if (Object.prototype.hasOwnProperty.call(parameters, param)) {
  14709. this.setParam(param, parameters[param]);
  14710. }
  14711. }
  14712. for (var header in headers) {
  14713. if (Object.prototype.hasOwnProperty.call(headers, header)) {
  14714. this.setHeader(header, headers[header]);
  14715. }
  14716. }
  14717. }
  14718. _createClass(URI, [{
  14719. key: "setParam",
  14720. value: function setParam(key, value) {
  14721. if (key) {
  14722. this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
  14723. }
  14724. }
  14725. }, {
  14726. key: "getParam",
  14727. value: function getParam(key) {
  14728. if (key) {
  14729. return this._parameters[key.toLowerCase()];
  14730. }
  14731. }
  14732. }, {
  14733. key: "hasParam",
  14734. value: function hasParam(key) {
  14735. if (key) {
  14736. return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
  14737. }
  14738. }
  14739. }, {
  14740. key: "deleteParam",
  14741. value: function deleteParam(parameter) {
  14742. parameter = parameter.toLowerCase();
  14743. if (this._parameters.hasOwnProperty(parameter)) {
  14744. var value = this._parameters[parameter];
  14745. delete this._parameters[parameter];
  14746. return value;
  14747. }
  14748. }
  14749. }, {
  14750. key: "clearParams",
  14751. value: function clearParams() {
  14752. this._parameters = {};
  14753. }
  14754. }, {
  14755. key: "setHeader",
  14756. value: function setHeader(name, value) {
  14757. this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
  14758. }
  14759. }, {
  14760. key: "getHeader",
  14761. value: function getHeader(name) {
  14762. if (name) {
  14763. return this._headers[Utils.headerize(name)];
  14764. }
  14765. }
  14766. }, {
  14767. key: "hasHeader",
  14768. value: function hasHeader(name) {
  14769. if (name) {
  14770. return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false;
  14771. }
  14772. }
  14773. }, {
  14774. key: "deleteHeader",
  14775. value: function deleteHeader(header) {
  14776. header = Utils.headerize(header);
  14777. if (this._headers.hasOwnProperty(header)) {
  14778. var value = this._headers[header];
  14779. delete this._headers[header];
  14780. return value;
  14781. }
  14782. }
  14783. }, {
  14784. key: "clearHeaders",
  14785. value: function clearHeaders() {
  14786. this._headers = {};
  14787. }
  14788. }, {
  14789. key: "clone",
  14790. value: function clone() {
  14791. return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers)));
  14792. }
  14793. }, {
  14794. key: "toString",
  14795. value: function toString() {
  14796. var headers = [];
  14797. var uri = "".concat(this._scheme, ":");
  14798. if (this._user) {
  14799. uri += "".concat(Utils.escapeUser(this._user), "@");
  14800. }
  14801. uri += this._host;
  14802. if (this._port || this._port === 0) {
  14803. uri += ":".concat(this._port);
  14804. }
  14805. for (var parameter in this._parameters) {
  14806. if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
  14807. uri += ";".concat(parameter);
  14808. if (this._parameters[parameter] !== null) {
  14809. uri += "=".concat(this._parameters[parameter]);
  14810. }
  14811. }
  14812. }
  14813. for (var header in this._headers) {
  14814. if (Object.prototype.hasOwnProperty.call(this._headers, header)) {
  14815. var _iteratorNormalCompletion = true;
  14816. var _didIteratorError = false;
  14817. var _iteratorError = undefined;
  14818. try {
  14819. for (var _iterator = this._headers[header][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  14820. var item = _step.value;
  14821. headers.push("".concat(header, "=").concat(item));
  14822. }
  14823. } catch (err) {
  14824. _didIteratorError = true;
  14825. _iteratorError = err;
  14826. } finally {
  14827. try {
  14828. if (!_iteratorNormalCompletion && _iterator.return != null) {
  14829. _iterator.return();
  14830. }
  14831. } finally {
  14832. if (_didIteratorError) {
  14833. throw _iteratorError;
  14834. }
  14835. }
  14836. }
  14837. }
  14838. }
  14839. if (headers.length > 0) {
  14840. uri += "?".concat(headers.join('&'));
  14841. }
  14842. return uri;
  14843. }
  14844. }, {
  14845. key: "toAor",
  14846. value: function toAor(show_port) {
  14847. var aor = "".concat(this._scheme, ":");
  14848. if (this._user) {
  14849. aor += "".concat(Utils.escapeUser(this._user), "@");
  14850. }
  14851. aor += this._host;
  14852. if (show_port && (this._port || this._port === 0)) {
  14853. aor += ":".concat(this._port);
  14854. }
  14855. return aor;
  14856. }
  14857. }, {
  14858. key: "scheme",
  14859. get: function get() {
  14860. return this._scheme;
  14861. },
  14862. set: function set(value) {
  14863. this._scheme = value.toLowerCase();
  14864. }
  14865. }, {
  14866. key: "user",
  14867. get: function get() {
  14868. return this._user;
  14869. },
  14870. set: function set(value) {
  14871. this._user = value;
  14872. }
  14873. }, {
  14874. key: "host",
  14875. get: function get() {
  14876. return this._host;
  14877. },
  14878. set: function set(value) {
  14879. this._host = value.toLowerCase();
  14880. }
  14881. }, {
  14882. key: "port",
  14883. get: function get() {
  14884. return this._port;
  14885. },
  14886. set: function set(value) {
  14887. this._port = value === 0 ? value : parseInt(value, 10) || null;
  14888. }
  14889. }]);
  14890. return URI;
  14891. }();
  14892. }),
  14893. /* 9 */
  14894. (function(module, exports, __webpack_require__) {
  14895. "use strict";
  14896. function _typeof(obj) {
  14897. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  14898. _typeof = function _typeof(obj) {
  14899. return typeof obj;
  14900. };
  14901. } else {
  14902. _typeof = function _typeof(obj) {
  14903. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  14904. };
  14905. }
  14906. return _typeof(obj);
  14907. }
  14908. function _classCallCheck(instance, Constructor) {
  14909. if (!(instance instanceof Constructor)) {
  14910. throw new TypeError("Cannot call a class as a function");
  14911. }
  14912. }
  14913. function _defineProperties(target, props) {
  14914. for (var i = 0; i < props.length; i++) {
  14915. var descriptor = props[i];
  14916. descriptor.enumerable = descriptor.enumerable || false;
  14917. descriptor.configurable = true;
  14918. if ("value" in descriptor) descriptor.writable = true;
  14919. Object.defineProperty(target, descriptor.key, descriptor);
  14920. }
  14921. }
  14922. function _createClass(Constructor, protoProps, staticProps) {
  14923. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  14924. if (staticProps) _defineProperties(Constructor, staticProps);
  14925. return Constructor;
  14926. }
  14927. function _possibleConstructorReturn(self, call) {
  14928. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  14929. return call;
  14930. }
  14931. return _assertThisInitialized(self);
  14932. }
  14933. function _getPrototypeOf(o) {
  14934. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  14935. return o.__proto__ || Object.getPrototypeOf(o);
  14936. };
  14937. return _getPrototypeOf(o);
  14938. }
  14939. function _inherits(subClass, superClass) {
  14940. if (typeof superClass !== "function" && superClass !== null) {
  14941. throw new TypeError("Super expression must either be null or a function");
  14942. }
  14943. subClass.prototype = Object.create(superClass && superClass.prototype, {
  14944. constructor: {
  14945. value: subClass,
  14946. writable: true,
  14947. configurable: true
  14948. }
  14949. });
  14950. if (superClass) _setPrototypeOf(subClass, superClass);
  14951. }
  14952. function _setPrototypeOf(o, p) {
  14953. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  14954. o.__proto__ = p;
  14955. return o;
  14956. };
  14957. return _setPrototypeOf(o, p);
  14958. }
  14959. function _assertThisInitialized(self) {
  14960. if (self === void 0) {
  14961. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  14962. }
  14963. return self;
  14964. }
  14965. var EventEmitter = __webpack_require__(7).EventEmitter;
  14966. var JsSIP_C = __webpack_require__(1);
  14967. var SIPMessage = __webpack_require__(5);
  14968. var Timers = __webpack_require__(16);
  14969. var debugnict = __webpack_require__(0)('JsSIP:NonInviteClientTransaction');
  14970. var debugict = __webpack_require__(0)('JsSIP:InviteClientTransaction');
  14971. var debugact = __webpack_require__(0)('JsSIP:AckClientTransaction');
  14972. var debugnist = __webpack_require__(0)('JsSIP:NonInviteServerTransaction');
  14973. var debugist = __webpack_require__(0)('JsSIP:InviteServerTransaction');
  14974. var C = {
  14975. // Transaction states.
  14976. STATUS_TRYING: 1,
  14977. STATUS_PROCEEDING: 2,
  14978. STATUS_CALLING: 3,
  14979. STATUS_ACCEPTED: 4,
  14980. STATUS_COMPLETED: 5,
  14981. STATUS_TERMINATED: 6,
  14982. STATUS_CONFIRMED: 7,
  14983. // Transaction types.
  14984. NON_INVITE_CLIENT: 'nict',
  14985. NON_INVITE_SERVER: 'nist',
  14986. INVITE_CLIENT: 'ict',
  14987. INVITE_SERVER: 'ist'
  14988. };
  14989. var NonInviteClientTransaction =
  14990. /*#__PURE__*/
  14991. function (_EventEmitter) {
  14992. _inherits(NonInviteClientTransaction, _EventEmitter);
  14993. function NonInviteClientTransaction(ua, transport, request, eventHandlers) {
  14994. var _this;
  14995. _classCallCheck(this, NonInviteClientTransaction);
  14996. _this = _possibleConstructorReturn(this, _getPrototypeOf(NonInviteClientTransaction).call(this));
  14997. _this.type = C.NON_INVITE_CLIENT;
  14998. _this.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  14999. _this.ua = ua;
  15000. _this.transport = transport;
  15001. _this.request = request;
  15002. _this.eventHandlers = eventHandlers;
  15003. var via = "SIP/2.0/".concat(transport.via_transport);
  15004. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this.id);
  15005. _this.request.setHeader('via', via);
  15006. _this.ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this)));
  15007. return _this;
  15008. }
  15009. _createClass(NonInviteClientTransaction, [{
  15010. key: "stateChanged",
  15011. value: function stateChanged(state) {
  15012. this.state = state;
  15013. this.emit('stateChanged');
  15014. }
  15015. }, {
  15016. key: "send",
  15017. value: function send() {
  15018. var _this2 = this;
  15019. this.stateChanged(C.STATUS_TRYING);
  15020. this.F = setTimeout(function () {
  15021. _this2.timer_F();
  15022. }, Timers.TIMER_F);
  15023. if (!this.transport.send(this.request)) {
  15024. this.onTransportError();
  15025. }
  15026. }
  15027. }, {
  15028. key: "onTransportError",
  15029. value: function onTransportError() {
  15030. debugnict("transport error occurred, deleting transaction ".concat(this.id));
  15031. clearTimeout(this.F);
  15032. clearTimeout(this.K);
  15033. this.stateChanged(C.STATUS_TERMINATED);
  15034. this.ua.destroyTransaction(this);
  15035. this.eventHandlers.onTransportError();
  15036. }
  15037. }, {
  15038. key: "timer_F",
  15039. value: function timer_F() {
  15040. debugnict("Timer F expired for transaction ".concat(this.id));
  15041. this.stateChanged(C.STATUS_TERMINATED);
  15042. this.ua.destroyTransaction(this);
  15043. this.eventHandlers.onRequestTimeout();
  15044. }
  15045. }, {
  15046. key: "timer_K",
  15047. value: function timer_K() {
  15048. this.stateChanged(C.STATUS_TERMINATED);
  15049. this.ua.destroyTransaction(this);
  15050. }
  15051. }, {
  15052. key: "receiveResponse",
  15053. value: function receiveResponse(response) {
  15054. var _this3 = this;
  15055. var status_code = response.status_code;
  15056. if (status_code < 200) {
  15057. switch (this.state) {
  15058. case C.STATUS_TRYING:
  15059. case C.STATUS_PROCEEDING:
  15060. this.stateChanged(C.STATUS_PROCEEDING);
  15061. this.eventHandlers.onReceiveResponse(response);
  15062. break;
  15063. }
  15064. } else {
  15065. switch (this.state) {
  15066. case C.STATUS_TRYING:
  15067. case C.STATUS_PROCEEDING:
  15068. this.stateChanged(C.STATUS_COMPLETED);
  15069. clearTimeout(this.F);
  15070. if (status_code === 408) {
  15071. this.eventHandlers.onRequestTimeout();
  15072. } else {
  15073. this.eventHandlers.onReceiveResponse(response);
  15074. }
  15075. this.K = setTimeout(function () {
  15076. _this3.timer_K();
  15077. }, Timers.TIMER_K);
  15078. break;
  15079. case C.STATUS_COMPLETED:
  15080. break;
  15081. }
  15082. }
  15083. }
  15084. }, {
  15085. key: "C",
  15086. get: function get() {
  15087. return C;
  15088. }
  15089. }]);
  15090. return NonInviteClientTransaction;
  15091. }(EventEmitter);
  15092. var InviteClientTransaction =
  15093. /*#__PURE__*/
  15094. function (_EventEmitter2) {
  15095. _inherits(InviteClientTransaction, _EventEmitter2);
  15096. function InviteClientTransaction(ua, transport, request, eventHandlers) {
  15097. var _this4;
  15098. _classCallCheck(this, InviteClientTransaction);
  15099. _this4 = _possibleConstructorReturn(this, _getPrototypeOf(InviteClientTransaction).call(this));
  15100. _this4.type = C.INVITE_CLIENT;
  15101. _this4.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  15102. _this4.ua = ua;
  15103. _this4.transport = transport;
  15104. _this4.request = request;
  15105. _this4.eventHandlers = eventHandlers;
  15106. request.transaction = _assertThisInitialized(_assertThisInitialized(_this4));
  15107. var via = "SIP/2.0/".concat(transport.via_transport);
  15108. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this4.id);
  15109. _this4.request.setHeader('via', via);
  15110. _this4.ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this4)));
  15111. return _this4;
  15112. }
  15113. _createClass(InviteClientTransaction, [{
  15114. key: "stateChanged",
  15115. value: function stateChanged(state) {
  15116. this.state = state;
  15117. this.emit('stateChanged');
  15118. }
  15119. }, {
  15120. key: "send",
  15121. value: function send() {
  15122. var _this5 = this;
  15123. this.stateChanged(C.STATUS_CALLING);
  15124. this.B = setTimeout(function () {
  15125. _this5.timer_B();
  15126. }, Timers.TIMER_B);
  15127. if (!this.transport.send(this.request)) {
  15128. this.onTransportError();
  15129. }
  15130. }
  15131. }, {
  15132. key: "onTransportError",
  15133. value: function onTransportError() {
  15134. clearTimeout(this.B);
  15135. clearTimeout(this.D);
  15136. clearTimeout(this.M);
  15137. if (this.state !== C.STATUS_ACCEPTED) {
  15138. debugict("transport error occurred, deleting transaction ".concat(this.id));
  15139. this.eventHandlers.onTransportError();
  15140. }
  15141. this.stateChanged(C.STATUS_TERMINATED);
  15142. this.ua.destroyTransaction(this);
  15143. } // RFC 6026 7.2.
  15144. }, {
  15145. key: "timer_M",
  15146. value: function timer_M() {
  15147. debugict("Timer M expired for transaction ".concat(this.id));
  15148. if (this.state === C.STATUS_ACCEPTED) {
  15149. clearTimeout(this.B);
  15150. this.stateChanged(C.STATUS_TERMINATED);
  15151. this.ua.destroyTransaction(this);
  15152. }
  15153. } // RFC 3261 17.1.1.
  15154. }, {
  15155. key: "timer_B",
  15156. value: function timer_B() {
  15157. debugict("Timer B expired for transaction ".concat(this.id));
  15158. if (this.state === C.STATUS_CALLING) {
  15159. this.stateChanged(C.STATUS_TERMINATED);
  15160. this.ua.destroyTransaction(this);
  15161. this.eventHandlers.onRequestTimeout();
  15162. }
  15163. }
  15164. }, {
  15165. key: "timer_D",
  15166. value: function timer_D() {
  15167. debugict("Timer D expired for transaction ".concat(this.id));
  15168. clearTimeout(this.B);
  15169. this.stateChanged(C.STATUS_TERMINATED);
  15170. this.ua.destroyTransaction(this);
  15171. }
  15172. }, {
  15173. key: "sendACK",
  15174. value: function sendACK(response) {
  15175. var _this6 = this;
  15176. var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, {
  15177. 'route_set': this.request.getHeaders('route'),
  15178. 'call_id': this.request.getHeader('call-id'),
  15179. 'cseq': this.request.cseq
  15180. });
  15181. ack.setHeader('from', this.request.getHeader('from'));
  15182. ack.setHeader('via', this.request.getHeader('via'));
  15183. ack.setHeader('to', response.getHeader('to'));
  15184. this.D = setTimeout(function () {
  15185. _this6.timer_D();
  15186. }, Timers.TIMER_D);
  15187. this.transport.send(ack);
  15188. }
  15189. }, {
  15190. key: "cancel",
  15191. value: function cancel(reason) {
  15192. // Send only if a provisional response (>100) has been received.
  15193. if (this.state !== C.STATUS_PROCEEDING) {
  15194. return;
  15195. }
  15196. var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, {
  15197. 'route_set': this.request.getHeaders('route'),
  15198. 'call_id': this.request.getHeader('call-id'),
  15199. 'cseq': this.request.cseq
  15200. });
  15201. cancel.setHeader('from', this.request.getHeader('from'));
  15202. cancel.setHeader('via', this.request.getHeader('via'));
  15203. cancel.setHeader('to', this.request.getHeader('to'));
  15204. if (reason) {
  15205. cancel.setHeader('reason', reason);
  15206. }
  15207. this.transport.send(cancel);
  15208. }
  15209. }, {
  15210. key: "receiveResponse",
  15211. value: function receiveResponse(response) {
  15212. var _this7 = this;
  15213. var status_code = response.status_code;
  15214. if (status_code >= 100 && status_code <= 199) {
  15215. switch (this.state) {
  15216. case C.STATUS_CALLING:
  15217. this.stateChanged(C.STATUS_PROCEEDING);
  15218. this.eventHandlers.onReceiveResponse(response);
  15219. break;
  15220. case C.STATUS_PROCEEDING:
  15221. this.eventHandlers.onReceiveResponse(response);
  15222. break;
  15223. }
  15224. } else if (status_code >= 200 && status_code <= 299) {
  15225. switch (this.state) {
  15226. case C.STATUS_CALLING:
  15227. case C.STATUS_PROCEEDING:
  15228. this.stateChanged(C.STATUS_ACCEPTED);
  15229. this.M = setTimeout(function () {
  15230. _this7.timer_M();
  15231. }, Timers.TIMER_M);
  15232. this.eventHandlers.onReceiveResponse(response);
  15233. break;
  15234. case C.STATUS_ACCEPTED:
  15235. this.eventHandlers.onReceiveResponse(response);
  15236. break;
  15237. }
  15238. } else if (status_code >= 300 && status_code <= 699) {
  15239. switch (this.state) {
  15240. case C.STATUS_CALLING:
  15241. case C.STATUS_PROCEEDING:
  15242. this.stateChanged(C.STATUS_COMPLETED);
  15243. this.sendACK(response);
  15244. this.eventHandlers.onReceiveResponse(response);
  15245. break;
  15246. case C.STATUS_COMPLETED:
  15247. this.sendACK(response);
  15248. break;
  15249. }
  15250. }
  15251. }
  15252. }, {
  15253. key: "C",
  15254. get: function get() {
  15255. return C;
  15256. }
  15257. }]);
  15258. return InviteClientTransaction;
  15259. }(EventEmitter);
  15260. var AckClientTransaction =
  15261. /*#__PURE__*/
  15262. function (_EventEmitter3) {
  15263. _inherits(AckClientTransaction, _EventEmitter3);
  15264. function AckClientTransaction(ua, transport, request, eventHandlers) {
  15265. var _this8;
  15266. _classCallCheck(this, AckClientTransaction);
  15267. _this8 = _possibleConstructorReturn(this, _getPrototypeOf(AckClientTransaction).call(this));
  15268. _this8.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  15269. _this8.transport = transport;
  15270. _this8.request = request;
  15271. _this8.eventHandlers = eventHandlers;
  15272. var via = "SIP/2.0/".concat(transport.via_transport);
  15273. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this8.id);
  15274. _this8.request.setHeader('via', via);
  15275. return _this8;
  15276. }
  15277. _createClass(AckClientTransaction, [{
  15278. key: "send",
  15279. value: function send() {
  15280. if (!this.transport.send(this.request)) {
  15281. this.onTransportError();
  15282. }
  15283. }
  15284. }, {
  15285. key: "onTransportError",
  15286. value: function onTransportError() {
  15287. debugact("transport error occurred for transaction ".concat(this.id));
  15288. this.eventHandlers.onTransportError();
  15289. }
  15290. }, {
  15291. key: "C",
  15292. get: function get() {
  15293. return C;
  15294. }
  15295. }]);
  15296. return AckClientTransaction;
  15297. }(EventEmitter);
  15298. var NonInviteServerTransaction =
  15299. /*#__PURE__*/
  15300. function (_EventEmitter4) {
  15301. _inherits(NonInviteServerTransaction, _EventEmitter4);
  15302. function NonInviteServerTransaction(ua, transport, request) {
  15303. var _this9;
  15304. _classCallCheck(this, NonInviteServerTransaction);
  15305. _this9 = _possibleConstructorReturn(this, _getPrototypeOf(NonInviteServerTransaction).call(this));
  15306. _this9.type = C.NON_INVITE_SERVER;
  15307. _this9.id = request.via_branch;
  15308. _this9.ua = ua;
  15309. _this9.transport = transport;
  15310. _this9.request = request;
  15311. _this9.last_response = '';
  15312. request.server_transaction = _assertThisInitialized(_assertThisInitialized(_this9));
  15313. _this9.state = C.STATUS_TRYING;
  15314. ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this9)));
  15315. return _this9;
  15316. }
  15317. _createClass(NonInviteServerTransaction, [{
  15318. key: "stateChanged",
  15319. value: function stateChanged(state) {
  15320. this.state = state;
  15321. this.emit('stateChanged');
  15322. }
  15323. }, {
  15324. key: "timer_J",
  15325. value: function timer_J() {
  15326. debugnist("Timer J expired for transaction ".concat(this.id));
  15327. this.stateChanged(C.STATUS_TERMINATED);
  15328. this.ua.destroyTransaction(this);
  15329. }
  15330. }, {
  15331. key: "onTransportError",
  15332. value: function onTransportError() {
  15333. if (!this.transportError) {
  15334. this.transportError = true;
  15335. debugnist("transport error occurred, deleting transaction ".concat(this.id));
  15336. clearTimeout(this.J);
  15337. this.stateChanged(C.STATUS_TERMINATED);
  15338. this.ua.destroyTransaction(this);
  15339. }
  15340. }
  15341. }, {
  15342. key: "receiveResponse",
  15343. value: function receiveResponse(status_code, response, onSuccess, onFailure) {
  15344. var _this10 = this;
  15345. if (status_code === 100) {
  15346. /* RFC 4320 4.1
  15347. * 'A SIP element MUST NOT
  15348. * send any provisional response with a
  15349. * Status-Code other than 100 to a non-INVITE request.'
  15350. */
  15351. switch (this.state) {
  15352. case C.STATUS_TRYING:
  15353. this.stateChanged(C.STATUS_PROCEEDING);
  15354. if (!this.transport.send(response)) {
  15355. this.onTransportError();
  15356. }
  15357. break;
  15358. case C.STATUS_PROCEEDING:
  15359. this.last_response = response;
  15360. if (!this.transport.send(response)) {
  15361. this.onTransportError();
  15362. if (onFailure) {
  15363. onFailure();
  15364. }
  15365. } else if (onSuccess) {
  15366. onSuccess();
  15367. }
  15368. break;
  15369. }
  15370. } else if (status_code >= 200 && status_code <= 699) {
  15371. switch (this.state) {
  15372. case C.STATUS_TRYING:
  15373. case C.STATUS_PROCEEDING:
  15374. this.stateChanged(C.STATUS_COMPLETED);
  15375. this.last_response = response;
  15376. this.J = setTimeout(function () {
  15377. _this10.timer_J();
  15378. }, Timers.TIMER_J);
  15379. if (!this.transport.send(response)) {
  15380. this.onTransportError();
  15381. if (onFailure) {
  15382. onFailure();
  15383. }
  15384. } else if (onSuccess) {
  15385. onSuccess();
  15386. }
  15387. break;
  15388. case C.STATUS_COMPLETED:
  15389. break;
  15390. }
  15391. }
  15392. }
  15393. }, {
  15394. key: "C",
  15395. get: function get() {
  15396. return C;
  15397. }
  15398. }]);
  15399. return NonInviteServerTransaction;
  15400. }(EventEmitter);
  15401. var InviteServerTransaction =
  15402. /*#__PURE__*/
  15403. function (_EventEmitter5) {
  15404. _inherits(InviteServerTransaction, _EventEmitter5);
  15405. function InviteServerTransaction(ua, transport, request) {
  15406. var _this11;
  15407. _classCallCheck(this, InviteServerTransaction);
  15408. _this11 = _possibleConstructorReturn(this, _getPrototypeOf(InviteServerTransaction).call(this));
  15409. _this11.type = C.INVITE_SERVER;
  15410. _this11.id = request.via_branch;
  15411. _this11.ua = ua;
  15412. _this11.transport = transport;
  15413. _this11.request = request;
  15414. _this11.last_response = '';
  15415. request.server_transaction = _assertThisInitialized(_assertThisInitialized(_this11));
  15416. _this11.state = C.STATUS_PROCEEDING;
  15417. ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this11)));
  15418. _this11.resendProvisionalTimer = null;
  15419. request.reply(100);
  15420. return _this11;
  15421. }
  15422. _createClass(InviteServerTransaction, [{
  15423. key: "stateChanged",
  15424. value: function stateChanged(state) {
  15425. this.state = state;
  15426. this.emit('stateChanged');
  15427. }
  15428. }, {
  15429. key: "timer_H",
  15430. value: function timer_H() {
  15431. debugist("Timer H expired for transaction ".concat(this.id));
  15432. if (this.state === C.STATUS_COMPLETED) {
  15433. debugist('ACK not received, dialog will be terminated');
  15434. }
  15435. this.stateChanged(C.STATUS_TERMINATED);
  15436. this.ua.destroyTransaction(this);
  15437. }
  15438. }, {
  15439. key: "timer_I",
  15440. value: function timer_I() {
  15441. this.stateChanged(C.STATUS_TERMINATED);
  15442. } // RFC 6026 7.1.
  15443. }, {
  15444. key: "timer_L",
  15445. value: function timer_L() {
  15446. debugist("Timer L expired for transaction ".concat(this.id));
  15447. if (this.state === C.STATUS_ACCEPTED) {
  15448. this.stateChanged(C.STATUS_TERMINATED);
  15449. this.ua.destroyTransaction(this);
  15450. }
  15451. }
  15452. }, {
  15453. key: "onTransportError",
  15454. value: function onTransportError() {
  15455. if (!this.transportError) {
  15456. this.transportError = true;
  15457. debugist("transport error occurred, deleting transaction ".concat(this.id));
  15458. if (this.resendProvisionalTimer !== null) {
  15459. clearInterval(this.resendProvisionalTimer);
  15460. this.resendProvisionalTimer = null;
  15461. }
  15462. clearTimeout(this.L);
  15463. clearTimeout(this.H);
  15464. clearTimeout(this.I);
  15465. this.stateChanged(C.STATUS_TERMINATED);
  15466. this.ua.destroyTransaction(this);
  15467. }
  15468. }
  15469. }, {
  15470. key: "resend_provisional",
  15471. value: function resend_provisional() {
  15472. if (!this.transport.send(this.last_response)) {
  15473. this.onTransportError();
  15474. }
  15475. } // INVITE Server Transaction RFC 3261 17.2.1.
  15476. }, {
  15477. key: "receiveResponse",
  15478. value: function receiveResponse(status_code, response, onSuccess, onFailure) {
  15479. var _this12 = this;
  15480. if (status_code >= 100 && status_code <= 199) {
  15481. switch (this.state) {
  15482. case C.STATUS_PROCEEDING:
  15483. if (!this.transport.send(response)) {
  15484. this.onTransportError();
  15485. }
  15486. this.last_response = response;
  15487. break;
  15488. }
  15489. }
  15490. if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) {
  15491. // Trigger the resendProvisionalTimer only for the first non 100 provisional response.
  15492. if (this.resendProvisionalTimer === null) {
  15493. this.resendProvisionalTimer = setInterval(function () {
  15494. _this12.resend_provisional();
  15495. }, Timers.PROVISIONAL_RESPONSE_INTERVAL);
  15496. }
  15497. } else if (status_code >= 200 && status_code <= 299) {
  15498. switch (this.state) {
  15499. case C.STATUS_PROCEEDING:
  15500. this.stateChanged(C.STATUS_ACCEPTED);
  15501. this.last_response = response;
  15502. this.L = setTimeout(function () {
  15503. _this12.timer_L();
  15504. }, Timers.TIMER_L);
  15505. if (this.resendProvisionalTimer !== null) {
  15506. clearInterval(this.resendProvisionalTimer);
  15507. this.resendProvisionalTimer = null;
  15508. }
  15509. /* falls through */
  15510. case C.STATUS_ACCEPTED:
  15511. // Note that this point will be reached for proceeding this.state also.
  15512. if (!this.transport.send(response)) {
  15513. this.onTransportError();
  15514. if (onFailure) {
  15515. onFailure();
  15516. }
  15517. } else if (onSuccess) {
  15518. onSuccess();
  15519. }
  15520. break;
  15521. }
  15522. } else if (status_code >= 300 && status_code <= 699) {
  15523. switch (this.state) {
  15524. case C.STATUS_PROCEEDING:
  15525. if (this.resendProvisionalTimer !== null) {
  15526. clearInterval(this.resendProvisionalTimer);
  15527. this.resendProvisionalTimer = null;
  15528. }
  15529. if (!this.transport.send(response)) {
  15530. this.onTransportError();
  15531. if (onFailure) {
  15532. onFailure();
  15533. }
  15534. } else {
  15535. this.stateChanged(C.STATUS_COMPLETED);
  15536. this.H = setTimeout(function () {
  15537. _this12.timer_H();
  15538. }, Timers.TIMER_H);
  15539. if (onSuccess) {
  15540. onSuccess();
  15541. }
  15542. }
  15543. break;
  15544. }
  15545. }
  15546. }
  15547. }, {
  15548. key: "C",
  15549. get: function get() {
  15550. return C;
  15551. }
  15552. }]);
  15553. return InviteServerTransaction;
  15554. }(EventEmitter);
  15555. /**
  15556. * INVITE:
  15557. * _true_ if retransmission
  15558. * _false_ new request
  15559. *
  15560. * ACK:
  15561. * _true_ ACK to non2xx response
  15562. * _false_ ACK must be passed to TU (accepted state)
  15563. * ACK to 2xx response
  15564. *
  15565. * CANCEL:
  15566. * _true_ no matching invite transaction
  15567. * _false_ matching invite transaction and no final response sent
  15568. *
  15569. * OTHER:
  15570. * _true_ retransmission
  15571. * _false_ new request
  15572. */
  15573. function checkTransaction(_ref, request) {
  15574. var _transactions = _ref._transactions;
  15575. var tr;
  15576. switch (request.method) {
  15577. case JsSIP_C.INVITE:
  15578. tr = _transactions.ist[request.via_branch];
  15579. if (tr) {
  15580. switch (tr.state) {
  15581. case C.STATUS_PROCEEDING:
  15582. tr.transport.send(tr.last_response);
  15583. break;
  15584. // RFC 6026 7.1 Invite retransmission.
  15585. // Received while in C.STATUS_ACCEPTED state. Absorb it.
  15586. case C.STATUS_ACCEPTED:
  15587. break;
  15588. }
  15589. return true;
  15590. }
  15591. break;
  15592. case JsSIP_C.ACK:
  15593. tr = _transactions.ist[request.via_branch]; // RFC 6026 7.1.
  15594. if (tr) {
  15595. if (tr.state === C.STATUS_ACCEPTED) {
  15596. return false;
  15597. } else if (tr.state === C.STATUS_COMPLETED) {
  15598. tr.state = C.STATUS_CONFIRMED;
  15599. tr.I = setTimeout(function () {
  15600. tr.timer_I();
  15601. }, Timers.TIMER_I);
  15602. return true;
  15603. }
  15604. } // ACK to 2XX Response.
  15605. else {
  15606. return false;
  15607. }
  15608. break;
  15609. case JsSIP_C.CANCEL:
  15610. tr = _transactions.ist[request.via_branch];
  15611. if (tr) {
  15612. request.reply_sl(200);
  15613. if (tr.state === C.STATUS_PROCEEDING) {
  15614. return false;
  15615. } else {
  15616. return true;
  15617. }
  15618. } else {
  15619. request.reply_sl(481);
  15620. return true;
  15621. }
  15622. default:
  15623. // Non-INVITE Server Transaction RFC 3261 17.2.2.
  15624. tr = _transactions.nist[request.via_branch];
  15625. if (tr) {
  15626. switch (tr.state) {
  15627. case C.STATUS_TRYING:
  15628. break;
  15629. case C.STATUS_PROCEEDING:
  15630. case C.STATUS_COMPLETED:
  15631. tr.transport.send(tr.last_response);
  15632. break;
  15633. }
  15634. return true;
  15635. }
  15636. break;
  15637. }
  15638. }
  15639. module.exports = {
  15640. C: C,
  15641. NonInviteClientTransaction: NonInviteClientTransaction,
  15642. InviteClientTransaction: InviteClientTransaction,
  15643. AckClientTransaction: AckClientTransaction,
  15644. NonInviteServerTransaction: NonInviteServerTransaction,
  15645. InviteServerTransaction: InviteServerTransaction,
  15646. checkTransaction: checkTransaction
  15647. };
  15648. }),
  15649. /* 10 */
  15650. (function(module, exports, __webpack_require__) {
  15651. "use strict";
  15652. function _classCallCheck(instance, Constructor) {
  15653. if (!(instance instanceof Constructor)) {
  15654. throw new TypeError("Cannot call a class as a function");
  15655. }
  15656. }
  15657. function _defineProperties(target, props) {
  15658. for (var i = 0; i < props.length; i++) {
  15659. var descriptor = props[i];
  15660. descriptor.enumerable = descriptor.enumerable || false;
  15661. descriptor.configurable = true;
  15662. if ("value" in descriptor) descriptor.writable = true;
  15663. Object.defineProperty(target, descriptor.key, descriptor);
  15664. }
  15665. }
  15666. function _createClass(Constructor, protoProps, staticProps) {
  15667. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  15668. if (staticProps) _defineProperties(Constructor, staticProps);
  15669. return Constructor;
  15670. }
  15671. var JsSIP_C = __webpack_require__(1);
  15672. var DigestAuthentication = __webpack_require__(31);
  15673. var Transactions = __webpack_require__(9);
  15674. var debug = __webpack_require__(0)('JsSIP:RequestSender'); // Default event handlers.
  15675. var EventHandlers = {
  15676. onRequestTimeout: function onRequestTimeout() {},
  15677. onTransportError: function onTransportError() {},
  15678. onReceiveResponse: function onReceiveResponse() {},
  15679. onAuthenticated: function onAuthenticated() {}
  15680. };
  15681. module.exports =
  15682. /*#__PURE__*/
  15683. function () {
  15684. function RequestSender(ua, request, eventHandlers) {
  15685. _classCallCheck(this, RequestSender);
  15686. this._ua = ua;
  15687. this._eventHandlers = eventHandlers;
  15688. this._method = request.method;
  15689. this._request = request;
  15690. this._auth = null;
  15691. this._challenged = false;
  15692. this._staled = false; // Define the undefined handlers.
  15693. for (var handler in EventHandlers) {
  15694. if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
  15695. if (!this._eventHandlers[handler]) {
  15696. this._eventHandlers[handler] = EventHandlers[handler];
  15697. }
  15698. }
  15699. } // If ua is in closing process or even closed just allow sending Bye and ACK.
  15700. if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) {
  15701. this._eventHandlers.onTransportError();
  15702. }
  15703. }
  15704. /**
  15705. * Create the client transaction and send the message.
  15706. */
  15707. _createClass(RequestSender, [{
  15708. key: "send",
  15709. value: function send() {
  15710. var _this = this;
  15711. var eventHandlers = {
  15712. onRequestTimeout: function onRequestTimeout() {
  15713. _this._eventHandlers.onRequestTimeout();
  15714. },
  15715. onTransportError: function onTransportError() {
  15716. _this._eventHandlers.onTransportError();
  15717. },
  15718. onReceiveResponse: function onReceiveResponse(response) {
  15719. _this._receiveResponse(response);
  15720. }
  15721. };
  15722. switch (this._method) {
  15723. case 'INVITE':
  15724. this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  15725. break;
  15726. case 'ACK':
  15727. this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  15728. break;
  15729. default:
  15730. this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  15731. }
  15732. this.clientTransaction.send();
  15733. }
  15734. /**
  15735. * Called from client transaction when receiving a correct response to the request.
  15736. * Authenticate request if needed or pass the response back to the applicant.
  15737. */
  15738. }, {
  15739. key: "_receiveResponse",
  15740. value: function _receiveResponse(response) {
  15741. var challenge;
  15742. var authorization_header_name;
  15743. var status_code = response.status_code;
  15744. /*
  15745. * Authentication
  15746. * Authenticate once. _challenged_ flag used to avoid infinite authentications.
  15747. */
  15748. if ((status_code === 401 || status_code === 407) && (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) {
  15749. // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header.
  15750. if (response.status_code === 401) {
  15751. challenge = response.parseHeader('www-authenticate');
  15752. authorization_header_name = 'authorization';
  15753. } else {
  15754. challenge = response.parseHeader('proxy-authenticate');
  15755. authorization_header_name = 'proxy-authorization';
  15756. } // Verify it seems a valid challenge.
  15757. if (!challenge) {
  15758. debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate"));
  15759. this._eventHandlers.onReceiveResponse(response);
  15760. return;
  15761. }
  15762. if (!this._challenged || !this._staled && challenge.stale === true) {
  15763. if (!this._auth) {
  15764. this._auth = new DigestAuthentication({
  15765. username: this._ua.configuration.authorization_user,
  15766. password: this._ua.configuration.password,
  15767. realm: this._ua.configuration.realm,
  15768. ha1: this._ua.configuration.ha1
  15769. });
  15770. } // Verify that the challenge is really valid.
  15771. if (!this._auth.authenticate(this._request, challenge)) {
  15772. this._eventHandlers.onReceiveResponse(response);
  15773. return;
  15774. }
  15775. this._challenged = true; // Update ha1 and realm in the UA.
  15776. this._ua.set('realm', this._auth.get('realm'));
  15777. this._ua.set('ha1', this._auth.get('ha1'));
  15778. if (challenge.stale) {
  15779. this._staled = true;
  15780. }
  15781. this._request = this._request.clone();
  15782. this._request.cseq += 1;
  15783. this._request.setHeader('cseq', "".concat(this._request.cseq, " ").concat(this._method));
  15784. this._request.setHeader(authorization_header_name, this._auth.toString());
  15785. this._eventHandlers.onAuthenticated(this._request);
  15786. this.send();
  15787. } else {
  15788. this._eventHandlers.onReceiveResponse(response);
  15789. }
  15790. } else {
  15791. this._eventHandlers.onReceiveResponse(response);
  15792. }
  15793. }
  15794. }]);
  15795. return RequestSender;
  15796. }();
  15797. }),
  15798. /* 11 */
  15799. (function(module, exports, __webpack_require__) {
  15800. "use strict";
  15801. function _classCallCheck(instance, Constructor) {
  15802. if (!(instance instanceof Constructor)) {
  15803. throw new TypeError("Cannot call a class as a function");
  15804. }
  15805. }
  15806. function _defineProperties(target, props) {
  15807. for (var i = 0; i < props.length; i++) {
  15808. var descriptor = props[i];
  15809. descriptor.enumerable = descriptor.enumerable || false;
  15810. descriptor.configurable = true;
  15811. if ("value" in descriptor) descriptor.writable = true;
  15812. Object.defineProperty(target, descriptor.key, descriptor);
  15813. }
  15814. }
  15815. function _createClass(Constructor, protoProps, staticProps) {
  15816. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  15817. if (staticProps) _defineProperties(Constructor, staticProps);
  15818. return Constructor;
  15819. }
  15820. var URI = __webpack_require__(8);
  15821. var Grammar = __webpack_require__(3);
  15822. module.exports =
  15823. /*#__PURE__*/
  15824. function () {
  15825. _createClass(NameAddrHeader, null, [{
  15826. key: "parse",
  15827. /**
  15828. * Parse the given string and returns a NameAddrHeader instance or undefined if
  15829. * it is an invalid NameAddrHeader.
  15830. */
  15831. value: function parse(name_addr_header) {
  15832. name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header');
  15833. if (name_addr_header !== -1) {
  15834. return name_addr_header;
  15835. } else {
  15836. return undefined;
  15837. }
  15838. }
  15839. }]);
  15840. function NameAddrHeader(uri, display_name, parameters) {
  15841. _classCallCheck(this, NameAddrHeader); // Checks.
  15842. if (!uri || !(uri instanceof URI)) {
  15843. throw new TypeError('missing or invalid "uri" parameter');
  15844. } // Initialize parameters.
  15845. this._uri = uri;
  15846. this._parameters = {};
  15847. this._display_name = display_name;
  15848. for (var param in parameters) {
  15849. if (Object.prototype.hasOwnProperty.call(parameters, param)) {
  15850. this.setParam(param, parameters[param]);
  15851. }
  15852. }
  15853. }
  15854. _createClass(NameAddrHeader, [{
  15855. key: "setParam",
  15856. value: function setParam(key, value) {
  15857. if (key) {
  15858. this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
  15859. }
  15860. }
  15861. }, {
  15862. key: "getParam",
  15863. value: function getParam(key) {
  15864. if (key) {
  15865. return this._parameters[key.toLowerCase()];
  15866. }
  15867. }
  15868. }, {
  15869. key: "hasParam",
  15870. value: function hasParam(key) {
  15871. if (key) {
  15872. return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
  15873. }
  15874. }
  15875. }, {
  15876. key: "deleteParam",
  15877. value: function deleteParam(parameter) {
  15878. parameter = parameter.toLowerCase();
  15879. if (this._parameters.hasOwnProperty(parameter)) {
  15880. var value = this._parameters[parameter];
  15881. delete this._parameters[parameter];
  15882. return value;
  15883. }
  15884. }
  15885. }, {
  15886. key: "clearParams",
  15887. value: function clearParams() {
  15888. this._parameters = {};
  15889. }
  15890. }, {
  15891. key: "clone",
  15892. value: function clone() {
  15893. return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters)));
  15894. }
  15895. }, {
  15896. key: "toString",
  15897. value: function toString() {
  15898. var body = this._display_name || this._display_name === 0 ? "\"".concat(this._display_name, "\" ") : '';
  15899. body += "<".concat(this._uri.toString(), ">");
  15900. for (var parameter in this._parameters) {
  15901. if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
  15902. body += ";".concat(parameter);
  15903. if (this._parameters[parameter] !== null) {
  15904. body += "=".concat(this._parameters[parameter]);
  15905. }
  15906. }
  15907. }
  15908. return body;
  15909. }
  15910. }, {
  15911. key: "uri",
  15912. get: function get() {
  15913. return this._uri;
  15914. }
  15915. }, {
  15916. key: "display_name",
  15917. get: function get() {
  15918. return this._display_name;
  15919. },
  15920. set: function set(value) {
  15921. this._display_name = value === 0 ? '0' : value;
  15922. }
  15923. }]);
  15924. return NameAddrHeader;
  15925. }();
  15926. }),
  15927. /* 12 */
  15928. (function(module, exports) {
  15929. module.exports = {"_from":"jssip","_id":"jssip@3.3.3","_inBundle":false,"_integrity":"sha512-SL+JkaY3w0n5Bbg7/NL/3wPTcjnkGM5IKUm6VRYYRyQTDiTR0ezLeqGjWACK2O/brT5l2QfR46AZ1iXMSLl4Dg==","_location":"/jssip","_phantomChildren":{"ms":"2.1.1"},"_requested":{"type":"tag","registry":true,"raw":"jssip","name":"jssip","escapedName":"jssip","rawSpec":"","saveSpec":null,"fetchSpec":"latest"},"_requiredBy":["#USER","/"],"_resolved":"https://registry.npmjs.org/jssip/-/jssip-3.3.3.tgz","_shasum":"d111efe06c926bf6752726668cf9e35f0c2f94fa","_spec":"jssip","_where":"/Users/entronica/eclipse-workspace/phone-js","author":{"name":"José Luis Millán","email":"jmillan@aliax.net","url":"https://github.com/jmillan"},"bugs":{"url":"https://github.com/versatica/JsSIP/issues"},"bundleDependencies":false,"contributors":[{"name":"Iñaki Baz Castillo","email":"ibc@aliax.net","url":"https://github.com/ibc"},{"name":"Saúl Ibarra Corretgé","email":"saghul@gmail.com","url":"https://github.com/saghul"}],"dependencies":{"debug":"^4.1.1","events":"^3.0.0","sdp-transform":"^2.7.0"},"deprecated":false,"description":"the Javascript SIP library","devDependencies":{"@babel/core":"^7.2.2","@babel/preset-env":"^7.2.3","ansi-colors":"^3.2.3","browserify":"^16.2.3","eslint":"^5.11.1","fancy-log":"^1.3.3","gulp":"^4.0.0","gulp-babel":"^8.0.0","gulp-eslint":"^5.0.0","gulp-expect-file":"^1.0.0","gulp-header":"^2.0.7","gulp-nodeunit-runner":"^0.2.2","gulp-plumber":"^1.2.1","gulp-rename":"^1.4.0","gulp-uglify-es":"^1.0.4","pegjs":"^0.7.0","vinyl-buffer":"^1.0.1","vinyl-source-stream":"^2.0.0"},"homepage":"https://jssip.net","keywords":["sip","websocket","webrtc","node","browser","library"],"license":"MIT","main":"lib-es5/JsSIP.js","name":"jssip","repository":{"type":"git","url":"git+https://github.com/versatica/JsSIP.git"},"scripts":{"prepublishOnly":"gulp babel","test":"gulp test"},"title":"JsSIP","version":"3.3.3"}
  15930. }),
  15931. /* 13 */
  15932. (function(module, exports, __webpack_require__) {
  15933. var parser = __webpack_require__(27);
  15934. var writer = __webpack_require__(28);
  15935. exports.write = writer;
  15936. exports.parse = parser.parse;
  15937. exports.parseFmtpConfig = parser.parseFmtpConfig;
  15938. exports.parseParams = parser.parseParams;
  15939. exports.parsePayloads = parser.parsePayloads;
  15940. exports.parseRemoteCandidates = parser.parseRemoteCandidates;
  15941. exports.parseImageAttributes = parser.parseImageAttributes;
  15942. exports.parseSimulcastStreamList = parser.parseSimulcastStreamList;
  15943. }),
  15944. /* 14 */
  15945. (function(module, exports) {
  15946. var grammar = module.exports = {
  15947. v: [{
  15948. name: 'version',
  15949. reg: /^(\d*)$/
  15950. }],
  15951. o: [{
  15952. //o=- 20518 0 IN IP4 203.0.113.1
  15953. // NB: sessionId will be a String in most cases because it is huge
  15954. name: 'origin',
  15955. reg: /^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,
  15956. names: ['username', 'sessionId', 'sessionVersion', 'netType', 'ipVer', 'address'],
  15957. format: '%s %s %d %s IP%d %s'
  15958. }],
  15959. // default parsing of these only (though some of these feel outdated)
  15960. s: [{
  15961. name: 'name'
  15962. }],
  15963. i: [{
  15964. name: 'description'
  15965. }],
  15966. u: [{
  15967. name: 'uri'
  15968. }],
  15969. e: [{
  15970. name: 'email'
  15971. }],
  15972. p: [{
  15973. name: 'phone'
  15974. }],
  15975. z: [{
  15976. name: 'timezones'
  15977. }],
  15978. // TODO: this one can actually be parsed properly..
  15979. r: [{
  15980. name: 'repeats'
  15981. }],
  15982. // TODO: this one can also be parsed properly
  15983. //k: [{}], // outdated thing ignored
  15984. t: [{
  15985. //t=0 0
  15986. name: 'timing',
  15987. reg: /^(\d*) (\d*)/,
  15988. names: ['start', 'stop'],
  15989. format: '%d %d'
  15990. }],
  15991. c: [{
  15992. //c=IN IP4 10.47.197.26
  15993. name: 'connection',
  15994. reg: /^IN IP(\d) (\S*)/,
  15995. names: ['version', 'ip'],
  15996. format: 'IN IP%d %s'
  15997. }],
  15998. b: [{
  15999. //b=AS:4000
  16000. push: 'bandwidth',
  16001. reg: /^(TIAS|AS|CT|RR|RS):(\d*)/,
  16002. names: ['type', 'limit'],
  16003. format: '%s:%s'
  16004. }],
  16005. m: [{
  16006. //m=video 51744 RTP/AVP 126 97 98 34 31
  16007. // NB: special - pushes to session
  16008. // TODO: rtp/fmtp should be filtered by the payloads found here?
  16009. reg: /^(\w*) (\d*) ([\w\/]*)(?: (.*))?/,
  16010. names: ['type', 'port', 'protocol', 'payloads'],
  16011. format: '%s %d %s %s'
  16012. }],
  16013. a: [{
  16014. //a=rtpmap:110 opus/48000/2
  16015. push: 'rtp',
  16016. reg: /^rtpmap:(\d*) ([\w\-\.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,
  16017. names: ['payload', 'codec', 'rate', 'encoding'],
  16018. format: function (o) {
  16019. return o.encoding ? 'rtpmap:%d %s/%s/%s' : o.rate ? 'rtpmap:%d %s/%s' : 'rtpmap:%d %s';
  16020. }
  16021. }, {
  16022. //a=fmtp:108 profile-level-id=24;object=23;bitrate=64000
  16023. //a=fmtp:111 minptime=10; useinbandfec=1
  16024. push: 'fmtp',
  16025. reg: /^fmtp:(\d*) ([\S| ]*)/,
  16026. names: ['payload', 'config'],
  16027. format: 'fmtp:%d %s'
  16028. }, {
  16029. //a=control:streamid=0
  16030. name: 'control',
  16031. reg: /^control:(.*)/,
  16032. format: 'control:%s'
  16033. }, {
  16034. //a=rtcp:65179 IN IP4 193.84.77.194
  16035. name: 'rtcp',
  16036. reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,
  16037. names: ['port', 'netType', 'ipVer', 'address'],
  16038. format: function (o) {
  16039. return o.address != null ? 'rtcp:%d %s IP%d %s' : 'rtcp:%d';
  16040. }
  16041. }, {
  16042. //a=rtcp-fb:98 trr-int 100
  16043. push: 'rtcpFbTrrInt',
  16044. reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/,
  16045. names: ['payload', 'value'],
  16046. format: 'rtcp-fb:%d trr-int %d'
  16047. }, {
  16048. //a=rtcp-fb:98 nack rpsi
  16049. push: 'rtcpFb',
  16050. reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,
  16051. names: ['payload', 'type', 'subtype'],
  16052. format: function (o) {
  16053. return o.subtype != null ? 'rtcp-fb:%s %s %s' : 'rtcp-fb:%s %s';
  16054. }
  16055. }, {
  16056. //a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  16057. //a=extmap:1/recvonly URI-gps-string
  16058. push: 'ext',
  16059. reg: /^extmap:(\d+)(?:\/(\w+))? (\S*)(?: (\S*))?/,
  16060. names: ['value', 'direction', 'uri', 'config'],
  16061. format: function (o) {
  16062. return 'extmap:%d' + (o.direction ? '/%s' : '%v') + ' %s' + (o.config ? ' %s' : '');
  16063. }
  16064. }, {
  16065. //a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32
  16066. push: 'crypto',
  16067. reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,
  16068. names: ['id', 'suite', 'config', 'sessionConfig'],
  16069. format: function (o) {
  16070. return o.sessionConfig != null ? 'crypto:%d %s %s %s' : 'crypto:%d %s %s';
  16071. }
  16072. }, {
  16073. //a=setup:actpass
  16074. name: 'setup',
  16075. reg: /^setup:(\w*)/,
  16076. format: 'setup:%s'
  16077. }, {
  16078. //a=mid:1
  16079. name: 'mid',
  16080. reg: /^mid:([^\s]*)/,
  16081. format: 'mid:%s'
  16082. }, {
  16083. //a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a
  16084. name: 'msid',
  16085. reg: /^msid:(.*)/,
  16086. format: 'msid:%s'
  16087. }, {
  16088. //a=ptime:20
  16089. name: 'ptime',
  16090. reg: /^ptime:(\d*)/,
  16091. format: 'ptime:%d'
  16092. }, {
  16093. //a=maxptime:60
  16094. name: 'maxptime',
  16095. reg: /^maxptime:(\d*)/,
  16096. format: 'maxptime:%d'
  16097. }, {
  16098. //a=sendrecv
  16099. name: 'direction',
  16100. reg: /^(sendrecv|recvonly|sendonly|inactive)/
  16101. }, {
  16102. //a=ice-lite
  16103. name: 'icelite',
  16104. reg: /^(ice-lite)/
  16105. }, {
  16106. //a=ice-ufrag:F7gI
  16107. name: 'iceUfrag',
  16108. reg: /^ice-ufrag:(\S*)/,
  16109. format: 'ice-ufrag:%s'
  16110. }, {
  16111. //a=ice-pwd:x9cml/YzichV2+XlhiMu8g
  16112. name: 'icePwd',
  16113. reg: /^ice-pwd:(\S*)/,
  16114. format: 'ice-pwd:%s'
  16115. }, {
  16116. //a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
  16117. name: 'fingerprint',
  16118. reg: /^fingerprint:(\S*) (\S*)/,
  16119. names: ['type', 'hash'],
  16120. format: 'fingerprint:%s %s'
  16121. }, {
  16122. //a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
  16123. //a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10
  16124. //a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0 network-id 3 network-cost 10
  16125. //a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10
  16126. //a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0 network-id 3 network-cost 10
  16127. push: 'candidates',
  16128. reg: /^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,
  16129. names: ['foundation', 'component', 'transport', 'priority', 'ip', 'port', 'type', 'raddr', 'rport', 'tcptype', 'generation', 'network-id', 'network-cost'],
  16130. format: function (o) {
  16131. var str = 'candidate:%s %d %s %d %s %d typ %s';
  16132. str += o.raddr != null ? ' raddr %s rport %d' : '%v%v'; // NB: candidate has three optional chunks, so %void middles one if it's missing
  16133. str += o.tcptype != null ? ' tcptype %s' : '%v';
  16134. if (o.generation != null) {
  16135. str += ' generation %d';
  16136. }
  16137. str += o['network-id'] != null ? ' network-id %d' : '%v';
  16138. str += o['network-cost'] != null ? ' network-cost %d' : '%v';
  16139. return str;
  16140. }
  16141. }, {
  16142. //a=end-of-candidates (keep after the candidates line for readability)
  16143. name: 'endOfCandidates',
  16144. reg: /^(end-of-candidates)/
  16145. }, {
  16146. //a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ...
  16147. name: 'remoteCandidates',
  16148. reg: /^remote-candidates:(.*)/,
  16149. format: 'remote-candidates:%s'
  16150. }, {
  16151. //a=ice-options:google-ice
  16152. name: 'iceOptions',
  16153. reg: /^ice-options:(\S*)/,
  16154. format: 'ice-options:%s'
  16155. }, {
  16156. //a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1
  16157. push: 'ssrcs',
  16158. reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,
  16159. names: ['id', 'attribute', 'value'],
  16160. format: function (o) {
  16161. var str = 'ssrc:%d';
  16162. if (o.attribute != null) {
  16163. str += ' %s';
  16164. if (o.value != null) {
  16165. str += ':%s';
  16166. }
  16167. }
  16168. return str;
  16169. }
  16170. }, {
  16171. //a=ssrc-group:FEC 1 2
  16172. //a=ssrc-group:FEC-FR 3004364195 1080772241
  16173. push: 'ssrcGroups',
  16174. // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E
  16175. reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,
  16176. names: ['semantics', 'ssrcs'],
  16177. format: 'ssrc-group:%s %s'
  16178. }, {
  16179. //a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV
  16180. name: 'msidSemantic',
  16181. reg: /^msid-semantic:\s?(\w*) (\S*)/,
  16182. names: ['semantic', 'token'],
  16183. format: 'msid-semantic: %s %s' // space after ':' is not accidental
  16184. }, {
  16185. //a=group:BUNDLE audio video
  16186. push: 'groups',
  16187. reg: /^group:(\w*) (.*)/,
  16188. names: ['type', 'mids'],
  16189. format: 'group:%s %s'
  16190. }, {
  16191. //a=rtcp-mux
  16192. name: 'rtcpMux',
  16193. reg: /^(rtcp-mux)/
  16194. }, {
  16195. //a=rtcp-rsize
  16196. name: 'rtcpRsize',
  16197. reg: /^(rtcp-rsize)/
  16198. }, {
  16199. //a=sctpmap:5000 webrtc-datachannel 1024
  16200. name: 'sctpmap',
  16201. reg: /^sctpmap:([\w_\/]*) (\S*)(?: (\S*))?/,
  16202. names: ['sctpmapNumber', 'app', 'maxMessageSize'],
  16203. format: function (o) {
  16204. return o.maxMessageSize != null ? 'sctpmap:%s %s %s' : 'sctpmap:%s %s';
  16205. }
  16206. }, {
  16207. //a=x-google-flag:conference
  16208. name: 'xGoogleFlag',
  16209. reg: /^x-google-flag:([^\s]*)/,
  16210. format: 'x-google-flag:%s'
  16211. }, {
  16212. //a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0
  16213. push: 'rids',
  16214. reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,
  16215. names: ['id', 'direction', 'params'],
  16216. format: function (o) {
  16217. return o.params ? 'rid:%s %s %s' : 'rid:%s %s';
  16218. }
  16219. }, {
  16220. //a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250]
  16221. //a=imageattr:* send [x=800,y=640] recv *
  16222. //a=imageattr:100 recv [x=320,y=240]
  16223. push: 'imageattrs',
  16224. reg: new RegExp( //a=imageattr:97
  16225. '^imageattr:(\\d+|\\*)' + //send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320]
  16226. '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' + //recv [x=330,y=250]
  16227. '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?'),
  16228. names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'],
  16229. format: function (o) {
  16230. return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : '');
  16231. }
  16232. }, {
  16233. //a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8
  16234. //a=simulcast:recv 1;4,5 send 6;7
  16235. name: 'simulcast',
  16236. reg: new RegExp( //a=simulcast:
  16237. '^simulcast:' + //send 1,2,3;~4,~5
  16238. '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' + //space + recv 6;~7,~8
  16239. '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' + //end
  16240. '$'),
  16241. names: ['dir1', 'list1', 'dir2', 'list2'],
  16242. format: function (o) {
  16243. return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : '');
  16244. }
  16245. }, {
  16246. //Old simulcast draft 03 (implemented by Firefox)
  16247. // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03
  16248. //a=simulcast: recv pt=97;98 send pt=97
  16249. //a=simulcast: send rid=5;6;7 paused=6,7
  16250. name: 'simulcast_03',
  16251. reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/,
  16252. names: ['value'],
  16253. format: 'simulcast: %s'
  16254. }, {
  16255. //a=framerate:25
  16256. //a=framerate:29.97
  16257. name: 'framerate',
  16258. reg: /^framerate:(\d+(?:$|\.\d+))/,
  16259. format: 'framerate:%s'
  16260. }, {
  16261. // RFC4570
  16262. //a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5
  16263. name: 'sourceFilter',
  16264. reg: /^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,
  16265. names: ['filterMode', 'netType', 'addressTypes', 'destAddress', 'srcList'],
  16266. format: 'source-filter: %s %s %s %s %s'
  16267. }, {
  16268. //a=bundle-only
  16269. name: 'bundleOnly',
  16270. reg: /^(bundle-only)/
  16271. }, {
  16272. //a=label:1
  16273. name: 'label',
  16274. reg: /^label:(.+)/,
  16275. format: 'label:%s'
  16276. }, {
  16277. // RFC version 26 for SCTP over DTLS
  16278. // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5
  16279. name: 'sctpPort',
  16280. reg: /^sctp-port:(\d+)$/,
  16281. format: 'sctp-port:%s'
  16282. }, {
  16283. // RFC version 26 for SCTP over DTLS
  16284. // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
  16285. name: 'maxMessageSize',
  16286. reg: /^max-message-size:(\d+)$/,
  16287. format: 'max-message-size:%s'
  16288. }, {
  16289. // any a= that we don't understand is kepts verbatim on media.invalid
  16290. push: 'invalid',
  16291. names: ['value']
  16292. }]
  16293. }; // set sensible defaults to avoid polluting the grammar with boring details
  16294. Object.keys(grammar).forEach(function (key) {
  16295. var objs = grammar[key];
  16296. objs.forEach(function (obj) {
  16297. if (!obj.reg) {
  16298. obj.reg = /(.*)/;
  16299. }
  16300. if (!obj.format) {
  16301. obj.format = '%s';
  16302. }
  16303. });
  16304. });
  16305. }),
  16306. /* 15 */
  16307. (function(module, exports) {
  16308. // shim for using process in browser
  16309. var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
  16310. // don't break things. But we need to wrap it in a try catch in case it is
  16311. // wrapped in strict mode code which doesn't define any globals. It's inside a
  16312. // function because try/catches deoptimize in certain engines.
  16313. var cachedSetTimeout;
  16314. var cachedClearTimeout;
  16315. function defaultSetTimout() {
  16316. throw new Error('setTimeout has not been defined');
  16317. }
  16318. function defaultClearTimeout() {
  16319. throw new Error('clearTimeout has not been defined');
  16320. }
  16321. (function () {
  16322. try {
  16323. if (typeof setTimeout === 'function') {
  16324. cachedSetTimeout = setTimeout;
  16325. } else {
  16326. cachedSetTimeout = defaultSetTimout;
  16327. }
  16328. } catch (e) {
  16329. cachedSetTimeout = defaultSetTimout;
  16330. }
  16331. try {
  16332. if (typeof clearTimeout === 'function') {
  16333. cachedClearTimeout = clearTimeout;
  16334. } else {
  16335. cachedClearTimeout = defaultClearTimeout;
  16336. }
  16337. } catch (e) {
  16338. cachedClearTimeout = defaultClearTimeout;
  16339. }
  16340. })();
  16341. function runTimeout(fun) {
  16342. if (cachedSetTimeout === setTimeout) {
  16343. //normal enviroments in sane situations
  16344. return setTimeout(fun, 0);
  16345. } // if setTimeout wasn't available but was latter defined
  16346. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  16347. cachedSetTimeout = setTimeout;
  16348. return setTimeout(fun, 0);
  16349. }
  16350. try {
  16351. // when when somebody has screwed with setTimeout but no I.E. maddness
  16352. return cachedSetTimeout(fun, 0);
  16353. } catch (e) {
  16354. try {
  16355. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  16356. return cachedSetTimeout.call(null, fun, 0);
  16357. } catch (e) {
  16358. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  16359. return cachedSetTimeout.call(this, fun, 0);
  16360. }
  16361. }
  16362. }
  16363. function runClearTimeout(marker) {
  16364. if (cachedClearTimeout === clearTimeout) {
  16365. //normal enviroments in sane situations
  16366. return clearTimeout(marker);
  16367. } // if clearTimeout wasn't available but was latter defined
  16368. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  16369. cachedClearTimeout = clearTimeout;
  16370. return clearTimeout(marker);
  16371. }
  16372. try {
  16373. // when when somebody has screwed with setTimeout but no I.E. maddness
  16374. return cachedClearTimeout(marker);
  16375. } catch (e) {
  16376. try {
  16377. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  16378. return cachedClearTimeout.call(null, marker);
  16379. } catch (e) {
  16380. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  16381. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  16382. return cachedClearTimeout.call(this, marker);
  16383. }
  16384. }
  16385. }
  16386. var queue = [];
  16387. var draining = false;
  16388. var currentQueue;
  16389. var queueIndex = -1;
  16390. function cleanUpNextTick() {
  16391. if (!draining || !currentQueue) {
  16392. return;
  16393. }
  16394. draining = false;
  16395. if (currentQueue.length) {
  16396. queue = currentQueue.concat(queue);
  16397. } else {
  16398. queueIndex = -1;
  16399. }
  16400. if (queue.length) {
  16401. drainQueue();
  16402. }
  16403. }
  16404. function drainQueue() {
  16405. if (draining) {
  16406. return;
  16407. }
  16408. var timeout = runTimeout(cleanUpNextTick);
  16409. draining = true;
  16410. var len = queue.length;
  16411. while (len) {
  16412. currentQueue = queue;
  16413. queue = [];
  16414. while (++queueIndex < len) {
  16415. if (currentQueue) {
  16416. currentQueue[queueIndex].run();
  16417. }
  16418. }
  16419. queueIndex = -1;
  16420. len = queue.length;
  16421. }
  16422. currentQueue = null;
  16423. draining = false;
  16424. runClearTimeout(timeout);
  16425. }
  16426. process.nextTick = function (fun) {
  16427. var args = new Array(arguments.length - 1);
  16428. if (arguments.length > 1) {
  16429. for (var i = 1; i < arguments.length; i++) {
  16430. args[i - 1] = arguments[i];
  16431. }
  16432. }
  16433. queue.push(new Item(fun, args));
  16434. if (queue.length === 1 && !draining) {
  16435. runTimeout(drainQueue);
  16436. }
  16437. }; // v8 likes predictible objects
  16438. function Item(fun, array) {
  16439. this.fun = fun;
  16440. this.array = array;
  16441. }
  16442. Item.prototype.run = function () {
  16443. this.fun.apply(null, this.array);
  16444. };
  16445. process.title = 'browser';
  16446. process.browser = true;
  16447. process.env = {};
  16448. process.argv = [];
  16449. process.version = ''; // empty string to avoid regexp issues
  16450. process.versions = {};
  16451. function noop() {}
  16452. process.on = noop;
  16453. process.addListener = noop;
  16454. process.once = noop;
  16455. process.off = noop;
  16456. process.removeListener = noop;
  16457. process.removeAllListeners = noop;
  16458. process.emit = noop;
  16459. process.prependListener = noop;
  16460. process.prependOnceListener = noop;
  16461. process.listeners = function (name) {
  16462. return [];
  16463. };
  16464. process.binding = function (name) {
  16465. throw new Error('process.binding is not supported');
  16466. };
  16467. process.cwd = function () {
  16468. return '/';
  16469. };
  16470. process.chdir = function (dir) {
  16471. throw new Error('process.chdir is not supported');
  16472. };
  16473. process.umask = function () {
  16474. return 0;
  16475. };
  16476. }),
  16477. /* 16 */
  16478. (function(module, exports, __webpack_require__) {
  16479. "use strict";
  16480. var T1 = 500,
  16481. T2 = 4000,
  16482. T4 = 5000;
  16483. module.exports = {
  16484. T1: T1,
  16485. T2: T2,
  16486. T4: T4,
  16487. TIMER_B: 64 * T1,
  16488. TIMER_D: 0 * T1,
  16489. TIMER_F: 64 * T1,
  16490. TIMER_H: 64 * T1,
  16491. TIMER_I: 0 * T1,
  16492. TIMER_J: 0 * T1,
  16493. TIMER_K: 0 * T4,
  16494. TIMER_L: 64 * T1,
  16495. TIMER_M: 64 * T1,
  16496. PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1
  16497. };
  16498. }),
  16499. /* 17 */
  16500. (function(module, exports, __webpack_require__) {
  16501. "use strict";
  16502. function _typeof(obj) {
  16503. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  16504. _typeof = function _typeof(obj) {
  16505. return typeof obj;
  16506. };
  16507. } else {
  16508. _typeof = function _typeof(obj) {
  16509. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  16510. };
  16511. }
  16512. return _typeof(obj);
  16513. }
  16514. function _classCallCheck(instance, Constructor) {
  16515. if (!(instance instanceof Constructor)) {
  16516. throw new TypeError("Cannot call a class as a function");
  16517. }
  16518. }
  16519. function _possibleConstructorReturn(self, call) {
  16520. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  16521. return call;
  16522. }
  16523. return _assertThisInitialized(self);
  16524. }
  16525. function _assertThisInitialized(self) {
  16526. if (self === void 0) {
  16527. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  16528. }
  16529. return self;
  16530. }
  16531. function _getPrototypeOf(o) {
  16532. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  16533. return o.__proto__ || Object.getPrototypeOf(o);
  16534. };
  16535. return _getPrototypeOf(o);
  16536. }
  16537. function _defineProperties(target, props) {
  16538. for (var i = 0; i < props.length; i++) {
  16539. var descriptor = props[i];
  16540. descriptor.enumerable = descriptor.enumerable || false;
  16541. descriptor.configurable = true;
  16542. if ("value" in descriptor) descriptor.writable = true;
  16543. Object.defineProperty(target, descriptor.key, descriptor);
  16544. }
  16545. }
  16546. function _createClass(Constructor, protoProps, staticProps) {
  16547. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  16548. if (staticProps) _defineProperties(Constructor, staticProps);
  16549. return Constructor;
  16550. }
  16551. function _inherits(subClass, superClass) {
  16552. if (typeof superClass !== "function" && superClass !== null) {
  16553. throw new TypeError("Super expression must either be null or a function");
  16554. }
  16555. subClass.prototype = Object.create(superClass && superClass.prototype, {
  16556. constructor: {
  16557. value: subClass,
  16558. writable: true,
  16559. configurable: true
  16560. }
  16561. });
  16562. if (superClass) _setPrototypeOf(subClass, superClass);
  16563. }
  16564. function _setPrototypeOf(o, p) {
  16565. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  16566. o.__proto__ = p;
  16567. return o;
  16568. };
  16569. return _setPrototypeOf(o, p);
  16570. }
  16571. /* globals RTCPeerConnection: false, RTCSessionDescription: false */
  16572. var EventEmitter = __webpack_require__(7).EventEmitter;
  16573. var sdp_transform = __webpack_require__(13);
  16574. var JsSIP_C = __webpack_require__(1);
  16575. var Exceptions = __webpack_require__(6);
  16576. var Transactions = __webpack_require__(9);
  16577. var Utils = __webpack_require__(2);
  16578. var Timers = __webpack_require__(16);
  16579. var SIPMessage = __webpack_require__(5);
  16580. var Dialog = __webpack_require__(32);
  16581. var RequestSender = __webpack_require__(10);
  16582. var RTCSession_DTMF = __webpack_require__(34);
  16583. var RTCSession_Info = __webpack_require__(35);
  16584. var RTCSession_ReferNotifier = __webpack_require__(36);
  16585. var RTCSession_ReferSubscriber = __webpack_require__(37);
  16586. var debug = __webpack_require__(0)('JsSIP:RTCSession');
  16587. var debugerror = __webpack_require__(0)('JsSIP:ERROR:RTCSession');
  16588. var PhoneLogger = __webpack_require__(59);
  16589. var PhoneNetwork = __webpack_require__(61);
  16590. debugerror.log = console.warn.bind(console);
  16591. var C = {
  16592. // RTCSession states.
  16593. STATUS_NULL: 0,
  16594. STATUS_INVITE_SENT: 1,
  16595. STATUS_1XX_RECEIVED: 2,
  16596. STATUS_INVITE_RECEIVED: 3,
  16597. STATUS_WAITING_FOR_ANSWER: 4,
  16598. STATUS_ANSWERED: 5,
  16599. STATUS_WAITING_FOR_ACK: 6,
  16600. STATUS_CANCELED: 7,
  16601. STATUS_TERMINATED: 8,
  16602. STATUS_CONFIRMED: 9
  16603. };
  16604. /**
  16605. * Local variables.
  16606. */
  16607. var holdMediaTypes = ['audio', 'video'];
  16608. module.exports =
  16609. /*#__PURE__*/
  16610. function (_EventEmitter) {
  16611. _inherits(RTCSession, _EventEmitter);
  16612. _createClass(RTCSession, null, [{
  16613. key: "C",
  16614. /**
  16615. * Expose C object.
  16616. */
  16617. get: function get() {
  16618. return C;
  16619. }
  16620. }]);
  16621. function RTCSession(ua) {
  16622. var _this;
  16623. _classCallCheck(this, RTCSession);
  16624. debug('new');
  16625. _this = _possibleConstructorReturn(this, _getPrototypeOf(RTCSession).call(this));
  16626. _this._id = null;
  16627. _this._ua = ua;
  16628. _this._status = C.STATUS_NULL;
  16629. _this._dialog = null;
  16630. _this._earlyDialogs = {};
  16631. _this._contact = null;
  16632. _this._from_tag = null;
  16633. _this._to_tag = null; // The RTCPeerConnection instance (public attribute).
  16634. _this._connection = null; // Prevent races on serial PeerConnction operations.
  16635. _this._connectionPromiseQueue = Promise.resolve(); // Incoming/Outgoing request being currently processed.
  16636. _this._request = null; // Cancel state for initial outgoing request.
  16637. _this._is_canceled = false;
  16638. _this._cancel_reason = ''; // RTCSession confirmation flag.
  16639. _this._is_confirmed = false; // Is late SDP being negotiated.
  16640. _this._late_sdp = false; // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()).
  16641. _this._rtcOfferConstraints = null;
  16642. _this._rtcAnswerConstraints = null; // Local MediaStream.
  16643. _this._localMediaStream = null;
  16644. _this._localMediaStreamLocallyGenerated = false; // Flag to indicate PeerConnection ready for new actions.
  16645. _this._rtcReady = true; // SIP Timers.
  16646. _this._timers = {
  16647. ackTimer: null,
  16648. expiresTimer: null,
  16649. invite2xxTimer: null,
  16650. userNoAnswerTimer: null
  16651. }; // Session info.
  16652. _this._direction = null;
  16653. _this._local_identity = null;
  16654. _this._remote_identity = null;
  16655. _this._start_time = null;
  16656. _this._end_time = null;
  16657. _this._tones = null; // Mute/Hold state.
  16658. _this._audioMuted = false;
  16659. _this._videoMuted = false;
  16660. _this._localHold = false;
  16661. _this._remoteHold = false; // Session Timers (RFC 4028).
  16662. _this._sessionTimers = {
  16663. enabled: _this._ua.configuration.session_timers,
  16664. refreshMethod: _this._ua.configuration.session_timers_refresh_method,
  16665. defaultExpires: JsSIP_C.SESSION_EXPIRES,
  16666. currentExpires: null,
  16667. running: false,
  16668. refresher: false,
  16669. timer: null // A setTimeout.
  16670. }; // Map of ReferSubscriber instances indexed by the REFER's CSeq number.
  16671. _this._referSubscribers = {}; // Custom session empty object for high level use.
  16672. _this._data = {};
  16673. return _this;
  16674. }
  16675. /**
  16676. * User API
  16677. */
  16678. // Expose RTCSession constants as a property of the RTCSession instance.
  16679. _createClass(RTCSession, [{
  16680. key: "isInProgress",
  16681. value: function isInProgress() {
  16682. switch (this._status) {
  16683. case C.STATUS_NULL:
  16684. case C.STATUS_INVITE_SENT:
  16685. case C.STATUS_1XX_RECEIVED:
  16686. case C.STATUS_INVITE_RECEIVED:
  16687. case C.STATUS_WAITING_FOR_ANSWER:
  16688. return true;
  16689. default:
  16690. return false;
  16691. }
  16692. }
  16693. }, {
  16694. key: "isEstablished",
  16695. value: function isEstablished() {
  16696. switch (this._status) {
  16697. case C.STATUS_ANSWERED:
  16698. case C.STATUS_WAITING_FOR_ACK:
  16699. case C.STATUS_CONFIRMED:
  16700. return true;
  16701. default:
  16702. return false;
  16703. }
  16704. }
  16705. }, {
  16706. key: "isEnded",
  16707. value: function isEnded() {
  16708. switch (this._status) {
  16709. case C.STATUS_CANCELED:
  16710. case C.STATUS_TERMINATED:
  16711. return true;
  16712. default:
  16713. return false;
  16714. }
  16715. }
  16716. }, {
  16717. key: "isMuted",
  16718. value: function isMuted() {
  16719. return {
  16720. audio: this._audioMuted,
  16721. video: this._videoMuted
  16722. };
  16723. }
  16724. }, {
  16725. key: "isOnHold",
  16726. value: function isOnHold() {
  16727. return {
  16728. local: this._localHold,
  16729. remote: this._remoteHold
  16730. };
  16731. }
  16732. }, {
  16733. key: "connect",
  16734. value: function connect(target) {
  16735. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  16736. var initCallback = arguments.length > 2 ? arguments[2] : undefined;
  16737. debug('connect()');
  16738. var originalTarget = target;
  16739. var eventHandlers = options.eventHandlers || {};
  16740. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16741. var mediaConstraints = options.mediaConstraints || {
  16742. audio: true,
  16743. video: true
  16744. };
  16745. var mediaStream = options.mediaStream || null;
  16746. var pcConfig = options.pcConfig || {
  16747. iceServers: []
  16748. };
  16749. var rtcConstraints = options.rtcConstraints || null;
  16750. var rtcOfferConstraints = options.rtcOfferConstraints || null;
  16751. this._rtcOfferConstraints = rtcOfferConstraints;
  16752. this._rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  16753. this._data = options.data || this._data; // Check target.
  16754. if (target === undefined) {
  16755. throw new TypeError('Not enough arguments');
  16756. } // Check Session Status.
  16757. if (this._status !== C.STATUS_NULL) {
  16758. throw new Exceptions.InvalidStateError(this._status);
  16759. } // Check WebRTC support.
  16760. if (!window.RTCPeerConnection) {
  16761. throw new Exceptions.NotSupportedError('WebRTC not supported');
  16762. } // Check target validity.
  16763. target = this._ua.normalizeTarget(target);
  16764. if (!target) {
  16765. throw new TypeError("Invalid target: ".concat(originalTarget));
  16766. } // Session Timers.
  16767. if (this._sessionTimers.enabled) {
  16768. if (Utils.isDecimal(options.sessionTimersExpires)) {
  16769. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  16770. this._sessionTimers.defaultExpires = options.sessionTimersExpires;
  16771. } else {
  16772. this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  16773. }
  16774. }
  16775. } // Set event handlers.
  16776. for (var event in eventHandlers) {
  16777. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  16778. this.on(event, eventHandlers[event]);
  16779. }
  16780. } // Session parameter initialization.
  16781. this._from_tag = Utils.newTag(); // Set anonymous property.
  16782. var anonymous = options.anonymous || false;
  16783. var requestParams = {
  16784. from_tag: this._from_tag
  16785. };
  16786. this._contact = this._ua.contact.toString({
  16787. anonymous: anonymous,
  16788. outbound: true
  16789. });
  16790. if (anonymous) {
  16791. requestParams.from_display_name = 'Anonymous';
  16792. requestParams.from_uri = 'sip:anonymous@anonymous.invalid';
  16793. extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()));
  16794. extraHeaders.push('Privacy: id');
  16795. }
  16796. extraHeaders.push("Contact: ".concat(this._contact));
  16797. extraHeaders.push('Content-Type: application/sdp');
  16798. if (this._sessionTimers.enabled) {
  16799. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires));
  16800. }
  16801. this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders);
  16802. this._id = this._request.call_id + this._from_tag; // Create a new RTCPeerConnection instance.
  16803. this._createRTCConnection(pcConfig, rtcConstraints); // Set internal properties.
  16804. this._direction = 'outgoing';
  16805. this._local_identity = this._request.from;
  16806. this._remote_identity = this._request.to; // User explicitly provided a newRTCSession callback for this session.
  16807. if (initCallback) {
  16808. initCallback(this);
  16809. }
  16810. this._newRTCSession('local', this._request);
  16811. this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream);
  16812. }
  16813. }, {
  16814. key: "init_incoming",
  16815. value: function init_incoming(request, initCallback) {
  16816. var _this2 = this;
  16817. debug('init_incoming()');
  16818. var expires;
  16819. var contentType = request.getHeader('Content-Type'); // Check body and content type.
  16820. if (request.body && contentType !== 'application/sdp') {
  16821. request.reply(415);
  16822. return;
  16823. } // Session parameter initialization.
  16824. this._status = C.STATUS_INVITE_RECEIVED;
  16825. this._from_tag = request.from_tag;
  16826. this._id = request.call_id + this._from_tag;
  16827. this._request = request;
  16828. this._contact = this._ua.contact.toString(); // Get the Expires header value if exists.
  16829. if (request.hasHeader('expires')) {
  16830. expires = request.getHeader('expires') * 1000;
  16831. }
  16832. /* Set the to_tag before
  16833. * replying a response code that will create a dialog.
  16834. */
  16835. request.to_tag = Utils.newTag(); // An error on dialog creation will fire 'failed' event.
  16836. if (!this._createDialog(request, 'UAS', true)) {
  16837. request.reply(500, 'Missing Contact header field');
  16838. return;
  16839. }
  16840. if (request.body) {
  16841. this._late_sdp = false;
  16842. } else {
  16843. this._late_sdp = true;
  16844. }
  16845. this._status = C.STATUS_WAITING_FOR_ANSWER; // Set userNoAnswerTimer.
  16846. this._timers.userNoAnswerTimer = setTimeout(function () {
  16847. request.reply(408);
  16848. _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER);
  16849. }, this._ua.configuration.no_answer_timeout);
  16850. /* Set expiresTimer
  16851. * RFC3261 13.3.1
  16852. */
  16853. if (expires) {
  16854. this._timers.expiresTimer = setTimeout(function () {
  16855. if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) {
  16856. request.reply(487);
  16857. _this2._failed('system', null, JsSIP_C.causes.EXPIRES);
  16858. }
  16859. }, expires);
  16860. } // Set internal properties.
  16861. this._direction = 'incoming';
  16862. this._local_identity = request.to;
  16863. this._remote_identity = request.from; // A init callback was specifically defined.
  16864. if (initCallback) {
  16865. initCallback(this);
  16866. } // Fire 'newRTCSession' event.
  16867. this._newRTCSession('remote', request); // The user may have rejected the call in the 'newRTCSession' event.
  16868. if (this._status === C.STATUS_TERMINATED) {
  16869. return;
  16870. } // Reply 180.
  16871. request.reply(180, null, ["Contact: ".concat(this._contact)]); // Fire 'progress' event.
  16872. // TODO: Document that 'response' field in 'progress' event is null for incoming calls.
  16873. this._progress('local', null);
  16874. }
  16875. /**
  16876. * Answer the call.
  16877. */
  16878. }, {
  16879. key: "answer",
  16880. value: function answer() {
  16881. var _this3 = this;
  16882. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16883. debug('answer()');
  16884. var request = this._request;
  16885. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16886. var mediaConstraints = options.mediaConstraints || {};
  16887. var mediaStream = options.mediaStream || null;
  16888. var pcConfig = options.pcConfig || {
  16889. iceServers: []
  16890. };
  16891. var rtcConstraints = options.rtcConstraints || null;
  16892. var rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  16893. var tracks;
  16894. var peerHasAudioLine = false;
  16895. var peerHasVideoLine = false;
  16896. var peerOffersFullAudio = false;
  16897. var peerOffersFullVideo = false;
  16898. this._rtcAnswerConstraints = rtcAnswerConstraints;
  16899. this._rtcOfferConstraints = options.rtcOfferConstraints || null;
  16900. this._data = options.data || this._data; // Check Session Direction and Status.
  16901. if (this._direction !== 'incoming') {
  16902. throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession');
  16903. } // Check Session status.
  16904. if (this._status !== C.STATUS_WAITING_FOR_ANSWER) {
  16905. throw new Exceptions.InvalidStateError(this._status);
  16906. } // Session Timers.
  16907. if (this._sessionTimers.enabled) {
  16908. if (Utils.isDecimal(options.sessionTimersExpires)) {
  16909. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  16910. this._sessionTimers.defaultExpires = options.sessionTimersExpires;
  16911. } else {
  16912. this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  16913. }
  16914. }
  16915. }
  16916. this._status = C.STATUS_ANSWERED; // An error on dialog creation will fire 'failed' event.
  16917. if (!this._createDialog(request, 'UAS')) {
  16918. request.reply(500, 'Error creating dialog');
  16919. return;
  16920. }
  16921. clearTimeout(this._timers.userNoAnswerTimer);
  16922. extraHeaders.unshift("Contact: ".concat(this._contact)); // Determine incoming media from incoming SDP offer (if any).
  16923. var sdp = request.parseSDP(); // Make sure sdp.media is an array, not the case if there is only one media.
  16924. if (!Array.isArray(sdp.media)) {
  16925. sdp.media = [sdp.media];
  16926. } // Go through all medias in SDP to find offered capabilities to answer with.
  16927. var _iteratorNormalCompletion = true;
  16928. var _didIteratorError = false;
  16929. var _iteratorError = undefined;
  16930. try {
  16931. for (var _iterator = sdp.media[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  16932. var m = _step.value;
  16933. if (m.type === 'audio') {
  16934. peerHasAudioLine = true;
  16935. if (!m.direction || m.direction === 'sendrecv') {
  16936. peerOffersFullAudio = true;
  16937. }
  16938. }
  16939. if (m.type === 'video') {
  16940. peerHasVideoLine = true;
  16941. if (!m.direction || m.direction === 'sendrecv') {
  16942. peerOffersFullVideo = true;
  16943. }
  16944. }
  16945. } // Remove audio from mediaStream if suggested by mediaConstraints.
  16946. } catch (err) {
  16947. _didIteratorError = true;
  16948. _iteratorError = err;
  16949. } finally {
  16950. try {
  16951. if (!_iteratorNormalCompletion && _iterator.return != null) {
  16952. _iterator.return();
  16953. }
  16954. } finally {
  16955. if (_didIteratorError) {
  16956. throw _iteratorError;
  16957. }
  16958. }
  16959. }
  16960. if (mediaStream && mediaConstraints.audio === false) {
  16961. tracks = mediaStream.getAudioTracks();
  16962. var _iteratorNormalCompletion2 = true;
  16963. var _didIteratorError2 = false;
  16964. var _iteratorError2 = undefined;
  16965. try {
  16966. for (var _iterator2 = tracks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  16967. var track = _step2.value;
  16968. mediaStream.removeTrack(track);
  16969. }
  16970. } catch (err) {
  16971. _didIteratorError2 = true;
  16972. _iteratorError2 = err;
  16973. } finally {
  16974. try {
  16975. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  16976. _iterator2.return();
  16977. }
  16978. } finally {
  16979. if (_didIteratorError2) {
  16980. throw _iteratorError2;
  16981. }
  16982. }
  16983. }
  16984. } // Remove video from mediaStream if suggested by mediaConstraints.
  16985. if (mediaStream && mediaConstraints.video === false) {
  16986. tracks = mediaStream.getVideoTracks();
  16987. var _iteratorNormalCompletion3 = true;
  16988. var _didIteratorError3 = false;
  16989. var _iteratorError3 = undefined;
  16990. try {
  16991. for (var _iterator3 = tracks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  16992. var _track = _step3.value;
  16993. mediaStream.removeTrack(_track);
  16994. }
  16995. } catch (err) {
  16996. _didIteratorError3 = true;
  16997. _iteratorError3 = err;
  16998. } finally {
  16999. try {
  17000. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  17001. _iterator3.return();
  17002. }
  17003. } finally {
  17004. if (_didIteratorError3) {
  17005. throw _iteratorError3;
  17006. }
  17007. }
  17008. }
  17009. } // Set audio constraints based on incoming stream if not supplied.
  17010. if (!mediaStream && mediaConstraints.audio === undefined) {
  17011. mediaConstraints.audio = peerOffersFullAudio;
  17012. } // Set video constraints based on incoming stream if not supplied.
  17013. if (!mediaStream && mediaConstraints.video === undefined) {
  17014. mediaConstraints.video = peerOffersFullVideo;
  17015. } // Don't ask for audio if the incoming offer has no audio section.
  17016. if (!mediaStream && !peerHasAudioLine) {
  17017. mediaConstraints.audio = false;
  17018. } // Don't ask for video if the incoming offer has no video section.
  17019. if (!mediaStream && !peerHasVideoLine) {
  17020. mediaConstraints.video = false;
  17021. } // Create a new RTCPeerConnection instance.
  17022. // TODO: This may throw an error, should react.
  17023. this._createRTCConnection(pcConfig, rtcConstraints);
  17024. Promise.resolve() // Handle local MediaStream.
  17025. .then(function () {
  17026. // A local MediaStream is given, use it.
  17027. if (mediaStream) {
  17028. return mediaStream;
  17029. } // Audio and/or video requested, prompt getUserMedia.
  17030. else if (mediaConstraints.audio || mediaConstraints.video) {
  17031. _this3._localMediaStreamLocallyGenerated = true;
  17032. return navigator.mediaDevices.getUserMedia(mediaConstraints).catch(function (error) {
  17033. if (_this3._status === C.STATUS_TERMINATED) {
  17034. throw new Error('terminated');
  17035. }
  17036. request.reply(480);
  17037. _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  17038. debugerror('emit "getusermediafailed" [error:%o]', error);
  17039. _this3.emit('getusermediafailed', error);
  17040. throw new Error('getUserMedia() failed');
  17041. });
  17042. }
  17043. }) // Attach MediaStream to RTCPeerconnection.
  17044. .then(function (stream) {
  17045. if (_this3._status === C.STATUS_TERMINATED) {
  17046. throw new Error('terminated');
  17047. }
  17048. _this3._localMediaStream = stream;
  17049. if (stream) {
  17050. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  17051. if(isSafari) {
  17052. _this3._connection.addStream(stream);
  17053. } else {
  17054. stream.getTracks().forEach(function (track) {
  17055. _this3._connection.addTrack(track, stream);
  17056. });
  17057. }
  17058. }
  17059. }) // Set remote description.
  17060. .then(function () {
  17061. if (_this3._late_sdp) {
  17062. return;
  17063. }
  17064. var e = {
  17065. originator: 'remote',
  17066. type: 'offer',
  17067. sdp: request.body
  17068. };
  17069. debug('emit "sdp"');
  17070. _this3.emit('sdp', e);
  17071. var offer = new RTCSessionDescription({
  17072. type: 'offer',
  17073. sdp: e.sdp
  17074. });
  17075. _this3._connectionPromiseQueue = _this3._connectionPromiseQueue.then(function () {
  17076. return _this3._connection.setRemoteDescription(offer);
  17077. }).catch(function (error) {
  17078. request.reply(488);
  17079. _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR);
  17080. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  17081. _this3.emit('peerconnection:setremotedescriptionfailed', error);
  17082. throw new Error('peerconnection.setRemoteDescription() failed');
  17083. });
  17084. return _this3._connectionPromiseQueue;
  17085. }) // Create local description.
  17086. .then(function () {
  17087. if (_this3._status === C.STATUS_TERMINATED) {
  17088. throw new Error('terminated');
  17089. } // TODO: Is this event already useful?
  17090. _this3._connecting(request);
  17091. if (!_this3._late_sdp) {
  17092. return _this3._createLocalDescription('answer', rtcAnswerConstraints).catch(function () {
  17093. request.reply(500);
  17094. throw new Error('_createLocalDescription() failed');
  17095. });
  17096. } else {
  17097. return _this3._createLocalDescription('offer', _this3._rtcOfferConstraints).catch(function () {
  17098. request.reply(500);
  17099. throw new Error('_createLocalDescription() failed');
  17100. });
  17101. }
  17102. }) // Send reply.
  17103. .then(function (desc) {
  17104. if (_this3._status === C.STATUS_TERMINATED) {
  17105. throw new Error('terminated');
  17106. }
  17107. _this3._handleSessionTimersInIncomingRequest(request, extraHeaders);
  17108. request.reply(200, null, extraHeaders, desc, function () {
  17109. _this3._status = C.STATUS_WAITING_FOR_ACK;
  17110. _this3._setInvite2xxTimer(request, desc);
  17111. _this3._setACKTimer();
  17112. _this3._accepted('local');
  17113. }, function () {
  17114. _this3._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  17115. });
  17116. }).catch(function (error) {
  17117. if (_this3._status === C.STATUS_TERMINATED) {
  17118. return;
  17119. }
  17120. debugerror(error);
  17121. });
  17122. }
  17123. /**
  17124. * Terminate the call.
  17125. */
  17126. }, {
  17127. key: "terminate",
  17128. value: function terminate() {
  17129. var _this4 = this;
  17130. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17131. debug('terminate()');
  17132. var cause = options.cause || JsSIP_C.causes.BYE;
  17133. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  17134. var body = options.body;
  17135. var cancel_reason;
  17136. var status_code = options.status_code;
  17137. var reason_phrase = options.reason_phrase; // Check Session Status.
  17138. if (this._status === C.STATUS_TERMINATED) {
  17139. throw new Exceptions.InvalidStateError(this._status);
  17140. }
  17141. switch (this._status) {
  17142. // - UAC -
  17143. case C.STATUS_NULL:
  17144. case C.STATUS_INVITE_SENT:
  17145. case C.STATUS_1XX_RECEIVED:
  17146. debug('canceling session');
  17147. if (status_code && (status_code < 200 || status_code >= 700)) {
  17148. throw new TypeError("Invalid status_code: ".concat(status_code));
  17149. } else if (status_code) {
  17150. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  17151. cancel_reason = "SIP ;cause=".concat(status_code, " ;text=\"").concat(reason_phrase, "\"");
  17152. } // Check Session Status.
  17153. if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) {
  17154. this._is_canceled = true;
  17155. this._cancel_reason = cancel_reason;
  17156. } else if (this._status === C.STATUS_1XX_RECEIVED) {
  17157. this._request.cancel(cancel_reason);
  17158. }
  17159. this._status = C.STATUS_CANCELED;
  17160. this._failed('local', null, JsSIP_C.causes.CANCELED);
  17161. break;
  17162. // - UAS -
  17163. case C.STATUS_WAITING_FOR_ANSWER:
  17164. case C.STATUS_ANSWERED:
  17165. debug('rejecting session');
  17166. status_code = status_code || 480;
  17167. if (status_code < 300 || status_code >= 700) {
  17168. throw new TypeError("Invalid status_code: ".concat(status_code));
  17169. }
  17170. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  17171. this._failed('local', null, JsSIP_C.causes.REJECTED);
  17172. break;
  17173. case C.STATUS_WAITING_FOR_ACK:
  17174. case C.STATUS_CONFIRMED:
  17175. debug('terminating session');
  17176. reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  17177. if (status_code && (status_code < 200 || status_code >= 700)) {
  17178. throw new TypeError("Invalid status_code: ".concat(status_code));
  17179. } else if (status_code) {
  17180. extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\""));
  17181. }
  17182. /* RFC 3261 section 15 (Terminating a session):
  17183. *
  17184. * "...the callee's UA MUST NOT send a BYE on a confirmed dialog
  17185. * until it has received an ACK for its 2xx response or until the server
  17186. * transaction times out."
  17187. */
  17188. if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) {
  17189. // Save the dialog for later restoration.
  17190. var dialog = this._dialog; // Send the BYE as soon as the ACK is received...
  17191. this.receiveRequest = function (_ref) {
  17192. var method = _ref.method;
  17193. if (method === JsSIP_C.ACK) {
  17194. _this4.sendRequest(JsSIP_C.BYE, {
  17195. extraHeaders: extraHeaders,
  17196. body: body
  17197. });
  17198. dialog.terminate();
  17199. }
  17200. }; // .., or when the INVITE transaction times out
  17201. this._request.server_transaction.on('stateChanged', function () {
  17202. if (_this4._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) {
  17203. _this4.sendRequest(JsSIP_C.BYE, {
  17204. extraHeaders: extraHeaders,
  17205. body: body
  17206. });
  17207. dialog.terminate();
  17208. }
  17209. });
  17210. this._ended('local', null, cause); // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-).
  17211. this._dialog = dialog; // Restore the dialog into 'ua' so the ACK can reach 'this' session.
  17212. this._ua.newDialog(dialog);
  17213. } else {
  17214. this.sendRequest(JsSIP_C.BYE, {
  17215. extraHeaders: extraHeaders,
  17216. body: body
  17217. });
  17218. this._ended('local', null, cause);
  17219. }
  17220. }
  17221. }
  17222. }, {
  17223. key: "sendDTMF",
  17224. value: function sendDTMF(tones) {
  17225. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  17226. debug('sendDTMF() | tones: %s', tones);
  17227. var position = 0;
  17228. var duration = options.duration || null;
  17229. var interToneGap = options.interToneGap || null;
  17230. if (tones === undefined) {
  17231. throw new TypeError('Not enough arguments');
  17232. } // Check Session Status.
  17233. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) {
  17234. throw new Exceptions.InvalidStateError(this._status);
  17235. } // Convert to string.
  17236. if (typeof tones === 'number') {
  17237. tones = tones.toString();
  17238. } // Check tones.
  17239. if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) {
  17240. throw new TypeError("Invalid tones: ".concat(tones));
  17241. } // Check duration.
  17242. if (duration && !Utils.isDecimal(duration)) {
  17243. throw new TypeError("Invalid tone duration: ".concat(duration));
  17244. } else if (!duration) {
  17245. duration = RTCSession_DTMF.C.DEFAULT_DURATION;
  17246. } else if (duration < RTCSession_DTMF.C.MIN_DURATION) {
  17247. debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds"));
  17248. duration = RTCSession_DTMF.C.MIN_DURATION;
  17249. } else if (duration > RTCSession_DTMF.C.MAX_DURATION) {
  17250. debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds"));
  17251. duration = RTCSession_DTMF.C.MAX_DURATION;
  17252. } else {
  17253. duration = Math.abs(duration);
  17254. }
  17255. options.duration = duration; // Check interToneGap.
  17256. if (interToneGap && !Utils.isDecimal(interToneGap)) {
  17257. throw new TypeError("Invalid interToneGap: ".concat(interToneGap));
  17258. } else if (!interToneGap) {
  17259. interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP;
  17260. } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) {
  17261. debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds"));
  17262. interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP;
  17263. } else {
  17264. interToneGap = Math.abs(interToneGap);
  17265. }
  17266. if (this._tones) {
  17267. // Tones are already queued, just add to the queue.
  17268. this._tones += tones;
  17269. return;
  17270. }
  17271. this._tones = tones; // Send the first tone.
  17272. _sendDTMF.call(this);
  17273. function _sendDTMF() {
  17274. var _this5 = this;
  17275. var timeout;
  17276. if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) {
  17277. // Stop sending DTMF.
  17278. this._tones = null;
  17279. return;
  17280. }
  17281. var tone = this._tones[position];
  17282. position += 1;
  17283. if (tone === ',') {
  17284. timeout = 2000;
  17285. } else {
  17286. var dtmf = new RTCSession_DTMF(this);
  17287. options.eventHandlers = {
  17288. onFailed: function onFailed() {
  17289. _this5._tones = null;
  17290. }
  17291. };
  17292. dtmf.send(tone, options);
  17293. timeout = duration + interToneGap;
  17294. } // Set timeout for the next tone.
  17295. setTimeout(_sendDTMF.bind(this), timeout);
  17296. }
  17297. }
  17298. }, {
  17299. key: "sendInfo",
  17300. value: function sendInfo(contentType, body) {
  17301. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  17302. debug('sendInfo()'); // Check Session Status.
  17303. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) {
  17304. throw new Exceptions.InvalidStateError(this._status);
  17305. }
  17306. var info = new RTCSession_Info(this);
  17307. info.send(contentType, body, options);
  17308. }
  17309. /**
  17310. * Mute
  17311. */
  17312. }, {
  17313. key: "mute",
  17314. value: function mute() {
  17315. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  17316. audio: true,
  17317. video: false
  17318. };
  17319. debug('mute()');
  17320. var audioMuted = false,
  17321. videoMuted = false;
  17322. if (this._audioMuted === false && options.audio) {
  17323. audioMuted = true;
  17324. this._audioMuted = true;
  17325. this._toggleMuteAudio(true);
  17326. }
  17327. if (this._videoMuted === false && options.video) {
  17328. videoMuted = true;
  17329. this._videoMuted = true;
  17330. this._toggleMuteVideo(true);
  17331. }
  17332. if (audioMuted === true || videoMuted === true) {
  17333. this._onmute({
  17334. audio: audioMuted,
  17335. video: videoMuted
  17336. });
  17337. }
  17338. }
  17339. /**
  17340. * Unmute
  17341. */
  17342. }, {
  17343. key: "unmute",
  17344. value: function unmute() {
  17345. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  17346. audio: true,
  17347. video: true
  17348. };
  17349. debug('unmute()');
  17350. var audioUnMuted = false,
  17351. videoUnMuted = false;
  17352. if (this._audioMuted === true && options.audio) {
  17353. audioUnMuted = true;
  17354. this._audioMuted = false;
  17355. if (this._localHold === false) {
  17356. this._toggleMuteAudio(false);
  17357. }
  17358. }
  17359. if (this._videoMuted === true && options.video) {
  17360. videoUnMuted = true;
  17361. this._videoMuted = false;
  17362. if (this._localHold === false) {
  17363. this._toggleMuteVideo(false);
  17364. }
  17365. }
  17366. if (audioUnMuted === true || videoUnMuted === true) {
  17367. this._onunmute({
  17368. audio: audioUnMuted,
  17369. video: videoUnMuted
  17370. });
  17371. }
  17372. }
  17373. /**
  17374. * Hold
  17375. */
  17376. }, {
  17377. key: "hold",
  17378. value: function hold() {
  17379. var _this6 = this;
  17380. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17381. var done = arguments.length > 1 ? arguments[1] : undefined;
  17382. debug('hold()');
  17383. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  17384. return false;
  17385. }
  17386. if (this._localHold === true) {
  17387. return false;
  17388. }
  17389. if (!this._isReadyToReOffer()) {
  17390. return false;
  17391. }
  17392. this._localHold = true;
  17393. this._onhold('local');
  17394. var eventHandlers = {
  17395. succeeded: function succeeded() {
  17396. if (done) {
  17397. done();
  17398. }
  17399. },
  17400. failed: function failed() {
  17401. _this6.terminate({
  17402. cause: JsSIP_C.causes.WEBRTC_ERROR,
  17403. status_code: 500,
  17404. reason_phrase: 'Hold Failed'
  17405. });
  17406. }
  17407. };
  17408. if (options.useUpdate) {
  17409. this._sendUpdate({
  17410. sdpOffer: true,
  17411. eventHandlers: eventHandlers,
  17412. extraHeaders: options.extraHeaders
  17413. });
  17414. } else {
  17415. this._sendReinvite({
  17416. eventHandlers: eventHandlers,
  17417. extraHeaders: options.extraHeaders
  17418. });
  17419. }
  17420. return true;
  17421. }
  17422. }, {
  17423. key: "unhold",
  17424. value: function unhold() {
  17425. var _this7 = this;
  17426. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17427. var done = arguments.length > 1 ? arguments[1] : undefined;
  17428. debug('unhold()');
  17429. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  17430. return false;
  17431. }
  17432. if (this._localHold === false) {
  17433. return false;
  17434. }
  17435. if (!this._isReadyToReOffer()) {
  17436. return false;
  17437. }
  17438. this._localHold = false;
  17439. this._onunhold('local');
  17440. var eventHandlers = {
  17441. succeeded: function succeeded() {
  17442. if (done) {
  17443. done();
  17444. }
  17445. },
  17446. failed: function failed() {
  17447. _this7.terminate({
  17448. cause: JsSIP_C.causes.WEBRTC_ERROR,
  17449. status_code: 500,
  17450. reason_phrase: 'Unhold Failed'
  17451. });
  17452. }
  17453. };
  17454. if (options.useUpdate) {
  17455. this._sendUpdate({
  17456. sdpOffer: true,
  17457. eventHandlers: eventHandlers,
  17458. extraHeaders: options.extraHeaders
  17459. });
  17460. } else {
  17461. this._sendReinvite({
  17462. eventHandlers: eventHandlers,
  17463. extraHeaders: options.extraHeaders
  17464. });
  17465. }
  17466. return true;
  17467. }
  17468. }, {
  17469. key: "renegotiate",
  17470. value: function renegotiate() {
  17471. var _this8 = this;
  17472. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17473. var done = arguments.length > 1 ? arguments[1] : undefined;
  17474. debug('renegotiate()');
  17475. var rtcOfferConstraints = options.rtcOfferConstraints || null;
  17476. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  17477. return false;
  17478. }
  17479. if (!this._isReadyToReOffer()) {
  17480. return false;
  17481. }
  17482. var eventHandlers = {
  17483. succeeded: function succeeded() {
  17484. if (done) {
  17485. done();
  17486. }
  17487. },
  17488. failed: function failed() {
  17489. _this8.terminate({
  17490. cause: JsSIP_C.causes.WEBRTC_ERROR,
  17491. status_code: 500,
  17492. reason_phrase: 'Media Renegotiation Failed'
  17493. });
  17494. }
  17495. };
  17496. this._setLocalMediaStatus();
  17497. if (options.useUpdate) {
  17498. this._sendUpdate({
  17499. sdpOffer: true,
  17500. eventHandlers: eventHandlers,
  17501. rtcOfferConstraints: rtcOfferConstraints,
  17502. extraHeaders: options.extraHeaders
  17503. });
  17504. } else {
  17505. this._sendReinvite({
  17506. eventHandlers: eventHandlers,
  17507. rtcOfferConstraints: rtcOfferConstraints,
  17508. extraHeaders: options.extraHeaders
  17509. });
  17510. }
  17511. return true;
  17512. }
  17513. /**
  17514. * Refer
  17515. */
  17516. }, {
  17517. key: "refer",
  17518. value: function refer(target, options) {
  17519. var _this9 = this;
  17520. debug('refer()');
  17521. var originalTarget = target;
  17522. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  17523. return false;
  17524. } // Check target validity.
  17525. target = this._ua.normalizeTarget(target);
  17526. if (!target) {
  17527. throw new TypeError("Invalid target: ".concat(originalTarget));
  17528. }
  17529. var referSubscriber = new RTCSession_ReferSubscriber(this);
  17530. referSubscriber.sendRefer(target, options); // Store in the map.
  17531. var id = referSubscriber.id;
  17532. this._referSubscribers[id] = referSubscriber; // Listen for ending events so we can remove it from the map.
  17533. referSubscriber.on('requestFailed', function () {
  17534. delete _this9._referSubscribers[id];
  17535. });
  17536. referSubscriber.on('accepted', function () {
  17537. delete _this9._referSubscribers[id];
  17538. });
  17539. referSubscriber.on('failed', function () {
  17540. delete _this9._referSubscribers[id];
  17541. });
  17542. return referSubscriber;
  17543. }
  17544. /**
  17545. * Send a generic in-dialog Request
  17546. */
  17547. }, {
  17548. key: "sendRequest",
  17549. value: function sendRequest(method, options) {
  17550. debug('sendRequest()');
  17551. return this._dialog.sendRequest(method, options);
  17552. }
  17553. /**
  17554. * In dialog Request Reception
  17555. */
  17556. }, {
  17557. key: "receiveRequest",
  17558. value: function receiveRequest(request) {
  17559. var _this10 = this;
  17560. debug('receiveRequest()');
  17561. if (request.method === JsSIP_C.CANCEL) {
  17562. /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL
  17563. * was in progress and that the UAC MAY continue with the session established by
  17564. * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the
  17565. * established session. So the CANCEL is processed only if the session is not yet
  17566. * established.
  17567. */
  17568. /*
  17569. * Terminate the whole session in case the user didn't accept (or yet send the answer)
  17570. * nor reject the request opening the session.
  17571. */
  17572. if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) {
  17573. this._status = C.STATUS_CANCELED;
  17574. this._request.reply(487);
  17575. this._failed('remote', request, JsSIP_C.causes.CANCELED);
  17576. }
  17577. } else {
  17578. // Requests arriving here are in-dialog requests.
  17579. switch (request.method) {
  17580. case JsSIP_C.ACK:
  17581. if (this._status !== C.STATUS_WAITING_FOR_ACK) {
  17582. return;
  17583. } // Update signaling status.
  17584. this._status = C.STATUS_CONFIRMED;
  17585. clearTimeout(this._timers.ackTimer);
  17586. clearTimeout(this._timers.invite2xxTimer);
  17587. if (this._late_sdp) {
  17588. if (!request.body) {
  17589. this.terminate({
  17590. cause: JsSIP_C.causes.MISSING_SDP,
  17591. status_code: 400
  17592. });
  17593. break;
  17594. }
  17595. var e = {
  17596. originator: 'remote',
  17597. type: 'answer',
  17598. sdp: request.body
  17599. };
  17600. debug('emit "sdp"');
  17601. this.emit('sdp', e);
  17602. var answer = new RTCSessionDescription({
  17603. type: 'answer',
  17604. sdp: e.sdp
  17605. });
  17606. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  17607. return _this10._connection.setRemoteDescription(answer);
  17608. }).then(function () {
  17609. if (!_this10._is_confirmed) {
  17610. _this10._confirmed('remote', request);
  17611. }
  17612. }).catch(function (error) {
  17613. _this10.terminate({
  17614. cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION,
  17615. status_code: 488
  17616. });
  17617. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  17618. _this10.emit('peerconnection:setremotedescriptionfailed', error);
  17619. });
  17620. } else if (!this._is_confirmed) {
  17621. this._confirmed('remote', request);
  17622. }
  17623. break;
  17624. case JsSIP_C.BYE:
  17625. if (this._status === C.STATUS_CONFIRMED) {
  17626. request.reply(200);
  17627. this._ended('remote', request, JsSIP_C.causes.BYE);
  17628. } else if (this._status === C.STATUS_INVITE_RECEIVED) {
  17629. request.reply(200);
  17630. this._request.reply(487, 'BYE Received');
  17631. this._ended('remote', request, JsSIP_C.causes.BYE);
  17632. } else {
  17633. request.reply(403, 'Wrong Status');
  17634. }
  17635. break;
  17636. case JsSIP_C.INVITE:
  17637. if (this._status === C.STATUS_CONFIRMED) {
  17638. if (request.hasHeader('replaces')) {
  17639. this._receiveReplaces(request);
  17640. } else {
  17641. this._receiveReinvite(request);
  17642. }
  17643. } else {
  17644. request.reply(403, 'Wrong Status');
  17645. }
  17646. break;
  17647. case JsSIP_C.INFO:
  17648. if (this._status === C.STATUS_1XX_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED || this._status === C.STATUS_WAITING_FOR_ACK || this._status === C.STATUS_CONFIRMED) {
  17649. var contentType = request.getHeader('content-type');
  17650. if (contentType && contentType.match(/^application\/dtmf-relay/i)) {
  17651. new RTCSession_DTMF(this).init_incoming(request);
  17652. } else if (contentType !== undefined) {
  17653. new RTCSession_Info(this).init_incoming(request);
  17654. } else {
  17655. request.reply(415);
  17656. }
  17657. } else {
  17658. request.reply(403, 'Wrong Status');
  17659. }
  17660. break;
  17661. case JsSIP_C.UPDATE:
  17662. if (this._status === C.STATUS_CONFIRMED) {
  17663. this._receiveUpdate(request);
  17664. } else {
  17665. request.reply(403, 'Wrong Status');
  17666. }
  17667. break;
  17668. case JsSIP_C.REFER:
  17669. if (this._status === C.STATUS_CONFIRMED) {
  17670. this._receiveRefer(request);
  17671. } else {
  17672. request.reply(403, 'Wrong Status');
  17673. }
  17674. break;
  17675. case JsSIP_C.NOTIFY:
  17676. if (this._status === C.STATUS_CONFIRMED) {
  17677. this._receiveNotify(request);
  17678. } else {
  17679. request.reply(403, 'Wrong Status');
  17680. }
  17681. break;
  17682. default:
  17683. request.reply(501);
  17684. }
  17685. }
  17686. }
  17687. /**
  17688. * Session Callbacks
  17689. */
  17690. }, {
  17691. key: "onTransportError",
  17692. value: function onTransportError() {
  17693. debugerror('onTransportError()');
  17694. if (this._status !== C.STATUS_TERMINATED) {
  17695. this.terminate({
  17696. status_code: 500,
  17697. reason_phrase: JsSIP_C.causes.CONNECTION_ERROR,
  17698. cause: JsSIP_C.causes.CONNECTION_ERROR
  17699. });
  17700. }
  17701. }
  17702. }, {
  17703. key: "onRequestTimeout",
  17704. value: function onRequestTimeout() {
  17705. debugerror('onRequestTimeout()');
  17706. if (this._status !== C.STATUS_TERMINATED) {
  17707. this.terminate({
  17708. status_code: 408,
  17709. reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT,
  17710. cause: JsSIP_C.causes.REQUEST_TIMEOUT
  17711. });
  17712. }
  17713. }
  17714. }, {
  17715. key: "onDialogError",
  17716. value: function onDialogError() {
  17717. debugerror('onDialogError()');
  17718. if (this._status !== C.STATUS_TERMINATED) {
  17719. this.terminate({
  17720. status_code: 500,
  17721. reason_phrase: JsSIP_C.causes.DIALOG_ERROR,
  17722. cause: JsSIP_C.causes.DIALOG_ERROR
  17723. });
  17724. }
  17725. } // Called from DTMF handler.
  17726. }, {
  17727. key: "newDTMF",
  17728. value: function newDTMF(data) {
  17729. debug('newDTMF()');
  17730. this.emit('newDTMF', data);
  17731. } // Called from Info handler.
  17732. }, {
  17733. key: "newInfo",
  17734. value: function newInfo(data) {
  17735. debug('newInfo()');
  17736. this.emit('newInfo', data);
  17737. }
  17738. /**
  17739. * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP.
  17740. */
  17741. }, {
  17742. key: "_isReadyToReOffer",
  17743. value: function _isReadyToReOffer() {
  17744. if (!this._rtcReady) {
  17745. debug('_isReadyToReOffer() | internal WebRTC status not ready');
  17746. return false;
  17747. } // No established yet.
  17748. if (!this._dialog) {
  17749. debug('_isReadyToReOffer() | session not established yet');
  17750. return false;
  17751. } // Another INVITE transaction is in progress.
  17752. if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) {
  17753. debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress');
  17754. return false;
  17755. }
  17756. return true;
  17757. }
  17758. }, {
  17759. key: "_close",
  17760. value: function _close() {
  17761. debug('close()');
  17762. if (this._status === C.STATUS_TERMINATED) {
  17763. return;
  17764. }
  17765. this._status = C.STATUS_TERMINATED; // Terminate RTC.
  17766. if (this._connection) {
  17767. try {
  17768. this._connection.close();
  17769. } catch (error) {
  17770. debugerror('close() | error closing the RTCPeerConnection: %o', error);
  17771. }
  17772. } // Close local MediaStream if it was not given by the user.
  17773. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) {
  17774. debug('close() | closing local MediaStream');
  17775. Utils.closeMediaStream(this._localMediaStream);
  17776. } // Terminate signaling.
  17777. // Clear SIP timers.
  17778. for (var timer in this._timers) {
  17779. if (Object.prototype.hasOwnProperty.call(this._timers, timer)) {
  17780. clearTimeout(this._timers[timer]);
  17781. }
  17782. } // Clear Session Timers.
  17783. clearTimeout(this._sessionTimers.timer); // Terminate confirmed dialog.
  17784. if (this._dialog) {
  17785. this._dialog.terminate();
  17786. delete this._dialog;
  17787. } // Terminate early dialogs.
  17788. for (var dialog in this._earlyDialogs) {
  17789. if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) {
  17790. this._earlyDialogs[dialog].terminate();
  17791. delete this._earlyDialogs[dialog];
  17792. }
  17793. } // Terminate REFER subscribers.
  17794. for (var subscriber in this._referSubscribers) {
  17795. if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) {
  17796. delete this._referSubscribers[subscriber];
  17797. }
  17798. }
  17799. this._ua.destroyRTCSession(this);
  17800. }
  17801. /**
  17802. * Private API.
  17803. */
  17804. /**
  17805. * RFC3261 13.3.1.4
  17806. * Response retransmissions cannot be accomplished by transaction layer
  17807. * since it is destroyed when receiving the first 2xx answer
  17808. */
  17809. }, {
  17810. key: "_setInvite2xxTimer",
  17811. value: function _setInvite2xxTimer(request, body) {
  17812. var timeout = Timers.T1;
  17813. function invite2xxRetransmission() {
  17814. if (this._status !== C.STATUS_WAITING_FOR_ACK) {
  17815. return;
  17816. }
  17817. request.reply(200, null, ["Contact: ".concat(this._contact)], body);
  17818. if (timeout < Timers.T2) {
  17819. timeout = timeout * 2;
  17820. if (timeout > Timers.T2) {
  17821. timeout = Timers.T2;
  17822. }
  17823. }
  17824. this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
  17825. }
  17826. this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
  17827. }
  17828. /**
  17829. * RFC3261 14.2
  17830. * If a UAS generates a 2xx response and never receives an ACK,
  17831. * it SHOULD generate a BYE to terminate the dialog.
  17832. */
  17833. }, {
  17834. key: "_setACKTimer",
  17835. value: function _setACKTimer() {
  17836. var _this11 = this;
  17837. this._timers.ackTimer = setTimeout(function () {
  17838. if (_this11._status === C.STATUS_WAITING_FOR_ACK) {
  17839. debug('no ACK received, terminating the session');
  17840. clearTimeout(_this11._timers.invite2xxTimer);
  17841. _this11.sendRequest(JsSIP_C.BYE);
  17842. _this11._ended('remote', null, JsSIP_C.causes.NO_ACK);
  17843. }
  17844. }, Timers.TIMER_H);
  17845. }
  17846. }, {
  17847. key: "_createRTCConnection",
  17848. value: function _createRTCConnection(pcConfig, rtcConstraints) {
  17849. var _this12 = this;
  17850. this._connection = new RTCPeerConnection(pcConfig, rtcConstraints);
  17851. this._connection.addEventListener('iceconnectionstatechange', function () {
  17852. var state = _this12._connection.iceConnectionState; // TODO: Do more with different states.
  17853. if (state === 'failed') {
  17854. _this12.terminate({
  17855. cause: JsSIP_C.causes.RTP_TIMEOUT,
  17856. status_code: 408,
  17857. reason_phrase: JsSIP_C.causes.RTP_TIMEOUT
  17858. });
  17859. }
  17860. });
  17861. debug('emit "peerconnection"');
  17862. this.emit('peerconnection', {
  17863. peerconnection: this._connection
  17864. });
  17865. }
  17866. }, {
  17867. key: "_createLocalDescription",
  17868. value: function _createLocalDescription(type, constraints) {
  17869. var _this13 = this;
  17870. debug('createLocalDescription()');
  17871. if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\""));
  17872. var connection = this._connection;
  17873. this._rtcReady = false;
  17874. return Promise.resolve() // Create Offer or Answer.
  17875. .then(function () {
  17876. if (type === 'offer') {
  17877. return connection.createOffer(constraints).catch(function (error) {
  17878. debugerror('emit "peerconnection:createofferfailed" [error:%o]', error);
  17879. _this13.emit('peerconnection:createofferfailed', error);
  17880. return Promise.reject(error);
  17881. });
  17882. } else {
  17883. return connection.createAnswer(constraints).catch(function (error) {
  17884. debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error);
  17885. _this13.emit('peerconnection:createanswerfailed', error);
  17886. return Promise.reject(error);
  17887. });
  17888. }
  17889. }) // Set local description.
  17890. .then(function (desc) {
  17891. return connection.setLocalDescription(desc).catch(function (error) {
  17892. _this13._rtcReady = true;
  17893. debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error);
  17894. _this13.emit('peerconnection:setlocaldescriptionfailed', error);
  17895. return Promise.reject(error);
  17896. });
  17897. }).then(function () {
  17898. // Resolve right away if 'pc.iceGatheringState' is 'complete'.
  17899. if (connection.iceGatheringState === 'complete') {
  17900. _this13._rtcReady = true;
  17901. var e = {
  17902. originator: 'local',
  17903. type: type,
  17904. sdp: connection.localDescription.sdp
  17905. };
  17906. debug('emit "sdp"');
  17907. _this13.emit('sdp', e);
  17908. return Promise.resolve(e.sdp);
  17909. } // Add 'pc.onicencandidate' event handler to resolve on last candidate.
  17910. return new Promise(function (resolve) {
  17911. var finished = false;
  17912. var listener;
  17913. var ready = function ready() {
  17914. connection.removeEventListener('icecandidate', listener);
  17915. finished = true;
  17916. _this13._rtcReady = true;
  17917. var e = {
  17918. originator: 'local',
  17919. type: type,
  17920. sdp: connection.localDescription.sdp
  17921. };
  17922. debug('emit "sdp"');
  17923. _this13.emit('sdp', e);
  17924. resolve(e.sdp);
  17925. };
  17926. connection.addEventListener('icecandidate', listener = function listener(event) {
  17927. var candidate = event.candidate;
  17928. if (candidate) {
  17929. _this13.emit('icecandidate', {
  17930. candidate: candidate,
  17931. ready: ready
  17932. });
  17933. } else if (!finished) {
  17934. ready();
  17935. }
  17936. });
  17937. });
  17938. });
  17939. }
  17940. /**
  17941. * Dialog Management
  17942. */
  17943. }, {
  17944. key: "_createDialog",
  17945. value: function _createDialog(message, type, early) {
  17946. var local_tag = type === 'UAS' ? message.to_tag : message.from_tag;
  17947. var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag;
  17948. var id = message.call_id + local_tag + remote_tag;
  17949. var early_dialog = this._earlyDialogs[id]; // Early Dialog.
  17950. if (early) {
  17951. if (early_dialog) {
  17952. return true;
  17953. } else {
  17954. early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created.
  17955. if (early_dialog.error) {
  17956. debug(early_dialog.error);
  17957. this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  17958. return false;
  17959. } else {
  17960. this._earlyDialogs[id] = early_dialog;
  17961. return true;
  17962. }
  17963. }
  17964. } // Confirmed Dialog.
  17965. else {
  17966. this._from_tag = message.from_tag;
  17967. this._to_tag = message.to_tag; // In case the dialog is in _early_ state, update it.
  17968. if (early_dialog) {
  17969. early_dialog.update(message, type);
  17970. this._dialog = early_dialog;
  17971. delete this._earlyDialogs[id];
  17972. return true;
  17973. } // Otherwise, create a _confirmed_ dialog.
  17974. var dialog = new Dialog(this, message, type);
  17975. if (dialog.error) {
  17976. debug(dialog.error);
  17977. this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  17978. return false;
  17979. } else {
  17980. this._dialog = dialog;
  17981. return true;
  17982. }
  17983. }
  17984. }
  17985. /**
  17986. * In dialog INVITE Reception
  17987. */
  17988. }, {
  17989. key: "_receiveReinvite",
  17990. value: function _receiveReinvite(request) {
  17991. var _this14 = this;
  17992. debug('receiveReinvite()');
  17993. var contentType = request.getHeader('Content-Type');
  17994. var data = {
  17995. request: request,
  17996. callback: undefined,
  17997. reject: reject.bind(this)
  17998. };
  17999. var rejected = false;
  18000. function reject() {
  18001. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  18002. rejected = true;
  18003. var status_code = options.status_code || 403;
  18004. var reason_phrase = options.reason_phrase || '';
  18005. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  18006. if (this._status !== C.STATUS_CONFIRMED) {
  18007. return false;
  18008. }
  18009. if (status_code < 300 || status_code >= 700) {
  18010. throw new TypeError("Invalid status_code: ".concat(status_code));
  18011. }
  18012. request.reply(status_code, reason_phrase, extraHeaders);
  18013. } // Emit 'reinvite'.
  18014. this.emit('reinvite', data);
  18015. if (rejected) {
  18016. return;
  18017. }
  18018. this._late_sdp = false; // Request without SDP.
  18019. if (!request.body) {
  18020. this._late_sdp = true;
  18021. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  18022. return _this14._createLocalDescription('offer', _this14._rtcOfferConstraints);
  18023. }).then(function (sdp) {
  18024. sendAnswer.call(_this14, sdp);
  18025. }).catch(function () {
  18026. request.reply(500);
  18027. });
  18028. return;
  18029. } // Request with SDP.
  18030. if (contentType !== 'application/sdp') {
  18031. debug('invalid Content-Type');
  18032. request.reply(415);
  18033. return;
  18034. }
  18035. this._processInDialogSdpOffer(request) // Send answer.
  18036. .then(function (desc) {
  18037. if (_this14._status === C.STATUS_TERMINATED) {
  18038. return;
  18039. }
  18040. sendAnswer.call(_this14, desc);
  18041. }).catch(function (error) {
  18042. debugerror(error);
  18043. });
  18044. function sendAnswer(desc) {
  18045. var _this15 = this;
  18046. var extraHeaders = ["Contact: ".concat(this._contact)];
  18047. this._handleSessionTimersInIncomingRequest(request, extraHeaders);
  18048. if (this._late_sdp) {
  18049. desc = this._mangleOffer(desc);
  18050. }
  18051. request.reply(200, null, extraHeaders, desc, function () {
  18052. _this15._status = C.STATUS_WAITING_FOR_ACK;
  18053. _this15._setInvite2xxTimer(request, desc);
  18054. _this15._setACKTimer();
  18055. }); // If callback is given execute it.
  18056. if (typeof data.callback === 'function') {
  18057. data.callback();
  18058. }
  18059. }
  18060. }
  18061. /**
  18062. * In dialog UPDATE Reception
  18063. */
  18064. }, {
  18065. key: "_receiveUpdate",
  18066. value: function _receiveUpdate(request) {
  18067. var _this16 = this;
  18068. debug('receiveUpdate()');
  18069. var contentType = request.getHeader('Content-Type');
  18070. var data = {
  18071. request: request,
  18072. callback: undefined,
  18073. reject: reject.bind(this)
  18074. };
  18075. var rejected = false;
  18076. function reject() {
  18077. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  18078. rejected = true;
  18079. var status_code = options.status_code || 403;
  18080. var reason_phrase = options.reason_phrase || '';
  18081. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  18082. if (this._status !== C.STATUS_CONFIRMED) {
  18083. return false;
  18084. }
  18085. if (status_code < 300 || status_code >= 700) {
  18086. throw new TypeError("Invalid status_code: ".concat(status_code));
  18087. }
  18088. request.reply(status_code, reason_phrase, extraHeaders);
  18089. } // Emit 'update'.
  18090. this.emit('update', data);
  18091. if (rejected) {
  18092. return;
  18093. }
  18094. if (!request.body) {
  18095. sendAnswer.call(this, null);
  18096. return;
  18097. }
  18098. if (contentType !== 'application/sdp') {
  18099. debug('invalid Content-Type');
  18100. request.reply(415);
  18101. return;
  18102. }
  18103. this._processInDialogSdpOffer(request) // Send answer.
  18104. .then(function (desc) {
  18105. if (_this16._status === C.STATUS_TERMINATED) {
  18106. return;
  18107. }
  18108. sendAnswer.call(_this16, desc);
  18109. }).catch(function (error) {
  18110. debugerror(error);
  18111. });
  18112. function sendAnswer(desc) {
  18113. var extraHeaders = ["Contact: ".concat(this._contact)];
  18114. this._handleSessionTimersInIncomingRequest(request, extraHeaders);
  18115. request.reply(200, null, extraHeaders, desc); // If callback is given execute it.
  18116. if (typeof data.callback === 'function') {
  18117. data.callback();
  18118. }
  18119. }
  18120. }
  18121. }, {
  18122. key: "_processInDialogSdpOffer",
  18123. value: function _processInDialogSdpOffer(request) {
  18124. var _this17 = this;
  18125. debug('_processInDialogSdpOffer()');
  18126. var sdp = request.parseSDP();
  18127. var hold = false;
  18128. var _iteratorNormalCompletion4 = true;
  18129. var _didIteratorError4 = false;
  18130. var _iteratorError4 = undefined;
  18131. try {
  18132. for (var _iterator4 = sdp.media[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  18133. var m = _step4.value;
  18134. if (holdMediaTypes.indexOf(m.type) === -1) {
  18135. continue;
  18136. }
  18137. var direction = m.direction || sdp.direction || 'sendrecv';
  18138. if (direction === 'sendonly' || direction === 'inactive') {
  18139. hold = true;
  18140. } // If at least one of the streams is active don't emit 'hold'.
  18141. else {
  18142. hold = false;
  18143. break;
  18144. }
  18145. }
  18146. } catch (err) {
  18147. _didIteratorError4 = true;
  18148. _iteratorError4 = err;
  18149. } finally {
  18150. try {
  18151. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  18152. _iterator4.return();
  18153. }
  18154. } finally {
  18155. if (_didIteratorError4) {
  18156. throw _iteratorError4;
  18157. }
  18158. }
  18159. }
  18160. var e = {
  18161. originator: 'remote',
  18162. type: 'offer',
  18163. sdp: request.body
  18164. };
  18165. debug('emit "sdp"');
  18166. this.emit('sdp', e);
  18167. var offer = new RTCSessionDescription({
  18168. type: 'offer',
  18169. sdp: e.sdp
  18170. });
  18171. this._connectionPromiseQueue = this._connectionPromiseQueue // Set remote description.
  18172. .then(function () {
  18173. if (_this17._status === C.STATUS_TERMINATED) {
  18174. throw new Error('terminated');
  18175. }
  18176. return _this17._connection.setRemoteDescription(offer).catch(function (error) {
  18177. request.reply(488);
  18178. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  18179. _this17.emit('peerconnection:setremotedescriptionfailed', error);
  18180. throw new Error('peerconnection.setRemoteDescription() failed');
  18181. });
  18182. }).then(function () {
  18183. if (_this17._status === C.STATUS_TERMINATED) {
  18184. throw new Error('terminated');
  18185. }
  18186. if (_this17._remoteHold === true && hold === false) {
  18187. _this17._remoteHold = false;
  18188. _this17._onunhold('remote');
  18189. } else if (_this17._remoteHold === false && hold === true) {
  18190. _this17._remoteHold = true;
  18191. _this17._onhold('remote');
  18192. }
  18193. }) // Create local description.
  18194. .then(function () {
  18195. if (_this17._status === C.STATUS_TERMINATED) {
  18196. throw new Error('terminated');
  18197. }
  18198. return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints).catch(function () {
  18199. request.reply(500);
  18200. throw new Error('_createLocalDescription() failed');
  18201. });
  18202. });
  18203. return this._connectionPromiseQueue;
  18204. }
  18205. /**
  18206. * In dialog Refer Reception
  18207. */
  18208. }, {
  18209. key: "_receiveRefer",
  18210. value: function _receiveRefer(request) {
  18211. var _this18 = this;
  18212. debug('receiveRefer()');
  18213. if (!request.refer_to) {
  18214. debug('no Refer-To header field present in REFER');
  18215. request.reply(400);
  18216. return;
  18217. }
  18218. if (request.refer_to.uri.scheme !== JsSIP_C.SIP) {
  18219. debug('Refer-To header field points to a non-SIP URI scheme');
  18220. request.reply(416);
  18221. return;
  18222. } // Reply before the transaction timer expires.
  18223. request.reply(202);
  18224. var notifier = new RTCSession_ReferNotifier(this, request.cseq);
  18225. debug('emit "refer"'); // Emit 'refer'.
  18226. this.emit('refer', {
  18227. request: request,
  18228. accept: function accept(initCallback, options) {
  18229. _accept.call(_this18, initCallback, options);
  18230. },
  18231. reject: function reject() {
  18232. _reject.call(_this18);
  18233. }
  18234. });
  18235. function _accept(initCallback) {
  18236. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  18237. initCallback = typeof initCallback === 'function' ? initCallback : null;
  18238. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  18239. return false;
  18240. }
  18241. var session = new RTCSession(this._ua);
  18242. session.on('progress', function (_ref2) {
  18243. var response = _ref2.response;
  18244. notifier.notify(response.status_code, response.reason_phrase);
  18245. });
  18246. session.on('accepted', function (_ref3) {
  18247. var response = _ref3.response;
  18248. notifier.notify(response.status_code, response.reason_phrase);
  18249. });
  18250. session.on('_failed', function (_ref4) {
  18251. var message = _ref4.message,
  18252. cause = _ref4.cause;
  18253. if (message) {
  18254. notifier.notify(message.status_code, message.reason_phrase);
  18255. } else {
  18256. notifier.notify(487, cause);
  18257. }
  18258. }); // Consider the Replaces header present in the Refer-To URI.
  18259. if (request.refer_to.uri.hasHeader('replaces')) {
  18260. var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces'));
  18261. options.extraHeaders = Utils.cloneArray(options.extraHeaders);
  18262. options.extraHeaders.push("Replaces: ".concat(replaces));
  18263. }
  18264. session.connect(request.refer_to.uri.toAor(), options, initCallback);
  18265. }
  18266. function _reject() {
  18267. notifier.notify(603);
  18268. }
  18269. }
  18270. /**
  18271. * In dialog Notify Reception
  18272. */
  18273. }, {
  18274. key: "_receiveNotify",
  18275. value: function _receiveNotify(request) {
  18276. debug('receiveNotify()');
  18277. if (!request.event) {
  18278. request.reply(400);
  18279. }
  18280. switch (request.event.event) {
  18281. case 'refer':
  18282. {
  18283. var id;
  18284. var referSubscriber;
  18285. if (request.event.params && request.event.params.id) {
  18286. id = request.event.params.id;
  18287. referSubscriber = this._referSubscribers[id];
  18288. } else if (Object.keys(this._referSubscribers).length === 1) {
  18289. referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]];
  18290. } else {
  18291. request.reply(400, 'Missing event id parameter');
  18292. return;
  18293. }
  18294. if (!referSubscriber) {
  18295. request.reply(481, 'Subscription does not exist');
  18296. return;
  18297. }
  18298. referSubscriber.receiveNotify(request);
  18299. request.reply(200);
  18300. break;
  18301. }
  18302. default:
  18303. {
  18304. request.reply(489);
  18305. }
  18306. }
  18307. }
  18308. /**
  18309. * INVITE with Replaces Reception
  18310. */
  18311. }, {
  18312. key: "_receiveReplaces",
  18313. value: function _receiveReplaces(request) {
  18314. var _this20 = this;
  18315. debug('receiveReplaces()');
  18316. function _accept2(initCallback) {
  18317. var _this19 = this;
  18318. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  18319. return false;
  18320. }
  18321. var session = new RTCSession(this._ua); // Terminate the current session when the new one is confirmed.
  18322. session.on('confirmed', function () {
  18323. _this19.terminate();
  18324. });
  18325. session.init_incoming(request, initCallback);
  18326. }
  18327. function _reject2() {
  18328. debug('Replaced INVITE rejected by the user');
  18329. request.reply(486);
  18330. } // Emit 'replace'.
  18331. this.emit('replaces', {
  18332. request: request,
  18333. accept: function accept(initCallback) {
  18334. _accept2.call(_this20, initCallback);
  18335. },
  18336. reject: function reject() {
  18337. _reject2.call(_this20);
  18338. }
  18339. });
  18340. }
  18341. /**
  18342. * Initial Request Sender
  18343. */
  18344. }, {
  18345. key: "_sendInitialRequest",
  18346. value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) {
  18347. var _this21 = this;
  18348. var request_sender = new RequestSender(this._ua, this._request, {
  18349. onRequestTimeout: function onRequestTimeout() {
  18350. _this21.onRequestTimeout();
  18351. },
  18352. onTransportError: function onTransportError() {
  18353. _this21.onTransportError();
  18354. },
  18355. // Update the request on authentication.
  18356. onAuthenticated: function onAuthenticated(request) {
  18357. _this21._request = request;
  18358. },
  18359. onReceiveResponse: function onReceiveResponse(response) {
  18360. _this21._receiveInviteResponse(response);
  18361. }
  18362. }); // This Promise is resolved within the next iteration, so the app has now
  18363. // a chance to set events such as 'peerconnection' and 'connecting'.
  18364. Promise.resolve() // Get a stream if required.
  18365. .then(function () {
  18366. // A stream is given, let the app set events such as 'peerconnection' and 'connecting'.
  18367. if (mediaStream) {
  18368. return mediaStream;
  18369. } // Request for user media access.
  18370. else if (mediaConstraints.audio || mediaConstraints.video) {
  18371. _this21._localMediaStreamLocallyGenerated = true;
  18372. return navigator.mediaDevices.getUserMedia(mediaConstraints).catch(function (error) {
  18373. if (_this21._status === C.STATUS_TERMINATED) {
  18374. throw new Error('terminated');
  18375. }
  18376. _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  18377. debugerror('emit "getusermediafailed" [error:%o]', error);
  18378. _this21.emit('getusermediafailed', error);
  18379. throw error;
  18380. });
  18381. }
  18382. }).then(function (stream) {
  18383. if (_this21._status === C.STATUS_TERMINATED) {
  18384. throw new Error('terminated');
  18385. }
  18386. _this21._localMediaStream = stream;
  18387. if (stream) {
  18388. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  18389. if(isSafari) {
  18390. _this21._connection.addStream(stream);
  18391. } else {
  18392. stream.getTracks().forEach(function (track) {
  18393. _this21._connection.addTrack(track, stream);
  18394. });
  18395. }
  18396. } // TODO: should this be triggered here?
  18397. _this21._connecting(_this21._request);
  18398. return _this21._createLocalDescription('offer', rtcOfferConstraints).catch(function (error) {
  18399. _this21._failed('local', null, JsSIP_C.causes.WEBRTC_ERROR);
  18400. throw error;
  18401. });
  18402. }).then(function (desc) {
  18403. if (_this21._is_canceled || _this21._status === C.STATUS_TERMINATED) {
  18404. throw new Error('terminated');
  18405. }
  18406. _this21._request.body = desc;
  18407. _this21._status = C.STATUS_INVITE_SENT;
  18408. debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent.
  18409. _this21.emit('sending', {
  18410. request: _this21._request
  18411. });
  18412. request_sender.send();
  18413. }).catch(function (error) {
  18414. if (_this21._status === C.STATUS_TERMINATED) {
  18415. return;
  18416. }
  18417. debugerror(error);
  18418. });
  18419. }
  18420. /**
  18421. * Reception of Response for Initial INVITE
  18422. */
  18423. }, {
  18424. key: "_receiveInviteResponse",
  18425. value: function _receiveInviteResponse(response) {
  18426. var _this22 = this;
  18427. debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests.
  18428. if (this._dialog && response.status_code >= 200 && response.status_code <= 299) {
  18429. /*
  18430. * If it is a retransmission from the endpoint that established
  18431. * the dialog, send an ACK
  18432. */
  18433. if (this._dialog.id.call_id === response.call_id && this._dialog.id.local_tag === response.from_tag && this._dialog.id.remote_tag === response.to_tag) {
  18434. this.sendRequest(JsSIP_C.ACK);
  18435. return;
  18436. } // If not, send an ACK and terminate.
  18437. else {
  18438. var dialog = new Dialog(this, response, 'UAC');
  18439. if (dialog.error !== undefined) {
  18440. debug(dialog.error);
  18441. return;
  18442. }
  18443. this.sendRequest(JsSIP_C.ACK);
  18444. this.sendRequest(JsSIP_C.BYE);
  18445. return;
  18446. }
  18447. } // Proceed to cancellation if the user requested.
  18448. if (this._is_canceled) {
  18449. if (response.status_code >= 100 && response.status_code < 200) {
  18450. this._request.cancel(this._cancel_reason);
  18451. } else if (response.status_code >= 200 && response.status_code < 299) {
  18452. this._acceptAndTerminate(response);
  18453. }
  18454. return;
  18455. }
  18456. if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) {
  18457. return;
  18458. }
  18459. switch (true) {
  18460. case /^100$/.test(response.status_code):
  18461. this._status = C.STATUS_1XX_RECEIVED;
  18462. break;
  18463. case /^1[0-9]{2}$/.test(response.status_code):
  18464. {
  18465. // Do nothing with 1xx responses without To tag.
  18466. if (!response.to_tag) {
  18467. debug('1xx response received without to tag');
  18468. break;
  18469. } // Create Early Dialog if 1XX comes with contact.
  18470. if (response.hasHeader('contact')) {
  18471. // An error on dialog creation will fire 'failed' event.
  18472. if (!this._createDialog(response, 'UAC', true)) {
  18473. break;
  18474. }
  18475. }
  18476. this._status = C.STATUS_1XX_RECEIVED;
  18477. this._progress('remote', response);
  18478. if (!response.body) {
  18479. break;
  18480. }
  18481. var e = {
  18482. originator: 'remote',
  18483. type: 'answer',
  18484. sdp: response.body
  18485. };
  18486. debug('emit "sdp"');
  18487. this.emit('sdp', e);
  18488. var answer = new RTCSessionDescription({
  18489. type: 'answer',
  18490. sdp: e.sdp
  18491. });
  18492. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  18493. return _this22._connection.setRemoteDescription(answer);
  18494. }).catch(function (error) {
  18495. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  18496. _this22.emit('peerconnection:setremotedescriptionfailed', error);
  18497. });
  18498. break;
  18499. }
  18500. case /^2[0-9]{2}$/.test(response.status_code):
  18501. {
  18502. this._status = C.STATUS_CONFIRMED;
  18503. if (!response.body) {
  18504. this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP);
  18505. this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  18506. break;
  18507. } // An error on dialog creation will fire 'failed' event.
  18508. if (!this._createDialog(response, 'UAC')) {
  18509. break;
  18510. }
  18511. var _e = {
  18512. originator: 'remote',
  18513. type: 'answer',
  18514. sdp: response.body
  18515. };
  18516. debug('emit "sdp"');
  18517. this.emit('sdp', _e);
  18518. var _answer = new RTCSessionDescription({
  18519. type: 'answer',
  18520. sdp: _e.sdp
  18521. });
  18522. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  18523. // Be ready for 200 with SDP after a 180/183 with SDP.
  18524. // We created a SDP 'answer' for it, so check the current signaling state.
  18525. if (_this22._connection.signalingState === 'stable') {
  18526. return _this22._connection.createOffer(_this22._rtcOfferConstraints).then(function (offer) {
  18527. return _this22._connection.setLocalDescription(offer);
  18528. }).catch(function (error) {
  18529. _this22._acceptAndTerminate(response, 500, error.toString());
  18530. _this22._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR);
  18531. });
  18532. }
  18533. }).then(function () {
  18534. _this22._connection.setRemoteDescription(_answer).then(function () {
  18535. // Handle Session Timers.
  18536. _this22._handleSessionTimersInIncomingResponse(response);
  18537. _this22._accepted('remote', response);
  18538. _this22.sendRequest(JsSIP_C.ACK);
  18539. _this22._confirmed('local', null);
  18540. }).catch(function (error) {
  18541. _this22._acceptAndTerminate(response, 488, 'Not Acceptable Here');
  18542. _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  18543. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  18544. _this22.emit('peerconnection:setremotedescriptionfailed', error);
  18545. });
  18546. });
  18547. break;
  18548. }
  18549. default:
  18550. {
  18551. var cause = Utils.sipErrorCause(response.status_code);
  18552. this._failed('remote', response, cause);
  18553. }
  18554. }
  18555. }
  18556. /**
  18557. * Send Re-INVITE
  18558. */
  18559. }, {
  18560. key: "_sendReinvite",
  18561. value: function _sendReinvite() {
  18562. var _this23 = this;
  18563. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  18564. debug('sendReinvite()');
  18565. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  18566. var eventHandlers = options.eventHandlers || {};
  18567. var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
  18568. var succeeded = false;
  18569. extraHeaders.push("Contact: ".concat(this._contact));
  18570. extraHeaders.push('Content-Type: application/sdp'); // Session Timers.
  18571. if (this._sessionTimers.running) {
  18572. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas'));
  18573. }
  18574. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  18575. return _this23._createLocalDescription('offer', rtcOfferConstraints);
  18576. }).then(function (sdp) {
  18577. sdp = _this23._mangleOffer(sdp);
  18578. var e = {
  18579. originator: 'local',
  18580. type: 'offer',
  18581. sdp: sdp
  18582. };
  18583. debug('emit "sdp"');
  18584. _this23.emit('sdp', e);
  18585. _this23.sendRequest(JsSIP_C.INVITE, {
  18586. extraHeaders: extraHeaders,
  18587. body: sdp,
  18588. eventHandlers: {
  18589. onSuccessResponse: function onSuccessResponse(response) {
  18590. onSucceeded.call(_this23, response);
  18591. succeeded = true;
  18592. },
  18593. onErrorResponse: function onErrorResponse(response) {
  18594. onFailed.call(_this23, response);
  18595. },
  18596. onTransportError: function onTransportError() {
  18597. _this23.onTransportError(); // Do nothing because session ends.
  18598. },
  18599. onRequestTimeout: function onRequestTimeout() {
  18600. _this23.onRequestTimeout(); // Do nothing because session ends.
  18601. },
  18602. onDialogError: function onDialogError() {
  18603. _this23.onDialogError(); // Do nothing because session ends.
  18604. }
  18605. }
  18606. });
  18607. }).catch(function () {
  18608. onFailed();
  18609. });
  18610. function onSucceeded(response) {
  18611. var _this24 = this;
  18612. if (this._status === C.STATUS_TERMINATED) {
  18613. return;
  18614. }
  18615. this.sendRequest(JsSIP_C.ACK); // If it is a 2XX retransmission exit now.
  18616. if (succeeded) {
  18617. return;
  18618. } // Handle Session Timers.
  18619. this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer.
  18620. if (!response.body) {
  18621. onFailed.call(this);
  18622. return;
  18623. } else if (response.getHeader('Content-Type') !== 'application/sdp') {
  18624. onFailed.call(this);
  18625. return;
  18626. }
  18627. var e = {
  18628. originator: 'remote',
  18629. type: 'answer',
  18630. sdp: response.body
  18631. };
  18632. debug('emit "sdp"');
  18633. this.emit('sdp', e);
  18634. var answer = new RTCSessionDescription({
  18635. type: 'answer',
  18636. sdp: e.sdp
  18637. });
  18638. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  18639. return _this24._connection.setRemoteDescription(answer);
  18640. }).then(function () {
  18641. if (eventHandlers.succeeded) {
  18642. eventHandlers.succeeded(response);
  18643. }
  18644. }).catch(function (error) {
  18645. onFailed.call(_this24);
  18646. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  18647. _this24.emit('peerconnection:setremotedescriptionfailed', error);
  18648. });
  18649. }
  18650. function onFailed(response) {
  18651. if (eventHandlers.failed) {
  18652. eventHandlers.failed(response);
  18653. }
  18654. }
  18655. }
  18656. /**
  18657. * Send UPDATE
  18658. */
  18659. }, {
  18660. key: "_sendUpdate",
  18661. value: function _sendUpdate() {
  18662. var _this25 = this;
  18663. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  18664. debug('sendUpdate()');
  18665. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  18666. var eventHandlers = options.eventHandlers || {};
  18667. var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
  18668. var sdpOffer = options.sdpOffer || false;
  18669. var succeeded = false;
  18670. extraHeaders.push("Contact: ".concat(this._contact)); // Session Timers.
  18671. if (this._sessionTimers.running) {
  18672. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas'));
  18673. }
  18674. if (sdpOffer) {
  18675. extraHeaders.push('Content-Type: application/sdp');
  18676. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  18677. return _this25._createLocalDescription('offer', rtcOfferConstraints);
  18678. }).then(function (sdp) {
  18679. sdp = _this25._mangleOffer(sdp);
  18680. var e = {
  18681. originator: 'local',
  18682. type: 'offer',
  18683. sdp: sdp
  18684. };
  18685. debug('emit "sdp"');
  18686. _this25.emit('sdp', e);
  18687. _this25.sendRequest(JsSIP_C.UPDATE, {
  18688. extraHeaders: extraHeaders,
  18689. body: sdp,
  18690. eventHandlers: {
  18691. onSuccessResponse: function onSuccessResponse(response) {
  18692. onSucceeded.call(_this25, response);
  18693. succeeded = true;
  18694. },
  18695. onErrorResponse: function onErrorResponse(response) {
  18696. onFailed.call(_this25, response);
  18697. },
  18698. onTransportError: function onTransportError() {
  18699. _this25.onTransportError(); // Do nothing because session ends.
  18700. },
  18701. onRequestTimeout: function onRequestTimeout() {
  18702. _this25.onRequestTimeout(); // Do nothing because session ends.
  18703. },
  18704. onDialogError: function onDialogError() {
  18705. _this25.onDialogError(); // Do nothing because session ends.
  18706. }
  18707. }
  18708. });
  18709. }).catch(function () {
  18710. onFailed.call(_this25);
  18711. });
  18712. } // No SDP.
  18713. else {
  18714. this.sendRequest(JsSIP_C.UPDATE, {
  18715. extraHeaders: extraHeaders,
  18716. eventHandlers: {
  18717. onSuccessResponse: function onSuccessResponse(response) {
  18718. onSucceeded.call(_this25, response);
  18719. },
  18720. onErrorResponse: function onErrorResponse(response) {
  18721. onFailed.call(_this25, response);
  18722. },
  18723. onTransportError: function onTransportError() {
  18724. _this25.onTransportError(); // Do nothing because session ends.
  18725. },
  18726. onRequestTimeout: function onRequestTimeout() {
  18727. _this25.onRequestTimeout(); // Do nothing because session ends.
  18728. },
  18729. onDialogError: function onDialogError() {
  18730. _this25.onDialogError(); // Do nothing because session ends.
  18731. }
  18732. }
  18733. });
  18734. }
  18735. function onSucceeded(response) {
  18736. var _this26 = this;
  18737. if (this._status === C.STATUS_TERMINATED) {
  18738. return;
  18739. } // If it is a 2XX retransmission exit now.
  18740. if (succeeded) {
  18741. return;
  18742. } // Handle Session Timers.
  18743. this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer.
  18744. if (sdpOffer) {
  18745. if (!response.body) {
  18746. onFailed.call(this);
  18747. return;
  18748. } else if (response.getHeader('Content-Type') !== 'application/sdp') {
  18749. onFailed.call(this);
  18750. return;
  18751. }
  18752. var e = {
  18753. originator: 'remote',
  18754. type: 'answer',
  18755. sdp: response.body
  18756. };
  18757. debug('emit "sdp"');
  18758. this.emit('sdp', e);
  18759. var answer = new RTCSessionDescription({
  18760. type: 'answer',
  18761. sdp: e.sdp
  18762. });
  18763. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  18764. return _this26._connection.setRemoteDescription(answer);
  18765. }).then(function () {
  18766. if (eventHandlers.succeeded) {
  18767. eventHandlers.succeeded(response);
  18768. }
  18769. }).catch(function (error) {
  18770. onFailed.call(_this26);
  18771. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  18772. _this26.emit('peerconnection:setremotedescriptionfailed', error);
  18773. });
  18774. } // No SDP answer.
  18775. else if (eventHandlers.succeeded) {
  18776. eventHandlers.succeeded(response);
  18777. }
  18778. }
  18779. function onFailed(response) {
  18780. if (eventHandlers.failed) {
  18781. eventHandlers.failed(response);
  18782. }
  18783. }
  18784. }
  18785. }, {
  18786. key: "_acceptAndTerminate",
  18787. value: function _acceptAndTerminate(response, status_code, reason_phrase) {
  18788. debug('acceptAndTerminate()');
  18789. var extraHeaders = [];
  18790. if (status_code) {
  18791. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  18792. extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\""));
  18793. } // An error on dialog creation will fire 'failed' event.
  18794. if (this._dialog || this._createDialog(response, 'UAC')) {
  18795. this.sendRequest(JsSIP_C.ACK);
  18796. this.sendRequest(JsSIP_C.BYE, {
  18797. extraHeaders: extraHeaders
  18798. });
  18799. } // Update session status.
  18800. this._status = C.STATUS_TERMINATED;
  18801. }
  18802. /**
  18803. * Correctly set the SDP direction attributes if the call is on local hold
  18804. */
  18805. }, {
  18806. key: "_mangleOffer",
  18807. value: function _mangleOffer(sdp) {
  18808. if (!this._localHold && !this._remoteHold) {
  18809. return sdp;
  18810. }
  18811. sdp = sdp_transform.parse(sdp); // Local hold.
  18812. if (this._localHold && !this._remoteHold) {
  18813. debug('mangleOffer() | me on hold, mangling offer');
  18814. var _iteratorNormalCompletion5 = true;
  18815. var _didIteratorError5 = false;
  18816. var _iteratorError5 = undefined;
  18817. try {
  18818. for (var _iterator5 = sdp.media[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  18819. var m = _step5.value;
  18820. if (holdMediaTypes.indexOf(m.type) === -1) {
  18821. continue;
  18822. }
  18823. if (!m.direction) {
  18824. m.direction = 'sendonly';
  18825. } else if (m.direction === 'sendrecv') {
  18826. m.direction = 'sendonly';
  18827. } else if (m.direction === 'recvonly') {
  18828. m.direction = 'inactive';
  18829. }
  18830. }
  18831. } catch (err) {
  18832. _didIteratorError5 = true;
  18833. _iteratorError5 = err;
  18834. } finally {
  18835. try {
  18836. if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
  18837. _iterator5.return();
  18838. }
  18839. } finally {
  18840. if (_didIteratorError5) {
  18841. throw _iteratorError5;
  18842. }
  18843. }
  18844. }
  18845. } // Local and remote hold.
  18846. else if (this._localHold && this._remoteHold) {
  18847. debug('mangleOffer() | both on hold, mangling offer');
  18848. var _iteratorNormalCompletion6 = true;
  18849. var _didIteratorError6 = false;
  18850. var _iteratorError6 = undefined;
  18851. try {
  18852. for (var _iterator6 = sdp.media[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
  18853. var _m = _step6.value;
  18854. if (holdMediaTypes.indexOf(_m.type) === -1) {
  18855. continue;
  18856. }
  18857. _m.direction = 'inactive';
  18858. }
  18859. } catch (err) {
  18860. _didIteratorError6 = true;
  18861. _iteratorError6 = err;
  18862. } finally {
  18863. try {
  18864. if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
  18865. _iterator6.return();
  18866. }
  18867. } finally {
  18868. if (_didIteratorError6) {
  18869. throw _iteratorError6;
  18870. }
  18871. }
  18872. }
  18873. } // Remote hold.
  18874. else if (this._remoteHold) {
  18875. debug('mangleOffer() | remote on hold, mangling offer');
  18876. var _iteratorNormalCompletion7 = true;
  18877. var _didIteratorError7 = false;
  18878. var _iteratorError7 = undefined;
  18879. try {
  18880. for (var _iterator7 = sdp.media[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
  18881. var _m2 = _step7.value;
  18882. if (holdMediaTypes.indexOf(_m2.type) === -1) {
  18883. continue;
  18884. }
  18885. if (!_m2.direction) {
  18886. _m2.direction = 'recvonly';
  18887. } else if (_m2.direction === 'sendrecv') {
  18888. _m2.direction = 'recvonly';
  18889. } else if (_m2.direction === 'recvonly') {
  18890. _m2.direction = 'inactive';
  18891. }
  18892. }
  18893. } catch (err) {
  18894. _didIteratorError7 = true;
  18895. _iteratorError7 = err;
  18896. } finally {
  18897. try {
  18898. if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
  18899. _iterator7.return();
  18900. }
  18901. } finally {
  18902. if (_didIteratorError7) {
  18903. throw _iteratorError7;
  18904. }
  18905. }
  18906. }
  18907. }
  18908. return sdp_transform.write(sdp);
  18909. }
  18910. }, {
  18911. key: "_setLocalMediaStatus",
  18912. value: function _setLocalMediaStatus() {
  18913. var enableAudio = true,
  18914. enableVideo = true;
  18915. if (this._localHold || this._remoteHold) {
  18916. enableAudio = false;
  18917. enableVideo = false;
  18918. }
  18919. if (this._audioMuted) {
  18920. enableAudio = false;
  18921. }
  18922. if (this._videoMuted) {
  18923. enableVideo = false;
  18924. }
  18925. this._toggleMuteAudio(!enableAudio);
  18926. this._toggleMuteVideo(!enableVideo);
  18927. }
  18928. /**
  18929. * Handle SessionTimers for an incoming INVITE or UPDATE.
  18930. * @param {IncomingRequest} request
  18931. * @param {Array} responseExtraHeaders Extra headers for the 200 response.
  18932. */
  18933. }, {
  18934. key: "_handleSessionTimersInIncomingRequest",
  18935. value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) {
  18936. if (!this._sessionTimers.enabled) {
  18937. return;
  18938. }
  18939. var session_expires_refresher;
  18940. if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  18941. this._sessionTimers.currentExpires = request.session_expires;
  18942. session_expires_refresher = request.session_expires_refresher || 'uas';
  18943. } else {
  18944. this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
  18945. session_expires_refresher = 'uas';
  18946. }
  18947. responseExtraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(session_expires_refresher));
  18948. this._sessionTimers.refresher = session_expires_refresher === 'uas';
  18949. this._runSessionTimer();
  18950. }
  18951. /**
  18952. * Handle SessionTimers for an incoming response to INVITE or UPDATE.
  18953. * @param {IncomingResponse} response
  18954. */
  18955. }, {
  18956. key: "_handleSessionTimersInIncomingResponse",
  18957. value: function _handleSessionTimersInIncomingResponse(response) {
  18958. if (!this._sessionTimers.enabled) {
  18959. return;
  18960. }
  18961. var session_expires_refresher;
  18962. if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  18963. this._sessionTimers.currentExpires = response.session_expires;
  18964. session_expires_refresher = response.session_expires_refresher || 'uac';
  18965. } else {
  18966. this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
  18967. session_expires_refresher = 'uac';
  18968. }
  18969. this._sessionTimers.refresher = session_expires_refresher === 'uac';
  18970. this._runSessionTimer();
  18971. }
  18972. }, {
  18973. key: "_runSessionTimer",
  18974. value: function _runSessionTimer() {
  18975. var _this27 = this;
  18976. var expires = this._sessionTimers.currentExpires;
  18977. this._sessionTimers.running = true;
  18978. clearTimeout(this._sessionTimers.timer); // I'm the refresher.
  18979. if (this._sessionTimers.refresher) {
  18980. this._sessionTimers.timer = setTimeout(function () {
  18981. if (_this27._status === C.STATUS_TERMINATED) {
  18982. return;
  18983. }
  18984. debug('runSessionTimer() | sending session refresh request');
  18985. if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) {
  18986. _this27._sendUpdate();
  18987. } else {
  18988. _this27._sendReinvite();
  18989. }
  18990. }, expires * 500); // Half the given interval (as the RFC states).
  18991. } // I'm not the refresher.
  18992. else {
  18993. this._sessionTimers.timer = setTimeout(function () {
  18994. if (_this27._status === C.STATUS_TERMINATED) {
  18995. return;
  18996. }
  18997. debugerror('runSessionTimer() | timer expired, terminating the session');
  18998. _this27.terminate({
  18999. cause: JsSIP_C.causes.REQUEST_TIMEOUT,
  19000. status_code: 408,
  19001. reason_phrase: 'Session Timer Expired'
  19002. });
  19003. }, expires * 1100);
  19004. }
  19005. }
  19006. }, {
  19007. key: "_toggleMuteAudio",
  19008. value: function _toggleMuteAudio(mute) {
  19009. var senders = this._connection.getSenders().filter(function (sender) {
  19010. return sender.track && sender.track.kind === 'audio';
  19011. });
  19012. var _iteratorNormalCompletion8 = true;
  19013. var _didIteratorError8 = false;
  19014. var _iteratorError8 = undefined;
  19015. try {
  19016. for (var _iterator8 = senders[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
  19017. var sender = _step8.value;
  19018. sender.track.enabled = !mute;
  19019. }
  19020. } catch (err) {
  19021. _didIteratorError8 = true;
  19022. _iteratorError8 = err;
  19023. } finally {
  19024. try {
  19025. if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
  19026. _iterator8.return();
  19027. }
  19028. } finally {
  19029. if (_didIteratorError8) {
  19030. throw _iteratorError8;
  19031. }
  19032. }
  19033. }
  19034. }
  19035. }, {
  19036. key: "_toggleMuteVideo",
  19037. value: function _toggleMuteVideo(mute) {
  19038. var senders = this._connection.getSenders().filter(function (sender) {
  19039. return sender.track && sender.track.kind === 'video';
  19040. });
  19041. var _iteratorNormalCompletion9 = true;
  19042. var _didIteratorError9 = false;
  19043. var _iteratorError9 = undefined;
  19044. try {
  19045. for (var _iterator9 = senders[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
  19046. var sender = _step9.value;
  19047. sender.track.enabled = !mute;
  19048. }
  19049. } catch (err) {
  19050. _didIteratorError9 = true;
  19051. _iteratorError9 = err;
  19052. } finally {
  19053. try {
  19054. if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
  19055. _iterator9.return();
  19056. }
  19057. } finally {
  19058. if (_didIteratorError9) {
  19059. throw _iteratorError9;
  19060. }
  19061. }
  19062. }
  19063. }
  19064. }, {
  19065. key: "_newRTCSession",
  19066. value: function _newRTCSession(originator, request) {
  19067. debug('newRTCSession()');
  19068. // const sessionId = request.call_id;
  19069. // request.extraHeaders.push('Transaction-ID: ' + sessionId)
  19070. PhoneNetwork.test();
  19071. PhoneLogger.info({
  19072. event: 'newRTCSession',
  19073. data: {
  19074. originator: originator,
  19075. session: this,
  19076. request: request
  19077. }
  19078. });
  19079. this._ua.newRTCSession(this, {
  19080. originator: originator,
  19081. session: this,
  19082. request: request
  19083. });
  19084. }
  19085. }, {
  19086. key: "_connecting",
  19087. value: function _connecting(request) {
  19088. debug('session connecting');
  19089. debug('emit "connecting"');
  19090. PhoneLogger.info({
  19091. event: 'connecting',
  19092. data: {
  19093. request: request
  19094. }
  19095. });
  19096. this.emit('connecting', {
  19097. request: request
  19098. });
  19099. console.log('connecting A :'+request)
  19100. }
  19101. }, {
  19102. key: "_progress",
  19103. value: function _progress(originator, response) {
  19104. debug('session progress');
  19105. debug('emit "progress"');
  19106. PhoneLogger.info({
  19107. event: 'progress',
  19108. data: {
  19109. originator: originator,
  19110. response: response || null
  19111. }
  19112. });
  19113. this.emit('progress', {
  19114. originator: originator,
  19115. response: response || null
  19116. });
  19117. }
  19118. }, {
  19119. key: "_accepted",
  19120. value: function _accepted(originator, message) {
  19121. debug('session accepted');
  19122. this._start_time = new Date();
  19123. debug('emit "accepted"');
  19124. PhoneLogger.info({
  19125. event: 'accepted',
  19126. data: {
  19127. originator: originator,
  19128. response: message || null
  19129. }
  19130. });
  19131. this.emit('accepted', {
  19132. originator: originator,
  19133. response: message || null
  19134. });
  19135. }
  19136. }, {
  19137. key: "_confirmed",
  19138. value: function _confirmed(originator, ack) {
  19139. debug('session confirmed');
  19140. this._is_confirmed = true;
  19141. debug('emit "confirmed"');
  19142. PhoneLogger.info({
  19143. event: 'confirmed',
  19144. data: {
  19145. originator: originator,
  19146. ack: ack || null
  19147. }
  19148. });
  19149. this.emit('confirmed', {
  19150. originator: originator,
  19151. ack: ack || null
  19152. });
  19153. }
  19154. }, {
  19155. key: "_ended",
  19156. value: function _ended(originator, message, cause) {
  19157. debug('session ended');
  19158. this._end_time = new Date();
  19159. this._close();
  19160. debug('emit "ended"');
  19161. PhoneLogger.info({
  19162. event: 'ended',
  19163. data: {
  19164. originator: originator,
  19165. message: message || null,
  19166. cause: cause
  19167. }
  19168. });
  19169. this.emit('ended', {
  19170. originator: originator,
  19171. message: message || null,
  19172. cause: cause
  19173. });
  19174. }
  19175. }, {
  19176. key: "_failed",
  19177. value: function _failed(originator, message, cause) {
  19178. debug('session failed'); // Emit private '_failed' event first.
  19179. debug('emit "_failed"');
  19180. this.emit('_failed', {
  19181. originator: originator,
  19182. message: message || null,
  19183. cause: cause
  19184. });
  19185. this._close();
  19186. PhoneLogger.error({
  19187. event: 'sessionFailed',
  19188. data: {
  19189. originator: originator,
  19190. message: message || null,
  19191. cause: cause
  19192. }
  19193. });
  19194. debug('emit "failed"');
  19195. this.emit('failed', {
  19196. originator: originator,
  19197. message: message || null,
  19198. cause: cause
  19199. });
  19200. }
  19201. }, {
  19202. key: "_onhold",
  19203. value: function _onhold(originator) {
  19204. debug('session onhold');
  19205. this._setLocalMediaStatus();
  19206. debug('emit "hold"');
  19207. this.emit('hold', {
  19208. originator: originator
  19209. });
  19210. }
  19211. }, {
  19212. key: "_onunhold",
  19213. value: function _onunhold(originator) {
  19214. debug('session onunhold');
  19215. this._setLocalMediaStatus();
  19216. debug('emit "unhold"');
  19217. this.emit('unhold', {
  19218. originator: originator
  19219. });
  19220. }
  19221. }, {
  19222. key: "_onmute",
  19223. value: function _onmute(_ref5) {
  19224. var audio = _ref5.audio,
  19225. video = _ref5.video;
  19226. debug('session onmute');
  19227. this._setLocalMediaStatus();
  19228. debug('emit "muted"');
  19229. this.emit('muted', {
  19230. audio: audio,
  19231. video: video
  19232. });
  19233. }
  19234. }, {
  19235. key: "_onunmute",
  19236. value: function _onunmute(_ref6) {
  19237. var audio = _ref6.audio,
  19238. video = _ref6.video;
  19239. debug('session onunmute');
  19240. this._setLocalMediaStatus();
  19241. debug('emit "unmuted"');
  19242. this.emit('unmuted', {
  19243. audio: audio,
  19244. video: video
  19245. });
  19246. }
  19247. }, {
  19248. key: "C",
  19249. get: function get() {
  19250. return C;
  19251. } // Expose session failed/ended causes as a property of the RTCSession instance.
  19252. }, {
  19253. key: "causes",
  19254. get: function get() {
  19255. return JsSIP_C.causes;
  19256. }
  19257. }, {
  19258. key: "id",
  19259. get: function get() {
  19260. return this._id;
  19261. }
  19262. }, {
  19263. key: "connection",
  19264. get: function get() {
  19265. return this._connection;
  19266. }
  19267. }, {
  19268. key: "contact",
  19269. get: function get() {
  19270. return this._contact;
  19271. }
  19272. }, {
  19273. key: "direction",
  19274. get: function get() {
  19275. return this._direction;
  19276. }
  19277. }, {
  19278. key: "local_identity",
  19279. get: function get() {
  19280. return this._local_identity;
  19281. }
  19282. }, {
  19283. key: "remote_identity",
  19284. get: function get() {
  19285. return this._remote_identity;
  19286. }
  19287. }, {
  19288. key: "start_time",
  19289. get: function get() {
  19290. return this._start_time;
  19291. }
  19292. }, {
  19293. key: "end_time",
  19294. get: function get() {
  19295. return this._end_time;
  19296. }
  19297. }, {
  19298. key: "data",
  19299. get: function get() {
  19300. return this._data;
  19301. },
  19302. set: function set(_data) {
  19303. this._data = _data;
  19304. }
  19305. }, {
  19306. key: "status",
  19307. get: function get() {
  19308. return this._status;
  19309. }
  19310. }]);
  19311. return RTCSession;
  19312. }(EventEmitter);
  19313. }),
  19314. /* 18 */
  19315. (function(module, exports, __webpack_require__) {
  19316. "use strict";
  19317. var Utils = __webpack_require__(2);
  19318. var Grammar = __webpack_require__(3);
  19319. var debugerror = __webpack_require__(0)('JsSIP:ERROR:Socket');
  19320. debugerror.log = console.warn.bind(console);
  19321. /**
  19322. * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/
  19323. *
  19324. * interface Socket {
  19325. * attribute String via_transport
  19326. * attribute String url
  19327. * attribute String sip_uri
  19328. *
  19329. * method connect();
  19330. * method disconnect();
  19331. * method send(data);
  19332. *
  19333. * attribute EventHandler onconnect
  19334. * attribute EventHandler ondisconnect
  19335. * attribute EventHandler ondata
  19336. * }
  19337. *
  19338. */
  19339. exports.isSocket = function (socket) {
  19340. // Ignore if an array is given.
  19341. if (Array.isArray(socket)) {
  19342. return false;
  19343. }
  19344. if (typeof socket === 'undefined') {
  19345. debugerror('undefined JsSIP.Socket instance');
  19346. return false;
  19347. } // Check Properties.
  19348. try {
  19349. if (!Utils.isString(socket.url)) {
  19350. debugerror('missing or invalid JsSIP.Socket url property');
  19351. throw new Error();
  19352. }
  19353. if (!Utils.isString(socket.via_transport)) {
  19354. debugerror('missing or invalid JsSIP.Socket via_transport property');
  19355. throw new Error();
  19356. }
  19357. if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) {
  19358. debugerror('missing or invalid JsSIP.Socket sip_uri property');
  19359. throw new Error();
  19360. }
  19361. } catch (e) {
  19362. return false;
  19363. } // Check Methods.
  19364. try {
  19365. ['connect', 'disconnect', 'send'].forEach(function (method) {
  19366. if (!Utils.isFunction(socket[method])) {
  19367. debugerror("missing or invalid JsSIP.Socket method: ".concat(method));
  19368. throw new Error();
  19369. }
  19370. });
  19371. } catch (e) {
  19372. return false;
  19373. }
  19374. return true;
  19375. };
  19376. }),
  19377. /* 19 */
  19378. (function(module, exports, __webpack_require__) {
  19379. "use strict";
  19380. /* eslint-env node */
  19381. // SDP helpers.
  19382. var SDPUtils = {}; // Generate an alphanumeric identifier for cname or mids.
  19383. // TODO: use UUIDs instead? https://gist.github.com/jed/982883
  19384. SDPUtils.generateIdentifier = function () {
  19385. return Math.random().toString(36).substr(2, 10);
  19386. }; // The RTCP CNAME used by all peerconnections from the same JS.
  19387. SDPUtils.localCName = SDPUtils.generateIdentifier(); // Splits SDP into lines, dealing with both CRLF and LF.
  19388. SDPUtils.splitLines = function (blob) {
  19389. return blob.trim().split('\n').map(function (line) {
  19390. return line.trim();
  19391. });
  19392. }; // Splits SDP into sessionpart and mediasections. Ensures CRLF.
  19393. SDPUtils.splitSections = function (blob) {
  19394. var parts = blob.split('\nm=');
  19395. return parts.map(function (part, index) {
  19396. return (index > 0 ? 'm=' + part : part).trim() + '\r\n';
  19397. });
  19398. }; // returns the session description.
  19399. SDPUtils.getDescription = function (blob) {
  19400. var sections = SDPUtils.splitSections(blob);
  19401. return sections && sections[0];
  19402. }; // returns the individual media sections.
  19403. SDPUtils.getMediaSections = function (blob) {
  19404. var sections = SDPUtils.splitSections(blob);
  19405. sections.shift();
  19406. return sections;
  19407. }; // Returns lines that start with a certain prefix.
  19408. SDPUtils.matchPrefix = function (blob, prefix) {
  19409. return SDPUtils.splitLines(blob).filter(function (line) {
  19410. return line.indexOf(prefix) === 0;
  19411. });
  19412. }; // Parses an ICE candidate line. Sample input:
  19413. // candidate:702786350 2 udp 41819902 8.8.8.8 60769 typ relay raddr 8.8.8.8
  19414. // rport 55996"
  19415. SDPUtils.parseCandidate = function (line) {
  19416. var parts; // Parse both variants.
  19417. if (line.indexOf('a=candidate:') === 0) {
  19418. parts = line.substring(12).split(' ');
  19419. } else {
  19420. parts = line.substring(10).split(' ');
  19421. }
  19422. var candidate = {
  19423. foundation: parts[0],
  19424. component: parseInt(parts[1], 10),
  19425. protocol: parts[2].toLowerCase(),
  19426. priority: parseInt(parts[3], 10),
  19427. ip: parts[4],
  19428. address: parts[4],
  19429. // address is an alias for ip.
  19430. port: parseInt(parts[5], 10),
  19431. // skip parts[6] == 'typ'
  19432. type: parts[7]
  19433. };
  19434. for (var i = 8; i < parts.length; i += 2) {
  19435. switch (parts[i]) {
  19436. case 'raddr':
  19437. candidate.relatedAddress = parts[i + 1];
  19438. break;
  19439. case 'rport':
  19440. candidate.relatedPort = parseInt(parts[i + 1], 10);
  19441. break;
  19442. case 'tcptype':
  19443. candidate.tcpType = parts[i + 1];
  19444. break;
  19445. case 'ufrag':
  19446. candidate.ufrag = parts[i + 1]; // for backward compability.
  19447. candidate.usernameFragment = parts[i + 1];
  19448. break;
  19449. default:
  19450. // extension handling, in particular ufrag
  19451. candidate[parts[i]] = parts[i + 1];
  19452. break;
  19453. }
  19454. }
  19455. return candidate;
  19456. }; // Translates a candidate object into SDP candidate attribute.
  19457. SDPUtils.writeCandidate = function (candidate) {
  19458. var sdp = [];
  19459. sdp.push(candidate.foundation);
  19460. sdp.push(candidate.component);
  19461. sdp.push(candidate.protocol.toUpperCase());
  19462. sdp.push(candidate.priority);
  19463. sdp.push(candidate.address || candidate.ip);
  19464. sdp.push(candidate.port);
  19465. var type = candidate.type;
  19466. sdp.push('typ');
  19467. sdp.push(type);
  19468. if (type !== 'host' && candidate.relatedAddress && candidate.relatedPort) {
  19469. sdp.push('raddr');
  19470. sdp.push(candidate.relatedAddress);
  19471. sdp.push('rport');
  19472. sdp.push(candidate.relatedPort);
  19473. }
  19474. if (candidate.tcpType && candidate.protocol.toLowerCase() === 'tcp') {
  19475. sdp.push('tcptype');
  19476. sdp.push(candidate.tcpType);
  19477. }
  19478. if (candidate.usernameFragment || candidate.ufrag) {
  19479. sdp.push('ufrag');
  19480. sdp.push(candidate.usernameFragment || candidate.ufrag);
  19481. }
  19482. return 'candidate:' + sdp.join(' ');
  19483. }; // Parses an ice-options line, returns an array of option tags.
  19484. // a=ice-options:foo bar
  19485. SDPUtils.parseIceOptions = function (line) {
  19486. return line.substr(14).split(' ');
  19487. }; // Parses an rtpmap line, returns RTCRtpCoddecParameters. Sample input:
  19488. // a=rtpmap:111 opus/48000/2
  19489. SDPUtils.parseRtpMap = function (line) {
  19490. var parts = line.substr(9).split(' ');
  19491. var parsed = {
  19492. payloadType: parseInt(parts.shift(), 10) // was: id
  19493. };
  19494. parts = parts[0].split('/');
  19495. parsed.name = parts[0];
  19496. parsed.clockRate = parseInt(parts[1], 10); // was: clockrate
  19497. parsed.channels = parts.length === 3 ? parseInt(parts[2], 10) : 1; // legacy alias, got renamed back to channels in ORTC.
  19498. parsed.numChannels = parsed.channels;
  19499. return parsed;
  19500. }; // Generate an a=rtpmap line from RTCRtpCodecCapability or
  19501. // RTCRtpCodecParameters.
  19502. SDPUtils.writeRtpMap = function (codec) {
  19503. var pt = codec.payloadType;
  19504. if (codec.preferredPayloadType !== undefined) {
  19505. pt = codec.preferredPayloadType;
  19506. }
  19507. var channels = codec.channels || codec.numChannels || 1;
  19508. return 'a=rtpmap:' + pt + ' ' + codec.name + '/' + codec.clockRate + (channels !== 1 ? '/' + channels : '') + '\r\n';
  19509. }; // Parses an a=extmap line (headerextension from RFC 5285). Sample input:
  19510. // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  19511. // a=extmap:2/sendonly urn:ietf:params:rtp-hdrext:toffset
  19512. SDPUtils.parseExtmap = function (line) {
  19513. var parts = line.substr(9).split(' ');
  19514. return {
  19515. id: parseInt(parts[0], 10),
  19516. direction: parts[0].indexOf('/') > 0 ? parts[0].split('/')[1] : 'sendrecv',
  19517. uri: parts[1]
  19518. };
  19519. }; // Generates a=extmap line from RTCRtpHeaderExtensionParameters or
  19520. // RTCRtpHeaderExtension.
  19521. SDPUtils.writeExtmap = function (headerExtension) {
  19522. return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) + (headerExtension.direction && headerExtension.direction !== 'sendrecv' ? '/' + headerExtension.direction : '') + ' ' + headerExtension.uri + '\r\n';
  19523. }; // Parses an ftmp line, returns dictionary. Sample input:
  19524. // a=fmtp:96 vbr=on;cng=on
  19525. // Also deals with vbr=on; cng=on
  19526. SDPUtils.parseFmtp = function (line) {
  19527. var parsed = {};
  19528. var kv;
  19529. var parts = line.substr(line.indexOf(' ') + 1).split(';');
  19530. for (var j = 0; j < parts.length; j++) {
  19531. kv = parts[j].trim().split('=');
  19532. parsed[kv[0].trim()] = kv[1];
  19533. }
  19534. return parsed;
  19535. }; // Generates an a=ftmp line from RTCRtpCodecCapability or RTCRtpCodecParameters.
  19536. SDPUtils.writeFmtp = function (codec) {
  19537. var line = '';
  19538. var pt = codec.payloadType;
  19539. if (codec.preferredPayloadType !== undefined) {
  19540. pt = codec.preferredPayloadType;
  19541. }
  19542. if (codec.parameters && Object.keys(codec.parameters).length) {
  19543. var params = [];
  19544. Object.keys(codec.parameters).forEach(function (param) {
  19545. if (codec.parameters[param]) {
  19546. params.push(param + '=' + codec.parameters[param]);
  19547. } else {
  19548. params.push(param);
  19549. }
  19550. });
  19551. line += 'a=fmtp:' + pt + ' ' + params.join(';') + '\r\n';
  19552. }
  19553. return line;
  19554. }; // Parses an rtcp-fb line, returns RTCPRtcpFeedback object. Sample input:
  19555. // a=rtcp-fb:98 nack rpsi
  19556. SDPUtils.parseRtcpFb = function (line) {
  19557. var parts = line.substr(line.indexOf(' ') + 1).split(' ');
  19558. return {
  19559. type: parts.shift(),
  19560. parameter: parts.join(' ')
  19561. };
  19562. }; // Generate a=rtcp-fb lines from RTCRtpCodecCapability or RTCRtpCodecParameters.
  19563. SDPUtils.writeRtcpFb = function (codec) {
  19564. var lines = '';
  19565. var pt = codec.payloadType;
  19566. if (codec.preferredPayloadType !== undefined) {
  19567. pt = codec.preferredPayloadType;
  19568. }
  19569. if (codec.rtcpFeedback && codec.rtcpFeedback.length) {
  19570. // FIXME: special handling for trr-int?
  19571. codec.rtcpFeedback.forEach(function (fb) {
  19572. lines += 'a=rtcp-fb:' + pt + ' ' + fb.type + (fb.parameter && fb.parameter.length ? ' ' + fb.parameter : '') + '\r\n';
  19573. });
  19574. }
  19575. return lines;
  19576. }; // Parses an RFC 5576 ssrc media attribute. Sample input:
  19577. // a=ssrc:3735928559 cname:something
  19578. SDPUtils.parseSsrcMedia = function (line) {
  19579. var sp = line.indexOf(' ');
  19580. var parts = {
  19581. ssrc: parseInt(line.substr(7, sp - 7), 10)
  19582. };
  19583. var colon = line.indexOf(':', sp);
  19584. if (colon > -1) {
  19585. parts.attribute = line.substr(sp + 1, colon - sp - 1);
  19586. parts.value = line.substr(colon + 1);
  19587. } else {
  19588. parts.attribute = line.substr(sp + 1);
  19589. }
  19590. return parts;
  19591. };
  19592. SDPUtils.parseSsrcGroup = function (line) {
  19593. var parts = line.substr(13).split(' ');
  19594. return {
  19595. semantics: parts.shift(),
  19596. ssrcs: parts.map(function (ssrc) {
  19597. return parseInt(ssrc, 10);
  19598. })
  19599. };
  19600. }; // Extracts the MID (RFC 5888) from a media section.
  19601. // returns the MID or undefined if no mid line was found.
  19602. SDPUtils.getMid = function (mediaSection) {
  19603. var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:')[0];
  19604. if (mid) {
  19605. return mid.substr(6);
  19606. }
  19607. };
  19608. SDPUtils.parseFingerprint = function (line) {
  19609. var parts = line.substr(14).split(' ');
  19610. return {
  19611. algorithm: parts[0].toLowerCase(),
  19612. // algorithm is case-sensitive in Edge.
  19613. value: parts[1]
  19614. };
  19615. }; // Extracts DTLS parameters from SDP media section or sessionpart.
  19616. // FIXME: for consistency with other functions this should only
  19617. // get the fingerprint line as input. See also getIceParameters.
  19618. SDPUtils.getDtlsParameters = function (mediaSection, sessionpart) {
  19619. var lines = SDPUtils.matchPrefix(mediaSection + sessionpart, 'a=fingerprint:'); // Note: a=setup line is ignored since we use the 'auto' role.
  19620. // Note2: 'algorithm' is not case sensitive except in Edge.
  19621. return {
  19622. role: 'auto',
  19623. fingerprints: lines.map(SDPUtils.parseFingerprint)
  19624. };
  19625. }; // Serializes DTLS parameters to SDP.
  19626. SDPUtils.writeDtlsParameters = function (params, setupType) {
  19627. var sdp = 'a=setup:' + setupType + '\r\n';
  19628. params.fingerprints.forEach(function (fp) {
  19629. sdp += 'a=fingerprint:' + fp.algorithm + ' ' + fp.value + '\r\n';
  19630. });
  19631. return sdp;
  19632. }; // Parses ICE information from SDP media section or sessionpart.
  19633. // FIXME: for consistency with other functions this should only
  19634. // get the ice-ufrag and ice-pwd lines as input.
  19635. SDPUtils.getIceParameters = function (mediaSection, sessionpart) {
  19636. var lines = SDPUtils.splitLines(mediaSection); // Search in session part, too.
  19637. lines = lines.concat(SDPUtils.splitLines(sessionpart));
  19638. var iceParameters = {
  19639. usernameFragment: lines.filter(function (line) {
  19640. return line.indexOf('a=ice-ufrag:') === 0;
  19641. })[0].substr(12),
  19642. password: lines.filter(function (line) {
  19643. return line.indexOf('a=ice-pwd:') === 0;
  19644. })[0].substr(10)
  19645. };
  19646. return iceParameters;
  19647. }; // Serializes ICE parameters to SDP.
  19648. SDPUtils.writeIceParameters = function (params) {
  19649. return 'a=ice-ufrag:' + params.usernameFragment + '\r\n' + 'a=ice-pwd:' + params.password + '\r\n';
  19650. }; // Parses the SDP media section and returns RTCRtpParameters.
  19651. SDPUtils.parseRtpParameters = function (mediaSection) {
  19652. var description = {
  19653. codecs: [],
  19654. headerExtensions: [],
  19655. fecMechanisms: [],
  19656. rtcp: []
  19657. };
  19658. var lines = SDPUtils.splitLines(mediaSection);
  19659. var mline = lines[0].split(' ');
  19660. for (var i = 3; i < mline.length; i++) {
  19661. // find all codecs from mline[3..]
  19662. var pt = mline[i];
  19663. var rtpmapline = SDPUtils.matchPrefix(mediaSection, 'a=rtpmap:' + pt + ' ')[0];
  19664. if (rtpmapline) {
  19665. var codec = SDPUtils.parseRtpMap(rtpmapline);
  19666. var fmtps = SDPUtils.matchPrefix(mediaSection, 'a=fmtp:' + pt + ' '); // Only the first a=fmtp:<pt> is considered.
  19667. codec.parameters = fmtps.length ? SDPUtils.parseFmtp(fmtps[0]) : {};
  19668. codec.rtcpFeedback = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-fb:' + pt + ' ').map(SDPUtils.parseRtcpFb);
  19669. description.codecs.push(codec); // parse FEC mechanisms from rtpmap lines.
  19670. switch (codec.name.toUpperCase()) {
  19671. case 'RED':
  19672. case 'ULPFEC':
  19673. description.fecMechanisms.push(codec.name.toUpperCase());
  19674. break;
  19675. default:
  19676. // only RED and ULPFEC are recognized as FEC mechanisms.
  19677. break;
  19678. }
  19679. }
  19680. }
  19681. SDPUtils.matchPrefix(mediaSection, 'a=extmap:').forEach(function (line) {
  19682. description.headerExtensions.push(SDPUtils.parseExtmap(line));
  19683. }); // FIXME: parse rtcp.
  19684. return description;
  19685. }; // Generates parts of the SDP media section describing the capabilities /
  19686. // parameters.
  19687. SDPUtils.writeRtpDescription = function (kind, caps) {
  19688. var sdp = ''; // Build the mline.
  19689. sdp += 'm=' + kind + ' ';
  19690. sdp += caps.codecs.length > 0 ? '9' : '0'; // reject if no codecs.
  19691. sdp += ' UDP/TLS/RTP/SAVPF ';
  19692. sdp += caps.codecs.map(function (codec) {
  19693. if (codec.preferredPayloadType !== undefined) {
  19694. return codec.preferredPayloadType;
  19695. }
  19696. return codec.payloadType;
  19697. }).join(' ') + '\r\n';
  19698. sdp += 'c=IN IP4 0.0.0.0\r\n';
  19699. sdp += 'a=rtcp:9 IN IP4 0.0.0.0\r\n'; // Add a=rtpmap lines for each codec. Also fmtp and rtcp-fb.
  19700. caps.codecs.forEach(function (codec) {
  19701. sdp += SDPUtils.writeRtpMap(codec);
  19702. sdp += SDPUtils.writeFmtp(codec);
  19703. sdp += SDPUtils.writeRtcpFb(codec);
  19704. });
  19705. var maxptime = 0;
  19706. caps.codecs.forEach(function (codec) {
  19707. if (codec.maxptime > maxptime) {
  19708. maxptime = codec.maxptime;
  19709. }
  19710. });
  19711. if (maxptime > 0) {
  19712. sdp += 'a=maxptime:' + maxptime + '\r\n';
  19713. }
  19714. sdp += 'a=rtcp-mux\r\n';
  19715. if (caps.headerExtensions) {
  19716. caps.headerExtensions.forEach(function (extension) {
  19717. sdp += SDPUtils.writeExtmap(extension);
  19718. });
  19719. } // FIXME: write fecMechanisms.
  19720. return sdp;
  19721. }; // Parses the SDP media section and returns an array of
  19722. // RTCRtpEncodingParameters.
  19723. SDPUtils.parseRtpEncodingParameters = function (mediaSection) {
  19724. var encodingParameters = [];
  19725. var description = SDPUtils.parseRtpParameters(mediaSection);
  19726. var hasRed = description.fecMechanisms.indexOf('RED') !== -1;
  19727. var hasUlpfec = description.fecMechanisms.indexOf('ULPFEC') !== -1; // filter a=ssrc:... cname:, ignore PlanB-msid
  19728. var ssrcs = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:').map(function (line) {
  19729. return SDPUtils.parseSsrcMedia(line);
  19730. }).filter(function (parts) {
  19731. return parts.attribute === 'cname';
  19732. });
  19733. var primarySsrc = ssrcs.length > 0 && ssrcs[0].ssrc;
  19734. var secondarySsrc;
  19735. var flows = SDPUtils.matchPrefix(mediaSection, 'a=ssrc-group:FID').map(function (line) {
  19736. var parts = line.substr(17).split(' ');
  19737. return parts.map(function (part) {
  19738. return parseInt(part, 10);
  19739. });
  19740. });
  19741. if (flows.length > 0 && flows[0].length > 1 && flows[0][0] === primarySsrc) {
  19742. secondarySsrc = flows[0][1];
  19743. }
  19744. description.codecs.forEach(function (codec) {
  19745. if (codec.name.toUpperCase() === 'RTX' && codec.parameters.apt) {
  19746. var encParam = {
  19747. ssrc: primarySsrc,
  19748. codecPayloadType: parseInt(codec.parameters.apt, 10)
  19749. };
  19750. if (primarySsrc && secondarySsrc) {
  19751. encParam.rtx = {
  19752. ssrc: secondarySsrc
  19753. };
  19754. }
  19755. encodingParameters.push(encParam);
  19756. if (hasRed) {
  19757. encParam = JSON.parse(JSON.stringify(encParam));
  19758. encParam.fec = {
  19759. ssrc: primarySsrc,
  19760. mechanism: hasUlpfec ? 'red+ulpfec' : 'red'
  19761. };
  19762. encodingParameters.push(encParam);
  19763. }
  19764. }
  19765. });
  19766. if (encodingParameters.length === 0 && primarySsrc) {
  19767. encodingParameters.push({
  19768. ssrc: primarySsrc
  19769. });
  19770. } // we support both b=AS and b=TIAS but interpret AS as TIAS.
  19771. var bandwidth = SDPUtils.matchPrefix(mediaSection, 'b=');
  19772. if (bandwidth.length) {
  19773. if (bandwidth[0].indexOf('b=TIAS:') === 0) {
  19774. bandwidth = parseInt(bandwidth[0].substr(7), 10);
  19775. } else if (bandwidth[0].indexOf('b=AS:') === 0) {
  19776. // use formula from JSEP to convert b=AS to TIAS value.
  19777. bandwidth = parseInt(bandwidth[0].substr(5), 10) * 1000 * 0.95 - 50 * 40 * 8;
  19778. } else {
  19779. bandwidth = undefined;
  19780. }
  19781. encodingParameters.forEach(function (params) {
  19782. params.maxBitrate = bandwidth;
  19783. });
  19784. }
  19785. return encodingParameters;
  19786. }; // parses http://draft.ortc.org/#rtcrtcpparameters*
  19787. SDPUtils.parseRtcpParameters = function (mediaSection) {
  19788. var rtcpParameters = {}; // Gets the first SSRC. Note tha with RTX there might be multiple
  19789. // SSRCs.
  19790. var remoteSsrc = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:').map(function (line) {
  19791. return SDPUtils.parseSsrcMedia(line);
  19792. }).filter(function (obj) {
  19793. return obj.attribute === 'cname';
  19794. })[0];
  19795. if (remoteSsrc) {
  19796. rtcpParameters.cname = remoteSsrc.value;
  19797. rtcpParameters.ssrc = remoteSsrc.ssrc;
  19798. } // Edge uses the compound attribute instead of reducedSize
  19799. // compound is !reducedSize
  19800. var rsize = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-rsize');
  19801. rtcpParameters.reducedSize = rsize.length > 0;
  19802. rtcpParameters.compound = rsize.length === 0; // parses the rtcp-mux attrіbute.
  19803. // Note that Edge does not support unmuxed RTCP.
  19804. var mux = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-mux');
  19805. rtcpParameters.mux = mux.length > 0;
  19806. return rtcpParameters;
  19807. }; // parses either a=msid: or a=ssrc:... msid lines and returns
  19808. // the id of the MediaStream and MediaStreamTrack.
  19809. SDPUtils.parseMsid = function (mediaSection) {
  19810. var parts;
  19811. var spec = SDPUtils.matchPrefix(mediaSection, 'a=msid:');
  19812. if (spec.length === 1) {
  19813. parts = spec[0].substr(7).split(' ');
  19814. return {
  19815. stream: parts[0],
  19816. track: parts[1]
  19817. };
  19818. }
  19819. var planB = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:').map(function (line) {
  19820. return SDPUtils.parseSsrcMedia(line);
  19821. }).filter(function (msidParts) {
  19822. return msidParts.attribute === 'msid';
  19823. });
  19824. if (planB.length > 0) {
  19825. parts = planB[0].value.split(' ');
  19826. return {
  19827. stream: parts[0],
  19828. track: parts[1]
  19829. };
  19830. }
  19831. }; // Generate a session ID for SDP.
  19832. // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-20#section-5.2.1
  19833. // recommends using a cryptographically random +ve 64-bit value
  19834. // but right now this should be acceptable and within the right range
  19835. SDPUtils.generateSessionId = function () {
  19836. return Math.random().toString().substr(2, 21);
  19837. }; // Write boilder plate for start of SDP
  19838. // sessId argument is optional - if not supplied it will
  19839. // be generated randomly
  19840. // sessVersion is optional and defaults to 2
  19841. // sessUser is optional and defaults to 'thisisadapterortc'
  19842. SDPUtils.writeSessionBoilerplate = function (sessId, sessVer, sessUser) {
  19843. var sessionId;
  19844. var version = sessVer !== undefined ? sessVer : 2;
  19845. if (sessId) {
  19846. sessionId = sessId;
  19847. } else {
  19848. sessionId = SDPUtils.generateSessionId();
  19849. }
  19850. var user = sessUser || 'thisisadapterortc'; // FIXME: sess-id should be an NTP timestamp.
  19851. return 'v=0\r\n' + 'o=' + user + ' ' + sessionId + ' ' + version + ' IN IP4 127.0.0.1\r\n' + 's=-\r\n' + 't=0 0\r\n';
  19852. };
  19853. SDPUtils.writeMediaSection = function (transceiver, caps, type, stream) {
  19854. var sdp = SDPUtils.writeRtpDescription(transceiver.kind, caps); // Map ICE parameters (ufrag, pwd) to SDP.
  19855. sdp += SDPUtils.writeIceParameters(transceiver.iceGatherer.getLocalParameters()); // Map DTLS parameters to SDP.
  19856. sdp += SDPUtils.writeDtlsParameters(transceiver.dtlsTransport.getLocalParameters(), type === 'offer' ? 'actpass' : 'active');
  19857. sdp += 'a=mid:' + transceiver.mid + '\r\n';
  19858. if (transceiver.direction) {
  19859. sdp += 'a=' + transceiver.direction + '\r\n';
  19860. } else if (transceiver.rtpSender && transceiver.rtpReceiver) {
  19861. sdp += 'a=sendrecv\r\n';
  19862. } else if (transceiver.rtpSender) {
  19863. sdp += 'a=sendonly\r\n';
  19864. } else if (transceiver.rtpReceiver) {
  19865. sdp += 'a=recvonly\r\n';
  19866. } else {
  19867. sdp += 'a=inactive\r\n';
  19868. }
  19869. if (transceiver.rtpSender) {
  19870. // spec.
  19871. var msid = 'msid:' + stream.id + ' ' + transceiver.rtpSender.track.id + '\r\n';
  19872. sdp += 'a=' + msid; // for Chrome.
  19873. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc + ' ' + msid;
  19874. if (transceiver.sendEncodingParameters[0].rtx) {
  19875. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc + ' ' + msid;
  19876. sdp += 'a=ssrc-group:FID ' + transceiver.sendEncodingParameters[0].ssrc + ' ' + transceiver.sendEncodingParameters[0].rtx.ssrc + '\r\n';
  19877. }
  19878. } // FIXME: this should be written by writeRtpDescription.
  19879. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc + ' cname:' + SDPUtils.localCName + '\r\n';
  19880. if (transceiver.rtpSender && transceiver.sendEncodingParameters[0].rtx) {
  19881. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc + ' cname:' + SDPUtils.localCName + '\r\n';
  19882. }
  19883. return sdp;
  19884. }; // Gets the direction from the mediaSection or the sessionpart.
  19885. SDPUtils.getDirection = function (mediaSection, sessionpart) {
  19886. // Look for sendrecv, sendonly, recvonly, inactive, default to sendrecv.
  19887. var lines = SDPUtils.splitLines(mediaSection);
  19888. for (var i = 0; i < lines.length; i++) {
  19889. switch (lines[i]) {
  19890. case 'a=sendrecv':
  19891. case 'a=sendonly':
  19892. case 'a=recvonly':
  19893. case 'a=inactive':
  19894. return lines[i].substr(2);
  19895. default: // FIXME: What should happen here?
  19896. }
  19897. }
  19898. if (sessionpart) {
  19899. return SDPUtils.getDirection(sessionpart);
  19900. }
  19901. return 'sendrecv';
  19902. };
  19903. SDPUtils.getKind = function (mediaSection) {
  19904. var lines = SDPUtils.splitLines(mediaSection);
  19905. var mline = lines[0].split(' ');
  19906. return mline[0].substr(2);
  19907. };
  19908. SDPUtils.isRejected = function (mediaSection) {
  19909. return mediaSection.split(' ', 2)[1] === '0';
  19910. };
  19911. SDPUtils.parseMLine = function (mediaSection) {
  19912. var lines = SDPUtils.splitLines(mediaSection);
  19913. var parts = lines[0].substr(2).split(' ');
  19914. return {
  19915. kind: parts[0],
  19916. port: parseInt(parts[1], 10),
  19917. protocol: parts[2],
  19918. fmt: parts.slice(3).join(' ')
  19919. };
  19920. };
  19921. SDPUtils.parseOLine = function (mediaSection) {
  19922. var line = SDPUtils.matchPrefix(mediaSection, 'o=')[0];
  19923. var parts = line.substr(2).split(' ');
  19924. return {
  19925. username: parts[0],
  19926. sessionId: parts[1],
  19927. sessionVersion: parseInt(parts[2], 10),
  19928. netType: parts[3],
  19929. addressType: parts[4],
  19930. address: parts[5]
  19931. };
  19932. }; // a very naive interpretation of a valid SDP.
  19933. SDPUtils.isValidSDP = function (blob) {
  19934. if (typeof blob !== 'string' || blob.length === 0) {
  19935. return false;
  19936. }
  19937. var lines = SDPUtils.splitLines(blob);
  19938. for (var i = 0; i < lines.length; i++) {
  19939. if (lines[i].length < 2 || lines[i].charAt(1) !== '=') {
  19940. return false;
  19941. } // TODO: check the modifier a bit more.
  19942. }
  19943. return true;
  19944. }; // Expose public methods.
  19945. if (true) {
  19946. module.exports = SDPUtils;
  19947. }
  19948. }),
  19949. /* 20 */
  19950. (function(module, exports, __webpack_require__) {
  19951. "use strict";
  19952. /* WEBPACK VAR INJECTION */(function(process, global) {var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__; // Last Updated On: 2018-10-26 9:36:48 AM UTC
  19953. // ________________
  19954. // DetectRTC v1.3.7
  19955. // Open-Sourced: https://github.com/muaz-khan/DetectRTC
  19956. // --------------------------------------------------
  19957. // Muaz Khan - www.MuazKhan.com
  19958. // MIT License - www.WebRTC-Experiment.com/licence
  19959. // --------------------------------------------------
  19960. (function () {
  19961. var browserFakeUserAgent = 'Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45';
  19962. var isNodejs = typeof process === 'object' && typeof process.versions === 'object' && process.versions.node &&
  19963. /*node-process*/
  19964. !process.browser;
  19965. if (isNodejs) {
  19966. var version = process.versions.node.toString().replace('v', '');
  19967. browserFakeUserAgent = 'Nodejs/' + version + ' (NodeOS) AppleWebKit/' + version + ' (KHTML, like Gecko) Nodejs/' + version + ' Nodejs/' + version;
  19968. }
  19969. (function (that) {
  19970. if (typeof window !== 'undefined') {
  19971. return;
  19972. }
  19973. if (typeof window === 'undefined' && typeof global !== 'undefined') {
  19974. global.navigator = {
  19975. userAgent: browserFakeUserAgent,
  19976. getUserMedia: function () {}
  19977. };
  19978. /*global window:true */
  19979. that.window = global;
  19980. } else if (typeof window === 'undefined') {// window = this;
  19981. }
  19982. if (typeof location === 'undefined') {
  19983. /*global location:true */
  19984. that.location = {
  19985. protocol: 'file:',
  19986. href: '',
  19987. hash: ''
  19988. };
  19989. }
  19990. if (typeof screen === 'undefined') {
  19991. /*global screen:true */
  19992. that.screen = {
  19993. width: 0,
  19994. height: 0
  19995. };
  19996. }
  19997. })(typeof global !== 'undefined' ? global : window);
  19998. /*global navigator:true */
  19999. var navigator = window.navigator;
  20000. if (typeof navigator !== 'undefined') {
  20001. if (typeof navigator.webkitGetUserMedia !== 'undefined') {
  20002. navigator.getUserMedia = navigator.webkitGetUserMedia;
  20003. }
  20004. if (typeof navigator.mozGetUserMedia !== 'undefined') {
  20005. navigator.getUserMedia = navigator.mozGetUserMedia;
  20006. }
  20007. } else {
  20008. navigator = {
  20009. getUserMedia: function () {},
  20010. userAgent: browserFakeUserAgent
  20011. };
  20012. }
  20013. var isMobileDevice = !!/Android|webOS|iPhone|iPad|iPod|BB10|BlackBerry|IEMobile|Opera Mini|Mobile|mobile/i.test(navigator.userAgent || '');
  20014. var isEdge = navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob);
  20015. var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
  20016. var isFirefox = typeof window.InstallTrigger !== 'undefined';
  20017. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  20018. var isChrome = !!window.chrome && !isOpera;
  20019. var isIE = typeof document !== 'undefined' && !!document.documentMode && !isEdge; // this one can also be used:
  20020. // https://www.websocket.org/js/stuff.js (DetectBrowser.js)
  20021. function getBrowserInfo() {
  20022. var nVer = navigator.appVersion;
  20023. var nAgt = navigator.userAgent;
  20024. var browserName = navigator.appName;
  20025. var fullVersion = '' + parseFloat(navigator.appVersion);
  20026. var majorVersion = parseInt(navigator.appVersion, 10);
  20027. var nameOffset, verOffset, ix; // both and safri and chrome has same userAgent
  20028. if (isSafari && !isChrome && nAgt.indexOf('CriOS') !== -1) {
  20029. isSafari = false;
  20030. isChrome = true;
  20031. } // In Opera, the true version is after 'Opera' or after 'Version'
  20032. if (isOpera) {
  20033. browserName = 'Opera';
  20034. try {
  20035. fullVersion = navigator.userAgent.split('OPR/')[1].split(' ')[0];
  20036. majorVersion = fullVersion.split('.')[0];
  20037. } catch (e) {
  20038. fullVersion = '0.0.0.0';
  20039. majorVersion = 0;
  20040. }
  20041. } // In MSIE version <=10, the true version is after 'MSIE' in userAgent
  20042. // In IE 11, look for the string after 'rv:'
  20043. else if (isIE) {
  20044. verOffset = nAgt.indexOf('rv:');
  20045. if (verOffset > 0) {
  20046. //IE 11
  20047. fullVersion = nAgt.substring(verOffset + 3);
  20048. } else {
  20049. //IE 10 or earlier
  20050. verOffset = nAgt.indexOf('MSIE');
  20051. fullVersion = nAgt.substring(verOffset + 5);
  20052. }
  20053. browserName = 'IE';
  20054. } // In Chrome, the true version is after 'Chrome'
  20055. else if (isChrome) {
  20056. verOffset = nAgt.indexOf('Chrome');
  20057. browserName = 'Chrome';
  20058. fullVersion = nAgt.substring(verOffset + 7);
  20059. } // In Safari, the true version is after 'Safari' or after 'Version'
  20060. else if (isSafari) {
  20061. verOffset = nAgt.indexOf('Safari');
  20062. browserName = 'Safari';
  20063. fullVersion = nAgt.substring(verOffset + 7);
  20064. if ((verOffset = nAgt.indexOf('Version')) !== -1) {
  20065. fullVersion = nAgt.substring(verOffset + 8);
  20066. }
  20067. if (navigator.userAgent.indexOf('Version/') !== -1) {
  20068. fullVersion = navigator.userAgent.split('Version/')[1].split(' ')[0];
  20069. }
  20070. } // In Firefox, the true version is after 'Firefox'
  20071. else if (isFirefox) {
  20072. verOffset = nAgt.indexOf('Firefox');
  20073. browserName = 'Firefox';
  20074. fullVersion = nAgt.substring(verOffset + 8);
  20075. } // In most other browsers, 'name/version' is at the end of userAgent
  20076. else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
  20077. browserName = nAgt.substring(nameOffset, verOffset);
  20078. fullVersion = nAgt.substring(verOffset + 1);
  20079. if (browserName.toLowerCase() === browserName.toUpperCase()) {
  20080. browserName = navigator.appName;
  20081. }
  20082. }
  20083. if (isEdge) {
  20084. browserName = 'Edge';
  20085. fullVersion = navigator.userAgent.split('Edge/')[1]; // fullVersion = parseInt(navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)[2], 10).toString();
  20086. } // trim the fullVersion string at semicolon/space/bracket if present
  20087. if ((ix = fullVersion.search(/[; \)]/)) !== -1) {
  20088. fullVersion = fullVersion.substring(0, ix);
  20089. }
  20090. majorVersion = parseInt('' + fullVersion, 10);
  20091. if (isNaN(majorVersion)) {
  20092. fullVersion = '' + parseFloat(navigator.appVersion);
  20093. majorVersion = parseInt(navigator.appVersion, 10);
  20094. }
  20095. return {
  20096. fullVersion: fullVersion,
  20097. version: majorVersion,
  20098. name: browserName,
  20099. isPrivateBrowsing: false
  20100. };
  20101. } // via: https://gist.github.com/cou929/7973956
  20102. function retry(isDone, next) {
  20103. var currentTrial = 0,
  20104. maxRetry = 50,
  20105. interval = 10,
  20106. isTimeout = false;
  20107. var id = window.setInterval(function () {
  20108. if (isDone()) {
  20109. window.clearInterval(id);
  20110. next(isTimeout);
  20111. }
  20112. if (currentTrial++ > maxRetry) {
  20113. window.clearInterval(id);
  20114. isTimeout = true;
  20115. next(isTimeout);
  20116. }
  20117. }, 10);
  20118. }
  20119. function isIE10OrLater(userAgent) {
  20120. var ua = userAgent.toLowerCase();
  20121. if (ua.indexOf('msie') === 0 && ua.indexOf('trident') === 0) {
  20122. return false;
  20123. }
  20124. var match = /(?:msie|rv:)\s?([\d\.]+)/.exec(ua);
  20125. if (match && parseInt(match[1], 10) >= 10) {
  20126. return true;
  20127. }
  20128. return false;
  20129. }
  20130. function detectPrivateMode(callback) {
  20131. var isPrivate;
  20132. try {
  20133. if (window.webkitRequestFileSystem) {
  20134. window.webkitRequestFileSystem(window.TEMPORARY, 1, function () {
  20135. isPrivate = false;
  20136. }, function (e) {
  20137. isPrivate = true;
  20138. });
  20139. } else if (window.indexedDB && /Firefox/.test(window.navigator.userAgent)) {
  20140. var db;
  20141. try {
  20142. db = window.indexedDB.open('test');
  20143. db.onerror = function () {
  20144. return true;
  20145. };
  20146. } catch (e) {
  20147. isPrivate = true;
  20148. }
  20149. if (typeof isPrivate === 'undefined') {
  20150. retry(function isDone() {
  20151. return db.readyState === 'done' ? true : false;
  20152. }, function next(isTimeout) {
  20153. if (!isTimeout) {
  20154. isPrivate = db.result ? false : true;
  20155. }
  20156. });
  20157. }
  20158. } else if (isIE10OrLater(window.navigator.userAgent)) {
  20159. isPrivate = false;
  20160. try {
  20161. if (!window.indexedDB) {
  20162. isPrivate = true;
  20163. }
  20164. } catch (e) {
  20165. isPrivate = true;
  20166. }
  20167. } else if (window.localStorage && /Safari/.test(window.navigator.userAgent)) {
  20168. try {
  20169. window.localStorage.setItem('test', 1);
  20170. } catch (e) {
  20171. isPrivate = true;
  20172. }
  20173. if (typeof isPrivate === 'undefined') {
  20174. isPrivate = false;
  20175. window.localStorage.removeItem('test');
  20176. }
  20177. }
  20178. } catch (e) {
  20179. isPrivate = false;
  20180. }
  20181. retry(function isDone() {
  20182. return typeof isPrivate !== 'undefined' ? true : false;
  20183. }, function next(isTimeout) {
  20184. callback(isPrivate);
  20185. });
  20186. }
  20187. var isMobile = {
  20188. Android: function () {
  20189. return navigator.userAgent.match(/Android/i);
  20190. },
  20191. BlackBerry: function () {
  20192. return navigator.userAgent.match(/BlackBerry|BB10/i);
  20193. },
  20194. iOS: function () {
  20195. return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  20196. },
  20197. Opera: function () {
  20198. return navigator.userAgent.match(/Opera Mini/i);
  20199. },
  20200. Windows: function () {
  20201. return navigator.userAgent.match(/IEMobile/i);
  20202. },
  20203. any: function () {
  20204. return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows();
  20205. },
  20206. getOsName: function () {
  20207. var osName = 'Unknown OS';
  20208. if (isMobile.Android()) {
  20209. osName = 'Android';
  20210. }
  20211. if (isMobile.BlackBerry()) {
  20212. osName = 'BlackBerry';
  20213. }
  20214. if (isMobile.iOS()) {
  20215. osName = 'iOS';
  20216. }
  20217. if (isMobile.Opera()) {
  20218. osName = 'Opera Mini';
  20219. }
  20220. if (isMobile.Windows()) {
  20221. osName = 'Windows';
  20222. }
  20223. return osName;
  20224. }
  20225. }; // via: http://jsfiddle.net/ChristianL/AVyND/
  20226. function detectDesktopOS() {
  20227. var unknown = '-';
  20228. var nVer = navigator.appVersion;
  20229. var nAgt = navigator.userAgent;
  20230. var os = unknown;
  20231. var clientStrings = [{
  20232. s: 'Windows 10',
  20233. r: /(Windows 10.0|Windows NT 10.0)/
  20234. }, {
  20235. s: 'Windows 8.1',
  20236. r: /(Windows 8.1|Windows NT 6.3)/
  20237. }, {
  20238. s: 'Windows 8',
  20239. r: /(Windows 8|Windows NT 6.2)/
  20240. }, {
  20241. s: 'Windows 7',
  20242. r: /(Windows 7|Windows NT 6.1)/
  20243. }, {
  20244. s: 'Windows Vista',
  20245. r: /Windows NT 6.0/
  20246. }, {
  20247. s: 'Windows Server 2003',
  20248. r: /Windows NT 5.2/
  20249. }, {
  20250. s: 'Windows XP',
  20251. r: /(Windows NT 5.1|Windows XP)/
  20252. }, {
  20253. s: 'Windows 2000',
  20254. r: /(Windows NT 5.0|Windows 2000)/
  20255. }, {
  20256. s: 'Windows ME',
  20257. r: /(Win 9x 4.90|Windows ME)/
  20258. }, {
  20259. s: 'Windows 98',
  20260. r: /(Windows 98|Win98)/
  20261. }, {
  20262. s: 'Windows 95',
  20263. r: /(Windows 95|Win95|Windows_95)/
  20264. }, {
  20265. s: 'Windows NT 4.0',
  20266. r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/
  20267. }, {
  20268. s: 'Windows CE',
  20269. r: /Windows CE/
  20270. }, {
  20271. s: 'Windows 3.11',
  20272. r: /Win16/
  20273. }, {
  20274. s: 'Android',
  20275. r: /Android/
  20276. }, {
  20277. s: 'Open BSD',
  20278. r: /OpenBSD/
  20279. }, {
  20280. s: 'Sun OS',
  20281. r: /SunOS/
  20282. }, {
  20283. s: 'Linux',
  20284. r: /(Linux|X11)/
  20285. }, {
  20286. s: 'iOS',
  20287. r: /(iPhone|iPad|iPod)/
  20288. }, {
  20289. s: 'Mac OS X',
  20290. r: /Mac OS X/
  20291. }, {
  20292. s: 'Mac OS',
  20293. r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/
  20294. }, {
  20295. s: 'QNX',
  20296. r: /QNX/
  20297. }, {
  20298. s: 'UNIX',
  20299. r: /UNIX/
  20300. }, {
  20301. s: 'BeOS',
  20302. r: /BeOS/
  20303. }, {
  20304. s: 'OS/2',
  20305. r: /OS\/2/
  20306. }, {
  20307. s: 'Search Bot',
  20308. r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/
  20309. }];
  20310. for (var i = 0, cs; cs = clientStrings[i]; i++) {
  20311. if (cs.r.test(nAgt)) {
  20312. os = cs.s;
  20313. break;
  20314. }
  20315. }
  20316. var osVersion = unknown;
  20317. if (/Windows/.test(os)) {
  20318. if (/Windows (.*)/.test(os)) {
  20319. osVersion = /Windows (.*)/.exec(os)[1];
  20320. }
  20321. os = 'Windows';
  20322. }
  20323. switch (os) {
  20324. case 'Mac OS X':
  20325. if (/Mac OS X (10[\.\_\d]+)/.test(nAgt)) {
  20326. osVersion = /Mac OS X (10[\.\_\d]+)/.exec(nAgt)[1];
  20327. }
  20328. break;
  20329. case 'Android':
  20330. if (/Android ([\.\_\d]+)/.test(nAgt)) {
  20331. osVersion = /Android ([\.\_\d]+)/.exec(nAgt)[1];
  20332. }
  20333. break;
  20334. case 'iOS':
  20335. if (/OS (\d+)_(\d+)_?(\d+)?/.test(nAgt)) {
  20336. osVersion = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
  20337. osVersion = osVersion[1] + '.' + osVersion[2] + '.' + (osVersion[3] | 0);
  20338. }
  20339. break;
  20340. }
  20341. return {
  20342. osName: os,
  20343. osVersion: osVersion
  20344. };
  20345. }
  20346. var osName = 'Unknown OS';
  20347. var osVersion = 'Unknown OS Version';
  20348. function getAndroidVersion(ua) {
  20349. ua = (ua || navigator.userAgent).toLowerCase();
  20350. var match = ua.match(/android\s([0-9\.]*)/);
  20351. return match ? match[1] : false;
  20352. }
  20353. var osInfo = detectDesktopOS();
  20354. if (osInfo && osInfo.osName && osInfo.osName != '-') {
  20355. osName = osInfo.osName;
  20356. osVersion = osInfo.osVersion;
  20357. } else if (isMobile.any()) {
  20358. osName = isMobile.getOsName();
  20359. if (osName == 'Android') {
  20360. osVersion = getAndroidVersion();
  20361. }
  20362. }
  20363. var isNodejs = typeof process === 'object' && typeof process.versions === 'object' && process.versions.node;
  20364. if (osName === 'Unknown OS' && isNodejs) {
  20365. osName = 'Nodejs';
  20366. osVersion = process.versions.node.toString().replace('v', '');
  20367. }
  20368. var isCanvasSupportsStreamCapturing = false;
  20369. var isVideoSupportsStreamCapturing = false;
  20370. ['captureStream', 'mozCaptureStream', 'webkitCaptureStream'].forEach(function (item) {
  20371. if (typeof document === 'undefined' || typeof document.createElement !== 'function') {
  20372. return;
  20373. }
  20374. if (!isCanvasSupportsStreamCapturing && item in document.createElement('canvas')) {
  20375. isCanvasSupportsStreamCapturing = true;
  20376. }
  20377. if (!isVideoSupportsStreamCapturing && item in document.createElement('video')) {
  20378. isVideoSupportsStreamCapturing = true;
  20379. }
  20380. });
  20381. const regexIpv4Local = /^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/,
  20382. regexIpv4 = /([0-9]{1,3}(\.[0-9]{1,3}){3})/,
  20383. regexIpv6 = /[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7}/; // via: https://github.com/diafygi/webrtc-ips
  20384. function DetectLocalIPAddress(callback, stream) {
  20385. if (!DetectRTC.isWebRTCSupported) {
  20386. return;
  20387. }
  20388. var isPublic = true,
  20389. isIpv4 = true;
  20390. getIPs(function (ip) {
  20391. if (ip.match(regexIpv4Local)) {
  20392. isPublic = false;
  20393. callback('Local: ' + ip, isPublic, isIpv4);
  20394. } else if (ip.match(regexIpv6)) {
  20395. //via https://ourcodeworld.com/articles/read/257/how-to-get-the-client-ip-address-with-javascript-only
  20396. isIpv4 = false;
  20397. callback('Public: ' + ip, isPublic, isIpv4);
  20398. } else {
  20399. callback('Public: ' + ip, isPublic, isIpv4);
  20400. }
  20401. }, stream);
  20402. }
  20403. function getIPs(callback, stream) {
  20404. if (typeof document === 'undefined' || typeof document.getElementById !== 'function') {
  20405. return;
  20406. }
  20407. var ipDuplicates = {};
  20408. var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
  20409. if (!RTCPeerConnection) {
  20410. var iframe = document.getElementById('iframe');
  20411. if (!iframe) {
  20412. return;
  20413. }
  20414. var win = iframe.contentWindow;
  20415. RTCPeerConnection = win.RTCPeerConnection || win.mozRTCPeerConnection || win.webkitRTCPeerConnection;
  20416. }
  20417. if (!RTCPeerConnection) {
  20418. return;
  20419. }
  20420. var peerConfig = null;
  20421. if (DetectRTC.browser === 'Chrome' && DetectRTC.browser.version < 58) {
  20422. // todo: add support for older Opera
  20423. peerConfig = {
  20424. optional: [{
  20425. RtpDataChannels: true
  20426. }]
  20427. };
  20428. }
  20429. var servers = {
  20430. iceServers: [{
  20431. urls: 'stun:stun.l.google.com:19302'
  20432. }]
  20433. };
  20434. var pc = new RTCPeerConnection(servers, peerConfig);
  20435. if (stream) {
  20436. if (pc.addStream) {
  20437. pc.addStream(stream);
  20438. } else if (pc.addTrack && stream.getTracks()[0]) {
  20439. pc.addTrack(stream.getTracks()[0], stream);
  20440. }
  20441. }
  20442. function handleCandidate(candidate) {
  20443. var match = regexIpv4.exec(candidate);
  20444. if (!match) {
  20445. return;
  20446. }
  20447. var ipAddress = match[1];
  20448. const isPublic = candidate.match(regexIpv4Local),
  20449. isIpv4 = true;
  20450. if (ipDuplicates[ipAddress] === undefined) {
  20451. callback(ipAddress, isPublic, isIpv4);
  20452. }
  20453. ipDuplicates[ipAddress] = true;
  20454. } // listen for candidate events
  20455. pc.onicecandidate = function (ice) {
  20456. if (ice.candidate) {
  20457. handleCandidate(ice.candidate.candidate);
  20458. }
  20459. }; // create data channel
  20460. if (!stream) {
  20461. try {
  20462. pc.createDataChannel('sctp', {});
  20463. } catch (e) {}
  20464. } // create an offer sdp
  20465. if (DetectRTC.isPromisesSupported) {
  20466. pc.createOffer().then(function (result) {
  20467. pc.setLocalDescription(result).then(afterCreateOffer);
  20468. });
  20469. } else {
  20470. pc.createOffer(function (result) {
  20471. pc.setLocalDescription(result, afterCreateOffer, function () {});
  20472. }, function () {});
  20473. }
  20474. function afterCreateOffer() {
  20475. var lines = pc.localDescription.sdp.split('\n');
  20476. lines.forEach(function (line) {
  20477. if (line.indexOf('a=candidate:') === 0) {
  20478. handleCandidate(line);
  20479. }
  20480. });
  20481. }
  20482. }
  20483. var MediaDevices = [];
  20484. var audioInputDevices = [];
  20485. var audioOutputDevices = [];
  20486. var videoInputDevices = [];
  20487. if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) {
  20488. // Firefox 38+ seems having support of enumerateDevices
  20489. // Thanks @xdumaine/enumerateDevices
  20490. navigator.enumerateDevices = function (callback) {
  20491. var enumerateDevices = navigator.mediaDevices.enumerateDevices();
  20492. if (enumerateDevices && enumerateDevices.then) {
  20493. navigator.mediaDevices.enumerateDevices().then(callback).catch(function () {
  20494. callback([]);
  20495. });
  20496. } else {
  20497. callback([]);
  20498. }
  20499. };
  20500. } // Media Devices detection
  20501. var canEnumerate = false;
  20502. /*global MediaStreamTrack:true */
  20503. if (typeof MediaStreamTrack !== 'undefined' && 'getSources' in MediaStreamTrack) {
  20504. canEnumerate = true;
  20505. } else if (navigator.mediaDevices && !!navigator.mediaDevices.enumerateDevices) {
  20506. canEnumerate = true;
  20507. }
  20508. var hasMicrophone = false;
  20509. var hasSpeakers = false;
  20510. var hasWebcam = false;
  20511. var isWebsiteHasMicrophonePermissions = false;
  20512. var isWebsiteHasWebcamPermissions = false; // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediadevices
  20513. function checkDeviceSupport(callback) {
  20514. if (!canEnumerate) {
  20515. if (callback) {
  20516. callback();
  20517. }
  20518. return;
  20519. }
  20520. if (!navigator.enumerateDevices && window.MediaStreamTrack && window.MediaStreamTrack.getSources) {
  20521. navigator.enumerateDevices = window.MediaStreamTrack.getSources.bind(window.MediaStreamTrack);
  20522. }
  20523. if (!navigator.enumerateDevices && navigator.enumerateDevices) {
  20524. navigator.enumerateDevices = navigator.enumerateDevices.bind(navigator);
  20525. }
  20526. if (!navigator.enumerateDevices) {
  20527. if (callback) {
  20528. callback();
  20529. }
  20530. return;
  20531. }
  20532. MediaDevices = [];
  20533. audioInputDevices = [];
  20534. audioOutputDevices = [];
  20535. videoInputDevices = [];
  20536. hasMicrophone = false;
  20537. hasSpeakers = false;
  20538. hasWebcam = false;
  20539. isWebsiteHasMicrophonePermissions = false;
  20540. isWebsiteHasWebcamPermissions = false; // to prevent duplication
  20541. var alreadyUsedDevices = {};
  20542. navigator.enumerateDevices(function (devices) {
  20543. devices.forEach(function (_device) {
  20544. var device = {};
  20545. for (var d in _device) {
  20546. try {
  20547. if (typeof _device[d] !== 'function') {
  20548. device[d] = _device[d];
  20549. }
  20550. } catch (e) {}
  20551. }
  20552. if (alreadyUsedDevices[device.deviceId + device.label + device.kind]) {
  20553. return;
  20554. } // if it is MediaStreamTrack.getSources
  20555. if (device.kind === 'audio') {
  20556. device.kind = 'audioinput';
  20557. }
  20558. if (device.kind === 'video') {
  20559. device.kind = 'videoinput';
  20560. }
  20561. if (!device.deviceId) {
  20562. device.deviceId = device.id;
  20563. }
  20564. if (!device.id) {
  20565. device.id = device.deviceId;
  20566. }
  20567. if (!device.label) {
  20568. device.isCustomLabel = true;
  20569. if (device.kind === 'videoinput') {
  20570. device.label = 'Camera ' + (videoInputDevices.length + 1);
  20571. } else if (device.kind === 'audioinput') {
  20572. device.label = 'Microphone ' + (audioInputDevices.length + 1);
  20573. } else if (device.kind === 'audiooutput') {
  20574. device.label = 'Speaker ' + (audioOutputDevices.length + 1);
  20575. } else {
  20576. device.label = 'Please invoke getUserMedia once.';
  20577. }
  20578. if (typeof DetectRTC !== 'undefined' && DetectRTC.browser.isChrome && DetectRTC.browser.version >= 46 && !/^(https:|chrome-extension:)$/g.test(location.protocol || '')) {
  20579. if (typeof document !== 'undefined' && typeof document.domain === 'string' && document.domain.search && document.domain.search(/localhost|127.0./g) === -1) {
  20580. device.label = 'HTTPs is required to get label of this ' + device.kind + ' device.';
  20581. }
  20582. }
  20583. } else {
  20584. // Firefox on Android still returns empty label
  20585. if (device.kind === 'videoinput' && !isWebsiteHasWebcamPermissions) {
  20586. isWebsiteHasWebcamPermissions = true;
  20587. }
  20588. if (device.kind === 'audioinput' && !isWebsiteHasMicrophonePermissions) {
  20589. isWebsiteHasMicrophonePermissions = true;
  20590. }
  20591. }
  20592. if (device.kind === 'audioinput') {
  20593. hasMicrophone = true;
  20594. if (audioInputDevices.indexOf(device) === -1) {
  20595. audioInputDevices.push(device);
  20596. }
  20597. }
  20598. if (device.kind === 'audiooutput') {
  20599. hasSpeakers = true;
  20600. if (audioOutputDevices.indexOf(device) === -1) {
  20601. audioOutputDevices.push(device);
  20602. }
  20603. }
  20604. if (device.kind === 'videoinput') {
  20605. hasWebcam = true;
  20606. if (videoInputDevices.indexOf(device) === -1) {
  20607. videoInputDevices.push(device);
  20608. }
  20609. } // there is no 'videoouput' in the spec.
  20610. MediaDevices.push(device);
  20611. alreadyUsedDevices[device.deviceId + device.label + device.kind] = device;
  20612. });
  20613. if (typeof DetectRTC !== 'undefined') {
  20614. // to sync latest outputs
  20615. DetectRTC.MediaDevices = MediaDevices;
  20616. DetectRTC.hasMicrophone = hasMicrophone;
  20617. DetectRTC.hasSpeakers = hasSpeakers;
  20618. DetectRTC.hasWebcam = hasWebcam;
  20619. DetectRTC.isWebsiteHasWebcamPermissions = isWebsiteHasWebcamPermissions;
  20620. DetectRTC.isWebsiteHasMicrophonePermissions = isWebsiteHasMicrophonePermissions;
  20621. DetectRTC.audioInputDevices = audioInputDevices;
  20622. DetectRTC.audioOutputDevices = audioOutputDevices;
  20623. DetectRTC.videoInputDevices = videoInputDevices;
  20624. }
  20625. if (callback) {
  20626. callback();
  20627. }
  20628. });
  20629. }
  20630. var DetectRTC = window.DetectRTC || {}; // ----------
  20631. // DetectRTC.browser.name || DetectRTC.browser.version || DetectRTC.browser.fullVersion
  20632. DetectRTC.browser = getBrowserInfo();
  20633. detectPrivateMode(function (isPrivateBrowsing) {
  20634. DetectRTC.browser.isPrivateBrowsing = !!isPrivateBrowsing;
  20635. }); // DetectRTC.isChrome || DetectRTC.isFirefox || DetectRTC.isEdge
  20636. DetectRTC.browser['is' + DetectRTC.browser.name] = true; // -----------
  20637. DetectRTC.osName = osName;
  20638. DetectRTC.osVersion = osVersion;
  20639. var isNodeWebkit = typeof process === 'object' && typeof process.versions === 'object' && process.versions['node-webkit']; // --------- Detect if system supports WebRTC 1.0 or WebRTC 1.1.
  20640. var isWebRTCSupported = false;
  20641. ['RTCPeerConnection', 'webkitRTCPeerConnection', 'mozRTCPeerConnection', 'RTCIceGatherer'].forEach(function (item) {
  20642. if (isWebRTCSupported) {
  20643. return;
  20644. }
  20645. if (item in window) {
  20646. isWebRTCSupported = true;
  20647. }
  20648. });
  20649. DetectRTC.isWebRTCSupported = isWebRTCSupported; //-------
  20650. DetectRTC.isORTCSupported = typeof RTCIceGatherer !== 'undefined'; // --------- Detect if system supports screen capturing API
  20651. var isScreenCapturingSupported = false;
  20652. if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 35) {
  20653. isScreenCapturingSupported = true;
  20654. } else if (DetectRTC.browser.isFirefox && DetectRTC.browser.version >= 34) {
  20655. isScreenCapturingSupported = true;
  20656. } else if (DetectRTC.browser.isEdge && DetectRTC.browser.version >= 17) {
  20657. isScreenCapturingSupported = true; // navigator.getDisplayMedia
  20658. } else if (DetectRTC.osName === 'Android' && DetectRTC.browser.isChrome) {
  20659. isScreenCapturingSupported = true;
  20660. }
  20661. if (!/^(https:|chrome-extension:)$/g.test(location.protocol || '')) {
  20662. var isNonLocalHost = typeof document !== 'undefined' && typeof document.domain === 'string' && document.domain.search && document.domain.search(/localhost|127.0./g) === -1;
  20663. if (isNonLocalHost && (DetectRTC.browser.isChrome || DetectRTC.browser.isEdge || DetectRTC.browser.isOpera)) {
  20664. isScreenCapturingSupported = false;
  20665. } else if (DetectRTC.browser.isFirefox) {
  20666. isScreenCapturingSupported = false;
  20667. }
  20668. }
  20669. DetectRTC.isScreenCapturingSupported = isScreenCapturingSupported; // --------- Detect if WebAudio API are supported
  20670. var webAudio = {
  20671. isSupported: false,
  20672. isCreateMediaStreamSourceSupported: false
  20673. };
  20674. ['AudioContext', 'webkitAudioContext', 'mozAudioContext', 'msAudioContext'].forEach(function (item) {
  20675. if (webAudio.isSupported) {
  20676. return;
  20677. }
  20678. if (item in window) {
  20679. webAudio.isSupported = true;
  20680. if (window[item] && 'createMediaStreamSource' in window[item].prototype) {
  20681. webAudio.isCreateMediaStreamSourceSupported = true;
  20682. }
  20683. }
  20684. });
  20685. DetectRTC.isAudioContextSupported = webAudio.isSupported;
  20686. DetectRTC.isCreateMediaStreamSourceSupported = webAudio.isCreateMediaStreamSourceSupported; // ---------- Detect if SCTP/RTP channels are supported.
  20687. var isRtpDataChannelsSupported = false;
  20688. if (DetectRTC.browser.isChrome && DetectRTC.browser.version > 31) {
  20689. isRtpDataChannelsSupported = true;
  20690. }
  20691. DetectRTC.isRtpDataChannelsSupported = isRtpDataChannelsSupported;
  20692. var isSCTPSupportd = false;
  20693. if (DetectRTC.browser.isFirefox && DetectRTC.browser.version > 28) {
  20694. isSCTPSupportd = true;
  20695. } else if (DetectRTC.browser.isChrome && DetectRTC.browser.version > 25) {
  20696. isSCTPSupportd = true;
  20697. } else if (DetectRTC.browser.isOpera && DetectRTC.browser.version >= 11) {
  20698. isSCTPSupportd = true;
  20699. }
  20700. DetectRTC.isSctpDataChannelsSupported = isSCTPSupportd; // ---------
  20701. DetectRTC.isMobileDevice = isMobileDevice; // "isMobileDevice" boolean is defined in "getBrowserInfo.js"
  20702. // ------
  20703. var isGetUserMediaSupported = false;
  20704. if (navigator.getUserMedia) {
  20705. isGetUserMediaSupported = true;
  20706. } else if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  20707. isGetUserMediaSupported = true;
  20708. }
  20709. if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 46 && !/^(https:|chrome-extension:)$/g.test(location.protocol || '')) {
  20710. if (typeof document !== 'undefined' && typeof document.domain === 'string' && document.domain.search && document.domain.search(/localhost|127.0./g) === -1) {
  20711. isGetUserMediaSupported = 'Requires HTTPs';
  20712. }
  20713. }
  20714. if (DetectRTC.osName === 'Nodejs') {
  20715. isGetUserMediaSupported = false;
  20716. }
  20717. DetectRTC.isGetUserMediaSupported = isGetUserMediaSupported;
  20718. var displayResolution = '';
  20719. if (screen.width) {
  20720. var width = screen.width ? screen.width : '';
  20721. var height = screen.height ? screen.height : '';
  20722. displayResolution += '' + width + ' x ' + height;
  20723. }
  20724. DetectRTC.displayResolution = displayResolution;
  20725. function getAspectRatio(w, h) {
  20726. function gcd(a, b) {
  20727. return b == 0 ? a : gcd(b, a % b);
  20728. }
  20729. var r = gcd(w, h);
  20730. return w / r / (h / r);
  20731. }
  20732. DetectRTC.displayAspectRatio = getAspectRatio(screen.width, screen.height).toFixed(2); // ----------
  20733. DetectRTC.isCanvasSupportsStreamCapturing = isCanvasSupportsStreamCapturing;
  20734. DetectRTC.isVideoSupportsStreamCapturing = isVideoSupportsStreamCapturing;
  20735. if (DetectRTC.browser.name == 'Chrome' && DetectRTC.browser.version >= 53) {
  20736. if (!DetectRTC.isCanvasSupportsStreamCapturing) {
  20737. DetectRTC.isCanvasSupportsStreamCapturing = 'Requires chrome flag: enable-experimental-web-platform-features';
  20738. }
  20739. if (!DetectRTC.isVideoSupportsStreamCapturing) {
  20740. DetectRTC.isVideoSupportsStreamCapturing = 'Requires chrome flag: enable-experimental-web-platform-features';
  20741. }
  20742. } // ------
  20743. DetectRTC.DetectLocalIPAddress = DetectLocalIPAddress;
  20744. DetectRTC.isWebSocketsSupported = 'WebSocket' in window && 2 === window.WebSocket.CLOSING;
  20745. DetectRTC.isWebSocketsBlocked = !DetectRTC.isWebSocketsSupported;
  20746. if (DetectRTC.osName === 'Nodejs') {
  20747. DetectRTC.isWebSocketsSupported = true;
  20748. DetectRTC.isWebSocketsBlocked = false;
  20749. }
  20750. DetectRTC.checkWebSocketsSupport = function (callback) {
  20751. callback = callback || function () {};
  20752. try {
  20753. var starttime;
  20754. var websocket = new WebSocket('wss://echo.websocket.org:443/');
  20755. websocket.onopen = function () {
  20756. DetectRTC.isWebSocketsBlocked = false;
  20757. starttime = new Date().getTime();
  20758. websocket.send('ping');
  20759. };
  20760. websocket.onmessage = function () {
  20761. DetectRTC.WebsocketLatency = new Date().getTime() - starttime + 'ms';
  20762. callback();
  20763. websocket.close();
  20764. websocket = null;
  20765. };
  20766. websocket.onerror = function () {
  20767. DetectRTC.isWebSocketsBlocked = true;
  20768. callback();
  20769. };
  20770. } catch (e) {
  20771. DetectRTC.isWebSocketsBlocked = true;
  20772. callback();
  20773. }
  20774. }; // -------
  20775. DetectRTC.load = function (callback) {
  20776. callback = callback || function () {};
  20777. checkDeviceSupport(callback);
  20778. }; // check for microphone/camera support!
  20779. if (typeof checkDeviceSupport === 'function') {// checkDeviceSupport();
  20780. }
  20781. if (typeof MediaDevices !== 'undefined') {
  20782. DetectRTC.MediaDevices = MediaDevices;
  20783. } else {
  20784. DetectRTC.MediaDevices = [];
  20785. }
  20786. DetectRTC.hasMicrophone = hasMicrophone;
  20787. DetectRTC.hasSpeakers = hasSpeakers;
  20788. DetectRTC.hasWebcam = hasWebcam;
  20789. DetectRTC.isWebsiteHasWebcamPermissions = isWebsiteHasWebcamPermissions;
  20790. DetectRTC.isWebsiteHasMicrophonePermissions = isWebsiteHasMicrophonePermissions;
  20791. DetectRTC.audioInputDevices = audioInputDevices;
  20792. DetectRTC.audioOutputDevices = audioOutputDevices;
  20793. DetectRTC.videoInputDevices = videoInputDevices; // ------
  20794. var isSetSinkIdSupported = false;
  20795. if (typeof document !== 'undefined' && typeof document.createElement === 'function' && 'setSinkId' in document.createElement('video')) {
  20796. isSetSinkIdSupported = true;
  20797. }
  20798. DetectRTC.isSetSinkIdSupported = isSetSinkIdSupported; // -----
  20799. var isRTPSenderReplaceTracksSupported = false;
  20800. if (DetectRTC.browser.isFirefox && typeof mozRTCPeerConnection !== 'undefined'
  20801. /*&& DetectRTC.browser.version > 39*/
  20802. ) {
  20803. /*global mozRTCPeerConnection:true */
  20804. if ('getSenders' in mozRTCPeerConnection.prototype) {
  20805. isRTPSenderReplaceTracksSupported = true;
  20806. }
  20807. } else if (DetectRTC.browser.isChrome && typeof webkitRTCPeerConnection !== 'undefined') {
  20808. /*global webkitRTCPeerConnection:true */
  20809. if ('getSenders' in webkitRTCPeerConnection.prototype) {
  20810. isRTPSenderReplaceTracksSupported = true;
  20811. }
  20812. }
  20813. DetectRTC.isRTPSenderReplaceTracksSupported = isRTPSenderReplaceTracksSupported; //------
  20814. var isRemoteStreamProcessingSupported = false;
  20815. if (DetectRTC.browser.isFirefox && DetectRTC.browser.version > 38) {
  20816. isRemoteStreamProcessingSupported = true;
  20817. }
  20818. DetectRTC.isRemoteStreamProcessingSupported = isRemoteStreamProcessingSupported; //-------
  20819. var isApplyConstraintsSupported = false;
  20820. /*global MediaStreamTrack:true */
  20821. if (typeof MediaStreamTrack !== 'undefined' && 'applyConstraints' in MediaStreamTrack.prototype) {
  20822. isApplyConstraintsSupported = true;
  20823. }
  20824. DetectRTC.isApplyConstraintsSupported = isApplyConstraintsSupported; //-------
  20825. var isMultiMonitorScreenCapturingSupported = false;
  20826. if (DetectRTC.browser.isFirefox && DetectRTC.browser.version >= 43) {
  20827. // version 43 merely supports platforms for multi-monitors
  20828. // version 44 will support exact multi-monitor selection i.e. you can select any monitor for screen capturing.
  20829. isMultiMonitorScreenCapturingSupported = true;
  20830. }
  20831. DetectRTC.isMultiMonitorScreenCapturingSupported = isMultiMonitorScreenCapturingSupported;
  20832. DetectRTC.isPromisesSupported = !!('Promise' in window); // version is generated by "grunt"
  20833. DetectRTC.version = '1.3.7';
  20834. if (typeof DetectRTC === 'undefined') {
  20835. window.DetectRTC = {};
  20836. }
  20837. var MediaStream = window.MediaStream;
  20838. if (typeof MediaStream === 'undefined' && typeof webkitMediaStream !== 'undefined') {
  20839. MediaStream = webkitMediaStream;
  20840. }
  20841. if (typeof MediaStream !== 'undefined' && typeof MediaStream === 'function') {
  20842. DetectRTC.MediaStream = Object.keys(MediaStream.prototype);
  20843. } else DetectRTC.MediaStream = false;
  20844. if (typeof MediaStreamTrack !== 'undefined') {
  20845. DetectRTC.MediaStreamTrack = Object.keys(MediaStreamTrack.prototype);
  20846. } else DetectRTC.MediaStreamTrack = false;
  20847. var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
  20848. if (typeof RTCPeerConnection !== 'undefined') {
  20849. DetectRTC.RTCPeerConnection = Object.keys(RTCPeerConnection.prototype);
  20850. } else DetectRTC.RTCPeerConnection = false;
  20851. window.DetectRTC = DetectRTC;
  20852. if (true
  20853. /* && !!module.exports*/
  20854. ) {
  20855. module.exports = DetectRTC;
  20856. }
  20857. if (true) {
  20858. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  20859. return DetectRTC;
  20860. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  20861. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  20862. }
  20863. })();
  20864. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15), __webpack_require__(21)))
  20865. }),
  20866. /* 21 */
  20867. (function(module, exports) {
  20868. var g; // This works in non-strict mode
  20869. g = function () {
  20870. return this;
  20871. }();
  20872. try {
  20873. // This works if eval is allowed (see CSP)
  20874. g = g || Function("return this")() || (1, eval)("this");
  20875. } catch (e) {
  20876. // This works if the window reference is available
  20877. if (typeof window === "object") g = window;
  20878. } // g can still be undefined, but nothing to do about it...
  20879. // We return undefined, instead of nothing here, so it's
  20880. // easier to handle this case. if(!global) { ...}
  20881. module.exports = g;
  20882. }),
  20883. /* 22 */
  20884. (function(module, exports, __webpack_require__) {
  20885. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
  20886. * jQuery JavaScript Library v3.3.1
  20887. * https://jquery.com/
  20888. *
  20889. * Includes Sizzle.js
  20890. * https://sizzlejs.com/
  20891. *
  20892. * Copyright JS Foundation and other contributors
  20893. * Released under the MIT license
  20894. * https://jquery.org/license
  20895. *
  20896. * Date: 2018-01-20T17:24Z
  20897. */
  20898. (function (global, factory) {
  20899. "use strict";
  20900. if (typeof module === "object" && typeof module.exports === "object") {
  20901. // For CommonJS and CommonJS-like environments where a proper `window`
  20902. // is present, execute the factory and get jQuery.
  20903. // For environments that do not have a `window` with a `document`
  20904. // (such as Node.js), expose a factory as module.exports.
  20905. // This accentuates the need for the creation of a real `window`.
  20906. // e.g. var jQuery = require("jquery")(window);
  20907. // See ticket #14549 for more info.
  20908. module.exports = global.document ? factory(global, true) : function (w) {
  20909. if (!w.document) {
  20910. throw new Error("jQuery requires a window with a document");
  20911. }
  20912. return factory(w);
  20913. };
  20914. } else {
  20915. factory(global);
  20916. } // Pass this if window is not defined yet
  20917. })(typeof window !== "undefined" ? window : this, function (window, noGlobal) {
  20918. // Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1
  20919. // throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode
  20920. // arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common
  20921. // enough that all such attempts are guarded in a try block.
  20922. "use strict";
  20923. var arr = [];
  20924. var document = window.document;
  20925. var getProto = Object.getPrototypeOf;
  20926. var slice = arr.slice;
  20927. var concat = arr.concat;
  20928. var push = arr.push;
  20929. var indexOf = arr.indexOf;
  20930. var class2type = {};
  20931. var toString = class2type.toString;
  20932. var hasOwn = class2type.hasOwnProperty;
  20933. var fnToString = hasOwn.toString;
  20934. var ObjectFunctionString = fnToString.call(Object);
  20935. var support = {};
  20936. var isFunction = function isFunction(obj) {
  20937. // Support: Chrome <=57, Firefox <=52
  20938. // In some browsers, typeof returns "function" for HTML <object> elements
  20939. // (i.e., `typeof document.createElement( "object" ) === "function"`).
  20940. // We don't want to classify *any* DOM node as a function.
  20941. return typeof obj === "function" && typeof obj.nodeType !== "number";
  20942. };
  20943. var isWindow = function isWindow(obj) {
  20944. return obj != null && obj === obj.window;
  20945. };
  20946. var preservedScriptAttributes = {
  20947. type: true,
  20948. src: true,
  20949. noModule: true
  20950. };
  20951. function DOMEval(code, doc, node) {
  20952. doc = doc || document;
  20953. var i,
  20954. script = doc.createElement("script");
  20955. script.text = code;
  20956. if (node) {
  20957. for (i in preservedScriptAttributes) {
  20958. if (node[i]) {
  20959. script[i] = node[i];
  20960. }
  20961. }
  20962. }
  20963. doc.head.appendChild(script).parentNode.removeChild(script);
  20964. }
  20965. function toType(obj) {
  20966. if (obj == null) {
  20967. return obj + "";
  20968. } // Support: Android <=2.3 only (functionish RegExp)
  20969. return typeof obj === "object" || typeof obj === "function" ? class2type[toString.call(obj)] || "object" : typeof obj;
  20970. }
  20971. /* global Symbol */
  20972. // Defining this global in .eslintrc.json would create a danger of using the global
  20973. // unguarded in another place, it seems safer to define global only for this module
  20974. var version = "3.3.1",
  20975. // Define a local copy of jQuery
  20976. jQuery = function (selector, context) {
  20977. // The jQuery object is actually just the init constructor 'enhanced'
  20978. // Need init if jQuery is called (just allow error to be thrown if not included)
  20979. return new jQuery.fn.init(selector, context);
  20980. },
  20981. // Support: Android <=4.0 only
  20982. // Make sure we trim BOM and NBSP
  20983. rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
  20984. jQuery.fn = jQuery.prototype = {
  20985. // The current version of jQuery being used
  20986. jquery: version,
  20987. constructor: jQuery,
  20988. // The default length of a jQuery object is 0
  20989. length: 0,
  20990. toArray: function () {
  20991. return slice.call(this);
  20992. },
  20993. // Get the Nth element in the matched element set OR
  20994. // Get the whole matched element set as a clean array
  20995. get: function (num) {
  20996. // Return all the elements in a clean array
  20997. if (num == null) {
  20998. return slice.call(this);
  20999. } // Return just the one element from the set
  21000. return num < 0 ? this[num + this.length] : this[num];
  21001. },
  21002. // Take an array of elements and push it onto the stack
  21003. // (returning the new matched element set)
  21004. pushStack: function (elems) {
  21005. // Build a new jQuery matched element set
  21006. var ret = jQuery.merge(this.constructor(), elems); // Add the old object onto the stack (as a reference)
  21007. ret.prevObject = this; // Return the newly-formed element set
  21008. return ret;
  21009. },
  21010. // Execute a callback for every element in the matched set.
  21011. each: function (callback) {
  21012. return jQuery.each(this, callback);
  21013. },
  21014. map: function (callback) {
  21015. return this.pushStack(jQuery.map(this, function (elem, i) {
  21016. return callback.call(elem, i, elem);
  21017. }));
  21018. },
  21019. slice: function () {
  21020. return this.pushStack(slice.apply(this, arguments));
  21021. },
  21022. first: function () {
  21023. return this.eq(0);
  21024. },
  21025. last: function () {
  21026. return this.eq(-1);
  21027. },
  21028. eq: function (i) {
  21029. var len = this.length,
  21030. j = +i + (i < 0 ? len : 0);
  21031. return this.pushStack(j >= 0 && j < len ? [this[j]] : []);
  21032. },
  21033. end: function () {
  21034. return this.prevObject || this.constructor();
  21035. },
  21036. // For internal use only.
  21037. // Behaves like an Array's method, not like a jQuery method.
  21038. push: push,
  21039. sort: arr.sort,
  21040. splice: arr.splice
  21041. };
  21042. jQuery.extend = jQuery.fn.extend = function () {
  21043. var options,
  21044. name,
  21045. src,
  21046. copy,
  21047. copyIsArray,
  21048. clone,
  21049. target = arguments[0] || {},
  21050. i = 1,
  21051. length = arguments.length,
  21052. deep = false; // Handle a deep copy situation
  21053. if (typeof target === "boolean") {
  21054. deep = target; // Skip the boolean and the target
  21055. target = arguments[i] || {};
  21056. i++;
  21057. } // Handle case when target is a string or something (possible in deep copy)
  21058. if (typeof target !== "object" && !isFunction(target)) {
  21059. target = {};
  21060. } // Extend jQuery itself if only one argument is passed
  21061. if (i === length) {
  21062. target = this;
  21063. i--;
  21064. }
  21065. for (; i < length; i++) {
  21066. // Only deal with non-null/undefined values
  21067. if ((options = arguments[i]) != null) {
  21068. // Extend the base object
  21069. for (name in options) {
  21070. src = target[name];
  21071. copy = options[name]; // Prevent never-ending loop
  21072. if (target === copy) {
  21073. continue;
  21074. } // Recurse if we're merging plain objects or arrays
  21075. if (deep && copy && (jQuery.isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) {
  21076. if (copyIsArray) {
  21077. copyIsArray = false;
  21078. clone = src && Array.isArray(src) ? src : [];
  21079. } else {
  21080. clone = src && jQuery.isPlainObject(src) ? src : {};
  21081. } // Never move original objects, clone them
  21082. target[name] = jQuery.extend(deep, clone, copy); // Don't bring in undefined values
  21083. } else if (copy !== undefined) {
  21084. target[name] = copy;
  21085. }
  21086. }
  21087. }
  21088. } // Return the modified object
  21089. return target;
  21090. };
  21091. jQuery.extend({
  21092. // Unique for each copy of jQuery on the page
  21093. expando: "jQuery" + (version + Math.random()).replace(/\D/g, ""),
  21094. // Assume jQuery is ready without the ready module
  21095. isReady: true,
  21096. error: function (msg) {
  21097. throw new Error(msg);
  21098. },
  21099. noop: function () {},
  21100. isPlainObject: function (obj) {
  21101. var proto, Ctor; // Detect obvious negatives
  21102. // Use toString instead of jQuery.type to catch host objects
  21103. if (!obj || toString.call(obj) !== "[object Object]") {
  21104. return false;
  21105. }
  21106. proto = getProto(obj); // Objects with no prototype (e.g., `Object.create( null )`) are plain
  21107. if (!proto) {
  21108. return true;
  21109. } // Objects with prototype are plain iff they were constructed by a global Object function
  21110. Ctor = hasOwn.call(proto, "constructor") && proto.constructor;
  21111. return typeof Ctor === "function" && fnToString.call(Ctor) === ObjectFunctionString;
  21112. },
  21113. isEmptyObject: function (obj) {
  21114. /* eslint-disable no-unused-vars */
  21115. // See https://github.com/eslint/eslint/issues/6125
  21116. var name;
  21117. for (name in obj) {
  21118. return false;
  21119. }
  21120. return true;
  21121. },
  21122. // Evaluates a script in a global context
  21123. globalEval: function (code) {
  21124. DOMEval(code);
  21125. },
  21126. each: function (obj, callback) {
  21127. var length,
  21128. i = 0;
  21129. if (isArrayLike(obj)) {
  21130. length = obj.length;
  21131. for (; i < length; i++) {
  21132. if (callback.call(obj[i], i, obj[i]) === false) {
  21133. break;
  21134. }
  21135. }
  21136. } else {
  21137. for (i in obj) {
  21138. if (callback.call(obj[i], i, obj[i]) === false) {
  21139. break;
  21140. }
  21141. }
  21142. }
  21143. return obj;
  21144. },
  21145. // Support: Android <=4.0 only
  21146. trim: function (text) {
  21147. return text == null ? "" : (text + "").replace(rtrim, "");
  21148. },
  21149. // results is for internal usage only
  21150. makeArray: function (arr, results) {
  21151. var ret = results || [];
  21152. if (arr != null) {
  21153. if (isArrayLike(Object(arr))) {
  21154. jQuery.merge(ret, typeof arr === "string" ? [arr] : arr);
  21155. } else {
  21156. push.call(ret, arr);
  21157. }
  21158. }
  21159. return ret;
  21160. },
  21161. inArray: function (elem, arr, i) {
  21162. return arr == null ? -1 : indexOf.call(arr, elem, i);
  21163. },
  21164. // Support: Android <=4.0 only, PhantomJS 1 only
  21165. // push.apply(_, arraylike) throws on ancient WebKit
  21166. merge: function (first, second) {
  21167. var len = +second.length,
  21168. j = 0,
  21169. i = first.length;
  21170. for (; j < len; j++) {
  21171. first[i++] = second[j];
  21172. }
  21173. first.length = i;
  21174. return first;
  21175. },
  21176. grep: function (elems, callback, invert) {
  21177. var callbackInverse,
  21178. matches = [],
  21179. i = 0,
  21180. length = elems.length,
  21181. callbackExpect = !invert; // Go through the array, only saving the items
  21182. // that pass the validator function
  21183. for (; i < length; i++) {
  21184. callbackInverse = !callback(elems[i], i);
  21185. if (callbackInverse !== callbackExpect) {
  21186. matches.push(elems[i]);
  21187. }
  21188. }
  21189. return matches;
  21190. },
  21191. // arg is for internal usage only
  21192. map: function (elems, callback, arg) {
  21193. var length,
  21194. value,
  21195. i = 0,
  21196. ret = []; // Go through the array, translating each of the items to their new values
  21197. if (isArrayLike(elems)) {
  21198. length = elems.length;
  21199. for (; i < length; i++) {
  21200. value = callback(elems[i], i, arg);
  21201. if (value != null) {
  21202. ret.push(value);
  21203. }
  21204. } // Go through every key on the object,
  21205. } else {
  21206. for (i in elems) {
  21207. value = callback(elems[i], i, arg);
  21208. if (value != null) {
  21209. ret.push(value);
  21210. }
  21211. }
  21212. } // Flatten any nested arrays
  21213. return concat.apply([], ret);
  21214. },
  21215. // A global GUID counter for objects
  21216. guid: 1,
  21217. // jQuery.support is not used in Core but other projects attach their
  21218. // properties to it so it needs to exist.
  21219. support: support
  21220. });
  21221. if (typeof Symbol === "function") {
  21222. jQuery.fn[Symbol.iterator] = arr[Symbol.iterator];
  21223. } // Populate the class2type map
  21224. jQuery.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "), function (i, name) {
  21225. class2type["[object " + name + "]"] = name.toLowerCase();
  21226. });
  21227. function isArrayLike(obj) {
  21228. // Support: real iOS 8.2 only (not reproducible in simulator)
  21229. // `in` check used to prevent JIT error (gh-2145)
  21230. // hasOwn isn't used here due to false negatives
  21231. // regarding Nodelist length in IE
  21232. var length = !!obj && "length" in obj && obj.length,
  21233. type = toType(obj);
  21234. if (isFunction(obj) || isWindow(obj)) {
  21235. return false;
  21236. }
  21237. return type === "array" || length === 0 || typeof length === "number" && length > 0 && length - 1 in obj;
  21238. }
  21239. var Sizzle =
  21240. /*!
  21241. * Sizzle CSS Selector Engine v2.3.3
  21242. * https://sizzlejs.com/
  21243. *
  21244. * Copyright jQuery Foundation and other contributors
  21245. * Released under the MIT license
  21246. * http://jquery.org/license
  21247. *
  21248. * Date: 2016-08-08
  21249. */
  21250. function (window) {
  21251. var i,
  21252. support,
  21253. Expr,
  21254. getText,
  21255. isXML,
  21256. tokenize,
  21257. compile,
  21258. select,
  21259. outermostContext,
  21260. sortInput,
  21261. hasDuplicate,
  21262. // Local document vars
  21263. setDocument,
  21264. document,
  21265. docElem,
  21266. documentIsHTML,
  21267. rbuggyQSA,
  21268. rbuggyMatches,
  21269. matches,
  21270. contains,
  21271. // Instance-specific data
  21272. expando = "sizzle" + 1 * new Date(),
  21273. preferredDoc = window.document,
  21274. dirruns = 0,
  21275. done = 0,
  21276. classCache = createCache(),
  21277. tokenCache = createCache(),
  21278. compilerCache = createCache(),
  21279. sortOrder = function (a, b) {
  21280. if (a === b) {
  21281. hasDuplicate = true;
  21282. }
  21283. return 0;
  21284. },
  21285. // Instance methods
  21286. hasOwn = {}.hasOwnProperty,
  21287. arr = [],
  21288. pop = arr.pop,
  21289. push_native = arr.push,
  21290. push = arr.push,
  21291. slice = arr.slice,
  21292. // Use a stripped-down indexOf as it's faster than native
  21293. // https://jsperf.com/thor-indexof-vs-for/5
  21294. indexOf = function (list, elem) {
  21295. var i = 0,
  21296. len = list.length;
  21297. for (; i < len; i++) {
  21298. if (list[i] === elem) {
  21299. return i;
  21300. }
  21301. }
  21302. return -1;
  21303. },
  21304. booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
  21305. // Regular expressions
  21306. // http://www.w3.org/TR/css3-selectors/#whitespace
  21307. whitespace = "[\\x20\\t\\r\\n\\f]",
  21308. // http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
  21309. identifier = "(?:\\\\.|[\\w-]|[^\0-\\xa0])+",
  21310. // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
  21311. attributes = "\\[" + whitespace + "*(" + identifier + ")(?:" + whitespace + // Operator (capture 2)
  21312. "*([*^$|!~]?=)" + whitespace + // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
  21313. "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace + "*\\]",
  21314. pseudos = ":(" + identifier + ")(?:\\((" + // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
  21315. // 1. quoted (capture 3; capture 4 or capture 5)
  21316. "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" + // 2. simple (capture 6)
  21317. "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" + // 3. anything else (capture 2)
  21318. ".*" + ")\\)|)",
  21319. // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
  21320. rwhitespace = new RegExp(whitespace + "+", "g"),
  21321. rtrim = new RegExp("^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g"),
  21322. rcomma = new RegExp("^" + whitespace + "*," + whitespace + "*"),
  21323. rcombinators = new RegExp("^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*"),
  21324. rattributeQuotes = new RegExp("=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g"),
  21325. rpseudo = new RegExp(pseudos),
  21326. ridentifier = new RegExp("^" + identifier + "$"),
  21327. matchExpr = {
  21328. "ID": new RegExp("^#(" + identifier + ")"),
  21329. "CLASS": new RegExp("^\\.(" + identifier + ")"),
  21330. "TAG": new RegExp("^(" + identifier + "|[*])"),
  21331. "ATTR": new RegExp("^" + attributes),
  21332. "PSEUDO": new RegExp("^" + pseudos),
  21333. "CHILD": new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace + "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace + "*(\\d+)|))" + whitespace + "*\\)|)", "i"),
  21334. "bool": new RegExp("^(?:" + booleans + ")$", "i"),
  21335. // For use in libraries implementing .is()
  21336. // We use this for POS matching in `select`
  21337. "needsContext": new RegExp("^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i")
  21338. },
  21339. rinputs = /^(?:input|select|textarea|button)$/i,
  21340. rheader = /^h\d$/i,
  21341. rnative = /^[^{]+\{\s*\[native \w/,
  21342. // Easily-parseable/retrievable ID or TAG or CLASS selectors
  21343. rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
  21344. rsibling = /[+~]/,
  21345. // CSS escapes
  21346. // http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
  21347. runescape = new RegExp("\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig"),
  21348. funescape = function (_, escaped, escapedWhitespace) {
  21349. var high = "0x" + escaped - 0x10000; // NaN means non-codepoint
  21350. // Support: Firefox<24
  21351. // Workaround erroneous numeric interpretation of +"0x"
  21352. return high !== high || escapedWhitespace ? escaped : high < 0 ? // BMP codepoint
  21353. String.fromCharCode(high + 0x10000) : // Supplemental Plane codepoint (surrogate pair)
  21354. String.fromCharCode(high >> 10 | 0xD800, high & 0x3FF | 0xDC00);
  21355. },
  21356. // CSS string/identifier serialization
  21357. // https://drafts.csswg.org/cssom/#common-serializing-idioms
  21358. rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,
  21359. fcssescape = function (ch, asCodePoint) {
  21360. if (asCodePoint) {
  21361. // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
  21362. if (ch === "\0") {
  21363. return "\uFFFD";
  21364. } // Control characters and (dependent upon position) numbers get escaped as code points
  21365. return ch.slice(0, -1) + "\\" + ch.charCodeAt(ch.length - 1).toString(16) + " ";
  21366. } // Other potentially-special ASCII characters get backslash-escaped
  21367. return "\\" + ch;
  21368. },
  21369. // Used for iframes
  21370. // See setDocument()
  21371. // Removing the function wrapper causes a "Permission Denied"
  21372. // error in IE
  21373. unloadHandler = function () {
  21374. setDocument();
  21375. },
  21376. disabledAncestor = addCombinator(function (elem) {
  21377. return elem.disabled === true && ("form" in elem || "label" in elem);
  21378. }, {
  21379. dir: "parentNode",
  21380. next: "legend"
  21381. }); // Optimize for push.apply( _, NodeList )
  21382. try {
  21383. push.apply(arr = slice.call(preferredDoc.childNodes), preferredDoc.childNodes); // Support: Android<4.0
  21384. // Detect silently failing push.apply
  21385. arr[preferredDoc.childNodes.length].nodeType;
  21386. } catch (e) {
  21387. push = {
  21388. apply: arr.length ? // Leverage slice if possible
  21389. function (target, els) {
  21390. push_native.apply(target, slice.call(els));
  21391. } : // Support: IE<9
  21392. // Otherwise append directly
  21393. function (target, els) {
  21394. var j = target.length,
  21395. i = 0; // Can't trust NodeList.length
  21396. while (target[j++] = els[i++]) {}
  21397. target.length = j - 1;
  21398. }
  21399. };
  21400. }
  21401. function Sizzle(selector, context, results, seed) {
  21402. var m,
  21403. i,
  21404. elem,
  21405. nid,
  21406. match,
  21407. groups,
  21408. newSelector,
  21409. newContext = context && context.ownerDocument,
  21410. // nodeType defaults to 9, since context defaults to document
  21411. nodeType = context ? context.nodeType : 9;
  21412. results = results || []; // Return early from calls with invalid selector or context
  21413. if (typeof selector !== "string" || !selector || nodeType !== 1 && nodeType !== 9 && nodeType !== 11) {
  21414. return results;
  21415. } // Try to shortcut find operations (as opposed to filters) in HTML documents
  21416. if (!seed) {
  21417. if ((context ? context.ownerDocument || context : preferredDoc) !== document) {
  21418. setDocument(context);
  21419. }
  21420. context = context || document;
  21421. if (documentIsHTML) {
  21422. // If the selector is sufficiently simple, try using a "get*By*" DOM method
  21423. // (excepting DocumentFragment context, where the methods don't exist)
  21424. if (nodeType !== 11 && (match = rquickExpr.exec(selector))) {
  21425. // ID selector
  21426. if (m = match[1]) {
  21427. // Document context
  21428. if (nodeType === 9) {
  21429. if (elem = context.getElementById(m)) {
  21430. // Support: IE, Opera, Webkit
  21431. // TODO: identify versions
  21432. // getElementById can match elements by name instead of ID
  21433. if (elem.id === m) {
  21434. results.push(elem);
  21435. return results;
  21436. }
  21437. } else {
  21438. return results;
  21439. } // Element context
  21440. } else {
  21441. // Support: IE, Opera, Webkit
  21442. // TODO: identify versions
  21443. // getElementById can match elements by name instead of ID
  21444. if (newContext && (elem = newContext.getElementById(m)) && contains(context, elem) && elem.id === m) {
  21445. results.push(elem);
  21446. return results;
  21447. }
  21448. } // Type selector
  21449. } else if (match[2]) {
  21450. push.apply(results, context.getElementsByTagName(selector));
  21451. return results; // Class selector
  21452. } else if ((m = match[3]) && support.getElementsByClassName && context.getElementsByClassName) {
  21453. push.apply(results, context.getElementsByClassName(m));
  21454. return results;
  21455. }
  21456. } // Take advantage of querySelectorAll
  21457. if (support.qsa && !compilerCache[selector + " "] && (!rbuggyQSA || !rbuggyQSA.test(selector))) {
  21458. if (nodeType !== 1) {
  21459. newContext = context;
  21460. newSelector = selector; // qSA looks outside Element context, which is not what we want
  21461. // Thanks to Andrew Dupont for this workaround technique
  21462. // Support: IE <=8
  21463. // Exclude object elements
  21464. } else if (context.nodeName.toLowerCase() !== "object") {
  21465. // Capture the context ID, setting it first if necessary
  21466. if (nid = context.getAttribute("id")) {
  21467. nid = nid.replace(rcssescape, fcssescape);
  21468. } else {
  21469. context.setAttribute("id", nid = expando);
  21470. } // Prefix every selector in the list
  21471. groups = tokenize(selector);
  21472. i = groups.length;
  21473. while (i--) {
  21474. groups[i] = "#" + nid + " " + toSelector(groups[i]);
  21475. }
  21476. newSelector = groups.join(","); // Expand context for sibling selectors
  21477. newContext = rsibling.test(selector) && testContext(context.parentNode) || context;
  21478. }
  21479. if (newSelector) {
  21480. try {
  21481. push.apply(results, newContext.querySelectorAll(newSelector));
  21482. return results;
  21483. } catch (qsaError) {} finally {
  21484. if (nid === expando) {
  21485. context.removeAttribute("id");
  21486. }
  21487. }
  21488. }
  21489. }
  21490. }
  21491. } // All others
  21492. return select(selector.replace(rtrim, "$1"), context, results, seed);
  21493. }
  21494. /**
  21495. * Create key-value caches of limited size
  21496. * @returns {function(string, object)} Returns the Object data after storing it on itself with
  21497. * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
  21498. * deleting the oldest entry
  21499. */
  21500. function createCache() {
  21501. var keys = [];
  21502. function cache(key, value) {
  21503. // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
  21504. if (keys.push(key + " ") > Expr.cacheLength) {
  21505. // Only keep the most recent entries
  21506. delete cache[keys.shift()];
  21507. }
  21508. return cache[key + " "] = value;
  21509. }
  21510. return cache;
  21511. }
  21512. /**
  21513. * Mark a function for special use by Sizzle
  21514. * @param {Function} fn The function to mark
  21515. */
  21516. function markFunction(fn) {
  21517. fn[expando] = true;
  21518. return fn;
  21519. }
  21520. /**
  21521. * Support testing using an element
  21522. * @param {Function} fn Passed the created element and returns a boolean result
  21523. */
  21524. function assert(fn) {
  21525. var el = document.createElement("fieldset");
  21526. try {
  21527. return !!fn(el);
  21528. } catch (e) {
  21529. return false;
  21530. } finally {
  21531. // Remove from its parent by default
  21532. if (el.parentNode) {
  21533. el.parentNode.removeChild(el);
  21534. } // release memory in IE
  21535. el = null;
  21536. }
  21537. }
  21538. /**
  21539. * Adds the same handler for all of the specified attrs
  21540. * @param {String} attrs Pipe-separated list of attributes
  21541. * @param {Function} handler The method that will be applied
  21542. */
  21543. function addHandle(attrs, handler) {
  21544. var arr = attrs.split("|"),
  21545. i = arr.length;
  21546. while (i--) {
  21547. Expr.attrHandle[arr[i]] = handler;
  21548. }
  21549. }
  21550. /**
  21551. * Checks document order of two siblings
  21552. * @param {Element} a
  21553. * @param {Element} b
  21554. * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
  21555. */
  21556. function siblingCheck(a, b) {
  21557. var cur = b && a,
  21558. diff = cur && a.nodeType === 1 && b.nodeType === 1 && a.sourceIndex - b.sourceIndex; // Use IE sourceIndex if available on both nodes
  21559. if (diff) {
  21560. return diff;
  21561. } // Check if b follows a
  21562. if (cur) {
  21563. while (cur = cur.nextSibling) {
  21564. if (cur === b) {
  21565. return -1;
  21566. }
  21567. }
  21568. }
  21569. return a ? 1 : -1;
  21570. }
  21571. /**
  21572. * Returns a function to use in pseudos for input types
  21573. * @param {String} type
  21574. */
  21575. function createInputPseudo(type) {
  21576. return function (elem) {
  21577. var name = elem.nodeName.toLowerCase();
  21578. return name === "input" && elem.type === type;
  21579. };
  21580. }
  21581. /**
  21582. * Returns a function to use in pseudos for buttons
  21583. * @param {String} type
  21584. */
  21585. function createButtonPseudo(type) {
  21586. return function (elem) {
  21587. var name = elem.nodeName.toLowerCase();
  21588. return (name === "input" || name === "button") && elem.type === type;
  21589. };
  21590. }
  21591. /**
  21592. * Returns a function to use in pseudos for :enabled/:disabled
  21593. * @param {Boolean} disabled true for :disabled; false for :enabled
  21594. */
  21595. function createDisabledPseudo(disabled) {
  21596. // Known :disabled false positives: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable
  21597. return function (elem) {
  21598. // Only certain elements can match :enabled or :disabled
  21599. // https://html.spec.whatwg.org/multipage/scripting.html#selector-enabled
  21600. // https://html.spec.whatwg.org/multipage/scripting.html#selector-disabled
  21601. if ("form" in elem) {
  21602. // Check for inherited disabledness on relevant non-disabled elements:
  21603. // * listed form-associated elements in a disabled fieldset
  21604. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  21605. // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled
  21606. // * option elements in a disabled optgroup
  21607. // https://html.spec.whatwg.org/multipage/forms.html#concept-option-disabled
  21608. // All such elements have a "form" property.
  21609. if (elem.parentNode && elem.disabled === false) {
  21610. // Option elements defer to a parent optgroup if present
  21611. if ("label" in elem) {
  21612. if ("label" in elem.parentNode) {
  21613. return elem.parentNode.disabled === disabled;
  21614. } else {
  21615. return elem.disabled === disabled;
  21616. }
  21617. } // Support: IE 6 - 11
  21618. // Use the isDisabled shortcut property to check for disabled fieldset ancestors
  21619. return elem.isDisabled === disabled || // Where there is no isDisabled, check manually
  21620. /* jshint -W018 */
  21621. elem.isDisabled !== !disabled && disabledAncestor(elem) === disabled;
  21622. }
  21623. return elem.disabled === disabled; // Try to winnow out elements that can't be disabled before trusting the disabled property.
  21624. // Some victims get caught in our net (label, legend, menu, track), but it shouldn't
  21625. // even exist on them, let alone have a boolean value.
  21626. } else if ("label" in elem) {
  21627. return elem.disabled === disabled;
  21628. } // Remaining elements are neither :enabled nor :disabled
  21629. return false;
  21630. };
  21631. }
  21632. /**
  21633. * Returns a function to use in pseudos for positionals
  21634. * @param {Function} fn
  21635. */
  21636. function createPositionalPseudo(fn) {
  21637. return markFunction(function (argument) {
  21638. argument = +argument;
  21639. return markFunction(function (seed, matches) {
  21640. var j,
  21641. matchIndexes = fn([], seed.length, argument),
  21642. i = matchIndexes.length; // Match elements found at the specified indexes
  21643. while (i--) {
  21644. if (seed[j = matchIndexes[i]]) {
  21645. seed[j] = !(matches[j] = seed[j]);
  21646. }
  21647. }
  21648. });
  21649. });
  21650. }
  21651. /**
  21652. * Checks a node for validity as a Sizzle context
  21653. * @param {Element|Object=} context
  21654. * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
  21655. */
  21656. function testContext(context) {
  21657. return context && typeof context.getElementsByTagName !== "undefined" && context;
  21658. } // Expose support vars for convenience
  21659. support = Sizzle.support = {};
  21660. /**
  21661. * Detects XML nodes
  21662. * @param {Element|Object} elem An element or a document
  21663. * @returns {Boolean} True iff elem is a non-HTML XML node
  21664. */
  21665. isXML = Sizzle.isXML = function (elem) {
  21666. // documentElement is verified for cases where it doesn't yet exist
  21667. // (such as loading iframes in IE - #4833)
  21668. var documentElement = elem && (elem.ownerDocument || elem).documentElement;
  21669. return documentElement ? documentElement.nodeName !== "HTML" : false;
  21670. };
  21671. /**
  21672. * Sets document-related variables once based on the current document
  21673. * @param {Element|Object} [doc] An element or document object to use to set the document
  21674. * @returns {Object} Returns the current document
  21675. */
  21676. setDocument = Sizzle.setDocument = function (node) {
  21677. var hasCompare,
  21678. subWindow,
  21679. doc = node ? node.ownerDocument || node : preferredDoc; // Return early if doc is invalid or already selected
  21680. if (doc === document || doc.nodeType !== 9 || !doc.documentElement) {
  21681. return document;
  21682. } // Update global variables
  21683. document = doc;
  21684. docElem = document.documentElement;
  21685. documentIsHTML = !isXML(document); // Support: IE 9-11, Edge
  21686. // Accessing iframe documents after unload throws "permission denied" errors (jQuery #13936)
  21687. if (preferredDoc !== document && (subWindow = document.defaultView) && subWindow.top !== subWindow) {
  21688. // Support: IE 11, Edge
  21689. if (subWindow.addEventListener) {
  21690. subWindow.addEventListener("unload", unloadHandler, false); // Support: IE 9 - 10 only
  21691. } else if (subWindow.attachEvent) {
  21692. subWindow.attachEvent("onunload", unloadHandler);
  21693. }
  21694. }
  21695. /* Attributes
  21696. ---------------------------------------------------------------------- */
  21697. // Support: IE<8
  21698. // Verify that getAttribute really returns attributes and not properties
  21699. // (excepting IE8 booleans)
  21700. support.attributes = assert(function (el) {
  21701. el.className = "i";
  21702. return !el.getAttribute("className");
  21703. });
  21704. /* getElement(s)By*
  21705. ---------------------------------------------------------------------- */
  21706. // Check if getElementsByTagName("*") returns only elements
  21707. support.getElementsByTagName = assert(function (el) {
  21708. el.appendChild(document.createComment(""));
  21709. return !el.getElementsByTagName("*").length;
  21710. }); // Support: IE<9
  21711. support.getElementsByClassName = rnative.test(document.getElementsByClassName); // Support: IE<10
  21712. // Check if getElementById returns elements by name
  21713. // The broken getElementById methods don't pick up programmatically-set names,
  21714. // so use a roundabout getElementsByName test
  21715. support.getById = assert(function (el) {
  21716. docElem.appendChild(el).id = expando;
  21717. return !document.getElementsByName || !document.getElementsByName(expando).length;
  21718. }); // ID filter and find
  21719. if (support.getById) {
  21720. Expr.filter["ID"] = function (id) {
  21721. var attrId = id.replace(runescape, funescape);
  21722. return function (elem) {
  21723. return elem.getAttribute("id") === attrId;
  21724. };
  21725. };
  21726. Expr.find["ID"] = function (id, context) {
  21727. if (typeof context.getElementById !== "undefined" && documentIsHTML) {
  21728. var elem = context.getElementById(id);
  21729. return elem ? [elem] : [];
  21730. }
  21731. };
  21732. } else {
  21733. Expr.filter["ID"] = function (id) {
  21734. var attrId = id.replace(runescape, funescape);
  21735. return function (elem) {
  21736. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  21737. return node && node.value === attrId;
  21738. };
  21739. }; // Support: IE 6 - 7 only
  21740. // getElementById is not reliable as a find shortcut
  21741. Expr.find["ID"] = function (id, context) {
  21742. if (typeof context.getElementById !== "undefined" && documentIsHTML) {
  21743. var node,
  21744. i,
  21745. elems,
  21746. elem = context.getElementById(id);
  21747. if (elem) {
  21748. // Verify the id attribute
  21749. node = elem.getAttributeNode("id");
  21750. if (node && node.value === id) {
  21751. return [elem];
  21752. } // Fall back on getElementsByName
  21753. elems = context.getElementsByName(id);
  21754. i = 0;
  21755. while (elem = elems[i++]) {
  21756. node = elem.getAttributeNode("id");
  21757. if (node && node.value === id) {
  21758. return [elem];
  21759. }
  21760. }
  21761. }
  21762. return [];
  21763. }
  21764. };
  21765. } // Tag
  21766. Expr.find["TAG"] = support.getElementsByTagName ? function (tag, context) {
  21767. if (typeof context.getElementsByTagName !== "undefined") {
  21768. return context.getElementsByTagName(tag); // DocumentFragment nodes don't have gEBTN
  21769. } else if (support.qsa) {
  21770. return context.querySelectorAll(tag);
  21771. }
  21772. } : function (tag, context) {
  21773. var elem,
  21774. tmp = [],
  21775. i = 0,
  21776. // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
  21777. results = context.getElementsByTagName(tag); // Filter out possible comments
  21778. if (tag === "*") {
  21779. while (elem = results[i++]) {
  21780. if (elem.nodeType === 1) {
  21781. tmp.push(elem);
  21782. }
  21783. }
  21784. return tmp;
  21785. }
  21786. return results;
  21787. }; // Class
  21788. Expr.find["CLASS"] = support.getElementsByClassName && function (className, context) {
  21789. if (typeof context.getElementsByClassName !== "undefined" && documentIsHTML) {
  21790. return context.getElementsByClassName(className);
  21791. }
  21792. };
  21793. /* QSA/matchesSelector
  21794. ---------------------------------------------------------------------- */
  21795. // QSA and matchesSelector support
  21796. // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
  21797. rbuggyMatches = []; // qSa(:focus) reports false when true (Chrome 21)
  21798. // We allow this because of a bug in IE8/9 that throws an error
  21799. // whenever `document.activeElement` is accessed on an iframe
  21800. // So, we allow :focus to pass through QSA all the time to avoid the IE error
  21801. // See https://bugs.jquery.com/ticket/13378
  21802. rbuggyQSA = [];
  21803. if (support.qsa = rnative.test(document.querySelectorAll)) {
  21804. // Build QSA regex
  21805. // Regex strategy adopted from Diego Perini
  21806. assert(function (el) {
  21807. // Select is set to empty string on purpose
  21808. // This is to test IE's treatment of not explicitly
  21809. // setting a boolean content attribute,
  21810. // since its presence should be enough
  21811. // https://bugs.jquery.com/ticket/12359
  21812. docElem.appendChild(el).innerHTML = "<a id='" + expando + "'></a>" + "<select id='" + expando + "-\r\\' msallowcapture=''>" + "<option selected=''></option></select>"; // Support: IE8, Opera 11-12.16
  21813. // Nothing should be selected when empty strings follow ^= or $= or *=
  21814. // The test attribute must be unknown in Opera but "safe" for WinRT
  21815. // https://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
  21816. if (el.querySelectorAll("[msallowcapture^='']").length) {
  21817. rbuggyQSA.push("[*^$]=" + whitespace + "*(?:''|\"\")");
  21818. } // Support: IE8
  21819. // Boolean attributes and "value" are not treated correctly
  21820. if (!el.querySelectorAll("[selected]").length) {
  21821. rbuggyQSA.push("\\[" + whitespace + "*(?:value|" + booleans + ")");
  21822. } // Support: Chrome<29, Android<4.4, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.8+
  21823. if (!el.querySelectorAll("[id~=" + expando + "-]").length) {
  21824. rbuggyQSA.push("~=");
  21825. } // Webkit/Opera - :checked should return selected option elements
  21826. // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
  21827. // IE8 throws error here and will not see later tests
  21828. if (!el.querySelectorAll(":checked").length) {
  21829. rbuggyQSA.push(":checked");
  21830. } // Support: Safari 8+, iOS 8+
  21831. // https://bugs.webkit.org/show_bug.cgi?id=136851
  21832. // In-page `selector#id sibling-combinator selector` fails
  21833. if (!el.querySelectorAll("a#" + expando + "+*").length) {
  21834. rbuggyQSA.push(".#.+[+~]");
  21835. }
  21836. });
  21837. assert(function (el) {
  21838. el.innerHTML = "<a href='' disabled='disabled'></a>" + "<select disabled='disabled'><option/></select>"; // Support: Windows 8 Native Apps
  21839. // The type and name attributes are restricted during .innerHTML assignment
  21840. var input = document.createElement("input");
  21841. input.setAttribute("type", "hidden");
  21842. el.appendChild(input).setAttribute("name", "D"); // Support: IE8
  21843. // Enforce case-sensitivity of name attribute
  21844. if (el.querySelectorAll("[name=d]").length) {
  21845. rbuggyQSA.push("name" + whitespace + "*[*^$|!~]?=");
  21846. } // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
  21847. // IE8 throws error here and will not see later tests
  21848. if (el.querySelectorAll(":enabled").length !== 2) {
  21849. rbuggyQSA.push(":enabled", ":disabled");
  21850. } // Support: IE9-11+
  21851. // IE's :disabled selector does not pick up the children of disabled fieldsets
  21852. docElem.appendChild(el).disabled = true;
  21853. if (el.querySelectorAll(":disabled").length !== 2) {
  21854. rbuggyQSA.push(":enabled", ":disabled");
  21855. } // Opera 10-11 does not throw on post-comma invalid pseudos
  21856. el.querySelectorAll("*,:x");
  21857. rbuggyQSA.push(",.*:");
  21858. });
  21859. }
  21860. if (support.matchesSelector = rnative.test(matches = docElem.matches || docElem.webkitMatchesSelector || docElem.mozMatchesSelector || docElem.oMatchesSelector || docElem.msMatchesSelector)) {
  21861. assert(function (el) {
  21862. // Check to see if it's possible to do matchesSelector
  21863. // on a disconnected node (IE 9)
  21864. support.disconnectedMatch = matches.call(el, "*"); // This should fail with an exception
  21865. // Gecko does not error, returns false instead
  21866. matches.call(el, "[s!='']:x");
  21867. rbuggyMatches.push("!=", pseudos);
  21868. });
  21869. }
  21870. rbuggyQSA = rbuggyQSA.length && new RegExp(rbuggyQSA.join("|"));
  21871. rbuggyMatches = rbuggyMatches.length && new RegExp(rbuggyMatches.join("|"));
  21872. /* Contains
  21873. ---------------------------------------------------------------------- */
  21874. hasCompare = rnative.test(docElem.compareDocumentPosition); // Element contains another
  21875. // Purposefully self-exclusive
  21876. // As in, an element does not contain itself
  21877. contains = hasCompare || rnative.test(docElem.contains) ? function (a, b) {
  21878. var adown = a.nodeType === 9 ? a.documentElement : a,
  21879. bup = b && b.parentNode;
  21880. return a === bup || !!(bup && bup.nodeType === 1 && (adown.contains ? adown.contains(bup) : a.compareDocumentPosition && a.compareDocumentPosition(bup) & 16));
  21881. } : function (a, b) {
  21882. if (b) {
  21883. while (b = b.parentNode) {
  21884. if (b === a) {
  21885. return true;
  21886. }
  21887. }
  21888. }
  21889. return false;
  21890. };
  21891. /* Sorting
  21892. ---------------------------------------------------------------------- */
  21893. // Document order sorting
  21894. sortOrder = hasCompare ? function (a, b) {
  21895. // Flag for duplicate removal
  21896. if (a === b) {
  21897. hasDuplicate = true;
  21898. return 0;
  21899. } // Sort on method existence if only one input has compareDocumentPosition
  21900. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  21901. if (compare) {
  21902. return compare;
  21903. } // Calculate position if both inputs belong to the same document
  21904. compare = (a.ownerDocument || a) === (b.ownerDocument || b) ? a.compareDocumentPosition(b) : // Otherwise we know they are disconnected
  21905. 1; // Disconnected nodes
  21906. if (compare & 1 || !support.sortDetached && b.compareDocumentPosition(a) === compare) {
  21907. // Choose the first element that is related to our preferred document
  21908. if (a === document || a.ownerDocument === preferredDoc && contains(preferredDoc, a)) {
  21909. return -1;
  21910. }
  21911. if (b === document || b.ownerDocument === preferredDoc && contains(preferredDoc, b)) {
  21912. return 1;
  21913. } // Maintain original order
  21914. return sortInput ? indexOf(sortInput, a) - indexOf(sortInput, b) : 0;
  21915. }
  21916. return compare & 4 ? -1 : 1;
  21917. } : function (a, b) {
  21918. // Exit early if the nodes are identical
  21919. if (a === b) {
  21920. hasDuplicate = true;
  21921. return 0;
  21922. }
  21923. var cur,
  21924. i = 0,
  21925. aup = a.parentNode,
  21926. bup = b.parentNode,
  21927. ap = [a],
  21928. bp = [b]; // Parentless nodes are either documents or disconnected
  21929. if (!aup || !bup) {
  21930. return a === document ? -1 : b === document ? 1 : aup ? -1 : bup ? 1 : sortInput ? indexOf(sortInput, a) - indexOf(sortInput, b) : 0; // If the nodes are siblings, we can do a quick check
  21931. } else if (aup === bup) {
  21932. return siblingCheck(a, b);
  21933. } // Otherwise we need full lists of their ancestors for comparison
  21934. cur = a;
  21935. while (cur = cur.parentNode) {
  21936. ap.unshift(cur);
  21937. }
  21938. cur = b;
  21939. while (cur = cur.parentNode) {
  21940. bp.unshift(cur);
  21941. } // Walk down the tree looking for a discrepancy
  21942. while (ap[i] === bp[i]) {
  21943. i++;
  21944. }
  21945. return i ? // Do a sibling check if the nodes have a common ancestor
  21946. siblingCheck(ap[i], bp[i]) : // Otherwise nodes in our document sort first
  21947. ap[i] === preferredDoc ? -1 : bp[i] === preferredDoc ? 1 : 0;
  21948. };
  21949. return document;
  21950. };
  21951. Sizzle.matches = function (expr, elements) {
  21952. return Sizzle(expr, null, null, elements);
  21953. };
  21954. Sizzle.matchesSelector = function (elem, expr) {
  21955. // Set document vars if needed
  21956. if ((elem.ownerDocument || elem) !== document) {
  21957. setDocument(elem);
  21958. } // Make sure that attribute selectors are quoted
  21959. expr = expr.replace(rattributeQuotes, "='$1']");
  21960. if (support.matchesSelector && documentIsHTML && !compilerCache[expr + " "] && (!rbuggyMatches || !rbuggyMatches.test(expr)) && (!rbuggyQSA || !rbuggyQSA.test(expr))) {
  21961. try {
  21962. var ret = matches.call(elem, expr); // IE 9's matchesSelector returns false on disconnected nodes
  21963. if (ret || support.disconnectedMatch || // As well, disconnected nodes are said to be in a document
  21964. // fragment in IE 9
  21965. elem.document && elem.document.nodeType !== 11) {
  21966. return ret;
  21967. }
  21968. } catch (e) {}
  21969. }
  21970. return Sizzle(expr, document, null, [elem]).length > 0;
  21971. };
  21972. Sizzle.contains = function (context, elem) {
  21973. // Set document vars if needed
  21974. if ((context.ownerDocument || context) !== document) {
  21975. setDocument(context);
  21976. }
  21977. return contains(context, elem);
  21978. };
  21979. Sizzle.attr = function (elem, name) {
  21980. // Set document vars if needed
  21981. if ((elem.ownerDocument || elem) !== document) {
  21982. setDocument(elem);
  21983. }
  21984. var fn = Expr.attrHandle[name.toLowerCase()],
  21985. // Don't get fooled by Object.prototype properties (jQuery #13807)
  21986. val = fn && hasOwn.call(Expr.attrHandle, name.toLowerCase()) ? fn(elem, name, !documentIsHTML) : undefined;
  21987. return val !== undefined ? val : support.attributes || !documentIsHTML ? elem.getAttribute(name) : (val = elem.getAttributeNode(name)) && val.specified ? val.value : null;
  21988. };
  21989. Sizzle.escape = function (sel) {
  21990. return (sel + "").replace(rcssescape, fcssescape);
  21991. };
  21992. Sizzle.error = function (msg) {
  21993. throw new Error("Syntax error, unrecognized expression: " + msg);
  21994. };
  21995. /**
  21996. * Document sorting and removing duplicates
  21997. * @param {ArrayLike} results
  21998. */
  21999. Sizzle.uniqueSort = function (results) {
  22000. var elem,
  22001. duplicates = [],
  22002. j = 0,
  22003. i = 0; // Unless we *know* we can detect duplicates, assume their presence
  22004. hasDuplicate = !support.detectDuplicates;
  22005. sortInput = !support.sortStable && results.slice(0);
  22006. results.sort(sortOrder);
  22007. if (hasDuplicate) {
  22008. while (elem = results[i++]) {
  22009. if (elem === results[i]) {
  22010. j = duplicates.push(i);
  22011. }
  22012. }
  22013. while (j--) {
  22014. results.splice(duplicates[j], 1);
  22015. }
  22016. } // Clear input after sorting to release objects
  22017. // See https://github.com/jquery/sizzle/pull/225
  22018. sortInput = null;
  22019. return results;
  22020. };
  22021. /**
  22022. * Utility function for retrieving the text value of an array of DOM nodes
  22023. * @param {Array|Element} elem
  22024. */
  22025. getText = Sizzle.getText = function (elem) {
  22026. var node,
  22027. ret = "",
  22028. i = 0,
  22029. nodeType = elem.nodeType;
  22030. if (!nodeType) {
  22031. // If no nodeType, this is expected to be an array
  22032. while (node = elem[i++]) {
  22033. // Do not traverse comment nodes
  22034. ret += getText(node);
  22035. }
  22036. } else if (nodeType === 1 || nodeType === 9 || nodeType === 11) {
  22037. // Use textContent for elements
  22038. // innerText usage removed for consistency of new lines (jQuery #11153)
  22039. if (typeof elem.textContent === "string") {
  22040. return elem.textContent;
  22041. } else {
  22042. // Traverse its children
  22043. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  22044. ret += getText(elem);
  22045. }
  22046. }
  22047. } else if (nodeType === 3 || nodeType === 4) {
  22048. return elem.nodeValue;
  22049. } // Do not include comment or processing instruction nodes
  22050. return ret;
  22051. };
  22052. Expr = Sizzle.selectors = {
  22053. // Can be adjusted by the user
  22054. cacheLength: 50,
  22055. createPseudo: markFunction,
  22056. match: matchExpr,
  22057. attrHandle: {},
  22058. find: {},
  22059. relative: {
  22060. ">": {
  22061. dir: "parentNode",
  22062. first: true
  22063. },
  22064. " ": {
  22065. dir: "parentNode"
  22066. },
  22067. "+": {
  22068. dir: "previousSibling",
  22069. first: true
  22070. },
  22071. "~": {
  22072. dir: "previousSibling"
  22073. }
  22074. },
  22075. preFilter: {
  22076. "ATTR": function (match) {
  22077. match[1] = match[1].replace(runescape, funescape); // Move the given value to match[3] whether quoted or unquoted
  22078. match[3] = (match[3] || match[4] || match[5] || "").replace(runescape, funescape);
  22079. if (match[2] === "~=") {
  22080. match[3] = " " + match[3] + " ";
  22081. }
  22082. return match.slice(0, 4);
  22083. },
  22084. "CHILD": function (match) {
  22085. /* matches from matchExpr["CHILD"]
  22086. 1 type (only|nth|...)
  22087. 2 what (child|of-type)
  22088. 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
  22089. 4 xn-component of xn+y argument ([+-]?\d*n|)
  22090. 5 sign of xn-component
  22091. 6 x of xn-component
  22092. 7 sign of y-component
  22093. 8 y of y-component
  22094. */
  22095. match[1] = match[1].toLowerCase();
  22096. if (match[1].slice(0, 3) === "nth") {
  22097. // nth-* requires argument
  22098. if (!match[3]) {
  22099. Sizzle.error(match[0]);
  22100. } // numeric x and y parameters for Expr.filter.CHILD
  22101. // remember that false/true cast respectively to 0/1
  22102. match[4] = +(match[4] ? match[5] + (match[6] || 1) : 2 * (match[3] === "even" || match[3] === "odd"));
  22103. match[5] = +(match[7] + match[8] || match[3] === "odd"); // other types prohibit arguments
  22104. } else if (match[3]) {
  22105. Sizzle.error(match[0]);
  22106. }
  22107. return match;
  22108. },
  22109. "PSEUDO": function (match) {
  22110. var excess,
  22111. unquoted = !match[6] && match[2];
  22112. if (matchExpr["CHILD"].test(match[0])) {
  22113. return null;
  22114. } // Accept quoted arguments as-is
  22115. if (match[3]) {
  22116. match[2] = match[4] || match[5] || ""; // Strip excess characters from unquoted arguments
  22117. } else if (unquoted && rpseudo.test(unquoted) && ( // Get excess from tokenize (recursively)
  22118. excess = tokenize(unquoted, true)) && ( // advance to the next closing parenthesis
  22119. excess = unquoted.indexOf(")", unquoted.length - excess) - unquoted.length)) {
  22120. // excess is a negative index
  22121. match[0] = match[0].slice(0, excess);
  22122. match[2] = unquoted.slice(0, excess);
  22123. } // Return only captures needed by the pseudo filter method (type and argument)
  22124. return match.slice(0, 3);
  22125. }
  22126. },
  22127. filter: {
  22128. "TAG": function (nodeNameSelector) {
  22129. var nodeName = nodeNameSelector.replace(runescape, funescape).toLowerCase();
  22130. return nodeNameSelector === "*" ? function () {
  22131. return true;
  22132. } : function (elem) {
  22133. return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
  22134. };
  22135. },
  22136. "CLASS": function (className) {
  22137. var pattern = classCache[className + " "];
  22138. return pattern || (pattern = new RegExp("(^|" + whitespace + ")" + className + "(" + whitespace + "|$)")) && classCache(className, function (elem) {
  22139. return pattern.test(typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "");
  22140. });
  22141. },
  22142. "ATTR": function (name, operator, check) {
  22143. return function (elem) {
  22144. var result = Sizzle.attr(elem, name);
  22145. if (result == null) {
  22146. return operator === "!=";
  22147. }
  22148. if (!operator) {
  22149. return true;
  22150. }
  22151. result += "";
  22152. return operator === "=" ? result === check : operator === "!=" ? result !== check : operator === "^=" ? check && result.indexOf(check) === 0 : operator === "*=" ? check && result.indexOf(check) > -1 : operator === "$=" ? check && result.slice(-check.length) === check : operator === "~=" ? (" " + result.replace(rwhitespace, " ") + " ").indexOf(check) > -1 : operator === "|=" ? result === check || result.slice(0, check.length + 1) === check + "-" : false;
  22153. };
  22154. },
  22155. "CHILD": function (type, what, argument, first, last) {
  22156. var simple = type.slice(0, 3) !== "nth",
  22157. forward = type.slice(-4) !== "last",
  22158. ofType = what === "of-type";
  22159. return first === 1 && last === 0 ? // Shortcut for :nth-*(n)
  22160. function (elem) {
  22161. return !!elem.parentNode;
  22162. } : function (elem, context, xml) {
  22163. var cache,
  22164. uniqueCache,
  22165. outerCache,
  22166. node,
  22167. nodeIndex,
  22168. start,
  22169. dir = simple !== forward ? "nextSibling" : "previousSibling",
  22170. parent = elem.parentNode,
  22171. name = ofType && elem.nodeName.toLowerCase(),
  22172. useCache = !xml && !ofType,
  22173. diff = false;
  22174. if (parent) {
  22175. // :(first|last|only)-(child|of-type)
  22176. if (simple) {
  22177. while (dir) {
  22178. node = elem;
  22179. while (node = node[dir]) {
  22180. if (ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1) {
  22181. return false;
  22182. }
  22183. } // Reverse direction for :only-* (if we haven't yet done so)
  22184. start = dir = type === "only" && !start && "nextSibling";
  22185. }
  22186. return true;
  22187. }
  22188. start = [forward ? parent.firstChild : parent.lastChild]; // non-xml :nth-child(...) stores cache data on `parent`
  22189. if (forward && useCache) {
  22190. // Seek `elem` from a previously-cached index
  22191. // ...in a gzip-friendly way
  22192. node = parent;
  22193. outerCache = node[expando] || (node[expando] = {}); // Support: IE <9 only
  22194. // Defend against cloned attroperties (jQuery gh-1709)
  22195. uniqueCache = outerCache[node.uniqueID] || (outerCache[node.uniqueID] = {});
  22196. cache = uniqueCache[type] || [];
  22197. nodeIndex = cache[0] === dirruns && cache[1];
  22198. diff = nodeIndex && cache[2];
  22199. node = nodeIndex && parent.childNodes[nodeIndex];
  22200. while (node = ++nodeIndex && node && node[dir] || ( // Fallback to seeking `elem` from the start
  22201. diff = nodeIndex = 0) || start.pop()) {
  22202. // When found, cache indexes on `parent` and break
  22203. if (node.nodeType === 1 && ++diff && node === elem) {
  22204. uniqueCache[type] = [dirruns, nodeIndex, diff];
  22205. break;
  22206. }
  22207. }
  22208. } else {
  22209. // Use previously-cached element index if available
  22210. if (useCache) {
  22211. // ...in a gzip-friendly way
  22212. node = elem;
  22213. outerCache = node[expando] || (node[expando] = {}); // Support: IE <9 only
  22214. // Defend against cloned attroperties (jQuery gh-1709)
  22215. uniqueCache = outerCache[node.uniqueID] || (outerCache[node.uniqueID] = {});
  22216. cache = uniqueCache[type] || [];
  22217. nodeIndex = cache[0] === dirruns && cache[1];
  22218. diff = nodeIndex;
  22219. } // xml :nth-child(...)
  22220. // or :nth-last-child(...) or :nth(-last)?-of-type(...)
  22221. if (diff === false) {
  22222. // Use the same loop as above to seek `elem` from the start
  22223. while (node = ++nodeIndex && node && node[dir] || (diff = nodeIndex = 0) || start.pop()) {
  22224. if ((ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1) && ++diff) {
  22225. // Cache the index of each encountered element
  22226. if (useCache) {
  22227. outerCache = node[expando] || (node[expando] = {}); // Support: IE <9 only
  22228. // Defend against cloned attroperties (jQuery gh-1709)
  22229. uniqueCache = outerCache[node.uniqueID] || (outerCache[node.uniqueID] = {});
  22230. uniqueCache[type] = [dirruns, diff];
  22231. }
  22232. if (node === elem) {
  22233. break;
  22234. }
  22235. }
  22236. }
  22237. }
  22238. } // Incorporate the offset, then check against cycle size
  22239. diff -= last;
  22240. return diff === first || diff % first === 0 && diff / first >= 0;
  22241. }
  22242. };
  22243. },
  22244. "PSEUDO": function (pseudo, argument) {
  22245. // pseudo-class names are case-insensitive
  22246. // http://www.w3.org/TR/selectors/#pseudo-classes
  22247. // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
  22248. // Remember that setFilters inherits from pseudos
  22249. var args,
  22250. fn = Expr.pseudos[pseudo] || Expr.setFilters[pseudo.toLowerCase()] || Sizzle.error("unsupported pseudo: " + pseudo); // The user may use createPseudo to indicate that
  22251. // arguments are needed to create the filter function
  22252. // just as Sizzle does
  22253. if (fn[expando]) {
  22254. return fn(argument);
  22255. } // But maintain support for old signatures
  22256. if (fn.length > 1) {
  22257. args = [pseudo, pseudo, "", argument];
  22258. return Expr.setFilters.hasOwnProperty(pseudo.toLowerCase()) ? markFunction(function (seed, matches) {
  22259. var idx,
  22260. matched = fn(seed, argument),
  22261. i = matched.length;
  22262. while (i--) {
  22263. idx = indexOf(seed, matched[i]);
  22264. seed[idx] = !(matches[idx] = matched[i]);
  22265. }
  22266. }) : function (elem) {
  22267. return fn(elem, 0, args);
  22268. };
  22269. }
  22270. return fn;
  22271. }
  22272. },
  22273. pseudos: {
  22274. // Potentially complex pseudos
  22275. "not": markFunction(function (selector) {
  22276. // Trim the selector passed to compile
  22277. // to avoid treating leading and trailing
  22278. // spaces as combinators
  22279. var input = [],
  22280. results = [],
  22281. matcher = compile(selector.replace(rtrim, "$1"));
  22282. return matcher[expando] ? markFunction(function (seed, matches, context, xml) {
  22283. var elem,
  22284. unmatched = matcher(seed, null, xml, []),
  22285. i = seed.length; // Match elements unmatched by `matcher`
  22286. while (i--) {
  22287. if (elem = unmatched[i]) {
  22288. seed[i] = !(matches[i] = elem);
  22289. }
  22290. }
  22291. }) : function (elem, context, xml) {
  22292. input[0] = elem;
  22293. matcher(input, null, xml, results); // Don't keep the element (issue #299)
  22294. input[0] = null;
  22295. return !results.pop();
  22296. };
  22297. }),
  22298. "has": markFunction(function (selector) {
  22299. return function (elem) {
  22300. return Sizzle(selector, elem).length > 0;
  22301. };
  22302. }),
  22303. "contains": markFunction(function (text) {
  22304. text = text.replace(runescape, funescape);
  22305. return function (elem) {
  22306. return (elem.textContent || elem.innerText || getText(elem)).indexOf(text) > -1;
  22307. };
  22308. }),
  22309. // "Whether an element is represented by a :lang() selector
  22310. // is based solely on the element's language value
  22311. // being equal to the identifier C,
  22312. // or beginning with the identifier C immediately followed by "-".
  22313. // The matching of C against the element's language value is performed case-insensitively.
  22314. // The identifier C does not have to be a valid language name."
  22315. // http://www.w3.org/TR/selectors/#lang-pseudo
  22316. "lang": markFunction(function (lang) {
  22317. // lang value must be a valid identifier
  22318. if (!ridentifier.test(lang || "")) {
  22319. Sizzle.error("unsupported lang: " + lang);
  22320. }
  22321. lang = lang.replace(runescape, funescape).toLowerCase();
  22322. return function (elem) {
  22323. var elemLang;
  22324. do {
  22325. if (elemLang = documentIsHTML ? elem.lang : elem.getAttribute("xml:lang") || elem.getAttribute("lang")) {
  22326. elemLang = elemLang.toLowerCase();
  22327. return elemLang === lang || elemLang.indexOf(lang + "-") === 0;
  22328. }
  22329. } while ((elem = elem.parentNode) && elem.nodeType === 1);
  22330. return false;
  22331. };
  22332. }),
  22333. // Miscellaneous
  22334. "target": function (elem) {
  22335. var hash = window.location && window.location.hash;
  22336. return hash && hash.slice(1) === elem.id;
  22337. },
  22338. "root": function (elem) {
  22339. return elem === docElem;
  22340. },
  22341. "focus": function (elem) {
  22342. return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
  22343. },
  22344. // Boolean properties
  22345. "enabled": createDisabledPseudo(false),
  22346. "disabled": createDisabledPseudo(true),
  22347. "checked": function (elem) {
  22348. // In CSS3, :checked should return both checked and selected elements
  22349. // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
  22350. var nodeName = elem.nodeName.toLowerCase();
  22351. return nodeName === "input" && !!elem.checked || nodeName === "option" && !!elem.selected;
  22352. },
  22353. "selected": function (elem) {
  22354. // Accessing this property makes selected-by-default
  22355. // options in Safari work properly
  22356. if (elem.parentNode) {
  22357. elem.parentNode.selectedIndex;
  22358. }
  22359. return elem.selected === true;
  22360. },
  22361. // Contents
  22362. "empty": function (elem) {
  22363. // http://www.w3.org/TR/selectors/#empty-pseudo
  22364. // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
  22365. // but not by others (comment: 8; processing instruction: 7; etc.)
  22366. // nodeType < 6 works because attributes (2) do not appear as children
  22367. for (elem = elem.firstChild; elem; elem = elem.nextSibling) {
  22368. if (elem.nodeType < 6) {
  22369. return false;
  22370. }
  22371. }
  22372. return true;
  22373. },
  22374. "parent": function (elem) {
  22375. return !Expr.pseudos["empty"](elem);
  22376. },
  22377. // Element/input types
  22378. "header": function (elem) {
  22379. return rheader.test(elem.nodeName);
  22380. },
  22381. "input": function (elem) {
  22382. return rinputs.test(elem.nodeName);
  22383. },
  22384. "button": function (elem) {
  22385. var name = elem.nodeName.toLowerCase();
  22386. return name === "input" && elem.type === "button" || name === "button";
  22387. },
  22388. "text": function (elem) {
  22389. var attr;
  22390. return elem.nodeName.toLowerCase() === "input" && elem.type === "text" && ( // Support: IE<8
  22391. // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
  22392. (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text");
  22393. },
  22394. // Position-in-collection
  22395. "first": createPositionalPseudo(function () {
  22396. return [0];
  22397. }),
  22398. "last": createPositionalPseudo(function (matchIndexes, length) {
  22399. return [length - 1];
  22400. }),
  22401. "eq": createPositionalPseudo(function (matchIndexes, length, argument) {
  22402. return [argument < 0 ? argument + length : argument];
  22403. }),
  22404. "even": createPositionalPseudo(function (matchIndexes, length) {
  22405. var i = 0;
  22406. for (; i < length; i += 2) {
  22407. matchIndexes.push(i);
  22408. }
  22409. return matchIndexes;
  22410. }),
  22411. "odd": createPositionalPseudo(function (matchIndexes, length) {
  22412. var i = 1;
  22413. for (; i < length; i += 2) {
  22414. matchIndexes.push(i);
  22415. }
  22416. return matchIndexes;
  22417. }),
  22418. "lt": createPositionalPseudo(function (matchIndexes, length, argument) {
  22419. var i = argument < 0 ? argument + length : argument;
  22420. for (; --i >= 0;) {
  22421. matchIndexes.push(i);
  22422. }
  22423. return matchIndexes;
  22424. }),
  22425. "gt": createPositionalPseudo(function (matchIndexes, length, argument) {
  22426. var i = argument < 0 ? argument + length : argument;
  22427. for (; ++i < length;) {
  22428. matchIndexes.push(i);
  22429. }
  22430. return matchIndexes;
  22431. })
  22432. }
  22433. };
  22434. Expr.pseudos["nth"] = Expr.pseudos["eq"]; // Add button/input type pseudos
  22435. for (i in {
  22436. radio: true,
  22437. checkbox: true,
  22438. file: true,
  22439. password: true,
  22440. image: true
  22441. }) {
  22442. Expr.pseudos[i] = createInputPseudo(i);
  22443. }
  22444. for (i in {
  22445. submit: true,
  22446. reset: true
  22447. }) {
  22448. Expr.pseudos[i] = createButtonPseudo(i);
  22449. } // Easy API for creating new setFilters
  22450. function setFilters() {}
  22451. setFilters.prototype = Expr.filters = Expr.pseudos;
  22452. Expr.setFilters = new setFilters();
  22453. tokenize = Sizzle.tokenize = function (selector, parseOnly) {
  22454. var matched,
  22455. match,
  22456. tokens,
  22457. type,
  22458. soFar,
  22459. groups,
  22460. preFilters,
  22461. cached = tokenCache[selector + " "];
  22462. if (cached) {
  22463. return parseOnly ? 0 : cached.slice(0);
  22464. }
  22465. soFar = selector;
  22466. groups = [];
  22467. preFilters = Expr.preFilter;
  22468. while (soFar) {
  22469. // Comma and first run
  22470. if (!matched || (match = rcomma.exec(soFar))) {
  22471. if (match) {
  22472. // Don't consume trailing commas as valid
  22473. soFar = soFar.slice(match[0].length) || soFar;
  22474. }
  22475. groups.push(tokens = []);
  22476. }
  22477. matched = false; // Combinators
  22478. if (match = rcombinators.exec(soFar)) {
  22479. matched = match.shift();
  22480. tokens.push({
  22481. value: matched,
  22482. // Cast descendant combinators to space
  22483. type: match[0].replace(rtrim, " ")
  22484. });
  22485. soFar = soFar.slice(matched.length);
  22486. } // Filters
  22487. for (type in Expr.filter) {
  22488. if ((match = matchExpr[type].exec(soFar)) && (!preFilters[type] || (match = preFilters[type](match)))) {
  22489. matched = match.shift();
  22490. tokens.push({
  22491. value: matched,
  22492. type: type,
  22493. matches: match
  22494. });
  22495. soFar = soFar.slice(matched.length);
  22496. }
  22497. }
  22498. if (!matched) {
  22499. break;
  22500. }
  22501. } // Return the length of the invalid excess
  22502. // if we're just parsing
  22503. // Otherwise, throw an error or return tokens
  22504. return parseOnly ? soFar.length : soFar ? Sizzle.error(selector) : // Cache the tokens
  22505. tokenCache(selector, groups).slice(0);
  22506. };
  22507. function toSelector(tokens) {
  22508. var i = 0,
  22509. len = tokens.length,
  22510. selector = "";
  22511. for (; i < len; i++) {
  22512. selector += tokens[i].value;
  22513. }
  22514. return selector;
  22515. }
  22516. function addCombinator(matcher, combinator, base) {
  22517. var dir = combinator.dir,
  22518. skip = combinator.next,
  22519. key = skip || dir,
  22520. checkNonElements = base && key === "parentNode",
  22521. doneName = done++;
  22522. return combinator.first ? // Check against closest ancestor/preceding element
  22523. function (elem, context, xml) {
  22524. while (elem = elem[dir]) {
  22525. if (elem.nodeType === 1 || checkNonElements) {
  22526. return matcher(elem, context, xml);
  22527. }
  22528. }
  22529. return false;
  22530. } : // Check against all ancestor/preceding elements
  22531. function (elem, context, xml) {
  22532. var oldCache,
  22533. uniqueCache,
  22534. outerCache,
  22535. newCache = [dirruns, doneName]; // We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching
  22536. if (xml) {
  22537. while (elem = elem[dir]) {
  22538. if (elem.nodeType === 1 || checkNonElements) {
  22539. if (matcher(elem, context, xml)) {
  22540. return true;
  22541. }
  22542. }
  22543. }
  22544. } else {
  22545. while (elem = elem[dir]) {
  22546. if (elem.nodeType === 1 || checkNonElements) {
  22547. outerCache = elem[expando] || (elem[expando] = {}); // Support: IE <9 only
  22548. // Defend against cloned attroperties (jQuery gh-1709)
  22549. uniqueCache = outerCache[elem.uniqueID] || (outerCache[elem.uniqueID] = {});
  22550. if (skip && skip === elem.nodeName.toLowerCase()) {
  22551. elem = elem[dir] || elem;
  22552. } else if ((oldCache = uniqueCache[key]) && oldCache[0] === dirruns && oldCache[1] === doneName) {
  22553. // Assign to newCache so results back-propagate to previous elements
  22554. return newCache[2] = oldCache[2];
  22555. } else {
  22556. // Reuse newcache so results back-propagate to previous elements
  22557. uniqueCache[key] = newCache; // A match means we're done; a fail means we have to keep checking
  22558. if (newCache[2] = matcher(elem, context, xml)) {
  22559. return true;
  22560. }
  22561. }
  22562. }
  22563. }
  22564. }
  22565. return false;
  22566. };
  22567. }
  22568. function elementMatcher(matchers) {
  22569. return matchers.length > 1 ? function (elem, context, xml) {
  22570. var i = matchers.length;
  22571. while (i--) {
  22572. if (!matchers[i](elem, context, xml)) {
  22573. return false;
  22574. }
  22575. }
  22576. return true;
  22577. } : matchers[0];
  22578. }
  22579. function multipleContexts(selector, contexts, results) {
  22580. var i = 0,
  22581. len = contexts.length;
  22582. for (; i < len; i++) {
  22583. Sizzle(selector, contexts[i], results);
  22584. }
  22585. return results;
  22586. }
  22587. function condense(unmatched, map, filter, context, xml) {
  22588. var elem,
  22589. newUnmatched = [],
  22590. i = 0,
  22591. len = unmatched.length,
  22592. mapped = map != null;
  22593. for (; i < len; i++) {
  22594. if (elem = unmatched[i]) {
  22595. if (!filter || filter(elem, context, xml)) {
  22596. newUnmatched.push(elem);
  22597. if (mapped) {
  22598. map.push(i);
  22599. }
  22600. }
  22601. }
  22602. }
  22603. return newUnmatched;
  22604. }
  22605. function setMatcher(preFilter, selector, matcher, postFilter, postFinder, postSelector) {
  22606. if (postFilter && !postFilter[expando]) {
  22607. postFilter = setMatcher(postFilter);
  22608. }
  22609. if (postFinder && !postFinder[expando]) {
  22610. postFinder = setMatcher(postFinder, postSelector);
  22611. }
  22612. return markFunction(function (seed, results, context, xml) {
  22613. var temp,
  22614. i,
  22615. elem,
  22616. preMap = [],
  22617. postMap = [],
  22618. preexisting = results.length,
  22619. // Get initial elements from seed or context
  22620. elems = seed || multipleContexts(selector || "*", context.nodeType ? [context] : context, []),
  22621. // Prefilter to get matcher input, preserving a map for seed-results synchronization
  22622. matcherIn = preFilter && (seed || !selector) ? condense(elems, preMap, preFilter, context, xml) : elems,
  22623. matcherOut = matcher ? // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
  22624. postFinder || (seed ? preFilter : preexisting || postFilter) ? // ...intermediate processing is necessary
  22625. [] : // ...otherwise use results directly
  22626. results : matcherIn; // Find primary matches
  22627. if (matcher) {
  22628. matcher(matcherIn, matcherOut, context, xml);
  22629. } // Apply postFilter
  22630. if (postFilter) {
  22631. temp = condense(matcherOut, postMap);
  22632. postFilter(temp, [], context, xml); // Un-match failing elements by moving them back to matcherIn
  22633. i = temp.length;
  22634. while (i--) {
  22635. if (elem = temp[i]) {
  22636. matcherOut[postMap[i]] = !(matcherIn[postMap[i]] = elem);
  22637. }
  22638. }
  22639. }
  22640. if (seed) {
  22641. if (postFinder || preFilter) {
  22642. if (postFinder) {
  22643. // Get the final matcherOut by condensing this intermediate into postFinder contexts
  22644. temp = [];
  22645. i = matcherOut.length;
  22646. while (i--) {
  22647. if (elem = matcherOut[i]) {
  22648. // Restore matcherIn since elem is not yet a final match
  22649. temp.push(matcherIn[i] = elem);
  22650. }
  22651. }
  22652. postFinder(null, matcherOut = [], temp, xml);
  22653. } // Move matched elements from seed to results to keep them synchronized
  22654. i = matcherOut.length;
  22655. while (i--) {
  22656. if ((elem = matcherOut[i]) && (temp = postFinder ? indexOf(seed, elem) : preMap[i]) > -1) {
  22657. seed[temp] = !(results[temp] = elem);
  22658. }
  22659. }
  22660. } // Add elements to results, through postFinder if defined
  22661. } else {
  22662. matcherOut = condense(matcherOut === results ? matcherOut.splice(preexisting, matcherOut.length) : matcherOut);
  22663. if (postFinder) {
  22664. postFinder(null, results, matcherOut, xml);
  22665. } else {
  22666. push.apply(results, matcherOut);
  22667. }
  22668. }
  22669. });
  22670. }
  22671. function matcherFromTokens(tokens) {
  22672. var checkContext,
  22673. matcher,
  22674. j,
  22675. len = tokens.length,
  22676. leadingRelative = Expr.relative[tokens[0].type],
  22677. implicitRelative = leadingRelative || Expr.relative[" "],
  22678. i = leadingRelative ? 1 : 0,
  22679. // The foundational matcher ensures that elements are reachable from top-level context(s)
  22680. matchContext = addCombinator(function (elem) {
  22681. return elem === checkContext;
  22682. }, implicitRelative, true),
  22683. matchAnyContext = addCombinator(function (elem) {
  22684. return indexOf(checkContext, elem) > -1;
  22685. }, implicitRelative, true),
  22686. matchers = [function (elem, context, xml) {
  22687. var ret = !leadingRelative && (xml || context !== outermostContext) || ((checkContext = context).nodeType ? matchContext(elem, context, xml) : matchAnyContext(elem, context, xml)); // Avoid hanging onto element (issue #299)
  22688. checkContext = null;
  22689. return ret;
  22690. }];
  22691. for (; i < len; i++) {
  22692. if (matcher = Expr.relative[tokens[i].type]) {
  22693. matchers = [addCombinator(elementMatcher(matchers), matcher)];
  22694. } else {
  22695. matcher = Expr.filter[tokens[i].type].apply(null, tokens[i].matches); // Return special upon seeing a positional matcher
  22696. if (matcher[expando]) {
  22697. // Find the next relative operator (if any) for proper handling
  22698. j = ++i;
  22699. for (; j < len; j++) {
  22700. if (Expr.relative[tokens[j].type]) {
  22701. break;
  22702. }
  22703. }
  22704. return setMatcher(i > 1 && elementMatcher(matchers), i > 1 && toSelector( // If the preceding token was a descendant combinator, insert an implicit any-element `*`
  22705. tokens.slice(0, i - 1).concat({
  22706. value: tokens[i - 2].type === " " ? "*" : ""
  22707. })).replace(rtrim, "$1"), matcher, i < j && matcherFromTokens(tokens.slice(i, j)), j < len && matcherFromTokens(tokens = tokens.slice(j)), j < len && toSelector(tokens));
  22708. }
  22709. matchers.push(matcher);
  22710. }
  22711. }
  22712. return elementMatcher(matchers);
  22713. }
  22714. function matcherFromGroupMatchers(elementMatchers, setMatchers) {
  22715. var bySet = setMatchers.length > 0,
  22716. byElement = elementMatchers.length > 0,
  22717. superMatcher = function (seed, context, xml, results, outermost) {
  22718. var elem,
  22719. j,
  22720. matcher,
  22721. matchedCount = 0,
  22722. i = "0",
  22723. unmatched = seed && [],
  22724. setMatched = [],
  22725. contextBackup = outermostContext,
  22726. // We must always have either seed elements or outermost context
  22727. elems = seed || byElement && Expr.find["TAG"]("*", outermost),
  22728. // Use integer dirruns iff this is the outermost matcher
  22729. dirrunsUnique = dirruns += contextBackup == null ? 1 : Math.random() || 0.1,
  22730. len = elems.length;
  22731. if (outermost) {
  22732. outermostContext = context === document || context || outermost;
  22733. } // Add elements passing elementMatchers directly to results
  22734. // Support: IE<9, Safari
  22735. // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
  22736. for (; i !== len && (elem = elems[i]) != null; i++) {
  22737. if (byElement && elem) {
  22738. j = 0;
  22739. if (!context && elem.ownerDocument !== document) {
  22740. setDocument(elem);
  22741. xml = !documentIsHTML;
  22742. }
  22743. while (matcher = elementMatchers[j++]) {
  22744. if (matcher(elem, context || document, xml)) {
  22745. results.push(elem);
  22746. break;
  22747. }
  22748. }
  22749. if (outermost) {
  22750. dirruns = dirrunsUnique;
  22751. }
  22752. } // Track unmatched elements for set filters
  22753. if (bySet) {
  22754. // They will have gone through all possible matchers
  22755. if (elem = !matcher && elem) {
  22756. matchedCount--;
  22757. } // Lengthen the array for every element, matched or not
  22758. if (seed) {
  22759. unmatched.push(elem);
  22760. }
  22761. }
  22762. } // `i` is now the count of elements visited above, and adding it to `matchedCount`
  22763. // makes the latter nonnegative.
  22764. matchedCount += i; // Apply set filters to unmatched elements
  22765. // NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount`
  22766. // equals `i`), unless we didn't visit _any_ elements in the above loop because we have
  22767. // no element matchers and no seed.
  22768. // Incrementing an initially-string "0" `i` allows `i` to remain a string only in that
  22769. // case, which will result in a "00" `matchedCount` that differs from `i` but is also
  22770. // numerically zero.
  22771. if (bySet && i !== matchedCount) {
  22772. j = 0;
  22773. while (matcher = setMatchers[j++]) {
  22774. matcher(unmatched, setMatched, context, xml);
  22775. }
  22776. if (seed) {
  22777. // Reintegrate element matches to eliminate the need for sorting
  22778. if (matchedCount > 0) {
  22779. while (i--) {
  22780. if (!(unmatched[i] || setMatched[i])) {
  22781. setMatched[i] = pop.call(results);
  22782. }
  22783. }
  22784. } // Discard index placeholder values to get only actual matches
  22785. setMatched = condense(setMatched);
  22786. } // Add matches to results
  22787. push.apply(results, setMatched); // Seedless set matches succeeding multiple successful matchers stipulate sorting
  22788. if (outermost && !seed && setMatched.length > 0 && matchedCount + setMatchers.length > 1) {
  22789. Sizzle.uniqueSort(results);
  22790. }
  22791. } // Override manipulation of globals by nested matchers
  22792. if (outermost) {
  22793. dirruns = dirrunsUnique;
  22794. outermostContext = contextBackup;
  22795. }
  22796. return unmatched;
  22797. };
  22798. return bySet ? markFunction(superMatcher) : superMatcher;
  22799. }
  22800. compile = Sizzle.compile = function (selector, match
  22801. /* Internal Use Only */
  22802. ) {
  22803. var i,
  22804. setMatchers = [],
  22805. elementMatchers = [],
  22806. cached = compilerCache[selector + " "];
  22807. if (!cached) {
  22808. // Generate a function of recursive functions that can be used to check each element
  22809. if (!match) {
  22810. match = tokenize(selector);
  22811. }
  22812. i = match.length;
  22813. while (i--) {
  22814. cached = matcherFromTokens(match[i]);
  22815. if (cached[expando]) {
  22816. setMatchers.push(cached);
  22817. } else {
  22818. elementMatchers.push(cached);
  22819. }
  22820. } // Cache the compiled function
  22821. cached = compilerCache(selector, matcherFromGroupMatchers(elementMatchers, setMatchers)); // Save selector and tokenization
  22822. cached.selector = selector;
  22823. }
  22824. return cached;
  22825. };
  22826. /**
  22827. * A low-level selection function that works with Sizzle's compiled
  22828. * selector functions
  22829. * @param {String|Function} selector A selector or a pre-compiled
  22830. * selector function built with Sizzle.compile
  22831. * @param {Element} context
  22832. * @param {Array} [results]
  22833. * @param {Array} [seed] A set of elements to match against
  22834. */
  22835. select = Sizzle.select = function (selector, context, results, seed) {
  22836. var i,
  22837. tokens,
  22838. token,
  22839. type,
  22840. find,
  22841. compiled = typeof selector === "function" && selector,
  22842. match = !seed && tokenize(selector = compiled.selector || selector);
  22843. results = results || []; // Try to minimize operations if there is only one selector in the list and no seed
  22844. // (the latter of which guarantees us context)
  22845. if (match.length === 1) {
  22846. // Reduce context if the leading compound selector is an ID
  22847. tokens = match[0] = match[0].slice(0);
  22848. if (tokens.length > 2 && (token = tokens[0]).type === "ID" && context.nodeType === 9 && documentIsHTML && Expr.relative[tokens[1].type]) {
  22849. context = (Expr.find["ID"](token.matches[0].replace(runescape, funescape), context) || [])[0];
  22850. if (!context) {
  22851. return results; // Precompiled matchers will still verify ancestry, so step up a level
  22852. } else if (compiled) {
  22853. context = context.parentNode;
  22854. }
  22855. selector = selector.slice(tokens.shift().value.length);
  22856. } // Fetch a seed set for right-to-left matching
  22857. i = matchExpr["needsContext"].test(selector) ? 0 : tokens.length;
  22858. while (i--) {
  22859. token = tokens[i]; // Abort if we hit a combinator
  22860. if (Expr.relative[type = token.type]) {
  22861. break;
  22862. }
  22863. if (find = Expr.find[type]) {
  22864. // Search, expanding context for leading sibling combinators
  22865. if (seed = find(token.matches[0].replace(runescape, funescape), rsibling.test(tokens[0].type) && testContext(context.parentNode) || context)) {
  22866. // If seed is empty or no tokens remain, we can return early
  22867. tokens.splice(i, 1);
  22868. selector = seed.length && toSelector(tokens);
  22869. if (!selector) {
  22870. push.apply(results, seed);
  22871. return results;
  22872. }
  22873. break;
  22874. }
  22875. }
  22876. }
  22877. } // Compile and execute a filtering function if one is not provided
  22878. // Provide `match` to avoid retokenization if we modified the selector above
  22879. (compiled || compile(selector, match))(seed, context, !documentIsHTML, results, !context || rsibling.test(selector) && testContext(context.parentNode) || context);
  22880. return results;
  22881. }; // One-time assignments
  22882. // Sort stability
  22883. support.sortStable = expando.split("").sort(sortOrder).join("") === expando; // Support: Chrome 14-35+
  22884. // Always assume duplicates if they aren't passed to the comparison function
  22885. support.detectDuplicates = !!hasDuplicate; // Initialize against the default document
  22886. setDocument(); // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
  22887. // Detached nodes confoundingly follow *each other*
  22888. support.sortDetached = assert(function (el) {
  22889. // Should return 1, but returns 4 (following)
  22890. return el.compareDocumentPosition(document.createElement("fieldset")) & 1;
  22891. }); // Support: IE<8
  22892. // Prevent attribute/property "interpolation"
  22893. // https://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
  22894. if (!assert(function (el) {
  22895. el.innerHTML = "<a href='#'></a>";
  22896. return el.firstChild.getAttribute("href") === "#";
  22897. })) {
  22898. addHandle("type|href|height|width", function (elem, name, isXML) {
  22899. if (!isXML) {
  22900. return elem.getAttribute(name, name.toLowerCase() === "type" ? 1 : 2);
  22901. }
  22902. });
  22903. } // Support: IE<9
  22904. // Use defaultValue in place of getAttribute("value")
  22905. if (!support.attributes || !assert(function (el) {
  22906. el.innerHTML = "<input/>";
  22907. el.firstChild.setAttribute("value", "");
  22908. return el.firstChild.getAttribute("value") === "";
  22909. })) {
  22910. addHandle("value", function (elem, name, isXML) {
  22911. if (!isXML && elem.nodeName.toLowerCase() === "input") {
  22912. return elem.defaultValue;
  22913. }
  22914. });
  22915. } // Support: IE<9
  22916. // Use getAttributeNode to fetch booleans when getAttribute lies
  22917. if (!assert(function (el) {
  22918. return el.getAttribute("disabled") == null;
  22919. })) {
  22920. addHandle(booleans, function (elem, name, isXML) {
  22921. var val;
  22922. if (!isXML) {
  22923. return elem[name] === true ? name.toLowerCase() : (val = elem.getAttributeNode(name)) && val.specified ? val.value : null;
  22924. }
  22925. });
  22926. }
  22927. return Sizzle;
  22928. }(window);
  22929. jQuery.find = Sizzle;
  22930. jQuery.expr = Sizzle.selectors; // Deprecated
  22931. jQuery.expr[":"] = jQuery.expr.pseudos;
  22932. jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort;
  22933. jQuery.text = Sizzle.getText;
  22934. jQuery.isXMLDoc = Sizzle.isXML;
  22935. jQuery.contains = Sizzle.contains;
  22936. jQuery.escapeSelector = Sizzle.escape;
  22937. var dir = function (elem, dir, until) {
  22938. var matched = [],
  22939. truncate = until !== undefined;
  22940. while ((elem = elem[dir]) && elem.nodeType !== 9) {
  22941. if (elem.nodeType === 1) {
  22942. if (truncate && jQuery(elem).is(until)) {
  22943. break;
  22944. }
  22945. matched.push(elem);
  22946. }
  22947. }
  22948. return matched;
  22949. };
  22950. var siblings = function (n, elem) {
  22951. var matched = [];
  22952. for (; n; n = n.nextSibling) {
  22953. if (n.nodeType === 1 && n !== elem) {
  22954. matched.push(n);
  22955. }
  22956. }
  22957. return matched;
  22958. };
  22959. var rneedsContext = jQuery.expr.match.needsContext;
  22960. function nodeName(elem, name) {
  22961. return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
  22962. }
  22963. ;
  22964. var rsingleTag = /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i; // Implement the identical functionality for filter and not
  22965. function winnow(elements, qualifier, not) {
  22966. if (isFunction(qualifier)) {
  22967. return jQuery.grep(elements, function (elem, i) {
  22968. return !!qualifier.call(elem, i, elem) !== not;
  22969. });
  22970. } // Single element
  22971. if (qualifier.nodeType) {
  22972. return jQuery.grep(elements, function (elem) {
  22973. return elem === qualifier !== not;
  22974. });
  22975. } // Arraylike of elements (jQuery, arguments, Array)
  22976. if (typeof qualifier !== "string") {
  22977. return jQuery.grep(elements, function (elem) {
  22978. return indexOf.call(qualifier, elem) > -1 !== not;
  22979. });
  22980. } // Filtered directly for both simple and complex selectors
  22981. return jQuery.filter(qualifier, elements, not);
  22982. }
  22983. jQuery.filter = function (expr, elems, not) {
  22984. var elem = elems[0];
  22985. if (not) {
  22986. expr = ":not(" + expr + ")";
  22987. }
  22988. if (elems.length === 1 && elem.nodeType === 1) {
  22989. return jQuery.find.matchesSelector(elem, expr) ? [elem] : [];
  22990. }
  22991. return jQuery.find.matches(expr, jQuery.grep(elems, function (elem) {
  22992. return elem.nodeType === 1;
  22993. }));
  22994. };
  22995. jQuery.fn.extend({
  22996. find: function (selector) {
  22997. var i,
  22998. ret,
  22999. len = this.length,
  23000. self = this;
  23001. if (typeof selector !== "string") {
  23002. return this.pushStack(jQuery(selector).filter(function () {
  23003. for (i = 0; i < len; i++) {
  23004. if (jQuery.contains(self[i], this)) {
  23005. return true;
  23006. }
  23007. }
  23008. }));
  23009. }
  23010. ret = this.pushStack([]);
  23011. for (i = 0; i < len; i++) {
  23012. jQuery.find(selector, self[i], ret);
  23013. }
  23014. return len > 1 ? jQuery.uniqueSort(ret) : ret;
  23015. },
  23016. filter: function (selector) {
  23017. return this.pushStack(winnow(this, selector || [], false));
  23018. },
  23019. not: function (selector) {
  23020. return this.pushStack(winnow(this, selector || [], true));
  23021. },
  23022. is: function (selector) {
  23023. return !!winnow(this, // If this is a positional/relative selector, check membership in the returned set
  23024. // so $("p:first").is("p:last") won't return true for a doc with two "p".
  23025. typeof selector === "string" && rneedsContext.test(selector) ? jQuery(selector) : selector || [], false).length;
  23026. }
  23027. }); // Initialize a jQuery object
  23028. // A central reference to the root jQuery(document)
  23029. var rootjQuery,
  23030. // A simple way to check for HTML strings
  23031. // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
  23032. // Strict HTML recognition (#11290: must start with <)
  23033. // Shortcut simple #id case for speed
  23034. rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
  23035. init = jQuery.fn.init = function (selector, context, root) {
  23036. var match, elem; // HANDLE: $(""), $(null), $(undefined), $(false)
  23037. if (!selector) {
  23038. return this;
  23039. } // Method init() accepts an alternate rootjQuery
  23040. // so migrate can support jQuery.sub (gh-2101)
  23041. root = root || rootjQuery; // Handle HTML strings
  23042. if (typeof selector === "string") {
  23043. if (selector[0] === "<" && selector[selector.length - 1] === ">" && selector.length >= 3) {
  23044. // Assume that strings that start and end with <> are HTML and skip the regex check
  23045. match = [null, selector, null];
  23046. } else {
  23047. match = rquickExpr.exec(selector);
  23048. } // Match html or make sure no context is specified for #id
  23049. if (match && (match[1] || !context)) {
  23050. // HANDLE: $(html) -> $(array)
  23051. if (match[1]) {
  23052. context = context instanceof jQuery ? context[0] : context; // Option to run scripts is true for back-compat
  23053. // Intentionally let the error be thrown if parseHTML is not present
  23054. jQuery.merge(this, jQuery.parseHTML(match[1], context && context.nodeType ? context.ownerDocument || context : document, true)); // HANDLE: $(html, props)
  23055. if (rsingleTag.test(match[1]) && jQuery.isPlainObject(context)) {
  23056. for (match in context) {
  23057. // Properties of context are called as methods if possible
  23058. if (isFunction(this[match])) {
  23059. this[match](context[match]); // ...and otherwise set as attributes
  23060. } else {
  23061. this.attr(match, context[match]);
  23062. }
  23063. }
  23064. }
  23065. return this; // HANDLE: $(#id)
  23066. } else {
  23067. elem = document.getElementById(match[2]);
  23068. if (elem) {
  23069. // Inject the element directly into the jQuery object
  23070. this[0] = elem;
  23071. this.length = 1;
  23072. }
  23073. return this;
  23074. } // HANDLE: $(expr, $(...))
  23075. } else if (!context || context.jquery) {
  23076. return (context || root).find(selector); // HANDLE: $(expr, context)
  23077. // (which is just equivalent to: $(context).find(expr)
  23078. } else {
  23079. return this.constructor(context).find(selector);
  23080. } // HANDLE: $(DOMElement)
  23081. } else if (selector.nodeType) {
  23082. this[0] = selector;
  23083. this.length = 1;
  23084. return this; // HANDLE: $(function)
  23085. // Shortcut for document ready
  23086. } else if (isFunction(selector)) {
  23087. return root.ready !== undefined ? root.ready(selector) : // Execute immediately if ready is not present
  23088. selector(jQuery);
  23089. }
  23090. return jQuery.makeArray(selector, this);
  23091. }; // Give the init function the jQuery prototype for later instantiation
  23092. init.prototype = jQuery.fn; // Initialize central reference
  23093. rootjQuery = jQuery(document);
  23094. var rparentsprev = /^(?:parents|prev(?:Until|All))/,
  23095. // Methods guaranteed to produce a unique set when starting from a unique set
  23096. guaranteedUnique = {
  23097. children: true,
  23098. contents: true,
  23099. next: true,
  23100. prev: true
  23101. };
  23102. jQuery.fn.extend({
  23103. has: function (target) {
  23104. var targets = jQuery(target, this),
  23105. l = targets.length;
  23106. return this.filter(function () {
  23107. var i = 0;
  23108. for (; i < l; i++) {
  23109. if (jQuery.contains(this, targets[i])) {
  23110. return true;
  23111. }
  23112. }
  23113. });
  23114. },
  23115. closest: function (selectors, context) {
  23116. var cur,
  23117. i = 0,
  23118. l = this.length,
  23119. matched = [],
  23120. targets = typeof selectors !== "string" && jQuery(selectors); // Positional selectors never match, since there's no _selection_ context
  23121. if (!rneedsContext.test(selectors)) {
  23122. for (; i < l; i++) {
  23123. for (cur = this[i]; cur && cur !== context; cur = cur.parentNode) {
  23124. // Always skip document fragments
  23125. if (cur.nodeType < 11 && (targets ? targets.index(cur) > -1 : // Don't pass non-elements to Sizzle
  23126. cur.nodeType === 1 && jQuery.find.matchesSelector(cur, selectors))) {
  23127. matched.push(cur);
  23128. break;
  23129. }
  23130. }
  23131. }
  23132. }
  23133. return this.pushStack(matched.length > 1 ? jQuery.uniqueSort(matched) : matched);
  23134. },
  23135. // Determine the position of an element within the set
  23136. index: function (elem) {
  23137. // No argument, return index in parent
  23138. if (!elem) {
  23139. return this[0] && this[0].parentNode ? this.first().prevAll().length : -1;
  23140. } // Index in selector
  23141. if (typeof elem === "string") {
  23142. return indexOf.call(jQuery(elem), this[0]);
  23143. } // Locate the position of the desired element
  23144. return indexOf.call(this, // If it receives a jQuery object, the first element is used
  23145. elem.jquery ? elem[0] : elem);
  23146. },
  23147. add: function (selector, context) {
  23148. return this.pushStack(jQuery.uniqueSort(jQuery.merge(this.get(), jQuery(selector, context))));
  23149. },
  23150. addBack: function (selector) {
  23151. return this.add(selector == null ? this.prevObject : this.prevObject.filter(selector));
  23152. }
  23153. });
  23154. function sibling(cur, dir) {
  23155. while ((cur = cur[dir]) && cur.nodeType !== 1) {}
  23156. return cur;
  23157. }
  23158. jQuery.each({
  23159. parent: function (elem) {
  23160. var parent = elem.parentNode;
  23161. return parent && parent.nodeType !== 11 ? parent : null;
  23162. },
  23163. parents: function (elem) {
  23164. return dir(elem, "parentNode");
  23165. },
  23166. parentsUntil: function (elem, i, until) {
  23167. return dir(elem, "parentNode", until);
  23168. },
  23169. next: function (elem) {
  23170. return sibling(elem, "nextSibling");
  23171. },
  23172. prev: function (elem) {
  23173. return sibling(elem, "previousSibling");
  23174. },
  23175. nextAll: function (elem) {
  23176. return dir(elem, "nextSibling");
  23177. },
  23178. prevAll: function (elem) {
  23179. return dir(elem, "previousSibling");
  23180. },
  23181. nextUntil: function (elem, i, until) {
  23182. return dir(elem, "nextSibling", until);
  23183. },
  23184. prevUntil: function (elem, i, until) {
  23185. return dir(elem, "previousSibling", until);
  23186. },
  23187. siblings: function (elem) {
  23188. return siblings((elem.parentNode || {}).firstChild, elem);
  23189. },
  23190. children: function (elem) {
  23191. return siblings(elem.firstChild);
  23192. },
  23193. contents: function (elem) {
  23194. if (nodeName(elem, "iframe")) {
  23195. return elem.contentDocument;
  23196. } // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only
  23197. // Treat the template element as a regular one in browsers that
  23198. // don't support it.
  23199. if (nodeName(elem, "template")) {
  23200. elem = elem.content || elem;
  23201. }
  23202. return jQuery.merge([], elem.childNodes);
  23203. }
  23204. }, function (name, fn) {
  23205. jQuery.fn[name] = function (until, selector) {
  23206. var matched = jQuery.map(this, fn, until);
  23207. if (name.slice(-5) !== "Until") {
  23208. selector = until;
  23209. }
  23210. if (selector && typeof selector === "string") {
  23211. matched = jQuery.filter(selector, matched);
  23212. }
  23213. if (this.length > 1) {
  23214. // Remove duplicates
  23215. if (!guaranteedUnique[name]) {
  23216. jQuery.uniqueSort(matched);
  23217. } // Reverse order for parents* and prev-derivatives
  23218. if (rparentsprev.test(name)) {
  23219. matched.reverse();
  23220. }
  23221. }
  23222. return this.pushStack(matched);
  23223. };
  23224. });
  23225. var rnothtmlwhite = /[^\x20\t\r\n\f]+/g; // Convert String-formatted options into Object-formatted ones
  23226. function createOptions(options) {
  23227. var object = {};
  23228. jQuery.each(options.match(rnothtmlwhite) || [], function (_, flag) {
  23229. object[flag] = true;
  23230. });
  23231. return object;
  23232. }
  23233. /*
  23234. * Create a callback list using the following parameters:
  23235. *
  23236. * options: an optional list of space-separated options that will change how
  23237. * the callback list behaves or a more traditional option object
  23238. *
  23239. * By default a callback list will act like an event callback list and can be
  23240. * "fired" multiple times.
  23241. *
  23242. * Possible options:
  23243. *
  23244. * once: will ensure the callback list can only be fired once (like a Deferred)
  23245. *
  23246. * memory: will keep track of previous values and will call any callback added
  23247. * after the list has been fired right away with the latest "memorized"
  23248. * values (like a Deferred)
  23249. *
  23250. * unique: will ensure a callback can only be added once (no duplicate in the list)
  23251. *
  23252. * stopOnFalse: interrupt callings when a callback returns false
  23253. *
  23254. */
  23255. jQuery.Callbacks = function (options) {
  23256. // Convert options from String-formatted to Object-formatted if needed
  23257. // (we check in cache first)
  23258. options = typeof options === "string" ? createOptions(options) : jQuery.extend({}, options);
  23259. var // Flag to know if list is currently firing
  23260. firing,
  23261. // Last fire value for non-forgettable lists
  23262. memory,
  23263. // Flag to know if list was already fired
  23264. fired,
  23265. // Flag to prevent firing
  23266. locked,
  23267. // Actual callback list
  23268. list = [],
  23269. // Queue of execution data for repeatable lists
  23270. queue = [],
  23271. // Index of currently firing callback (modified by add/remove as needed)
  23272. firingIndex = -1,
  23273. // Fire callbacks
  23274. fire = function () {
  23275. // Enforce single-firing
  23276. locked = locked || options.once; // Execute callbacks for all pending executions,
  23277. // respecting firingIndex overrides and runtime changes
  23278. fired = firing = true;
  23279. for (; queue.length; firingIndex = -1) {
  23280. memory = queue.shift();
  23281. while (++firingIndex < list.length) {
  23282. // Run callback and check for early termination
  23283. if (list[firingIndex].apply(memory[0], memory[1]) === false && options.stopOnFalse) {
  23284. // Jump to end and forget the data so .add doesn't re-fire
  23285. firingIndex = list.length;
  23286. memory = false;
  23287. }
  23288. }
  23289. } // Forget the data if we're done with it
  23290. if (!options.memory) {
  23291. memory = false;
  23292. }
  23293. firing = false; // Clean up if we're done firing for good
  23294. if (locked) {
  23295. // Keep an empty list if we have data for future add calls
  23296. if (memory) {
  23297. list = []; // Otherwise, this object is spent
  23298. } else {
  23299. list = "";
  23300. }
  23301. }
  23302. },
  23303. // Actual Callbacks object
  23304. self = {
  23305. // Add a callback or a collection of callbacks to the list
  23306. add: function () {
  23307. if (list) {
  23308. // If we have memory from a past run, we should fire after adding
  23309. if (memory && !firing) {
  23310. firingIndex = list.length - 1;
  23311. queue.push(memory);
  23312. }
  23313. (function add(args) {
  23314. jQuery.each(args, function (_, arg) {
  23315. if (isFunction(arg)) {
  23316. if (!options.unique || !self.has(arg)) {
  23317. list.push(arg);
  23318. }
  23319. } else if (arg && arg.length && toType(arg) !== "string") {
  23320. // Inspect recursively
  23321. add(arg);
  23322. }
  23323. });
  23324. })(arguments);
  23325. if (memory && !firing) {
  23326. fire();
  23327. }
  23328. }
  23329. return this;
  23330. },
  23331. // Remove a callback from the list
  23332. remove: function () {
  23333. jQuery.each(arguments, function (_, arg) {
  23334. var index;
  23335. while ((index = jQuery.inArray(arg, list, index)) > -1) {
  23336. list.splice(index, 1); // Handle firing indexes
  23337. if (index <= firingIndex) {
  23338. firingIndex--;
  23339. }
  23340. }
  23341. });
  23342. return this;
  23343. },
  23344. // Check if a given callback is in the list.
  23345. // If no argument is given, return whether or not list has callbacks attached.
  23346. has: function (fn) {
  23347. return fn ? jQuery.inArray(fn, list) > -1 : list.length > 0;
  23348. },
  23349. // Remove all callbacks from the list
  23350. empty: function () {
  23351. if (list) {
  23352. list = [];
  23353. }
  23354. return this;
  23355. },
  23356. // Disable .fire and .add
  23357. // Abort any current/pending executions
  23358. // Clear all callbacks and values
  23359. disable: function () {
  23360. locked = queue = [];
  23361. list = memory = "";
  23362. return this;
  23363. },
  23364. disabled: function () {
  23365. return !list;
  23366. },
  23367. // Disable .fire
  23368. // Also disable .add unless we have memory (since it would have no effect)
  23369. // Abort any pending executions
  23370. lock: function () {
  23371. locked = queue = [];
  23372. if (!memory && !firing) {
  23373. list = memory = "";
  23374. }
  23375. return this;
  23376. },
  23377. locked: function () {
  23378. return !!locked;
  23379. },
  23380. // Call all callbacks with the given context and arguments
  23381. fireWith: function (context, args) {
  23382. if (!locked) {
  23383. args = args || [];
  23384. args = [context, args.slice ? args.slice() : args];
  23385. queue.push(args);
  23386. if (!firing) {
  23387. fire();
  23388. }
  23389. }
  23390. return this;
  23391. },
  23392. // Call all the callbacks with the given arguments
  23393. fire: function () {
  23394. self.fireWith(this, arguments);
  23395. return this;
  23396. },
  23397. // To know if the callbacks have already been called at least once
  23398. fired: function () {
  23399. return !!fired;
  23400. }
  23401. };
  23402. return self;
  23403. };
  23404. function Identity(v) {
  23405. return v;
  23406. }
  23407. function Thrower(ex) {
  23408. throw ex;
  23409. }
  23410. function adoptValue(value, resolve, reject, noValue) {
  23411. var method;
  23412. try {
  23413. // Check for promise aspect first to privilege synchronous behavior
  23414. if (value && isFunction(method = value.promise)) {
  23415. method.call(value).done(resolve).fail(reject); // Other thenables
  23416. } else if (value && isFunction(method = value.then)) {
  23417. method.call(value, resolve, reject); // Other non-thenables
  23418. } else {
  23419. // Control `resolve` arguments by letting Array#slice cast boolean `noValue` to integer:
  23420. // * false: [ value ].slice( 0 ) => resolve( value )
  23421. // * true: [ value ].slice( 1 ) => resolve()
  23422. resolve.apply(undefined, [value].slice(noValue));
  23423. } // For Promises/A+, convert exceptions into rejections
  23424. // Since jQuery.when doesn't unwrap thenables, we can skip the extra checks appearing in
  23425. // Deferred#then to conditionally suppress rejection.
  23426. } catch (value) {
  23427. // Support: Android 4.0 only
  23428. // Strict mode functions invoked without .call/.apply get global-object context
  23429. reject.apply(undefined, [value]);
  23430. }
  23431. }
  23432. jQuery.extend({
  23433. Deferred: function (func) {
  23434. var tuples = [// action, add listener, callbacks,
  23435. // ... .then handlers, argument index, [final state]
  23436. ["notify", "progress", jQuery.Callbacks("memory"), jQuery.Callbacks("memory"), 2], ["resolve", "done", jQuery.Callbacks("once memory"), jQuery.Callbacks("once memory"), 0, "resolved"], ["reject", "fail", jQuery.Callbacks("once memory"), jQuery.Callbacks("once memory"), 1, "rejected"]],
  23437. state = "pending",
  23438. promise = {
  23439. state: function () {
  23440. return state;
  23441. },
  23442. always: function () {
  23443. deferred.done(arguments).fail(arguments);
  23444. return this;
  23445. },
  23446. "catch": function (fn) {
  23447. return promise.then(null, fn);
  23448. },
  23449. // Keep pipe for back-compat
  23450. pipe: function ()
  23451. /* fnDone, fnFail, fnProgress */
  23452. {
  23453. var fns = arguments;
  23454. return jQuery.Deferred(function (newDefer) {
  23455. jQuery.each(tuples, function (i, tuple) {
  23456. // Map tuples (progress, done, fail) to arguments (done, fail, progress)
  23457. var fn = isFunction(fns[tuple[4]]) && fns[tuple[4]]; // deferred.progress(function() { bind to newDefer or newDefer.notify })
  23458. // deferred.done(function() { bind to newDefer or newDefer.resolve })
  23459. // deferred.fail(function() { bind to newDefer or newDefer.reject })
  23460. deferred[tuple[1]](function () {
  23461. var returned = fn && fn.apply(this, arguments);
  23462. if (returned && isFunction(returned.promise)) {
  23463. returned.promise().progress(newDefer.notify).done(newDefer.resolve).fail(newDefer.reject);
  23464. } else {
  23465. newDefer[tuple[0] + "With"](this, fn ? [returned] : arguments);
  23466. }
  23467. });
  23468. });
  23469. fns = null;
  23470. }).promise();
  23471. },
  23472. then: function (onFulfilled, onRejected, onProgress) {
  23473. var maxDepth = 0;
  23474. function resolve(depth, deferred, handler, special) {
  23475. return function () {
  23476. var that = this,
  23477. args = arguments,
  23478. mightThrow = function () {
  23479. var returned, then; // Support: Promises/A+ section 2.3.3.3.3
  23480. // https://promisesaplus.com/#point-59
  23481. // Ignore double-resolution attempts
  23482. if (depth < maxDepth) {
  23483. return;
  23484. }
  23485. returned = handler.apply(that, args); // Support: Promises/A+ section 2.3.1
  23486. // https://promisesaplus.com/#point-48
  23487. if (returned === deferred.promise()) {
  23488. throw new TypeError("Thenable self-resolution");
  23489. } // Support: Promises/A+ sections 2.3.3.1, 3.5
  23490. // https://promisesaplus.com/#point-54
  23491. // https://promisesaplus.com/#point-75
  23492. // Retrieve `then` only once
  23493. then = returned && ( // Support: Promises/A+ section 2.3.4
  23494. // https://promisesaplus.com/#point-64
  23495. // Only check objects and functions for thenability
  23496. typeof returned === "object" || typeof returned === "function") && returned.then; // Handle a returned thenable
  23497. if (isFunction(then)) {
  23498. // Special processors (notify) just wait for resolution
  23499. if (special) {
  23500. then.call(returned, resolve(maxDepth, deferred, Identity, special), resolve(maxDepth, deferred, Thrower, special)); // Normal processors (resolve) also hook into progress
  23501. } else {
  23502. // ...and disregard older resolution values
  23503. maxDepth++;
  23504. then.call(returned, resolve(maxDepth, deferred, Identity, special), resolve(maxDepth, deferred, Thrower, special), resolve(maxDepth, deferred, Identity, deferred.notifyWith));
  23505. } // Handle all other returned values
  23506. } else {
  23507. // Only substitute handlers pass on context
  23508. // and multiple values (non-spec behavior)
  23509. if (handler !== Identity) {
  23510. that = undefined;
  23511. args = [returned];
  23512. } // Process the value(s)
  23513. // Default process is resolve
  23514. (special || deferred.resolveWith)(that, args);
  23515. }
  23516. },
  23517. // Only normal processors (resolve) catch and reject exceptions
  23518. process = special ? mightThrow : function () {
  23519. try {
  23520. mightThrow();
  23521. } catch (e) {
  23522. if (jQuery.Deferred.exceptionHook) {
  23523. jQuery.Deferred.exceptionHook(e, process.stackTrace);
  23524. } // Support: Promises/A+ section 2.3.3.3.4.1
  23525. // https://promisesaplus.com/#point-61
  23526. // Ignore post-resolution exceptions
  23527. if (depth + 1 >= maxDepth) {
  23528. // Only substitute handlers pass on context
  23529. // and multiple values (non-spec behavior)
  23530. if (handler !== Thrower) {
  23531. that = undefined;
  23532. args = [e];
  23533. }
  23534. deferred.rejectWith(that, args);
  23535. }
  23536. }
  23537. }; // Support: Promises/A+ section 2.3.3.3.1
  23538. // https://promisesaplus.com/#point-57
  23539. // Re-resolve proterminatemises immediately to dodge false rejection from
  23540. // subsequent errors
  23541. if (depth) {
  23542. process();
  23543. } else {
  23544. // Call an optional hook to record the stack, in case of exception
  23545. // since it's otherwise lost when execution goes async
  23546. if (jQuery.Deferred.getStackHook) {
  23547. process.stackTrace = jQuery.Deferred.getStackHook();
  23548. }
  23549. window.setTimeout(process);
  23550. }
  23551. };
  23552. }
  23553. return jQuery.Deferred(function (newDefer) {
  23554. // progress_handlers.add( ... )
  23555. tuples[0][3].add(resolve(0, newDefer, isFunction(onProgress) ? onProgress : Identity, newDefer.notifyWith)); // fulfilled_handlers.add( ... )
  23556. tuples[1][3].add(resolve(0, newDefer, isFunction(onFulfilled) ? onFulfilled : Identity)); // rejected_handlers.add( ... )
  23557. tuples[2][3].add(resolve(0, newDefer, isFunction(onRejected) ? onRejected : Thrower));
  23558. }).promise();
  23559. },
  23560. // Get a promise for this deferred
  23561. // If obj is provided, the promise aspect is added to the object
  23562. promise: function (obj) {
  23563. return obj != null ? jQuery.extend(obj, promise) : promise;
  23564. }
  23565. },
  23566. deferred = {}; // Add list-specific methods
  23567. jQuery.each(tuples, function (i, tuple) {
  23568. var list = tuple[2],
  23569. stateString = tuple[5]; // promise.progress = list.add
  23570. // promise.done = list.add
  23571. // promise.fail = list.add
  23572. promise[tuple[1]] = list.add; // Handle state
  23573. if (stateString) {
  23574. list.add(function () {
  23575. // state = "resolved" (i.e., fulfilled)
  23576. // state = "rejected"
  23577. state = stateString;
  23578. }, // rejected_callbacks.disable
  23579. // fulfilled_callbacks.disable
  23580. tuples[3 - i][2].disable, // rejected_handlers.disable
  23581. // fulfilled_handlers.disable
  23582. tuples[3 - i][3].disable, // progress_callbacks.lock
  23583. tuples[0][2].lock, // progress_handlers.lock
  23584. tuples[0][3].lock);
  23585. } // progress_handlers.fire
  23586. // fulfilled_handlers.fire
  23587. // rejected_handlers.fire
  23588. list.add(tuple[3].fire); // deferred.notify = function() { deferred.notifyWith(...) }
  23589. // deferred.resolve = function() { deferred.resolveWith(...) }
  23590. // deferred.reject = function() { deferred.rejectWith(...) }
  23591. deferred[tuple[0]] = function () {
  23592. deferred[tuple[0] + "With"](this === deferred ? undefined : this, arguments);
  23593. return this;
  23594. }; // deferred.notifyWith = list.fireWith
  23595. // deferred.resolveWith = list.fireWith
  23596. // deferred.rejectWith = list.fireWith
  23597. deferred[tuple[0] + "With"] = list.fireWith;
  23598. }); // Make the deferred a promise
  23599. promise.promise(deferred); // Call given func if any
  23600. if (func) {
  23601. func.call(deferred, deferred);
  23602. } // All done!
  23603. return deferred;
  23604. },
  23605. // Deferred helper
  23606. when: function (singleValue) {
  23607. var // count of uncompleted subordinates
  23608. remaining = arguments.length,
  23609. // count of unprocessed arguments
  23610. i = remaining,
  23611. // subordinate fulfillment data
  23612. resolveContexts = Array(i),
  23613. resolveValues = slice.call(arguments),
  23614. // the master Deferred
  23615. master = jQuery.Deferred(),
  23616. // subordinate callback factory
  23617. updateFunc = function (i) {
  23618. return function (value) {
  23619. resolveContexts[i] = this;
  23620. resolveValues[i] = arguments.length > 1 ? slice.call(arguments) : value;
  23621. if (! --remaining) {
  23622. master.resolveWith(resolveContexts, resolveValues);
  23623. }
  23624. };
  23625. }; // Single- and empty arguments are adopted like Promise.resolve
  23626. if (remaining <= 1) {
  23627. adoptValue(singleValue, master.done(updateFunc(i)).resolve, master.reject, !remaining); // Use .then() to unwrap secondary thenables (cf. gh-3000)
  23628. if (master.state() === "pending" || isFunction(resolveValues[i] && resolveValues[i].then)) {
  23629. return master.then();
  23630. }
  23631. } // Multiple arguments are aggregated like Promise.all array elements
  23632. while (i--) {
  23633. adoptValue(resolveValues[i], updateFunc(i), master.reject);
  23634. }
  23635. return master.promise();
  23636. }
  23637. }); // These usually indicate a programmer mistake during development,
  23638. // warn about them ASAP rather than swallowing them by default.
  23639. var rerrorNames = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;
  23640. jQuery.Deferred.exceptionHook = function (error, stack) {
  23641. // Support: IE 8 - 9 only
  23642. // Console exists when dev tools are open, which can happen at any time
  23643. if (window.console && window.console.warn && error && rerrorNames.test(error.name)) {
  23644. window.console.warn("jQuery.Deferred exception: " + error.message, error.stack, stack);
  23645. }
  23646. };
  23647. jQuery.readyException = function (error) {
  23648. window.setTimeout(function () {
  23649. throw error;
  23650. });
  23651. }; // The deferred used on DOM ready
  23652. var readyList = jQuery.Deferred();
  23653. jQuery.fn.ready = function (fn) {
  23654. readyList.then(fn) // Wrap jQuery.readyException in a function so that the lookup
  23655. // happens at the time of error handling instead of callback
  23656. // registration.
  23657. .catch(function (error) {
  23658. jQuery.readyException(error);
  23659. });
  23660. return this;
  23661. };
  23662. jQuery.extend({
  23663. // Is the DOM ready to be used? Set to true once it occurs.
  23664. isReady: false,
  23665. // A counter to track how many items to wait for before
  23666. // the ready event fires. See #6781
  23667. readyWait: 1,
  23668. // Handle when the DOM is ready
  23669. ready: function (wait) {
  23670. // Abort if there are pending holds or we're already ready
  23671. if (wait === true ? --jQuery.readyWait : jQuery.isReady) {
  23672. return;
  23673. } // Remember that the DOM is ready
  23674. jQuery.isReady = true; // If a normal DOM Ready event fired, decrement, and wait if need be
  23675. if (wait !== true && --jQuery.readyWait > 0) {
  23676. return;
  23677. } // If there are functions bound, to execute
  23678. readyList.resolveWith(document, [jQuery]);
  23679. }
  23680. });
  23681. jQuery.ready.then = readyList.then; // The ready event handler and self cleanup method
  23682. function completed() {
  23683. document.removeEventListener("DOMContentLoaded", completed);
  23684. window.removeEventListener("load", completed);
  23685. jQuery.ready();
  23686. } // Catch cases where $(document).ready() is called
  23687. // after the browser event has already occurred.
  23688. // Support: IE <=9 - 10 only
  23689. // Older IE sometimes signals "interactive" too soon
  23690. if (document.readyState === "complete" || document.readyState !== "loading" && !document.documentElement.doScroll) {
  23691. // Handle it asynchronously to allow scripts the opportunity to delay ready
  23692. window.setTimeout(jQuery.ready);
  23693. } else {
  23694. // Use the handy event callback
  23695. document.addEventListener("DOMContentLoaded", completed); // A fallback to window.onload, that will always work
  23696. window.addEventListener("load", completed);
  23697. } // Multifunctional method to get and set values of a collection
  23698. // The value/s can optionally be executed if it's a function
  23699. var access = function (elems, fn, key, value, chainable, emptyGet, raw) {
  23700. var i = 0,
  23701. len = elems.length,
  23702. bulk = key == null; // Sets many values
  23703. if (toType(key) === "object") {
  23704. chainable = true;
  23705. for (i in key) {
  23706. access(elems, fn, i, key[i], true, emptyGet, raw);
  23707. } // Sets one value
  23708. } else if (value !== undefined) {
  23709. chainable = true;
  23710. if (!isFunction(value)) {
  23711. raw = true;
  23712. }
  23713. if (bulk) {
  23714. // Bulk operations run against the entire set
  23715. if (raw) {
  23716. fn.call(elems, value);
  23717. fn = null; // ...except when executing function values
  23718. } else {
  23719. bulk = fn;
  23720. fn = function (elem, key, value) {
  23721. return bulk.call(jQuery(elem), value);
  23722. };
  23723. }
  23724. }
  23725. if (fn) {
  23726. for (; i < len; i++) {
  23727. fn(elems[i], key, raw ? value : value.call(elems[i], i, fn(elems[i], key)));
  23728. }
  23729. }
  23730. }
  23731. if (chainable) {
  23732. return elems;
  23733. } // Gets
  23734. if (bulk) {
  23735. return fn.call(elems);
  23736. }
  23737. return len ? fn(elems[0], key) : emptyGet;
  23738. }; // Matches dashed string for camelizing
  23739. var rmsPrefix = /^-ms-/,
  23740. rdashAlpha = /-([a-z])/g; // Used by camelCase as callback to replace()
  23741. function fcamelCase(all, letter) {
  23742. return letter.toUpperCase();
  23743. } // Convert dashed to camelCase; used by the css and data modules
  23744. // Support: IE <=9 - 11, Edge 12 - 15
  23745. // Microsoft forgot to hump their vendor prefix (#9572)
  23746. function camelCase(string) {
  23747. return string.replace(rmsPrefix, "ms-").replace(rdashAlpha, fcamelCase);
  23748. }
  23749. var acceptData = function (owner) {
  23750. // Accepts only:
  23751. // - Node
  23752. // - Node.ELEMENT_NODE
  23753. // - Node.DOCUMENT_NODE
  23754. // - Object
  23755. // - Any
  23756. return owner.nodeType === 1 || owner.nodeType === 9 || !+owner.nodeType;
  23757. };
  23758. function Data() {
  23759. this.expando = jQuery.expando + Data.uid++;
  23760. }
  23761. Data.uid = 1;
  23762. Data.prototype = {
  23763. cache: function (owner) {
  23764. // Check if the owner object already has a cache
  23765. var value = owner[this.expando]; // If not, create one
  23766. if (!value) {
  23767. value = {}; // We can accept data for non-element nodes in modern browsers,
  23768. // but we should not, see #8335.
  23769. // Always return an empty object.
  23770. if (acceptData(owner)) {
  23771. // If it is a node unlikely to be stringify-ed or looped over
  23772. // use plain assignment
  23773. if (owner.nodeType) {
  23774. owner[this.expando] = value; // Otherwise secure it in a non-enumerable property
  23775. // configurable must be true to allow the property to be
  23776. // deleted when data is removed
  23777. } else {
  23778. Object.defineProperty(owner, this.expando, {
  23779. value: value,
  23780. configurable: true
  23781. });
  23782. }
  23783. }
  23784. }
  23785. return value;
  23786. },
  23787. set: function (owner, data, value) {
  23788. var prop,
  23789. cache = this.cache(owner); // Handle: [ owner, key, value ] args
  23790. // Always use camelCase key (gh-2257)
  23791. if (typeof data === "string") {
  23792. cache[camelCase(data)] = value; // Handle: [ owner, { properties } ] args
  23793. } else {
  23794. // Copy the properties one-by-one to the cache object
  23795. for (prop in data) {
  23796. cache[camelCase(prop)] = data[prop];
  23797. }
  23798. }
  23799. return cache;
  23800. },
  23801. get: function (owner, key) {
  23802. return key === undefined ? this.cache(owner) : // Always use camelCase key (gh-2257)
  23803. owner[this.expando] && owner[this.expando][camelCase(key)];
  23804. },
  23805. access: function (owner, key, value) {
  23806. // In cases where either:
  23807. //
  23808. // 1. No key was specified
  23809. // 2. A string key was specified, but no value provided
  23810. //
  23811. // Take the "read" path and allow the get method to determine
  23812. // which value to return, respectively either:
  23813. //
  23814. // 1. The entire cache object
  23815. // 2. The data stored at the key
  23816. //
  23817. if (key === undefined || key && typeof key === "string" && value === undefined) {
  23818. return this.get(owner, key);
  23819. } // When the key is not a string, or both a key and value
  23820. // are specified, set or extend (existing objects) with either:
  23821. //
  23822. // 1. An object of properties
  23823. // 2. A key and value
  23824. //
  23825. this.set(owner, key, value); // Since the "set" path can have two possible entry points
  23826. // return the expected data based on which path was taken[*]
  23827. return value !== undefined ? value : key;
  23828. },
  23829. remove: function (owner, key) {
  23830. var i,
  23831. cache = owner[this.expando];
  23832. if (cache === undefined) {
  23833. return;
  23834. }
  23835. if (key !== undefined) {
  23836. // Support array or space separated string of keys
  23837. if (Array.isArray(key)) {
  23838. // If key is an array of keys...
  23839. // We always set camelCase keys, so remove that.
  23840. key = key.map(camelCase);
  23841. } else {
  23842. key = camelCase(key); // If a key with the spaces exists, use it.
  23843. // Otherwise, create an array by matching non-whitespace
  23844. key = key in cache ? [key] : key.match(rnothtmlwhite) || [];
  23845. }
  23846. i = key.length;
  23847. while (i--) {
  23848. delete cache[key[i]];
  23849. }
  23850. } // Remove the expando if there's no more data
  23851. if (key === undefined || jQuery.isEmptyObject(cache)) {
  23852. // Support: Chrome <=35 - 45
  23853. // Webkit & Blink performance suffers when deleting properties
  23854. // from DOM nodes, so set to undefined instead
  23855. // https://bugs.chromium.org/p/chromium/issues/detail?id=378607 (bug restricted)
  23856. if (owner.nodeType) {
  23857. owner[this.expando] = undefined;
  23858. } else {
  23859. delete owner[this.expando];
  23860. }
  23861. }
  23862. },
  23863. hasData: function (owner) {
  23864. var cache = owner[this.expando];
  23865. return cache !== undefined && !jQuery.isEmptyObject(cache);
  23866. }
  23867. };
  23868. var dataPriv = new Data();
  23869. var dataUser = new Data(); // Implementation Summary
  23870. //
  23871. // 1. Enforce API surface and semantic compatibility with 1.9.x branch
  23872. // 2. Improve the module's maintainability by reducing the storage
  23873. // paths to a single mechanism.
  23874. // 3. Use the same single mechanism to support "private" and "user" data.
  23875. // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
  23876. // 5. Avoid exposing implementation details on user objects (eg. expando properties)
  23877. // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
  23878. var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
  23879. rmultiDash = /[A-Z]/g;
  23880. function getData(data) {
  23881. if (data === "true") {
  23882. return true;
  23883. }
  23884. if (data === "false") {
  23885. return false;
  23886. }
  23887. if (data === "null") {
  23888. return null;
  23889. } // Only convert to a number if it doesn't change the string
  23890. if (data === +data + "") {
  23891. return +data;
  23892. }
  23893. if (rbrace.test(data)) {
  23894. return JSON.parse(data);
  23895. }
  23896. return data;
  23897. }
  23898. function dataAttr(elem, key, data) {
  23899. var name; // If nothing was found internally, try to fetch any
  23900. // data from the HTML5 data-* attribute
  23901. if (data === undefined && elem.nodeType === 1) {
  23902. name = "data-" + key.replace(rmultiDash, "-$&").toLowerCase();
  23903. data = elem.getAttribute(name);
  23904. if (typeof data === "string") {
  23905. try {
  23906. data = getData(data);
  23907. } catch (e) {} // Make sure we set the data so it isn't changed later
  23908. dataUser.set(elem, key, data);
  23909. } else {
  23910. data = undefined;
  23911. }
  23912. }
  23913. return data;
  23914. }
  23915. jQuery.extend({
  23916. hasData: function (elem) {
  23917. return dataUser.hasData(elem) || dataPriv.hasData(elem);
  23918. },
  23919. data: function (elem, name, data) {
  23920. return dataUser.access(elem, name, data);
  23921. },
  23922. removeData: function (elem, name) {
  23923. dataUser.remove(elem, name);
  23924. },
  23925. // TODO: Now that all calls to _data and _removeData have been replaced
  23926. // with direct calls to dataPriv methods, these can be deprecated.
  23927. _data: function (elem, name, data) {
  23928. return dataPriv.access(elem, name, data);
  23929. },
  23930. _removeData: function (elem, name) {
  23931. dataPriv.remove(elem, name);
  23932. }
  23933. });
  23934. jQuery.fn.extend({
  23935. data: function (key, value) {
  23936. var i,
  23937. name,
  23938. data,
  23939. elem = this[0],
  23940. attrs = elem && elem.attributes; // Gets all values
  23941. if (key === undefined) {
  23942. if (this.length) {
  23943. data = dataUser.get(elem);
  23944. if (elem.nodeType === 1 && !dataPriv.get(elem, "hasDataAttrs")) {
  23945. i = attrs.length;
  23946. while (i--) {
  23947. // Support: IE 11 only
  23948. // The attrs elements can be null (#14894)
  23949. if (attrs[i]) {
  23950. name = attrs[i].name;
  23951. if (name.indexOf("data-") === 0) {
  23952. name = camelCase(name.slice(5));
  23953. dataAttr(elem, name, data[name]);
  23954. }
  23955. }
  23956. }
  23957. dataPriv.set(elem, "hasDataAttrs", true);
  23958. }
  23959. }
  23960. return data;
  23961. } // Sets multiple values
  23962. if (typeof key === "object") {
  23963. return this.each(function () {
  23964. dataUser.set(this, key);
  23965. });
  23966. }
  23967. return access(this, function (value) {
  23968. var data; // The calling jQuery object (element matches) is not empty
  23969. // (and therefore has an element appears at this[ 0 ]) and the
  23970. // `value` parameter was not undefined. An empty jQuery object
  23971. // will result in `undefined` for elem = this[ 0 ] which will
  23972. // throw an exception if an attempt to read a data cache is made.
  23973. if (elem && value === undefined) {
  23974. // Attempt to get data from the cache
  23975. // The key will always be camelCased in Data
  23976. data = dataUser.get(elem, key);
  23977. if (data !== undefined) {
  23978. return data;
  23979. } // Attempt to "discover" the data in
  23980. // HTML5 custom data-* attrs
  23981. data = dataAttr(elem, key);
  23982. if (data !== undefined) {
  23983. return data;
  23984. } // We tried really hard, but the data doesn't exist.
  23985. return;
  23986. } // Set the data...
  23987. this.each(function () {
  23988. // We always store the camelCased key
  23989. dataUser.set(this, key, value);
  23990. });
  23991. }, null, value, arguments.length > 1, null, true);
  23992. },
  23993. removeData: function (key) {
  23994. return this.each(function () {
  23995. dataUser.remove(this, key);
  23996. });
  23997. }
  23998. });
  23999. jQuery.extend({
  24000. queue: function (elem, type, data) {
  24001. var queue;
  24002. if (elem) {
  24003. type = (type || "fx") + "queue";
  24004. queue = dataPriv.get(elem, type); // Speed up dequeue by getting out quickly if this is just a lookup
  24005. if (data) {
  24006. if (!queue || Array.isArray(data)) {
  24007. queue = dataPriv.access(elem, type, jQuery.makeArray(data));
  24008. } else {
  24009. queue.push(data);
  24010. }
  24011. }
  24012. return queue || [];
  24013. }
  24014. },
  24015. dequeue: function (elem, type) {
  24016. type = type || "fx";
  24017. var queue = jQuery.queue(elem, type),
  24018. startLength = queue.length,
  24019. fn = queue.shift(),
  24020. hooks = jQuery._queueHooks(elem, type),
  24021. next = function () {
  24022. jQuery.dequeue(elem, type);
  24023. }; // If the fx queue is dequeued, always remove the progress sentinel
  24024. if (fn === "inprogress") {
  24025. fn = queue.shift();
  24026. startLength--;
  24027. }
  24028. if (fn) {
  24029. // Add a progress sentinel to prevent the fx queue from being
  24030. // automatically dequeued
  24031. if (type === "fx") {
  24032. queue.unshift("inprogress");
  24033. } // Clear up the last queue stop function
  24034. delete hooks.stop;
  24035. fn.call(elem, next, hooks);
  24036. }
  24037. if (!startLength && hooks) {
  24038. hooks.empty.fire();
  24039. }
  24040. },
  24041. // Not public - generate a queueHooks object, or return the current one
  24042. _queueHooks: function (elem, type) {
  24043. var key = type + "queueHooks";
  24044. return dataPriv.get(elem, key) || dataPriv.access(elem, key, {
  24045. empty: jQuery.Callbacks("once memory").add(function () {
  24046. dataPriv.remove(elem, [type + "queue", key]);
  24047. })
  24048. });
  24049. }
  24050. });
  24051. jQuery.fn.extend({
  24052. queue: function (type, data) {
  24053. var setter = 2;
  24054. if (typeof type !== "string") {
  24055. data = type;
  24056. type = "fx";
  24057. setter--;
  24058. }
  24059. if (arguments.length < setter) {
  24060. return jQuery.queue(this[0], type);
  24061. }
  24062. return data === undefined ? this : this.each(function () {
  24063. var queue = jQuery.queue(this, type, data); // Ensure a hooks for this queue
  24064. jQuery._queueHooks(this, type);
  24065. if (type === "fx" && queue[0] !== "inprogress") {
  24066. jQuery.dequeue(this, type);
  24067. }
  24068. });
  24069. },
  24070. dequeue: function (type) {
  24071. return this.each(function () {
  24072. jQuery.dequeue(this, type);
  24073. });
  24074. },
  24075. clearQueue: function (type) {
  24076. return this.queue(type || "fx", []);
  24077. },
  24078. // Get a promise resolved when queues of a certain type
  24079. // are emptied (fx is the type by default)
  24080. promise: function (type, obj) {
  24081. var tmp,
  24082. count = 1,
  24083. defer = jQuery.Deferred(),
  24084. elements = this,
  24085. i = this.length,
  24086. resolve = function () {
  24087. if (! --count) {
  24088. defer.resolveWith(elements, [elements]);
  24089. }
  24090. };
  24091. if (typeof type !== "string") {
  24092. obj = type;
  24093. type = undefined;
  24094. }
  24095. type = type || "fx";
  24096. while (i--) {
  24097. tmp = dataPriv.get(elements[i], type + "queueHooks");
  24098. if (tmp && tmp.empty) {
  24099. count++;
  24100. tmp.empty.add(resolve);
  24101. }
  24102. }
  24103. resolve();
  24104. return defer.promise(obj);
  24105. }
  24106. });
  24107. var pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source;
  24108. var rcssNum = new RegExp("^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i");
  24109. var cssExpand = ["Top", "Right", "Bottom", "Left"];
  24110. var isHiddenWithinTree = function (elem, el) {
  24111. // isHiddenWithinTree might be called from jQuery#filter function;
  24112. // in that case, element will be second argument
  24113. elem = el || elem; // Inline style trumps all
  24114. return elem.style.display === "none" || elem.style.display === "" && // Otherwise, check computed style
  24115. // Support: Firefox <=43 - 45
  24116. // Disconnected elements can have computed display: none, so first confirm that elem is
  24117. // in the document.
  24118. jQuery.contains(elem.ownerDocument, elem) && jQuery.css(elem, "display") === "none";
  24119. };
  24120. var swap = function (elem, options, callback, args) {
  24121. var ret,
  24122. name,
  24123. old = {}; // Remember the old values, and insert the new ones
  24124. for (name in options) {
  24125. old[name] = elem.style[name];
  24126. elem.style[name] = options[name];
  24127. }
  24128. ret = callback.apply(elem, args || []); // Revert the old values
  24129. for (name in options) {
  24130. elem.style[name] = old[name];
  24131. }
  24132. return ret;
  24133. };
  24134. function adjustCSS(elem, prop, valueParts, tween) {
  24135. var adjusted,
  24136. scale,
  24137. maxIterations = 20,
  24138. currentValue = tween ? function () {
  24139. return tween.cur();
  24140. } : function () {
  24141. return jQuery.css(elem, prop, "");
  24142. },
  24143. initial = currentValue(),
  24144. unit = valueParts && valueParts[3] || (jQuery.cssNumber[prop] ? "" : "px"),
  24145. // Starting value computation is required for potential unit mismatches
  24146. initialInUnit = (jQuery.cssNumber[prop] || unit !== "px" && +initial) && rcssNum.exec(jQuery.css(elem, prop));
  24147. if (initialInUnit && initialInUnit[3] !== unit) {
  24148. // Support: Firefox <=54
  24149. // Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144)
  24150. initial = initial / 2; // Trust units reported by jQuery.css
  24151. unit = unit || initialInUnit[3]; // Iteratively approximate from a nonzero starting point
  24152. initialInUnit = +initial || 1;
  24153. while (maxIterations--) {
  24154. // Evaluate and update our best guess (doubling guesses that zero out).
  24155. // Finish if the scale equals or crosses 1 (making the old*new product non-positive).
  24156. jQuery.style(elem, prop, initialInUnit + unit);
  24157. if ((1 - scale) * (1 - (scale = currentValue() / initial || 0.5)) <= 0) {
  24158. maxIterations = 0;
  24159. }
  24160. initialInUnit = initialInUnit / scale;
  24161. }
  24162. initialInUnit = initialInUnit * 2;
  24163. jQuery.style(elem, prop, initialInUnit + unit); // Make sure we update the tween properties later on
  24164. valueParts = valueParts || [];
  24165. }
  24166. if (valueParts) {
  24167. initialInUnit = +initialInUnit || +initial || 0; // Apply relative offset (+=/-=) if specified
  24168. adjusted = valueParts[1] ? initialInUnit + (valueParts[1] + 1) * valueParts[2] : +valueParts[2];
  24169. if (tween) {
  24170. tween.unit = unit;
  24171. tween.start = initialInUnit;
  24172. tween.end = adjusted;
  24173. }
  24174. }
  24175. return adjusted;
  24176. }
  24177. var defaultDisplayMap = {};
  24178. function getDefaultDisplay(elem) {
  24179. var temp,
  24180. doc = elem.ownerDocument,
  24181. nodeName = elem.nodeName,
  24182. display = defaultDisplayMap[nodeName];
  24183. if (display) {
  24184. return display;
  24185. }
  24186. temp = doc.body.appendChild(doc.createElement(nodeName));
  24187. display = jQuery.css(temp, "display");
  24188. temp.parentNode.removeChild(temp);
  24189. if (display === "none") {
  24190. display = "block";
  24191. }
  24192. defaultDisplayMap[nodeName] = display;
  24193. return display;
  24194. }
  24195. function showHide(elements, show) {
  24196. var display,
  24197. elem,
  24198. values = [],
  24199. index = 0,
  24200. length = elements.length; // Determine new display value for elements that need to change
  24201. for (; index < length; index++) {
  24202. elem = elements[index];
  24203. if (!elem.style) {
  24204. continue;
  24205. }
  24206. display = elem.style.display;
  24207. if (show) {
  24208. // Since we force visibility upon cascade-hidden elements, an immediate (and slow)
  24209. // check is required in this first loop unless we have a nonempty display value (either
  24210. // inline or about-to-be-restored)
  24211. if (display === "none") {
  24212. values[index] = dataPriv.get(elem, "display") || null;
  24213. if (!values[index]) {
  24214. elem.style.display = "";
  24215. }
  24216. }
  24217. if (elem.style.display === "" && isHiddenWithinTree(elem)) {
  24218. values[index] = getDefaultDisplay(elem);
  24219. }
  24220. } else {
  24221. if (display !== "none") {
  24222. values[index] = "none"; // Remember what we're overwriting
  24223. dataPriv.set(elem, "display", display);
  24224. }
  24225. }
  24226. } // Set the display of the elements in a second loop to avoid constant reflow
  24227. for (index = 0; index < length; index++) {
  24228. if (values[index] != null) {
  24229. elements[index].style.display = values[index];
  24230. }
  24231. }
  24232. return elements;
  24233. }
  24234. jQuery.fn.extend({
  24235. show: function () {
  24236. return showHide(this, true);
  24237. },
  24238. hide: function () {
  24239. return showHide(this);
  24240. },
  24241. toggle: function (state) {
  24242. if (typeof state === "boolean") {
  24243. return state ? this.show() : this.hide();
  24244. }
  24245. return this.each(function () {
  24246. if (isHiddenWithinTree(this)) {
  24247. jQuery(this).show();
  24248. } else {
  24249. jQuery(this).hide();
  24250. }
  24251. });
  24252. }
  24253. });
  24254. var rcheckableType = /^(?:checkbox|radio)$/i;
  24255. var rtagName = /<([a-z][^\/\0>\x20\t\r\n\f]+)/i;
  24256. var rscriptType = /^$|^module$|\/(?:java|ecma)script/i; // We have to close these tags to support XHTML (#13200)
  24257. var wrapMap = {
  24258. // Support: IE <=9 only
  24259. option: [1, "<select multiple='multiple'>", "</select>"],
  24260. // XHTML parsers do not magically insert elements in the
  24261. // same way that tag soup parsers do. So we cannot shorten
  24262. // this by omitting <tbody> or other required elements.
  24263. thead: [1, "<table>", "</table>"],
  24264. col: [2, "<table><colgroup>", "</colgroup></table>"],
  24265. tr: [2, "<table><tbody>", "</tbody></table>"],
  24266. td: [3, "<table><tbody><tr>", "</tr></tbody></table>"],
  24267. _default: [0, "", ""]
  24268. }; // Support: IE <=9 only
  24269. wrapMap.optgroup = wrapMap.option;
  24270. wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
  24271. wrapMap.th = wrapMap.td;
  24272. function getAll(context, tag) {
  24273. // Support: IE <=9 - 11 only
  24274. // Use typeof to avoid zero-argument method invocation on host objects (#15151)
  24275. var ret;
  24276. if (typeof context.getElementsByTagName !== "undefined") {
  24277. ret = context.getElementsByTagName(tag || "*");
  24278. } else if (typeof context.querySelectorAll !== "undefined") {
  24279. ret = context.querySelectorAll(tag || "*");
  24280. } else {
  24281. ret = [];
  24282. }
  24283. if (tag === undefined || tag && nodeName(context, tag)) {
  24284. return jQuery.merge([context], ret);
  24285. }
  24286. return ret;
  24287. } // Mark scripts as having already been evaluated
  24288. function setGlobalEval(elems, refElements) {
  24289. var i = 0,
  24290. l = elems.length;
  24291. for (; i < l; i++) {
  24292. dataPriv.set(elems[i], "globalEval", !refElements || dataPriv.get(refElements[i], "globalEval"));
  24293. }
  24294. }
  24295. var rhtml = /<|&#?\w+;/;
  24296. function buildFragment(elems, context, scripts, selection, ignored) {
  24297. var elem,
  24298. tmp,
  24299. tag,
  24300. wrap,
  24301. contains,
  24302. j,
  24303. fragment = context.createDocumentFragment(),
  24304. nodes = [],
  24305. i = 0,
  24306. l = elems.length;
  24307. for (; i < l; i++) {
  24308. elem = elems[i];
  24309. if (elem || elem === 0) {
  24310. // Add nodes directly
  24311. if (toType(elem) === "object") {
  24312. // Support: Android <=4.0 only, PhantomJS 1 only
  24313. // push.apply(_, arraylike) throws on ancient WebKit
  24314. jQuery.merge(nodes, elem.nodeType ? [elem] : elem); // Convert non-html into a text node
  24315. } else if (!rhtml.test(elem)) {
  24316. nodes.push(context.createTextNode(elem)); // Convert html into DOM nodes
  24317. } else {
  24318. tmp = tmp || fragment.appendChild(context.createElement("div")); // Deserialize a standard representation
  24319. tag = (rtagName.exec(elem) || ["", ""])[1].toLowerCase();
  24320. wrap = wrapMap[tag] || wrapMap._default;
  24321. tmp.innerHTML = wrap[1] + jQuery.htmlPrefilter(elem) + wrap[2]; // Descend through wrappers to the right content
  24322. j = wrap[0];
  24323. while (j--) {
  24324. tmp = tmp.lastChild;
  24325. } // Support: Android <=4.0 only, PhantomJS 1 only
  24326. // push.apply(_, arraylike) throws on ancient WebKit
  24327. jQuery.merge(nodes, tmp.childNodes); // Remember the top-level container
  24328. tmp = fragment.firstChild; // Ensure the created nodes are orphaned (#12392)
  24329. tmp.textContent = "";
  24330. }
  24331. }
  24332. } // Remove wrapper from fragment
  24333. fragment.textContent = "";
  24334. i = 0;
  24335. while (elem = nodes[i++]) {
  24336. // Skip elements already in the context collection (trac-4087)
  24337. if (selection && jQuery.inArray(elem, selection) > -1) {
  24338. if (ignored) {
  24339. ignored.push(elem);
  24340. }
  24341. continue;
  24342. }
  24343. contains = jQuery.contains(elem.ownerDocument, elem); // Append to fragment
  24344. tmp = getAll(fragment.appendChild(elem), "script"); // Preserve script evaluation history
  24345. if (contains) {
  24346. setGlobalEval(tmp);
  24347. } // Capture executables
  24348. if (scripts) {
  24349. j = 0;
  24350. while (elem = tmp[j++]) {
  24351. if (rscriptType.test(elem.type || "")) {
  24352. scripts.push(elem);
  24353. }
  24354. }
  24355. }
  24356. }
  24357. return fragment;
  24358. }
  24359. (function () {
  24360. var fragment = document.createDocumentFragment(),
  24361. div = fragment.appendChild(document.createElement("div")),
  24362. input = document.createElement("input"); // Support: Android 4.0 - 4.3 only
  24363. // Check state lost if the name is set (#11217)
  24364. // Support: Windows Web Apps (WWA)
  24365. // `name` and `type` must use .setAttribute for WWA (#14901)
  24366. input.setAttribute("type", "radio");
  24367. input.setAttribute("checked", "checked");
  24368. input.setAttribute("name", "t");
  24369. div.appendChild(input); // Support: Android <=4.1 only
  24370. // Older WebKit doesn't clone checked state correctly in fragments
  24371. support.checkClone = div.cloneNode(true).cloneNode(true).lastChild.checked; // Support: IE <=11 only
  24372. // Make sure textarea (and checkbox) defaultValue is properly cloned
  24373. div.innerHTML = "<textarea>x</textarea>";
  24374. support.noCloneChecked = !!div.cloneNode(true).lastChild.defaultValue;
  24375. })();
  24376. var documentElement = document.documentElement;
  24377. var rkeyEvent = /^key/,
  24378. rmouseEvent = /^(?:mouse|pointer|contextmenu|drag|drop)|click/,
  24379. rtypenamespace = /^([^.]*)(?:\.(.+)|)/;
  24380. function returnTrue() {
  24381. return true;
  24382. }
  24383. function returnFalse() {
  24384. return false;
  24385. } // Support: IE <=9 only
  24386. // See #13393 for more info
  24387. function safeActiveElement() {
  24388. try {
  24389. return document.activeElement;
  24390. } catch (err) {}
  24391. }
  24392. function on(elem, types, selector, data, fn, one) {
  24393. var origFn, type; // Types can be a map of types/handlers
  24394. if (typeof types === "object") {
  24395. // ( types-Object, selector, data )
  24396. if (typeof selector !== "string") {
  24397. // ( types-Object, data )
  24398. data = data || selector;
  24399. selector = undefined;
  24400. }
  24401. for (type in types) {
  24402. on(elem, type, selector, data, types[type], one);
  24403. }
  24404. return elem;
  24405. }
  24406. if (data == null && fn == null) {
  24407. // ( types, fn )
  24408. fn = selector;
  24409. data = selector = undefined;
  24410. } else if (fn == null) {
  24411. if (typeof selector === "string") {
  24412. // ( types, selector, fn )
  24413. fn = data;
  24414. data = undefined;
  24415. } else {
  24416. // ( types, data, fn )
  24417. fn = data;
  24418. data = selector;
  24419. selector = undefined;
  24420. }
  24421. }
  24422. if (fn === false) {
  24423. fn = returnFalse;
  24424. } else if (!fn) {
  24425. return elem;
  24426. }
  24427. if (one === 1) {
  24428. origFn = fn;
  24429. fn = function (event) {
  24430. // Can use an empty set, since event contains the info
  24431. jQuery().off(event);
  24432. return origFn.apply(this, arguments);
  24433. }; // Use same guid so caller can remove using origFn
  24434. fn.guid = origFn.guid || (origFn.guid = jQuery.guid++);
  24435. }
  24436. return elem.each(function () {
  24437. jQuery.event.add(this, types, fn, data, selector);
  24438. });
  24439. }
  24440. /*
  24441. * Helper functions for managing events -- not part of the public interface.
  24442. * Props to Dean Edwards' addEvent library for many of the ideas.
  24443. */
  24444. jQuery.event = {
  24445. global: {},
  24446. add: function (elem, types, handler, data, selector) {
  24447. var handleObjIn,
  24448. eventHandle,
  24449. tmp,
  24450. events,
  24451. t,
  24452. handleObj,
  24453. special,
  24454. handlers,
  24455. type,
  24456. namespaces,
  24457. origType,
  24458. elemData = dataPriv.get(elem); // Don't attach events to noData or text/comment nodes (but allow plain objects)
  24459. if (!elemData) {
  24460. return;
  24461. } // Caller can pass in an object of custom data in lieu of the handler
  24462. if (handler.handler) {
  24463. handleObjIn = handler;
  24464. handler = handleObjIn.handler;
  24465. selector = handleObjIn.selector;
  24466. } // Ensure that invalid selectors throw exceptions at attach time
  24467. // Evaluate against documentElement in case elem is a non-element node (e.g., document)
  24468. if (selector) {
  24469. jQuery.find.matchesSelector(documentElement, selector);
  24470. } // Make sure that the handler has a unique ID, used to find/remove it later
  24471. if (!handler.guid) {
  24472. handler.guid = jQuery.guid++;
  24473. } // Init the element's event structure and main handler, if this is the first
  24474. if (!(events = elemData.events)) {
  24475. events = elemData.events = {};
  24476. }
  24477. if (!(eventHandle = elemData.handle)) {
  24478. eventHandle = elemData.handle = function (e) {
  24479. // Discard the second event of a jQuery.event.trigger() and
  24480. // when an event is called after a page has unloaded
  24481. return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ? jQuery.event.dispatch.apply(elem, arguments) : undefined;
  24482. };
  24483. } // Handle multiple events separated by a space
  24484. types = (types || "").match(rnothtmlwhite) || [""];
  24485. t = types.length;
  24486. while (t--) {
  24487. tmp = rtypenamespace.exec(types[t]) || [];
  24488. type = origType = tmp[1];
  24489. namespaces = (tmp[2] || "").split(".").sort(); // There *must* be a type, no attaching namespace-only handlers
  24490. if (!type) {
  24491. continue;
  24492. } // If event changes its type, use the special event handlers for the changed type
  24493. special = jQuery.event.special[type] || {}; // If selector defined, determine special event api type, otherwise given type
  24494. type = (selector ? special.delegateType : special.bindType) || type; // Update special based on newly reset type
  24495. special = jQuery.event.special[type] || {}; // handleObj is passed to all event handlers
  24496. handleObj = jQuery.extend({
  24497. type: type,
  24498. origType: origType,
  24499. data: data,
  24500. handler: handler,
  24501. guid: handler.guid,
  24502. selector: selector,
  24503. needsContext: selector && jQuery.expr.match.needsContext.test(selector),
  24504. namespace: namespaces.join(".")
  24505. }, handleObjIn); // Init the event handler queue if we're the first
  24506. if (!(handlers = events[type])) {
  24507. handlers = events[type] = [];
  24508. handlers.delegateCount = 0; // Only use addEventListener if the special events handler returns false
  24509. if (!special.setup || special.setup.call(elem, data, namespaces, eventHandle) === false) {
  24510. if (elem.addEventListener) {
  24511. elem.addEventListener(type, eventHandle);
  24512. }
  24513. }
  24514. }
  24515. if (special.add) {
  24516. special.add.call(elem, handleObj);
  24517. if (!handleObj.handler.guid) {
  24518. handleObj.handler.guid = handler.guid;
  24519. }
  24520. } // Add to the element's handler list, delegates in front
  24521. if (selector) {
  24522. handlers.splice(handlers.delegateCount++, 0, handleObj);
  24523. } else {
  24524. handlers.push(handleObj);
  24525. } // Keep track of which events have ever been used, for event optimization
  24526. jQuery.event.global[type] = true;
  24527. }
  24528. },
  24529. // Detach an event or set of events from an element
  24530. remove: function (elem, types, handler, selector, mappedTypes) {
  24531. var j,
  24532. origCount,
  24533. tmp,
  24534. events,
  24535. t,
  24536. handleObj,
  24537. special,
  24538. handlers,
  24539. type,
  24540. namespaces,
  24541. origType,
  24542. elemData = dataPriv.hasData(elem) && dataPriv.get(elem);
  24543. if (!elemData || !(events = elemData.events)) {
  24544. return;
  24545. } // Once for each type.namespace in types; type may be omitted
  24546. types = (types || "").match(rnothtmlwhite) || [""];
  24547. t = types.length;
  24548. while (t--) {
  24549. tmp = rtypenamespace.exec(types[t]) || [];
  24550. type = origType = tmp[1];
  24551. namespaces = (tmp[2] || "").split(".").sort(); // Unbind all events (on this namespace, if provided) for the element
  24552. if (!type) {
  24553. for (type in events) {
  24554. jQuery.event.remove(elem, type + types[t], handler, selector, true);
  24555. }
  24556. continue;
  24557. }
  24558. special = jQuery.event.special[type] || {};
  24559. type = (selector ? special.delegateType : special.bindType) || type;
  24560. handlers = events[type] || [];
  24561. tmp = tmp[2] && new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)"); // Remove matching events
  24562. origCount = j = handlers.length;
  24563. while (j--) {
  24564. handleObj = handlers[j];
  24565. if ((mappedTypes || origType === handleObj.origType) && (!handler || handler.guid === handleObj.guid) && (!tmp || tmp.test(handleObj.namespace)) && (!selector || selector === handleObj.selector || selector === "**" && handleObj.selector)) {
  24566. handlers.splice(j, 1);
  24567. if (handleObj.selector) {
  24568. handlers.delegateCount--;
  24569. }
  24570. if (special.remove) {
  24571. special.remove.call(elem, handleObj);
  24572. }
  24573. }
  24574. } // Remove generic event handler if we removed something and no more handlers exist
  24575. // (avoids potential for endless recursion during removal of special event handlers)
  24576. if (origCount && !handlers.length) {
  24577. if (!special.teardown || special.teardown.call(elem, namespaces, elemData.handle) === false) {
  24578. jQuery.removeEvent(elem, type, elemData.handle);
  24579. }
  24580. delete events[type];
  24581. }
  24582. } // Remove data and the expando if it's no longer used
  24583. if (jQuery.isEmptyObject(events)) {
  24584. dataPriv.remove(elem, "handle events");
  24585. }
  24586. },
  24587. dispatch: function (nativeEvent) {
  24588. // Make a writable jQuery.Event from the native event object
  24589. var event = jQuery.event.fix(nativeEvent);
  24590. var i,
  24591. j,
  24592. ret,
  24593. matched,
  24594. handleObj,
  24595. handlerQueue,
  24596. args = new Array(arguments.length),
  24597. handlers = (dataPriv.get(this, "events") || {})[event.type] || [],
  24598. special = jQuery.event.special[event.type] || {}; // Use the fix-ed jQuery.Event rather than the (read-only) native event
  24599. args[0] = event;
  24600. for (i = 1; i < arguments.length; i++) {
  24601. args[i] = arguments[i];
  24602. }
  24603. event.delegateTarget = this; // Call the preDispatch hook for the mapped type, and let it bail if desired
  24604. if (special.preDispatch && special.preDispatch.call(this, event) === false) {
  24605. return;
  24606. } // Determine handlers
  24607. handlerQueue = jQuery.event.handlers.call(this, event, handlers); // Run delegates first; they may want to stop propagation beneath us
  24608. i = 0;
  24609. while ((matched = handlerQueue[i++]) && !event.isPropagationStopped()) {
  24610. event.currentTarget = matched.elem;
  24611. j = 0;
  24612. while ((handleObj = matched.handlers[j++]) && !event.isImmediatePropagationStopped()) {
  24613. // Triggered event must either 1) have no namespace, or 2) have namespace(s)
  24614. // a subset or equal to those in the bound event (both can have no namespace).
  24615. if (!event.rnamespace || event.rnamespace.test(handleObj.namespace)) {
  24616. event.handleObj = handleObj;
  24617. event.data = handleObj.data;
  24618. ret = ((jQuery.event.special[handleObj.origType] || {}).handle || handleObj.handler).apply(matched.elem, args);
  24619. if (ret !== undefined) {
  24620. if ((event.result = ret) === false) {
  24621. event.preventDefault();
  24622. event.stopPropagation();
  24623. }
  24624. }
  24625. }
  24626. }
  24627. } // Call the postDispatch hook for the mapped type
  24628. if (special.postDispatch) {
  24629. special.postDispatch.call(this, event);
  24630. }
  24631. return event.result;
  24632. },
  24633. handlers: function (event, handlers) {
  24634. var i,
  24635. handleObj,
  24636. sel,
  24637. matchedHandlers,
  24638. matchedSelectors,
  24639. handlerQueue = [],
  24640. delegateCount = handlers.delegateCount,
  24641. cur = event.target; // Find delegate handlers
  24642. if (delegateCount && // Support: IE <=9
  24643. // Black-hole SVG <use> instance trees (trac-13180)
  24644. cur.nodeType && // Support: Firefox <=42
  24645. // Suppress spec-violating clicks indicating a non-primary pointer button (trac-3861)
  24646. // https://www.w3.org/TR/DOM-Level-3-Events/#event-type-click
  24647. // Support: IE 11 only
  24648. // ...but not arrow key "clicks" of radio inputs, which can have `button` -1 (gh-2343)
  24649. !(event.type === "click" && event.button >= 1)) {
  24650. for (; cur !== this; cur = cur.parentNode || this) {
  24651. // Don't check non-elements (#13208)
  24652. // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
  24653. if (cur.nodeType === 1 && !(event.type === "click" && cur.disabled === true)) {
  24654. matchedHandlers = [];
  24655. matchedSelectors = {};
  24656. for (i = 0; i < delegateCount; i++) {
  24657. handleObj = handlers[i]; // Don't conflict with Object.prototype properties (#13203)
  24658. sel = handleObj.selector + " ";
  24659. if (matchedSelectors[sel] === undefined) {
  24660. matchedSelectors[sel] = handleObj.needsContext ? jQuery(sel, this).index(cur) > -1 : jQuery.find(sel, this, null, [cur]).length;
  24661. }
  24662. if (matchedSelectors[sel]) {
  24663. matchedHandlers.push(handleObj);
  24664. }
  24665. }
  24666. if (matchedHandlers.length) {
  24667. handlerQueue.push({
  24668. elem: cur,
  24669. handlers: matchedHandlers
  24670. });
  24671. }
  24672. }
  24673. }
  24674. } // Add the remaining (directly-bound) handlers
  24675. cur = this;
  24676. if (delegateCount < handlers.length) {
  24677. handlerQueue.push({
  24678. elem: cur,
  24679. handlers: handlers.slice(delegateCount)
  24680. });
  24681. }
  24682. return handlerQueue;
  24683. },
  24684. addProp: function (name, hook) {
  24685. Object.defineProperty(jQuery.Event.prototype, name, {
  24686. enumerable: true,
  24687. configurable: true,
  24688. get: isFunction(hook) ? function () {
  24689. if (this.originalEvent) {
  24690. return hook(this.originalEvent);
  24691. }
  24692. } : function () {
  24693. if (this.originalEvent) {
  24694. return this.originalEvent[name];
  24695. }
  24696. },
  24697. set: function (value) {
  24698. Object.defineProperty(this, name, {
  24699. enumerable: true,
  24700. configurable: true,
  24701. writable: true,
  24702. value: value
  24703. });
  24704. }
  24705. });
  24706. },
  24707. fix: function (originalEvent) {
  24708. return originalEvent[jQuery.expando] ? originalEvent : new jQuery.Event(originalEvent);
  24709. },
  24710. special: {
  24711. load: {
  24712. // Prevent triggered image.load events from bubbling to window.load
  24713. noBubble: true
  24714. },
  24715. focus: {
  24716. // Fire native event if possible so blur/focus sequence is correct
  24717. trigger: function () {
  24718. if (this !== safeActiveElement() && this.focus) {
  24719. this.focus();
  24720. return false;
  24721. }
  24722. },
  24723. delegateType: "focusin"
  24724. },
  24725. blur: {
  24726. trigger: function () {
  24727. if (this === safeActiveElement() && this.blur) {
  24728. this.blur();
  24729. return false;
  24730. }
  24731. },
  24732. delegateType: "focusout"
  24733. },
  24734. click: {
  24735. // For checkbox, fire native event so checked state will be right
  24736. trigger: function () {
  24737. if (this.type === "checkbox" && this.click && nodeName(this, "input")) {
  24738. this.click();
  24739. return false;
  24740. }
  24741. },
  24742. // For cross-browser consistency, don't fire native .click() on links
  24743. _default: function (event) {
  24744. return nodeName(event.target, "a");
  24745. }
  24746. },
  24747. beforeunload: {
  24748. postDispatch: function (event) {
  24749. // Support: Firefox 20+
  24750. // Firefox doesn't alert if the returnValue field is not set.
  24751. if (event.result !== undefined && event.originalEvent) {
  24752. event.originalEvent.returnValue = event.result;
  24753. }
  24754. }
  24755. }
  24756. }
  24757. };
  24758. jQuery.removeEvent = function (elem, type, handle) {
  24759. // This "if" is needed for plain objects
  24760. if (elem.removeEventListener) {
  24761. elem.removeEventListener(type, handle);
  24762. }
  24763. };
  24764. jQuery.Event = function (src, props) {
  24765. // Allow instantiation without the 'new' keyword
  24766. if (!(this instanceof jQuery.Event)) {
  24767. return new jQuery.Event(src, props);
  24768. } // Event object
  24769. if (src && src.type) {
  24770. this.originalEvent = src;
  24771. this.type = src.type; // Events bubbling up the document may have been marked as prevented
  24772. // by a handler lower down the tree; reflect the correct value.
  24773. this.isDefaultPrevented = src.defaultPrevented || src.defaultPrevented === undefined && // Support: Android <=2.3 only
  24774. src.returnValue === false ? returnTrue : returnFalse; // Create target properties
  24775. // Support: Safari <=6 - 7 only
  24776. // Target should not be a text node (#504, #13143)
  24777. this.target = src.target && src.target.nodeType === 3 ? src.target.parentNode : src.target;
  24778. this.currentTarget = src.currentTarget;
  24779. this.relatedTarget = src.relatedTarget; // Event type
  24780. } else {
  24781. this.type = src;
  24782. } // Put explicitly provided properties onto the event object
  24783. if (props) {
  24784. jQuery.extend(this, props);
  24785. } // Create a timestamp if incoming event doesn't have one
  24786. this.timeStamp = src && src.timeStamp || Date.now(); // Mark it as fixed
  24787. this[jQuery.expando] = true;
  24788. }; // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
  24789. // https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
  24790. jQuery.Event.prototype = {
  24791. constructor: jQuery.Event,
  24792. isDefaultPrevented: returnFalse,
  24793. isPropagationStopped: returnFalse,
  24794. isImmediatePropagationStopped: returnFalse,
  24795. isSimulated: false,
  24796. preventDefault: function () {
  24797. var e = this.originalEvent;
  24798. this.isDefaultPrevented = returnTrue;
  24799. if (e && !this.isSimulated) {
  24800. e.preventDefault();
  24801. }
  24802. },
  24803. stopPropagation: function () {
  24804. var e = this.originalEvent;
  24805. this.isPropagationStopped = returnTrue;
  24806. if (e && !this.isSimulated) {
  24807. e.stopPropagation();
  24808. }
  24809. },
  24810. stopImmediatePropagation: function () {
  24811. var e = this.originalEvent;
  24812. this.isImmediatePropagationStopped = returnTrue;
  24813. if (e && !this.isSimulated) {
  24814. e.stopImmediatePropagation();
  24815. }
  24816. this.stopPropagation();
  24817. }
  24818. }; // Includes all common event props including KeyEvent and MouseEvent specific props
  24819. jQuery.each({
  24820. altKey: true,
  24821. bubbles: true,
  24822. cancelable: true,
  24823. changedTouches: true,
  24824. ctrlKey: true,
  24825. detail: true,
  24826. eventPhase: true,
  24827. metaKey: true,
  24828. pageX: true,
  24829. pageY: true,
  24830. shiftKey: true,
  24831. view: true,
  24832. "char": true,
  24833. charCode: true,
  24834. key: true,
  24835. keyCode: true,
  24836. button: true,
  24837. buttons: true,
  24838. clientX: true,
  24839. clientY: true,
  24840. offsetX: true,
  24841. offsetY: true,
  24842. pointerId: true,
  24843. pointerType: true,
  24844. screenX: true,
  24845. screenY: true,
  24846. targetTouches: true,
  24847. toElement: true,
  24848. touches: true,
  24849. which: function (event) {
  24850. var button = event.button; // Add which for key events
  24851. if (event.which == null && rkeyEvent.test(event.type)) {
  24852. return event.charCode != null ? event.charCode : event.keyCode;
  24853. } // Add which for click: 1 === left; 2 === middle; 3 === right
  24854. if (!event.which && button !== undefined && rmouseEvent.test(event.type)) {
  24855. if (button & 1) {
  24856. return 1;
  24857. }
  24858. if (button & 2) {
  24859. return 3;
  24860. }
  24861. if (button & 4) {
  24862. return 2;
  24863. }
  24864. return 0;
  24865. }
  24866. return event.which;
  24867. }
  24868. }, jQuery.event.addProp); // Create mouseenter/leave events using mouseover/out and event-time checks
  24869. // so that event delegation works in jQuery.
  24870. // Do the same for pointerenter/pointerleave and pointerover/pointerout
  24871. //
  24872. // Support: Safari 7 only
  24873. // Safari sends mouseenter too often; see:
  24874. // https://bugs.chromium.org/p/chromium/issues/detail?id=470258
  24875. // for the description of the bug (it existed in older Chrome versions as well).
  24876. jQuery.each({
  24877. mouseenter: "mouseover",
  24878. mouseleave: "mouseout",
  24879. pointerenter: "pointerover",
  24880. pointerleave: "pointerout"
  24881. }, function (orig, fix) {
  24882. jQuery.event.special[orig] = {
  24883. delegateType: fix,
  24884. bindType: fix,
  24885. handle: function (event) {
  24886. var ret,
  24887. target = this,
  24888. related = event.relatedTarget,
  24889. handleObj = event.handleObj; // For mouseenter/leave call the handler if related is outside the target.
  24890. // NB: No relatedTarget if the mouse left/entered the browser window
  24891. if (!related || related !== target && !jQuery.contains(target, related)) {
  24892. event.type = handleObj.origType;
  24893. ret = handleObj.handler.apply(this, arguments);
  24894. event.type = fix;
  24895. }
  24896. return ret;
  24897. }
  24898. };
  24899. });
  24900. jQuery.fn.extend({
  24901. on: function (types, selector, data, fn) {
  24902. return on(this, types, selector, data, fn);
  24903. },
  24904. one: function (types, selector, data, fn) {
  24905. return on(this, types, selector, data, fn, 1);
  24906. },
  24907. off: function (types, selector, fn) {
  24908. var handleObj, type;
  24909. if (types && types.preventDefault && types.handleObj) {
  24910. // ( event ) dispatched jQuery.Event
  24911. handleObj = types.handleObj;
  24912. jQuery(types.delegateTarget).off(handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType, handleObj.selector, handleObj.handler);
  24913. return this;
  24914. }
  24915. if (typeof types === "object") {
  24916. // ( types-object [, selector] )
  24917. for (type in types) {
  24918. this.off(type, selector, types[type]);
  24919. }
  24920. return this;
  24921. }
  24922. if (selector === false || typeof selector === "function") {
  24923. // ( types [, fn] )
  24924. fn = selector;
  24925. selector = undefined;
  24926. }
  24927. if (fn === false) {
  24928. fn = returnFalse;
  24929. }
  24930. return this.each(function () {
  24931. jQuery.event.remove(this, types, fn, selector);
  24932. });
  24933. }
  24934. });
  24935. var
  24936. /* eslint-disable max-len */
  24937. // See https://github.com/eslint/eslint/issues/3229
  24938. rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,
  24939. /* eslint-enable */
  24940. // Support: IE <=10 - 11, Edge 12 - 13 only
  24941. // In IE/Edge using regex groups here causes severe slowdowns.
  24942. // See https://connect.microsoft.com/IE/feedback/details/1736512/
  24943. rnoInnerhtml = /<script|<style|<link/i,
  24944. // checked="checked" or checked
  24945. rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
  24946. rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g; // Prefer a tbody over its parent table for containing new rows
  24947. function manipulationTarget(elem, content) {
  24948. if (nodeName(elem, "table") && nodeName(content.nodeType !== 11 ? content : content.firstChild, "tr")) {
  24949. return jQuery(elem).children("tbody")[0] || elem;
  24950. }
  24951. return elem;
  24952. } // Replace/restore the type attribute of script elements for safe DOM manipulation
  24953. function disableScript(elem) {
  24954. elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
  24955. return elem;
  24956. }
  24957. function restoreScript(elem) {
  24958. if ((elem.type || "").slice(0, 5) === "true/") {
  24959. elem.type = elem.type.slice(5);
  24960. } else {
  24961. elem.removeAttribute("type");
  24962. }
  24963. return elem;
  24964. }
  24965. function cloneCopyEvent(src, dest) {
  24966. var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
  24967. if (dest.nodeType !== 1) {
  24968. return;
  24969. } // 1. Copy private data: events, handlers, etc.
  24970. if (dataPriv.hasData(src)) {
  24971. pdataOld = dataPriv.access(src);
  24972. pdataCur = dataPriv.set(dest, pdataOld);
  24973. events = pdataOld.events;
  24974. if (events) {
  24975. delete pdataCur.handle;
  24976. pdataCur.events = {};
  24977. for (type in events) {
  24978. for (i = 0, l = events[type].length; i < l; i++) {
  24979. jQuery.event.add(dest, type, events[type][i]);
  24980. }
  24981. }
  24982. }
  24983. } // 2. Copy user data
  24984. if (dataUser.hasData(src)) {
  24985. udataOld = dataUser.access(src);
  24986. udataCur = jQuery.extend({}, udataOld);
  24987. dataUser.set(dest, udataCur);
  24988. }
  24989. } // Fix IE bugs, see support tests
  24990. function fixInput(src, dest) {
  24991. var nodeName = dest.nodeName.toLowerCase(); // Fails to persist the checked state of a cloned checkbox or radio button.
  24992. if (nodeName === "input" && rcheckableType.test(src.type)) {
  24993. dest.checked = src.checked; // Fails to return the selected option to the default selected state when cloning options
  24994. } else if (nodeName === "input" || nodeName === "textarea") {
  24995. dest.defaultValue = src.defaultValue;
  24996. }
  24997. }
  24998. function domManip(collection, args, callback, ignored) {
  24999. // Flatten any nested arrays
  25000. args = concat.apply([], args);
  25001. var fragment,
  25002. first,
  25003. scripts,
  25004. hasScripts,
  25005. node,
  25006. doc,
  25007. i = 0,
  25008. l = collection.length,
  25009. iNoClone = l - 1,
  25010. value = args[0],
  25011. valueIsFunction = isFunction(value); // We can't cloneNode fragments that contain checked, in WebKit
  25012. if (valueIsFunction || l > 1 && typeof value === "string" && !support.checkClone && rchecked.test(value)) {
  25013. return collection.each(function (index) {
  25014. var self = collection.eq(index);
  25015. if (valueIsFunction) {
  25016. args[0] = value.call(this, index, self.html());
  25017. }
  25018. domManip(self, args, callback, ignored);
  25019. });
  25020. }
  25021. if (l) {
  25022. fragment = buildFragment(args, collection[0].ownerDocument, false, collection, ignored);
  25023. first = fragment.firstChild;
  25024. if (fragment.childNodes.length === 1) {
  25025. fragment = first;
  25026. } // Require either new content or an interest in ignored elements to invoke the callback
  25027. if (first || ignored) {
  25028. scripts = jQuery.map(getAll(fragment, "script"), disableScript);
  25029. hasScripts = scripts.length; // Use the original fragment for the last item
  25030. // instead of the first because it can end up
  25031. // being emptied incorrectly in certain situations (#8070).
  25032. for (; i < l; i++) {
  25033. node = fragment;
  25034. if (i !== iNoClone) {
  25035. node = jQuery.clone(node, true, true); // Keep references to cloned scripts for later restoration
  25036. if (hasScripts) {
  25037. // Support: Android <=4.0 only, PhantomJS 1 only
  25038. // push.apply(_, arraylike) throws on ancient WebKit
  25039. jQuery.merge(scripts, getAll(node, "script"));
  25040. }
  25041. }
  25042. callback.call(collection[i], node, i);
  25043. }
  25044. if (hasScripts) {
  25045. doc = scripts[scripts.length - 1].ownerDocument; // Reenable scripts
  25046. jQuery.map(scripts, restoreScript); // Evaluate executable scripts on first document insertion
  25047. for (i = 0; i < hasScripts; i++) {
  25048. node = scripts[i];
  25049. if (rscriptType.test(node.type || "") && !dataPriv.access(node, "globalEval") && jQuery.contains(doc, node)) {
  25050. if (node.src && (node.type || "").toLowerCase() !== "module") {
  25051. // Optional AJAX dependency, but won't run scripts if not present
  25052. if (jQuery._evalUrl) {
  25053. jQuery._evalUrl(node.src);
  25054. }
  25055. } else {
  25056. DOMEval(node.textContent.replace(rcleanScript, ""), doc, node);
  25057. }
  25058. }
  25059. }
  25060. }
  25061. }
  25062. }
  25063. return collection;
  25064. }
  25065. function remove(elem, selector, keepData) {
  25066. var node,
  25067. nodes = selector ? jQuery.filter(selector, elem) : elem,
  25068. i = 0;
  25069. for (; (node = nodes[i]) != null; i++) {
  25070. if (!keepData && node.nodeType === 1) {
  25071. jQuery.cleanData(getAll(node));
  25072. }
  25073. if (node.parentNode) {
  25074. if (keepData && jQuery.contains(node.ownerDocument, node)) {
  25075. setGlobalEval(getAll(node, "script"));
  25076. }
  25077. node.parentNode.removeChild(node);
  25078. }
  25079. }
  25080. return elem;
  25081. }
  25082. jQuery.extend({
  25083. htmlPrefilter: function (html) {
  25084. return html.replace(rxhtmlTag, "<$1></$2>");
  25085. },
  25086. clone: function (elem, dataAndEvents, deepDataAndEvents) {
  25087. var i,
  25088. l,
  25089. srcElements,
  25090. destElements,
  25091. clone = elem.cloneNode(true),
  25092. inPage = jQuery.contains(elem.ownerDocument, elem); // Fix IE cloning issues
  25093. if (!support.noCloneChecked && (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem)) {
  25094. // We eschew Sizzle here for performance reasons: https://jsperf.com/getall-vs-sizzle/2
  25095. destElements = getAll(clone);
  25096. srcElements = getAll(elem);
  25097. for (i = 0, l = srcElements.length; i < l; i++) {
  25098. fixInput(srcElements[i], destElements[i]);
  25099. }
  25100. } // Copy the events from the original to the clone
  25101. if (dataAndEvents) {
  25102. if (deepDataAndEvents) {
  25103. srcElements = srcElements || getAll(elem);
  25104. destElements = destElements || getAll(clone);
  25105. for (i = 0, l = srcElements.length; i < l; i++) {
  25106. cloneCopyEvent(srcElements[i], destElements[i]);
  25107. }
  25108. } else {
  25109. cloneCopyEvent(elem, clone);
  25110. }
  25111. } // Preserve script evaluation history
  25112. destElements = getAll(clone, "script");
  25113. if (destElements.length > 0) {
  25114. setGlobalEval(destElements, !inPage && getAll(elem, "script"));
  25115. } // Return the cloned set
  25116. return clone;
  25117. },
  25118. cleanData: function (elems) {
  25119. var data,
  25120. elem,
  25121. type,
  25122. special = jQuery.event.special,
  25123. i = 0;
  25124. for (; (elem = elems[i]) !== undefined; i++) {
  25125. if (acceptData(elem)) {
  25126. if (data = elem[dataPriv.expando]) {
  25127. if (data.events) {
  25128. for (type in data.events) {
  25129. if (special[type]) {
  25130. jQuery.event.remove(elem, type); // This is a shortcut to avoid jQuery.event.remove's overhead
  25131. } else {
  25132. jQuery.removeEvent(elem, type, data.handle);
  25133. }
  25134. }
  25135. } // Support: Chrome <=35 - 45+
  25136. // Assign undefined instead of using delete, see Data#remove
  25137. elem[dataPriv.expando] = undefined;
  25138. }
  25139. if (elem[dataUser.expando]) {
  25140. // Support: Chrome <=35 - 45+
  25141. // Assign undefined instead of using delete, see Data#remove
  25142. elem[dataUser.expando] = undefined;
  25143. }
  25144. }
  25145. }
  25146. }
  25147. });
  25148. jQuery.fn.extend({
  25149. detach: function (selector) {
  25150. return remove(this, selector, true);
  25151. },
  25152. remove: function (selector) {
  25153. return remove(this, selector);
  25154. },
  25155. text: function (value) {
  25156. return access(this, function (value) {
  25157. return value === undefined ? jQuery.text(this) : this.empty().each(function () {
  25158. if (this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9) {
  25159. this.textContent = value;
  25160. }
  25161. });
  25162. }, null, value, arguments.length);
  25163. },
  25164. append: function () {
  25165. return domManip(this, arguments, function (elem) {
  25166. if (this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9) {
  25167. var target = manipulationTarget(this, elem);
  25168. target.appendChild(elem);
  25169. }
  25170. });
  25171. },
  25172. prepend: function () {
  25173. return domManip(this, arguments, function (elem) {
  25174. if (this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9) {
  25175. var target = manipulationTarget(this, elem);
  25176. target.insertBefore(elem, target.firstChild);
  25177. }
  25178. });
  25179. },
  25180. before: function () {
  25181. return domManip(this, arguments, function (elem) {
  25182. if (this.parentNode) {
  25183. this.parentNode.insertBefore(elem, this);
  25184. }
  25185. });
  25186. },
  25187. after: function () {
  25188. return domManip(this, arguments, function (elem) {
  25189. if (this.parentNode) {
  25190. this.parentNode.insertBefore(elem, this.nextSibling);
  25191. }
  25192. });
  25193. },
  25194. empty: function () {
  25195. var elem,
  25196. i = 0;
  25197. for (; (elem = this[i]) != null; i++) {
  25198. if (elem.nodeType === 1) {
  25199. // Prevent memory leaks
  25200. jQuery.cleanData(getAll(elem, false)); // Remove any remaining nodes
  25201. elem.textContent = "";
  25202. }
  25203. }
  25204. return this;
  25205. },
  25206. clone: function (dataAndEvents, deepDataAndEvents) {
  25207. dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
  25208. deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
  25209. return this.map(function () {
  25210. return jQuery.clone(this, dataAndEvents, deepDataAndEvents);
  25211. });
  25212. },
  25213. html: function (value) {
  25214. return access(this, function (value) {
  25215. var elem = this[0] || {},
  25216. i = 0,
  25217. l = this.length;
  25218. if (value === undefined && elem.nodeType === 1) {
  25219. return elem.innerHTML;
  25220. } // See if we can take a shortcut and just use innerHTML
  25221. if (typeof value === "string" && !rnoInnerhtml.test(value) && !wrapMap[(rtagName.exec(value) || ["", ""])[1].toLowerCase()]) {
  25222. value = jQuery.htmlPrefilter(value);
  25223. try {
  25224. for (; i < l; i++) {
  25225. elem = this[i] || {}; // Remove element nodes and prevent memory leaks
  25226. if (elem.nodeType === 1) {
  25227. jQuery.cleanData(getAll(elem, false));
  25228. elem.innerHTML = value;
  25229. }
  25230. }
  25231. elem = 0; // If using innerHTML throws an exception, use the fallback method
  25232. } catch (e) {}
  25233. }
  25234. if (elem) {
  25235. this.empty().append(value);
  25236. }
  25237. }, null, value, arguments.length);
  25238. },
  25239. replaceWith: function () {
  25240. var ignored = []; // Make the changes, replacing each non-ignored context element with the new content
  25241. return domManip(this, arguments, function (elem) {
  25242. var parent = this.parentNode;
  25243. if (jQuery.inArray(this, ignored) < 0) {
  25244. jQuery.cleanData(getAll(this));
  25245. if (parent) {
  25246. parent.replaceChild(elem, this);
  25247. }
  25248. } // Force callback invocation
  25249. }, ignored);
  25250. }
  25251. });
  25252. jQuery.each({
  25253. appendTo: "append",
  25254. prependTo: "prepend",
  25255. insertBefore: "before",
  25256. insertAfter: "after",
  25257. replaceAll: "replaceWith"
  25258. }, function (name, original) {
  25259. jQuery.fn[name] = function (selector) {
  25260. var elems,
  25261. ret = [],
  25262. insert = jQuery(selector),
  25263. last = insert.length - 1,
  25264. i = 0;
  25265. for (; i <= last; i++) {
  25266. elems = i === last ? this : this.clone(true);
  25267. jQuery(insert[i])[original](elems); // Support: Android <=4.0 only, PhantomJS 1 only
  25268. // .get() because push.apply(_, arraylike) throws on ancient WebKit
  25269. push.apply(ret, elems.get());
  25270. }
  25271. return this.pushStack(ret);
  25272. };
  25273. });
  25274. var rnumnonpx = new RegExp("^(" + pnum + ")(?!px)[a-z%]+$", "i");
  25275. var getStyles = function (elem) {
  25276. // Support: IE <=11 only, Firefox <=30 (#15098, #14150)
  25277. // IE throws on elements created in popups
  25278. // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
  25279. var view = elem.ownerDocument.defaultView;
  25280. if (!view || !view.opener) {
  25281. view = window;
  25282. }
  25283. return view.getComputedStyle(elem);
  25284. };
  25285. var rboxStyle = new RegExp(cssExpand.join("|"), "i");
  25286. (function () {
  25287. // Executing both pixelPosition & boxSizingReliable tests require only one layout
  25288. // so they're executed at the same time to save the second computation.
  25289. function computeStyleTests() {
  25290. // This is a singleton, we need to execute it only once
  25291. if (!div) {
  25292. return;
  25293. }
  25294. container.style.cssText = "position:absolute;left:-11111px;width:60px;" + "margin-top:1px;padding:0;border:0";
  25295. div.style.cssText = "position:relative;display:block;box-sizing:border-box;overflow:scroll;" + "margin:auto;border:1px;padding:1px;" + "width:60%;top:1%";
  25296. documentElement.appendChild(container).appendChild(div);
  25297. var divStyle = window.getComputedStyle(div);
  25298. pixelPositionVal = divStyle.top !== "1%"; // Support: Android 4.0 - 4.3 only, Firefox <=3 - 44
  25299. reliableMarginLeftVal = roundPixelMeasures(divStyle.marginLeft) === 12; // Support: Android 4.0 - 4.3 only, Safari <=9.1 - 10.1, iOS <=7.0 - 9.3
  25300. // Some styles come back with percentage values, even though they shouldn't
  25301. div.style.right = "60%";
  25302. pixelBoxStylesVal = roundPixelMeasures(divStyle.right) === 36; // Support: IE 9 - 11 only
  25303. // Detect misreporting of content dimensions for box-sizing:border-box elements
  25304. boxSizingReliableVal = roundPixelMeasures(divStyle.width) === 36; // Support: IE 9 only
  25305. // Detect overflow:scroll screwiness (gh-3699)
  25306. div.style.position = "absolute";
  25307. scrollboxSizeVal = div.offsetWidth === 36 || "absolute";
  25308. documentElement.removeChild(container); // Nullify the div so it wouldn't be stored in the memory and
  25309. // it will also be a sign that checks already performed
  25310. div = null;
  25311. }
  25312. function roundPixelMeasures(measure) {
  25313. return Math.round(parseFloat(measure));
  25314. }
  25315. var pixelPositionVal,
  25316. boxSizingReliableVal,
  25317. scrollboxSizeVal,
  25318. pixelBoxStylesVal,
  25319. reliableMarginLeftVal,
  25320. container = document.createElement("div"),
  25321. div = document.createElement("div"); // Finish early in limited (non-browser) environments
  25322. if (!div.style) {
  25323. return;
  25324. } // Support: IE <=9 - 11 only
  25325. // Style of cloned element affects source element cloned (#8908)
  25326. div.style.backgroundClip = "content-box";
  25327. div.cloneNode(true).style.backgroundClip = "";
  25328. support.clearCloneStyle = div.style.backgroundClip === "content-box";
  25329. jQuery.extend(support, {
  25330. boxSizingReliable: function () {
  25331. computeStyleTests();
  25332. return boxSizingReliableVal;
  25333. },
  25334. pixelBoxStyles: function () {
  25335. computeStyleTests();
  25336. return pixelBoxStylesVal;
  25337. },
  25338. pixelPosition: function () {
  25339. computeStyleTests();
  25340. return pixelPositionVal;
  25341. },
  25342. reliableMarginLeft: function () {
  25343. computeStyleTests();
  25344. return reliableMarginLeftVal;
  25345. },
  25346. scrollboxSize: function () {
  25347. computeStyleTests();
  25348. return scrollboxSizeVal;
  25349. }
  25350. });
  25351. })();
  25352. function curCSS(elem, name, computed) {
  25353. var width,
  25354. minWidth,
  25355. maxWidth,
  25356. ret,
  25357. // Support: Firefox 51+
  25358. // Retrieving style before computed somehow
  25359. // fixes an issue with getting wrong values
  25360. // on detached elements
  25361. style = elem.style;
  25362. computed = computed || getStyles(elem); // getPropertyValue is needed for:
  25363. // .css('filter') (IE 9 only, #12537)
  25364. // .css('--customProperty) (#3144)
  25365. if (computed) {
  25366. ret = computed.getPropertyValue(name) || computed[name];
  25367. if (ret === "" && !jQuery.contains(elem.ownerDocument, elem)) {
  25368. ret = jQuery.style(elem, name);
  25369. } // A tribute to the "awesome hack by Dean Edwards"
  25370. // Android Browser returns percentage for some values,
  25371. // but width seems to be reliably pixels.
  25372. // This is against the CSSOM draft spec:
  25373. // https://drafts.csswg.org/cssom/#resolved-values
  25374. if (!support.pixelBoxStyles() && rnumnonpx.test(ret) && rboxStyle.test(name)) {
  25375. // Remember the original values
  25376. width = style.width;
  25377. minWidth = style.minWidth;
  25378. maxWidth = style.maxWidth; // Put in the new values to get a computed value out
  25379. style.minWidth = style.maxWidth = style.width = ret;
  25380. ret = computed.width; // Revert the changed values
  25381. style.width = width;
  25382. style.minWidth = minWidth;
  25383. style.maxWidth = maxWidth;
  25384. }
  25385. }
  25386. return ret !== undefined ? // Support: IE <=9 - 11 only
  25387. // IE returns zIndex value as an integer.
  25388. ret + "" : ret;
  25389. }
  25390. function addGetHookIf(conditionFn, hookFn) {
  25391. // Define the hook, we'll check on the first run if it's really needed.
  25392. return {
  25393. get: function () {
  25394. if (conditionFn()) {
  25395. // Hook not needed (or it's not possible to use it due
  25396. // to missing dependency), remove it.
  25397. delete this.get;
  25398. return;
  25399. } // Hook needed; redefine it so that the support test is not executed again.
  25400. return (this.get = hookFn).apply(this, arguments);
  25401. }
  25402. };
  25403. }
  25404. var // Swappable if display is none or starts with table
  25405. // except "table", "table-cell", or "table-caption"
  25406. // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
  25407. rdisplayswap = /^(none|table(?!-c[ea]).+)/,
  25408. rcustomProp = /^--/,
  25409. cssShow = {
  25410. position: "absolute",
  25411. visibility: "hidden",
  25412. display: "block"
  25413. },
  25414. cssNormalTransform = {
  25415. letterSpacing: "0",
  25416. fontWeight: "400"
  25417. },
  25418. cssPrefixes = ["Webkit", "Moz", "ms"],
  25419. emptyStyle = document.createElement("div").style; // Return a css property mapped to a potentially vendor prefixed property
  25420. function vendorPropName(name) {
  25421. // Shortcut for names that are not vendor prefixed
  25422. if (name in emptyStyle) {
  25423. return name;
  25424. } // Check for vendor prefixed names
  25425. var capName = name[0].toUpperCase() + name.slice(1),
  25426. i = cssPrefixes.length;
  25427. while (i--) {
  25428. name = cssPrefixes[i] + capName;
  25429. if (name in emptyStyle) {
  25430. return name;
  25431. }
  25432. }
  25433. } // Return a property mapped along what jQuery.cssProps suggests or to
  25434. // a vendor prefixed property.
  25435. function finalPropName(name) {
  25436. var ret = jQuery.cssProps[name];
  25437. if (!ret) {
  25438. ret = jQuery.cssProps[name] = vendorPropName(name) || name;
  25439. }
  25440. return ret;
  25441. }
  25442. function setPositiveNumber(elem, value, subtract) {
  25443. // Any relative (+/-) values have already been
  25444. // normalized at this point
  25445. var matches = rcssNum.exec(value);
  25446. return matches ? // Guard against undefined "subtract", e.g., when used as in cssHooks
  25447. Math.max(0, matches[2] - (subtract || 0)) + (matches[3] || "px") : value;
  25448. }
  25449. function boxModelAdjustment(elem, dimension, box, isBorderBox, styles, computedVal) {
  25450. var i = dimension === "width" ? 1 : 0,
  25451. extra = 0,
  25452. delta = 0; // Adjustment may not be necessary
  25453. if (box === (isBorderBox ? "border" : "content")) {
  25454. return 0;
  25455. }
  25456. for (; i < 4; i += 2) {
  25457. // Both box models exclude margin
  25458. if (box === "margin") {
  25459. delta += jQuery.css(elem, box + cssExpand[i], true, styles);
  25460. } // If we get here with a content-box, we're seeking "padding" or "border" or "margin"
  25461. if (!isBorderBox) {
  25462. // Add padding
  25463. delta += jQuery.css(elem, "padding" + cssExpand[i], true, styles); // For "border" or "margin", add border
  25464. if (box !== "padding") {
  25465. delta += jQuery.css(elem, "border" + cssExpand[i] + "Width", true, styles); // But still keep track of it otherwise
  25466. } else {
  25467. extra += jQuery.css(elem, "border" + cssExpand[i] + "Width", true, styles);
  25468. } // If we get here with a border-box (content + padding + border), we're seeking "content" or
  25469. // "padding" or "margin"
  25470. } else {
  25471. // For "content", subtract padding
  25472. if (box === "content") {
  25473. delta -= jQuery.css(elem, "padding" + cssExpand[i], true, styles);
  25474. } // For "content" or "padding", subtract border
  25475. if (box !== "margin") {
  25476. delta -= jQuery.css(elem, "border" + cssExpand[i] + "Width", true, styles);
  25477. }
  25478. }
  25479. } // Account for positive content-box scroll gutter when requested by providing computedVal
  25480. if (!isBorderBox && computedVal >= 0) {
  25481. // offsetWidth/offsetHeight is a rounded sum of content, padding, scroll gutter, and border
  25482. // Assuming integer scroll gutter, subtract the rest and round down
  25483. delta += Math.max(0, Math.ceil(elem["offset" + dimension[0].toUpperCase() + dimension.slice(1)] - computedVal - delta - extra - 0.5));
  25484. }
  25485. return delta;
  25486. }
  25487. function getWidthOrHeight(elem, dimension, extra) {
  25488. // Start with computed style
  25489. var styles = getStyles(elem),
  25490. val = curCSS(elem, dimension, styles),
  25491. isBorderBox = jQuery.css(elem, "boxSizing", false, styles) === "border-box",
  25492. valueIsBorderBox = isBorderBox; // Support: Firefox <=54
  25493. // Return a confounding non-pixel value or feign ignorance, as appropriate.
  25494. if (rnumnonpx.test(val)) {
  25495. if (!extra) {
  25496. return val;
  25497. }
  25498. val = "auto";
  25499. } // Check for style in case a browser which returns unreliable values
  25500. // for getComputedStyle silently falls back to the reliable elem.style
  25501. valueIsBorderBox = valueIsBorderBox && (support.boxSizingReliable() || val === elem.style[dimension]); // Fall back to offsetWidth/offsetHeight when value is "auto"
  25502. // This happens for inline elements with no explicit setting (gh-3571)
  25503. // Support: Android <=4.1 - 4.3 only
  25504. // Also use offsetWidth/offsetHeight for misreported inline dimensions (gh-3602)
  25505. if (val === "auto" || !parseFloat(val) && jQuery.css(elem, "display", false, styles) === "inline") {
  25506. val = elem["offset" + dimension[0].toUpperCase() + dimension.slice(1)]; // offsetWidth/offsetHeight provide border-box values
  25507. valueIsBorderBox = true;
  25508. } // Normalize "" and auto
  25509. val = parseFloat(val) || 0; // Adjust for the element's box model
  25510. return val + boxModelAdjustment(elem, dimension, extra || (isBorderBox ? "border" : "content"), valueIsBorderBox, styles, // Provide the current computed size to request scroll gutter calculation (gh-3589)
  25511. val) + "px";
  25512. }
  25513. jQuery.extend({
  25514. // Add in style property hooks for overriding the default
  25515. // behavior of getting and setting a style property
  25516. cssHooks: {
  25517. opacity: {
  25518. get: function (elem, computed) {
  25519. if (computed) {
  25520. // We should always get a number back from opacity
  25521. var ret = curCSS(elem, "opacity");
  25522. return ret === "" ? "1" : ret;
  25523. }
  25524. }
  25525. }
  25526. },
  25527. // Don't automatically add "px" to these possibly-unitless properties
  25528. cssNumber: {
  25529. "animationIterationCount": true,
  25530. "columnCount": true,
  25531. "fillOpacity": true,
  25532. "flexGrow": true,
  25533. "flexShrink": true,
  25534. "fontWeight": true,
  25535. "lineHeight": true,
  25536. "opacity": true,
  25537. "order": true,
  25538. "orphans": true,
  25539. "widows": true,
  25540. "zIndex": true,
  25541. "zoom": true
  25542. },
  25543. // Add in properties whose names you wish to fix before
  25544. // setting or getting the value
  25545. cssProps: {},
  25546. // Get and set the style property on a DOM Node
  25547. style: function (elem, name, value, extra) {
  25548. // Don't set styles on text and comment nodes
  25549. if (!elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style) {
  25550. return;
  25551. } // Make sure that we're working with the right name
  25552. var ret,
  25553. type,
  25554. hooks,
  25555. origName = camelCase(name),
  25556. isCustomProp = rcustomProp.test(name),
  25557. style = elem.style; // Make sure that we're working with the right name. We don't
  25558. // want to query the value if it is a CSS custom property
  25559. // since they are user-defined.
  25560. if (!isCustomProp) {
  25561. name = finalPropName(origName);
  25562. } // Gets hook for the prefixed version, then unprefixed version
  25563. hooks = jQuery.cssHooks[name] || jQuery.cssHooks[origName]; // Check if we're setting a value
  25564. if (value !== undefined) {
  25565. type = typeof value; // Convert "+=" or "-=" to relative numbers (#7345)
  25566. if (type === "string" && (ret = rcssNum.exec(value)) && ret[1]) {
  25567. value = adjustCSS(elem, name, ret); // Fixes bug #9237
  25568. type = "number";
  25569. } // Make sure that null and NaN values aren't set (#7116)
  25570. if (value == null || value !== value) {
  25571. return;
  25572. } // If a number was passed in, add the unit (except for certain CSS properties)
  25573. if (type === "number") {
  25574. value += ret && ret[3] || (jQuery.cssNumber[origName] ? "" : "px");
  25575. } // background-* props affect original clone's values
  25576. if (!support.clearCloneStyle && value === "" && name.indexOf("background") === 0) {
  25577. style[name] = "inherit";
  25578. } // If a hook was provided, use that value, otherwise just set the specified value
  25579. if (!hooks || !("set" in hooks) || (value = hooks.set(elem, value, extra)) !== undefined) {
  25580. if (isCustomProp) {
  25581. style.setProperty(name, value);
  25582. } else {
  25583. style[name] = value;
  25584. }
  25585. }
  25586. } else {
  25587. // If a hook was provided get the non-computed value from there
  25588. if (hooks && "get" in hooks && (ret = hooks.get(elem, false, extra)) !== undefined) {
  25589. return ret;
  25590. } // Otherwise just get the value from the style object
  25591. return style[name];
  25592. }
  25593. },
  25594. css: function (elem, name, extra, styles) {
  25595. var val,
  25596. num,
  25597. hooks,
  25598. origName = camelCase(name),
  25599. isCustomProp = rcustomProp.test(name); // Make sure that we're working with the right name. We don't
  25600. // want to modify the value if it is a CSS custom property
  25601. // since they are user-defined.
  25602. if (!isCustomProp) {
  25603. name = finalPropName(origName);
  25604. } // Try prefixed name followed by the unprefixed name
  25605. hooks = jQuery.cssHooks[name] || jQuery.cssHooks[origName]; // If a hook was provided get the computed value from there
  25606. if (hooks && "get" in hooks) {
  25607. val = hooks.get(elem, true, extra);
  25608. } // Otherwise, if a way to get the computed value exists, use that
  25609. if (val === undefined) {
  25610. val = curCSS(elem, name, styles);
  25611. } // Convert "normal" to computed value
  25612. if (val === "normal" && name in cssNormalTransform) {
  25613. val = cssNormalTransform[name];
  25614. } // Make numeric if forced or a qualifier was provided and val looks numeric
  25615. if (extra === "" || extra) {
  25616. num = parseFloat(val);
  25617. return extra === true || isFinite(num) ? num || 0 : val;
  25618. }
  25619. return val;
  25620. }
  25621. });
  25622. jQuery.each(["height", "width"], function (i, dimension) {
  25623. jQuery.cssHooks[dimension] = {
  25624. get: function (elem, computed, extra) {
  25625. if (computed) {
  25626. // Certain elements can have dimension info if we invisibly show them
  25627. // but it must have a current display style that would benefit
  25628. return rdisplayswap.test(jQuery.css(elem, "display")) && ( // Support: Safari 8+
  25629. // Table columns in Safari have non-zero offsetWidth & zero
  25630. // getBoundingClientRect().width unless display is changed.
  25631. // Support: IE <=11 only
  25632. // Running getBoundingClientRect on a disconnected node
  25633. // in IE throws an error.
  25634. !elem.getClientRects().length || !elem.getBoundingClientRect().width) ? swap(elem, cssShow, function () {
  25635. return getWidthOrHeight(elem, dimension, extra);
  25636. }) : getWidthOrHeight(elem, dimension, extra);
  25637. }
  25638. },
  25639. set: function (elem, value, extra) {
  25640. var matches,
  25641. styles = getStyles(elem),
  25642. isBorderBox = jQuery.css(elem, "boxSizing", false, styles) === "border-box",
  25643. subtract = extra && boxModelAdjustment(elem, dimension, extra, isBorderBox, styles); // Account for unreliable border-box dimensions by comparing offset* to computed and
  25644. // faking a content-box to get border and padding (gh-3699)
  25645. if (isBorderBox && support.scrollboxSize() === styles.position) {
  25646. subtract -= Math.ceil(elem["offset" + dimension[0].toUpperCase() + dimension.slice(1)] - parseFloat(styles[dimension]) - boxModelAdjustment(elem, dimension, "border", false, styles) - 0.5);
  25647. } // Convert to pixels if value adjustment is needed
  25648. if (subtract && (matches = rcssNum.exec(value)) && (matches[3] || "px") !== "px") {
  25649. elem.style[dimension] = value;
  25650. value = jQuery.css(elem, dimension);
  25651. }
  25652. return setPositiveNumber(elem, value, subtract);
  25653. }
  25654. };
  25655. });
  25656. jQuery.cssHooks.marginLeft = addGetHookIf(support.reliableMarginLeft, function (elem, computed) {
  25657. if (computed) {
  25658. return (parseFloat(curCSS(elem, "marginLeft")) || elem.getBoundingClientRect().left - swap(elem, {
  25659. marginLeft: 0
  25660. }, function () {
  25661. return elem.getBoundingClientRect().left;
  25662. })) + "px";
  25663. }
  25664. }); // These hooks are used by animate to expand properties
  25665. jQuery.each({
  25666. margin: "",
  25667. padding: "",
  25668. border: "Width"
  25669. }, function (prefix, suffix) {
  25670. jQuery.cssHooks[prefix + suffix] = {
  25671. expand: function (value) {
  25672. var i = 0,
  25673. expanded = {},
  25674. // Assumes a single number if not a string
  25675. parts = typeof value === "string" ? value.split(" ") : [value];
  25676. for (; i < 4; i++) {
  25677. expanded[prefix + cssExpand[i] + suffix] = parts[i] || parts[i - 2] || parts[0];
  25678. }
  25679. return expanded;
  25680. }
  25681. };
  25682. if (prefix !== "margin") {
  25683. jQuery.cssHooks[prefix + suffix].set = setPositiveNumber;
  25684. }
  25685. });
  25686. jQuery.fn.extend({
  25687. css: function (name, value) {
  25688. return access(this, function (elem, name, value) {
  25689. var styles,
  25690. len,
  25691. map = {},
  25692. i = 0;
  25693. if (Array.isArray(name)) {
  25694. styles = getStyles(elem);
  25695. len = name.length;
  25696. for (; i < len; i++) {
  25697. map[name[i]] = jQuery.css(elem, name[i], false, styles);
  25698. }
  25699. return map;
  25700. }
  25701. return value !== undefined ? jQuery.style(elem, name, value) : jQuery.css(elem, name);
  25702. }, name, value, arguments.length > 1);
  25703. }
  25704. });
  25705. function Tween(elem, options, prop, end, easing) {
  25706. return new Tween.prototype.init(elem, options, prop, end, easing);
  25707. }
  25708. jQuery.Tween = Tween;
  25709. Tween.prototype = {
  25710. constructor: Tween,
  25711. init: function (elem, options, prop, end, easing, unit) {
  25712. this.elem = elem;
  25713. this.prop = prop;
  25714. this.easing = easing || jQuery.easing._default;
  25715. this.options = options;
  25716. this.start = this.now = this.cur();
  25717. this.end = end;
  25718. this.unit = unit || (jQuery.cssNumber[prop] ? "" : "px");
  25719. },
  25720. cur: function () {
  25721. var hooks = Tween.propHooks[this.prop];
  25722. return hooks && hooks.get ? hooks.get(this) : Tween.propHooks._default.get(this);
  25723. },
  25724. run: function (percent) {
  25725. var eased,
  25726. hooks = Tween.propHooks[this.prop];
  25727. if (this.options.duration) {
  25728. this.pos = eased = jQuery.easing[this.easing](percent, this.options.duration * percent, 0, 1, this.options.duration);
  25729. } else {
  25730. this.pos = eased = percent;
  25731. }
  25732. this.now = (this.end - this.start) * eased + this.start;
  25733. if (this.options.step) {
  25734. this.options.step.call(this.elem, this.now, this);
  25735. }
  25736. if (hooks && hooks.set) {
  25737. hooks.set(this);
  25738. } else {
  25739. Tween.propHooks._default.set(this);
  25740. }
  25741. return this;
  25742. }
  25743. };
  25744. Tween.prototype.init.prototype = Tween.prototype;
  25745. Tween.propHooks = {
  25746. _default: {
  25747. get: function (tween) {
  25748. var result; // Use a property on the element directly when it is not a DOM element,
  25749. // or when there is no matching style property that exists.
  25750. if (tween.elem.nodeType !== 1 || tween.elem[tween.prop] != null && tween.elem.style[tween.prop] == null) {
  25751. return tween.elem[tween.prop];
  25752. } // Passing an empty string as a 3rd parameter to .css will automatically
  25753. // attempt a parseFloat and fallback to a string if the parse fails.
  25754. // Simple values such as "10px" are parsed to Float;
  25755. // complex values such as "rotate(1rad)" are returned as-is.
  25756. result = jQuery.css(tween.elem, tween.prop, ""); // Empty strings, null, undefined and "auto" are converted to 0.
  25757. return !result || result === "auto" ? 0 : result;
  25758. },
  25759. set: function (tween) {
  25760. // Use step hook for back compat.
  25761. // Use cssHook if its there.
  25762. // Use .style if available and use plain properties where available.
  25763. if (jQuery.fx.step[tween.prop]) {
  25764. jQuery.fx.step[tween.prop](tween);
  25765. } else if (tween.elem.nodeType === 1 && (tween.elem.style[jQuery.cssProps[tween.prop]] != null || jQuery.cssHooks[tween.prop])) {
  25766. jQuery.style(tween.elem, tween.prop, tween.now + tween.unit);
  25767. } else {
  25768. tween.elem[tween.prop] = tween.now;
  25769. }
  25770. }
  25771. }
  25772. }; // Support: IE <=9 only
  25773. // Panic based approach to setting things on disconnected nodes
  25774. Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
  25775. set: function (tween) {
  25776. if (tween.elem.nodeType && tween.elem.parentNode) {
  25777. tween.elem[tween.prop] = tween.now;
  25778. }
  25779. }
  25780. };
  25781. jQuery.easing = {
  25782. linear: function (p) {
  25783. return p;
  25784. },
  25785. swing: function (p) {
  25786. return 0.5 - Math.cos(p * Math.PI) / 2;
  25787. },
  25788. _default: "swing"
  25789. };
  25790. jQuery.fx = Tween.prototype.init; // Back compat <1.8 extension point
  25791. jQuery.fx.step = {};
  25792. var fxNow,
  25793. inProgress,
  25794. rfxtypes = /^(?:toggle|show|hide)$/,
  25795. rrun = /queueHooks$/;
  25796. function schedule() {
  25797. if (inProgress) {
  25798. if (document.hidden === false && window.requestAnimationFrame) {
  25799. window.requestAnimationFrame(schedule);
  25800. } else {
  25801. window.setTimeout(schedule, jQuery.fx.interval);
  25802. }
  25803. jQuery.fx.tick();
  25804. }
  25805. } // Animations created synchronously will run synchronously
  25806. function createFxNow() {
  25807. window.setTimeout(function () {
  25808. fxNow = undefined;
  25809. });
  25810. return fxNow = Date.now();
  25811. } // Generate parameters to create a standard animation
  25812. function genFx(type, includeWidth) {
  25813. var which,
  25814. i = 0,
  25815. attrs = {
  25816. height: type
  25817. }; // If we include width, step value is 1 to do all cssExpand values,
  25818. // otherwise step value is 2 to skip over Left and Right
  25819. includeWidth = includeWidth ? 1 : 0;
  25820. for (; i < 4; i += 2 - includeWidth) {
  25821. which = cssExpand[i];
  25822. attrs["margin" + which] = attrs["padding" + which] = type;
  25823. }
  25824. if (includeWidth) {
  25825. attrs.opacity = attrs.width = type;
  25826. }
  25827. return attrs;
  25828. }
  25829. function createTween(value, prop, animation) {
  25830. var tween,
  25831. collection = (Animation.tweeners[prop] || []).concat(Animation.tweeners["*"]),
  25832. index = 0,
  25833. length = collection.length;
  25834. for (; index < length; index++) {
  25835. if (tween = collection[index].call(animation, prop, value)) {
  25836. // We're done with this property
  25837. return tween;
  25838. }
  25839. }
  25840. }
  25841. function defaultPrefilter(elem, props, opts) {
  25842. var prop,
  25843. value,
  25844. toggle,
  25845. hooks,
  25846. oldfire,
  25847. propTween,
  25848. restoreDisplay,
  25849. display,
  25850. isBox = "width" in props || "height" in props,
  25851. anim = this,
  25852. orig = {},
  25853. style = elem.style,
  25854. hidden = elem.nodeType && isHiddenWithinTree(elem),
  25855. dataShow = dataPriv.get(elem, "fxshow"); // Queue-skipping animations hijack the fx hooks
  25856. if (!opts.queue) {
  25857. hooks = jQuery._queueHooks(elem, "fx");
  25858. if (hooks.unqueued == null) {
  25859. hooks.unqueued = 0;
  25860. oldfire = hooks.empty.fire;
  25861. hooks.empty.fire = function () {
  25862. if (!hooks.unqueued) {
  25863. oldfire();
  25864. }
  25865. };
  25866. }
  25867. hooks.unqueued++;
  25868. anim.always(function () {
  25869. // Ensure the complete handler is called before this completes
  25870. anim.always(function () {
  25871. hooks.unqueued--;
  25872. if (!jQuery.queue(elem, "fx").length) {
  25873. hooks.empty.fire();
  25874. }
  25875. });
  25876. });
  25877. } // Detect show/hide animations
  25878. for (prop in props) {
  25879. value = props[prop];
  25880. if (rfxtypes.test(value)) {
  25881. delete props[prop];
  25882. toggle = toggle || value === "toggle";
  25883. if (value === (hidden ? "hide" : "show")) {
  25884. // Pretend to be hidden if this is a "show" and
  25885. // there is still data from a stopped show/hide
  25886. if (value === "show" && dataShow && dataShow[prop] !== undefined) {
  25887. hidden = true; // Ignore all other no-op show/hide data
  25888. } else {
  25889. continue;
  25890. }
  25891. }
  25892. orig[prop] = dataShow && dataShow[prop] || jQuery.style(elem, prop);
  25893. }
  25894. } // Bail out if this is a no-op like .hide().hide()
  25895. propTween = !jQuery.isEmptyObject(props);
  25896. if (!propTween && jQuery.isEmptyObject(orig)) {
  25897. return;
  25898. } // Restrict "overflow" and "display" styles during box animations
  25899. if (isBox && elem.nodeType === 1) {
  25900. // Support: IE <=9 - 11, Edge 12 - 15
  25901. // Record all 3 overflow attributes because IE does not infer the shorthand
  25902. // from identically-valued overflowX and overflowY and Edge just mirrors
  25903. // the overflowX value there.
  25904. opts.overflow = [style.overflow, style.overflowX, style.overflowY]; // Identify a display type, preferring old show/hide data over the CSS cascade
  25905. restoreDisplay = dataShow && dataShow.display;
  25906. if (restoreDisplay == null) {
  25907. restoreDisplay = dataPriv.get(elem, "display");
  25908. }
  25909. display = jQuery.css(elem, "display");
  25910. if (display === "none") {
  25911. if (restoreDisplay) {
  25912. display = restoreDisplay;
  25913. } else {
  25914. // Get nonempty value(s) by temporarily forcing visibility
  25915. showHide([elem], true);
  25916. restoreDisplay = elem.style.display || restoreDisplay;
  25917. display = jQuery.css(elem, "display");
  25918. showHide([elem]);
  25919. }
  25920. } // Animate inline elements as inline-block
  25921. if (display === "inline" || display === "inline-block" && restoreDisplay != null) {
  25922. if (jQuery.css(elem, "float") === "none") {
  25923. // Restore the original display value at the end of pure show/hide animations
  25924. if (!propTween) {
  25925. anim.done(function () {
  25926. style.display = restoreDisplay;
  25927. });
  25928. if (restoreDisplay == null) {
  25929. display = style.display;
  25930. restoreDisplay = display === "none" ? "" : display;
  25931. }
  25932. }
  25933. style.display = "inline-block";
  25934. }
  25935. }
  25936. }
  25937. if (opts.overflow) {
  25938. style.overflow = "hidden";
  25939. anim.always(function () {
  25940. style.overflow = opts.overflow[0];
  25941. style.overflowX = opts.overflow[1];
  25942. style.overflowY = opts.overflow[2];
  25943. });
  25944. } // Implement show/hide animations
  25945. propTween = false;
  25946. for (prop in orig) {
  25947. // General show/hide setup for this element animation
  25948. if (!propTween) {
  25949. if (dataShow) {
  25950. if ("hidden" in dataShow) {
  25951. hidden = dataShow.hidden;
  25952. }
  25953. } else {
  25954. dataShow = dataPriv.access(elem, "fxshow", {
  25955. display: restoreDisplay
  25956. });
  25957. } // Store hidden/visible for toggle so `.stop().toggle()` "reverses"
  25958. if (toggle) {
  25959. dataShow.hidden = !hidden;
  25960. } // Show elements before animating them
  25961. if (hidden) {
  25962. showHide([elem], true);
  25963. }
  25964. /* eslint-disable no-loop-func */
  25965. anim.done(function () {
  25966. /* eslint-enable no-loop-func */
  25967. // The final step of a "hide" animation is actually hiding the element
  25968. if (!hidden) {
  25969. showHide([elem]);
  25970. }
  25971. dataPriv.remove(elem, "fxshow");
  25972. for (prop in orig) {
  25973. jQuery.style(elem, prop, orig[prop]);
  25974. }
  25975. });
  25976. } // Per-property setup
  25977. propTween = createTween(hidden ? dataShow[prop] : 0, prop, anim);
  25978. if (!(prop in dataShow)) {
  25979. dataShow[prop] = propTween.start;
  25980. if (hidden) {
  25981. propTween.end = propTween.start;
  25982. propTween.start = 0;
  25983. }
  25984. }
  25985. }
  25986. }
  25987. function propFilter(props, specialEasing) {
  25988. var index, name, easing, value, hooks; // camelCase, specialEasing and expand cssHook pass
  25989. for (index in props) {
  25990. name = camelCase(index);
  25991. easing = specialEasing[name];
  25992. value = props[index];
  25993. if (Array.isArray(value)) {
  25994. easing = value[1];
  25995. value = props[index] = value[0];
  25996. }
  25997. if (index !== name) {
  25998. props[name] = value;
  25999. delete props[index];
  26000. }
  26001. hooks = jQuery.cssHooks[name];
  26002. if (hooks && "expand" in hooks) {
  26003. value = hooks.expand(value);
  26004. delete props[name]; // Not quite $.extend, this won't overwrite existing keys.
  26005. // Reusing 'index' because we have the correct "name"
  26006. for (index in value) {
  26007. if (!(index in props)) {
  26008. props[index] = value[index];
  26009. specialEasing[index] = easing;
  26010. }
  26011. }
  26012. } else {
  26013. specialEasing[name] = easing;
  26014. }
  26015. }
  26016. }
  26017. function Animation(elem, properties, options) {
  26018. var result,
  26019. stopped,
  26020. index = 0,
  26021. length = Animation.prefilters.length,
  26022. deferred = jQuery.Deferred().always(function () {
  26023. // Don't match elem in the :animated selector
  26024. delete tick.elem;
  26025. }),
  26026. tick = function () {
  26027. if (stopped) {
  26028. return false;
  26029. }
  26030. var currentTime = fxNow || createFxNow(),
  26031. remaining = Math.max(0, animation.startTime + animation.duration - currentTime),
  26032. // Support: Android 2.3 only
  26033. // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
  26034. temp = remaining / animation.duration || 0,
  26035. percent = 1 - temp,
  26036. index = 0,
  26037. length = animation.tweens.length;
  26038. for (; index < length; index++) {
  26039. animation.tweens[index].run(percent);
  26040. }
  26041. deferred.notifyWith(elem, [animation, percent, remaining]); // If there's more to do, yield
  26042. if (percent < 1 && length) {
  26043. return remaining;
  26044. } // If this was an empty animation, synthesize a final progress notification
  26045. if (!length) {
  26046. deferred.notifyWith(elem, [animation, 1, 0]);
  26047. } // Resolve the animation and report its conclusion
  26048. deferred.resolveWith(elem, [animation]);
  26049. return false;
  26050. },
  26051. animation = deferred.promise({
  26052. elem: elem,
  26053. props: jQuery.extend({}, properties),
  26054. opts: jQuery.extend(true, {
  26055. specialEasing: {},
  26056. easing: jQuery.easing._default
  26057. }, options),
  26058. originalProperties: properties,
  26059. originalOptions: options,
  26060. startTime: fxNow || createFxNow(),
  26061. duration: options.duration,
  26062. tweens: [],
  26063. createTween: function (prop, end) {
  26064. var tween = jQuery.Tween(elem, animation.opts, prop, end, animation.opts.specialEasing[prop] || animation.opts.easing);
  26065. animation.tweens.push(tween);
  26066. return tween;
  26067. },
  26068. stop: function (gotoEnd) {
  26069. var index = 0,
  26070. // If we are going to the end, we want to run all the tweens
  26071. // otherwise we skip this part
  26072. length = gotoEnd ? animation.tweens.length : 0;
  26073. if (stopped) {
  26074. return this;
  26075. }
  26076. stopped = true;
  26077. for (; index < length; index++) {
  26078. animation.tweens[index].run(1);
  26079. } // Resolve when we played the last frame; otherwise, reject
  26080. if (gotoEnd) {
  26081. deferred.notifyWith(elem, [animation, 1, 0]);
  26082. deferred.resolveWith(elem, [animation, gotoEnd]);
  26083. } else {
  26084. deferred.rejectWith(elem, [animation, gotoEnd]);
  26085. }
  26086. return this;
  26087. }
  26088. }),
  26089. props = animation.props;
  26090. propFilter(props, animation.opts.specialEasing);
  26091. for (; index < length; index++) {
  26092. result = Animation.prefilters[index].call(animation, elem, props, animation.opts);
  26093. if (result) {
  26094. if (isFunction(result.stop)) {
  26095. jQuery._queueHooks(animation.elem, animation.opts.queue).stop = result.stop.bind(result);
  26096. }
  26097. return result;
  26098. }
  26099. }
  26100. jQuery.map(props, createTween, animation);
  26101. if (isFunction(animation.opts.start)) {
  26102. animation.opts.start.call(elem, animation);
  26103. } // Attach callbacks from options
  26104. animation.progress(animation.opts.progress).done(animation.opts.done, animation.opts.complete).fail(animation.opts.fail).always(animation.opts.always);
  26105. jQuery.fx.timer(jQuery.extend(tick, {
  26106. elem: elem,
  26107. anim: animation,
  26108. queue: animation.opts.queue
  26109. }));
  26110. return animation;
  26111. }
  26112. jQuery.Animation = jQuery.extend(Animation, {
  26113. tweeners: {
  26114. "*": [function (prop, value) {
  26115. var tween = this.createTween(prop, value);
  26116. adjustCSS(tween.elem, prop, rcssNum.exec(value), tween);
  26117. return tween;
  26118. }]
  26119. },
  26120. tweener: function (props, callback) {
  26121. if (isFunction(props)) {
  26122. callback = props;
  26123. props = ["*"];
  26124. } else {
  26125. props = props.match(rnothtmlwhite);
  26126. }
  26127. var prop,
  26128. index = 0,
  26129. length = props.length;
  26130. for (; index < length; index++) {
  26131. prop = props[index];
  26132. Animation.tweeners[prop] = Animation.tweeners[prop] || [];
  26133. Animation.tweeners[prop].unshift(callback);
  26134. }
  26135. },
  26136. prefilters: [defaultPrefilter],
  26137. prefilter: function (callback, prepend) {
  26138. if (prepend) {
  26139. Animation.prefilters.unshift(callback);
  26140. } else {
  26141. Animation.prefilters.push(callback);
  26142. }
  26143. }
  26144. });
  26145. jQuery.speed = function (speed, easing, fn) {
  26146. var opt = speed && typeof speed === "object" ? jQuery.extend({}, speed) : {
  26147. complete: fn || !fn && easing || isFunction(speed) && speed,
  26148. duration: speed,
  26149. easing: fn && easing || easing && !isFunction(easing) && easing
  26150. }; // Go to the end state if fx are off
  26151. if (jQuery.fx.off) {
  26152. opt.duration = 0;
  26153. } else {
  26154. if (typeof opt.duration !== "number") {
  26155. if (opt.duration in jQuery.fx.speeds) {
  26156. opt.duration = jQuery.fx.speeds[opt.duration];
  26157. } else {
  26158. opt.duration = jQuery.fx.speeds._default;
  26159. }
  26160. }
  26161. } // Normalize opt.queue - true/undefined/null -> "fx"
  26162. if (opt.queue == null || opt.queue === true) {
  26163. opt.queue = "fx";
  26164. } // Queueing
  26165. opt.old = opt.complete;
  26166. opt.complete = function () {
  26167. if (isFunction(opt.old)) {
  26168. opt.old.call(this);
  26169. }
  26170. if (opt.queue) {
  26171. jQuery.dequeue(this, opt.queue);
  26172. }
  26173. };
  26174. return opt;
  26175. };
  26176. jQuery.fn.extend({
  26177. fadeTo: function (speed, to, easing, callback) {
  26178. // Show any hidden elements after setting opacity to 0
  26179. return this.filter(isHiddenWithinTree).css("opacity", 0).show() // Animate to the value specified
  26180. .end().animate({
  26181. opacity: to
  26182. }, speed, easing, callback);
  26183. },
  26184. animate: function (prop, speed, easing, callback) {
  26185. var empty = jQuery.isEmptyObject(prop),
  26186. optall = jQuery.speed(speed, easing, callback),
  26187. doAnimation = function () {
  26188. // Operate on a copy of prop so per-property easing won't be lost
  26189. var anim = Animation(this, jQuery.extend({}, prop), optall); // Empty animations, or finishing resolves immediately
  26190. if (empty || dataPriv.get(this, "finish")) {
  26191. anim.stop(true);
  26192. }
  26193. };
  26194. doAnimation.finish = doAnimation;
  26195. return empty || optall.queue === false ? this.each(doAnimation) : this.queue(optall.queue, doAnimation);
  26196. },
  26197. stop: function (type, clearQueue, gotoEnd) {
  26198. var stopQueue = function (hooks) {
  26199. var stop = hooks.stop;
  26200. delete hooks.stop;
  26201. stop(gotoEnd);
  26202. };
  26203. if (typeof type !== "string") {
  26204. gotoEnd = clearQueue;
  26205. clearQueue = type;
  26206. type = undefined;
  26207. }
  26208. if (clearQueue && type !== false) {
  26209. this.queue(type || "fx", []);
  26210. }
  26211. return this.each(function () {
  26212. var dequeue = true,
  26213. index = type != null && type + "queueHooks",
  26214. timers = jQuery.timers,
  26215. data = dataPriv.get(this);
  26216. if (index) {
  26217. if (data[index] && data[index].stop) {
  26218. stopQueue(data[index]);
  26219. }
  26220. } else {
  26221. for (index in data) {
  26222. if (data[index] && data[index].stop && rrun.test(index)) {
  26223. stopQueue(data[index]);
  26224. }
  26225. }
  26226. }
  26227. for (index = timers.length; index--;) {
  26228. if (timers[index].elem === this && (type == null || timers[index].queue === type)) {
  26229. timers[index].anim.stop(gotoEnd);
  26230. dequeue = false;
  26231. timers.splice(index, 1);
  26232. }
  26233. } // Start the next in the queue if the last step wasn't forced.
  26234. // Timers currently will call their complete callbacks, which
  26235. // will dequeue but only if they were gotoEnd.
  26236. if (dequeue || !gotoEnd) {
  26237. jQuery.dequeue(this, type);
  26238. }
  26239. });
  26240. },
  26241. finish: function (type) {
  26242. if (type !== false) {
  26243. type = type || "fx";
  26244. }
  26245. return this.each(function () {
  26246. var index,
  26247. data = dataPriv.get(this),
  26248. queue = data[type + "queue"],
  26249. hooks = data[type + "queueHooks"],
  26250. timers = jQuery.timers,
  26251. length = queue ? queue.length : 0; // Enable finishing flag on private data
  26252. data.finish = true; // Empty the queue first
  26253. jQuery.queue(this, type, []);
  26254. if (hooks && hooks.stop) {
  26255. hooks.stop.call(this, true);
  26256. } // Look for any active animations, and finish them
  26257. for (index = timers.length; index--;) {
  26258. if (timers[index].elem === this && timers[index].queue === type) {
  26259. timers[index].anim.stop(true);
  26260. timers.splice(index, 1);
  26261. }
  26262. } // Look for any animations in the old queue and finish them
  26263. for (index = 0; index < length; index++) {
  26264. if (queue[index] && queue[index].finish) {
  26265. queue[index].finish.call(this);
  26266. }
  26267. } // Turn off finishing flag
  26268. delete data.finish;
  26269. });
  26270. }
  26271. });
  26272. jQuery.each(["toggle", "show", "hide"], function (i, name) {
  26273. var cssFn = jQuery.fn[name];
  26274. jQuery.fn[name] = function (speed, easing, callback) {
  26275. return speed == null || typeof speed === "boolean" ? cssFn.apply(this, arguments) : this.animate(genFx(name, true), speed, easing, callback);
  26276. };
  26277. }); // Generate shortcuts for custom animations
  26278. jQuery.each({
  26279. slideDown: genFx("show"),
  26280. slideUp: genFx("hide"),
  26281. slideToggle: genFx("toggle"),
  26282. fadeIn: {
  26283. opacity: "show"
  26284. },
  26285. fadeOut: {
  26286. opacity: "hide"
  26287. },
  26288. fadeToggle: {
  26289. opacity: "toggle"
  26290. }
  26291. }, function (name, props) {
  26292. jQuery.fn[name] = function (speed, easing, callback) {
  26293. return this.animate(props, speed, easing, callback);
  26294. };
  26295. });
  26296. jQuery.timers = [];
  26297. jQuery.fx.tick = function () {
  26298. var timer,
  26299. i = 0,
  26300. timers = jQuery.timers;
  26301. fxNow = Date.now();
  26302. for (; i < timers.length; i++) {
  26303. timer = timers[i]; // Run the timer and safely remove it when done (allowing for external removal)
  26304. if (!timer() && timers[i] === timer) {
  26305. timers.splice(i--, 1);
  26306. }
  26307. }
  26308. if (!timers.length) {
  26309. jQuery.fx.stop();
  26310. }
  26311. fxNow = undefined;
  26312. };
  26313. jQuery.fx.timer = function (timer) {
  26314. jQuery.timers.push(timer);
  26315. jQuery.fx.start();
  26316. };
  26317. jQuery.fx.interval = 13;
  26318. jQuery.fx.start = function () {
  26319. if (inProgress) {
  26320. return;
  26321. }
  26322. inProgress = true;
  26323. schedule();
  26324. };
  26325. jQuery.fx.stop = function () {
  26326. inProgress = null;
  26327. };
  26328. jQuery.fx.speeds = {
  26329. slow: 600,
  26330. fast: 200,
  26331. // Default speed
  26332. _default: 400
  26333. }; // Based off of the plugin by Clint Helfers, with permission.
  26334. // https://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/
  26335. jQuery.fn.delay = function (time, type) {
  26336. time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
  26337. type = type || "fx";
  26338. return this.queue(type, function (next, hooks) {
  26339. var timeout = window.setTimeout(next, time);
  26340. hooks.stop = function () {
  26341. window.clearTimeout(timeout);
  26342. };
  26343. });
  26344. };
  26345. (function () {
  26346. var input = document.createElement("input"),
  26347. select = document.createElement("select"),
  26348. opt = select.appendChild(document.createElement("option"));
  26349. input.type = "checkbox"; // Support: Android <=4.3 only
  26350. // Default value for a checkbox should be "on"
  26351. support.checkOn = input.value !== ""; // Support: IE <=11 only
  26352. // Must access selectedIndex to make default options select
  26353. support.optSelected = opt.selected; // Support: IE <=11 only
  26354. // An input loses its value after becoming a radio
  26355. input = document.createElement("input");
  26356. input.value = "t";
  26357. input.type = "radio";
  26358. support.radioValue = input.value === "t";
  26359. })();
  26360. var boolHook,
  26361. attrHandle = jQuery.expr.attrHandle;
  26362. jQuery.fn.extend({
  26363. attr: function (name, value) {
  26364. return access(this, jQuery.attr, name, value, arguments.length > 1);
  26365. },
  26366. removeAttr: function (name) {
  26367. return this.each(function () {
  26368. jQuery.removeAttr(this, name);
  26369. });
  26370. }
  26371. });
  26372. jQuery.extend({
  26373. attr: function (elem, name, value) {
  26374. var ret,
  26375. hooks,
  26376. nType = elem.nodeType; // Don't get/set attributes on text, comment and attribute nodes
  26377. if (nType === 3 || nType === 8 || nType === 2) {
  26378. return;
  26379. } // Fallback to prop when attributes are not supported
  26380. if (typeof elem.getAttribute === "undefined") {
  26381. return jQuery.prop(elem, name, value);
  26382. } // Attribute hooks are determined by the lowercase version
  26383. // Grab necessary hook if one is defined
  26384. if (nType !== 1 || !jQuery.isXMLDoc(elem)) {
  26385. hooks = jQuery.attrHooks[name.toLowerCase()] || (jQuery.expr.match.bool.test(name) ? boolHook : undefined);
  26386. }
  26387. if (value !== undefined) {
  26388. if (value === null) {
  26389. jQuery.removeAttr(elem, name);
  26390. return;
  26391. }
  26392. if (hooks && "set" in hooks && (ret = hooks.set(elem, value, name)) !== undefined) {
  26393. return ret;
  26394. }
  26395. elem.setAttribute(name, value + "");
  26396. return value;
  26397. }
  26398. if (hooks && "get" in hooks && (ret = hooks.get(elem, name)) !== null) {
  26399. return ret;
  26400. }
  26401. ret = jQuery.find.attr(elem, name); // Non-existent attributes return null, we normalize to undefined
  26402. return ret == null ? undefined : ret;
  26403. },
  26404. attrHooks: {
  26405. type: {
  26406. set: function (elem, value) {
  26407. if (!support.radioValue && value === "radio" && nodeName(elem, "input")) {
  26408. var val = elem.value;
  26409. elem.setAttribute("type", value);
  26410. if (val) {
  26411. elem.value = val;
  26412. }
  26413. return value;
  26414. }
  26415. }
  26416. }
  26417. },
  26418. removeAttr: function (elem, value) {
  26419. var name,
  26420. i = 0,
  26421. // Attribute names can contain non-HTML whitespace characters
  26422. // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
  26423. attrNames = value && value.match(rnothtmlwhite);
  26424. if (attrNames && elem.nodeType === 1) {
  26425. while (name = attrNames[i++]) {
  26426. elem.removeAttribute(name);
  26427. }
  26428. }
  26429. }
  26430. }); // Hooks for boolean attributes
  26431. boolHook = {
  26432. set: function (elem, value, name) {
  26433. if (value === false) {
  26434. // Remove boolean attributes when set to false
  26435. jQuery.removeAttr(elem, name);
  26436. } else {
  26437. elem.setAttribute(name, name);
  26438. }
  26439. return name;
  26440. }
  26441. };
  26442. jQuery.each(jQuery.expr.match.bool.source.match(/\w+/g), function (i, name) {
  26443. var getter = attrHandle[name] || jQuery.find.attr;
  26444. attrHandle[name] = function (elem, name, isXML) {
  26445. var ret,
  26446. handle,
  26447. lowercaseName = name.toLowerCase();
  26448. if (!isXML) {
  26449. // Avoid an infinite loop by temporarily removing this function from the getter
  26450. handle = attrHandle[lowercaseName];
  26451. attrHandle[lowercaseName] = ret;
  26452. ret = getter(elem, name, isXML) != null ? lowercaseName : null;
  26453. attrHandle[lowercaseName] = handle;
  26454. }
  26455. return ret;
  26456. };
  26457. });
  26458. var rfocusable = /^(?:input|select|textarea|button)$/i,
  26459. rclickable = /^(?:a|area)$/i;
  26460. jQuery.fn.extend({
  26461. prop: function (name, value) {
  26462. return access(this, jQuery.prop, name, value, arguments.length > 1);
  26463. },
  26464. removeProp: function (name) {
  26465. return this.each(function () {
  26466. delete this[jQuery.propFix[name] || name];
  26467. });
  26468. }
  26469. });
  26470. jQuery.extend({
  26471. prop: function (elem, name, value) {
  26472. var ret,
  26473. hooks,
  26474. nType = elem.nodeType; // Don't get/set properties on text, comment and attribute nodes
  26475. if (nType === 3 || nType === 8 || nType === 2) {
  26476. return;
  26477. }
  26478. if (nType !== 1 || !jQuery.isXMLDoc(elem)) {
  26479. // Fix name and attach hooks
  26480. name = jQuery.propFix[name] || name;
  26481. hooks = jQuery.propHooks[name];
  26482. }
  26483. if (value !== undefined) {
  26484. if (hooks && "set" in hooks && (ret = hooks.set(elem, value, name)) !== undefined) {
  26485. return ret;
  26486. }
  26487. return elem[name] = value;
  26488. }
  26489. if (hooks && "get" in hooks && (ret = hooks.get(elem, name)) !== null) {
  26490. return ret;
  26491. }
  26492. return elem[name];
  26493. },
  26494. propHooks: {
  26495. tabIndex: {
  26496. get: function (elem) {
  26497. // Support: IE <=9 - 11 only
  26498. // elem.tabIndex doesn't always return the
  26499. // correct value when it hasn't been explicitly set
  26500. // https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
  26501. // Use proper attribute retrieval(#12072)
  26502. var tabindex = jQuery.find.attr(elem, "tabindex");
  26503. if (tabindex) {
  26504. return parseInt(tabindex, 10);
  26505. }
  26506. if (rfocusable.test(elem.nodeName) || rclickable.test(elem.nodeName) && elem.href) {
  26507. return 0;
  26508. }
  26509. return -1;
  26510. }
  26511. }
  26512. },
  26513. propFix: {
  26514. "for": "htmlFor",
  26515. "class": "className"
  26516. }
  26517. }); // Support: IE <=11 only
  26518. // Accessing the selectedIndex property
  26519. // forces the browser to respect setting selected
  26520. // on the option
  26521. // The getter ensures a default option is selected
  26522. // when in an optgroup
  26523. // eslint rule "no-unused-expressions" is disabled for this code
  26524. // since it considers such accessions noop
  26525. if (!support.optSelected) {
  26526. jQuery.propHooks.selected = {
  26527. get: function (elem) {
  26528. /* eslint no-unused-expressions: "off" */
  26529. var parent = elem.parentNode;
  26530. if (parent && parent.parentNode) {
  26531. parent.parentNode.selectedIndex;
  26532. }
  26533. return null;
  26534. },
  26535. set: function (elem) {
  26536. /* eslint no-unused-expressions: "off" */
  26537. var parent = elem.parentNode;
  26538. if (parent) {
  26539. parent.selectedIndex;
  26540. if (parent.parentNode) {
  26541. parent.parentNode.selectedIndex;
  26542. }
  26543. }
  26544. }
  26545. };
  26546. }
  26547. jQuery.each(["tabIndex", "readOnly", "maxLength", "cellSpacing", "cellPadding", "rowSpan", "colSpan", "useMap", "frameBorder", "contentEditable"], function () {
  26548. jQuery.propFix[this.toLowerCase()] = this;
  26549. }); // Strip and collapse whitespace according to HTML spec
  26550. // https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace
  26551. function stripAndCollapse(value) {
  26552. var tokens = value.match(rnothtmlwhite) || [];
  26553. return tokens.join(" ");
  26554. }
  26555. function getClass(elem) {
  26556. return elem.getAttribute && elem.getAttribute("class") || "";
  26557. }
  26558. function classesToArray(value) {
  26559. if (Array.isArray(value)) {
  26560. return value;
  26561. }
  26562. if (typeof value === "string") {
  26563. return value.match(rnothtmlwhite) || [];
  26564. }
  26565. return [];
  26566. }
  26567. jQuery.fn.extend({
  26568. addClass: function (value) {
  26569. var classes,
  26570. elem,
  26571. cur,
  26572. curValue,
  26573. clazz,
  26574. j,
  26575. finalValue,
  26576. i = 0;
  26577. if (isFunction(value)) {
  26578. return this.each(function (j) {
  26579. jQuery(this).addClass(value.call(this, j, getClass(this)));
  26580. });
  26581. }
  26582. classes = classesToArray(value);
  26583. if (classes.length) {
  26584. while (elem = this[i++]) {
  26585. curValue = getClass(elem);
  26586. cur = elem.nodeType === 1 && " " + stripAndCollapse(curValue) + " ";
  26587. if (cur) {
  26588. j = 0;
  26589. while (clazz = classes[j++]) {
  26590. if (cur.indexOf(" " + clazz + " ") < 0) {
  26591. cur += clazz + " ";
  26592. }
  26593. } // Only assign if different to avoid unneeded rendering.
  26594. finalValue = stripAndCollapse(cur);
  26595. if (curValue !== finalValue) {
  26596. elem.setAttribute("class", finalValue);
  26597. }
  26598. }
  26599. }
  26600. }
  26601. return this;
  26602. },
  26603. removeClass: function (value) {
  26604. var classes,
  26605. elem,
  26606. cur,
  26607. curValue,
  26608. clazz,
  26609. j,
  26610. finalValue,
  26611. i = 0;
  26612. if (isFunction(value)) {
  26613. return this.each(function (j) {
  26614. jQuery(this).removeClass(value.call(this, j, getClass(this)));
  26615. });
  26616. }
  26617. if (!arguments.length) {
  26618. return this.attr("class", "");
  26619. }
  26620. classes = classesToArray(value);
  26621. if (classes.length) {
  26622. while (elem = this[i++]) {
  26623. curValue = getClass(elem); // This expression is here for better compressibility (see addClass)
  26624. cur = elem.nodeType === 1 && " " + stripAndCollapse(curValue) + " ";
  26625. if (cur) {
  26626. j = 0;
  26627. while (clazz = classes[j++]) {
  26628. // Remove *all* instances
  26629. while (cur.indexOf(" " + clazz + " ") > -1) {
  26630. cur = cur.replace(" " + clazz + " ", " ");
  26631. }
  26632. } // Only assign if different to avoid unneeded rendering.
  26633. finalValue = stripAndCollapse(cur);
  26634. if (curValue !== finalValue) {
  26635. elem.setAttribute("class", finalValue);
  26636. }
  26637. }
  26638. }
  26639. }
  26640. return this;
  26641. },
  26642. toggleClass: function (value, stateVal) {
  26643. var type = typeof value,
  26644. isValidValue = type === "string" || Array.isArray(value);
  26645. if (typeof stateVal === "boolean" && isValidValue) {
  26646. return stateVal ? this.addClass(value) : this.removeClass(value);
  26647. }
  26648. if (isFunction(value)) {
  26649. return this.each(function (i) {
  26650. jQuery(this).toggleClass(value.call(this, i, getClass(this), stateVal), stateVal);
  26651. });
  26652. }
  26653. return this.each(function () {
  26654. var className, i, self, classNames;
  26655. if (isValidValue) {
  26656. // Toggle individual class names
  26657. i = 0;
  26658. self = jQuery(this);
  26659. classNames = classesToArray(value);
  26660. while (className = classNames[i++]) {
  26661. // Check each className given, space separated list
  26662. if (self.hasClass(className)) {
  26663. self.removeClass(className);
  26664. } else {
  26665. self.addClass(className);
  26666. }
  26667. } // Toggle whole class name
  26668. } else if (value === undefined || type === "boolean") {
  26669. className = getClass(this);
  26670. if (className) {
  26671. // Store className if set
  26672. dataPriv.set(this, "__className__", className);
  26673. } // If the element has a class name or if we're passed `false`,
  26674. // then remove the whole classname (if there was one, the above saved it).
  26675. // Otherwise bring back whatever was previously saved (if anything),
  26676. // falling back to the empty string if nothing was stored.
  26677. if (this.setAttribute) {
  26678. this.setAttribute("class", className || value === false ? "" : dataPriv.get(this, "__className__") || "");
  26679. }
  26680. }
  26681. });
  26682. },
  26683. hasClass: function (selector) {
  26684. var className,
  26685. elem,
  26686. i = 0;
  26687. className = " " + selector + " ";
  26688. while (elem = this[i++]) {
  26689. if (elem.nodeType === 1 && (" " + stripAndCollapse(getClass(elem)) + " ").indexOf(className) > -1) {
  26690. return true;
  26691. }
  26692. }
  26693. return false;
  26694. }
  26695. });
  26696. var rreturn = /\r/g;
  26697. jQuery.fn.extend({
  26698. val: function (value) {
  26699. var hooks,
  26700. ret,
  26701. valueIsFunction,
  26702. elem = this[0];
  26703. if (!arguments.length) {
  26704. if (elem) {
  26705. hooks = jQuery.valHooks[elem.type] || jQuery.valHooks[elem.nodeName.toLowerCase()];
  26706. if (hooks && "get" in hooks && (ret = hooks.get(elem, "value")) !== undefined) {
  26707. return ret;
  26708. }
  26709. ret = elem.value; // Handle most common string cases
  26710. if (typeof ret === "string") {
  26711. return ret.replace(rreturn, "");
  26712. } // Handle cases where value is null/undef or number
  26713. return ret == null ? "" : ret;
  26714. }
  26715. return;
  26716. }
  26717. valueIsFunction = isFunction(value);
  26718. return this.each(function (i) {
  26719. var val;
  26720. if (this.nodeType !== 1) {
  26721. return;
  26722. }
  26723. if (valueIsFunction) {
  26724. val = value.call(this, i, jQuery(this).val());
  26725. } else {
  26726. val = value;
  26727. } // Treat null/undefined as ""; convert numbers to string
  26728. if (val == null) {
  26729. val = "";
  26730. } else if (typeof val === "number") {
  26731. val += "";
  26732. } else if (Array.isArray(val)) {
  26733. val = jQuery.map(val, function (value) {
  26734. return value == null ? "" : value + "";
  26735. });
  26736. }
  26737. hooks = jQuery.valHooks[this.type] || jQuery.valHooks[this.nodeName.toLowerCase()]; // If set returns undefined, fall back to normal setting
  26738. if (!hooks || !("set" in hooks) || hooks.set(this, val, "value") === undefined) {
  26739. this.value = val;
  26740. }
  26741. });
  26742. }
  26743. });
  26744. jQuery.extend({
  26745. valHooks: {
  26746. option: {
  26747. get: function (elem) {
  26748. var val = jQuery.find.attr(elem, "value");
  26749. return val != null ? val : // Support: IE <=10 - 11 only
  26750. // option.text throws exceptions (#14686, #14858)
  26751. // Strip and collapse whitespace
  26752. // https://html.spec.whatwg.org/#strip-and-collapse-whitespace
  26753. stripAndCollapse(jQuery.text(elem));
  26754. }
  26755. },
  26756. select: {
  26757. get: function (elem) {
  26758. var value,
  26759. option,
  26760. i,
  26761. options = elem.options,
  26762. index = elem.selectedIndex,
  26763. one = elem.type === "select-one",
  26764. values = one ? null : [],
  26765. max = one ? index + 1 : options.length;
  26766. if (index < 0) {
  26767. i = max;
  26768. } else {
  26769. i = one ? index : 0;
  26770. } // Loop through all the selected options
  26771. for (; i < max; i++) {
  26772. option = options[i]; // Support: IE <=9 only
  26773. // IE8-9 doesn't update selected after form reset (#2551)
  26774. if ((option.selected || i === index) && // Don't return options that are disabled or in a disabled optgroup
  26775. !option.disabled && (!option.parentNode.disabled || !nodeName(option.parentNode, "optgroup"))) {
  26776. // Get the specific value for the option
  26777. value = jQuery(option).val(); // We don't need an array for one selects
  26778. if (one) {
  26779. return value;
  26780. } // Multi-Selects return an array
  26781. values.push(value);
  26782. }
  26783. }
  26784. return values;
  26785. },
  26786. set: function (elem, value) {
  26787. var optionSet,
  26788. option,
  26789. options = elem.options,
  26790. values = jQuery.makeArray(value),
  26791. i = options.length;
  26792. while (i--) {
  26793. option = options[i];
  26794. /* eslint-disable no-cond-assign */
  26795. if (option.selected = jQuery.inArray(jQuery.valHooks.option.get(option), values) > -1) {
  26796. optionSet = true;
  26797. }
  26798. /* eslint-enable no-cond-assign */
  26799. } // Force browsers to behave consistently when non-matching value is set
  26800. if (!optionSet) {
  26801. elem.selectedIndex = -1;
  26802. }
  26803. return values;
  26804. }
  26805. }
  26806. }
  26807. }); // Radios and checkboxes getter/setter
  26808. jQuery.each(["radio", "checkbox"], function () {
  26809. jQuery.valHooks[this] = {
  26810. set: function (elem, value) {
  26811. if (Array.isArray(value)) {
  26812. return elem.checked = jQuery.inArray(jQuery(elem).val(), value) > -1;
  26813. }
  26814. }
  26815. };
  26816. if (!support.checkOn) {
  26817. jQuery.valHooks[this].get = function (elem) {
  26818. return elem.getAttribute("value") === null ? "on" : elem.value;
  26819. };
  26820. }
  26821. }); // Return jQuery for attributes-only inclusion
  26822. support.focusin = "onfocusin" in window;
  26823. var rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
  26824. stopPropagationCallback = function (e) {
  26825. e.stopPropagation();
  26826. };
  26827. jQuery.extend(jQuery.event, {
  26828. trigger: function (event, data, elem, onlyHandlers) {
  26829. var i,
  26830. cur,
  26831. tmp,
  26832. bubbleType,
  26833. ontype,
  26834. handle,
  26835. special,
  26836. lastElement,
  26837. eventPath = [elem || document],
  26838. type = hasOwn.call(event, "type") ? event.type : event,
  26839. namespaces = hasOwn.call(event, "namespace") ? event.namespace.split(".") : [];
  26840. cur = lastElement = tmp = elem = elem || document; // Don't do events on text and comment nodes
  26841. if (elem.nodeType === 3 || elem.nodeType === 8) {
  26842. return;
  26843. } // focus/blur morphs to focusin/out; ensure we're not firing them right now
  26844. if (rfocusMorph.test(type + jQuery.event.triggered)) {
  26845. return;
  26846. }
  26847. if (type.indexOf(".") > -1) {
  26848. // Namespaced trigger; create a regexp to match event type in handle()
  26849. namespaces = type.split(".");
  26850. type = namespaces.shift();
  26851. namespaces.sort();
  26852. }
  26853. ontype = type.indexOf(":") < 0 && "on" + type; // Caller can pass in a jQuery.Event object, Object, or just an event type string
  26854. event = event[jQuery.expando] ? event : new jQuery.Event(type, typeof event === "object" && event); // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
  26855. event.isTrigger = onlyHandlers ? 2 : 3;
  26856. event.namespace = namespaces.join(".");
  26857. event.rnamespace = event.namespace ? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)") : null; // Clean up the event in case it is being reused
  26858. event.result = undefined;
  26859. if (!event.target) {
  26860. event.target = elem;
  26861. } // Clone any incoming data and prepend the event, creating the handler arg list
  26862. data = data == null ? [event] : jQuery.makeArray(data, [event]); // Allow special events to draw outside the lines
  26863. special = jQuery.event.special[type] || {};
  26864. if (!onlyHandlers && special.trigger && special.trigger.apply(elem, data) === false) {
  26865. return;
  26866. } // Determine event propagation path in advance, per W3C events spec (#9951)
  26867. // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
  26868. if (!onlyHandlers && !special.noBubble && !isWindow(elem)) {
  26869. bubbleType = special.delegateType || type;
  26870. if (!rfocusMorph.test(bubbleType + type)) {
  26871. cur = cur.parentNode;
  26872. }
  26873. for (; cur; cur = cur.parentNode) {
  26874. eventPath.push(cur);
  26875. tmp = cur;
  26876. } // Only add window if we got to document (e.g., not plain obj or detached DOM)
  26877. if (tmp === (elem.ownerDocument || document)) {
  26878. eventPath.push(tmp.defaultView || tmp.parentWindow || window);
  26879. }
  26880. } // Fire handlers on the event path
  26881. i = 0;
  26882. while ((cur = eventPath[i++]) && !event.isPropagationStopped()) {
  26883. lastElement = cur;
  26884. event.type = i > 1 ? bubbleType : special.bindType || type; // jQuery handler
  26885. handle = (dataPriv.get(cur, "events") || {})[event.type] && dataPriv.get(cur, "handle");
  26886. if (handle) {
  26887. handle.apply(cur, data);
  26888. } // Native handler
  26889. handle = ontype && cur[ontype];
  26890. if (handle && handle.apply && acceptData(cur)) {
  26891. event.result = handle.apply(cur, data);
  26892. if (event.result === false) {
  26893. event.preventDefault();
  26894. }
  26895. }
  26896. }
  26897. event.type = type; // If nobody prevented the default action, do it now
  26898. if (!onlyHandlers && !event.isDefaultPrevented()) {
  26899. if ((!special._default || special._default.apply(eventPath.pop(), data) === false) && acceptData(elem)) {
  26900. // Call a native DOM method on the target with the same name as the event.
  26901. // Don't do default actions on window, that's where global variables be (#6170)
  26902. if (ontype && isFunction(elem[type]) && !isWindow(elem)) {
  26903. // Don't re-trigger an onFOO event when we call its FOO() method
  26904. tmp = elem[ontype];
  26905. if (tmp) {
  26906. elem[ontype] = null;
  26907. } // Prevent re-triggering of the same event, since we already bubbled it above
  26908. jQuery.event.triggered = type;
  26909. if (event.isPropagationStopped()) {
  26910. lastElement.addEventListener(type, stopPropagationCallback);
  26911. }
  26912. elem[type]();
  26913. if (event.isPropagationStopped()) {
  26914. lastElement.removeEventListener(type, stopPropagationCallback);
  26915. }
  26916. jQuery.event.triggered = undefined;
  26917. if (tmp) {
  26918. elem[ontype] = tmp;
  26919. }
  26920. }
  26921. }
  26922. }
  26923. return event.result;
  26924. },
  26925. // Piggyback on a donor event to simulate a different one
  26926. // Used only for `focus(in | out)` events
  26927. simulate: function (type, elem, event) {
  26928. var e = jQuery.extend(new jQuery.Event(), event, {
  26929. type: type,
  26930. isSimulated: true
  26931. });
  26932. jQuery.event.trigger(e, null, elem);
  26933. }
  26934. });
  26935. jQuery.fn.extend({
  26936. trigger: function (type, data) {
  26937. return this.each(function () {
  26938. jQuery.event.trigger(type, data, this);
  26939. });
  26940. },
  26941. triggerHandler: function (type, data) {
  26942. var elem = this[0];
  26943. if (elem) {
  26944. return jQuery.event.trigger(type, data, elem, true);
  26945. }
  26946. }
  26947. }); // Support: Firefox <=44
  26948. // Firefox doesn't have focus(in | out) events
  26949. // Related ticket - https://bugzilla.mozilla.org/show_bug.cgi?id=687787
  26950. //
  26951. // Support: Chrome <=48 - 49, Safari <=9.0 - 9.1
  26952. // focus(in | out) events fire after focus & blur events,
  26953. // which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order
  26954. // Related ticket - https://bugs.chromium.org/p/chromium/issues/detail?id=449857
  26955. if (!support.focusin) {
  26956. jQuery.each({
  26957. focus: "focusin",
  26958. blur: "focusout"
  26959. }, function (orig, fix) {
  26960. // Attach a single capturing handler on the document while someone wants focusin/focusout
  26961. var handler = function (event) {
  26962. jQuery.event.simulate(fix, event.target, jQuery.event.fix(event));
  26963. };
  26964. jQuery.event.special[fix] = {
  26965. setup: function () {
  26966. var doc = this.ownerDocument || this,
  26967. attaches = dataPriv.access(doc, fix);
  26968. if (!attaches) {
  26969. doc.addEventListener(orig, handler, true);
  26970. }
  26971. dataPriv.access(doc, fix, (attaches || 0) + 1);
  26972. },
  26973. teardown: function () {
  26974. var doc = this.ownerDocument || this,
  26975. attaches = dataPriv.access(doc, fix) - 1;
  26976. if (!attaches) {
  26977. doc.removeEventListener(orig, handler, true);
  26978. dataPriv.remove(doc, fix);
  26979. } else {
  26980. dataPriv.access(doc, fix, attaches);
  26981. }
  26982. }
  26983. };
  26984. });
  26985. }
  26986. var location = window.location;
  26987. var nonce = Date.now();
  26988. var rquery = /\?/; // Cross-browser xml parsing
  26989. jQuery.parseXML = function (data) {
  26990. var xml;
  26991. if (!data || typeof data !== "string") {
  26992. return null;
  26993. } // Support: IE 9 - 11 only
  26994. // IE throws on parseFromString with invalid input.
  26995. try {
  26996. xml = new window.DOMParser().parseFromString(data, "text/xml");
  26997. } catch (e) {
  26998. xml = undefined;
  26999. }
  27000. if (!xml || xml.getElementsByTagName("parsererror").length) {
  27001. jQuery.error("Invalid XML: " + data);
  27002. }
  27003. return xml;
  27004. };
  27005. var rbracket = /\[\]$/,
  27006. rCRLF = /\r?\n/g,
  27007. rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
  27008. rsubmittable = /^(?:input|select|textarea|keygen)/i;
  27009. function buildParams(prefix, obj, traditional, add) {
  27010. var name;
  27011. if (Array.isArray(obj)) {
  27012. // Serialize array item.
  27013. jQuery.each(obj, function (i, v) {
  27014. if (traditional || rbracket.test(prefix)) {
  27015. // Treat each array item as a scalar.
  27016. add(prefix, v);
  27017. } else {
  27018. // Item is non-scalar (array or object), encode its numeric index.
  27019. buildParams(prefix + "[" + (typeof v === "object" && v != null ? i : "") + "]", v, traditional, add);
  27020. }
  27021. });
  27022. } else if (!traditional && toType(obj) === "object") {
  27023. // Serialize object item.
  27024. for (name in obj) {
  27025. buildParams(prefix + "[" + name + "]", obj[name], traditional, add);
  27026. }
  27027. } else {
  27028. // Serialize scalar item.
  27029. add(prefix, obj);
  27030. }
  27031. } // Serialize an array of form elements or a set of
  27032. // key/values into a query string
  27033. jQuery.param = function (a, traditional) {
  27034. var prefix,
  27035. s = [],
  27036. add = function (key, valueOrFunction) {
  27037. // If value is a function, invoke it and use its return value
  27038. var value = isFunction(valueOrFunction) ? valueOrFunction() : valueOrFunction;
  27039. s[s.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value == null ? "" : value);
  27040. }; // If an array was passed in, assume that it is an array of form elements.
  27041. if (Array.isArray(a) || a.jquery && !jQuery.isPlainObject(a)) {
  27042. // Serialize the form elements
  27043. jQuery.each(a, function () {
  27044. add(this.name, this.value);
  27045. });
  27046. } else {
  27047. // If traditional, encode the "old" way (the way 1.3.2 or older
  27048. // did it), otherwise encode params recursively.
  27049. for (prefix in a) {
  27050. buildParams(prefix, a[prefix], traditional, add);
  27051. }
  27052. } // Return the resulting serialization
  27053. return s.join("&");
  27054. };
  27055. jQuery.fn.extend({
  27056. serialize: function () {
  27057. return jQuery.param(this.serializeArray());
  27058. },
  27059. serializeArray: function () {
  27060. return this.map(function () {
  27061. // Can add propHook for "elements" to filter or add form elements
  27062. var elements = jQuery.prop(this, "elements");
  27063. return elements ? jQuery.makeArray(elements) : this;
  27064. }).filter(function () {
  27065. var type = this.type; // Use .is( ":disabled" ) so that fieldset[disabled] works
  27066. return this.name && !jQuery(this).is(":disabled") && rsubmittable.test(this.nodeName) && !rsubmitterTypes.test(type) && (this.checked || !rcheckableType.test(type));
  27067. }).map(function (i, elem) {
  27068. var val = jQuery(this).val();
  27069. if (val == null) {
  27070. return null;
  27071. }
  27072. if (Array.isArray(val)) {
  27073. return jQuery.map(val, function (val) {
  27074. return {
  27075. name: elem.name,
  27076. value: val.replace(rCRLF, "\r\n")
  27077. };
  27078. });
  27079. }
  27080. return {
  27081. name: elem.name,
  27082. value: val.replace(rCRLF, "\r\n")
  27083. };
  27084. }).get();
  27085. }
  27086. });
  27087. var r20 = /%20/g,
  27088. rhash = /#.*$/,
  27089. rantiCache = /([?&])_=[^&]*/,
  27090. rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
  27091. // #7653, #8125, #8152: local protocol detection
  27092. rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
  27093. rnoContent = /^(?:GET|HEAD)$/,
  27094. rprotocol = /^\/\//,
  27095. /* Prefilters
  27096. * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
  27097. * 2) These are called:
  27098. * - BEFORE asking for a transport
  27099. * - AFTER param serialization (s.data is a string if s.processData is true)
  27100. * 3) key is the dataType
  27101. * 4) the catchall symbol "*" can be used
  27102. * 5) execution will start with transport dataType and THEN continue down to "*" if needed
  27103. */
  27104. prefilters = {},
  27105. /* Transports bindings
  27106. * 1) key is the dataType
  27107. * 2) the catchall symbol "*" can be used
  27108. * 3) selection will start with transport dataType and THEN go to "*" if needed
  27109. */
  27110. transports = {},
  27111. // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
  27112. allTypes = "*/".concat("*"),
  27113. // Anchor tag for parsing the document origin
  27114. originAnchor = document.createElement("a");
  27115. originAnchor.href = location.href; // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
  27116. function addToPrefiltersOrTransports(structure) {
  27117. // dataTypeExpression is optional and defaults to "*"
  27118. return function (dataTypeExpression, func) {
  27119. if (typeof dataTypeExpression !== "string") {
  27120. func = dataTypeExpression;
  27121. dataTypeExpression = "*";
  27122. }
  27123. var dataType,
  27124. i = 0,
  27125. dataTypes = dataTypeExpression.toLowerCase().match(rnothtmlwhite) || [];
  27126. if (isFunction(func)) {
  27127. // For each dataType in the dataTypeExpression
  27128. while (dataType = dataTypes[i++]) {
  27129. // Prepend if requested
  27130. if (dataType[0] === "+") {
  27131. dataType = dataType.slice(1) || "*";
  27132. (structure[dataType] = structure[dataType] || []).unshift(func); // Otherwise append
  27133. } else {
  27134. (structure[dataType] = structure[dataType] || []).push(func);
  27135. }
  27136. }
  27137. }
  27138. };
  27139. } // Base inspection function for prefilters and transports
  27140. function inspectPrefiltersOrTransports(structure, options, originalOptions, jqXHR) {
  27141. var inspected = {},
  27142. seekingTransport = structure === transports;
  27143. function inspect(dataType) {
  27144. var selected;
  27145. inspected[dataType] = true;
  27146. jQuery.each(structure[dataType] || [], function (_, prefilterOrFactory) {
  27147. var dataTypeOrTransport = prefilterOrFactory(options, originalOptions, jqXHR);
  27148. if (typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[dataTypeOrTransport]) {
  27149. options.dataTypes.unshift(dataTypeOrTransport);
  27150. inspect(dataTypeOrTransport);
  27151. return false;
  27152. } else if (seekingTransport) {
  27153. return !(selected = dataTypeOrTransport);
  27154. }
  27155. });
  27156. return selected;
  27157. }
  27158. return inspect(options.dataTypes[0]) || !inspected["*"] && inspect("*");
  27159. } // A special extend for ajax options
  27160. // that takes "flat" options (not to be deep extended)
  27161. // Fixes #9887
  27162. function ajaxExtend(target, src) {
  27163. var key,
  27164. deep,
  27165. flatOptions = jQuery.ajaxSettings.flatOptions || {};
  27166. for (key in src) {
  27167. if (src[key] !== undefined) {
  27168. (flatOptions[key] ? target : deep || (deep = {}))[key] = src[key];
  27169. }
  27170. }
  27171. if (deep) {
  27172. jQuery.extend(true, target, deep);
  27173. }
  27174. return target;
  27175. }
  27176. /* Handles responses to an ajax request:
  27177. * - finds the right dataType (mediates between content-type and expected dataType)
  27178. * - returns the corresponding response
  27179. */
  27180. function ajaxHandleResponses(s, jqXHR, responses) {
  27181. var ct,
  27182. type,
  27183. finalDataType,
  27184. firstDataType,
  27185. contents = s.contents,
  27186. dataTypes = s.dataTypes; // Remove auto dataType and get content-type in the process
  27187. while (dataTypes[0] === "*") {
  27188. dataTypes.shift();
  27189. if (ct === undefined) {
  27190. ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
  27191. }
  27192. } // Check if we're dealing with a known content-type
  27193. if (ct) {
  27194. for (type in contents) {
  27195. if (contents[type] && contents[type].test(ct)) {
  27196. dataTypes.unshift(type);
  27197. break;
  27198. }
  27199. }
  27200. } // Check to see if we have a response for the expected dataType
  27201. if (dataTypes[0] in responses) {
  27202. finalDataType = dataTypes[0];
  27203. } else {
  27204. // Try convertible dataTypes
  27205. for (type in responses) {
  27206. if (!dataTypes[0] || s.converters[type + " " + dataTypes[0]]) {
  27207. finalDataType = type;
  27208. break;
  27209. }
  27210. if (!firstDataType) {
  27211. firstDataType = type;
  27212. }
  27213. } // Or just use first one
  27214. finalDataType = finalDataType || firstDataType;
  27215. } // If we found a dataType
  27216. // We add the dataType to the list if needed
  27217. // and return the corresponding response
  27218. if (finalDataType) {
  27219. if (finalDataType !== dataTypes[0]) {
  27220. dataTypes.unshift(finalDataType);
  27221. }
  27222. return responses[finalDataType];
  27223. }
  27224. }
  27225. /* Chain conversions given the request and the original response
  27226. * Also sets the responseXXX fields on the jqXHR instance
  27227. */
  27228. function ajaxConvert(s, response, jqXHR, isSuccess) {
  27229. var conv2,
  27230. current,
  27231. conv,
  27232. tmp,
  27233. prev,
  27234. converters = {},
  27235. // Work with a copy of dataTypes in case we need to modify it for conversion
  27236. dataTypes = s.dataTypes.slice(); // Create converters map with lowercased keys
  27237. if (dataTypes[1]) {
  27238. for (conv in s.converters) {
  27239. converters[conv.toLowerCase()] = s.converters[conv];
  27240. }
  27241. }
  27242. current = dataTypes.shift(); // Convert to each sequential dataType
  27243. while (current) {
  27244. if (s.responseFields[current]) {
  27245. jqXHR[s.responseFields[current]] = response;
  27246. } // Apply the dataFilter if provided
  27247. if (!prev && isSuccess && s.dataFilter) {
  27248. response = s.dataFilter(response, s.dataType);
  27249. }
  27250. prev = current;
  27251. current = dataTypes.shift();
  27252. if (current) {
  27253. // There's only work to do if current dataType is non-auto
  27254. if (current === "*") {
  27255. current = prev; // Convert response if prev dataType is non-auto and differs from current
  27256. } else if (prev !== "*" && prev !== current) {
  27257. // Seek a direct converter
  27258. conv = converters[prev + " " + current] || converters["* " + current]; // If none found, seek a pair
  27259. if (!conv) {
  27260. for (conv2 in converters) {
  27261. // If conv2 outputs current
  27262. tmp = conv2.split(" ");
  27263. if (tmp[1] === current) {
  27264. // If prev can be converted to accepted input
  27265. conv = converters[prev + " " + tmp[0]] || converters["* " + tmp[0]];
  27266. if (conv) {
  27267. // Condense equivalence converters
  27268. if (conv === true) {
  27269. conv = converters[conv2]; // Otherwise, insert the intermediate dataType
  27270. } else if (converters[conv2] !== true) {
  27271. current = tmp[0];
  27272. dataTypes.unshift(tmp[1]);
  27273. }
  27274. break;
  27275. }
  27276. }
  27277. }
  27278. } // Apply converter (if not an equivalence)
  27279. if (conv !== true) {
  27280. // Unless errors are allowed to bubble, catch and return them
  27281. if (conv && s.throws) {
  27282. response = conv(response);
  27283. } else {
  27284. try {
  27285. response = conv(response);
  27286. } catch (e) {
  27287. return {
  27288. state: "parsererror",
  27289. error: conv ? e : "No conversion from " + prev + " to " + current
  27290. };
  27291. }
  27292. }
  27293. }
  27294. }
  27295. }
  27296. }
  27297. return {
  27298. state: "success",
  27299. data: response
  27300. };
  27301. }
  27302. jQuery.extend({
  27303. // Counter for holding the number of active queries
  27304. active: 0,
  27305. // Last-Modified header cache for next request
  27306. lastModified: {},
  27307. etag: {},
  27308. ajaxSettings: {
  27309. url: location.href,
  27310. type: "GET",
  27311. isLocal: rlocalProtocol.test(location.protocol),
  27312. global: true,
  27313. processData: true,
  27314. async: true,
  27315. contentType: "application/x-www-form-urlencoded; charset=UTF-8",
  27316. /*
  27317. timeout: 0,
  27318. data: null,
  27319. dataType: null,
  27320. username: null,
  27321. password: null,
  27322. cache: null,
  27323. throws: false,
  27324. traditional: false,
  27325. headers: {},
  27326. */
  27327. accepts: {
  27328. "*": allTypes,
  27329. text: "text/plain",
  27330. html: "text/html",
  27331. xml: "application/xml, text/xml",
  27332. json: "application/json, text/javascript"
  27333. },
  27334. contents: {
  27335. xml: /\bxml\b/,
  27336. html: /\bhtml/,
  27337. json: /\bjson\b/
  27338. },
  27339. responseFields: {
  27340. xml: "responseXML",
  27341. text: "responseText",
  27342. json: "responseJSON"
  27343. },
  27344. // Data converters
  27345. // Keys separate source (or catchall "*") and destination types with a single space
  27346. converters: {
  27347. // Convert anything to text
  27348. "* text": String,
  27349. // Text to html (true = no transformation)
  27350. "text html": true,
  27351. // Evaluate text as a json expression
  27352. "text json": JSON.parse,
  27353. // Parse text as xml
  27354. "text xml": jQuery.parseXML
  27355. },
  27356. // For options that shouldn't be deep extended:
  27357. // you can add your own custom options here if
  27358. // and when you create one that shouldn't be
  27359. // deep extended (see ajaxExtend)
  27360. flatOptions: {
  27361. url: true,
  27362. context: true
  27363. }
  27364. },
  27365. // Creates a full fledged settings object into target
  27366. // with both ajaxSettings and settings fields.
  27367. // If target is omitted, writes into ajaxSettings.
  27368. ajaxSetup: function (target, settings) {
  27369. return settings ? // Building a settings object
  27370. ajaxExtend(ajaxExtend(target, jQuery.ajaxSettings), settings) : // Extending ajaxSettings
  27371. ajaxExtend(jQuery.ajaxSettings, target);
  27372. },
  27373. ajaxPrefilter: addToPrefiltersOrTransports(prefilters),
  27374. ajaxTransport: addToPrefiltersOrTransports(transports),
  27375. // Main method
  27376. ajax: function (url, options) {
  27377. // If url is an object, simulate pre-1.5 signature
  27378. if (typeof url === "object") {
  27379. options = url;
  27380. url = undefined;
  27381. } // Force options to be an object
  27382. options = options || {};
  27383. var transport,
  27384. // URL without anti-cache param
  27385. cacheURL,
  27386. // Response headers
  27387. responseHeadersString,
  27388. responseHeaders,
  27389. // timeout handle
  27390. timeoutTimer,
  27391. // Url cleanup var
  27392. urlAnchor,
  27393. // Request state (becomes false upon send and true upon completion)
  27394. completed,
  27395. // To know if global events are to be dispatched
  27396. fireGlobals,
  27397. // Loop variable
  27398. i,
  27399. // uncached part of the url
  27400. uncached,
  27401. // Create the final options object
  27402. s = jQuery.ajaxSetup({}, options),
  27403. // Callbacks context
  27404. callbackContext = s.context || s,
  27405. // Context for global events is callbackContext if it is a DOM node or jQuery collection
  27406. globalEventContext = s.context && (callbackContext.nodeType || callbackContext.jquery) ? jQuery(callbackContext) : jQuery.event,
  27407. // Deferreds
  27408. deferred = jQuery.Deferred(),
  27409. completeDeferred = jQuery.Callbacks("once memory"),
  27410. // Status-dependent callbacks
  27411. statusCode = s.statusCode || {},
  27412. // Headers (they are sent all at once)
  27413. requestHeaders = {},
  27414. requestHeadersNames = {},
  27415. // Default abort message
  27416. strAbort = "canceled",
  27417. // Fake xhr
  27418. jqXHR = {
  27419. readyState: 0,
  27420. // Builds headers hashtable if needed
  27421. getResponseHeader: function (key) {
  27422. var match;
  27423. if (completed) {
  27424. if (!responseHeaders) {
  27425. responseHeaders = {};
  27426. while (match = rheaders.exec(responseHeadersString)) {
  27427. responseHeaders[match[1].toLowerCase()] = match[2];
  27428. }
  27429. }
  27430. match = responseHeaders[key.toLowerCase()];
  27431. }
  27432. return match == null ? null : match;
  27433. },
  27434. // Raw string
  27435. getAllResponseHeaders: function () {
  27436. return completed ? responseHeadersString : null;
  27437. },
  27438. // Caches the header
  27439. setRequestHeader: function (name, value) {
  27440. if (completed == null) {
  27441. name = requestHeadersNames[name.toLowerCase()] = requestHeadersNames[name.toLowerCase()] || name;
  27442. requestHeaders[name] = value;
  27443. }
  27444. return this;
  27445. },
  27446. // Overrides response content-type header
  27447. overrideMimeType: function (type) {
  27448. if (completed == null) {
  27449. s.mimeType = type;
  27450. }
  27451. return this;
  27452. },
  27453. // Status-dependent callbacks
  27454. statusCode: function (map) {
  27455. var code;
  27456. if (map) {
  27457. if (completed) {
  27458. // Execute the appropriate callbacks
  27459. jqXHR.always(map[jqXHR.status]);
  27460. } else {
  27461. // Lazy-add the new callbacks in a way that preserves old ones
  27462. for (code in map) {
  27463. statusCode[code] = [statusCode[code], map[code]];
  27464. }
  27465. }
  27466. }
  27467. return this;
  27468. },
  27469. // Cancel the request
  27470. abort: function (statusText) {
  27471. var finalText = statusText || strAbort;
  27472. if (transport) {
  27473. transport.abort(finalText);
  27474. }
  27475. done(0, finalText);
  27476. return this;
  27477. }
  27478. }; // Attach deferreds
  27479. deferred.promise(jqXHR); // Add protocol if not provided (prefilters might expect it)
  27480. // Handle falsy url in the settings object (#10093: consistency with old signature)
  27481. // We also use the url parameter if available
  27482. s.url = ((url || s.url || location.href) + "").replace(rprotocol, location.protocol + "//"); // Alias method option to type as per ticket #12004
  27483. s.type = options.method || options.type || s.method || s.type; // Extract dataTypes list
  27484. s.dataTypes = (s.dataType || "*").toLowerCase().match(rnothtmlwhite) || [""]; // A cross-domain request is in order when the origin doesn't match the current origin.
  27485. if (s.crossDomain == null) {
  27486. urlAnchor = document.createElement("a"); // Support: IE <=8 - 11, Edge 12 - 15
  27487. // IE throws exception on accessing the href property if url is malformed,
  27488. // e.g. http://example.com:80x/
  27489. try {
  27490. urlAnchor.href = s.url; // Support: IE <=8 - 11 only
  27491. // Anchor's host property isn't correctly set when s.url is relative
  27492. urlAnchor.href = urlAnchor.href;
  27493. s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !== urlAnchor.protocol + "//" + urlAnchor.host;
  27494. } catch (e) {
  27495. // If there is an error parsing the URL, assume it is crossDomain,
  27496. // it can be rejected by the transport if it is invalid
  27497. s.crossDomain = true;
  27498. }
  27499. } // Convert data if not already a string
  27500. if (s.data && s.processData && typeof s.data !== "string") {
  27501. s.data = jQuery.param(s.data, s.traditional);
  27502. } // Apply prefilters
  27503. inspectPrefiltersOrTransports(prefilters, s, options, jqXHR); // If request was aborted inside a prefilter, stop there
  27504. if (completed) {
  27505. return jqXHR;
  27506. } // We can fire global events as of now if asked to
  27507. // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
  27508. fireGlobals = jQuery.event && s.global; // Watch for a new set of requests
  27509. if (fireGlobals && jQuery.active++ === 0) {
  27510. jQuery.event.trigger("ajaxStart");
  27511. } // Uppercase the type
  27512. s.type = s.type.toUpperCase(); // Determine if request has content
  27513. s.hasContent = !rnoContent.test(s.type); // Save the URL in case we're toying with the If-Modified-Since
  27514. // and/or If-None-Match header later on
  27515. // Remove hash to simplify url manipulation
  27516. cacheURL = s.url.replace(rhash, ""); // More options handling for requests with no content
  27517. if (!s.hasContent) {
  27518. // Remember the hash so we can put it back
  27519. uncached = s.url.slice(cacheURL.length); // If data is available and should be processed, append data to url
  27520. if (s.data && (s.processData || typeof s.data === "string")) {
  27521. cacheURL += (rquery.test(cacheURL) ? "&" : "?") + s.data; // #9682: remove data so that it's not used in an eventual retry
  27522. delete s.data;
  27523. } // Add or update anti-cache param if needed
  27524. if (s.cache === false) {
  27525. cacheURL = cacheURL.replace(rantiCache, "$1");
  27526. uncached = (rquery.test(cacheURL) ? "&" : "?") + "_=" + nonce++ + uncached;
  27527. } // Put hash and anti-cache on the URL that will be requested (gh-1732)
  27528. s.url = cacheURL + uncached; // Change '%20' to '+' if this is encoded form body content (gh-2658)
  27529. } else if (s.data && s.processData && (s.contentType || "").indexOf("application/x-www-form-urlencoded") === 0) {
  27530. s.data = s.data.replace(r20, "+");
  27531. } // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  27532. if (s.ifModified) {
  27533. if (jQuery.lastModified[cacheURL]) {
  27534. jqXHR.setRequestHeader("If-Modified-Since", jQuery.lastModified[cacheURL]);
  27535. }
  27536. if (jQuery.etag[cacheURL]) {
  27537. jqXHR.setRequestHeader("If-None-Match", jQuery.etag[cacheURL]);
  27538. }
  27539. } // Set the correct header, if data is being sent
  27540. if (s.data && s.hasContent && s.contentType !== false || options.contentType) {
  27541. jqXHR.setRequestHeader("Content-Type", s.contentType);
  27542. } // Set the Accepts header for the server, depending on the dataType
  27543. jqXHR.setRequestHeader("Accept", s.dataTypes[0] && s.accepts[s.dataTypes[0]] ? s.accepts[s.dataTypes[0]] + (s.dataTypes[0] !== "*" ? ", " + allTypes + "; q=0.01" : "") : s.accepts["*"]); // Check for headers option
  27544. for (i in s.headers) {
  27545. jqXHR.setRequestHeader(i, s.headers[i]);
  27546. } // Allow custom headers/mimetypes and early abort
  27547. if (s.beforeSend && (s.beforeSend.call(callbackContext, jqXHR, s) === false || completed)) {
  27548. // Abort if not done already and return
  27549. return jqXHR.abort();
  27550. } // Aborting is no longer a cancellation
  27551. strAbort = "abort"; // Install callbacks on deferreds
  27552. completeDeferred.add(s.complete);
  27553. jqXHR.done(s.success);
  27554. jqXHR.fail(s.error); // Get transport
  27555. transport = inspectPrefiltersOrTransports(transports, s, options, jqXHR); // If no transport, we auto-abort
  27556. if (!transport) {
  27557. done(-1, "No Transport");
  27558. } else {
  27559. jqXHR.readyState = 1; // Send global event
  27560. if (fireGlobals) {
  27561. globalEventContext.trigger("ajaxSend", [jqXHR, s]);
  27562. } // If request was aborted inside ajaxSend, stop there
  27563. if (completed) {
  27564. return jqXHR;
  27565. } // Timeout
  27566. if (s.async && s.timeout > 0) {
  27567. timeoutTimer = window.setTimeout(function () {
  27568. jqXHR.abort("timeout");
  27569. }, s.timeout);
  27570. }
  27571. try {
  27572. completed = false;
  27573. transport.send(requestHeaders, done);
  27574. } catch (e) {
  27575. // Rethrow post-completion exceptions
  27576. if (completed) {
  27577. throw e;
  27578. } // Propagate others as results
  27579. done(-1, e);
  27580. }
  27581. } // Callback for when everything is done
  27582. function done(status, nativeStatusText, responses, headers) {
  27583. var isSuccess,
  27584. success,
  27585. error,
  27586. response,
  27587. modified,
  27588. statusText = nativeStatusText; // Ignore repeat invocations
  27589. if (completed) {
  27590. return;
  27591. }
  27592. completed = true; // Clear timeout if it exists
  27593. if (timeoutTimer) {
  27594. window.clearTimeout(timeoutTimer);
  27595. } // Dereference transport for early garbage collection
  27596. // (no matter how long the jqXHR object will be used)
  27597. transport = undefined; // Cache response headers
  27598. responseHeadersString = headers || ""; // Set readyState
  27599. jqXHR.readyState = status > 0 ? 4 : 0; // Determine if successful
  27600. isSuccess = status >= 200 && status < 300 || status === 304; // Get response data
  27601. if (responses) {
  27602. response = ajaxHandleResponses(s, jqXHR, responses);
  27603. } // Convert no matter what (that way responseXXX fields are always set)
  27604. response = ajaxConvert(s, response, jqXHR, isSuccess); // If successful, handle type chaining
  27605. if (isSuccess) {
  27606. // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  27607. if (s.ifModified) {
  27608. modified = jqXHR.getResponseHeader("Last-Modified");
  27609. if (modified) {
  27610. jQuery.lastModified[cacheURL] = modified;
  27611. }
  27612. modified = jqXHR.getResponseHeader("etag");
  27613. if (modified) {
  27614. jQuery.etag[cacheURL] = modified;
  27615. }
  27616. } // if no content
  27617. if (status === 204 || s.type === "HEAD") {
  27618. statusText = "nocontent"; // if not modified
  27619. } else if (status === 304) {
  27620. statusText = "notmodified"; // If we have data, let's convert it
  27621. } else {
  27622. statusText = response.state;
  27623. success = response.data;
  27624. error = response.error;
  27625. isSuccess = !error;
  27626. }
  27627. } else {
  27628. // Extract error from statusText and normalize for non-aborts
  27629. error = statusText;
  27630. if (status || !statusText) {
  27631. statusText = "error";
  27632. if (status < 0) {
  27633. status = 0;
  27634. }
  27635. }
  27636. } // Set data for the fake xhr object
  27637. jqXHR.status = status;
  27638. jqXHR.statusText = (nativeStatusText || statusText) + ""; // Success/Error
  27639. if (isSuccess) {
  27640. deferred.resolveWith(callbackContext, [success, statusText, jqXHR]);
  27641. } else {
  27642. deferred.rejectWith(callbackContext, [jqXHR, statusText, error]);
  27643. } // Status-dependent callbacks
  27644. jqXHR.statusCode(statusCode);
  27645. statusCode = undefined;
  27646. if (fireGlobals) {
  27647. globalEventContext.trigger(isSuccess ? "ajaxSuccess" : "ajaxError", [jqXHR, s, isSuccess ? success : error]);
  27648. } // Complete
  27649. completeDeferred.fireWith(callbackContext, [jqXHR, statusText]);
  27650. if (fireGlobals) {
  27651. globalEventContext.trigger("ajaxComplete", [jqXHR, s]); // Handle the global AJAX counter
  27652. if (! --jQuery.active) {
  27653. jQuery.event.trigger("ajaxStop");
  27654. }
  27655. }
  27656. }
  27657. return jqXHR;
  27658. },
  27659. getJSON: function (url, data, callback) {
  27660. return jQuery.get(url, data, callback, "json");
  27661. },
  27662. getScript: function (url, callback) {
  27663. return jQuery.get(url, undefined, callback, "script");
  27664. }
  27665. });
  27666. jQuery.each(["get", "post"], function (i, method) {
  27667. jQuery[method] = function (url, data, callback, type) {
  27668. // Shift arguments if data argument was omitted
  27669. if (isFunction(data)) {
  27670. type = type || callback;
  27671. callback = data;
  27672. data = undefined;
  27673. } // The url can be an options object (which then must have .url)
  27674. return jQuery.ajax(jQuery.extend({
  27675. url: url,
  27676. type: method,
  27677. dataType: type,
  27678. data: data,
  27679. success: callback
  27680. }, jQuery.isPlainObject(url) && url));
  27681. };
  27682. });
  27683. jQuery._evalUrl = function (url) {
  27684. return jQuery.ajax({
  27685. url: url,
  27686. // Make this explicit, since user can override this through ajaxSetup (#11264)
  27687. type: "GET",
  27688. dataType: "script",
  27689. cache: true,
  27690. async: false,
  27691. global: false,
  27692. "throws": true
  27693. });
  27694. };
  27695. jQuery.fn.extend({
  27696. wrapAll: function (html) {
  27697. var wrap;
  27698. if (this[0]) {
  27699. if (isFunction(html)) {
  27700. html = html.call(this[0]);
  27701. } // The elements to wrap the target around
  27702. wrap = jQuery(html, this[0].ownerDocument).eq(0).clone(true);
  27703. if (this[0].parentNode) {
  27704. wrap.insertBefore(this[0]);
  27705. }
  27706. wrap.map(function () {
  27707. var elem = this;
  27708. while (elem.firstElementChild) {
  27709. elem = elem.firstElementChild;
  27710. }
  27711. return elem;
  27712. }).append(this);
  27713. }
  27714. return this;
  27715. },
  27716. wrapInner: function (html) {
  27717. if (isFunction(html)) {
  27718. return this.each(function (i) {
  27719. jQuery(this).wrapInner(html.call(this, i));
  27720. });
  27721. }
  27722. return this.each(function () {
  27723. var self = jQuery(this),
  27724. contents = self.contents();
  27725. if (contents.length) {
  27726. contents.wrapAll(html);
  27727. } else {
  27728. self.append(html);
  27729. }
  27730. });
  27731. },
  27732. wrap: function (html) {
  27733. var htmlIsFunction = isFunction(html);
  27734. return this.each(function (i) {
  27735. jQuery(this).wrapAll(htmlIsFunction ? html.call(this, i) : html);
  27736. });
  27737. },
  27738. unwrap: function (selector) {
  27739. this.parent(selector).not("body").each(function () {
  27740. jQuery(this).replaceWith(this.childNodes);
  27741. });
  27742. return this;
  27743. }
  27744. });
  27745. jQuery.expr.pseudos.hidden = function (elem) {
  27746. return !jQuery.expr.pseudos.visible(elem);
  27747. };
  27748. jQuery.expr.pseudos.visible = function (elem) {
  27749. return !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length);
  27750. };
  27751. jQuery.ajaxSettings.xhr = function () {
  27752. try {
  27753. return new window.XMLHttpRequest();
  27754. } catch (e) {}
  27755. };
  27756. var xhrSuccessStatus = {
  27757. // File protocol always yields status code 0, assume 200
  27758. 0: 200,
  27759. // Support: IE <=9 only
  27760. // #1450: sometimes IE returns 1223 when it should be 204
  27761. 1223: 204
  27762. },
  27763. xhrSupported = jQuery.ajaxSettings.xhr();
  27764. support.cors = !!xhrSupported && "withCredentials" in xhrSupported;
  27765. support.ajax = xhrSupported = !!xhrSupported;
  27766. jQuery.ajaxTransport(function (options) {
  27767. var callback, errorCallback; // Cross domain only allowed if supported through XMLHttpRequest
  27768. if (support.cors || xhrSupported && !options.crossDomain) {
  27769. return {
  27770. send: function (headers, complete) {
  27771. var i,
  27772. xhr = options.xhr();
  27773. xhr.open(options.type, options.url, options.async, options.username, options.password); // Apply custom fields if provided
  27774. if (options.xhrFields) {
  27775. for (i in options.xhrFields) {
  27776. xhr[i] = options.xhrFields[i];
  27777. }
  27778. } // Override mime type if needed
  27779. if (options.mimeType && xhr.overrideMimeType) {
  27780. xhr.overrideMimeType(options.mimeType);
  27781. } // X-Requested-With header
  27782. // For cross-domain requests, seeing as conditions for a preflight are
  27783. // akin to a jigsaw puzzle, we simply never set it to be sure.
  27784. // (it can always be set on a per-request basis or even using ajaxSetup)
  27785. // For same-domain requests, won't change header if already provided.
  27786. if (!options.crossDomain && !headers["X-Requested-With"]) {
  27787. headers["X-Requested-With"] = "XMLHttpRequest";
  27788. } // Set headers
  27789. for (i in headers) {
  27790. xhr.setRequestHeader(i, headers[i]);
  27791. } // Callback
  27792. callback = function (type) {
  27793. return function () {
  27794. if (callback) {
  27795. callback = errorCallback = xhr.onload = xhr.onerror = xhr.onabort = xhr.ontimeout = xhr.onreadystatechange = null;
  27796. if (type === "abort") {
  27797. xhr.abort();
  27798. } else if (type === "error") {
  27799. // Support: IE <=9 only
  27800. // On a manual native abort, IE9 throws
  27801. // errors on any property access that is not readyState
  27802. if (typeof xhr.status !== "number") {
  27803. complete(0, "error");
  27804. } else {
  27805. complete( // File: protocol always yields status 0; see #8605, #14207
  27806. xhr.status, xhr.statusText);
  27807. }
  27808. } else {
  27809. complete(xhrSuccessStatus[xhr.status] || xhr.status, xhr.statusText, // Support: IE <=9 only
  27810. // IE9 has no XHR2 but throws on binary (trac-11426)
  27811. // For XHR2 non-text, let the caller handle it (gh-2498)
  27812. (xhr.responseType || "text") !== "text" || typeof xhr.responseText !== "string" ? {
  27813. binary: xhr.response
  27814. } : {
  27815. text: xhr.responseText
  27816. }, xhr.getAllResponseHeaders());
  27817. }
  27818. }
  27819. };
  27820. }; // Listen to events
  27821. xhr.onload = callback();
  27822. errorCallback = xhr.onerror = xhr.ontimeout = callback("error"); // Support: IE 9 only
  27823. // Use onreadystatechange to replace onabort
  27824. // to handle uncaught aborts
  27825. if (xhr.onabort !== undefined) {
  27826. xhr.onabort = errorCallback;
  27827. } else {
  27828. xhr.onreadystatechange = function () {
  27829. // Check readyState before timeout as it changes
  27830. if (xhr.readyState === 4) {
  27831. // Allow onerror to be called first,
  27832. // but that will not handle a native abort
  27833. // Also, save errorCallback to a variable
  27834. // as xhr.onerror cannot be accessed
  27835. window.setTimeout(function () {
  27836. if (callback) {
  27837. errorCallback();
  27838. }
  27839. });
  27840. }
  27841. };
  27842. } // Create the abort callback
  27843. callback = callback("abort");
  27844. try {
  27845. // Do send the request (this may raise an exception)
  27846. xhr.send(options.hasContent && options.data || null);
  27847. } catch (e) {
  27848. // #14683: Only rethrow if this hasn't been notified as an error yet
  27849. if (callback) {
  27850. throw e;
  27851. }
  27852. }
  27853. },
  27854. abort: function () {
  27855. if (callback) {
  27856. callback();
  27857. }
  27858. }
  27859. };
  27860. }
  27861. }); // Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432)
  27862. jQuery.ajaxPrefilter(function (s) {
  27863. if (s.crossDomain) {
  27864. s.contents.script = false;
  27865. }
  27866. }); // Install script dataType
  27867. jQuery.ajaxSetup({
  27868. accepts: {
  27869. script: "text/javascript, application/javascript, " + "application/ecmascript, application/x-ecmascript"
  27870. },
  27871. contents: {
  27872. script: /\b(?:java|ecma)script\b/
  27873. },
  27874. converters: {
  27875. "text script": function (text) {
  27876. jQuery.globalEval(text);
  27877. return text;
  27878. }
  27879. }
  27880. }); // Handle cache's special case and crossDomain
  27881. jQuery.ajaxPrefilter("script", function (s) {
  27882. if (s.cache === undefined) {
  27883. s.cache = false;
  27884. }
  27885. if (s.crossDomain) {
  27886. s.type = "GET";
  27887. }
  27888. }); // Bind script tag hack transport
  27889. jQuery.ajaxTransport("script", function (s) {
  27890. // This transport only deals with cross domain requests
  27891. if (s.crossDomain) {
  27892. var script, callback;
  27893. return {
  27894. send: function (_, complete) {
  27895. script = jQuery("<script>").prop({
  27896. charset: s.scriptCharset,
  27897. src: s.url
  27898. }).on("load error", callback = function (evt) {
  27899. script.remove();
  27900. callback = null;
  27901. if (evt) {
  27902. complete(evt.type === "error" ? 404 : 200, evt.type);
  27903. }
  27904. }); // Use native DOM manipulation to avoid our domManip AJAX trickery
  27905. document.head.appendChild(script[0]);
  27906. },
  27907. abort: function () {
  27908. if (callback) {
  27909. callback();
  27910. }
  27911. }
  27912. };
  27913. }
  27914. });
  27915. var oldCallbacks = [],
  27916. rjsonp = /(=)\?(?=&|$)|\?\?/; // Default jsonp settings
  27917. jQuery.ajaxSetup({
  27918. jsonp: "callback",
  27919. jsonpCallback: function () {
  27920. var callback = oldCallbacks.pop() || jQuery.expando + "_" + nonce++;
  27921. this[callback] = true;
  27922. return callback;
  27923. }
  27924. }); // Detect, normalize options and install callbacks for jsonp requests
  27925. jQuery.ajaxPrefilter("json jsonp", function (s, originalSettings, jqXHR) {
  27926. var callbackName,
  27927. overwritten,
  27928. responseContainer,
  27929. jsonProp = s.jsonp !== false && (rjsonp.test(s.url) ? "url" : typeof s.data === "string" && (s.contentType || "").indexOf("application/x-www-form-urlencoded") === 0 && rjsonp.test(s.data) && "data"); // Handle iff the expected data type is "jsonp" or we have a parameter to set
  27930. if (jsonProp || s.dataTypes[0] === "jsonp") {
  27931. // Get callback name, remembering preexisting value associated with it
  27932. callbackName = s.jsonpCallback = isFunction(s.jsonpCallback) ? s.jsonpCallback() : s.jsonpCallback; // Insert callback into url or form data
  27933. if (jsonProp) {
  27934. s[jsonProp] = s[jsonProp].replace(rjsonp, "$1" + callbackName);
  27935. } else if (s.jsonp !== false) {
  27936. s.url += (rquery.test(s.url) ? "&" : "?") + s.jsonp + "=" + callbackName;
  27937. } // Use data converter to retrieve json after script execution
  27938. s.converters["script json"] = function () {
  27939. if (!responseContainer) {
  27940. jQuery.error(callbackName + " was not called");
  27941. }
  27942. return responseContainer[0];
  27943. }; // Force json dataType
  27944. s.dataTypes[0] = "json"; // Install callback
  27945. overwritten = window[callbackName];
  27946. window[callbackName] = function () {
  27947. responseContainer = arguments;
  27948. }; // Clean-up function (fires after converters)
  27949. jqXHR.always(function () {
  27950. // If previous value didn't exist - remove it
  27951. if (overwritten === undefined) {
  27952. jQuery(window).removeProp(callbackName); // Otherwise restore preexisting value
  27953. } else {
  27954. window[callbackName] = overwritten;
  27955. } // Save back as free
  27956. if (s[callbackName]) {
  27957. // Make sure that re-using the options doesn't screw things around
  27958. s.jsonpCallback = originalSettings.jsonpCallback; // Save the callback name for future use
  27959. oldCallbacks.push(callbackName);
  27960. } // Call if it was a function and we have a response
  27961. if (responseContainer && isFunction(overwritten)) {
  27962. overwritten(responseContainer[0]);
  27963. }
  27964. responseContainer = overwritten = undefined;
  27965. }); // Delegate to script
  27966. return "script";
  27967. }
  27968. }); // Support: Safari 8 only
  27969. // In Safari 8 documents created via document.implementation.createHTMLDocument
  27970. // collapse sibling forms: the second one becomes a child of the first one.
  27971. // Because of that, this security measure has to be disabled in Safari 8.
  27972. // https://bugs.webkit.org/show_bug.cgi?id=137337
  27973. support.createHTMLDocument = function () {
  27974. var body = document.implementation.createHTMLDocument("").body;
  27975. body.innerHTML = "<form></form><form></form>";
  27976. return body.childNodes.length === 2;
  27977. }(); // Argument "data" should be string of html
  27978. // context (optional): If specified, the fragment will be created in this context,
  27979. // defaults to document
  27980. // keepScripts (optional): If true, will include scripts passed in the html string
  27981. jQuery.parseHTML = function (data, context, keepScripts) {
  27982. if (typeof data !== "string") {
  27983. return [];
  27984. }
  27985. if (typeof context === "boolean") {
  27986. keepScripts = context;
  27987. context = false;
  27988. }
  27989. var base, parsed, scripts;
  27990. if (!context) {
  27991. // Stop scripts or inline event handlers from being executed immediately
  27992. // by using document.implementation
  27993. if (support.createHTMLDocument) {
  27994. context = document.implementation.createHTMLDocument(""); // Set the base href for the created document
  27995. // so any parsed elements with URLs
  27996. // are based on the document's URL (gh-2965)
  27997. base = context.createElement("base");
  27998. base.href = document.location.href;
  27999. context.head.appendChild(base);
  28000. } else {
  28001. context = document;
  28002. }
  28003. }
  28004. parsed = rsingleTag.exec(data);
  28005. scripts = !keepScripts && []; // Single tag
  28006. if (parsed) {
  28007. return [context.createElement(parsed[1])];
  28008. }
  28009. parsed = buildFragment([data], context, scripts);
  28010. if (scripts && scripts.length) {
  28011. jQuery(scripts).remove();
  28012. }
  28013. return jQuery.merge([], parsed.childNodes);
  28014. };
  28015. /**
  28016. * Load a url into a page
  28017. */
  28018. jQuery.fn.load = function (url, params, callback) {
  28019. var selector,
  28020. type,
  28021. response,
  28022. self = this,
  28023. off = url.indexOf(" ");
  28024. if (off > -1) {
  28025. selector = stripAndCollapse(url.slice(off));
  28026. url = url.slice(0, off);
  28027. } // If it's a function
  28028. if (isFunction(params)) {
  28029. // We assume that it's the callback
  28030. callback = params;
  28031. params = undefined; // Otherwise, build a param string
  28032. } else if (params && typeof params === "object") {
  28033. type = "POST";
  28034. } // If we have elements to modify, make the request
  28035. if (self.length > 0) {
  28036. jQuery.ajax({
  28037. url: url,
  28038. // If "type" variable is undefined, then "GET" method will be used.
  28039. // Make value of this field explicit since
  28040. // user can override it through ajaxSetup method
  28041. type: type || "GET",
  28042. dataType: "html",
  28043. data: params
  28044. }).done(function (responseText) {
  28045. // Save response for use in complete callback
  28046. response = arguments;
  28047. self.html(selector ? // If a selector was specified, locate the right elements in a dummy div
  28048. // Exclude scripts to avoid IE 'Permission Denied' errors
  28049. jQuery("<div>").append(jQuery.parseHTML(responseText)).find(selector) : // Otherwise use the full result
  28050. responseText); // If the request succeeds, this function gets "data", "status", "jqXHR"
  28051. // but they are ignored because response was set above.
  28052. // If it fails, this function gets "jqXHR", "status", "error"
  28053. }).always(callback && function (jqXHR, status) {
  28054. self.each(function () {
  28055. callback.apply(this, response || [jqXHR.responseText, status, jqXHR]);
  28056. });
  28057. });
  28058. }
  28059. return this;
  28060. }; // Attach a bunch of functions for handling common AJAX events
  28061. jQuery.each(["ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend"], function (i, type) {
  28062. jQuery.fn[type] = function (fn) {
  28063. return this.on(type, fn);
  28064. };
  28065. });
  28066. jQuery.expr.pseudos.animated = function (elem) {
  28067. return jQuery.grep(jQuery.timers, function (fn) {
  28068. return elem === fn.elem;
  28069. }).length;
  28070. };
  28071. jQuery.offset = {
  28072. setOffset: function (elem, options, i) {
  28073. var curPosition,
  28074. curLeft,
  28075. curCSSTop,
  28076. curTop,
  28077. curOffset,
  28078. curCSSLeft,
  28079. calculatePosition,
  28080. position = jQuery.css(elem, "position"),
  28081. curElem = jQuery(elem),
  28082. props = {}; // Set position first, in-case top/left are set even on static elem
  28083. if (position === "static") {
  28084. elem.style.position = "relative";
  28085. }
  28086. curOffset = curElem.offset();
  28087. curCSSTop = jQuery.css(elem, "top");
  28088. curCSSLeft = jQuery.css(elem, "left");
  28089. calculatePosition = (position === "absolute" || position === "fixed") && (curCSSTop + curCSSLeft).indexOf("auto") > -1; // Need to be able to calculate position if either
  28090. // top or left is auto and position is either absolute or fixed
  28091. if (calculatePosition) {
  28092. curPosition = curElem.position();
  28093. curTop = curPosition.top;
  28094. curLeft = curPosition.left;
  28095. } else {
  28096. curTop = parseFloat(curCSSTop) || 0;
  28097. curLeft = parseFloat(curCSSLeft) || 0;
  28098. }
  28099. if (isFunction(options)) {
  28100. // Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
  28101. options = options.call(elem, i, jQuery.extend({}, curOffset));
  28102. }
  28103. if (options.top != null) {
  28104. props.top = options.top - curOffset.top + curTop;
  28105. }
  28106. if (options.left != null) {
  28107. props.left = options.left - curOffset.left + curLeft;
  28108. }
  28109. if ("using" in options) {
  28110. options.using.call(elem, props);
  28111. } else {
  28112. curElem.css(props);
  28113. }
  28114. }
  28115. };
  28116. jQuery.fn.extend({
  28117. // offset() relates an element's border box to the document origin
  28118. offset: function (options) {
  28119. // Preserve chaining for setter
  28120. if (arguments.length) {
  28121. return options === undefined ? this : this.each(function (i) {
  28122. jQuery.offset.setOffset(this, options, i);
  28123. });
  28124. }
  28125. var rect,
  28126. win,
  28127. elem = this[0];
  28128. if (!elem) {
  28129. return;
  28130. } // Return zeros for disconnected and hidden (display: none) elements (gh-2310)
  28131. // Support: IE <=11 only
  28132. // Running getBoundingClientRect on a
  28133. // disconnected node in IE throws an error
  28134. if (!elem.getClientRects().length) {
  28135. return {
  28136. top: 0,
  28137. left: 0
  28138. };
  28139. } // Get document-relative position by adding viewport scroll to viewport-relative gBCR
  28140. rect = elem.getBoundingClientRect();
  28141. win = elem.ownerDocument.defaultView;
  28142. return {
  28143. top: rect.top + win.pageYOffset,
  28144. left: rect.left + win.pageXOffset
  28145. };
  28146. },
  28147. // position() relates an element's margin box to its offset parent's padding box
  28148. // This corresponds to the behavior of CSS absolute positioning
  28149. position: function () {
  28150. if (!this[0]) {
  28151. return;
  28152. }
  28153. var offsetParent,
  28154. offset,
  28155. doc,
  28156. elem = this[0],
  28157. parentOffset = {
  28158. top: 0,
  28159. left: 0
  28160. }; // position:fixed elements are offset from the viewport, which itself always has zero offset
  28161. if (jQuery.css(elem, "position") === "fixed") {
  28162. // Assume position:fixed implies availability of getBoundingClientRect
  28163. offset = elem.getBoundingClientRect();
  28164. } else {
  28165. offset = this.offset(); // Account for the *real* offset parent, which can be the document or its root element
  28166. // when a statically positioned element is identified
  28167. doc = elem.ownerDocument;
  28168. offsetParent = elem.offsetParent || doc.documentElement;
  28169. while (offsetParent && (offsetParent === doc.body || offsetParent === doc.documentElement) && jQuery.css(offsetParent, "position") === "static") {
  28170. offsetParent = offsetParent.parentNode;
  28171. }
  28172. if (offsetParent && offsetParent !== elem && offsetParent.nodeType === 1) {
  28173. // Incorporate borders into its offset, since they are outside its content origin
  28174. parentOffset = jQuery(offsetParent).offset();
  28175. parentOffset.top += jQuery.css(offsetParent, "borderTopWidth", true);
  28176. parentOffset.left += jQuery.css(offsetParent, "borderLeftWidth", true);
  28177. }
  28178. } // Subtract parent offsets and element margins
  28179. return {
  28180. top: offset.top - parentOffset.top - jQuery.css(elem, "marginTop", true),
  28181. left: offset.left - parentOffset.left - jQuery.css(elem, "marginLeft", true)
  28182. };
  28183. },
  28184. // This method will return documentElement in the following cases:
  28185. // 1) For the element inside the iframe without offsetParent, this method will return
  28186. // documentElement of the parent window
  28187. // 2) For the hidden or detached element
  28188. // 3) For body or html element, i.e. in case of the html node - it will return itself
  28189. //
  28190. // but those exceptions were never presented as a real life use-cases
  28191. // and might be considered as more preferable results.
  28192. //
  28193. // This logic, however, is not guaranteed and can change at any point in the future
  28194. offsetParent: function () {
  28195. return this.map(function () {
  28196. var offsetParent = this.offsetParent;
  28197. while (offsetParent && jQuery.css(offsetParent, "position") === "static") {
  28198. offsetParent = offsetParent.offsetParent;
  28199. }
  28200. return offsetParent || documentElement;
  28201. });
  28202. }
  28203. }); // Create scrollLeft and scrollTop methods
  28204. jQuery.each({
  28205. scrollLeft: "pageXOffset",
  28206. scrollTop: "pageYOffset"
  28207. }, function (method, prop) {
  28208. var top = "pageYOffset" === prop;
  28209. jQuery.fn[method] = function (val) {
  28210. return access(this, function (elem, method, val) {
  28211. // Coalesce documents and windows
  28212. var win;
  28213. if (isWindow(elem)) {
  28214. win = elem;
  28215. } else if (elem.nodeType === 9) {
  28216. win = elem.defaultView;
  28217. }
  28218. if (val === undefined) {
  28219. return win ? win[prop] : elem[method];
  28220. }
  28221. if (win) {
  28222. win.scrollTo(!top ? val : win.pageXOffset, top ? val : win.pageYOffset);
  28223. } else {
  28224. elem[method] = val;
  28225. }
  28226. }, method, val, arguments.length);
  28227. };
  28228. }); // Support: Safari <=7 - 9.1, Chrome <=37 - 49
  28229. // Add the top/left cssHooks using jQuery.fn.position
  28230. // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
  28231. // Blink bug: https://bugs.chromium.org/p/chromium/issues/detail?id=589347
  28232. // getComputedStyle returns percent when specified for top/left/bottom/right;
  28233. // rather than make the css module depend on the offset module, just check for it here
  28234. jQuery.each(["top", "left"], function (i, prop) {
  28235. jQuery.cssHooks[prop] = addGetHookIf(support.pixelPosition, function (elem, computed) {
  28236. if (computed) {
  28237. computed = curCSS(elem, prop); // If curCSS returns percentage, fallback to offset
  28238. return rnumnonpx.test(computed) ? jQuery(elem).position()[prop] + "px" : computed;
  28239. }
  28240. });
  28241. }); // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
  28242. jQuery.each({
  28243. Height: "height",
  28244. Width: "width"
  28245. }, function (name, type) {
  28246. jQuery.each({
  28247. padding: "inner" + name,
  28248. content: type,
  28249. "": "outer" + name
  28250. }, function (defaultExtra, funcName) {
  28251. // Margin is only for outerHeight, outerWidth
  28252. jQuery.fn[funcName] = function (margin, value) {
  28253. var chainable = arguments.length && (defaultExtra || typeof margin !== "boolean"),
  28254. extra = defaultExtra || (margin === true || value === true ? "margin" : "border");
  28255. return access(this, function (elem, type, value) {
  28256. var doc;
  28257. if (isWindow(elem)) {
  28258. // $( window ).outerWidth/Height return w/h including scrollbars (gh-1729)
  28259. return funcName.indexOf("outer") === 0 ? elem["inner" + name] : elem.document.documentElement["client" + name];
  28260. } // Get document width or height
  28261. if (elem.nodeType === 9) {
  28262. doc = elem.documentElement; // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
  28263. // whichever is greatest
  28264. return Math.max(elem.body["scroll" + name], doc["scroll" + name], elem.body["offset" + name], doc["offset" + name], doc["client" + name]);
  28265. }
  28266. return value === undefined ? // Get width or height on the element, requesting but not forcing parseFloat
  28267. jQuery.css(elem, type, extra) : // Set width or height on the element
  28268. jQuery.style(elem, type, value, extra);
  28269. }, type, chainable ? margin : undefined, chainable);
  28270. };
  28271. });
  28272. });
  28273. jQuery.each(("blur focus focusin focusout resize scroll click dblclick " + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + "change select submit keydown keypress keyup contextmenu").split(" "), function (i, name) {
  28274. // Handle event binding
  28275. jQuery.fn[name] = function (data, fn) {
  28276. return arguments.length > 0 ? this.on(name, null, data, fn) : this.trigger(name);
  28277. };
  28278. });
  28279. jQuery.fn.extend({
  28280. hover: function (fnOver, fnOut) {
  28281. return this.mouseenter(fnOver).mouseleave(fnOut || fnOver);
  28282. }
  28283. });
  28284. jQuery.fn.extend({
  28285. bind: function (types, data, fn) {
  28286. return this.on(types, null, data, fn);
  28287. },
  28288. unbind: function (types, fn) {
  28289. return this.off(types, null, fn);
  28290. },
  28291. delegate: function (selector, types, data, fn) {
  28292. return this.on(types, selector, data, fn);
  28293. },
  28294. undelegate: function (selector, types, fn) {
  28295. // ( namespace ) or ( selector, types [, fn] )
  28296. return arguments.length === 1 ? this.off(selector, "**") : this.off(types, selector || "**", fn);
  28297. }
  28298. }); // Bind a function to a context, optionally partially applying any
  28299. // arguments.
  28300. // jQuery.proxy is deprecated to promote standards (specifically Function#bind)
  28301. // However, it is not slated for removal any time soon
  28302. jQuery.proxy = function (fn, context) {
  28303. var tmp, args, proxy;
  28304. if (typeof context === "string") {
  28305. tmp = fn[context];
  28306. context = fn;
  28307. fn = tmp;
  28308. } // Quick check to determine if target is callable, in the spec
  28309. // this throws a TypeError, but we will just return undefined.
  28310. if (!isFunction(fn)) {
  28311. return undefined;
  28312. } // Simulated bind
  28313. args = slice.call(arguments, 2);
  28314. proxy = function () {
  28315. return fn.apply(context || this, args.concat(slice.call(arguments)));
  28316. }; // Set the guid of unique handler to the same of original handler, so it can be removed
  28317. proxy.guid = fn.guid = fn.guid || jQuery.guid++;
  28318. return proxy;
  28319. };
  28320. jQuery.holdReady = function (hold) {
  28321. if (hold) {
  28322. jQuery.readyWait++;
  28323. } else {
  28324. jQuery.ready(true);
  28325. }
  28326. };
  28327. jQuery.isArray = Array.isArray;
  28328. jQuery.parseJSON = JSON.parse;
  28329. jQuery.nodeName = nodeName;
  28330. jQuery.isFunction = isFunction;
  28331. jQuery.isWindow = isWindow;
  28332. jQuery.camelCase = camelCase;
  28333. jQuery.type = toType;
  28334. jQuery.now = Date.now;
  28335. jQuery.isNumeric = function (obj) {
  28336. // As of jQuery 3.0, isNumeric is limited to
  28337. // strings and numbers (primitives or objects)
  28338. // that can be coerced to finite numbers (gh-2662)
  28339. var type = jQuery.type(obj);
  28340. return (type === "number" || type === "string") && // parseFloat NaNs numeric-cast false positives ("")
  28341. // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  28342. // subtraction forces infinities to NaN
  28343. !isNaN(obj - parseFloat(obj));
  28344. }; // Register as a named AMD module, since jQuery can be concatenated with other
  28345. // files that may use define, but not via a proper concatenation script that
  28346. // understands anonymous AMD modules. A named AMD is safest and most robust
  28347. // way to register. Lowercase jquery is used because AMD module names are
  28348. // derived from file names, and jQuery is normally delivered in a lowercase
  28349. // file name. Do this after creating the global so that if an AMD module wants
  28350. // to call noConflict to hide this version of jQuery, it will work.
  28351. // Note that for maximum portability, libraries that are not jQuery should
  28352. // declare themselves as anonymous modules, and avoid setting a global if an
  28353. // AMD loader is present. jQuery is a special case. For more information, see
  28354. // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
  28355. if (true) {
  28356. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  28357. return jQuery;
  28358. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  28359. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  28360. }
  28361. var // Map over jQuery in case of overwrite
  28362. _jQuery = window.jQuery,
  28363. // Map over the $ in case of overwrite
  28364. _$ = window.$;
  28365. jQuery.noConflict = function (deep) {
  28366. if (window.$ === jQuery) {
  28367. window.$ = _$;
  28368. }
  28369. if (deep && window.jQuery === jQuery) {
  28370. window.jQuery = _jQuery;
  28371. }
  28372. return jQuery;
  28373. };
  28374. if (!noGlobal) {
  28375. window.jQuery = window.$ = jQuery;
  28376. }
  28377. return jQuery;
  28378. });
  28379. }),
  28380. /* 23 */
  28381. (function(module, exports, __webpack_require__) {
  28382. //import JsSIP from 'jssip';
  28383. var _JsSIP = __webpack_require__(24);
  28384. var adapter = __webpack_require__(44);
  28385. var _DetectRTC = __webpack_require__(20);
  28386. var _PhoneLogger = __webpack_require__(59);
  28387. var _PhoneNetwork = __webpack_require__(61);
  28388. var PhoneJs = _JsSIP;
  28389. var DetectRTC = _DetectRTC;
  28390. var PhoneLogger = _PhoneLogger;
  28391. var PhoneNetwork = _PhoneNetwork;
  28392. var _default = {
  28393. WS_IP: '13.228.213.46',
  28394. WS_PORT: '10080',
  28395. SIP_IP: '125.91.33.50',
  28396. SIP_PORT: '8052'
  28397. };
  28398. function reloadDetectRTC(callback1, callback2) {
  28399. DetectRTC.load(function () {
  28400. // onDetectRTCLoaded();
  28401. if (callback2 && typeof callback2 == 'function') {
  28402. callback2();
  28403. }
  28404. if (callback1 && typeof callback1 == 'function') {
  28405. callback1();
  28406. }
  28407. });
  28408. }
  28409. PhoneJs._def = _default;
  28410. PhoneJs.DetectRTC = DetectRTC;
  28411. PhoneJs.PhoneLogger = PhoneLogger;
  28412. PhoneJs.PhoneNetwork = PhoneNetwork;
  28413. module.exports = PhoneJs;
  28414. module.exports.loadDetectRTC = function (callback) {
  28415. DetectRTC.load(function () {
  28416. reloadDetectRTC(null, callback);
  28417. try {
  28418. if (DetectRTC.MediaDevices[0] && DetectRTC.MediaDevices[0].isCustomLabel) {
  28419. navigator.mediaDevices.getUserMedia({
  28420. audio: true,
  28421. video: true
  28422. }).then(function (stream) {
  28423. var video;
  28424. try {
  28425. video = document.createElement('video');
  28426. video.muted = true;
  28427. video.volume = 0;
  28428. video.src = URL.createObjectURL(stream);
  28429. video.style.display = 'none';
  28430. video.style.opacity = 0;
  28431. (document.body || document.documentElement).appendChild(vide);
  28432. } catch (e) {}
  28433. reloadDetectRTC(function () {
  28434. // release camera
  28435. stream.getTracks().forEach(function (track) {
  28436. track.stop();
  28437. });
  28438. if (video && video.parentNode) {
  28439. video.parentNode.removeChild(video);
  28440. }
  28441. }, callback);
  28442. }).catch(reloadDetectRTC);
  28443. return;
  28444. }
  28445. } catch (e) {}
  28446. if (callback && typeof callback == 'function') {
  28447. callback();
  28448. }
  28449. });
  28450. }; //module.exports.JsSIP = _JsSIP;
  28451. }),
  28452. /* 24 */
  28453. (function(module, exports, __webpack_require__) {
  28454. "use strict";
  28455. var pkg = __webpack_require__(12);
  28456. var C = __webpack_require__(1);
  28457. var Exceptions = __webpack_require__(6);
  28458. var Utils = __webpack_require__(2);
  28459. var UA = __webpack_require__(25);
  28460. var URI = __webpack_require__(8);
  28461. var NameAddrHeader = __webpack_require__(11);
  28462. var Grammar = __webpack_require__(3);
  28463. var WebSocketInterface = __webpack_require__(43);
  28464. var debug = __webpack_require__(0)('JsSIP');
  28465. debug('version %s', pkg.version);
  28466. /**
  28467. * Expose the JsSIP module.
  28468. */
  28469. module.exports = {
  28470. C: C,
  28471. Exceptions: Exceptions,
  28472. Utils: Utils,
  28473. UA: UA,
  28474. URI: URI,
  28475. NameAddrHeader: NameAddrHeader,
  28476. WebSocketInterface: WebSocketInterface,
  28477. Grammar: Grammar,
  28478. // Expose the debug module.
  28479. debug: __webpack_require__(0),
  28480. get name() {
  28481. return pkg.title;
  28482. },
  28483. get version() {
  28484. return pkg.version;
  28485. }
  28486. };
  28487. }),
  28488. (function(module, exports, __webpack_require__) {
  28489. "use strict";
  28490. function _typeof(obj) {
  28491. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  28492. _typeof = function _typeof(obj) {
  28493. return typeof obj;
  28494. };
  28495. } else {
  28496. _typeof = function _typeof(obj) {
  28497. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  28498. };
  28499. }
  28500. return _typeof(obj);
  28501. }
  28502. function _classCallCheck(instance, Constructor) {
  28503. if (!(instance instanceof Constructor)) {
  28504. throw new TypeError("Cannot call a class as a function");
  28505. }
  28506. }
  28507. function _possibleConstructorReturn(self, call) {
  28508. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  28509. return call;
  28510. }
  28511. return _assertThisInitialized(self);
  28512. }
  28513. function _getPrototypeOf(o) {
  28514. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  28515. return o.__proto__ || Object.getPrototypeOf(o);
  28516. };
  28517. return _getPrototypeOf(o);
  28518. }
  28519. function _defineProperties(target, props) {
  28520. for (var i = 0; i < props.length; i++) {
  28521. var descriptor = props[i];
  28522. descriptor.enumerable = descriptor.enumerable || false;
  28523. descriptor.configurable = true;
  28524. if ("value" in descriptor) descriptor.writable = true;
  28525. Object.defineProperty(target, descriptor.key, descriptor);
  28526. }
  28527. }
  28528. function _createClass(Constructor, protoProps, staticProps) {
  28529. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  28530. if (staticProps) _defineProperties(Constructor, staticProps);
  28531. return Constructor;
  28532. }
  28533. function _inherits(subClass, superClass) {
  28534. if (typeof superClass !== "function" && superClass !== null) {
  28535. throw new TypeError("Super expression must either be null or a function");
  28536. }
  28537. subClass.prototype = Object.create(superClass && superClass.prototype, {
  28538. constructor: {
  28539. value: subClass,
  28540. writable: true,
  28541. configurable: true
  28542. }
  28543. });
  28544. if (superClass) _setPrototypeOf(subClass, superClass);
  28545. }
  28546. function _setPrototypeOf(o, p) {
  28547. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  28548. o.__proto__ = p;
  28549. return o;
  28550. };
  28551. return _setPrototypeOf(o, p);
  28552. }
  28553. function _assertThisInitialized(self) {
  28554. if (self === void 0) {
  28555. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  28556. }
  28557. return self;
  28558. }
  28559. var EventEmitter = __webpack_require__(7).EventEmitter;
  28560. var JsSIP_C = __webpack_require__(1);
  28561. var Registrator = __webpack_require__(26);
  28562. var RTCSession = __webpack_require__(17);
  28563. var Message = __webpack_require__(38);
  28564. var Transactions = __webpack_require__(9);
  28565. var Transport = __webpack_require__(39);
  28566. var Utils = __webpack_require__(2);
  28567. var Exceptions = __webpack_require__(6);
  28568. var URI = __webpack_require__(8);
  28569. var Grammar = __webpack_require__(3);
  28570. var Parser = __webpack_require__(40);
  28571. var SIPMessage = __webpack_require__(5);
  28572. var sanityCheck = __webpack_require__(41);
  28573. var config = __webpack_require__(42);
  28574. var debug = __webpack_require__(0)('JsSIP:UA');
  28575. var debugerror = __webpack_require__(0)('JsSIP:ERROR:UA');
  28576. var PhoneLogger = __webpack_require__(59);
  28577. debugerror.log = console.warn.bind(console);
  28578. var C = {
  28579. // UA status codes.
  28580. STATUS_INIT: 0,
  28581. STATUS_READY: 1,
  28582. STATUS_USER_CLOSED: 2,
  28583. STATUS_NOT_READY: 3,
  28584. // UA error codes.
  28585. CONFIGURATION_ERROR: 1,
  28586. NETWORK_ERROR: 2
  28587. };
  28588. /**
  28589. * The User-Agent class.
  28590. * @class JsSIP.UA
  28591. * @param {Object} configuration Configuration parameters.
  28592. * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid.
  28593. * @throws {TypeError} If no configuration is given.
  28594. */
  28595. module.exports =
  28596. /*#__PURE__*/
  28597. function (_EventEmitter) {
  28598. _inherits(UA, _EventEmitter);
  28599. _createClass(UA, null, [{
  28600. key: "C",
  28601. // Expose C object.
  28602. get: function get() {
  28603. return C;
  28604. }
  28605. }]);
  28606. function setBandwidth(sdp, audio, video) {
  28607. // remove existing bandwidth lines
  28608. sdp = sdp.replace(/b=AS([^\r\n]+\r\n)/g, '');
  28609. sdp = sdp.replace(/b=TIAS([^\r\n]+\r\n)/g, '');
  28610. // audio bandwidth kilobits per second
  28611. if(audio) {
  28612. sdp = sdp.replace(/a=mid:audio\r\n/g, 'a=mid:audio\r\nb=AS:'+audio+'\r\n'+'b=TIAS:'+audio+'\r\n');
  28613. }
  28614. // video bandwidth kilobits per second
  28615. if(video) {
  28616. sdp = sdp.replace(/a=mid:video\r\n/g, 'a=mid:video\r\nb=AS:'+video+'\r\n'+'b=TIAS:'+video+'\r\n');
  28617. }
  28618. return sdp;
  28619. }
  28620. function UA(configuration) {
  28621. var _this;
  28622. _classCallCheck(this, UA);
  28623. debug('new() [configuration:%o]', configuration);
  28624. _this = _possibleConstructorReturn(this, _getPrototypeOf(UA).call(this));
  28625. _this._cache = {
  28626. credentials: {}
  28627. };
  28628. _this._configuration = Object.assign({}, config.settings);
  28629. _this._dynConfiguration = {};
  28630. _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE).
  28631. _this._applicants = {};
  28632. _this._sessions = {};
  28633. _this._transport = null;
  28634. _this._contact = null;
  28635. _this._status = C.STATUS_INIT;
  28636. _this._error = null;
  28637. _this._transactions = {
  28638. nist: {},
  28639. nict: {},
  28640. ist: {},
  28641. ict: {}
  28642. }; // Custom UA empty object for high level use.
  28643. _this._data = {};
  28644. _this._closeTimer = null; // Check configuration argument.
  28645. if (configuration === undefined) {
  28646. throw new TypeError('Not enough arguments');
  28647. } // Load configuration.
  28648. try {
  28649. _this._loadConfig(configuration);
  28650. } catch (e) {
  28651. _this._status = C.STATUS_NOT_READY;
  28652. _this._error = C.CONFIGURATION_ERROR;
  28653. throw e;
  28654. } // Initialize registrator.
  28655. _this._registrator = new Registrator(_assertThisInitialized(_assertThisInitialized(_this)));
  28656. return _this;
  28657. }
  28658. _createClass(UA, [{
  28659. key: "start",
  28660. // =================
  28661. // High Level API
  28662. // =================
  28663. /**
  28664. * Connect to the server if status = STATUS_INIT.
  28665. * Resume UA after being closed.
  28666. */
  28667. value: function start() {
  28668. debug('start()');
  28669. if (this._status === C.STATUS_INIT) {
  28670. this._transport.connect();
  28671. } else if (this._status === C.STATUS_USER_CLOSED) {
  28672. debug('restarting UA'); // Disconnect.
  28673. if (this._closeTimer !== null) {
  28674. clearTimeout(this._closeTimer);
  28675. this._closeTimer = null;
  28676. this._transport.disconnect();
  28677. } // Reconnect.
  28678. this._status = C.STATUS_INIT;
  28679. this._transport.connect();
  28680. } else if (this._status === C.STATUS_READY) {
  28681. debug('UA is in READY status, not restarted');
  28682. } else {
  28683. debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect');
  28684. } // Set dynamic configuration.
  28685. this._dynConfiguration.register = this._configuration.register;
  28686. }
  28687. /**
  28688. * Register.
  28689. */
  28690. }, {
  28691. key: "register",
  28692. value: function register() {
  28693. debug('register()');
  28694. this._dynConfiguration.register = true;
  28695. this._registrator.register();
  28696. }
  28697. /**
  28698. * Unregister.
  28699. */
  28700. }, {
  28701. key: "unregister",
  28702. value: function unregister(options) {
  28703. debug('unregister()');
  28704. this._dynConfiguration.register = false;
  28705. this._registrator.unregister(options);
  28706. }
  28707. /**
  28708. * Get the Registrator instance.
  28709. */
  28710. }, {
  28711. key: "registrator",
  28712. value: function registrator() {
  28713. return this._registrator;
  28714. }
  28715. /**
  28716. * Registration state.
  28717. */
  28718. }, {
  28719. key: "isRegistered",
  28720. value: function isRegistered() {
  28721. return this._registrator.registered;
  28722. }
  28723. /**
  28724. * Connection state.
  28725. */
  28726. }, {
  28727. key: "isConnected",
  28728. value: function isConnected() {
  28729. return this._transport.isConnected();
  28730. }
  28731. /**
  28732. * Make an outgoing call.
  28733. *
  28734. * -param {String} target
  28735. * -param {Object} [options]
  28736. *
  28737. * -throws {TypeError}
  28738. *
  28739. */
  28740. }, {
  28741. key: "call",
  28742. value: function call(target, options) {
  28743. debug('call()');
  28744. var session = new RTCSession(this);
  28745. session.connect(target, options);
  28746. return session;
  28747. }
  28748. /**
  28749. * Send a message.
  28750. *
  28751. * -param {String} target
  28752. * -param {String} body
  28753. * -param {Object} [options]
  28754. *
  28755. * -throws {TypeError}
  28756. *
  28757. */
  28758. },{
  28759. key: 'setVideoBandwidth',
  28760. value: function setVideoBandwidth(val) {
  28761. debug('setVideoBandwidth()');
  28762. this._videoBandwidth = val;
  28763. }
  28764. },{
  28765. key: 'setAudioBandwidth',
  28766. value: function setAudioBandwidth(val) {
  28767. debug('setAudioBandwidth()');
  28768. this._audioBandwidth = val;
  28769. }
  28770. }, {
  28771. key: "sendMessage",
  28772. value: function sendMessage(target, body, options) {
  28773. debug('sendMessage()');
  28774. var message = new Message(this);
  28775. message.send(target, body, options);
  28776. return message;
  28777. }
  28778. /**
  28779. * Terminate ongoing sessions.
  28780. */
  28781. }, {
  28782. key: "terminateSessions",
  28783. value: function terminateSessions(options) {
  28784. debug('terminateSessions()');
  28785. for (var idx in this._sessions) {
  28786. if (!this._sessions[idx].isEnded()) {
  28787. this._sessions[idx].terminate(options);
  28788. }
  28789. }
  28790. }
  28791. /**
  28792. * Gracefully close.
  28793. *
  28794. */
  28795. }, {
  28796. key: "stop",
  28797. value: function stop() {
  28798. var _this2 = this;
  28799. debug('stop()'); // Remove dynamic settings.
  28800. this._dynConfiguration = {};
  28801. if (this._status === C.STATUS_USER_CLOSED) {
  28802. debug('UA already closed');
  28803. return;
  28804. } // Close registrator.
  28805. this._registrator.close(); // If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
  28806. var num_sessions = Object.keys(this._sessions).length; // Run _terminate_ on every Session.
  28807. for (var session in this._sessions) {
  28808. if (Object.prototype.hasOwnProperty.call(this._sessions, session)) {
  28809. debug("closing session ".concat(session));
  28810. try {
  28811. this._sessions[session].terminate();
  28812. } catch (error) {}
  28813. }
  28814. } // Run _close_ on every applicant.
  28815. for (var applicant in this._applicants) {
  28816. if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try {
  28817. this._applicants[applicant].close();
  28818. } catch (error) {}
  28819. }
  28820. this._status = C.STATUS_USER_CLOSED;
  28821. var num_transactions = Object.keys(this._transactions.nict).length + Object.keys(this._transactions.nist).length + Object.keys(this._transactions.ict).length + Object.keys(this._transactions.ist).length;
  28822. if (num_transactions === 0 && num_sessions === 0) {
  28823. this._transport.disconnect();
  28824. } else {
  28825. this._closeTimer = setTimeout(function () {
  28826. _this2._closeTimer = null;
  28827. _this2._transport.disconnect();
  28828. }, 2000);
  28829. }
  28830. }
  28831. /**
  28832. * Normalice a string into a valid SIP request URI
  28833. * -param {String} target
  28834. * -returns {JsSIP.URI|undefined}
  28835. */
  28836. }, {
  28837. key: "normalizeTarget",
  28838. value: function normalizeTarget(target) {
  28839. return Utils.normalizeTarget(target, this._configuration.hostport_params);
  28840. }
  28841. /**
  28842. * Allow retrieving configuration and autogenerated fields in runtime.
  28843. */
  28844. }, {
  28845. key: "get",
  28846. value: function get(parameter) {
  28847. switch (parameter) {
  28848. case 'realm':
  28849. return this._configuration.realm;
  28850. case 'ha1':
  28851. return this._configuration.ha1;
  28852. default:
  28853. debugerror('get() | cannot get "%s" parameter in runtime', parameter);
  28854. return undefined;
  28855. }
  28856. }
  28857. /**
  28858. * Allow configuration changes in runtime.
  28859. * Returns true if the parameter could be set.
  28860. */
  28861. }, {
  28862. key: "set",
  28863. value: function set(parameter, value) {
  28864. switch (parameter) {
  28865. case 'password':
  28866. {
  28867. this._configuration.password = String(value);
  28868. break;
  28869. }
  28870. case 'realm':
  28871. {
  28872. this._configuration.realm = String(value);
  28873. break;
  28874. }
  28875. case 'ha1':
  28876. {
  28877. this._configuration.ha1 = String(value); // Delete the plain SIP password.
  28878. this._configuration.password = null;
  28879. break;
  28880. }
  28881. case 'display_name':
  28882. {
  28883. if (Grammar.parse("\"".concat(value, "\""), 'display_name') === -1) {
  28884. debugerror('set() | wrong "display_name"');
  28885. return false;
  28886. }
  28887. this._configuration.display_name = value;
  28888. break;
  28889. }
  28890. default:
  28891. debugerror('set() | cannot set "%s" parameter in runtime', parameter);
  28892. return false;
  28893. }
  28894. return true;
  28895. } // ==========================
  28896. // Event Handlers.
  28897. // ==========================
  28898. /**
  28899. * new Transaction
  28900. */
  28901. }, {
  28902. key: "newTransaction",
  28903. value: function newTransaction(transaction) {
  28904. this._transactions[transaction.type][transaction.id] = transaction;
  28905. this.emit('newTransaction', {
  28906. transaction: transaction
  28907. });
  28908. }
  28909. /**
  28910. * Transaction destroyed.
  28911. */
  28912. }, {
  28913. key: "destroyTransaction",
  28914. value: function destroyTransaction(transaction) {
  28915. delete this._transactions[transaction.type][transaction.id];
  28916. this.emit('transactionDestroyed', {
  28917. transaction: transaction
  28918. });
  28919. }
  28920. /**
  28921. * new Dialog
  28922. */
  28923. }, {
  28924. key: "newDialog",
  28925. value: function newDialog(dialog) {
  28926. this._dialogs[dialog.id] = dialog;
  28927. }
  28928. /**
  28929. * Dialog destroyed.
  28930. */
  28931. }, {
  28932. key: "destroyDialog",
  28933. value: function destroyDialog(dialog) {
  28934. delete this._dialogs[dialog.id];
  28935. }
  28936. /**
  28937. * new Message
  28938. */
  28939. }, {
  28940. key: "newMessage",
  28941. value: function newMessage(message, data) {
  28942. this._applicants[message] = message;
  28943. this.emit('newMessage', data);
  28944. }
  28945. /**
  28946. * Message destroyed.
  28947. */
  28948. }, {
  28949. key: "destroyMessage",
  28950. value: function destroyMessage(message) {
  28951. delete this._applicants[message];
  28952. }
  28953. /**
  28954. * new RTCSession
  28955. */
  28956. }, {
  28957. key: "newRTCSession",
  28958. value: function newRTCSession(session, data) {
  28959. var videoBandwidth = this._videoBandwidth;
  28960. var audioBandwidth = this._audioBandwidth;
  28961. session.on('sdp', function (e) {
  28962. var sdp = e.sdp;
  28963. e.sdp = setBandwidth(sdp, audioBandwidth, videoBandwidth);
  28964. });
  28965. this._sessions[session.id] = session;
  28966. this.emit('newRTCSession', data);
  28967. }
  28968. /**
  28969. * RTCSession destroyed.
  28970. */
  28971. }, {
  28972. key: "destroyRTCSession",
  28973. value: function destroyRTCSession(session) {
  28974. delete this._sessions[session.id];
  28975. }
  28976. /**
  28977. * Registered
  28978. */
  28979. }, {
  28980. key: "registered",
  28981. value: function registered(data) {
  28982. var user;
  28983. if (data.response.headers.From[0]) {
  28984. var _from = data.response.headers.From[0].raw;
  28985. // const from = _from.match(new RegExp(' ' + "(.*)" + ';'));
  28986. // user = from[1] ? from[1] : '';
  28987. user = _from;
  28988. }
  28989. PhoneLogger.user = user;
  28990. // console.log(PhoneLogger.user);
  28991. PhoneLogger.info({
  28992. event: "registered",
  28993. data: data
  28994. });
  28995. this.emit('registered', data);
  28996. }
  28997. /**
  28998. * Unregistered
  28999. */
  29000. }, {
  29001. key: "unregistered",
  29002. value: function unregistered(data) {
  29003. PhoneLogger.info({
  29004. event: "unregistered",
  29005. data: data
  29006. });
  29007. this.emit('unregistered', data);
  29008. }
  29009. /**
  29010. * Registration Failed
  29011. */
  29012. }, {
  29013. key: "registrationFailed",
  29014. value: function registrationFailed(data) {
  29015. PhoneLogger.error({
  29016. event: "registrationFailed",
  29017. data: data
  29018. });
  29019. this.emit('registrationFailed', data);
  29020. } // =========================
  29021. // ReceiveRequest.
  29022. // =========================
  29023. /**
  29024. * Request reception
  29025. */
  29026. }, {
  29027. key: "receiveRequest",
  29028. value: function receiveRequest(request) {
  29029. var method = request.method; // Check that request URI points to us.
  29030. if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) {
  29031. debug('Request-URI does not point to us');
  29032. if (request.method !== JsSIP_C.ACK) {
  29033. request.reply_sl(404);
  29034. }
  29035. return;
  29036. } // Check request URI scheme.
  29037. if (request.ruri.scheme === JsSIP_C.SIPS) {
  29038. request.reply_sl(416);
  29039. return;
  29040. } // Check transaction.
  29041. if (Transactions.checkTransaction(this, request)) {
  29042. return;
  29043. } // Create the server transaction.
  29044. if (method === JsSIP_C.INVITE) {
  29045. /* eslint-disable no-new */
  29046. new Transactions.InviteServerTransaction(this, this._transport, request);
  29047. /* eslint-enable no-new */
  29048. } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) {
  29049. /* eslint-disable no-new */
  29050. new Transactions.NonInviteServerTransaction(this, this._transport, request);
  29051. /* eslint-enable no-new */
  29052. }
  29053. /* RFC3261 12.2.2
  29054. * Requests that do not change in any way the state of a dialog may be
  29055. * received within a dialog (for example, an OPTIONS request).
  29056. * They are processed as if they had been received outside the dialog.
  29057. */
  29058. if (method === JsSIP_C.OPTIONS) {
  29059. request.reply(200);
  29060. } else if (method === JsSIP_C.MESSAGE) {
  29061. if (this.listeners('newMessage').length === 0) {
  29062. request.reply(405);
  29063. return;
  29064. }
  29065. var message = new Message(this);
  29066. message.init_incoming(request);
  29067. } else if (method === JsSIP_C.INVITE) {
  29068. // Initial INVITE.
  29069. if (!request.to_tag && this.listeners('newRTCSession').length === 0) {
  29070. request.reply(405);
  29071. return;
  29072. }
  29073. }
  29074. var dialog;
  29075. var session; // Initial Request.
  29076. if (!request.to_tag) {
  29077. switch (method) {
  29078. case JsSIP_C.INVITE:
  29079. if (window.RTCPeerConnection) {
  29080. // TODO
  29081. if (request.hasHeader('replaces')) {
  29082. var replaces = request.replaces;
  29083. dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag);
  29084. if (dialog) {
  29085. session = dialog.owner;
  29086. if (!session.isEnded()) {
  29087. session.receiveRequest(request);
  29088. } else {
  29089. request.reply(603);
  29090. }
  29091. } else {
  29092. request.reply(481);
  29093. }
  29094. } else {
  29095. session = new RTCSession(this);
  29096. session.init_incoming(request);
  29097. }
  29098. } else {
  29099. debugerror('INVITE received but WebRTC is not supported');
  29100. request.reply(488);
  29101. }
  29102. break;
  29103. case JsSIP_C.BYE:
  29104. // Out of dialog BYE received.
  29105. request.reply(481);
  29106. break;
  29107. case JsSIP_C.CANCEL:
  29108. session = this._findSession(request);
  29109. if (session) {
  29110. session.receiveRequest(request);
  29111. } else {
  29112. debug('received CANCEL request for a non existent session');
  29113. }
  29114. break;
  29115. case JsSIP_C.ACK:
  29116. /* Absorb it.
  29117. * ACK request without a corresponding Invite Transaction
  29118. * and without To tag.
  29119. */
  29120. break;
  29121. case JsSIP_C.NOTIFY:
  29122. // Receive new sip event.
  29123. this.emit('sipEvent', {
  29124. event: request.event,
  29125. request: request
  29126. });
  29127. request.reply(200);
  29128. break;
  29129. default:
  29130. request.reply(405);
  29131. break;
  29132. }
  29133. } // In-dialog request.
  29134. else {
  29135. dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag);
  29136. if (dialog) {
  29137. dialog.receiveRequest(request);
  29138. } else if (method === JsSIP_C.NOTIFY) {
  29139. session = this._findSession(request);
  29140. if (session) {
  29141. session.receiveRequest(request);
  29142. } else {
  29143. debug('received NOTIFY request for a non existent subscription');
  29144. request.reply(481, 'Subscription does not exist');
  29145. }
  29146. }
  29147. /* RFC3261 12.2.2
  29148. * Request with to tag, but no matching dialog found.
  29149. * Exception: ACK for an Invite request for which a dialog has not
  29150. * been created.
  29151. */
  29152. else if (method !== JsSIP_C.ACK) {
  29153. request.reply(481);
  29154. }
  29155. }
  29156. } // =================
  29157. // Utils.
  29158. // =================
  29159. /**
  29160. * Get the session to which the request belongs to, if any.
  29161. */
  29162. }, {
  29163. key: "_findSession",
  29164. value: function _findSession(_ref) {
  29165. var call_id = _ref.call_id,
  29166. from_tag = _ref.from_tag,
  29167. to_tag = _ref.to_tag;
  29168. var sessionIDa = call_id + from_tag;
  29169. var sessionA = this._sessions[sessionIDa];
  29170. var sessionIDb = call_id + to_tag;
  29171. var sessionB = this._sessions[sessionIDb];
  29172. if (sessionA) {
  29173. return sessionA;
  29174. } else if (sessionB) {
  29175. return sessionB;
  29176. } else {
  29177. return null;
  29178. }
  29179. }
  29180. /**
  29181. * Get the dialog to which the request belongs to, if any.
  29182. */
  29183. }, {
  29184. key: "_findDialog",
  29185. value: function _findDialog(call_id, from_tag, to_tag) {
  29186. var id = call_id + from_tag + to_tag;
  29187. var dialog = this._dialogs[id];
  29188. if (dialog) {
  29189. return dialog;
  29190. } else {
  29191. id = call_id + to_tag + from_tag;
  29192. dialog = this._dialogs[id];
  29193. if (dialog) {
  29194. return dialog;
  29195. } else {
  29196. return null;
  29197. }
  29198. }
  29199. }
  29200. }, {
  29201. key: "_loadConfig",
  29202. value: function _loadConfig(configuration) {
  29203. // Check and load the given configuration.
  29204. try {
  29205. config.load(this._configuration, configuration);
  29206. } catch (e) {
  29207. throw e;
  29208. } // Post Configuration Process.
  29209. // Allow passing 0 number as display_name.
  29210. if (this._configuration.display_name === 0) {
  29211. this._configuration.display_name = '0';
  29212. } // Instance-id for GRUU.
  29213. if (!this._configuration.instance_id) {
  29214. this._configuration.instance_id = Utils.newUUID();
  29215. } // Jssip_id instance parameter. Static random tag of length 5.
  29216. this._configuration.jssip_id = Utils.createRandomToken(5); // String containing this._configuration.uri without scheme and user.
  29217. var hostport_params = this._configuration.uri.clone();
  29218. hostport_params.user = null;
  29219. this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, ''); // Transport.
  29220. try {
  29221. this._transport = new Transport(this._configuration.sockets, {
  29222. // Recovery options.
  29223. max_interval: this._configuration.connection_recovery_max_interval,
  29224. min_interval: this._configuration.connection_recovery_min_interval
  29225. }); // Transport event callbacks.
  29226. this._transport.onconnecting = onTransportConnecting.bind(this);
  29227. this._transport.onconnect = onTransportConnect.bind(this);
  29228. this._transport.ondisconnect = onTransportDisconnect.bind(this);
  29229. this._transport.ondata = onTransportData.bind(this);
  29230. } catch (e) {
  29231. debugerror(e);
  29232. throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets);
  29233. } // Remove sockets instance from configuration object.
  29234. delete this._configuration.sockets; // Check whether authorization_user is explicitly defined.
  29235. // Take 'this._configuration.uri.user' value if not.
  29236. if (!this._configuration.authorization_user) {
  29237. this._configuration.authorization_user = this._configuration.uri.user;
  29238. } // If no 'registrar_server' is set use the 'uri' value without user portion and
  29239. // without URI params/headers.
  29240. if (!this._configuration.registrar_server) {
  29241. var registrar_server = this._configuration.uri.clone();
  29242. registrar_server.user = null;
  29243. registrar_server.clearParams();
  29244. registrar_server.clearHeaders();
  29245. this._configuration.registrar_server = registrar_server;
  29246. } // User no_answer_timeout.
  29247. this._configuration.no_answer_timeout *= 1000; // Via Host.
  29248. if (this._configuration.contact_uri) {
  29249. this._configuration.via_host = this._configuration.contact_uri.host;
  29250. } // Contact URI.
  29251. else {
  29252. this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, {
  29253. transport: 'ws'
  29254. });
  29255. }
  29256. this._contact = {
  29257. pub_gruu: null,
  29258. temp_gruu: null,
  29259. uri: this._configuration.contact_uri,
  29260. toString: function toString() {
  29261. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  29262. var anonymous = options.anonymous || null;
  29263. var outbound = options.outbound || null;
  29264. var contact = '<';
  29265. if (anonymous) {
  29266. contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
  29267. } else {
  29268. contact += this.pub_gruu || this.uri.toString();
  29269. }
  29270. contact += '>';
  29271. return contact;
  29272. }
  29273. }; // Seal the configuration.
  29274. var writable_parameters = ['password', 'realm', 'ha1', 'display_name', 'register'];
  29275. for (var parameter in this._configuration) {
  29276. if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) {
  29277. if (writable_parameters.indexOf(parameter) !== -1) {
  29278. Object.defineProperty(this._configuration, parameter, {
  29279. writable: true,
  29280. configurable: false
  29281. });
  29282. } else {
  29283. Object.defineProperty(this._configuration, parameter, {
  29284. writable: false,
  29285. configurable: false
  29286. });
  29287. }
  29288. }
  29289. }
  29290. debug('configuration parameters after validation:');
  29291. for (var _parameter in this._configuration) {
  29292. // Only show the user user configurable parameters.
  29293. if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) {
  29294. switch (_parameter) {
  29295. case 'uri':
  29296. case 'registrar_server':
  29297. debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter]));
  29298. break;
  29299. case 'password':
  29300. case 'ha1':
  29301. debug("- ".concat(_parameter, ": NOT SHOWN"));
  29302. break;
  29303. default:
  29304. debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter])));
  29305. }
  29306. }
  29307. }
  29308. return;
  29309. }
  29310. }, {
  29311. key: "C",
  29312. get: function get() {
  29313. return C;
  29314. }
  29315. }, {
  29316. key: "status",
  29317. get: function get() {
  29318. return this._status;
  29319. }
  29320. }, {
  29321. key: "contact",
  29322. get: function get() {
  29323. return this._contact;
  29324. }
  29325. }, {
  29326. key: "configuration",
  29327. get: function get() {
  29328. return this._configuration;
  29329. }
  29330. }, {
  29331. key: "transport",
  29332. get: function get() {
  29333. return this._transport;
  29334. }
  29335. }]);
  29336. return UA;
  29337. }(EventEmitter);
  29338. /**
  29339. * Transport event handlers
  29340. */
  29341. // Transport connecting event.
  29342. function onTransportConnecting(data) {
  29343. this.emit('connecting', data);
  29344. } // Transport connected event.
  29345. function onTransportConnect(data) {
  29346. if (this._status === C.STATUS_USER_CLOSED) {
  29347. return;
  29348. }
  29349. this._status = C.STATUS_READY;
  29350. this._error = null;
  29351. this.emit('connected', data);
  29352. if (this._dynConfiguration.register) {
  29353. this._registrator.register();
  29354. }
  29355. } // Transport disconnected event.
  29356. function onTransportDisconnect(data) {
  29357. // Run _onTransportError_ callback on every client transaction using _transport_.
  29358. var client_transactions = ['nict', 'ict', 'nist', 'ist'];
  29359. for (var _i = 0; _i < client_transactions.length; _i++) {
  29360. var type = client_transactions[_i];
  29361. for (var id in this._transactions[type]) {
  29362. if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) {
  29363. this._transactions[type][id].onTransportError();
  29364. }
  29365. }
  29366. }
  29367. this.emit('disconnected', data); // Call registrator _onTransportClosed_.
  29368. this._registrator.onTransportClosed();
  29369. if (this._status !== C.STATUS_USER_CLOSED) {
  29370. this._status = C.STATUS_NOT_READY;
  29371. this._error = C.NETWORK_ERROR;
  29372. }
  29373. } // Transport data event.
  29374. function onTransportData(data) {
  29375. var transport = data.transport;
  29376. var message = data.message;
  29377. message = Parser.parseMessage(message, this);
  29378. if (!message) {
  29379. return;
  29380. }
  29381. if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) {
  29382. return;
  29383. } // Do some sanity check.
  29384. if (!sanityCheck(message, this, transport)) {
  29385. return;
  29386. }
  29387. if (message instanceof SIPMessage.IncomingRequest) {
  29388. message.transport = transport;
  29389. this.receiveRequest(message);
  29390. } else if (message instanceof SIPMessage.IncomingResponse) {
  29391. /* Unike stated in 18.1.2, if a response does not match
  29392. * any transaction, it is discarded here and no passed to the core
  29393. * in order to be discarded there.
  29394. */
  29395. var transaction;
  29396. switch (message.method) {
  29397. case JsSIP_C.INVITE:
  29398. transaction = this._transactions.ict[message.via_branch];
  29399. if (transaction) {
  29400. transaction.receiveResponse(message);
  29401. }
  29402. break;
  29403. case JsSIP_C.ACK:
  29404. // Just in case ;-).
  29405. break;
  29406. default:
  29407. transaction = this._transactions.nict[message.via_branch];
  29408. if (transaction) {
  29409. transaction.receiveResponse(message);
  29410. }
  29411. break;
  29412. }
  29413. }
  29414. }
  29415. }),
  29416. /* 26 */
  29417. (function(module, exports, __webpack_require__) {
  29418. "use strict";
  29419. function _classCallCheck(instance, Constructor) {
  29420. if (!(instance instanceof Constructor)) {
  29421. throw new TypeError("Cannot call a class as a function");
  29422. }
  29423. }
  29424. function _defineProperties(target, props) {
  29425. for (var i = 0; i < props.length; i++) {
  29426. var descriptor = props[i];
  29427. descriptor.enumerable = descriptor.enumerable || false;
  29428. descriptor.configurable = true;
  29429. if ("value" in descriptor) descriptor.writable = true;
  29430. Object.defineProperty(target, descriptor.key, descriptor);
  29431. }
  29432. }
  29433. function _createClass(Constructor, protoProps, staticProps) {
  29434. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  29435. if (staticProps) _defineProperties(Constructor, staticProps);
  29436. return Constructor;
  29437. }
  29438. var Utils = __webpack_require__(2);
  29439. var JsSIP_C = __webpack_require__(1);
  29440. var SIPMessage = __webpack_require__(5);
  29441. var RequestSender = __webpack_require__(10);
  29442. var debug = __webpack_require__(0)('JsSIP:Registrator');
  29443. var MIN_REGISTER_EXPIRES = 10; // In seconds.
  29444. module.exports =
  29445. /*#__PURE__*/
  29446. function () {
  29447. function Registrator(ua, transport) {
  29448. _classCallCheck(this, Registrator);
  29449. var reg_id = 1; // Force reg_id to 1.
  29450. this._ua = ua;
  29451. this._transport = transport;
  29452. this._registrar = ua.configuration.registrar_server;
  29453. this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2.
  29454. this._call_id = Utils.createRandomToken(22);
  29455. this._cseq = 0;
  29456. this._to_uri = ua.configuration.uri;
  29457. this._registrationTimer = null; // Ongoing Register request.
  29458. this._registering = false; // Set status.
  29459. this._registered = false; // Contact header.
  29460. this._contact = this._ua.contact.toString(); // Sip.ice media feature tag (RFC 5768).
  29461. this._contact += ';+sip.ice'; // Custom headers for REGISTER and un-REGISTER.
  29462. this._extraHeaders = []; // Custom Contact header params for REGISTER and un-REGISTER.
  29463. this._extraContactParams = '';
  29464. if (reg_id) {
  29465. this._contact += ";reg-id=".concat(reg_id);
  29466. this._contact += ";+sip.instance=\"<urn:uuid:".concat(this._ua.configuration.instance_id, ">\"");
  29467. }
  29468. }
  29469. _createClass(Registrator, [{
  29470. key: "setExtraHeaders",
  29471. value: function setExtraHeaders(extraHeaders) {
  29472. if (!Array.isArray(extraHeaders)) {
  29473. extraHeaders = [];
  29474. }
  29475. this._extraHeaders = extraHeaders.slice();
  29476. }
  29477. }, {
  29478. key: "setExtraContactParams",
  29479. value: function setExtraContactParams(extraContactParams) {
  29480. if (!(extraContactParams instanceof Object)) {
  29481. extraContactParams = {};
  29482. } // Reset it.
  29483. this._extraContactParams = '';
  29484. for (var param_key in extraContactParams) {
  29485. if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) {
  29486. var param_value = extraContactParams[param_key];
  29487. this._extraContactParams += ";".concat(param_key);
  29488. if (param_value) {
  29489. this._extraContactParams += "=".concat(param_value);
  29490. }
  29491. }
  29492. }
  29493. }
  29494. }, {
  29495. key: "register",
  29496. value: function register() {
  29497. var _this = this;
  29498. if (this._registering) {
  29499. debug('Register request in progress...');
  29500. return;
  29501. }
  29502. var extraHeaders = this._extraHeaders.slice();
  29503. extraHeaders.push("Contact: ".concat(this._contact, ";expires=").concat(this._expires).concat(this._extraContactParams));
  29504. extraHeaders.push("Expires: ".concat(this._expires));
  29505. var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
  29506. 'to_uri': this._to_uri,
  29507. 'call_id': this._call_id,
  29508. 'cseq': this._cseq += 1
  29509. }, extraHeaders);
  29510. var request_sender = new RequestSender(this._ua, request, {
  29511. onRequestTimeout: function onRequestTimeout() {
  29512. _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  29513. },
  29514. onTransportError: function onTransportError() {
  29515. _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR);
  29516. },
  29517. // Increase the CSeq on authentication.
  29518. onAuthenticated: function onAuthenticated() {
  29519. _this._cseq += 1;
  29520. },
  29521. onReceiveResponse: function onReceiveResponse(response) {
  29522. // Discard responses to older REGISTER/un-REGISTER requests.
  29523. if (response.cseq !== _this._cseq) {
  29524. return;
  29525. } // Clear registration timer.
  29526. if (_this._registrationTimer !== null) {
  29527. clearTimeout(_this._registrationTimer);
  29528. _this._registrationTimer = null;
  29529. }
  29530. switch (true) {
  29531. case /^1[0-9]{2}$/.test(response.status_code):
  29532. {
  29533. // Ignore provisional responses.
  29534. break;
  29535. }
  29536. case /^2[0-9]{2}$/.test(response.status_code):
  29537. {
  29538. _this._registering = false;
  29539. if (!response.hasHeader('Contact')) {
  29540. debug('no Contact header in response to REGISTER, response ignored');
  29541. break;
  29542. }
  29543. var contacts = response.headers['Contact'].reduce(function (a, b) {
  29544. return a.concat(b.parsed);
  29545. }, []); // Get the Contact pointing to us and update the expires value accordingly.
  29546. var contact = contacts.find(function (element) {
  29547. return element.uri.user === _this._ua.contact.uri.user;
  29548. });
  29549. if (!contact) {
  29550. debug('no Contact header pointing to us, response ignored');
  29551. break;
  29552. }
  29553. var expires = contact.getParam('expires');
  29554. if (!expires && response.hasHeader('expires')) {
  29555. expires = response.getHeader('expires');
  29556. }
  29557. if (!expires) {
  29558. expires = _this._expires;
  29559. }
  29560. expires = Number(expires);
  29561. if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES; // Re-Register or emit an event before the expiration interval has elapsed.
  29562. // For that, decrease the expires value. ie: 3 seconds.
  29563. _this._registrationTimer = setTimeout(function () {
  29564. _this._registrationTimer = null; // If there are no listeners for registrationExpiring, renew registration.
  29565. // If there are listeners, let the function listening do the register call.
  29566. if (_this._ua.listeners('registrationExpiring').length === 0) {
  29567. _this.register();
  29568. } else {
  29569. _this._ua.emit('registrationExpiring');
  29570. }
  29571. }, expires * 1000 - 5000); // Save gruu values.
  29572. if (contact.hasParam('temp-gruu')) {
  29573. _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, '');
  29574. }
  29575. if (contact.hasParam('pub-gruu')) {
  29576. _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, '');
  29577. }
  29578. if (!_this._registered) {
  29579. _this._registered = true;
  29580. _this._ua.registered({
  29581. response: response
  29582. });
  29583. }
  29584. break;
  29585. }
  29586. // Interval too brief RFC3261 10.2.8.
  29587. case /^423$/.test(response.status_code):
  29588. {
  29589. if (response.hasHeader('min-expires')) {
  29590. // Increase our registration interval to the suggested minimum.
  29591. _this._expires = Number(response.getHeader('min-expires'));
  29592. if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES; // Attempt the registration again immediately.
  29593. _this.register();
  29594. } else {
  29595. // This response MUST contain a Min-Expires header field.
  29596. debug('423 response received for REGISTER without Min-Expires');
  29597. _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE);
  29598. }
  29599. break;
  29600. }
  29601. default:
  29602. {
  29603. var cause = Utils.sipErrorCause(response.status_code);
  29604. _this._registrationFailure(response, cause);
  29605. }
  29606. }
  29607. }
  29608. });
  29609. this._registering = true;
  29610. request_sender.send();
  29611. }
  29612. }, {
  29613. key: "unregister",
  29614. value: function unregister() {
  29615. var _this2 = this;
  29616. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  29617. if (!this._registered) {
  29618. debug('already unregistered');
  29619. return;
  29620. }
  29621. this._registered = false; // Clear the registration timer.
  29622. if (this._registrationTimer !== null) {
  29623. clearTimeout(this._registrationTimer);
  29624. this._registrationTimer = null;
  29625. }
  29626. var extraHeaders = this._extraHeaders.slice();
  29627. if (options.all) {
  29628. extraHeaders.push("Contact: *".concat(this._extraContactParams));
  29629. } else {
  29630. extraHeaders.push("Contact: ".concat(this._contact, ";expires=0").concat(this._extraContactParams));
  29631. }
  29632. extraHeaders.push('Expires: 0');
  29633. var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
  29634. 'to_uri': this._to_uri,
  29635. 'call_id': this._call_id,
  29636. 'cseq': this._cseq += 1
  29637. }, extraHeaders);
  29638. var request_sender = new RequestSender(this._ua, request, {
  29639. onRequestTimeout: function onRequestTimeout() {
  29640. _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  29641. },
  29642. onTransportError: function onTransportError() {
  29643. _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR);
  29644. },
  29645. // Increase the CSeq on authentication.
  29646. onAuthenticated: function onAuthenticated() {
  29647. _this2._cseq += 1;
  29648. },
  29649. onReceiveResponse: function onReceiveResponse(response) {
  29650. switch (true) {
  29651. case /^1[0-9]{2}$/.test(response.status_code):
  29652. // Ignore provisional responses.
  29653. break;
  29654. case /^2[0-9]{2}$/.test(response.status_code):
  29655. _this2._unregistered(response);
  29656. break;
  29657. default:
  29658. {
  29659. var cause = Utils.sipErrorCause(response.status_code);
  29660. _this2._unregistered(response, cause);
  29661. }
  29662. }
  29663. }
  29664. });
  29665. request_sender.send();
  29666. }
  29667. }, {
  29668. key: "close",
  29669. value: function close() {
  29670. if (this._registered) {
  29671. this.unregister();
  29672. }
  29673. }
  29674. }, {
  29675. key: "onTransportClosed",
  29676. value: function onTransportClosed() {
  29677. this._registering = false;
  29678. if (this._registrationTimer !== null) {
  29679. clearTimeout(this._registrationTimer);
  29680. this._registrationTimer = null;
  29681. }
  29682. if (this._registered) {
  29683. this._registered = false;
  29684. this._ua.unregistered({});
  29685. }
  29686. }
  29687. }, {
  29688. key: "_registrationFailure",
  29689. value: function _registrationFailure(response, cause) {
  29690. this._registering = false;
  29691. this._ua.registrationFailed({
  29692. response: response || null,
  29693. cause: cause
  29694. });
  29695. if (this._registered) {
  29696. this._registered = false;
  29697. this._ua.unregistered({
  29698. response: response || null,
  29699. cause: cause
  29700. });
  29701. }
  29702. }
  29703. }, {
  29704. key: "_unregistered",
  29705. value: function _unregistered(response, cause) {
  29706. this._registering = false;
  29707. this._registered = false;
  29708. this._ua.unregistered({
  29709. response: response || null,
  29710. cause: cause || null
  29711. });
  29712. }
  29713. }, {
  29714. key: "registered",
  29715. get: function get() {
  29716. return this._registered;
  29717. }
  29718. }]);
  29719. return Registrator;
  29720. }();
  29721. }),
  29722. /* 27 */
  29723. (function(module, exports, __webpack_require__) {
  29724. var toIntIfInt = function (v) {
  29725. return String(Number(v)) === v ? Number(v) : v;
  29726. };
  29727. var attachProperties = function (match, location, names, rawName) {
  29728. if (rawName && !names) {
  29729. location[rawName] = toIntIfInt(match[1]);
  29730. } else {
  29731. for (var i = 0; i < names.length; i += 1) {
  29732. if (match[i + 1] != null) {
  29733. location[names[i]] = toIntIfInt(match[i + 1]);
  29734. }
  29735. }
  29736. }
  29737. };
  29738. var parseReg = function (obj, location, content) {
  29739. var needsBlank = obj.name && obj.names;
  29740. if (obj.push && !location[obj.push]) {
  29741. location[obj.push] = [];
  29742. } else if (needsBlank && !location[obj.name]) {
  29743. location[obj.name] = {};
  29744. }
  29745. var keyLocation = obj.push ? {} : // blank object that will be pushed
  29746. needsBlank ? location[obj.name] : location; // otherwise, named location or root
  29747. attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name);
  29748. if (obj.push) {
  29749. location[obj.push].push(keyLocation);
  29750. }
  29751. };
  29752. var grammar = __webpack_require__(14);
  29753. var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/);
  29754. exports.parse = function (sdp) {
  29755. var session = {},
  29756. media = [],
  29757. location = session; // points at where properties go under (one of the above)
  29758. // parse lines we understand
  29759. sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) {
  29760. var type = l[0];
  29761. var content = l.slice(2);
  29762. if (type === 'm') {
  29763. media.push({
  29764. rtp: [],
  29765. fmtp: []
  29766. });
  29767. location = media[media.length - 1]; // point at latest media line
  29768. }
  29769. for (var j = 0; j < (grammar[type] || []).length; j += 1) {
  29770. var obj = grammar[type][j];
  29771. if (obj.reg.test(content)) {
  29772. return parseReg(obj, location, content);
  29773. }
  29774. }
  29775. });
  29776. session.media = media; // link it up
  29777. return session;
  29778. };
  29779. var paramReducer = function (acc, expr) {
  29780. var s = expr.split(/=(.+)/, 2);
  29781. if (s.length === 2) {
  29782. acc[s[0]] = toIntIfInt(s[1]);
  29783. } else if (s.length === 1 && expr.length > 1) {
  29784. acc[s[0]] = undefined;
  29785. }
  29786. return acc;
  29787. };
  29788. exports.parseParams = function (str) {
  29789. return str.split(/\;\s?/).reduce(paramReducer, {});
  29790. }; // For backward compatibility - alias will be removed in 3.0.0
  29791. exports.parseFmtpConfig = exports.parseParams;
  29792. exports.parsePayloads = function (str) {
  29793. return str.split(' ').map(Number);
  29794. };
  29795. exports.parseRemoteCandidates = function (str) {
  29796. var candidates = [];
  29797. var parts = str.split(' ').map(toIntIfInt);
  29798. for (var i = 0; i < parts.length; i += 3) {
  29799. candidates.push({
  29800. component: parts[i],
  29801. ip: parts[i + 1],
  29802. port: parts[i + 2]
  29803. });
  29804. }
  29805. return candidates;
  29806. };
  29807. exports.parseImageAttributes = function (str) {
  29808. return str.split(' ').map(function (item) {
  29809. return item.substring(1, item.length - 1).split(',').reduce(paramReducer, {});
  29810. });
  29811. };
  29812. exports.parseSimulcastStreamList = function (str) {
  29813. return str.split(';').map(function (stream) {
  29814. return stream.split(',').map(function (format) {
  29815. var scid,
  29816. paused = false;
  29817. if (format[0] !== '~') {
  29818. scid = toIntIfInt(format);
  29819. } else {
  29820. scid = toIntIfInt(format.substring(1, format.length));
  29821. paused = true;
  29822. }
  29823. return {
  29824. scid: scid,
  29825. paused: paused
  29826. };
  29827. });
  29828. });
  29829. };
  29830. }),
  29831. /* 28 */
  29832. (function(module, exports, __webpack_require__) {
  29833. var grammar = __webpack_require__(14); // customized janus.format - discards excess arguments and can void middle ones
  29834. var formatRegExp = /%[sdv%]/g;
  29835. var format = function (formatStr) {
  29836. var i = 1;
  29837. var args = arguments;
  29838. var len = args.length;
  29839. return formatStr.replace(formatRegExp, function (x) {
  29840. if (i >= len) {
  29841. return x; // missing argument
  29842. }
  29843. var arg = args[i];
  29844. i += 1;
  29845. switch (x) {
  29846. case '%%':
  29847. return '%';
  29848. case '%s':
  29849. return String(arg);
  29850. case '%d':
  29851. return Number(arg);
  29852. case '%v':
  29853. return '';
  29854. }
  29855. }); // NB: we discard excess arguments - they are typically undefined from makeLine
  29856. };
  29857. var makeLine = function (type, obj, location) {
  29858. var str = obj.format instanceof Function ? obj.format(obj.push ? location : location[obj.name]) : obj.format;
  29859. var args = [type + '=' + str];
  29860. if (obj.names) {
  29861. for (var i = 0; i < obj.names.length; i += 1) {
  29862. var n = obj.names[i];
  29863. if (obj.name) {
  29864. args.push(location[obj.name][n]);
  29865. } else {
  29866. // for mLine and push attributes
  29867. args.push(location[obj.names[i]]);
  29868. }
  29869. }
  29870. } else {
  29871. args.push(location[obj.name]);
  29872. }
  29873. return format.apply(null, args);
  29874. }; // RFC specified order
  29875. // TODO: extend this with all the rest
  29876. var defaultOuterOrder = ['v', 'o', 's', 'i', 'u', 'e', 'p', 'c', 'b', 't', 'r', 'z', 'a'];
  29877. var defaultInnerOrder = ['i', 'c', 'b', 'a'];
  29878. module.exports = function (session, opts) {
  29879. opts = opts || {}; // ensure certain properties exist
  29880. if (session.version == null) {
  29881. session.version = 0; // 'v=0' must be there (only defined version atm)
  29882. }
  29883. if (session.name == null) {
  29884. session.name = ' '; // 's= ' must be there if no meaningful name set
  29885. }
  29886. session.media.forEach(function (mLine) {
  29887. if (mLine.payloads == null) {
  29888. mLine.payloads = '';
  29889. }
  29890. });
  29891. var outerOrder = opts.outerOrder || defaultOuterOrder;
  29892. var innerOrder = opts.innerOrder || defaultInnerOrder;
  29893. var sdp = []; // loop through outerOrder for matching properties on session
  29894. outerOrder.forEach(function (type) {
  29895. grammar[type].forEach(function (obj) {
  29896. if (obj.name in session && session[obj.name] != null) {
  29897. sdp.push(makeLine(type, obj, session));
  29898. } else if (obj.push in session && session[obj.push] != null) {
  29899. session[obj.push].forEach(function (el) {
  29900. sdp.push(makeLine(type, obj, el));
  29901. });
  29902. }
  29903. });
  29904. }); // then for each media line, follow the innerOrder
  29905. session.media.forEach(function (mLine) {
  29906. sdp.push(makeLine('m', grammar.m[0], mLine));
  29907. innerOrder.forEach(function (type) {
  29908. grammar[type].forEach(function (obj) {
  29909. if (obj.name in mLine && mLine[obj.name] != null) {
  29910. sdp.push(makeLine(type, obj, mLine));
  29911. } else if (obj.push in mLine && mLine[obj.push] != null) {
  29912. mLine[obj.push].forEach(function (el) {
  29913. sdp.push(makeLine(type, obj, el));
  29914. });
  29915. }
  29916. });
  29917. });
  29918. });
  29919. return sdp.join('\r\n') + '\r\n';
  29920. };
  29921. }),
  29922. /* 29 */
  29923. (function(module, exports, __webpack_require__) {
  29924. /**
  29925. * This is the common logic for both the Node.js and web browser
  29926. * implementations of `debug()`.
  29927. */
  29928. function setup(env) {
  29929. createDebug.debug = createDebug;
  29930. createDebug.default = createDebug;
  29931. createDebug.coerce = coerce;
  29932. createDebug.disable = disable;
  29933. createDebug.enable = enable;
  29934. createDebug.enabled = enabled;
  29935. createDebug.humanize = __webpack_require__(30);
  29936. Object.keys(env).forEach(key => {
  29937. createDebug[key] = env[key];
  29938. });
  29939. /**
  29940. * Active `debug` instances.
  29941. */
  29942. createDebug.instances = [];
  29943. /**
  29944. * The currently active debug mode names, and names to skip.
  29945. */
  29946. createDebug.names = [];
  29947. createDebug.skips = [];
  29948. /**
  29949. * Map of special "%n" handling functions, for the debug "format" argument.
  29950. *
  29951. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  29952. */
  29953. createDebug.formatters = {};
  29954. /**
  29955. * Selects a color for a debug namespace
  29956. * @param {String} namespace The namespace string for the for the debug instance to be colored
  29957. * @return {Number|String} An ANSI color code for the given namespace
  29958. * @api private
  29959. */
  29960. function selectColor(namespace) {
  29961. let hash = 0;
  29962. for (let i = 0; i < namespace.length; i++) {
  29963. hash = (hash << 5) - hash + namespace.charCodeAt(i);
  29964. hash |= 0; // Convert to 32bit integer
  29965. }
  29966. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  29967. }
  29968. createDebug.selectColor = selectColor;
  29969. /**
  29970. * Create a debugger with the given `namespace`.
  29971. *
  29972. * @param {String} namespace
  29973. * @return {Function}
  29974. * @api public
  29975. */
  29976. function createDebug(namespace) {
  29977. let prevTime;
  29978. function debug(...args) {
  29979. // TODO: Disabled?
  29980. /*if (!debug.enabled) {
  29981. return;
  29982. }*/
  29983. const self = debug; // Set `diff` timestamp
  29984. const curr = Number(new Date());
  29985. const ms = curr - (prevTime || curr);
  29986. self.diff = ms;
  29987. self.prev = prevTime;
  29988. self.curr = curr;
  29989. prevTime = curr;
  29990. args[0] = createDebug.coerce(args[0]);
  29991. if (typeof args[0] !== 'string') {
  29992. // Anything else let's inspect with %O
  29993. args.unshift('%O');
  29994. } // Apply any `formatters` transformations
  29995. let index = 0;
  29996. args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
  29997. // If we encounter an escaped % then don't increase the array index
  29998. if (match === '%%') {
  29999. return match;
  30000. }
  30001. index++;
  30002. const formatter = createDebug.formatters[format];
  30003. if (typeof formatter === 'function') {
  30004. const val = args[index];
  30005. match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format`
  30006. args.splice(index, 1);
  30007. index--;
  30008. }
  30009. return match;
  30010. }); // Apply env-specific formatting (colors, etc.)
  30011. createDebug.formatArgs.call(self, args);
  30012. const logFn = self.log || createDebug.log;
  30013. logFn.apply(self, args);
  30014. }
  30015. debug.namespace = namespace;
  30016. debug.enabled = createDebug.enabled(namespace);
  30017. debug.useColors = createDebug.useColors();
  30018. debug.color = selectColor(namespace);
  30019. debug.destroy = destroy;
  30020. debug.extend = extend; // Debug.formatArgs = formatArgs;
  30021. // debug.rawLog = rawLog;
  30022. // env-specific initialization logic for debug instances
  30023. if (typeof createDebug.init === 'function') {
  30024. createDebug.init(debug);
  30025. }
  30026. createDebug.instances.push(debug);
  30027. return debug;
  30028. }
  30029. function destroy() {
  30030. const index = createDebug.instances.indexOf(this);
  30031. if (index !== -1) {
  30032. createDebug.instances.splice(index, 1);
  30033. return true;
  30034. }
  30035. return false;
  30036. }
  30037. function extend(namespace, delimiter) {
  30038. const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  30039. newDebug.log = this.log;
  30040. return newDebug;
  30041. }
  30042. /**
  30043. * Enables a debug mode by namespaces. This can include modes
  30044. * separated by a colon and wildcards.
  30045. *
  30046. * @param {String} namespaces
  30047. * @api public
  30048. */
  30049. function enable(namespaces) {
  30050. createDebug.save(namespaces);
  30051. createDebug.names = [];
  30052. createDebug.skips = [];
  30053. let i;
  30054. const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  30055. const len = split.length;
  30056. for (i = 0; i < len; i++) {
  30057. if (!split[i]) {
  30058. // ignore empty strings
  30059. continue;
  30060. }
  30061. namespaces = split[i].replace(/\*/g, '.*?');
  30062. if (namespaces[0] === '-') {
  30063. createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  30064. } else {
  30065. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  30066. }
  30067. }
  30068. for (i = 0; i < createDebug.instances.length; i++) {
  30069. const instance = createDebug.instances[i];
  30070. instance.enabled = createDebug.enabled(instance.namespace);
  30071. }
  30072. }
  30073. /**
  30074. * Disable debug output.
  30075. *
  30076. * @return {String} namespaces
  30077. * @api public
  30078. */
  30079. function disable() {
  30080. const namespaces = [...createDebug.names.map(toNamespace), ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)].join(',');
  30081. createDebug.enable('');
  30082. return namespaces;
  30083. }
  30084. /**
  30085. * Returns true if the given mode name is enabled, false otherwise.
  30086. *
  30087. * @param {String} name
  30088. * @return {Boolean}
  30089. * @api public
  30090. */
  30091. function enabled(name) {
  30092. if (name[name.length - 1] === '*') {
  30093. return true;
  30094. }
  30095. let i;
  30096. let len;
  30097. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  30098. if (createDebug.skips[i].test(name)) {
  30099. return false;
  30100. }
  30101. }
  30102. for (i = 0, len = createDebug.names.length; i < len; i++) {
  30103. if (createDebug.names[i].test(name)) {
  30104. return true;
  30105. }
  30106. }
  30107. return false;
  30108. }
  30109. /**
  30110. * Convert regexp to namespace
  30111. *
  30112. * @param {RegExp} regxep
  30113. * @return {String} namespace
  30114. * @api private
  30115. */
  30116. function toNamespace(regexp) {
  30117. return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
  30118. }
  30119. /**
  30120. * Coerce `val`.
  30121. *
  30122. * @param {Mixed} val
  30123. * @return {Mixed}
  30124. * @api private
  30125. */
  30126. function coerce(val) {
  30127. if (val instanceof Error) {
  30128. return val.stack || val.message;
  30129. }
  30130. return val;
  30131. }
  30132. createDebug.enable(createDebug.load());
  30133. return createDebug;
  30134. }
  30135. module.exports = setup;
  30136. }),
  30137. /* 30 */
  30138. (function(module, exports) {
  30139. /**
  30140. * Helpers.
  30141. */
  30142. var s = 1000;
  30143. var m = s * 60;
  30144. var h = m * 60;
  30145. var d = h * 24;
  30146. var w = d * 7;
  30147. var y = d * 365.25;
  30148. /**
  30149. * Parse or format the given `val`.
  30150. *
  30151. * Options:
  30152. *
  30153. * - `long` verbose formatting [false]
  30154. *
  30155. * @param {String|Number} val
  30156. * @param {Object} [options]
  30157. * @throws {Error} throw an error if val is not a non-empty string or a number
  30158. * @return {String|Number}
  30159. * @api public
  30160. */
  30161. module.exports = function (val, options) {
  30162. options = options || {};
  30163. var type = typeof val;
  30164. if (type === 'string' && val.length > 0) {
  30165. return parse(val);
  30166. } else if (type === 'number' && isNaN(val) === false) {
  30167. return options.long ? fmtLong(val) : fmtShort(val);
  30168. }
  30169. throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
  30170. };
  30171. /**
  30172. * Parse the given `str` and return milliseconds.
  30173. *
  30174. * @param {String} str
  30175. * @return {Number}
  30176. * @api private
  30177. */
  30178. function parse(str) {
  30179. str = String(str);
  30180. if (str.length > 100) {
  30181. return;
  30182. }
  30183. var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
  30184. if (!match) {
  30185. return;
  30186. }
  30187. var n = parseFloat(match[1]);
  30188. var type = (match[2] || 'ms').toLowerCase();
  30189. switch (type) {
  30190. case 'years':
  30191. case 'year':
  30192. case 'yrs':
  30193. case 'yr':
  30194. case 'y':
  30195. return n * y;
  30196. case 'weeks':
  30197. case 'week':
  30198. case 'w':
  30199. return n * w;
  30200. case 'days':
  30201. case 'day':
  30202. case 'd':
  30203. return n * d;
  30204. case 'hours':
  30205. case 'hour':
  30206. case 'hrs':
  30207. case 'hr':
  30208. case 'h':
  30209. return n * h;
  30210. case 'minutes':
  30211. case 'minute':
  30212. case 'mins':
  30213. case 'min':
  30214. case 'm':
  30215. return n * m;
  30216. case 'seconds':
  30217. case 'second':
  30218. case 'secs':
  30219. case 'sec':
  30220. case 's':
  30221. return n * s;
  30222. case 'milliseconds':
  30223. case 'millisecond':
  30224. case 'msecs':
  30225. case 'msec':
  30226. case 'ms':
  30227. return n;
  30228. default:
  30229. return undefined;
  30230. }
  30231. }
  30232. /**
  30233. * Short format for `ms`.
  30234. *
  30235. * @param {Number} ms
  30236. * @return {String}
  30237. * @api private
  30238. */
  30239. function fmtShort(ms) {
  30240. var msAbs = Math.abs(ms);
  30241. if (msAbs >= d) {
  30242. return Math.round(ms / d) + 'd';
  30243. }
  30244. if (msAbs >= h) {
  30245. return Math.round(ms / h) + 'h';
  30246. }
  30247. if (msAbs >= m) {
  30248. return Math.round(ms / m) + 'm';
  30249. }
  30250. if (msAbs >= s) {
  30251. return Math.round(ms / s) + 's';
  30252. }
  30253. return ms + 'ms';
  30254. }
  30255. /**
  30256. * Long format for `ms`.
  30257. *
  30258. * @param {Number} ms
  30259. * @return {String}
  30260. * @api private
  30261. */
  30262. function fmtLong(ms) {
  30263. var msAbs = Math.abs(ms);
  30264. if (msAbs >= d) {
  30265. return plural(ms, msAbs, d, 'day');
  30266. }
  30267. if (msAbs >= h) {
  30268. return plural(ms, msAbs, h, 'hour');
  30269. }
  30270. if (msAbs >= m) {
  30271. return plural(ms, msAbs, m, 'minute');
  30272. }
  30273. if (msAbs >= s) {
  30274. return plural(ms, msAbs, s, 'second');
  30275. }
  30276. return ms + ' ms';
  30277. }
  30278. /**
  30279. * Pluralization helper.
  30280. */
  30281. function plural(ms, msAbs, n, name) {
  30282. var isPlural = msAbs >= n * 1.5;
  30283. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  30284. }
  30285. }),
  30286. /* 31 */
  30287. (function(module, exports, __webpack_require__) {
  30288. "use strict";
  30289. function _classCallCheck(instance, Constructor) {
  30290. if (!(instance instanceof Constructor)) {
  30291. throw new TypeError("Cannot call a class as a function");
  30292. }
  30293. }
  30294. function _defineProperties(target, props) {
  30295. for (var i = 0; i < props.length; i++) {
  30296. var descriptor = props[i];
  30297. descriptor.enumerable = descriptor.enumerable || false;
  30298. descriptor.configurable = true;
  30299. if ("value" in descriptor) descriptor.writable = true;
  30300. Object.defineProperty(target, descriptor.key, descriptor);
  30301. }
  30302. }
  30303. function _createClass(Constructor, protoProps, staticProps) {
  30304. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  30305. if (staticProps) _defineProperties(Constructor, staticProps);
  30306. return Constructor;
  30307. }
  30308. var Utils = __webpack_require__(2);
  30309. var debug = __webpack_require__(0)('JsSIP:DigestAuthentication');
  30310. var debugerror = __webpack_require__(0)('JsSIP:ERROR:DigestAuthentication');
  30311. debugerror.log = console.warn.bind(console);
  30312. module.exports =
  30313. /*#__PURE__*/
  30314. function () {
  30315. function DigestAuthentication(credentials) {
  30316. _classCallCheck(this, DigestAuthentication);
  30317. this._credentials = credentials;
  30318. this._cnonce = null;
  30319. this._nc = 0;
  30320. this._ncHex = '00000000';
  30321. this._algorithm = null;
  30322. this._realm = null;
  30323. this._nonce = null;
  30324. this._opaque = null;
  30325. this._stale = null;
  30326. this._qop = null;
  30327. this._method = null;
  30328. this._uri = null;
  30329. this._ha1 = null;
  30330. this._response = null;
  30331. }
  30332. _createClass(DigestAuthentication, [{
  30333. key: "get",
  30334. value: function get(parameter) {
  30335. switch (parameter) {
  30336. case 'realm':
  30337. return this._realm;
  30338. case 'ha1':
  30339. return this._ha1;
  30340. default:
  30341. debugerror('get() | cannot get "%s" parameter', parameter);
  30342. return undefined;
  30343. }
  30344. }
  30345. /**
  30346. * Performs Digest authentication given a SIP request and the challenge
  30347. * received in a response to that request.
  30348. * Returns true if auth was successfully generated, false otherwise.
  30349. */
  30350. }, {
  30351. key: "authenticate",
  30352. value: function authenticate(_ref, challenge)
  30353. /* test interface */
  30354. {
  30355. var method = _ref.method,
  30356. ruri = _ref.ruri,
  30357. body = _ref.body;
  30358. var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  30359. this._algorithm = challenge.algorithm;
  30360. this._realm = challenge.realm;
  30361. this._nonce = challenge.nonce;
  30362. this._opaque = challenge.opaque;
  30363. this._stale = challenge.stale;
  30364. if (this._algorithm) {
  30365. if (this._algorithm !== 'MD5') {
  30366. debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');
  30367. return false;
  30368. }
  30369. } else {
  30370. this._algorithm = 'MD5';
  30371. }
  30372. if (!this._nonce) {
  30373. debugerror('authenticate() | challenge without Digest nonce, authentication aborted');
  30374. return false;
  30375. }
  30376. if (!this._realm) {
  30377. debugerror('authenticate() | challenge without Digest realm, authentication aborted');
  30378. return false;
  30379. } // If no plain SIP password is provided.
  30380. if (!this._credentials.password) {
  30381. // If ha1 is not provided we cannot authenticate.
  30382. if (!this._credentials.ha1) {
  30383. debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted');
  30384. return false;
  30385. } // If the realm does not match the stored realm we cannot authenticate.
  30386. if (this._credentials.realm !== this._realm) {
  30387. debugerror('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm);
  30388. return false;
  30389. }
  30390. } // 'qop' can contain a list of values (Array). Let's choose just one.
  30391. if (challenge.qop) {
  30392. if (challenge.qop.indexOf('auth-int') > -1) {
  30393. this._qop = 'auth-int';
  30394. } else if (challenge.qop.indexOf('auth') > -1) {
  30395. this._qop = 'auth';
  30396. } else {
  30397. // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here.
  30398. debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');
  30399. return false;
  30400. }
  30401. } else {
  30402. this._qop = null;
  30403. } // Fill other attributes.
  30404. this._method = method;
  30405. this._uri = ruri;
  30406. this._cnonce = cnonce || Utils.createRandomToken(12);
  30407. this._nc += 1;
  30408. var hex = Number(this._nc).toString(16);
  30409. this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex; // Nc-value = 8LHEX. Max value = 'FFFFFFFF'.
  30410. if (this._nc === 4294967296) {
  30411. this._nc = 1;
  30412. this._ncHex = '00000001';
  30413. } // Calculate the Digest "response" value.
  30414. // If we have plain SIP password then regenerate ha1.
  30415. if (this._credentials.password) {
  30416. // HA1 = MD5(A1) = MD5(username:realm:password).
  30417. this._ha1 = Utils.calculateMD5("".concat(this._credentials.username, ":").concat(this._realm, ":").concat(this._credentials.password));
  30418. } // Otherwise reuse the stored ha1.
  30419. else {
  30420. this._ha1 = this._credentials.ha1;
  30421. }
  30422. var ha2;
  30423. if (this._qop === 'auth') {
  30424. // HA2 = MD5(A2) = MD5(method:digestURI).
  30425. ha2 = Utils.calculateMD5("".concat(this._method, ":").concat(this._uri)); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
  30426. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2));
  30427. } else if (this._qop === 'auth-int') {
  30428. // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)).
  30429. ha2 = Utils.calculateMD5("".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : ''))); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
  30430. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2));
  30431. } else if (this._qop === null) {
  30432. // HA2 = MD5(A2) = MD5(method:digestURI).
  30433. ha2 = Utils.calculateMD5("".concat(this._method, ":").concat(this._uri)); // Response = MD5(HA1:nonce:HA2).
  30434. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2));
  30435. }
  30436. debug('authenticate() | response generated');
  30437. return true;
  30438. }
  30439. /**
  30440. * Return the Proxy-Authorization or WWW-Authorization header value.
  30441. */
  30442. }, {
  30443. key: "toString",
  30444. value: function toString() {
  30445. var auth_params = [];
  30446. if (!this._response) {
  30447. throw new Error('response field does not exist, cannot generate Authorization header');
  30448. }
  30449. auth_params.push("algorithm=".concat(this._algorithm));
  30450. auth_params.push("username=\"".concat(this._credentials.username, "\""));
  30451. auth_params.push("realm=\"".concat(this._realm, "\""));
  30452. auth_params.push("nonce=\"".concat(this._nonce, "\""));
  30453. auth_params.push("uri=\"".concat(this._uri, "\""));
  30454. auth_params.push("response=\"".concat(this._response, "\""));
  30455. if (this._opaque) {
  30456. auth_params.push("opaque=\"".concat(this._opaque, "\""));
  30457. }
  30458. if (this._qop) {
  30459. auth_params.push("qop=".concat(this._qop));
  30460. auth_params.push("cnonce=\"".concat(this._cnonce, "\""));
  30461. auth_params.push("nc=".concat(this._ncHex));
  30462. }
  30463. return "Digest ".concat(auth_params.join(', '));
  30464. }
  30465. }]);
  30466. return DigestAuthentication;
  30467. }();
  30468. }),
  30469. /* 32 */
  30470. (function(module, exports, __webpack_require__) {
  30471. "use strict";
  30472. function _classCallCheck(instance, Constructor) {
  30473. if (!(instance instanceof Constructor)) {
  30474. throw new TypeError("Cannot call a class as a function");
  30475. }
  30476. }
  30477. function _defineProperties(target, props) {
  30478. for (var i = 0; i < props.length; i++) {
  30479. var descriptor = props[i];
  30480. descriptor.enumerable = descriptor.enumerable || false;
  30481. descriptor.configurable = true;
  30482. if ("value" in descriptor) descriptor.writable = true;
  30483. Object.defineProperty(target, descriptor.key, descriptor);
  30484. }
  30485. }
  30486. function _createClass(Constructor, protoProps, staticProps) {
  30487. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  30488. if (staticProps) _defineProperties(Constructor, staticProps);
  30489. return Constructor;
  30490. }
  30491. var SIPMessage = __webpack_require__(5);
  30492. var JsSIP_C = __webpack_require__(1);
  30493. var Transactions = __webpack_require__(9);
  30494. var Dialog_RequestSender = __webpack_require__(33);
  30495. var Utils = __webpack_require__(2);
  30496. var debug = __webpack_require__(0)('JsSIP:Dialog');
  30497. var C = {
  30498. // Dialog states.
  30499. STATUS_EARLY: 1,
  30500. STATUS_CONFIRMED: 2
  30501. }; // RFC 3261 12.1.
  30502. module.exports =
  30503. /*#__PURE__*/
  30504. function () {
  30505. _createClass(Dialog, null, [{
  30506. key: "C",
  30507. // Expose C object.
  30508. get: function get() {
  30509. return C;
  30510. }
  30511. }]);
  30512. function Dialog(owner, message, type) {
  30513. var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED;
  30514. _classCallCheck(this, Dialog);
  30515. this._owner = owner;
  30516. this._ua = owner._ua;
  30517. this._uac_pending_reply = false;
  30518. this._uas_pending_reply = false;
  30519. if (!message.hasHeader('contact')) {
  30520. return {
  30521. error: 'unable to create a Dialog without Contact header field'
  30522. };
  30523. }
  30524. if (message instanceof SIPMessage.IncomingResponse) {
  30525. state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED;
  30526. }
  30527. var contact = message.parseHeader('contact'); // RFC 3261 12.1.1.
  30528. if (type === 'UAS') {
  30529. this._id = {
  30530. call_id: message.call_id,
  30531. local_tag: message.to_tag,
  30532. remote_tag: message.from_tag,
  30533. toString: function toString() {
  30534. return this.call_id + this.local_tag + this.remote_tag;
  30535. }
  30536. };
  30537. this._state = state;
  30538. this._remote_seqnum = message.cseq;
  30539. this._local_uri = message.parseHeader('to').uri;
  30540. this._remote_uri = message.parseHeader('from').uri;
  30541. this._remote_target = contact.uri;
  30542. this._route_set = message.getHeaders('record-route');
  30543. this._ack_seqnum = this._remote_seqnum;
  30544. } // RFC 3261 12.1.2.
  30545. else if (type === 'UAC') {
  30546. this._id = {
  30547. call_id: message.call_id,
  30548. local_tag: message.from_tag,
  30549. remote_tag: message.to_tag,
  30550. toString: function toString() {
  30551. return this.call_id + this.local_tag + this.remote_tag;
  30552. }
  30553. };
  30554. this._state = state;
  30555. this._local_seqnum = message.cseq;
  30556. this._local_uri = message.parseHeader('from').uri;
  30557. this._remote_uri = message.parseHeader('to').uri;
  30558. this._remote_target = contact.uri;
  30559. this._route_set = message.getHeaders('record-route').reverse();
  30560. this._ack_seqnum = null;
  30561. }
  30562. this._ua.newDialog(this);
  30563. debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED'));
  30564. }
  30565. _createClass(Dialog, [{
  30566. key: "update",
  30567. value: function update(message, type) {
  30568. this._state = C.STATUS_CONFIRMED;
  30569. debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state"));
  30570. if (type === 'UAC') {
  30571. // RFC 3261 13.2.2.4.
  30572. this._route_set = message.getHeaders('record-route').reverse();
  30573. }
  30574. }
  30575. }, {
  30576. key: "terminate",
  30577. value: function terminate() {
  30578. debug("dialog ".concat(this._id.toString(), " deleted"));
  30579. this._ua.destroyDialog(this);
  30580. }
  30581. }, {
  30582. key: "sendRequest",
  30583. value: function sendRequest(method) {
  30584. var _this = this;
  30585. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  30586. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  30587. var eventHandlers = options.eventHandlers || {};
  30588. var body = options.body || null;
  30589. var request = this._createRequest(method, extraHeaders, body); // Increase the local CSeq on authentication.
  30590. eventHandlers.onAuthenticated = function () {
  30591. _this._local_seqnum += 1;
  30592. };
  30593. var request_sender = new Dialog_RequestSender(this, request, eventHandlers);
  30594. request_sender.send(); // Return the instance of OutgoingRequest.
  30595. return request;
  30596. }
  30597. }, {
  30598. key: "receiveRequest",
  30599. value: function receiveRequest(request) {
  30600. // Check in-dialog request.
  30601. if (!this._checkInDialogRequest(request)) {
  30602. return;
  30603. } // ACK received. Cleanup this._ack_seqnum.
  30604. if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) {
  30605. this._ack_seqnum = null;
  30606. } // INVITE received. Set this._ack_seqnum.
  30607. else if (request.method === JsSIP_C.INVITE) {
  30608. this._ack_seqnum = request.cseq;
  30609. }
  30610. this._owner.receiveRequest(request);
  30611. } // RFC 3261 12.2.1.1.
  30612. }, {
  30613. key: "_createRequest",
  30614. value: function _createRequest(method, extraHeaders, body) {
  30615. extraHeaders = Utils.cloneArray(extraHeaders);
  30616. if (!this._local_seqnum) {
  30617. this._local_seqnum = Math.floor(Math.random() * 10000);
  30618. }
  30619. var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1;
  30620. var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, {
  30621. 'cseq': cseq,
  30622. 'call_id': this._id.call_id,
  30623. 'from_uri': this._local_uri,
  30624. 'from_tag': this._id.local_tag,
  30625. 'to_uri': this._remote_uri,
  30626. 'to_tag': this._id.remote_tag,
  30627. 'route_set': this._route_set
  30628. }, extraHeaders, body);
  30629. return request;
  30630. } // RFC 3261 12.2.2.
  30631. }, {
  30632. key: "_checkInDialogRequest",
  30633. value: function _checkInDialogRequest(request) {
  30634. var _this2 = this;
  30635. if (!this._remote_seqnum) {
  30636. this._remote_seqnum = request.cseq;
  30637. } else if (request.cseq < this._remote_seqnum) {
  30638. if (request.method === JsSIP_C.ACK) {
  30639. // We are not expecting any ACK with lower seqnum than the current one.
  30640. // Or this is not the ACK we are waiting for.
  30641. if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) {
  30642. return false;
  30643. }
  30644. } else {
  30645. request.reply(500);
  30646. return false;
  30647. }
  30648. } else if (request.cseq > this._remote_seqnum) {
  30649. this._remote_seqnum = request.cseq;
  30650. } // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-.
  30651. if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) {
  30652. if (this._uac_pending_reply === true) {
  30653. request.reply(491);
  30654. } else if (this._uas_pending_reply === true) {
  30655. var retryAfter = (Math.random() * 10 | 0) + 1;
  30656. request.reply(500, null, ["Retry-After:".concat(retryAfter)]);
  30657. return false;
  30658. } else {
  30659. this._uas_pending_reply = true;
  30660. var stateChanged = function stateChanged() {
  30661. if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED || request.server_transaction.state === Transactions.C.STATUS_COMPLETED || request.server_transaction.state === Transactions.C.STATUS_TERMINATED) {
  30662. request.server_transaction.removeListener('stateChanged', stateChanged);
  30663. _this2._uas_pending_reply = false;
  30664. }
  30665. };
  30666. request.server_transaction.on('stateChanged', stateChanged);
  30667. } // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted.
  30668. if (request.hasHeader('contact')) {
  30669. request.server_transaction.on('stateChanged', function () {
  30670. if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED) {
  30671. _this2._remote_target = request.parseHeader('contact').uri;
  30672. }
  30673. });
  30674. }
  30675. } else if (request.method === JsSIP_C.NOTIFY) {
  30676. // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted.
  30677. if (request.hasHeader('contact')) {
  30678. request.server_transaction.on('stateChanged', function () {
  30679. if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) {
  30680. _this2._remote_target = request.parseHeader('contact').uri;
  30681. }
  30682. });
  30683. }
  30684. }
  30685. return true;
  30686. }
  30687. }, {
  30688. key: "id",
  30689. get: function get() {
  30690. return this._id;
  30691. }
  30692. }, {
  30693. key: "local_seqnum",
  30694. get: function get() {
  30695. return this._local_seqnum;
  30696. },
  30697. set: function set(num) {
  30698. this._local_seqnum = num;
  30699. }
  30700. }, {
  30701. key: "owner",
  30702. get: function get() {
  30703. return this._owner;
  30704. }
  30705. }, {
  30706. key: "uac_pending_reply",
  30707. get: function get() {
  30708. return this._uac_pending_reply;
  30709. },
  30710. set: function set(pending) {
  30711. this._uac_pending_reply = pending;
  30712. }
  30713. }, {
  30714. key: "uas_pending_reply",
  30715. get: function get() {
  30716. return this._uas_pending_reply;
  30717. }
  30718. }]);
  30719. return Dialog;
  30720. }();
  30721. }),
  30722. /* 33 */
  30723. (function(module, exports, __webpack_require__) {
  30724. "use strict";
  30725. function _classCallCheck(instance, Constructor) {
  30726. if (!(instance instanceof Constructor)) {
  30727. throw new TypeError("Cannot call a class as a function");
  30728. }
  30729. }
  30730. function _defineProperties(target, props) {
  30731. for (var i = 0; i < props.length; i++) {
  30732. var descriptor = props[i];
  30733. descriptor.enumerable = descriptor.enumerable || false;
  30734. descriptor.configurable = true;
  30735. if ("value" in descriptor) descriptor.writable = true;
  30736. Object.defineProperty(target, descriptor.key, descriptor);
  30737. }
  30738. }
  30739. function _createClass(Constructor, protoProps, staticProps) {
  30740. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  30741. if (staticProps) _defineProperties(Constructor, staticProps);
  30742. return Constructor;
  30743. }
  30744. var JsSIP_C = __webpack_require__(1);
  30745. var Transactions = __webpack_require__(9);
  30746. var RTCSession = __webpack_require__(17);
  30747. var RequestSender = __webpack_require__(10); // Default event handlers.
  30748. var EventHandlers = {
  30749. onRequestTimeout: function onRequestTimeout() {},
  30750. onTransportError: function onTransportError() {},
  30751. onSuccessResponse: function onSuccessResponse() {},
  30752. onErrorResponse: function onErrorResponse() {},
  30753. onAuthenticated: function onAuthenticated() {},
  30754. onDialogError: function onDialogError() {}
  30755. };
  30756. module.exports =
  30757. /*#__PURE__*/
  30758. function () {
  30759. function DialogRequestSender(dialog, request, eventHandlers) {
  30760. _classCallCheck(this, DialogRequestSender);
  30761. this._dialog = dialog;
  30762. this._ua = dialog._ua;
  30763. this._request = request;
  30764. this._eventHandlers = eventHandlers; // RFC3261 14.1 Modifying an Existing Session. UAC Behavior.
  30765. this._reattempt = false;
  30766. this._reattemptTimer = null; // Define the undefined handlers.
  30767. for (var handler in EventHandlers) {
  30768. if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
  30769. if (!this._eventHandlers[handler]) {
  30770. this._eventHandlers[handler] = EventHandlers[handler];
  30771. }
  30772. }
  30773. }
  30774. }
  30775. _createClass(DialogRequestSender, [{
  30776. key: "send",
  30777. value: function send() {
  30778. var _this = this;
  30779. var request_sender = new RequestSender(this._ua, this._request, {
  30780. onRequestTimeout: function onRequestTimeout() {
  30781. _this._eventHandlers.onRequestTimeout();
  30782. },
  30783. onTransportError: function onTransportError() {
  30784. _this._eventHandlers.onTransportError();
  30785. },
  30786. onAuthenticated: function onAuthenticated(request) {
  30787. _this._eventHandlers.onAuthenticated(request);
  30788. },
  30789. onReceiveResponse: function onReceiveResponse(response) {
  30790. _this._receiveResponse(response);
  30791. }
  30792. });
  30793. request_sender.send(); // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-.
  30794. if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) {
  30795. this._dialog.uac_pending_reply = true;
  30796. var stateChanged = function stateChanged() {
  30797. if (request_sender.clientTransaction.state === Transactions.C.STATUS_ACCEPTED || request_sender.clientTransaction.state === Transactions.C.STATUS_COMPLETED || request_sender.clientTransaction.state === Transactions.C.STATUS_TERMINATED) {
  30798. request_sender.clientTransaction.removeListener('stateChanged', stateChanged);
  30799. _this._dialog.uac_pending_reply = false;
  30800. }
  30801. };
  30802. request_sender.clientTransaction.on('stateChanged', stateChanged);
  30803. }
  30804. }
  30805. }, {
  30806. key: "_receiveResponse",
  30807. value: function _receiveResponse(response) {
  30808. var _this2 = this; // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog.
  30809. if (response.status_code === 408 || response.status_code === 481) {
  30810. this._eventHandlers.onDialogError(response);
  30811. } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) {
  30812. if (this._reattempt) {
  30813. if (response.status_code >= 200 && response.status_code < 300) {
  30814. this._eventHandlers.onSuccessResponse(response);
  30815. } else if (response.status_code >= 300) {
  30816. this._eventHandlers.onErrorResponse(response);
  30817. }
  30818. } else {
  30819. this._request.cseq.value = this._dialog.local_seqnum += 1;
  30820. this._reattemptTimer = setTimeout(function () {
  30821. // TODO: look at dialog state instead.
  30822. if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) {
  30823. _this2._reattempt = true;
  30824. _this2._request_sender.send();
  30825. }
  30826. }, 1000);
  30827. }
  30828. } else if (response.status_code >= 200 && response.status_code < 300) {
  30829. this._eventHandlers.onSuccessResponse(response);
  30830. } else if (response.status_code >= 300) {
  30831. this._eventHandlers.onErrorResponse(response);
  30832. }
  30833. }
  30834. }, {
  30835. key: "request",
  30836. get: function get() {
  30837. return this._request;
  30838. }
  30839. }]);
  30840. return DialogRequestSender;
  30841. }();
  30842. }),
  30843. /* 34 */
  30844. (function(module, exports, __webpack_require__) {
  30845. "use strict";
  30846. function _typeof(obj) {
  30847. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  30848. _typeof = function _typeof(obj) {
  30849. return typeof obj;
  30850. };
  30851. } else {
  30852. _typeof = function _typeof(obj) {
  30853. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  30854. };
  30855. }
  30856. return _typeof(obj);
  30857. }
  30858. function _classCallCheck(instance, Constructor) {
  30859. if (!(instance instanceof Constructor)) {
  30860. throw new TypeError("Cannot call a class as a function");
  30861. }
  30862. }
  30863. function _defineProperties(target, props) {
  30864. for (var i = 0; i < props.length; i++) {
  30865. var descriptor = props[i];
  30866. descriptor.enumerable = descriptor.enumerable || false;
  30867. descriptor.configurable = true;
  30868. if ("value" in descriptor) descriptor.writable = true;
  30869. Object.defineProperty(target, descriptor.key, descriptor);
  30870. }
  30871. }
  30872. function _createClass(Constructor, protoProps, staticProps) {
  30873. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  30874. if (staticProps) _defineProperties(Constructor, staticProps);
  30875. return Constructor;
  30876. }
  30877. function _possibleConstructorReturn(self, call) {
  30878. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  30879. return call;
  30880. }
  30881. return _assertThisInitialized(self);
  30882. }
  30883. function _assertThisInitialized(self) {
  30884. if (self === void 0) {
  30885. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  30886. }
  30887. return self;
  30888. }
  30889. function _getPrototypeOf(o) {
  30890. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  30891. return o.__proto__ || Object.getPrototypeOf(o);
  30892. };
  30893. return _getPrototypeOf(o);
  30894. }
  30895. function _inherits(subClass, superClass) {
  30896. if (typeof superClass !== "function" && superClass !== null) {
  30897. throw new TypeError("Super expression must either be null or a function");
  30898. }
  30899. subClass.prototype = Object.create(superClass && superClass.prototype, {
  30900. constructor: {
  30901. value: subClass,
  30902. writable: true,
  30903. configurable: true
  30904. }
  30905. });
  30906. if (superClass) _setPrototypeOf(subClass, superClass);
  30907. }
  30908. function _setPrototypeOf(o, p) {
  30909. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  30910. o.__proto__ = p;
  30911. return o;
  30912. };
  30913. return _setPrototypeOf(o, p);
  30914. }
  30915. var EventEmitter = __webpack_require__(7).EventEmitter;
  30916. var JsSIP_C = __webpack_require__(1);
  30917. var Exceptions = __webpack_require__(6);
  30918. var Utils = __webpack_require__(2);
  30919. var debug = __webpack_require__(0)('JsSIP:RTCSession:DTMF');
  30920. var debugerror = __webpack_require__(0)('JsSIP:ERROR:RTCSession:DTMF');
  30921. debugerror.log = console.warn.bind(console);
  30922. var C = {
  30923. MIN_DURATION: 70,
  30924. MAX_DURATION: 6000,
  30925. DEFAULT_DURATION: 100,
  30926. MIN_INTER_TONE_GAP: 50,
  30927. DEFAULT_INTER_TONE_GAP: 500
  30928. };
  30929. module.exports =
  30930. /*#__PURE__*/
  30931. function (_EventEmitter) {
  30932. _inherits(DTMF, _EventEmitter);
  30933. function DTMF(session) {
  30934. var _this;
  30935. _classCallCheck(this, DTMF);
  30936. _this = _possibleConstructorReturn(this, _getPrototypeOf(DTMF).call(this));
  30937. _this._session = session;
  30938. _this._direction = null;
  30939. _this._tone = null;
  30940. _this._duration = null;
  30941. _this._request = null;
  30942. return _this;
  30943. }
  30944. _createClass(DTMF, [{
  30945. key: "send",
  30946. value: function send(tone) {
  30947. var _this2 = this;
  30948. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  30949. if (tone === undefined) {
  30950. throw new TypeError('Not enough arguments');
  30951. }
  30952. this._direction = 'outgoing'; // Check RTCSession Status.
  30953. if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
  30954. throw new Exceptions.InvalidStateError(this._session.status);
  30955. }
  30956. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  30957. this.eventHandlers = options.eventHandlers || {}; // Check tone type.
  30958. if (typeof tone === 'string') {
  30959. tone = tone.toUpperCase();
  30960. } else if (typeof tone === 'number') {
  30961. tone = tone.toString();
  30962. } else {
  30963. throw new TypeError("Invalid tone: ".concat(tone));
  30964. } // Check tone value.
  30965. if (!tone.match(/^[0-9A-DR#*]$/)) {
  30966. throw new TypeError("Invalid tone: ".concat(tone));
  30967. } else {
  30968. this._tone = tone;
  30969. } // Duration is checked/corrected in RTCSession.
  30970. this._duration = options.duration;
  30971. extraHeaders.push('Content-Type: application/dtmf-relay');
  30972. var body = "Signal=".concat(this._tone, "\r\n");
  30973. body += "Duration=".concat(this._duration);
  30974. this._session.newDTMF({
  30975. originator: 'local',
  30976. dtmf: this,
  30977. request: this._request
  30978. });
  30979. this._session.sendRequest(JsSIP_C.INFO, {
  30980. extraHeaders: extraHeaders,
  30981. eventHandlers: {
  30982. onSuccessResponse: function onSuccessResponse(response) {
  30983. _this2.emit('succeeded', {
  30984. originator: 'remote',
  30985. response: response
  30986. });
  30987. },
  30988. onErrorResponse: function onErrorResponse(response) {
  30989. if (_this2.eventHandlers.onFailed) {
  30990. _this2.eventHandlers.onFailed();
  30991. }
  30992. _this2.emit('failed', {
  30993. originator: 'remote',
  30994. response: response
  30995. });
  30996. },
  30997. onRequestTimeout: function onRequestTimeout() {
  30998. _this2._session.onRequestTimeout();
  30999. },
  31000. onTransportError: function onTransportError() {
  31001. _this2._session.onTransportError();
  31002. },
  31003. onDialogError: function onDialogError() {
  31004. _this2._session.onDialogError();
  31005. }
  31006. },
  31007. body: body
  31008. });
  31009. }
  31010. }, {
  31011. key: "init_incoming",
  31012. value: function init_incoming(request) {
  31013. var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;
  31014. var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;
  31015. this._direction = 'incoming';
  31016. this._request = request;
  31017. request.reply(200);
  31018. if (request.body) {
  31019. var body = request.body.split('\n');
  31020. if (body.length >= 1) {
  31021. if (reg_tone.test(body[0])) {
  31022. this._tone = body[0].replace(reg_tone, '$2');
  31023. }
  31024. }
  31025. if (body.length >= 2) {
  31026. if (reg_duration.test(body[1])) {
  31027. this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10);
  31028. }
  31029. }
  31030. }
  31031. if (!this._duration) {
  31032. this._duration = C.DEFAULT_DURATION;
  31033. }
  31034. if (!this._tone) {
  31035. debug('invalid INFO DTMF received, discarded');
  31036. } else {
  31037. this._session.newDTMF({
  31038. originator: 'remote',
  31039. dtmf: this,
  31040. request: request
  31041. });
  31042. }
  31043. }
  31044. }, {
  31045. key: "tone",
  31046. get: function get() {
  31047. return this._tone;
  31048. }
  31049. }, {
  31050. key: "duration",
  31051. get: function get() {
  31052. return this._duration;
  31053. }
  31054. }]);
  31055. return DTMF;
  31056. }(EventEmitter);
  31057. /**
  31058. * Expose C object.
  31059. */
  31060. module.exports.C = C;
  31061. }),
  31062. /* 35 */
  31063. (function(module, exports, __webpack_require__) {
  31064. "use strict";
  31065. function _typeof(obj) {
  31066. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  31067. _typeof = function _typeof(obj) {
  31068. return typeof obj;
  31069. };
  31070. } else {
  31071. _typeof = function _typeof(obj) {
  31072. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  31073. };
  31074. }
  31075. return _typeof(obj);
  31076. }
  31077. function _classCallCheck(instance, Constructor) {
  31078. if (!(instance instanceof Constructor)) {
  31079. throw new TypeError("Cannot call a class as a function");
  31080. }
  31081. }
  31082. function _defineProperties(target, props) {
  31083. for (var i = 0; i < props.length; i++) {
  31084. var descriptor = props[i];
  31085. descriptor.enumerable = descriptor.enumerable || false;
  31086. descriptor.configurable = true;
  31087. if ("value" in descriptor) descriptor.writable = true;
  31088. Object.defineProperty(target, descriptor.key, descriptor);
  31089. }
  31090. }
  31091. function _createClass(Constructor, protoProps, staticProps) {
  31092. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  31093. if (staticProps) _defineProperties(Constructor, staticProps);
  31094. return Constructor;
  31095. }
  31096. function _possibleConstructorReturn(self, call) {
  31097. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  31098. return call;
  31099. }
  31100. return _assertThisInitialized(self);
  31101. }
  31102. function _assertThisInitialized(self) {
  31103. if (self === void 0) {
  31104. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  31105. }
  31106. return self;
  31107. }
  31108. function _getPrototypeOf(o) {
  31109. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  31110. return o.__proto__ || Object.getPrototypeOf(o);
  31111. };
  31112. return _getPrototypeOf(o);
  31113. }
  31114. function _inherits(subClass, superClass) {
  31115. if (typeof superClass !== "function" && superClass !== null) {
  31116. throw new TypeError("Super expression must either be null or a function");
  31117. }
  31118. subClass.prototype = Object.create(superClass && superClass.prototype, {
  31119. constructor: {
  31120. value: subClass,
  31121. writable: true,
  31122. configurable: true
  31123. }
  31124. });
  31125. if (superClass) _setPrototypeOf(subClass, superClass);
  31126. }
  31127. function _setPrototypeOf(o, p) {
  31128. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  31129. o.__proto__ = p;
  31130. return o;
  31131. };
  31132. return _setPrototypeOf(o, p);
  31133. }
  31134. var EventEmitter = __webpack_require__(7).EventEmitter;
  31135. var debugerror = __webpack_require__(0)('JsSIP:ERROR:RTCSession:Info');
  31136. debugerror.log = console.warn.bind(console);
  31137. var JsSIP_C = __webpack_require__(1);
  31138. var Exceptions = __webpack_require__(6);
  31139. var Utils = __webpack_require__(2);
  31140. module.exports =
  31141. /*#__PURE__*/
  31142. function (_EventEmitter) {
  31143. _inherits(Info, _EventEmitter);
  31144. function Info(session) {
  31145. var _this;
  31146. _classCallCheck(this, Info);
  31147. _this = _possibleConstructorReturn(this, _getPrototypeOf(Info).call(this));
  31148. _this._session = session;
  31149. _this._direction = null;
  31150. _this._contentType = null;
  31151. _this._body = null;
  31152. return _this;
  31153. }
  31154. _createClass(Info, [{
  31155. key: "send",
  31156. value: function send(contentType, body) {
  31157. var _this2 = this;
  31158. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  31159. this._direction = 'outgoing';
  31160. if (contentType === undefined) {
  31161. throw new TypeError('Not enough arguments');
  31162. } // Check RTCSession Status.
  31163. if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
  31164. throw new Exceptions.InvalidStateError(this._session.status);
  31165. }
  31166. this._contentType = contentType;
  31167. this._body = body;
  31168. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  31169. extraHeaders.push("Content-Type: ".concat(contentType));
  31170. this._session.newInfo({
  31171. originator: 'local',
  31172. info: this,
  31173. request: this.request
  31174. });
  31175. this._session.sendRequest(JsSIP_C.INFO, {
  31176. extraHeaders: extraHeaders,
  31177. eventHandlers: {
  31178. onSuccessResponse: function onSuccessResponse(response) {
  31179. _this2.emit('succeeded', {
  31180. originator: 'remote',
  31181. response: response
  31182. });
  31183. },
  31184. onErrorResponse: function onErrorResponse(response) {
  31185. _this2.emit('failed', {
  31186. originator: 'remote',
  31187. response: response
  31188. });
  31189. },
  31190. onTransportError: function onTransportError() {
  31191. _this2._session.onTransportError();
  31192. },
  31193. onRequestTimeout: function onRequestTimeout() {
  31194. _this2._session.onRequestTimeout();
  31195. },
  31196. onDialogError: function onDialogError() {
  31197. _this2._session.onDialogError();
  31198. }
  31199. },
  31200. body: body
  31201. });
  31202. }
  31203. }, {
  31204. key: "init_incoming",
  31205. value: function init_incoming(request) {
  31206. this._direction = 'incoming';
  31207. this.request = request;
  31208. request.reply(200);
  31209. this._contentType = request.getHeader('content-type');
  31210. this._body = request.body;
  31211. this._session.newInfo({
  31212. originator: 'remote',
  31213. info: this,
  31214. request: request
  31215. });
  31216. }
  31217. }, {
  31218. key: "contentType",
  31219. get: function get() {
  31220. return this._contentType;
  31221. }
  31222. }, {
  31223. key: "body",
  31224. get: function get() {
  31225. return this._body;
  31226. }
  31227. }]);
  31228. return Info;
  31229. }(EventEmitter);
  31230. }),
  31231. /* 36 */
  31232. (function(module, exports, __webpack_require__) {
  31233. "use strict";
  31234. function _classCallCheck(instance, Constructor) {
  31235. if (!(instance instanceof Constructor)) {
  31236. throw new TypeError("Cannot call a class as a function");
  31237. }
  31238. }
  31239. function _defineProperties(target, props) {
  31240. for (var i = 0; i < props.length; i++) {
  31241. var descriptor = props[i];
  31242. descriptor.enumerable = descriptor.enumerable || false;
  31243. descriptor.configurable = true;
  31244. if ("value" in descriptor) descriptor.writable = true;
  31245. Object.defineProperty(target, descriptor.key, descriptor);
  31246. }
  31247. }
  31248. function _createClass(Constructor, protoProps, staticProps) {
  31249. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  31250. if (staticProps) _defineProperties(Constructor, staticProps);
  31251. return Constructor;
  31252. }
  31253. var JsSIP_C = __webpack_require__(1);
  31254. var debug = __webpack_require__(0)('JsSIP:RTCSession:ReferNotifier');
  31255. var C = {
  31256. event_type: 'refer',
  31257. body_type: 'message/sipfrag;version=2.0',
  31258. expires: 300
  31259. };
  31260. module.exports =
  31261. /*#__PURE__*/
  31262. function () {
  31263. function ReferNotifier(session, id, expires) {
  31264. _classCallCheck(this, ReferNotifier);
  31265. this._session = session;
  31266. this._id = id;
  31267. this._expires = expires || C.expires;
  31268. this._active = true; // The creation of a Notifier results in an immediate NOTIFY.
  31269. this.notify(100);
  31270. }
  31271. _createClass(ReferNotifier, [{
  31272. key: "notify",
  31273. value: function notify(code, reason) {
  31274. debug('notify()');
  31275. if (this._active === false) {
  31276. return;
  31277. }
  31278. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  31279. var state;
  31280. if (code >= 200) {
  31281. state = 'terminated;reason=noresource';
  31282. } else {
  31283. state = "active;expires=".concat(this._expires);
  31284. } // Put this in a try/catch block.
  31285. this._session.sendRequest(JsSIP_C.NOTIFY, {
  31286. extraHeaders: ["Event: ".concat(C.event_type, ";id=").concat(this._id), "Subscription-State: ".concat(state), "Content-Type: ".concat(C.body_type)],
  31287. body: "SIP/2.0 ".concat(code, " ").concat(reason),
  31288. eventHandlers: {
  31289. // If a negative response is received, subscription is canceled.
  31290. onErrorResponse: function onErrorResponse() {
  31291. this._active = false;
  31292. }
  31293. }
  31294. });
  31295. }
  31296. }]);
  31297. return ReferNotifier;
  31298. }();
  31299. }),
  31300. /* 37 */
  31301. (function(module, exports, __webpack_require__) {
  31302. "use strict";
  31303. function _typeof(obj) {
  31304. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  31305. _typeof = function _typeof(obj) {
  31306. return typeof obj;
  31307. };
  31308. } else {
  31309. _typeof = function _typeof(obj) {
  31310. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  31311. };
  31312. }
  31313. return _typeof(obj);
  31314. }
  31315. function _classCallCheck(instance, Constructor) {
  31316. if (!(instance instanceof Constructor)) {
  31317. throw new TypeError("Cannot call a class as a function");
  31318. }
  31319. }
  31320. function _defineProperties(target, props) {
  31321. for (var i = 0; i < props.length; i++) {
  31322. var descriptor = props[i];
  31323. descriptor.enumerable = descriptor.enumerable || false;
  31324. descriptor.configurable = true;
  31325. if ("value" in descriptor) descriptor.writable = true;
  31326. Object.defineProperty(target, descriptor.key, descriptor);
  31327. }
  31328. }
  31329. function _createClass(Constructor, protoProps, staticProps) {
  31330. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  31331. if (staticProps) _defineProperties(Constructor, staticProps);
  31332. return Constructor;
  31333. }
  31334. function _possibleConstructorReturn(self, call) {
  31335. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  31336. return call;
  31337. }
  31338. return _assertThisInitialized(self);
  31339. }
  31340. function _assertThisInitialized(self) {
  31341. if (self === void 0) {
  31342. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  31343. }
  31344. return self;
  31345. }
  31346. function _getPrototypeOf(o) {
  31347. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  31348. return o.__proto__ || Object.getPrototypeOf(o);
  31349. };
  31350. return _getPrototypeOf(o);
  31351. }
  31352. function _inherits(subClass, superClass) {
  31353. if (typeof superClass !== "function" && superClass !== null) {
  31354. throw new TypeError("Super expression must either be null or a function");
  31355. }
  31356. subClass.prototype = Object.create(superClass && superClass.prototype, {
  31357. constructor: {
  31358. value: subClass,
  31359. writable: true,
  31360. configurable: true
  31361. }
  31362. });
  31363. if (superClass) _setPrototypeOf(subClass, superClass);
  31364. }
  31365. function _setPrototypeOf(o, p) {
  31366. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  31367. o.__proto__ = p;
  31368. return o;
  31369. };
  31370. return _setPrototypeOf(o, p);
  31371. }
  31372. var EventEmitter = __webpack_require__(7).EventEmitter;
  31373. var JsSIP_C = __webpack_require__(1);
  31374. var Grammar = __webpack_require__(3);
  31375. var Utils = __webpack_require__(2);
  31376. var debug = __webpack_require__(0)('JsSIP:RTCSession:ReferSubscriber');
  31377. module.exports =
  31378. /*#__PURE__*/
  31379. function (_EventEmitter) {
  31380. _inherits(ReferSubscriber, _EventEmitter);
  31381. function ReferSubscriber(session) {
  31382. var _this;
  31383. _classCallCheck(this, ReferSubscriber);
  31384. _this = _possibleConstructorReturn(this, _getPrototypeOf(ReferSubscriber).call(this));
  31385. _this._id = null;
  31386. _this._session = session;
  31387. return _this;
  31388. }
  31389. _createClass(ReferSubscriber, [{
  31390. key: "sendRefer",
  31391. value: function sendRefer(target) {
  31392. var _this2 = this;
  31393. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31394. debug('sendRefer()');
  31395. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  31396. var eventHandlers = options.eventHandlers || {}; // Set event handlers.
  31397. for (var event in eventHandlers) {
  31398. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  31399. this.on(event, eventHandlers[event]);
  31400. }
  31401. } // Replaces URI header field.
  31402. var replaces = null;
  31403. if (options.replaces) {
  31404. replaces = options.replaces._request.call_id;
  31405. replaces += ";to-tag=".concat(options.replaces._to_tag);
  31406. replaces += ";from-tag=".concat(options.replaces._from_tag);
  31407. replaces = encodeURIComponent(replaces);
  31408. } // Refer-To header field.
  31409. var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">");
  31410. extraHeaders.push(referTo);
  31411. extraHeaders.push("Contact: ".concat(this._session.contact));
  31412. var request = this._session.sendRequest(JsSIP_C.REFER, {
  31413. extraHeaders: extraHeaders,
  31414. eventHandlers: {
  31415. onSuccessResponse: function onSuccessResponse(response) {
  31416. _this2._requestSucceeded(response);
  31417. },
  31418. onErrorResponse: function onErrorResponse(response) {
  31419. _this2._requestFailed(response, JsSIP_C.causes.REJECTED);
  31420. },
  31421. onTransportError: function onTransportError() {
  31422. _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR);
  31423. },
  31424. onRequestTimeout: function onRequestTimeout() {
  31425. _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  31426. },
  31427. onDialogError: function onDialogError() {
  31428. _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR);
  31429. }
  31430. }
  31431. });
  31432. this._id = request.cseq;
  31433. }
  31434. }, {
  31435. key: "receiveNotify",
  31436. value: function receiveNotify(request) {
  31437. debug('receiveNotify()');
  31438. if (!request.body) {
  31439. return;
  31440. }
  31441. var status_line = Grammar.parse(request.body.trim(), 'Status_Line');
  31442. if (status_line === -1) {
  31443. debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\""));
  31444. return;
  31445. }
  31446. switch (true) {
  31447. case /^100$/.test(status_line.status_code):
  31448. this.emit('trying', {
  31449. request: request,
  31450. status_line: status_line
  31451. });
  31452. break;
  31453. case /^1[0-9]{2}$/.test(status_line.status_code):
  31454. this.emit('progress', {
  31455. request: request,
  31456. status_line: status_line
  31457. });
  31458. break;
  31459. case /^2[0-9]{2}$/.test(status_line.status_code):
  31460. this.emit('accepted', {
  31461. request: request,
  31462. status_line: status_line
  31463. });
  31464. break;
  31465. default:
  31466. this.emit('failed', {
  31467. request: request,
  31468. status_line: status_line
  31469. });
  31470. break;
  31471. }
  31472. }
  31473. }, {
  31474. key: "_requestSucceeded",
  31475. value: function _requestSucceeded(response) {
  31476. debug('REFER succeeded');
  31477. debug('emit "requestSucceeded"');
  31478. this.emit('requestSucceeded', {
  31479. response: response
  31480. });
  31481. }
  31482. }, {
  31483. key: "_requestFailed",
  31484. value: function _requestFailed(response, cause) {
  31485. debug('REFER failed');
  31486. debug('emit "requestFailed"');
  31487. this.emit('requestFailed', {
  31488. response: response || null,
  31489. cause: cause
  31490. });
  31491. }
  31492. }, {
  31493. key: "id",
  31494. get: function get() {
  31495. return this._id;
  31496. }
  31497. }]);
  31498. return ReferSubscriber;
  31499. }(EventEmitter);
  31500. }),
  31501. /* 38 */
  31502. (function(module, exports, __webpack_require__) {
  31503. "use strict";
  31504. function _typeof(obj) {
  31505. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  31506. _typeof = function _typeof(obj) {
  31507. return typeof obj;
  31508. };
  31509. } else {
  31510. _typeof = function _typeof(obj) {
  31511. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  31512. };
  31513. }
  31514. return _typeof(obj);
  31515. }
  31516. function _classCallCheck(instance, Constructor) {
  31517. if (!(instance instanceof Constructor)) {
  31518. throw new TypeError("Cannot call a class as a function");
  31519. }
  31520. }
  31521. function _defineProperties(target, props) {
  31522. for (var i = 0; i < props.length; i++) {
  31523. var descriptor = props[i];
  31524. descriptor.enumerable = descriptor.enumerable || false;
  31525. descriptor.configurable = true;
  31526. if ("value" in descriptor) descriptor.writable = true;
  31527. Object.defineProperty(target, descriptor.key, descriptor);
  31528. }
  31529. }
  31530. function _createClass(Constructor, protoProps, staticProps) {
  31531. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  31532. if (staticProps) _defineProperties(Constructor, staticProps);
  31533. return Constructor;
  31534. }
  31535. function _possibleConstructorReturn(self, call) {
  31536. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  31537. return call;
  31538. }
  31539. return _assertThisInitialized(self);
  31540. }
  31541. function _assertThisInitialized(self) {
  31542. if (self === void 0) {
  31543. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  31544. }
  31545. return self;
  31546. }
  31547. function _getPrototypeOf(o) {
  31548. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  31549. return o.__proto__ || Object.getPrototypeOf(o);
  31550. };
  31551. return _getPrototypeOf(o);
  31552. }
  31553. function _inherits(subClass, superClass) {
  31554. if (typeof superClass !== "function" && superClass !== null) {
  31555. throw new TypeError("Super expression must either be null or a function");
  31556. }
  31557. subClass.prototype = Object.create(superClass && superClass.prototype, {
  31558. constructor: {
  31559. value: subClass,
  31560. writable: true,
  31561. configurable: true
  31562. }
  31563. });
  31564. if (superClass) _setPrototypeOf(subClass, superClass);
  31565. }
  31566. function _setPrototypeOf(o, p) {
  31567. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  31568. o.__proto__ = p;
  31569. return o;
  31570. };
  31571. return _setPrototypeOf(o, p);
  31572. }
  31573. var EventEmitter = __webpack_require__(7).EventEmitter;
  31574. var JsSIP_C = __webpack_require__(1);
  31575. var SIPMessage = __webpack_require__(5);
  31576. var Utils = __webpack_require__(2);
  31577. var RequestSender = __webpack_require__(10);
  31578. var Exceptions = __webpack_require__(6);
  31579. var debug = __webpack_require__(0)('JsSIP:Message');
  31580. module.exports =
  31581. /*#__PURE__*/
  31582. function (_EventEmitter) {
  31583. _inherits(Message, _EventEmitter);
  31584. function Message(ua) {
  31585. var _this;
  31586. _classCallCheck(this, Message);
  31587. _this = _possibleConstructorReturn(this, _getPrototypeOf(Message).call(this));
  31588. _this._ua = ua;
  31589. _this._request = null;
  31590. _this._closed = false;
  31591. _this._direction = null;
  31592. _this._local_identity = null;
  31593. _this._remote_identity = null; // Whether an incoming message has been replied.
  31594. _this._is_replied = false; // Custom message empty object for high level use.
  31595. _this._data = {};
  31596. return _this;
  31597. }
  31598. _createClass(Message, [{
  31599. key: "send",
  31600. value: function send(target, body) {
  31601. var _this2 = this;
  31602. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  31603. var originalTarget = target;
  31604. if (target === undefined || body === undefined) {
  31605. throw new TypeError('Not enough arguments');
  31606. } // Check target validity.
  31607. target = this._ua.normalizeTarget(target);
  31608. if (!target) {
  31609. throw new TypeError("Invalid target: ".concat(originalTarget));
  31610. } // Get call options.
  31611. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  31612. var eventHandlers = options.eventHandlers || {};
  31613. var contentType = options.contentType || 'text/plain'; // Set event handlers.
  31614. for (var event in eventHandlers) {
  31615. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  31616. this.on(event, eventHandlers[event]);
  31617. }
  31618. }
  31619. extraHeaders.push("Content-Type: ".concat(contentType));
  31620. this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, null, extraHeaders);
  31621. if (body) {
  31622. this._request.body = body;
  31623. }
  31624. var request_sender = new RequestSender(this._ua, this._request, {
  31625. onRequestTimeout: function onRequestTimeout() {
  31626. _this2._onRequestTimeout();
  31627. },
  31628. onTransportError: function onTransportError() {
  31629. _this2._onTransportError();
  31630. },
  31631. onReceiveResponse: function onReceiveResponse(response) {
  31632. _this2._receiveResponse(response);
  31633. }
  31634. });
  31635. this._newMessage('local', this._request);
  31636. request_sender.send();
  31637. }
  31638. }, {
  31639. key: "init_incoming",
  31640. value: function init_incoming(request) {
  31641. this._request = request;
  31642. this._newMessage('remote', request); // Reply with a 200 OK if the user didn't reply.
  31643. if (!this._is_replied) {
  31644. this._is_replied = true;
  31645. request.reply(200);
  31646. }
  31647. this._close();
  31648. }
  31649. /**
  31650. * Accept the incoming Message
  31651. * Only valid for incoming Messages
  31652. */
  31653. }, {
  31654. key: "accept",
  31655. value: function accept() {
  31656. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31657. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  31658. var body = options.body;
  31659. if (this._direction !== 'incoming') {
  31660. throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message');
  31661. }
  31662. if (this._is_replied) {
  31663. throw new Error('incoming Message already replied');
  31664. }
  31665. this._is_replied = true;
  31666. this._request.reply(200, null, extraHeaders, body);
  31667. }
  31668. /**
  31669. * Reject the incoming Message
  31670. * Only valid for incoming Messages
  31671. */
  31672. }, {
  31673. key: "reject",
  31674. value: function reject() {
  31675. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31676. var status_code = options.status_code || 480;
  31677. var reason_phrase = options.reason_phrase;
  31678. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  31679. var body = options.body;
  31680. if (this._direction !== 'incoming') {
  31681. throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message');
  31682. }
  31683. if (this._is_replied) {
  31684. throw new Error('incoming Message already replied');
  31685. }
  31686. if (status_code < 300 || status_code >= 700) {
  31687. throw new TypeError("Invalid status_code: ".concat(status_code));
  31688. }
  31689. this._is_replied = true;
  31690. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  31691. }
  31692. }, {
  31693. key: "_receiveResponse",
  31694. value: function _receiveResponse(response) {
  31695. if (this._closed) {
  31696. return;
  31697. }
  31698. switch (true) {
  31699. case /^1[0-9]{2}$/.test(response.status_code):
  31700. // Ignore provisional responses.
  31701. break;
  31702. case /^2[0-9]{2}$/.test(response.status_code):
  31703. this._succeeded('remote', response);
  31704. break;
  31705. default:
  31706. {
  31707. var cause = Utils.sipErrorCause(response.status_code);
  31708. this._failed('remote', response, cause);
  31709. break;
  31710. }
  31711. }
  31712. }
  31713. }, {
  31714. key: "_onRequestTimeout",
  31715. value: function _onRequestTimeout() {
  31716. if (this._closed) {
  31717. return;
  31718. }
  31719. this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT);
  31720. }
  31721. }, {
  31722. key: "_onTransportError",
  31723. value: function _onTransportError() {
  31724. if (this._closed) {
  31725. return;
  31726. }
  31727. this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  31728. }
  31729. }, {
  31730. key: "_close",
  31731. value: function _close() {
  31732. this._closed = true;
  31733. this._ua.destroyMessage(this);
  31734. }
  31735. /**
  31736. * Internal Callbacks
  31737. */
  31738. }, {
  31739. key: "_newMessage",
  31740. value: function _newMessage(originator, request) {
  31741. if (originator === 'remote') {
  31742. this._direction = 'incoming';
  31743. this._local_identity = request.to;
  31744. this._remote_identity = request.from;
  31745. } else if (originator === 'local') {
  31746. this._direction = 'outgoing';
  31747. this._local_identity = request.from;
  31748. this._remote_identity = request.to;
  31749. }
  31750. this._ua.newMessage(this, {
  31751. originator: originator,
  31752. message: this,
  31753. request: request
  31754. });
  31755. }
  31756. }, {
  31757. key: "_failed",
  31758. value: function _failed(originator, response, cause) {
  31759. debug('MESSAGE failed');
  31760. this._close();
  31761. debug('emit "failed"');
  31762. this.emit('failed', {
  31763. originator: originator,
  31764. response: response || null,
  31765. cause: cause
  31766. });
  31767. }
  31768. }, {
  31769. key: "_succeeded",
  31770. value: function _succeeded(originator, response) {
  31771. debug('MESSAGE succeeded');
  31772. this._close();
  31773. debug('emit "succeeded"');
  31774. this.emit('succeeded', {
  31775. originator: originator,
  31776. response: response
  31777. });
  31778. }
  31779. }, {
  31780. key: "direction",
  31781. get: function get() {
  31782. return this._direction;
  31783. }
  31784. }, {
  31785. key: "local_identity",
  31786. get: function get() {
  31787. return this._local_identity;
  31788. }
  31789. }, {
  31790. key: "remote_identity",
  31791. get: function get() {
  31792. return this._remote_identity;
  31793. }
  31794. }]);
  31795. return Message;
  31796. }(EventEmitter);
  31797. }),
  31798. /* 39 */
  31799. (function(module, exports, __webpack_require__) {
  31800. "use strict";
  31801. function _classCallCheck(instance, Constructor) {
  31802. if (!(instance instanceof Constructor)) {
  31803. throw new TypeError("Cannot call a class as a function");
  31804. }
  31805. }
  31806. function _defineProperties(target, props) {
  31807. for (var i = 0; i < props.length; i++) {
  31808. var descriptor = props[i];
  31809. descriptor.enumerable = descriptor.enumerable || false;
  31810. descriptor.configurable = true;
  31811. if ("value" in descriptor) descriptor.writable = true;
  31812. Object.defineProperty(target, descriptor.key, descriptor);
  31813. }
  31814. }
  31815. function _createClass(Constructor, protoProps, staticProps) {
  31816. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  31817. if (staticProps) _defineProperties(Constructor, staticProps);
  31818. return Constructor;
  31819. }
  31820. var Socket = __webpack_require__(18);
  31821. var debug = __webpack_require__(0)('JsSIP:Transport');
  31822. var debugerror = __webpack_require__(0)('JsSIP:ERROR:Transport');
  31823. var PhoneLogger = __webpack_require__(59);
  31824. var user;
  31825. debugerror.log = console.warn.bind(console);
  31826. /**
  31827. * Constants
  31828. */
  31829. var C = {
  31830. // Transport status.
  31831. STATUS_CONNECTED: 0,
  31832. STATUS_CONNECTING: 1,
  31833. STATUS_DISCONNECTED: 2,
  31834. // Socket status.
  31835. SOCKET_STATUS_READY: 0,
  31836. SOCKET_STATUS_ERROR: 1,
  31837. // Recovery options.
  31838. recovery_options: {
  31839. min_interval: 2,
  31840. // minimum interval in seconds between recover attempts
  31841. max_interval: 30 // maximum interval in seconds between recover attempts
  31842. }
  31843. };
  31844. /*
  31845. * Manages one or multiple JsSIP.Socket instances.
  31846. * Is reponsible for transport recovery logic among all socket instances.
  31847. *
  31848. * @socket JsSIP::Socket instance
  31849. */
  31850. module.exports =
  31851. /*#__PURE__*/
  31852. function () {
  31853. function Transport(sockets) {
  31854. var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options;
  31855. _classCallCheck(this, Transport);
  31856. debug('new()');
  31857. this.status = C.STATUS_DISCONNECTED; // Current socket.
  31858. this.socket = null; // Socket collection.
  31859. this.sockets = [];
  31860. this.recovery_options = recovery_options;
  31861. this.recover_attempts = 0;
  31862. this.recovery_timer = null;
  31863. this.close_requested = false;
  31864. if (typeof sockets === 'undefined') {
  31865. throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument');
  31866. }
  31867. if (!(sockets instanceof Array)) {
  31868. sockets = [sockets];
  31869. }
  31870. sockets.forEach(function (socket) {
  31871. if (!Socket.isSocket(socket.socket)) {
  31872. throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance');
  31873. }
  31874. if (socket.weight && !Number(socket.weight)) {
  31875. throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number');
  31876. }
  31877. this.sockets.push({
  31878. socket: socket.socket,
  31879. weight: socket.weight || 0,
  31880. status: C.SOCKET_STATUS_READY
  31881. });
  31882. }, this); // Get the socket with higher weight.
  31883. this._getSocket();
  31884. }
  31885. /**
  31886. * Instance Methods
  31887. */
  31888. _createClass(Transport, [{
  31889. key: "connect",
  31890. value: function connect() {
  31891. debug('connect()');
  31892. if (this.isConnected()) {
  31893. debug('Transport is already connected');
  31894. return;
  31895. } else if (this.isConnecting()) {
  31896. debug('Transport is connecting');
  31897. return;
  31898. }
  31899. this.close_requested = false;
  31900. this.status = C.STATUS_CONNECTING;
  31901. this.onconnecting({
  31902. socket: this.socket,
  31903. attempts: this.recover_attempts
  31904. });
  31905. if (!this.close_requested) {
  31906. // Bind socket event callbacks.
  31907. this.socket.onconnect = this._onConnect.bind(this);
  31908. this.socket.ondisconnect = this._onDisconnect.bind(this);
  31909. this.socket.ondata = this._onData.bind(this);
  31910. this.socket.connect();
  31911. }
  31912. return;
  31913. }
  31914. }, {
  31915. key: "disconnect",
  31916. value: function disconnect() {
  31917. debug('close()');
  31918. this.close_requested = true;
  31919. this.recover_attempts = 0;
  31920. this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer.
  31921. if (this.recovery_timer !== null) {
  31922. clearTimeout(this.recovery_timer);
  31923. this.recovery_timer = null;
  31924. } // Unbind socket event callbacks.
  31925. this.socket.onconnect = function () {};
  31926. this.socket.ondisconnect = function () {};
  31927. this.socket.ondata = function () {};
  31928. this.socket.disconnect();
  31929. this.ondisconnect({
  31930. socket: this.socket,
  31931. error: false
  31932. });
  31933. }
  31934. }, {
  31935. key: "send",
  31936. value: function send(data) {
  31937. debug('send()');
  31938. if (!this.isConnected()) {
  31939. debugerror('unable to send message, transport is not connected');
  31940. return false;
  31941. }
  31942. // var uri = JSON.parse(JSON.stringify(data.ua._configuration.uri));
  31943. // const user = '<' + uri._scheme + ':' + uri._user + '@' + uri._host + ':' + uri._port + '>';
  31944. var message = data.toString();
  31945. PhoneLogger.debug({
  31946. direction: 'SEND',
  31947. // user: user,
  31948. data: data
  31949. });
  31950. console.log('%c SEND Message! ', 'background: #D11D05; color: #BABACA');
  31951. console.log(message);
  31952. debug("sending message:\n\n".concat(message, "\n"));
  31953. return this.socket.send(message);
  31954. }
  31955. }, {
  31956. key: "isConnected",
  31957. value: function isConnected() {
  31958. return this.status === C.STATUS_CONNECTED;
  31959. }
  31960. }, {
  31961. key: "isConnecting",
  31962. value: function isConnecting() {
  31963. return this.status === C.STATUS_CONNECTING;
  31964. }
  31965. /**
  31966. * Private API.
  31967. */
  31968. }, {
  31969. key: "_reconnect",
  31970. value: function _reconnect() {
  31971. var _this = this;
  31972. this.recover_attempts += 1;
  31973. var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1);
  31974. if (k < this.recovery_options.min_interval) {
  31975. k = this.recovery_options.min_interval;
  31976. } else if (k > this.recovery_options.max_interval) {
  31977. k = this.recovery_options.max_interval;
  31978. }
  31979. debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds"));
  31980. this.recovery_timer = setTimeout(function () {
  31981. if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) {
  31982. // Get the next available socket with higher weight.
  31983. _this._getSocket(); // Connect the socket.
  31984. _this.connect();
  31985. }
  31986. }, k * 1000);
  31987. }
  31988. /**
  31989. * get the next available socket with higher weight
  31990. */
  31991. }, {
  31992. key: "_getSocket",
  31993. value: function _getSocket() {
  31994. var candidates = [];
  31995. this.sockets.forEach(function (socket) {
  31996. if (socket.status === C.SOCKET_STATUS_ERROR) {
  31997. return; // continue the array iteration
  31998. } else if (candidates.length === 0) {
  31999. candidates.push(socket);
  32000. } else if (socket.weight > candidates[0].weight) {
  32001. candidates = [socket];
  32002. } else if (socket.weight === candidates[0].weight) {
  32003. candidates.push(socket);
  32004. }
  32005. });
  32006. if (candidates.length === 0) {
  32007. // All sockets have failed. reset sockets status.
  32008. this.sockets.forEach(function (socket) {
  32009. socket.status = C.SOCKET_STATUS_READY;
  32010. }); // Get next available socket.
  32011. this._getSocket();
  32012. return;
  32013. }
  32014. var idx = Math.floor(Math.random() * candidates.length);
  32015. this.socket = candidates[idx].socket;
  32016. }
  32017. /**
  32018. * Socket Event Handlers
  32019. */
  32020. }, {
  32021. key: "_onConnect",
  32022. value: function _onConnect() {
  32023. this.recover_attempts = 0;
  32024. this.status = C.STATUS_CONNECTED; // Clear recovery_timer.
  32025. if (this.recovery_timer !== null) {
  32026. clearTimeout(this.recovery_timer);
  32027. this.recovery_timer = null;
  32028. }
  32029. this.onconnect({
  32030. socket: this
  32031. });
  32032. }
  32033. }, {
  32034. key: "_onDisconnect",
  32035. value: function _onDisconnect(error, code, reason) {
  32036. this.status = C.STATUS_DISCONNECTED;
  32037. this.ondisconnect({
  32038. socket: this.socket,
  32039. error: error,
  32040. code: code,
  32041. reason: reason
  32042. });
  32043. if (this.close_requested) {
  32044. return;
  32045. } // Update socket status.
  32046. else {
  32047. this.sockets.forEach(function (socket) {
  32048. if (this.socket === socket.socket) {
  32049. socket.status = C.SOCKET_STATUS_ERROR;
  32050. }
  32051. }, this);
  32052. }
  32053. this._reconnect(error);
  32054. }
  32055. }, {
  32056. key: "_onData",
  32057. value: function _onData(data) {
  32058. // CRLF Keep Alive response from server. Ignore it.
  32059. if (data === '\r\n') {
  32060. debug('received message with CRLF Keep Alive response');
  32061. return;
  32062. } // Binary message.
  32063. else if (typeof data !== 'string') {
  32064. try {
  32065. data = String.fromCharCode.apply(null, new Uint8Array(data));
  32066. } catch (evt) {
  32067. debug('received binary message failed to be converted into string,' + ' message discarded');
  32068. return;
  32069. }
  32070. debug("received binary message:\n\n".concat(data, "\n"));
  32071. } // Text message.
  32072. else {
  32073. // console.log(data)
  32074. // const uri = data.ua._configuration.uri;
  32075. // const user = '<' + uri._scheme + ':' + uri._user + '@' + uri._host + ':' + uri._port + '>'
  32076. PhoneLogger.debug({
  32077. direction: 'RECV',
  32078. // user: user,
  32079. data: data
  32080. });
  32081. debug("received text message:\n\n".concat(data, "\n"));
  32082. }
  32083. // console.log("received text message:");
  32084. console.log('%c RECEIVED Message! ', 'background: #02AC1E; color: #BABACA');
  32085. console.log(data);
  32086. this.ondata({
  32087. transport: this,
  32088. message: data
  32089. });
  32090. }
  32091. }, {
  32092. key: "via_transport",
  32093. get: function get() {
  32094. return this.socket.via_transport;
  32095. }
  32096. }, {
  32097. key: "url",
  32098. get: function get() {
  32099. return this.socket.url;
  32100. }
  32101. }, {
  32102. key: "sip_uri",
  32103. get: function get() {
  32104. return this.socket.sip_uri;
  32105. }
  32106. }]);
  32107. return Transport;
  32108. }();
  32109. }),
  32110. /* 40 */
  32111. (function(module, exports, __webpack_require__) {
  32112. "use strict";
  32113. var Grammar = __webpack_require__(3);
  32114. var SIPMessage = __webpack_require__(5);
  32115. var debugerror = __webpack_require__(0)('JsSIP:ERROR:Parser');
  32116. debugerror.log = console.warn.bind(console);
  32117. /**
  32118. * Parse SIP Message
  32119. */
  32120. exports.parseMessage = function (data, ua) {
  32121. var message;
  32122. var bodyStart;
  32123. var headerEnd = data.indexOf('\r\n');
  32124. if (headerEnd === -1) {
  32125. debugerror('parseMessage() | no CRLF found, not a SIP message');
  32126. return;
  32127. } // Parse first line. Check if it is a Request or a Reply.
  32128. var firstLine = data.substring(0, headerEnd);
  32129. var parsed = Grammar.parse(firstLine, 'Request_Response');
  32130. if (parsed === -1) {
  32131. debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\""));
  32132. return;
  32133. } else if (!parsed.status_code) {
  32134. message = new SIPMessage.IncomingRequest(ua);
  32135. message.method = parsed.method;
  32136. message.ruri = parsed.uri;
  32137. } else {
  32138. message = new SIPMessage.IncomingResponse();
  32139. message.status_code = parsed.status_code;
  32140. message.reason_phrase = parsed.reason_phrase;
  32141. }
  32142. message.data = data;
  32143. var headerStart = headerEnd + 2;
  32144. /* Loop over every line in data. Detect the end of each header and parse
  32145. * it or simply add to the headers collection.
  32146. */
  32147. while (true) {
  32148. headerEnd = getHeader(data, headerStart); // The SIP message has normally finished.
  32149. if (headerEnd === -2) {
  32150. bodyStart = headerStart + 2;
  32151. break;
  32152. } // Data.indexOf returned -1 due to a malformed message.
  32153. else if (headerEnd === -1) {
  32154. debugerror('parseMessage() | malformed message');
  32155. return;
  32156. }
  32157. parsed = parseHeader(message, data, headerStart, headerEnd);
  32158. if (parsed !== true) {
  32159. debugerror('parseMessage() |', parsed.error);
  32160. return;
  32161. }
  32162. headerStart = headerEnd + 2;
  32163. }
  32164. /* RFC3261 18.3.
  32165. * If there are additional bytes in the transport packet
  32166. * beyond the end of the body, they MUST be discarded.
  32167. */
  32168. if (message.hasHeader('content-length')) {
  32169. var contentLength = message.getHeader('content-length');
  32170. message.body = data.substr(bodyStart, contentLength);
  32171. } else {
  32172. message.body = data.substring(bodyStart);
  32173. }
  32174. return message;
  32175. };
  32176. /**
  32177. * Extract and parse every header of a SIP message.
  32178. */
  32179. function getHeader(data, headerStart) {
  32180. // 'start' position of the header.
  32181. var start = headerStart; // 'end' position of the header.
  32182. var end = 0; // 'partial end' position of the header.
  32183. var partialEnd = 0; // End of message.
  32184. if (data.substring(start, start + 2).match(/(^\r\n)/)) {
  32185. return -2;
  32186. }
  32187. while (end === 0) {
  32188. // Partial End of Header.
  32189. partialEnd = data.indexOf('\r\n', start); // 'indexOf' returns -1 if the value to be found never occurs.
  32190. if (partialEnd === -1) {
  32191. return partialEnd;
  32192. }
  32193. if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) {
  32194. // Not the end of the message. Continue from the next position.
  32195. start = partialEnd + 2;
  32196. } else {
  32197. end = partialEnd;
  32198. }
  32199. }
  32200. return end;
  32201. }
  32202. function parseHeader(message, data, headerStart, headerEnd) {
  32203. var parsed;
  32204. var hcolonIndex = data.indexOf(':', headerStart);
  32205. var headerName = data.substring(headerStart, hcolonIndex).trim();
  32206. var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim(); // If header-field is well-known, parse it.
  32207. switch (headerName.toLowerCase()) {
  32208. case 'via':
  32209. case 'v':
  32210. message.addHeader('via', headerValue);
  32211. if (message.getHeaders('via').length === 1) {
  32212. parsed = message.parseHeader('Via');
  32213. if (parsed) {
  32214. message.via = parsed;
  32215. message.via_branch = parsed.branch;
  32216. }
  32217. } else {
  32218. parsed = 0;
  32219. }
  32220. break;
  32221. case 'from':
  32222. case 'f':
  32223. message.setHeader('from', headerValue);
  32224. parsed = message.parseHeader('from');
  32225. if (parsed) {
  32226. message.from = parsed;
  32227. message.from_tag = parsed.getParam('tag');
  32228. }
  32229. break;
  32230. case 'to':
  32231. case 't':
  32232. message.setHeader('to', headerValue);
  32233. parsed = message.parseHeader('to');
  32234. if (parsed) {
  32235. message.to = parsed;
  32236. message.to_tag = parsed.getParam('tag');
  32237. }
  32238. break;
  32239. case 'record-route':
  32240. parsed = Grammar.parse(headerValue, 'Record_Route');
  32241. if (parsed === -1) {
  32242. parsed = undefined;
  32243. } else {
  32244. var _iteratorNormalCompletion = true;
  32245. var _didIteratorError = false;
  32246. var _iteratorError = undefined;
  32247. try {
  32248. for (var _iterator = parsed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  32249. var header = _step.value;
  32250. message.addHeader('record-route', headerValue.substring(header.possition, header.offset));
  32251. message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed;
  32252. }
  32253. } catch (err) {
  32254. _didIteratorError = true;
  32255. _iteratorError = err;
  32256. } finally {
  32257. try {
  32258. if (!_iteratorNormalCompletion && _iterator.return != null) {
  32259. _iterator.return();
  32260. }
  32261. } finally {
  32262. if (_didIteratorError) {
  32263. throw _iteratorError;
  32264. }
  32265. }
  32266. }
  32267. }
  32268. break;
  32269. case 'call-id':
  32270. case 'i':
  32271. message.setHeader('call-id', headerValue);
  32272. parsed = message.parseHeader('call-id');
  32273. if (parsed) {
  32274. message.call_id = headerValue;
  32275. }
  32276. break;
  32277. case 'contact':
  32278. case 'm':
  32279. parsed = Grammar.parse(headerValue, 'Contact');
  32280. if (parsed === -1) {
  32281. parsed = undefined;
  32282. } else {
  32283. var _iteratorNormalCompletion2 = true;
  32284. var _didIteratorError2 = false;
  32285. var _iteratorError2 = undefined;
  32286. try {
  32287. for (var _iterator2 = parsed[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  32288. var _header = _step2.value;
  32289. message.addHeader('contact', headerValue.substring(_header.possition, _header.offset));
  32290. message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed;
  32291. }
  32292. } catch (err) {
  32293. _didIteratorError2 = true;
  32294. _iteratorError2 = err;
  32295. } finally {
  32296. try {
  32297. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  32298. _iterator2.return();
  32299. }
  32300. } finally {
  32301. if (_didIteratorError2) {
  32302. throw _iteratorError2;
  32303. }
  32304. }
  32305. }
  32306. }
  32307. break;
  32308. case 'content-length':
  32309. case 'l':
  32310. message.setHeader('content-length', headerValue);
  32311. parsed = message.parseHeader('content-length');
  32312. break;
  32313. case 'content-type':
  32314. case 'c':
  32315. message.setHeader('content-type', headerValue);
  32316. parsed = message.parseHeader('content-type');
  32317. break;
  32318. case 'cseq':
  32319. message.setHeader('cseq', headerValue);
  32320. parsed = message.parseHeader('cseq');
  32321. if (parsed) {
  32322. message.cseq = parsed.value;
  32323. }
  32324. if (message instanceof SIPMessage.IncomingResponse) {
  32325. message.method = parsed.method;
  32326. }
  32327. break;
  32328. case 'max-forwards':
  32329. message.setHeader('max-forwards', headerValue);
  32330. parsed = message.parseHeader('max-forwards');
  32331. break;
  32332. case 'www-authenticate':
  32333. message.setHeader('www-authenticate', headerValue);
  32334. parsed = message.parseHeader('www-authenticate');
  32335. break;
  32336. case 'proxy-authenticate':
  32337. message.setHeader('proxy-authenticate', headerValue);
  32338. parsed = message.parseHeader('proxy-authenticate');
  32339. break;
  32340. case 'session-expires':
  32341. case 'x':
  32342. message.setHeader('session-expires', headerValue);
  32343. parsed = message.parseHeader('session-expires');
  32344. if (parsed) {
  32345. message.session_expires = parsed.expires;
  32346. message.session_expires_refresher = parsed.refresher;
  32347. }
  32348. break;
  32349. case 'refer-to':
  32350. case 'r':
  32351. message.setHeader('refer-to', headerValue);
  32352. parsed = message.parseHeader('refer-to');
  32353. if (parsed) {
  32354. message.refer_to = parsed;
  32355. }
  32356. break;
  32357. case 'replaces':
  32358. message.setHeader('replaces', headerValue);
  32359. parsed = message.parseHeader('replaces');
  32360. if (parsed) {
  32361. message.replaces = parsed;
  32362. }
  32363. break;
  32364. case 'event':
  32365. case 'o':
  32366. message.setHeader('event', headerValue);
  32367. parsed = message.parseHeader('event');
  32368. if (parsed) {
  32369. message.event = parsed;
  32370. }
  32371. break;
  32372. default:
  32373. // Do not parse this header.
  32374. message.addHeader(headerName, headerValue);
  32375. parsed = 0;
  32376. }
  32377. if (parsed === undefined) {
  32378. return {
  32379. error: "error parsing header \"".concat(headerName, "\"")
  32380. };
  32381. } else {
  32382. return true;
  32383. }
  32384. }
  32385. }),
  32386. /* 41 */
  32387. (function(module, exports, __webpack_require__) {
  32388. "use strict";
  32389. var JsSIP_C = __webpack_require__(1);
  32390. var SIPMessage = __webpack_require__(5);
  32391. var Utils = __webpack_require__(2);
  32392. var debug = __webpack_require__(0)('JsSIP:sanityCheck'); // Checks for requests and responses.
  32393. var all = [minimumHeaders]; // Checks for requests.
  32394. var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2]; // Checks for responses.
  32395. var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response]; // local variables.
  32396. var message;
  32397. var ua;
  32398. var transport;
  32399. module.exports = function (m, u, t) {
  32400. message = m;
  32401. ua = u;
  32402. transport = t;
  32403. for (var _i = 0; _i < all.length; _i++) {
  32404. var _check2 = all[_i];
  32405. if (_check2() === false) {
  32406. return false;
  32407. }
  32408. }
  32409. if (message instanceof SIPMessage.IncomingRequest) {
  32410. for (var _i2 = 0; _i2 < requests.length; _i2++) {
  32411. var check = requests[_i2];
  32412. if (check() === false) {
  32413. return false;
  32414. }
  32415. }
  32416. } else if (message instanceof SIPMessage.IncomingResponse) {
  32417. for (var _i3 = 0; _i3 < responses.length; _i3++) {
  32418. var _check = responses[_i3];
  32419. if (_check() === false) {
  32420. return false;
  32421. }
  32422. }
  32423. } // Everything is OK.
  32424. return true;
  32425. };
  32426. /*
  32427. * Sanity Check for incoming Messages
  32428. *
  32429. * Requests:
  32430. * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme
  32431. * - _rfc3261_16_3_4_ Receive a Request already sent by us
  32432. * Does not look at via sent-by but at jssip_id, which is inserted as
  32433. * a prefix in all initial requests generated by the ua
  32434. * - _rfc3261_18_3_request_ Body Content-Length
  32435. * - _rfc3261_8_2_2_2_ Merged Requests
  32436. *
  32437. * Responses:
  32438. * - _rfc3261_8_1_3_3_ Multiple Via headers
  32439. * - _rfc3261_18_3_response_ Body Content-Length
  32440. *
  32441. * All:
  32442. * - Minimum headers in a SIP message
  32443. */
  32444. // Sanity Check functions for requests.
  32445. function rfc3261_8_2_2_1() {
  32446. if (message.s('to').uri.scheme !== 'sip') {
  32447. reply(416);
  32448. return false;
  32449. }
  32450. }
  32451. function rfc3261_16_3_4() {
  32452. if (!message.to_tag) {
  32453. if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) {
  32454. reply(482);
  32455. return false;
  32456. }
  32457. }
  32458. }
  32459. function rfc3261_18_3_request() {
  32460. var len = Utils.str_utf8_length(message.body);
  32461. var contentLength = message.getHeader('content-length');
  32462. if (len < contentLength) {
  32463. reply(400);
  32464. return false;
  32465. }
  32466. }
  32467. function rfc3261_8_2_2_2() {
  32468. var fromTag = message.from_tag;
  32469. var call_id = message.call_id;
  32470. var cseq = message.cseq;
  32471. var tr; // Accept any in-dialog request.
  32472. if (message.to_tag) {
  32473. return;
  32474. } // INVITE request.
  32475. if (message.method === JsSIP_C.INVITE) {
  32476. // If the branch matches the key of any IST then assume it is a retransmission
  32477. // and ignore the INVITE.
  32478. // TODO: we should reply the last response.
  32479. if (ua._transactions.ist[message.via_branch]) {
  32480. return false;
  32481. } // Otherwise check whether it is a merged request.
  32482. else {
  32483. for (var transaction in ua._transactions.ist) {
  32484. if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) {
  32485. tr = ua._transactions.ist[transaction];
  32486. if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  32487. reply(482);
  32488. return false;
  32489. }
  32490. }
  32491. }
  32492. }
  32493. } // Non INVITE request.
  32494. // If the branch matches the key of any NIST then assume it is a retransmission
  32495. // and ignore the request.
  32496. // TODO: we should reply the last response.
  32497. else if (ua._transactions.nist[message.via_branch]) {
  32498. return false;
  32499. } // Otherwise check whether it is a merged request.
  32500. else {
  32501. for (var _transaction in ua._transactions.nist) {
  32502. if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) {
  32503. tr = ua._transactions.nist[_transaction];
  32504. if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  32505. reply(482);
  32506. return false;
  32507. }
  32508. }
  32509. }
  32510. }
  32511. } // Sanity Check functions for responses.
  32512. function rfc3261_8_1_3_3() {
  32513. if (message.getHeaders('via').length > 1) {
  32514. debug('more than one Via header field present in the response, dropping the response');
  32515. return false;
  32516. }
  32517. }
  32518. function rfc3261_18_3_response() {
  32519. var len = Utils.str_utf8_length(message.body),
  32520. contentLength = message.getHeader('content-length');
  32521. if (len < contentLength) {
  32522. debug('message body length is lower than the value in Content-Length header field, dropping the response');
  32523. return false;
  32524. }
  32525. } // Sanity Check functions for requests and responses.
  32526. function minimumHeaders() {
  32527. var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via'];
  32528. for (var _i4 = 0; _i4 < mandatoryHeaders.length; _i4++) {
  32529. var header = mandatoryHeaders[_i4];
  32530. if (!message.hasHeader(header)) {
  32531. debug("missing mandatory header field : ".concat(header, ", dropping the response"));
  32532. return false;
  32533. }
  32534. }
  32535. } // Reply.
  32536. function reply(status_code) {
  32537. var vias = message.getHeaders('via');
  32538. var to;
  32539. var response = "SIP/2.0 ".concat(status_code, " ").concat(JsSIP_C.REASON_PHRASE[status_code], "\r\n");
  32540. var _iteratorNormalCompletion = true;
  32541. var _didIteratorError = false;
  32542. var _iteratorError = undefined;
  32543. try {
  32544. for (var _iterator = vias[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  32545. var via = _step.value;
  32546. response += "Via: ".concat(via, "\r\n");
  32547. }
  32548. } catch (err) {
  32549. _didIteratorError = true;
  32550. _iteratorError = err;
  32551. } finally {
  32552. try {
  32553. if (!_iteratorNormalCompletion && _iterator.return != null) {
  32554. _iterator.return();
  32555. }
  32556. } finally {
  32557. if (_didIteratorError) {
  32558. throw _iteratorError;
  32559. }
  32560. }
  32561. }
  32562. to = message.getHeader('To');
  32563. if (!message.to_tag) {
  32564. to += ";tag=".concat(Utils.newTag());
  32565. }
  32566. response += "To: ".concat(to, "\r\n");
  32567. response += "From: ".concat(message.getHeader('From'), "\r\n");
  32568. response += "Call-ID: ".concat(message.call_id, "\r\n");
  32569. response += "CSeq: ".concat(message.cseq, " ").concat(message.method, "\r\n");
  32570. response += '\r\n';
  32571. transport.send(response);
  32572. }
  32573. }),
  32574. /* 42 */
  32575. (function(module, exports, __webpack_require__) {
  32576. "use strict";
  32577. var Utils = __webpack_require__(2);
  32578. var JsSIP_C = __webpack_require__(1);
  32579. var Grammar = __webpack_require__(3);
  32580. var URI = __webpack_require__(8);
  32581. var Socket = __webpack_require__(18);
  32582. var Exceptions = __webpack_require__(6); // Default settings.
  32583. exports.settings = {
  32584. // SIP authentication.
  32585. authorization_user: null,
  32586. password: null,
  32587. realm: null,
  32588. ha1: null,
  32589. // SIP account.
  32590. display_name: null,
  32591. uri: null,
  32592. contact_uri: null,
  32593. // SIP instance id (GRUU).
  32594. instance_id: null,
  32595. // Preloaded SIP Route header field.
  32596. use_preloaded_route: false,
  32597. // Session parameters.
  32598. session_timers: true,
  32599. session_timers_refresh_method: JsSIP_C.UPDATE,
  32600. no_answer_timeout: 60,
  32601. // Registration parameters.
  32602. register: true,
  32603. register_expires: 600,
  32604. registrar_server: null,
  32605. // Connection options.
  32606. sockets: null,
  32607. connection_recovery_max_interval: null,
  32608. connection_recovery_min_interval: null,
  32609. /*
  32610. * Host address.
  32611. * Value to be set in Via sent_by and host part of Contact FQDN.
  32612. */
  32613. via_host: "".concat(Utils.createRandomToken(12), ".invalid")
  32614. }; // Configuration checks.
  32615. var checks = {
  32616. mandatory: {
  32617. sockets: function sockets(_sockets2) {
  32618. /* Allow defining sockets parameter as:
  32619. * Socket: socket
  32620. * Array of Socket: [socket1, socket2]
  32621. * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}]
  32622. * Array of Objects and Socket: [{socket: socket1}, socket2]
  32623. */
  32624. var _sockets = [];
  32625. if (Socket.isSocket(_sockets2)) {
  32626. _sockets.push({
  32627. socket: _sockets2
  32628. });
  32629. } else if (Array.isArray(_sockets2) && _sockets2.length) {
  32630. var _iteratorNormalCompletion = true;
  32631. var _didIteratorError = false;
  32632. var _iteratorError = undefined;
  32633. try {
  32634. for (var _iterator = _sockets2[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  32635. var socket = _step.value;
  32636. if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) {
  32637. _sockets.push(socket);
  32638. } else if (Socket.isSocket(socket)) {
  32639. _sockets.push({
  32640. socket: socket
  32641. });
  32642. }
  32643. }
  32644. } catch (err) {
  32645. _didIteratorError = true;
  32646. _iteratorError = err;
  32647. } finally {
  32648. try {
  32649. if (!_iteratorNormalCompletion && _iterator.return != null) {
  32650. _iterator.return();
  32651. }
  32652. } finally {
  32653. if (_didIteratorError) {
  32654. throw _iteratorError;
  32655. }
  32656. }
  32657. }
  32658. } else {
  32659. return;
  32660. }
  32661. return _sockets;
  32662. },
  32663. uri: function uri(_uri) {
  32664. if (!/^sip:/i.test(_uri)) {
  32665. _uri = "".concat(JsSIP_C.SIP, ":").concat(_uri);
  32666. }
  32667. var parsed = URI.parse(_uri);
  32668. if (!parsed) {
  32669. return;
  32670. } else if (!parsed.user) {
  32671. return;
  32672. } else {
  32673. return parsed;
  32674. }
  32675. }
  32676. },
  32677. optional: {
  32678. authorization_user: function authorization_user(_authorization_user) {
  32679. if (Grammar.parse("\"".concat(_authorization_user, "\""), 'quoted_string') === -1) {
  32680. return;
  32681. } else {
  32682. return _authorization_user;
  32683. }
  32684. },
  32685. user_agent: function user_agent(_user_agent) {
  32686. if (typeof _user_agent === 'string') {
  32687. return _user_agent;
  32688. }
  32689. },
  32690. connection_recovery_max_interval: function connection_recovery_max_interval(_connection_recovery_max_interval) {
  32691. if (Utils.isDecimal(_connection_recovery_max_interval)) {
  32692. var value = Number(_connection_recovery_max_interval);
  32693. if (value > 0) {
  32694. return value;
  32695. }
  32696. }
  32697. },
  32698. connection_recovery_min_interval: function connection_recovery_min_interval(_connection_recovery_min_interval) {
  32699. if (Utils.isDecimal(_connection_recovery_min_interval)) {
  32700. var value = Number(_connection_recovery_min_interval);
  32701. if (value > 0) {
  32702. return value;
  32703. }
  32704. }
  32705. },
  32706. contact_uri: function contact_uri(_contact_uri) {
  32707. if (typeof _contact_uri === 'string') {
  32708. var uri = Grammar.parse(_contact_uri, 'SIP_URI');
  32709. if (uri !== -1) {
  32710. return uri;
  32711. }
  32712. }
  32713. },
  32714. display_name: function display_name(_display_name) {
  32715. if (Grammar.parse("\"".concat(_display_name, "\""), 'display_name') === -1) {
  32716. return;
  32717. } else {
  32718. return _display_name;
  32719. }
  32720. },
  32721. instance_id: function instance_id(_instance_id) {
  32722. if (/^uuid:/i.test(_instance_id)) {
  32723. _instance_id = _instance_id.substr(5);
  32724. }
  32725. if (Grammar.parse(_instance_id, 'uuid') === -1) {
  32726. return;
  32727. } else {
  32728. return _instance_id;
  32729. }
  32730. },
  32731. no_answer_timeout: function no_answer_timeout(_no_answer_timeout) {
  32732. if (Utils.isDecimal(_no_answer_timeout)) {
  32733. var value = Number(_no_answer_timeout);
  32734. if (value > 0) {
  32735. return value;
  32736. }
  32737. }
  32738. },
  32739. session_timers: function session_timers(_session_timers) {
  32740. if (typeof _session_timers === 'boolean') {
  32741. return _session_timers;
  32742. }
  32743. },
  32744. session_timers_refresh_method: function session_timers_refresh_method(method) {
  32745. if (typeof method === 'string') {
  32746. method = method.toUpperCase();
  32747. if (method === JsSIP_C.INVITE || method === JsSIP_C.UPDATE) {
  32748. return method;
  32749. }
  32750. }
  32751. },
  32752. password: function password(_password) {
  32753. return String(_password);
  32754. },
  32755. realm: function realm(_realm) {
  32756. return String(_realm);
  32757. },
  32758. ha1: function ha1(_ha) {
  32759. return String(_ha);
  32760. },
  32761. register: function register(_register) {
  32762. if (typeof _register === 'boolean') {
  32763. return _register;
  32764. }
  32765. },
  32766. register_expires: function register_expires(_register_expires) {
  32767. if (Utils.isDecimal(_register_expires)) {
  32768. var value = Number(_register_expires);
  32769. if (value > 0) {
  32770. return value;
  32771. }
  32772. }
  32773. },
  32774. registrar_server: function registrar_server(_registrar_server) {
  32775. if (!/^sip:/i.test(_registrar_server)) {
  32776. _registrar_server = "".concat(JsSIP_C.SIP, ":").concat(_registrar_server);
  32777. }
  32778. var parsed = URI.parse(_registrar_server);
  32779. if (!parsed) {
  32780. return;
  32781. } else if (parsed.user) {
  32782. return;
  32783. } else {
  32784. return parsed;
  32785. }
  32786. },
  32787. use_preloaded_route: function use_preloaded_route(_use_preloaded_route) {
  32788. if (typeof _use_preloaded_route === 'boolean') {
  32789. return _use_preloaded_route;
  32790. }
  32791. }
  32792. }
  32793. };
  32794. exports.load = function (dst, src) {
  32795. // Check Mandatory parameters.
  32796. for (var parameter in checks.mandatory) {
  32797. if (!src.hasOwnProperty(parameter)) {
  32798. throw new Exceptions.ConfigurationError(parameter);
  32799. } else {
  32800. var value = src[parameter];
  32801. var checked_value = checks.mandatory[parameter](value);
  32802. if (checked_value !== undefined) {
  32803. dst[parameter] = checked_value;
  32804. } else {
  32805. throw new Exceptions.ConfigurationError(parameter, value);
  32806. }
  32807. }
  32808. } // Check Optional parameters.
  32809. for (var _parameter in checks.optional) {
  32810. if (src.hasOwnProperty(_parameter)) {
  32811. var _value = src[_parameter];
  32812. /* If the parameter value is null, empty string, undefined, empty array
  32813. * or it's a number with NaN value, then apply its default value.
  32814. */
  32815. if (Utils.isEmpty(_value)) {
  32816. continue;
  32817. }
  32818. var _checked_value = checks.optional[_parameter](_value);
  32819. if (_checked_value !== undefined) {
  32820. dst[_parameter] = _checked_value;
  32821. } else {
  32822. throw new Exceptions.ConfigurationError(_parameter, _value);
  32823. }
  32824. }
  32825. }
  32826. };
  32827. }),
  32828. /* 43 */
  32829. (function(module, exports, __webpack_require__) {
  32830. "use strict";
  32831. function _classCallCheck(instance, Constructor) {
  32832. if (!(instance instanceof Constructor)) {
  32833. throw new TypeError("Cannot call a class as a function");
  32834. }
  32835. }
  32836. function _defineProperties(target, props) {
  32837. for (var i = 0; i < props.length; i++) {
  32838. var descriptor = props[i];
  32839. descriptor.enumerable = descriptor.enumerable || false;
  32840. descriptor.configurable = true;
  32841. if ("value" in descriptor) descriptor.writable = true;
  32842. Object.defineProperty(target, descriptor.key, descriptor);
  32843. }
  32844. }
  32845. function _createClass(Constructor, protoProps, staticProps) {
  32846. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  32847. if (staticProps) _defineProperties(Constructor, staticProps);
  32848. return Constructor;
  32849. }
  32850. var Grammar = __webpack_require__(3);
  32851. var debug = __webpack_require__(0)('JsSIP:WebSocketInterface');
  32852. var debugerror = __webpack_require__(0)('JsSIP:ERROR:WebSocketInterface');
  32853. var PhoneNetwork = __webpack_require__(61);
  32854. debugerror.log = console.warn.bind(console);
  32855. module.exports =
  32856. /*#__PURE__*/
  32857. function () {
  32858. function WebSocketInterface(url) {
  32859. _classCallCheck(this, WebSocketInterface);
  32860. debug('new() [url:"%s"]', url);
  32861. this._url = url;
  32862. this._sip_uri = null;
  32863. this._via_transport = null;
  32864. this._ws = null;
  32865. var parsed_url = Grammar.parse(url, 'absoluteURI');
  32866. if (parsed_url === -1) {
  32867. debugerror("invalid WebSocket URI: ".concat(url));
  32868. throw new TypeError("Invalid argument: ".concat(url));
  32869. } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') {
  32870. debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme));
  32871. throw new TypeError("Invalid argument: ".concat(url));
  32872. } else {
  32873. this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=udp");
  32874. this._via_transport = parsed_url.scheme.toUpperCase();
  32875. }
  32876. }
  32877. _createClass(WebSocketInterface, [{
  32878. key: "connect",
  32879. value: function connect() {
  32880. debug('connect()');
  32881. if (this.isConnected()) {
  32882. debug("WebSocket ".concat(this._url, " is already connected"));
  32883. return;
  32884. } else if (this.isConnecting()) {
  32885. debug("WebSocket ".concat(this._url, " is connecting"));
  32886. return;
  32887. }
  32888. if (this._ws) {
  32889. this.disconnect();
  32890. }
  32891. debug("connecting to WebSocket ".concat(this._url));
  32892. PhoneNetwork.test();
  32893. try {
  32894. this._ws = new WebSocket(this._url, 'sip');
  32895. this._ws.binaryType = 'arraybuffer';
  32896. this._ws.onopen = this._onOpen.bind(this);
  32897. this._ws.onclose = this._onClose.bind(this);
  32898. this._ws.onmessage = this._onMessage.bind(this);
  32899. this._ws.onerror = this._onError.bind(this);
  32900. } catch (e) {
  32901. this._onError(e);
  32902. }
  32903. }
  32904. }, {
  32905. key: "disconnect",
  32906. value: function disconnect() {
  32907. debug('disconnect()');
  32908. if (this._ws) {
  32909. // Unbind websocket event callbacks.
  32910. this._ws.onopen = function () {};
  32911. this._ws.onclose = function () {};
  32912. this._ws.onmessage = function () {};
  32913. this._ws.onerror = function () {};
  32914. this._ws.close();
  32915. this._ws = null;
  32916. }
  32917. }
  32918. }, {
  32919. key: "send",
  32920. value: function send(message) {
  32921. debug('send()');
  32922. if (this.isConnected()) {
  32923. this._ws.send(message);
  32924. return true;
  32925. } else {
  32926. debugerror('unable to send message, WebSocket is not open');
  32927. return false;
  32928. }
  32929. }
  32930. }, {
  32931. key: "isConnected",
  32932. value: function isConnected() {
  32933. return this._ws && this._ws.readyState === this._ws.OPEN;
  32934. }
  32935. }, {
  32936. key: "isConnecting",
  32937. value: function isConnecting() {
  32938. return this._ws && this._ws.readyState === this._ws.CONNECTING;
  32939. }
  32940. /**
  32941. * WebSocket Event Handlers
  32942. */
  32943. }, {
  32944. key: "_onOpen",
  32945. value: function _onOpen() {
  32946. debug("WebSocket ".concat(this._url, " connected"));
  32947. this.onconnect();
  32948. }
  32949. }, {
  32950. key: "_onClose",
  32951. value: function _onClose(_ref) {
  32952. var wasClean = _ref.wasClean,
  32953. code = _ref.code,
  32954. reason = _ref.reason;
  32955. debug("WebSocket ".concat(this._url, " closed"));
  32956. if (wasClean === false) {
  32957. debug('WebSocket abrupt disconnection');
  32958. }
  32959. var data = {
  32960. socket: this,
  32961. error: !wasClean,
  32962. code: code,
  32963. reason: reason
  32964. };
  32965. this.ondisconnect(data);
  32966. }
  32967. }, {
  32968. key: "_onMessage",
  32969. value: function _onMessage(_ref2) {
  32970. var data = _ref2.data;
  32971. debug('received WebSocket message');
  32972. this.ondata(data);
  32973. }
  32974. }, {
  32975. key: "_onError",
  32976. value: function _onError(e) {
  32977. debugerror("WebSocket ".concat(this._url, " error: ").concat(e));
  32978. }
  32979. }, {
  32980. key: "via_transport",
  32981. get: function get() {
  32982. return this._via_transport;
  32983. },
  32984. set: function set(value) {
  32985. this._via_transport = value.toUpperCase();
  32986. }
  32987. }, {
  32988. key: "sip_uri",
  32989. get: function get() {
  32990. return this._sip_uri;
  32991. }
  32992. }, {
  32993. key: "url",
  32994. get: function get() {
  32995. return this._url;
  32996. }
  32997. }]);
  32998. return WebSocketInterface;
  32999. }();
  33000. }),
  33001. /* 44 */
  33002. (function(module, __webpack_exports__, __webpack_require__) {
  33003. "use strict";
  33004. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  33005. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__adapter_factory_js__ = __webpack_require__(45);
  33006. /*
  33007. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  33008. *
  33009. * Use of this source code is governed by a BSD-style license
  33010. * that can be found in the LICENSE file in the root of the source
  33011. * tree.
  33012. */
  33013. /* eslint-env node */
  33014. const adapter = Object(__WEBPACK_IMPORTED_MODULE_0__adapter_factory_js__["a" /* adapterFactory */])({
  33015. window
  33016. });
  33017. /* harmony default export */ __webpack_exports__["default"] = (adapter);
  33018. }),
  33019. /* 45 */
  33020. (function(module, __webpack_exports__, __webpack_require__) {
  33021. "use strict";
  33022. /* harmony export (immutable) */ __webpack_exports__["a"] = adapterFactory;
  33023. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(4);
  33024. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__ = __webpack_require__(46);
  33025. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__edge_edge_shim__ = __webpack_require__(49);
  33026. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__ = __webpack_require__(54);
  33027. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__ = __webpack_require__(57);
  33028. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__common_shim__ = __webpack_require__(58);
  33029. /*
  33030. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  33031. *
  33032. * Use of this source code is governed by a BSD-style license
  33033. * that can be found in the LICENSE file in the root of the source
  33034. * tree.
  33035. */
  33036. // Browser shims.
  33037. // Shimming starts here.
  33038. function adapterFactory({
  33039. window
  33040. } = {}, options = {
  33041. shimChrome: true,
  33042. shimFirefox: true,
  33043. shimEdge: true,
  33044. shimSafari: true
  33045. }) {
  33046. // Utils.
  33047. const logging = __WEBPACK_IMPORTED_MODULE_0__utils__["f" /* log */];
  33048. const browserDetails = __WEBPACK_IMPORTED_MODULE_0__utils__["b" /* detectBrowser */](window);
  33049. const adapter = {
  33050. browserDetails,
  33051. commonShim: __WEBPACK_IMPORTED_MODULE_5__common_shim__,
  33052. extractVersion: __WEBPACK_IMPORTED_MODULE_0__utils__["e" /* extractVersion */],
  33053. disableLog: __WEBPACK_IMPORTED_MODULE_0__utils__["c" /* disableLog */],
  33054. disableWarnings: __WEBPACK_IMPORTED_MODULE_0__utils__["d" /* disableWarnings */]
  33055. }; // Shim browser if found.
  33056. switch (browserDetails.browser) {
  33057. case 'chrome':
  33058. if (!__WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__ || !__WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["shimPeerConnection"] || !options.shimChrome) {
  33059. logging('Chrome shim is not included in this adapter release.');
  33060. return adapter;
  33061. }
  33062. logging('adapter.js shimming chrome.'); // Export to the adapter global object visible in the browser.
  33063. adapter.browserShim = __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__;
  33064. __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["shimGetUserMedia"](window);
  33065. __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["shimMediaStream"](window);
  33066. __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["shimPeerConnection"](window);
  33067. __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["shimOnTrack"](window);
  33068. __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["shimAddTrackRemoveTrack"](window);
  33069. __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["shimGetSendersWithDtmf"](window);
  33070. __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["shimSenderReceiverGetStats"](window);
  33071. __WEBPACK_IMPORTED_MODULE_1__chrome_chrome_shim__["fixNegotiationNeeded"](window);
  33072. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimRTCIceCandidate"](window);
  33073. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimConnectionState"](window);
  33074. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimMaxMessageSize"](window);
  33075. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimSendThrowTypeError"](window);
  33076. break;
  33077. case 'firefox':
  33078. if (!__WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__ || !__WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__["shimPeerConnection"] || !options.shimFirefox) {
  33079. logging('Firefox shim is not included in this adapter release.');
  33080. return adapter;
  33081. }
  33082. logging('adapter.js shimming firefox.'); // Export to the adapter global object visible in the browser.
  33083. adapter.browserShim = __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__;
  33084. __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__["shimGetUserMedia"](window);
  33085. __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__["shimPeerConnection"](window);
  33086. __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__["shimOnTrack"](window);
  33087. __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__["shimRemoveStream"](window);
  33088. __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__["shimSenderGetStats"](window);
  33089. __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__["shimReceiverGetStats"](window);
  33090. __WEBPACK_IMPORTED_MODULE_3__firefox_firefox_shim__["shimRTCDataChannel"](window);
  33091. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimRTCIceCandidate"](window);
  33092. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimConnectionState"](window);
  33093. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimMaxMessageSize"](window);
  33094. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimSendThrowTypeError"](window);
  33095. break;
  33096. case 'edge':
  33097. if (!__WEBPACK_IMPORTED_MODULE_2__edge_edge_shim__ || !__WEBPACK_IMPORTED_MODULE_2__edge_edge_shim__["shimPeerConnection"] || !options.shimEdge) {
  33098. logging('MS edge shim is not included in this adapter release.');
  33099. return adapter;
  33100. }
  33101. logging('adapter.js shimming edge.'); // Export to the adapter global object visible in the browser.
  33102. adapter.browserShim = __WEBPACK_IMPORTED_MODULE_2__edge_edge_shim__;
  33103. __WEBPACK_IMPORTED_MODULE_2__edge_edge_shim__["shimGetUserMedia"](window);
  33104. __WEBPACK_IMPORTED_MODULE_2__edge_edge_shim__["shimGetDisplayMedia"](window);
  33105. __WEBPACK_IMPORTED_MODULE_2__edge_edge_shim__["shimPeerConnection"](window);
  33106. __WEBPACK_IMPORTED_MODULE_2__edge_edge_shim__["shimReplaceTrack"](window); // the edge shim implements the full RTCIceCandidate object.
  33107. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimMaxMessageSize"](window);
  33108. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimSendThrowTypeError"](window);
  33109. break;
  33110. case 'safari':
  33111. if (!__WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__ || !options.shimSafari) {
  33112. logging('Safari shim is not included in this adapter release.');
  33113. return adapter;
  33114. }
  33115. logging('adapter.js shimming safari.'); // Export to the adapter global object visible in the browser.
  33116. adapter.browserShim = __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__;
  33117. __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__["shimRTCIceServerUrls"](window);
  33118. __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__["shimCreateOfferLegacy"](window);
  33119. __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__["shimCallbacksAPI"](window);
  33120. __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__["shimLocalStreamsAPI"](window);
  33121. __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__["shimRemoteStreamsAPI"](window);
  33122. __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__["shimTrackEventTransceiver"](window);
  33123. __WEBPACK_IMPORTED_MODULE_4__safari_safari_shim__["shimGetUserMedia"](window);
  33124. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimRTCIceCandidate"](window);
  33125. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimMaxMessageSize"](window);
  33126. __WEBPACK_IMPORTED_MODULE_5__common_shim__["shimSendThrowTypeError"](window);
  33127. break;
  33128. default:
  33129. logging('Unsupported browser!');
  33130. break;
  33131. }
  33132. return adapter;
  33133. }
  33134. }),
  33135. /* 46 */
  33136. (function(module, __webpack_exports__, __webpack_require__) {
  33137. "use strict";
  33138. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  33139. /* harmony export (immutable) */ __webpack_exports__["shimMediaStream"] = shimMediaStream;
  33140. /* harmony export (immutable) */ __webpack_exports__["shimOnTrack"] = shimOnTrack;
  33141. /* harmony export (immutable) */ __webpack_exports__["shimGetSendersWithDtmf"] = shimGetSendersWithDtmf;
  33142. /* harmony export (immutable) */ __webpack_exports__["shimSenderReceiverGetStats"] = shimSenderReceiverGetStats;
  33143. /* harmony export (immutable) */ __webpack_exports__["shimAddTrackRemoveTrackWithNative"] = shimAddTrackRemoveTrackWithNative;
  33144. /* harmony export (immutable) */ __webpack_exports__["shimAddTrackRemoveTrack"] = shimAddTrackRemoveTrack;
  33145. /* harmony export (immutable) */ __webpack_exports__["shimPeerConnection"] = shimPeerConnection;
  33146. /* harmony export (immutable) */ __webpack_exports__["fixNegotiationNeeded"] = fixNegotiationNeeded;
  33147. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils_js__ = __webpack_require__(4);
  33148. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__getusermedia__ = __webpack_require__(47);
  33149. /* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "shimGetUserMedia", function() { return __WEBPACK_IMPORTED_MODULE_1__getusermedia__["a"]; });
  33150. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__getdisplaymedia__ = __webpack_require__(48);
  33151. /* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "shimGetDisplayMedia", function() { return __WEBPACK_IMPORTED_MODULE_2__getdisplaymedia__["a"]; });
  33152. /*
  33153. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  33154. *
  33155. * Use of this source code is governed by a BSD-style license
  33156. * that can be found in the LICENSE file in the root of the source
  33157. * tree.
  33158. */
  33159. /* eslint-env node */
  33160. /* iterates the stats graph recursively. */
  33161. function walkStats(stats, base, resultSet) {
  33162. if (!base || resultSet.has(base.id)) {
  33163. return;
  33164. }
  33165. resultSet.set(base.id, base);
  33166. Object.keys(base).forEach(name => {
  33167. if (name.endsWith('Id')) {
  33168. walkStats(stats, stats.get(base[name]), resultSet);
  33169. } else if (name.endsWith('Ids')) {
  33170. base[name].forEach(id => {
  33171. walkStats(stats, stats.get(id), resultSet);
  33172. });
  33173. }
  33174. });
  33175. }
  33176. /* filter getStats for a sender/receiver track. */
  33177. function filterStats(result, track, outbound) {
  33178. const streamStatsType = outbound ? 'outbound-rtp' : 'inbound-rtp';
  33179. const filteredResult = new Map();
  33180. if (track === null) {
  33181. return filteredResult;
  33182. }
  33183. const trackStats = [];
  33184. result.forEach(value => {
  33185. if (value.type === 'track' && value.trackIdentifier === track.id) {
  33186. trackStats.push(value);
  33187. }
  33188. });
  33189. trackStats.forEach(trackStat => {
  33190. result.forEach(stats => {
  33191. if (stats.type === streamStatsType && stats.trackId === trackStat.id) {
  33192. walkStats(result, stats, filteredResult);
  33193. }
  33194. });
  33195. });
  33196. return filteredResult;
  33197. }
  33198. function shimMediaStream(window) {
  33199. window.MediaStream = window.MediaStream || window.webkitMediaStream;
  33200. }
  33201. function shimOnTrack(window) {
  33202. if (typeof window === 'object' && window.RTCPeerConnection && !('ontrack' in window.RTCPeerConnection.prototype)) {
  33203. Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {
  33204. get() {
  33205. return this._ontrack;
  33206. },
  33207. set(f) {
  33208. if (this._ontrack) {
  33209. this.removeEventListener('track', this._ontrack);
  33210. }
  33211. this.addEventListener('track', this._ontrack = f);
  33212. },
  33213. enumerable: true,
  33214. configurable: true
  33215. });
  33216. const origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
  33217. window.RTCPeerConnection.prototype.setRemoteDescription = function () {
  33218. if (!this._ontrackpoly) {
  33219. this._ontrackpoly = e => {
  33220. // onaddstream does not fire when a track is added to an existing
  33221. // stream. But stream.onaddtrack is implemented so we use that.
  33222. e.stream.addEventListener('addtrack', te => {
  33223. let receiver;
  33224. if (window.RTCPeerConnection.prototype.getReceivers) {
  33225. receiver = this.getReceivers().find(r => r.track && r.track.id === te.track.id);
  33226. } else {
  33227. receiver = {
  33228. track: te.track
  33229. };
  33230. }
  33231. const event = new Event('track');
  33232. event.track = te.track;
  33233. event.receiver = receiver;
  33234. event.transceiver = {
  33235. receiver
  33236. };
  33237. event.streams = [e.stream];
  33238. this.dispatchEvent(event);
  33239. });
  33240. e.stream.getTracks().forEach(track => {
  33241. let receiver;
  33242. if (window.RTCPeerConnection.prototype.getReceivers) {
  33243. receiver = this.getReceivers().find(r => r.track && r.track.id === track.id);
  33244. } else {
  33245. receiver = {
  33246. track
  33247. };
  33248. }
  33249. const event = new Event('track');
  33250. event.track = track;
  33251. event.receiver = receiver;
  33252. event.transceiver = {
  33253. receiver
  33254. };
  33255. event.streams = [e.stream];
  33256. this.dispatchEvent(event);
  33257. });
  33258. };
  33259. this.addEventListener('addstream', this._ontrackpoly);
  33260. }
  33261. return origSetRemoteDescription.apply(this, arguments);
  33262. };
  33263. } else {
  33264. // even if RTCRtpTransceiver is in window, it is only used and
  33265. // emitted in unified-plan. Unfortunately this means we need
  33266. // to unconditionally wrap the event.
  33267. __WEBPACK_IMPORTED_MODULE_0__utils_js__["g" /* wrapPeerConnectionEvent */](window, 'track', e => {
  33268. if (!e.transceiver) {
  33269. Object.defineProperty(e, 'transceiver', {
  33270. value: {
  33271. receiver: e.receiver
  33272. }
  33273. });
  33274. }
  33275. return e;
  33276. });
  33277. }
  33278. }
  33279. function shimGetSendersWithDtmf(window) {
  33280. // Overrides addTrack/removeTrack, depends on shimAddTrackRemoveTrack.
  33281. if (typeof window === 'object' && window.RTCPeerConnection && !('getSenders' in window.RTCPeerConnection.prototype) && 'createDTMFSender' in window.RTCPeerConnection.prototype) {
  33282. const shimSenderWithDtmf = function (pc, track) {
  33283. return {
  33284. track,
  33285. get dtmf() {
  33286. if (this._dtmf === undefined) {
  33287. if (track.kind === 'audio') {
  33288. this._dtmf = pc.createDTMFSender(track);
  33289. } else {
  33290. this._dtmf = null;
  33291. }
  33292. }
  33293. return this._dtmf;
  33294. },
  33295. _pc: pc
  33296. };
  33297. }; // augment addTrack when getSenders is not available.
  33298. if (!window.RTCPeerConnection.prototype.getSenders) {
  33299. window.RTCPeerConnection.prototype.getSenders = function () {
  33300. this._senders = this._senders || [];
  33301. return this._senders.slice(); // return a copy of the internal state.
  33302. };
  33303. const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  33304. window.RTCPeerConnection.prototype.addTrack = function (track, stream) {
  33305. let sender = origAddTrack.apply(this, arguments);
  33306. if (!sender) {
  33307. sender = shimSenderWithDtmf(this, track);
  33308. this._senders.push(sender);
  33309. }
  33310. return sender;
  33311. };
  33312. const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
  33313. window.RTCPeerConnection.prototype.removeTrack = function (sender) {
  33314. origRemoveTrack.apply(this, arguments);
  33315. const idx = this._senders.indexOf(sender);
  33316. if (idx !== -1) {
  33317. this._senders.splice(idx, 1);
  33318. }
  33319. };
  33320. }
  33321. const origAddStream = window.RTCPeerConnection.prototype.addStream;
  33322. window.RTCPeerConnection.prototype.addStream = function (stream) {
  33323. this._senders = this._senders || [];
  33324. origAddStream.apply(this, [stream]);
  33325. stream.getTracks().forEach(track => {
  33326. this._senders.push(shimSenderWithDtmf(this, track));
  33327. });
  33328. };
  33329. const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
  33330. window.RTCPeerConnection.prototype.removeStream = function (stream) {
  33331. this._senders = this._senders || [];
  33332. origRemoveStream.apply(this, [stream]);
  33333. stream.getTracks().forEach(track => {
  33334. const sender = this._senders.find(s => s.track === track);
  33335. if (sender) {
  33336. // remove sender
  33337. this._senders.splice(this._senders.indexOf(sender), 1);
  33338. }
  33339. });
  33340. };
  33341. } else if (typeof window === 'object' && window.RTCPeerConnection && 'getSenders' in window.RTCPeerConnection.prototype && 'createDTMFSender' in window.RTCPeerConnection.prototype && window.RTCRtpSender && !('dtmf' in window.RTCRtpSender.prototype)) {
  33342. const origGetSenders = window.RTCPeerConnection.prototype.getSenders;
  33343. window.RTCPeerConnection.prototype.getSenders = function () {
  33344. const senders = origGetSenders.apply(this, []);
  33345. senders.forEach(sender => sender._pc = this);
  33346. return senders;
  33347. };
  33348. Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', {
  33349. get() {
  33350. if (this._dtmf === undefined) {
  33351. if (this.track.kind === 'audio') {
  33352. this._dtmf = this._pc.createDTMFSender(this.track);
  33353. } else {
  33354. this._dtmf = null;
  33355. }
  33356. }
  33357. return this._dtmf;
  33358. }
  33359. });
  33360. }
  33361. }
  33362. function shimSenderReceiverGetStats(window) {
  33363. if (!(typeof window === 'object' && window.RTCPeerConnection && window.RTCRtpSender && window.RTCRtpReceiver)) {
  33364. return;
  33365. } // shim sender stats.
  33366. if (!('getStats' in window.RTCRtpSender.prototype)) {
  33367. const origGetSenders = window.RTCPeerConnection.prototype.getSenders;
  33368. if (origGetSenders) {
  33369. window.RTCPeerConnection.prototype.getSenders = function () {
  33370. const senders = origGetSenders.apply(this, []);
  33371. senders.forEach(sender => sender._pc = this);
  33372. return senders;
  33373. };
  33374. }
  33375. const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  33376. if (origAddTrack) {
  33377. window.RTCPeerConnection.prototype.addTrack = function () {
  33378. const sender = origAddTrack.apply(this, arguments);
  33379. sender._pc = this;
  33380. return sender;
  33381. };
  33382. }
  33383. window.RTCRtpSender.prototype.getStats = function () {
  33384. const sender = this;
  33385. return this._pc.getStats().then(result =>
  33386. /* Note: this will include stats of all senders that
  33387. * send a track with the same id as sender.track as
  33388. * it is not possible to identify the RTCRtpSender.
  33389. */
  33390. filterStats(result, sender.track, true));
  33391. };
  33392. } // shim receiver stats.
  33393. if (!('getStats' in window.RTCRtpReceiver.prototype)) {
  33394. const origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;
  33395. if (origGetReceivers) {
  33396. window.RTCPeerConnection.prototype.getReceivers = function () {
  33397. const receivers = origGetReceivers.apply(this, []);
  33398. receivers.forEach(receiver => receiver._pc = this);
  33399. return receivers;
  33400. };
  33401. }
  33402. __WEBPACK_IMPORTED_MODULE_0__utils_js__["g" /* wrapPeerConnectionEvent */](window, 'track', e => {
  33403. e.receiver._pc = e.srcElement;
  33404. return e;
  33405. });
  33406. window.RTCRtpReceiver.prototype.getStats = function () {
  33407. const receiver = this;
  33408. return this._pc.getStats().then(result => filterStats(result, receiver.track, false));
  33409. };
  33410. }
  33411. if (!('getStats' in window.RTCRtpSender.prototype && 'getStats' in window.RTCRtpReceiver.prototype)) {
  33412. return;
  33413. } // shim RTCPeerConnection.getStats(track).
  33414. const origGetStats = window.RTCPeerConnection.prototype.getStats;
  33415. window.RTCPeerConnection.prototype.getStats = function () {
  33416. if (arguments.length > 0 && arguments[0] instanceof window.MediaStreamTrack) {
  33417. const track = arguments[0];
  33418. let sender;
  33419. let receiver;
  33420. let err;
  33421. this.getSenders().forEach(s => {
  33422. if (s.track === track) {
  33423. if (sender) {
  33424. err = true;
  33425. } else {
  33426. sender = s;
  33427. }
  33428. }
  33429. });
  33430. this.getReceivers().forEach(r => {
  33431. if (r.track === track) {
  33432. if (receiver) {
  33433. err = true;
  33434. } else {
  33435. receiver = r;
  33436. }
  33437. }
  33438. return r.track === track;
  33439. });
  33440. if (err || sender && receiver) {
  33441. return Promise.reject(new DOMException('There are more than one sender or receiver for the track.', 'InvalidAccessError'));
  33442. } else if (sender) {
  33443. return sender.getStats();
  33444. } else if (receiver) {
  33445. return receiver.getStats();
  33446. }
  33447. return Promise.reject(new DOMException('There is no sender or receiver for the track.', 'InvalidAccessError'));
  33448. }
  33449. return origGetStats.apply(this, arguments);
  33450. };
  33451. }
  33452. function shimAddTrackRemoveTrackWithNative(window) {
  33453. // shim addTrack/removeTrack with native variants in order to make
  33454. // the interactions with legacy getLocalStreams behave as in other browsers.
  33455. // Keeps a mapping stream.id => [stream, rtpsenders...]
  33456. window.RTCPeerConnection.prototype.getLocalStreams = function () {
  33457. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  33458. return Object.keys(this._shimmedLocalStreams).map(streamId => this._shimmedLocalStreams[streamId][0]);
  33459. };
  33460. const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  33461. window.RTCPeerConnection.prototype.addTrack = function (track, stream) {
  33462. if (!stream) {
  33463. return origAddTrack.apply(this, arguments);
  33464. }
  33465. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  33466. const sender = origAddTrack.apply(this, arguments);
  33467. if (!this._shimmedLocalStreams[stream.id]) {
  33468. this._shimmedLocalStreams[stream.id] = [stream, sender];
  33469. } else if (this._shimmedLocalStreams[stream.id].indexOf(sender) === -1) {
  33470. this._shimmedLocalStreams[stream.id].push(sender);
  33471. }
  33472. return sender;
  33473. };
  33474. const origAddStream = window.RTCPeerConnection.prototype.addStream;
  33475. window.RTCPeerConnection.prototype.addStream = function (stream) {
  33476. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  33477. stream.getTracks().forEach(track => {
  33478. const alreadyExists = this.getSenders().find(s => s.track === track);
  33479. if (alreadyExists) {
  33480. throw new DOMException('Track already exists.', 'InvalidAccessError');
  33481. }
  33482. });
  33483. const existingSenders = this.getSenders();
  33484. origAddStream.apply(this, arguments);
  33485. const newSenders = this.getSenders().filter(newSender => existingSenders.indexOf(newSender) === -1);
  33486. this._shimmedLocalStreams[stream.id] = [stream].concat(newSenders);
  33487. };
  33488. const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
  33489. window.RTCPeerConnection.prototype.removeStream = function (stream) {
  33490. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  33491. delete this._shimmedLocalStreams[stream.id];
  33492. return origRemoveStream.apply(this, arguments);
  33493. };
  33494. const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
  33495. window.RTCPeerConnection.prototype.removeTrack = function (sender) {
  33496. this._shimmedLocalStreams = this._shimmedLocalStreams || {};
  33497. if (sender) {
  33498. Object.keys(this._shimmedLocalStreams).forEach(streamId => {
  33499. const idx = this._shimmedLocalStreams[streamId].indexOf(sender);
  33500. if (idx !== -1) {
  33501. this._shimmedLocalStreams[streamId].splice(idx, 1);
  33502. }
  33503. if (this._shimmedLocalStreams[streamId].length === 1) {
  33504. delete this._shimmedLocalStreams[streamId];
  33505. }
  33506. });
  33507. }
  33508. return origRemoveTrack.apply(this, arguments);
  33509. };
  33510. }
  33511. function shimAddTrackRemoveTrack(window) {
  33512. if (!window.RTCPeerConnection) {
  33513. return;
  33514. }
  33515. const browserDetails = __WEBPACK_IMPORTED_MODULE_0__utils_js__["b" /* detectBrowser */](window); // shim addTrack and removeTrack.
  33516. if (window.RTCPeerConnection.prototype.addTrack && browserDetails.version >= 65) {
  33517. return shimAddTrackRemoveTrackWithNative(window);
  33518. } // also shim pc.getLocalStreams when addTrack is shimmed
  33519. // to return the original streams.
  33520. const origGetLocalStreams = window.RTCPeerConnection.prototype.getLocalStreams;
  33521. window.RTCPeerConnection.prototype.getLocalStreams = function () {
  33522. const nativeStreams = origGetLocalStreams.apply(this);
  33523. this._reverseStreams = this._reverseStreams || {};
  33524. return nativeStreams.map(stream => this._reverseStreams[stream.id]);
  33525. };
  33526. const origAddStream = window.RTCPeerConnection.prototype.addStream;
  33527. window.RTCPeerConnection.prototype.addStream = function (stream) {
  33528. this._streams = this._streams || {};
  33529. this._reverseStreams = this._reverseStreams || {};
  33530. stream.getTracks().forEach(track => {
  33531. const alreadyExists = this.getSenders().find(s => s.track === track);
  33532. if (alreadyExists) {
  33533. throw new DOMException('Track already exists.', 'InvalidAccessError');
  33534. }
  33535. }); // Add identity mapping for consistency with addTrack.
  33536. // Unless this is being used with a stream from addTrack.
  33537. if (!this._reverseStreams[stream.id]) {
  33538. const newStream = new window.MediaStream(stream.getTracks());
  33539. this._streams[stream.id] = newStream;
  33540. this._reverseStreams[newStream.id] = stream;
  33541. stream = newStream;
  33542. }
  33543. origAddStream.apply(this, [stream]);
  33544. };
  33545. const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
  33546. window.RTCPeerConnection.prototype.removeStream = function (stream) {
  33547. this._streams = this._streams || {};
  33548. this._reverseStreams = this._reverseStreams || {};
  33549. origRemoveStream.apply(this, [this._streams[stream.id] || stream]);
  33550. delete this._reverseStreams[this._streams[stream.id] ? this._streams[stream.id].id : stream.id];
  33551. delete this._streams[stream.id];
  33552. };
  33553. window.RTCPeerConnection.prototype.addTrack = function (track, stream) {
  33554. if (this.signalingState === 'closed') {
  33555. throw new DOMException('The RTCPeerConnection\'s signalingState is \'closed\'.', 'InvalidStateError');
  33556. }
  33557. const streams = [].slice.call(arguments, 1);
  33558. if (streams.length !== 1 || !streams[0].getTracks().find(t => t === track)) {
  33559. // this is not fully correct but all we can manage without
  33560. // [[associated MediaStreams]] internal slot.
  33561. throw new DOMException('The adapter.js addTrack polyfill only supports a single ' + ' stream which is associated with the specified track.', 'NotSupportedError');
  33562. }
  33563. const alreadyExists = this.getSenders().find(s => s.track === track);
  33564. if (alreadyExists) {
  33565. throw new DOMException('Track already exists.', 'InvalidAccessError');
  33566. }
  33567. this._streams = this._streams || {};
  33568. this._reverseStreams = this._reverseStreams || {};
  33569. const oldStream = this._streams[stream.id];
  33570. if (oldStream) {
  33571. // this is using odd Chrome behaviour, use with caution:
  33572. // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
  33573. // Note: we rely on the high-level addTrack/dtmf shim to
  33574. // create the sender with a dtmf sender.
  33575. oldStream.addTrack(track); // Trigger ONN async.
  33576. Promise.resolve().then(() => {
  33577. this.dispatchEvent(new Event('negotiationneeded'));
  33578. });
  33579. } else {
  33580. const newStream = new window.MediaStream([track]);
  33581. this._streams[stream.id] = newStream;
  33582. this._reverseStreams[newStream.id] = stream;
  33583. this.addStream(newStream);
  33584. }
  33585. return this.getSenders().find(s => s.track === track);
  33586. }; // replace the internal stream id with the external one and
  33587. // vice versa.
  33588. function replaceInternalStreamId(pc, description) {
  33589. let sdp = description.sdp;
  33590. Object.keys(pc._reverseStreams || []).forEach(internalId => {
  33591. const externalStream = pc._reverseStreams[internalId];
  33592. const internalStream = pc._streams[externalStream.id];
  33593. sdp = sdp.replace(new RegExp(internalStream.id, 'g'), externalStream.id);
  33594. });
  33595. return new RTCSessionDescription({
  33596. type: description.type,
  33597. sdp
  33598. });
  33599. }
  33600. function replaceExternalStreamId(pc, description) {
  33601. let sdp = description.sdp;
  33602. Object.keys(pc._reverseStreams || []).forEach(internalId => {
  33603. const externalStream = pc._reverseStreams[internalId];
  33604. const internalStream = pc._streams[externalStream.id];
  33605. sdp = sdp.replace(new RegExp(externalStream.id, 'g'), internalStream.id);
  33606. });
  33607. return new RTCSessionDescription({
  33608. type: description.type,
  33609. sdp
  33610. });
  33611. }
  33612. ['createOffer', 'createAnswer'].forEach(function (method) {
  33613. const nativeMethod = window.RTCPeerConnection.prototype[method];
  33614. window.RTCPeerConnection.prototype[method] = function () {
  33615. const args = arguments;
  33616. const isLegacyCall = arguments.length && typeof arguments[0] === 'function';
  33617. if (isLegacyCall) {
  33618. return nativeMethod.apply(this, [description => {
  33619. const desc = replaceInternalStreamId(this, description);
  33620. args[0].apply(null, [desc]);
  33621. }, err => {
  33622. if (args[1]) {
  33623. args[1].apply(null, err);
  33624. }
  33625. }, arguments[2]]);
  33626. }
  33627. return nativeMethod.apply(this, arguments).then(description => replaceInternalStreamId(this, description));
  33628. };
  33629. });
  33630. const origSetLocalDescription = window.RTCPeerConnection.prototype.setLocalDescription;
  33631. window.RTCPeerConnection.prototype.setLocalDescription = function () {
  33632. if (!arguments.length || !arguments[0].type) {
  33633. return origSetLocalDescription.apply(this, arguments);
  33634. }
  33635. arguments[0] = replaceExternalStreamId(this, arguments[0]);
  33636. return origSetLocalDescription.apply(this, arguments);
  33637. }; // TODO: mangle getStats: https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamstats-streamidentifier
  33638. const origLocalDescription = Object.getOwnPropertyDescriptor(window.RTCPeerConnection.prototype, 'localDescription');
  33639. Object.defineProperty(window.RTCPeerConnection.prototype, 'localDescription', {
  33640. get() {
  33641. const description = origLocalDescription.get.apply(this);
  33642. if (description.type === '') {
  33643. return description;
  33644. }
  33645. return replaceInternalStreamId(this, description);
  33646. }
  33647. });
  33648. window.RTCPeerConnection.prototype.removeTrack = function (sender) {
  33649. if (this.signalingState === 'closed') {
  33650. throw new DOMException('The RTCPeerConnection\'s signalingState is \'closed\'.', 'InvalidStateError');
  33651. } // We can not yet check for sender instanceof RTCRtpSender
  33652. // since we shim RTPSender. So we check if sender._pc is set.
  33653. if (!sender._pc) {
  33654. throw new DOMException('Argument 1 of RTCPeerConnection.removeTrack ' + 'does not implement interface RTCRtpSender.', 'TypeError');
  33655. }
  33656. const isLocal = sender._pc === this;
  33657. if (!isLocal) {
  33658. throw new DOMException('Sender was not created by this connection.', 'InvalidAccessError');
  33659. } // Search for the native stream the senders track belongs to.
  33660. this._streams = this._streams || {};
  33661. let stream;
  33662. Object.keys(this._streams).forEach(streamid => {
  33663. const hasTrack = this._streams[streamid].getTracks().find(track => sender.track === track);
  33664. if (hasTrack) {
  33665. stream = this._streams[streamid];
  33666. }
  33667. });
  33668. if (stream) {
  33669. if (stream.getTracks().length === 1) {
  33670. // if this is the last track of the stream, remove the stream. This
  33671. // takes care of any shimmed _senders.
  33672. this.removeStream(this._reverseStreams[stream.id]);
  33673. } else {
  33674. // relying on the same odd chrome behaviour as above.
  33675. stream.removeTrack(sender.track);
  33676. }
  33677. this.dispatchEvent(new Event('negotiationneeded'));
  33678. }
  33679. };
  33680. }
  33681. function shimPeerConnection(window) {
  33682. if (!window.RTCPeerConnection && window.webkitRTCPeerConnection) {
  33683. // very basic support for old versions.
  33684. window.RTCPeerConnection = window.webkitRTCPeerConnection;
  33685. }
  33686. if (!window.RTCPeerConnection) {
  33687. return;
  33688. }
  33689. const origGetStats = window.RTCPeerConnection.prototype.getStats;
  33690. window.RTCPeerConnection.prototype.getStats = function (selector, successCallback, errorCallback) {
  33691. const args = arguments; // If selector is a function then we are in the old style stats so just
  33692. // pass back the original getStats format to avoid breaking old users.
  33693. if (arguments.length > 0 && typeof selector === 'function') {
  33694. return origGetStats.apply(this, arguments);
  33695. } // When spec-style getStats is supported, return those when called with
  33696. // either no arguments or the selector argument is null.
  33697. if (origGetStats.length === 0 && (arguments.length === 0 || typeof arguments[0] !== 'function')) {
  33698. return origGetStats.apply(this, []);
  33699. }
  33700. const fixChromeStats_ = function (response) {
  33701. const standardReport = {};
  33702. const reports = response.result();
  33703. reports.forEach(report => {
  33704. const standardStats = {
  33705. id: report.id,
  33706. timestamp: report.timestamp,
  33707. type: {
  33708. localcandidate: 'local-candidate',
  33709. remotecandidate: 'remote-candidate'
  33710. }[report.type] || report.type
  33711. };
  33712. report.names().forEach(name => {
  33713. standardStats[name] = report.stat(name);
  33714. });
  33715. standardReport[standardStats.id] = standardStats;
  33716. });
  33717. return standardReport;
  33718. }; // shim getStats with maplike support
  33719. const makeMapStats = function (stats) {
  33720. return new Map(Object.keys(stats).map(key => [key, stats[key]]));
  33721. };
  33722. if (arguments.length >= 2) {
  33723. const successCallbackWrapper_ = function (response) {
  33724. args[1](makeMapStats(fixChromeStats_(response)));
  33725. };
  33726. return origGetStats.apply(this, [successCallbackWrapper_, arguments[0]]);
  33727. } // promise-support
  33728. return new Promise((resolve, reject) => {
  33729. origGetStats.apply(this, [function (response) {
  33730. resolve(makeMapStats(fixChromeStats_(response)));
  33731. }, reject]);
  33732. }).then(successCallback, errorCallback);
  33733. }; // shim implicit creation of RTCSessionDescription/RTCIceCandidate
  33734. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'].forEach(function (method) {
  33735. const nativeMethod = window.RTCPeerConnection.prototype[method];
  33736. window.RTCPeerConnection.prototype[method] = function () {
  33737. arguments[0] = new (method === 'addIceCandidate' ? window.RTCIceCandidate : window.RTCSessionDescription)(arguments[0]);
  33738. return nativeMethod.apply(this, arguments);
  33739. };
  33740. }); // support for addIceCandidate(null or undefined)
  33741. const nativeAddIceCandidate = window.RTCPeerConnection.prototype.addIceCandidate;
  33742. window.RTCPeerConnection.prototype.addIceCandidate = function () {
  33743. if (!arguments[0]) {
  33744. if (arguments[1]) {
  33745. arguments[1].apply(null);
  33746. }
  33747. return Promise.resolve();
  33748. }
  33749. return nativeAddIceCandidate.apply(this, arguments);
  33750. };
  33751. }
  33752. function fixNegotiationNeeded(window) {
  33753. __WEBPACK_IMPORTED_MODULE_0__utils_js__["g" /* wrapPeerConnectionEvent */](window, 'negotiationneeded', e => {
  33754. const pc = e.target;
  33755. if (pc.signalingState !== 'stable') {
  33756. return;
  33757. }
  33758. return e;
  33759. });
  33760. }
  33761. }),
  33762. /* 47 */
  33763. (function(module, __webpack_exports__, __webpack_require__) {
  33764. "use strict";
  33765. /* harmony export (immutable) */ __webpack_exports__["a"] = shimGetUserMedia;
  33766. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils_js__ = __webpack_require__(4);
  33767. /*
  33768. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  33769. *
  33770. * Use of this source code is governed by a BSD-style license
  33771. * that can be found in the LICENSE file in the root of the source
  33772. * tree.
  33773. */
  33774. /* eslint-env node */
  33775. const logging = __WEBPACK_IMPORTED_MODULE_0__utils_js__["f" /* log */];
  33776. function shimGetUserMedia(window) {
  33777. const navigator = window && window.navigator;
  33778. if (!navigator.mediaDevices) {
  33779. return;
  33780. }
  33781. const browserDetails = __WEBPACK_IMPORTED_MODULE_0__utils_js__["b" /* detectBrowser */](window);
  33782. const constraintsToChrome_ = function (c) {
  33783. if (typeof c !== 'object' || c.mandatory || c.optional) {
  33784. return c;
  33785. }
  33786. const cc = {};
  33787. Object.keys(c).forEach(key => {
  33788. if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
  33789. return;
  33790. }
  33791. const r = typeof c[key] === 'object' ? c[key] : {
  33792. ideal: c[key]
  33793. };
  33794. if (r.exact !== undefined && typeof r.exact === 'number') {
  33795. r.min = r.max = r.exact;
  33796. }
  33797. const oldname_ = function (prefix, name) {
  33798. if (prefix) {
  33799. return prefix + name.charAt(0).toUpperCase() + name.slice(1);
  33800. }
  33801. return name === 'deviceId' ? 'sourceId' : name;
  33802. };
  33803. if (r.ideal !== undefined) {
  33804. cc.optional = cc.optional || [];
  33805. let oc = {};
  33806. if (typeof r.ideal === 'number') {
  33807. oc[oldname_('min', key)] = r.ideal;
  33808. cc.optional.push(oc);
  33809. oc = {};
  33810. oc[oldname_('max', key)] = r.ideal;
  33811. cc.optional.push(oc);
  33812. } else {
  33813. oc[oldname_('', key)] = r.ideal;
  33814. cc.optional.push(oc);
  33815. }
  33816. }
  33817. if (r.exact !== undefined && typeof r.exact !== 'number') {
  33818. cc.mandatory = cc.mandatory || {};
  33819. cc.mandatory[oldname_('', key)] = r.exact;
  33820. } else {
  33821. ['min', 'max'].forEach(mix => {
  33822. if (r[mix] !== undefined) {
  33823. cc.mandatory = cc.mandatory || {};
  33824. cc.mandatory[oldname_(mix, key)] = r[mix];
  33825. }
  33826. });
  33827. }
  33828. });
  33829. if (c.advanced) {
  33830. cc.optional = (cc.optional || []).concat(c.advanced);
  33831. }
  33832. return cc;
  33833. };
  33834. const shimConstraints_ = function (constraints, func) {
  33835. if (browserDetails.version >= 61) {
  33836. return func(constraints);
  33837. }
  33838. constraints = JSON.parse(JSON.stringify(constraints));
  33839. if (constraints && typeof constraints.audio === 'object') {
  33840. const remap = function (obj, a, b) {
  33841. if (a in obj && !(b in obj)) {
  33842. obj[b] = obj[a];
  33843. delete obj[a];
  33844. }
  33845. };
  33846. constraints = JSON.parse(JSON.stringify(constraints));
  33847. remap(constraints.audio, 'autoGainControl', 'googAutoGainControl');
  33848. remap(constraints.audio, 'noiseSuppression', 'googNoiseSuppression');
  33849. constraints.audio = constraintsToChrome_(constraints.audio);
  33850. }
  33851. if (constraints && typeof constraints.video === 'object') {
  33852. // Shim facingMode for mobile & surface pro.
  33853. let face = constraints.video.facingMode;
  33854. face = face && (typeof face === 'object' ? face : {
  33855. ideal: face
  33856. });
  33857. const getSupportedFacingModeLies = browserDetails.version < 66;
  33858. if (face && (face.exact === 'user' || face.exact === 'environment' || face.ideal === 'user' || face.ideal === 'environment') && !(navigator.mediaDevices.getSupportedConstraints && navigator.mediaDevices.getSupportedConstraints().facingMode && !getSupportedFacingModeLies)) {
  33859. delete constraints.video.facingMode;
  33860. let matches;
  33861. if (face.exact === 'environment' || face.ideal === 'environment') {
  33862. matches = ['back', 'rear'];
  33863. } else if (face.exact === 'user' || face.ideal === 'user') {
  33864. matches = ['front'];
  33865. }
  33866. if (matches) {
  33867. // Look for matches in label, or use last cam for back (typical).
  33868. return navigator.mediaDevices.enumerateDevices().then(devices => {
  33869. devices = devices.filter(d => d.kind === 'videoinput');
  33870. let dev = devices.find(d => matches.some(match => d.label.toLowerCase().includes(match)));
  33871. if (!dev && devices.length && matches.includes('back')) {
  33872. dev = devices[devices.length - 1]; // more likely the back cam
  33873. }
  33874. if (dev) {
  33875. constraints.video.deviceId = face.exact ? {
  33876. exact: dev.deviceId
  33877. } : {
  33878. ideal: dev.deviceId
  33879. };
  33880. }
  33881. constraints.video = constraintsToChrome_(constraints.video);
  33882. logging('chrome: ' + JSON.stringify(constraints));
  33883. return func(constraints);
  33884. });
  33885. }
  33886. }
  33887. constraints.video = constraintsToChrome_(constraints.video);
  33888. }
  33889. logging('chrome: ' + JSON.stringify(constraints));
  33890. return func(constraints);
  33891. };
  33892. const shimError_ = function (e) {
  33893. if (browserDetails.version >= 64) {
  33894. return e;
  33895. }
  33896. return {
  33897. name: {
  33898. PermissionDeniedError: 'NotAllowedError',
  33899. PermissionDismissedError: 'NotAllowedError',
  33900. InvalidStateError: 'NotAllowedError',
  33901. DevicesNotFoundError: 'NotFoundError',
  33902. ConstraintNotSatisfiedError: 'OverconstrainedError',
  33903. TrackStartError: 'NotReadableError',
  33904. MediaDeviceFailedDueToShutdown: 'NotAllowedError',
  33905. MediaDeviceKillSwitchOn: 'NotAllowedError',
  33906. TabCaptureError: 'AbortError',
  33907. ScreenCaptureError: 'AbortError',
  33908. DeviceCaptureError: 'AbortError'
  33909. }[e.name] || e.name,
  33910. message: e.message,
  33911. constraint: e.constraint || e.constraintName,
  33912. toString() {
  33913. return this.name + (this.message && ': ') + this.message;
  33914. }
  33915. };
  33916. };
  33917. const getUserMedia_ = function (constraints, onSuccess, onError) {
  33918. shimConstraints_(constraints, c => {
  33919. navigator.webkitGetUserMedia(c, onSuccess, e => {
  33920. if (onError) {
  33921. onError(shimError_(e));
  33922. }
  33923. });
  33924. });
  33925. };
  33926. navigator.getUserMedia = getUserMedia_.bind(navigator); // Even though Chrome 45 has navigator.mediaDevices and a getUserMedia
  33927. // function which returns a Promise, it does not accept spec-style
  33928. // constraints.
  33929. const origGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
  33930. navigator.mediaDevices.getUserMedia = function (cs) {
  33931. return shimConstraints_(cs, c => origGetUserMedia(c).then(stream => {
  33932. if (c.audio && !stream.getAudioTracks().length || c.video && !stream.getVideoTracks().length) {
  33933. stream.getTracks().forEach(track => {
  33934. track.stop();
  33935. });
  33936. throw new DOMException('', 'NotFoundError');
  33937. }
  33938. return stream;
  33939. }, e => Promise.reject(shimError_(e))));
  33940. };
  33941. }
  33942. }),
  33943. /* 48 */
  33944. (function(module, __webpack_exports__, __webpack_require__) {
  33945. "use strict";
  33946. /* harmony export (immutable) */ __webpack_exports__["a"] = shimGetDisplayMedia;
  33947. /*
  33948. * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.
  33949. *
  33950. * Use of this source code is governed by a BSD-style license
  33951. * that can be found in the LICENSE file in the root of the source
  33952. * tree.
  33953. */
  33954. /* eslint-env node */
  33955. function shimGetDisplayMedia(window, getSourceId) {
  33956. if (window.navigator.mediaDevices && 'getDisplayMedia' in window.navigator.mediaDevices) {
  33957. return;
  33958. }
  33959. if (!window.navigator.mediaDevices) {
  33960. return;
  33961. } // getSourceId is a function that returns a promise resolving with
  33962. // the sourceId of the screen/window/tab to be shared.
  33963. if (typeof getSourceId !== 'function') {
  33964. console.error('shimGetDisplayMedia: getSourceId argument is not ' + 'a function');
  33965. return;
  33966. }
  33967. window.navigator.mediaDevices.getDisplayMedia = function (constraints) {
  33968. return getSourceId(constraints).then(sourceId => {
  33969. const widthSpecified = constraints.video && constraints.video.width;
  33970. const heightSpecified = constraints.video && constraints.video.height;
  33971. const frameRateSpecified = constraints.video && constraints.video.frameRate;
  33972. constraints.video = {
  33973. mandatory: {
  33974. chromeMediaSource: 'desktop',
  33975. chromeMediaSourceId: sourceId,
  33976. maxFrameRate: frameRateSpecified || 3
  33977. }
  33978. };
  33979. if (widthSpecified) {
  33980. constraints.video.mandatory.maxWidth = widthSpecified;
  33981. }
  33982. if (heightSpecified) {
  33983. constraints.video.mandatory.maxHeight = heightSpecified;
  33984. }
  33985. return window.navigator.mediaDevices.getUserMedia(constraints);
  33986. });
  33987. };
  33988. }
  33989. }),
  33990. /* 49 */
  33991. (function(module, __webpack_exports__, __webpack_require__) {
  33992. "use strict";
  33993. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  33994. /* harmony export (immutable) */ __webpack_exports__["shimPeerConnection"] = shimPeerConnection;
  33995. /* harmony export (immutable) */ __webpack_exports__["shimReplaceTrack"] = shimReplaceTrack;
  33996. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(4);
  33997. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__filtericeservers__ = __webpack_require__(50);
  33998. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_rtcpeerconnection_shim__ = __webpack_require__(51);
  33999. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_rtcpeerconnection_shim___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_rtcpeerconnection_shim__);
  34000. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__getusermedia__ = __webpack_require__(52);
  34001. /* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "shimGetUserMedia", function() { return __WEBPACK_IMPORTED_MODULE_3__getusermedia__["a"]; });
  34002. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__getdisplaymedia__ = __webpack_require__(53);
  34003. /* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "shimGetDisplayMedia", function() { return __WEBPACK_IMPORTED_MODULE_4__getdisplaymedia__["a"]; });
  34004. /*
  34005. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  34006. *
  34007. * Use of this source code is governed by a BSD-style license
  34008. * that can be found in the LICENSE file in the root of the source
  34009. * tree.
  34010. */
  34011. /* eslint-env node */
  34012. function shimPeerConnection(window) {
  34013. const browserDetails = __WEBPACK_IMPORTED_MODULE_0__utils__["b" /* detectBrowser */](window);
  34014. if (window.RTCIceGatherer) {
  34015. if (!window.RTCIceCandidate) {
  34016. window.RTCIceCandidate = function (args) {
  34017. return args;
  34018. };
  34019. }
  34020. if (!window.RTCSessionDescription) {
  34021. window.RTCSessionDescription = function (args) {
  34022. return args;
  34023. };
  34024. } // this adds an additional event listener to MediaStrackTrack that signals
  34025. // when a tracks enabled property was changed. Workaround for a bug in
  34026. // addStream, see below. No longer required in 15025+
  34027. if (browserDetails.version < 15025) {
  34028. const origMSTEnabled = Object.getOwnPropertyDescriptor(window.MediaStreamTrack.prototype, 'enabled');
  34029. Object.defineProperty(window.MediaStreamTrack.prototype, 'enabled', {
  34030. set(value) {
  34031. origMSTEnabled.set.call(this, value);
  34032. const ev = new Event('enabled');
  34033. ev.enabled = value;
  34034. this.dispatchEvent(ev);
  34035. }
  34036. });
  34037. }
  34038. } // ORTC defines the DTMF sender a bit different.
  34039. // https://github.com/w3c/ortc/issues/714
  34040. if (window.RTCRtpSender && !('dtmf' in window.RTCRtpSender.prototype)) {
  34041. Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', {
  34042. get() {
  34043. if (this._dtmf === undefined) {
  34044. if (this.track.kind === 'audio') {
  34045. this._dtmf = new window.RTCDtmfSender(this);
  34046. } else if (this.track.kind === 'video') {
  34047. this._dtmf = null;
  34048. }
  34049. }
  34050. return this._dtmf;
  34051. }
  34052. });
  34053. } // Edge currently only implements the RTCDtmfSender, not the
  34054. // RTCDTMFSender alias. See http://draft.ortc.org/#rtcdtmfsender2*
  34055. if (window.RTCDtmfSender && !window.RTCDTMFSender) {
  34056. window.RTCDTMFSender = window.RTCDtmfSender;
  34057. }
  34058. const RTCPeerConnectionShim = __WEBPACK_IMPORTED_MODULE_2_rtcpeerconnection_shim___default()(window, browserDetails.version);
  34059. window.RTCPeerConnection = function (config) {
  34060. if (config && config.iceServers) {
  34061. config.iceServers = Object(__WEBPACK_IMPORTED_MODULE_1__filtericeservers__["a" /* filterIceServers */])(config.iceServers, browserDetails.version);
  34062. __WEBPACK_IMPORTED_MODULE_0__utils__["f" /* log */]('ICE servers after filtering:', config.iceServers);
  34063. }
  34064. return new RTCPeerConnectionShim(config);
  34065. };
  34066. window.RTCPeerConnection.prototype = RTCPeerConnectionShim.prototype;
  34067. }
  34068. function shimReplaceTrack(window) {
  34069. // ORTC has replaceTrack -- https://github.com/w3c/ortc/issues/614
  34070. if (window.RTCRtpSender && !('replaceTrack' in window.RTCRtpSender.prototype)) {
  34071. window.RTCRtpSender.prototype.replaceTrack = window.RTCRtpSender.prototype.setTrack;
  34072. }
  34073. }
  34074. }),
  34075. /* 50 */
  34076. (function(module, __webpack_exports__, __webpack_require__) {
  34077. "use strict";
  34078. /* harmony export (immutable) */ __webpack_exports__["a"] = filterIceServers;
  34079. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(4);
  34080. /*
  34081. * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
  34082. *
  34083. * Use of this source code is governed by a BSD-style license
  34084. * that can be found in the LICENSE file in the root of the source
  34085. * tree.
  34086. */
  34087. /* eslint-env node */
  34088. // Edge does not like
  34089. // 1) stun: filtered after 14393 unless ?transport=udp is present
  34090. // 2) turn: that does not have all of turn:host:port?transport=udp
  34091. // 3) turn: with ipv6 addresses
  34092. // 4) turn: occurring muliple times
  34093. function filterIceServers(iceServers, edgeVersion) {
  34094. let hasTurn = false;
  34095. iceServers = JSON.parse(JSON.stringify(iceServers));
  34096. return iceServers.filter(server => {
  34097. if (server && (server.urls || server.url)) {
  34098. var urls = server.urls || server.url;
  34099. if (server.url && !server.urls) {
  34100. __WEBPACK_IMPORTED_MODULE_0__utils__["a" /* deprecated */]('RTCIceServer.url', 'RTCIceServer.urls');
  34101. }
  34102. const isString = typeof urls === 'string';
  34103. if (isString) {
  34104. urls = [urls];
  34105. }
  34106. urls = urls.filter(url => {
  34107. // filter STUN unconditionally.
  34108. if (url.indexOf('stun:') === 0) {
  34109. return false;
  34110. }
  34111. const validTurn = url.startsWith('turn') && !url.startsWith('turn:[') && url.includes('transport=udp');
  34112. if (validTurn && !hasTurn) {
  34113. hasTurn = true;
  34114. return true;
  34115. }
  34116. return validTurn && !hasTurn;
  34117. });
  34118. delete server.url;
  34119. server.urls = isString ? urls[0] : urls;
  34120. return !!urls.length;
  34121. }
  34122. });
  34123. }
  34124. }),
  34125. /* 51 */
  34126. (function(module, exports, __webpack_require__) {
  34127. "use strict";
  34128. /*
  34129. * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  34130. *
  34131. * Use of this source code is governed by a BSD-style license
  34132. * that can be found in the LICENSE file in the root of the source
  34133. * tree.
  34134. */
  34135. /* eslint-env node */
  34136. var SDPUtils = __webpack_require__(19);
  34137. function fixStatsType(stat) {
  34138. return {
  34139. inboundrtp: 'inbound-rtp',
  34140. outboundrtp: 'outbound-rtp',
  34141. candidatepair: 'candidate-pair',
  34142. localcandidate: 'local-candidate',
  34143. remotecandidate: 'remote-candidate'
  34144. }[stat.type] || stat.type;
  34145. }
  34146. function writeMediaSection(transceiver, caps, type, stream, dtlsRole) {
  34147. var sdp = SDPUtils.writeRtpDescription(transceiver.kind, caps); // Map ICE parameters (ufrag, pwd) to SDP.
  34148. sdp += SDPUtils.writeIceParameters(transceiver.iceGatherer.getLocalParameters()); // Map DTLS parameters to SDP.
  34149. sdp += SDPUtils.writeDtlsParameters(transceiver.dtlsTransport.getLocalParameters(), type === 'offer' ? 'actpass' : dtlsRole || 'active');
  34150. sdp += 'a=mid:' + transceiver.mid + '\r\n';
  34151. if (transceiver.rtpSender && transceiver.rtpReceiver) {
  34152. sdp += 'a=sendrecv\r\n';
  34153. } else if (transceiver.rtpSender) {
  34154. sdp += 'a=sendonly\r\n';
  34155. } else if (transceiver.rtpReceiver) {
  34156. sdp += 'a=recvonly\r\n';
  34157. } else {
  34158. sdp += 'a=inactive\r\n';
  34159. }
  34160. if (transceiver.rtpSender) {
  34161. var trackId = transceiver.rtpSender._initialTrackId || transceiver.rtpSender.track.id;
  34162. transceiver.rtpSender._initialTrackId = trackId; // spec.
  34163. var msid = 'msid:' + (stream ? stream.id : '-') + ' ' + trackId + '\r\n';
  34164. sdp += 'a=' + msid; // for Chrome. Legacy should no longer be required.
  34165. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc + ' ' + msid; // RTX
  34166. if (transceiver.sendEncodingParameters[0].rtx) {
  34167. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc + ' ' + msid;
  34168. sdp += 'a=ssrc-group:FID ' + transceiver.sendEncodingParameters[0].ssrc + ' ' + transceiver.sendEncodingParameters[0].rtx.ssrc + '\r\n';
  34169. }
  34170. } // FIXME: this should be written by writeRtpDescription.
  34171. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc + ' cname:' + SDPUtils.localCName + '\r\n';
  34172. if (transceiver.rtpSender && transceiver.sendEncodingParameters[0].rtx) {
  34173. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc + ' cname:' + SDPUtils.localCName + '\r\n';
  34174. }
  34175. return sdp;
  34176. } // Edge does not like
  34177. // 1) stun: filtered after 14393 unless ?transport=udp is present
  34178. // 2) turn: that does not have all of turn:host:port?transport=udp
  34179. // 3) turn: with ipv6 addresses
  34180. // 4) turn: occurring muliple times
  34181. function filterIceServers(iceServers, edgeVersion) {
  34182. var hasTurn = false;
  34183. iceServers = JSON.parse(JSON.stringify(iceServers));
  34184. return iceServers.filter(function (server) {
  34185. if (server && (server.urls || server.url)) {
  34186. var urls = server.urls || server.url;
  34187. if (server.url && !server.urls) {
  34188. console.warn('RTCIceServer.url is deprecated! Use urls instead.');
  34189. }
  34190. var isString = typeof urls === 'string';
  34191. if (isString) {
  34192. urls = [urls];
  34193. }
  34194. urls = urls.filter(function (url) {
  34195. var validTurn = url.indexOf('turn:') === 0 && url.indexOf('transport=udp') !== -1 && url.indexOf('turn:[') === -1 && !hasTurn;
  34196. if (validTurn) {
  34197. hasTurn = true;
  34198. return true;
  34199. }
  34200. return url.indexOf('stun:') === 0 && edgeVersion >= 14393 && url.indexOf('?transport=udp') === -1;
  34201. });
  34202. delete server.url;
  34203. server.urls = isString ? urls[0] : urls;
  34204. return !!urls.length;
  34205. }
  34206. });
  34207. } // Determines the intersection of local and remote capabilities.
  34208. function getCommonCapabilities(localCapabilities, remoteCapabilities) {
  34209. var commonCapabilities = {
  34210. codecs: [],
  34211. headerExtensions: [],
  34212. fecMechanisms: []
  34213. };
  34214. var findCodecByPayloadType = function (pt, codecs) {
  34215. pt = parseInt(pt, 10);
  34216. for (var i = 0; i < codecs.length; i++) {
  34217. if (codecs[i].payloadType === pt || codecs[i].preferredPayloadType === pt) {
  34218. return codecs[i];
  34219. }
  34220. }
  34221. };
  34222. var rtxCapabilityMatches = function (lRtx, rRtx, lCodecs, rCodecs) {
  34223. var lCodec = findCodecByPayloadType(lRtx.parameters.apt, lCodecs);
  34224. var rCodec = findCodecByPayloadType(rRtx.parameters.apt, rCodecs);
  34225. return lCodec && rCodec && lCodec.name.toLowerCase() === rCodec.name.toLowerCase();
  34226. };
  34227. localCapabilities.codecs.forEach(function (lCodec) {
  34228. for (var i = 0; i < remoteCapabilities.codecs.length; i++) {
  34229. var rCodec = remoteCapabilities.codecs[i];
  34230. if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() && lCodec.clockRate === rCodec.clockRate) {
  34231. if (lCodec.name.toLowerCase() === 'rtx' && lCodec.parameters && rCodec.parameters.apt) {
  34232. // for RTX we need to find the local rtx that has a apt
  34233. // which points to the same local codec as the remote one.
  34234. if (!rtxCapabilityMatches(lCodec, rCodec, localCapabilities.codecs, remoteCapabilities.codecs)) {
  34235. continue;
  34236. }
  34237. }
  34238. rCodec = JSON.parse(JSON.stringify(rCodec)); // deepcopy
  34239. // number of channels is the highest common number of channels
  34240. rCodec.numChannels = Math.min(lCodec.numChannels, rCodec.numChannels); // push rCodec so we reply with offerer payload type
  34241. commonCapabilities.codecs.push(rCodec); // determine common feedback mechanisms
  34242. rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function (fb) {
  34243. for (var j = 0; j < lCodec.rtcpFeedback.length; j++) {
  34244. if (lCodec.rtcpFeedback[j].type === fb.type && lCodec.rtcpFeedback[j].parameter === fb.parameter) {
  34245. return true;
  34246. }
  34247. }
  34248. return false;
  34249. }); // FIXME: also need to determine .parameters
  34250. // see https://github.com/openpeer/ortc/issues/569
  34251. break;
  34252. }
  34253. }
  34254. });
  34255. localCapabilities.headerExtensions.forEach(function (lHeaderExtension) {
  34256. for (var i = 0; i < remoteCapabilities.headerExtensions.length; i++) {
  34257. var rHeaderExtension = remoteCapabilities.headerExtensions[i];
  34258. if (lHeaderExtension.uri === rHeaderExtension.uri) {
  34259. commonCapabilities.headerExtensions.push(rHeaderExtension);
  34260. break;
  34261. }
  34262. }
  34263. }); // FIXME: fecMechanisms
  34264. return commonCapabilities;
  34265. } // is action=setLocalDescription with type allowed in signalingState
  34266. function isActionAllowedInSignalingState(action, type, signalingState) {
  34267. return {
  34268. offer: {
  34269. setLocalDescription: ['stable', 'have-local-offer'],
  34270. setRemoteDescription: ['stable', 'have-remote-offer']
  34271. },
  34272. answer: {
  34273. setLocalDescription: ['have-remote-offer', 'have-local-pranswer'],
  34274. setRemoteDescription: ['have-local-offer', 'have-remote-pranswer']
  34275. }
  34276. }[type][action].indexOf(signalingState) !== -1;
  34277. }
  34278. function maybeAddCandidate(iceTransport, candidate) {
  34279. // Edge's internal representation adds some fields therefore
  34280. // not all fieldѕ are taken into account.
  34281. var alreadyAdded = iceTransport.getRemoteCandidates().find(function (remoteCandidate) {
  34282. return candidate.foundation === remoteCandidate.foundation && candidate.ip === remoteCandidate.ip && candidate.port === remoteCandidate.port && candidate.priority === remoteCandidate.priority && candidate.protocol === remoteCandidate.protocol && candidate.type === remoteCandidate.type;
  34283. });
  34284. if (!alreadyAdded) {
  34285. iceTransport.addRemoteCandidate(candidate);
  34286. }
  34287. return !alreadyAdded;
  34288. }
  34289. function makeError(name, description) {
  34290. var e = new Error(description);
  34291. e.name = name; // legacy error codes from https://heycam.github.io/webidl/#idl-DOMException-error-names
  34292. e.code = {
  34293. NotSupportedError: 9,
  34294. InvalidStateError: 11,
  34295. InvalidAccessError: 15,
  34296. TypeError: undefined,
  34297. OperationError: undefined
  34298. }[name];
  34299. return e;
  34300. }
  34301. module.exports = function (window, edgeVersion) {
  34302. // https://w3c.github.io/mediacapture-main/#mediastream
  34303. // Helper function to add the track to the stream and
  34304. // dispatch the event ourselves.
  34305. function addTrackToStreamAndFireEvent(track, stream) {
  34306. stream.addTrack(track);
  34307. stream.dispatchEvent(new window.MediaStreamTrackEvent('addtrack', {
  34308. track: track
  34309. }));
  34310. }
  34311. function removeTrackFromStreamAndFireEvent(track, stream) {
  34312. stream.removeTrack(track);
  34313. stream.dispatchEvent(new window.MediaStreamTrackEvent('removetrack', {
  34314. track: track
  34315. }));
  34316. }
  34317. function fireAddTrack(pc, track, receiver, streams) {
  34318. var trackEvent = new Event('track');
  34319. trackEvent.track = track;
  34320. trackEvent.receiver = receiver;
  34321. trackEvent.transceiver = {
  34322. receiver: receiver
  34323. };
  34324. trackEvent.streams = streams;
  34325. window.setTimeout(function () {
  34326. pc._dispatchEvent('track', trackEvent);
  34327. });
  34328. }
  34329. var RTCPeerConnection = function (config) {
  34330. var pc = this;
  34331. var _eventTarget = document.createDocumentFragment();
  34332. ['addEventListener', 'removeEventListener', 'dispatchEvent'].forEach(function (method) {
  34333. pc[method] = _eventTarget[method].bind(_eventTarget);
  34334. });
  34335. this.canTrickleIceCandidates = null;
  34336. this.needNegotiation = false;
  34337. this.localStreams = [];
  34338. this.remoteStreams = [];
  34339. this._localDescription = null;
  34340. this._remoteDescription = null;
  34341. this.signalingState = 'stable';
  34342. this.iceConnectionState = 'new';
  34343. this.connectionState = 'new';
  34344. this.iceGatheringState = 'new';
  34345. config = JSON.parse(JSON.stringify(config || {}));
  34346. this.usingBundle = config.bundlePolicy === 'max-bundle';
  34347. if (config.rtcpMuxPolicy === 'negotiate') {
  34348. throw makeError('NotSupportedError', 'rtcpMuxPolicy \'negotiate\' is not supported');
  34349. } else if (!config.rtcpMuxPolicy) {
  34350. config.rtcpMuxPolicy = 'require';
  34351. }
  34352. switch (config.iceTransportPolicy) {
  34353. case 'all':
  34354. case 'relay':
  34355. break;
  34356. default:
  34357. config.iceTransportPolicy = 'all';
  34358. break;
  34359. }
  34360. switch (config.bundlePolicy) {
  34361. case 'balanced':
  34362. case 'max-compat':
  34363. case 'max-bundle':
  34364. break;
  34365. default:
  34366. config.bundlePolicy = 'balanced';
  34367. break;
  34368. }
  34369. config.iceServers = filterIceServers(config.iceServers || [], edgeVersion);
  34370. this._iceGatherers = [];
  34371. if (config.iceCandidatePoolSize) {
  34372. for (var i = config.iceCandidatePoolSize; i > 0; i--) {
  34373. this._iceGatherers.push(new window.RTCIceGatherer({
  34374. iceServers: config.iceServers,
  34375. gatherPolicy: config.iceTransportPolicy
  34376. }));
  34377. }
  34378. } else {
  34379. config.iceCandidatePoolSize = 0;
  34380. }
  34381. this._config = config; // per-track iceGathers, iceTransports, dtlsTransports, rtpSenders, ...
  34382. // everything that is needed to describe a SDP m-line.
  34383. this.transceivers = [];
  34384. this._sdpSessionId = SDPUtils.generateSessionId();
  34385. this._sdpSessionVersion = 0;
  34386. this._dtlsRole = undefined; // role for a=setup to use in answers.
  34387. this._isClosed = false;
  34388. };
  34389. Object.defineProperty(RTCPeerConnection.prototype, 'localDescription', {
  34390. configurable: true,
  34391. get: function () {
  34392. return this._localDescription;
  34393. }
  34394. });
  34395. Object.defineProperty(RTCPeerConnection.prototype, 'remoteDescription', {
  34396. configurable: true,
  34397. get: function () {
  34398. return this._remoteDescription;
  34399. }
  34400. }); // set up event handlers on prototype
  34401. RTCPeerConnection.prototype.onicecandidate = null;
  34402. RTCPeerConnection.prototype.onaddstream = null;
  34403. RTCPeerConnection.prototype.ontrack = null;
  34404. RTCPeerConnection.prototype.onremovestream = null;
  34405. RTCPeerConnection.prototype.onsignalingstatechange = null;
  34406. RTCPeerConnection.prototype.oniceconnectionstatechange = null;
  34407. RTCPeerConnection.prototype.onconnectionstatechange = null;
  34408. RTCPeerConnection.prototype.onicegatheringstatechange = null;
  34409. RTCPeerConnection.prototype.onnegotiationneeded = null;
  34410. RTCPeerConnection.prototype.ondatachannel = null;
  34411. RTCPeerConnection.prototype._dispatchEvent = function (name, event) {
  34412. if (this._isClosed) {
  34413. return;
  34414. }
  34415. this.dispatchEvent(event);
  34416. if (typeof this['on' + name] === 'function') {
  34417. this['on' + name](event);
  34418. }
  34419. };
  34420. RTCPeerConnection.prototype._emitGatheringStateChange = function () {
  34421. var event = new Event('icegatheringstatechange');
  34422. this._dispatchEvent('icegatheringstatechange', event);
  34423. };
  34424. RTCPeerConnection.prototype.getConfiguration = function () {
  34425. return this._config;
  34426. };
  34427. RTCPeerConnection.prototype.getLocalStreams = function () {
  34428. return this.localStreams;
  34429. };
  34430. RTCPeerConnection.prototype.getRemoteStreams = function () {
  34431. return this.remoteStreams;
  34432. }; // internal helper to create a transceiver object.
  34433. // (which is not yet the same as the WebRTC 1.0 transceiver)
  34434. RTCPeerConnection.prototype._createTransceiver = function (kind, doNotAdd) {
  34435. var hasBundleTransport = this.transceivers.length > 0;
  34436. var transceiver = {
  34437. track: null,
  34438. iceGatherer: null,
  34439. iceTransport: null,
  34440. dtlsTransport: null,
  34441. localCapabilities: null,
  34442. remoteCapabilities: null,
  34443. rtpSender: null,
  34444. rtpReceiver: null,
  34445. kind: kind,
  34446. mid: null,
  34447. sendEncodingParameters: null,
  34448. recvEncodingParameters: null,
  34449. stream: null,
  34450. associatedRemoteMediaStreams: [],
  34451. wantReceive: true
  34452. };
  34453. if (this.usingBundle && hasBundleTransport) {
  34454. transceiver.iceTransport = this.transceivers[0].iceTransport;
  34455. transceiver.dtlsTransport = this.transceivers[0].dtlsTransport;
  34456. } else {
  34457. var transports = this._createIceAndDtlsTransports();
  34458. transceiver.iceTransport = transports.iceTransport;
  34459. transceiver.dtlsTransport = transports.dtlsTransport;
  34460. }
  34461. if (!doNotAdd) {
  34462. this.transceivers.push(transceiver);
  34463. }
  34464. return transceiver;
  34465. };
  34466. RTCPeerConnection.prototype.addTrack = function (track, stream) {
  34467. if (this._isClosed) {
  34468. throw makeError('InvalidStateError', 'Attempted to call addTrack on a closed peerconnection.');
  34469. }
  34470. var alreadyExists = this.transceivers.find(function (s) {
  34471. return s.track === track;
  34472. });
  34473. if (alreadyExists) {
  34474. throw makeError('InvalidAccessError', 'Track already exists.');
  34475. }
  34476. var transceiver;
  34477. for (var i = 0; i < this.transceivers.length; i++) {
  34478. if (!this.transceivers[i].track && this.transceivers[i].kind === track.kind) {
  34479. transceiver = this.transceivers[i];
  34480. }
  34481. }
  34482. if (!transceiver) {
  34483. transceiver = this._createTransceiver(track.kind);
  34484. }
  34485. this._maybeFireNegotiationNeeded();
  34486. if (this.localStreams.indexOf(stream) === -1) {
  34487. this.localStreams.push(stream);
  34488. }
  34489. transceiver.track = track;
  34490. transceiver.stream = stream;
  34491. transceiver.rtpSender = new window.RTCRtpSender(track, transceiver.dtlsTransport);
  34492. return transceiver.rtpSender;
  34493. };
  34494. RTCPeerConnection.prototype.addStream = function (stream) {
  34495. var pc = this;
  34496. if (edgeVersion >= 15025) {
  34497. stream.getTracks().forEach(function (track) {
  34498. pc.addTrack(track, stream);
  34499. });
  34500. } else {
  34501. // Clone is necessary for local demos mostly, attaching directly
  34502. // to two different senders does not work (build 10547).
  34503. // Fixed in 15025 (or earlier)
  34504. var clonedStream = stream.clone();
  34505. stream.getTracks().forEach(function (track, idx) {
  34506. var clonedTrack = clonedStream.getTracks()[idx];
  34507. track.addEventListener('enabled', function (event) {
  34508. clonedTrack.enabled = event.enabled;
  34509. });
  34510. });
  34511. clonedStream.getTracks().forEach(function (track) {
  34512. pc.addTrack(track, clonedStream);
  34513. });
  34514. }
  34515. };
  34516. RTCPeerConnection.prototype.removeTrack = function (sender) {
  34517. if (this._isClosed) {
  34518. throw makeError('InvalidStateError', 'Attempted to call removeTrack on a closed peerconnection.');
  34519. }
  34520. if (!(sender instanceof window.RTCRtpSender)) {
  34521. throw new TypeError('Argument 1 of RTCPeerConnection.removeTrack ' + 'does not implement interface RTCRtpSender.');
  34522. }
  34523. var transceiver = this.transceivers.find(function (t) {
  34524. return t.rtpSender === sender;
  34525. });
  34526. if (!transceiver) {
  34527. throw makeError('InvalidAccessError', 'Sender was not created by this connection.');
  34528. }
  34529. var stream = transceiver.stream;
  34530. transceiver.rtpSender.stop();
  34531. transceiver.rtpSender = null;
  34532. transceiver.track = null;
  34533. transceiver.stream = null; // remove the stream from the set of local streams
  34534. var localStreams = this.transceivers.map(function (t) {
  34535. return t.stream;
  34536. });
  34537. if (localStreams.indexOf(stream) === -1 && this.localStreams.indexOf(stream) > -1) {
  34538. this.localStreams.splice(this.localStreams.indexOf(stream), 1);
  34539. }
  34540. this._maybeFireNegotiationNeeded();
  34541. };
  34542. RTCPeerConnection.prototype.removeStream = function (stream) {
  34543. var pc = this;
  34544. stream.getTracks().forEach(function (track) {
  34545. var sender = pc.getSenders().find(function (s) {
  34546. return s.track === track;
  34547. });
  34548. if (sender) {
  34549. pc.removeTrack(sender);
  34550. }
  34551. });
  34552. };
  34553. RTCPeerConnection.prototype.getSenders = function () {
  34554. return this.transceivers.filter(function (transceiver) {
  34555. return !!transceiver.rtpSender;
  34556. }).map(function (transceiver) {
  34557. return transceiver.rtpSender;
  34558. });
  34559. };
  34560. RTCPeerConnection.prototype.getReceivers = function () {
  34561. return this.transceivers.filter(function (transceiver) {
  34562. return !!transceiver.rtpReceiver;
  34563. }).map(function (transceiver) {
  34564. return transceiver.rtpReceiver;
  34565. });
  34566. };
  34567. RTCPeerConnection.prototype._createIceGatherer = function (sdpMLineIndex, usingBundle) {
  34568. var pc = this;
  34569. if (usingBundle && sdpMLineIndex > 0) {
  34570. return this.transceivers[0].iceGatherer;
  34571. } else if (this._iceGatherers.length) {
  34572. return this._iceGatherers.shift();
  34573. }
  34574. var iceGatherer = new window.RTCIceGatherer({
  34575. iceServers: this._config.iceServers,
  34576. gatherPolicy: this._config.iceTransportPolicy
  34577. });
  34578. Object.defineProperty(iceGatherer, 'state', {
  34579. value: 'new',
  34580. writable: true
  34581. });
  34582. this.transceivers[sdpMLineIndex].bufferedCandidateEvents = [];
  34583. this.transceivers[sdpMLineIndex].bufferCandidates = function (event) {
  34584. var end = !event.candidate || Object.keys(event.candidate).length === 0; // polyfill since RTCIceGatherer.state is not implemented in
  34585. // Edge 10547 yet.
  34586. iceGatherer.state = end ? 'completed' : 'gathering';
  34587. if (pc.transceivers[sdpMLineIndex].bufferedCandidateEvents !== null) {
  34588. pc.transceivers[sdpMLineIndex].bufferedCandidateEvents.push(event);
  34589. }
  34590. };
  34591. iceGatherer.addEventListener('localcandidate', this.transceivers[sdpMLineIndex].bufferCandidates);
  34592. return iceGatherer;
  34593. }; // start gathering from an RTCIceGatherer.
  34594. RTCPeerConnection.prototype._gather = function (mid, sdpMLineIndex) {
  34595. var pc = this;
  34596. var iceGatherer = this.transceivers[sdpMLineIndex].iceGatherer;
  34597. if (iceGatherer.onlocalcandidate) {
  34598. return;
  34599. }
  34600. var bufferedCandidateEvents = this.transceivers[sdpMLineIndex].bufferedCandidateEvents;
  34601. this.transceivers[sdpMLineIndex].bufferedCandidateEvents = null;
  34602. iceGatherer.removeEventListener('localcandidate', this.transceivers[sdpMLineIndex].bufferCandidates);
  34603. iceGatherer.onlocalcandidate = function (evt) {
  34604. if (pc.usingBundle && sdpMLineIndex > 0) {
  34605. // if we know that we use bundle we can drop candidates with
  34606. // ѕdpMLineIndex > 0. If we don't do this then our state gets
  34607. // confused since we dispose the extra ice gatherer.
  34608. return;
  34609. }
  34610. var event = new Event('icecandidate');
  34611. event.candidate = {
  34612. sdpMid: mid,
  34613. sdpMLineIndex: sdpMLineIndex
  34614. };
  34615. var cand = evt.candidate; // Edge emits an empty object for RTCIceCandidateComplete‥
  34616. var end = !cand || Object.keys(cand).length === 0;
  34617. if (end) {
  34618. // polyfill since RTCIceGatherer.state is not implemented in
  34619. // Edge 10547 yet.
  34620. if (iceGatherer.state === 'new' || iceGatherer.state === 'gathering') {
  34621. iceGatherer.state = 'completed';
  34622. }
  34623. } else {
  34624. if (iceGatherer.state === 'new') {
  34625. iceGatherer.state = 'gathering';
  34626. } // RTCIceCandidate doesn't have a component, needs to be added
  34627. cand.component = 1; // also the usernameFragment. TODO: update SDP to take both variants.
  34628. cand.ufrag = iceGatherer.getLocalParameters().usernameFragment;
  34629. var serializedCandidate = SDPUtils.writeCandidate(cand);
  34630. event.candidate = Object.assign(event.candidate, SDPUtils.parseCandidate(serializedCandidate));
  34631. event.candidate.candidate = serializedCandidate;
  34632. event.candidate.toJSON = function () {
  34633. return {
  34634. candidate: event.candidate.candidate,
  34635. sdpMid: event.candidate.sdpMid,
  34636. sdpMLineIndex: event.candidate.sdpMLineIndex,
  34637. usernameFragment: event.candidate.usernameFragment
  34638. };
  34639. };
  34640. } // update local description.
  34641. var sections = SDPUtils.getMediaSections(pc._localDescription.sdp);
  34642. if (!end) {
  34643. sections[event.candidate.sdpMLineIndex] += 'a=' + event.candidate.candidate + '\r\n';
  34644. } else {
  34645. sections[event.candidate.sdpMLineIndex] += 'a=end-of-candidates\r\n';
  34646. }
  34647. pc._localDescription.sdp = SDPUtils.getDescription(pc._localDescription.sdp) + sections.join('');
  34648. var complete = pc.transceivers.every(function (transceiver) {
  34649. return transceiver.iceGatherer && transceiver.iceGatherer.state === 'completed';
  34650. });
  34651. if (pc.iceGatheringState !== 'gathering') {
  34652. pc.iceGatheringState = 'gathering';
  34653. pc._emitGatheringStateChange();
  34654. } // Emit candidate. Also emit null candidate when all gatherers are
  34655. // complete.
  34656. if (!end) {
  34657. pc._dispatchEvent('icecandidate', event);
  34658. }
  34659. if (complete) {
  34660. pc._dispatchEvent('icecandidate', new Event('icecandidate'));
  34661. pc.iceGatheringState = 'complete';
  34662. pc._emitGatheringStateChange();
  34663. }
  34664. }; // emit already gathered candidates.
  34665. window.setTimeout(function () {
  34666. bufferedCandidateEvents.forEach(function (e) {
  34667. iceGatherer.onlocalcandidate(e);
  34668. });
  34669. }, 0);
  34670. }; // Create ICE transport and DTLS transport.
  34671. RTCPeerConnection.prototype._createIceAndDtlsTransports = function () {
  34672. var pc = this;
  34673. var iceTransport = new window.RTCIceTransport(null);
  34674. iceTransport.onicestatechange = function () {
  34675. pc._updateIceConnectionState();
  34676. pc._updateConnectionState();
  34677. };
  34678. var dtlsTransport = new window.RTCDtlsTransport(iceTransport);
  34679. dtlsTransport.ondtlsstatechange = function () {
  34680. pc._updateConnectionState();
  34681. };
  34682. dtlsTransport.onerror = function () {
  34683. // onerror does not set state to failed by itself.
  34684. Object.defineProperty(dtlsTransport, 'state', {
  34685. value: 'failed',
  34686. writable: true
  34687. });
  34688. pc._updateConnectionState();
  34689. };
  34690. return {
  34691. iceTransport: iceTransport,
  34692. dtlsTransport: dtlsTransport
  34693. };
  34694. }; // Destroy ICE gatherer, ICE transport and DTLS transport.
  34695. // Without triggering the callbacks.
  34696. RTCPeerConnection.prototype._disposeIceAndDtlsTransports = function (sdpMLineIndex) {
  34697. var iceGatherer = this.transceivers[sdpMLineIndex].iceGatherer;
  34698. if (iceGatherer) {
  34699. delete iceGatherer.onlocalcandidate;
  34700. delete this.transceivers[sdpMLineIndex].iceGatherer;
  34701. }
  34702. var iceTransport = this.transceivers[sdpMLineIndex].iceTransport;
  34703. if (iceTransport) {
  34704. delete iceTransport.onicestatechange;
  34705. delete this.transceivers[sdpMLineIndex].iceTransport;
  34706. }
  34707. var dtlsTransport = this.transceivers[sdpMLineIndex].dtlsTransport;
  34708. if (dtlsTransport) {
  34709. delete dtlsTransport.ondtlsstatechange;
  34710. delete dtlsTransport.onerror;
  34711. delete this.transceivers[sdpMLineIndex].dtlsTransport;
  34712. }
  34713. }; // Start the RTP Sender and Receiver for a transceiver.
  34714. RTCPeerConnection.prototype._transceive = function (transceiver, send, recv) {
  34715. var params = getCommonCapabilities(transceiver.localCapabilities, transceiver.remoteCapabilities);
  34716. if (send && transceiver.rtpSender) {
  34717. params.encodings = transceiver.sendEncodingParameters;
  34718. params.rtcp = {
  34719. cname: SDPUtils.localCName,
  34720. compound: transceiver.rtcpParameters.compound
  34721. };
  34722. if (transceiver.recvEncodingParameters.length) {
  34723. params.rtcp.ssrc = transceiver.recvEncodingParameters[0].ssrc;
  34724. }
  34725. transceiver.rtpSender.send(params);
  34726. }
  34727. if (recv && transceiver.rtpReceiver && params.codecs.length > 0) {
  34728. // remove RTX field in Edge 14942
  34729. if (transceiver.kind === 'video' && transceiver.recvEncodingParameters && edgeVersion < 15019) {
  34730. transceiver.recvEncodingParameters.forEach(function (p) {
  34731. delete p.rtx;
  34732. });
  34733. }
  34734. if (transceiver.recvEncodingParameters.length) {
  34735. params.encodings = transceiver.recvEncodingParameters;
  34736. } else {
  34737. params.encodings = [{}];
  34738. }
  34739. params.rtcp = {
  34740. compound: transceiver.rtcpParameters.compound
  34741. };
  34742. if (transceiver.rtcpParameters.cname) {
  34743. params.rtcp.cname = transceiver.rtcpParameters.cname;
  34744. }
  34745. if (transceiver.sendEncodingParameters.length) {
  34746. params.rtcp.ssrc = transceiver.sendEncodingParameters[0].ssrc;
  34747. }
  34748. transceiver.rtpReceiver.receive(params);
  34749. }
  34750. };
  34751. RTCPeerConnection.prototype.setLocalDescription = function (description) {
  34752. var pc = this; // Note: pranswer is not supported.
  34753. if (['offer', 'answer'].indexOf(description.type) === -1) {
  34754. return Promise.reject(makeError('TypeError', 'Unsupported type "' + description.type + '"'));
  34755. }
  34756. if (!isActionAllowedInSignalingState('setLocalDescription', description.type, pc.signalingState) || pc._isClosed) {
  34757. return Promise.reject(makeError('InvalidStateError', 'Can not set local ' + description.type + ' in state ' + pc.signalingState));
  34758. }
  34759. var sections;
  34760. var sessionpart;
  34761. if (description.type === 'offer') {
  34762. // VERY limited support for SDP munging. Limited to:
  34763. // * changing the order of codecs
  34764. sections = SDPUtils.splitSections(description.sdp);
  34765. sessionpart = sections.shift();
  34766. sections.forEach(function (mediaSection, sdpMLineIndex) {
  34767. var caps = SDPUtils.parseRtpParameters(mediaSection);
  34768. pc.transceivers[sdpMLineIndex].localCapabilities = caps;
  34769. });
  34770. pc.transceivers.forEach(function (transceiver, sdpMLineIndex) {
  34771. pc._gather(transceiver.mid, sdpMLineIndex);
  34772. });
  34773. } else if (description.type === 'answer') {
  34774. sections = SDPUtils.splitSections(pc._remoteDescription.sdp);
  34775. sessionpart = sections.shift();
  34776. var isIceLite = SDPUtils.matchPrefix(sessionpart, 'a=ice-lite').length > 0;
  34777. sections.forEach(function (mediaSection, sdpMLineIndex) {
  34778. var transceiver = pc.transceivers[sdpMLineIndex];
  34779. var iceGatherer = transceiver.iceGatherer;
  34780. var iceTransport = transceiver.iceTransport;
  34781. var dtlsTransport = transceiver.dtlsTransport;
  34782. var localCapabilities = transceiver.localCapabilities;
  34783. var remoteCapabilities = transceiver.remoteCapabilities; // treat bundle-only as not-rejected.
  34784. var rejected = SDPUtils.isRejected(mediaSection) && SDPUtils.matchPrefix(mediaSection, 'a=bundle-only').length === 0;
  34785. if (!rejected && !transceiver.rejected) {
  34786. var remoteIceParameters = SDPUtils.getIceParameters(mediaSection, sessionpart);
  34787. var remoteDtlsParameters = SDPUtils.getDtlsParameters(mediaSection, sessionpart);
  34788. if (isIceLite) {
  34789. remoteDtlsParameters.role = 'server';
  34790. }
  34791. if (!pc.usingBundle || sdpMLineIndex === 0) {
  34792. pc._gather(transceiver.mid, sdpMLineIndex);
  34793. if (iceTransport.state === 'new') {
  34794. iceTransport.start(iceGatherer, remoteIceParameters, isIceLite ? 'controlling' : 'controlled');
  34795. }
  34796. if (dtlsTransport.state === 'new') {
  34797. dtlsTransport.start(remoteDtlsParameters);
  34798. }
  34799. } // Calculate intersection of capabilities.
  34800. var params = getCommonCapabilities(localCapabilities, remoteCapabilities); // Start the RTCRtpSender. The RTCRtpReceiver for this
  34801. // transceiver has already been started in setRemoteDescription.
  34802. pc._transceive(transceiver, params.codecs.length > 0, false);
  34803. }
  34804. });
  34805. }
  34806. pc._localDescription = {
  34807. type: description.type,
  34808. sdp: description.sdp
  34809. };
  34810. if (description.type === 'offer') {
  34811. pc._updateSignalingState('have-local-offer');
  34812. } else {
  34813. pc._updateSignalingState('stable');
  34814. }
  34815. return Promise.resolve();
  34816. };
  34817. RTCPeerConnection.prototype.setRemoteDescription = function (description) {
  34818. var pc = this; // Note: pranswer is not supported.
  34819. if (['offer', 'answer'].indexOf(description.type) === -1) {
  34820. return Promise.reject(makeError('TypeError', 'Unsupported type "' + description.type + '"'));
  34821. }
  34822. if (!isActionAllowedInSignalingState('setRemoteDescription', description.type, pc.signalingState) || pc._isClosed) {
  34823. return Promise.reject(makeError('InvalidStateError', 'Can not set remote ' + description.type + ' in state ' + pc.signalingState));
  34824. }
  34825. var streams = {};
  34826. pc.remoteStreams.forEach(function (stream) {
  34827. streams[stream.id] = stream;
  34828. });
  34829. var receiverList = [];
  34830. var sections = SDPUtils.splitSections(description.sdp);
  34831. var sessionpart = sections.shift();
  34832. var isIceLite = SDPUtils.matchPrefix(sessionpart, 'a=ice-lite').length > 0;
  34833. var usingBundle = SDPUtils.matchPrefix(sessionpart, 'a=group:BUNDLE ').length > 0;
  34834. pc.usingBundle = usingBundle;
  34835. var iceOptions = SDPUtils.matchPrefix(sessionpart, 'a=ice-options:')[0];
  34836. if (iceOptions) {
  34837. pc.canTrickleIceCandidates = iceOptions.substr(14).split(' ').indexOf('trickle') >= 0;
  34838. } else {
  34839. pc.canTrickleIceCandidates = false;
  34840. }
  34841. sections.forEach(function (mediaSection, sdpMLineIndex) {
  34842. var lines = SDPUtils.splitLines(mediaSection);
  34843. var kind = SDPUtils.getKind(mediaSection); // treat bundle-only as not-rejected.
  34844. var rejected = SDPUtils.isRejected(mediaSection) && SDPUtils.matchPrefix(mediaSection, 'a=bundle-only').length === 0;
  34845. var protocol = lines[0].substr(2).split(' ')[2];
  34846. var direction = SDPUtils.getDirection(mediaSection, sessionpart);
  34847. var remoteMsid = SDPUtils.parseMsid(mediaSection);
  34848. var mid = SDPUtils.getMid(mediaSection) || SDPUtils.generateIdentifier(); // Reject datachannels which are not implemented yet.
  34849. if (rejected || kind === 'application' && (protocol === 'DTLS/SCTP' || protocol === 'UDP/DTLS/SCTP')) {
  34850. // TODO: this is dangerous in the case where a non-rejected m-line
  34851. // becomes rejected.
  34852. pc.transceivers[sdpMLineIndex] = {
  34853. mid: mid,
  34854. kind: kind,
  34855. protocol: protocol,
  34856. rejected: true
  34857. };
  34858. return;
  34859. }
  34860. if (!rejected && pc.transceivers[sdpMLineIndex] && pc.transceivers[sdpMLineIndex].rejected) {
  34861. // recycle a rejected transceiver.
  34862. pc.transceivers[sdpMLineIndex] = pc._createTransceiver(kind, true);
  34863. }
  34864. var transceiver;
  34865. var iceGatherer;
  34866. var iceTransport;
  34867. var dtlsTransport;
  34868. var rtpReceiver;
  34869. var sendEncodingParameters;
  34870. var recvEncodingParameters;
  34871. var localCapabilities;
  34872. var track; // FIXME: ensure the mediaSection has rtcp-mux set.
  34873. var remoteCapabilities = SDPUtils.parseRtpParameters(mediaSection);
  34874. var remoteIceParameters;
  34875. var remoteDtlsParameters;
  34876. if (!rejected) {
  34877. remoteIceParameters = SDPUtils.getIceParameters(mediaSection, sessionpart);
  34878. remoteDtlsParameters = SDPUtils.getDtlsParameters(mediaSection, sessionpart);
  34879. remoteDtlsParameters.role = 'client';
  34880. }
  34881. recvEncodingParameters = SDPUtils.parseRtpEncodingParameters(mediaSection);
  34882. var rtcpParameters = SDPUtils.parseRtcpParameters(mediaSection);
  34883. var isComplete = SDPUtils.matchPrefix(mediaSection, 'a=end-of-candidates', sessionpart).length > 0;
  34884. var cands = SDPUtils.matchPrefix(mediaSection, 'a=candidate:').map(function (cand) {
  34885. return SDPUtils.parseCandidate(cand);
  34886. }).filter(function (cand) {
  34887. return cand.component === 1;
  34888. }); // Check if we can use BUNDLE and dispose transports.
  34889. if ((description.type === 'offer' || description.type === 'answer') && !rejected && usingBundle && sdpMLineIndex > 0 && pc.transceivers[sdpMLineIndex]) {
  34890. pc._disposeIceAndDtlsTransports(sdpMLineIndex);
  34891. pc.transceivers[sdpMLineIndex].iceGatherer = pc.transceivers[0].iceGatherer;
  34892. pc.transceivers[sdpMLineIndex].iceTransport = pc.transceivers[0].iceTransport;
  34893. pc.transceivers[sdpMLineIndex].dtlsTransport = pc.transceivers[0].dtlsTransport;
  34894. if (pc.transceivers[sdpMLineIndex].rtpSender) {
  34895. pc.transceivers[sdpMLineIndex].rtpSender.setTransport(pc.transceivers[0].dtlsTransport);
  34896. }
  34897. if (pc.transceivers[sdpMLineIndex].rtpReceiver) {
  34898. pc.transceivers[sdpMLineIndex].rtpReceiver.setTransport(pc.transceivers[0].dtlsTransport);
  34899. }
  34900. }
  34901. if (description.type === 'offer' && !rejected) {
  34902. transceiver = pc.transceivers[sdpMLineIndex] || pc._createTransceiver(kind);
  34903. transceiver.mid = mid;
  34904. if (!transceiver.iceGatherer) {
  34905. transceiver.iceGatherer = pc._createIceGatherer(sdpMLineIndex, usingBundle);
  34906. }
  34907. if (cands.length && transceiver.iceTransport.state === 'new') {
  34908. if (isComplete && (!usingBundle || sdpMLineIndex === 0)) {
  34909. transceiver.iceTransport.setRemoteCandidates(cands);
  34910. } else {
  34911. cands.forEach(function (candidate) {
  34912. maybeAddCandidate(transceiver.iceTransport, candidate);
  34913. });
  34914. }
  34915. }
  34916. localCapabilities = window.RTCRtpReceiver.getCapabilities(kind); // filter RTX until additional stuff needed for RTX is implemented
  34917. // in adapter.js
  34918. if (edgeVersion < 15019) {
  34919. localCapabilities.codecs = localCapabilities.codecs.filter(function (codec) {
  34920. return codec.name !== 'rtx';
  34921. });
  34922. }
  34923. sendEncodingParameters = transceiver.sendEncodingParameters || [{
  34924. ssrc: (2 * sdpMLineIndex + 2) * 1001
  34925. }]; // TODO: rewrite to use http://w3c.github.io/webrtc-pc/#set-associated-remote-streams
  34926. var isNewTrack = false;
  34927. if (direction === 'sendrecv' || direction === 'sendonly') {
  34928. isNewTrack = !transceiver.rtpReceiver;
  34929. rtpReceiver = transceiver.rtpReceiver || new window.RTCRtpReceiver(transceiver.dtlsTransport, kind);
  34930. if (isNewTrack) {
  34931. var stream;
  34932. track = rtpReceiver.track; // FIXME: does not work with Plan B.
  34933. if (remoteMsid && remoteMsid.stream === '-') {// no-op. a stream id of '-' means: no associated stream.
  34934. } else if (remoteMsid) {
  34935. if (!streams[remoteMsid.stream]) {
  34936. streams[remoteMsid.stream] = new window.MediaStream();
  34937. Object.defineProperty(streams[remoteMsid.stream], 'id', {
  34938. get: function () {
  34939. return remoteMsid.stream;
  34940. }
  34941. });
  34942. }
  34943. Object.defineProperty(track, 'id', {
  34944. get: function () {
  34945. return remoteMsid.track;
  34946. }
  34947. });
  34948. stream = streams[remoteMsid.stream];
  34949. } else {
  34950. if (!streams.default) {
  34951. streams.default = new window.MediaStream();
  34952. }
  34953. stream = streams.default;
  34954. }
  34955. if (stream) {
  34956. addTrackToStreamAndFireEvent(track, stream);
  34957. transceiver.associatedRemoteMediaStreams.push(stream);
  34958. }
  34959. receiverList.push([track, rtpReceiver, stream]);
  34960. }
  34961. } else if (transceiver.rtpReceiver && transceiver.rtpReceiver.track) {
  34962. transceiver.associatedRemoteMediaStreams.forEach(function (s) {
  34963. var nativeTrack = s.getTracks().find(function (t) {
  34964. return t.id === transceiver.rtpReceiver.track.id;
  34965. });
  34966. if (nativeTrack) {
  34967. removeTrackFromStreamAndFireEvent(nativeTrack, s);
  34968. }
  34969. });
  34970. transceiver.associatedRemoteMediaStreams = [];
  34971. }
  34972. transceiver.localCapabilities = localCapabilities;
  34973. transceiver.remoteCapabilities = remoteCapabilities;
  34974. transceiver.rtpReceiver = rtpReceiver;
  34975. transceiver.rtcpParameters = rtcpParameters;
  34976. transceiver.sendEncodingParameters = sendEncodingParameters;
  34977. transceiver.recvEncodingParameters = recvEncodingParameters; // Start the RTCRtpReceiver now. The RTPSender is started in
  34978. // setLocalDescription.
  34979. pc._transceive(pc.transceivers[sdpMLineIndex], false, isNewTrack);
  34980. } else if (description.type === 'answer' && !rejected) {
  34981. transceiver = pc.transceivers[sdpMLineIndex];
  34982. iceGatherer = transceiver.iceGatherer;
  34983. iceTransport = transceiver.iceTransport;
  34984. dtlsTransport = transceiver.dtlsTransport;
  34985. rtpReceiver = transceiver.rtpReceiver;
  34986. sendEncodingParameters = transceiver.sendEncodingParameters;
  34987. localCapabilities = transceiver.localCapabilities;
  34988. pc.transceivers[sdpMLineIndex].recvEncodingParameters = recvEncodingParameters;
  34989. pc.transceivers[sdpMLineIndex].remoteCapabilities = remoteCapabilities;
  34990. pc.transceivers[sdpMLineIndex].rtcpParameters = rtcpParameters;
  34991. if (cands.length && iceTransport.state === 'new') {
  34992. if ((isIceLite || isComplete) && (!usingBundle || sdpMLineIndex === 0)) {
  34993. iceTransport.setRemoteCandidates(cands);
  34994. } else {
  34995. cands.forEach(function (candidate) {
  34996. maybeAddCandidate(transceiver.iceTransport, candidate);
  34997. });
  34998. }
  34999. }
  35000. if (!usingBundle || sdpMLineIndex === 0) {
  35001. if (iceTransport.state === 'new') {
  35002. iceTransport.start(iceGatherer, remoteIceParameters, 'controlling');
  35003. }
  35004. if (dtlsTransport.state === 'new') {
  35005. dtlsTransport.start(remoteDtlsParameters);
  35006. }
  35007. } // If the offer contained RTX but the answer did not,
  35008. // remove RTX from sendEncodingParameters.
  35009. var commonCapabilities = getCommonCapabilities(transceiver.localCapabilities, transceiver.remoteCapabilities);
  35010. var hasRtx = commonCapabilities.codecs.filter(function (c) {
  35011. return c.name.toLowerCase() === 'rtx';
  35012. }).length;
  35013. if (!hasRtx && transceiver.sendEncodingParameters[0].rtx) {
  35014. delete transceiver.sendEncodingParameters[0].rtx;
  35015. }
  35016. pc._transceive(transceiver, direction === 'sendrecv' || direction === 'recvonly', direction === 'sendrecv' || direction === 'sendonly'); // TODO: rewrite to use http://w3c.github.io/webrtc-pc/#set-associated-remote-streams
  35017. if (rtpReceiver && (direction === 'sendrecv' || direction === 'sendonly')) {
  35018. track = rtpReceiver.track;
  35019. if (remoteMsid) {
  35020. if (!streams[remoteMsid.stream]) {
  35021. streams[remoteMsid.stream] = new window.MediaStream();
  35022. }
  35023. addTrackToStreamAndFireEvent(track, streams[remoteMsid.stream]);
  35024. receiverList.push([track, rtpReceiver, streams[remoteMsid.stream]]);
  35025. } else {
  35026. if (!streams.default) {
  35027. streams.default = new window.MediaStream();
  35028. }
  35029. addTrackToStreamAndFireEvent(track, streams.default);
  35030. receiverList.push([track, rtpReceiver, streams.default]);
  35031. }
  35032. } else {
  35033. // FIXME: actually the receiver should be created later.
  35034. delete transceiver.rtpReceiver;
  35035. }
  35036. }
  35037. });
  35038. if (pc._dtlsRole === undefined) {
  35039. pc._dtlsRole = description.type === 'offer' ? 'active' : 'passive';
  35040. }
  35041. pc._remoteDescription = {
  35042. type: description.type,
  35043. sdp: description.sdp
  35044. };
  35045. if (description.type === 'offer') {
  35046. pc._updateSignalingState('have-remote-offer');
  35047. } else {
  35048. pc._updateSignalingState('stable');
  35049. }
  35050. Object.keys(streams).forEach(function (sid) {
  35051. var stream = streams[sid];
  35052. if (stream.getTracks().length) {
  35053. if (pc.remoteStreams.indexOf(stream) === -1) {
  35054. pc.remoteStreams.push(stream);
  35055. var event = new Event('addstream');
  35056. event.stream = stream;
  35057. window.setTimeout(function () {
  35058. pc._dispatchEvent('addstream', event);
  35059. });
  35060. }
  35061. receiverList.forEach(function (item) {
  35062. var track = item[0];
  35063. var receiver = item[1];
  35064. if (stream.id !== item[2].id) {
  35065. return;
  35066. }
  35067. fireAddTrack(pc, track, receiver, [stream]);
  35068. });
  35069. }
  35070. });
  35071. receiverList.forEach(function (item) {
  35072. if (item[2]) {
  35073. return;
  35074. }
  35075. fireAddTrack(pc, item[0], item[1], []);
  35076. }); // check whether addIceCandidate({}) was called within four seconds after
  35077. // setRemoteDescription.
  35078. window.setTimeout(function () {
  35079. if (!(pc && pc.transceivers)) {
  35080. return;
  35081. }
  35082. pc.transceivers.forEach(function (transceiver) {
  35083. if (transceiver.iceTransport && transceiver.iceTransport.state === 'new' && transceiver.iceTransport.getRemoteCandidates().length > 0) {
  35084. console.warn('Timeout for addRemoteCandidate. Consider sending ' + 'an end-of-candidates notification');
  35085. transceiver.iceTransport.addRemoteCandidate({});
  35086. }
  35087. });
  35088. }, 4000);
  35089. return Promise.resolve();
  35090. };
  35091. RTCPeerConnection.prototype.close = function () {
  35092. this.transceivers.forEach(function (transceiver) {
  35093. /* not yet
  35094. if (transceiver.iceGatherer) {
  35095. transceiver.iceGatherer.close();
  35096. }
  35097. */
  35098. if (transceiver.iceTransport) {
  35099. transceiver.iceTransport.stop();
  35100. }
  35101. if (transceiver.dtlsTransport) {
  35102. transceiver.dtlsTransport.stop();
  35103. }
  35104. if (transceiver.rtpSender) {
  35105. transceiver.rtpSender.stop();
  35106. }
  35107. if (transceiver.rtpReceiver) {
  35108. transceiver.rtpReceiver.stop();
  35109. }
  35110. }); // FIXME: clean up tracks, local streams, remote streams, etc
  35111. this._isClosed = true;
  35112. this._updateSignalingState('closed');
  35113. }; // Update the signaling state.
  35114. RTCPeerConnection.prototype._updateSignalingState = function (newState) {
  35115. this.signalingState = newState;
  35116. var event = new Event('signalingstatechange');
  35117. this._dispatchEvent('signalingstatechange', event);
  35118. }; // Determine whether to fire the negotiationneeded event.
  35119. RTCPeerConnection.prototype._maybeFireNegotiationNeeded = function () {
  35120. var pc = this;
  35121. if (this.signalingState !== 'stable' || this.needNegotiation === true) {
  35122. return;
  35123. }
  35124. this.needNegotiation = true;
  35125. window.setTimeout(function () {
  35126. if (pc.needNegotiation) {
  35127. pc.needNegotiation = false;
  35128. var event = new Event('negotiationneeded');
  35129. pc._dispatchEvent('negotiationneeded', event);
  35130. }
  35131. }, 0);
  35132. }; // Update the ice connection state.
  35133. RTCPeerConnection.prototype._updateIceConnectionState = function () {
  35134. var newState;
  35135. var states = {
  35136. 'new': 0,
  35137. closed: 0,
  35138. checking: 0,
  35139. connected: 0,
  35140. completed: 0,
  35141. disconnected: 0,
  35142. failed: 0
  35143. };
  35144. this.transceivers.forEach(function (transceiver) {
  35145. if (transceiver.iceTransport && !transceiver.rejected) {
  35146. states[transceiver.iceTransport.state]++;
  35147. }
  35148. });
  35149. newState = 'new';
  35150. if (states.failed > 0) {
  35151. newState = 'failed';
  35152. } else if (states.checking > 0) {
  35153. newState = 'checking';
  35154. } else if (states.disconnected > 0) {
  35155. newState = 'disconnected';
  35156. } else if (states.new > 0) {
  35157. newState = 'new';
  35158. } else if (states.connected > 0) {
  35159. newState = 'connected';
  35160. } else if (states.completed > 0) {
  35161. newState = 'completed';
  35162. }
  35163. if (newState !== this.iceConnectionState) {
  35164. this.iceConnectionState = newState;
  35165. var event = new Event('iceconnectionstatechange');
  35166. this._dispatchEvent('iceconnectionstatechange', event);
  35167. }
  35168. }; // Update the connection state.
  35169. RTCPeerConnection.prototype._updateConnectionState = function () {
  35170. var newState;
  35171. var states = {
  35172. 'new': 0,
  35173. closed: 0,
  35174. connecting: 0,
  35175. connected: 0,
  35176. completed: 0,
  35177. disconnected: 0,
  35178. failed: 0
  35179. };
  35180. this.transceivers.forEach(function (transceiver) {
  35181. if (transceiver.iceTransport && transceiver.dtlsTransport && !transceiver.rejected) {
  35182. states[transceiver.iceTransport.state]++;
  35183. states[transceiver.dtlsTransport.state]++;
  35184. }
  35185. }); // ICETransport.completed and connected are the same for this purpose.
  35186. states.connected += states.completed;
  35187. newState = 'new';
  35188. if (states.failed > 0) {
  35189. newState = 'failed';
  35190. } else if (states.connecting > 0) {
  35191. newState = 'connecting';
  35192. } else if (states.disconnected > 0) {
  35193. newState = 'disconnected';
  35194. } else if (states.new > 0) {
  35195. newState = 'new';
  35196. } else if (states.connected > 0) {
  35197. newState = 'connected';
  35198. }
  35199. if (newState !== this.connectionState) {
  35200. this.connectionState = newState;
  35201. var event = new Event('connectionstatechange');
  35202. this._dispatchEvent('connectionstatechange', event);
  35203. }
  35204. };
  35205. RTCPeerConnection.prototype.createOffer = function () {
  35206. var pc = this;
  35207. if (pc._isClosed) {
  35208. return Promise.reject(makeError('InvalidStateError', 'Can not call createOffer after close'));
  35209. }
  35210. var numAudioTracks = pc.transceivers.filter(function (t) {
  35211. return t.kind === 'audio';
  35212. }).length;
  35213. var numVideoTracks = pc.transceivers.filter(function (t) {
  35214. return t.kind === 'video';
  35215. }).length; // Determine number of audio and video tracks we need to send/recv.
  35216. var offerOptions = arguments[0];
  35217. if (offerOptions) {
  35218. // Reject Chrome legacy constraints.
  35219. if (offerOptions.mandatory || offerOptions.optional) {
  35220. throw new TypeError('Legacy mandatory/optional constraints not supported.');
  35221. }
  35222. if (offerOptions.offerToReceiveAudio !== undefined) {
  35223. if (offerOptions.offerToReceiveAudio === true) {
  35224. numAudioTracks = 1;
  35225. } else if (offerOptions.offerToReceiveAudio === false) {
  35226. numAudioTracks = 0;
  35227. } else {
  35228. numAudioTracks = offerOptions.offerToReceiveAudio;
  35229. }
  35230. }
  35231. if (offerOptions.offerToReceiveVideo !== undefined) {
  35232. if (offerOptions.offerToReceiveVideo === true) {
  35233. numVideoTracks = 1;
  35234. } else if (offerOptions.offerToReceiveVideo === false) {
  35235. numVideoTracks = 0;
  35236. } else {
  35237. numVideoTracks = offerOptions.offerToReceiveVideo;
  35238. }
  35239. }
  35240. }
  35241. pc.transceivers.forEach(function (transceiver) {
  35242. if (transceiver.kind === 'audio') {
  35243. numAudioTracks--;
  35244. if (numAudioTracks < 0) {
  35245. transceiver.wantReceive = false;
  35246. }
  35247. } else if (transceiver.kind === 'video') {
  35248. numVideoTracks--;
  35249. if (numVideoTracks < 0) {
  35250. transceiver.wantReceive = false;
  35251. }
  35252. }
  35253. }); // Create M-lines for recvonly streams.
  35254. while (numAudioTracks > 0 || numVideoTracks > 0) {
  35255. if (numAudioTracks > 0) {
  35256. pc._createTransceiver('audio');
  35257. numAudioTracks--;
  35258. }
  35259. if (numVideoTracks > 0) {
  35260. pc._createTransceiver('video');
  35261. numVideoTracks--;
  35262. }
  35263. }
  35264. var sdp = SDPUtils.writeSessionBoilerplate(pc._sdpSessionId, pc._sdpSessionVersion++);
  35265. pc.transceivers.forEach(function (transceiver, sdpMLineIndex) {
  35266. // For each track, create an ice gatherer, ice transport,
  35267. // dtls transport, potentially rtpsender and rtpreceiver.
  35268. var track = transceiver.track;
  35269. var kind = transceiver.kind;
  35270. var mid = transceiver.mid || SDPUtils.generateIdentifier();
  35271. transceiver.mid = mid;
  35272. if (!transceiver.iceGatherer) {
  35273. transceiver.iceGatherer = pc._createIceGatherer(sdpMLineIndex, pc.usingBundle);
  35274. }
  35275. var localCapabilities = window.RTCRtpSender.getCapabilities(kind); // filter RTX until additional stuff needed for RTX is implemented
  35276. // in adapter.js
  35277. if (edgeVersion < 15019) {
  35278. localCapabilities.codecs = localCapabilities.codecs.filter(function (codec) {
  35279. return codec.name !== 'rtx';
  35280. });
  35281. }
  35282. localCapabilities.codecs.forEach(function (codec) {
  35283. // work around https://bugs.chromium.org/p/webrtc/issues/detail?id=6552
  35284. // by adding level-asymmetry-allowed=1
  35285. if (codec.name === 'H264' && codec.parameters['level-asymmetry-allowed'] === undefined) {
  35286. codec.parameters['level-asymmetry-allowed'] = '1';
  35287. } // for subsequent offers, we might have to re-use the payload
  35288. // type of the last offer.
  35289. if (transceiver.remoteCapabilities && transceiver.remoteCapabilities.codecs) {
  35290. transceiver.remoteCapabilities.codecs.forEach(function (remoteCodec) {
  35291. if (codec.name.toLowerCase() === remoteCodec.name.toLowerCase() && codec.clockRate === remoteCodec.clockRate) {
  35292. codec.preferredPayloadType = remoteCodec.payloadType;
  35293. }
  35294. });
  35295. }
  35296. });
  35297. localCapabilities.headerExtensions.forEach(function (hdrExt) {
  35298. var remoteExtensions = transceiver.remoteCapabilities && transceiver.remoteCapabilities.headerExtensions || [];
  35299. remoteExtensions.forEach(function (rHdrExt) {
  35300. if (hdrExt.uri === rHdrExt.uri) {
  35301. hdrExt.id = rHdrExt.id;
  35302. }
  35303. });
  35304. }); // generate an ssrc now, to be used later in rtpSender.send
  35305. var sendEncodingParameters = transceiver.sendEncodingParameters || [{
  35306. ssrc: (2 * sdpMLineIndex + 1) * 1001
  35307. }];
  35308. if (track) {
  35309. // add RTX
  35310. if (edgeVersion >= 15019 && kind === 'video' && !sendEncodingParameters[0].rtx) {
  35311. sendEncodingParameters[0].rtx = {
  35312. ssrc: sendEncodingParameters[0].ssrc + 1
  35313. };
  35314. }
  35315. }
  35316. if (transceiver.wantReceive) {
  35317. transceiver.rtpReceiver = new window.RTCRtpReceiver(transceiver.dtlsTransport, kind);
  35318. }
  35319. transceiver.localCapabilities = localCapabilities;
  35320. transceiver.sendEncodingParameters = sendEncodingParameters;
  35321. }); // always offer BUNDLE and dispose on return if not supported.
  35322. if (pc._config.bundlePolicy !== 'max-compat') {
  35323. sdp += 'a=group:BUNDLE ' + pc.transceivers.map(function (t) {
  35324. return t.mid;
  35325. }).join(' ') + '\r\n';
  35326. }
  35327. sdp += 'a=ice-options:trickle\r\n';
  35328. pc.transceivers.forEach(function (transceiver, sdpMLineIndex) {
  35329. sdp += writeMediaSection(transceiver, transceiver.localCapabilities, 'offer', transceiver.stream, pc._dtlsRole);
  35330. sdp += 'a=rtcp-rsize\r\n';
  35331. if (transceiver.iceGatherer && pc.iceGatheringState !== 'new' && (sdpMLineIndex === 0 || !pc.usingBundle)) {
  35332. transceiver.iceGatherer.getLocalCandidates().forEach(function (cand) {
  35333. cand.component = 1;
  35334. sdp += 'a=' + SDPUtils.writeCandidate(cand) + '\r\n';
  35335. });
  35336. if (transceiver.iceGatherer.state === 'completed') {
  35337. sdp += 'a=end-of-candidates\r\n';
  35338. }
  35339. }
  35340. });
  35341. var desc = new window.RTCSessionDescription({
  35342. type: 'offer',
  35343. sdp: sdp
  35344. });
  35345. return Promise.resolve(desc);
  35346. };
  35347. RTCPeerConnection.prototype.createAnswer = function () {
  35348. var pc = this;
  35349. if (pc._isClosed) {
  35350. return Promise.reject(makeError('InvalidStateError', 'Can not call createAnswer after close'));
  35351. }
  35352. if (!(pc.signalingState === 'have-remote-offer' || pc.signalingState === 'have-local-pranswer')) {
  35353. return Promise.reject(makeError('InvalidStateError', 'Can not call createAnswer in signalingState ' + pc.signalingState));
  35354. }
  35355. var sdp = SDPUtils.writeSessionBoilerplate(pc._sdpSessionId, pc._sdpSessionVersion++);
  35356. if (pc.usingBundle) {
  35357. sdp += 'a=group:BUNDLE ' + pc.transceivers.map(function (t) {
  35358. return t.mid;
  35359. }).join(' ') + '\r\n';
  35360. }
  35361. sdp += 'a=ice-options:trickle\r\n';
  35362. var mediaSectionsInOffer = SDPUtils.getMediaSections(pc._remoteDescription.sdp).length;
  35363. pc.transceivers.forEach(function (transceiver, sdpMLineIndex) {
  35364. if (sdpMLineIndex + 1 > mediaSectionsInOffer) {
  35365. return;
  35366. }
  35367. if (transceiver.rejected) {
  35368. if (transceiver.kind === 'application') {
  35369. if (transceiver.protocol === 'DTLS/SCTP') {
  35370. // legacy fmt
  35371. sdp += 'm=application 0 DTLS/SCTP 5000\r\n';
  35372. } else {
  35373. sdp += 'm=application 0 ' + transceiver.protocol + ' webrtc-datachannel\r\n';
  35374. }
  35375. } else if (transceiver.kind === 'audio') {
  35376. sdp += 'm=audio 0 UDP/TLS/RTP/SAVPF 0\r\n' + 'a=rtpmap:0 PCMU/8000\r\n';
  35377. } else if (transceiver.kind === 'video') {
  35378. sdp += 'm=video 0 UDP/TLS/RTP/SAVPF 120\r\n' + 'a=rtpmap:120 VP8/90000\r\n';
  35379. }
  35380. sdp += 'c=IN IP4 0.0.0.0\r\n' + 'a=inactive\r\n' + 'a=mid:' + transceiver.mid + '\r\n';
  35381. return;
  35382. } // FIXME: look at direction.
  35383. if (transceiver.stream) {
  35384. var localTrack;
  35385. if (transceiver.kind === 'audio') {
  35386. localTrack = transceiver.stream.getAudioTracks()[0];
  35387. } else if (transceiver.kind === 'video') {
  35388. localTrack = transceiver.stream.getVideoTracks()[0];
  35389. }
  35390. if (localTrack) {
  35391. // add RTX
  35392. if (edgeVersion >= 15019 && transceiver.kind === 'video' && !transceiver.sendEncodingParameters[0].rtx) {
  35393. transceiver.sendEncodingParameters[0].rtx = {
  35394. ssrc: transceiver.sendEncodingParameters[0].ssrc + 1
  35395. };
  35396. }
  35397. }
  35398. } // Calculate intersection of capabilities.
  35399. var commonCapabilities = getCommonCapabilities(transceiver.localCapabilities, transceiver.remoteCapabilities);
  35400. var hasRtx = commonCapabilities.codecs.filter(function (c) {
  35401. return c.name.toLowerCase() === 'rtx';
  35402. }).length;
  35403. if (!hasRtx && transceiver.sendEncodingParameters[0].rtx) {
  35404. delete transceiver.sendEncodingParameters[0].rtx;
  35405. }
  35406. sdp += writeMediaSection(transceiver, commonCapabilities, 'answer', transceiver.stream, pc._dtlsRole);
  35407. if (transceiver.rtcpParameters && transceiver.rtcpParameters.reducedSize) {
  35408. sdp += 'a=rtcp-rsize\r\n';
  35409. }
  35410. });
  35411. var desc = new window.RTCSessionDescription({
  35412. type: 'answer',
  35413. sdp: sdp
  35414. });
  35415. return Promise.resolve(desc);
  35416. };
  35417. RTCPeerConnection.prototype.addIceCandidate = function (candidate) {
  35418. var pc = this;
  35419. var sections;
  35420. if (candidate && !(candidate.sdpMLineIndex !== undefined || candidate.sdpMid)) {
  35421. return Promise.reject(new TypeError('sdpMLineIndex or sdpMid required'));
  35422. } // TODO: needs to go into ops queue.
  35423. return new Promise(function (resolve, reject) {
  35424. if (!pc._remoteDescription) {
  35425. return reject(makeError('InvalidStateError', 'Can not add ICE candidate without a remote description'));
  35426. } else if (!candidate || candidate.candidate === '') {
  35427. for (var j = 0; j < pc.transceivers.length; j++) {
  35428. if (pc.transceivers[j].rejected) {
  35429. continue;
  35430. }
  35431. pc.transceivers[j].iceTransport.addRemoteCandidate({});
  35432. sections = SDPUtils.getMediaSections(pc._remoteDescription.sdp);
  35433. sections[j] += 'a=end-of-candidates\r\n';
  35434. pc._remoteDescription.sdp = SDPUtils.getDescription(pc._remoteDescription.sdp) + sections.join('');
  35435. if (pc.usingBundle) {
  35436. break;
  35437. }
  35438. }
  35439. } else {
  35440. var sdpMLineIndex = candidate.sdpMLineIndex;
  35441. if (candidate.sdpMid) {
  35442. for (var i = 0; i < pc.transceivers.length; i++) {
  35443. if (pc.transceivers[i].mid === candidate.sdpMid) {
  35444. sdpMLineIndex = i;
  35445. break;
  35446. }
  35447. }
  35448. }
  35449. var transceiver = pc.transceivers[sdpMLineIndex];
  35450. if (transceiver) {
  35451. if (transceiver.rejected) {
  35452. return resolve();
  35453. }
  35454. var cand = Object.keys(candidate.candidate).length > 0 ? SDPUtils.parseCandidate(candidate.candidate) : {}; // Ignore Chrome's invalid candidates since Edge does not like them.
  35455. if (cand.protocol === 'tcp' && (cand.port === 0 || cand.port === 9)) {
  35456. return resolve();
  35457. } // Ignore RTCP candidates, we assume RTCP-MUX.
  35458. if (cand.component && cand.component !== 1) {
  35459. return resolve();
  35460. } // when using bundle, avoid adding candidates to the wrong
  35461. // ice transport. And avoid adding candidates added in the SDP.
  35462. if (sdpMLineIndex === 0 || sdpMLineIndex > 0 && transceiver.iceTransport !== pc.transceivers[0].iceTransport) {
  35463. if (!maybeAddCandidate(transceiver.iceTransport, cand)) {
  35464. return reject(makeError('OperationError', 'Can not add ICE candidate'));
  35465. }
  35466. } // update the remoteDescription.
  35467. var candidateString = candidate.candidate.trim();
  35468. if (candidateString.indexOf('a=') === 0) {
  35469. candidateString = candidateString.substr(2);
  35470. }
  35471. sections = SDPUtils.getMediaSections(pc._remoteDescription.sdp);
  35472. sections[sdpMLineIndex] += 'a=' + (cand.type ? candidateString : 'end-of-candidates') + '\r\n';
  35473. pc._remoteDescription.sdp = SDPUtils.getDescription(pc._remoteDescription.sdp) + sections.join('');
  35474. } else {
  35475. return reject(makeError('OperationError', 'Can not add ICE candidate'));
  35476. }
  35477. }
  35478. resolve();
  35479. });
  35480. };
  35481. RTCPeerConnection.prototype.getStats = function (selector) {
  35482. if (selector && selector instanceof window.MediaStreamTrack) {
  35483. var senderOrReceiver = null;
  35484. this.transceivers.forEach(function (transceiver) {
  35485. if (transceiver.rtpSender && transceiver.rtpSender.track === selector) {
  35486. senderOrReceiver = transceiver.rtpSender;
  35487. } else if (transceiver.rtpReceiver && transceiver.rtpReceiver.track === selector) {
  35488. senderOrReceiver = transceiver.rtpReceiver;
  35489. }
  35490. });
  35491. if (!senderOrReceiver) {
  35492. throw makeError('InvalidAccessError', 'Invalid selector.');
  35493. }
  35494. return senderOrReceiver.getStats();
  35495. }
  35496. var promises = [];
  35497. this.transceivers.forEach(function (transceiver) {
  35498. ['rtpSender', 'rtpReceiver', 'iceGatherer', 'iceTransport', 'dtlsTransport'].forEach(function (method) {
  35499. if (transceiver[method]) {
  35500. promises.push(transceiver[method].getStats());
  35501. }
  35502. });
  35503. });
  35504. return Promise.all(promises).then(function (allStats) {
  35505. var results = new Map();
  35506. allStats.forEach(function (stats) {
  35507. stats.forEach(function (stat) {
  35508. results.set(stat.id, stat);
  35509. });
  35510. });
  35511. return results;
  35512. });
  35513. }; // fix low-level stat names and return Map instead of object.
  35514. var ortcObjects = ['RTCRtpSender', 'RTCRtpReceiver', 'RTCIceGatherer', 'RTCIceTransport', 'RTCDtlsTransport'];
  35515. ortcObjects.forEach(function (ortcObjectName) {
  35516. var obj = window[ortcObjectName];
  35517. if (obj && obj.prototype && obj.prototype.getStats) {
  35518. var nativeGetstats = obj.prototype.getStats;
  35519. obj.prototype.getStats = function () {
  35520. return nativeGetstats.apply(this).then(function (nativeStats) {
  35521. var mapStats = new Map();
  35522. Object.keys(nativeStats).forEach(function (id) {
  35523. nativeStats[id].type = fixStatsType(nativeStats[id]);
  35524. mapStats.set(id, nativeStats[id]);
  35525. });
  35526. return mapStats;
  35527. });
  35528. };
  35529. }
  35530. }); // legacy callback shims. Should be moved to adapter.js some days.
  35531. var methods = ['createOffer', 'createAnswer'];
  35532. methods.forEach(function (method) {
  35533. var nativeMethod = RTCPeerConnection.prototype[method];
  35534. RTCPeerConnection.prototype[method] = function () {
  35535. var args = arguments;
  35536. if (typeof args[0] === 'function' || typeof args[1] === 'function') {
  35537. // legacy
  35538. return nativeMethod.apply(this, [arguments[2]]).then(function (description) {
  35539. if (typeof args[0] === 'function') {
  35540. args[0].apply(null, [description]);
  35541. }
  35542. }, function (error) {
  35543. if (typeof args[1] === 'function') {
  35544. args[1].apply(null, [error]);
  35545. }
  35546. });
  35547. }
  35548. return nativeMethod.apply(this, arguments);
  35549. };
  35550. });
  35551. methods = ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'];
  35552. methods.forEach(function (method) {
  35553. var nativeMethod = RTCPeerConnection.prototype[method];
  35554. RTCPeerConnection.prototype[method] = function () {
  35555. var args = arguments;
  35556. if (typeof args[1] === 'function' || typeof args[2] === 'function') {
  35557. // legacy
  35558. return nativeMethod.apply(this, arguments).then(function () {
  35559. if (typeof args[1] === 'function') {
  35560. args[1].apply(null);
  35561. }
  35562. }, function (error) {
  35563. if (typeof args[2] === 'function') {
  35564. args[2].apply(null, [error]);
  35565. }
  35566. });
  35567. }
  35568. return nativeMethod.apply(this, arguments);
  35569. };
  35570. }); // getStats is special. It doesn't have a spec legacy method yet we support
  35571. // getStats(something, cb) without error callbacks.
  35572. ['getStats'].forEach(function (method) {
  35573. var nativeMethod = RTCPeerConnection.prototype[method];
  35574. RTCPeerConnection.prototype[method] = function () {
  35575. var args = arguments;
  35576. if (typeof args[1] === 'function') {
  35577. return nativeMethod.apply(this, arguments).then(function () {
  35578. if (typeof args[1] === 'function') {
  35579. args[1].apply(null);
  35580. }
  35581. });
  35582. }
  35583. return nativeMethod.apply(this, arguments);
  35584. };
  35585. });
  35586. return RTCPeerConnection;
  35587. };
  35588. }),
  35589. /* 52 */
  35590. (function(module, __webpack_exports__, __webpack_require__) {
  35591. "use strict";
  35592. /* harmony export (immutable) */ __webpack_exports__["a"] = shimGetUserMedia;
  35593. /*
  35594. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  35595. *
  35596. * Use of this source code is governed by a BSD-style license
  35597. * that can be found in the LICENSE file in the root of the source
  35598. * tree.
  35599. */
  35600. /* eslint-env node */
  35601. function shimGetUserMedia(window) {
  35602. const navigator = window && window.navigator;
  35603. const shimError_ = function (e) {
  35604. return {
  35605. name: {
  35606. PermissionDeniedError: 'NotAllowedError'
  35607. }[e.name] || e.name,
  35608. message: e.message,
  35609. constraint: e.constraint,
  35610. toString() {
  35611. return this.name;
  35612. }
  35613. };
  35614. }; // getUserMedia error shim.
  35615. const origGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
  35616. navigator.mediaDevices.getUserMedia = function (c) {
  35617. return origGetUserMedia(c).catch(e => Promise.reject(shimError_(e)));
  35618. };
  35619. }
  35620. }),
  35621. /* 53 */
  35622. (function(module, __webpack_exports__, __webpack_require__) {
  35623. "use strict";
  35624. /* harmony export (immutable) */ __webpack_exports__["a"] = shimGetDisplayMedia;
  35625. /*
  35626. * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.
  35627. *
  35628. * Use of this source code is governed by a BSD-style license
  35629. * that can be found in the LICENSE file in the root of the source
  35630. * tree.
  35631. */
  35632. /* eslint-env node */
  35633. function shimGetDisplayMedia(window) {
  35634. if (!('getDisplayMedia' in window.navigator)) {
  35635. return;
  35636. }
  35637. if (!window.navigator.mediaDevices) {
  35638. return;
  35639. }
  35640. if (window.navigator.mediaDevices && 'getDisplayMedia' in window.navigator.mediaDevices) {
  35641. return;
  35642. }
  35643. window.navigator.mediaDevices.getDisplayMedia = window.navigator.getDisplayMedia.bind(window.navigator.mediaDevices);
  35644. }
  35645. }),
  35646. /* 54 */
  35647. (function(module, __webpack_exports__, __webpack_require__) {
  35648. "use strict";
  35649. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  35650. /* harmony export (immutable) */ __webpack_exports__["shimOnTrack"] = shimOnTrack;
  35651. /* harmony export (immutable) */ __webpack_exports__["shimPeerConnection"] = shimPeerConnection;
  35652. /* harmony export (immutable) */ __webpack_exports__["shimSenderGetStats"] = shimSenderGetStats;
  35653. /* harmony export (immutable) */ __webpack_exports__["shimReceiverGetStats"] = shimReceiverGetStats;
  35654. /* harmony export (immutable) */ __webpack_exports__["shimRemoveStream"] = shimRemoveStream;
  35655. /* harmony export (immutable) */ __webpack_exports__["shimRTCDataChannel"] = shimRTCDataChannel;
  35656. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(4);
  35657. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__getusermedia__ = __webpack_require__(55);
  35658. /* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "shimGetUserMedia", function() { return __WEBPACK_IMPORTED_MODULE_1__getusermedia__["a"]; });
  35659. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__getdisplaymedia__ = __webpack_require__(56);
  35660. /* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "shimGetDisplayMedia", function() { return __WEBPACK_IMPORTED_MODULE_2__getdisplaymedia__["a"]; });
  35661. /*
  35662. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  35663. *
  35664. * Use of this source code is governed by a BSD-style license
  35665. * that can be found in the LICENSE file in the root of the source
  35666. * tree.
  35667. */
  35668. /* eslint-env node */
  35669. function shimOnTrack(window) {
  35670. if (typeof window === 'object' && window.RTCTrackEvent && 'receiver' in window.RTCTrackEvent.prototype && !('transceiver' in window.RTCTrackEvent.prototype)) {
  35671. Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {
  35672. get() {
  35673. return {
  35674. receiver: this.receiver
  35675. };
  35676. }
  35677. });
  35678. }
  35679. }
  35680. function shimPeerConnection(window) {
  35681. const browserDetails = __WEBPACK_IMPORTED_MODULE_0__utils__["b" /* detectBrowser */](window);
  35682. if (typeof window !== 'object' || !(window.RTCPeerConnection || window.mozRTCPeerConnection)) {
  35683. return; // probably media.peerconnection.enabled=false in about:config
  35684. }
  35685. if (!window.RTCPeerConnection && window.mozRTCPeerConnection) {
  35686. // very basic support for old versions.
  35687. window.RTCPeerConnection = window.mozRTCPeerConnection;
  35688. } // shim away need for obsolete RTCIceCandidate/RTCSessionDescription.
  35689. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'].forEach(function (method) {
  35690. const nativeMethod = window.RTCPeerConnection.prototype[method];
  35691. window.RTCPeerConnection.prototype[method] = function () {
  35692. arguments[0] = new (method === 'addIceCandidate' ? window.RTCIceCandidate : window.RTCSessionDescription)(arguments[0]);
  35693. return nativeMethod.apply(this, arguments);
  35694. };
  35695. }); // support for addIceCandidate(null or undefined)
  35696. const nativeAddIceCandidate = window.RTCPeerConnection.prototype.addIceCandidate;
  35697. window.RTCPeerConnection.prototype.addIceCandidate = function () {
  35698. if (!arguments[0]) {
  35699. if (arguments[1]) {
  35700. arguments[1].apply(null);
  35701. }
  35702. return Promise.resolve();
  35703. }
  35704. return nativeAddIceCandidate.apply(this, arguments);
  35705. };
  35706. const modernStatsTypes = {
  35707. inboundrtp: 'inbound-rtp',
  35708. outboundrtp: 'outbound-rtp',
  35709. candidatepair: 'candidate-pair',
  35710. localcandidate: 'local-candidate',
  35711. remotecandidate: 'remote-candidate'
  35712. };
  35713. const nativeGetStats = window.RTCPeerConnection.prototype.getStats;
  35714. window.RTCPeerConnection.prototype.getStats = function (selector, onSucc, onErr) {
  35715. return nativeGetStats.apply(this, [selector || null]).then(stats => {
  35716. if (browserDetails.version < 53 && !onSucc) {
  35717. // Shim only promise getStats with spec-hyphens in type names
  35718. // Leave callback version alone; misc old uses of forEach before Map
  35719. try {
  35720. stats.forEach(stat => {
  35721. stat.type = modernStatsTypes[stat.type] || stat.type;
  35722. });
  35723. } catch (e) {
  35724. if (e.name !== 'TypeError') {
  35725. throw e;
  35726. } // Avoid TypeError: "type" is read-only, in old versions. 34-43ish
  35727. stats.forEach((stat, i) => {
  35728. stats.set(i, Object.assign({}, stat, {
  35729. type: modernStatsTypes[stat.type] || stat.type
  35730. }));
  35731. });
  35732. }
  35733. }
  35734. return stats;
  35735. }).then(onSucc, onErr);
  35736. };
  35737. }
  35738. function shimSenderGetStats(window) {
  35739. if (!(typeof window === 'object' && window.RTCPeerConnection && window.RTCRtpSender)) {
  35740. return;
  35741. }
  35742. if (window.RTCRtpSender && 'getStats' in window.RTCRtpSender.prototype) {
  35743. return;
  35744. }
  35745. const origGetSenders = window.RTCPeerConnection.prototype.getSenders;
  35746. if (origGetSenders) {
  35747. window.RTCPeerConnection.prototype.getSenders = function () {
  35748. const senders = origGetSenders.apply(this, []);
  35749. senders.forEach(sender => sender._pc = this);
  35750. return senders;
  35751. };
  35752. }
  35753. const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  35754. if (origAddTrack) {
  35755. window.RTCPeerConnection.prototype.addTrack = function () {
  35756. const sender = origAddTrack.apply(this, arguments);
  35757. sender._pc = this;
  35758. return sender;
  35759. };
  35760. }
  35761. window.RTCRtpSender.prototype.getStats = function () {
  35762. return this.track ? this._pc.getStats(this.track) : Promise.resolve(new Map());
  35763. };
  35764. }
  35765. function shimReceiverGetStats(window) {
  35766. if (!(typeof window === 'object' && window.RTCPeerConnection && window.RTCRtpSender)) {
  35767. return;
  35768. }
  35769. if (window.RTCRtpSender && 'getStats' in window.RTCRtpReceiver.prototype) {
  35770. return;
  35771. }
  35772. const origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;
  35773. if (origGetReceivers) {
  35774. window.RTCPeerConnection.prototype.getReceivers = function () {
  35775. const receivers = origGetReceivers.apply(this, []);
  35776. receivers.forEach(receiver => receiver._pc = this);
  35777. return receivers;
  35778. };
  35779. }
  35780. __WEBPACK_IMPORTED_MODULE_0__utils__["g" /* wrapPeerConnectionEvent */](window, 'track', e => {
  35781. e.receiver._pc = e.srcElement;
  35782. return e;
  35783. });
  35784. window.RTCRtpReceiver.prototype.getStats = function () {
  35785. return this._pc.getStats(this.track);
  35786. };
  35787. }
  35788. function shimRemoveStream(window) {
  35789. if (!window.RTCPeerConnection || 'removeStream' in window.RTCPeerConnection.prototype) {
  35790. return;
  35791. }
  35792. window.RTCPeerConnection.prototype.removeStream = function (stream) {
  35793. __WEBPACK_IMPORTED_MODULE_0__utils__["a" /* deprecated */]('removeStream', 'removeTrack');
  35794. this.getSenders().forEach(sender => {
  35795. if (sender.track && stream.getTracks().includes(sender.track)) {
  35796. this.removeTrack(sender);
  35797. }
  35798. });
  35799. };
  35800. }
  35801. function shimRTCDataChannel(window) {
  35802. // rename DataChannel to RTCDataChannel (native fix in FF60):
  35803. // https://bugzilla.mozilla.org/show_bug.cgi?id=1173851
  35804. if (window.DataChannel && !window.RTCDataChannel) {
  35805. window.RTCDataChannel = window.DataChannel;
  35806. }
  35807. }
  35808. }),
  35809. /* 55 */
  35810. (function(module, __webpack_exports__, __webpack_require__) {
  35811. "use strict";
  35812. /* harmony export (immutable) */ __webpack_exports__["a"] = shimGetUserMedia;
  35813. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(4);
  35814. /*
  35815. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  35816. *
  35817. * Use of this source code is governed by a BSD-style license
  35818. * that can be found in the LICENSE file in the root of the source
  35819. * tree.
  35820. */
  35821. /* eslint-env node */
  35822. function shimGetUserMedia(window) {
  35823. const browserDetails = __WEBPACK_IMPORTED_MODULE_0__utils__["b" /* detectBrowser */](window);
  35824. const navigator = window && window.navigator;
  35825. const MediaStreamTrack = window && window.MediaStreamTrack;
  35826. navigator.getUserMedia = function (constraints, onSuccess, onError) {
  35827. // Replace Firefox 44+'s deprecation warning with unprefixed version.
  35828. __WEBPACK_IMPORTED_MODULE_0__utils__["a" /* deprecated */]('navigator.getUserMedia', 'navigator.mediaDevices.getUserMedia');
  35829. navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
  35830. };
  35831. if (!(browserDetails.version > 55 && 'autoGainControl' in navigator.mediaDevices.getSupportedConstraints())) {
  35832. const remap = function (obj, a, b) {
  35833. if (a in obj && !(b in obj)) {
  35834. obj[b] = obj[a];
  35835. delete obj[a];
  35836. }
  35837. };
  35838. const nativeGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
  35839. navigator.mediaDevices.getUserMedia = function (c) {
  35840. if (typeof c === 'object' && typeof c.audio === 'object') {
  35841. c = JSON.parse(JSON.stringify(c));
  35842. remap(c.audio, 'autoGainControl', 'mozAutoGainControl');
  35843. remap(c.audio, 'noiseSuppression', 'mozNoiseSuppression');
  35844. }
  35845. return nativeGetUserMedia(c);
  35846. };
  35847. if (MediaStreamTrack && MediaStreamTrack.prototype.getSettings) {
  35848. const nativeGetSettings = MediaStreamTrack.prototype.getSettings;
  35849. MediaStreamTrack.prototype.getSettings = function () {
  35850. const obj = nativeGetSettings.apply(this, arguments);
  35851. remap(obj, 'mozAutoGainControl', 'autoGainControl');
  35852. remap(obj, 'mozNoiseSuppression', 'noiseSuppression');
  35853. return obj;
  35854. };
  35855. }
  35856. if (MediaStreamTrack && MediaStreamTrack.prototype.applyConstraints) {
  35857. const nativeApplyConstraints = MediaStreamTrack.prototype.applyConstraints;
  35858. MediaStreamTrack.prototype.applyConstraints = function (c) {
  35859. if (this.kind === 'audio' && typeof c === 'object') {
  35860. c = JSON.parse(JSON.stringify(c));
  35861. remap(c, 'autoGainControl', 'mozAutoGainControl');
  35862. remap(c, 'noiseSuppression', 'mozNoiseSuppression');
  35863. }
  35864. return nativeApplyConstraints.apply(this, [c]);
  35865. };
  35866. }
  35867. }
  35868. }
  35869. }),
  35870. /* 56 */
  35871. (function(module, __webpack_exports__, __webpack_require__) {
  35872. "use strict";
  35873. /* harmony export (immutable) */ __webpack_exports__["a"] = shimGetDisplayMedia;
  35874. /*
  35875. * Copyright (c) 2018 The adapter.js project authors. All Rights Reserved.
  35876. *
  35877. * Use of this source code is governed by a BSD-style license
  35878. * that can be found in the LICENSE file in the root of the source
  35879. * tree.
  35880. */
  35881. /* eslint-env node */
  35882. function shimGetDisplayMedia(window, preferredMediaSource) {
  35883. if (window.navigator.mediaDevices && 'getDisplayMedia' in window.navigator.mediaDevices) {
  35884. return;
  35885. }
  35886. if (!window.navigator.mediaDevices) {
  35887. return;
  35888. }
  35889. window.navigator.mediaDevices.getDisplayMedia = function (constraints) {
  35890. if (!(constraints && constraints.video)) {
  35891. const err = new DOMException('getDisplayMedia without video ' + 'constraints is undefined');
  35892. err.name = 'NotFoundError'; // from https://heycam.github.io/webidl/#idl-DOMException-error-names
  35893. err.code = 8;
  35894. return Promise.reject(err);
  35895. }
  35896. if (constraints.video === true) {
  35897. constraints.video = {
  35898. mediaSource: preferredMediaSource
  35899. };
  35900. } else {
  35901. constraints.video.mediaSource = preferredMediaSource;
  35902. }
  35903. return window.navigator.mediaDevices.getUserMedia(constraints);
  35904. };
  35905. }
  35906. }),
  35907. /* 57 */
  35908. (function(module, __webpack_exports__, __webpack_require__) {
  35909. "use strict";
  35910. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  35911. /* harmony export (immutable) */ __webpack_exports__["shimLocalStreamsAPI"] = shimLocalStreamsAPI;
  35912. /* harmony export (immutable) */ __webpack_exports__["shimRemoteStreamsAPI"] = shimRemoteStreamsAPI;
  35913. /* harmony export (immutable) */ __webpack_exports__["shimCallbacksAPI"] = shimCallbacksAPI;
  35914. /* harmony export (immutable) */ __webpack_exports__["shimGetUserMedia"] = shimGetUserMedia;
  35915. /* harmony export (immutable) */ __webpack_exports__["shimRTCIceServerUrls"] = shimRTCIceServerUrls;
  35916. /* harmony export (immutable) */ __webpack_exports__["shimTrackEventTransceiver"] = shimTrackEventTransceiver;
  35917. /* harmony export (immutable) */ __webpack_exports__["shimCreateOfferLegacy"] = shimCreateOfferLegacy;
  35918. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(4);
  35919. /*
  35920. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  35921. *
  35922. * Use of this source code is governed by a BSD-style license
  35923. * that can be found in the LICENSE file in the root of the source
  35924. * tree.
  35925. */
  35926. function shimLocalStreamsAPI(window) {
  35927. if (typeof window !== 'object' || !window.RTCPeerConnection) {
  35928. return;
  35929. }
  35930. if (!('getLocalStreams' in window.RTCPeerConnection.prototype)) {
  35931. window.RTCPeerConnection.prototype.getLocalStreams = function () {
  35932. if (!this._localStreams) {
  35933. this._localStreams = [];
  35934. }
  35935. return this._localStreams;
  35936. };
  35937. }
  35938. if (!('addStream' in window.RTCPeerConnection.prototype)) {
  35939. const _addTrack = window.RTCPeerConnection.prototype.addTrack;
  35940. window.RTCPeerConnection.prototype.addStream = function (stream) {
  35941. if (!this._localStreams) {
  35942. this._localStreams = [];
  35943. }
  35944. if (!this._localStreams.includes(stream)) {
  35945. this._localStreams.push(stream);
  35946. }
  35947. stream.getTracks().forEach(track => _addTrack.call(this, track, stream));
  35948. };
  35949. window.RTCPeerConnection.prototype.addTrack = function (track, stream) {
  35950. if (stream) {
  35951. if (!this._localStreams) {
  35952. this._localStreams = [stream];
  35953. } else if (!this._localStreams.includes(stream)) {
  35954. this._localStreams.push(stream);
  35955. }
  35956. }
  35957. return _addTrack.call(this, track, stream);
  35958. };
  35959. }
  35960. if (!('removeStream' in window.RTCPeerConnection.prototype)) {
  35961. window.RTCPeerConnection.prototype.removeStream = function (stream) {
  35962. if (!this._localStreams) {
  35963. this._localStreams = [];
  35964. }
  35965. const index = this._localStreams.indexOf(stream);
  35966. if (index === -1) {
  35967. return;
  35968. }
  35969. this._localStreams.splice(index, 1);
  35970. const tracks = stream.getTracks();
  35971. this.getSenders().forEach(sender => {
  35972. if (tracks.includes(sender.track)) {
  35973. this.removeTrack(sender);
  35974. }
  35975. });
  35976. };
  35977. }
  35978. }
  35979. function shimRemoteStreamsAPI(window) {
  35980. if (typeof window !== 'object' || !window.RTCPeerConnection) {
  35981. return;
  35982. }
  35983. if (!('getRemoteStreams' in window.RTCPeerConnection.prototype)) {
  35984. window.RTCPeerConnection.prototype.getRemoteStreams = function () {
  35985. return this._remoteStreams ? this._remoteStreams : [];
  35986. };
  35987. }
  35988. if (!('onaddstream' in window.RTCPeerConnection.prototype)) {
  35989. Object.defineProperty(window.RTCPeerConnection.prototype, 'onaddstream', {
  35990. get() {
  35991. return this._onaddstream;
  35992. },
  35993. set(f) {
  35994. if (this._onaddstream) {
  35995. this.removeEventListener('addstream', this._onaddstream);
  35996. this.removeEventListener('track', this._onaddstreampoly);
  35997. }
  35998. this.addEventListener('addstream', this._onaddstream = f);
  35999. this.addEventListener('track', this._onaddstreampoly = e => {
  36000. e.streams.forEach(stream => {
  36001. if (!this._remoteStreams) {
  36002. this._remoteStreams = [];
  36003. }
  36004. if (this._remoteStreams.includes(stream)) {
  36005. return;
  36006. }
  36007. this._remoteStreams.push(stream);
  36008. const event = new Event('addstream');
  36009. event.stream = stream;
  36010. this.dispatchEvent(event);
  36011. });
  36012. });
  36013. }
  36014. });
  36015. const origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
  36016. window.RTCPeerConnection.prototype.setRemoteDescription = function () {
  36017. const pc = this;
  36018. if (!this._onaddstreampoly) {
  36019. this.addEventListener('track', this._onaddstreampoly = function (e) {
  36020. e.streams.forEach(stream => {
  36021. if (!pc._remoteStreams) {
  36022. pc._remoteStreams = [];
  36023. }
  36024. if (pc._remoteStreams.indexOf(stream) >= 0) {
  36025. return;
  36026. }
  36027. pc._remoteStreams.push(stream);
  36028. const event = new Event('addstream');
  36029. event.stream = stream;
  36030. pc.dispatchEvent(event);
  36031. });
  36032. });
  36033. }
  36034. return origSetRemoteDescription.apply(pc, arguments);
  36035. };
  36036. }
  36037. }
  36038. function shimCallbacksAPI(window) {
  36039. if (typeof window !== 'object' || !window.RTCPeerConnection) {
  36040. return;
  36041. }
  36042. const prototype = window.RTCPeerConnection.prototype;
  36043. const createOffer = prototype.createOffer;
  36044. const createAnswer = prototype.createAnswer;
  36045. const setLocalDescription = prototype.setLocalDescription;
  36046. const setRemoteDescription = prototype.setRemoteDescription;
  36047. const addIceCandidate = prototype.addIceCandidate;
  36048. prototype.createOffer = function (successCallback, failureCallback) {
  36049. const options = arguments.length >= 2 ? arguments[2] : arguments[0];
  36050. const promise = createOffer.apply(this, [options]);
  36051. if (!failureCallback) {
  36052. return promise;
  36053. }
  36054. promise.then(successCallback, failureCallback);
  36055. return Promise.resolve();
  36056. };
  36057. prototype.createAnswer = function (successCallback, failureCallback) {
  36058. const options = arguments.length >= 2 ? arguments[2] : arguments[0];
  36059. const promise = createAnswer.apply(this, [options]);
  36060. if (!failureCallback) {
  36061. return promise;
  36062. }
  36063. promise.then(successCallback, failureCallback);
  36064. return Promise.resolve();
  36065. };
  36066. let withCallback = function (description, successCallback, failureCallback) {
  36067. const promise = setLocalDescription.apply(this, [description]);
  36068. if (!failureCallback) {
  36069. return promise;
  36070. }
  36071. promise.then(successCallback, failureCallback);
  36072. return Promise.resolve();
  36073. };
  36074. prototype.setLocalDescription = withCallback;
  36075. withCallback = function (description, successCallback, failureCallback) {
  36076. const promise = setRemoteDescription.apply(this, [description]);
  36077. if (!failureCallback) {
  36078. return promise;
  36079. }
  36080. promise.then(successCallback, failureCallback);
  36081. return Promise.resolve();
  36082. };
  36083. prototype.setRemoteDescription = withCallback;
  36084. withCallback = function (candidate, successCallback, failureCallback) {
  36085. const promise = addIceCandidate.apply(this, [candidate]);
  36086. if (!failureCallback) {
  36087. return promise;
  36088. }
  36089. promise.then(successCallback, failureCallback);
  36090. return Promise.resolve();
  36091. };
  36092. prototype.addIceCandidate = withCallback;
  36093. }
  36094. function shimGetUserMedia(window) {
  36095. const navigator = window && window.navigator;
  36096. if (!navigator.getUserMedia && navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  36097. navigator.getUserMedia = function (constraints, cb, errcb) {
  36098. navigator.mediaDevices.getUserMedia(constraints).then(cb, errcb);
  36099. }.bind(navigator);
  36100. }
  36101. }
  36102. function shimRTCIceServerUrls(window) {
  36103. // migrate from non-spec RTCIceServer.url to RTCIceServer.urls
  36104. const OrigPeerConnection = window.RTCPeerConnection;
  36105. window.RTCPeerConnection = function (pcConfig, pcConstraints) {
  36106. if (pcConfig && pcConfig.iceServers) {
  36107. const newIceServers = [];
  36108. for (let i = 0; i < pcConfig.iceServers.length; i++) {
  36109. let server = pcConfig.iceServers[i];
  36110. if (!server.hasOwnProperty('urls') && server.hasOwnProperty('url')) {
  36111. __WEBPACK_IMPORTED_MODULE_0__utils__["a" /* deprecated */]('RTCIceServer.url', 'RTCIceServer.urls');
  36112. server = JSON.parse(JSON.stringify(server));
  36113. server.urls = server.url;
  36114. delete server.url;
  36115. newIceServers.push(server);
  36116. } else {
  36117. newIceServers.push(pcConfig.iceServers[i]);
  36118. }
  36119. }
  36120. pcConfig.iceServers = newIceServers;
  36121. }
  36122. return new OrigPeerConnection(pcConfig, pcConstraints);
  36123. };
  36124. window.RTCPeerConnection.prototype = OrigPeerConnection.prototype; // wrap static methods. Currently just generateCertificate.
  36125. if ('generateCertificate' in window.RTCPeerConnection) {
  36126. Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
  36127. get() {
  36128. return OrigPeerConnection.generateCertificate;
  36129. }
  36130. });
  36131. }
  36132. }
  36133. function shimTrackEventTransceiver(window) {
  36134. // Add event.transceiver member over deprecated event.receiver
  36135. if (typeof window === 'object' && window.RTCPeerConnection && 'receiver' in window.RTCTrackEvent.prototype && // can't check 'transceiver' in window.RTCTrackEvent.prototype, as it is
  36136. // defined for some reason even when window.RTCTransceiver is not.
  36137. !window.RTCTransceiver) {
  36138. Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {
  36139. get() {
  36140. return {
  36141. receiver: this.receiver
  36142. };
  36143. }
  36144. });
  36145. }
  36146. }
  36147. function shimCreateOfferLegacy(window) {
  36148. const origCreateOffer = window.RTCPeerConnection.prototype.createOffer;
  36149. window.RTCPeerConnection.prototype.createOffer = function (offerOptions) {
  36150. if (offerOptions) {
  36151. if (typeof offerOptions.offerToReceiveAudio !== 'undefined') {
  36152. // support bit values
  36153. offerOptions.offerToReceiveAudio = !!offerOptions.offerToReceiveAudio;
  36154. }
  36155. const audioTransceiver = this.getTransceivers().find(transceiver => transceiver.sender.track && transceiver.sender.track.kind === 'audio');
  36156. if (offerOptions.offerToReceiveAudio === false && audioTransceiver) {
  36157. if (audioTransceiver.direction === 'sendrecv') {
  36158. if (audioTransceiver.setDirection) {
  36159. audioTransceiver.setDirection('sendonly');
  36160. } else {
  36161. audioTransceiver.direction = 'sendonly';
  36162. }
  36163. } else if (audioTransceiver.direction === 'recvonly') {
  36164. if (audioTransceiver.setDirection) {
  36165. audioTransceiver.setDirection('inactive');
  36166. } else {
  36167. audioTransceiver.direction = 'inactive';
  36168. }
  36169. }
  36170. } else if (offerOptions.offerToReceiveAudio === true && !audioTransceiver) {
  36171. this.addTransceiver('audio');
  36172. }
  36173. if (typeof offerOptions.offerToReceiveVideo !== 'undefined') {
  36174. // support bit values
  36175. offerOptions.offerToReceiveVideo = !!offerOptions.offerToReceiveVideo;
  36176. }
  36177. const videoTransceiver = this.getTransceivers().find(transceiver => transceiver.sender.track && transceiver.sender.track.kind === 'video');
  36178. if (offerOptions.offerToReceiveVideo === false && videoTransceiver) {
  36179. if (videoTransceiver.direction === 'sendrecv') {
  36180. if (videoTransceiver.setDirection) {
  36181. videoTransceiver.setDirection('sendonly');
  36182. } else {
  36183. videoTransceiver.direction = 'sendonly';
  36184. }
  36185. } else if (videoTransceiver.direction === 'recvonly') {
  36186. if (videoTransceiver.setDirection) {
  36187. videoTransceiver.setDirection('inactive');
  36188. } else {
  36189. videoTransceiver.direction = 'inactive';
  36190. }
  36191. }
  36192. } else if (offerOptions.offerToReceiveVideo === true && !videoTransceiver) {
  36193. this.addTransceiver('video');
  36194. }
  36195. }
  36196. return origCreateOffer.apply(this, arguments);
  36197. };
  36198. }
  36199. }),
  36200. /* 58 */
  36201. (function(module, __webpack_exports__, __webpack_require__) {
  36202. "use strict";
  36203. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  36204. /* harmony export (immutable) */ __webpack_exports__["shimRTCIceCandidate"] = shimRTCIceCandidate;
  36205. /* harmony export (immutable) */ __webpack_exports__["shimMaxMessageSize"] = shimMaxMessageSize;
  36206. /* harmony export (immutable) */ __webpack_exports__["shimSendThrowTypeError"] = shimSendThrowTypeError;
  36207. /* harmony export (immutable) */ __webpack_exports__["shimConnectionState"] = shimConnectionState;
  36208. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_sdp__ = __webpack_require__(19);
  36209. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_sdp___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_sdp__);
  36210. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__utils__ = __webpack_require__(4);
  36211. /*
  36212. * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  36213. *
  36214. * Use of this source code is governed by a BSD-style license
  36215. * that can be found in the LICENSE file in the root of the source
  36216. * tree.
  36217. */
  36218. /* eslint-env node */
  36219. function shimRTCIceCandidate(window) {
  36220. // foundation is arbitrarily chosen as an indicator for full support for
  36221. // https://w3c.github.io/webrtc-pc/#rtcicecandidate-interface
  36222. if (!window.RTCIceCandidate || window.RTCIceCandidate && 'foundation' in window.RTCIceCandidate.prototype) {
  36223. return;
  36224. }
  36225. const NativeRTCIceCandidate = window.RTCIceCandidate;
  36226. window.RTCIceCandidate = function (args) {
  36227. // Remove the a= which shouldn't be part of the candidate string.
  36228. if (typeof args === 'object' && args.candidate && args.candidate.indexOf('a=') === 0) {
  36229. args = JSON.parse(JSON.stringify(args));
  36230. args.candidate = args.candidate.substr(2);
  36231. }
  36232. if (args.candidate && args.candidate.length) {
  36233. // Augment the native candidate with the parsed fields.
  36234. const nativeCandidate = new NativeRTCIceCandidate(args);
  36235. const parsedCandidate = __WEBPACK_IMPORTED_MODULE_0_sdp___default.a.parseCandidate(args.candidate);
  36236. const augmentedCandidate = Object.assign(nativeCandidate, parsedCandidate); // Add a serializer that does not serialize the extra attributes.
  36237. augmentedCandidate.toJSON = function () {
  36238. return {
  36239. candidate: augmentedCandidate.candidate,
  36240. sdpMid: augmentedCandidate.sdpMid,
  36241. sdpMLineIndex: augmentedCandidate.sdpMLineIndex,
  36242. usernameFragment: augmentedCandidate.usernameFragment
  36243. };
  36244. };
  36245. return augmentedCandidate;
  36246. }
  36247. return new NativeRTCIceCandidate(args);
  36248. };
  36249. window.RTCIceCandidate.prototype = NativeRTCIceCandidate.prototype; // Hook up the augmented candidate in onicecandidate and
  36250. // addEventListener('icecandidate', ...)
  36251. __WEBPACK_IMPORTED_MODULE_1__utils__["g" /* wrapPeerConnectionEvent */](window, 'icecandidate', e => {
  36252. if (e.candidate) {
  36253. Object.defineProperty(e, 'candidate', {
  36254. value: new window.RTCIceCandidate(e.candidate),
  36255. writable: 'false'
  36256. });
  36257. }
  36258. return e;
  36259. });
  36260. }
  36261. function shimMaxMessageSize(window) {
  36262. if (window.RTCSctpTransport || !window.RTCPeerConnection) {
  36263. return;
  36264. }
  36265. const browserDetails = __WEBPACK_IMPORTED_MODULE_1__utils__["b" /* detectBrowser */](window);
  36266. if (!('sctp' in window.RTCPeerConnection.prototype)) {
  36267. Object.defineProperty(window.RTCPeerConnection.prototype, 'sctp', {
  36268. get() {
  36269. return typeof this._sctp === 'undefined' ? null : this._sctp;
  36270. }
  36271. });
  36272. }
  36273. const sctpInDescription = function (description) {
  36274. const sections = __WEBPACK_IMPORTED_MODULE_0_sdp___default.a.splitSections(description.sdp);
  36275. sections.shift();
  36276. return sections.some(mediaSection => {
  36277. const mLine = __WEBPACK_IMPORTED_MODULE_0_sdp___default.a.parseMLine(mediaSection);
  36278. return mLine && mLine.kind === 'application' && mLine.protocol.indexOf('SCTP') !== -1;
  36279. });
  36280. };
  36281. const getRemoteFirefoxVersion = function (description) {
  36282. // TODO: Is there a better solution for detecting Firefox?
  36283. const match = description.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);
  36284. if (match === null || match.length < 2) {
  36285. return -1;
  36286. }
  36287. const version = parseInt(match[1], 10); // Test for NaN (yes, this is ugly)
  36288. return version !== version ? -1 : version;
  36289. };
  36290. const getCanSendMaxMessageSize = function (remoteIsFirefox) {
  36291. // Every implementation we know can send at least 64 KiB.
  36292. // Note: Although Chrome is technically able to send up to 256 KiB, the
  36293. // data does not reach the other peer reliably.
  36294. // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=8419
  36295. let canSendMaxMessageSize = 65536;
  36296. if (browserDetails.browser === 'firefox') {
  36297. if (browserDetails.version < 57) {
  36298. if (remoteIsFirefox === -1) {
  36299. // FF < 57 will send in 16 KiB chunks using the deprecated PPID
  36300. // fragmentation.
  36301. canSendMaxMessageSize = 16384;
  36302. } else {
  36303. // However, other FF (and RAWRTC) can reassemble PPID-fragmented
  36304. // messages. Thus, supporting ~2 GiB when sending.
  36305. canSendMaxMessageSize = 2147483637;
  36306. }
  36307. } else if (browserDetails.version < 60) {
  36308. // Currently, all FF >= 57 will reset the remote maximum message size
  36309. // to the default value when a data channel is created at a later
  36310. // stage. :(
  36311. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831
  36312. canSendMaxMessageSize = browserDetails.version === 57 ? 65535 : 65536;
  36313. } else {
  36314. // FF >= 60 supports sending ~2 GiB
  36315. canSendMaxMessageSize = 2147483637;
  36316. }
  36317. }
  36318. return canSendMaxMessageSize;
  36319. };
  36320. const getMaxMessageSize = function (description, remoteIsFirefox) {
  36321. // Note: 65536 bytes is the default value from the SDP spec. Also,
  36322. // every implementation we know supports receiving 65536 bytes.
  36323. let maxMessageSize = 65536; // FF 57 has a slightly incorrect default remote max message size, so
  36324. // we need to adjust it here to avoid a failure when sending.
  36325. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1425697
  36326. if (browserDetails.browser === 'firefox' && browserDetails.version === 57) {
  36327. maxMessageSize = 65535;
  36328. }
  36329. const match = __WEBPACK_IMPORTED_MODULE_0_sdp___default.a.matchPrefix(description.sdp, 'a=max-message-size:');
  36330. if (match.length > 0) {
  36331. maxMessageSize = parseInt(match[0].substr(19), 10);
  36332. } else if (browserDetails.browser === 'firefox' && remoteIsFirefox !== -1) {
  36333. // If the maximum message size is not present in the remote SDP and
  36334. // both local and remote are Firefox, the remote peer can receive
  36335. // ~2 GiB.
  36336. maxMessageSize = 2147483637;
  36337. }
  36338. return maxMessageSize;
  36339. };
  36340. const origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
  36341. window.RTCPeerConnection.prototype.setRemoteDescription = function () {
  36342. this._sctp = null;
  36343. if (sctpInDescription(arguments[0])) {
  36344. // Check if the remote is FF.
  36345. const isFirefox = getRemoteFirefoxVersion(arguments[0]); // Get the maximum message size the local peer is capable of sending
  36346. const canSendMMS = getCanSendMaxMessageSize(isFirefox); // Get the maximum message size of the remote peer.
  36347. const remoteMMS = getMaxMessageSize(arguments[0], isFirefox); // Determine final maximum message size
  36348. let maxMessageSize;
  36349. if (canSendMMS === 0 && remoteMMS === 0) {
  36350. maxMessageSize = Number.POSITIVE_INFINITY;
  36351. } else if (canSendMMS === 0 || remoteMMS === 0) {
  36352. maxMessageSize = Math.max(canSendMMS, remoteMMS);
  36353. } else {
  36354. maxMessageSize = Math.min(canSendMMS, remoteMMS);
  36355. } // Create a dummy RTCSctpTransport object and the 'maxMessageSize'
  36356. // attribute.
  36357. const sctp = {};
  36358. Object.defineProperty(sctp, 'maxMessageSize', {
  36359. get() {
  36360. return maxMessageSize;
  36361. }
  36362. });
  36363. this._sctp = sctp;
  36364. }
  36365. return origSetRemoteDescription.apply(this, arguments);
  36366. };
  36367. }
  36368. function shimSendThrowTypeError(window) {
  36369. if (!(window.RTCPeerConnection && 'createDataChannel' in window.RTCPeerConnection.prototype)) {
  36370. return;
  36371. } // Note: Although Firefox >= 57 has a native implementation, the maximum
  36372. // message size can be reset for all data channels at a later stage.
  36373. // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831
  36374. function wrapDcSend(dc, pc) {
  36375. const origDataChannelSend = dc.send;
  36376. dc.send = function () {
  36377. const data = arguments[0];
  36378. const length = data.length || data.size || data.byteLength;
  36379. if (dc.readyState === 'open' && pc.sctp && length > pc.sctp.maxMessageSize) {
  36380. throw new TypeError('Message too large (can send a maximum of ' + pc.sctp.maxMessageSize + ' bytes)');
  36381. }
  36382. return origDataChannelSend.apply(dc, arguments);
  36383. };
  36384. }
  36385. const origCreateDataChannel = window.RTCPeerConnection.prototype.createDataChannel;
  36386. window.RTCPeerConnection.prototype.createDataChannel = function () {
  36387. const dataChannel = origCreateDataChannel.apply(this, arguments);
  36388. wrapDcSend(dataChannel, this);
  36389. return dataChannel;
  36390. };
  36391. __WEBPACK_IMPORTED_MODULE_1__utils__["g" /* wrapPeerConnectionEvent */](window, 'datachannel', e => {
  36392. wrapDcSend(e.channel, e.target);
  36393. return e;
  36394. });
  36395. }
  36396. /* shims RTCConnectionState by pretending it is the same as iceConnectionState.
  36397. * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12
  36398. * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect
  36399. * since DTLS failures would be hidden. See
  36400. * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827
  36401. * for the Firefox tracking bug.
  36402. */
  36403. function shimConnectionState(window) {
  36404. if (!window.RTCPeerConnection || 'connectionState' in window.RTCPeerConnection.prototype) {
  36405. return;
  36406. }
  36407. const proto = window.RTCPeerConnection.prototype;
  36408. Object.defineProperty(proto, 'connectionState', {
  36409. get() {
  36410. return {
  36411. completed: 'connected',
  36412. checking: 'connecting'
  36413. }[this.iceConnectionState] || this.iceConnectionState;
  36414. },
  36415. enumerable: true,
  36416. configurable: true
  36417. });
  36418. Object.defineProperty(proto, 'onconnectionstatechange', {
  36419. get() {
  36420. return this._onconnectionstatechange || null;
  36421. },
  36422. set(cb) {
  36423. if (this._onconnectionstatechange) {
  36424. this.removeEventListener('connectionstatechange', this._onconnectionstatechange);
  36425. delete this._onconnectionstatechange;
  36426. }
  36427. if (cb) {
  36428. this.addEventListener('connectionstatechange', this._onconnectionstatechange = cb);
  36429. }
  36430. },
  36431. enumerable: true,
  36432. configurable: true
  36433. });
  36434. ['setLocalDescription', 'setRemoteDescription'].forEach(method => {
  36435. const origMethod = proto[method];
  36436. proto[method] = function () {
  36437. if (!this._connectionstatechangepoly) {
  36438. this._connectionstatechangepoly = e => {
  36439. const pc = e.target;
  36440. if (pc._lastConnectionState !== pc.connectionState) {
  36441. pc._lastConnectionState = pc.connectionState;
  36442. const newEvent = new Event('connectionstatechange', e);
  36443. pc.dispatchEvent(newEvent);
  36444. }
  36445. return e;
  36446. };
  36447. this.addEventListener('iceconnectionstatechange', this._connectionstatechangepoly);
  36448. }
  36449. return origMethod.apply(this, arguments);
  36450. };
  36451. });
  36452. }
  36453. }),
  36454. /* 59 */
  36455. (function(module, exports, __webpack_require__) {
  36456. var $ = __webpack_require__(22);
  36457. var DetectRTC = __webpack_require__(20);
  36458. var JSON = __webpack_require__(60);
  36459. var PhoneNetwork = __webpack_require__(61);
  36460. var PhoneLogger = {
  36461. enable: false,
  36462. Level: 'DEBUG'
  36463. };
  36464. PhoneLogger.url = 'https://localhost:49999';
  36465. PhoneLogger.port = '49999'; // PhoneLogger.user = '';
  36466. var rootAPI = '/api';
  36467. var seq = 0;
  36468. const authorizationToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImxvZ2dlciIsInBhc3N3b3JkIjoid1JGZCU1Lnd-cF44PDdxLSIsImlhdCI6MTU0OTI1NzU0OH0.L_rBP1IejBsWFZdT4Ih7CFJd-DrQEwY91t8i-wThb4c';
  36469. PhoneLogger.debug = function (debug) {
  36470. if (!PhoneLogger.enable||PhoneLogger.Level !== 'DEBUG') return;
  36471. var _data = {
  36472. event: 'debug',
  36473. seq: seq,
  36474. user: PhoneLogger.user,
  36475. direction: debug.direction,
  36476. network: {
  36477. latency: PhoneNetwork.latency,
  36478. uploadSpeed: PhoneNetwork.uploadSpeed,
  36479. downloadSpeed: PhoneNetwork.downloadSpeed
  36480. },
  36481. isWebRTCSupported: DetectRTC.isWebRTCSupported,
  36482. isGetUserMediaSupported: DetectRTC.isGetUserMediaSupported,
  36483. isWebSocketsSupported: DetectRTC.isWebSocketsSupported,
  36484. isAudioContextSupported : DetectRTC.isAudioContextSupported,
  36485. os: DetectRTC.osName + ' ' + DetectRTC.osVersion,
  36486. browser: DetectRTC.browser.name + ' ' + PhoneJs.DetectRTC.browser.fullVersion,
  36487. isMobileDevice: DetectRTC.isMobileDevice // hasMicrophone: DetectRTC.hasMicrophone,
  36488. // hasWebcam: DetectRTC.hasWebcam,
  36489. // hasWebcamPermissions: DetectRTC.isWebsiteHasWebcamPermissions,
  36490. // hasMicrophonePermissions: DetectRTC.isWebsiteHasMicrophonePermissions,
  36491. // isGetUserMediaSupported: DetectRTC.isGetUserMediaSupported,
  36492. // isWebRTCSupported: DetectRTC.isWebRTCSupported
  36493. };
  36494. if (typeof data !== 'string') {
  36495. _data.data = debug.data.toString();
  36496. } else {
  36497. _data.data = debug.data;
  36498. }
  36499. var body = JSON.stringify(_data);
  36500. // var url = PhoneLogger.url + rootAPI + '/debug';
  36501. var url = PhoneLogger.url + rootAPI + '/log';
  36502. seq++;
  36503. $.ajax({
  36504. url: url,
  36505. dataType: 'json',
  36506. headers: {
  36507. 'Authorization':'Bearer ' + authorizationToken,
  36508. },
  36509. type: 'POST',
  36510. contentType: 'application/json',
  36511. data: body,
  36512. success: function (data) {
  36513. },
  36514. error: function (error) {
  36515. console.log('error: ' + JSON.stringify(error));
  36516. }
  36517. });
  36518. };
  36519. PhoneLogger.info = function (info) {
  36520. // console.log(info);
  36521. // console.log(info);
  36522. if (!PhoneLogger.enable||PhoneLogger.Level === 'ERROR') return; // var _data = {};
  36523. info.os = DetectRTC.osName + ' ' + DetectRTC.osVersion;
  36524. info.browser = DetectRTC.browser.name + ' ' + PhoneJs.DetectRTC.browser.fullVersion;
  36525. info.isMobileDevice = DetectRTC.isMobileDevice;
  36526. info.isWebRTCSupported = DetectRTC.isWebRTCSupported;
  36527. info.isGetUserMediaSupported = DetectRTC.isGetUserMediaSupported;
  36528. info.isWebSocketsSupported = DetectRTC.isWebSocketsSupported;
  36529. info.isAudioContextSupported = DetectRTC.isAudioContextSupported;
  36530. info.network = {
  36531. latency: PhoneNetwork.latency,
  36532. uploadSpeed: PhoneNetwork.uploadSpeed,
  36533. downloadSpeed: PhoneNetwork.downloadSpeed
  36534. }
  36535. var body = JSON.stringify(info);
  36536. // var url = PhoneLogger.url + rootAPI + '/info';
  36537. var url = PhoneLogger.url + rootAPI + '/log';
  36538. $.ajax({
  36539. url: url,
  36540. dataType: 'json',
  36541. headers: {
  36542. 'Authorization':'Bearer ' + authorizationToken,
  36543. },
  36544. type: 'POST',
  36545. contentType: 'application/json',
  36546. data: body,
  36547. success: function (data) {},
  36548. error: function (error) {
  36549. console.log('error: ' + JSON.stringify(error));
  36550. }
  36551. });
  36552. };
  36553. PhoneLogger.error = function (error) {
  36554. if(!PhoneLogger.enable) return;
  36555. var _data = {};
  36556. error.os = DetectRTC.osName + ' ' + DetectRTC.osVersion;
  36557. error.browser = DetectRTC.browser.name + ' ' + PhoneJs.DetectRTC.browser.fullVersion;
  36558. error.isMobileDevice = DetectRTC.isMobileDevice;
  36559. error.isWebRTCSupported = DetectRTC.isWebRTCSupported;
  36560. error.isGetUserMediaSupported = DetectRTC.isGetUserMediaSupported;
  36561. error.isWebSocketsSupported = DetectRTC.isWebSocketsSupported;
  36562. error.isAudioContextSupported = DetectRTC.isAudioContextSupported;
  36563. error.network = {
  36564. latency: PhoneNetwork.latency,
  36565. uploadSpeed: PhoneNetwork.uploadSpeed,
  36566. downloadSpeed: PhoneNetwork.downloadSpeed
  36567. }
  36568. var body = JSON.stringify(error);
  36569. // var url = PhoneLogger.url + rootAPI + '/error';
  36570. var url = PhoneLogger.url + rootAPI + '/log';
  36571. $.ajax({
  36572. url: url,
  36573. dataType: 'json',
  36574. headers: {
  36575. 'Authorization':'Bearer ' + authorizationToken,
  36576. },
  36577. type: 'POST',
  36578. contentType: 'application/json',
  36579. data: body,
  36580. success: function (data) {// console.log('response: ' + data);
  36581. },
  36582. error: function (error) {
  36583. console.log('error: ' + JSON.stringify(error));
  36584. }
  36585. });
  36586. };
  36587. module.exports = PhoneLogger;
  36588. }),
  36589. /* 60 */
  36590. (function(module, exports) {
  36591. /*!
  36592. Copyright (C) 2013-2017 by Andrea Giammarchi - @WebReflection
  36593. Permission is hereby granted, free of charge, to any person obtaining a copy
  36594. of this software and associated documentation files (the "Software"), to deal
  36595. in the Software without restriction, including without limitation the rights
  36596. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  36597. copies of the Software, and to permit persons to whom the Software is
  36598. furnished to do so, subject to the following conditions:
  36599. The above copyright notice and this permission notice shall be included in
  36600. all copies or substantial portions of the Software.
  36601. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  36602. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  36603. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  36604. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  36605. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  36606. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  36607. THE SOFTWARE.
  36608. */
  36609. var // should be a not so common char
  36610. // possibly one JSON does not encode
  36611. // possibly one encodeURIComponent does not encode
  36612. // right now this char is '~' but this might change in the future
  36613. specialChar = '~',
  36614. safeSpecialChar = '\\x' + ('0' + specialChar.charCodeAt(0).toString(16)).slice(-2),
  36615. escapedSafeSpecialChar = '\\' + safeSpecialChar,
  36616. specialCharRG = new RegExp(safeSpecialChar, 'g'),
  36617. safeSpecialCharRG = new RegExp(escapedSafeSpecialChar, 'g'),
  36618. safeStartWithSpecialCharRG = new RegExp('(?:^|([^\\\\]))' + escapedSafeSpecialChar),
  36619. indexOf = [].indexOf || function (v) {
  36620. for (var i = this.length; i-- && this[i] !== v;);
  36621. return i;
  36622. },
  36623. $String = String // there's no way to drop warnings in JSHint
  36624. // about new String ... well, I need that here!
  36625. // faked, and happy linter!
  36626. ;
  36627. function generateReplacer(value, replacer, resolve) {
  36628. var doNotIgnore = false,
  36629. inspect = !!replacer,
  36630. path = [],
  36631. all = [value],
  36632. seen = [value],
  36633. mapp = [resolve ? specialChar : '[Circular]'],
  36634. last = value,
  36635. lvl = 1,
  36636. i,
  36637. fn;
  36638. if (inspect) {
  36639. fn = typeof replacer === 'object' ? function (key, value) {
  36640. return key !== '' && replacer.indexOf(key) < 0 ? void 0 : value;
  36641. } : replacer;
  36642. }
  36643. return function (key, value) {
  36644. // the replacer has rights to decide
  36645. // if a new object should be returned
  36646. // or if there's some key to drop
  36647. // let's call it here rather than "too late"
  36648. if (inspect) value = fn.call(this, key, value); // first pass should be ignored, since it's just the initial object
  36649. if (doNotIgnore) {
  36650. if (last !== this) {
  36651. i = lvl - indexOf.call(all, this) - 1;
  36652. lvl -= i;
  36653. all.splice(lvl, all.length);
  36654. path.splice(lvl - 1, path.length);
  36655. last = this;
  36656. } // console.log(lvl, key, path);
  36657. if (typeof value === 'object' && value) {
  36658. // if object isn't referring to parent object, add to the
  36659. // object path stack. Otherwise it is already there.
  36660. if (indexOf.call(all, value) < 0) {
  36661. all.push(last = value);
  36662. }
  36663. lvl = all.length;
  36664. i = indexOf.call(seen, value);
  36665. if (i < 0) {
  36666. i = seen.push(value) - 1;
  36667. if (resolve) {
  36668. // key cannot contain specialChar but could be not a string
  36669. path.push(('' + key).replace(specialCharRG, safeSpecialChar));
  36670. mapp[i] = specialChar + path.join(specialChar);
  36671. } else {
  36672. mapp[i] = mapp[0];
  36673. }
  36674. } else {
  36675. value = mapp[i];
  36676. }
  36677. } else {
  36678. if (typeof value === 'string' && resolve) {
  36679. // ensure no special char involved on deserialization
  36680. // in this case only first char is important
  36681. // no need to replace all value (better performance)
  36682. value = value.replace(safeSpecialChar, escapedSafeSpecialChar).replace(specialChar, safeSpecialChar);
  36683. }
  36684. }
  36685. } else {
  36686. doNotIgnore = true;
  36687. }
  36688. return value;
  36689. };
  36690. }
  36691. function retrieveFromPath(current, keys) {
  36692. for (var i = 0, length = keys.length; i < length; current = current[// keys should be normalized back here
  36693. keys[i++].replace(safeSpecialCharRG, specialChar)]);
  36694. return current;
  36695. }
  36696. function generateReviver(reviver) {
  36697. return function (key, value) {
  36698. var isString = typeof value === 'string';
  36699. if (isString && value.charAt(0) === specialChar) {
  36700. return new $String(value.slice(1));
  36701. }
  36702. if (key === '') value = regenerate(value, value, {}); // again, only one needed, do not use the RegExp for this replacement
  36703. // only keys need the RegExp
  36704. if (isString) value = value.replace(safeStartWithSpecialCharRG, '$1' + specialChar).replace(escapedSafeSpecialChar, safeSpecialChar);
  36705. return reviver ? reviver.call(this, key, value) : value;
  36706. };
  36707. }
  36708. function regenerateArray(root, current, retrieve) {
  36709. for (var i = 0, length = current.length; i < length; i++) {
  36710. current[i] = regenerate(root, current[i], retrieve);
  36711. }
  36712. return current;
  36713. }
  36714. function regenerateObject(root, current, retrieve) {
  36715. for (var key in current) {
  36716. if (current.hasOwnProperty(key)) {
  36717. current[key] = regenerate(root, current[key], retrieve);
  36718. }
  36719. }
  36720. return current;
  36721. }
  36722. function regenerate(root, current, retrieve) {
  36723. return current instanceof Array ? // fast Array reconstruction
  36724. regenerateArray(root, current, retrieve) : current instanceof $String ? // root is an empty string
  36725. current.length ? retrieve.hasOwnProperty(current) ? retrieve[current] : retrieve[current] = retrieveFromPath(root, current.split(specialChar)) : root : current instanceof Object ? // dedicated Object parser
  36726. regenerateObject(root, current, retrieve) : // value as it is
  36727. current;
  36728. }
  36729. var CircularJSON = {
  36730. stringify: function stringify(value, replacer, space, doNotResolve) {
  36731. return CircularJSON.parser.stringify(value, generateReplacer(value, replacer, !doNotResolve), space);
  36732. },
  36733. parse: function parse(text, reviver) {
  36734. return CircularJSON.parser.parse(text, generateReviver(reviver));
  36735. },
  36736. // A parser should be an API 1:1 compatible with JSON
  36737. // it should expose stringify and parse methods.
  36738. // The default parser is the native JSON.
  36739. parser: JSON
  36740. };
  36741. module.exports = CircularJSON;
  36742. }),
  36743. /* 61 */
  36744. (function(module, exports, __webpack_require__) {
  36745. var $ = __webpack_require__(22);
  36746. var Network = __webpack_require__(62);
  36747. var PhoneNetwork = {};
  36748. PhoneNetwork.url = 'https://localhost:49999';
  36749. PhoneNetwork.enable = false;
  36750. const authorizationToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImxvZ2dlciIsInBhc3N3b3JkIjoid1JGZCU1Lnd-cF44PDdxLSIsImlhdCI6MTU0OTI1NzU0OH0.L_rBP1IejBsWFZdT4Ih7CFJd-DrQEwY91t8i-wThb4c';
  36751. // PhoneNetwork.url = 'https://phone-log.entro-lab.com';
  36752. var net = new Network({
  36753. endpoint: PhoneNetwork.url + '/api/speedtest',
  36754. // Where is located the PHP file.
  36755. latency: {
  36756. // Where is located your `network.php` file.
  36757. // endpoint: PhoneNetwork.url,
  36758. // How many measures should be returned.
  36759. measures: 5,
  36760. // How much attempts to get a valid value should be done for each measure.
  36761. attempts: 3
  36762. },
  36763. upload: {
  36764. // Where is located your `network.php` file.
  36765. // endpoint: 'https://localhost:3443/api/speedtest',
  36766. // The delay while you want to take measures.
  36767. delay: 3000,
  36768. data: {
  36769. // The amount of data to initially use.
  36770. size: 2 * 1024 * 1024,
  36771. // 2 MB
  36772. // If the measure period can't reach the delay defined in the settings,
  36773. // the data amount is multiplied by the following value.
  36774. multiplier: 2
  36775. }
  36776. },
  36777. download: {
  36778. // endpoint: 'https://localhost:3443/api/speedtest',
  36779. delay: 3000,
  36780. data: {
  36781. // The amount of data to initially use.
  36782. size: 1 * 1024 * 1024,
  36783. // 10 MB
  36784. // If the measure period can't reach the delay defined in the settings,
  36785. // the data amount is multiplied by the following value.
  36786. multiplier: 2
  36787. }
  36788. }
  36789. });
  36790. var arrTimes = [];
  36791. var i = 0; // start
  36792. var timesToTest = 5;
  36793. var tThreshold = 150; //ms
  36794. var dummyImage = new Image();
  36795. var isConnectedFast = false;
  36796. var downloadSize = 380685; //bytes
  36797. var uploadSize = 380685; //bytes
  36798. var average;
  36799. PhoneNetwork.test = function (callback) {
  36800. if(!PhoneNetwork.enable) return;
  36801. testLatency(function (data) {
  36802. i = 0;
  36803. isConnectedFast = data.avg <= tThreshold;
  36804. /** output */
  36805. if (data.avg) {
  36806. PhoneNetwork.latency = data.avg.toFixed(2);
  36807. // console.log("Latency: " + PhoneNetwork.latency + "ms - isConnectedFast? " + isConnectedFast);
  36808. testConnectionSpeed(function (response) {
  36809. if (callback && typeof callback == 'function') {
  36810. callback(response);
  36811. }
  36812. });
  36813. } else {
  36814. if (callback && typeof callback == 'function') {
  36815. callback(data);
  36816. }
  36817. }
  36818. });
  36819. // testConnectionSpeed(callback);
  36820. // if (callback && typeof callback == 'function') {
  36821. // callback();
  36822. // }
  36823. };
  36824. PhoneNetwork.testLatency = function (callback) {
  36825. net.latency.on('end', function (averageLatency, allLatencies) {
  36826. // "allLatencies" is an array containing the five calculated latencies in
  36827. // milliseconds. They're used to determine an average latency.
  36828. // console.log('latency', averageLatency.toFixed(2), allLatencies);
  36829. PhoneNetwork.latency = averageLatency.toFixed(2);
  36830. });
  36831. net.latency.start();
  36832. };
  36833. PhoneNetwork.testUpload = function (callback) {
  36834. net.upload.on('start', function (dataSize) {// console.log('start', dataSize);
  36835. }).on('progress', function (averageSpeed, instantSpeed) {// Every bandwidth measure are in Mega BYTES per second!
  36836. // console.log('progress', averageSpeed, instantSpeed);
  36837. }).on('restart', function (dataSize) {// The restart event is triggered when the module didn't have time
  36838. // (according to the `delay` option) to take all the measures. A new
  36839. // request will start with data size increased by the multiplier value.
  36840. // console.log('restart', dataSize);
  36841. }).on('end', function (averageSpeed, allInstantSpeeds) {
  36842. // console.log('upload', averageSpeed, allInstantSpeeds);
  36843. PhoneNetwork.uploadSpeed = averageSpeed.toFixed(2);
  36844. }).start();
  36845. };
  36846. PhoneNetwork.testDownload = function (callback) {
  36847. net.upload.on('start', function (dataSize) {// console.log('start', dataSize);
  36848. }).on('progress', function (averageSpeed, instantSpeed) {// Every bandwidth measure are in Mega BYTES per second!
  36849. // console.log('progress', averageSpeed, instantSpeed);
  36850. }).on('restart', function (dataSize) {// The restart event is triggered when the module didn't have time
  36851. // (according to the `delay` option) to take all the measures. A new
  36852. // request will start with data size increased by the multiplier value.
  36853. // console.log('restart', dataSize);
  36854. }).on('end', function (averageSpeed, allInstantSpeeds) {
  36855. // console.log('download', averageSpeed, allInstantSpeeds);
  36856. PhoneNetwork.downloadSpeed = averageSpeed.toFixed(2);
  36857. }).start();
  36858. };
  36859. /** test and average time took to download image from server, called recursively timesToTest times */
  36860. function testLatency(cb) {
  36861. var testImage = PhoneNetwork.url + '/static/images/sample1.jpg';
  36862. var tStart = new Date().getTime();
  36863. if (i < timesToTest - 1) {
  36864. // dummyImage.src = testImage + '?t=' + tStart;
  36865. // dummyImage.onload = function () {
  36866. // var tEnd = new Date().getTime();
  36867. // var tTimeTook = tEnd - tStart;
  36868. // arrTimes[i] = tTimeTook;
  36869. // testLatency(cb);
  36870. // i++;
  36871. // };
  36872. $.ajax({
  36873. url: PhoneNetwork.url + '/api/latencytest',
  36874. headers: {
  36875. 'Authorization':'Bearer ' + authorizationToken,
  36876. },
  36877. type: 'GET',
  36878. data: '',
  36879. success: function (data) {
  36880. var tEnd = new Date().getTime();
  36881. var tTimeTook = tEnd - tStart;
  36882. arrTimes[i] = tTimeTook;
  36883. testLatency(cb);
  36884. i++;
  36885. },
  36886. error: function (error) {
  36887. // console.log(error);
  36888. cb(error);
  36889. }
  36890. });
  36891. } else {
  36892. /** calculate average of array items then callback */
  36893. var sum = arrTimes.reduce(function (a, b) {
  36894. return a + b;
  36895. });
  36896. var avg = sum / arrTimes.length;
  36897. cb({avg: avg});
  36898. }
  36899. }
  36900. function getBase64Image(img) {
  36901. var canvas = document.createElement("canvas");
  36902. canvas.width = img.width;
  36903. canvas.height = img.height;
  36904. var ctx = canvas.getContext("2d");
  36905. ctx.drawImage(img, 0, 0);
  36906. var dataURL = canvas.toDataURL("image/png");
  36907. return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
  36908. }
  36909. function toDataUrl(url, callback) {
  36910. var xhr = new XMLHttpRequest();
  36911. xhr.onload = function () {
  36912. var reader = new FileReader();
  36913. reader.onloadend = function () {
  36914. callback(reader.result);
  36915. };
  36916. reader.readAsDataURL(xhr.response);
  36917. };
  36918. xhr.open('GET', url);
  36919. xhr.responseType = 'blob';
  36920. xhr.send();
  36921. }
  36922. function testConnectionSpeed(callback) {
  36923. var startDownloadTime, endDownloadTime;
  36924. var startUploadTime, endUploadTime;
  36925. var download = new Image();
  36926. var imageAddr = PhoneNetwork.url + '/static/images/sample2.jpg';
  36927. $.ajax({
  36928. url: PhoneNetwork.url + '/api/speedtest',
  36929. headers: {
  36930. 'Authorization':'Bearer ' + authorizationToken,
  36931. },
  36932. // dataType: 'json',
  36933. type: 'GET',
  36934. contentType: 'text/plain',
  36935. // processData: false,
  36936. // data: myBase64,
  36937. success: function (data) {
  36938. endDownloadTime = new Date().getTime();
  36939. startUploadTime = new Date().getTime();
  36940. $.ajax({
  36941. url: PhoneNetwork.url + '/api/speedtest',
  36942. headers: {
  36943. 'Authorization':'Bearer ' + authorizationToken,
  36944. },
  36945. // dataType: 'json',
  36946. type: 'POST',
  36947. // contentType: 'text/plain',
  36948. // processData: false,
  36949. data: {data : data},
  36950. success: function (data) {
  36951. endUploadTime = (new Date()).getTime();
  36952. var result = getResult();
  36953. if (callback && typeof callback == 'function') {
  36954. callback(result);
  36955. }
  36956. },
  36957. error: function (error) {
  36958. // return error;
  36959. if (callback && typeof callback == 'function') {
  36960. callback(error);
  36961. }
  36962. // console.log('error: ' + JSON.stringify(error));
  36963. }
  36964. });
  36965. },
  36966. error: function (error) {
  36967. // return error;
  36968. if (callback && typeof callback == 'function') {
  36969. callback(error);
  36970. }
  36971. // console.log('error: ' + JSON.stringify(error));
  36972. }
  36973. });
  36974. // download.onload = function () {
  36975. // endDownloadTime = new Date().getTime();
  36976. // toDataUrl(imageAddr, function (myBase64) {
  36977. // startUploadTime = new Date().getTime();
  36978. // $.ajax({
  36979. // url: PhoneNetwork.url + '/api/speedtest',
  36980. // headers: {
  36981. // 'Authorization':'Bearer ' + authorizationToken,
  36982. // },
  36983. // // dataType: 'json',
  36984. // type: 'POST',
  36985. // contentType: 'text/plain',
  36986. // // processData: false,
  36987. // data: myBase64,
  36988. // success: function (data) {
  36989. // endUploadTime = (new Date()).getTime();
  36990. // getResult();
  36991. // if (callback && typeof callback == 'function') {
  36992. // callback();
  36993. // }
  36994. // },
  36995. // error: function (error) {
  36996. // console.log('error: ' + JSON.stringify(error));
  36997. // }
  36998. // });
  36999. // });
  37000. // };
  37001. download.onerror = function (err, msg) {
  37002. console.log("Invalid image, or error downloading");
  37003. };
  37004. startDownloadTime = new Date().getTime();
  37005. var cacheBuster = "?nnn=" + startDownloadTime;
  37006. // download.src = imageAddr + cacheBuster;
  37007. function getResult() {
  37008. var durationDownload = (endDownloadTime - startDownloadTime) / 1000;
  37009. var bitsDownLoaded = downloadSize * 8;
  37010. var speedDownloadBps = (bitsDownLoaded / durationDownload).toFixed(2);
  37011. var speedDownloadKbps = (speedDownloadBps / 1024).toFixed(2);
  37012. var speedDownloadMbps = (speedDownloadKbps / 1024).toFixed(2);
  37013. var durationUpload = (endUploadTime - startUploadTime) / 1000;
  37014. var bitsUpLoaded = uploadSize * 8;
  37015. var speedUploadBps = (bitsUpLoaded / durationUpload).toFixed(2);
  37016. var speedUploadKbps = (speedUploadBps / 1024).toFixed(2);
  37017. var speedUploadMbps = (speedUploadKbps / 1024).toFixed(2); // ShowProgressMessage([
  37018. // "Your connection speed is:",
  37019. // speedBps + " bps",
  37020. // speedKbps + " kbps",
  37021. // speedMbps + " Mbps"
  37022. // ]);
  37023. PhoneNetwork.downloadSpeed = speedDownloadMbps;
  37024. PhoneNetwork.uploadSpeed = speedUploadMbps;
  37025. // console.log(["Your Download speed is:", // speedBps + " bps",
  37026. // // speedKbps + " kbps",
  37027. // speedDownloadMbps + " Mbps"], ["Your Upload speed is:", // speedBps + " bps",
  37028. // // speedKbps + " kbps",
  37029. // speedUploadMbps + " Mbps"]);
  37030. return {
  37031. latency: PhoneNetwork.latency,
  37032. downloadSpeed: speedDownloadMbps,
  37033. uploadSpeed: speedUploadMbps
  37034. }
  37035. }
  37036. }
  37037. module.exports = PhoneNetwork;
  37038. }),
  37039. /* 62 */
  37040. (function(module, exports, __webpack_require__) {
  37041. /* WEBPACK VAR INJECTION */(function(global) {var require;var require;(function (f) {
  37042. if (true) {
  37043. module.exports = f();
  37044. } else if (typeof define === "function" && define.amd) {
  37045. define([], f);
  37046. } else {
  37047. var g;
  37048. if (typeof window !== "undefined") {
  37049. g = window;
  37050. } else if (typeof global !== "undefined") {
  37051. g = global;
  37052. } else if (typeof self !== "undefined") {
  37053. g = self;
  37054. } else {
  37055. g = this;
  37056. }
  37057. g.Network = f();
  37058. }
  37059. })(function () {
  37060. var define, module, exports;
  37061. return function e(t, n, r) {
  37062. function s(o, u) {
  37063. if (!n[o]) {
  37064. if (!t[o]) {
  37065. var a = typeof require == "function" && require;
  37066. if (!u && a) return require(o, !0);
  37067. if (i) return i(o, !0);
  37068. var f = new Error("Cannot find module '" + o + "'");
  37069. throw f.code = "MODULE_NOT_FOUND", f;
  37070. }
  37071. var l = n[o] = {
  37072. exports: {}
  37073. };
  37074. t[o][0].call(l.exports, function (e) {
  37075. var n = t[o][1][e];
  37076. return s(n ? n : e);
  37077. }, l, l.exports, e, t, n, r);
  37078. }
  37079. return n[o].exports;
  37080. }
  37081. var i = typeof require == "function" && require;
  37082. for (var o = 0; o < r.length; o++) s(r[o]);
  37083. return s;
  37084. }({
  37085. 1: [function (require, module, exports) {
  37086. 'use strict';
  37087. Object.defineProperty(exports, '__esModule', {
  37088. value: true
  37089. });
  37090. var _createDecoratedClass = function () {
  37091. function defineProperties(target, descriptors, initializers) {
  37092. for (var i = 0; i < descriptors.length; i++) {
  37093. var descriptor = descriptors[i];
  37094. var decorators = descriptor.decorators;
  37095. var key = descriptor.key;
  37096. delete descriptor.key;
  37097. delete descriptor.decorators;
  37098. descriptor.enumerable = descriptor.enumerable || false;
  37099. descriptor.configurable = true;
  37100. if ('value' in descriptor || descriptor.initializer) descriptor.writable = true;
  37101. if (decorators) {
  37102. for (var f = 0; f < decorators.length; f++) {
  37103. var decorator = decorators[f];
  37104. if (typeof decorator === 'function') {
  37105. descriptor = decorator(target, key, descriptor) || descriptor;
  37106. } else {
  37107. throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator);
  37108. }
  37109. }
  37110. if (descriptor.initializer !== undefined) {
  37111. initializers[key] = descriptor;
  37112. continue;
  37113. }
  37114. }
  37115. Object.defineProperty(target, key, descriptor);
  37116. }
  37117. }
  37118. return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) {
  37119. if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers);
  37120. if (staticProps) defineProperties(Constructor, staticProps, staticInitializers);
  37121. return Constructor;
  37122. };
  37123. }();
  37124. function _classCallCheck(instance, Constructor) {
  37125. if (!(instance instanceof Constructor)) {
  37126. throw new TypeError('Cannot call a class as a function');
  37127. }
  37128. }
  37129. function _defineDecoratedPropertyDescriptor(target, key, descriptors) {
  37130. var _descriptor = descriptors[key];
  37131. if (!_descriptor) return;
  37132. var descriptor = {};
  37133. for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
  37134. descriptor.value = descriptor.initializer.call(target);
  37135. Object.defineProperty(target, key, descriptor);
  37136. }
  37137. var _utilsDecorators = require('../utils/decorators');
  37138. /**
  37139. * A callback used as an event handler.
  37140. * @public
  37141. * @callback EventDispatcher~eventHandler
  37142. * @param {...*} args The extra parameters provided to the `trigger` method.
  37143. * @returns {?boolean} If `false` is explicitly returned, the `trigger` method will return `false`.
  37144. */
  37145. /**
  37146. * @class EventDispatcher
  37147. */
  37148. var EventDispatcher = function () {
  37149. var _instanceInitializers = {};
  37150. function EventDispatcher() {
  37151. _classCallCheck(this, EventDispatcher);
  37152. _defineDecoratedPropertyDescriptor(this, '_eventCallbacks', _instanceInitializers);
  37153. }
  37154. _createDecoratedClass(EventDispatcher, [{
  37155. key: 'on',
  37156. /**
  37157. * Attach a callback to one or more events.
  37158. * @public
  37159. * @method EventDispatcher#on
  37160. * @param {string|string[]} events One or multiple event names.
  37161. * @param {EventDispatcher~eventHandler} callback An event handler.
  37162. * @returns {EventDispatcher}
  37163. */
  37164. value: function on(events, callback) {
  37165. var _this = this;
  37166. events = Array.isArray(events) ? events : [events];
  37167. events.forEach(function (event) {
  37168. var eventCallbacks = _this._eventCallbacks[event] = _this._eventCallbacks[event] || []; // If the callback isn't already registered, store it.
  37169. if (!~eventCallbacks.indexOf(callback)) {
  37170. eventCallbacks.push(callback);
  37171. }
  37172. });
  37173. return this;
  37174. }
  37175. /**
  37176. * Detach a callback from one or more events.
  37177. * @public
  37178. * @method EventDispatcher#off
  37179. * @param {string|string[]} events One or multiple event names.
  37180. * @param {EventDispatcher~eventHandler} [callback=null] An event handler.
  37181. * @returns {EventDispatcher}
  37182. */
  37183. }, {
  37184. key: 'off',
  37185. value: function off(events) {
  37186. var _this2 = this;
  37187. var callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
  37188. events = Array.isArray(events) ? events : [events];
  37189. events.forEach(function (event) {
  37190. var eventCallbacks = _this2._eventCallbacks[event]; // If there is no specified callback, simply delete all the callbacks binded to the provided event.
  37191. if (!callback && eventCallbacks) {
  37192. delete _this2._eventCallbacks[event];
  37193. } else {
  37194. var callbackIndex = eventCallbacks ? eventCallbacks.indexOf(callback) : -1; // If the callback is registered, remove it from the array.
  37195. if (callbackIndex != -1) {
  37196. eventCallbacks.splice(callbackIndex, 1);
  37197. }
  37198. }
  37199. });
  37200. return this;
  37201. }
  37202. /**
  37203. * Trigger an event.
  37204. * @public
  37205. * @method EventDispatcher#trigger
  37206. * @param {string} event An event name.
  37207. * @param {...*} extraParameters Some extra parameters to pass to the event handlers.
  37208. * @returns {boolean} Returns `false` if one of the event handlers explicitly returned `false`.
  37209. */
  37210. }, {
  37211. key: 'trigger',
  37212. value: function trigger(event) {
  37213. for (var _len = arguments.length, extraParameters = Array(_len > 1 ? _len - 1 : 0), _key2 = 1; _key2 < _len; _key2++) {
  37214. extraParameters[_key2 - 1] = arguments[_key2];
  37215. }
  37216. var eventCallbacks = this._eventCallbacks[event] || []; // A callback can return a boolean value which will be logically compared to the other callbacks values before
  37217. // being returned by the trigger() method. This allows a callback to send a "signal" to the caller, like
  37218. // cancelling an action.
  37219. var returnValue = true;
  37220. eventCallbacks.forEach(function (eventCallback) {
  37221. // A callback must explicitly return false if it wants the trigger() method to return false, undefined will
  37222. // not work. This avoids crappy callbacks to mess up with the triggering system.
  37223. var value = eventCallback.apply(undefined, extraParameters);
  37224. value = value !== false ? true : false;
  37225. returnValue = returnValue && value; // Compare the result of the callback to the actual return value
  37226. });
  37227. return returnValue;
  37228. }
  37229. }, {
  37230. key: '_eventCallbacks',
  37231. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37232. initializer: function initializer() {
  37233. return {};
  37234. },
  37235. enumerable: true
  37236. }], null, _instanceInitializers);
  37237. return EventDispatcher;
  37238. }();
  37239. exports['default'] = EventDispatcher;
  37240. module.exports = exports['default'];
  37241. /**
  37242. * All the registered event callbacks, organized by events.
  37243. * @private
  37244. * @member {Object} EventDispatcher#_eventCallbacks
  37245. */
  37246. }, {
  37247. "../utils/decorators": 7
  37248. }],
  37249. 2: [function (require, module, exports) {
  37250. 'use strict';
  37251. Object.defineProperty(exports, '__esModule', {
  37252. value: true
  37253. });
  37254. var _createDecoratedClass = function () {
  37255. function defineProperties(target, descriptors, initializers) {
  37256. for (var i = 0; i < descriptors.length; i++) {
  37257. var descriptor = descriptors[i];
  37258. var decorators = descriptor.decorators;
  37259. var key = descriptor.key;
  37260. delete descriptor.key;
  37261. delete descriptor.decorators;
  37262. descriptor.enumerable = descriptor.enumerable || false;
  37263. descriptor.configurable = true;
  37264. if ('value' in descriptor || descriptor.initializer) descriptor.writable = true;
  37265. if (decorators) {
  37266. for (var f = 0; f < decorators.length; f++) {
  37267. var decorator = decorators[f];
  37268. if (typeof decorator === 'function') {
  37269. descriptor = decorator(target, key, descriptor) || descriptor;
  37270. } else {
  37271. throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator);
  37272. }
  37273. }
  37274. if (descriptor.initializer !== undefined) {
  37275. initializers[key] = descriptor;
  37276. continue;
  37277. }
  37278. }
  37279. Object.defineProperty(target, key, descriptor);
  37280. }
  37281. }
  37282. return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) {
  37283. if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers);
  37284. if (staticProps) defineProperties(Constructor, staticProps, staticInitializers);
  37285. return Constructor;
  37286. };
  37287. }();
  37288. var _get = function get(_x2, _x3, _x4) {
  37289. var _again = true;
  37290. _function: while (_again) {
  37291. var object = _x2,
  37292. property = _x3,
  37293. receiver = _x4;
  37294. desc = parent = getter = undefined;
  37295. _again = false;
  37296. if (object === null) object = Function.prototype;
  37297. var desc = Object.getOwnPropertyDescriptor(object, property);
  37298. if (desc === undefined) {
  37299. var parent = Object.getPrototypeOf(object);
  37300. if (parent === null) {
  37301. return undefined;
  37302. } else {
  37303. _x2 = parent;
  37304. _x3 = property;
  37305. _x4 = receiver;
  37306. _again = true;
  37307. continue _function;
  37308. }
  37309. } else if ('value' in desc) {
  37310. return desc.value;
  37311. } else {
  37312. var getter = desc.get;
  37313. if (getter === undefined) {
  37314. return undefined;
  37315. }
  37316. return getter.call(receiver);
  37317. }
  37318. }
  37319. };
  37320. function _interopRequireDefault(obj) {
  37321. return obj && obj.__esModule ? obj : {
  37322. 'default': obj
  37323. };
  37324. }
  37325. function _classCallCheck(instance, Constructor) {
  37326. if (!(instance instanceof Constructor)) {
  37327. throw new TypeError('Cannot call a class as a function');
  37328. }
  37329. }
  37330. function _inherits(subClass, superClass) {
  37331. if (typeof superClass !== 'function' && superClass !== null) {
  37332. throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
  37333. }
  37334. subClass.prototype = Object.create(superClass && superClass.prototype, {
  37335. constructor: {
  37336. value: subClass,
  37337. enumerable: false,
  37338. writable: true,
  37339. configurable: true
  37340. }
  37341. });
  37342. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  37343. }
  37344. function _defineDecoratedPropertyDescriptor(target, key, descriptors) {
  37345. var _descriptor = descriptors[key];
  37346. if (!_descriptor) return;
  37347. var descriptor = {};
  37348. for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
  37349. descriptor.value = descriptor.initializer.call(target);
  37350. Object.defineProperty(target, key, descriptor);
  37351. }
  37352. var _HttpModule2 = require('./HttpModule');
  37353. var _HttpModule3 = _interopRequireDefault(_HttpModule2);
  37354. var _Timing = require('../Timing');
  37355. var _Timing2 = _interopRequireDefault(_Timing);
  37356. var _utilsHelpers = require('../../utils/helpers');
  37357. var _utilsDecorators = require('../../utils/decorators');
  37358. /**
  37359. * @public
  37360. * @typedef {Object} BandwidthModule~settingsObject
  37361. * @extends HttpModule~settingsObject
  37362. * @property {Object} data
  37363. * @property {number} data.size The amount of data to initially use.
  37364. * @property {number} [data.multiplier=2] If the measure period can't reach the delay defined in the settings, the data amount is multiplied by the following value.
  37365. */
  37366. /**
  37367. * Apply a new set of custom settings.
  37368. * @public
  37369. * @method BandwidthModule#settings
  37370. * @param {BandwidthModule~settingsObject} settings A set of custom settings.
  37371. * @returns {BandwidthModule}
  37372. */
  37373. /**
  37374. * Return the current set of settings.
  37375. * @public
  37376. * @method BandwidthModule#settings^2
  37377. * @returns {BandwidthModule~settingsObject}
  37378. */
  37379. /**
  37380. * @class BandwidthModule
  37381. * @extends HttpModule
  37382. * @param {string} loadingType The loading type, `upload` or `download`.
  37383. * @param {BandwidthModule~settingsObject} [settings={}] A set of custom settings.
  37384. */
  37385. var BandwidthModule = function (_HttpModule) {
  37386. var _instanceInitializers = {};
  37387. var _instanceInitializers = {};
  37388. _inherits(BandwidthModule, _HttpModule);
  37389. _createDecoratedClass(BandwidthModule, [{
  37390. key: '_loadingType',
  37391. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37392. initializer: function initializer() {
  37393. return undefined;
  37394. },
  37395. /**
  37396. *
  37397. * @private
  37398. * @member {boolean} BandwidthModule#_intendedEnd
  37399. */
  37400. enumerable: true
  37401. }, {
  37402. key: '_intendedEnd',
  37403. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37404. initializer: function initializer() {
  37405. return false;
  37406. },
  37407. /**
  37408. *
  37409. * @private
  37410. * @member {boolean} BandwidthModule#_isRestarting
  37411. */
  37412. enumerable: true
  37413. }, {
  37414. key: '_isRestarting',
  37415. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37416. initializer: function initializer() {
  37417. return false;
  37418. },
  37419. /**
  37420. * Tracks the value of the `loaded` property for each progress event.
  37421. * @private
  37422. * @member {?number} BandwidthModule#_lastLoadedValue
  37423. */
  37424. enumerable: true
  37425. }, {
  37426. key: '_lastLoadedValue',
  37427. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37428. initializer: function initializer() {
  37429. return null;
  37430. },
  37431. /**
  37432. * The recorded measures of speed.
  37433. * @private
  37434. * @member {number[]} BandwidthModule#_speedRecords
  37435. */
  37436. enumerable: true
  37437. }, {
  37438. key: '_speedRecords',
  37439. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37440. initializer: function initializer() {
  37441. return [];
  37442. },
  37443. /**
  37444. * The average speed.
  37445. * @private
  37446. * @member {number} BandwidthModule#_avgSpeed
  37447. */
  37448. enumerable: true
  37449. }, {
  37450. key: '_avgSpeed',
  37451. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37452. initializer: function initializer() {
  37453. return undefined;
  37454. },
  37455. /**
  37456. * The ID of the current request.
  37457. * @private
  37458. * @member {number} BandwidthModule#_requestID
  37459. */
  37460. enumerable: true
  37461. }, {
  37462. key: '_requestID',
  37463. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37464. initializer: function initializer() {
  37465. return 0;
  37466. },
  37467. /**
  37468. * The ID of the current progress event.
  37469. * @private
  37470. * @member {number} BandwidthModule#_progressID
  37471. */
  37472. enumerable: true
  37473. }, {
  37474. key: '_progressID',
  37475. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37476. initializer: function initializer() {
  37477. return 0;
  37478. },
  37479. /**
  37480. * Defines if measures have started.
  37481. * @private
  37482. * @member {boolean} BandwidthModule#_started
  37483. */
  37484. enumerable: true
  37485. }, {
  37486. key: '_started',
  37487. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37488. initializer: function initializer() {
  37489. return false;
  37490. },
  37491. /**
  37492. * Defines if the current progress event is the first one triggered for the current request.
  37493. * @private
  37494. * @member {boolean} BandwidthModule#_firstProgress
  37495. */
  37496. enumerable: true
  37497. }, {
  37498. key: '_firstProgress',
  37499. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37500. initializer: function initializer() {
  37501. return true;
  37502. },
  37503. /**
  37504. * @private
  37505. * @member {Defer} BandwidthModule#_deferredProgress
  37506. */
  37507. enumerable: true
  37508. }, {
  37509. key: '_deferredProgress',
  37510. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37511. initializer: function initializer() {
  37512. return undefined;
  37513. },
  37514. /**
  37515. * Unique labels for each request, exclusively used to make measures.
  37516. * @private
  37517. * @member {Object} BandwidthModule#_timingLabels
  37518. * @property {?string} start
  37519. * @property {?string} progress
  37520. * @property {?string} end
  37521. * @property {?string} measure
  37522. */
  37523. enumerable: true
  37524. }, {
  37525. key: '_timingLabels',
  37526. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37527. initializer: function initializer() {
  37528. return {
  37529. start: null,
  37530. progress: null,
  37531. end: null,
  37532. measure: null
  37533. };
  37534. },
  37535. enumerable: true
  37536. }], null, _instanceInitializers);
  37537. function BandwidthModule(loadingType) {
  37538. var _this = this;
  37539. var settings = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  37540. _classCallCheck(this, BandwidthModule);
  37541. loadingType = ~['upload', 'download'].indexOf(loadingType) ? loadingType : 'download';
  37542. _get(Object.getPrototypeOf(BandwidthModule.prototype), 'constructor', this).call(this, loadingType);
  37543. _defineDecoratedPropertyDescriptor(this, '_loadingType', _instanceInitializers);
  37544. _defineDecoratedPropertyDescriptor(this, '_intendedEnd', _instanceInitializers);
  37545. _defineDecoratedPropertyDescriptor(this, '_isRestarting', _instanceInitializers);
  37546. _defineDecoratedPropertyDescriptor(this, '_lastLoadedValue', _instanceInitializers);
  37547. _defineDecoratedPropertyDescriptor(this, '_speedRecords', _instanceInitializers);
  37548. _defineDecoratedPropertyDescriptor(this, '_avgSpeed', _instanceInitializers);
  37549. _defineDecoratedPropertyDescriptor(this, '_requestID', _instanceInitializers);
  37550. _defineDecoratedPropertyDescriptor(this, '_progressID', _instanceInitializers);
  37551. _defineDecoratedPropertyDescriptor(this, '_started', _instanceInitializers);
  37552. _defineDecoratedPropertyDescriptor(this, '_firstProgress', _instanceInitializers);
  37553. _defineDecoratedPropertyDescriptor(this, '_deferredProgress', _instanceInitializers);
  37554. _defineDecoratedPropertyDescriptor(this, '_timingLabels', _instanceInitializers);
  37555. this._extendDefaultSettings({
  37556. data: {
  37557. // 2 MB for upload, 10 MB for download
  37558. size: loadingType == 'upload' ? 2 * 1024 * 1024 : 10 * 1024 * 1024,
  37559. multiplier: 2
  37560. }
  37561. }).settings(settings);
  37562. this._loadingType = loadingType; // Bind to XHR events
  37563. this.on('xhr-upload-loadstart', function () {
  37564. return _Timing2['default'].mark(_this._timingLabels.start);
  37565. });
  37566. this.on('xhr-readystatechange', function (xhr) {
  37567. if (!_this._started && xhr.readyState == XMLHttpRequest.LOADING) {
  37568. _Timing2['default'].mark(_this._timingLabels.start);
  37569. _this._started = true;
  37570. }
  37571. });
  37572. var eventsPrefix = loadingType == 'upload' ? 'xhr-upload' : 'xhr';
  37573. this.on(eventsPrefix + '-progress', function (xhr, event) {
  37574. return _this._progress(event);
  37575. });
  37576. this.on(eventsPrefix + '-timeout', function () {
  37577. return _this._timeout();
  37578. });
  37579. this.on(eventsPrefix + '-loadend', function () {
  37580. return _this._end();
  37581. });
  37582. }
  37583. /**
  37584. * Start requesting the server to make measures.
  37585. * @public
  37586. * @method BandwidthModule#start
  37587. * @returns {BandwidthModule}
  37588. */
  37589. _createDecoratedClass(BandwidthModule, [{
  37590. key: 'start',
  37591. value: function start() {
  37592. var loadingType = this._loadingType,
  37593. dataSettings = this.settings().data,
  37594. reqID = this._requestID++;
  37595. this._intendedEnd = false;
  37596. this._lastLoadedValue = null;
  37597. this._speedRecords = [];
  37598. this._started = false;
  37599. this._firstProgress = true;
  37600. this._deferredProgress = (0, _utilsHelpers.defer)(); // Trigger the start event
  37601. if (!this._isRestarting) {
  37602. this.trigger('start', dataSettings.size);
  37603. } // Create unique timing labels for the new request
  37604. var labels = this._timingLabels;
  37605. labels.start = loadingType + '-' + reqID + '-start';
  37606. labels.progress = loadingType + '-' + reqID + '-progress';
  37607. labels.end = loadingType + '-' + reqID + '-end';
  37608. labels.measure = loadingType + '-' + reqID + '-measure'; // Generate some random data to upload to the server. Here we're using a Blob instead of an ArrayBuffer because
  37609. // of a bug in Chrome (tested in v33.0.1750.146), causing a freeze of the page while trying to directly upload
  37610. // an ArrayBuffer (through an ArrayBufferView). The freeze lasts nearly 4.5s for 10MB of data. Using a Blob
  37611. // seems to solve the problem.
  37612. var blob = loadingType == 'upload' ? new Blob([new ArrayBuffer(dataSettings.size)]) : null;
  37613. var type = loadingType == 'download' ? 'GET' : 'POST'; // Initiate and send a new request
  37614. this._newRequest(type, {
  37615. size: dataSettings.size
  37616. })._sendRequest(blob);
  37617. return this;
  37618. }
  37619. /**
  37620. * Abort the measures.
  37621. * @public
  37622. * @method BandwidthModule#abort
  37623. * @returns {BandwidthModule}
  37624. */
  37625. }, {
  37626. key: 'abort',
  37627. value: function abort() {
  37628. this._intendedEnd = true;
  37629. return this._abort();
  37630. }
  37631. /**
  37632. * Make bandwidth measures for the current request.
  37633. * @private
  37634. * @method BandwidthModule#_progress
  37635. * @param {ProgressEvent} event The event associated with the progress event of the current request.
  37636. * @returns {BandwidthModule}
  37637. */
  37638. }, {
  37639. key: '_progress',
  37640. value: function _progress(event) {
  37641. var _this2 = this; // Ignore the first progress event, it generally contributes to get incoherent values.
  37642. if (this._firstProgress) return this._firstProgress = false; // Execute the previous progress trigger
  37643. this._deferredProgress.run();
  37644. var labels = this._timingLabels,
  37645. progressID = this._progressID++,
  37646. markLabel = labels.progress + '-' + progressID,
  37647. loaded = event.loaded;
  37648. _Timing2['default'].mark(markLabel); // Measure the average speed (B/s) since the request started
  37649. var avgMeasure = _Timing2['default'].measure(labels.measure + '-avg-' + progressID, labels.start, markLabel),
  37650. avgSpeed = loaded / avgMeasure * 1000;
  37651. var instantSpeed;
  37652. if (this._lastLoadedValue === null) {
  37653. // We are executing the first progress event of the current request
  37654. instantSpeed = avgSpeed; // The instant speed of the first progress event is equal to the average one
  37655. } else {
  37656. // Measure the instant speed (B/s), which defines the speed between two progress events.
  37657. var instantMeasure = _Timing2['default'].measure(labels.measure + '-instant-' + progressID, // Set the mark of the previous progress event as the starting point
  37658. labels.progress + '-' + (progressID - 1), markLabel);
  37659. instantSpeed = (loaded - this._lastLoadedValue) / instantMeasure * 1000;
  37660. } // Save the `loaded` property of the event for the next progress event
  37661. this._lastLoadedValue = loaded; // Defer measures saving and event triggering, this allows to cancel the last progress event, which can generate
  37662. // incoherent values.
  37663. this._deferredProgress = (0, _utilsHelpers.defer)(function () {
  37664. _this2._avgSpeed = avgSpeed;
  37665. _this2._speedRecords.push(instantSpeed);
  37666. _this2.trigger('progress', avgSpeed, instantSpeed);
  37667. });
  37668. return this;
  37669. }
  37670. /**
  37671. * Mark the current request as entirely finished (this means it ended after a time out).
  37672. * @private
  37673. * @method BandwidthModule#_timeout
  37674. * @returns {BandwidthModule}
  37675. */
  37676. }, {
  37677. key: '_timeout',
  37678. value: function _timeout() {
  37679. this._intendedEnd = true;
  37680. return this;
  37681. }
  37682. /**
  37683. * End the measures.
  37684. * @private
  37685. * @method BandwidthModule#_end
  37686. * @returns {BandwidthModule}
  37687. */
  37688. }, {
  37689. key: '_end',
  37690. value: function _end() {
  37691. // A timeout or an abort occured, bypass the further requests and trigger the "end" event.
  37692. if (this._intendedEnd) {
  37693. this._isRestarting = false;
  37694. this.trigger('end', this._avgSpeed, this._speedRecords);
  37695. } // The request ended to early, restart it with an increased data size.
  37696. else {
  37697. var dataSettings = this.settings().data,
  37698. size = dataSettings.size * dataSettings.multiplier;
  37699. this.settings({
  37700. data: {
  37701. size: size
  37702. }
  37703. });
  37704. this.trigger('restart', size);
  37705. this._isRestarting = true;
  37706. this.start();
  37707. }
  37708. return this;
  37709. }
  37710. }], null, _instanceInitializers);
  37711. return BandwidthModule;
  37712. }(_HttpModule3['default']);
  37713. exports['default'] = BandwidthModule;
  37714. module.exports = exports['default'];
  37715. /**
  37716. *
  37717. * @private
  37718. * @member {string} BandwidthModule#_loadingType
  37719. */
  37720. }, {
  37721. "../../utils/decorators": 7,
  37722. "../../utils/helpers": 8,
  37723. "../Timing": 6,
  37724. "./HttpModule": 3
  37725. }],
  37726. 3: [function (require, module, exports) {
  37727. 'use strict';
  37728. Object.defineProperty(exports, '__esModule', {
  37729. value: true
  37730. });
  37731. var _createDecoratedClass = function () {
  37732. function defineProperties(target, descriptors, initializers) {
  37733. for (var i = 0; i < descriptors.length; i++) {
  37734. var descriptor = descriptors[i];
  37735. var decorators = descriptor.decorators;
  37736. var key = descriptor.key;
  37737. delete descriptor.key;
  37738. delete descriptor.decorators;
  37739. descriptor.enumerable = descriptor.enumerable || false;
  37740. descriptor.configurable = true;
  37741. if ('value' in descriptor || descriptor.initializer) descriptor.writable = true;
  37742. if (decorators) {
  37743. for (var f = 0; f < decorators.length; f++) {
  37744. var decorator = decorators[f];
  37745. if (typeof decorator === 'function') {
  37746. descriptor = decorator(target, key, descriptor) || descriptor;
  37747. } else {
  37748. throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator);
  37749. }
  37750. }
  37751. if (descriptor.initializer !== undefined) {
  37752. initializers[key] = descriptor;
  37753. continue;
  37754. }
  37755. }
  37756. Object.defineProperty(target, key, descriptor);
  37757. }
  37758. }
  37759. return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) {
  37760. if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers);
  37761. if (staticProps) defineProperties(Constructor, staticProps, staticInitializers);
  37762. return Constructor;
  37763. };
  37764. }();
  37765. var _get = function get(_x4, _x5, _x6) {
  37766. var _again = true;
  37767. _function: while (_again) {
  37768. var object = _x4,
  37769. property = _x5,
  37770. receiver = _x6;
  37771. desc = parent = getter = undefined;
  37772. _again = false;
  37773. if (object === null) object = Function.prototype;
  37774. var desc = Object.getOwnPropertyDescriptor(object, property);
  37775. if (desc === undefined) {
  37776. var parent = Object.getPrototypeOf(object);
  37777. if (parent === null) {
  37778. return undefined;
  37779. } else {
  37780. _x4 = parent;
  37781. _x5 = property;
  37782. _x6 = receiver;
  37783. _again = true;
  37784. continue _function;
  37785. }
  37786. } else if ('value' in desc) {
  37787. return desc.value;
  37788. } else {
  37789. var getter = desc.get;
  37790. if (getter === undefined) {
  37791. return undefined;
  37792. }
  37793. return getter.call(receiver);
  37794. }
  37795. }
  37796. };
  37797. function _interopRequireDefault(obj) {
  37798. return obj && obj.__esModule ? obj : {
  37799. 'default': obj
  37800. };
  37801. }
  37802. function _classCallCheck(instance, Constructor) {
  37803. if (!(instance instanceof Constructor)) {
  37804. throw new TypeError('Cannot call a class as a function');
  37805. }
  37806. }
  37807. function _inherits(subClass, superClass) {
  37808. if (typeof superClass !== 'function' && superClass !== null) {
  37809. throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
  37810. }
  37811. subClass.prototype = Object.create(superClass && superClass.prototype, {
  37812. constructor: {
  37813. value: subClass,
  37814. enumerable: false,
  37815. writable: true,
  37816. configurable: true
  37817. }
  37818. });
  37819. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  37820. }
  37821. function _defineDecoratedPropertyDescriptor(target, key, descriptors) {
  37822. var _descriptor = descriptors[key];
  37823. if (!_descriptor) return;
  37824. var descriptor = {};
  37825. for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
  37826. descriptor.value = descriptor.initializer.call(target);
  37827. Object.defineProperty(target, key, descriptor);
  37828. }
  37829. var _EventDispatcher2 = require('../EventDispatcher');
  37830. var _EventDispatcher3 = _interopRequireDefault(_EventDispatcher2);
  37831. var _utilsHelpers = require('../../utils/helpers');
  37832. var _utilsDecorators = require('../../utils/decorators');
  37833. /**
  37834. * @public
  37835. * @typedef {Object} HttpModule~settingsObject
  37836. * @property {string} [endpoint=./network.php] Where is located your `network.php` file.
  37837. * @property {number} [delay=8000] The delay while you want to take measures.
  37838. */
  37839. /**
  37840. * @class HttpModule
  37841. * @extends EventDispatcher
  37842. * @param {string} moduleName The name of the instanciated module.
  37843. * @param {HttpModule~settingsObject} [settings={}] A set of custom settings.
  37844. */
  37845. var HttpModule = function (_EventDispatcher) {
  37846. var _instanceInitializers = {};
  37847. var _instanceInitializers = {};
  37848. _inherits(HttpModule, _EventDispatcher);
  37849. _createDecoratedClass(HttpModule, [{
  37850. key: '_defaultSettings',
  37851. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37852. initializer: function initializer() {
  37853. return null;
  37854. },
  37855. /**
  37856. * The current settings.
  37857. * @private
  37858. * @member {?Object} HttpModule#_settings
  37859. */
  37860. enumerable: true
  37861. }, {
  37862. key: '_settings',
  37863. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37864. initializer: function initializer() {
  37865. return null;
  37866. },
  37867. /**
  37868. * The module name, will be send to the server.
  37869. * @private
  37870. * @member {string} HttpModule#_moduleName
  37871. */
  37872. enumerable: true
  37873. }, {
  37874. key: '_moduleName',
  37875. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37876. initializer: function initializer() {
  37877. return undefined;
  37878. },
  37879. /**
  37880. * The current XMLHttpRequest object.
  37881. * @private
  37882. * @member {?XMLHttpRequest} HttpModule#_xhr
  37883. */
  37884. enumerable: true
  37885. }, {
  37886. key: '_xhr',
  37887. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37888. initializer: function initializer() {
  37889. return null;
  37890. },
  37891. /**
  37892. * An URL token to avoid any caching issues. Also allows to identify the request in the Resource Timing entries.
  37893. * @private
  37894. * @member {?string} HttpModule#_lastURLToken
  37895. */
  37896. enumerable: true
  37897. }, {
  37898. key: '_lastURLToken',
  37899. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37900. initializer: function initializer() {
  37901. return null;
  37902. },
  37903. /**
  37904. * Defines if the module is currently running an HTTP request.
  37905. * @private
  37906. * @member {boolean} HttpModule#_requesting
  37907. */
  37908. enumerable: true
  37909. }, {
  37910. key: '_requesting',
  37911. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37912. initializer: function initializer() {
  37913. return false;
  37914. },
  37915. /**
  37916. * Defines if the requesting status has been overridden by the `_setRequesting` method.
  37917. * @private
  37918. * @member {boolean} HttpModule#_requestingOverridden
  37919. */
  37920. enumerable: true
  37921. }, {
  37922. key: '_requestingOverridden',
  37923. decorators: [(0, _utilsDecorators.enumerable)(false)],
  37924. initializer: function initializer() {
  37925. return false;
  37926. },
  37927. enumerable: true
  37928. }], null, _instanceInitializers);
  37929. function HttpModule(moduleName) {
  37930. var _this = this;
  37931. var settings = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  37932. _classCallCheck(this, HttpModule);
  37933. _get(Object.getPrototypeOf(HttpModule.prototype), 'constructor', this).call(this);
  37934. _defineDecoratedPropertyDescriptor(this, '_defaultSettings', _instanceInitializers);
  37935. _defineDecoratedPropertyDescriptor(this, '_settings', _instanceInitializers);
  37936. _defineDecoratedPropertyDescriptor(this, '_moduleName', _instanceInitializers);
  37937. _defineDecoratedPropertyDescriptor(this, '_xhr', _instanceInitializers);
  37938. _defineDecoratedPropertyDescriptor(this, '_lastURLToken', _instanceInitializers);
  37939. _defineDecoratedPropertyDescriptor(this, '_requesting', _instanceInitializers);
  37940. _defineDecoratedPropertyDescriptor(this, '_requestingOverridden', _instanceInitializers);
  37941. this._extendDefaultSettings({
  37942. endpoint: './network.php',
  37943. delay: 8000
  37944. });
  37945. this.settings(settings);
  37946. this._moduleName = moduleName; // Each time a request starts or ends, set the requesting value unless it has been overridden with the
  37947. // _setRequesting() method.
  37948. this.on(['xhr-loadstart', 'xhr-upload-loadstart'], function () {
  37949. if (!_this._requestingOverridden) {
  37950. _this._requesting = true;
  37951. }
  37952. });
  37953. this.on(['xhr-loadend', 'xhr-upload-loadend'], function () {
  37954. if (!_this._requestingOverridden) {
  37955. _this._requesting = false;
  37956. }
  37957. });
  37958. }
  37959. /**
  37960. * Apply a new set of custom settings.
  37961. * @public
  37962. * @method HttpModule#settings
  37963. * @param {HttpModule~settingsObject} settings A set of custom settings.
  37964. * @returns {HttpModule}
  37965. */
  37966. /**
  37967. * Return the current set of settings.
  37968. * @public
  37969. * @method HttpModule#settings^2
  37970. * @returns {HttpModule~settingsObject}
  37971. */
  37972. _createDecoratedClass(HttpModule, [{
  37973. key: 'settings',
  37974. value: function settings() {
  37975. var _settings = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
  37976. if ((0, _utilsHelpers.isObject)(_settings)) {
  37977. this._settings = (0, _utilsHelpers.assignStrict)(this._defaultSettings || {}, this._settings || {}, _settings);
  37978. return this;
  37979. } else {
  37980. return (0, _utilsHelpers.copy)(this._settings || this._defaultSettings || {});
  37981. }
  37982. }
  37983. /**
  37984. * Return if the module is currently making a request.
  37985. * @public
  37986. * @method HttpModule#isRequesting
  37987. * @returns {boolean} `true` if the module is requesting, otherwise `false`.
  37988. */
  37989. }, {
  37990. key: 'isRequesting',
  37991. value: function isRequesting() {
  37992. return this._requesting;
  37993. }
  37994. /**
  37995. * Extend the set of default settings.
  37996. * @protected
  37997. * @method HttpModule#_extendDefaultSettings
  37998. * @param {Object} settings The new properties to add to the default settings.
  37999. * @returns {HttpModule}
  38000. */
  38001. }, {
  38002. key: '_extendDefaultSettings',
  38003. value: function _extendDefaultSettings(settings) {
  38004. this._defaultSettings = (0, _utilsHelpers.assign)(this._defaultSettings || {}, settings);
  38005. return this;
  38006. }
  38007. /**
  38008. * Create a new XHR request.
  38009. * @protected
  38010. * @method HttpModule#_newRequest
  38011. * @param {string} httpMethod The HTTP method to use with the request, GET or POST.
  38012. * @param {Object} queryParams The query parameters to use with the request.
  38013. * @returns {HttpModule}
  38014. */
  38015. }, {
  38016. key: '_newRequest',
  38017. value: function _newRequest(httpMethod, queryParams) {
  38018. var _this2 = this; // Check if a callback binded to the "_newRequest" event returns false, if it's the case, cancel the request
  38019. // creation. If the requesting status has been overridden, there's no need to cancel the request since the user
  38020. // should know what he's doing.
  38021. if (!this.trigger('_newRequest') && !this._requestingOverridden) {
  38022. console.warn('To ensure accurate measures, you can only make one request at a time.');
  38023. return this;
  38024. }
  38025. var settings = this.settings(),
  38026. xhr = new XMLHttpRequest(),
  38027. validHttpMethods = ['GET', 'POST']; // Prepare the new request.
  38028. if (!~validHttpMethods.indexOf(httpMethod)) {
  38029. console.warn('The HTTP method must be GET or POST.');
  38030. return this;
  38031. }
  38032. queryParams = queryParams || {};
  38033. var tokenSuffix = new Date().getTime();
  38034. this._lastURLToken = 'network-' + tokenSuffix; // Append the query parameters
  38035. var url = settings.endpoint;
  38036. url += ~url.indexOf('?') ? '&' : '?';
  38037. url += 'module=' + this._moduleName;
  38038. Object.keys(queryParams).forEach(function (param) {
  38039. var value = encodeURIComponent(queryParams[param]);
  38040. url += '&' + param + '=' + value;
  38041. });
  38042. url += '&' + this._lastURLToken;
  38043. xhr.open(httpMethod, url); // Abort the previous request if it hasn't been sent
  38044. if (this._xhr && this._xhr.readyState == XMLHttpRequest.OPENED) {
  38045. this._xhr.abort();
  38046. } // Replace the old request by the new one
  38047. this._xhr = xhr; // Bind all the XHR events
  38048. var events = ['loadstart', 'progress', 'abort', 'error', 'load', 'timeout', 'loadend', 'readystatechange'];
  38049. events.forEach(function (eventType) {
  38050. xhr.addEventListener(eventType, function () {
  38051. for (var _len = arguments.length, args = Array(_len), _key2 = 0; _key2 < _len; _key2++) {
  38052. args[_key2] = arguments[_key2];
  38053. } // A last progress event can be triggered once a request has timed out, ignore it.
  38054. if (eventType == 'progress' && !_this2._requesting) return;
  38055. _this2.trigger.apply(_this2, ['xhr-' + eventType, xhr].concat(args));
  38056. }); // The XMLHttpRequestUpload interface supports all the above event types except the "readystatechange" one
  38057. if (eventType != 'readystatechange') {
  38058. xhr.upload.addEventListener(eventType, function () {
  38059. for (var _len2 = arguments.length, args = Array(_len2), _key3 = 0; _key3 < _len2; _key3++) {
  38060. args[_key3] = arguments[_key3];
  38061. }
  38062. _this2.trigger.apply(_this2, ['xhr-upload-' + eventType, xhr].concat(args));
  38063. });
  38064. }
  38065. }); // Define the timeout of the request. We don't use the native `timeout` property since it can distort the
  38066. // measures.
  38067. // See: https://github.com/nesk/network.js/issues/26
  38068. var startTimeout = function startTimeout(xhr) {
  38069. setTimeout(function () {
  38070. if (xhr.readyState != XMLHttpRequest.UNSENT && xhr.readyState != XMLHttpRequest.DONE) {
  38071. _this2.trigger('xhr-timeout');
  38072. _this2.trigger('xhr-upload-timeout');
  38073. xhr.abort();
  38074. }
  38075. }, settings.delay);
  38076. };
  38077. this.on('xhr-upload-loadstart', startTimeout).on('xhr-readystatechange', function (timeoutStarted) {
  38078. return function (xhr) {
  38079. if (!timeoutStarted && xhr.readyState == XMLHttpRequest.LOADING) {
  38080. timeoutStarted = true;
  38081. startTimeout(xhr);
  38082. }
  38083. };
  38084. }(false));
  38085. return this;
  38086. }
  38087. /**
  38088. * Send a newly created XHR request.
  38089. * @protected
  38090. * @method HttpModule#_sendRequest
  38091. * @param {?*} [data=null] The data to send with the request.
  38092. * @returns {HttpModule}
  38093. */
  38094. }, {
  38095. key: '_sendRequest',
  38096. value: function _sendRequest() {
  38097. var data = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
  38098. if (this._xhr && this._xhr.readyState == XMLHttpRequest.OPENED) {
  38099. this._xhr.send(data);
  38100. } else {
  38101. console.warn('A request must have been created before sending any data.');
  38102. }
  38103. return this;
  38104. }
  38105. /**
  38106. * Abort the current request.
  38107. * @protected
  38108. * @method HttpModule#_abort
  38109. * @returns {HttpModule}
  38110. */
  38111. }, {
  38112. key: '_abort',
  38113. value: function _abort() {
  38114. if (this._xhr) {
  38115. this._xhr.abort();
  38116. }
  38117. return this;
  38118. }
  38119. /**
  38120. * Get the Resource Timing entry associated to the current request.
  38121. * @protected
  38122. * @method HttpModule#_getTimingEntry
  38123. * @param {HttpModule~timingCallback} callback A callback used to send back the timing entry.
  38124. * @returns {HttpModule}
  38125. */
  38126. }, {
  38127. key: '_getTimingEntry',
  38128. value: function _getTimingEntry(callback) {
  38129. // The Resource Timing entries aren't immediately available once the 'load' event is triggered by an
  38130. // XMLHttpRequest, we must wait for another process tick to check for a refreshed list.
  38131. setTimeout(function (lastURLToken) {
  38132. return function () {
  38133. // Filter the timing entries to return only the one concerned by the last request made
  38134. var entries = performance.getEntriesByType('resource').filter(function (entry) {
  38135. return ~entry.name.indexOf(lastURLToken);
  38136. });
  38137. /**
  38138. * A callback used to send back the timing entry.
  38139. * @private
  38140. * @callback HttpModule~timingCallback
  38141. * @param {PerformanceResourceTiming} entry The Resource Timing entry associated to the current request.
  38142. */
  38143. callback(entries.length ? entries[0] : null);
  38144. };
  38145. }(this._lastURLToken), 0);
  38146. return this;
  38147. }
  38148. /**
  38149. * Override the requesting status of the module.
  38150. * @protected
  38151. * @method HttpModule#_setRequesting
  38152. * @param {boolean} isRequesting The requesting status.
  38153. * @returns {HttpModule}
  38154. */
  38155. }, {
  38156. key: '_setRequesting',
  38157. value: function _setRequesting(isRequesting) {
  38158. this._requestingOverridden = true;
  38159. this._requesting = isRequesting;
  38160. return this;
  38161. }
  38162. }], null, _instanceInitializers);
  38163. return HttpModule;
  38164. }(_EventDispatcher3['default']);
  38165. exports['default'] = HttpModule;
  38166. module.exports = exports['default'];
  38167. /**
  38168. * The default settings.
  38169. * @private
  38170. * @member {?Object} HttpModule#_defaultSettings
  38171. */
  38172. }, {
  38173. "../../utils/decorators": 7,
  38174. "../../utils/helpers": 8,
  38175. "../EventDispatcher": 1
  38176. }],
  38177. 4: [function (require, module, exports) {
  38178. 'use strict';
  38179. Object.defineProperty(exports, '__esModule', {
  38180. value: true
  38181. });
  38182. var _createDecoratedClass = function () {
  38183. function defineProperties(target, descriptors, initializers) {
  38184. for (var i = 0; i < descriptors.length; i++) {
  38185. var descriptor = descriptors[i];
  38186. var decorators = descriptor.decorators;
  38187. var key = descriptor.key;
  38188. delete descriptor.key;
  38189. delete descriptor.decorators;
  38190. descriptor.enumerable = descriptor.enumerable || false;
  38191. descriptor.configurable = true;
  38192. if ('value' in descriptor || descriptor.initializer) descriptor.writable = true;
  38193. if (decorators) {
  38194. for (var f = 0; f < decorators.length; f++) {
  38195. var decorator = decorators[f];
  38196. if (typeof decorator === 'function') {
  38197. descriptor = decorator(target, key, descriptor) || descriptor;
  38198. } else {
  38199. throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator);
  38200. }
  38201. }
  38202. if (descriptor.initializer !== undefined) {
  38203. initializers[key] = descriptor;
  38204. continue;
  38205. }
  38206. }
  38207. Object.defineProperty(target, key, descriptor);
  38208. }
  38209. }
  38210. return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) {
  38211. if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers);
  38212. if (staticProps) defineProperties(Constructor, staticProps, staticInitializers);
  38213. return Constructor;
  38214. };
  38215. }();
  38216. var _get = function get(_x5, _x6, _x7) {
  38217. var _again = true;
  38218. _function: while (_again) {
  38219. var object = _x5,
  38220. property = _x6,
  38221. receiver = _x7;
  38222. desc = parent = getter = undefined;
  38223. _again = false;
  38224. if (object === null) object = Function.prototype;
  38225. var desc = Object.getOwnPropertyDescriptor(object, property);
  38226. if (desc === undefined) {
  38227. var parent = Object.getPrototypeOf(object);
  38228. if (parent === null) {
  38229. return undefined;
  38230. } else {
  38231. _x5 = parent;
  38232. _x6 = property;
  38233. _x7 = receiver;
  38234. _again = true;
  38235. continue _function;
  38236. }
  38237. } else if ('value' in desc) {
  38238. return desc.value;
  38239. } else {
  38240. var getter = desc.get;
  38241. if (getter === undefined) {
  38242. return undefined;
  38243. }
  38244. return getter.call(receiver);
  38245. }
  38246. }
  38247. };
  38248. function _interopRequireDefault(obj) {
  38249. return obj && obj.__esModule ? obj : {
  38250. 'default': obj
  38251. };
  38252. }
  38253. function _classCallCheck(instance, Constructor) {
  38254. if (!(instance instanceof Constructor)) {
  38255. throw new TypeError('Cannot call a class as a function');
  38256. }
  38257. }
  38258. function _inherits(subClass, superClass) {
  38259. if (typeof superClass !== 'function' && superClass !== null) {
  38260. throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
  38261. }
  38262. subClass.prototype = Object.create(superClass && superClass.prototype, {
  38263. constructor: {
  38264. value: subClass,
  38265. enumerable: false,
  38266. writable: true,
  38267. configurable: true
  38268. }
  38269. });
  38270. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  38271. }
  38272. function _defineDecoratedPropertyDescriptor(target, key, descriptors) {
  38273. var _descriptor = descriptors[key];
  38274. if (!_descriptor) return;
  38275. var descriptor = {};
  38276. for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
  38277. descriptor.value = descriptor.initializer.call(target);
  38278. Object.defineProperty(target, key, descriptor);
  38279. }
  38280. var _HttpModule2 = require('./HttpModule');
  38281. var _HttpModule3 = _interopRequireDefault(_HttpModule2);
  38282. var _Timing = require('../Timing');
  38283. var _Timing2 = _interopRequireDefault(_Timing);
  38284. var _utilsHelpers = require('../../utils/helpers');
  38285. var _utilsDecorators = require('../../utils/decorators');
  38286. /**
  38287. * @public
  38288. * @typedef {Object} LatencyModule~settingsObject
  38289. * @property {string} [endpoint=./network.php] Where is located your `network.php` file.
  38290. * @property {number} [measures=5] How many measures should be returned.
  38291. * @property {number} [attempts=3] How much attempts to get a valid value should be done for each measure.
  38292. */
  38293. /**
  38294. * @class LatencyModule
  38295. * @extends HttpModule
  38296. * @param {LatencyModule~settingsObject} [settings={}] A set of custom settings.
  38297. */
  38298. var LatencyModule = function (_HttpModule) {
  38299. var _instanceInitializers = {};
  38300. var _instanceInitializers = {};
  38301. _inherits(LatencyModule, _HttpModule);
  38302. _createDecoratedClass(LatencyModule, [{
  38303. key: '_supportsResourceTiming',
  38304. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38305. initializer: function initializer() {
  38306. return undefined;
  38307. },
  38308. /**
  38309. * The total number of requests left.
  38310. * @private
  38311. * @member {number} LatencyModule#_requestsLeft
  38312. */
  38313. enumerable: true
  38314. }, {
  38315. key: '_requestsLeft',
  38316. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38317. initializer: function initializer() {
  38318. return undefined;
  38319. },
  38320. /**
  38321. * The total number of attempts left.
  38322. * @private
  38323. * @member {number} LatencyModule#_attemptsLeft
  38324. */
  38325. enumerable: true
  38326. }, {
  38327. key: '_attemptsLeft',
  38328. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38329. initializer: function initializer() {
  38330. return undefined;
  38331. },
  38332. /**
  38333. * The measured latencies.
  38334. * @private
  38335. * @member {number[]} LatencyModule#_latencies
  38336. */
  38337. enumerable: true
  38338. }, {
  38339. key: '_latencies',
  38340. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38341. initializer: function initializer() {
  38342. return undefined;
  38343. },
  38344. /**
  38345. * The ID of the current request.
  38346. * @private
  38347. * @member {number} LatencyModule#_requestID
  38348. */
  38349. enumerable: true
  38350. }, {
  38351. key: '_requestID',
  38352. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38353. initializer: function initializer() {
  38354. return 0;
  38355. },
  38356. /**
  38357. * Unique labels for each request, exclusively used to make measures.
  38358. * @private
  38359. * @member {Object} LatencyModule#_requestID
  38360. * @property {?string} start
  38361. * @property {?string} end
  38362. * @property {?string} measure
  38363. */
  38364. enumerable: true
  38365. }, {
  38366. key: '_timingLabels',
  38367. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38368. initializer: function initializer() {
  38369. return {
  38370. start: null,
  38371. end: null,
  38372. measure: null
  38373. };
  38374. },
  38375. enumerable: true
  38376. }], null, _instanceInitializers);
  38377. function LatencyModule() {
  38378. var settings = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  38379. _classCallCheck(this, LatencyModule);
  38380. _get(Object.getPrototypeOf(LatencyModule.prototype), 'constructor', this).call(this, 'latency');
  38381. _defineDecoratedPropertyDescriptor(this, '_supportsResourceTiming', _instanceInitializers);
  38382. _defineDecoratedPropertyDescriptor(this, '_requestsLeft', _instanceInitializers);
  38383. _defineDecoratedPropertyDescriptor(this, '_attemptsLeft', _instanceInitializers);
  38384. _defineDecoratedPropertyDescriptor(this, '_latencies', _instanceInitializers);
  38385. _defineDecoratedPropertyDescriptor(this, '_requestID', _instanceInitializers);
  38386. _defineDecoratedPropertyDescriptor(this, '_timingLabels', _instanceInitializers);
  38387. this._extendDefaultSettings({
  38388. measures: 5,
  38389. attempts: 3
  38390. }).settings(settings);
  38391. this._defineResourceTimingSupport();
  38392. }
  38393. /**
  38394. * Apply a new set of custom settings.
  38395. * @public
  38396. * @method LatencyModule#settings
  38397. * @param {LatencyModule~settingsObject} settings A set of custom settings.
  38398. * @returns {LatencyModule}
  38399. */
  38400. /**
  38401. * Return the current set of settings.
  38402. * @public
  38403. * @method LatencyModule#settings^2
  38404. * @returns {LatencyModule~settingsObject}
  38405. */
  38406. _createDecoratedClass(LatencyModule, [{
  38407. key: 'settings',
  38408. value: function settings() {
  38409. var _settings = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
  38410. if ((0, _utilsHelpers.isObject)(_settings)) {
  38411. return _get(Object.getPrototypeOf(LatencyModule.prototype), 'settings', this).call(this, (0, _utilsHelpers.assignStrict)(_settings, {
  38412. delay: 0 // We dont want any timeout during a latency calculation
  38413. }));
  38414. } else {
  38415. return (0, _utilsHelpers.except)(_get(Object.getPrototypeOf(LatencyModule.prototype), 'settings', this).call(this), ['delay']);
  38416. }
  38417. }
  38418. /**
  38419. * Start requesting the server to make measures.
  38420. * @public
  38421. * @method LatencyModule#start
  38422. * @returns {LatencyModule}
  38423. */
  38424. }, {
  38425. key: 'start',
  38426. value: function start() {
  38427. var _settings2 = this.settings(); // Set the number of requests required to establish the network latency.
  38428. var measures = _settings2.measures;
  38429. var attempts = _settings2.attempts;
  38430. this._requestsLeft = measures;
  38431. this._attemptsLeft = attempts * measures; // If the browser doesn't support the Resource Timing API, add a request that will be ignored to avoid a longer
  38432. // request due to a possible DNS/whatever fetch.
  38433. if (!this._supportsResourceTiming) {
  38434. this._requestsLeft++;
  38435. this._attemptsLeft++;
  38436. } // Override the requesting value since a complete latency request consists off multiple ones
  38437. this._setRequesting(true);
  38438. this._latencies = [];
  38439. this._nextRequest();
  38440. return this;
  38441. }
  38442. /**
  38443. * Define if the module should support the Resource Timing API.
  38444. * @private
  38445. * @method LatencyModule#_defineResourceTimingSupport
  38446. * @param {boolean} supportsResourceTiming If `undefined`, the support will be determined by feature detection.
  38447. * @returns {LatencyModule}
  38448. */
  38449. }, {
  38450. key: '_defineResourceTimingSupport',
  38451. value: function _defineResourceTimingSupport(supportsResourceTiming) {
  38452. var _this = this;
  38453. if (typeof supportsResourceTiming !== 'boolean') supportsResourceTiming = _Timing2['default'].supportsResourceTiming;
  38454. this._supportsResourceTiming = supportsResourceTiming; // Unregisters all the previously registered events, since this method can be called multiple times.
  38455. this.off(['xhr-load', 'xhr-loadstart', 'xhr-readystatechange']); // Measure the latency with the Resource Timing API once the request is finished
  38456. if (supportsResourceTiming) {
  38457. this.on('xhr-load', function () {
  38458. return _this._measure();
  38459. });
  38460. } // If the browser doesn't support the Resource Timing API, we fallback on a Datetime solution.
  38461. else {
  38462. // Set a mark when the request starts
  38463. this.on('xhr-loadstart', function () {
  38464. return _Timing2['default'].mark(_this._timingLabels.start);
  38465. }); // Then make a measure with the previous mark
  38466. this.on('xhr-readystatechange', function (xhr) {
  38467. return _this._measure(xhr);
  38468. });
  38469. }
  38470. }
  38471. /**
  38472. * Initiate the next request used for latency measures.
  38473. * @private
  38474. * @method LatencyModule#_nextRequest
  38475. * @param {boolean} [retry=false] Defines if the next request is a retry due to a failing request or not.
  38476. * @returns {LatencyModule}
  38477. */
  38478. }, {
  38479. key: '_nextRequest',
  38480. value: function _nextRequest() {
  38481. var _this2 = this;
  38482. var retry = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
  38483. var reqID = this._requestID++;
  38484. var requestsLeft = retry ? this._requestsLeft : this._requestsLeft--;
  38485. if (this._attemptsLeft-- && (requestsLeft || retry)) {
  38486. // Create unique timing labels for the new request
  38487. var labels = this._timingLabels;
  38488. labels.start = 'latency-' + reqID + '-start';
  38489. labels.end = 'latency-' + reqID + '-end';
  38490. labels.measure = 'latency-' + reqID + '-measure'; // Create the new request and send it
  38491. this._newRequest('GET')._sendRequest();
  38492. } else {
  38493. // All the requests are finished, set the requesting status to false.
  38494. this._setRequesting(false); // If all the requests have been executed, calculate the average latency. Since the _getTimingEntry() method
  38495. // is asynchronous, wait for the next process tick to execute the _end() method, to be sure that all the
  38496. // latencies have been retrieved.
  38497. setTimeout(function () {
  38498. return _this2._end();
  38499. }, 0);
  38500. }
  38501. return this;
  38502. }
  38503. /**
  38504. * Make latency measures for the last request.
  38505. * @private
  38506. * @method LatencyModule#_measure
  38507. * @param {?XMLHttpRequest} [xhr=null] The concerned XMLHttpRequest if the browser doesn't support the Resource Timing API.
  38508. * @returns {LatencyModule}
  38509. */
  38510. }, {
  38511. key: '_measure',
  38512. value: function _measure() {
  38513. var _this3 = this;
  38514. var xhr = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; // With Resource Timing API
  38515. if (!xhr) {
  38516. this._getTimingEntry(function (entry) {
  38517. // The latency calculation differs between an HTTP and an HTTPS connection
  38518. // See: http://www.w3.org/TR/resource-timing/#processing-model
  38519. var latency = !entry.secureConnectionStart ? entry.connectEnd - entry.connectStart : entry.secureConnectionStart - entry.connectStart;
  38520. if (latency) _this3._latencies.push(latency);
  38521. _this3._nextRequest(!latency);
  38522. });
  38523. } // Without Resource Timing API
  38524. else if (this._requestsLeft < this.settings().measures) {
  38525. // Measure and save the latency if the headers have been received
  38526. if (xhr.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
  38527. var labels = this._timingLabels;
  38528. _Timing2['default'].mark(labels.end);
  38529. var latency = _Timing2['default'].measure(labels.measure, labels.start, labels.end);
  38530. if (latency) this._latencies.push(latency); // Abort the current request before we run a new one
  38531. this._abort();
  38532. this._nextRequest(!latency);
  38533. }
  38534. } // Ignore the first request when using the XHR states. See the comments in the start() method for explanations.
  38535. else {
  38536. this._nextRequest();
  38537. }
  38538. return this;
  38539. }
  38540. /**
  38541. * End the measures.
  38542. * @private
  38543. * @method LatencyModule#_end
  38544. * @returns {LatencyModule}
  38545. */
  38546. }, {
  38547. key: '_end',
  38548. value: function _end() {
  38549. var latencies = this._latencies; // Get the average latency
  38550. var avgLatency = latencies.reduce(function (a, b) {
  38551. return a + b;
  38552. }, 0) / (latencies.length || 1);
  38553. avgLatency = avgLatency || null; // If there is no measures, restart with the polyfill.
  38554. if (!latencies.length) {
  38555. this._defineResourceTimingSupport(false);
  38556. this.start();
  38557. return this;
  38558. } // If there is not enough measures, display a warning.
  38559. if (latencies.length < this.settings().measures) {
  38560. var _settings3 = this.settings();
  38561. var measures = _settings3.measures;
  38562. var attempts = _settings3.attempts;
  38563. console.warn('\n An insufficient number of measures have been processed, this could be due to your web server using\n persistant connections or to your client settings (measures: ' + measures + ', attempts: ' + attempts + ').\n ');
  38564. } // Trigger the "end" event with the average latency and the latency list as parameters
  38565. this.trigger('end', avgLatency, latencies);
  38566. return this;
  38567. }
  38568. }], null, _instanceInitializers);
  38569. return LatencyModule;
  38570. }(_HttpModule3['default']);
  38571. exports['default'] = LatencyModule;
  38572. module.exports = exports['default'];
  38573. /**
  38574. * Defines if the module supports the Resource Timing API.
  38575. * @private
  38576. * @member {number} LatencyModule#_requestsLeft
  38577. */
  38578. }, {
  38579. "../../utils/decorators": 7,
  38580. "../../utils/helpers": 8,
  38581. "../Timing": 6,
  38582. "./HttpModule": 3
  38583. }],
  38584. 5: [function (require, module, exports) {
  38585. 'use strict';
  38586. Object.defineProperty(exports, '__esModule', {
  38587. value: true
  38588. });
  38589. var _createDecoratedClass = function () {
  38590. function defineProperties(target, descriptors, initializers) {
  38591. for (var i = 0; i < descriptors.length; i++) {
  38592. var descriptor = descriptors[i];
  38593. var decorators = descriptor.decorators;
  38594. var key = descriptor.key;
  38595. delete descriptor.key;
  38596. delete descriptor.decorators;
  38597. descriptor.enumerable = descriptor.enumerable || false;
  38598. descriptor.configurable = true;
  38599. if ('value' in descriptor || descriptor.initializer) descriptor.writable = true;
  38600. if (decorators) {
  38601. for (var f = 0; f < decorators.length; f++) {
  38602. var decorator = decorators[f];
  38603. if (typeof decorator === 'function') {
  38604. descriptor = decorator(target, key, descriptor) || descriptor;
  38605. } else {
  38606. throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator);
  38607. }
  38608. }
  38609. if (descriptor.initializer !== undefined) {
  38610. initializers[key] = descriptor;
  38611. continue;
  38612. }
  38613. }
  38614. Object.defineProperty(target, key, descriptor);
  38615. }
  38616. }
  38617. return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) {
  38618. if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers);
  38619. if (staticProps) defineProperties(Constructor, staticProps, staticInitializers);
  38620. return Constructor;
  38621. };
  38622. }();
  38623. function _interopRequireDefault(obj) {
  38624. return obj && obj.__esModule ? obj : {
  38625. 'default': obj
  38626. };
  38627. }
  38628. function _defineProperty(obj, key, value) {
  38629. if (key in obj) {
  38630. Object.defineProperty(obj, key, {
  38631. value: value,
  38632. enumerable: true,
  38633. configurable: true,
  38634. writable: true
  38635. });
  38636. } else {
  38637. obj[key] = value;
  38638. }
  38639. return obj;
  38640. }
  38641. function _classCallCheck(instance, Constructor) {
  38642. if (!(instance instanceof Constructor)) {
  38643. throw new TypeError('Cannot call a class as a function');
  38644. }
  38645. }
  38646. function _defineDecoratedPropertyDescriptor(target, key, descriptors) {
  38647. var _descriptor = descriptors[key];
  38648. if (!_descriptor) return;
  38649. var descriptor = {};
  38650. for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
  38651. descriptor.value = descriptor.initializer.call(target);
  38652. Object.defineProperty(target, key, descriptor);
  38653. }
  38654. var _EventDispatcher = require('./EventDispatcher');
  38655. var _EventDispatcher2 = _interopRequireDefault(_EventDispatcher);
  38656. var _HttpHttpModule = require('./Http/HttpModule');
  38657. var _HttpHttpModule2 = _interopRequireDefault(_HttpHttpModule);
  38658. var _HttpLatencyModule = require('./Http/LatencyModule');
  38659. var _HttpLatencyModule2 = _interopRequireDefault(_HttpLatencyModule);
  38660. var _HttpBandwidthModule = require('./Http/BandwidthModule');
  38661. var _HttpBandwidthModule2 = _interopRequireDefault(_HttpBandwidthModule);
  38662. var _Timing = require('./Timing');
  38663. var _Timing2 = _interopRequireDefault(_Timing);
  38664. var _utilsHelpers = require('../utils/helpers');
  38665. var _utilsDecorators = require('../utils/decorators');
  38666. /**
  38667. * @public
  38668. * @typedef {Object} Network~settingsObject
  38669. * @property {LatencyModule~settingsObject} latency
  38670. * @property {BandwidthModule~settingsObject} upload
  38671. * @property {BandwidthModule~settingsObject} download
  38672. * @example
  38673. * {
  38674. * // Top-level properties are applied to all the modules
  38675. * endpoint: './my-new-endpoint/',
  38676. *
  38677. * // Top-level properties will be overridden by the ones specified in each module
  38678. * latency: {
  38679. * endpoint: './my-new-latency-endpoint/'
  38680. * }
  38681. * }
  38682. */
  38683. /**
  38684. * @class Network
  38685. * @param {Network~settingsObject} [settings={}] A set of custom settings.
  38686. * @member {LatencyModule} latency The latency module.
  38687. * @member {BandwidthModule} upload The upload module.
  38688. * @member {BandwidthModule} download The download module.
  38689. */
  38690. var Network = function () {
  38691. var _instanceInitializers = {};
  38692. var _instanceInitializers = {};
  38693. _createDecoratedClass(Network, [{
  38694. key: '_modules',
  38695. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38696. initializer: function initializer() {
  38697. return {};
  38698. },
  38699. /**
  38700. * Defines if the registered modules have been initialized.
  38701. * @private
  38702. * @member {boolean} Network#_modulesInitialized
  38703. */
  38704. enumerable: true
  38705. }, {
  38706. key: '_modulesInitialized',
  38707. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38708. initializer: function initializer() {
  38709. return false;
  38710. },
  38711. /**
  38712. * The settings defined via the constructor, they will be applied once the modules are initialized.
  38713. * @private
  38714. * @member {Network~settingsObject} Network#_pendingSettings
  38715. */
  38716. enumerable: true
  38717. }, {
  38718. key: '_pendingSettings',
  38719. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38720. initializer: function initializer() {
  38721. return {};
  38722. },
  38723. /**
  38724. * Expose all the internal classes to the global scope. Only for testing purposes!
  38725. * @private
  38726. * @method Network._exposeInternalClasses
  38727. * @returns {Network}
  38728. */
  38729. enumerable: true
  38730. }], [{
  38731. key: '_exposeInternalClasses',
  38732. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38733. value: function _exposeInternalClasses() {
  38734. var global = (0, _utilsHelpers.getGlobalObject)(),
  38735. classes = {
  38736. EventDispatcher: _EventDispatcher2['default'],
  38737. HttpModule: _HttpHttpModule2['default'],
  38738. LatencyModule: _HttpLatencyModule2['default'],
  38739. BandwidthModule: _HttpBandwidthModule2['default'],
  38740. Timing: _Timing2['default']
  38741. };
  38742. Object.keys(classes).forEach(function (name) {
  38743. global[name] = classes[name];
  38744. });
  38745. return this;
  38746. }
  38747. }, {
  38748. key: 'supportsResourceTiming',
  38749. /**
  38750. * Defines if the current browser supports the Resource Timing API.
  38751. * @public
  38752. * @readonly
  38753. * @member {boolean} Network#supportsResourceTiming
  38754. */
  38755. get: function get() {
  38756. return _Timing2['default'].supportsResourceTiming;
  38757. }
  38758. /**
  38759. * The registered modules.
  38760. * @private
  38761. * @member {Object} Network#_modules
  38762. */
  38763. }], _instanceInitializers);
  38764. function Network() {
  38765. var settings = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  38766. _classCallCheck(this, Network);
  38767. _defineDecoratedPropertyDescriptor(this, '_modules', _instanceInitializers);
  38768. _defineDecoratedPropertyDescriptor(this, '_modulesInitialized', _instanceInitializers);
  38769. _defineDecoratedPropertyDescriptor(this, '_pendingSettings', _instanceInitializers);
  38770. this._registerModule('latency', function (settings) {
  38771. return new _HttpLatencyModule2['default'](settings);
  38772. })._registerModule('upload', function (settings) {
  38773. return new _HttpBandwidthModule2['default']('upload', settings);
  38774. })._registerModule('download', function (settings) {
  38775. return new _HttpBandwidthModule2['default']('download', settings);
  38776. });
  38777. this._initModules(this.settings(settings));
  38778. }
  38779. /**
  38780. * Apply a new set of custom settings.
  38781. * @public
  38782. * @method Network#settings
  38783. * @param {Network~settingsObject} settings A set of custom settings.
  38784. * @returns {Network}
  38785. */
  38786. /**
  38787. * Return the current set of settings.
  38788. * @public
  38789. * @method Network#settings^2
  38790. * @returns {Network~settingsObject}
  38791. */
  38792. _createDecoratedClass(Network, [{
  38793. key: 'settings',
  38794. value: function settings() {
  38795. var _this = this;
  38796. var _settings = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
  38797. var moduleNames = Object.keys(this._modules);
  38798. if ((0, _utilsHelpers.isObject)(_settings)) {
  38799. var _ret = function () {
  38800. // Extract the global settings
  38801. var globalSettings = (0, _utilsHelpers.except)(_settings, moduleNames); // Extract the local settings
  38802. var localSettings = (0, _utilsHelpers.except)(_settings, Object.keys(globalSettings)); // Create new settings with the global ones nested in the local ones
  38803. _settings = moduleNames.reduce(function (settings, moduleName) {
  38804. return (0, _utilsHelpers.assign)(settings, _defineProperty({}, moduleName, globalSettings));
  38805. }, {}); // Apply the local settings to the new settings
  38806. _settings = (0, _utilsHelpers.assign)(_settings, localSettings); // Apply the settings to the modules
  38807. if (_this._modulesInitialized) {
  38808. Object.keys(_this._modules).forEach(function (name) {
  38809. _this._modules[name].settings(_settings[name]);
  38810. });
  38811. } // If the modules aren't instanciated, store the settings.
  38812. else {
  38813. _this._pendingSettings = _settings;
  38814. }
  38815. return {
  38816. v: _this
  38817. };
  38818. }();
  38819. if (typeof _ret === 'object') return _ret.v;
  38820. } else {
  38821. return moduleNames.reduce(function (settings, moduleName) {
  38822. return (0, _utilsHelpers.assign)(settings, _defineProperty({}, moduleName, _this._modules[moduleName].settings()));
  38823. }, {});
  38824. }
  38825. }
  38826. /**
  38827. * Return if a module is currently making a request.
  38828. * @public
  38829. * @method Network#isRequesting
  38830. * @returns {boolean} `true` if a module is requesting, otherwise `false`.
  38831. */
  38832. }, {
  38833. key: 'isRequesting',
  38834. value: function isRequesting() {
  38835. var requesting = false;
  38836. for (var _name in this._modules) {
  38837. if (this._modules.hasOwnProperty(_name)) {
  38838. requesting = requesting || this._modules[_name].isRequesting();
  38839. }
  38840. }
  38841. return requesting;
  38842. }
  38843. /**
  38844. * Register a new module for the current `Network` instance.
  38845. * @private
  38846. * @method Network#registerModule
  38847. * @param {string} name The name of the module. Will be used to create the property `Network.<name>`.
  38848. * @param {Network~moduleCallback} moduleCallback A callback used to initialize a module with a set of settings.
  38849. * @returns {Network}
  38850. */
  38851. }, {
  38852. key: '_registerModule',
  38853. value: function _registerModule(name, moduleCallback) {
  38854. /**
  38855. * A callback used to initialize a module with a set of settings.
  38856. * @private
  38857. * @callback Network~moduleCallback
  38858. * @param {Object} settings A set of custom settings.
  38859. * @returns {HttpModule} An instanciated subclass of `HttpModule`.
  38860. */
  38861. this._modules[name] = moduleCallback;
  38862. return this;
  38863. }
  38864. /**
  38865. * Initialize all the registered modules with the settings passed to the constructor.
  38866. * @private
  38867. * @method Network#_initModules
  38868. * @returns {Network}
  38869. */
  38870. }, {
  38871. key: '_initModules',
  38872. value: function _initModules() {
  38873. var _this2 = this;
  38874. if (!this._modulesInitialized) {
  38875. // Initialize the modules with their respective settings
  38876. Object.keys(this._modules).forEach(function (name) {
  38877. _this2._modules[name] = _this2._modules[name](_this2._pendingSettings[name]).on('_newRequest', function () {
  38878. return !_this2.isRequesting();
  38879. });
  38880. _this2[name] = _this2._modules[name];
  38881. });
  38882. this._modulesInitialized = true;
  38883. }
  38884. return this;
  38885. }
  38886. }], null, _instanceInitializers);
  38887. return Network;
  38888. }();
  38889. exports['default'] = Network;
  38890. module.exports = exports['default'];
  38891. }, {
  38892. "../utils/decorators": 7,
  38893. "../utils/helpers": 8,
  38894. "./EventDispatcher": 1,
  38895. "./Http/BandwidthModule": 2,
  38896. "./Http/HttpModule": 3,
  38897. "./Http/LatencyModule": 4,
  38898. "./Timing": 6
  38899. }],
  38900. 6: [function (require, module, exports) {
  38901. 'use strict';
  38902. Object.defineProperty(exports, '__esModule', {
  38903. value: true
  38904. });
  38905. var _createDecoratedClass = function () {
  38906. function defineProperties(target, descriptors, initializers) {
  38907. for (var i = 0; i < descriptors.length; i++) {
  38908. var descriptor = descriptors[i];
  38909. var decorators = descriptor.decorators;
  38910. var key = descriptor.key;
  38911. delete descriptor.key;
  38912. delete descriptor.decorators;
  38913. descriptor.enumerable = descriptor.enumerable || false;
  38914. descriptor.configurable = true;
  38915. if ('value' in descriptor || descriptor.initializer) descriptor.writable = true;
  38916. if (decorators) {
  38917. for (var f = 0; f < decorators.length; f++) {
  38918. var decorator = decorators[f];
  38919. if (typeof decorator === 'function') {
  38920. descriptor = decorator(target, key, descriptor) || descriptor;
  38921. } else {
  38922. throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator);
  38923. }
  38924. }
  38925. if (descriptor.initializer !== undefined) {
  38926. initializers[key] = descriptor;
  38927. continue;
  38928. }
  38929. }
  38930. Object.defineProperty(target, key, descriptor);
  38931. }
  38932. }
  38933. return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) {
  38934. if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers);
  38935. if (staticProps) defineProperties(Constructor, staticProps, staticInitializers);
  38936. return Constructor;
  38937. };
  38938. }();
  38939. function _classCallCheck(instance, Constructor) {
  38940. if (!(instance instanceof Constructor)) {
  38941. throw new TypeError('Cannot call a class as a function');
  38942. }
  38943. }
  38944. function _defineDecoratedPropertyDescriptor(target, key, descriptors) {
  38945. var _descriptor = descriptors[key];
  38946. if (!_descriptor) return;
  38947. var descriptor = {};
  38948. for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
  38949. descriptor.value = descriptor.initializer.call(target);
  38950. Object.defineProperty(target, key, descriptor);
  38951. }
  38952. var _utilsHelpers = require('../utils/helpers');
  38953. var _utilsDecorators = require('../utils/decorators');
  38954. /**
  38955. * @private
  38956. * @class Timing
  38957. */
  38958. var Timing = function () {
  38959. var _instanceInitializers = {};
  38960. var _instanceInitializers = {};
  38961. _createDecoratedClass(Timing, [{
  38962. key: 'supportsResourceTiming',
  38963. /**
  38964. * Defines if the current browser supports the Resource Timing API.
  38965. * @public
  38966. * @readonly
  38967. * @member {boolean} Timing#supportsResourceTiming
  38968. */
  38969. get: function get() {
  38970. return Boolean(this._support.resourceTiming);
  38971. }
  38972. /**
  38973. * Defines if the current browser supports some specific Timing APIs.
  38974. * @private
  38975. * @member {Object} Timing#_support
  38976. * @property {boolean} performance `true` if the Performance API is available.
  38977. * @property {boolean} userTiming `true` if the User Timing API is available.
  38978. * @property {boolean} resourceTiming `true` if the Resource Timing API is available.
  38979. */
  38980. }, {
  38981. key: '_support',
  38982. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38983. initializer: function initializer() {
  38984. return {};
  38985. },
  38986. /**
  38987. * All the marks created by the `mark` method.
  38988. * @private
  38989. * @member {Object} Timing#_marks
  38990. */
  38991. enumerable: true
  38992. }, {
  38993. key: '_marks',
  38994. decorators: [(0, _utilsDecorators.enumerable)(false)],
  38995. initializer: function initializer() {
  38996. return {};
  38997. },
  38998. /**
  38999. * All the measures created by the `measure` method.
  39000. * @private
  39001. * @member {Object} Timing#_measures
  39002. */
  39003. enumerable: true
  39004. }, {
  39005. key: '_measures',
  39006. decorators: [(0, _utilsDecorators.enumerable)(false)],
  39007. initializer: function initializer() {
  39008. return {};
  39009. },
  39010. enumerable: true
  39011. }], null, _instanceInitializers);
  39012. function Timing() {
  39013. _classCallCheck(this, Timing);
  39014. _defineDecoratedPropertyDescriptor(this, '_support', _instanceInitializers);
  39015. _defineDecoratedPropertyDescriptor(this, '_marks', _instanceInitializers);
  39016. _defineDecoratedPropertyDescriptor(this, '_measures', _instanceInitializers);
  39017. var global = (0, _utilsHelpers.getGlobalObject)();
  39018. this._support = {
  39019. performance: !!global.performance,
  39020. userTiming: global.performance && performance.mark,
  39021. resourceTiming: global.performance && typeof performance.getEntriesByType == "function" && performance.timing
  39022. };
  39023. }
  39024. /**
  39025. * Create a new timing mark.
  39026. * @public
  39027. * @method Timing#mark
  39028. * @param {string} label A label associated to the mark.
  39029. * @returns {Timing}
  39030. */
  39031. _createDecoratedClass(Timing, [{
  39032. key: 'mark',
  39033. value: function mark(label) {
  39034. var support = this._support,
  39035. marks = this._marks;
  39036. if (support.userTiming) {
  39037. performance.mark(label);
  39038. }
  39039. if (support.performance) {
  39040. marks[label] = performance.now();
  39041. } else {
  39042. marks[label] = new Date().getTime();
  39043. }
  39044. return this;
  39045. }
  39046. /**
  39047. * Measure the delay between two marks.
  39048. * @public
  39049. * @method Timing#measure
  39050. * @param {string} measureLabel A label associated to the measure.
  39051. * @param {string} markLabelA The label of the first mark.
  39052. * @param {string} markLabelB The label of the second mark.
  39053. * @returns {number} The measured value.
  39054. */
  39055. }, {
  39056. key: 'measure',
  39057. value: function measure(measureLabel, markLabelA, markLabelB) {
  39058. var support = this._support,
  39059. marks = this._marks,
  39060. measures = this._measures;
  39061. if (typeof measures[measureLabel] == 'undefined') {
  39062. var measureWithoutUserTiming = marks[markLabelB] - marks[markLabelA];
  39063. if (support.userTiming) {
  39064. performance.measure(measureLabel, markLabelA, markLabelB);
  39065. var entriesByName = performance.getEntriesByName(measureLabel); // The performance API could return no corresponding entries in Firefox so we must use a fallback.
  39066. // See: https://github.com/nesk/network.js/issues/32#issuecomment-118434305
  39067. measures[measureLabel] = entriesByName.length ? entriesByName[0].duration : measureWithoutUserTiming;
  39068. } else {
  39069. measures[measureLabel] = measureWithoutUserTiming;
  39070. }
  39071. }
  39072. return measures[measureLabel];
  39073. }
  39074. }], null, _instanceInitializers);
  39075. return Timing;
  39076. }();
  39077. exports['default'] = new Timing();
  39078. module.exports = exports['default'];
  39079. }, {
  39080. "../utils/decorators": 7,
  39081. "../utils/helpers": 8
  39082. }],
  39083. 7: [function (require, module, exports) {
  39084. /**
  39085. * @callback propertyDecorator
  39086. * @param target
  39087. * @param key
  39088. * @param descriptor
  39089. */
  39090. /**
  39091. * Set the enumerability of a property.
  39092. * @private
  39093. * @function enumerable
  39094. * @param {boolean} isEnumerable Whether the property should be enumerable or not.
  39095. * @returns {propertyDecorator}
  39096. */
  39097. "use strict";
  39098. Object.defineProperty(exports, "__esModule", {
  39099. value: true
  39100. });
  39101. exports.enumerable = enumerable;
  39102. function enumerable(isEnumerable) {
  39103. return function (target, key, descriptor) {
  39104. descriptor.enumerable = isEnumerable;
  39105. return descriptor;
  39106. };
  39107. }
  39108. }, {}],
  39109. 8: [function (require, module, exports) {
  39110. (function (global) {
  39111. /**
  39112. * Return the global object.
  39113. * @private
  39114. * @function getGlobalObject
  39115. * @return {Object}
  39116. * @see https://gist.github.com/rauschma/1bff02da66472f555c75
  39117. */
  39118. 'use strict';
  39119. Object.defineProperty(exports, '__esModule', {
  39120. value: true
  39121. });
  39122. var _createClass = function () {
  39123. function defineProperties(target, props) {
  39124. for (var i = 0; i < props.length; i++) {
  39125. var descriptor = props[i];
  39126. descriptor.enumerable = descriptor.enumerable || false;
  39127. descriptor.configurable = true;
  39128. if ('value' in descriptor) descriptor.writable = true;
  39129. Object.defineProperty(target, descriptor.key, descriptor);
  39130. }
  39131. }
  39132. return function (Constructor, protoProps, staticProps) {
  39133. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  39134. if (staticProps) defineProperties(Constructor, staticProps);
  39135. return Constructor;
  39136. };
  39137. }();
  39138. exports.getGlobalObject = getGlobalObject;
  39139. exports.isObject = isObject;
  39140. exports.copy = copy;
  39141. exports.assign = assign;
  39142. exports.assignStrict = assignStrict;
  39143. exports.except = except;
  39144. exports.defer = defer;
  39145. function _classCallCheck(instance, Constructor) {
  39146. if (!(instance instanceof Constructor)) {
  39147. throw new TypeError('Cannot call a class as a function');
  39148. }
  39149. }
  39150. function getGlobalObject() {
  39151. // Workers don’t have `window`, only `self`.
  39152. if (typeof self !== 'undefined') {
  39153. return self;
  39154. }
  39155. if (typeof global !== 'undefined') {
  39156. return global;
  39157. } // Not all environments allow `eval` and `Function`, use only as a last resort.
  39158. return new Function('return this')();
  39159. }
  39160. /**
  39161. * Determine if the provided value is an object.
  39162. * @private
  39163. * @function isObject
  39164. * @param {*} obj The value to check.
  39165. * @returns {boolean} `true` if the value is an object, otherwise `false`.
  39166. */
  39167. function isObject(obj) {
  39168. return obj != undefined && obj != null && typeof obj.valueOf() == 'object';
  39169. }
  39170. /**
  39171. * Make a deep copy of any value.
  39172. * @private
  39173. * @function copy
  39174. * @param {*} value The value to copy.
  39175. * @returns {*} The copied value.
  39176. */
  39177. function copy(value) {
  39178. return JSON.parse(JSON.stringify(value));
  39179. }
  39180. /**
  39181. * Copy the properties in the source objects over to the destination object.
  39182. * @private
  39183. * @function _assign
  39184. * @param {boolean} strict Given `true`, new properties will not be copied.
  39185. * @param {Object} [target={}] The destination object.
  39186. * @param {...Object} sources The source objects.
  39187. * @returns {Object} The destination object once the properties are copied.
  39188. */
  39189. function _assign(strict) {
  39190. var target = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  39191. target = copy(target);
  39192. for (var _len = arguments.length, sources = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  39193. sources[_key - 2] = arguments[_key];
  39194. }
  39195. sources.forEach(function (source) {
  39196. Object.keys(source).forEach(function (key) {
  39197. if (!strict || target.hasOwnProperty(key)) {
  39198. var value = source[key];
  39199. target[key] = isObject(value) ? _assign(strict, target[key], value) : value;
  39200. }
  39201. });
  39202. });
  39203. return target;
  39204. }
  39205. /**
  39206. * Copy all the properties in the source objects over to the destination object.
  39207. * @private
  39208. * @function assign
  39209. * @param {Object} [target={}] The destination object.
  39210. * @param {...Object} sources The source objects.
  39211. * @returns {Object} The destination object once the properties are copied.
  39212. */
  39213. function assign() {
  39214. var target = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  39215. for (var _len2 = arguments.length, sources = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  39216. sources[_key2 - 1] = arguments[_key2];
  39217. }
  39218. return _assign.apply(undefined, [false, target].concat(sources));
  39219. }
  39220. /**
  39221. * Copy the properties (but no new ones) in the source objects over to the destination object.
  39222. * @private
  39223. * @function assignStrict
  39224. * @param {Object} [target={}] The destination object.
  39225. * @param {...Object} sources The source objects.
  39226. * @returns {Object} The destination object once the properties are copied.
  39227. */
  39228. function assignStrict() {
  39229. var target = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  39230. for (var _len3 = arguments.length, sources = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  39231. sources[_key3 - 1] = arguments[_key3];
  39232. }
  39233. return _assign.apply(undefined, [true, target].concat(sources));
  39234. }
  39235. /**
  39236. * Get a copy of an object without some of its properties.
  39237. * @private
  39238. * @function except
  39239. * @param {Object} obj The original object.
  39240. * @param {string[]} properties The properties to exclude from the copied object.
  39241. * @returns {Object} The copied object without the specified properties.
  39242. */
  39243. function except(obj, properties) {
  39244. var objCopy = copy(obj);
  39245. properties.forEach(function (index) {
  39246. return delete objCopy[index];
  39247. });
  39248. return objCopy;
  39249. }
  39250. /**
  39251. * Defer the execution of a function.
  39252. * @private
  39253. * @function defer
  39254. * @param {Function} func The function to defer.
  39255. * @returns {Defer} The Defer object used to execute the function when needed.
  39256. */
  39257. function defer() {
  39258. var func = arguments.length <= 0 || arguments[0] === undefined ? function () {} : arguments[0];
  39259. /**
  39260. * @private
  39261. * @class Defer
  39262. */
  39263. return new (function () {
  39264. function _class() {
  39265. _classCallCheck(this, _class);
  39266. this.func = func;
  39267. }
  39268. /**
  39269. * Execute the deferred function.
  39270. * @public
  39271. * @method Defer#run
  39272. */
  39273. _createClass(_class, [{
  39274. key: 'run',
  39275. value: function run() {
  39276. if (this.func) this.func();
  39277. delete this.func;
  39278. }
  39279. }]);
  39280. return _class;
  39281. }())();
  39282. }
  39283. }).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
  39284. }, {}]
  39285. }, {}, [5])(5);
  39286. });
  39287. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(21)))
  39288. })
  39289. ]);
  39290. });