jssip-3.2.4.js 945 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644
  1. /*
  2. * JsSIP v3.2.4
  3. * the Javascript SIP library
  4. * Copyright: 2012-2018 José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)
  5. * Homepage: http://jssip.net
  6. * License: MIT
  7. */
  8. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  9. 'use strict';
  10. var Utils = require('./Utils');
  11. var JsSIP_C = require('./Constants');
  12. var Grammar = require('./Grammar');
  13. var URI = require('./URI');
  14. var Socket = require('./Socket');
  15. var Exceptions = require('./Exceptions');
  16. // Default settings.
  17. exports.settings = {
  18. // SIP authentication.
  19. authorization_user: null,
  20. password: null,
  21. realm: null,
  22. ha1: null,
  23. // SIP account.
  24. display_name: null,
  25. uri: null,
  26. contact_uri: null,
  27. // SIP instance id (GRUU).
  28. instance_id: null,
  29. // Preloaded SIP Route header field.
  30. use_preloaded_route: false,
  31. // Session parameters.
  32. session_timers: true,
  33. session_timers_refresh_method: JsSIP_C.UPDATE,
  34. no_answer_timeout: 60,
  35. // Registration parameters.
  36. register: true,
  37. register_expires: 600,
  38. registrar_server: null,
  39. // Connection options.
  40. sockets: null,
  41. connection_recovery_max_interval: null,
  42. connection_recovery_min_interval: null,
  43. /*
  44. * Host address.
  45. * Value to be set in Via sent_by and host part of Contact FQDN.
  46. */
  47. via_host: Utils.createRandomToken(12) + '.invalid'
  48. };
  49. // Configuration checks.
  50. var checks = {
  51. mandatory: {
  52. sockets: function sockets(_sockets2) {
  53. /* Allow defining sockets parameter as:
  54. * Socket: socket
  55. * Array of Socket: [socket1, socket2]
  56. * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}]
  57. * Array of Objects and Socket: [{socket: socket1}, socket2]
  58. */
  59. var _sockets = [];
  60. if (Socket.isSocket(_sockets2)) {
  61. _sockets.push({ socket: _sockets2 });
  62. } else if (Array.isArray(_sockets2) && _sockets2.length) {
  63. var _iteratorNormalCompletion = true;
  64. var _didIteratorError = false;
  65. var _iteratorError = undefined;
  66. try {
  67. for (var _iterator = _sockets2[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  68. var socket = _step.value;
  69. if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) {
  70. _sockets.push(socket);
  71. } else if (Socket.isSocket(socket)) {
  72. _sockets.push({ socket: socket });
  73. }
  74. }
  75. } catch (err) {
  76. _didIteratorError = true;
  77. _iteratorError = err;
  78. } finally {
  79. try {
  80. if (!_iteratorNormalCompletion && _iterator.return) {
  81. _iterator.return();
  82. }
  83. } finally {
  84. if (_didIteratorError) {
  85. throw _iteratorError;
  86. }
  87. }
  88. }
  89. } else {
  90. return;
  91. }
  92. return _sockets;
  93. },
  94. uri: function uri(_uri) {
  95. if (!/^sip:/i.test(_uri)) {
  96. _uri = JsSIP_C.SIP + ':' + _uri;
  97. }
  98. var parsed = URI.parse(_uri);
  99. if (!parsed) {
  100. return;
  101. } else if (!parsed.user) {
  102. return;
  103. } else {
  104. return parsed;
  105. }
  106. }
  107. },
  108. optional: {
  109. authorization_user: function authorization_user(_authorization_user) {
  110. if (Grammar.parse('"' + _authorization_user + '"', 'quoted_string') === -1) {
  111. return;
  112. } else {
  113. return _authorization_user;
  114. }
  115. },
  116. user_agent: function user_agent(_user_agent) {
  117. if (typeof _user_agent === 'string') {
  118. return _user_agent;
  119. }
  120. },
  121. connection_recovery_max_interval: function connection_recovery_max_interval(_connection_recovery_max_interval) {
  122. if (Utils.isDecimal(_connection_recovery_max_interval)) {
  123. var value = Number(_connection_recovery_max_interval);
  124. if (value > 0) {
  125. return value;
  126. }
  127. }
  128. },
  129. connection_recovery_min_interval: function connection_recovery_min_interval(_connection_recovery_min_interval) {
  130. if (Utils.isDecimal(_connection_recovery_min_interval)) {
  131. var value = Number(_connection_recovery_min_interval);
  132. if (value > 0) {
  133. return value;
  134. }
  135. }
  136. },
  137. contact_uri: function contact_uri(_contact_uri) {
  138. if (typeof _contact_uri === 'string') {
  139. var uri = Grammar.parse(_contact_uri, 'SIP_URI');
  140. if (uri !== -1) {
  141. return uri;
  142. }
  143. }
  144. },
  145. display_name: function display_name(_display_name) {
  146. if (Grammar.parse('"' + _display_name + '"', 'display_name') === -1) {
  147. return;
  148. } else {
  149. return _display_name;
  150. }
  151. },
  152. instance_id: function instance_id(_instance_id) {
  153. if (/^uuid:/i.test(_instance_id)) {
  154. _instance_id = _instance_id.substr(5);
  155. }
  156. if (Grammar.parse(_instance_id, 'uuid') === -1) {
  157. return;
  158. } else {
  159. return _instance_id;
  160. }
  161. },
  162. no_answer_timeout: function no_answer_timeout(_no_answer_timeout) {
  163. if (Utils.isDecimal(_no_answer_timeout)) {
  164. var value = Number(_no_answer_timeout);
  165. if (value > 0) {
  166. return value;
  167. }
  168. }
  169. },
  170. session_timers: function session_timers(_session_timers) {
  171. if (typeof _session_timers === 'boolean') {
  172. return _session_timers;
  173. }
  174. },
  175. session_timers_refresh_method: function session_timers_refresh_method(method) {
  176. if (typeof method === 'string') {
  177. method = method.toUpperCase();
  178. if (method === JsSIP_C.INVITE || method === JsSIP_C.UPDATE) {
  179. return method;
  180. }
  181. }
  182. },
  183. password: function password(_password) {
  184. return String(_password);
  185. },
  186. realm: function realm(_realm) {
  187. return String(_realm);
  188. },
  189. ha1: function ha1(_ha) {
  190. return String(_ha);
  191. },
  192. register: function register(_register) {
  193. if (typeof _register === 'boolean') {
  194. return _register;
  195. }
  196. },
  197. register_expires: function register_expires(_register_expires) {
  198. if (Utils.isDecimal(_register_expires)) {
  199. var value = Number(_register_expires);
  200. if (value > 0) {
  201. return value;
  202. }
  203. }
  204. },
  205. registrar_server: function registrar_server(_registrar_server) {
  206. if (!/^sip:/i.test(_registrar_server)) {
  207. _registrar_server = JsSIP_C.SIP + ':' + _registrar_server;
  208. }
  209. var parsed = URI.parse(_registrar_server);
  210. if (!parsed) {
  211. return;
  212. } else if (parsed.user) {
  213. return;
  214. } else {
  215. return parsed;
  216. }
  217. },
  218. use_preloaded_route: function use_preloaded_route(_use_preloaded_route) {
  219. if (typeof _use_preloaded_route === 'boolean') {
  220. return _use_preloaded_route;
  221. }
  222. }
  223. }
  224. };
  225. exports.load = function (dst, src) {
  226. // Check Mandatory parameters.
  227. for (var parameter in checks.mandatory) {
  228. if (!src.hasOwnProperty(parameter)) {
  229. throw new Exceptions.ConfigurationError(parameter);
  230. } else {
  231. var value = src[parameter];
  232. var checked_value = checks.mandatory[parameter](value);
  233. if (checked_value !== undefined) {
  234. dst[parameter] = checked_value;
  235. } else {
  236. throw new Exceptions.ConfigurationError(parameter, value);
  237. }
  238. }
  239. }
  240. // Check Optional parameters.
  241. for (var _parameter in checks.optional) {
  242. if (src.hasOwnProperty(_parameter)) {
  243. var _value = src[_parameter];
  244. /* If the parameter value is null, empty string, undefined, empty array
  245. * or it's a number with NaN value, then apply its default value.
  246. */
  247. if (Utils.isEmpty(_value)) {
  248. continue;
  249. }
  250. var _checked_value = checks.optional[_parameter](_value);
  251. if (_checked_value !== undefined) {
  252. dst[_parameter] = _checked_value;
  253. } else {
  254. throw new Exceptions.ConfigurationError(_parameter, _value);
  255. }
  256. }
  257. }
  258. };
  259. },{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":20,"./URI":25,"./Utils":26}],2:[function(require,module,exports){
  260. 'use strict';
  261. var pkg = require('../package.json');
  262. module.exports = {
  263. USER_AGENT: pkg.title + ' ' + pkg.version,
  264. // SIP scheme.
  265. SIP: 'sip',
  266. SIPS: 'sips',
  267. // End and Failure causes.
  268. causes: {
  269. // Generic error causes.
  270. CONNECTION_ERROR: 'Connection Error',
  271. REQUEST_TIMEOUT: 'Request Timeout',
  272. SIP_FAILURE_CODE: 'SIP Failure Code',
  273. INTERNAL_ERROR: 'Internal Error',
  274. // SIP error causes.
  275. BUSY: 'Busy',
  276. REJECTED: 'Rejected',
  277. REDIRECTED: 'Redirected',
  278. UNAVAILABLE: 'Unavailable',
  279. NOT_FOUND: 'Not Found',
  280. ADDRESS_INCOMPLETE: 'Address Incomplete',
  281. INCOMPATIBLE_SDP: 'Incompatible SDP',
  282. MISSING_SDP: 'Missing SDP',
  283. AUTHENTICATION_ERROR: 'Authentication Error',
  284. // Session error causes.
  285. BYE: 'Terminated',
  286. WEBRTC_ERROR: 'WebRTC Error',
  287. CANCELED: 'Canceled',
  288. NO_ANSWER: 'No Answer',
  289. EXPIRES: 'Expires',
  290. NO_ACK: 'No ACK',
  291. DIALOG_ERROR: 'Dialog Error',
  292. USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access',
  293. BAD_MEDIA_DESCRIPTION: 'Bad Media Description',
  294. RTP_TIMEOUT: 'RTP Timeout'
  295. },
  296. SIP_ERROR_CAUSES: {
  297. REDIRECTED: [300, 301, 302, 305, 380],
  298. BUSY: [486, 600],
  299. REJECTED: [403, 603],
  300. NOT_FOUND: [404, 604],
  301. UNAVAILABLE: [480, 410, 408, 430],
  302. ADDRESS_INCOMPLETE: [484, 424],
  303. INCOMPATIBLE_SDP: [488, 606],
  304. AUTHENTICATION_ERROR: [401, 407]
  305. },
  306. // SIP Methods.
  307. ACK: 'ACK',
  308. BYE: 'BYE',
  309. CANCEL: 'CANCEL',
  310. INFO: 'INFO',
  311. INVITE: 'INVITE',
  312. MESSAGE: 'MESSAGE',
  313. NOTIFY: 'NOTIFY',
  314. OPTIONS: 'OPTIONS',
  315. REGISTER: 'REGISTER',
  316. REFER: 'REFER',
  317. UPDATE: 'UPDATE',
  318. SUBSCRIBE: 'SUBSCRIBE',
  319. /* SIP Response Reasons
  320. * DOC: http://www.iana.org/assignments/sip-parameters
  321. * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7
  322. */
  323. REASON_PHRASE: {
  324. 100: 'Trying',
  325. 180: 'Ringing',
  326. 181: 'Call Is Being Forwarded',
  327. 182: 'Queued',
  328. 183: 'Session Progress',
  329. 199: 'Early Dialog Terminated', // draft-ietf-sipcore-199
  330. 200: 'OK',
  331. 202: 'Accepted', // RFC 3265
  332. 204: 'No Notification', // RFC 5839
  333. 300: 'Multiple Choices',
  334. 301: 'Moved Permanently',
  335. 302: 'Moved Temporarily',
  336. 305: 'Use Proxy',
  337. 380: 'Alternative Service',
  338. 400: 'Bad Request',
  339. 401: 'Unauthorized',
  340. 402: 'Payment Required',
  341. 403: 'Forbidden',
  342. 404: 'Not Found',
  343. 405: 'Method Not Allowed',
  344. 406: 'Not Acceptable',
  345. 407: 'Proxy Authentication Required',
  346. 408: 'Request Timeout',
  347. 410: 'Gone',
  348. 412: 'Conditional Request Failed', // RFC 3903
  349. 413: 'Request Entity Too Large',
  350. 414: 'Request-URI Too Long',
  351. 415: 'Unsupported Media Type',
  352. 416: 'Unsupported URI Scheme',
  353. 417: 'Unknown Resource-Priority', // RFC 4412
  354. 420: 'Bad Extension',
  355. 421: 'Extension Required',
  356. 422: 'Session Interval Too Small', // RFC 4028
  357. 423: 'Interval Too Brief',
  358. 424: 'Bad Location Information', // RFC 6442
  359. 428: 'Use Identity Header', // RFC 4474
  360. 429: 'Provide Referrer Identity', // RFC 3892
  361. 430: 'Flow Failed', // RFC 5626
  362. 433: 'Anonymity Disallowed', // RFC 5079
  363. 436: 'Bad Identity-Info', // RFC 4474
  364. 437: 'Unsupported Certificate', // RFC 4744
  365. 438: 'Invalid Identity Header', // RFC 4744
  366. 439: 'First Hop Lacks Outbound Support', // RFC 5626
  367. 440: 'Max-Breadth Exceeded', // RFC 5393
  368. 469: 'Bad Info Package', // draft-ietf-sipcore-info-events
  369. 470: 'Consent Needed', // RFC 5360
  370. 478: 'Unresolvable Destination', // Custom code copied from Kamailio.
  371. 480: 'Temporarily Unavailable',
  372. 481: 'Call/Transaction Does Not Exist',
  373. 482: 'Loop Detected',
  374. 483: 'Too Many Hops',
  375. 484: 'Address Incomplete',
  376. 485: 'Ambiguous',
  377. 486: 'Busy Here',
  378. 487: 'Request Terminated',
  379. 488: 'Not Acceptable Here',
  380. 489: 'Bad Event', // RFC 3265
  381. 491: 'Request Pending',
  382. 493: 'Undecipherable',
  383. 494: 'Security Agreement Required', // RFC 3329
  384. 500: 'JsSIP Internal Error',
  385. 501: 'Not Implemented',
  386. 502: 'Bad Gateway',
  387. 503: 'Service Unavailable',
  388. 504: 'Server Time-out',
  389. 505: 'Version Not Supported',
  390. 513: 'Message Too Large',
  391. 580: 'Precondition Failure', // RFC 3312
  392. 600: 'Busy Everywhere',
  393. 603: 'Decline',
  394. 604: 'Does Not Exist Anywhere',
  395. 606: 'Not Acceptable'
  396. },
  397. ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO',
  398. ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay',
  399. MAX_FORWARDS: 69,
  400. SESSION_EXPIRES: 180,
  401. MIN_SESSION_EXPIRES: 60
  402. };
  403. },{"../package.json":51}],3:[function(require,module,exports){
  404. 'use strict';
  405. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  406. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  407. var SIPMessage = require('./SIPMessage');
  408. var JsSIP_C = require('./Constants');
  409. var Transactions = require('./Transactions');
  410. var Dialog_RequestSender = require('./Dialog/RequestSender');
  411. var Utils = require('./Utils');
  412. var debug = require('debug')('JsSIP:Dialog');
  413. var C = {
  414. // Dialog states.
  415. STATUS_EARLY: 1,
  416. STATUS_CONFIRMED: 2
  417. };
  418. // RFC 3261 12.1.
  419. module.exports = function () {
  420. _createClass(Dialog, null, [{
  421. key: 'C',
  422. // Expose C object.
  423. get: function get() {
  424. return C;
  425. }
  426. }]);
  427. function Dialog(owner, message, type) {
  428. var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED;
  429. _classCallCheck(this, Dialog);
  430. this._owner = owner;
  431. this._ua = owner._ua;
  432. this._uac_pending_reply = false;
  433. this._uas_pending_reply = false;
  434. if (!message.hasHeader('contact')) {
  435. return {
  436. error: 'unable to create a Dialog without Contact header field'
  437. };
  438. }
  439. if (message instanceof SIPMessage.IncomingResponse) {
  440. state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED;
  441. }
  442. var contact = message.parseHeader('contact');
  443. // RFC 3261 12.1.1.
  444. if (type === 'UAS') {
  445. this._id = {
  446. call_id: message.call_id,
  447. local_tag: message.to_tag,
  448. remote_tag: message.from_tag,
  449. toString: function toString() {
  450. return this.call_id + this.local_tag + this.remote_tag;
  451. }
  452. };
  453. this._state = state;
  454. this._remote_seqnum = message.cseq;
  455. this._local_uri = message.parseHeader('to').uri;
  456. this._remote_uri = message.parseHeader('from').uri;
  457. this._remote_target = contact.uri;
  458. this._route_set = message.getHeaders('record-route');
  459. this._ack_seqnum = this._remote_seqnum;
  460. }
  461. // RFC 3261 12.1.2.
  462. else if (type === 'UAC') {
  463. this._id = {
  464. call_id: message.call_id,
  465. local_tag: message.from_tag,
  466. remote_tag: message.to_tag,
  467. toString: function toString() {
  468. return this.call_id + this.local_tag + this.remote_tag;
  469. }
  470. };
  471. this._state = state;
  472. this._local_seqnum = message.cseq;
  473. this._local_uri = message.parseHeader('from').uri;
  474. this._remote_uri = message.parseHeader('to').uri;
  475. this._remote_target = contact.uri;
  476. this._route_set = message.getHeaders('record-route').reverse();
  477. this._ack_seqnum = null;
  478. }
  479. this._ua.newDialog(this);
  480. debug('new ' + type + ' dialog created with status ' + (this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED'));
  481. }
  482. _createClass(Dialog, [{
  483. key: 'update',
  484. value: function update(message, type) {
  485. this._state = C.STATUS_CONFIRMED;
  486. debug('dialog ' + this._id.toString() + ' changed to CONFIRMED state');
  487. if (type === 'UAC') {
  488. // RFC 3261 13.2.2.4.
  489. this._route_set = message.getHeaders('record-route').reverse();
  490. }
  491. }
  492. }, {
  493. key: 'terminate',
  494. value: function terminate() {
  495. debug('dialog ' + this._id.toString() + ' deleted');
  496. this._ua.destroyDialog(this);
  497. }
  498. }, {
  499. key: 'sendRequest',
  500. value: function sendRequest(method) {
  501. var _this = this;
  502. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  503. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  504. var eventHandlers = options.eventHandlers || {};
  505. var body = options.body || null;
  506. var request = this._createRequest(method, extraHeaders, body);
  507. // Increase the local CSeq on authentication.
  508. eventHandlers.onAuthenticated = function () {
  509. _this._local_seqnum += 1;
  510. };
  511. var request_sender = new Dialog_RequestSender(this, request, eventHandlers);
  512. request_sender.send();
  513. // Return the instance of OutgoingRequest.
  514. return request;
  515. }
  516. }, {
  517. key: 'receiveRequest',
  518. value: function receiveRequest(request) {
  519. // Check in-dialog request.
  520. if (!this._checkInDialogRequest(request)) {
  521. return;
  522. }
  523. // ACK received. Cleanup this._ack_seqnum.
  524. if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) {
  525. this._ack_seqnum = null;
  526. }
  527. // INVITE received. Set this._ack_seqnum.
  528. else if (request.method === JsSIP_C.INVITE) {
  529. this._ack_seqnum = request.cseq;
  530. }
  531. this._owner.receiveRequest(request);
  532. }
  533. // RFC 3261 12.2.1.1.
  534. }, {
  535. key: '_createRequest',
  536. value: function _createRequest(method, extraHeaders, body) {
  537. extraHeaders = Utils.cloneArray(extraHeaders);
  538. if (!this._local_seqnum) {
  539. this._local_seqnum = Math.floor(Math.random() * 10000);
  540. }
  541. var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1;
  542. var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, {
  543. 'cseq': cseq,
  544. 'call_id': this._id.call_id,
  545. 'from_uri': this._local_uri,
  546. 'from_tag': this._id.local_tag,
  547. 'to_uri': this._remote_uri,
  548. 'to_tag': this._id.remote_tag,
  549. 'route_set': this._route_set
  550. }, extraHeaders, body);
  551. return request;
  552. }
  553. // RFC 3261 12.2.2.
  554. }, {
  555. key: '_checkInDialogRequest',
  556. value: function _checkInDialogRequest(request) {
  557. var _this2 = this;
  558. if (!this._remote_seqnum) {
  559. this._remote_seqnum = request.cseq;
  560. } else if (request.cseq < this._remote_seqnum) {
  561. if (request.method === JsSIP_C.ACK) {
  562. // We are not expecting any ACK with lower seqnum than the current one.
  563. // Or this is not the ACK we are waiting for.
  564. if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) {
  565. return false;
  566. }
  567. } else {
  568. request.reply(500);
  569. return false;
  570. }
  571. } else if (request.cseq > this._remote_seqnum) {
  572. this._remote_seqnum = request.cseq;
  573. }
  574. // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-.
  575. if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) {
  576. if (this._uac_pending_reply === true) {
  577. request.reply(491);
  578. } else if (this._uas_pending_reply === true) {
  579. var retryAfter = (Math.random() * 10 | 0) + 1;
  580. request.reply(500, null, ['Retry-After:' + retryAfter]);
  581. return false;
  582. } else {
  583. this._uas_pending_reply = true;
  584. var stateChanged = function stateChanged() {
  585. 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) {
  586. request.server_transaction.removeListener('stateChanged', stateChanged);
  587. _this2._uas_pending_reply = false;
  588. }
  589. };
  590. request.server_transaction.on('stateChanged', stateChanged);
  591. }
  592. // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted.
  593. if (request.hasHeader('contact')) {
  594. request.server_transaction.on('stateChanged', function () {
  595. if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED) {
  596. _this2._remote_target = request.parseHeader('contact').uri;
  597. }
  598. });
  599. }
  600. } else if (request.method === JsSIP_C.NOTIFY) {
  601. // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted.
  602. if (request.hasHeader('contact')) {
  603. request.server_transaction.on('stateChanged', function () {
  604. if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) {
  605. _this2._remote_target = request.parseHeader('contact').uri;
  606. }
  607. });
  608. }
  609. }
  610. return true;
  611. }
  612. }, {
  613. key: 'id',
  614. get: function get() {
  615. return this._id;
  616. }
  617. }, {
  618. key: 'local_seqnum',
  619. get: function get() {
  620. return this._local_seqnum;
  621. },
  622. set: function set(num) {
  623. this._local_seqnum = num;
  624. }
  625. }, {
  626. key: 'owner',
  627. get: function get() {
  628. return this._owner;
  629. }
  630. }, {
  631. key: 'uac_pending_reply',
  632. get: function get() {
  633. return this._uac_pending_reply;
  634. },
  635. set: function set(pending) {
  636. this._uac_pending_reply = pending;
  637. }
  638. }, {
  639. key: 'uas_pending_reply',
  640. get: function get() {
  641. return this._uas_pending_reply;
  642. }
  643. }]);
  644. return Dialog;
  645. }();
  646. },{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":19,"./Transactions":22,"./Utils":26,"debug":29}],4:[function(require,module,exports){
  647. 'use strict';
  648. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  649. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  650. var JsSIP_C = require('../Constants');
  651. var Transactions = require('../Transactions');
  652. var RTCSession = require('../RTCSession');
  653. var RequestSender = require('../RequestSender');
  654. // Default event handlers.
  655. var EventHandlers = {
  656. onRequestTimeout: function onRequestTimeout() {},
  657. onTransportError: function onTransportError() {},
  658. onSuccessResponse: function onSuccessResponse() {},
  659. onErrorResponse: function onErrorResponse() {},
  660. onAuthenticated: function onAuthenticated() {},
  661. onDialogError: function onDialogError() {}
  662. };
  663. module.exports = function () {
  664. function DialogRequestSender(dialog, request, eventHandlers) {
  665. _classCallCheck(this, DialogRequestSender);
  666. this._dialog = dialog;
  667. this._ua = dialog._ua;
  668. this._request = request;
  669. this._eventHandlers = eventHandlers;
  670. // RFC3261 14.1 Modifying an Existing Session. UAC Behavior.
  671. this._reattempt = false;
  672. this._reattemptTimer = null;
  673. // Define the undefined handlers.
  674. for (var handler in EventHandlers) {
  675. if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
  676. if (!this._eventHandlers[handler]) {
  677. this._eventHandlers[handler] = EventHandlers[handler];
  678. }
  679. }
  680. }
  681. }
  682. _createClass(DialogRequestSender, [{
  683. key: 'send',
  684. value: function send() {
  685. var _this = this;
  686. var request_sender = new RequestSender(this._ua, this._request, {
  687. onRequestTimeout: function onRequestTimeout() {
  688. _this._eventHandlers.onRequestTimeout();
  689. },
  690. onTransportError: function onTransportError() {
  691. _this._eventHandlers.onTransportError();
  692. },
  693. onAuthenticated: function onAuthenticated(request) {
  694. _this._eventHandlers.onAuthenticated(request);
  695. },
  696. onReceiveResponse: function onReceiveResponse(response) {
  697. _this._receiveResponse(response);
  698. }
  699. });
  700. request_sender.send();
  701. // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-.
  702. if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) {
  703. this._dialog.uac_pending_reply = true;
  704. var stateChanged = function stateChanged() {
  705. 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) {
  706. request_sender.clientTransaction.removeListener('stateChanged', stateChanged);
  707. _this._dialog.uac_pending_reply = false;
  708. }
  709. };
  710. request_sender.clientTransaction.on('stateChanged', stateChanged);
  711. }
  712. }
  713. }, {
  714. key: '_receiveResponse',
  715. value: function _receiveResponse(response) {
  716. var _this2 = this;
  717. // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog.
  718. if (response.status_code === 408 || response.status_code === 481) {
  719. this._eventHandlers.onDialogError(response);
  720. } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) {
  721. if (this._reattempt) {
  722. if (response.status_code >= 200 && response.status_code < 300) {
  723. this._eventHandlers.onSuccessResponse(response);
  724. } else if (response.status_code >= 300) {
  725. this._eventHandlers.onErrorResponse(response);
  726. }
  727. } else {
  728. this._request.cseq.value = this._dialog.local_seqnum += 1;
  729. this._reattemptTimer = setTimeout(function () {
  730. // TODO: look at dialog state instead.
  731. if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) {
  732. _this2._reattempt = true;
  733. _this2._request_sender.send();
  734. }
  735. }, 1000);
  736. }
  737. } else if (response.status_code >= 200 && response.status_code < 300) {
  738. this._eventHandlers.onSuccessResponse(response);
  739. } else if (response.status_code >= 300) {
  740. this._eventHandlers.onErrorResponse(response);
  741. }
  742. }
  743. }, {
  744. key: 'request',
  745. get: function get() {
  746. return this._request;
  747. }
  748. }]);
  749. return DialogRequestSender;
  750. }();
  751. },{"../Constants":2,"../RTCSession":12,"../RequestSender":18,"../Transactions":22}],5:[function(require,module,exports){
  752. 'use strict';
  753. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  754. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  755. var Utils = require('./Utils');
  756. var debug = require('debug')('JsSIP:DigestAuthentication');
  757. var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication');
  758. debugerror.log = console.warn.bind(console);
  759. module.exports = function () {
  760. function DigestAuthentication(credentials) {
  761. _classCallCheck(this, DigestAuthentication);
  762. this._credentials = credentials;
  763. this._cnonce = null;
  764. this._nc = 0;
  765. this._ncHex = '00000000';
  766. this._algorithm = null;
  767. this._realm = null;
  768. this._nonce = null;
  769. this._opaque = null;
  770. this._stale = null;
  771. this._qop = null;
  772. this._method = null;
  773. this._uri = null;
  774. this._ha1 = null;
  775. this._response = null;
  776. }
  777. _createClass(DigestAuthentication, [{
  778. key: 'get',
  779. value: function get(parameter) {
  780. switch (parameter) {
  781. case 'realm':
  782. return this._realm;
  783. case 'ha1':
  784. return this._ha1;
  785. default:
  786. debugerror('get() | cannot get "%s" parameter', parameter);
  787. return undefined;
  788. }
  789. }
  790. /**
  791. * Performs Digest authentication given a SIP request and the challenge
  792. * received in a response to that request.
  793. * Returns true if auth was successfully generated, false otherwise.
  794. */
  795. }, {
  796. key: 'authenticate',
  797. value: function authenticate(_ref, challenge) /* test interface */{
  798. var method = _ref.method,
  799. ruri = _ref.ruri,
  800. body = _ref.body;
  801. var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  802. this._algorithm = challenge.algorithm;
  803. this._realm = challenge.realm;
  804. this._nonce = challenge.nonce;
  805. this._opaque = challenge.opaque;
  806. this._stale = challenge.stale;
  807. if (this._algorithm) {
  808. if (this._algorithm !== 'MD5') {
  809. debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');
  810. return false;
  811. }
  812. } else {
  813. this._algorithm = 'MD5';
  814. }
  815. if (!this._nonce) {
  816. debugerror('authenticate() | challenge without Digest nonce, authentication aborted');
  817. return false;
  818. }
  819. if (!this._realm) {
  820. debugerror('authenticate() | challenge without Digest realm, authentication aborted');
  821. return false;
  822. }
  823. // If no plain SIP password is provided.
  824. if (!this._credentials.password) {
  825. // If ha1 is not provided we cannot authenticate.
  826. if (!this._credentials.ha1) {
  827. debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted');
  828. return false;
  829. }
  830. // If the realm does not match the stored realm we cannot authenticate.
  831. if (this._credentials.realm !== this._realm) {
  832. 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);
  833. return false;
  834. }
  835. }
  836. // 'qop' can contain a list of values (Array). Let's choose just one.
  837. if (challenge.qop) {
  838. if (challenge.qop.indexOf('auth-int') > -1) {
  839. this._qop = 'auth-int';
  840. } else if (challenge.qop.indexOf('auth') > -1) {
  841. this._qop = 'auth';
  842. } else {
  843. // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here.
  844. debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');
  845. return false;
  846. }
  847. } else {
  848. this._qop = null;
  849. }
  850. // Fill other attributes.
  851. this._method = method;
  852. this._uri = ruri;
  853. this._cnonce = cnonce || Utils.createRandomToken(12);
  854. this._nc += 1;
  855. var hex = Number(this._nc).toString(16);
  856. this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex;
  857. // Nc-value = 8LHEX. Max value = 'FFFFFFFF'.
  858. if (this._nc === 4294967296) {
  859. this._nc = 1;
  860. this._ncHex = '00000001';
  861. }
  862. // Calculate the Digest "response" value.
  863. // If we have plain SIP password then regenerate ha1.
  864. if (this._credentials.password) {
  865. // HA1 = MD5(A1) = MD5(username:realm:password).
  866. this._ha1 = Utils.calculateMD5(this._credentials.username + ':' + this._realm + ':' + this._credentials.password);
  867. }
  868. // Otherwise reuse the stored ha1.
  869. else {
  870. this._ha1 = this._credentials.ha1;
  871. }
  872. var ha2 = void 0;
  873. if (this._qop === 'auth') {
  874. // HA2 = MD5(A2) = MD5(method:digestURI).
  875. ha2 = Utils.calculateMD5(this._method + ':' + this._uri);
  876. // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
  877. this._response = Utils.calculateMD5(this._ha1 + ':' + this._nonce + ':' + this._ncHex + ':' + this._cnonce + ':auth:' + ha2);
  878. } else if (this._qop === 'auth-int') {
  879. // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)).
  880. ha2 = Utils.calculateMD5(this._method + ':' + this._uri + ':' + Utils.calculateMD5(body ? body : ''));
  881. // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
  882. this._response = Utils.calculateMD5(this._ha1 + ':' + this._nonce + ':' + this._ncHex + ':' + this._cnonce + ':auth-int:' + ha2);
  883. } else if (this._qop === null) {
  884. // HA2 = MD5(A2) = MD5(method:digestURI).
  885. ha2 = Utils.calculateMD5(this._method + ':' + this._uri);
  886. // Response = MD5(HA1:nonce:HA2).
  887. this._response = Utils.calculateMD5(this._ha1 + ':' + this._nonce + ':' + ha2);
  888. }
  889. debug('authenticate() | response generated');
  890. return true;
  891. }
  892. /**
  893. * Return the Proxy-Authorization or WWW-Authorization header value.
  894. */
  895. }, {
  896. key: 'toString',
  897. value: function toString() {
  898. var auth_params = [];
  899. if (!this._response) {
  900. throw new Error('response field does not exist, cannot generate Authorization header');
  901. }
  902. auth_params.push('algorithm=' + this._algorithm);
  903. auth_params.push('username="' + this._credentials.username + '"');
  904. auth_params.push('realm="' + this._realm + '"');
  905. auth_params.push('nonce="' + this._nonce + '"');
  906. auth_params.push('uri="' + this._uri + '"');
  907. auth_params.push('response="' + this._response + '"');
  908. if (this._opaque) {
  909. auth_params.push('opaque="' + this._opaque + '"');
  910. }
  911. if (this._qop) {
  912. auth_params.push('qop=' + this._qop);
  913. auth_params.push('cnonce="' + this._cnonce + '"');
  914. auth_params.push('nc=' + this._ncHex);
  915. }
  916. return 'Digest ' + auth_params.join(', ');
  917. }
  918. }]);
  919. return DigestAuthentication;
  920. }();
  921. },{"./Utils":26,"debug":29}],6:[function(require,module,exports){
  922. 'use strict';
  923. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  924. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  925. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  926. var ConfigurationError = function (_Error) {
  927. _inherits(ConfigurationError, _Error);
  928. function ConfigurationError(parameter, value) {
  929. _classCallCheck(this, ConfigurationError);
  930. var _this = _possibleConstructorReturn(this, (ConfigurationError.__proto__ || Object.getPrototypeOf(ConfigurationError)).call(this));
  931. _this.code = 1;
  932. _this.name = 'CONFIGURATION_ERROR';
  933. _this.parameter = parameter;
  934. _this.value = value;
  935. _this.message = !_this.value ? 'Missing parameter: ' + _this.parameter : 'Invalid value ' + JSON.stringify(_this.value) + ' for parameter "' + _this.parameter + '"';
  936. return _this;
  937. }
  938. return ConfigurationError;
  939. }(Error);
  940. var InvalidStateError = function (_Error2) {
  941. _inherits(InvalidStateError, _Error2);
  942. function InvalidStateError(status) {
  943. _classCallCheck(this, InvalidStateError);
  944. var _this2 = _possibleConstructorReturn(this, (InvalidStateError.__proto__ || Object.getPrototypeOf(InvalidStateError)).call(this));
  945. _this2.code = 2;
  946. _this2.name = 'INVALID_STATE_ERROR';
  947. _this2.status = status;
  948. _this2.message = 'Invalid status: ' + status;
  949. return _this2;
  950. }
  951. return InvalidStateError;
  952. }(Error);
  953. var NotSupportedError = function (_Error3) {
  954. _inherits(NotSupportedError, _Error3);
  955. function NotSupportedError(message) {
  956. _classCallCheck(this, NotSupportedError);
  957. var _this3 = _possibleConstructorReturn(this, (NotSupportedError.__proto__ || Object.getPrototypeOf(NotSupportedError)).call(this));
  958. _this3.code = 3;
  959. _this3.name = 'NOT_SUPPORTED_ERROR';
  960. _this3.message = message;
  961. return _this3;
  962. }
  963. return NotSupportedError;
  964. }(Error);
  965. var NotReadyError = function (_Error4) {
  966. _inherits(NotReadyError, _Error4);
  967. function NotReadyError(message) {
  968. _classCallCheck(this, NotReadyError);
  969. var _this4 = _possibleConstructorReturn(this, (NotReadyError.__proto__ || Object.getPrototypeOf(NotReadyError)).call(this));
  970. _this4.code = 4;
  971. _this4.name = 'NOT_READY_ERROR';
  972. _this4.message = message;
  973. return _this4;
  974. }
  975. return NotReadyError;
  976. }(Error);
  977. module.exports = {
  978. ConfigurationError: ConfigurationError,
  979. InvalidStateError: InvalidStateError,
  980. NotSupportedError: NotSupportedError,
  981. NotReadyError: NotReadyError
  982. };
  983. },{}],7:[function(require,module,exports){
  984. 'use strict';
  985. module.exports = function () {
  986. /*
  987. * Generated by PEG.js 0.7.0.
  988. *
  989. * http://pegjs.majda.cz/
  990. */
  991. function quote(s) {
  992. /*
  993. * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
  994. * string literal except for the closing quote character, backslash,
  995. * carriage return, line separator, paragraph separator, and line feed.
  996. * Any character may appear in the form of an escape sequence.
  997. *
  998. * For portability, we also escape escape all control and non-ASCII
  999. * characters. Note that "\0" and "\v" escape sequences are not used
  1000. * because JSHint does not like the first and IE the second.
  1001. */
  1002. return '"' + s.replace(/\\/g, '\\\\') // backslash
  1003. .replace(/"/g, '\\"') // closing quote character
  1004. .replace(/\x08/g, '\\b') // backspace
  1005. .replace(/\t/g, '\\t') // horizontal tab
  1006. .replace(/\n/g, '\\n') // line feed
  1007. .replace(/\f/g, '\\f') // form feed
  1008. .replace(/\r/g, '\\r') // carriage return
  1009. .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"';
  1010. }
  1011. var result = {
  1012. /*
  1013. * Parses the input with a generated parser. If the parsing is successfull,
  1014. * returns a value explicitly or implicitly specified by the grammar from
  1015. * which the parser was generated (see |PEG.buildParser|). If the parsing is
  1016. * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
  1017. */
  1018. parse: function parse(input, startRule) {
  1019. var parseFunctions = {
  1020. "CRLF": parse_CRLF,
  1021. "DIGIT": parse_DIGIT,
  1022. "ALPHA": parse_ALPHA,
  1023. "HEXDIG": parse_HEXDIG,
  1024. "WSP": parse_WSP,
  1025. "OCTET": parse_OCTET,
  1026. "DQUOTE": parse_DQUOTE,
  1027. "SP": parse_SP,
  1028. "HTAB": parse_HTAB,
  1029. "alphanum": parse_alphanum,
  1030. "reserved": parse_reserved,
  1031. "unreserved": parse_unreserved,
  1032. "mark": parse_mark,
  1033. "escaped": parse_escaped,
  1034. "LWS": parse_LWS,
  1035. "SWS": parse_SWS,
  1036. "HCOLON": parse_HCOLON,
  1037. "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM,
  1038. "TEXT_UTF8char": parse_TEXT_UTF8char,
  1039. "UTF8_NONASCII": parse_UTF8_NONASCII,
  1040. "UTF8_CONT": parse_UTF8_CONT,
  1041. "LHEX": parse_LHEX,
  1042. "token": parse_token,
  1043. "token_nodot": parse_token_nodot,
  1044. "separators": parse_separators,
  1045. "word": parse_word,
  1046. "STAR": parse_STAR,
  1047. "SLASH": parse_SLASH,
  1048. "EQUAL": parse_EQUAL,
  1049. "LPAREN": parse_LPAREN,
  1050. "RPAREN": parse_RPAREN,
  1051. "RAQUOT": parse_RAQUOT,
  1052. "LAQUOT": parse_LAQUOT,
  1053. "COMMA": parse_COMMA,
  1054. "SEMI": parse_SEMI,
  1055. "COLON": parse_COLON,
  1056. "LDQUOT": parse_LDQUOT,
  1057. "RDQUOT": parse_RDQUOT,
  1058. "comment": parse_comment,
  1059. "ctext": parse_ctext,
  1060. "quoted_string": parse_quoted_string,
  1061. "quoted_string_clean": parse_quoted_string_clean,
  1062. "qdtext": parse_qdtext,
  1063. "quoted_pair": parse_quoted_pair,
  1064. "SIP_URI_noparams": parse_SIP_URI_noparams,
  1065. "SIP_URI": parse_SIP_URI,
  1066. "uri_scheme": parse_uri_scheme,
  1067. "uri_scheme_sips": parse_uri_scheme_sips,
  1068. "uri_scheme_sip": parse_uri_scheme_sip,
  1069. "userinfo": parse_userinfo,
  1070. "user": parse_user,
  1071. "user_unreserved": parse_user_unreserved,
  1072. "password": parse_password,
  1073. "hostport": parse_hostport,
  1074. "host": parse_host,
  1075. "hostname": parse_hostname,
  1076. "domainlabel": parse_domainlabel,
  1077. "toplabel": parse_toplabel,
  1078. "IPv6reference": parse_IPv6reference,
  1079. "IPv6address": parse_IPv6address,
  1080. "h16": parse_h16,
  1081. "ls32": parse_ls32,
  1082. "IPv4address": parse_IPv4address,
  1083. "dec_octet": parse_dec_octet,
  1084. "port": parse_port,
  1085. "uri_parameters": parse_uri_parameters,
  1086. "uri_parameter": parse_uri_parameter,
  1087. "transport_param": parse_transport_param,
  1088. "user_param": parse_user_param,
  1089. "method_param": parse_method_param,
  1090. "ttl_param": parse_ttl_param,
  1091. "maddr_param": parse_maddr_param,
  1092. "lr_param": parse_lr_param,
  1093. "other_param": parse_other_param,
  1094. "pname": parse_pname,
  1095. "pvalue": parse_pvalue,
  1096. "paramchar": parse_paramchar,
  1097. "param_unreserved": parse_param_unreserved,
  1098. "headers": parse_headers,
  1099. "header": parse_header,
  1100. "hname": parse_hname,
  1101. "hvalue": parse_hvalue,
  1102. "hnv_unreserved": parse_hnv_unreserved,
  1103. "Request_Response": parse_Request_Response,
  1104. "Request_Line": parse_Request_Line,
  1105. "Request_URI": parse_Request_URI,
  1106. "absoluteURI": parse_absoluteURI,
  1107. "hier_part": parse_hier_part,
  1108. "net_path": parse_net_path,
  1109. "abs_path": parse_abs_path,
  1110. "opaque_part": parse_opaque_part,
  1111. "uric": parse_uric,
  1112. "uric_no_slash": parse_uric_no_slash,
  1113. "path_segments": parse_path_segments,
  1114. "segment": parse_segment,
  1115. "param": parse_param,
  1116. "pchar": parse_pchar,
  1117. "scheme": parse_scheme,
  1118. "authority": parse_authority,
  1119. "srvr": parse_srvr,
  1120. "reg_name": parse_reg_name,
  1121. "query": parse_query,
  1122. "SIP_Version": parse_SIP_Version,
  1123. "INVITEm": parse_INVITEm,
  1124. "ACKm": parse_ACKm,
  1125. "OPTIONSm": parse_OPTIONSm,
  1126. "BYEm": parse_BYEm,
  1127. "CANCELm": parse_CANCELm,
  1128. "REGISTERm": parse_REGISTERm,
  1129. "SUBSCRIBEm": parse_SUBSCRIBEm,
  1130. "NOTIFYm": parse_NOTIFYm,
  1131. "REFERm": parse_REFERm,
  1132. "Method": parse_Method,
  1133. "Status_Line": parse_Status_Line,
  1134. "Status_Code": parse_Status_Code,
  1135. "extension_code": parse_extension_code,
  1136. "Reason_Phrase": parse_Reason_Phrase,
  1137. "Allow_Events": parse_Allow_Events,
  1138. "Call_ID": parse_Call_ID,
  1139. "Contact": parse_Contact,
  1140. "contact_param": parse_contact_param,
  1141. "name_addr": parse_name_addr,
  1142. "display_name": parse_display_name,
  1143. "contact_params": parse_contact_params,
  1144. "c_p_q": parse_c_p_q,
  1145. "c_p_expires": parse_c_p_expires,
  1146. "delta_seconds": parse_delta_seconds,
  1147. "qvalue": parse_qvalue,
  1148. "generic_param": parse_generic_param,
  1149. "gen_value": parse_gen_value,
  1150. "Content_Disposition": parse_Content_Disposition,
  1151. "disp_type": parse_disp_type,
  1152. "disp_param": parse_disp_param,
  1153. "handling_param": parse_handling_param,
  1154. "Content_Encoding": parse_Content_Encoding,
  1155. "Content_Length": parse_Content_Length,
  1156. "Content_Type": parse_Content_Type,
  1157. "media_type": parse_media_type,
  1158. "m_type": parse_m_type,
  1159. "discrete_type": parse_discrete_type,
  1160. "composite_type": parse_composite_type,
  1161. "extension_token": parse_extension_token,
  1162. "x_token": parse_x_token,
  1163. "m_subtype": parse_m_subtype,
  1164. "m_parameter": parse_m_parameter,
  1165. "m_value": parse_m_value,
  1166. "CSeq": parse_CSeq,
  1167. "CSeq_value": parse_CSeq_value,
  1168. "Expires": parse_Expires,
  1169. "Event": parse_Event,
  1170. "event_type": parse_event_type,
  1171. "From": parse_From,
  1172. "from_param": parse_from_param,
  1173. "tag_param": parse_tag_param,
  1174. "Max_Forwards": parse_Max_Forwards,
  1175. "Min_Expires": parse_Min_Expires,
  1176. "Name_Addr_Header": parse_Name_Addr_Header,
  1177. "Proxy_Authenticate": parse_Proxy_Authenticate,
  1178. "challenge": parse_challenge,
  1179. "other_challenge": parse_other_challenge,
  1180. "auth_param": parse_auth_param,
  1181. "digest_cln": parse_digest_cln,
  1182. "realm": parse_realm,
  1183. "realm_value": parse_realm_value,
  1184. "domain": parse_domain,
  1185. "URI": parse_URI,
  1186. "nonce": parse_nonce,
  1187. "nonce_value": parse_nonce_value,
  1188. "opaque": parse_opaque,
  1189. "stale": parse_stale,
  1190. "algorithm": parse_algorithm,
  1191. "qop_options": parse_qop_options,
  1192. "qop_value": parse_qop_value,
  1193. "Proxy_Require": parse_Proxy_Require,
  1194. "Record_Route": parse_Record_Route,
  1195. "rec_route": parse_rec_route,
  1196. "Reason": parse_Reason,
  1197. "reason_param": parse_reason_param,
  1198. "reason_cause": parse_reason_cause,
  1199. "Require": parse_Require,
  1200. "Route": parse_Route,
  1201. "route_param": parse_route_param,
  1202. "Subscription_State": parse_Subscription_State,
  1203. "substate_value": parse_substate_value,
  1204. "subexp_params": parse_subexp_params,
  1205. "event_reason_value": parse_event_reason_value,
  1206. "Subject": parse_Subject,
  1207. "Supported": parse_Supported,
  1208. "To": parse_To,
  1209. "to_param": parse_to_param,
  1210. "Via": parse_Via,
  1211. "via_param": parse_via_param,
  1212. "via_params": parse_via_params,
  1213. "via_ttl": parse_via_ttl,
  1214. "via_maddr": parse_via_maddr,
  1215. "via_received": parse_via_received,
  1216. "via_branch": parse_via_branch,
  1217. "response_port": parse_response_port,
  1218. "sent_protocol": parse_sent_protocol,
  1219. "protocol_name": parse_protocol_name,
  1220. "transport": parse_transport,
  1221. "sent_by": parse_sent_by,
  1222. "via_host": parse_via_host,
  1223. "via_port": parse_via_port,
  1224. "ttl": parse_ttl,
  1225. "WWW_Authenticate": parse_WWW_Authenticate,
  1226. "Session_Expires": parse_Session_Expires,
  1227. "s_e_expires": parse_s_e_expires,
  1228. "s_e_params": parse_s_e_params,
  1229. "s_e_refresher": parse_s_e_refresher,
  1230. "extension_header": parse_extension_header,
  1231. "header_value": parse_header_value,
  1232. "message_body": parse_message_body,
  1233. "uuid_URI": parse_uuid_URI,
  1234. "uuid": parse_uuid,
  1235. "hex4": parse_hex4,
  1236. "hex8": parse_hex8,
  1237. "hex12": parse_hex12,
  1238. "Refer_To": parse_Refer_To,
  1239. "Replaces": parse_Replaces,
  1240. "call_id": parse_call_id,
  1241. "replaces_param": parse_replaces_param,
  1242. "to_tag": parse_to_tag,
  1243. "from_tag": parse_from_tag,
  1244. "early_flag": parse_early_flag
  1245. };
  1246. if (startRule !== undefined) {
  1247. if (parseFunctions[startRule] === undefined) {
  1248. throw new Error("Invalid rule name: " + quote(startRule) + ".");
  1249. }
  1250. } else {
  1251. startRule = "CRLF";
  1252. }
  1253. var pos = 0;
  1254. var reportFailures = 0;
  1255. var rightmostFailuresPos = 0;
  1256. var rightmostFailuresExpected = [];
  1257. function padLeft(input, padding, length) {
  1258. var result = input;
  1259. var padLength = length - input.length;
  1260. for (var i = 0; i < padLength; i++) {
  1261. result = padding + result;
  1262. }
  1263. return result;
  1264. }
  1265. function escape(ch) {
  1266. var charCode = ch.charCodeAt(0);
  1267. var escapeChar;
  1268. var length;
  1269. if (charCode <= 0xFF) {
  1270. escapeChar = 'x';
  1271. length = 2;
  1272. } else {
  1273. escapeChar = 'u';
  1274. length = 4;
  1275. }
  1276. return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
  1277. }
  1278. function matchFailed(failure) {
  1279. if (pos < rightmostFailuresPos) {
  1280. return;
  1281. }
  1282. if (pos > rightmostFailuresPos) {
  1283. rightmostFailuresPos = pos;
  1284. rightmostFailuresExpected = [];
  1285. }
  1286. rightmostFailuresExpected.push(failure);
  1287. }
  1288. function parse_CRLF() {
  1289. var result0;
  1290. if (input.substr(pos, 2) === "\r\n") {
  1291. result0 = "\r\n";
  1292. pos += 2;
  1293. } else {
  1294. result0 = null;
  1295. if (reportFailures === 0) {
  1296. matchFailed("\"\\r\\n\"");
  1297. }
  1298. }
  1299. return result0;
  1300. }
  1301. function parse_DIGIT() {
  1302. var result0;
  1303. if (/^[0-9]/.test(input.charAt(pos))) {
  1304. result0 = input.charAt(pos);
  1305. pos++;
  1306. } else {
  1307. result0 = null;
  1308. if (reportFailures === 0) {
  1309. matchFailed("[0-9]");
  1310. }
  1311. }
  1312. return result0;
  1313. }
  1314. function parse_ALPHA() {
  1315. var result0;
  1316. if (/^[a-zA-Z]/.test(input.charAt(pos))) {
  1317. result0 = input.charAt(pos);
  1318. pos++;
  1319. } else {
  1320. result0 = null;
  1321. if (reportFailures === 0) {
  1322. matchFailed("[a-zA-Z]");
  1323. }
  1324. }
  1325. return result0;
  1326. }
  1327. function parse_HEXDIG() {
  1328. var result0;
  1329. if (/^[0-9a-fA-F]/.test(input.charAt(pos))) {
  1330. result0 = input.charAt(pos);
  1331. pos++;
  1332. } else {
  1333. result0 = null;
  1334. if (reportFailures === 0) {
  1335. matchFailed("[0-9a-fA-F]");
  1336. }
  1337. }
  1338. return result0;
  1339. }
  1340. function parse_WSP() {
  1341. var result0;
  1342. result0 = parse_SP();
  1343. if (result0 === null) {
  1344. result0 = parse_HTAB();
  1345. }
  1346. return result0;
  1347. }
  1348. function parse_OCTET() {
  1349. var result0;
  1350. if (/^[\0-\xFF]/.test(input.charAt(pos))) {
  1351. result0 = input.charAt(pos);
  1352. pos++;
  1353. } else {
  1354. result0 = null;
  1355. if (reportFailures === 0) {
  1356. matchFailed("[\\0-\\xFF]");
  1357. }
  1358. }
  1359. return result0;
  1360. }
  1361. function parse_DQUOTE() {
  1362. var result0;
  1363. if (/^["]/.test(input.charAt(pos))) {
  1364. result0 = input.charAt(pos);
  1365. pos++;
  1366. } else {
  1367. result0 = null;
  1368. if (reportFailures === 0) {
  1369. matchFailed("[\"]");
  1370. }
  1371. }
  1372. return result0;
  1373. }
  1374. function parse_SP() {
  1375. var result0;
  1376. if (input.charCodeAt(pos) === 32) {
  1377. result0 = " ";
  1378. pos++;
  1379. } else {
  1380. result0 = null;
  1381. if (reportFailures === 0) {
  1382. matchFailed("\" \"");
  1383. }
  1384. }
  1385. return result0;
  1386. }
  1387. function parse_HTAB() {
  1388. var result0;
  1389. if (input.charCodeAt(pos) === 9) {
  1390. result0 = "\t";
  1391. pos++;
  1392. } else {
  1393. result0 = null;
  1394. if (reportFailures === 0) {
  1395. matchFailed("\"\\t\"");
  1396. }
  1397. }
  1398. return result0;
  1399. }
  1400. function parse_alphanum() {
  1401. var result0;
  1402. if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) {
  1403. result0 = input.charAt(pos);
  1404. pos++;
  1405. } else {
  1406. result0 = null;
  1407. if (reportFailures === 0) {
  1408. matchFailed("[a-zA-Z0-9]");
  1409. }
  1410. }
  1411. return result0;
  1412. }
  1413. function parse_reserved() {
  1414. var result0;
  1415. if (input.charCodeAt(pos) === 59) {
  1416. result0 = ";";
  1417. pos++;
  1418. } else {
  1419. result0 = null;
  1420. if (reportFailures === 0) {
  1421. matchFailed("\";\"");
  1422. }
  1423. }
  1424. if (result0 === null) {
  1425. if (input.charCodeAt(pos) === 47) {
  1426. result0 = "/";
  1427. pos++;
  1428. } else {
  1429. result0 = null;
  1430. if (reportFailures === 0) {
  1431. matchFailed("\"/\"");
  1432. }
  1433. }
  1434. if (result0 === null) {
  1435. if (input.charCodeAt(pos) === 63) {
  1436. result0 = "?";
  1437. pos++;
  1438. } else {
  1439. result0 = null;
  1440. if (reportFailures === 0) {
  1441. matchFailed("\"?\"");
  1442. }
  1443. }
  1444. if (result0 === null) {
  1445. if (input.charCodeAt(pos) === 58) {
  1446. result0 = ":";
  1447. pos++;
  1448. } else {
  1449. result0 = null;
  1450. if (reportFailures === 0) {
  1451. matchFailed("\":\"");
  1452. }
  1453. }
  1454. if (result0 === null) {
  1455. if (input.charCodeAt(pos) === 64) {
  1456. result0 = "@";
  1457. pos++;
  1458. } else {
  1459. result0 = null;
  1460. if (reportFailures === 0) {
  1461. matchFailed("\"@\"");
  1462. }
  1463. }
  1464. if (result0 === null) {
  1465. if (input.charCodeAt(pos) === 38) {
  1466. result0 = "&";
  1467. pos++;
  1468. } else {
  1469. result0 = null;
  1470. if (reportFailures === 0) {
  1471. matchFailed("\"&\"");
  1472. }
  1473. }
  1474. if (result0 === null) {
  1475. if (input.charCodeAt(pos) === 61) {
  1476. result0 = "=";
  1477. pos++;
  1478. } else {
  1479. result0 = null;
  1480. if (reportFailures === 0) {
  1481. matchFailed("\"=\"");
  1482. }
  1483. }
  1484. if (result0 === null) {
  1485. if (input.charCodeAt(pos) === 43) {
  1486. result0 = "+";
  1487. pos++;
  1488. } else {
  1489. result0 = null;
  1490. if (reportFailures === 0) {
  1491. matchFailed("\"+\"");
  1492. }
  1493. }
  1494. if (result0 === null) {
  1495. if (input.charCodeAt(pos) === 36) {
  1496. result0 = "$";
  1497. pos++;
  1498. } else {
  1499. result0 = null;
  1500. if (reportFailures === 0) {
  1501. matchFailed("\"$\"");
  1502. }
  1503. }
  1504. if (result0 === null) {
  1505. if (input.charCodeAt(pos) === 44) {
  1506. result0 = ",";
  1507. pos++;
  1508. } else {
  1509. result0 = null;
  1510. if (reportFailures === 0) {
  1511. matchFailed("\",\"");
  1512. }
  1513. }
  1514. }
  1515. }
  1516. }
  1517. }
  1518. }
  1519. }
  1520. }
  1521. }
  1522. }
  1523. return result0;
  1524. }
  1525. function parse_unreserved() {
  1526. var result0;
  1527. result0 = parse_alphanum();
  1528. if (result0 === null) {
  1529. result0 = parse_mark();
  1530. }
  1531. return result0;
  1532. }
  1533. function parse_mark() {
  1534. var result0;
  1535. if (input.charCodeAt(pos) === 45) {
  1536. result0 = "-";
  1537. pos++;
  1538. } else {
  1539. result0 = null;
  1540. if (reportFailures === 0) {
  1541. matchFailed("\"-\"");
  1542. }
  1543. }
  1544. if (result0 === null) {
  1545. if (input.charCodeAt(pos) === 95) {
  1546. result0 = "_";
  1547. pos++;
  1548. } else {
  1549. result0 = null;
  1550. if (reportFailures === 0) {
  1551. matchFailed("\"_\"");
  1552. }
  1553. }
  1554. if (result0 === null) {
  1555. if (input.charCodeAt(pos) === 46) {
  1556. result0 = ".";
  1557. pos++;
  1558. } else {
  1559. result0 = null;
  1560. if (reportFailures === 0) {
  1561. matchFailed("\".\"");
  1562. }
  1563. }
  1564. if (result0 === null) {
  1565. if (input.charCodeAt(pos) === 33) {
  1566. result0 = "!";
  1567. pos++;
  1568. } else {
  1569. result0 = null;
  1570. if (reportFailures === 0) {
  1571. matchFailed("\"!\"");
  1572. }
  1573. }
  1574. if (result0 === null) {
  1575. if (input.charCodeAt(pos) === 126) {
  1576. result0 = "~";
  1577. pos++;
  1578. } else {
  1579. result0 = null;
  1580. if (reportFailures === 0) {
  1581. matchFailed("\"~\"");
  1582. }
  1583. }
  1584. if (result0 === null) {
  1585. if (input.charCodeAt(pos) === 42) {
  1586. result0 = "*";
  1587. pos++;
  1588. } else {
  1589. result0 = null;
  1590. if (reportFailures === 0) {
  1591. matchFailed("\"*\"");
  1592. }
  1593. }
  1594. if (result0 === null) {
  1595. if (input.charCodeAt(pos) === 39) {
  1596. result0 = "'";
  1597. pos++;
  1598. } else {
  1599. result0 = null;
  1600. if (reportFailures === 0) {
  1601. matchFailed("\"'\"");
  1602. }
  1603. }
  1604. if (result0 === null) {
  1605. if (input.charCodeAt(pos) === 40) {
  1606. result0 = "(";
  1607. pos++;
  1608. } else {
  1609. result0 = null;
  1610. if (reportFailures === 0) {
  1611. matchFailed("\"(\"");
  1612. }
  1613. }
  1614. if (result0 === null) {
  1615. if (input.charCodeAt(pos) === 41) {
  1616. result0 = ")";
  1617. pos++;
  1618. } else {
  1619. result0 = null;
  1620. if (reportFailures === 0) {
  1621. matchFailed("\")\"");
  1622. }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. }
  1630. }
  1631. }
  1632. return result0;
  1633. }
  1634. function parse_escaped() {
  1635. var result0, result1, result2;
  1636. var pos0, pos1;
  1637. pos0 = pos;
  1638. pos1 = pos;
  1639. if (input.charCodeAt(pos) === 37) {
  1640. result0 = "%";
  1641. pos++;
  1642. } else {
  1643. result0 = null;
  1644. if (reportFailures === 0) {
  1645. matchFailed("\"%\"");
  1646. }
  1647. }
  1648. if (result0 !== null) {
  1649. result1 = parse_HEXDIG();
  1650. if (result1 !== null) {
  1651. result2 = parse_HEXDIG();
  1652. if (result2 !== null) {
  1653. result0 = [result0, result1, result2];
  1654. } else {
  1655. result0 = null;
  1656. pos = pos1;
  1657. }
  1658. } else {
  1659. result0 = null;
  1660. pos = pos1;
  1661. }
  1662. } else {
  1663. result0 = null;
  1664. pos = pos1;
  1665. }
  1666. if (result0 !== null) {
  1667. result0 = function (offset, escaped) {
  1668. return escaped.join('');
  1669. }(pos0, result0);
  1670. }
  1671. if (result0 === null) {
  1672. pos = pos0;
  1673. }
  1674. return result0;
  1675. }
  1676. function parse_LWS() {
  1677. var result0, result1, result2;
  1678. var pos0, pos1, pos2;
  1679. pos0 = pos;
  1680. pos1 = pos;
  1681. pos2 = pos;
  1682. result0 = [];
  1683. result1 = parse_WSP();
  1684. while (result1 !== null) {
  1685. result0.push(result1);
  1686. result1 = parse_WSP();
  1687. }
  1688. if (result0 !== null) {
  1689. result1 = parse_CRLF();
  1690. if (result1 !== null) {
  1691. result0 = [result0, result1];
  1692. } else {
  1693. result0 = null;
  1694. pos = pos2;
  1695. }
  1696. } else {
  1697. result0 = null;
  1698. pos = pos2;
  1699. }
  1700. result0 = result0 !== null ? result0 : "";
  1701. if (result0 !== null) {
  1702. result2 = parse_WSP();
  1703. if (result2 !== null) {
  1704. result1 = [];
  1705. while (result2 !== null) {
  1706. result1.push(result2);
  1707. result2 = parse_WSP();
  1708. }
  1709. } else {
  1710. result1 = null;
  1711. }
  1712. if (result1 !== null) {
  1713. result0 = [result0, result1];
  1714. } else {
  1715. result0 = null;
  1716. pos = pos1;
  1717. }
  1718. } else {
  1719. result0 = null;
  1720. pos = pos1;
  1721. }
  1722. if (result0 !== null) {
  1723. result0 = function (offset) {
  1724. return " ";
  1725. }(pos0);
  1726. }
  1727. if (result0 === null) {
  1728. pos = pos0;
  1729. }
  1730. return result0;
  1731. }
  1732. function parse_SWS() {
  1733. var result0;
  1734. result0 = parse_LWS();
  1735. result0 = result0 !== null ? result0 : "";
  1736. return result0;
  1737. }
  1738. function parse_HCOLON() {
  1739. var result0, result1, result2;
  1740. var pos0, pos1;
  1741. pos0 = pos;
  1742. pos1 = pos;
  1743. result0 = [];
  1744. result1 = parse_SP();
  1745. if (result1 === null) {
  1746. result1 = parse_HTAB();
  1747. }
  1748. while (result1 !== null) {
  1749. result0.push(result1);
  1750. result1 = parse_SP();
  1751. if (result1 === null) {
  1752. result1 = parse_HTAB();
  1753. }
  1754. }
  1755. if (result0 !== null) {
  1756. if (input.charCodeAt(pos) === 58) {
  1757. result1 = ":";
  1758. pos++;
  1759. } else {
  1760. result1 = null;
  1761. if (reportFailures === 0) {
  1762. matchFailed("\":\"");
  1763. }
  1764. }
  1765. if (result1 !== null) {
  1766. result2 = parse_SWS();
  1767. if (result2 !== null) {
  1768. result0 = [result0, result1, result2];
  1769. } else {
  1770. result0 = null;
  1771. pos = pos1;
  1772. }
  1773. } else {
  1774. result0 = null;
  1775. pos = pos1;
  1776. }
  1777. } else {
  1778. result0 = null;
  1779. pos = pos1;
  1780. }
  1781. if (result0 !== null) {
  1782. result0 = function (offset) {
  1783. return ':';
  1784. }(pos0);
  1785. }
  1786. if (result0 === null) {
  1787. pos = pos0;
  1788. }
  1789. return result0;
  1790. }
  1791. function parse_TEXT_UTF8_TRIM() {
  1792. var result0, result1, result2, result3;
  1793. var pos0, pos1, pos2;
  1794. pos0 = pos;
  1795. pos1 = pos;
  1796. result1 = parse_TEXT_UTF8char();
  1797. if (result1 !== null) {
  1798. result0 = [];
  1799. while (result1 !== null) {
  1800. result0.push(result1);
  1801. result1 = parse_TEXT_UTF8char();
  1802. }
  1803. } else {
  1804. result0 = null;
  1805. }
  1806. if (result0 !== null) {
  1807. result1 = [];
  1808. pos2 = pos;
  1809. result2 = [];
  1810. result3 = parse_LWS();
  1811. while (result3 !== null) {
  1812. result2.push(result3);
  1813. result3 = parse_LWS();
  1814. }
  1815. if (result2 !== null) {
  1816. result3 = parse_TEXT_UTF8char();
  1817. if (result3 !== null) {
  1818. result2 = [result2, result3];
  1819. } else {
  1820. result2 = null;
  1821. pos = pos2;
  1822. }
  1823. } else {
  1824. result2 = null;
  1825. pos = pos2;
  1826. }
  1827. while (result2 !== null) {
  1828. result1.push(result2);
  1829. pos2 = pos;
  1830. result2 = [];
  1831. result3 = parse_LWS();
  1832. while (result3 !== null) {
  1833. result2.push(result3);
  1834. result3 = parse_LWS();
  1835. }
  1836. if (result2 !== null) {
  1837. result3 = parse_TEXT_UTF8char();
  1838. if (result3 !== null) {
  1839. result2 = [result2, result3];
  1840. } else {
  1841. result2 = null;
  1842. pos = pos2;
  1843. }
  1844. } else {
  1845. result2 = null;
  1846. pos = pos2;
  1847. }
  1848. }
  1849. if (result1 !== null) {
  1850. result0 = [result0, result1];
  1851. } else {
  1852. result0 = null;
  1853. pos = pos1;
  1854. }
  1855. } else {
  1856. result0 = null;
  1857. pos = pos1;
  1858. }
  1859. if (result0 !== null) {
  1860. result0 = function (offset) {
  1861. return input.substring(pos, offset);
  1862. }(pos0);
  1863. }
  1864. if (result0 === null) {
  1865. pos = pos0;
  1866. }
  1867. return result0;
  1868. }
  1869. function parse_TEXT_UTF8char() {
  1870. var result0;
  1871. if (/^[!-~]/.test(input.charAt(pos))) {
  1872. result0 = input.charAt(pos);
  1873. pos++;
  1874. } else {
  1875. result0 = null;
  1876. if (reportFailures === 0) {
  1877. matchFailed("[!-~]");
  1878. }
  1879. }
  1880. if (result0 === null) {
  1881. result0 = parse_UTF8_NONASCII();
  1882. }
  1883. return result0;
  1884. }
  1885. function parse_UTF8_NONASCII() {
  1886. var result0;
  1887. if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) {
  1888. result0 = input.charAt(pos);
  1889. pos++;
  1890. } else {
  1891. result0 = null;
  1892. if (reportFailures === 0) {
  1893. matchFailed('[\\x80-\\uFFFF]');
  1894. }
  1895. }
  1896. return result0;
  1897. }
  1898. function parse_UTF8_CONT() {
  1899. var result0;
  1900. if (/^[\x80-\xBF]/.test(input.charAt(pos))) {
  1901. result0 = input.charAt(pos);
  1902. pos++;
  1903. } else {
  1904. result0 = null;
  1905. if (reportFailures === 0) {
  1906. matchFailed("[\\x80-\\xBF]");
  1907. }
  1908. }
  1909. return result0;
  1910. }
  1911. function parse_LHEX() {
  1912. var result0;
  1913. result0 = parse_DIGIT();
  1914. if (result0 === null) {
  1915. if (/^[a-f]/.test(input.charAt(pos))) {
  1916. result0 = input.charAt(pos);
  1917. pos++;
  1918. } else {
  1919. result0 = null;
  1920. if (reportFailures === 0) {
  1921. matchFailed("[a-f]");
  1922. }
  1923. }
  1924. }
  1925. return result0;
  1926. }
  1927. function parse_token() {
  1928. var result0, result1;
  1929. var pos0;
  1930. pos0 = pos;
  1931. result1 = parse_alphanum();
  1932. if (result1 === null) {
  1933. if (input.charCodeAt(pos) === 45) {
  1934. result1 = "-";
  1935. pos++;
  1936. } else {
  1937. result1 = null;
  1938. if (reportFailures === 0) {
  1939. matchFailed("\"-\"");
  1940. }
  1941. }
  1942. if (result1 === null) {
  1943. if (input.charCodeAt(pos) === 46) {
  1944. result1 = ".";
  1945. pos++;
  1946. } else {
  1947. result1 = null;
  1948. if (reportFailures === 0) {
  1949. matchFailed("\".\"");
  1950. }
  1951. }
  1952. if (result1 === null) {
  1953. if (input.charCodeAt(pos) === 33) {
  1954. result1 = "!";
  1955. pos++;
  1956. } else {
  1957. result1 = null;
  1958. if (reportFailures === 0) {
  1959. matchFailed("\"!\"");
  1960. }
  1961. }
  1962. if (result1 === null) {
  1963. if (input.charCodeAt(pos) === 37) {
  1964. result1 = "%";
  1965. pos++;
  1966. } else {
  1967. result1 = null;
  1968. if (reportFailures === 0) {
  1969. matchFailed("\"%\"");
  1970. }
  1971. }
  1972. if (result1 === null) {
  1973. if (input.charCodeAt(pos) === 42) {
  1974. result1 = "*";
  1975. pos++;
  1976. } else {
  1977. result1 = null;
  1978. if (reportFailures === 0) {
  1979. matchFailed("\"*\"");
  1980. }
  1981. }
  1982. if (result1 === null) {
  1983. if (input.charCodeAt(pos) === 95) {
  1984. result1 = "_";
  1985. pos++;
  1986. } else {
  1987. result1 = null;
  1988. if (reportFailures === 0) {
  1989. matchFailed("\"_\"");
  1990. }
  1991. }
  1992. if (result1 === null) {
  1993. if (input.charCodeAt(pos) === 43) {
  1994. result1 = "+";
  1995. pos++;
  1996. } else {
  1997. result1 = null;
  1998. if (reportFailures === 0) {
  1999. matchFailed("\"+\"");
  2000. }
  2001. }
  2002. if (result1 === null) {
  2003. if (input.charCodeAt(pos) === 96) {
  2004. result1 = "`";
  2005. pos++;
  2006. } else {
  2007. result1 = null;
  2008. if (reportFailures === 0) {
  2009. matchFailed("\"`\"");
  2010. }
  2011. }
  2012. if (result1 === null) {
  2013. if (input.charCodeAt(pos) === 39) {
  2014. result1 = "'";
  2015. pos++;
  2016. } else {
  2017. result1 = null;
  2018. if (reportFailures === 0) {
  2019. matchFailed("\"'\"");
  2020. }
  2021. }
  2022. if (result1 === null) {
  2023. if (input.charCodeAt(pos) === 126) {
  2024. result1 = "~";
  2025. pos++;
  2026. } else {
  2027. result1 = null;
  2028. if (reportFailures === 0) {
  2029. matchFailed("\"~\"");
  2030. }
  2031. }
  2032. }
  2033. }
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. }
  2040. }
  2041. }
  2042. if (result1 !== null) {
  2043. result0 = [];
  2044. while (result1 !== null) {
  2045. result0.push(result1);
  2046. result1 = parse_alphanum();
  2047. if (result1 === null) {
  2048. if (input.charCodeAt(pos) === 45) {
  2049. result1 = "-";
  2050. pos++;
  2051. } else {
  2052. result1 = null;
  2053. if (reportFailures === 0) {
  2054. matchFailed("\"-\"");
  2055. }
  2056. }
  2057. if (result1 === null) {
  2058. if (input.charCodeAt(pos) === 46) {
  2059. result1 = ".";
  2060. pos++;
  2061. } else {
  2062. result1 = null;
  2063. if (reportFailures === 0) {
  2064. matchFailed("\".\"");
  2065. }
  2066. }
  2067. if (result1 === null) {
  2068. if (input.charCodeAt(pos) === 33) {
  2069. result1 = "!";
  2070. pos++;
  2071. } else {
  2072. result1 = null;
  2073. if (reportFailures === 0) {
  2074. matchFailed("\"!\"");
  2075. }
  2076. }
  2077. if (result1 === null) {
  2078. if (input.charCodeAt(pos) === 37) {
  2079. result1 = "%";
  2080. pos++;
  2081. } else {
  2082. result1 = null;
  2083. if (reportFailures === 0) {
  2084. matchFailed("\"%\"");
  2085. }
  2086. }
  2087. if (result1 === null) {
  2088. if (input.charCodeAt(pos) === 42) {
  2089. result1 = "*";
  2090. pos++;
  2091. } else {
  2092. result1 = null;
  2093. if (reportFailures === 0) {
  2094. matchFailed("\"*\"");
  2095. }
  2096. }
  2097. if (result1 === null) {
  2098. if (input.charCodeAt(pos) === 95) {
  2099. result1 = "_";
  2100. pos++;
  2101. } else {
  2102. result1 = null;
  2103. if (reportFailures === 0) {
  2104. matchFailed("\"_\"");
  2105. }
  2106. }
  2107. if (result1 === null) {
  2108. if (input.charCodeAt(pos) === 43) {
  2109. result1 = "+";
  2110. pos++;
  2111. } else {
  2112. result1 = null;
  2113. if (reportFailures === 0) {
  2114. matchFailed("\"+\"");
  2115. }
  2116. }
  2117. if (result1 === null) {
  2118. if (input.charCodeAt(pos) === 96) {
  2119. result1 = "`";
  2120. pos++;
  2121. } else {
  2122. result1 = null;
  2123. if (reportFailures === 0) {
  2124. matchFailed("\"`\"");
  2125. }
  2126. }
  2127. if (result1 === null) {
  2128. if (input.charCodeAt(pos) === 39) {
  2129. result1 = "'";
  2130. pos++;
  2131. } else {
  2132. result1 = null;
  2133. if (reportFailures === 0) {
  2134. matchFailed("\"'\"");
  2135. }
  2136. }
  2137. if (result1 === null) {
  2138. if (input.charCodeAt(pos) === 126) {
  2139. result1 = "~";
  2140. pos++;
  2141. } else {
  2142. result1 = null;
  2143. if (reportFailures === 0) {
  2144. matchFailed("\"~\"");
  2145. }
  2146. }
  2147. }
  2148. }
  2149. }
  2150. }
  2151. }
  2152. }
  2153. }
  2154. }
  2155. }
  2156. }
  2157. }
  2158. } else {
  2159. result0 = null;
  2160. }
  2161. if (result0 !== null) {
  2162. result0 = function (offset) {
  2163. return input.substring(pos, offset);
  2164. }(pos0);
  2165. }
  2166. if (result0 === null) {
  2167. pos = pos0;
  2168. }
  2169. return result0;
  2170. }
  2171. function parse_token_nodot() {
  2172. var result0, result1;
  2173. var pos0;
  2174. pos0 = pos;
  2175. result1 = parse_alphanum();
  2176. if (result1 === null) {
  2177. if (input.charCodeAt(pos) === 45) {
  2178. result1 = "-";
  2179. pos++;
  2180. } else {
  2181. result1 = null;
  2182. if (reportFailures === 0) {
  2183. matchFailed("\"-\"");
  2184. }
  2185. }
  2186. if (result1 === null) {
  2187. if (input.charCodeAt(pos) === 33) {
  2188. result1 = "!";
  2189. pos++;
  2190. } else {
  2191. result1 = null;
  2192. if (reportFailures === 0) {
  2193. matchFailed("\"!\"");
  2194. }
  2195. }
  2196. if (result1 === null) {
  2197. if (input.charCodeAt(pos) === 37) {
  2198. result1 = "%";
  2199. pos++;
  2200. } else {
  2201. result1 = null;
  2202. if (reportFailures === 0) {
  2203. matchFailed("\"%\"");
  2204. }
  2205. }
  2206. if (result1 === null) {
  2207. if (input.charCodeAt(pos) === 42) {
  2208. result1 = "*";
  2209. pos++;
  2210. } else {
  2211. result1 = null;
  2212. if (reportFailures === 0) {
  2213. matchFailed("\"*\"");
  2214. }
  2215. }
  2216. if (result1 === null) {
  2217. if (input.charCodeAt(pos) === 95) {
  2218. result1 = "_";
  2219. pos++;
  2220. } else {
  2221. result1 = null;
  2222. if (reportFailures === 0) {
  2223. matchFailed("\"_\"");
  2224. }
  2225. }
  2226. if (result1 === null) {
  2227. if (input.charCodeAt(pos) === 43) {
  2228. result1 = "+";
  2229. pos++;
  2230. } else {
  2231. result1 = null;
  2232. if (reportFailures === 0) {
  2233. matchFailed("\"+\"");
  2234. }
  2235. }
  2236. if (result1 === null) {
  2237. if (input.charCodeAt(pos) === 96) {
  2238. result1 = "`";
  2239. pos++;
  2240. } else {
  2241. result1 = null;
  2242. if (reportFailures === 0) {
  2243. matchFailed("\"`\"");
  2244. }
  2245. }
  2246. if (result1 === null) {
  2247. if (input.charCodeAt(pos) === 39) {
  2248. result1 = "'";
  2249. pos++;
  2250. } else {
  2251. result1 = null;
  2252. if (reportFailures === 0) {
  2253. matchFailed("\"'\"");
  2254. }
  2255. }
  2256. if (result1 === null) {
  2257. if (input.charCodeAt(pos) === 126) {
  2258. result1 = "~";
  2259. pos++;
  2260. } else {
  2261. result1 = null;
  2262. if (reportFailures === 0) {
  2263. matchFailed("\"~\"");
  2264. }
  2265. }
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. }
  2275. if (result1 !== null) {
  2276. result0 = [];
  2277. while (result1 !== null) {
  2278. result0.push(result1);
  2279. result1 = parse_alphanum();
  2280. if (result1 === null) {
  2281. if (input.charCodeAt(pos) === 45) {
  2282. result1 = "-";
  2283. pos++;
  2284. } else {
  2285. result1 = null;
  2286. if (reportFailures === 0) {
  2287. matchFailed("\"-\"");
  2288. }
  2289. }
  2290. if (result1 === null) {
  2291. if (input.charCodeAt(pos) === 33) {
  2292. result1 = "!";
  2293. pos++;
  2294. } else {
  2295. result1 = null;
  2296. if (reportFailures === 0) {
  2297. matchFailed("\"!\"");
  2298. }
  2299. }
  2300. if (result1 === null) {
  2301. if (input.charCodeAt(pos) === 37) {
  2302. result1 = "%";
  2303. pos++;
  2304. } else {
  2305. result1 = null;
  2306. if (reportFailures === 0) {
  2307. matchFailed("\"%\"");
  2308. }
  2309. }
  2310. if (result1 === null) {
  2311. if (input.charCodeAt(pos) === 42) {
  2312. result1 = "*";
  2313. pos++;
  2314. } else {
  2315. result1 = null;
  2316. if (reportFailures === 0) {
  2317. matchFailed("\"*\"");
  2318. }
  2319. }
  2320. if (result1 === null) {
  2321. if (input.charCodeAt(pos) === 95) {
  2322. result1 = "_";
  2323. pos++;
  2324. } else {
  2325. result1 = null;
  2326. if (reportFailures === 0) {
  2327. matchFailed("\"_\"");
  2328. }
  2329. }
  2330. if (result1 === null) {
  2331. if (input.charCodeAt(pos) === 43) {
  2332. result1 = "+";
  2333. pos++;
  2334. } else {
  2335. result1 = null;
  2336. if (reportFailures === 0) {
  2337. matchFailed("\"+\"");
  2338. }
  2339. }
  2340. if (result1 === null) {
  2341. if (input.charCodeAt(pos) === 96) {
  2342. result1 = "`";
  2343. pos++;
  2344. } else {
  2345. result1 = null;
  2346. if (reportFailures === 0) {
  2347. matchFailed("\"`\"");
  2348. }
  2349. }
  2350. if (result1 === null) {
  2351. if (input.charCodeAt(pos) === 39) {
  2352. result1 = "'";
  2353. pos++;
  2354. } else {
  2355. result1 = null;
  2356. if (reportFailures === 0) {
  2357. matchFailed("\"'\"");
  2358. }
  2359. }
  2360. if (result1 === null) {
  2361. if (input.charCodeAt(pos) === 126) {
  2362. result1 = "~";
  2363. pos++;
  2364. } else {
  2365. result1 = null;
  2366. if (reportFailures === 0) {
  2367. matchFailed("\"~\"");
  2368. }
  2369. }
  2370. }
  2371. }
  2372. }
  2373. }
  2374. }
  2375. }
  2376. }
  2377. }
  2378. }
  2379. }
  2380. } else {
  2381. result0 = null;
  2382. }
  2383. if (result0 !== null) {
  2384. result0 = function (offset) {
  2385. return input.substring(pos, offset);
  2386. }(pos0);
  2387. }
  2388. if (result0 === null) {
  2389. pos = pos0;
  2390. }
  2391. return result0;
  2392. }
  2393. function parse_separators() {
  2394. var result0;
  2395. if (input.charCodeAt(pos) === 40) {
  2396. result0 = "(";
  2397. pos++;
  2398. } else {
  2399. result0 = null;
  2400. if (reportFailures === 0) {
  2401. matchFailed("\"(\"");
  2402. }
  2403. }
  2404. if (result0 === null) {
  2405. if (input.charCodeAt(pos) === 41) {
  2406. result0 = ")";
  2407. pos++;
  2408. } else {
  2409. result0 = null;
  2410. if (reportFailures === 0) {
  2411. matchFailed("\")\"");
  2412. }
  2413. }
  2414. if (result0 === null) {
  2415. if (input.charCodeAt(pos) === 60) {
  2416. result0 = "<";
  2417. pos++;
  2418. } else {
  2419. result0 = null;
  2420. if (reportFailures === 0) {
  2421. matchFailed("\"<\"");
  2422. }
  2423. }
  2424. if (result0 === null) {
  2425. if (input.charCodeAt(pos) === 62) {
  2426. result0 = ">";
  2427. pos++;
  2428. } else {
  2429. result0 = null;
  2430. if (reportFailures === 0) {
  2431. matchFailed("\">\"");
  2432. }
  2433. }
  2434. if (result0 === null) {
  2435. if (input.charCodeAt(pos) === 64) {
  2436. result0 = "@";
  2437. pos++;
  2438. } else {
  2439. result0 = null;
  2440. if (reportFailures === 0) {
  2441. matchFailed("\"@\"");
  2442. }
  2443. }
  2444. if (result0 === null) {
  2445. if (input.charCodeAt(pos) === 44) {
  2446. result0 = ",";
  2447. pos++;
  2448. } else {
  2449. result0 = null;
  2450. if (reportFailures === 0) {
  2451. matchFailed("\",\"");
  2452. }
  2453. }
  2454. if (result0 === null) {
  2455. if (input.charCodeAt(pos) === 59) {
  2456. result0 = ";";
  2457. pos++;
  2458. } else {
  2459. result0 = null;
  2460. if (reportFailures === 0) {
  2461. matchFailed("\";\"");
  2462. }
  2463. }
  2464. if (result0 === null) {
  2465. if (input.charCodeAt(pos) === 58) {
  2466. result0 = ":";
  2467. pos++;
  2468. } else {
  2469. result0 = null;
  2470. if (reportFailures === 0) {
  2471. matchFailed("\":\"");
  2472. }
  2473. }
  2474. if (result0 === null) {
  2475. if (input.charCodeAt(pos) === 92) {
  2476. result0 = "\\";
  2477. pos++;
  2478. } else {
  2479. result0 = null;
  2480. if (reportFailures === 0) {
  2481. matchFailed("\"\\\\\"");
  2482. }
  2483. }
  2484. if (result0 === null) {
  2485. result0 = parse_DQUOTE();
  2486. if (result0 === null) {
  2487. if (input.charCodeAt(pos) === 47) {
  2488. result0 = "/";
  2489. pos++;
  2490. } else {
  2491. result0 = null;
  2492. if (reportFailures === 0) {
  2493. matchFailed("\"/\"");
  2494. }
  2495. }
  2496. if (result0 === null) {
  2497. if (input.charCodeAt(pos) === 91) {
  2498. result0 = "[";
  2499. pos++;
  2500. } else {
  2501. result0 = null;
  2502. if (reportFailures === 0) {
  2503. matchFailed("\"[\"");
  2504. }
  2505. }
  2506. if (result0 === null) {
  2507. if (input.charCodeAt(pos) === 93) {
  2508. result0 = "]";
  2509. pos++;
  2510. } else {
  2511. result0 = null;
  2512. if (reportFailures === 0) {
  2513. matchFailed("\"]\"");
  2514. }
  2515. }
  2516. if (result0 === null) {
  2517. if (input.charCodeAt(pos) === 63) {
  2518. result0 = "?";
  2519. pos++;
  2520. } else {
  2521. result0 = null;
  2522. if (reportFailures === 0) {
  2523. matchFailed("\"?\"");
  2524. }
  2525. }
  2526. if (result0 === null) {
  2527. if (input.charCodeAt(pos) === 61) {
  2528. result0 = "=";
  2529. pos++;
  2530. } else {
  2531. result0 = null;
  2532. if (reportFailures === 0) {
  2533. matchFailed("\"=\"");
  2534. }
  2535. }
  2536. if (result0 === null) {
  2537. if (input.charCodeAt(pos) === 123) {
  2538. result0 = "{";
  2539. pos++;
  2540. } else {
  2541. result0 = null;
  2542. if (reportFailures === 0) {
  2543. matchFailed("\"{\"");
  2544. }
  2545. }
  2546. if (result0 === null) {
  2547. if (input.charCodeAt(pos) === 125) {
  2548. result0 = "}";
  2549. pos++;
  2550. } else {
  2551. result0 = null;
  2552. if (reportFailures === 0) {
  2553. matchFailed("\"}\"");
  2554. }
  2555. }
  2556. if (result0 === null) {
  2557. result0 = parse_SP();
  2558. if (result0 === null) {
  2559. result0 = parse_HTAB();
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. }
  2571. }
  2572. }
  2573. }
  2574. }
  2575. }
  2576. }
  2577. }
  2578. return result0;
  2579. }
  2580. function parse_word() {
  2581. var result0, result1;
  2582. var pos0;
  2583. pos0 = pos;
  2584. result1 = parse_alphanum();
  2585. if (result1 === null) {
  2586. if (input.charCodeAt(pos) === 45) {
  2587. result1 = "-";
  2588. pos++;
  2589. } else {
  2590. result1 = null;
  2591. if (reportFailures === 0) {
  2592. matchFailed("\"-\"");
  2593. }
  2594. }
  2595. if (result1 === null) {
  2596. if (input.charCodeAt(pos) === 46) {
  2597. result1 = ".";
  2598. pos++;
  2599. } else {
  2600. result1 = null;
  2601. if (reportFailures === 0) {
  2602. matchFailed("\".\"");
  2603. }
  2604. }
  2605. if (result1 === null) {
  2606. if (input.charCodeAt(pos) === 33) {
  2607. result1 = "!";
  2608. pos++;
  2609. } else {
  2610. result1 = null;
  2611. if (reportFailures === 0) {
  2612. matchFailed("\"!\"");
  2613. }
  2614. }
  2615. if (result1 === null) {
  2616. if (input.charCodeAt(pos) === 37) {
  2617. result1 = "%";
  2618. pos++;
  2619. } else {
  2620. result1 = null;
  2621. if (reportFailures === 0) {
  2622. matchFailed("\"%\"");
  2623. }
  2624. }
  2625. if (result1 === null) {
  2626. if (input.charCodeAt(pos) === 42) {
  2627. result1 = "*";
  2628. pos++;
  2629. } else {
  2630. result1 = null;
  2631. if (reportFailures === 0) {
  2632. matchFailed("\"*\"");
  2633. }
  2634. }
  2635. if (result1 === null) {
  2636. if (input.charCodeAt(pos) === 95) {
  2637. result1 = "_";
  2638. pos++;
  2639. } else {
  2640. result1 = null;
  2641. if (reportFailures === 0) {
  2642. matchFailed("\"_\"");
  2643. }
  2644. }
  2645. if (result1 === null) {
  2646. if (input.charCodeAt(pos) === 43) {
  2647. result1 = "+";
  2648. pos++;
  2649. } else {
  2650. result1 = null;
  2651. if (reportFailures === 0) {
  2652. matchFailed("\"+\"");
  2653. }
  2654. }
  2655. if (result1 === null) {
  2656. if (input.charCodeAt(pos) === 96) {
  2657. result1 = "`";
  2658. pos++;
  2659. } else {
  2660. result1 = null;
  2661. if (reportFailures === 0) {
  2662. matchFailed("\"`\"");
  2663. }
  2664. }
  2665. if (result1 === null) {
  2666. if (input.charCodeAt(pos) === 39) {
  2667. result1 = "'";
  2668. pos++;
  2669. } else {
  2670. result1 = null;
  2671. if (reportFailures === 0) {
  2672. matchFailed("\"'\"");
  2673. }
  2674. }
  2675. if (result1 === null) {
  2676. if (input.charCodeAt(pos) === 126) {
  2677. result1 = "~";
  2678. pos++;
  2679. } else {
  2680. result1 = null;
  2681. if (reportFailures === 0) {
  2682. matchFailed("\"~\"");
  2683. }
  2684. }
  2685. if (result1 === null) {
  2686. if (input.charCodeAt(pos) === 40) {
  2687. result1 = "(";
  2688. pos++;
  2689. } else {
  2690. result1 = null;
  2691. if (reportFailures === 0) {
  2692. matchFailed("\"(\"");
  2693. }
  2694. }
  2695. if (result1 === null) {
  2696. if (input.charCodeAt(pos) === 41) {
  2697. result1 = ")";
  2698. pos++;
  2699. } else {
  2700. result1 = null;
  2701. if (reportFailures === 0) {
  2702. matchFailed("\")\"");
  2703. }
  2704. }
  2705. if (result1 === null) {
  2706. if (input.charCodeAt(pos) === 60) {
  2707. result1 = "<";
  2708. pos++;
  2709. } else {
  2710. result1 = null;
  2711. if (reportFailures === 0) {
  2712. matchFailed("\"<\"");
  2713. }
  2714. }
  2715. if (result1 === null) {
  2716. if (input.charCodeAt(pos) === 62) {
  2717. result1 = ">";
  2718. pos++;
  2719. } else {
  2720. result1 = null;
  2721. if (reportFailures === 0) {
  2722. matchFailed("\">\"");
  2723. }
  2724. }
  2725. if (result1 === null) {
  2726. if (input.charCodeAt(pos) === 58) {
  2727. result1 = ":";
  2728. pos++;
  2729. } else {
  2730. result1 = null;
  2731. if (reportFailures === 0) {
  2732. matchFailed("\":\"");
  2733. }
  2734. }
  2735. if (result1 === null) {
  2736. if (input.charCodeAt(pos) === 92) {
  2737. result1 = "\\";
  2738. pos++;
  2739. } else {
  2740. result1 = null;
  2741. if (reportFailures === 0) {
  2742. matchFailed("\"\\\\\"");
  2743. }
  2744. }
  2745. if (result1 === null) {
  2746. result1 = parse_DQUOTE();
  2747. if (result1 === null) {
  2748. if (input.charCodeAt(pos) === 47) {
  2749. result1 = "/";
  2750. pos++;
  2751. } else {
  2752. result1 = null;
  2753. if (reportFailures === 0) {
  2754. matchFailed("\"/\"");
  2755. }
  2756. }
  2757. if (result1 === null) {
  2758. if (input.charCodeAt(pos) === 91) {
  2759. result1 = "[";
  2760. pos++;
  2761. } else {
  2762. result1 = null;
  2763. if (reportFailures === 0) {
  2764. matchFailed("\"[\"");
  2765. }
  2766. }
  2767. if (result1 === null) {
  2768. if (input.charCodeAt(pos) === 93) {
  2769. result1 = "]";
  2770. pos++;
  2771. } else {
  2772. result1 = null;
  2773. if (reportFailures === 0) {
  2774. matchFailed("\"]\"");
  2775. }
  2776. }
  2777. if (result1 === null) {
  2778. if (input.charCodeAt(pos) === 63) {
  2779. result1 = "?";
  2780. pos++;
  2781. } else {
  2782. result1 = null;
  2783. if (reportFailures === 0) {
  2784. matchFailed("\"?\"");
  2785. }
  2786. }
  2787. if (result1 === null) {
  2788. if (input.charCodeAt(pos) === 123) {
  2789. result1 = "{";
  2790. pos++;
  2791. } else {
  2792. result1 = null;
  2793. if (reportFailures === 0) {
  2794. matchFailed("\"{\"");
  2795. }
  2796. }
  2797. if (result1 === null) {
  2798. if (input.charCodeAt(pos) === 125) {
  2799. result1 = "}";
  2800. pos++;
  2801. } else {
  2802. result1 = null;
  2803. if (reportFailures === 0) {
  2804. matchFailed("\"}\"");
  2805. }
  2806. }
  2807. }
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. }
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. }
  2822. }
  2823. }
  2824. }
  2825. }
  2826. }
  2827. }
  2828. }
  2829. }
  2830. if (result1 !== null) {
  2831. result0 = [];
  2832. while (result1 !== null) {
  2833. result0.push(result1);
  2834. result1 = parse_alphanum();
  2835. if (result1 === null) {
  2836. if (input.charCodeAt(pos) === 45) {
  2837. result1 = "-";
  2838. pos++;
  2839. } else {
  2840. result1 = null;
  2841. if (reportFailures === 0) {
  2842. matchFailed("\"-\"");
  2843. }
  2844. }
  2845. if (result1 === null) {
  2846. if (input.charCodeAt(pos) === 46) {
  2847. result1 = ".";
  2848. pos++;
  2849. } else {
  2850. result1 = null;
  2851. if (reportFailures === 0) {
  2852. matchFailed("\".\"");
  2853. }
  2854. }
  2855. if (result1 === null) {
  2856. if (input.charCodeAt(pos) === 33) {
  2857. result1 = "!";
  2858. pos++;
  2859. } else {
  2860. result1 = null;
  2861. if (reportFailures === 0) {
  2862. matchFailed("\"!\"");
  2863. }
  2864. }
  2865. if (result1 === null) {
  2866. if (input.charCodeAt(pos) === 37) {
  2867. result1 = "%";
  2868. pos++;
  2869. } else {
  2870. result1 = null;
  2871. if (reportFailures === 0) {
  2872. matchFailed("\"%\"");
  2873. }
  2874. }
  2875. if (result1 === null) {
  2876. if (input.charCodeAt(pos) === 42) {
  2877. result1 = "*";
  2878. pos++;
  2879. } else {
  2880. result1 = null;
  2881. if (reportFailures === 0) {
  2882. matchFailed("\"*\"");
  2883. }
  2884. }
  2885. if (result1 === null) {
  2886. if (input.charCodeAt(pos) === 95) {
  2887. result1 = "_";
  2888. pos++;
  2889. } else {
  2890. result1 = null;
  2891. if (reportFailures === 0) {
  2892. matchFailed("\"_\"");
  2893. }
  2894. }
  2895. if (result1 === null) {
  2896. if (input.charCodeAt(pos) === 43) {
  2897. result1 = "+";
  2898. pos++;
  2899. } else {
  2900. result1 = null;
  2901. if (reportFailures === 0) {
  2902. matchFailed("\"+\"");
  2903. }
  2904. }
  2905. if (result1 === null) {
  2906. if (input.charCodeAt(pos) === 96) {
  2907. result1 = "`";
  2908. pos++;
  2909. } else {
  2910. result1 = null;
  2911. if (reportFailures === 0) {
  2912. matchFailed("\"`\"");
  2913. }
  2914. }
  2915. if (result1 === null) {
  2916. if (input.charCodeAt(pos) === 39) {
  2917. result1 = "'";
  2918. pos++;
  2919. } else {
  2920. result1 = null;
  2921. if (reportFailures === 0) {
  2922. matchFailed("\"'\"");
  2923. }
  2924. }
  2925. if (result1 === null) {
  2926. if (input.charCodeAt(pos) === 126) {
  2927. result1 = "~";
  2928. pos++;
  2929. } else {
  2930. result1 = null;
  2931. if (reportFailures === 0) {
  2932. matchFailed("\"~\"");
  2933. }
  2934. }
  2935. if (result1 === null) {
  2936. if (input.charCodeAt(pos) === 40) {
  2937. result1 = "(";
  2938. pos++;
  2939. } else {
  2940. result1 = null;
  2941. if (reportFailures === 0) {
  2942. matchFailed("\"(\"");
  2943. }
  2944. }
  2945. if (result1 === null) {
  2946. if (input.charCodeAt(pos) === 41) {
  2947. result1 = ")";
  2948. pos++;
  2949. } else {
  2950. result1 = null;
  2951. if (reportFailures === 0) {
  2952. matchFailed("\")\"");
  2953. }
  2954. }
  2955. if (result1 === null) {
  2956. if (input.charCodeAt(pos) === 60) {
  2957. result1 = "<";
  2958. pos++;
  2959. } else {
  2960. result1 = null;
  2961. if (reportFailures === 0) {
  2962. matchFailed("\"<\"");
  2963. }
  2964. }
  2965. if (result1 === null) {
  2966. if (input.charCodeAt(pos) === 62) {
  2967. result1 = ">";
  2968. pos++;
  2969. } else {
  2970. result1 = null;
  2971. if (reportFailures === 0) {
  2972. matchFailed("\">\"");
  2973. }
  2974. }
  2975. if (result1 === null) {
  2976. if (input.charCodeAt(pos) === 58) {
  2977. result1 = ":";
  2978. pos++;
  2979. } else {
  2980. result1 = null;
  2981. if (reportFailures === 0) {
  2982. matchFailed("\":\"");
  2983. }
  2984. }
  2985. if (result1 === null) {
  2986. if (input.charCodeAt(pos) === 92) {
  2987. result1 = "\\";
  2988. pos++;
  2989. } else {
  2990. result1 = null;
  2991. if (reportFailures === 0) {
  2992. matchFailed("\"\\\\\"");
  2993. }
  2994. }
  2995. if (result1 === null) {
  2996. result1 = parse_DQUOTE();
  2997. if (result1 === null) {
  2998. if (input.charCodeAt(pos) === 47) {
  2999. result1 = "/";
  3000. pos++;
  3001. } else {
  3002. result1 = null;
  3003. if (reportFailures === 0) {
  3004. matchFailed("\"/\"");
  3005. }
  3006. }
  3007. if (result1 === null) {
  3008. if (input.charCodeAt(pos) === 91) {
  3009. result1 = "[";
  3010. pos++;
  3011. } else {
  3012. result1 = null;
  3013. if (reportFailures === 0) {
  3014. matchFailed("\"[\"");
  3015. }
  3016. }
  3017. if (result1 === null) {
  3018. if (input.charCodeAt(pos) === 93) {
  3019. result1 = "]";
  3020. pos++;
  3021. } else {
  3022. result1 = null;
  3023. if (reportFailures === 0) {
  3024. matchFailed("\"]\"");
  3025. }
  3026. }
  3027. if (result1 === null) {
  3028. if (input.charCodeAt(pos) === 63) {
  3029. result1 = "?";
  3030. pos++;
  3031. } else {
  3032. result1 = null;
  3033. if (reportFailures === 0) {
  3034. matchFailed("\"?\"");
  3035. }
  3036. }
  3037. if (result1 === null) {
  3038. if (input.charCodeAt(pos) === 123) {
  3039. result1 = "{";
  3040. pos++;
  3041. } else {
  3042. result1 = null;
  3043. if (reportFailures === 0) {
  3044. matchFailed("\"{\"");
  3045. }
  3046. }
  3047. if (result1 === null) {
  3048. if (input.charCodeAt(pos) === 125) {
  3049. result1 = "}";
  3050. pos++;
  3051. } else {
  3052. result1 = null;
  3053. if (reportFailures === 0) {
  3054. matchFailed("\"}\"");
  3055. }
  3056. }
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. }
  3063. }
  3064. }
  3065. }
  3066. }
  3067. }
  3068. }
  3069. }
  3070. }
  3071. }
  3072. }
  3073. }
  3074. }
  3075. }
  3076. }
  3077. }
  3078. }
  3079. }
  3080. }
  3081. } else {
  3082. result0 = null;
  3083. }
  3084. if (result0 !== null) {
  3085. result0 = function (offset) {
  3086. return input.substring(pos, offset);
  3087. }(pos0);
  3088. }
  3089. if (result0 === null) {
  3090. pos = pos0;
  3091. }
  3092. return result0;
  3093. }
  3094. function parse_STAR() {
  3095. var result0, result1, result2;
  3096. var pos0, pos1;
  3097. pos0 = pos;
  3098. pos1 = pos;
  3099. result0 = parse_SWS();
  3100. if (result0 !== null) {
  3101. if (input.charCodeAt(pos) === 42) {
  3102. result1 = "*";
  3103. pos++;
  3104. } else {
  3105. result1 = null;
  3106. if (reportFailures === 0) {
  3107. matchFailed("\"*\"");
  3108. }
  3109. }
  3110. if (result1 !== null) {
  3111. result2 = parse_SWS();
  3112. if (result2 !== null) {
  3113. result0 = [result0, result1, result2];
  3114. } else {
  3115. result0 = null;
  3116. pos = pos1;
  3117. }
  3118. } else {
  3119. result0 = null;
  3120. pos = pos1;
  3121. }
  3122. } else {
  3123. result0 = null;
  3124. pos = pos1;
  3125. }
  3126. if (result0 !== null) {
  3127. result0 = function (offset) {
  3128. return "*";
  3129. }(pos0);
  3130. }
  3131. if (result0 === null) {
  3132. pos = pos0;
  3133. }
  3134. return result0;
  3135. }
  3136. function parse_SLASH() {
  3137. var result0, result1, result2;
  3138. var pos0, pos1;
  3139. pos0 = pos;
  3140. pos1 = pos;
  3141. result0 = parse_SWS();
  3142. if (result0 !== null) {
  3143. if (input.charCodeAt(pos) === 47) {
  3144. result1 = "/";
  3145. pos++;
  3146. } else {
  3147. result1 = null;
  3148. if (reportFailures === 0) {
  3149. matchFailed("\"/\"");
  3150. }
  3151. }
  3152. if (result1 !== null) {
  3153. result2 = parse_SWS();
  3154. if (result2 !== null) {
  3155. result0 = [result0, result1, result2];
  3156. } else {
  3157. result0 = null;
  3158. pos = pos1;
  3159. }
  3160. } else {
  3161. result0 = null;
  3162. pos = pos1;
  3163. }
  3164. } else {
  3165. result0 = null;
  3166. pos = pos1;
  3167. }
  3168. if (result0 !== null) {
  3169. result0 = function (offset) {
  3170. return "/";
  3171. }(pos0);
  3172. }
  3173. if (result0 === null) {
  3174. pos = pos0;
  3175. }
  3176. return result0;
  3177. }
  3178. function parse_EQUAL() {
  3179. var result0, result1, result2;
  3180. var pos0, pos1;
  3181. pos0 = pos;
  3182. pos1 = pos;
  3183. result0 = parse_SWS();
  3184. if (result0 !== null) {
  3185. if (input.charCodeAt(pos) === 61) {
  3186. result1 = "=";
  3187. pos++;
  3188. } else {
  3189. result1 = null;
  3190. if (reportFailures === 0) {
  3191. matchFailed("\"=\"");
  3192. }
  3193. }
  3194. if (result1 !== null) {
  3195. result2 = parse_SWS();
  3196. if (result2 !== null) {
  3197. result0 = [result0, result1, result2];
  3198. } else {
  3199. result0 = null;
  3200. pos = pos1;
  3201. }
  3202. } else {
  3203. result0 = null;
  3204. pos = pos1;
  3205. }
  3206. } else {
  3207. result0 = null;
  3208. pos = pos1;
  3209. }
  3210. if (result0 !== null) {
  3211. result0 = function (offset) {
  3212. return "=";
  3213. }(pos0);
  3214. }
  3215. if (result0 === null) {
  3216. pos = pos0;
  3217. }
  3218. return result0;
  3219. }
  3220. function parse_LPAREN() {
  3221. var result0, result1, result2;
  3222. var pos0, pos1;
  3223. pos0 = pos;
  3224. pos1 = pos;
  3225. result0 = parse_SWS();
  3226. if (result0 !== null) {
  3227. if (input.charCodeAt(pos) === 40) {
  3228. result1 = "(";
  3229. pos++;
  3230. } else {
  3231. result1 = null;
  3232. if (reportFailures === 0) {
  3233. matchFailed("\"(\"");
  3234. }
  3235. }
  3236. if (result1 !== null) {
  3237. result2 = parse_SWS();
  3238. if (result2 !== null) {
  3239. result0 = [result0, result1, result2];
  3240. } else {
  3241. result0 = null;
  3242. pos = pos1;
  3243. }
  3244. } else {
  3245. result0 = null;
  3246. pos = pos1;
  3247. }
  3248. } else {
  3249. result0 = null;
  3250. pos = pos1;
  3251. }
  3252. if (result0 !== null) {
  3253. result0 = function (offset) {
  3254. return "(";
  3255. }(pos0);
  3256. }
  3257. if (result0 === null) {
  3258. pos = pos0;
  3259. }
  3260. return result0;
  3261. }
  3262. function parse_RPAREN() {
  3263. var result0, result1, result2;
  3264. var pos0, pos1;
  3265. pos0 = pos;
  3266. pos1 = pos;
  3267. result0 = parse_SWS();
  3268. if (result0 !== null) {
  3269. if (input.charCodeAt(pos) === 41) {
  3270. result1 = ")";
  3271. pos++;
  3272. } else {
  3273. result1 = null;
  3274. if (reportFailures === 0) {
  3275. matchFailed("\")\"");
  3276. }
  3277. }
  3278. if (result1 !== null) {
  3279. result2 = parse_SWS();
  3280. if (result2 !== null) {
  3281. result0 = [result0, result1, result2];
  3282. } else {
  3283. result0 = null;
  3284. pos = pos1;
  3285. }
  3286. } else {
  3287. result0 = null;
  3288. pos = pos1;
  3289. }
  3290. } else {
  3291. result0 = null;
  3292. pos = pos1;
  3293. }
  3294. if (result0 !== null) {
  3295. result0 = function (offset) {
  3296. return ")";
  3297. }(pos0);
  3298. }
  3299. if (result0 === null) {
  3300. pos = pos0;
  3301. }
  3302. return result0;
  3303. }
  3304. function parse_RAQUOT() {
  3305. var result0, result1;
  3306. var pos0, pos1;
  3307. pos0 = pos;
  3308. pos1 = pos;
  3309. if (input.charCodeAt(pos) === 62) {
  3310. result0 = ">";
  3311. pos++;
  3312. } else {
  3313. result0 = null;
  3314. if (reportFailures === 0) {
  3315. matchFailed("\">\"");
  3316. }
  3317. }
  3318. if (result0 !== null) {
  3319. result1 = parse_SWS();
  3320. if (result1 !== null) {
  3321. result0 = [result0, result1];
  3322. } else {
  3323. result0 = null;
  3324. pos = pos1;
  3325. }
  3326. } else {
  3327. result0 = null;
  3328. pos = pos1;
  3329. }
  3330. if (result0 !== null) {
  3331. result0 = function (offset) {
  3332. return ">";
  3333. }(pos0);
  3334. }
  3335. if (result0 === null) {
  3336. pos = pos0;
  3337. }
  3338. return result0;
  3339. }
  3340. function parse_LAQUOT() {
  3341. var result0, result1;
  3342. var pos0, pos1;
  3343. pos0 = pos;
  3344. pos1 = pos;
  3345. result0 = parse_SWS();
  3346. if (result0 !== null) {
  3347. if (input.charCodeAt(pos) === 60) {
  3348. result1 = "<";
  3349. pos++;
  3350. } else {
  3351. result1 = null;
  3352. if (reportFailures === 0) {
  3353. matchFailed("\"<\"");
  3354. }
  3355. }
  3356. if (result1 !== null) {
  3357. result0 = [result0, result1];
  3358. } else {
  3359. result0 = null;
  3360. pos = pos1;
  3361. }
  3362. } else {
  3363. result0 = null;
  3364. pos = pos1;
  3365. }
  3366. if (result0 !== null) {
  3367. result0 = function (offset) {
  3368. return "<";
  3369. }(pos0);
  3370. }
  3371. if (result0 === null) {
  3372. pos = pos0;
  3373. }
  3374. return result0;
  3375. }
  3376. function parse_COMMA() {
  3377. var result0, result1, result2;
  3378. var pos0, pos1;
  3379. pos0 = pos;
  3380. pos1 = pos;
  3381. result0 = parse_SWS();
  3382. if (result0 !== null) {
  3383. if (input.charCodeAt(pos) === 44) {
  3384. result1 = ",";
  3385. pos++;
  3386. } else {
  3387. result1 = null;
  3388. if (reportFailures === 0) {
  3389. matchFailed("\",\"");
  3390. }
  3391. }
  3392. if (result1 !== null) {
  3393. result2 = parse_SWS();
  3394. if (result2 !== null) {
  3395. result0 = [result0, result1, result2];
  3396. } else {
  3397. result0 = null;
  3398. pos = pos1;
  3399. }
  3400. } else {
  3401. result0 = null;
  3402. pos = pos1;
  3403. }
  3404. } else {
  3405. result0 = null;
  3406. pos = pos1;
  3407. }
  3408. if (result0 !== null) {
  3409. result0 = function (offset) {
  3410. return ",";
  3411. }(pos0);
  3412. }
  3413. if (result0 === null) {
  3414. pos = pos0;
  3415. }
  3416. return result0;
  3417. }
  3418. function parse_SEMI() {
  3419. var result0, result1, result2;
  3420. var pos0, pos1;
  3421. pos0 = pos;
  3422. pos1 = pos;
  3423. result0 = parse_SWS();
  3424. if (result0 !== null) {
  3425. if (input.charCodeAt(pos) === 59) {
  3426. result1 = ";";
  3427. pos++;
  3428. } else {
  3429. result1 = null;
  3430. if (reportFailures === 0) {
  3431. matchFailed("\";\"");
  3432. }
  3433. }
  3434. if (result1 !== null) {
  3435. result2 = parse_SWS();
  3436. if (result2 !== null) {
  3437. result0 = [result0, result1, result2];
  3438. } else {
  3439. result0 = null;
  3440. pos = pos1;
  3441. }
  3442. } else {
  3443. result0 = null;
  3444. pos = pos1;
  3445. }
  3446. } else {
  3447. result0 = null;
  3448. pos = pos1;
  3449. }
  3450. if (result0 !== null) {
  3451. result0 = function (offset) {
  3452. return ";";
  3453. }(pos0);
  3454. }
  3455. if (result0 === null) {
  3456. pos = pos0;
  3457. }
  3458. return result0;
  3459. }
  3460. function parse_COLON() {
  3461. var result0, result1, result2;
  3462. var pos0, pos1;
  3463. pos0 = pos;
  3464. pos1 = pos;
  3465. result0 = parse_SWS();
  3466. if (result0 !== null) {
  3467. if (input.charCodeAt(pos) === 58) {
  3468. result1 = ":";
  3469. pos++;
  3470. } else {
  3471. result1 = null;
  3472. if (reportFailures === 0) {
  3473. matchFailed("\":\"");
  3474. }
  3475. }
  3476. if (result1 !== null) {
  3477. result2 = parse_SWS();
  3478. if (result2 !== null) {
  3479. result0 = [result0, result1, result2];
  3480. } else {
  3481. result0 = null;
  3482. pos = pos1;
  3483. }
  3484. } else {
  3485. result0 = null;
  3486. pos = pos1;
  3487. }
  3488. } else {
  3489. result0 = null;
  3490. pos = pos1;
  3491. }
  3492. if (result0 !== null) {
  3493. result0 = function (offset) {
  3494. return ":";
  3495. }(pos0);
  3496. }
  3497. if (result0 === null) {
  3498. pos = pos0;
  3499. }
  3500. return result0;
  3501. }
  3502. function parse_LDQUOT() {
  3503. var result0, result1;
  3504. var pos0, pos1;
  3505. pos0 = pos;
  3506. pos1 = pos;
  3507. result0 = parse_SWS();
  3508. if (result0 !== null) {
  3509. result1 = parse_DQUOTE();
  3510. if (result1 !== null) {
  3511. result0 = [result0, result1];
  3512. } else {
  3513. result0 = null;
  3514. pos = pos1;
  3515. }
  3516. } else {
  3517. result0 = null;
  3518. pos = pos1;
  3519. }
  3520. if (result0 !== null) {
  3521. result0 = function (offset) {
  3522. return "\"";
  3523. }(pos0);
  3524. }
  3525. if (result0 === null) {
  3526. pos = pos0;
  3527. }
  3528. return result0;
  3529. }
  3530. function parse_RDQUOT() {
  3531. var result0, result1;
  3532. var pos0, pos1;
  3533. pos0 = pos;
  3534. pos1 = pos;
  3535. result0 = parse_DQUOTE();
  3536. if (result0 !== null) {
  3537. result1 = parse_SWS();
  3538. if (result1 !== null) {
  3539. result0 = [result0, result1];
  3540. } else {
  3541. result0 = null;
  3542. pos = pos1;
  3543. }
  3544. } else {
  3545. result0 = null;
  3546. pos = pos1;
  3547. }
  3548. if (result0 !== null) {
  3549. result0 = function (offset) {
  3550. return "\"";
  3551. }(pos0);
  3552. }
  3553. if (result0 === null) {
  3554. pos = pos0;
  3555. }
  3556. return result0;
  3557. }
  3558. function parse_comment() {
  3559. var result0, result1, result2;
  3560. var pos0;
  3561. pos0 = pos;
  3562. result0 = parse_LPAREN();
  3563. if (result0 !== null) {
  3564. result1 = [];
  3565. result2 = parse_ctext();
  3566. if (result2 === null) {
  3567. result2 = parse_quoted_pair();
  3568. if (result2 === null) {
  3569. result2 = parse_comment();
  3570. }
  3571. }
  3572. while (result2 !== null) {
  3573. result1.push(result2);
  3574. result2 = parse_ctext();
  3575. if (result2 === null) {
  3576. result2 = parse_quoted_pair();
  3577. if (result2 === null) {
  3578. result2 = parse_comment();
  3579. }
  3580. }
  3581. }
  3582. if (result1 !== null) {
  3583. result2 = parse_RPAREN();
  3584. if (result2 !== null) {
  3585. result0 = [result0, result1, result2];
  3586. } else {
  3587. result0 = null;
  3588. pos = pos0;
  3589. }
  3590. } else {
  3591. result0 = null;
  3592. pos = pos0;
  3593. }
  3594. } else {
  3595. result0 = null;
  3596. pos = pos0;
  3597. }
  3598. return result0;
  3599. }
  3600. function parse_ctext() {
  3601. var result0;
  3602. if (/^[!-']/.test(input.charAt(pos))) {
  3603. result0 = input.charAt(pos);
  3604. pos++;
  3605. } else {
  3606. result0 = null;
  3607. if (reportFailures === 0) {
  3608. matchFailed("[!-']");
  3609. }
  3610. }
  3611. if (result0 === null) {
  3612. if (/^[*-[]/.test(input.charAt(pos))) {
  3613. result0 = input.charAt(pos);
  3614. pos++;
  3615. } else {
  3616. result0 = null;
  3617. if (reportFailures === 0) {
  3618. matchFailed("[*-[]");
  3619. }
  3620. }
  3621. if (result0 === null) {
  3622. if (/^[\]-~]/.test(input.charAt(pos))) {
  3623. result0 = input.charAt(pos);
  3624. pos++;
  3625. } else {
  3626. result0 = null;
  3627. if (reportFailures === 0) {
  3628. matchFailed("[\\]-~]");
  3629. }
  3630. }
  3631. if (result0 === null) {
  3632. result0 = parse_UTF8_NONASCII();
  3633. if (result0 === null) {
  3634. result0 = parse_LWS();
  3635. }
  3636. }
  3637. }
  3638. }
  3639. return result0;
  3640. }
  3641. function parse_quoted_string() {
  3642. var result0, result1, result2, result3;
  3643. var pos0, pos1;
  3644. pos0 = pos;
  3645. pos1 = pos;
  3646. result0 = parse_SWS();
  3647. if (result0 !== null) {
  3648. result1 = parse_DQUOTE();
  3649. if (result1 !== null) {
  3650. result2 = [];
  3651. result3 = parse_qdtext();
  3652. if (result3 === null) {
  3653. result3 = parse_quoted_pair();
  3654. }
  3655. while (result3 !== null) {
  3656. result2.push(result3);
  3657. result3 = parse_qdtext();
  3658. if (result3 === null) {
  3659. result3 = parse_quoted_pair();
  3660. }
  3661. }
  3662. if (result2 !== null) {
  3663. result3 = parse_DQUOTE();
  3664. if (result3 !== null) {
  3665. result0 = [result0, result1, result2, result3];
  3666. } else {
  3667. result0 = null;
  3668. pos = pos1;
  3669. }
  3670. } else {
  3671. result0 = null;
  3672. pos = pos1;
  3673. }
  3674. } else {
  3675. result0 = null;
  3676. pos = pos1;
  3677. }
  3678. } else {
  3679. result0 = null;
  3680. pos = pos1;
  3681. }
  3682. if (result0 !== null) {
  3683. result0 = function (offset) {
  3684. return input.substring(pos, offset);
  3685. }(pos0);
  3686. }
  3687. if (result0 === null) {
  3688. pos = pos0;
  3689. }
  3690. return result0;
  3691. }
  3692. function parse_quoted_string_clean() {
  3693. var result0, result1, result2, result3;
  3694. var pos0, pos1;
  3695. pos0 = pos;
  3696. pos1 = pos;
  3697. result0 = parse_SWS();
  3698. if (result0 !== null) {
  3699. result1 = parse_DQUOTE();
  3700. if (result1 !== null) {
  3701. result2 = [];
  3702. result3 = parse_qdtext();
  3703. if (result3 === null) {
  3704. result3 = parse_quoted_pair();
  3705. }
  3706. while (result3 !== null) {
  3707. result2.push(result3);
  3708. result3 = parse_qdtext();
  3709. if (result3 === null) {
  3710. result3 = parse_quoted_pair();
  3711. }
  3712. }
  3713. if (result2 !== null) {
  3714. result3 = parse_DQUOTE();
  3715. if (result3 !== null) {
  3716. result0 = [result0, result1, result2, result3];
  3717. } else {
  3718. result0 = null;
  3719. pos = pos1;
  3720. }
  3721. } else {
  3722. result0 = null;
  3723. pos = pos1;
  3724. }
  3725. } else {
  3726. result0 = null;
  3727. pos = pos1;
  3728. }
  3729. } else {
  3730. result0 = null;
  3731. pos = pos1;
  3732. }
  3733. if (result0 !== null) {
  3734. result0 = function (offset) {
  3735. return input.substring(pos - 1, offset + 1);
  3736. }(pos0);
  3737. }
  3738. if (result0 === null) {
  3739. pos = pos0;
  3740. }
  3741. return result0;
  3742. }
  3743. function parse_qdtext() {
  3744. var result0;
  3745. result0 = parse_LWS();
  3746. if (result0 === null) {
  3747. if (input.charCodeAt(pos) === 33) {
  3748. result0 = "!";
  3749. pos++;
  3750. } else {
  3751. result0 = null;
  3752. if (reportFailures === 0) {
  3753. matchFailed("\"!\"");
  3754. }
  3755. }
  3756. if (result0 === null) {
  3757. if (/^[#-[]/.test(input.charAt(pos))) {
  3758. result0 = input.charAt(pos);
  3759. pos++;
  3760. } else {
  3761. result0 = null;
  3762. if (reportFailures === 0) {
  3763. matchFailed("[#-[]");
  3764. }
  3765. }
  3766. if (result0 === null) {
  3767. if (/^[\]-~]/.test(input.charAt(pos))) {
  3768. result0 = input.charAt(pos);
  3769. pos++;
  3770. } else {
  3771. result0 = null;
  3772. if (reportFailures === 0) {
  3773. matchFailed("[\\]-~]");
  3774. }
  3775. }
  3776. if (result0 === null) {
  3777. result0 = parse_UTF8_NONASCII();
  3778. }
  3779. }
  3780. }
  3781. }
  3782. return result0;
  3783. }
  3784. function parse_quoted_pair() {
  3785. var result0, result1;
  3786. var pos0;
  3787. pos0 = pos;
  3788. if (input.charCodeAt(pos) === 92) {
  3789. result0 = "\\";
  3790. pos++;
  3791. } else {
  3792. result0 = null;
  3793. if (reportFailures === 0) {
  3794. matchFailed("\"\\\\\"");
  3795. }
  3796. }
  3797. if (result0 !== null) {
  3798. if (/^[\0-\t]/.test(input.charAt(pos))) {
  3799. result1 = input.charAt(pos);
  3800. pos++;
  3801. } else {
  3802. result1 = null;
  3803. if (reportFailures === 0) {
  3804. matchFailed("[\\0-\\t]");
  3805. }
  3806. }
  3807. if (result1 === null) {
  3808. if (/^[\x0B-\f]/.test(input.charAt(pos))) {
  3809. result1 = input.charAt(pos);
  3810. pos++;
  3811. } else {
  3812. result1 = null;
  3813. if (reportFailures === 0) {
  3814. matchFailed("[\\x0B-\\f]");
  3815. }
  3816. }
  3817. if (result1 === null) {
  3818. if (/^[\x0E-]/.test(input.charAt(pos))) {
  3819. result1 = input.charAt(pos);
  3820. pos++;
  3821. } else {
  3822. result1 = null;
  3823. if (reportFailures === 0) {
  3824. matchFailed("[\\x0E-]");
  3825. }
  3826. }
  3827. }
  3828. }
  3829. if (result1 !== null) {
  3830. result0 = [result0, result1];
  3831. } else {
  3832. result0 = null;
  3833. pos = pos0;
  3834. }
  3835. } else {
  3836. result0 = null;
  3837. pos = pos0;
  3838. }
  3839. return result0;
  3840. }
  3841. function parse_SIP_URI_noparams() {
  3842. var result0, result1, result2, result3;
  3843. var pos0, pos1;
  3844. pos0 = pos;
  3845. pos1 = pos;
  3846. result0 = parse_uri_scheme();
  3847. if (result0 !== null) {
  3848. if (input.charCodeAt(pos) === 58) {
  3849. result1 = ":";
  3850. pos++;
  3851. } else {
  3852. result1 = null;
  3853. if (reportFailures === 0) {
  3854. matchFailed("\":\"");
  3855. }
  3856. }
  3857. if (result1 !== null) {
  3858. result2 = parse_userinfo();
  3859. result2 = result2 !== null ? result2 : "";
  3860. if (result2 !== null) {
  3861. result3 = parse_hostport();
  3862. if (result3 !== null) {
  3863. result0 = [result0, result1, result2, result3];
  3864. } else {
  3865. result0 = null;
  3866. pos = pos1;
  3867. }
  3868. } else {
  3869. result0 = null;
  3870. pos = pos1;
  3871. }
  3872. } else {
  3873. result0 = null;
  3874. pos = pos1;
  3875. }
  3876. } else {
  3877. result0 = null;
  3878. pos = pos1;
  3879. }
  3880. if (result0 !== null) {
  3881. result0 = function (offset) {
  3882. try {
  3883. data.uri = new URI(data.scheme, data.user, data.host, data.port);
  3884. delete data.scheme;
  3885. delete data.user;
  3886. delete data.host;
  3887. delete data.host_type;
  3888. delete data.port;
  3889. } catch (e) {
  3890. data = -1;
  3891. }
  3892. }(pos0);
  3893. }
  3894. if (result0 === null) {
  3895. pos = pos0;
  3896. }
  3897. return result0;
  3898. }
  3899. function parse_SIP_URI() {
  3900. var result0, result1, result2, result3, result4, result5;
  3901. var pos0, pos1;
  3902. pos0 = pos;
  3903. pos1 = pos;
  3904. result0 = parse_uri_scheme();
  3905. if (result0 !== null) {
  3906. if (input.charCodeAt(pos) === 58) {
  3907. result1 = ":";
  3908. pos++;
  3909. } else {
  3910. result1 = null;
  3911. if (reportFailures === 0) {
  3912. matchFailed("\":\"");
  3913. }
  3914. }
  3915. if (result1 !== null) {
  3916. result2 = parse_userinfo();
  3917. result2 = result2 !== null ? result2 : "";
  3918. if (result2 !== null) {
  3919. result3 = parse_hostport();
  3920. if (result3 !== null) {
  3921. result4 = parse_uri_parameters();
  3922. if (result4 !== null) {
  3923. result5 = parse_headers();
  3924. result5 = result5 !== null ? result5 : "";
  3925. if (result5 !== null) {
  3926. result0 = [result0, result1, result2, result3, result4, result5];
  3927. } else {
  3928. result0 = null;
  3929. pos = pos1;
  3930. }
  3931. } else {
  3932. result0 = null;
  3933. pos = pos1;
  3934. }
  3935. } else {
  3936. result0 = null;
  3937. pos = pos1;
  3938. }
  3939. } else {
  3940. result0 = null;
  3941. pos = pos1;
  3942. }
  3943. } else {
  3944. result0 = null;
  3945. pos = pos1;
  3946. }
  3947. } else {
  3948. result0 = null;
  3949. pos = pos1;
  3950. }
  3951. if (result0 !== null) {
  3952. result0 = function (offset) {
  3953. var header;
  3954. try {
  3955. data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers);
  3956. delete data.scheme;
  3957. delete data.user;
  3958. delete data.host;
  3959. delete data.host_type;
  3960. delete data.port;
  3961. delete data.uri_params;
  3962. if (startRule === 'SIP_URI') {
  3963. data = data.uri;
  3964. }
  3965. } catch (e) {
  3966. data = -1;
  3967. }
  3968. }(pos0);
  3969. }
  3970. if (result0 === null) {
  3971. pos = pos0;
  3972. }
  3973. return result0;
  3974. }
  3975. function parse_uri_scheme() {
  3976. var result0;
  3977. result0 = parse_uri_scheme_sips();
  3978. if (result0 === null) {
  3979. result0 = parse_uri_scheme_sip();
  3980. }
  3981. return result0;
  3982. }
  3983. function parse_uri_scheme_sips() {
  3984. var result0;
  3985. var pos0;
  3986. pos0 = pos;
  3987. if (input.substr(pos, 4).toLowerCase() === "sips") {
  3988. result0 = input.substr(pos, 4);
  3989. pos += 4;
  3990. } else {
  3991. result0 = null;
  3992. if (reportFailures === 0) {
  3993. matchFailed("\"sips\"");
  3994. }
  3995. }
  3996. if (result0 !== null) {
  3997. result0 = function (offset, scheme) {
  3998. data.scheme = scheme.toLowerCase();
  3999. }(pos0, result0);
  4000. }
  4001. if (result0 === null) {
  4002. pos = pos0;
  4003. }
  4004. return result0;
  4005. }
  4006. function parse_uri_scheme_sip() {
  4007. var result0;
  4008. var pos0;
  4009. pos0 = pos;
  4010. if (input.substr(pos, 3).toLowerCase() === "sip") {
  4011. result0 = input.substr(pos, 3);
  4012. pos += 3;
  4013. } else {
  4014. result0 = null;
  4015. if (reportFailures === 0) {
  4016. matchFailed("\"sip\"");
  4017. }
  4018. }
  4019. if (result0 !== null) {
  4020. result0 = function (offset, scheme) {
  4021. data.scheme = scheme.toLowerCase();
  4022. }(pos0, result0);
  4023. }
  4024. if (result0 === null) {
  4025. pos = pos0;
  4026. }
  4027. return result0;
  4028. }
  4029. function parse_userinfo() {
  4030. var result0, result1, result2;
  4031. var pos0, pos1, pos2;
  4032. pos0 = pos;
  4033. pos1 = pos;
  4034. result0 = parse_user();
  4035. if (result0 !== null) {
  4036. pos2 = pos;
  4037. if (input.charCodeAt(pos) === 58) {
  4038. result1 = ":";
  4039. pos++;
  4040. } else {
  4041. result1 = null;
  4042. if (reportFailures === 0) {
  4043. matchFailed("\":\"");
  4044. }
  4045. }
  4046. if (result1 !== null) {
  4047. result2 = parse_password();
  4048. if (result2 !== null) {
  4049. result1 = [result1, result2];
  4050. } else {
  4051. result1 = null;
  4052. pos = pos2;
  4053. }
  4054. } else {
  4055. result1 = null;
  4056. pos = pos2;
  4057. }
  4058. result1 = result1 !== null ? result1 : "";
  4059. if (result1 !== null) {
  4060. if (input.charCodeAt(pos) === 64) {
  4061. result2 = "@";
  4062. pos++;
  4063. } else {
  4064. result2 = null;
  4065. if (reportFailures === 0) {
  4066. matchFailed("\"@\"");
  4067. }
  4068. }
  4069. if (result2 !== null) {
  4070. result0 = [result0, result1, result2];
  4071. } else {
  4072. result0 = null;
  4073. pos = pos1;
  4074. }
  4075. } else {
  4076. result0 = null;
  4077. pos = pos1;
  4078. }
  4079. } else {
  4080. result0 = null;
  4081. pos = pos1;
  4082. }
  4083. if (result0 !== null) {
  4084. result0 = function (offset) {
  4085. data.user = decodeURIComponent(input.substring(pos - 1, offset));
  4086. }(pos0);
  4087. }
  4088. if (result0 === null) {
  4089. pos = pos0;
  4090. }
  4091. return result0;
  4092. }
  4093. function parse_user() {
  4094. var result0, result1;
  4095. result1 = parse_unreserved();
  4096. if (result1 === null) {
  4097. result1 = parse_escaped();
  4098. if (result1 === null) {
  4099. result1 = parse_user_unreserved();
  4100. }
  4101. }
  4102. if (result1 !== null) {
  4103. result0 = [];
  4104. while (result1 !== null) {
  4105. result0.push(result1);
  4106. result1 = parse_unreserved();
  4107. if (result1 === null) {
  4108. result1 = parse_escaped();
  4109. if (result1 === null) {
  4110. result1 = parse_user_unreserved();
  4111. }
  4112. }
  4113. }
  4114. } else {
  4115. result0 = null;
  4116. }
  4117. return result0;
  4118. }
  4119. function parse_user_unreserved() {
  4120. var result0;
  4121. if (input.charCodeAt(pos) === 38) {
  4122. result0 = "&";
  4123. pos++;
  4124. } else {
  4125. result0 = null;
  4126. if (reportFailures === 0) {
  4127. matchFailed("\"&\"");
  4128. }
  4129. }
  4130. if (result0 === null) {
  4131. if (input.charCodeAt(pos) === 61) {
  4132. result0 = "=";
  4133. pos++;
  4134. } else {
  4135. result0 = null;
  4136. if (reportFailures === 0) {
  4137. matchFailed("\"=\"");
  4138. }
  4139. }
  4140. if (result0 === null) {
  4141. if (input.charCodeAt(pos) === 43) {
  4142. result0 = "+";
  4143. pos++;
  4144. } else {
  4145. result0 = null;
  4146. if (reportFailures === 0) {
  4147. matchFailed("\"+\"");
  4148. }
  4149. }
  4150. if (result0 === null) {
  4151. if (input.charCodeAt(pos) === 36) {
  4152. result0 = "$";
  4153. pos++;
  4154. } else {
  4155. result0 = null;
  4156. if (reportFailures === 0) {
  4157. matchFailed("\"$\"");
  4158. }
  4159. }
  4160. if (result0 === null) {
  4161. if (input.charCodeAt(pos) === 44) {
  4162. result0 = ",";
  4163. pos++;
  4164. } else {
  4165. result0 = null;
  4166. if (reportFailures === 0) {
  4167. matchFailed("\",\"");
  4168. }
  4169. }
  4170. if (result0 === null) {
  4171. if (input.charCodeAt(pos) === 59) {
  4172. result0 = ";";
  4173. pos++;
  4174. } else {
  4175. result0 = null;
  4176. if (reportFailures === 0) {
  4177. matchFailed("\";\"");
  4178. }
  4179. }
  4180. if (result0 === null) {
  4181. if (input.charCodeAt(pos) === 63) {
  4182. result0 = "?";
  4183. pos++;
  4184. } else {
  4185. result0 = null;
  4186. if (reportFailures === 0) {
  4187. matchFailed("\"?\"");
  4188. }
  4189. }
  4190. if (result0 === null) {
  4191. if (input.charCodeAt(pos) === 47) {
  4192. result0 = "/";
  4193. pos++;
  4194. } else {
  4195. result0 = null;
  4196. if (reportFailures === 0) {
  4197. matchFailed("\"/\"");
  4198. }
  4199. }
  4200. }
  4201. }
  4202. }
  4203. }
  4204. }
  4205. }
  4206. }
  4207. return result0;
  4208. }
  4209. function parse_password() {
  4210. var result0, result1;
  4211. var pos0;
  4212. pos0 = pos;
  4213. result0 = [];
  4214. result1 = parse_unreserved();
  4215. if (result1 === null) {
  4216. result1 = parse_escaped();
  4217. if (result1 === null) {
  4218. if (input.charCodeAt(pos) === 38) {
  4219. result1 = "&";
  4220. pos++;
  4221. } else {
  4222. result1 = null;
  4223. if (reportFailures === 0) {
  4224. matchFailed("\"&\"");
  4225. }
  4226. }
  4227. if (result1 === null) {
  4228. if (input.charCodeAt(pos) === 61) {
  4229. result1 = "=";
  4230. pos++;
  4231. } else {
  4232. result1 = null;
  4233. if (reportFailures === 0) {
  4234. matchFailed("\"=\"");
  4235. }
  4236. }
  4237. if (result1 === null) {
  4238. if (input.charCodeAt(pos) === 43) {
  4239. result1 = "+";
  4240. pos++;
  4241. } else {
  4242. result1 = null;
  4243. if (reportFailures === 0) {
  4244. matchFailed("\"+\"");
  4245. }
  4246. }
  4247. if (result1 === null) {
  4248. if (input.charCodeAt(pos) === 36) {
  4249. result1 = "$";
  4250. pos++;
  4251. } else {
  4252. result1 = null;
  4253. if (reportFailures === 0) {
  4254. matchFailed("\"$\"");
  4255. }
  4256. }
  4257. if (result1 === null) {
  4258. if (input.charCodeAt(pos) === 44) {
  4259. result1 = ",";
  4260. pos++;
  4261. } else {
  4262. result1 = null;
  4263. if (reportFailures === 0) {
  4264. matchFailed("\",\"");
  4265. }
  4266. }
  4267. }
  4268. }
  4269. }
  4270. }
  4271. }
  4272. }
  4273. while (result1 !== null) {
  4274. result0.push(result1);
  4275. result1 = parse_unreserved();
  4276. if (result1 === null) {
  4277. result1 = parse_escaped();
  4278. if (result1 === null) {
  4279. if (input.charCodeAt(pos) === 38) {
  4280. result1 = "&";
  4281. pos++;
  4282. } else {
  4283. result1 = null;
  4284. if (reportFailures === 0) {
  4285. matchFailed("\"&\"");
  4286. }
  4287. }
  4288. if (result1 === null) {
  4289. if (input.charCodeAt(pos) === 61) {
  4290. result1 = "=";
  4291. pos++;
  4292. } else {
  4293. result1 = null;
  4294. if (reportFailures === 0) {
  4295. matchFailed("\"=\"");
  4296. }
  4297. }
  4298. if (result1 === null) {
  4299. if (input.charCodeAt(pos) === 43) {
  4300. result1 = "+";
  4301. pos++;
  4302. } else {
  4303. result1 = null;
  4304. if (reportFailures === 0) {
  4305. matchFailed("\"+\"");
  4306. }
  4307. }
  4308. if (result1 === null) {
  4309. if (input.charCodeAt(pos) === 36) {
  4310. result1 = "$";
  4311. pos++;
  4312. } else {
  4313. result1 = null;
  4314. if (reportFailures === 0) {
  4315. matchFailed("\"$\"");
  4316. }
  4317. }
  4318. if (result1 === null) {
  4319. if (input.charCodeAt(pos) === 44) {
  4320. result1 = ",";
  4321. pos++;
  4322. } else {
  4323. result1 = null;
  4324. if (reportFailures === 0) {
  4325. matchFailed("\",\"");
  4326. }
  4327. }
  4328. }
  4329. }
  4330. }
  4331. }
  4332. }
  4333. }
  4334. }
  4335. if (result0 !== null) {
  4336. result0 = function (offset) {
  4337. data.password = input.substring(pos, offset);
  4338. }(pos0);
  4339. }
  4340. if (result0 === null) {
  4341. pos = pos0;
  4342. }
  4343. return result0;
  4344. }
  4345. function parse_hostport() {
  4346. var result0, result1, result2;
  4347. var pos0, pos1;
  4348. pos0 = pos;
  4349. result0 = parse_host();
  4350. if (result0 !== null) {
  4351. pos1 = pos;
  4352. if (input.charCodeAt(pos) === 58) {
  4353. result1 = ":";
  4354. pos++;
  4355. } else {
  4356. result1 = null;
  4357. if (reportFailures === 0) {
  4358. matchFailed("\":\"");
  4359. }
  4360. }
  4361. if (result1 !== null) {
  4362. result2 = parse_port();
  4363. if (result2 !== null) {
  4364. result1 = [result1, result2];
  4365. } else {
  4366. result1 = null;
  4367. pos = pos1;
  4368. }
  4369. } else {
  4370. result1 = null;
  4371. pos = pos1;
  4372. }
  4373. result1 = result1 !== null ? result1 : "";
  4374. if (result1 !== null) {
  4375. result0 = [result0, result1];
  4376. } else {
  4377. result0 = null;
  4378. pos = pos0;
  4379. }
  4380. } else {
  4381. result0 = null;
  4382. pos = pos0;
  4383. }
  4384. return result0;
  4385. }
  4386. function parse_host() {
  4387. var result0;
  4388. var pos0;
  4389. pos0 = pos;
  4390. result0 = parse_hostname();
  4391. if (result0 === null) {
  4392. result0 = parse_IPv4address();
  4393. if (result0 === null) {
  4394. result0 = parse_IPv6reference();
  4395. }
  4396. }
  4397. if (result0 !== null) {
  4398. result0 = function (offset) {
  4399. data.host = input.substring(pos, offset).toLowerCase();
  4400. return data.host;
  4401. }(pos0);
  4402. }
  4403. if (result0 === null) {
  4404. pos = pos0;
  4405. }
  4406. return result0;
  4407. }
  4408. function parse_hostname() {
  4409. var result0, result1, result2;
  4410. var pos0, pos1, pos2;
  4411. pos0 = pos;
  4412. pos1 = pos;
  4413. result0 = [];
  4414. pos2 = pos;
  4415. result1 = parse_domainlabel();
  4416. if (result1 !== null) {
  4417. if (input.charCodeAt(pos) === 46) {
  4418. result2 = ".";
  4419. pos++;
  4420. } else {
  4421. result2 = null;
  4422. if (reportFailures === 0) {
  4423. matchFailed("\".\"");
  4424. }
  4425. }
  4426. if (result2 !== null) {
  4427. result1 = [result1, result2];
  4428. } else {
  4429. result1 = null;
  4430. pos = pos2;
  4431. }
  4432. } else {
  4433. result1 = null;
  4434. pos = pos2;
  4435. }
  4436. while (result1 !== null) {
  4437. result0.push(result1);
  4438. pos2 = pos;
  4439. result1 = parse_domainlabel();
  4440. if (result1 !== null) {
  4441. if (input.charCodeAt(pos) === 46) {
  4442. result2 = ".";
  4443. pos++;
  4444. } else {
  4445. result2 = null;
  4446. if (reportFailures === 0) {
  4447. matchFailed("\".\"");
  4448. }
  4449. }
  4450. if (result2 !== null) {
  4451. result1 = [result1, result2];
  4452. } else {
  4453. result1 = null;
  4454. pos = pos2;
  4455. }
  4456. } else {
  4457. result1 = null;
  4458. pos = pos2;
  4459. }
  4460. }
  4461. if (result0 !== null) {
  4462. result1 = parse_toplabel();
  4463. if (result1 !== null) {
  4464. if (input.charCodeAt(pos) === 46) {
  4465. result2 = ".";
  4466. pos++;
  4467. } else {
  4468. result2 = null;
  4469. if (reportFailures === 0) {
  4470. matchFailed("\".\"");
  4471. }
  4472. }
  4473. result2 = result2 !== null ? result2 : "";
  4474. if (result2 !== null) {
  4475. result0 = [result0, result1, result2];
  4476. } else {
  4477. result0 = null;
  4478. pos = pos1;
  4479. }
  4480. } else {
  4481. result0 = null;
  4482. pos = pos1;
  4483. }
  4484. } else {
  4485. result0 = null;
  4486. pos = pos1;
  4487. }
  4488. if (result0 !== null) {
  4489. result0 = function (offset) {
  4490. data.host_type = 'domain';
  4491. return input.substring(pos, offset);
  4492. }(pos0);
  4493. }
  4494. if (result0 === null) {
  4495. pos = pos0;
  4496. }
  4497. return result0;
  4498. }
  4499. function parse_domainlabel() {
  4500. var result0, result1, result2;
  4501. var pos0;
  4502. pos0 = pos;
  4503. result0 = parse_alphanum();
  4504. if (result0 !== null) {
  4505. result1 = [];
  4506. result2 = parse_alphanum();
  4507. if (result2 === null) {
  4508. if (input.charCodeAt(pos) === 45) {
  4509. result2 = "-";
  4510. pos++;
  4511. } else {
  4512. result2 = null;
  4513. if (reportFailures === 0) {
  4514. matchFailed("\"-\"");
  4515. }
  4516. }
  4517. if (result2 === null) {
  4518. if (input.charCodeAt(pos) === 95) {
  4519. result2 = "_";
  4520. pos++;
  4521. } else {
  4522. result2 = null;
  4523. if (reportFailures === 0) {
  4524. matchFailed("\"_\"");
  4525. }
  4526. }
  4527. }
  4528. }
  4529. while (result2 !== null) {
  4530. result1.push(result2);
  4531. result2 = parse_alphanum();
  4532. if (result2 === null) {
  4533. if (input.charCodeAt(pos) === 45) {
  4534. result2 = "-";
  4535. pos++;
  4536. } else {
  4537. result2 = null;
  4538. if (reportFailures === 0) {
  4539. matchFailed("\"-\"");
  4540. }
  4541. }
  4542. if (result2 === null) {
  4543. if (input.charCodeAt(pos) === 95) {
  4544. result2 = "_";
  4545. pos++;
  4546. } else {
  4547. result2 = null;
  4548. if (reportFailures === 0) {
  4549. matchFailed("\"_\"");
  4550. }
  4551. }
  4552. }
  4553. }
  4554. }
  4555. if (result1 !== null) {
  4556. result0 = [result0, result1];
  4557. } else {
  4558. result0 = null;
  4559. pos = pos0;
  4560. }
  4561. } else {
  4562. result0 = null;
  4563. pos = pos0;
  4564. }
  4565. return result0;
  4566. }
  4567. function parse_toplabel() {
  4568. var result0, result1, result2;
  4569. var pos0;
  4570. pos0 = pos;
  4571. result0 = parse_ALPHA();
  4572. if (result0 !== null) {
  4573. result1 = [];
  4574. result2 = parse_alphanum();
  4575. if (result2 === null) {
  4576. if (input.charCodeAt(pos) === 45) {
  4577. result2 = "-";
  4578. pos++;
  4579. } else {
  4580. result2 = null;
  4581. if (reportFailures === 0) {
  4582. matchFailed("\"-\"");
  4583. }
  4584. }
  4585. if (result2 === null) {
  4586. if (input.charCodeAt(pos) === 95) {
  4587. result2 = "_";
  4588. pos++;
  4589. } else {
  4590. result2 = null;
  4591. if (reportFailures === 0) {
  4592. matchFailed("\"_\"");
  4593. }
  4594. }
  4595. }
  4596. }
  4597. while (result2 !== null) {
  4598. result1.push(result2);
  4599. result2 = parse_alphanum();
  4600. if (result2 === null) {
  4601. if (input.charCodeAt(pos) === 45) {
  4602. result2 = "-";
  4603. pos++;
  4604. } else {
  4605. result2 = null;
  4606. if (reportFailures === 0) {
  4607. matchFailed("\"-\"");
  4608. }
  4609. }
  4610. if (result2 === null) {
  4611. if (input.charCodeAt(pos) === 95) {
  4612. result2 = "_";
  4613. pos++;
  4614. } else {
  4615. result2 = null;
  4616. if (reportFailures === 0) {
  4617. matchFailed("\"_\"");
  4618. }
  4619. }
  4620. }
  4621. }
  4622. }
  4623. if (result1 !== null) {
  4624. result0 = [result0, result1];
  4625. } else {
  4626. result0 = null;
  4627. pos = pos0;
  4628. }
  4629. } else {
  4630. result0 = null;
  4631. pos = pos0;
  4632. }
  4633. return result0;
  4634. }
  4635. function parse_IPv6reference() {
  4636. var result0, result1, result2;
  4637. var pos0, pos1;
  4638. pos0 = pos;
  4639. pos1 = pos;
  4640. if (input.charCodeAt(pos) === 91) {
  4641. result0 = "[";
  4642. pos++;
  4643. } else {
  4644. result0 = null;
  4645. if (reportFailures === 0) {
  4646. matchFailed("\"[\"");
  4647. }
  4648. }
  4649. if (result0 !== null) {
  4650. result1 = parse_IPv6address();
  4651. if (result1 !== null) {
  4652. if (input.charCodeAt(pos) === 93) {
  4653. result2 = "]";
  4654. pos++;
  4655. } else {
  4656. result2 = null;
  4657. if (reportFailures === 0) {
  4658. matchFailed("\"]\"");
  4659. }
  4660. }
  4661. if (result2 !== null) {
  4662. result0 = [result0, result1, result2];
  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. if (result0 !== null) {
  4676. result0 = function (offset) {
  4677. data.host_type = 'IPv6';
  4678. return input.substring(pos, offset);
  4679. }(pos0);
  4680. }
  4681. if (result0 === null) {
  4682. pos = pos0;
  4683. }
  4684. return result0;
  4685. }
  4686. function parse_IPv6address() {
  4687. var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12;
  4688. var pos0, pos1, pos2;
  4689. pos0 = pos;
  4690. pos1 = pos;
  4691. result0 = parse_h16();
  4692. if (result0 !== null) {
  4693. if (input.charCodeAt(pos) === 58) {
  4694. result1 = ":";
  4695. pos++;
  4696. } else {
  4697. result1 = null;
  4698. if (reportFailures === 0) {
  4699. matchFailed("\":\"");
  4700. }
  4701. }
  4702. if (result1 !== null) {
  4703. result2 = parse_h16();
  4704. if (result2 !== null) {
  4705. if (input.charCodeAt(pos) === 58) {
  4706. result3 = ":";
  4707. pos++;
  4708. } else {
  4709. result3 = null;
  4710. if (reportFailures === 0) {
  4711. matchFailed("\":\"");
  4712. }
  4713. }
  4714. if (result3 !== null) {
  4715. result4 = parse_h16();
  4716. if (result4 !== null) {
  4717. if (input.charCodeAt(pos) === 58) {
  4718. result5 = ":";
  4719. pos++;
  4720. } else {
  4721. result5 = null;
  4722. if (reportFailures === 0) {
  4723. matchFailed("\":\"");
  4724. }
  4725. }
  4726. if (result5 !== null) {
  4727. result6 = parse_h16();
  4728. if (result6 !== null) {
  4729. if (input.charCodeAt(pos) === 58) {
  4730. result7 = ":";
  4731. pos++;
  4732. } else {
  4733. result7 = null;
  4734. if (reportFailures === 0) {
  4735. matchFailed("\":\"");
  4736. }
  4737. }
  4738. if (result7 !== null) {
  4739. result8 = parse_h16();
  4740. if (result8 !== null) {
  4741. if (input.charCodeAt(pos) === 58) {
  4742. result9 = ":";
  4743. pos++;
  4744. } else {
  4745. result9 = null;
  4746. if (reportFailures === 0) {
  4747. matchFailed("\":\"");
  4748. }
  4749. }
  4750. if (result9 !== null) {
  4751. result10 = parse_h16();
  4752. if (result10 !== null) {
  4753. if (input.charCodeAt(pos) === 58) {
  4754. result11 = ":";
  4755. pos++;
  4756. } else {
  4757. result11 = null;
  4758. if (reportFailures === 0) {
  4759. matchFailed("\":\"");
  4760. }
  4761. }
  4762. if (result11 !== null) {
  4763. result12 = parse_ls32();
  4764. if (result12 !== null) {
  4765. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
  4766. } else {
  4767. result0 = null;
  4768. pos = pos1;
  4769. }
  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_h16();
  4879. if (result9 !== null) {
  4880. if (input.charCodeAt(pos) === 58) {
  4881. result10 = ":";
  4882. pos++;
  4883. } else {
  4884. result10 = null;
  4885. if (reportFailures === 0) {
  4886. matchFailed("\":\"");
  4887. }
  4888. }
  4889. if (result10 !== null) {
  4890. result11 = parse_ls32();
  4891. if (result11 !== null) {
  4892. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11];
  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. } else {
  4922. result0 = null;
  4923. pos = pos1;
  4924. }
  4925. } else {
  4926. result0 = null;
  4927. pos = pos1;
  4928. }
  4929. } else {
  4930. result0 = null;
  4931. pos = pos1;
  4932. }
  4933. } else {
  4934. result0 = null;
  4935. pos = pos1;
  4936. }
  4937. } else {
  4938. result0 = null;
  4939. pos = pos1;
  4940. }
  4941. if (result0 === null) {
  4942. pos1 = pos;
  4943. if (input.substr(pos, 2) === "::") {
  4944. result0 = "::";
  4945. pos += 2;
  4946. } else {
  4947. result0 = null;
  4948. if (reportFailures === 0) {
  4949. matchFailed("\"::\"");
  4950. }
  4951. }
  4952. if (result0 !== null) {
  4953. result1 = parse_h16();
  4954. if (result1 !== null) {
  4955. if (input.charCodeAt(pos) === 58) {
  4956. result2 = ":";
  4957. pos++;
  4958. } else {
  4959. result2 = null;
  4960. if (reportFailures === 0) {
  4961. matchFailed("\":\"");
  4962. }
  4963. }
  4964. if (result2 !== null) {
  4965. result3 = parse_h16();
  4966. if (result3 !== null) {
  4967. if (input.charCodeAt(pos) === 58) {
  4968. result4 = ":";
  4969. pos++;
  4970. } else {
  4971. result4 = null;
  4972. if (reportFailures === 0) {
  4973. matchFailed("\":\"");
  4974. }
  4975. }
  4976. if (result4 !== null) {
  4977. result5 = parse_h16();
  4978. if (result5 !== null) {
  4979. if (input.charCodeAt(pos) === 58) {
  4980. result6 = ":";
  4981. pos++;
  4982. } else {
  4983. result6 = null;
  4984. if (reportFailures === 0) {
  4985. matchFailed("\":\"");
  4986. }
  4987. }
  4988. if (result6 !== null) {
  4989. result7 = parse_h16();
  4990. if (result7 !== null) {
  4991. if (input.charCodeAt(pos) === 58) {
  4992. result8 = ":";
  4993. pos++;
  4994. } else {
  4995. result8 = null;
  4996. if (reportFailures === 0) {
  4997. matchFailed("\":\"");
  4998. }
  4999. }
  5000. if (result8 !== null) {
  5001. result9 = parse_ls32();
  5002. if (result9 !== null) {
  5003. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  5004. } else {
  5005. result0 = null;
  5006. pos = pos1;
  5007. }
  5008. } else {
  5009. result0 = null;
  5010. pos = pos1;
  5011. }
  5012. } else {
  5013. result0 = null;
  5014. pos = pos1;
  5015. }
  5016. } else {
  5017. result0 = null;
  5018. pos = pos1;
  5019. }
  5020. } else {
  5021. result0 = null;
  5022. pos = pos1;
  5023. }
  5024. } else {
  5025. result0 = null;
  5026. pos = pos1;
  5027. }
  5028. } else {
  5029. result0 = null;
  5030. pos = pos1;
  5031. }
  5032. } else {
  5033. result0 = null;
  5034. pos = pos1;
  5035. }
  5036. } else {
  5037. result0 = null;
  5038. pos = pos1;
  5039. }
  5040. } else {
  5041. result0 = null;
  5042. pos = pos1;
  5043. }
  5044. if (result0 === null) {
  5045. pos1 = pos;
  5046. if (input.substr(pos, 2) === "::") {
  5047. result0 = "::";
  5048. pos += 2;
  5049. } else {
  5050. result0 = null;
  5051. if (reportFailures === 0) {
  5052. matchFailed("\"::\"");
  5053. }
  5054. }
  5055. if (result0 !== null) {
  5056. result1 = parse_h16();
  5057. if (result1 !== null) {
  5058. if (input.charCodeAt(pos) === 58) {
  5059. result2 = ":";
  5060. pos++;
  5061. } else {
  5062. result2 = null;
  5063. if (reportFailures === 0) {
  5064. matchFailed("\":\"");
  5065. }
  5066. }
  5067. if (result2 !== null) {
  5068. result3 = parse_h16();
  5069. if (result3 !== null) {
  5070. if (input.charCodeAt(pos) === 58) {
  5071. result4 = ":";
  5072. pos++;
  5073. } else {
  5074. result4 = null;
  5075. if (reportFailures === 0) {
  5076. matchFailed("\":\"");
  5077. }
  5078. }
  5079. if (result4 !== null) {
  5080. result5 = parse_h16();
  5081. if (result5 !== null) {
  5082. if (input.charCodeAt(pos) === 58) {
  5083. result6 = ":";
  5084. pos++;
  5085. } else {
  5086. result6 = null;
  5087. if (reportFailures === 0) {
  5088. matchFailed("\":\"");
  5089. }
  5090. }
  5091. if (result6 !== null) {
  5092. result7 = parse_ls32();
  5093. if (result7 !== null) {
  5094. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5095. } else {
  5096. result0 = null;
  5097. pos = pos1;
  5098. }
  5099. } else {
  5100. result0 = null;
  5101. pos = pos1;
  5102. }
  5103. } else {
  5104. result0 = null;
  5105. pos = pos1;
  5106. }
  5107. } else {
  5108. result0 = null;
  5109. pos = pos1;
  5110. }
  5111. } else {
  5112. result0 = null;
  5113. pos = pos1;
  5114. }
  5115. } else {
  5116. result0 = null;
  5117. pos = pos1;
  5118. }
  5119. } else {
  5120. result0 = null;
  5121. pos = pos1;
  5122. }
  5123. } else {
  5124. result0 = null;
  5125. pos = pos1;
  5126. }
  5127. if (result0 === null) {
  5128. pos1 = pos;
  5129. if (input.substr(pos, 2) === "::") {
  5130. result0 = "::";
  5131. pos += 2;
  5132. } else {
  5133. result0 = null;
  5134. if (reportFailures === 0) {
  5135. matchFailed("\"::\"");
  5136. }
  5137. }
  5138. if (result0 !== null) {
  5139. result1 = parse_h16();
  5140. if (result1 !== null) {
  5141. if (input.charCodeAt(pos) === 58) {
  5142. result2 = ":";
  5143. pos++;
  5144. } else {
  5145. result2 = null;
  5146. if (reportFailures === 0) {
  5147. matchFailed("\":\"");
  5148. }
  5149. }
  5150. if (result2 !== null) {
  5151. result3 = parse_h16();
  5152. if (result3 !== null) {
  5153. if (input.charCodeAt(pos) === 58) {
  5154. result4 = ":";
  5155. pos++;
  5156. } else {
  5157. result4 = null;
  5158. if (reportFailures === 0) {
  5159. matchFailed("\":\"");
  5160. }
  5161. }
  5162. if (result4 !== null) {
  5163. result5 = parse_ls32();
  5164. if (result5 !== null) {
  5165. result0 = [result0, result1, result2, result3, result4, result5];
  5166. } else {
  5167. result0 = null;
  5168. pos = pos1;
  5169. }
  5170. } else {
  5171. result0 = null;
  5172. pos = pos1;
  5173. }
  5174. } else {
  5175. result0 = null;
  5176. pos = pos1;
  5177. }
  5178. } else {
  5179. result0 = null;
  5180. pos = pos1;
  5181. }
  5182. } else {
  5183. result0 = null;
  5184. pos = pos1;
  5185. }
  5186. } else {
  5187. result0 = null;
  5188. pos = pos1;
  5189. }
  5190. if (result0 === null) {
  5191. pos1 = pos;
  5192. if (input.substr(pos, 2) === "::") {
  5193. result0 = "::";
  5194. pos += 2;
  5195. } else {
  5196. result0 = null;
  5197. if (reportFailures === 0) {
  5198. matchFailed("\"::\"");
  5199. }
  5200. }
  5201. if (result0 !== null) {
  5202. result1 = parse_h16();
  5203. if (result1 !== null) {
  5204. if (input.charCodeAt(pos) === 58) {
  5205. result2 = ":";
  5206. pos++;
  5207. } else {
  5208. result2 = null;
  5209. if (reportFailures === 0) {
  5210. matchFailed("\":\"");
  5211. }
  5212. }
  5213. if (result2 !== null) {
  5214. result3 = parse_ls32();
  5215. if (result3 !== null) {
  5216. result0 = [result0, result1, result2, result3];
  5217. } else {
  5218. result0 = null;
  5219. pos = pos1;
  5220. }
  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. if (result0 === null) {
  5234. pos1 = pos;
  5235. if (input.substr(pos, 2) === "::") {
  5236. result0 = "::";
  5237. pos += 2;
  5238. } else {
  5239. result0 = null;
  5240. if (reportFailures === 0) {
  5241. matchFailed("\"::\"");
  5242. }
  5243. }
  5244. if (result0 !== null) {
  5245. result1 = parse_ls32();
  5246. if (result1 !== null) {
  5247. result0 = [result0, result1];
  5248. } else {
  5249. result0 = null;
  5250. pos = pos1;
  5251. }
  5252. } else {
  5253. result0 = null;
  5254. pos = pos1;
  5255. }
  5256. if (result0 === null) {
  5257. pos1 = pos;
  5258. if (input.substr(pos, 2) === "::") {
  5259. result0 = "::";
  5260. pos += 2;
  5261. } else {
  5262. result0 = null;
  5263. if (reportFailures === 0) {
  5264. matchFailed("\"::\"");
  5265. }
  5266. }
  5267. if (result0 !== null) {
  5268. result1 = parse_h16();
  5269. if (result1 !== null) {
  5270. result0 = [result0, result1];
  5271. } else {
  5272. result0 = null;
  5273. pos = pos1;
  5274. }
  5275. } else {
  5276. result0 = null;
  5277. pos = pos1;
  5278. }
  5279. if (result0 === null) {
  5280. pos1 = pos;
  5281. result0 = parse_h16();
  5282. if (result0 !== null) {
  5283. if (input.substr(pos, 2) === "::") {
  5284. result1 = "::";
  5285. pos += 2;
  5286. } else {
  5287. result1 = null;
  5288. if (reportFailures === 0) {
  5289. matchFailed("\"::\"");
  5290. }
  5291. }
  5292. if (result1 !== null) {
  5293. result2 = parse_h16();
  5294. if (result2 !== null) {
  5295. if (input.charCodeAt(pos) === 58) {
  5296. result3 = ":";
  5297. pos++;
  5298. } else {
  5299. result3 = null;
  5300. if (reportFailures === 0) {
  5301. matchFailed("\":\"");
  5302. }
  5303. }
  5304. if (result3 !== null) {
  5305. result4 = parse_h16();
  5306. if (result4 !== null) {
  5307. if (input.charCodeAt(pos) === 58) {
  5308. result5 = ":";
  5309. pos++;
  5310. } else {
  5311. result5 = null;
  5312. if (reportFailures === 0) {
  5313. matchFailed("\":\"");
  5314. }
  5315. }
  5316. if (result5 !== null) {
  5317. result6 = parse_h16();
  5318. if (result6 !== null) {
  5319. if (input.charCodeAt(pos) === 58) {
  5320. result7 = ":";
  5321. pos++;
  5322. } else {
  5323. result7 = null;
  5324. if (reportFailures === 0) {
  5325. matchFailed("\":\"");
  5326. }
  5327. }
  5328. if (result7 !== null) {
  5329. result8 = parse_h16();
  5330. if (result8 !== null) {
  5331. if (input.charCodeAt(pos) === 58) {
  5332. result9 = ":";
  5333. pos++;
  5334. } else {
  5335. result9 = null;
  5336. if (reportFailures === 0) {
  5337. matchFailed("\":\"");
  5338. }
  5339. }
  5340. if (result9 !== null) {
  5341. result10 = parse_ls32();
  5342. if (result10 !== null) {
  5343. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10];
  5344. } else {
  5345. result0 = null;
  5346. pos = pos1;
  5347. }
  5348. } else {
  5349. result0 = null;
  5350. pos = pos1;
  5351. }
  5352. } else {
  5353. result0 = null;
  5354. pos = pos1;
  5355. }
  5356. } else {
  5357. result0 = null;
  5358. pos = pos1;
  5359. }
  5360. } else {
  5361. result0 = null;
  5362. pos = pos1;
  5363. }
  5364. } else {
  5365. result0 = null;
  5366. pos = pos1;
  5367. }
  5368. } else {
  5369. result0 = null;
  5370. pos = pos1;
  5371. }
  5372. } else {
  5373. result0 = null;
  5374. pos = pos1;
  5375. }
  5376. } else {
  5377. result0 = null;
  5378. pos = pos1;
  5379. }
  5380. } else {
  5381. result0 = null;
  5382. pos = pos1;
  5383. }
  5384. } else {
  5385. result0 = null;
  5386. pos = pos1;
  5387. }
  5388. if (result0 === null) {
  5389. pos1 = pos;
  5390. result0 = parse_h16();
  5391. if (result0 !== null) {
  5392. pos2 = pos;
  5393. if (input.charCodeAt(pos) === 58) {
  5394. result1 = ":";
  5395. pos++;
  5396. } else {
  5397. result1 = null;
  5398. if (reportFailures === 0) {
  5399. matchFailed("\":\"");
  5400. }
  5401. }
  5402. if (result1 !== null) {
  5403. result2 = parse_h16();
  5404. if (result2 !== null) {
  5405. result1 = [result1, result2];
  5406. } else {
  5407. result1 = null;
  5408. pos = pos2;
  5409. }
  5410. } else {
  5411. result1 = null;
  5412. pos = pos2;
  5413. }
  5414. result1 = result1 !== null ? result1 : "";
  5415. if (result1 !== null) {
  5416. if (input.substr(pos, 2) === "::") {
  5417. result2 = "::";
  5418. pos += 2;
  5419. } else {
  5420. result2 = null;
  5421. if (reportFailures === 0) {
  5422. matchFailed("\"::\"");
  5423. }
  5424. }
  5425. if (result2 !== null) {
  5426. result3 = parse_h16();
  5427. if (result3 !== null) {
  5428. if (input.charCodeAt(pos) === 58) {
  5429. result4 = ":";
  5430. pos++;
  5431. } else {
  5432. result4 = null;
  5433. if (reportFailures === 0) {
  5434. matchFailed("\":\"");
  5435. }
  5436. }
  5437. if (result4 !== null) {
  5438. result5 = parse_h16();
  5439. if (result5 !== null) {
  5440. if (input.charCodeAt(pos) === 58) {
  5441. result6 = ":";
  5442. pos++;
  5443. } else {
  5444. result6 = null;
  5445. if (reportFailures === 0) {
  5446. matchFailed("\":\"");
  5447. }
  5448. }
  5449. if (result6 !== null) {
  5450. result7 = parse_h16();
  5451. if (result7 !== null) {
  5452. if (input.charCodeAt(pos) === 58) {
  5453. result8 = ":";
  5454. pos++;
  5455. } else {
  5456. result8 = null;
  5457. if (reportFailures === 0) {
  5458. matchFailed("\":\"");
  5459. }
  5460. }
  5461. if (result8 !== null) {
  5462. result9 = parse_ls32();
  5463. if (result9 !== null) {
  5464. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  5465. } else {
  5466. result0 = null;
  5467. pos = pos1;
  5468. }
  5469. } else {
  5470. result0 = null;
  5471. pos = pos1;
  5472. }
  5473. } else {
  5474. result0 = null;
  5475. pos = pos1;
  5476. }
  5477. } else {
  5478. result0 = null;
  5479. pos = pos1;
  5480. }
  5481. } else {
  5482. result0 = null;
  5483. pos = pos1;
  5484. }
  5485. } else {
  5486. result0 = null;
  5487. pos = pos1;
  5488. }
  5489. } else {
  5490. result0 = null;
  5491. pos = pos1;
  5492. }
  5493. } else {
  5494. result0 = null;
  5495. pos = pos1;
  5496. }
  5497. } else {
  5498. result0 = null;
  5499. pos = pos1;
  5500. }
  5501. } else {
  5502. result0 = null;
  5503. pos = pos1;
  5504. }
  5505. if (result0 === null) {
  5506. pos1 = pos;
  5507. result0 = parse_h16();
  5508. if (result0 !== null) {
  5509. pos2 = pos;
  5510. if (input.charCodeAt(pos) === 58) {
  5511. result1 = ":";
  5512. pos++;
  5513. } else {
  5514. result1 = null;
  5515. if (reportFailures === 0) {
  5516. matchFailed("\":\"");
  5517. }
  5518. }
  5519. if (result1 !== null) {
  5520. result2 = parse_h16();
  5521. if (result2 !== null) {
  5522. result1 = [result1, result2];
  5523. } else {
  5524. result1 = null;
  5525. pos = pos2;
  5526. }
  5527. } else {
  5528. result1 = null;
  5529. pos = pos2;
  5530. }
  5531. result1 = result1 !== null ? result1 : "";
  5532. if (result1 !== null) {
  5533. pos2 = pos;
  5534. if (input.charCodeAt(pos) === 58) {
  5535. result2 = ":";
  5536. pos++;
  5537. } else {
  5538. result2 = null;
  5539. if (reportFailures === 0) {
  5540. matchFailed("\":\"");
  5541. }
  5542. }
  5543. if (result2 !== null) {
  5544. result3 = parse_h16();
  5545. if (result3 !== null) {
  5546. result2 = [result2, result3];
  5547. } else {
  5548. result2 = null;
  5549. pos = pos2;
  5550. }
  5551. } else {
  5552. result2 = null;
  5553. pos = pos2;
  5554. }
  5555. result2 = result2 !== null ? result2 : "";
  5556. if (result2 !== null) {
  5557. if (input.substr(pos, 2) === "::") {
  5558. result3 = "::";
  5559. pos += 2;
  5560. } else {
  5561. result3 = null;
  5562. if (reportFailures === 0) {
  5563. matchFailed("\"::\"");
  5564. }
  5565. }
  5566. if (result3 !== null) {
  5567. result4 = parse_h16();
  5568. if (result4 !== null) {
  5569. if (input.charCodeAt(pos) === 58) {
  5570. result5 = ":";
  5571. pos++;
  5572. } else {
  5573. result5 = null;
  5574. if (reportFailures === 0) {
  5575. matchFailed("\":\"");
  5576. }
  5577. }
  5578. if (result5 !== null) {
  5579. result6 = parse_h16();
  5580. if (result6 !== null) {
  5581. if (input.charCodeAt(pos) === 58) {
  5582. result7 = ":";
  5583. pos++;
  5584. } else {
  5585. result7 = null;
  5586. if (reportFailures === 0) {
  5587. matchFailed("\":\"");
  5588. }
  5589. }
  5590. if (result7 !== null) {
  5591. result8 = parse_ls32();
  5592. if (result8 !== null) {
  5593. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  5594. } else {
  5595. result0 = null;
  5596. pos = pos1;
  5597. }
  5598. } else {
  5599. result0 = null;
  5600. pos = pos1;
  5601. }
  5602. } else {
  5603. result0 = null;
  5604. pos = pos1;
  5605. }
  5606. } else {
  5607. result0 = null;
  5608. pos = pos1;
  5609. }
  5610. } else {
  5611. result0 = null;
  5612. pos = pos1;
  5613. }
  5614. } else {
  5615. result0 = null;
  5616. pos = pos1;
  5617. }
  5618. } else {
  5619. result0 = null;
  5620. pos = pos1;
  5621. }
  5622. } else {
  5623. result0 = null;
  5624. pos = pos1;
  5625. }
  5626. } else {
  5627. result0 = null;
  5628. pos = pos1;
  5629. }
  5630. if (result0 === null) {
  5631. pos1 = pos;
  5632. result0 = parse_h16();
  5633. if (result0 !== null) {
  5634. pos2 = pos;
  5635. if (input.charCodeAt(pos) === 58) {
  5636. result1 = ":";
  5637. pos++;
  5638. } else {
  5639. result1 = null;
  5640. if (reportFailures === 0) {
  5641. matchFailed("\":\"");
  5642. }
  5643. }
  5644. if (result1 !== null) {
  5645. result2 = parse_h16();
  5646. if (result2 !== null) {
  5647. result1 = [result1, result2];
  5648. } else {
  5649. result1 = null;
  5650. pos = pos2;
  5651. }
  5652. } else {
  5653. result1 = null;
  5654. pos = pos2;
  5655. }
  5656. result1 = result1 !== null ? result1 : "";
  5657. if (result1 !== null) {
  5658. pos2 = pos;
  5659. if (input.charCodeAt(pos) === 58) {
  5660. result2 = ":";
  5661. pos++;
  5662. } else {
  5663. result2 = null;
  5664. if (reportFailures === 0) {
  5665. matchFailed("\":\"");
  5666. }
  5667. }
  5668. if (result2 !== null) {
  5669. result3 = parse_h16();
  5670. if (result3 !== null) {
  5671. result2 = [result2, result3];
  5672. } else {
  5673. result2 = null;
  5674. pos = pos2;
  5675. }
  5676. } else {
  5677. result2 = null;
  5678. pos = pos2;
  5679. }
  5680. result2 = result2 !== null ? result2 : "";
  5681. if (result2 !== null) {
  5682. pos2 = pos;
  5683. if (input.charCodeAt(pos) === 58) {
  5684. result3 = ":";
  5685. pos++;
  5686. } else {
  5687. result3 = null;
  5688. if (reportFailures === 0) {
  5689. matchFailed("\":\"");
  5690. }
  5691. }
  5692. if (result3 !== null) {
  5693. result4 = parse_h16();
  5694. if (result4 !== null) {
  5695. result3 = [result3, result4];
  5696. } else {
  5697. result3 = null;
  5698. pos = pos2;
  5699. }
  5700. } else {
  5701. result3 = null;
  5702. pos = pos2;
  5703. }
  5704. result3 = result3 !== null ? result3 : "";
  5705. if (result3 !== null) {
  5706. if (input.substr(pos, 2) === "::") {
  5707. result4 = "::";
  5708. pos += 2;
  5709. } else {
  5710. result4 = null;
  5711. if (reportFailures === 0) {
  5712. matchFailed("\"::\"");
  5713. }
  5714. }
  5715. if (result4 !== null) {
  5716. result5 = parse_h16();
  5717. if (result5 !== null) {
  5718. if (input.charCodeAt(pos) === 58) {
  5719. result6 = ":";
  5720. pos++;
  5721. } else {
  5722. result6 = null;
  5723. if (reportFailures === 0) {
  5724. matchFailed("\":\"");
  5725. }
  5726. }
  5727. if (result6 !== null) {
  5728. result7 = parse_ls32();
  5729. if (result7 !== null) {
  5730. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5731. } else {
  5732. result0 = null;
  5733. pos = pos1;
  5734. }
  5735. } else {
  5736. result0 = null;
  5737. pos = pos1;
  5738. }
  5739. } else {
  5740. result0 = null;
  5741. pos = pos1;
  5742. }
  5743. } else {
  5744. result0 = null;
  5745. pos = pos1;
  5746. }
  5747. } else {
  5748. result0 = null;
  5749. pos = pos1;
  5750. }
  5751. } else {
  5752. result0 = null;
  5753. pos = pos1;
  5754. }
  5755. } else {
  5756. result0 = null;
  5757. pos = pos1;
  5758. }
  5759. } else {
  5760. result0 = null;
  5761. pos = pos1;
  5762. }
  5763. if (result0 === null) {
  5764. pos1 = pos;
  5765. result0 = parse_h16();
  5766. if (result0 !== null) {
  5767. pos2 = pos;
  5768. if (input.charCodeAt(pos) === 58) {
  5769. result1 = ":";
  5770. pos++;
  5771. } else {
  5772. result1 = null;
  5773. if (reportFailures === 0) {
  5774. matchFailed("\":\"");
  5775. }
  5776. }
  5777. if (result1 !== null) {
  5778. result2 = parse_h16();
  5779. if (result2 !== null) {
  5780. result1 = [result1, result2];
  5781. } else {
  5782. result1 = null;
  5783. pos = pos2;
  5784. }
  5785. } else {
  5786. result1 = null;
  5787. pos = pos2;
  5788. }
  5789. result1 = result1 !== null ? result1 : "";
  5790. if (result1 !== null) {
  5791. pos2 = pos;
  5792. if (input.charCodeAt(pos) === 58) {
  5793. result2 = ":";
  5794. pos++;
  5795. } else {
  5796. result2 = null;
  5797. if (reportFailures === 0) {
  5798. matchFailed("\":\"");
  5799. }
  5800. }
  5801. if (result2 !== null) {
  5802. result3 = parse_h16();
  5803. if (result3 !== null) {
  5804. result2 = [result2, result3];
  5805. } else {
  5806. result2 = null;
  5807. pos = pos2;
  5808. }
  5809. } else {
  5810. result2 = null;
  5811. pos = pos2;
  5812. }
  5813. result2 = result2 !== null ? result2 : "";
  5814. if (result2 !== null) {
  5815. pos2 = pos;
  5816. if (input.charCodeAt(pos) === 58) {
  5817. result3 = ":";
  5818. pos++;
  5819. } else {
  5820. result3 = null;
  5821. if (reportFailures === 0) {
  5822. matchFailed("\":\"");
  5823. }
  5824. }
  5825. if (result3 !== null) {
  5826. result4 = parse_h16();
  5827. if (result4 !== null) {
  5828. result3 = [result3, result4];
  5829. } else {
  5830. result3 = null;
  5831. pos = pos2;
  5832. }
  5833. } else {
  5834. result3 = null;
  5835. pos = pos2;
  5836. }
  5837. result3 = result3 !== null ? result3 : "";
  5838. if (result3 !== null) {
  5839. pos2 = pos;
  5840. if (input.charCodeAt(pos) === 58) {
  5841. result4 = ":";
  5842. pos++;
  5843. } else {
  5844. result4 = null;
  5845. if (reportFailures === 0) {
  5846. matchFailed("\":\"");
  5847. }
  5848. }
  5849. if (result4 !== null) {
  5850. result5 = parse_h16();
  5851. if (result5 !== null) {
  5852. result4 = [result4, result5];
  5853. } else {
  5854. result4 = null;
  5855. pos = pos2;
  5856. }
  5857. } else {
  5858. result4 = null;
  5859. pos = pos2;
  5860. }
  5861. result4 = result4 !== null ? result4 : "";
  5862. if (result4 !== null) {
  5863. if (input.substr(pos, 2) === "::") {
  5864. result5 = "::";
  5865. pos += 2;
  5866. } else {
  5867. result5 = null;
  5868. if (reportFailures === 0) {
  5869. matchFailed("\"::\"");
  5870. }
  5871. }
  5872. if (result5 !== null) {
  5873. result6 = parse_ls32();
  5874. if (result6 !== null) {
  5875. result0 = [result0, result1, result2, result3, result4, result5, result6];
  5876. } else {
  5877. result0 = null;
  5878. pos = pos1;
  5879. }
  5880. } else {
  5881. result0 = null;
  5882. pos = pos1;
  5883. }
  5884. } else {
  5885. result0 = null;
  5886. pos = pos1;
  5887. }
  5888. } else {
  5889. result0 = null;
  5890. pos = pos1;
  5891. }
  5892. } else {
  5893. result0 = null;
  5894. pos = pos1;
  5895. }
  5896. } else {
  5897. result0 = null;
  5898. pos = pos1;
  5899. }
  5900. } else {
  5901. result0 = null;
  5902. pos = pos1;
  5903. }
  5904. if (result0 === null) {
  5905. pos1 = pos;
  5906. result0 = parse_h16();
  5907. if (result0 !== null) {
  5908. pos2 = pos;
  5909. if (input.charCodeAt(pos) === 58) {
  5910. result1 = ":";
  5911. pos++;
  5912. } else {
  5913. result1 = null;
  5914. if (reportFailures === 0) {
  5915. matchFailed("\":\"");
  5916. }
  5917. }
  5918. if (result1 !== null) {
  5919. result2 = parse_h16();
  5920. if (result2 !== null) {
  5921. result1 = [result1, result2];
  5922. } else {
  5923. result1 = null;
  5924. pos = pos2;
  5925. }
  5926. } else {
  5927. result1 = null;
  5928. pos = pos2;
  5929. }
  5930. result1 = result1 !== null ? result1 : "";
  5931. if (result1 !== null) {
  5932. pos2 = pos;
  5933. if (input.charCodeAt(pos) === 58) {
  5934. result2 = ":";
  5935. pos++;
  5936. } else {
  5937. result2 = null;
  5938. if (reportFailures === 0) {
  5939. matchFailed("\":\"");
  5940. }
  5941. }
  5942. if (result2 !== null) {
  5943. result3 = parse_h16();
  5944. if (result3 !== null) {
  5945. result2 = [result2, result3];
  5946. } else {
  5947. result2 = null;
  5948. pos = pos2;
  5949. }
  5950. } else {
  5951. result2 = null;
  5952. pos = pos2;
  5953. }
  5954. result2 = result2 !== null ? result2 : "";
  5955. if (result2 !== null) {
  5956. pos2 = pos;
  5957. if (input.charCodeAt(pos) === 58) {
  5958. result3 = ":";
  5959. pos++;
  5960. } else {
  5961. result3 = null;
  5962. if (reportFailures === 0) {
  5963. matchFailed("\":\"");
  5964. }
  5965. }
  5966. if (result3 !== null) {
  5967. result4 = parse_h16();
  5968. if (result4 !== null) {
  5969. result3 = [result3, result4];
  5970. } else {
  5971. result3 = null;
  5972. pos = pos2;
  5973. }
  5974. } else {
  5975. result3 = null;
  5976. pos = pos2;
  5977. }
  5978. result3 = result3 !== null ? result3 : "";
  5979. if (result3 !== null) {
  5980. pos2 = pos;
  5981. if (input.charCodeAt(pos) === 58) {
  5982. result4 = ":";
  5983. pos++;
  5984. } else {
  5985. result4 = null;
  5986. if (reportFailures === 0) {
  5987. matchFailed("\":\"");
  5988. }
  5989. }
  5990. if (result4 !== null) {
  5991. result5 = parse_h16();
  5992. if (result5 !== null) {
  5993. result4 = [result4, result5];
  5994. } else {
  5995. result4 = null;
  5996. pos = pos2;
  5997. }
  5998. } else {
  5999. result4 = null;
  6000. pos = pos2;
  6001. }
  6002. result4 = result4 !== null ? result4 : "";
  6003. if (result4 !== null) {
  6004. pos2 = pos;
  6005. if (input.charCodeAt(pos) === 58) {
  6006. result5 = ":";
  6007. pos++;
  6008. } else {
  6009. result5 = null;
  6010. if (reportFailures === 0) {
  6011. matchFailed("\":\"");
  6012. }
  6013. }
  6014. if (result5 !== null) {
  6015. result6 = parse_h16();
  6016. if (result6 !== null) {
  6017. result5 = [result5, result6];
  6018. } else {
  6019. result5 = null;
  6020. pos = pos2;
  6021. }
  6022. } else {
  6023. result5 = null;
  6024. pos = pos2;
  6025. }
  6026. result5 = result5 !== null ? result5 : "";
  6027. if (result5 !== null) {
  6028. if (input.substr(pos, 2) === "::") {
  6029. result6 = "::";
  6030. pos += 2;
  6031. } else {
  6032. result6 = null;
  6033. if (reportFailures === 0) {
  6034. matchFailed("\"::\"");
  6035. }
  6036. }
  6037. if (result6 !== null) {
  6038. result7 = parse_h16();
  6039. if (result7 !== null) {
  6040. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  6041. } else {
  6042. result0 = null;
  6043. pos = pos1;
  6044. }
  6045. } else {
  6046. result0 = null;
  6047. pos = pos1;
  6048. }
  6049. } else {
  6050. result0 = null;
  6051. pos = pos1;
  6052. }
  6053. } else {
  6054. result0 = null;
  6055. pos = pos1;
  6056. }
  6057. } else {
  6058. result0 = null;
  6059. pos = pos1;
  6060. }
  6061. } else {
  6062. result0 = null;
  6063. pos = pos1;
  6064. }
  6065. } else {
  6066. result0 = null;
  6067. pos = pos1;
  6068. }
  6069. } else {
  6070. result0 = null;
  6071. pos = pos1;
  6072. }
  6073. if (result0 === null) {
  6074. pos1 = pos;
  6075. result0 = parse_h16();
  6076. if (result0 !== null) {
  6077. pos2 = pos;
  6078. if (input.charCodeAt(pos) === 58) {
  6079. result1 = ":";
  6080. pos++;
  6081. } else {
  6082. result1 = null;
  6083. if (reportFailures === 0) {
  6084. matchFailed("\":\"");
  6085. }
  6086. }
  6087. if (result1 !== null) {
  6088. result2 = parse_h16();
  6089. if (result2 !== null) {
  6090. result1 = [result1, result2];
  6091. } else {
  6092. result1 = null;
  6093. pos = pos2;
  6094. }
  6095. } else {
  6096. result1 = null;
  6097. pos = pos2;
  6098. }
  6099. result1 = result1 !== null ? result1 : "";
  6100. if (result1 !== null) {
  6101. pos2 = pos;
  6102. if (input.charCodeAt(pos) === 58) {
  6103. result2 = ":";
  6104. pos++;
  6105. } else {
  6106. result2 = null;
  6107. if (reportFailures === 0) {
  6108. matchFailed("\":\"");
  6109. }
  6110. }
  6111. if (result2 !== null) {
  6112. result3 = parse_h16();
  6113. if (result3 !== null) {
  6114. result2 = [result2, result3];
  6115. } else {
  6116. result2 = null;
  6117. pos = pos2;
  6118. }
  6119. } else {
  6120. result2 = null;
  6121. pos = pos2;
  6122. }
  6123. result2 = result2 !== null ? result2 : "";
  6124. if (result2 !== null) {
  6125. pos2 = pos;
  6126. if (input.charCodeAt(pos) === 58) {
  6127. result3 = ":";
  6128. pos++;
  6129. } else {
  6130. result3 = null;
  6131. if (reportFailures === 0) {
  6132. matchFailed("\":\"");
  6133. }
  6134. }
  6135. if (result3 !== null) {
  6136. result4 = parse_h16();
  6137. if (result4 !== null) {
  6138. result3 = [result3, result4];
  6139. } else {
  6140. result3 = null;
  6141. pos = pos2;
  6142. }
  6143. } else {
  6144. result3 = null;
  6145. pos = pos2;
  6146. }
  6147. result3 = result3 !== null ? result3 : "";
  6148. if (result3 !== null) {
  6149. pos2 = pos;
  6150. if (input.charCodeAt(pos) === 58) {
  6151. result4 = ":";
  6152. pos++;
  6153. } else {
  6154. result4 = null;
  6155. if (reportFailures === 0) {
  6156. matchFailed("\":\"");
  6157. }
  6158. }
  6159. if (result4 !== null) {
  6160. result5 = parse_h16();
  6161. if (result5 !== null) {
  6162. result4 = [result4, result5];
  6163. } else {
  6164. result4 = null;
  6165. pos = pos2;
  6166. }
  6167. } else {
  6168. result4 = null;
  6169. pos = pos2;
  6170. }
  6171. result4 = result4 !== null ? result4 : "";
  6172. if (result4 !== null) {
  6173. pos2 = pos;
  6174. if (input.charCodeAt(pos) === 58) {
  6175. result5 = ":";
  6176. pos++;
  6177. } else {
  6178. result5 = null;
  6179. if (reportFailures === 0) {
  6180. matchFailed("\":\"");
  6181. }
  6182. }
  6183. if (result5 !== null) {
  6184. result6 = parse_h16();
  6185. if (result6 !== null) {
  6186. result5 = [result5, result6];
  6187. } else {
  6188. result5 = null;
  6189. pos = pos2;
  6190. }
  6191. } else {
  6192. result5 = null;
  6193. pos = pos2;
  6194. }
  6195. result5 = result5 !== null ? result5 : "";
  6196. if (result5 !== null) {
  6197. pos2 = pos;
  6198. if (input.charCodeAt(pos) === 58) {
  6199. result6 = ":";
  6200. pos++;
  6201. } else {
  6202. result6 = null;
  6203. if (reportFailures === 0) {
  6204. matchFailed("\":\"");
  6205. }
  6206. }
  6207. if (result6 !== null) {
  6208. result7 = parse_h16();
  6209. if (result7 !== null) {
  6210. result6 = [result6, result7];
  6211. } else {
  6212. result6 = null;
  6213. pos = pos2;
  6214. }
  6215. } else {
  6216. result6 = null;
  6217. pos = pos2;
  6218. }
  6219. result6 = result6 !== null ? result6 : "";
  6220. if (result6 !== null) {
  6221. if (input.substr(pos, 2) === "::") {
  6222. result7 = "::";
  6223. pos += 2;
  6224. } else {
  6225. result7 = null;
  6226. if (reportFailures === 0) {
  6227. matchFailed("\"::\"");
  6228. }
  6229. }
  6230. if (result7 !== null) {
  6231. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  6232. } else {
  6233. result0 = null;
  6234. pos = pos1;
  6235. }
  6236. } else {
  6237. result0 = null;
  6238. pos = pos1;
  6239. }
  6240. } else {
  6241. result0 = null;
  6242. pos = pos1;
  6243. }
  6244. } else {
  6245. result0 = null;
  6246. pos = pos1;
  6247. }
  6248. } else {
  6249. result0 = null;
  6250. pos = pos1;
  6251. }
  6252. } else {
  6253. result0 = null;
  6254. pos = pos1;
  6255. }
  6256. } else {
  6257. result0 = null;
  6258. pos = pos1;
  6259. }
  6260. } else {
  6261. result0 = null;
  6262. pos = pos1;
  6263. }
  6264. }
  6265. }
  6266. }
  6267. }
  6268. }
  6269. }
  6270. }
  6271. }
  6272. }
  6273. }
  6274. }
  6275. }
  6276. }
  6277. }
  6278. if (result0 !== null) {
  6279. result0 = function (offset) {
  6280. data.host_type = 'IPv6';
  6281. return input.substring(pos, offset);
  6282. }(pos0);
  6283. }
  6284. if (result0 === null) {
  6285. pos = pos0;
  6286. }
  6287. return result0;
  6288. }
  6289. function parse_h16() {
  6290. var result0, result1, result2, result3;
  6291. var pos0;
  6292. pos0 = pos;
  6293. result0 = parse_HEXDIG();
  6294. if (result0 !== null) {
  6295. result1 = parse_HEXDIG();
  6296. result1 = result1 !== null ? result1 : "";
  6297. if (result1 !== null) {
  6298. result2 = parse_HEXDIG();
  6299. result2 = result2 !== null ? result2 : "";
  6300. if (result2 !== null) {
  6301. result3 = parse_HEXDIG();
  6302. result3 = result3 !== null ? result3 : "";
  6303. if (result3 !== null) {
  6304. result0 = [result0, result1, result2, result3];
  6305. } else {
  6306. result0 = null;
  6307. pos = pos0;
  6308. }
  6309. } else {
  6310. result0 = null;
  6311. pos = pos0;
  6312. }
  6313. } else {
  6314. result0 = null;
  6315. pos = pos0;
  6316. }
  6317. } else {
  6318. result0 = null;
  6319. pos = pos0;
  6320. }
  6321. return result0;
  6322. }
  6323. function parse_ls32() {
  6324. var result0, result1, result2;
  6325. var pos0;
  6326. pos0 = pos;
  6327. result0 = parse_h16();
  6328. if (result0 !== null) {
  6329. if (input.charCodeAt(pos) === 58) {
  6330. result1 = ":";
  6331. pos++;
  6332. } else {
  6333. result1 = null;
  6334. if (reportFailures === 0) {
  6335. matchFailed("\":\"");
  6336. }
  6337. }
  6338. if (result1 !== null) {
  6339. result2 = parse_h16();
  6340. if (result2 !== null) {
  6341. result0 = [result0, result1, result2];
  6342. } else {
  6343. result0 = null;
  6344. pos = pos0;
  6345. }
  6346. } else {
  6347. result0 = null;
  6348. pos = pos0;
  6349. }
  6350. } else {
  6351. result0 = null;
  6352. pos = pos0;
  6353. }
  6354. if (result0 === null) {
  6355. result0 = parse_IPv4address();
  6356. }
  6357. return result0;
  6358. }
  6359. function parse_IPv4address() {
  6360. var result0, result1, result2, result3, result4, result5, result6;
  6361. var pos0, pos1;
  6362. pos0 = pos;
  6363. pos1 = pos;
  6364. result0 = parse_dec_octet();
  6365. if (result0 !== null) {
  6366. if (input.charCodeAt(pos) === 46) {
  6367. result1 = ".";
  6368. pos++;
  6369. } else {
  6370. result1 = null;
  6371. if (reportFailures === 0) {
  6372. matchFailed("\".\"");
  6373. }
  6374. }
  6375. if (result1 !== null) {
  6376. result2 = parse_dec_octet();
  6377. if (result2 !== null) {
  6378. if (input.charCodeAt(pos) === 46) {
  6379. result3 = ".";
  6380. pos++;
  6381. } else {
  6382. result3 = null;
  6383. if (reportFailures === 0) {
  6384. matchFailed("\".\"");
  6385. }
  6386. }
  6387. if (result3 !== null) {
  6388. result4 = parse_dec_octet();
  6389. if (result4 !== null) {
  6390. if (input.charCodeAt(pos) === 46) {
  6391. result5 = ".";
  6392. pos++;
  6393. } else {
  6394. result5 = null;
  6395. if (reportFailures === 0) {
  6396. matchFailed("\".\"");
  6397. }
  6398. }
  6399. if (result5 !== null) {
  6400. result6 = parse_dec_octet();
  6401. if (result6 !== null) {
  6402. result0 = [result0, result1, result2, result3, result4, result5, result6];
  6403. } else {
  6404. result0 = null;
  6405. pos = pos1;
  6406. }
  6407. } else {
  6408. result0 = null;
  6409. pos = pos1;
  6410. }
  6411. } else {
  6412. result0 = null;
  6413. pos = pos1;
  6414. }
  6415. } else {
  6416. result0 = null;
  6417. pos = pos1;
  6418. }
  6419. } else {
  6420. result0 = null;
  6421. pos = pos1;
  6422. }
  6423. } else {
  6424. result0 = null;
  6425. pos = pos1;
  6426. }
  6427. } else {
  6428. result0 = null;
  6429. pos = pos1;
  6430. }
  6431. if (result0 !== null) {
  6432. result0 = function (offset) {
  6433. data.host_type = 'IPv4';
  6434. return input.substring(pos, offset);
  6435. }(pos0);
  6436. }
  6437. if (result0 === null) {
  6438. pos = pos0;
  6439. }
  6440. return result0;
  6441. }
  6442. function parse_dec_octet() {
  6443. var result0, result1, result2;
  6444. var pos0;
  6445. pos0 = pos;
  6446. if (input.substr(pos, 2) === "25") {
  6447. result0 = "25";
  6448. pos += 2;
  6449. } else {
  6450. result0 = null;
  6451. if (reportFailures === 0) {
  6452. matchFailed("\"25\"");
  6453. }
  6454. }
  6455. if (result0 !== null) {
  6456. if (/^[0-5]/.test(input.charAt(pos))) {
  6457. result1 = input.charAt(pos);
  6458. pos++;
  6459. } else {
  6460. result1 = null;
  6461. if (reportFailures === 0) {
  6462. matchFailed("[0-5]");
  6463. }
  6464. }
  6465. if (result1 !== null) {
  6466. result0 = [result0, result1];
  6467. } else {
  6468. result0 = null;
  6469. pos = pos0;
  6470. }
  6471. } else {
  6472. result0 = null;
  6473. pos = pos0;
  6474. }
  6475. if (result0 === null) {
  6476. pos0 = pos;
  6477. if (input.charCodeAt(pos) === 50) {
  6478. result0 = "2";
  6479. pos++;
  6480. } else {
  6481. result0 = null;
  6482. if (reportFailures === 0) {
  6483. matchFailed("\"2\"");
  6484. }
  6485. }
  6486. if (result0 !== null) {
  6487. if (/^[0-4]/.test(input.charAt(pos))) {
  6488. result1 = input.charAt(pos);
  6489. pos++;
  6490. } else {
  6491. result1 = null;
  6492. if (reportFailures === 0) {
  6493. matchFailed("[0-4]");
  6494. }
  6495. }
  6496. if (result1 !== null) {
  6497. result2 = parse_DIGIT();
  6498. if (result2 !== null) {
  6499. result0 = [result0, result1, result2];
  6500. } else {
  6501. result0 = null;
  6502. pos = pos0;
  6503. }
  6504. } else {
  6505. result0 = null;
  6506. pos = pos0;
  6507. }
  6508. } else {
  6509. result0 = null;
  6510. pos = pos0;
  6511. }
  6512. if (result0 === null) {
  6513. pos0 = pos;
  6514. if (input.charCodeAt(pos) === 49) {
  6515. result0 = "1";
  6516. pos++;
  6517. } else {
  6518. result0 = null;
  6519. if (reportFailures === 0) {
  6520. matchFailed("\"1\"");
  6521. }
  6522. }
  6523. if (result0 !== null) {
  6524. result1 = parse_DIGIT();
  6525. if (result1 !== null) {
  6526. result2 = parse_DIGIT();
  6527. if (result2 !== null) {
  6528. result0 = [result0, result1, result2];
  6529. } else {
  6530. result0 = null;
  6531. pos = pos0;
  6532. }
  6533. } else {
  6534. result0 = null;
  6535. pos = pos0;
  6536. }
  6537. } else {
  6538. result0 = null;
  6539. pos = pos0;
  6540. }
  6541. if (result0 === null) {
  6542. pos0 = pos;
  6543. if (/^[1-9]/.test(input.charAt(pos))) {
  6544. result0 = input.charAt(pos);
  6545. pos++;
  6546. } else {
  6547. result0 = null;
  6548. if (reportFailures === 0) {
  6549. matchFailed("[1-9]");
  6550. }
  6551. }
  6552. if (result0 !== null) {
  6553. result1 = parse_DIGIT();
  6554. if (result1 !== null) {
  6555. result0 = [result0, result1];
  6556. } else {
  6557. result0 = null;
  6558. pos = pos0;
  6559. }
  6560. } else {
  6561. result0 = null;
  6562. pos = pos0;
  6563. }
  6564. if (result0 === null) {
  6565. result0 = parse_DIGIT();
  6566. }
  6567. }
  6568. }
  6569. }
  6570. return result0;
  6571. }
  6572. function parse_port() {
  6573. var result0, result1, result2, result3, result4;
  6574. var pos0, pos1;
  6575. pos0 = pos;
  6576. pos1 = pos;
  6577. result0 = parse_DIGIT();
  6578. result0 = result0 !== null ? result0 : "";
  6579. if (result0 !== null) {
  6580. result1 = parse_DIGIT();
  6581. result1 = result1 !== null ? result1 : "";
  6582. if (result1 !== null) {
  6583. result2 = parse_DIGIT();
  6584. result2 = result2 !== null ? result2 : "";
  6585. if (result2 !== null) {
  6586. result3 = parse_DIGIT();
  6587. result3 = result3 !== null ? result3 : "";
  6588. if (result3 !== null) {
  6589. result4 = parse_DIGIT();
  6590. result4 = result4 !== null ? result4 : "";
  6591. if (result4 !== null) {
  6592. result0 = [result0, result1, result2, result3, result4];
  6593. } else {
  6594. result0 = null;
  6595. pos = pos1;
  6596. }
  6597. } else {
  6598. result0 = null;
  6599. pos = pos1;
  6600. }
  6601. } else {
  6602. result0 = null;
  6603. pos = pos1;
  6604. }
  6605. } else {
  6606. result0 = null;
  6607. pos = pos1;
  6608. }
  6609. } else {
  6610. result0 = null;
  6611. pos = pos1;
  6612. }
  6613. if (result0 !== null) {
  6614. result0 = function (offset, port) {
  6615. port = parseInt(port.join(''));
  6616. data.port = port;
  6617. return port;
  6618. }(pos0, result0);
  6619. }
  6620. if (result0 === null) {
  6621. pos = pos0;
  6622. }
  6623. return result0;
  6624. }
  6625. function parse_uri_parameters() {
  6626. var result0, result1, result2;
  6627. var pos0;
  6628. result0 = [];
  6629. pos0 = pos;
  6630. if (input.charCodeAt(pos) === 59) {
  6631. result1 = ";";
  6632. pos++;
  6633. } else {
  6634. result1 = null;
  6635. if (reportFailures === 0) {
  6636. matchFailed("\";\"");
  6637. }
  6638. }
  6639. if (result1 !== null) {
  6640. result2 = parse_uri_parameter();
  6641. if (result2 !== null) {
  6642. result1 = [result1, result2];
  6643. } else {
  6644. result1 = null;
  6645. pos = pos0;
  6646. }
  6647. } else {
  6648. result1 = null;
  6649. pos = pos0;
  6650. }
  6651. while (result1 !== null) {
  6652. result0.push(result1);
  6653. pos0 = pos;
  6654. if (input.charCodeAt(pos) === 59) {
  6655. result1 = ";";
  6656. pos++;
  6657. } else {
  6658. result1 = null;
  6659. if (reportFailures === 0) {
  6660. matchFailed("\";\"");
  6661. }
  6662. }
  6663. if (result1 !== null) {
  6664. result2 = parse_uri_parameter();
  6665. if (result2 !== null) {
  6666. result1 = [result1, result2];
  6667. } else {
  6668. result1 = null;
  6669. pos = pos0;
  6670. }
  6671. } else {
  6672. result1 = null;
  6673. pos = pos0;
  6674. }
  6675. }
  6676. return result0;
  6677. }
  6678. function parse_uri_parameter() {
  6679. var result0;
  6680. result0 = parse_transport_param();
  6681. if (result0 === null) {
  6682. result0 = parse_user_param();
  6683. if (result0 === null) {
  6684. result0 = parse_method_param();
  6685. if (result0 === null) {
  6686. result0 = parse_ttl_param();
  6687. if (result0 === null) {
  6688. result0 = parse_maddr_param();
  6689. if (result0 === null) {
  6690. result0 = parse_lr_param();
  6691. if (result0 === null) {
  6692. result0 = parse_other_param();
  6693. }
  6694. }
  6695. }
  6696. }
  6697. }
  6698. }
  6699. return result0;
  6700. }
  6701. function parse_transport_param() {
  6702. var result0, result1;
  6703. var pos0, pos1;
  6704. pos0 = pos;
  6705. pos1 = pos;
  6706. if (input.substr(pos, 10).toLowerCase() === "transport=") {
  6707. result0 = input.substr(pos, 10);
  6708. pos += 10;
  6709. } else {
  6710. result0 = null;
  6711. if (reportFailures === 0) {
  6712. matchFailed("\"transport=\"");
  6713. }
  6714. }
  6715. if (result0 !== null) {
  6716. if (input.substr(pos, 3).toLowerCase() === "udp") {
  6717. result1 = input.substr(pos, 3);
  6718. pos += 3;
  6719. } else {
  6720. result1 = null;
  6721. if (reportFailures === 0) {
  6722. matchFailed("\"udp\"");
  6723. }
  6724. }
  6725. if (result1 === null) {
  6726. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  6727. result1 = input.substr(pos, 3);
  6728. pos += 3;
  6729. } else {
  6730. result1 = null;
  6731. if (reportFailures === 0) {
  6732. matchFailed("\"tcp\"");
  6733. }
  6734. }
  6735. if (result1 === null) {
  6736. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  6737. result1 = input.substr(pos, 4);
  6738. pos += 4;
  6739. } else {
  6740. result1 = null;
  6741. if (reportFailures === 0) {
  6742. matchFailed("\"sctp\"");
  6743. }
  6744. }
  6745. if (result1 === null) {
  6746. if (input.substr(pos, 3).toLowerCase() === "tls") {
  6747. result1 = input.substr(pos, 3);
  6748. pos += 3;
  6749. } else {
  6750. result1 = null;
  6751. if (reportFailures === 0) {
  6752. matchFailed("\"tls\"");
  6753. }
  6754. }
  6755. if (result1 === null) {
  6756. result1 = parse_token();
  6757. }
  6758. }
  6759. }
  6760. }
  6761. if (result1 !== null) {
  6762. result0 = [result0, result1];
  6763. } else {
  6764. result0 = null;
  6765. pos = pos1;
  6766. }
  6767. } else {
  6768. result0 = null;
  6769. pos = pos1;
  6770. }
  6771. if (result0 !== null) {
  6772. result0 = function (offset, transport) {
  6773. if (!data.uri_params) data.uri_params = {};
  6774. data.uri_params['transport'] = transport.toLowerCase();
  6775. }(pos0, result0[1]);
  6776. }
  6777. if (result0 === null) {
  6778. pos = pos0;
  6779. }
  6780. return result0;
  6781. }
  6782. function parse_user_param() {
  6783. var result0, result1;
  6784. var pos0, pos1;
  6785. pos0 = pos;
  6786. pos1 = pos;
  6787. if (input.substr(pos, 5).toLowerCase() === "user=") {
  6788. result0 = input.substr(pos, 5);
  6789. pos += 5;
  6790. } else {
  6791. result0 = null;
  6792. if (reportFailures === 0) {
  6793. matchFailed("\"user=\"");
  6794. }
  6795. }
  6796. if (result0 !== null) {
  6797. if (input.substr(pos, 5).toLowerCase() === "phone") {
  6798. result1 = input.substr(pos, 5);
  6799. pos += 5;
  6800. } else {
  6801. result1 = null;
  6802. if (reportFailures === 0) {
  6803. matchFailed("\"phone\"");
  6804. }
  6805. }
  6806. if (result1 === null) {
  6807. if (input.substr(pos, 2).toLowerCase() === "ip") {
  6808. result1 = input.substr(pos, 2);
  6809. pos += 2;
  6810. } else {
  6811. result1 = null;
  6812. if (reportFailures === 0) {
  6813. matchFailed("\"ip\"");
  6814. }
  6815. }
  6816. if (result1 === null) {
  6817. result1 = parse_token();
  6818. }
  6819. }
  6820. if (result1 !== null) {
  6821. result0 = [result0, result1];
  6822. } else {
  6823. result0 = null;
  6824. pos = pos1;
  6825. }
  6826. } else {
  6827. result0 = null;
  6828. pos = pos1;
  6829. }
  6830. if (result0 !== null) {
  6831. result0 = function (offset, user) {
  6832. if (!data.uri_params) data.uri_params = {};
  6833. data.uri_params['user'] = user.toLowerCase();
  6834. }(pos0, result0[1]);
  6835. }
  6836. if (result0 === null) {
  6837. pos = pos0;
  6838. }
  6839. return result0;
  6840. }
  6841. function parse_method_param() {
  6842. var result0, result1;
  6843. var pos0, pos1;
  6844. pos0 = pos;
  6845. pos1 = pos;
  6846. if (input.substr(pos, 7).toLowerCase() === "method=") {
  6847. result0 = input.substr(pos, 7);
  6848. pos += 7;
  6849. } else {
  6850. result0 = null;
  6851. if (reportFailures === 0) {
  6852. matchFailed("\"method=\"");
  6853. }
  6854. }
  6855. if (result0 !== null) {
  6856. result1 = parse_Method();
  6857. if (result1 !== null) {
  6858. result0 = [result0, result1];
  6859. } else {
  6860. result0 = null;
  6861. pos = pos1;
  6862. }
  6863. } else {
  6864. result0 = null;
  6865. pos = pos1;
  6866. }
  6867. if (result0 !== null) {
  6868. result0 = function (offset, method) {
  6869. if (!data.uri_params) data.uri_params = {};
  6870. data.uri_params['method'] = method;
  6871. }(pos0, result0[1]);
  6872. }
  6873. if (result0 === null) {
  6874. pos = pos0;
  6875. }
  6876. return result0;
  6877. }
  6878. function parse_ttl_param() {
  6879. var result0, result1;
  6880. var pos0, pos1;
  6881. pos0 = pos;
  6882. pos1 = pos;
  6883. if (input.substr(pos, 4).toLowerCase() === "ttl=") {
  6884. result0 = input.substr(pos, 4);
  6885. pos += 4;
  6886. } else {
  6887. result0 = null;
  6888. if (reportFailures === 0) {
  6889. matchFailed("\"ttl=\"");
  6890. }
  6891. }
  6892. if (result0 !== null) {
  6893. result1 = parse_ttl();
  6894. if (result1 !== null) {
  6895. result0 = [result0, result1];
  6896. } else {
  6897. result0 = null;
  6898. pos = pos1;
  6899. }
  6900. } else {
  6901. result0 = null;
  6902. pos = pos1;
  6903. }
  6904. if (result0 !== null) {
  6905. result0 = function (offset, ttl) {
  6906. if (!data.params) data.params = {};
  6907. data.params['ttl'] = ttl;
  6908. }(pos0, result0[1]);
  6909. }
  6910. if (result0 === null) {
  6911. pos = pos0;
  6912. }
  6913. return result0;
  6914. }
  6915. function parse_maddr_param() {
  6916. var result0, result1;
  6917. var pos0, pos1;
  6918. pos0 = pos;
  6919. pos1 = pos;
  6920. if (input.substr(pos, 6).toLowerCase() === "maddr=") {
  6921. result0 = input.substr(pos, 6);
  6922. pos += 6;
  6923. } else {
  6924. result0 = null;
  6925. if (reportFailures === 0) {
  6926. matchFailed("\"maddr=\"");
  6927. }
  6928. }
  6929. if (result0 !== null) {
  6930. result1 = parse_host();
  6931. if (result1 !== null) {
  6932. result0 = [result0, result1];
  6933. } else {
  6934. result0 = null;
  6935. pos = pos1;
  6936. }
  6937. } else {
  6938. result0 = null;
  6939. pos = pos1;
  6940. }
  6941. if (result0 !== null) {
  6942. result0 = function (offset, maddr) {
  6943. if (!data.uri_params) data.uri_params = {};
  6944. data.uri_params['maddr'] = maddr;
  6945. }(pos0, result0[1]);
  6946. }
  6947. if (result0 === null) {
  6948. pos = pos0;
  6949. }
  6950. return result0;
  6951. }
  6952. function parse_lr_param() {
  6953. var result0, result1, result2;
  6954. var pos0, pos1, pos2;
  6955. pos0 = pos;
  6956. pos1 = pos;
  6957. if (input.substr(pos, 2).toLowerCase() === "lr") {
  6958. result0 = input.substr(pos, 2);
  6959. pos += 2;
  6960. } else {
  6961. result0 = null;
  6962. if (reportFailures === 0) {
  6963. matchFailed("\"lr\"");
  6964. }
  6965. }
  6966. if (result0 !== null) {
  6967. pos2 = pos;
  6968. if (input.charCodeAt(pos) === 61) {
  6969. result1 = "=";
  6970. pos++;
  6971. } else {
  6972. result1 = null;
  6973. if (reportFailures === 0) {
  6974. matchFailed("\"=\"");
  6975. }
  6976. }
  6977. if (result1 !== null) {
  6978. result2 = parse_token();
  6979. if (result2 !== null) {
  6980. result1 = [result1, result2];
  6981. } else {
  6982. result1 = null;
  6983. pos = pos2;
  6984. }
  6985. } else {
  6986. result1 = null;
  6987. pos = pos2;
  6988. }
  6989. result1 = result1 !== null ? result1 : "";
  6990. if (result1 !== null) {
  6991. result0 = [result0, result1];
  6992. } else {
  6993. result0 = null;
  6994. pos = pos1;
  6995. }
  6996. } else {
  6997. result0 = null;
  6998. pos = pos1;
  6999. }
  7000. if (result0 !== null) {
  7001. result0 = function (offset) {
  7002. if (!data.uri_params) data.uri_params = {};
  7003. data.uri_params['lr'] = undefined;
  7004. }(pos0);
  7005. }
  7006. if (result0 === null) {
  7007. pos = pos0;
  7008. }
  7009. return result0;
  7010. }
  7011. function parse_other_param() {
  7012. var result0, result1, result2;
  7013. var pos0, pos1, pos2;
  7014. pos0 = pos;
  7015. pos1 = pos;
  7016. result0 = parse_pname();
  7017. if (result0 !== null) {
  7018. pos2 = pos;
  7019. if (input.charCodeAt(pos) === 61) {
  7020. result1 = "=";
  7021. pos++;
  7022. } else {
  7023. result1 = null;
  7024. if (reportFailures === 0) {
  7025. matchFailed("\"=\"");
  7026. }
  7027. }
  7028. if (result1 !== null) {
  7029. result2 = parse_pvalue();
  7030. if (result2 !== null) {
  7031. result1 = [result1, result2];
  7032. } else {
  7033. result1 = null;
  7034. pos = pos2;
  7035. }
  7036. } else {
  7037. result1 = null;
  7038. pos = pos2;
  7039. }
  7040. result1 = result1 !== null ? result1 : "";
  7041. if (result1 !== null) {
  7042. result0 = [result0, result1];
  7043. } else {
  7044. result0 = null;
  7045. pos = pos1;
  7046. }
  7047. } else {
  7048. result0 = null;
  7049. pos = pos1;
  7050. }
  7051. if (result0 !== null) {
  7052. result0 = function (offset, param, value) {
  7053. if (!data.uri_params) data.uri_params = {};
  7054. if (typeof value === 'undefined') {
  7055. value = undefined;
  7056. } else {
  7057. value = value[1];
  7058. }
  7059. data.uri_params[param.toLowerCase()] = value;
  7060. }(pos0, result0[0], result0[1]);
  7061. }
  7062. if (result0 === null) {
  7063. pos = pos0;
  7064. }
  7065. return result0;
  7066. }
  7067. function parse_pname() {
  7068. var result0, result1;
  7069. var pos0;
  7070. pos0 = pos;
  7071. result1 = parse_paramchar();
  7072. if (result1 !== null) {
  7073. result0 = [];
  7074. while (result1 !== null) {
  7075. result0.push(result1);
  7076. result1 = parse_paramchar();
  7077. }
  7078. } else {
  7079. result0 = null;
  7080. }
  7081. if (result0 !== null) {
  7082. result0 = function (offset, pname) {
  7083. return pname.join('');
  7084. }(pos0, result0);
  7085. }
  7086. if (result0 === null) {
  7087. pos = pos0;
  7088. }
  7089. return result0;
  7090. }
  7091. function parse_pvalue() {
  7092. var result0, result1;
  7093. var pos0;
  7094. pos0 = pos;
  7095. result1 = parse_paramchar();
  7096. if (result1 !== null) {
  7097. result0 = [];
  7098. while (result1 !== null) {
  7099. result0.push(result1);
  7100. result1 = parse_paramchar();
  7101. }
  7102. } else {
  7103. result0 = null;
  7104. }
  7105. if (result0 !== null) {
  7106. result0 = function (offset, pvalue) {
  7107. return pvalue.join('');
  7108. }(pos0, result0);
  7109. }
  7110. if (result0 === null) {
  7111. pos = pos0;
  7112. }
  7113. return result0;
  7114. }
  7115. function parse_paramchar() {
  7116. var result0;
  7117. result0 = parse_param_unreserved();
  7118. if (result0 === null) {
  7119. result0 = parse_unreserved();
  7120. if (result0 === null) {
  7121. result0 = parse_escaped();
  7122. }
  7123. }
  7124. return result0;
  7125. }
  7126. function parse_param_unreserved() {
  7127. var result0;
  7128. if (input.charCodeAt(pos) === 91) {
  7129. result0 = "[";
  7130. pos++;
  7131. } else {
  7132. result0 = null;
  7133. if (reportFailures === 0) {
  7134. matchFailed("\"[\"");
  7135. }
  7136. }
  7137. if (result0 === null) {
  7138. if (input.charCodeAt(pos) === 93) {
  7139. result0 = "]";
  7140. pos++;
  7141. } else {
  7142. result0 = null;
  7143. if (reportFailures === 0) {
  7144. matchFailed("\"]\"");
  7145. }
  7146. }
  7147. if (result0 === null) {
  7148. if (input.charCodeAt(pos) === 47) {
  7149. result0 = "/";
  7150. pos++;
  7151. } else {
  7152. result0 = null;
  7153. if (reportFailures === 0) {
  7154. matchFailed("\"/\"");
  7155. }
  7156. }
  7157. if (result0 === null) {
  7158. if (input.charCodeAt(pos) === 58) {
  7159. result0 = ":";
  7160. pos++;
  7161. } else {
  7162. result0 = null;
  7163. if (reportFailures === 0) {
  7164. matchFailed("\":\"");
  7165. }
  7166. }
  7167. if (result0 === null) {
  7168. if (input.charCodeAt(pos) === 38) {
  7169. result0 = "&";
  7170. pos++;
  7171. } else {
  7172. result0 = null;
  7173. if (reportFailures === 0) {
  7174. matchFailed("\"&\"");
  7175. }
  7176. }
  7177. if (result0 === null) {
  7178. if (input.charCodeAt(pos) === 43) {
  7179. result0 = "+";
  7180. pos++;
  7181. } else {
  7182. result0 = null;
  7183. if (reportFailures === 0) {
  7184. matchFailed("\"+\"");
  7185. }
  7186. }
  7187. if (result0 === null) {
  7188. if (input.charCodeAt(pos) === 36) {
  7189. result0 = "$";
  7190. pos++;
  7191. } else {
  7192. result0 = null;
  7193. if (reportFailures === 0) {
  7194. matchFailed("\"$\"");
  7195. }
  7196. }
  7197. }
  7198. }
  7199. }
  7200. }
  7201. }
  7202. }
  7203. return result0;
  7204. }
  7205. function parse_headers() {
  7206. var result0, result1, result2, result3, result4;
  7207. var pos0, pos1;
  7208. pos0 = pos;
  7209. if (input.charCodeAt(pos) === 63) {
  7210. result0 = "?";
  7211. pos++;
  7212. } else {
  7213. result0 = null;
  7214. if (reportFailures === 0) {
  7215. matchFailed("\"?\"");
  7216. }
  7217. }
  7218. if (result0 !== null) {
  7219. result1 = parse_header();
  7220. if (result1 !== null) {
  7221. result2 = [];
  7222. pos1 = pos;
  7223. if (input.charCodeAt(pos) === 38) {
  7224. result3 = "&";
  7225. pos++;
  7226. } else {
  7227. result3 = null;
  7228. if (reportFailures === 0) {
  7229. matchFailed("\"&\"");
  7230. }
  7231. }
  7232. if (result3 !== null) {
  7233. result4 = parse_header();
  7234. if (result4 !== null) {
  7235. result3 = [result3, result4];
  7236. } else {
  7237. result3 = null;
  7238. pos = pos1;
  7239. }
  7240. } else {
  7241. result3 = null;
  7242. pos = pos1;
  7243. }
  7244. while (result3 !== null) {
  7245. result2.push(result3);
  7246. pos1 = pos;
  7247. if (input.charCodeAt(pos) === 38) {
  7248. result3 = "&";
  7249. pos++;
  7250. } else {
  7251. result3 = null;
  7252. if (reportFailures === 0) {
  7253. matchFailed("\"&\"");
  7254. }
  7255. }
  7256. if (result3 !== null) {
  7257. result4 = parse_header();
  7258. if (result4 !== null) {
  7259. result3 = [result3, result4];
  7260. } else {
  7261. result3 = null;
  7262. pos = pos1;
  7263. }
  7264. } else {
  7265. result3 = null;
  7266. pos = pos1;
  7267. }
  7268. }
  7269. if (result2 !== null) {
  7270. result0 = [result0, result1, result2];
  7271. } else {
  7272. result0 = null;
  7273. pos = pos0;
  7274. }
  7275. } else {
  7276. result0 = null;
  7277. pos = pos0;
  7278. }
  7279. } else {
  7280. result0 = null;
  7281. pos = pos0;
  7282. }
  7283. return result0;
  7284. }
  7285. function parse_header() {
  7286. var result0, result1, result2;
  7287. var pos0, pos1;
  7288. pos0 = pos;
  7289. pos1 = pos;
  7290. result0 = parse_hname();
  7291. if (result0 !== null) {
  7292. if (input.charCodeAt(pos) === 61) {
  7293. result1 = "=";
  7294. pos++;
  7295. } else {
  7296. result1 = null;
  7297. if (reportFailures === 0) {
  7298. matchFailed("\"=\"");
  7299. }
  7300. }
  7301. if (result1 !== null) {
  7302. result2 = parse_hvalue();
  7303. if (result2 !== null) {
  7304. result0 = [result0, result1, result2];
  7305. } else {
  7306. result0 = null;
  7307. pos = pos1;
  7308. }
  7309. } else {
  7310. result0 = null;
  7311. pos = pos1;
  7312. }
  7313. } else {
  7314. result0 = null;
  7315. pos = pos1;
  7316. }
  7317. if (result0 !== null) {
  7318. result0 = function (offset, hname, hvalue) {
  7319. hname = hname.join('').toLowerCase();
  7320. hvalue = hvalue.join('');
  7321. if (!data.uri_headers) data.uri_headers = {};
  7322. if (!data.uri_headers[hname]) {
  7323. data.uri_headers[hname] = [hvalue];
  7324. } else {
  7325. data.uri_headers[hname].push(hvalue);
  7326. }
  7327. }(pos0, result0[0], result0[2]);
  7328. }
  7329. if (result0 === null) {
  7330. pos = pos0;
  7331. }
  7332. return result0;
  7333. }
  7334. function parse_hname() {
  7335. var result0, result1;
  7336. result1 = parse_hnv_unreserved();
  7337. if (result1 === null) {
  7338. result1 = parse_unreserved();
  7339. if (result1 === null) {
  7340. result1 = parse_escaped();
  7341. }
  7342. }
  7343. if (result1 !== null) {
  7344. result0 = [];
  7345. while (result1 !== null) {
  7346. result0.push(result1);
  7347. result1 = parse_hnv_unreserved();
  7348. if (result1 === null) {
  7349. result1 = parse_unreserved();
  7350. if (result1 === null) {
  7351. result1 = parse_escaped();
  7352. }
  7353. }
  7354. }
  7355. } else {
  7356. result0 = null;
  7357. }
  7358. return result0;
  7359. }
  7360. function parse_hvalue() {
  7361. var result0, result1;
  7362. result0 = [];
  7363. result1 = parse_hnv_unreserved();
  7364. if (result1 === null) {
  7365. result1 = parse_unreserved();
  7366. if (result1 === null) {
  7367. result1 = parse_escaped();
  7368. }
  7369. }
  7370. while (result1 !== null) {
  7371. result0.push(result1);
  7372. result1 = parse_hnv_unreserved();
  7373. if (result1 === null) {
  7374. result1 = parse_unreserved();
  7375. if (result1 === null) {
  7376. result1 = parse_escaped();
  7377. }
  7378. }
  7379. }
  7380. return result0;
  7381. }
  7382. function parse_hnv_unreserved() {
  7383. var result0;
  7384. if (input.charCodeAt(pos) === 91) {
  7385. result0 = "[";
  7386. pos++;
  7387. } else {
  7388. result0 = null;
  7389. if (reportFailures === 0) {
  7390. matchFailed("\"[\"");
  7391. }
  7392. }
  7393. if (result0 === null) {
  7394. if (input.charCodeAt(pos) === 93) {
  7395. result0 = "]";
  7396. pos++;
  7397. } else {
  7398. result0 = null;
  7399. if (reportFailures === 0) {
  7400. matchFailed("\"]\"");
  7401. }
  7402. }
  7403. if (result0 === null) {
  7404. if (input.charCodeAt(pos) === 47) {
  7405. result0 = "/";
  7406. pos++;
  7407. } else {
  7408. result0 = null;
  7409. if (reportFailures === 0) {
  7410. matchFailed("\"/\"");
  7411. }
  7412. }
  7413. if (result0 === null) {
  7414. if (input.charCodeAt(pos) === 63) {
  7415. result0 = "?";
  7416. pos++;
  7417. } else {
  7418. result0 = null;
  7419. if (reportFailures === 0) {
  7420. matchFailed("\"?\"");
  7421. }
  7422. }
  7423. if (result0 === null) {
  7424. if (input.charCodeAt(pos) === 58) {
  7425. result0 = ":";
  7426. pos++;
  7427. } else {
  7428. result0 = null;
  7429. if (reportFailures === 0) {
  7430. matchFailed("\":\"");
  7431. }
  7432. }
  7433. if (result0 === null) {
  7434. if (input.charCodeAt(pos) === 43) {
  7435. result0 = "+";
  7436. pos++;
  7437. } else {
  7438. result0 = null;
  7439. if (reportFailures === 0) {
  7440. matchFailed("\"+\"");
  7441. }
  7442. }
  7443. if (result0 === null) {
  7444. if (input.charCodeAt(pos) === 36) {
  7445. result0 = "$";
  7446. pos++;
  7447. } else {
  7448. result0 = null;
  7449. if (reportFailures === 0) {
  7450. matchFailed("\"$\"");
  7451. }
  7452. }
  7453. }
  7454. }
  7455. }
  7456. }
  7457. }
  7458. }
  7459. return result0;
  7460. }
  7461. function parse_Request_Response() {
  7462. var result0;
  7463. result0 = parse_Status_Line();
  7464. if (result0 === null) {
  7465. result0 = parse_Request_Line();
  7466. }
  7467. return result0;
  7468. }
  7469. function parse_Request_Line() {
  7470. var result0, result1, result2, result3, result4;
  7471. var pos0;
  7472. pos0 = pos;
  7473. result0 = parse_Method();
  7474. if (result0 !== null) {
  7475. result1 = parse_SP();
  7476. if (result1 !== null) {
  7477. result2 = parse_Request_URI();
  7478. if (result2 !== null) {
  7479. result3 = parse_SP();
  7480. if (result3 !== null) {
  7481. result4 = parse_SIP_Version();
  7482. if (result4 !== null) {
  7483. result0 = [result0, result1, result2, result3, result4];
  7484. } else {
  7485. result0 = null;
  7486. pos = pos0;
  7487. }
  7488. } else {
  7489. result0 = null;
  7490. pos = pos0;
  7491. }
  7492. } else {
  7493. result0 = null;
  7494. pos = pos0;
  7495. }
  7496. } else {
  7497. result0 = null;
  7498. pos = pos0;
  7499. }
  7500. } else {
  7501. result0 = null;
  7502. pos = pos0;
  7503. }
  7504. return result0;
  7505. }
  7506. function parse_Request_URI() {
  7507. var result0;
  7508. result0 = parse_SIP_URI();
  7509. if (result0 === null) {
  7510. result0 = parse_absoluteURI();
  7511. }
  7512. return result0;
  7513. }
  7514. function parse_absoluteURI() {
  7515. var result0, result1, result2;
  7516. var pos0;
  7517. pos0 = pos;
  7518. result0 = parse_scheme();
  7519. if (result0 !== null) {
  7520. if (input.charCodeAt(pos) === 58) {
  7521. result1 = ":";
  7522. pos++;
  7523. } else {
  7524. result1 = null;
  7525. if (reportFailures === 0) {
  7526. matchFailed("\":\"");
  7527. }
  7528. }
  7529. if (result1 !== null) {
  7530. result2 = parse_hier_part();
  7531. if (result2 === null) {
  7532. result2 = parse_opaque_part();
  7533. }
  7534. if (result2 !== null) {
  7535. result0 = [result0, result1, result2];
  7536. } else {
  7537. result0 = null;
  7538. pos = pos0;
  7539. }
  7540. } else {
  7541. result0 = null;
  7542. pos = pos0;
  7543. }
  7544. } else {
  7545. result0 = null;
  7546. pos = pos0;
  7547. }
  7548. return result0;
  7549. }
  7550. function parse_hier_part() {
  7551. var result0, result1, result2;
  7552. var pos0, pos1;
  7553. pos0 = pos;
  7554. result0 = parse_net_path();
  7555. if (result0 === null) {
  7556. result0 = parse_abs_path();
  7557. }
  7558. if (result0 !== null) {
  7559. pos1 = pos;
  7560. if (input.charCodeAt(pos) === 63) {
  7561. result1 = "?";
  7562. pos++;
  7563. } else {
  7564. result1 = null;
  7565. if (reportFailures === 0) {
  7566. matchFailed("\"?\"");
  7567. }
  7568. }
  7569. if (result1 !== null) {
  7570. result2 = parse_query();
  7571. if (result2 !== null) {
  7572. result1 = [result1, result2];
  7573. } else {
  7574. result1 = null;
  7575. pos = pos1;
  7576. }
  7577. } else {
  7578. result1 = null;
  7579. pos = pos1;
  7580. }
  7581. result1 = result1 !== null ? result1 : "";
  7582. if (result1 !== null) {
  7583. result0 = [result0, result1];
  7584. } else {
  7585. result0 = null;
  7586. pos = pos0;
  7587. }
  7588. } else {
  7589. result0 = null;
  7590. pos = pos0;
  7591. }
  7592. return result0;
  7593. }
  7594. function parse_net_path() {
  7595. var result0, result1, result2;
  7596. var pos0;
  7597. pos0 = pos;
  7598. if (input.substr(pos, 2) === "//") {
  7599. result0 = "//";
  7600. pos += 2;
  7601. } else {
  7602. result0 = null;
  7603. if (reportFailures === 0) {
  7604. matchFailed("\"//\"");
  7605. }
  7606. }
  7607. if (result0 !== null) {
  7608. result1 = parse_authority();
  7609. if (result1 !== null) {
  7610. result2 = parse_abs_path();
  7611. result2 = result2 !== null ? result2 : "";
  7612. if (result2 !== null) {
  7613. result0 = [result0, result1, result2];
  7614. } else {
  7615. result0 = null;
  7616. pos = pos0;
  7617. }
  7618. } else {
  7619. result0 = null;
  7620. pos = pos0;
  7621. }
  7622. } else {
  7623. result0 = null;
  7624. pos = pos0;
  7625. }
  7626. return result0;
  7627. }
  7628. function parse_abs_path() {
  7629. var result0, result1;
  7630. var pos0;
  7631. pos0 = pos;
  7632. if (input.charCodeAt(pos) === 47) {
  7633. result0 = "/";
  7634. pos++;
  7635. } else {
  7636. result0 = null;
  7637. if (reportFailures === 0) {
  7638. matchFailed("\"/\"");
  7639. }
  7640. }
  7641. if (result0 !== null) {
  7642. result1 = parse_path_segments();
  7643. if (result1 !== null) {
  7644. result0 = [result0, result1];
  7645. } else {
  7646. result0 = null;
  7647. pos = pos0;
  7648. }
  7649. } else {
  7650. result0 = null;
  7651. pos = pos0;
  7652. }
  7653. return result0;
  7654. }
  7655. function parse_opaque_part() {
  7656. var result0, result1, result2;
  7657. var pos0;
  7658. pos0 = pos;
  7659. result0 = parse_uric_no_slash();
  7660. if (result0 !== null) {
  7661. result1 = [];
  7662. result2 = parse_uric();
  7663. while (result2 !== null) {
  7664. result1.push(result2);
  7665. result2 = parse_uric();
  7666. }
  7667. if (result1 !== null) {
  7668. result0 = [result0, result1];
  7669. } else {
  7670. result0 = null;
  7671. pos = pos0;
  7672. }
  7673. } else {
  7674. result0 = null;
  7675. pos = pos0;
  7676. }
  7677. return result0;
  7678. }
  7679. function parse_uric() {
  7680. var result0;
  7681. result0 = parse_reserved();
  7682. if (result0 === null) {
  7683. result0 = parse_unreserved();
  7684. if (result0 === null) {
  7685. result0 = parse_escaped();
  7686. }
  7687. }
  7688. return result0;
  7689. }
  7690. function parse_uric_no_slash() {
  7691. var result0;
  7692. result0 = parse_unreserved();
  7693. if (result0 === null) {
  7694. result0 = parse_escaped();
  7695. if (result0 === null) {
  7696. if (input.charCodeAt(pos) === 59) {
  7697. result0 = ";";
  7698. pos++;
  7699. } else {
  7700. result0 = null;
  7701. if (reportFailures === 0) {
  7702. matchFailed("\";\"");
  7703. }
  7704. }
  7705. if (result0 === null) {
  7706. if (input.charCodeAt(pos) === 63) {
  7707. result0 = "?";
  7708. pos++;
  7709. } else {
  7710. result0 = null;
  7711. if (reportFailures === 0) {
  7712. matchFailed("\"?\"");
  7713. }
  7714. }
  7715. if (result0 === null) {
  7716. if (input.charCodeAt(pos) === 58) {
  7717. result0 = ":";
  7718. pos++;
  7719. } else {
  7720. result0 = null;
  7721. if (reportFailures === 0) {
  7722. matchFailed("\":\"");
  7723. }
  7724. }
  7725. if (result0 === null) {
  7726. if (input.charCodeAt(pos) === 64) {
  7727. result0 = "@";
  7728. pos++;
  7729. } else {
  7730. result0 = null;
  7731. if (reportFailures === 0) {
  7732. matchFailed("\"@\"");
  7733. }
  7734. }
  7735. if (result0 === null) {
  7736. if (input.charCodeAt(pos) === 38) {
  7737. result0 = "&";
  7738. pos++;
  7739. } else {
  7740. result0 = null;
  7741. if (reportFailures === 0) {
  7742. matchFailed("\"&\"");
  7743. }
  7744. }
  7745. if (result0 === null) {
  7746. if (input.charCodeAt(pos) === 61) {
  7747. result0 = "=";
  7748. pos++;
  7749. } else {
  7750. result0 = null;
  7751. if (reportFailures === 0) {
  7752. matchFailed("\"=\"");
  7753. }
  7754. }
  7755. if (result0 === null) {
  7756. if (input.charCodeAt(pos) === 43) {
  7757. result0 = "+";
  7758. pos++;
  7759. } else {
  7760. result0 = null;
  7761. if (reportFailures === 0) {
  7762. matchFailed("\"+\"");
  7763. }
  7764. }
  7765. if (result0 === null) {
  7766. if (input.charCodeAt(pos) === 36) {
  7767. result0 = "$";
  7768. pos++;
  7769. } else {
  7770. result0 = null;
  7771. if (reportFailures === 0) {
  7772. matchFailed("\"$\"");
  7773. }
  7774. }
  7775. if (result0 === null) {
  7776. if (input.charCodeAt(pos) === 44) {
  7777. result0 = ",";
  7778. pos++;
  7779. } else {
  7780. result0 = null;
  7781. if (reportFailures === 0) {
  7782. matchFailed("\",\"");
  7783. }
  7784. }
  7785. }
  7786. }
  7787. }
  7788. }
  7789. }
  7790. }
  7791. }
  7792. }
  7793. }
  7794. }
  7795. return result0;
  7796. }
  7797. function parse_path_segments() {
  7798. var result0, result1, result2, result3;
  7799. var pos0, pos1;
  7800. pos0 = pos;
  7801. result0 = parse_segment();
  7802. if (result0 !== null) {
  7803. result1 = [];
  7804. pos1 = pos;
  7805. if (input.charCodeAt(pos) === 47) {
  7806. result2 = "/";
  7807. pos++;
  7808. } else {
  7809. result2 = null;
  7810. if (reportFailures === 0) {
  7811. matchFailed("\"/\"");
  7812. }
  7813. }
  7814. if (result2 !== null) {
  7815. result3 = parse_segment();
  7816. if (result3 !== null) {
  7817. result2 = [result2, result3];
  7818. } else {
  7819. result2 = null;
  7820. pos = pos1;
  7821. }
  7822. } else {
  7823. result2 = null;
  7824. pos = pos1;
  7825. }
  7826. while (result2 !== null) {
  7827. result1.push(result2);
  7828. pos1 = pos;
  7829. if (input.charCodeAt(pos) === 47) {
  7830. result2 = "/";
  7831. pos++;
  7832. } else {
  7833. result2 = null;
  7834. if (reportFailures === 0) {
  7835. matchFailed("\"/\"");
  7836. }
  7837. }
  7838. if (result2 !== null) {
  7839. result3 = parse_segment();
  7840. if (result3 !== null) {
  7841. result2 = [result2, result3];
  7842. } else {
  7843. result2 = null;
  7844. pos = pos1;
  7845. }
  7846. } else {
  7847. result2 = null;
  7848. pos = pos1;
  7849. }
  7850. }
  7851. if (result1 !== null) {
  7852. result0 = [result0, result1];
  7853. } else {
  7854. result0 = null;
  7855. pos = pos0;
  7856. }
  7857. } else {
  7858. result0 = null;
  7859. pos = pos0;
  7860. }
  7861. return result0;
  7862. }
  7863. function parse_segment() {
  7864. var result0, result1, result2, result3;
  7865. var pos0, pos1;
  7866. pos0 = pos;
  7867. result0 = [];
  7868. result1 = parse_pchar();
  7869. while (result1 !== null) {
  7870. result0.push(result1);
  7871. result1 = parse_pchar();
  7872. }
  7873. if (result0 !== null) {
  7874. result1 = [];
  7875. pos1 = pos;
  7876. if (input.charCodeAt(pos) === 59) {
  7877. result2 = ";";
  7878. pos++;
  7879. } else {
  7880. result2 = null;
  7881. if (reportFailures === 0) {
  7882. matchFailed("\";\"");
  7883. }
  7884. }
  7885. if (result2 !== null) {
  7886. result3 = parse_param();
  7887. if (result3 !== null) {
  7888. result2 = [result2, result3];
  7889. } else {
  7890. result2 = null;
  7891. pos = pos1;
  7892. }
  7893. } else {
  7894. result2 = null;
  7895. pos = pos1;
  7896. }
  7897. while (result2 !== null) {
  7898. result1.push(result2);
  7899. pos1 = pos;
  7900. if (input.charCodeAt(pos) === 59) {
  7901. result2 = ";";
  7902. pos++;
  7903. } else {
  7904. result2 = null;
  7905. if (reportFailures === 0) {
  7906. matchFailed("\";\"");
  7907. }
  7908. }
  7909. if (result2 !== null) {
  7910. result3 = parse_param();
  7911. if (result3 !== null) {
  7912. result2 = [result2, result3];
  7913. } else {
  7914. result2 = null;
  7915. pos = pos1;
  7916. }
  7917. } else {
  7918. result2 = null;
  7919. pos = pos1;
  7920. }
  7921. }
  7922. if (result1 !== null) {
  7923. result0 = [result0, result1];
  7924. } else {
  7925. result0 = null;
  7926. pos = pos0;
  7927. }
  7928. } else {
  7929. result0 = null;
  7930. pos = pos0;
  7931. }
  7932. return result0;
  7933. }
  7934. function parse_param() {
  7935. var result0, result1;
  7936. result0 = [];
  7937. result1 = parse_pchar();
  7938. while (result1 !== null) {
  7939. result0.push(result1);
  7940. result1 = parse_pchar();
  7941. }
  7942. return result0;
  7943. }
  7944. function parse_pchar() {
  7945. var result0;
  7946. result0 = parse_unreserved();
  7947. if (result0 === null) {
  7948. result0 = parse_escaped();
  7949. if (result0 === null) {
  7950. if (input.charCodeAt(pos) === 58) {
  7951. result0 = ":";
  7952. pos++;
  7953. } else {
  7954. result0 = null;
  7955. if (reportFailures === 0) {
  7956. matchFailed("\":\"");
  7957. }
  7958. }
  7959. if (result0 === null) {
  7960. if (input.charCodeAt(pos) === 64) {
  7961. result0 = "@";
  7962. pos++;
  7963. } else {
  7964. result0 = null;
  7965. if (reportFailures === 0) {
  7966. matchFailed("\"@\"");
  7967. }
  7968. }
  7969. if (result0 === null) {
  7970. if (input.charCodeAt(pos) === 38) {
  7971. result0 = "&";
  7972. pos++;
  7973. } else {
  7974. result0 = null;
  7975. if (reportFailures === 0) {
  7976. matchFailed("\"&\"");
  7977. }
  7978. }
  7979. if (result0 === null) {
  7980. if (input.charCodeAt(pos) === 61) {
  7981. result0 = "=";
  7982. pos++;
  7983. } else {
  7984. result0 = null;
  7985. if (reportFailures === 0) {
  7986. matchFailed("\"=\"");
  7987. }
  7988. }
  7989. if (result0 === null) {
  7990. if (input.charCodeAt(pos) === 43) {
  7991. result0 = "+";
  7992. pos++;
  7993. } else {
  7994. result0 = null;
  7995. if (reportFailures === 0) {
  7996. matchFailed("\"+\"");
  7997. }
  7998. }
  7999. if (result0 === null) {
  8000. if (input.charCodeAt(pos) === 36) {
  8001. result0 = "$";
  8002. pos++;
  8003. } else {
  8004. result0 = null;
  8005. if (reportFailures === 0) {
  8006. matchFailed("\"$\"");
  8007. }
  8008. }
  8009. if (result0 === null) {
  8010. if (input.charCodeAt(pos) === 44) {
  8011. result0 = ",";
  8012. pos++;
  8013. } else {
  8014. result0 = null;
  8015. if (reportFailures === 0) {
  8016. matchFailed("\",\"");
  8017. }
  8018. }
  8019. }
  8020. }
  8021. }
  8022. }
  8023. }
  8024. }
  8025. }
  8026. }
  8027. return result0;
  8028. }
  8029. function parse_scheme() {
  8030. var result0, result1, result2;
  8031. var pos0, pos1;
  8032. pos0 = pos;
  8033. pos1 = pos;
  8034. result0 = parse_ALPHA();
  8035. if (result0 !== null) {
  8036. result1 = [];
  8037. result2 = parse_ALPHA();
  8038. if (result2 === null) {
  8039. result2 = parse_DIGIT();
  8040. if (result2 === null) {
  8041. if (input.charCodeAt(pos) === 43) {
  8042. result2 = "+";
  8043. pos++;
  8044. } else {
  8045. result2 = null;
  8046. if (reportFailures === 0) {
  8047. matchFailed("\"+\"");
  8048. }
  8049. }
  8050. if (result2 === null) {
  8051. if (input.charCodeAt(pos) === 45) {
  8052. result2 = "-";
  8053. pos++;
  8054. } else {
  8055. result2 = null;
  8056. if (reportFailures === 0) {
  8057. matchFailed("\"-\"");
  8058. }
  8059. }
  8060. if (result2 === null) {
  8061. if (input.charCodeAt(pos) === 46) {
  8062. result2 = ".";
  8063. pos++;
  8064. } else {
  8065. result2 = null;
  8066. if (reportFailures === 0) {
  8067. matchFailed("\".\"");
  8068. }
  8069. }
  8070. }
  8071. }
  8072. }
  8073. }
  8074. while (result2 !== null) {
  8075. result1.push(result2);
  8076. result2 = parse_ALPHA();
  8077. if (result2 === null) {
  8078. result2 = parse_DIGIT();
  8079. if (result2 === null) {
  8080. if (input.charCodeAt(pos) === 43) {
  8081. result2 = "+";
  8082. pos++;
  8083. } else {
  8084. result2 = null;
  8085. if (reportFailures === 0) {
  8086. matchFailed("\"+\"");
  8087. }
  8088. }
  8089. if (result2 === null) {
  8090. if (input.charCodeAt(pos) === 45) {
  8091. result2 = "-";
  8092. pos++;
  8093. } else {
  8094. result2 = null;
  8095. if (reportFailures === 0) {
  8096. matchFailed("\"-\"");
  8097. }
  8098. }
  8099. if (result2 === null) {
  8100. if (input.charCodeAt(pos) === 46) {
  8101. result2 = ".";
  8102. pos++;
  8103. } else {
  8104. result2 = null;
  8105. if (reportFailures === 0) {
  8106. matchFailed("\".\"");
  8107. }
  8108. }
  8109. }
  8110. }
  8111. }
  8112. }
  8113. }
  8114. if (result1 !== null) {
  8115. result0 = [result0, result1];
  8116. } else {
  8117. result0 = null;
  8118. pos = pos1;
  8119. }
  8120. } else {
  8121. result0 = null;
  8122. pos = pos1;
  8123. }
  8124. if (result0 !== null) {
  8125. result0 = function (offset) {
  8126. data.scheme = input.substring(pos, offset);
  8127. }(pos0);
  8128. }
  8129. if (result0 === null) {
  8130. pos = pos0;
  8131. }
  8132. return result0;
  8133. }
  8134. function parse_authority() {
  8135. var result0;
  8136. result0 = parse_srvr();
  8137. if (result0 === null) {
  8138. result0 = parse_reg_name();
  8139. }
  8140. return result0;
  8141. }
  8142. function parse_srvr() {
  8143. var result0, result1;
  8144. var pos0, pos1;
  8145. pos0 = pos;
  8146. pos1 = pos;
  8147. result0 = parse_userinfo();
  8148. if (result0 !== null) {
  8149. if (input.charCodeAt(pos) === 64) {
  8150. result1 = "@";
  8151. pos++;
  8152. } else {
  8153. result1 = null;
  8154. if (reportFailures === 0) {
  8155. matchFailed("\"@\"");
  8156. }
  8157. }
  8158. if (result1 !== null) {
  8159. result0 = [result0, result1];
  8160. } else {
  8161. result0 = null;
  8162. pos = pos1;
  8163. }
  8164. } else {
  8165. result0 = null;
  8166. pos = pos1;
  8167. }
  8168. result0 = result0 !== null ? result0 : "";
  8169. if (result0 !== null) {
  8170. result1 = parse_hostport();
  8171. if (result1 !== null) {
  8172. result0 = [result0, result1];
  8173. } else {
  8174. result0 = null;
  8175. pos = pos0;
  8176. }
  8177. } else {
  8178. result0 = null;
  8179. pos = pos0;
  8180. }
  8181. result0 = result0 !== null ? result0 : "";
  8182. return result0;
  8183. }
  8184. function parse_reg_name() {
  8185. var result0, result1;
  8186. result1 = parse_unreserved();
  8187. if (result1 === null) {
  8188. result1 = parse_escaped();
  8189. if (result1 === null) {
  8190. if (input.charCodeAt(pos) === 36) {
  8191. result1 = "$";
  8192. pos++;
  8193. } else {
  8194. result1 = null;
  8195. if (reportFailures === 0) {
  8196. matchFailed("\"$\"");
  8197. }
  8198. }
  8199. if (result1 === null) {
  8200. if (input.charCodeAt(pos) === 44) {
  8201. result1 = ",";
  8202. pos++;
  8203. } else {
  8204. result1 = null;
  8205. if (reportFailures === 0) {
  8206. matchFailed("\",\"");
  8207. }
  8208. }
  8209. if (result1 === null) {
  8210. if (input.charCodeAt(pos) === 59) {
  8211. result1 = ";";
  8212. pos++;
  8213. } else {
  8214. result1 = null;
  8215. if (reportFailures === 0) {
  8216. matchFailed("\";\"");
  8217. }
  8218. }
  8219. if (result1 === null) {
  8220. if (input.charCodeAt(pos) === 58) {
  8221. result1 = ":";
  8222. pos++;
  8223. } else {
  8224. result1 = null;
  8225. if (reportFailures === 0) {
  8226. matchFailed("\":\"");
  8227. }
  8228. }
  8229. if (result1 === null) {
  8230. if (input.charCodeAt(pos) === 64) {
  8231. result1 = "@";
  8232. pos++;
  8233. } else {
  8234. result1 = null;
  8235. if (reportFailures === 0) {
  8236. matchFailed("\"@\"");
  8237. }
  8238. }
  8239. if (result1 === null) {
  8240. if (input.charCodeAt(pos) === 38) {
  8241. result1 = "&";
  8242. pos++;
  8243. } else {
  8244. result1 = null;
  8245. if (reportFailures === 0) {
  8246. matchFailed("\"&\"");
  8247. }
  8248. }
  8249. if (result1 === null) {
  8250. if (input.charCodeAt(pos) === 61) {
  8251. result1 = "=";
  8252. pos++;
  8253. } else {
  8254. result1 = null;
  8255. if (reportFailures === 0) {
  8256. matchFailed("\"=\"");
  8257. }
  8258. }
  8259. if (result1 === null) {
  8260. if (input.charCodeAt(pos) === 43) {
  8261. result1 = "+";
  8262. pos++;
  8263. } else {
  8264. result1 = null;
  8265. if (reportFailures === 0) {
  8266. matchFailed("\"+\"");
  8267. }
  8268. }
  8269. }
  8270. }
  8271. }
  8272. }
  8273. }
  8274. }
  8275. }
  8276. }
  8277. }
  8278. if (result1 !== null) {
  8279. result0 = [];
  8280. while (result1 !== null) {
  8281. result0.push(result1);
  8282. result1 = parse_unreserved();
  8283. if (result1 === null) {
  8284. result1 = parse_escaped();
  8285. if (result1 === null) {
  8286. if (input.charCodeAt(pos) === 36) {
  8287. result1 = "$";
  8288. pos++;
  8289. } else {
  8290. result1 = null;
  8291. if (reportFailures === 0) {
  8292. matchFailed("\"$\"");
  8293. }
  8294. }
  8295. if (result1 === null) {
  8296. if (input.charCodeAt(pos) === 44) {
  8297. result1 = ",";
  8298. pos++;
  8299. } else {
  8300. result1 = null;
  8301. if (reportFailures === 0) {
  8302. matchFailed("\",\"");
  8303. }
  8304. }
  8305. if (result1 === null) {
  8306. if (input.charCodeAt(pos) === 59) {
  8307. result1 = ";";
  8308. pos++;
  8309. } else {
  8310. result1 = null;
  8311. if (reportFailures === 0) {
  8312. matchFailed("\";\"");
  8313. }
  8314. }
  8315. if (result1 === null) {
  8316. if (input.charCodeAt(pos) === 58) {
  8317. result1 = ":";
  8318. pos++;
  8319. } else {
  8320. result1 = null;
  8321. if (reportFailures === 0) {
  8322. matchFailed("\":\"");
  8323. }
  8324. }
  8325. if (result1 === null) {
  8326. if (input.charCodeAt(pos) === 64) {
  8327. result1 = "@";
  8328. pos++;
  8329. } else {
  8330. result1 = null;
  8331. if (reportFailures === 0) {
  8332. matchFailed("\"@\"");
  8333. }
  8334. }
  8335. if (result1 === null) {
  8336. if (input.charCodeAt(pos) === 38) {
  8337. result1 = "&";
  8338. pos++;
  8339. } else {
  8340. result1 = null;
  8341. if (reportFailures === 0) {
  8342. matchFailed("\"&\"");
  8343. }
  8344. }
  8345. if (result1 === null) {
  8346. if (input.charCodeAt(pos) === 61) {
  8347. result1 = "=";
  8348. pos++;
  8349. } else {
  8350. result1 = null;
  8351. if (reportFailures === 0) {
  8352. matchFailed("\"=\"");
  8353. }
  8354. }
  8355. if (result1 === null) {
  8356. if (input.charCodeAt(pos) === 43) {
  8357. result1 = "+";
  8358. pos++;
  8359. } else {
  8360. result1 = null;
  8361. if (reportFailures === 0) {
  8362. matchFailed("\"+\"");
  8363. }
  8364. }
  8365. }
  8366. }
  8367. }
  8368. }
  8369. }
  8370. }
  8371. }
  8372. }
  8373. }
  8374. }
  8375. } else {
  8376. result0 = null;
  8377. }
  8378. return result0;
  8379. }
  8380. function parse_query() {
  8381. var result0, result1;
  8382. result0 = [];
  8383. result1 = parse_uric();
  8384. while (result1 !== null) {
  8385. result0.push(result1);
  8386. result1 = parse_uric();
  8387. }
  8388. return result0;
  8389. }
  8390. function parse_SIP_Version() {
  8391. var result0, result1, result2, result3, result4, result5;
  8392. var pos0, pos1;
  8393. pos0 = pos;
  8394. pos1 = pos;
  8395. if (input.substr(pos, 3).toLowerCase() === "sip") {
  8396. result0 = input.substr(pos, 3);
  8397. pos += 3;
  8398. } else {
  8399. result0 = null;
  8400. if (reportFailures === 0) {
  8401. matchFailed("\"SIP\"");
  8402. }
  8403. }
  8404. if (result0 !== null) {
  8405. if (input.charCodeAt(pos) === 47) {
  8406. result1 = "/";
  8407. pos++;
  8408. } else {
  8409. result1 = null;
  8410. if (reportFailures === 0) {
  8411. matchFailed("\"/\"");
  8412. }
  8413. }
  8414. if (result1 !== null) {
  8415. result3 = parse_DIGIT();
  8416. if (result3 !== null) {
  8417. result2 = [];
  8418. while (result3 !== null) {
  8419. result2.push(result3);
  8420. result3 = parse_DIGIT();
  8421. }
  8422. } else {
  8423. result2 = null;
  8424. }
  8425. if (result2 !== null) {
  8426. if (input.charCodeAt(pos) === 46) {
  8427. result3 = ".";
  8428. pos++;
  8429. } else {
  8430. result3 = null;
  8431. if (reportFailures === 0) {
  8432. matchFailed("\".\"");
  8433. }
  8434. }
  8435. if (result3 !== null) {
  8436. result5 = parse_DIGIT();
  8437. if (result5 !== null) {
  8438. result4 = [];
  8439. while (result5 !== null) {
  8440. result4.push(result5);
  8441. result5 = parse_DIGIT();
  8442. }
  8443. } else {
  8444. result4 = null;
  8445. }
  8446. if (result4 !== null) {
  8447. result0 = [result0, result1, result2, result3, result4];
  8448. } else {
  8449. result0 = null;
  8450. pos = pos1;
  8451. }
  8452. } else {
  8453. result0 = null;
  8454. pos = pos1;
  8455. }
  8456. } else {
  8457. result0 = null;
  8458. pos = pos1;
  8459. }
  8460. } else {
  8461. result0 = null;
  8462. pos = pos1;
  8463. }
  8464. } else {
  8465. result0 = null;
  8466. pos = pos1;
  8467. }
  8468. if (result0 !== null) {
  8469. result0 = function (offset) {
  8470. data.sip_version = input.substring(pos, offset);
  8471. }(pos0);
  8472. }
  8473. if (result0 === null) {
  8474. pos = pos0;
  8475. }
  8476. return result0;
  8477. }
  8478. function parse_INVITEm() {
  8479. var result0;
  8480. if (input.substr(pos, 6) === "INVITE") {
  8481. result0 = "INVITE";
  8482. pos += 6;
  8483. } else {
  8484. result0 = null;
  8485. if (reportFailures === 0) {
  8486. matchFailed("\"INVITE\"");
  8487. }
  8488. }
  8489. return result0;
  8490. }
  8491. function parse_ACKm() {
  8492. var result0;
  8493. if (input.substr(pos, 3) === "ACK") {
  8494. result0 = "ACK";
  8495. pos += 3;
  8496. } else {
  8497. result0 = null;
  8498. if (reportFailures === 0) {
  8499. matchFailed("\"ACK\"");
  8500. }
  8501. }
  8502. return result0;
  8503. }
  8504. function parse_OPTIONSm() {
  8505. var result0;
  8506. if (input.substr(pos, 7) === "OPTIONS") {
  8507. result0 = "OPTIONS";
  8508. pos += 7;
  8509. } else {
  8510. result0 = null;
  8511. if (reportFailures === 0) {
  8512. matchFailed("\"OPTIONS\"");
  8513. }
  8514. }
  8515. return result0;
  8516. }
  8517. function parse_BYEm() {
  8518. var result0;
  8519. if (input.substr(pos, 3) === "BYE") {
  8520. result0 = "BYE";
  8521. pos += 3;
  8522. } else {
  8523. result0 = null;
  8524. if (reportFailures === 0) {
  8525. matchFailed("\"BYE\"");
  8526. }
  8527. }
  8528. return result0;
  8529. }
  8530. function parse_CANCELm() {
  8531. var result0;
  8532. if (input.substr(pos, 6) === "CANCEL") {
  8533. result0 = "CANCEL";
  8534. pos += 6;
  8535. } else {
  8536. result0 = null;
  8537. if (reportFailures === 0) {
  8538. matchFailed("\"CANCEL\"");
  8539. }
  8540. }
  8541. return result0;
  8542. }
  8543. function parse_REGISTERm() {
  8544. var result0;
  8545. if (input.substr(pos, 8) === "REGISTER") {
  8546. result0 = "REGISTER";
  8547. pos += 8;
  8548. } else {
  8549. result0 = null;
  8550. if (reportFailures === 0) {
  8551. matchFailed("\"REGISTER\"");
  8552. }
  8553. }
  8554. return result0;
  8555. }
  8556. function parse_SUBSCRIBEm() {
  8557. var result0;
  8558. if (input.substr(pos, 9) === "SUBSCRIBE") {
  8559. result0 = "SUBSCRIBE";
  8560. pos += 9;
  8561. } else {
  8562. result0 = null;
  8563. if (reportFailures === 0) {
  8564. matchFailed("\"SUBSCRIBE\"");
  8565. }
  8566. }
  8567. return result0;
  8568. }
  8569. function parse_NOTIFYm() {
  8570. var result0;
  8571. if (input.substr(pos, 6) === "NOTIFY") {
  8572. result0 = "NOTIFY";
  8573. pos += 6;
  8574. } else {
  8575. result0 = null;
  8576. if (reportFailures === 0) {
  8577. matchFailed("\"NOTIFY\"");
  8578. }
  8579. }
  8580. return result0;
  8581. }
  8582. function parse_REFERm() {
  8583. var result0;
  8584. if (input.substr(pos, 5) === "REFER") {
  8585. result0 = "REFER";
  8586. pos += 5;
  8587. } else {
  8588. result0 = null;
  8589. if (reportFailures === 0) {
  8590. matchFailed("\"REFER\"");
  8591. }
  8592. }
  8593. return result0;
  8594. }
  8595. function parse_Method() {
  8596. var result0;
  8597. var pos0;
  8598. pos0 = pos;
  8599. result0 = parse_INVITEm();
  8600. if (result0 === null) {
  8601. result0 = parse_ACKm();
  8602. if (result0 === null) {
  8603. result0 = parse_OPTIONSm();
  8604. if (result0 === null) {
  8605. result0 = parse_BYEm();
  8606. if (result0 === null) {
  8607. result0 = parse_CANCELm();
  8608. if (result0 === null) {
  8609. result0 = parse_REGISTERm();
  8610. if (result0 === null) {
  8611. result0 = parse_SUBSCRIBEm();
  8612. if (result0 === null) {
  8613. result0 = parse_NOTIFYm();
  8614. if (result0 === null) {
  8615. result0 = parse_REFERm();
  8616. if (result0 === null) {
  8617. result0 = parse_token();
  8618. }
  8619. }
  8620. }
  8621. }
  8622. }
  8623. }
  8624. }
  8625. }
  8626. }
  8627. if (result0 !== null) {
  8628. result0 = function (offset) {
  8629. data.method = input.substring(pos, offset);
  8630. return data.method;
  8631. }(pos0);
  8632. }
  8633. if (result0 === null) {
  8634. pos = pos0;
  8635. }
  8636. return result0;
  8637. }
  8638. function parse_Status_Line() {
  8639. var result0, result1, result2, result3, result4;
  8640. var pos0;
  8641. pos0 = pos;
  8642. result0 = parse_SIP_Version();
  8643. if (result0 !== null) {
  8644. result1 = parse_SP();
  8645. if (result1 !== null) {
  8646. result2 = parse_Status_Code();
  8647. if (result2 !== null) {
  8648. result3 = parse_SP();
  8649. if (result3 !== null) {
  8650. result4 = parse_Reason_Phrase();
  8651. if (result4 !== null) {
  8652. result0 = [result0, result1, result2, result3, result4];
  8653. } else {
  8654. result0 = null;
  8655. pos = pos0;
  8656. }
  8657. } else {
  8658. result0 = null;
  8659. pos = pos0;
  8660. }
  8661. } else {
  8662. result0 = null;
  8663. pos = pos0;
  8664. }
  8665. } else {
  8666. result0 = null;
  8667. pos = pos0;
  8668. }
  8669. } else {
  8670. result0 = null;
  8671. pos = pos0;
  8672. }
  8673. return result0;
  8674. }
  8675. function parse_Status_Code() {
  8676. var result0;
  8677. var pos0;
  8678. pos0 = pos;
  8679. result0 = parse_extension_code();
  8680. if (result0 !== null) {
  8681. result0 = function (offset, status_code) {
  8682. data.status_code = parseInt(status_code.join(''));
  8683. }(pos0, result0);
  8684. }
  8685. if (result0 === null) {
  8686. pos = pos0;
  8687. }
  8688. return result0;
  8689. }
  8690. function parse_extension_code() {
  8691. var result0, result1, result2;
  8692. var pos0;
  8693. pos0 = pos;
  8694. result0 = parse_DIGIT();
  8695. if (result0 !== null) {
  8696. result1 = parse_DIGIT();
  8697. if (result1 !== null) {
  8698. result2 = parse_DIGIT();
  8699. if (result2 !== null) {
  8700. result0 = [result0, result1, result2];
  8701. } else {
  8702. result0 = null;
  8703. pos = pos0;
  8704. }
  8705. } else {
  8706. result0 = null;
  8707. pos = pos0;
  8708. }
  8709. } else {
  8710. result0 = null;
  8711. pos = pos0;
  8712. }
  8713. return result0;
  8714. }
  8715. function parse_Reason_Phrase() {
  8716. var result0, result1;
  8717. var pos0;
  8718. pos0 = pos;
  8719. result0 = [];
  8720. result1 = parse_reserved();
  8721. if (result1 === null) {
  8722. result1 = parse_unreserved();
  8723. if (result1 === null) {
  8724. result1 = parse_escaped();
  8725. if (result1 === null) {
  8726. result1 = parse_UTF8_NONASCII();
  8727. if (result1 === null) {
  8728. result1 = parse_UTF8_CONT();
  8729. if (result1 === null) {
  8730. result1 = parse_SP();
  8731. if (result1 === null) {
  8732. result1 = parse_HTAB();
  8733. }
  8734. }
  8735. }
  8736. }
  8737. }
  8738. }
  8739. while (result1 !== null) {
  8740. result0.push(result1);
  8741. result1 = parse_reserved();
  8742. if (result1 === null) {
  8743. result1 = parse_unreserved();
  8744. if (result1 === null) {
  8745. result1 = parse_escaped();
  8746. if (result1 === null) {
  8747. result1 = parse_UTF8_NONASCII();
  8748. if (result1 === null) {
  8749. result1 = parse_UTF8_CONT();
  8750. if (result1 === null) {
  8751. result1 = parse_SP();
  8752. if (result1 === null) {
  8753. result1 = parse_HTAB();
  8754. }
  8755. }
  8756. }
  8757. }
  8758. }
  8759. }
  8760. }
  8761. if (result0 !== null) {
  8762. result0 = function (offset) {
  8763. data.reason_phrase = input.substring(pos, offset);
  8764. }(pos0);
  8765. }
  8766. if (result0 === null) {
  8767. pos = pos0;
  8768. }
  8769. return result0;
  8770. }
  8771. function parse_Allow_Events() {
  8772. var result0, result1, result2, result3;
  8773. var pos0, pos1;
  8774. pos0 = pos;
  8775. result0 = parse_event_type();
  8776. if (result0 !== null) {
  8777. result1 = [];
  8778. pos1 = pos;
  8779. result2 = parse_COMMA();
  8780. if (result2 !== null) {
  8781. result3 = parse_event_type();
  8782. if (result3 !== null) {
  8783. result2 = [result2, result3];
  8784. } else {
  8785. result2 = null;
  8786. pos = pos1;
  8787. }
  8788. } else {
  8789. result2 = null;
  8790. pos = pos1;
  8791. }
  8792. while (result2 !== null) {
  8793. result1.push(result2);
  8794. pos1 = pos;
  8795. result2 = parse_COMMA();
  8796. if (result2 !== null) {
  8797. result3 = parse_event_type();
  8798. if (result3 !== null) {
  8799. result2 = [result2, result3];
  8800. } else {
  8801. result2 = null;
  8802. pos = pos1;
  8803. }
  8804. } else {
  8805. result2 = null;
  8806. pos = pos1;
  8807. }
  8808. }
  8809. if (result1 !== null) {
  8810. result0 = [result0, result1];
  8811. } else {
  8812. result0 = null;
  8813. pos = pos0;
  8814. }
  8815. } else {
  8816. result0 = null;
  8817. pos = pos0;
  8818. }
  8819. return result0;
  8820. }
  8821. function parse_Call_ID() {
  8822. var result0, result1, result2;
  8823. var pos0, pos1, pos2;
  8824. pos0 = pos;
  8825. pos1 = pos;
  8826. result0 = parse_word();
  8827. if (result0 !== null) {
  8828. pos2 = pos;
  8829. if (input.charCodeAt(pos) === 64) {
  8830. result1 = "@";
  8831. pos++;
  8832. } else {
  8833. result1 = null;
  8834. if (reportFailures === 0) {
  8835. matchFailed("\"@\"");
  8836. }
  8837. }
  8838. if (result1 !== null) {
  8839. result2 = parse_word();
  8840. if (result2 !== null) {
  8841. result1 = [result1, result2];
  8842. } else {
  8843. result1 = null;
  8844. pos = pos2;
  8845. }
  8846. } else {
  8847. result1 = null;
  8848. pos = pos2;
  8849. }
  8850. result1 = result1 !== null ? result1 : "";
  8851. if (result1 !== null) {
  8852. result0 = [result0, result1];
  8853. } else {
  8854. result0 = null;
  8855. pos = pos1;
  8856. }
  8857. } else {
  8858. result0 = null;
  8859. pos = pos1;
  8860. }
  8861. if (result0 !== null) {
  8862. result0 = function (offset) {
  8863. data = input.substring(pos, offset);
  8864. }(pos0);
  8865. }
  8866. if (result0 === null) {
  8867. pos = pos0;
  8868. }
  8869. return result0;
  8870. }
  8871. function parse_Contact() {
  8872. var result0, result1, result2, result3;
  8873. var pos0, pos1, pos2;
  8874. pos0 = pos;
  8875. result0 = parse_STAR();
  8876. if (result0 === null) {
  8877. pos1 = pos;
  8878. result0 = parse_contact_param();
  8879. if (result0 !== null) {
  8880. result1 = [];
  8881. pos2 = pos;
  8882. result2 = parse_COMMA();
  8883. if (result2 !== null) {
  8884. result3 = parse_contact_param();
  8885. if (result3 !== null) {
  8886. result2 = [result2, result3];
  8887. } else {
  8888. result2 = null;
  8889. pos = pos2;
  8890. }
  8891. } else {
  8892. result2 = null;
  8893. pos = pos2;
  8894. }
  8895. while (result2 !== null) {
  8896. result1.push(result2);
  8897. pos2 = pos;
  8898. result2 = parse_COMMA();
  8899. if (result2 !== null) {
  8900. result3 = parse_contact_param();
  8901. if (result3 !== null) {
  8902. result2 = [result2, result3];
  8903. } else {
  8904. result2 = null;
  8905. pos = pos2;
  8906. }
  8907. } else {
  8908. result2 = null;
  8909. pos = pos2;
  8910. }
  8911. }
  8912. if (result1 !== null) {
  8913. result0 = [result0, result1];
  8914. } else {
  8915. result0 = null;
  8916. pos = pos1;
  8917. }
  8918. } else {
  8919. result0 = null;
  8920. pos = pos1;
  8921. }
  8922. }
  8923. if (result0 !== null) {
  8924. result0 = function (offset) {
  8925. var idx, length;
  8926. length = data.multi_header.length;
  8927. for (idx = 0; idx < length; idx++) {
  8928. if (data.multi_header[idx].parsed === null) {
  8929. data = null;
  8930. break;
  8931. }
  8932. }
  8933. if (data !== null) {
  8934. data = data.multi_header;
  8935. } else {
  8936. data = -1;
  8937. }
  8938. }(pos0);
  8939. }
  8940. if (result0 === null) {
  8941. pos = pos0;
  8942. }
  8943. return result0;
  8944. }
  8945. function parse_contact_param() {
  8946. var result0, result1, result2, result3;
  8947. var pos0, pos1, pos2;
  8948. pos0 = pos;
  8949. pos1 = pos;
  8950. result0 = parse_SIP_URI_noparams();
  8951. if (result0 === null) {
  8952. result0 = parse_name_addr();
  8953. }
  8954. if (result0 !== null) {
  8955. result1 = [];
  8956. pos2 = pos;
  8957. result2 = parse_SEMI();
  8958. if (result2 !== null) {
  8959. result3 = parse_contact_params();
  8960. if (result3 !== null) {
  8961. result2 = [result2, result3];
  8962. } else {
  8963. result2 = null;
  8964. pos = pos2;
  8965. }
  8966. } else {
  8967. result2 = null;
  8968. pos = pos2;
  8969. }
  8970. while (result2 !== null) {
  8971. result1.push(result2);
  8972. pos2 = pos;
  8973. result2 = parse_SEMI();
  8974. if (result2 !== null) {
  8975. result3 = parse_contact_params();
  8976. if (result3 !== null) {
  8977. result2 = [result2, result3];
  8978. } else {
  8979. result2 = null;
  8980. pos = pos2;
  8981. }
  8982. } else {
  8983. result2 = null;
  8984. pos = pos2;
  8985. }
  8986. }
  8987. if (result1 !== null) {
  8988. result0 = [result0, result1];
  8989. } else {
  8990. result0 = null;
  8991. pos = pos1;
  8992. }
  8993. } else {
  8994. result0 = null;
  8995. pos = pos1;
  8996. }
  8997. if (result0 !== null) {
  8998. result0 = function (offset) {
  8999. var header;
  9000. if (!data.multi_header) data.multi_header = [];
  9001. try {
  9002. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  9003. delete data.uri;
  9004. delete data.display_name;
  9005. delete data.params;
  9006. } catch (e) {
  9007. header = null;
  9008. }
  9009. data.multi_header.push({ 'possition': pos,
  9010. 'offset': offset,
  9011. 'parsed': header
  9012. });
  9013. }(pos0);
  9014. }
  9015. if (result0 === null) {
  9016. pos = pos0;
  9017. }
  9018. return result0;
  9019. }
  9020. function parse_name_addr() {
  9021. var result0, result1, result2, result3;
  9022. var pos0;
  9023. pos0 = pos;
  9024. result0 = parse_display_name();
  9025. result0 = result0 !== null ? result0 : "";
  9026. if (result0 !== null) {
  9027. result1 = parse_LAQUOT();
  9028. if (result1 !== null) {
  9029. result2 = parse_SIP_URI();
  9030. if (result2 !== null) {
  9031. result3 = parse_RAQUOT();
  9032. if (result3 !== null) {
  9033. result0 = [result0, result1, result2, result3];
  9034. } else {
  9035. result0 = null;
  9036. pos = pos0;
  9037. }
  9038. } else {
  9039. result0 = null;
  9040. pos = pos0;
  9041. }
  9042. } else {
  9043. result0 = null;
  9044. pos = pos0;
  9045. }
  9046. } else {
  9047. result0 = null;
  9048. pos = pos0;
  9049. }
  9050. return result0;
  9051. }
  9052. function parse_display_name() {
  9053. var result0, result1, result2, result3;
  9054. var pos0, pos1, pos2;
  9055. pos0 = pos;
  9056. pos1 = pos;
  9057. result0 = parse_token();
  9058. if (result0 !== null) {
  9059. result1 = [];
  9060. pos2 = pos;
  9061. result2 = parse_LWS();
  9062. if (result2 !== null) {
  9063. result3 = parse_token();
  9064. if (result3 !== null) {
  9065. result2 = [result2, result3];
  9066. } else {
  9067. result2 = null;
  9068. pos = pos2;
  9069. }
  9070. } else {
  9071. result2 = null;
  9072. pos = pos2;
  9073. }
  9074. while (result2 !== null) {
  9075. result1.push(result2);
  9076. pos2 = pos;
  9077. result2 = parse_LWS();
  9078. if (result2 !== null) {
  9079. result3 = parse_token();
  9080. if (result3 !== null) {
  9081. result2 = [result2, result3];
  9082. } else {
  9083. result2 = null;
  9084. pos = pos2;
  9085. }
  9086. } else {
  9087. result2 = null;
  9088. pos = pos2;
  9089. }
  9090. }
  9091. if (result1 !== null) {
  9092. result0 = [result0, result1];
  9093. } else {
  9094. result0 = null;
  9095. pos = pos1;
  9096. }
  9097. } else {
  9098. result0 = null;
  9099. pos = pos1;
  9100. }
  9101. if (result0 === null) {
  9102. result0 = parse_quoted_string();
  9103. }
  9104. if (result0 !== null) {
  9105. result0 = function (offset, display_name) {
  9106. display_name = input.substring(pos, offset).trim();
  9107. if (display_name[0] === '\"') {
  9108. display_name = display_name.substring(1, display_name.length - 1);
  9109. }
  9110. data.display_name = display_name;
  9111. }(pos0, result0);
  9112. }
  9113. if (result0 === null) {
  9114. pos = pos0;
  9115. }
  9116. return result0;
  9117. }
  9118. function parse_contact_params() {
  9119. var result0;
  9120. result0 = parse_c_p_q();
  9121. if (result0 === null) {
  9122. result0 = parse_c_p_expires();
  9123. if (result0 === null) {
  9124. result0 = parse_generic_param();
  9125. }
  9126. }
  9127. return result0;
  9128. }
  9129. function parse_c_p_q() {
  9130. var result0, result1, result2;
  9131. var pos0, pos1;
  9132. pos0 = pos;
  9133. pos1 = pos;
  9134. if (input.substr(pos, 1).toLowerCase() === "q") {
  9135. result0 = input.substr(pos, 1);
  9136. pos++;
  9137. } else {
  9138. result0 = null;
  9139. if (reportFailures === 0) {
  9140. matchFailed("\"q\"");
  9141. }
  9142. }
  9143. if (result0 !== null) {
  9144. result1 = parse_EQUAL();
  9145. if (result1 !== null) {
  9146. result2 = parse_qvalue();
  9147. if (result2 !== null) {
  9148. result0 = [result0, result1, result2];
  9149. } else {
  9150. result0 = null;
  9151. pos = pos1;
  9152. }
  9153. } else {
  9154. result0 = null;
  9155. pos = pos1;
  9156. }
  9157. } else {
  9158. result0 = null;
  9159. pos = pos1;
  9160. }
  9161. if (result0 !== null) {
  9162. result0 = function (offset, q) {
  9163. if (!data.params) data.params = {};
  9164. data.params['q'] = q;
  9165. }(pos0, result0[2]);
  9166. }
  9167. if (result0 === null) {
  9168. pos = pos0;
  9169. }
  9170. return result0;
  9171. }
  9172. function parse_c_p_expires() {
  9173. var result0, result1, result2;
  9174. var pos0, pos1;
  9175. pos0 = pos;
  9176. pos1 = pos;
  9177. if (input.substr(pos, 7).toLowerCase() === "expires") {
  9178. result0 = input.substr(pos, 7);
  9179. pos += 7;
  9180. } else {
  9181. result0 = null;
  9182. if (reportFailures === 0) {
  9183. matchFailed("\"expires\"");
  9184. }
  9185. }
  9186. if (result0 !== null) {
  9187. result1 = parse_EQUAL();
  9188. if (result1 !== null) {
  9189. result2 = parse_delta_seconds();
  9190. if (result2 !== null) {
  9191. result0 = [result0, result1, result2];
  9192. } else {
  9193. result0 = null;
  9194. pos = pos1;
  9195. }
  9196. } else {
  9197. result0 = null;
  9198. pos = pos1;
  9199. }
  9200. } else {
  9201. result0 = null;
  9202. pos = pos1;
  9203. }
  9204. if (result0 !== null) {
  9205. result0 = function (offset, expires) {
  9206. if (!data.params) data.params = {};
  9207. data.params['expires'] = expires;
  9208. }(pos0, result0[2]);
  9209. }
  9210. if (result0 === null) {
  9211. pos = pos0;
  9212. }
  9213. return result0;
  9214. }
  9215. function parse_delta_seconds() {
  9216. var result0, result1;
  9217. var pos0;
  9218. pos0 = pos;
  9219. result1 = parse_DIGIT();
  9220. if (result1 !== null) {
  9221. result0 = [];
  9222. while (result1 !== null) {
  9223. result0.push(result1);
  9224. result1 = parse_DIGIT();
  9225. }
  9226. } else {
  9227. result0 = null;
  9228. }
  9229. if (result0 !== null) {
  9230. result0 = function (offset, delta_seconds) {
  9231. return parseInt(delta_seconds.join(''));
  9232. }(pos0, result0);
  9233. }
  9234. if (result0 === null) {
  9235. pos = pos0;
  9236. }
  9237. return result0;
  9238. }
  9239. function parse_qvalue() {
  9240. var result0, result1, result2, result3, result4;
  9241. var pos0, pos1, pos2;
  9242. pos0 = pos;
  9243. pos1 = pos;
  9244. if (input.charCodeAt(pos) === 48) {
  9245. result0 = "0";
  9246. pos++;
  9247. } else {
  9248. result0 = null;
  9249. if (reportFailures === 0) {
  9250. matchFailed("\"0\"");
  9251. }
  9252. }
  9253. if (result0 !== null) {
  9254. pos2 = pos;
  9255. if (input.charCodeAt(pos) === 46) {
  9256. result1 = ".";
  9257. pos++;
  9258. } else {
  9259. result1 = null;
  9260. if (reportFailures === 0) {
  9261. matchFailed("\".\"");
  9262. }
  9263. }
  9264. if (result1 !== null) {
  9265. result2 = parse_DIGIT();
  9266. result2 = result2 !== null ? result2 : "";
  9267. if (result2 !== null) {
  9268. result3 = parse_DIGIT();
  9269. result3 = result3 !== null ? result3 : "";
  9270. if (result3 !== null) {
  9271. result4 = parse_DIGIT();
  9272. result4 = result4 !== null ? result4 : "";
  9273. if (result4 !== null) {
  9274. result1 = [result1, result2, result3, result4];
  9275. } else {
  9276. result1 = null;
  9277. pos = pos2;
  9278. }
  9279. } else {
  9280. result1 = null;
  9281. pos = pos2;
  9282. }
  9283. } else {
  9284. result1 = null;
  9285. pos = pos2;
  9286. }
  9287. } else {
  9288. result1 = null;
  9289. pos = pos2;
  9290. }
  9291. result1 = result1 !== null ? result1 : "";
  9292. if (result1 !== null) {
  9293. result0 = [result0, result1];
  9294. } else {
  9295. result0 = null;
  9296. pos = pos1;
  9297. }
  9298. } else {
  9299. result0 = null;
  9300. pos = pos1;
  9301. }
  9302. if (result0 !== null) {
  9303. result0 = function (offset) {
  9304. return parseFloat(input.substring(pos, offset));
  9305. }(pos0);
  9306. }
  9307. if (result0 === null) {
  9308. pos = pos0;
  9309. }
  9310. return result0;
  9311. }
  9312. function parse_generic_param() {
  9313. var result0, result1, result2;
  9314. var pos0, pos1, pos2;
  9315. pos0 = pos;
  9316. pos1 = pos;
  9317. result0 = parse_token();
  9318. if (result0 !== null) {
  9319. pos2 = pos;
  9320. result1 = parse_EQUAL();
  9321. if (result1 !== null) {
  9322. result2 = parse_gen_value();
  9323. if (result2 !== null) {
  9324. result1 = [result1, result2];
  9325. } else {
  9326. result1 = null;
  9327. pos = pos2;
  9328. }
  9329. } else {
  9330. result1 = null;
  9331. pos = pos2;
  9332. }
  9333. result1 = result1 !== null ? result1 : "";
  9334. if (result1 !== null) {
  9335. result0 = [result0, result1];
  9336. } else {
  9337. result0 = null;
  9338. pos = pos1;
  9339. }
  9340. } else {
  9341. result0 = null;
  9342. pos = pos1;
  9343. }
  9344. if (result0 !== null) {
  9345. result0 = function (offset, param, value) {
  9346. if (!data.params) data.params = {};
  9347. if (typeof value === 'undefined') {
  9348. value = undefined;
  9349. } else {
  9350. value = value[1];
  9351. }
  9352. data.params[param.toLowerCase()] = value;
  9353. }(pos0, result0[0], result0[1]);
  9354. }
  9355. if (result0 === null) {
  9356. pos = pos0;
  9357. }
  9358. return result0;
  9359. }
  9360. function parse_gen_value() {
  9361. var result0;
  9362. result0 = parse_token();
  9363. if (result0 === null) {
  9364. result0 = parse_host();
  9365. if (result0 === null) {
  9366. result0 = parse_quoted_string();
  9367. }
  9368. }
  9369. return result0;
  9370. }
  9371. function parse_Content_Disposition() {
  9372. var result0, result1, result2, result3;
  9373. var pos0, pos1;
  9374. pos0 = pos;
  9375. result0 = parse_disp_type();
  9376. if (result0 !== null) {
  9377. result1 = [];
  9378. pos1 = pos;
  9379. result2 = parse_SEMI();
  9380. if (result2 !== null) {
  9381. result3 = parse_disp_param();
  9382. if (result3 !== null) {
  9383. result2 = [result2, result3];
  9384. } else {
  9385. result2 = null;
  9386. pos = pos1;
  9387. }
  9388. } else {
  9389. result2 = null;
  9390. pos = pos1;
  9391. }
  9392. while (result2 !== null) {
  9393. result1.push(result2);
  9394. pos1 = pos;
  9395. result2 = parse_SEMI();
  9396. if (result2 !== null) {
  9397. result3 = parse_disp_param();
  9398. if (result3 !== null) {
  9399. result2 = [result2, result3];
  9400. } else {
  9401. result2 = null;
  9402. pos = pos1;
  9403. }
  9404. } else {
  9405. result2 = null;
  9406. pos = pos1;
  9407. }
  9408. }
  9409. if (result1 !== null) {
  9410. result0 = [result0, result1];
  9411. } else {
  9412. result0 = null;
  9413. pos = pos0;
  9414. }
  9415. } else {
  9416. result0 = null;
  9417. pos = pos0;
  9418. }
  9419. return result0;
  9420. }
  9421. function parse_disp_type() {
  9422. var result0;
  9423. if (input.substr(pos, 6).toLowerCase() === "render") {
  9424. result0 = input.substr(pos, 6);
  9425. pos += 6;
  9426. } else {
  9427. result0 = null;
  9428. if (reportFailures === 0) {
  9429. matchFailed("\"render\"");
  9430. }
  9431. }
  9432. if (result0 === null) {
  9433. if (input.substr(pos, 7).toLowerCase() === "session") {
  9434. result0 = input.substr(pos, 7);
  9435. pos += 7;
  9436. } else {
  9437. result0 = null;
  9438. if (reportFailures === 0) {
  9439. matchFailed("\"session\"");
  9440. }
  9441. }
  9442. if (result0 === null) {
  9443. if (input.substr(pos, 4).toLowerCase() === "icon") {
  9444. result0 = input.substr(pos, 4);
  9445. pos += 4;
  9446. } else {
  9447. result0 = null;
  9448. if (reportFailures === 0) {
  9449. matchFailed("\"icon\"");
  9450. }
  9451. }
  9452. if (result0 === null) {
  9453. if (input.substr(pos, 5).toLowerCase() === "alert") {
  9454. result0 = input.substr(pos, 5);
  9455. pos += 5;
  9456. } else {
  9457. result0 = null;
  9458. if (reportFailures === 0) {
  9459. matchFailed("\"alert\"");
  9460. }
  9461. }
  9462. if (result0 === null) {
  9463. result0 = parse_token();
  9464. }
  9465. }
  9466. }
  9467. }
  9468. return result0;
  9469. }
  9470. function parse_disp_param() {
  9471. var result0;
  9472. result0 = parse_handling_param();
  9473. if (result0 === null) {
  9474. result0 = parse_generic_param();
  9475. }
  9476. return result0;
  9477. }
  9478. function parse_handling_param() {
  9479. var result0, result1, result2;
  9480. var pos0;
  9481. pos0 = pos;
  9482. if (input.substr(pos, 8).toLowerCase() === "handling") {
  9483. result0 = input.substr(pos, 8);
  9484. pos += 8;
  9485. } else {
  9486. result0 = null;
  9487. if (reportFailures === 0) {
  9488. matchFailed("\"handling\"");
  9489. }
  9490. }
  9491. if (result0 !== null) {
  9492. result1 = parse_EQUAL();
  9493. if (result1 !== null) {
  9494. if (input.substr(pos, 8).toLowerCase() === "optional") {
  9495. result2 = input.substr(pos, 8);
  9496. pos += 8;
  9497. } else {
  9498. result2 = null;
  9499. if (reportFailures === 0) {
  9500. matchFailed("\"optional\"");
  9501. }
  9502. }
  9503. if (result2 === null) {
  9504. if (input.substr(pos, 8).toLowerCase() === "required") {
  9505. result2 = input.substr(pos, 8);
  9506. pos += 8;
  9507. } else {
  9508. result2 = null;
  9509. if (reportFailures === 0) {
  9510. matchFailed("\"required\"");
  9511. }
  9512. }
  9513. if (result2 === null) {
  9514. result2 = parse_token();
  9515. }
  9516. }
  9517. if (result2 !== null) {
  9518. result0 = [result0, result1, result2];
  9519. } else {
  9520. result0 = null;
  9521. pos = pos0;
  9522. }
  9523. } else {
  9524. result0 = null;
  9525. pos = pos0;
  9526. }
  9527. } else {
  9528. result0 = null;
  9529. pos = pos0;
  9530. }
  9531. return result0;
  9532. }
  9533. function parse_Content_Encoding() {
  9534. var result0, result1, result2, result3;
  9535. var pos0, pos1;
  9536. pos0 = pos;
  9537. result0 = parse_token();
  9538. if (result0 !== null) {
  9539. result1 = [];
  9540. pos1 = pos;
  9541. result2 = parse_COMMA();
  9542. if (result2 !== null) {
  9543. result3 = parse_token();
  9544. if (result3 !== null) {
  9545. result2 = [result2, result3];
  9546. } else {
  9547. result2 = null;
  9548. pos = pos1;
  9549. }
  9550. } else {
  9551. result2 = null;
  9552. pos = pos1;
  9553. }
  9554. while (result2 !== null) {
  9555. result1.push(result2);
  9556. pos1 = pos;
  9557. result2 = parse_COMMA();
  9558. if (result2 !== null) {
  9559. result3 = parse_token();
  9560. if (result3 !== null) {
  9561. result2 = [result2, result3];
  9562. } else {
  9563. result2 = null;
  9564. pos = pos1;
  9565. }
  9566. } else {
  9567. result2 = null;
  9568. pos = pos1;
  9569. }
  9570. }
  9571. if (result1 !== null) {
  9572. result0 = [result0, result1];
  9573. } else {
  9574. result0 = null;
  9575. pos = pos0;
  9576. }
  9577. } else {
  9578. result0 = null;
  9579. pos = pos0;
  9580. }
  9581. return result0;
  9582. }
  9583. function parse_Content_Length() {
  9584. var result0, result1;
  9585. var pos0;
  9586. pos0 = pos;
  9587. result1 = parse_DIGIT();
  9588. if (result1 !== null) {
  9589. result0 = [];
  9590. while (result1 !== null) {
  9591. result0.push(result1);
  9592. result1 = parse_DIGIT();
  9593. }
  9594. } else {
  9595. result0 = null;
  9596. }
  9597. if (result0 !== null) {
  9598. result0 = function (offset, length) {
  9599. data = parseInt(length.join(''));
  9600. }(pos0, result0);
  9601. }
  9602. if (result0 === null) {
  9603. pos = pos0;
  9604. }
  9605. return result0;
  9606. }
  9607. function parse_Content_Type() {
  9608. var result0;
  9609. var pos0;
  9610. pos0 = pos;
  9611. result0 = parse_media_type();
  9612. if (result0 !== null) {
  9613. result0 = function (offset) {
  9614. data = input.substring(pos, offset);
  9615. }(pos0);
  9616. }
  9617. if (result0 === null) {
  9618. pos = pos0;
  9619. }
  9620. return result0;
  9621. }
  9622. function parse_media_type() {
  9623. var result0, result1, result2, result3, result4, result5;
  9624. var pos0, pos1;
  9625. pos0 = pos;
  9626. result0 = parse_m_type();
  9627. if (result0 !== null) {
  9628. result1 = parse_SLASH();
  9629. if (result1 !== null) {
  9630. result2 = parse_m_subtype();
  9631. if (result2 !== null) {
  9632. result3 = [];
  9633. pos1 = pos;
  9634. result4 = parse_SEMI();
  9635. if (result4 !== null) {
  9636. result5 = parse_m_parameter();
  9637. if (result5 !== null) {
  9638. result4 = [result4, result5];
  9639. } else {
  9640. result4 = null;
  9641. pos = pos1;
  9642. }
  9643. } else {
  9644. result4 = null;
  9645. pos = pos1;
  9646. }
  9647. while (result4 !== null) {
  9648. result3.push(result4);
  9649. pos1 = pos;
  9650. result4 = parse_SEMI();
  9651. if (result4 !== null) {
  9652. result5 = parse_m_parameter();
  9653. if (result5 !== null) {
  9654. result4 = [result4, result5];
  9655. } else {
  9656. result4 = null;
  9657. pos = pos1;
  9658. }
  9659. } else {
  9660. result4 = null;
  9661. pos = pos1;
  9662. }
  9663. }
  9664. if (result3 !== null) {
  9665. result0 = [result0, result1, result2, result3];
  9666. } else {
  9667. result0 = null;
  9668. pos = pos0;
  9669. }
  9670. } else {
  9671. result0 = null;
  9672. pos = pos0;
  9673. }
  9674. } else {
  9675. result0 = null;
  9676. pos = pos0;
  9677. }
  9678. } else {
  9679. result0 = null;
  9680. pos = pos0;
  9681. }
  9682. return result0;
  9683. }
  9684. function parse_m_type() {
  9685. var result0;
  9686. result0 = parse_discrete_type();
  9687. if (result0 === null) {
  9688. result0 = parse_composite_type();
  9689. }
  9690. return result0;
  9691. }
  9692. function parse_discrete_type() {
  9693. var result0;
  9694. if (input.substr(pos, 4).toLowerCase() === "text") {
  9695. result0 = input.substr(pos, 4);
  9696. pos += 4;
  9697. } else {
  9698. result0 = null;
  9699. if (reportFailures === 0) {
  9700. matchFailed("\"text\"");
  9701. }
  9702. }
  9703. if (result0 === null) {
  9704. if (input.substr(pos, 5).toLowerCase() === "image") {
  9705. result0 = input.substr(pos, 5);
  9706. pos += 5;
  9707. } else {
  9708. result0 = null;
  9709. if (reportFailures === 0) {
  9710. matchFailed("\"image\"");
  9711. }
  9712. }
  9713. if (result0 === null) {
  9714. if (input.substr(pos, 5).toLowerCase() === "audio") {
  9715. result0 = input.substr(pos, 5);
  9716. pos += 5;
  9717. } else {
  9718. result0 = null;
  9719. if (reportFailures === 0) {
  9720. matchFailed("\"audio\"");
  9721. }
  9722. }
  9723. if (result0 === null) {
  9724. if (input.substr(pos, 5).toLowerCase() === "video") {
  9725. result0 = input.substr(pos, 5);
  9726. pos += 5;
  9727. } else {
  9728. result0 = null;
  9729. if (reportFailures === 0) {
  9730. matchFailed("\"video\"");
  9731. }
  9732. }
  9733. if (result0 === null) {
  9734. if (input.substr(pos, 11).toLowerCase() === "application") {
  9735. result0 = input.substr(pos, 11);
  9736. pos += 11;
  9737. } else {
  9738. result0 = null;
  9739. if (reportFailures === 0) {
  9740. matchFailed("\"application\"");
  9741. }
  9742. }
  9743. if (result0 === null) {
  9744. result0 = parse_extension_token();
  9745. }
  9746. }
  9747. }
  9748. }
  9749. }
  9750. return result0;
  9751. }
  9752. function parse_composite_type() {
  9753. var result0;
  9754. if (input.substr(pos, 7).toLowerCase() === "message") {
  9755. result0 = input.substr(pos, 7);
  9756. pos += 7;
  9757. } else {
  9758. result0 = null;
  9759. if (reportFailures === 0) {
  9760. matchFailed("\"message\"");
  9761. }
  9762. }
  9763. if (result0 === null) {
  9764. if (input.substr(pos, 9).toLowerCase() === "multipart") {
  9765. result0 = input.substr(pos, 9);
  9766. pos += 9;
  9767. } else {
  9768. result0 = null;
  9769. if (reportFailures === 0) {
  9770. matchFailed("\"multipart\"");
  9771. }
  9772. }
  9773. if (result0 === null) {
  9774. result0 = parse_extension_token();
  9775. }
  9776. }
  9777. return result0;
  9778. }
  9779. function parse_extension_token() {
  9780. var result0;
  9781. result0 = parse_token();
  9782. if (result0 === null) {
  9783. result0 = parse_x_token();
  9784. }
  9785. return result0;
  9786. }
  9787. function parse_x_token() {
  9788. var result0, result1;
  9789. var pos0;
  9790. pos0 = pos;
  9791. if (input.substr(pos, 2).toLowerCase() === "x-") {
  9792. result0 = input.substr(pos, 2);
  9793. pos += 2;
  9794. } else {
  9795. result0 = null;
  9796. if (reportFailures === 0) {
  9797. matchFailed("\"x-\"");
  9798. }
  9799. }
  9800. if (result0 !== null) {
  9801. result1 = parse_token();
  9802. if (result1 !== null) {
  9803. result0 = [result0, result1];
  9804. } else {
  9805. result0 = null;
  9806. pos = pos0;
  9807. }
  9808. } else {
  9809. result0 = null;
  9810. pos = pos0;
  9811. }
  9812. return result0;
  9813. }
  9814. function parse_m_subtype() {
  9815. var result0;
  9816. result0 = parse_extension_token();
  9817. if (result0 === null) {
  9818. result0 = parse_token();
  9819. }
  9820. return result0;
  9821. }
  9822. function parse_m_parameter() {
  9823. var result0, result1, result2;
  9824. var pos0;
  9825. pos0 = pos;
  9826. result0 = parse_token();
  9827. if (result0 !== null) {
  9828. result1 = parse_EQUAL();
  9829. if (result1 !== null) {
  9830. result2 = parse_m_value();
  9831. if (result2 !== null) {
  9832. result0 = [result0, result1, result2];
  9833. } else {
  9834. result0 = null;
  9835. pos = pos0;
  9836. }
  9837. } else {
  9838. result0 = null;
  9839. pos = pos0;
  9840. }
  9841. } else {
  9842. result0 = null;
  9843. pos = pos0;
  9844. }
  9845. return result0;
  9846. }
  9847. function parse_m_value() {
  9848. var result0;
  9849. result0 = parse_token();
  9850. if (result0 === null) {
  9851. result0 = parse_quoted_string();
  9852. }
  9853. return result0;
  9854. }
  9855. function parse_CSeq() {
  9856. var result0, result1, result2;
  9857. var pos0;
  9858. pos0 = pos;
  9859. result0 = parse_CSeq_value();
  9860. if (result0 !== null) {
  9861. result1 = parse_LWS();
  9862. if (result1 !== null) {
  9863. result2 = parse_Method();
  9864. if (result2 !== null) {
  9865. result0 = [result0, result1, result2];
  9866. } else {
  9867. result0 = null;
  9868. pos = pos0;
  9869. }
  9870. } else {
  9871. result0 = null;
  9872. pos = pos0;
  9873. }
  9874. } else {
  9875. result0 = null;
  9876. pos = pos0;
  9877. }
  9878. return result0;
  9879. }
  9880. function parse_CSeq_value() {
  9881. var result0, result1;
  9882. var pos0;
  9883. pos0 = pos;
  9884. result1 = parse_DIGIT();
  9885. if (result1 !== null) {
  9886. result0 = [];
  9887. while (result1 !== null) {
  9888. result0.push(result1);
  9889. result1 = parse_DIGIT();
  9890. }
  9891. } else {
  9892. result0 = null;
  9893. }
  9894. if (result0 !== null) {
  9895. result0 = function (offset, cseq_value) {
  9896. data.value = parseInt(cseq_value.join(''));
  9897. }(pos0, result0);
  9898. }
  9899. if (result0 === null) {
  9900. pos = pos0;
  9901. }
  9902. return result0;
  9903. }
  9904. function parse_Expires() {
  9905. var result0;
  9906. var pos0;
  9907. pos0 = pos;
  9908. result0 = parse_delta_seconds();
  9909. if (result0 !== null) {
  9910. result0 = function (offset, expires) {
  9911. data = expires;
  9912. }(pos0, result0);
  9913. }
  9914. if (result0 === null) {
  9915. pos = pos0;
  9916. }
  9917. return result0;
  9918. }
  9919. function parse_Event() {
  9920. var result0, result1, result2, result3;
  9921. var pos0, pos1, pos2;
  9922. pos0 = pos;
  9923. pos1 = pos;
  9924. result0 = parse_event_type();
  9925. if (result0 !== null) {
  9926. result1 = [];
  9927. pos2 = pos;
  9928. result2 = parse_SEMI();
  9929. if (result2 !== null) {
  9930. result3 = parse_generic_param();
  9931. if (result3 !== null) {
  9932. result2 = [result2, result3];
  9933. } else {
  9934. result2 = null;
  9935. pos = pos2;
  9936. }
  9937. } else {
  9938. result2 = null;
  9939. pos = pos2;
  9940. }
  9941. while (result2 !== null) {
  9942. result1.push(result2);
  9943. pos2 = pos;
  9944. result2 = parse_SEMI();
  9945. if (result2 !== null) {
  9946. result3 = parse_generic_param();
  9947. if (result3 !== null) {
  9948. result2 = [result2, result3];
  9949. } else {
  9950. result2 = null;
  9951. pos = pos2;
  9952. }
  9953. } else {
  9954. result2 = null;
  9955. pos = pos2;
  9956. }
  9957. }
  9958. if (result1 !== null) {
  9959. result0 = [result0, result1];
  9960. } else {
  9961. result0 = null;
  9962. pos = pos1;
  9963. }
  9964. } else {
  9965. result0 = null;
  9966. pos = pos1;
  9967. }
  9968. if (result0 !== null) {
  9969. result0 = function (offset, event_type) {
  9970. data.event = event_type.join('').toLowerCase();
  9971. }(pos0, result0[0]);
  9972. }
  9973. if (result0 === null) {
  9974. pos = pos0;
  9975. }
  9976. return result0;
  9977. }
  9978. function parse_event_type() {
  9979. var result0, result1, result2, result3;
  9980. var pos0, pos1;
  9981. pos0 = pos;
  9982. result0 = parse_token_nodot();
  9983. if (result0 !== null) {
  9984. result1 = [];
  9985. pos1 = pos;
  9986. if (input.charCodeAt(pos) === 46) {
  9987. result2 = ".";
  9988. pos++;
  9989. } else {
  9990. result2 = null;
  9991. if (reportFailures === 0) {
  9992. matchFailed("\".\"");
  9993. }
  9994. }
  9995. if (result2 !== null) {
  9996. result3 = parse_token_nodot();
  9997. if (result3 !== null) {
  9998. result2 = [result2, result3];
  9999. } else {
  10000. result2 = null;
  10001. pos = pos1;
  10002. }
  10003. } else {
  10004. result2 = null;
  10005. pos = pos1;
  10006. }
  10007. while (result2 !== null) {
  10008. result1.push(result2);
  10009. pos1 = pos;
  10010. if (input.charCodeAt(pos) === 46) {
  10011. result2 = ".";
  10012. pos++;
  10013. } else {
  10014. result2 = null;
  10015. if (reportFailures === 0) {
  10016. matchFailed("\".\"");
  10017. }
  10018. }
  10019. if (result2 !== null) {
  10020. result3 = parse_token_nodot();
  10021. if (result3 !== null) {
  10022. result2 = [result2, result3];
  10023. } else {
  10024. result2 = null;
  10025. pos = pos1;
  10026. }
  10027. } else {
  10028. result2 = null;
  10029. pos = pos1;
  10030. }
  10031. }
  10032. if (result1 !== null) {
  10033. result0 = [result0, result1];
  10034. } else {
  10035. result0 = null;
  10036. pos = pos0;
  10037. }
  10038. } else {
  10039. result0 = null;
  10040. pos = pos0;
  10041. }
  10042. return result0;
  10043. }
  10044. function parse_From() {
  10045. var result0, result1, result2, result3;
  10046. var pos0, pos1, pos2;
  10047. pos0 = pos;
  10048. pos1 = pos;
  10049. result0 = parse_SIP_URI_noparams();
  10050. if (result0 === null) {
  10051. result0 = parse_name_addr();
  10052. }
  10053. if (result0 !== null) {
  10054. result1 = [];
  10055. pos2 = pos;
  10056. result2 = parse_SEMI();
  10057. if (result2 !== null) {
  10058. result3 = parse_from_param();
  10059. if (result3 !== null) {
  10060. result2 = [result2, result3];
  10061. } else {
  10062. result2 = null;
  10063. pos = pos2;
  10064. }
  10065. } else {
  10066. result2 = null;
  10067. pos = pos2;
  10068. }
  10069. while (result2 !== null) {
  10070. result1.push(result2);
  10071. pos2 = pos;
  10072. result2 = parse_SEMI();
  10073. if (result2 !== null) {
  10074. result3 = parse_from_param();
  10075. if (result3 !== null) {
  10076. result2 = [result2, result3];
  10077. } else {
  10078. result2 = null;
  10079. pos = pos2;
  10080. }
  10081. } else {
  10082. result2 = null;
  10083. pos = pos2;
  10084. }
  10085. }
  10086. if (result1 !== null) {
  10087. result0 = [result0, result1];
  10088. } else {
  10089. result0 = null;
  10090. pos = pos1;
  10091. }
  10092. } else {
  10093. result0 = null;
  10094. pos = pos1;
  10095. }
  10096. if (result0 !== null) {
  10097. result0 = function (offset) {
  10098. var tag = data.tag;
  10099. try {
  10100. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  10101. if (tag) {
  10102. data.setParam('tag', tag);
  10103. }
  10104. } catch (e) {
  10105. data = -1;
  10106. }
  10107. }(pos0);
  10108. }
  10109. if (result0 === null) {
  10110. pos = pos0;
  10111. }
  10112. return result0;
  10113. }
  10114. function parse_from_param() {
  10115. var result0;
  10116. result0 = parse_tag_param();
  10117. if (result0 === null) {
  10118. result0 = parse_generic_param();
  10119. }
  10120. return result0;
  10121. }
  10122. function parse_tag_param() {
  10123. var result0, result1, result2;
  10124. var pos0, pos1;
  10125. pos0 = pos;
  10126. pos1 = pos;
  10127. if (input.substr(pos, 3).toLowerCase() === "tag") {
  10128. result0 = input.substr(pos, 3);
  10129. pos += 3;
  10130. } else {
  10131. result0 = null;
  10132. if (reportFailures === 0) {
  10133. matchFailed("\"tag\"");
  10134. }
  10135. }
  10136. if (result0 !== null) {
  10137. result1 = parse_EQUAL();
  10138. if (result1 !== null) {
  10139. result2 = parse_token();
  10140. if (result2 !== null) {
  10141. result0 = [result0, result1, result2];
  10142. } else {
  10143. result0 = null;
  10144. pos = pos1;
  10145. }
  10146. } else {
  10147. result0 = null;
  10148. pos = pos1;
  10149. }
  10150. } else {
  10151. result0 = null;
  10152. pos = pos1;
  10153. }
  10154. if (result0 !== null) {
  10155. result0 = function (offset, tag) {
  10156. data.tag = tag;
  10157. }(pos0, result0[2]);
  10158. }
  10159. if (result0 === null) {
  10160. pos = pos0;
  10161. }
  10162. return result0;
  10163. }
  10164. function parse_Max_Forwards() {
  10165. var result0, result1;
  10166. var pos0;
  10167. pos0 = pos;
  10168. result1 = parse_DIGIT();
  10169. if (result1 !== null) {
  10170. result0 = [];
  10171. while (result1 !== null) {
  10172. result0.push(result1);
  10173. result1 = parse_DIGIT();
  10174. }
  10175. } else {
  10176. result0 = null;
  10177. }
  10178. if (result0 !== null) {
  10179. result0 = function (offset, forwards) {
  10180. data = parseInt(forwards.join(''));
  10181. }(pos0, result0);
  10182. }
  10183. if (result0 === null) {
  10184. pos = pos0;
  10185. }
  10186. return result0;
  10187. }
  10188. function parse_Min_Expires() {
  10189. var result0;
  10190. var pos0;
  10191. pos0 = pos;
  10192. result0 = parse_delta_seconds();
  10193. if (result0 !== null) {
  10194. result0 = function (offset, min_expires) {
  10195. data = min_expires;
  10196. }(pos0, result0);
  10197. }
  10198. if (result0 === null) {
  10199. pos = pos0;
  10200. }
  10201. return result0;
  10202. }
  10203. function parse_Name_Addr_Header() {
  10204. var result0, result1, result2, result3, result4, result5, result6;
  10205. var pos0, pos1, pos2;
  10206. pos0 = pos;
  10207. pos1 = pos;
  10208. result0 = [];
  10209. result1 = parse_display_name();
  10210. while (result1 !== null) {
  10211. result0.push(result1);
  10212. result1 = parse_display_name();
  10213. }
  10214. if (result0 !== null) {
  10215. result1 = parse_LAQUOT();
  10216. if (result1 !== null) {
  10217. result2 = parse_SIP_URI();
  10218. if (result2 !== null) {
  10219. result3 = parse_RAQUOT();
  10220. if (result3 !== null) {
  10221. result4 = [];
  10222. pos2 = pos;
  10223. result5 = parse_SEMI();
  10224. if (result5 !== null) {
  10225. result6 = parse_generic_param();
  10226. if (result6 !== null) {
  10227. result5 = [result5, result6];
  10228. } else {
  10229. result5 = null;
  10230. pos = pos2;
  10231. }
  10232. } else {
  10233. result5 = null;
  10234. pos = pos2;
  10235. }
  10236. while (result5 !== null) {
  10237. result4.push(result5);
  10238. pos2 = pos;
  10239. result5 = parse_SEMI();
  10240. if (result5 !== null) {
  10241. result6 = parse_generic_param();
  10242. if (result6 !== null) {
  10243. result5 = [result5, result6];
  10244. } else {
  10245. result5 = null;
  10246. pos = pos2;
  10247. }
  10248. } else {
  10249. result5 = null;
  10250. pos = pos2;
  10251. }
  10252. }
  10253. if (result4 !== null) {
  10254. result0 = [result0, result1, result2, result3, result4];
  10255. } else {
  10256. result0 = null;
  10257. pos = pos1;
  10258. }
  10259. } else {
  10260. result0 = null;
  10261. pos = pos1;
  10262. }
  10263. } else {
  10264. result0 = null;
  10265. pos = pos1;
  10266. }
  10267. } else {
  10268. result0 = null;
  10269. pos = pos1;
  10270. }
  10271. } else {
  10272. result0 = null;
  10273. pos = pos1;
  10274. }
  10275. if (result0 !== null) {
  10276. result0 = function (offset) {
  10277. try {
  10278. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  10279. } catch (e) {
  10280. data = -1;
  10281. }
  10282. }(pos0);
  10283. }
  10284. if (result0 === null) {
  10285. pos = pos0;
  10286. }
  10287. return result0;
  10288. }
  10289. function parse_Proxy_Authenticate() {
  10290. var result0;
  10291. result0 = parse_challenge();
  10292. return result0;
  10293. }
  10294. function parse_challenge() {
  10295. var result0, result1, result2, result3, result4, result5;
  10296. var pos0, pos1;
  10297. pos0 = pos;
  10298. if (input.substr(pos, 6).toLowerCase() === "digest") {
  10299. result0 = input.substr(pos, 6);
  10300. pos += 6;
  10301. } else {
  10302. result0 = null;
  10303. if (reportFailures === 0) {
  10304. matchFailed("\"Digest\"");
  10305. }
  10306. }
  10307. if (result0 !== null) {
  10308. result1 = parse_LWS();
  10309. if (result1 !== null) {
  10310. result2 = parse_digest_cln();
  10311. if (result2 !== null) {
  10312. result3 = [];
  10313. pos1 = pos;
  10314. result4 = parse_COMMA();
  10315. if (result4 !== null) {
  10316. result5 = parse_digest_cln();
  10317. if (result5 !== null) {
  10318. result4 = [result4, result5];
  10319. } else {
  10320. result4 = null;
  10321. pos = pos1;
  10322. }
  10323. } else {
  10324. result4 = null;
  10325. pos = pos1;
  10326. }
  10327. while (result4 !== null) {
  10328. result3.push(result4);
  10329. pos1 = pos;
  10330. result4 = parse_COMMA();
  10331. if (result4 !== null) {
  10332. result5 = parse_digest_cln();
  10333. if (result5 !== null) {
  10334. result4 = [result4, result5];
  10335. } else {
  10336. result4 = null;
  10337. pos = pos1;
  10338. }
  10339. } else {
  10340. result4 = null;
  10341. pos = pos1;
  10342. }
  10343. }
  10344. if (result3 !== null) {
  10345. result0 = [result0, result1, result2, result3];
  10346. } else {
  10347. result0 = null;
  10348. pos = pos0;
  10349. }
  10350. } else {
  10351. result0 = null;
  10352. pos = pos0;
  10353. }
  10354. } else {
  10355. result0 = null;
  10356. pos = pos0;
  10357. }
  10358. } else {
  10359. result0 = null;
  10360. pos = pos0;
  10361. }
  10362. if (result0 === null) {
  10363. result0 = parse_other_challenge();
  10364. }
  10365. return result0;
  10366. }
  10367. function parse_other_challenge() {
  10368. var result0, result1, result2, result3, result4, result5;
  10369. var pos0, pos1;
  10370. pos0 = pos;
  10371. result0 = parse_token();
  10372. if (result0 !== null) {
  10373. result1 = parse_LWS();
  10374. if (result1 !== null) {
  10375. result2 = parse_auth_param();
  10376. if (result2 !== null) {
  10377. result3 = [];
  10378. pos1 = pos;
  10379. result4 = parse_COMMA();
  10380. if (result4 !== null) {
  10381. result5 = parse_auth_param();
  10382. if (result5 !== null) {
  10383. result4 = [result4, result5];
  10384. } else {
  10385. result4 = null;
  10386. pos = pos1;
  10387. }
  10388. } else {
  10389. result4 = null;
  10390. pos = pos1;
  10391. }
  10392. while (result4 !== null) {
  10393. result3.push(result4);
  10394. pos1 = pos;
  10395. result4 = parse_COMMA();
  10396. if (result4 !== null) {
  10397. result5 = parse_auth_param();
  10398. if (result5 !== null) {
  10399. result4 = [result4, result5];
  10400. } else {
  10401. result4 = null;
  10402. pos = pos1;
  10403. }
  10404. } else {
  10405. result4 = null;
  10406. pos = pos1;
  10407. }
  10408. }
  10409. if (result3 !== null) {
  10410. result0 = [result0, result1, result2, result3];
  10411. } else {
  10412. result0 = null;
  10413. pos = pos0;
  10414. }
  10415. } else {
  10416. result0 = null;
  10417. pos = pos0;
  10418. }
  10419. } else {
  10420. result0 = null;
  10421. pos = pos0;
  10422. }
  10423. } else {
  10424. result0 = null;
  10425. pos = pos0;
  10426. }
  10427. return result0;
  10428. }
  10429. function parse_auth_param() {
  10430. var result0, result1, result2;
  10431. var pos0;
  10432. pos0 = pos;
  10433. result0 = parse_token();
  10434. if (result0 !== null) {
  10435. result1 = parse_EQUAL();
  10436. if (result1 !== null) {
  10437. result2 = parse_token();
  10438. if (result2 === null) {
  10439. result2 = parse_quoted_string();
  10440. }
  10441. if (result2 !== null) {
  10442. result0 = [result0, result1, result2];
  10443. } else {
  10444. result0 = null;
  10445. pos = pos0;
  10446. }
  10447. } else {
  10448. result0 = null;
  10449. pos = pos0;
  10450. }
  10451. } else {
  10452. result0 = null;
  10453. pos = pos0;
  10454. }
  10455. return result0;
  10456. }
  10457. function parse_digest_cln() {
  10458. var result0;
  10459. result0 = parse_realm();
  10460. if (result0 === null) {
  10461. result0 = parse_domain();
  10462. if (result0 === null) {
  10463. result0 = parse_nonce();
  10464. if (result0 === null) {
  10465. result0 = parse_opaque();
  10466. if (result0 === null) {
  10467. result0 = parse_stale();
  10468. if (result0 === null) {
  10469. result0 = parse_algorithm();
  10470. if (result0 === null) {
  10471. result0 = parse_qop_options();
  10472. if (result0 === null) {
  10473. result0 = parse_auth_param();
  10474. }
  10475. }
  10476. }
  10477. }
  10478. }
  10479. }
  10480. }
  10481. return result0;
  10482. }
  10483. function parse_realm() {
  10484. var result0, result1, result2;
  10485. var pos0;
  10486. pos0 = pos;
  10487. if (input.substr(pos, 5).toLowerCase() === "realm") {
  10488. result0 = input.substr(pos, 5);
  10489. pos += 5;
  10490. } else {
  10491. result0 = null;
  10492. if (reportFailures === 0) {
  10493. matchFailed("\"realm\"");
  10494. }
  10495. }
  10496. if (result0 !== null) {
  10497. result1 = parse_EQUAL();
  10498. if (result1 !== null) {
  10499. result2 = parse_realm_value();
  10500. if (result2 !== null) {
  10501. result0 = [result0, result1, result2];
  10502. } else {
  10503. result0 = null;
  10504. pos = pos0;
  10505. }
  10506. } else {
  10507. result0 = null;
  10508. pos = pos0;
  10509. }
  10510. } else {
  10511. result0 = null;
  10512. pos = pos0;
  10513. }
  10514. return result0;
  10515. }
  10516. function parse_realm_value() {
  10517. var result0;
  10518. var pos0;
  10519. pos0 = pos;
  10520. result0 = parse_quoted_string_clean();
  10521. if (result0 !== null) {
  10522. result0 = function (offset, realm) {
  10523. data.realm = realm;
  10524. }(pos0, result0);
  10525. }
  10526. if (result0 === null) {
  10527. pos = pos0;
  10528. }
  10529. return result0;
  10530. }
  10531. function parse_domain() {
  10532. var result0, result1, result2, result3, result4, result5, result6;
  10533. var pos0, pos1;
  10534. pos0 = pos;
  10535. if (input.substr(pos, 6).toLowerCase() === "domain") {
  10536. result0 = input.substr(pos, 6);
  10537. pos += 6;
  10538. } else {
  10539. result0 = null;
  10540. if (reportFailures === 0) {
  10541. matchFailed("\"domain\"");
  10542. }
  10543. }
  10544. if (result0 !== null) {
  10545. result1 = parse_EQUAL();
  10546. if (result1 !== null) {
  10547. result2 = parse_LDQUOT();
  10548. if (result2 !== null) {
  10549. result3 = parse_URI();
  10550. if (result3 !== null) {
  10551. result4 = [];
  10552. pos1 = pos;
  10553. result6 = parse_SP();
  10554. if (result6 !== null) {
  10555. result5 = [];
  10556. while (result6 !== null) {
  10557. result5.push(result6);
  10558. result6 = parse_SP();
  10559. }
  10560. } else {
  10561. result5 = null;
  10562. }
  10563. if (result5 !== null) {
  10564. result6 = parse_URI();
  10565. if (result6 !== null) {
  10566. result5 = [result5, result6];
  10567. } else {
  10568. result5 = null;
  10569. pos = pos1;
  10570. }
  10571. } else {
  10572. result5 = null;
  10573. pos = pos1;
  10574. }
  10575. while (result5 !== null) {
  10576. result4.push(result5);
  10577. pos1 = pos;
  10578. result6 = parse_SP();
  10579. if (result6 !== null) {
  10580. result5 = [];
  10581. while (result6 !== null) {
  10582. result5.push(result6);
  10583. result6 = parse_SP();
  10584. }
  10585. } else {
  10586. result5 = null;
  10587. }
  10588. if (result5 !== null) {
  10589. result6 = parse_URI();
  10590. if (result6 !== null) {
  10591. result5 = [result5, result6];
  10592. } else {
  10593. result5 = null;
  10594. pos = pos1;
  10595. }
  10596. } else {
  10597. result5 = null;
  10598. pos = pos1;
  10599. }
  10600. }
  10601. if (result4 !== null) {
  10602. result5 = parse_RDQUOT();
  10603. if (result5 !== null) {
  10604. result0 = [result0, result1, result2, result3, result4, result5];
  10605. } else {
  10606. result0 = null;
  10607. pos = pos0;
  10608. }
  10609. } else {
  10610. result0 = null;
  10611. pos = pos0;
  10612. }
  10613. } else {
  10614. result0 = null;
  10615. pos = pos0;
  10616. }
  10617. } else {
  10618. result0 = null;
  10619. pos = pos0;
  10620. }
  10621. } else {
  10622. result0 = null;
  10623. pos = pos0;
  10624. }
  10625. } else {
  10626. result0 = null;
  10627. pos = pos0;
  10628. }
  10629. return result0;
  10630. }
  10631. function parse_URI() {
  10632. var result0;
  10633. result0 = parse_absoluteURI();
  10634. if (result0 === null) {
  10635. result0 = parse_abs_path();
  10636. }
  10637. return result0;
  10638. }
  10639. function parse_nonce() {
  10640. var result0, result1, result2;
  10641. var pos0;
  10642. pos0 = pos;
  10643. if (input.substr(pos, 5).toLowerCase() === "nonce") {
  10644. result0 = input.substr(pos, 5);
  10645. pos += 5;
  10646. } else {
  10647. result0 = null;
  10648. if (reportFailures === 0) {
  10649. matchFailed("\"nonce\"");
  10650. }
  10651. }
  10652. if (result0 !== null) {
  10653. result1 = parse_EQUAL();
  10654. if (result1 !== null) {
  10655. result2 = parse_nonce_value();
  10656. if (result2 !== null) {
  10657. result0 = [result0, result1, result2];
  10658. } else {
  10659. result0 = null;
  10660. pos = pos0;
  10661. }
  10662. } else {
  10663. result0 = null;
  10664. pos = pos0;
  10665. }
  10666. } else {
  10667. result0 = null;
  10668. pos = pos0;
  10669. }
  10670. return result0;
  10671. }
  10672. function parse_nonce_value() {
  10673. var result0;
  10674. var pos0;
  10675. pos0 = pos;
  10676. result0 = parse_quoted_string_clean();
  10677. if (result0 !== null) {
  10678. result0 = function (offset, nonce) {
  10679. data.nonce = nonce;
  10680. }(pos0, result0);
  10681. }
  10682. if (result0 === null) {
  10683. pos = pos0;
  10684. }
  10685. return result0;
  10686. }
  10687. function parse_opaque() {
  10688. var result0, result1, result2;
  10689. var pos0, pos1;
  10690. pos0 = pos;
  10691. pos1 = pos;
  10692. if (input.substr(pos, 6).toLowerCase() === "opaque") {
  10693. result0 = input.substr(pos, 6);
  10694. pos += 6;
  10695. } else {
  10696. result0 = null;
  10697. if (reportFailures === 0) {
  10698. matchFailed("\"opaque\"");
  10699. }
  10700. }
  10701. if (result0 !== null) {
  10702. result1 = parse_EQUAL();
  10703. if (result1 !== null) {
  10704. result2 = parse_quoted_string_clean();
  10705. if (result2 !== null) {
  10706. result0 = [result0, result1, result2];
  10707. } else {
  10708. result0 = null;
  10709. pos = pos1;
  10710. }
  10711. } else {
  10712. result0 = null;
  10713. pos = pos1;
  10714. }
  10715. } else {
  10716. result0 = null;
  10717. pos = pos1;
  10718. }
  10719. if (result0 !== null) {
  10720. result0 = function (offset, opaque) {
  10721. data.opaque = opaque;
  10722. }(pos0, result0[2]);
  10723. }
  10724. if (result0 === null) {
  10725. pos = pos0;
  10726. }
  10727. return result0;
  10728. }
  10729. function parse_stale() {
  10730. var result0, result1, result2;
  10731. var pos0, pos1;
  10732. pos0 = pos;
  10733. if (input.substr(pos, 5).toLowerCase() === "stale") {
  10734. result0 = input.substr(pos, 5);
  10735. pos += 5;
  10736. } else {
  10737. result0 = null;
  10738. if (reportFailures === 0) {
  10739. matchFailed("\"stale\"");
  10740. }
  10741. }
  10742. if (result0 !== null) {
  10743. result1 = parse_EQUAL();
  10744. if (result1 !== null) {
  10745. pos1 = pos;
  10746. if (input.substr(pos, 4).toLowerCase() === "true") {
  10747. result2 = input.substr(pos, 4);
  10748. pos += 4;
  10749. } else {
  10750. result2 = null;
  10751. if (reportFailures === 0) {
  10752. matchFailed("\"true\"");
  10753. }
  10754. }
  10755. if (result2 !== null) {
  10756. result2 = function (offset) {
  10757. data.stale = true;
  10758. }(pos1);
  10759. }
  10760. if (result2 === null) {
  10761. pos = pos1;
  10762. }
  10763. if (result2 === null) {
  10764. pos1 = pos;
  10765. if (input.substr(pos, 5).toLowerCase() === "false") {
  10766. result2 = input.substr(pos, 5);
  10767. pos += 5;
  10768. } else {
  10769. result2 = null;
  10770. if (reportFailures === 0) {
  10771. matchFailed("\"false\"");
  10772. }
  10773. }
  10774. if (result2 !== null) {
  10775. result2 = function (offset) {
  10776. data.stale = false;
  10777. }(pos1);
  10778. }
  10779. if (result2 === null) {
  10780. pos = pos1;
  10781. }
  10782. }
  10783. if (result2 !== null) {
  10784. result0 = [result0, result1, result2];
  10785. } else {
  10786. result0 = null;
  10787. pos = pos0;
  10788. }
  10789. } else {
  10790. result0 = null;
  10791. pos = pos0;
  10792. }
  10793. } else {
  10794. result0 = null;
  10795. pos = pos0;
  10796. }
  10797. return result0;
  10798. }
  10799. function parse_algorithm() {
  10800. var result0, result1, result2;
  10801. var pos0, pos1;
  10802. pos0 = pos;
  10803. pos1 = pos;
  10804. if (input.substr(pos, 9).toLowerCase() === "algorithm") {
  10805. result0 = input.substr(pos, 9);
  10806. pos += 9;
  10807. } else {
  10808. result0 = null;
  10809. if (reportFailures === 0) {
  10810. matchFailed("\"algorithm\"");
  10811. }
  10812. }
  10813. if (result0 !== null) {
  10814. result1 = parse_EQUAL();
  10815. if (result1 !== null) {
  10816. if (input.substr(pos, 3).toLowerCase() === "md5") {
  10817. result2 = input.substr(pos, 3);
  10818. pos += 3;
  10819. } else {
  10820. result2 = null;
  10821. if (reportFailures === 0) {
  10822. matchFailed("\"MD5\"");
  10823. }
  10824. }
  10825. if (result2 === null) {
  10826. if (input.substr(pos, 8).toLowerCase() === "md5-sess") {
  10827. result2 = input.substr(pos, 8);
  10828. pos += 8;
  10829. } else {
  10830. result2 = null;
  10831. if (reportFailures === 0) {
  10832. matchFailed("\"MD5-sess\"");
  10833. }
  10834. }
  10835. if (result2 === null) {
  10836. result2 = parse_token();
  10837. }
  10838. }
  10839. if (result2 !== null) {
  10840. result0 = [result0, result1, result2];
  10841. } else {
  10842. result0 = null;
  10843. pos = pos1;
  10844. }
  10845. } else {
  10846. result0 = null;
  10847. pos = pos1;
  10848. }
  10849. } else {
  10850. result0 = null;
  10851. pos = pos1;
  10852. }
  10853. if (result0 !== null) {
  10854. result0 = function (offset, algorithm) {
  10855. data.algorithm = algorithm.toUpperCase();
  10856. }(pos0, result0[2]);
  10857. }
  10858. if (result0 === null) {
  10859. pos = pos0;
  10860. }
  10861. return result0;
  10862. }
  10863. function parse_qop_options() {
  10864. var result0, result1, result2, result3, result4, result5, result6;
  10865. var pos0, pos1, pos2;
  10866. pos0 = pos;
  10867. if (input.substr(pos, 3).toLowerCase() === "qop") {
  10868. result0 = input.substr(pos, 3);
  10869. pos += 3;
  10870. } else {
  10871. result0 = null;
  10872. if (reportFailures === 0) {
  10873. matchFailed("\"qop\"");
  10874. }
  10875. }
  10876. if (result0 !== null) {
  10877. result1 = parse_EQUAL();
  10878. if (result1 !== null) {
  10879. result2 = parse_LDQUOT();
  10880. if (result2 !== null) {
  10881. pos1 = pos;
  10882. result3 = parse_qop_value();
  10883. if (result3 !== null) {
  10884. result4 = [];
  10885. pos2 = pos;
  10886. if (input.charCodeAt(pos) === 44) {
  10887. result5 = ",";
  10888. pos++;
  10889. } else {
  10890. result5 = null;
  10891. if (reportFailures === 0) {
  10892. matchFailed("\",\"");
  10893. }
  10894. }
  10895. if (result5 !== null) {
  10896. result6 = parse_qop_value();
  10897. if (result6 !== null) {
  10898. result5 = [result5, result6];
  10899. } else {
  10900. result5 = null;
  10901. pos = pos2;
  10902. }
  10903. } else {
  10904. result5 = null;
  10905. pos = pos2;
  10906. }
  10907. while (result5 !== null) {
  10908. result4.push(result5);
  10909. pos2 = pos;
  10910. if (input.charCodeAt(pos) === 44) {
  10911. result5 = ",";
  10912. pos++;
  10913. } else {
  10914. result5 = null;
  10915. if (reportFailures === 0) {
  10916. matchFailed("\",\"");
  10917. }
  10918. }
  10919. if (result5 !== null) {
  10920. result6 = parse_qop_value();
  10921. if (result6 !== null) {
  10922. result5 = [result5, result6];
  10923. } else {
  10924. result5 = null;
  10925. pos = pos2;
  10926. }
  10927. } else {
  10928. result5 = null;
  10929. pos = pos2;
  10930. }
  10931. }
  10932. if (result4 !== null) {
  10933. result3 = [result3, result4];
  10934. } else {
  10935. result3 = null;
  10936. pos = pos1;
  10937. }
  10938. } else {
  10939. result3 = null;
  10940. pos = pos1;
  10941. }
  10942. if (result3 !== null) {
  10943. result4 = parse_RDQUOT();
  10944. if (result4 !== null) {
  10945. result0 = [result0, result1, result2, result3, result4];
  10946. } else {
  10947. result0 = null;
  10948. pos = pos0;
  10949. }
  10950. } else {
  10951. result0 = null;
  10952. pos = pos0;
  10953. }
  10954. } else {
  10955. result0 = null;
  10956. pos = pos0;
  10957. }
  10958. } else {
  10959. result0 = null;
  10960. pos = pos0;
  10961. }
  10962. } else {
  10963. result0 = null;
  10964. pos = pos0;
  10965. }
  10966. return result0;
  10967. }
  10968. function parse_qop_value() {
  10969. var result0;
  10970. var pos0;
  10971. pos0 = pos;
  10972. if (input.substr(pos, 8).toLowerCase() === "auth-int") {
  10973. result0 = input.substr(pos, 8);
  10974. pos += 8;
  10975. } else {
  10976. result0 = null;
  10977. if (reportFailures === 0) {
  10978. matchFailed("\"auth-int\"");
  10979. }
  10980. }
  10981. if (result0 === null) {
  10982. if (input.substr(pos, 4).toLowerCase() === "auth") {
  10983. result0 = input.substr(pos, 4);
  10984. pos += 4;
  10985. } else {
  10986. result0 = null;
  10987. if (reportFailures === 0) {
  10988. matchFailed("\"auth\"");
  10989. }
  10990. }
  10991. if (result0 === null) {
  10992. result0 = parse_token();
  10993. }
  10994. }
  10995. if (result0 !== null) {
  10996. result0 = function (offset, qop_value) {
  10997. data.qop || (data.qop = []);
  10998. data.qop.push(qop_value.toLowerCase());
  10999. }(pos0, result0);
  11000. }
  11001. if (result0 === null) {
  11002. pos = pos0;
  11003. }
  11004. return result0;
  11005. }
  11006. function parse_Proxy_Require() {
  11007. var result0, result1, result2, result3;
  11008. var pos0, pos1;
  11009. pos0 = pos;
  11010. result0 = parse_token();
  11011. if (result0 !== null) {
  11012. result1 = [];
  11013. pos1 = pos;
  11014. result2 = parse_COMMA();
  11015. if (result2 !== null) {
  11016. result3 = parse_token();
  11017. if (result3 !== null) {
  11018. result2 = [result2, result3];
  11019. } else {
  11020. result2 = null;
  11021. pos = pos1;
  11022. }
  11023. } else {
  11024. result2 = null;
  11025. pos = pos1;
  11026. }
  11027. while (result2 !== null) {
  11028. result1.push(result2);
  11029. pos1 = pos;
  11030. result2 = parse_COMMA();
  11031. if (result2 !== null) {
  11032. result3 = parse_token();
  11033. if (result3 !== null) {
  11034. result2 = [result2, result3];
  11035. } else {
  11036. result2 = null;
  11037. pos = pos1;
  11038. }
  11039. } else {
  11040. result2 = null;
  11041. pos = pos1;
  11042. }
  11043. }
  11044. if (result1 !== null) {
  11045. result0 = [result0, result1];
  11046. } else {
  11047. result0 = null;
  11048. pos = pos0;
  11049. }
  11050. } else {
  11051. result0 = null;
  11052. pos = pos0;
  11053. }
  11054. return result0;
  11055. }
  11056. function parse_Record_Route() {
  11057. var result0, result1, result2, result3;
  11058. var pos0, pos1, pos2;
  11059. pos0 = pos;
  11060. pos1 = pos;
  11061. result0 = parse_rec_route();
  11062. if (result0 !== null) {
  11063. result1 = [];
  11064. pos2 = pos;
  11065. result2 = parse_COMMA();
  11066. if (result2 !== null) {
  11067. result3 = parse_rec_route();
  11068. if (result3 !== null) {
  11069. result2 = [result2, result3];
  11070. } else {
  11071. result2 = null;
  11072. pos = pos2;
  11073. }
  11074. } else {
  11075. result2 = null;
  11076. pos = pos2;
  11077. }
  11078. while (result2 !== null) {
  11079. result1.push(result2);
  11080. pos2 = pos;
  11081. result2 = parse_COMMA();
  11082. if (result2 !== null) {
  11083. result3 = parse_rec_route();
  11084. if (result3 !== null) {
  11085. result2 = [result2, result3];
  11086. } else {
  11087. result2 = null;
  11088. pos = pos2;
  11089. }
  11090. } else {
  11091. result2 = null;
  11092. pos = pos2;
  11093. }
  11094. }
  11095. if (result1 !== null) {
  11096. result0 = [result0, result1];
  11097. } else {
  11098. result0 = null;
  11099. pos = pos1;
  11100. }
  11101. } else {
  11102. result0 = null;
  11103. pos = pos1;
  11104. }
  11105. if (result0 !== null) {
  11106. result0 = function (offset) {
  11107. var idx, length;
  11108. length = data.multi_header.length;
  11109. for (idx = 0; idx < length; idx++) {
  11110. if (data.multi_header[idx].parsed === null) {
  11111. data = null;
  11112. break;
  11113. }
  11114. }
  11115. if (data !== null) {
  11116. data = data.multi_header;
  11117. } else {
  11118. data = -1;
  11119. }
  11120. }(pos0);
  11121. }
  11122. if (result0 === null) {
  11123. pos = pos0;
  11124. }
  11125. return result0;
  11126. }
  11127. function parse_rec_route() {
  11128. var result0, result1, result2, result3;
  11129. var pos0, pos1, pos2;
  11130. pos0 = pos;
  11131. pos1 = pos;
  11132. result0 = parse_name_addr();
  11133. if (result0 !== null) {
  11134. result1 = [];
  11135. pos2 = pos;
  11136. result2 = parse_SEMI();
  11137. if (result2 !== null) {
  11138. result3 = parse_generic_param();
  11139. if (result3 !== null) {
  11140. result2 = [result2, result3];
  11141. } else {
  11142. result2 = null;
  11143. pos = pos2;
  11144. }
  11145. } else {
  11146. result2 = null;
  11147. pos = pos2;
  11148. }
  11149. while (result2 !== null) {
  11150. result1.push(result2);
  11151. pos2 = pos;
  11152. result2 = parse_SEMI();
  11153. if (result2 !== null) {
  11154. result3 = parse_generic_param();
  11155. if (result3 !== null) {
  11156. result2 = [result2, result3];
  11157. } else {
  11158. result2 = null;
  11159. pos = pos2;
  11160. }
  11161. } else {
  11162. result2 = null;
  11163. pos = pos2;
  11164. }
  11165. }
  11166. if (result1 !== null) {
  11167. result0 = [result0, result1];
  11168. } else {
  11169. result0 = null;
  11170. pos = pos1;
  11171. }
  11172. } else {
  11173. result0 = null;
  11174. pos = pos1;
  11175. }
  11176. if (result0 !== null) {
  11177. result0 = function (offset) {
  11178. var header;
  11179. if (!data.multi_header) data.multi_header = [];
  11180. try {
  11181. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  11182. delete data.uri;
  11183. delete data.display_name;
  11184. delete data.params;
  11185. } catch (e) {
  11186. header = null;
  11187. }
  11188. data.multi_header.push({ 'possition': pos,
  11189. 'offset': offset,
  11190. 'parsed': header
  11191. });
  11192. }(pos0);
  11193. }
  11194. if (result0 === null) {
  11195. pos = pos0;
  11196. }
  11197. return result0;
  11198. }
  11199. function parse_Reason() {
  11200. var result0, result1, result2, result3;
  11201. var pos0, pos1, pos2;
  11202. pos0 = pos;
  11203. pos1 = pos;
  11204. if (input.substr(pos, 3).toLowerCase() === "sip") {
  11205. result0 = input.substr(pos, 3);
  11206. pos += 3;
  11207. } else {
  11208. result0 = null;
  11209. if (reportFailures === 0) {
  11210. matchFailed("\"SIP\"");
  11211. }
  11212. }
  11213. if (result0 === null) {
  11214. result0 = parse_token();
  11215. }
  11216. if (result0 !== null) {
  11217. result1 = [];
  11218. pos2 = pos;
  11219. result2 = parse_SEMI();
  11220. if (result2 !== null) {
  11221. result3 = parse_reason_param();
  11222. if (result3 !== null) {
  11223. result2 = [result2, result3];
  11224. } else {
  11225. result2 = null;
  11226. pos = pos2;
  11227. }
  11228. } else {
  11229. result2 = null;
  11230. pos = pos2;
  11231. }
  11232. while (result2 !== null) {
  11233. result1.push(result2);
  11234. pos2 = pos;
  11235. result2 = parse_SEMI();
  11236. if (result2 !== null) {
  11237. result3 = parse_reason_param();
  11238. if (result3 !== null) {
  11239. result2 = [result2, result3];
  11240. } else {
  11241. result2 = null;
  11242. pos = pos2;
  11243. }
  11244. } else {
  11245. result2 = null;
  11246. pos = pos2;
  11247. }
  11248. }
  11249. if (result1 !== null) {
  11250. result0 = [result0, result1];
  11251. } else {
  11252. result0 = null;
  11253. pos = pos1;
  11254. }
  11255. } else {
  11256. result0 = null;
  11257. pos = pos1;
  11258. }
  11259. if (result0 !== null) {
  11260. result0 = function (offset, protocol) {
  11261. data.protocol = protocol.toLowerCase();
  11262. if (!data.params) data.params = {};
  11263. if (data.params.text && data.params.text[0] === '"') {
  11264. var text = data.params.text;
  11265. data.text = text.substring(1, text.length - 1);
  11266. delete data.params.text;
  11267. }
  11268. }(pos0, result0[0]);
  11269. }
  11270. if (result0 === null) {
  11271. pos = pos0;
  11272. }
  11273. return result0;
  11274. }
  11275. function parse_reason_param() {
  11276. var result0;
  11277. result0 = parse_reason_cause();
  11278. if (result0 === null) {
  11279. result0 = parse_generic_param();
  11280. }
  11281. return result0;
  11282. }
  11283. function parse_reason_cause() {
  11284. var result0, result1, result2, result3;
  11285. var pos0, pos1;
  11286. pos0 = pos;
  11287. pos1 = pos;
  11288. if (input.substr(pos, 5).toLowerCase() === "cause") {
  11289. result0 = input.substr(pos, 5);
  11290. pos += 5;
  11291. } else {
  11292. result0 = null;
  11293. if (reportFailures === 0) {
  11294. matchFailed("\"cause\"");
  11295. }
  11296. }
  11297. if (result0 !== null) {
  11298. result1 = parse_EQUAL();
  11299. if (result1 !== null) {
  11300. result3 = parse_DIGIT();
  11301. if (result3 !== null) {
  11302. result2 = [];
  11303. while (result3 !== null) {
  11304. result2.push(result3);
  11305. result3 = parse_DIGIT();
  11306. }
  11307. } else {
  11308. result2 = null;
  11309. }
  11310. if (result2 !== null) {
  11311. result0 = [result0, result1, result2];
  11312. } else {
  11313. result0 = null;
  11314. pos = pos1;
  11315. }
  11316. } else {
  11317. result0 = null;
  11318. pos = pos1;
  11319. }
  11320. } else {
  11321. result0 = null;
  11322. pos = pos1;
  11323. }
  11324. if (result0 !== null) {
  11325. result0 = function (offset, cause) {
  11326. data.cause = parseInt(cause.join(''));
  11327. }(pos0, result0[2]);
  11328. }
  11329. if (result0 === null) {
  11330. pos = pos0;
  11331. }
  11332. return result0;
  11333. }
  11334. function parse_Require() {
  11335. var result0, result1, result2, result3;
  11336. var pos0, pos1;
  11337. pos0 = pos;
  11338. result0 = parse_token();
  11339. if (result0 !== null) {
  11340. result1 = [];
  11341. pos1 = pos;
  11342. result2 = parse_COMMA();
  11343. if (result2 !== null) {
  11344. result3 = parse_token();
  11345. if (result3 !== null) {
  11346. result2 = [result2, result3];
  11347. } else {
  11348. result2 = null;
  11349. pos = pos1;
  11350. }
  11351. } else {
  11352. result2 = null;
  11353. pos = pos1;
  11354. }
  11355. while (result2 !== null) {
  11356. result1.push(result2);
  11357. pos1 = pos;
  11358. result2 = parse_COMMA();
  11359. if (result2 !== null) {
  11360. result3 = parse_token();
  11361. if (result3 !== null) {
  11362. result2 = [result2, result3];
  11363. } else {
  11364. result2 = null;
  11365. pos = pos1;
  11366. }
  11367. } else {
  11368. result2 = null;
  11369. pos = pos1;
  11370. }
  11371. }
  11372. if (result1 !== null) {
  11373. result0 = [result0, result1];
  11374. } else {
  11375. result0 = null;
  11376. pos = pos0;
  11377. }
  11378. } else {
  11379. result0 = null;
  11380. pos = pos0;
  11381. }
  11382. return result0;
  11383. }
  11384. function parse_Route() {
  11385. var result0, result1, result2, result3;
  11386. var pos0, pos1;
  11387. pos0 = pos;
  11388. result0 = parse_route_param();
  11389. if (result0 !== null) {
  11390. result1 = [];
  11391. pos1 = pos;
  11392. result2 = parse_COMMA();
  11393. if (result2 !== null) {
  11394. result3 = parse_route_param();
  11395. if (result3 !== null) {
  11396. result2 = [result2, result3];
  11397. } else {
  11398. result2 = null;
  11399. pos = pos1;
  11400. }
  11401. } else {
  11402. result2 = null;
  11403. pos = pos1;
  11404. }
  11405. while (result2 !== null) {
  11406. result1.push(result2);
  11407. pos1 = pos;
  11408. result2 = parse_COMMA();
  11409. if (result2 !== null) {
  11410. result3 = parse_route_param();
  11411. if (result3 !== null) {
  11412. result2 = [result2, result3];
  11413. } else {
  11414. result2 = null;
  11415. pos = pos1;
  11416. }
  11417. } else {
  11418. result2 = null;
  11419. pos = pos1;
  11420. }
  11421. }
  11422. if (result1 !== null) {
  11423. result0 = [result0, result1];
  11424. } else {
  11425. result0 = null;
  11426. pos = pos0;
  11427. }
  11428. } else {
  11429. result0 = null;
  11430. pos = pos0;
  11431. }
  11432. return result0;
  11433. }
  11434. function parse_route_param() {
  11435. var result0, result1, result2, result3;
  11436. var pos0, pos1;
  11437. pos0 = pos;
  11438. result0 = parse_name_addr();
  11439. if (result0 !== null) {
  11440. result1 = [];
  11441. pos1 = pos;
  11442. result2 = parse_SEMI();
  11443. if (result2 !== null) {
  11444. result3 = parse_generic_param();
  11445. if (result3 !== null) {
  11446. result2 = [result2, result3];
  11447. } else {
  11448. result2 = null;
  11449. pos = pos1;
  11450. }
  11451. } else {
  11452. result2 = null;
  11453. pos = pos1;
  11454. }
  11455. while (result2 !== null) {
  11456. result1.push(result2);
  11457. pos1 = pos;
  11458. result2 = parse_SEMI();
  11459. if (result2 !== null) {
  11460. result3 = parse_generic_param();
  11461. if (result3 !== null) {
  11462. result2 = [result2, result3];
  11463. } else {
  11464. result2 = null;
  11465. pos = pos1;
  11466. }
  11467. } else {
  11468. result2 = null;
  11469. pos = pos1;
  11470. }
  11471. }
  11472. if (result1 !== null) {
  11473. result0 = [result0, result1];
  11474. } else {
  11475. result0 = null;
  11476. pos = pos0;
  11477. }
  11478. } else {
  11479. result0 = null;
  11480. pos = pos0;
  11481. }
  11482. return result0;
  11483. }
  11484. function parse_Subscription_State() {
  11485. var result0, result1, result2, result3;
  11486. var pos0, pos1;
  11487. pos0 = pos;
  11488. result0 = parse_substate_value();
  11489. if (result0 !== null) {
  11490. result1 = [];
  11491. pos1 = pos;
  11492. result2 = parse_SEMI();
  11493. if (result2 !== null) {
  11494. result3 = parse_subexp_params();
  11495. if (result3 !== null) {
  11496. result2 = [result2, result3];
  11497. } else {
  11498. result2 = null;
  11499. pos = pos1;
  11500. }
  11501. } else {
  11502. result2 = null;
  11503. pos = pos1;
  11504. }
  11505. while (result2 !== null) {
  11506. result1.push(result2);
  11507. pos1 = pos;
  11508. result2 = parse_SEMI();
  11509. if (result2 !== null) {
  11510. result3 = parse_subexp_params();
  11511. if (result3 !== null) {
  11512. result2 = [result2, result3];
  11513. } else {
  11514. result2 = null;
  11515. pos = pos1;
  11516. }
  11517. } else {
  11518. result2 = null;
  11519. pos = pos1;
  11520. }
  11521. }
  11522. if (result1 !== null) {
  11523. result0 = [result0, result1];
  11524. } else {
  11525. result0 = null;
  11526. pos = pos0;
  11527. }
  11528. } else {
  11529. result0 = null;
  11530. pos = pos0;
  11531. }
  11532. return result0;
  11533. }
  11534. function parse_substate_value() {
  11535. var result0;
  11536. var pos0;
  11537. pos0 = pos;
  11538. if (input.substr(pos, 6).toLowerCase() === "active") {
  11539. result0 = input.substr(pos, 6);
  11540. pos += 6;
  11541. } else {
  11542. result0 = null;
  11543. if (reportFailures === 0) {
  11544. matchFailed("\"active\"");
  11545. }
  11546. }
  11547. if (result0 === null) {
  11548. if (input.substr(pos, 7).toLowerCase() === "pending") {
  11549. result0 = input.substr(pos, 7);
  11550. pos += 7;
  11551. } else {
  11552. result0 = null;
  11553. if (reportFailures === 0) {
  11554. matchFailed("\"pending\"");
  11555. }
  11556. }
  11557. if (result0 === null) {
  11558. if (input.substr(pos, 10).toLowerCase() === "terminated") {
  11559. result0 = input.substr(pos, 10);
  11560. pos += 10;
  11561. } else {
  11562. result0 = null;
  11563. if (reportFailures === 0) {
  11564. matchFailed("\"terminated\"");
  11565. }
  11566. }
  11567. if (result0 === null) {
  11568. result0 = parse_token();
  11569. }
  11570. }
  11571. }
  11572. if (result0 !== null) {
  11573. result0 = function (offset) {
  11574. data.state = input.substring(pos, offset);
  11575. }(pos0);
  11576. }
  11577. if (result0 === null) {
  11578. pos = pos0;
  11579. }
  11580. return result0;
  11581. }
  11582. function parse_subexp_params() {
  11583. var result0, result1, result2;
  11584. var pos0, pos1;
  11585. pos0 = pos;
  11586. pos1 = pos;
  11587. if (input.substr(pos, 6).toLowerCase() === "reason") {
  11588. result0 = input.substr(pos, 6);
  11589. pos += 6;
  11590. } else {
  11591. result0 = null;
  11592. if (reportFailures === 0) {
  11593. matchFailed("\"reason\"");
  11594. }
  11595. }
  11596. if (result0 !== null) {
  11597. result1 = parse_EQUAL();
  11598. if (result1 !== null) {
  11599. result2 = parse_event_reason_value();
  11600. if (result2 !== null) {
  11601. result0 = [result0, result1, result2];
  11602. } else {
  11603. result0 = null;
  11604. pos = pos1;
  11605. }
  11606. } else {
  11607. result0 = null;
  11608. pos = pos1;
  11609. }
  11610. } else {
  11611. result0 = null;
  11612. pos = pos1;
  11613. }
  11614. if (result0 !== null) {
  11615. result0 = function (offset, reason) {
  11616. if (typeof reason !== 'undefined') data.reason = reason;
  11617. }(pos0, result0[2]);
  11618. }
  11619. if (result0 === null) {
  11620. pos = pos0;
  11621. }
  11622. if (result0 === null) {
  11623. pos0 = pos;
  11624. pos1 = pos;
  11625. if (input.substr(pos, 7).toLowerCase() === "expires") {
  11626. result0 = input.substr(pos, 7);
  11627. pos += 7;
  11628. } else {
  11629. result0 = null;
  11630. if (reportFailures === 0) {
  11631. matchFailed("\"expires\"");
  11632. }
  11633. }
  11634. if (result0 !== null) {
  11635. result1 = parse_EQUAL();
  11636. if (result1 !== null) {
  11637. result2 = parse_delta_seconds();
  11638. if (result2 !== null) {
  11639. result0 = [result0, result1, result2];
  11640. } else {
  11641. result0 = null;
  11642. pos = pos1;
  11643. }
  11644. } else {
  11645. result0 = null;
  11646. pos = pos1;
  11647. }
  11648. } else {
  11649. result0 = null;
  11650. pos = pos1;
  11651. }
  11652. if (result0 !== null) {
  11653. result0 = function (offset, expires) {
  11654. if (typeof expires !== 'undefined') data.expires = expires;
  11655. }(pos0, result0[2]);
  11656. }
  11657. if (result0 === null) {
  11658. pos = pos0;
  11659. }
  11660. if (result0 === null) {
  11661. pos0 = pos;
  11662. pos1 = pos;
  11663. if (input.substr(pos, 11).toLowerCase() === "retry_after") {
  11664. result0 = input.substr(pos, 11);
  11665. pos += 11;
  11666. } else {
  11667. result0 = null;
  11668. if (reportFailures === 0) {
  11669. matchFailed("\"retry_after\"");
  11670. }
  11671. }
  11672. if (result0 !== null) {
  11673. result1 = parse_EQUAL();
  11674. if (result1 !== null) {
  11675. result2 = parse_delta_seconds();
  11676. if (result2 !== null) {
  11677. result0 = [result0, result1, result2];
  11678. } else {
  11679. result0 = null;
  11680. pos = pos1;
  11681. }
  11682. } else {
  11683. result0 = null;
  11684. pos = pos1;
  11685. }
  11686. } else {
  11687. result0 = null;
  11688. pos = pos1;
  11689. }
  11690. if (result0 !== null) {
  11691. result0 = function (offset, retry_after) {
  11692. if (typeof retry_after !== 'undefined') data.retry_after = retry_after;
  11693. }(pos0, result0[2]);
  11694. }
  11695. if (result0 === null) {
  11696. pos = pos0;
  11697. }
  11698. if (result0 === null) {
  11699. result0 = parse_generic_param();
  11700. }
  11701. }
  11702. }
  11703. return result0;
  11704. }
  11705. function parse_event_reason_value() {
  11706. var result0;
  11707. if (input.substr(pos, 11).toLowerCase() === "deactivated") {
  11708. result0 = input.substr(pos, 11);
  11709. pos += 11;
  11710. } else {
  11711. result0 = null;
  11712. if (reportFailures === 0) {
  11713. matchFailed("\"deactivated\"");
  11714. }
  11715. }
  11716. if (result0 === null) {
  11717. if (input.substr(pos, 9).toLowerCase() === "probation") {
  11718. result0 = input.substr(pos, 9);
  11719. pos += 9;
  11720. } else {
  11721. result0 = null;
  11722. if (reportFailures === 0) {
  11723. matchFailed("\"probation\"");
  11724. }
  11725. }
  11726. if (result0 === null) {
  11727. if (input.substr(pos, 8).toLowerCase() === "rejected") {
  11728. result0 = input.substr(pos, 8);
  11729. pos += 8;
  11730. } else {
  11731. result0 = null;
  11732. if (reportFailures === 0) {
  11733. matchFailed("\"rejected\"");
  11734. }
  11735. }
  11736. if (result0 === null) {
  11737. if (input.substr(pos, 7).toLowerCase() === "timeout") {
  11738. result0 = input.substr(pos, 7);
  11739. pos += 7;
  11740. } else {
  11741. result0 = null;
  11742. if (reportFailures === 0) {
  11743. matchFailed("\"timeout\"");
  11744. }
  11745. }
  11746. if (result0 === null) {
  11747. if (input.substr(pos, 6).toLowerCase() === "giveup") {
  11748. result0 = input.substr(pos, 6);
  11749. pos += 6;
  11750. } else {
  11751. result0 = null;
  11752. if (reportFailures === 0) {
  11753. matchFailed("\"giveup\"");
  11754. }
  11755. }
  11756. if (result0 === null) {
  11757. if (input.substr(pos, 10).toLowerCase() === "noresource") {
  11758. result0 = input.substr(pos, 10);
  11759. pos += 10;
  11760. } else {
  11761. result0 = null;
  11762. if (reportFailures === 0) {
  11763. matchFailed("\"noresource\"");
  11764. }
  11765. }
  11766. if (result0 === null) {
  11767. if (input.substr(pos, 9).toLowerCase() === "invariant") {
  11768. result0 = input.substr(pos, 9);
  11769. pos += 9;
  11770. } else {
  11771. result0 = null;
  11772. if (reportFailures === 0) {
  11773. matchFailed("\"invariant\"");
  11774. }
  11775. }
  11776. if (result0 === null) {
  11777. result0 = parse_token();
  11778. }
  11779. }
  11780. }
  11781. }
  11782. }
  11783. }
  11784. }
  11785. return result0;
  11786. }
  11787. function parse_Subject() {
  11788. var result0;
  11789. result0 = parse_TEXT_UTF8_TRIM();
  11790. result0 = result0 !== null ? result0 : "";
  11791. return result0;
  11792. }
  11793. function parse_Supported() {
  11794. var result0, result1, result2, result3;
  11795. var pos0, pos1;
  11796. pos0 = pos;
  11797. result0 = parse_token();
  11798. if (result0 !== null) {
  11799. result1 = [];
  11800. pos1 = pos;
  11801. result2 = parse_COMMA();
  11802. if (result2 !== null) {
  11803. result3 = parse_token();
  11804. if (result3 !== null) {
  11805. result2 = [result2, result3];
  11806. } else {
  11807. result2 = null;
  11808. pos = pos1;
  11809. }
  11810. } else {
  11811. result2 = null;
  11812. pos = pos1;
  11813. }
  11814. while (result2 !== null) {
  11815. result1.push(result2);
  11816. pos1 = pos;
  11817. result2 = parse_COMMA();
  11818. if (result2 !== null) {
  11819. result3 = parse_token();
  11820. if (result3 !== null) {
  11821. result2 = [result2, result3];
  11822. } else {
  11823. result2 = null;
  11824. pos = pos1;
  11825. }
  11826. } else {
  11827. result2 = null;
  11828. pos = pos1;
  11829. }
  11830. }
  11831. if (result1 !== null) {
  11832. result0 = [result0, result1];
  11833. } else {
  11834. result0 = null;
  11835. pos = pos0;
  11836. }
  11837. } else {
  11838. result0 = null;
  11839. pos = pos0;
  11840. }
  11841. result0 = result0 !== null ? result0 : "";
  11842. return result0;
  11843. }
  11844. function parse_To() {
  11845. var result0, result1, result2, result3;
  11846. var pos0, pos1, pos2;
  11847. pos0 = pos;
  11848. pos1 = pos;
  11849. result0 = parse_SIP_URI_noparams();
  11850. if (result0 === null) {
  11851. result0 = parse_name_addr();
  11852. }
  11853. if (result0 !== null) {
  11854. result1 = [];
  11855. pos2 = pos;
  11856. result2 = parse_SEMI();
  11857. if (result2 !== null) {
  11858. result3 = parse_to_param();
  11859. if (result3 !== null) {
  11860. result2 = [result2, result3];
  11861. } else {
  11862. result2 = null;
  11863. pos = pos2;
  11864. }
  11865. } else {
  11866. result2 = null;
  11867. pos = pos2;
  11868. }
  11869. while (result2 !== null) {
  11870. result1.push(result2);
  11871. pos2 = pos;
  11872. result2 = parse_SEMI();
  11873. if (result2 !== null) {
  11874. result3 = parse_to_param();
  11875. if (result3 !== null) {
  11876. result2 = [result2, result3];
  11877. } else {
  11878. result2 = null;
  11879. pos = pos2;
  11880. }
  11881. } else {
  11882. result2 = null;
  11883. pos = pos2;
  11884. }
  11885. }
  11886. if (result1 !== null) {
  11887. result0 = [result0, result1];
  11888. } else {
  11889. result0 = null;
  11890. pos = pos1;
  11891. }
  11892. } else {
  11893. result0 = null;
  11894. pos = pos1;
  11895. }
  11896. if (result0 !== null) {
  11897. result0 = function (offset) {
  11898. var tag = data.tag;
  11899. try {
  11900. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  11901. if (tag) {
  11902. data.setParam('tag', tag);
  11903. }
  11904. } catch (e) {
  11905. data = -1;
  11906. }
  11907. }(pos0);
  11908. }
  11909. if (result0 === null) {
  11910. pos = pos0;
  11911. }
  11912. return result0;
  11913. }
  11914. function parse_to_param() {
  11915. var result0;
  11916. result0 = parse_tag_param();
  11917. if (result0 === null) {
  11918. result0 = parse_generic_param();
  11919. }
  11920. return result0;
  11921. }
  11922. function parse_Via() {
  11923. var result0, result1, result2, result3;
  11924. var pos0, pos1;
  11925. pos0 = pos;
  11926. result0 = parse_via_param();
  11927. if (result0 !== null) {
  11928. result1 = [];
  11929. pos1 = pos;
  11930. result2 = parse_COMMA();
  11931. if (result2 !== null) {
  11932. result3 = parse_via_param();
  11933. if (result3 !== null) {
  11934. result2 = [result2, result3];
  11935. } else {
  11936. result2 = null;
  11937. pos = pos1;
  11938. }
  11939. } else {
  11940. result2 = null;
  11941. pos = pos1;
  11942. }
  11943. while (result2 !== null) {
  11944. result1.push(result2);
  11945. pos1 = pos;
  11946. result2 = parse_COMMA();
  11947. if (result2 !== null) {
  11948. result3 = parse_via_param();
  11949. if (result3 !== null) {
  11950. result2 = [result2, result3];
  11951. } else {
  11952. result2 = null;
  11953. pos = pos1;
  11954. }
  11955. } else {
  11956. result2 = null;
  11957. pos = pos1;
  11958. }
  11959. }
  11960. if (result1 !== null) {
  11961. result0 = [result0, result1];
  11962. } else {
  11963. result0 = null;
  11964. pos = pos0;
  11965. }
  11966. } else {
  11967. result0 = null;
  11968. pos = pos0;
  11969. }
  11970. return result0;
  11971. }
  11972. function parse_via_param() {
  11973. var result0, result1, result2, result3, result4, result5;
  11974. var pos0, pos1;
  11975. pos0 = pos;
  11976. result0 = parse_sent_protocol();
  11977. if (result0 !== null) {
  11978. result1 = parse_LWS();
  11979. if (result1 !== null) {
  11980. result2 = parse_sent_by();
  11981. if (result2 !== null) {
  11982. result3 = [];
  11983. pos1 = pos;
  11984. result4 = parse_SEMI();
  11985. if (result4 !== null) {
  11986. result5 = parse_via_params();
  11987. if (result5 !== null) {
  11988. result4 = [result4, result5];
  11989. } else {
  11990. result4 = null;
  11991. pos = pos1;
  11992. }
  11993. } else {
  11994. result4 = null;
  11995. pos = pos1;
  11996. }
  11997. while (result4 !== null) {
  11998. result3.push(result4);
  11999. pos1 = pos;
  12000. result4 = parse_SEMI();
  12001. if (result4 !== null) {
  12002. result5 = parse_via_params();
  12003. if (result5 !== null) {
  12004. result4 = [result4, result5];
  12005. } else {
  12006. result4 = null;
  12007. pos = pos1;
  12008. }
  12009. } else {
  12010. result4 = null;
  12011. pos = pos1;
  12012. }
  12013. }
  12014. if (result3 !== null) {
  12015. result0 = [result0, result1, result2, result3];
  12016. } else {
  12017. result0 = null;
  12018. pos = pos0;
  12019. }
  12020. } else {
  12021. result0 = null;
  12022. pos = pos0;
  12023. }
  12024. } else {
  12025. result0 = null;
  12026. pos = pos0;
  12027. }
  12028. } else {
  12029. result0 = null;
  12030. pos = pos0;
  12031. }
  12032. return result0;
  12033. }
  12034. function parse_via_params() {
  12035. var result0;
  12036. result0 = parse_via_ttl();
  12037. if (result0 === null) {
  12038. result0 = parse_via_maddr();
  12039. if (result0 === null) {
  12040. result0 = parse_via_received();
  12041. if (result0 === null) {
  12042. result0 = parse_via_branch();
  12043. if (result0 === null) {
  12044. result0 = parse_response_port();
  12045. if (result0 === null) {
  12046. result0 = parse_generic_param();
  12047. }
  12048. }
  12049. }
  12050. }
  12051. }
  12052. return result0;
  12053. }
  12054. function parse_via_ttl() {
  12055. var result0, result1, result2;
  12056. var pos0, pos1;
  12057. pos0 = pos;
  12058. pos1 = pos;
  12059. if (input.substr(pos, 3).toLowerCase() === "ttl") {
  12060. result0 = input.substr(pos, 3);
  12061. pos += 3;
  12062. } else {
  12063. result0 = null;
  12064. if (reportFailures === 0) {
  12065. matchFailed("\"ttl\"");
  12066. }
  12067. }
  12068. if (result0 !== null) {
  12069. result1 = parse_EQUAL();
  12070. if (result1 !== null) {
  12071. result2 = parse_ttl();
  12072. if (result2 !== null) {
  12073. result0 = [result0, result1, result2];
  12074. } else {
  12075. result0 = null;
  12076. pos = pos1;
  12077. }
  12078. } else {
  12079. result0 = null;
  12080. pos = pos1;
  12081. }
  12082. } else {
  12083. result0 = null;
  12084. pos = pos1;
  12085. }
  12086. if (result0 !== null) {
  12087. result0 = function (offset, via_ttl_value) {
  12088. data.ttl = via_ttl_value;
  12089. }(pos0, result0[2]);
  12090. }
  12091. if (result0 === null) {
  12092. pos = pos0;
  12093. }
  12094. return result0;
  12095. }
  12096. function parse_via_maddr() {
  12097. var result0, result1, result2;
  12098. var pos0, pos1;
  12099. pos0 = pos;
  12100. pos1 = pos;
  12101. if (input.substr(pos, 5).toLowerCase() === "maddr") {
  12102. result0 = input.substr(pos, 5);
  12103. pos += 5;
  12104. } else {
  12105. result0 = null;
  12106. if (reportFailures === 0) {
  12107. matchFailed("\"maddr\"");
  12108. }
  12109. }
  12110. if (result0 !== null) {
  12111. result1 = parse_EQUAL();
  12112. if (result1 !== null) {
  12113. result2 = parse_host();
  12114. if (result2 !== null) {
  12115. result0 = [result0, result1, result2];
  12116. } else {
  12117. result0 = null;
  12118. pos = pos1;
  12119. }
  12120. } else {
  12121. result0 = null;
  12122. pos = pos1;
  12123. }
  12124. } else {
  12125. result0 = null;
  12126. pos = pos1;
  12127. }
  12128. if (result0 !== null) {
  12129. result0 = function (offset, via_maddr) {
  12130. data.maddr = via_maddr;
  12131. }(pos0, result0[2]);
  12132. }
  12133. if (result0 === null) {
  12134. pos = pos0;
  12135. }
  12136. return result0;
  12137. }
  12138. function parse_via_received() {
  12139. var result0, result1, result2;
  12140. var pos0, pos1;
  12141. pos0 = pos;
  12142. pos1 = pos;
  12143. if (input.substr(pos, 8).toLowerCase() === "received") {
  12144. result0 = input.substr(pos, 8);
  12145. pos += 8;
  12146. } else {
  12147. result0 = null;
  12148. if (reportFailures === 0) {
  12149. matchFailed("\"received\"");
  12150. }
  12151. }
  12152. if (result0 !== null) {
  12153. result1 = parse_EQUAL();
  12154. if (result1 !== null) {
  12155. result2 = parse_IPv4address();
  12156. if (result2 === null) {
  12157. result2 = parse_IPv6address();
  12158. }
  12159. if (result2 !== null) {
  12160. result0 = [result0, result1, result2];
  12161. } else {
  12162. result0 = null;
  12163. pos = pos1;
  12164. }
  12165. } else {
  12166. result0 = null;
  12167. pos = pos1;
  12168. }
  12169. } else {
  12170. result0 = null;
  12171. pos = pos1;
  12172. }
  12173. if (result0 !== null) {
  12174. result0 = function (offset, via_received) {
  12175. data.received = via_received;
  12176. }(pos0, result0[2]);
  12177. }
  12178. if (result0 === null) {
  12179. pos = pos0;
  12180. }
  12181. return result0;
  12182. }
  12183. function parse_via_branch() {
  12184. var result0, result1, result2;
  12185. var pos0, pos1;
  12186. pos0 = pos;
  12187. pos1 = pos;
  12188. if (input.substr(pos, 6).toLowerCase() === "branch") {
  12189. result0 = input.substr(pos, 6);
  12190. pos += 6;
  12191. } else {
  12192. result0 = null;
  12193. if (reportFailures === 0) {
  12194. matchFailed("\"branch\"");
  12195. }
  12196. }
  12197. if (result0 !== null) {
  12198. result1 = parse_EQUAL();
  12199. if (result1 !== null) {
  12200. result2 = parse_token();
  12201. if (result2 !== null) {
  12202. result0 = [result0, result1, result2];
  12203. } else {
  12204. result0 = null;
  12205. pos = pos1;
  12206. }
  12207. } else {
  12208. result0 = null;
  12209. pos = pos1;
  12210. }
  12211. } else {
  12212. result0 = null;
  12213. pos = pos1;
  12214. }
  12215. if (result0 !== null) {
  12216. result0 = function (offset, via_branch) {
  12217. data.branch = via_branch;
  12218. }(pos0, result0[2]);
  12219. }
  12220. if (result0 === null) {
  12221. pos = pos0;
  12222. }
  12223. return result0;
  12224. }
  12225. function parse_response_port() {
  12226. var result0, result1, result2, result3;
  12227. var pos0, pos1, pos2;
  12228. pos0 = pos;
  12229. pos1 = pos;
  12230. if (input.substr(pos, 5).toLowerCase() === "rport") {
  12231. result0 = input.substr(pos, 5);
  12232. pos += 5;
  12233. } else {
  12234. result0 = null;
  12235. if (reportFailures === 0) {
  12236. matchFailed("\"rport\"");
  12237. }
  12238. }
  12239. if (result0 !== null) {
  12240. pos2 = pos;
  12241. result1 = parse_EQUAL();
  12242. if (result1 !== null) {
  12243. result2 = [];
  12244. result3 = parse_DIGIT();
  12245. while (result3 !== null) {
  12246. result2.push(result3);
  12247. result3 = parse_DIGIT();
  12248. }
  12249. if (result2 !== null) {
  12250. result1 = [result1, result2];
  12251. } else {
  12252. result1 = null;
  12253. pos = pos2;
  12254. }
  12255. } else {
  12256. result1 = null;
  12257. pos = pos2;
  12258. }
  12259. result1 = result1 !== null ? result1 : "";
  12260. if (result1 !== null) {
  12261. result0 = [result0, result1];
  12262. } else {
  12263. result0 = null;
  12264. pos = pos1;
  12265. }
  12266. } else {
  12267. result0 = null;
  12268. pos = pos1;
  12269. }
  12270. if (result0 !== null) {
  12271. result0 = function (offset) {
  12272. if (typeof response_port !== 'undefined') data.rport = response_port.join('');
  12273. }(pos0);
  12274. }
  12275. if (result0 === null) {
  12276. pos = pos0;
  12277. }
  12278. return result0;
  12279. }
  12280. function parse_sent_protocol() {
  12281. var result0, result1, result2, result3, result4;
  12282. var pos0;
  12283. pos0 = pos;
  12284. result0 = parse_protocol_name();
  12285. if (result0 !== null) {
  12286. result1 = parse_SLASH();
  12287. if (result1 !== null) {
  12288. result2 = parse_token();
  12289. if (result2 !== null) {
  12290. result3 = parse_SLASH();
  12291. if (result3 !== null) {
  12292. result4 = parse_transport();
  12293. if (result4 !== null) {
  12294. result0 = [result0, result1, result2, result3, result4];
  12295. } else {
  12296. result0 = null;
  12297. pos = pos0;
  12298. }
  12299. } else {
  12300. result0 = null;
  12301. pos = pos0;
  12302. }
  12303. } else {
  12304. result0 = null;
  12305. pos = pos0;
  12306. }
  12307. } else {
  12308. result0 = null;
  12309. pos = pos0;
  12310. }
  12311. } else {
  12312. result0 = null;
  12313. pos = pos0;
  12314. }
  12315. return result0;
  12316. }
  12317. function parse_protocol_name() {
  12318. var result0;
  12319. var pos0;
  12320. pos0 = pos;
  12321. if (input.substr(pos, 3).toLowerCase() === "sip") {
  12322. result0 = input.substr(pos, 3);
  12323. pos += 3;
  12324. } else {
  12325. result0 = null;
  12326. if (reportFailures === 0) {
  12327. matchFailed("\"SIP\"");
  12328. }
  12329. }
  12330. if (result0 === null) {
  12331. result0 = parse_token();
  12332. }
  12333. if (result0 !== null) {
  12334. result0 = function (offset, via_protocol) {
  12335. data.protocol = via_protocol;
  12336. }(pos0, result0);
  12337. }
  12338. if (result0 === null) {
  12339. pos = pos0;
  12340. }
  12341. return result0;
  12342. }
  12343. function parse_transport() {
  12344. var result0;
  12345. var pos0;
  12346. pos0 = pos;
  12347. if (input.substr(pos, 3).toLowerCase() === "udp") {
  12348. result0 = input.substr(pos, 3);
  12349. pos += 3;
  12350. } else {
  12351. result0 = null;
  12352. if (reportFailures === 0) {
  12353. matchFailed("\"UDP\"");
  12354. }
  12355. }
  12356. if (result0 === null) {
  12357. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  12358. result0 = input.substr(pos, 3);
  12359. pos += 3;
  12360. } else {
  12361. result0 = null;
  12362. if (reportFailures === 0) {
  12363. matchFailed("\"TCP\"");
  12364. }
  12365. }
  12366. if (result0 === null) {
  12367. if (input.substr(pos, 3).toLowerCase() === "tls") {
  12368. result0 = input.substr(pos, 3);
  12369. pos += 3;
  12370. } else {
  12371. result0 = null;
  12372. if (reportFailures === 0) {
  12373. matchFailed("\"TLS\"");
  12374. }
  12375. }
  12376. if (result0 === null) {
  12377. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  12378. result0 = input.substr(pos, 4);
  12379. pos += 4;
  12380. } else {
  12381. result0 = null;
  12382. if (reportFailures === 0) {
  12383. matchFailed("\"SCTP\"");
  12384. }
  12385. }
  12386. if (result0 === null) {
  12387. result0 = parse_token();
  12388. }
  12389. }
  12390. }
  12391. }
  12392. if (result0 !== null) {
  12393. result0 = function (offset, via_transport) {
  12394. data.transport = via_transport;
  12395. }(pos0, result0);
  12396. }
  12397. if (result0 === null) {
  12398. pos = pos0;
  12399. }
  12400. return result0;
  12401. }
  12402. function parse_sent_by() {
  12403. var result0, result1, result2;
  12404. var pos0, pos1;
  12405. pos0 = pos;
  12406. result0 = parse_via_host();
  12407. if (result0 !== null) {
  12408. pos1 = pos;
  12409. result1 = parse_COLON();
  12410. if (result1 !== null) {
  12411. result2 = parse_via_port();
  12412. if (result2 !== null) {
  12413. result1 = [result1, result2];
  12414. } else {
  12415. result1 = null;
  12416. pos = pos1;
  12417. }
  12418. } else {
  12419. result1 = null;
  12420. pos = pos1;
  12421. }
  12422. result1 = result1 !== null ? result1 : "";
  12423. if (result1 !== null) {
  12424. result0 = [result0, result1];
  12425. } else {
  12426. result0 = null;
  12427. pos = pos0;
  12428. }
  12429. } else {
  12430. result0 = null;
  12431. pos = pos0;
  12432. }
  12433. return result0;
  12434. }
  12435. function parse_via_host() {
  12436. var result0;
  12437. var pos0;
  12438. pos0 = pos;
  12439. result0 = parse_IPv4address();
  12440. if (result0 === null) {
  12441. result0 = parse_IPv6reference();
  12442. if (result0 === null) {
  12443. result0 = parse_hostname();
  12444. }
  12445. }
  12446. if (result0 !== null) {
  12447. result0 = function (offset) {
  12448. data.host = input.substring(pos, offset);
  12449. }(pos0);
  12450. }
  12451. if (result0 === null) {
  12452. pos = pos0;
  12453. }
  12454. return result0;
  12455. }
  12456. function parse_via_port() {
  12457. var result0, result1, result2, result3, result4;
  12458. var pos0, pos1;
  12459. pos0 = pos;
  12460. pos1 = pos;
  12461. result0 = parse_DIGIT();
  12462. result0 = result0 !== null ? result0 : "";
  12463. if (result0 !== null) {
  12464. result1 = parse_DIGIT();
  12465. result1 = result1 !== null ? result1 : "";
  12466. if (result1 !== null) {
  12467. result2 = parse_DIGIT();
  12468. result2 = result2 !== null ? result2 : "";
  12469. if (result2 !== null) {
  12470. result3 = parse_DIGIT();
  12471. result3 = result3 !== null ? result3 : "";
  12472. if (result3 !== null) {
  12473. result4 = parse_DIGIT();
  12474. result4 = result4 !== null ? result4 : "";
  12475. if (result4 !== null) {
  12476. result0 = [result0, result1, result2, result3, result4];
  12477. } else {
  12478. result0 = null;
  12479. pos = pos1;
  12480. }
  12481. } else {
  12482. result0 = null;
  12483. pos = pos1;
  12484. }
  12485. } else {
  12486. result0 = null;
  12487. pos = pos1;
  12488. }
  12489. } else {
  12490. result0 = null;
  12491. pos = pos1;
  12492. }
  12493. } else {
  12494. result0 = null;
  12495. pos = pos1;
  12496. }
  12497. if (result0 !== null) {
  12498. result0 = function (offset, via_sent_by_port) {
  12499. data.port = parseInt(via_sent_by_port.join(''));
  12500. }(pos0, result0);
  12501. }
  12502. if (result0 === null) {
  12503. pos = pos0;
  12504. }
  12505. return result0;
  12506. }
  12507. function parse_ttl() {
  12508. var result0, result1, result2;
  12509. var pos0, pos1;
  12510. pos0 = pos;
  12511. pos1 = pos;
  12512. result0 = parse_DIGIT();
  12513. if (result0 !== null) {
  12514. result1 = parse_DIGIT();
  12515. result1 = result1 !== null ? result1 : "";
  12516. if (result1 !== null) {
  12517. result2 = parse_DIGIT();
  12518. result2 = result2 !== null ? result2 : "";
  12519. if (result2 !== null) {
  12520. result0 = [result0, result1, result2];
  12521. } else {
  12522. result0 = null;
  12523. pos = pos1;
  12524. }
  12525. } else {
  12526. result0 = null;
  12527. pos = pos1;
  12528. }
  12529. } else {
  12530. result0 = null;
  12531. pos = pos1;
  12532. }
  12533. if (result0 !== null) {
  12534. result0 = function (offset, ttl) {
  12535. return parseInt(ttl.join(''));
  12536. }(pos0, result0);
  12537. }
  12538. if (result0 === null) {
  12539. pos = pos0;
  12540. }
  12541. return result0;
  12542. }
  12543. function parse_WWW_Authenticate() {
  12544. var result0;
  12545. result0 = parse_challenge();
  12546. return result0;
  12547. }
  12548. function parse_Session_Expires() {
  12549. var result0, result1, result2, result3;
  12550. var pos0, pos1;
  12551. pos0 = pos;
  12552. result0 = parse_s_e_expires();
  12553. if (result0 !== null) {
  12554. result1 = [];
  12555. pos1 = pos;
  12556. result2 = parse_SEMI();
  12557. if (result2 !== null) {
  12558. result3 = parse_s_e_params();
  12559. if (result3 !== null) {
  12560. result2 = [result2, result3];
  12561. } else {
  12562. result2 = null;
  12563. pos = pos1;
  12564. }
  12565. } else {
  12566. result2 = null;
  12567. pos = pos1;
  12568. }
  12569. while (result2 !== null) {
  12570. result1.push(result2);
  12571. pos1 = pos;
  12572. result2 = parse_SEMI();
  12573. if (result2 !== null) {
  12574. result3 = parse_s_e_params();
  12575. if (result3 !== null) {
  12576. result2 = [result2, result3];
  12577. } else {
  12578. result2 = null;
  12579. pos = pos1;
  12580. }
  12581. } else {
  12582. result2 = null;
  12583. pos = pos1;
  12584. }
  12585. }
  12586. if (result1 !== null) {
  12587. result0 = [result0, result1];
  12588. } else {
  12589. result0 = null;
  12590. pos = pos0;
  12591. }
  12592. } else {
  12593. result0 = null;
  12594. pos = pos0;
  12595. }
  12596. return result0;
  12597. }
  12598. function parse_s_e_expires() {
  12599. var result0;
  12600. var pos0;
  12601. pos0 = pos;
  12602. result0 = parse_delta_seconds();
  12603. if (result0 !== null) {
  12604. result0 = function (offset, expires) {
  12605. data.expires = expires;
  12606. }(pos0, result0);
  12607. }
  12608. if (result0 === null) {
  12609. pos = pos0;
  12610. }
  12611. return result0;
  12612. }
  12613. function parse_s_e_params() {
  12614. var result0;
  12615. result0 = parse_s_e_refresher();
  12616. if (result0 === null) {
  12617. result0 = parse_generic_param();
  12618. }
  12619. return result0;
  12620. }
  12621. function parse_s_e_refresher() {
  12622. var result0, result1, result2;
  12623. var pos0, pos1;
  12624. pos0 = pos;
  12625. pos1 = pos;
  12626. if (input.substr(pos, 9).toLowerCase() === "refresher") {
  12627. result0 = input.substr(pos, 9);
  12628. pos += 9;
  12629. } else {
  12630. result0 = null;
  12631. if (reportFailures === 0) {
  12632. matchFailed("\"refresher\"");
  12633. }
  12634. }
  12635. if (result0 !== null) {
  12636. result1 = parse_EQUAL();
  12637. if (result1 !== null) {
  12638. if (input.substr(pos, 3).toLowerCase() === "uac") {
  12639. result2 = input.substr(pos, 3);
  12640. pos += 3;
  12641. } else {
  12642. result2 = null;
  12643. if (reportFailures === 0) {
  12644. matchFailed("\"uac\"");
  12645. }
  12646. }
  12647. if (result2 === null) {
  12648. if (input.substr(pos, 3).toLowerCase() === "uas") {
  12649. result2 = input.substr(pos, 3);
  12650. pos += 3;
  12651. } else {
  12652. result2 = null;
  12653. if (reportFailures === 0) {
  12654. matchFailed("\"uas\"");
  12655. }
  12656. }
  12657. }
  12658. if (result2 !== null) {
  12659. result0 = [result0, result1, result2];
  12660. } else {
  12661. result0 = null;
  12662. pos = pos1;
  12663. }
  12664. } else {
  12665. result0 = null;
  12666. pos = pos1;
  12667. }
  12668. } else {
  12669. result0 = null;
  12670. pos = pos1;
  12671. }
  12672. if (result0 !== null) {
  12673. result0 = function (offset, s_e_refresher_value) {
  12674. data.refresher = s_e_refresher_value.toLowerCase();
  12675. }(pos0, result0[2]);
  12676. }
  12677. if (result0 === null) {
  12678. pos = pos0;
  12679. }
  12680. return result0;
  12681. }
  12682. function parse_extension_header() {
  12683. var result0, result1, result2;
  12684. var pos0;
  12685. pos0 = pos;
  12686. result0 = parse_token();
  12687. if (result0 !== null) {
  12688. result1 = parse_HCOLON();
  12689. if (result1 !== null) {
  12690. result2 = parse_header_value();
  12691. if (result2 !== null) {
  12692. result0 = [result0, result1, result2];
  12693. } else {
  12694. result0 = null;
  12695. pos = pos0;
  12696. }
  12697. } else {
  12698. result0 = null;
  12699. pos = pos0;
  12700. }
  12701. } else {
  12702. result0 = null;
  12703. pos = pos0;
  12704. }
  12705. return result0;
  12706. }
  12707. function parse_header_value() {
  12708. var result0, result1;
  12709. result0 = [];
  12710. result1 = parse_TEXT_UTF8char();
  12711. if (result1 === null) {
  12712. result1 = parse_UTF8_CONT();
  12713. if (result1 === null) {
  12714. result1 = parse_LWS();
  12715. }
  12716. }
  12717. while (result1 !== null) {
  12718. result0.push(result1);
  12719. result1 = parse_TEXT_UTF8char();
  12720. if (result1 === null) {
  12721. result1 = parse_UTF8_CONT();
  12722. if (result1 === null) {
  12723. result1 = parse_LWS();
  12724. }
  12725. }
  12726. }
  12727. return result0;
  12728. }
  12729. function parse_message_body() {
  12730. var result0, result1;
  12731. result0 = [];
  12732. result1 = parse_OCTET();
  12733. while (result1 !== null) {
  12734. result0.push(result1);
  12735. result1 = parse_OCTET();
  12736. }
  12737. return result0;
  12738. }
  12739. function parse_uuid_URI() {
  12740. var result0, result1;
  12741. var pos0;
  12742. pos0 = pos;
  12743. if (input.substr(pos, 5) === "uuid:") {
  12744. result0 = "uuid:";
  12745. pos += 5;
  12746. } else {
  12747. result0 = null;
  12748. if (reportFailures === 0) {
  12749. matchFailed("\"uuid:\"");
  12750. }
  12751. }
  12752. if (result0 !== null) {
  12753. result1 = parse_uuid();
  12754. if (result1 !== null) {
  12755. result0 = [result0, result1];
  12756. } else {
  12757. result0 = null;
  12758. pos = pos0;
  12759. }
  12760. } else {
  12761. result0 = null;
  12762. pos = pos0;
  12763. }
  12764. return result0;
  12765. }
  12766. function parse_uuid() {
  12767. var result0, result1, result2, result3, result4, result5, result6, result7, result8;
  12768. var pos0, pos1;
  12769. pos0 = pos;
  12770. pos1 = pos;
  12771. result0 = parse_hex8();
  12772. if (result0 !== null) {
  12773. if (input.charCodeAt(pos) === 45) {
  12774. result1 = "-";
  12775. pos++;
  12776. } else {
  12777. result1 = null;
  12778. if (reportFailures === 0) {
  12779. matchFailed("\"-\"");
  12780. }
  12781. }
  12782. if (result1 !== null) {
  12783. result2 = parse_hex4();
  12784. if (result2 !== null) {
  12785. if (input.charCodeAt(pos) === 45) {
  12786. result3 = "-";
  12787. pos++;
  12788. } else {
  12789. result3 = null;
  12790. if (reportFailures === 0) {
  12791. matchFailed("\"-\"");
  12792. }
  12793. }
  12794. if (result3 !== null) {
  12795. result4 = parse_hex4();
  12796. if (result4 !== null) {
  12797. if (input.charCodeAt(pos) === 45) {
  12798. result5 = "-";
  12799. pos++;
  12800. } else {
  12801. result5 = null;
  12802. if (reportFailures === 0) {
  12803. matchFailed("\"-\"");
  12804. }
  12805. }
  12806. if (result5 !== null) {
  12807. result6 = parse_hex4();
  12808. if (result6 !== null) {
  12809. if (input.charCodeAt(pos) === 45) {
  12810. result7 = "-";
  12811. pos++;
  12812. } else {
  12813. result7 = null;
  12814. if (reportFailures === 0) {
  12815. matchFailed("\"-\"");
  12816. }
  12817. }
  12818. if (result7 !== null) {
  12819. result8 = parse_hex12();
  12820. if (result8 !== null) {
  12821. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  12822. } else {
  12823. result0 = null;
  12824. pos = pos1;
  12825. }
  12826. } else {
  12827. result0 = null;
  12828. pos = pos1;
  12829. }
  12830. } else {
  12831. result0 = null;
  12832. pos = pos1;
  12833. }
  12834. } else {
  12835. result0 = null;
  12836. pos = pos1;
  12837. }
  12838. } else {
  12839. result0 = null;
  12840. pos = pos1;
  12841. }
  12842. } else {
  12843. result0 = null;
  12844. pos = pos1;
  12845. }
  12846. } else {
  12847. result0 = null;
  12848. pos = pos1;
  12849. }
  12850. } else {
  12851. result0 = null;
  12852. pos = pos1;
  12853. }
  12854. } else {
  12855. result0 = null;
  12856. pos = pos1;
  12857. }
  12858. if (result0 !== null) {
  12859. result0 = function (offset, uuid) {
  12860. data = input.substring(pos + 5, offset);
  12861. }(pos0, result0[0]);
  12862. }
  12863. if (result0 === null) {
  12864. pos = pos0;
  12865. }
  12866. return result0;
  12867. }
  12868. function parse_hex4() {
  12869. var result0, result1, result2, result3;
  12870. var pos0;
  12871. pos0 = pos;
  12872. result0 = parse_HEXDIG();
  12873. if (result0 !== null) {
  12874. result1 = parse_HEXDIG();
  12875. if (result1 !== null) {
  12876. result2 = parse_HEXDIG();
  12877. if (result2 !== null) {
  12878. result3 = parse_HEXDIG();
  12879. if (result3 !== null) {
  12880. result0 = [result0, result1, result2, result3];
  12881. } else {
  12882. result0 = null;
  12883. pos = pos0;
  12884. }
  12885. } else {
  12886. result0 = null;
  12887. pos = pos0;
  12888. }
  12889. } else {
  12890. result0 = null;
  12891. pos = pos0;
  12892. }
  12893. } else {
  12894. result0 = null;
  12895. pos = pos0;
  12896. }
  12897. return result0;
  12898. }
  12899. function parse_hex8() {
  12900. var result0, result1;
  12901. var pos0;
  12902. pos0 = pos;
  12903. result0 = parse_hex4();
  12904. if (result0 !== null) {
  12905. result1 = parse_hex4();
  12906. if (result1 !== null) {
  12907. result0 = [result0, result1];
  12908. } else {
  12909. result0 = null;
  12910. pos = pos0;
  12911. }
  12912. } else {
  12913. result0 = null;
  12914. pos = pos0;
  12915. }
  12916. return result0;
  12917. }
  12918. function parse_hex12() {
  12919. var result0, result1, result2;
  12920. var pos0;
  12921. pos0 = pos;
  12922. result0 = parse_hex4();
  12923. if (result0 !== null) {
  12924. result1 = parse_hex4();
  12925. if (result1 !== null) {
  12926. result2 = parse_hex4();
  12927. if (result2 !== null) {
  12928. result0 = [result0, result1, result2];
  12929. } else {
  12930. result0 = null;
  12931. pos = pos0;
  12932. }
  12933. } else {
  12934. result0 = null;
  12935. pos = pos0;
  12936. }
  12937. } else {
  12938. result0 = null;
  12939. pos = pos0;
  12940. }
  12941. return result0;
  12942. }
  12943. function parse_Refer_To() {
  12944. var result0, result1, result2, result3;
  12945. var pos0, pos1, pos2;
  12946. pos0 = pos;
  12947. pos1 = pos;
  12948. result0 = parse_SIP_URI_noparams();
  12949. if (result0 === null) {
  12950. result0 = parse_name_addr();
  12951. }
  12952. if (result0 !== null) {
  12953. result1 = [];
  12954. pos2 = pos;
  12955. result2 = parse_SEMI();
  12956. if (result2 !== null) {
  12957. result3 = parse_generic_param();
  12958. if (result3 !== null) {
  12959. result2 = [result2, result3];
  12960. } else {
  12961. result2 = null;
  12962. pos = pos2;
  12963. }
  12964. } else {
  12965. result2 = null;
  12966. pos = pos2;
  12967. }
  12968. while (result2 !== null) {
  12969. result1.push(result2);
  12970. pos2 = pos;
  12971. result2 = parse_SEMI();
  12972. if (result2 !== null) {
  12973. result3 = parse_generic_param();
  12974. if (result3 !== null) {
  12975. result2 = [result2, result3];
  12976. } else {
  12977. result2 = null;
  12978. pos = pos2;
  12979. }
  12980. } else {
  12981. result2 = null;
  12982. pos = pos2;
  12983. }
  12984. }
  12985. if (result1 !== null) {
  12986. result0 = [result0, result1];
  12987. } else {
  12988. result0 = null;
  12989. pos = pos1;
  12990. }
  12991. } else {
  12992. result0 = null;
  12993. pos = pos1;
  12994. }
  12995. if (result0 !== null) {
  12996. result0 = function (offset) {
  12997. try {
  12998. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  12999. } catch (e) {
  13000. data = -1;
  13001. }
  13002. }(pos0);
  13003. }
  13004. if (result0 === null) {
  13005. pos = pos0;
  13006. }
  13007. return result0;
  13008. }
  13009. function parse_Replaces() {
  13010. var result0, result1, result2, result3;
  13011. var pos0, pos1;
  13012. pos0 = pos;
  13013. result0 = parse_call_id();
  13014. if (result0 !== null) {
  13015. result1 = [];
  13016. pos1 = pos;
  13017. result2 = parse_SEMI();
  13018. if (result2 !== null) {
  13019. result3 = parse_replaces_param();
  13020. if (result3 !== null) {
  13021. result2 = [result2, result3];
  13022. } else {
  13023. result2 = null;
  13024. pos = pos1;
  13025. }
  13026. } else {
  13027. result2 = null;
  13028. pos = pos1;
  13029. }
  13030. while (result2 !== null) {
  13031. result1.push(result2);
  13032. pos1 = pos;
  13033. result2 = parse_SEMI();
  13034. if (result2 !== null) {
  13035. result3 = parse_replaces_param();
  13036. if (result3 !== null) {
  13037. result2 = [result2, result3];
  13038. } else {
  13039. result2 = null;
  13040. pos = pos1;
  13041. }
  13042. } else {
  13043. result2 = null;
  13044. pos = pos1;
  13045. }
  13046. }
  13047. if (result1 !== null) {
  13048. result0 = [result0, result1];
  13049. } else {
  13050. result0 = null;
  13051. pos = pos0;
  13052. }
  13053. } else {
  13054. result0 = null;
  13055. pos = pos0;
  13056. }
  13057. return result0;
  13058. }
  13059. function parse_call_id() {
  13060. var result0, result1, result2;
  13061. var pos0, pos1, pos2;
  13062. pos0 = pos;
  13063. pos1 = pos;
  13064. result0 = parse_word();
  13065. if (result0 !== null) {
  13066. pos2 = pos;
  13067. if (input.charCodeAt(pos) === 64) {
  13068. result1 = "@";
  13069. pos++;
  13070. } else {
  13071. result1 = null;
  13072. if (reportFailures === 0) {
  13073. matchFailed("\"@\"");
  13074. }
  13075. }
  13076. if (result1 !== null) {
  13077. result2 = parse_word();
  13078. if (result2 !== null) {
  13079. result1 = [result1, result2];
  13080. } else {
  13081. result1 = null;
  13082. pos = pos2;
  13083. }
  13084. } else {
  13085. result1 = null;
  13086. pos = pos2;
  13087. }
  13088. result1 = result1 !== null ? result1 : "";
  13089. if (result1 !== null) {
  13090. result0 = [result0, result1];
  13091. } else {
  13092. result0 = null;
  13093. pos = pos1;
  13094. }
  13095. } else {
  13096. result0 = null;
  13097. pos = pos1;
  13098. }
  13099. if (result0 !== null) {
  13100. result0 = function (offset) {
  13101. data.call_id = input.substring(pos, offset);
  13102. }(pos0);
  13103. }
  13104. if (result0 === null) {
  13105. pos = pos0;
  13106. }
  13107. return result0;
  13108. }
  13109. function parse_replaces_param() {
  13110. var result0;
  13111. result0 = parse_to_tag();
  13112. if (result0 === null) {
  13113. result0 = parse_from_tag();
  13114. if (result0 === null) {
  13115. result0 = parse_early_flag();
  13116. if (result0 === null) {
  13117. result0 = parse_generic_param();
  13118. }
  13119. }
  13120. }
  13121. return result0;
  13122. }
  13123. function parse_to_tag() {
  13124. var result0, result1, result2;
  13125. var pos0, pos1;
  13126. pos0 = pos;
  13127. pos1 = pos;
  13128. if (input.substr(pos, 6) === "to-tag") {
  13129. result0 = "to-tag";
  13130. pos += 6;
  13131. } else {
  13132. result0 = null;
  13133. if (reportFailures === 0) {
  13134. matchFailed("\"to-tag\"");
  13135. }
  13136. }
  13137. if (result0 !== null) {
  13138. result1 = parse_EQUAL();
  13139. if (result1 !== null) {
  13140. result2 = parse_token();
  13141. if (result2 !== null) {
  13142. result0 = [result0, result1, result2];
  13143. } else {
  13144. result0 = null;
  13145. pos = pos1;
  13146. }
  13147. } else {
  13148. result0 = null;
  13149. pos = pos1;
  13150. }
  13151. } else {
  13152. result0 = null;
  13153. pos = pos1;
  13154. }
  13155. if (result0 !== null) {
  13156. result0 = function (offset, to_tag) {
  13157. data.to_tag = to_tag;
  13158. }(pos0, result0[2]);
  13159. }
  13160. if (result0 === null) {
  13161. pos = pos0;
  13162. }
  13163. return result0;
  13164. }
  13165. function parse_from_tag() {
  13166. var result0, result1, result2;
  13167. var pos0, pos1;
  13168. pos0 = pos;
  13169. pos1 = pos;
  13170. if (input.substr(pos, 8) === "from-tag") {
  13171. result0 = "from-tag";
  13172. pos += 8;
  13173. } else {
  13174. result0 = null;
  13175. if (reportFailures === 0) {
  13176. matchFailed("\"from-tag\"");
  13177. }
  13178. }
  13179. if (result0 !== null) {
  13180. result1 = parse_EQUAL();
  13181. if (result1 !== null) {
  13182. result2 = parse_token();
  13183. if (result2 !== null) {
  13184. result0 = [result0, result1, result2];
  13185. } else {
  13186. result0 = null;
  13187. pos = pos1;
  13188. }
  13189. } else {
  13190. result0 = null;
  13191. pos = pos1;
  13192. }
  13193. } else {
  13194. result0 = null;
  13195. pos = pos1;
  13196. }
  13197. if (result0 !== null) {
  13198. result0 = function (offset, from_tag) {
  13199. data.from_tag = from_tag;
  13200. }(pos0, result0[2]);
  13201. }
  13202. if (result0 === null) {
  13203. pos = pos0;
  13204. }
  13205. return result0;
  13206. }
  13207. function parse_early_flag() {
  13208. var result0;
  13209. var pos0;
  13210. pos0 = pos;
  13211. if (input.substr(pos, 10) === "early-only") {
  13212. result0 = "early-only";
  13213. pos += 10;
  13214. } else {
  13215. result0 = null;
  13216. if (reportFailures === 0) {
  13217. matchFailed("\"early-only\"");
  13218. }
  13219. }
  13220. if (result0 !== null) {
  13221. result0 = function (offset) {
  13222. data.early_only = true;
  13223. }(pos0);
  13224. }
  13225. if (result0 === null) {
  13226. pos = pos0;
  13227. }
  13228. return result0;
  13229. }
  13230. function cleanupExpected(expected) {
  13231. expected.sort();
  13232. var lastExpected = null;
  13233. var cleanExpected = [];
  13234. for (var i = 0; i < expected.length; i++) {
  13235. if (expected[i] !== lastExpected) {
  13236. cleanExpected.push(expected[i]);
  13237. lastExpected = expected[i];
  13238. }
  13239. }
  13240. return cleanExpected;
  13241. }
  13242. function computeErrorPosition() {
  13243. /*
  13244. * The first idea was to use |String.split| to break the input up to the
  13245. * error position along newlines and derive the line and column from
  13246. * there. However IE's |split| implementation is so broken that it was
  13247. * enough to prevent it.
  13248. */
  13249. var line = 1;
  13250. var column = 1;
  13251. var seenCR = false;
  13252. for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
  13253. var ch = input.charAt(i);
  13254. if (ch === "\n") {
  13255. if (!seenCR) {
  13256. line++;
  13257. }
  13258. column = 1;
  13259. seenCR = false;
  13260. } else if (ch === "\r" || ch === '\u2028' || ch === '\u2029') {
  13261. line++;
  13262. column = 1;
  13263. seenCR = true;
  13264. } else {
  13265. column++;
  13266. seenCR = false;
  13267. }
  13268. }
  13269. return { line: line, column: column };
  13270. }
  13271. var URI = require('./URI');
  13272. var NameAddrHeader = require('./NameAddrHeader');
  13273. var data = {};
  13274. var result = parseFunctions[startRule]();
  13275. /*
  13276. * The parser is now in one of the following three states:
  13277. *
  13278. * 1. The parser successfully parsed the whole input.
  13279. *
  13280. * - |result !== null|
  13281. * - |pos === input.length|
  13282. * - |rightmostFailuresExpected| may or may not contain something
  13283. *
  13284. * 2. The parser successfully parsed only a part of the input.
  13285. *
  13286. * - |result !== null|
  13287. * - |pos < input.length|
  13288. * - |rightmostFailuresExpected| may or may not contain something
  13289. *
  13290. * 3. The parser did not successfully parse any part of the input.
  13291. *
  13292. * - |result === null|
  13293. * - |pos === 0|
  13294. * - |rightmostFailuresExpected| contains at least one failure
  13295. *
  13296. * All code following this comment (including called functions) must
  13297. * handle these states.
  13298. */
  13299. if (result === null || pos !== input.length) {
  13300. var offset = Math.max(pos, rightmostFailuresPos);
  13301. var found = offset < input.length ? input.charAt(offset) : null;
  13302. var errorPosition = computeErrorPosition();
  13303. new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
  13304. return -1;
  13305. }
  13306. return data;
  13307. },
  13308. /* Returns the parser source code. */
  13309. toSource: function toSource() {
  13310. return this._source;
  13311. }
  13312. };
  13313. /* Thrown when a parser encounters a syntax error. */
  13314. result.SyntaxError = function (expected, found, offset, line, column) {
  13315. function buildMessage(expected, found) {
  13316. var expectedHumanized, foundHumanized;
  13317. switch (expected.length) {
  13318. case 0:
  13319. expectedHumanized = "end of input";
  13320. break;
  13321. case 1:
  13322. expectedHumanized = expected[0];
  13323. break;
  13324. default:
  13325. expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
  13326. }
  13327. foundHumanized = found ? quote(found) : "end of input";
  13328. return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
  13329. }
  13330. this.name = "SyntaxError";
  13331. this.expected = expected;
  13332. this.found = found;
  13333. this.message = buildMessage(expected, found);
  13334. this.offset = offset;
  13335. this.line = line;
  13336. this.column = column;
  13337. };
  13338. result.SyntaxError.prototype = Error.prototype;
  13339. return result;
  13340. }();
  13341. },{"./NameAddrHeader":10,"./URI":25}],8:[function(require,module,exports){
  13342. 'use strict';
  13343. var adapter = require('webrtc-adapter');
  13344. var pkg = require('../package.json');
  13345. var C = require('./Constants');
  13346. var Exceptions = require('./Exceptions');
  13347. var Utils = require('./Utils');
  13348. var UA = require('./UA');
  13349. var URI = require('./URI');
  13350. var NameAddrHeader = require('./NameAddrHeader');
  13351. var Grammar = require('./Grammar');
  13352. var WebSocketInterface = require('./WebSocketInterface');
  13353. var debug = require('debug')('JsSIP');
  13354. debug('version %s', pkg.version);
  13355. /**
  13356. * Expose the JsSIP module.
  13357. */
  13358. module.exports = {
  13359. C: C,
  13360. Exceptions: Exceptions,
  13361. Utils: Utils,
  13362. UA: UA,
  13363. URI: URI,
  13364. NameAddrHeader: NameAddrHeader,
  13365. WebSocketInterface: WebSocketInterface,
  13366. Grammar: Grammar,
  13367. // Expose the debug module.
  13368. debug: require('debug'),
  13369. // Expose the adapter module.
  13370. adapter: adapter,
  13371. get name() {
  13372. return pkg.title;
  13373. },
  13374. get version() {
  13375. return pkg.version;
  13376. }
  13377. };
  13378. },{"../package.json":51,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":24,"./URI":25,"./Utils":26,"./WebSocketInterface":27,"debug":29,"webrtc-adapter":40}],9:[function(require,module,exports){
  13379. 'use strict';
  13380. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  13381. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13382. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13383. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13384. var EventEmitter = require('events').EventEmitter;
  13385. var JsSIP_C = require('./Constants');
  13386. var SIPMessage = require('./SIPMessage');
  13387. var Utils = require('./Utils');
  13388. var RequestSender = require('./RequestSender');
  13389. var Exceptions = require('./Exceptions');
  13390. var debug = require('debug')('JsSIP:Message');
  13391. module.exports = function (_EventEmitter) {
  13392. _inherits(Message, _EventEmitter);
  13393. function Message(ua) {
  13394. _classCallCheck(this, Message);
  13395. var _this = _possibleConstructorReturn(this, (Message.__proto__ || Object.getPrototypeOf(Message)).call(this));
  13396. _this._ua = ua;
  13397. _this._request = null;
  13398. _this._closed = false;
  13399. _this._direction = null;
  13400. _this._local_identity = null;
  13401. _this._remote_identity = null;
  13402. // Whether an incoming message has been replied.
  13403. _this._is_replied = false;
  13404. // Custom message empty object for high level use.
  13405. _this._data = {};
  13406. return _this;
  13407. }
  13408. _createClass(Message, [{
  13409. key: 'send',
  13410. value: function send(target, body) {
  13411. var _this2 = this;
  13412. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  13413. var originalTarget = target;
  13414. if (target === undefined || body === undefined) {
  13415. throw new TypeError('Not enough arguments');
  13416. }
  13417. // Check target validity.
  13418. target = this._ua.normalizeTarget(target);
  13419. if (!target) {
  13420. throw new TypeError('Invalid target: ' + originalTarget);
  13421. }
  13422. // Get call options.
  13423. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13424. var eventHandlers = options.eventHandlers || {};
  13425. var contentType = options.contentType || 'text/plain';
  13426. // Set event handlers.
  13427. for (var event in eventHandlers) {
  13428. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  13429. this.on(event, eventHandlers[event]);
  13430. }
  13431. }
  13432. extraHeaders.push('Content-Type: ' + contentType);
  13433. this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, null, extraHeaders);
  13434. if (body) {
  13435. this._request.body = body;
  13436. }
  13437. var request_sender = new RequestSender(this._ua, this._request, {
  13438. onRequestTimeout: function onRequestTimeout() {
  13439. _this2._onRequestTimeout();
  13440. },
  13441. onTransportError: function onTransportError() {
  13442. _this2._onTransportError();
  13443. },
  13444. onReceiveResponse: function onReceiveResponse(response) {
  13445. _this2._receiveResponse(response);
  13446. }
  13447. });
  13448. this._newMessage('local', this._request);
  13449. request_sender.send();
  13450. }
  13451. }, {
  13452. key: 'init_incoming',
  13453. value: function init_incoming(request) {
  13454. this._request = request;
  13455. this._newMessage('remote', request);
  13456. // Reply with a 200 OK if the user didn't reply.
  13457. if (!this._is_replied) {
  13458. this._is_replied = true;
  13459. request.reply(200);
  13460. }
  13461. this._close();
  13462. }
  13463. /**
  13464. * Accept the incoming Message
  13465. * Only valid for incoming Messages
  13466. */
  13467. }, {
  13468. key: 'accept',
  13469. value: function accept() {
  13470. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13471. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13472. var body = options.body;
  13473. if (this._direction !== 'incoming') {
  13474. throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message');
  13475. }
  13476. if (this._is_replied) {
  13477. throw new Error('incoming Message already replied');
  13478. }
  13479. this._is_replied = true;
  13480. this._request.reply(200, null, extraHeaders, body);
  13481. }
  13482. /**
  13483. * Reject the incoming Message
  13484. * Only valid for incoming Messages
  13485. */
  13486. }, {
  13487. key: 'reject',
  13488. value: function reject() {
  13489. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13490. var status_code = options.status_code || 480;
  13491. var reason_phrase = options.reason_phrase;
  13492. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13493. var body = options.body;
  13494. if (this._direction !== 'incoming') {
  13495. throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message');
  13496. }
  13497. if (this._is_replied) {
  13498. throw new Error('incoming Message already replied');
  13499. }
  13500. if (status_code < 300 || status_code >= 700) {
  13501. throw new TypeError('Invalid status_code: ' + status_code);
  13502. }
  13503. this._is_replied = true;
  13504. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  13505. }
  13506. }, {
  13507. key: '_receiveResponse',
  13508. value: function _receiveResponse(response) {
  13509. if (this._closed) {
  13510. return;
  13511. }
  13512. switch (true) {
  13513. case /^1[0-9]{2}$/.test(response.status_code):
  13514. // Ignore provisional responses.
  13515. break;
  13516. case /^2[0-9]{2}$/.test(response.status_code):
  13517. this._succeeded('remote', response);
  13518. break;
  13519. default:
  13520. {
  13521. var cause = Utils.sipErrorCause(response.status_code);
  13522. this._failed('remote', response, cause);
  13523. break;
  13524. }
  13525. }
  13526. }
  13527. }, {
  13528. key: '_onRequestTimeout',
  13529. value: function _onRequestTimeout() {
  13530. if (this._closed) {
  13531. return;
  13532. }
  13533. this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT);
  13534. }
  13535. }, {
  13536. key: '_onTransportError',
  13537. value: function _onTransportError() {
  13538. if (this._closed) {
  13539. return;
  13540. }
  13541. this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  13542. }
  13543. }, {
  13544. key: '_close',
  13545. value: function _close() {
  13546. this._closed = true;
  13547. this._ua.destroyMessage(this);
  13548. }
  13549. /**
  13550. * Internal Callbacks
  13551. */
  13552. }, {
  13553. key: '_newMessage',
  13554. value: function _newMessage(originator, request) {
  13555. if (originator === 'remote') {
  13556. this._direction = 'incoming';
  13557. this._local_identity = request.to;
  13558. this._remote_identity = request.from;
  13559. } else if (originator === 'local') {
  13560. this._direction = 'outgoing';
  13561. this._local_identity = request.from;
  13562. this._remote_identity = request.to;
  13563. }
  13564. this._ua.newMessage(this, {
  13565. originator: originator,
  13566. message: this,
  13567. request: request
  13568. });
  13569. }
  13570. }, {
  13571. key: '_failed',
  13572. value: function _failed(originator, response, cause) {
  13573. debug('MESSAGE failed');
  13574. this._close();
  13575. debug('emit "failed"');
  13576. this.emit('failed', {
  13577. originator: originator,
  13578. response: response || null,
  13579. cause: cause
  13580. });
  13581. }
  13582. }, {
  13583. key: '_succeeded',
  13584. value: function _succeeded(originator, response) {
  13585. debug('MESSAGE succeeded');
  13586. this._close();
  13587. debug('emit "succeeded"');
  13588. this.emit('succeeded', {
  13589. originator: originator,
  13590. response: response
  13591. });
  13592. }
  13593. }, {
  13594. key: 'direction',
  13595. get: function get() {
  13596. return this._direction;
  13597. }
  13598. }, {
  13599. key: 'local_identity',
  13600. get: function get() {
  13601. return this._local_identity;
  13602. }
  13603. }, {
  13604. key: 'remote_identity',
  13605. get: function get() {
  13606. return this._remote_identity;
  13607. }
  13608. }]);
  13609. return Message;
  13610. }(EventEmitter);
  13611. },{"./Constants":2,"./Exceptions":6,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":29,"events":31}],10:[function(require,module,exports){
  13612. 'use strict';
  13613. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  13614. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13615. var URI = require('./URI');
  13616. var Grammar = require('./Grammar');
  13617. module.exports = function () {
  13618. _createClass(NameAddrHeader, null, [{
  13619. key: 'parse',
  13620. /**
  13621. * Parse the given string and returns a NameAddrHeader instance or undefined if
  13622. * it is an invalid NameAddrHeader.
  13623. */
  13624. value: function parse(name_addr_header) {
  13625. name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header');
  13626. if (name_addr_header !== -1) {
  13627. return name_addr_header;
  13628. } else {
  13629. return undefined;
  13630. }
  13631. }
  13632. }]);
  13633. function NameAddrHeader(uri, display_name, parameters) {
  13634. _classCallCheck(this, NameAddrHeader);
  13635. // Checks.
  13636. if (!uri || !(uri instanceof URI)) {
  13637. throw new TypeError('missing or invalid "uri" parameter');
  13638. }
  13639. // Initialize parameters.
  13640. this._uri = uri;
  13641. this._parameters = {};
  13642. this._display_name = display_name;
  13643. for (var param in parameters) {
  13644. if (Object.prototype.hasOwnProperty.call(parameters, param)) {
  13645. this.setParam(param, parameters[param]);
  13646. }
  13647. }
  13648. }
  13649. _createClass(NameAddrHeader, [{
  13650. key: 'setParam',
  13651. value: function setParam(key, value) {
  13652. if (key) {
  13653. this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
  13654. }
  13655. }
  13656. }, {
  13657. key: 'getParam',
  13658. value: function getParam(key) {
  13659. if (key) {
  13660. return this._parameters[key.toLowerCase()];
  13661. }
  13662. }
  13663. }, {
  13664. key: 'hasParam',
  13665. value: function hasParam(key) {
  13666. if (key) {
  13667. return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
  13668. }
  13669. }
  13670. }, {
  13671. key: 'deleteParam',
  13672. value: function deleteParam(parameter) {
  13673. parameter = parameter.toLowerCase();
  13674. if (this._parameters.hasOwnProperty(parameter)) {
  13675. var value = this._parameters[parameter];
  13676. delete this._parameters[parameter];
  13677. return value;
  13678. }
  13679. }
  13680. }, {
  13681. key: 'clearParams',
  13682. value: function clearParams() {
  13683. this._parameters = {};
  13684. }
  13685. }, {
  13686. key: 'clone',
  13687. value: function clone() {
  13688. return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters)));
  13689. }
  13690. }, {
  13691. key: 'toString',
  13692. value: function toString() {
  13693. var body = this._display_name || this._display_name === 0 ? '"' + this._display_name + '" ' : '';
  13694. body += '<' + this._uri.toString() + '>';
  13695. for (var parameter in this._parameters) {
  13696. if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
  13697. body += ';' + parameter;
  13698. if (this._parameters[parameter] !== null) {
  13699. body += '=' + this._parameters[parameter];
  13700. }
  13701. }
  13702. }
  13703. return body;
  13704. }
  13705. }, {
  13706. key: 'uri',
  13707. get: function get() {
  13708. return this._uri;
  13709. }
  13710. }, {
  13711. key: 'display_name',
  13712. get: function get() {
  13713. return this._display_name;
  13714. },
  13715. set: function set(value) {
  13716. this._display_name = value === 0 ? '0' : value;
  13717. }
  13718. }]);
  13719. return NameAddrHeader;
  13720. }();
  13721. },{"./Grammar":7,"./URI":25}],11:[function(require,module,exports){
  13722. 'use strict';
  13723. var Grammar = require('./Grammar');
  13724. var SIPMessage = require('./SIPMessage');
  13725. var debugerror = require('debug')('JsSIP:ERROR:Parser');
  13726. debugerror.log = console.warn.bind(console);
  13727. /**
  13728. * Parse SIP Message
  13729. */
  13730. exports.parseMessage = function (data, ua) {
  13731. var message = void 0;
  13732. var bodyStart = void 0;
  13733. var headerEnd = data.indexOf('\r\n');
  13734. if (headerEnd === -1) {
  13735. debugerror('parseMessage() | no CRLF found, not a SIP message');
  13736. return;
  13737. }
  13738. // Parse first line. Check if it is a Request or a Reply.
  13739. var firstLine = data.substring(0, headerEnd);
  13740. var parsed = Grammar.parse(firstLine, 'Request_Response');
  13741. if (parsed === -1) {
  13742. debugerror('parseMessage() | error parsing first line of SIP message: "' + firstLine + '"');
  13743. return;
  13744. } else if (!parsed.status_code) {
  13745. message = new SIPMessage.IncomingRequest(ua);
  13746. message.method = parsed.method;
  13747. message.ruri = parsed.uri;
  13748. } else {
  13749. message = new SIPMessage.IncomingResponse();
  13750. message.status_code = parsed.status_code;
  13751. message.reason_phrase = parsed.reason_phrase;
  13752. }
  13753. message.data = data;
  13754. var headerStart = headerEnd + 2;
  13755. /* Loop over every line in data. Detect the end of each header and parse
  13756. * it or simply add to the headers collection.
  13757. */
  13758. while (true) {
  13759. headerEnd = getHeader(data, headerStart);
  13760. // The SIP message has normally finished.
  13761. if (headerEnd === -2) {
  13762. bodyStart = headerStart + 2;
  13763. break;
  13764. }
  13765. // Data.indexOf returned -1 due to a malformed message.
  13766. else if (headerEnd === -1) {
  13767. debugerror('parseMessage() | malformed message');
  13768. return;
  13769. }
  13770. parsed = parseHeader(message, data, headerStart, headerEnd);
  13771. if (parsed !== true) {
  13772. debugerror('parseMessage() |', parsed.error);
  13773. return;
  13774. }
  13775. headerStart = headerEnd + 2;
  13776. }
  13777. /* RFC3261 18.3.
  13778. * If there are additional bytes in the transport packet
  13779. * beyond the end of the body, they MUST be discarded.
  13780. */
  13781. if (message.hasHeader('content-length')) {
  13782. var contentLength = message.getHeader('content-length');
  13783. message.body = data.substr(bodyStart, contentLength);
  13784. } else {
  13785. message.body = data.substring(bodyStart);
  13786. }
  13787. return message;
  13788. };
  13789. /**
  13790. * Extract and parse every header of a SIP message.
  13791. */
  13792. function getHeader(data, headerStart) {
  13793. // 'start' position of the header.
  13794. var start = headerStart;
  13795. // 'end' position of the header.
  13796. var end = 0;
  13797. // 'partial end' position of the header.
  13798. var partialEnd = 0;
  13799. // End of message.
  13800. if (data.substring(start, start + 2).match(/(^\r\n)/)) {
  13801. return -2;
  13802. }
  13803. while (end === 0) {
  13804. // Partial End of Header.
  13805. partialEnd = data.indexOf('\r\n', start);
  13806. // 'indexOf' returns -1 if the value to be found never occurs.
  13807. if (partialEnd === -1) {
  13808. return partialEnd;
  13809. }
  13810. if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) {
  13811. // Not the end of the message. Continue from the next position.
  13812. start = partialEnd + 2;
  13813. } else {
  13814. end = partialEnd;
  13815. }
  13816. }
  13817. return end;
  13818. }
  13819. function parseHeader(message, data, headerStart, headerEnd) {
  13820. var parsed = void 0;
  13821. var hcolonIndex = data.indexOf(':', headerStart);
  13822. var headerName = data.substring(headerStart, hcolonIndex).trim();
  13823. var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim();
  13824. // If header-field is well-known, parse it.
  13825. switch (headerName.toLowerCase()) {
  13826. case 'via':
  13827. case 'v':
  13828. message.addHeader('via', headerValue);
  13829. if (message.getHeaders('via').length === 1) {
  13830. parsed = message.parseHeader('Via');
  13831. if (parsed) {
  13832. message.via = parsed;
  13833. message.via_branch = parsed.branch;
  13834. }
  13835. } else {
  13836. parsed = 0;
  13837. }
  13838. break;
  13839. case 'from':
  13840. case 'f':
  13841. message.setHeader('from', headerValue);
  13842. parsed = message.parseHeader('from');
  13843. if (parsed) {
  13844. message.from = parsed;
  13845. message.from_tag = parsed.getParam('tag');
  13846. }
  13847. break;
  13848. case 'to':
  13849. case 't':
  13850. message.setHeader('to', headerValue);
  13851. parsed = message.parseHeader('to');
  13852. if (parsed) {
  13853. message.to = parsed;
  13854. message.to_tag = parsed.getParam('tag');
  13855. }
  13856. break;
  13857. case 'record-route':
  13858. parsed = Grammar.parse(headerValue, 'Record_Route');
  13859. if (parsed === -1) {
  13860. parsed = undefined;
  13861. } else {
  13862. var _iteratorNormalCompletion = true;
  13863. var _didIteratorError = false;
  13864. var _iteratorError = undefined;
  13865. try {
  13866. for (var _iterator = parsed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  13867. var header = _step.value;
  13868. message.addHeader('record-route', headerValue.substring(header.possition, header.offset));
  13869. message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed;
  13870. }
  13871. } catch (err) {
  13872. _didIteratorError = true;
  13873. _iteratorError = err;
  13874. } finally {
  13875. try {
  13876. if (!_iteratorNormalCompletion && _iterator.return) {
  13877. _iterator.return();
  13878. }
  13879. } finally {
  13880. if (_didIteratorError) {
  13881. throw _iteratorError;
  13882. }
  13883. }
  13884. }
  13885. }
  13886. break;
  13887. case 'call-id':
  13888. case 'i':
  13889. message.setHeader('call-id', headerValue);
  13890. parsed = message.parseHeader('call-id');
  13891. if (parsed) {
  13892. message.call_id = headerValue;
  13893. }
  13894. break;
  13895. case 'contact':
  13896. case 'm':
  13897. parsed = Grammar.parse(headerValue, 'Contact');
  13898. if (parsed === -1) {
  13899. parsed = undefined;
  13900. } else {
  13901. var _iteratorNormalCompletion2 = true;
  13902. var _didIteratorError2 = false;
  13903. var _iteratorError2 = undefined;
  13904. try {
  13905. for (var _iterator2 = parsed[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  13906. var _header = _step2.value;
  13907. message.addHeader('contact', headerValue.substring(_header.possition, _header.offset));
  13908. message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed;
  13909. }
  13910. } catch (err) {
  13911. _didIteratorError2 = true;
  13912. _iteratorError2 = err;
  13913. } finally {
  13914. try {
  13915. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  13916. _iterator2.return();
  13917. }
  13918. } finally {
  13919. if (_didIteratorError2) {
  13920. throw _iteratorError2;
  13921. }
  13922. }
  13923. }
  13924. }
  13925. break;
  13926. case 'content-length':
  13927. case 'l':
  13928. message.setHeader('content-length', headerValue);
  13929. parsed = message.parseHeader('content-length');
  13930. break;
  13931. case 'content-type':
  13932. case 'c':
  13933. message.setHeader('content-type', headerValue);
  13934. parsed = message.parseHeader('content-type');
  13935. break;
  13936. case 'cseq':
  13937. message.setHeader('cseq', headerValue);
  13938. parsed = message.parseHeader('cseq');
  13939. if (parsed) {
  13940. message.cseq = parsed.value;
  13941. }
  13942. if (message instanceof SIPMessage.IncomingResponse) {
  13943. message.method = parsed.method;
  13944. }
  13945. break;
  13946. case 'max-forwards':
  13947. message.setHeader('max-forwards', headerValue);
  13948. parsed = message.parseHeader('max-forwards');
  13949. break;
  13950. case 'www-authenticate':
  13951. message.setHeader('www-authenticate', headerValue);
  13952. parsed = message.parseHeader('www-authenticate');
  13953. break;
  13954. case 'proxy-authenticate':
  13955. message.setHeader('proxy-authenticate', headerValue);
  13956. parsed = message.parseHeader('proxy-authenticate');
  13957. break;
  13958. case 'session-expires':
  13959. case 'x':
  13960. message.setHeader('session-expires', headerValue);
  13961. parsed = message.parseHeader('session-expires');
  13962. if (parsed) {
  13963. message.session_expires = parsed.expires;
  13964. message.session_expires_refresher = parsed.refresher;
  13965. }
  13966. break;
  13967. case 'refer-to':
  13968. case 'r':
  13969. message.setHeader('refer-to', headerValue);
  13970. parsed = message.parseHeader('refer-to');
  13971. if (parsed) {
  13972. message.refer_to = parsed;
  13973. }
  13974. break;
  13975. case 'replaces':
  13976. message.setHeader('replaces', headerValue);
  13977. parsed = message.parseHeader('replaces');
  13978. if (parsed) {
  13979. message.replaces = parsed;
  13980. }
  13981. break;
  13982. case 'event':
  13983. case 'o':
  13984. message.setHeader('event', headerValue);
  13985. parsed = message.parseHeader('event');
  13986. if (parsed) {
  13987. message.event = parsed;
  13988. }
  13989. break;
  13990. default:
  13991. // Do not parse this header.
  13992. message.setHeader(headerName, headerValue);
  13993. parsed = 0;
  13994. }
  13995. if (parsed === undefined) {
  13996. return {
  13997. error: 'error parsing header "' + headerName + '"'
  13998. };
  13999. } else {
  14000. return true;
  14001. }
  14002. }
  14003. },{"./Grammar":7,"./SIPMessage":19,"debug":29}],12:[function(require,module,exports){
  14004. 'use strict';
  14005. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  14006. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  14007. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14008. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  14009. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  14010. /* globals RTCPeerConnection: false, RTCSessionDescription: false */
  14011. var EventEmitter = require('events').EventEmitter;
  14012. var sdp_transform = require('sdp-transform');
  14013. var JsSIP_C = require('./Constants');
  14014. var Exceptions = require('./Exceptions');
  14015. var Transactions = require('./Transactions');
  14016. var Utils = require('./Utils');
  14017. var Timers = require('./Timers');
  14018. var SIPMessage = require('./SIPMessage');
  14019. var Dialog = require('./Dialog');
  14020. var RequestSender = require('./RequestSender');
  14021. var RTCSession_DTMF = require('./RTCSession/DTMF');
  14022. var RTCSession_Info = require('./RTCSession/Info');
  14023. var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier');
  14024. var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber');
  14025. var debug = require('debug')('JsSIP:RTCSession');
  14026. var debugerror = require('debug')('JsSIP:ERROR:RTCSession');
  14027. debugerror.log = console.warn.bind(console);
  14028. var C = {
  14029. // RTCSession states.
  14030. STATUS_NULL: 0,
  14031. STATUS_INVITE_SENT: 1,
  14032. STATUS_1XX_RECEIVED: 2,
  14033. STATUS_INVITE_RECEIVED: 3,
  14034. STATUS_WAITING_FOR_ANSWER: 4,
  14035. STATUS_ANSWERED: 5,
  14036. STATUS_WAITING_FOR_ACK: 6,
  14037. STATUS_CANCELED: 7,
  14038. STATUS_TERMINATED: 8,
  14039. STATUS_CONFIRMED: 9
  14040. };
  14041. /**
  14042. * Local variables.
  14043. */
  14044. var holdMediaTypes = ['audio', 'video'];
  14045. module.exports = function (_EventEmitter) {
  14046. _inherits(RTCSession, _EventEmitter);
  14047. _createClass(RTCSession, null, [{
  14048. key: 'C',
  14049. /**
  14050. * Expose C object.
  14051. */
  14052. get: function get() {
  14053. return C;
  14054. }
  14055. }]);
  14056. function RTCSession(ua) {
  14057. _classCallCheck(this, RTCSession);
  14058. debug('new');
  14059. var _this = _possibleConstructorReturn(this, (RTCSession.__proto__ || Object.getPrototypeOf(RTCSession)).call(this));
  14060. _this._id = null;
  14061. _this._ua = ua;
  14062. _this._status = C.STATUS_NULL;
  14063. _this._dialog = null;
  14064. _this._earlyDialogs = {};
  14065. _this._contact = null;
  14066. _this._from_tag = null;
  14067. _this._to_tag = null;
  14068. // The RTCPeerConnection instance (public attribute).
  14069. _this._connection = null;
  14070. // Prevent races on serial PeerConnction operations.
  14071. _this._connectionPromiseQueue = Promise.resolve();
  14072. // Incoming/Outgoing request being currently processed.
  14073. _this._request = null;
  14074. // Cancel state for initial outgoing request.
  14075. _this._is_canceled = false;
  14076. _this._cancel_reason = '';
  14077. // RTCSession confirmation flag.
  14078. _this._is_confirmed = false;
  14079. // Is late SDP being negotiated.
  14080. _this._late_sdp = false;
  14081. // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()).
  14082. _this._rtcOfferConstraints = null;
  14083. _this._rtcAnswerConstraints = null;
  14084. // Local MediaStream.
  14085. _this._localMediaStream = null;
  14086. _this._localMediaStreamLocallyGenerated = false;
  14087. // Flag to indicate PeerConnection ready for new actions.
  14088. _this._rtcReady = true;
  14089. // SIP Timers.
  14090. _this._timers = {
  14091. ackTimer: null,
  14092. expiresTimer: null,
  14093. invite2xxTimer: null,
  14094. userNoAnswerTimer: null
  14095. };
  14096. // Session info.
  14097. _this._direction = null;
  14098. _this._local_identity = null;
  14099. _this._remote_identity = null;
  14100. _this._start_time = null;
  14101. _this._end_time = null;
  14102. _this._tones = null;
  14103. // Mute/Hold state.
  14104. _this._audioMuted = false;
  14105. _this._videoMuted = false;
  14106. _this._localHold = false;
  14107. _this._remoteHold = false;
  14108. // Session Timers (RFC 4028).
  14109. _this._sessionTimers = {
  14110. enabled: _this._ua.configuration.session_timers,
  14111. refreshMethod: _this._ua.configuration.session_timers_refresh_method,
  14112. defaultExpires: JsSIP_C.SESSION_EXPIRES,
  14113. currentExpires: null,
  14114. running: false,
  14115. refresher: false,
  14116. timer: null // A setTimeout.
  14117. };
  14118. // Map of ReferSubscriber instances indexed by the REFER's CSeq number.
  14119. _this._referSubscribers = {};
  14120. // Custom session empty object for high level use.
  14121. _this._data = {};
  14122. return _this;
  14123. }
  14124. /**
  14125. * User API
  14126. */
  14127. // Expose RTCSession constants as a property of the RTCSession instance.
  14128. _createClass(RTCSession, [{
  14129. key: 'isInProgress',
  14130. value: function isInProgress() {
  14131. switch (this._status) {
  14132. case C.STATUS_NULL:
  14133. case C.STATUS_INVITE_SENT:
  14134. case C.STATUS_1XX_RECEIVED:
  14135. case C.STATUS_INVITE_RECEIVED:
  14136. case C.STATUS_WAITING_FOR_ANSWER:
  14137. return true;
  14138. default:
  14139. return false;
  14140. }
  14141. }
  14142. }, {
  14143. key: 'isEstablished',
  14144. value: function isEstablished() {
  14145. switch (this._status) {
  14146. case C.STATUS_ANSWERED:
  14147. case C.STATUS_WAITING_FOR_ACK:
  14148. case C.STATUS_CONFIRMED:
  14149. return true;
  14150. default:
  14151. return false;
  14152. }
  14153. }
  14154. }, {
  14155. key: 'isEnded',
  14156. value: function isEnded() {
  14157. switch (this._status) {
  14158. case C.STATUS_CANCELED:
  14159. case C.STATUS_TERMINATED:
  14160. return true;
  14161. default:
  14162. return false;
  14163. }
  14164. }
  14165. }, {
  14166. key: 'isMuted',
  14167. value: function isMuted() {
  14168. return {
  14169. audio: this._audioMuted,
  14170. video: this._videoMuted
  14171. };
  14172. }
  14173. }, {
  14174. key: 'isOnHold',
  14175. value: function isOnHold() {
  14176. return {
  14177. local: this._localHold,
  14178. remote: this._remoteHold
  14179. };
  14180. }
  14181. }, {
  14182. key: 'connect',
  14183. value: function connect(target) {
  14184. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  14185. var initCallback = arguments[2];
  14186. debug('connect()');
  14187. var originalTarget = target;
  14188. var eventHandlers = options.eventHandlers || {};
  14189. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14190. var mediaConstraints = options.mediaConstraints || { audio: true, video: true };
  14191. var mediaStream = options.mediaStream || null;
  14192. var pcConfig = options.pcConfig || { iceServers: [] };
  14193. var rtcConstraints = options.rtcConstraints || null;
  14194. var rtcOfferConstraints = options.rtcOfferConstraints || null;
  14195. this._rtcOfferConstraints = rtcOfferConstraints;
  14196. this._rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  14197. this._data = options.data || this._data;
  14198. // Check target.
  14199. if (target === undefined) {
  14200. throw new TypeError('Not enough arguments');
  14201. }
  14202. // Check Session Status.
  14203. if (this._status !== C.STATUS_NULL) {
  14204. throw new Exceptions.InvalidStateError(this._status);
  14205. }
  14206. // Check WebRTC support.
  14207. if (!window.RTCPeerConnection) {
  14208. throw new Exceptions.NotSupportedError('WebRTC not supported');
  14209. }
  14210. // Check target validity.
  14211. target = this._ua.normalizeTarget(target);
  14212. if (!target) {
  14213. throw new TypeError('Invalid target: ' + originalTarget);
  14214. }
  14215. // Session Timers.
  14216. if (this._sessionTimers.enabled) {
  14217. if (Utils.isDecimal(options.sessionTimersExpires)) {
  14218. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  14219. this._sessionTimers.defaultExpires = options.sessionTimersExpires;
  14220. } else {
  14221. this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  14222. }
  14223. }
  14224. }
  14225. // Set event handlers.
  14226. for (var event in eventHandlers) {
  14227. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  14228. this.on(event, eventHandlers[event]);
  14229. }
  14230. }
  14231. // Session parameter initialization.
  14232. this._from_tag = Utils.newTag();
  14233. // Set anonymous property.
  14234. var anonymous = options.anonymous || false;
  14235. var requestParams = { from_tag: this._from_tag };
  14236. this._contact = this._ua.contact.toString({
  14237. anonymous: anonymous,
  14238. outbound: true
  14239. });
  14240. if (anonymous) {
  14241. requestParams.from_display_name = 'Anonymous';
  14242. requestParams.from_uri = 'sip:anonymous@anonymous.invalid';
  14243. extraHeaders.push('P-Preferred-Identity: ' + this._ua.configuration.uri.toString());
  14244. extraHeaders.push('Privacy: id');
  14245. }
  14246. extraHeaders.push('Contact: ' + this._contact);
  14247. extraHeaders.push('Content-Type: application/sdp');
  14248. if (this._sessionTimers.enabled) {
  14249. extraHeaders.push('Session-Expires: ' + this._sessionTimers.defaultExpires);
  14250. }
  14251. this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders);
  14252. this._id = this._request.call_id + this._from_tag;
  14253. // Create a new RTCPeerConnection instance.
  14254. this._createRTCConnection(pcConfig, rtcConstraints);
  14255. // Set internal properties.
  14256. this._direction = 'outgoing';
  14257. this._local_identity = this._request.from;
  14258. this._remote_identity = this._request.to;
  14259. // User explicitly provided a newRTCSession callback for this session.
  14260. if (initCallback) {
  14261. initCallback(this);
  14262. }
  14263. this._newRTCSession('local', this._request);
  14264. this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream);
  14265. }
  14266. }, {
  14267. key: 'init_incoming',
  14268. value: function init_incoming(request, initCallback) {
  14269. var _this2 = this;
  14270. debug('init_incoming()');
  14271. var expires = void 0;
  14272. var contentType = request.getHeader('Content-Type');
  14273. // Check body and content type.
  14274. if (request.body && contentType !== 'application/sdp') {
  14275. request.reply(415);
  14276. return;
  14277. }
  14278. // Session parameter initialization.
  14279. this._status = C.STATUS_INVITE_RECEIVED;
  14280. this._from_tag = request.from_tag;
  14281. this._id = request.call_id + this._from_tag;
  14282. this._request = request;
  14283. this._contact = this._ua.contact.toString();
  14284. // Get the Expires header value if exists.
  14285. if (request.hasHeader('expires')) {
  14286. expires = request.getHeader('expires') * 1000;
  14287. }
  14288. /* Set the to_tag before
  14289. * replying a response code that will create a dialog.
  14290. */
  14291. request.to_tag = Utils.newTag();
  14292. // An error on dialog creation will fire 'failed' event.
  14293. if (!this._createDialog(request, 'UAS', true)) {
  14294. request.reply(500, 'Missing Contact header field');
  14295. return;
  14296. }
  14297. if (request.body) {
  14298. this._late_sdp = false;
  14299. } else {
  14300. this._late_sdp = true;
  14301. }
  14302. this._status = C.STATUS_WAITING_FOR_ANSWER;
  14303. // Set userNoAnswerTimer.
  14304. this._timers.userNoAnswerTimer = setTimeout(function () {
  14305. request.reply(408);
  14306. _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER);
  14307. }, this._ua.configuration.no_answer_timeout);
  14308. /* Set expiresTimer
  14309. * RFC3261 13.3.1
  14310. */
  14311. if (expires) {
  14312. this._timers.expiresTimer = setTimeout(function () {
  14313. if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) {
  14314. request.reply(487);
  14315. _this2._failed('system', null, JsSIP_C.causes.EXPIRES);
  14316. }
  14317. }, expires);
  14318. }
  14319. // Set internal properties.
  14320. this._direction = 'incoming';
  14321. this._local_identity = request.to;
  14322. this._remote_identity = request.from;
  14323. // A init callback was specifically defined.
  14324. if (initCallback) {
  14325. initCallback(this);
  14326. }
  14327. // Fire 'newRTCSession' event.
  14328. this._newRTCSession('remote', request);
  14329. // The user may have rejected the call in the 'newRTCSession' event.
  14330. if (this._status === C.STATUS_TERMINATED) {
  14331. return;
  14332. }
  14333. // Reply 180.
  14334. request.reply(180, null, ['Contact: ' + this._contact]);
  14335. // Fire 'progress' event.
  14336. // TODO: Document that 'response' field in 'progress' event is null for incoming calls.
  14337. this._progress('local', null);
  14338. }
  14339. /**
  14340. * Answer the call.
  14341. */
  14342. }, {
  14343. key: 'answer',
  14344. value: function answer() {
  14345. var _this3 = this;
  14346. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14347. debug('answer()');
  14348. var request = this._request;
  14349. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14350. var mediaConstraints = options.mediaConstraints || {};
  14351. var mediaStream = options.mediaStream || null;
  14352. var pcConfig = options.pcConfig || { iceServers: [] };
  14353. var rtcConstraints = options.rtcConstraints || null;
  14354. var rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  14355. var tracks = void 0;
  14356. var peerHasAudioLine = false;
  14357. var peerHasVideoLine = false;
  14358. var peerOffersFullAudio = false;
  14359. var peerOffersFullVideo = false;
  14360. this._rtcAnswerConstraints = rtcAnswerConstraints;
  14361. this._rtcOfferConstraints = options.rtcOfferConstraints || null;
  14362. this._data = options.data || this._data;
  14363. // Check Session Direction and Status.
  14364. if (this._direction !== 'incoming') {
  14365. throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession');
  14366. }
  14367. // Check Session status.
  14368. if (this._status !== C.STATUS_WAITING_FOR_ANSWER) {
  14369. throw new Exceptions.InvalidStateError(this._status);
  14370. }
  14371. // Session Timers.
  14372. if (this._sessionTimers.enabled) {
  14373. if (Utils.isDecimal(options.sessionTimersExpires)) {
  14374. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  14375. this._sessionTimers.defaultExpires = options.sessionTimersExpires;
  14376. } else {
  14377. this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  14378. }
  14379. }
  14380. }
  14381. this._status = C.STATUS_ANSWERED;
  14382. // An error on dialog creation will fire 'failed' event.
  14383. if (!this._createDialog(request, 'UAS')) {
  14384. request.reply(500, 'Error creating dialog');
  14385. return;
  14386. }
  14387. clearTimeout(this._timers.userNoAnswerTimer);
  14388. extraHeaders.unshift('Contact: ' + this._contact);
  14389. // Determine incoming media from incoming SDP offer (if any).
  14390. var sdp = request.parseSDP();
  14391. // Make sure sdp.media is an array, not the case if there is only one media.
  14392. if (!Array.isArray(sdp.media)) {
  14393. sdp.media = [sdp.media];
  14394. }
  14395. // Go through all medias in SDP to find offered capabilities to answer with.
  14396. var _iteratorNormalCompletion = true;
  14397. var _didIteratorError = false;
  14398. var _iteratorError = undefined;
  14399. try {
  14400. for (var _iterator = sdp.media[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  14401. var m = _step.value;
  14402. if (m.type === 'audio') {
  14403. peerHasAudioLine = true;
  14404. if (!m.direction || m.direction === 'sendrecv') {
  14405. peerOffersFullAudio = true;
  14406. }
  14407. }
  14408. if (m.type === 'video') {
  14409. peerHasVideoLine = true;
  14410. if (!m.direction || m.direction === 'sendrecv') {
  14411. peerOffersFullVideo = true;
  14412. }
  14413. }
  14414. }
  14415. // Remove audio from mediaStream if suggested by mediaConstraints.
  14416. } catch (err) {
  14417. _didIteratorError = true;
  14418. _iteratorError = err;
  14419. } finally {
  14420. try {
  14421. if (!_iteratorNormalCompletion && _iterator.return) {
  14422. _iterator.return();
  14423. }
  14424. } finally {
  14425. if (_didIteratorError) {
  14426. throw _iteratorError;
  14427. }
  14428. }
  14429. }
  14430. if (mediaStream && mediaConstraints.audio === false) {
  14431. tracks = mediaStream.getAudioTracks();
  14432. var _iteratorNormalCompletion2 = true;
  14433. var _didIteratorError2 = false;
  14434. var _iteratorError2 = undefined;
  14435. try {
  14436. for (var _iterator2 = tracks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  14437. var track = _step2.value;
  14438. mediaStream.removeTrack(track);
  14439. }
  14440. } catch (err) {
  14441. _didIteratorError2 = true;
  14442. _iteratorError2 = err;
  14443. } finally {
  14444. try {
  14445. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  14446. _iterator2.return();
  14447. }
  14448. } finally {
  14449. if (_didIteratorError2) {
  14450. throw _iteratorError2;
  14451. }
  14452. }
  14453. }
  14454. }
  14455. // Remove video from mediaStream if suggested by mediaConstraints.
  14456. if (mediaStream && mediaConstraints.video === false) {
  14457. tracks = mediaStream.getVideoTracks();
  14458. var _iteratorNormalCompletion3 = true;
  14459. var _didIteratorError3 = false;
  14460. var _iteratorError3 = undefined;
  14461. try {
  14462. for (var _iterator3 = tracks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  14463. var _track = _step3.value;
  14464. mediaStream.removeTrack(_track);
  14465. }
  14466. } catch (err) {
  14467. _didIteratorError3 = true;
  14468. _iteratorError3 = err;
  14469. } finally {
  14470. try {
  14471. if (!_iteratorNormalCompletion3 && _iterator3.return) {
  14472. _iterator3.return();
  14473. }
  14474. } finally {
  14475. if (_didIteratorError3) {
  14476. throw _iteratorError3;
  14477. }
  14478. }
  14479. }
  14480. }
  14481. // Set audio constraints based on incoming stream if not supplied.
  14482. if (!mediaStream && mediaConstraints.audio === undefined) {
  14483. mediaConstraints.audio = peerOffersFullAudio;
  14484. }
  14485. // Set video constraints based on incoming stream if not supplied.
  14486. if (!mediaStream && mediaConstraints.video === undefined) {
  14487. mediaConstraints.video = peerOffersFullVideo;
  14488. }
  14489. // Don't ask for audio if the incoming offer has no audio section.
  14490. if (!mediaStream && !peerHasAudioLine) {
  14491. mediaConstraints.audio = false;
  14492. }
  14493. // Don't ask for video if the incoming offer has no video section.
  14494. if (!mediaStream && !peerHasVideoLine) {
  14495. mediaConstraints.video = false;
  14496. }
  14497. // Create a new RTCPeerConnection instance.
  14498. // TODO: This may throw an error, should react.
  14499. this._createRTCConnection(pcConfig, rtcConstraints);
  14500. // If a local MediaStream is given use it.
  14501. if (mediaStream) {
  14502. userMediaSucceeded.call(this, mediaStream);
  14503. }
  14504. // If at least audio or video is requested prompt getUserMedia.
  14505. else if (mediaConstraints.audio || mediaConstraints.video) {
  14506. this._localMediaStreamLocallyGenerated = true;
  14507. navigator.mediaDevices.getUserMedia(mediaConstraints).then(userMediaSucceeded.bind(this)).catch(function (error) {
  14508. userMediaFailed.call(_this3, error);
  14509. debugerror('emit "getusermediafailed" [error:%o]', error);
  14510. _this3.emit('getusermediafailed', error);
  14511. });
  14512. // Otherwise don't prompt getUserMedia.
  14513. } else {
  14514. userMediaSucceeded.call(this, null);
  14515. }
  14516. // User media succeeded.
  14517. function userMediaSucceeded(stream) {
  14518. var _this4 = this;
  14519. if (this._status === C.STATUS_TERMINATED) {
  14520. return;
  14521. }
  14522. this._localMediaStream = stream;
  14523. if (stream) {
  14524. this._connection.addStream(stream);
  14525. }
  14526. if (!this._late_sdp) {
  14527. var e = { originator: 'remote', type: 'offer', sdp: request.body };
  14528. debug('emit "sdp"');
  14529. this.emit('sdp', e);
  14530. var offer = new RTCSessionDescription({ type: 'offer', sdp: e.sdp });
  14531. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  14532. return _this4._connection.setRemoteDescription(offer);
  14533. }).then(remoteDescriptionSucceededOrNotNeeded.bind(this)).catch(function (error) {
  14534. request.reply(488);
  14535. _this4._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR);
  14536. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  14537. _this4.emit('peerconnection:setremotedescriptionfailed', error);
  14538. });
  14539. } else {
  14540. remoteDescriptionSucceededOrNotNeeded.call(this);
  14541. }
  14542. }
  14543. // User media failed.
  14544. function userMediaFailed() {
  14545. if (this._status === C.STATUS_TERMINATED) {
  14546. return;
  14547. }
  14548. request.reply(480);
  14549. this._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  14550. }
  14551. function remoteDescriptionSucceededOrNotNeeded() {
  14552. this._connecting(request);
  14553. if (!this._late_sdp) {
  14554. this._createLocalDescription('answer', rtcSucceeded.bind(this), rtcFailed.bind(this), rtcAnswerConstraints);
  14555. } else {
  14556. this._createLocalDescription('offer', rtcSucceeded.bind(this), rtcFailed.bind(this), this._rtcOfferConstraints);
  14557. }
  14558. }
  14559. function rtcSucceeded(desc) {
  14560. if (this._status === C.STATUS_TERMINATED) {
  14561. return;
  14562. }
  14563. // Run for reply success callback.
  14564. function replySucceeded() {
  14565. this._status = C.STATUS_WAITING_FOR_ACK;
  14566. this._setInvite2xxTimer(request, desc);
  14567. this._setACKTimer();
  14568. this._accepted('local');
  14569. }
  14570. // Run for reply failure callback.
  14571. function replyFailed() {
  14572. this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  14573. }
  14574. this._handleSessionTimersInIncomingRequest(request, extraHeaders);
  14575. request.reply(200, null, extraHeaders, desc, replySucceeded.bind(this), replyFailed.bind(this));
  14576. }
  14577. function rtcFailed() {
  14578. if (this._status === C.STATUS_TERMINATED) {
  14579. return;
  14580. }
  14581. request.reply(500);
  14582. this._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR);
  14583. }
  14584. }
  14585. /**
  14586. * Terminate the call.
  14587. */
  14588. }, {
  14589. key: 'terminate',
  14590. value: function terminate() {
  14591. var _this5 = this;
  14592. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14593. debug('terminate()');
  14594. var cause = options.cause || JsSIP_C.causes.BYE;
  14595. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14596. var body = options.body;
  14597. var cancel_reason = void 0;
  14598. var status_code = options.status_code;
  14599. var reason_phrase = options.reason_phrase;
  14600. // Check Session Status.
  14601. if (this._status === C.STATUS_TERMINATED) {
  14602. throw new Exceptions.InvalidStateError(this._status);
  14603. }
  14604. switch (this._status) {
  14605. // - UAC -
  14606. case C.STATUS_NULL:
  14607. case C.STATUS_INVITE_SENT:
  14608. case C.STATUS_1XX_RECEIVED:
  14609. debug('canceling session');
  14610. if (status_code && (status_code < 200 || status_code >= 700)) {
  14611. throw new TypeError('Invalid status_code: ' + status_code);
  14612. } else if (status_code) {
  14613. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  14614. cancel_reason = 'SIP ;cause=' + status_code + ' ;text="' + reason_phrase + '"';
  14615. }
  14616. // Check Session Status.
  14617. if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) {
  14618. this._is_canceled = true;
  14619. this._cancel_reason = cancel_reason;
  14620. } else if (this._status === C.STATUS_1XX_RECEIVED) {
  14621. this._request.cancel(cancel_reason);
  14622. }
  14623. this._status = C.STATUS_CANCELED;
  14624. this._failed('local', null, JsSIP_C.causes.CANCELED);
  14625. break;
  14626. // - UAS -
  14627. case C.STATUS_WAITING_FOR_ANSWER:
  14628. case C.STATUS_ANSWERED:
  14629. debug('rejecting session');
  14630. status_code = status_code || 480;
  14631. if (status_code < 300 || status_code >= 700) {
  14632. throw new TypeError('Invalid status_code: ' + status_code);
  14633. }
  14634. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  14635. this._failed('local', null, JsSIP_C.causes.REJECTED);
  14636. break;
  14637. case C.STATUS_WAITING_FOR_ACK:
  14638. case C.STATUS_CONFIRMED:
  14639. debug('terminating session');
  14640. reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  14641. if (status_code && (status_code < 200 || status_code >= 700)) {
  14642. throw new TypeError('Invalid status_code: ' + status_code);
  14643. } else if (status_code) {
  14644. extraHeaders.push('Reason: SIP ;cause=' + status_code + '; text="' + reason_phrase + '"');
  14645. }
  14646. /* RFC 3261 section 15 (Terminating a session):
  14647. *
  14648. * "...the callee's UA MUST NOT send a BYE on a confirmed dialog
  14649. * until it has received an ACK for its 2xx response or until the server
  14650. * transaction times out."
  14651. */
  14652. if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) {
  14653. // Save the dialog for later restoration.
  14654. var dialog = this._dialog;
  14655. // Send the BYE as soon as the ACK is received...
  14656. this.receiveRequest = function (_ref) {
  14657. var method = _ref.method;
  14658. if (method === JsSIP_C.ACK) {
  14659. _this5.sendRequest(JsSIP_C.BYE, {
  14660. extraHeaders: extraHeaders,
  14661. body: body
  14662. });
  14663. dialog.terminate();
  14664. }
  14665. };
  14666. // .., or when the INVITE transaction times out
  14667. this._request.server_transaction.on('stateChanged', function () {
  14668. if (_this5._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) {
  14669. _this5.sendRequest(JsSIP_C.BYE, {
  14670. extraHeaders: extraHeaders,
  14671. body: body
  14672. });
  14673. dialog.terminate();
  14674. }
  14675. });
  14676. this._ended('local', null, cause);
  14677. // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-).
  14678. this._dialog = dialog;
  14679. // Restore the dialog into 'ua' so the ACK can reach 'this' session.
  14680. this._ua.newDialog(dialog);
  14681. } else {
  14682. this.sendRequest(JsSIP_C.BYE, {
  14683. extraHeaders: extraHeaders,
  14684. body: body
  14685. });
  14686. this._ended('local', null, cause);
  14687. }
  14688. }
  14689. }
  14690. }, {
  14691. key: 'sendDTMF',
  14692. value: function sendDTMF(tones) {
  14693. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  14694. debug('sendDTMF() | tones: %s', tones);
  14695. var position = 0;
  14696. var duration = options.duration || null;
  14697. var interToneGap = options.interToneGap || null;
  14698. if (tones === undefined) {
  14699. throw new TypeError('Not enough arguments');
  14700. }
  14701. // Check Session Status.
  14702. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) {
  14703. throw new Exceptions.InvalidStateError(this._status);
  14704. }
  14705. // Convert to string.
  14706. if (typeof tones === 'number') {
  14707. tones = tones.toString();
  14708. }
  14709. // Check tones.
  14710. if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) {
  14711. throw new TypeError('Invalid tones: ' + tones);
  14712. }
  14713. // Check duration.
  14714. if (duration && !Utils.isDecimal(duration)) {
  14715. throw new TypeError('Invalid tone duration: ' + duration);
  14716. } else if (!duration) {
  14717. duration = RTCSession_DTMF.C.DEFAULT_DURATION;
  14718. } else if (duration < RTCSession_DTMF.C.MIN_DURATION) {
  14719. debug('"duration" value is lower than the minimum allowed, setting it to ' + RTCSession_DTMF.C.MIN_DURATION + ' milliseconds');
  14720. duration = RTCSession_DTMF.C.MIN_DURATION;
  14721. } else if (duration > RTCSession_DTMF.C.MAX_DURATION) {
  14722. debug('"duration" value is greater than the maximum allowed, setting it to ' + RTCSession_DTMF.C.MAX_DURATION + ' milliseconds');
  14723. duration = RTCSession_DTMF.C.MAX_DURATION;
  14724. } else {
  14725. duration = Math.abs(duration);
  14726. }
  14727. options.duration = duration;
  14728. // Check interToneGap.
  14729. if (interToneGap && !Utils.isDecimal(interToneGap)) {
  14730. throw new TypeError('Invalid interToneGap: ' + interToneGap);
  14731. } else if (!interToneGap) {
  14732. interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP;
  14733. } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) {
  14734. debug('"interToneGap" value is lower than the minimum allowed, setting it to ' + RTCSession_DTMF.C.MIN_INTER_TONE_GAP + ' milliseconds');
  14735. interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP;
  14736. } else {
  14737. interToneGap = Math.abs(interToneGap);
  14738. }
  14739. if (this._tones) {
  14740. // Tones are already queued, just add to the queue.
  14741. this._tones += tones;
  14742. return;
  14743. }
  14744. this._tones = tones;
  14745. // Send the first tone.
  14746. _sendDTMF.call(this);
  14747. function _sendDTMF() {
  14748. var _this6 = this;
  14749. var timeout = void 0;
  14750. if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) {
  14751. // Stop sending DTMF.
  14752. this._tones = null;
  14753. return;
  14754. }
  14755. var tone = this._tones[position];
  14756. position += 1;
  14757. if (tone === ',') {
  14758. timeout = 2000;
  14759. } else {
  14760. var dtmf = new RTCSession_DTMF(this);
  14761. options.eventHandlers = {
  14762. onFailed: function onFailed() {
  14763. _this6._tones = null;
  14764. }
  14765. };
  14766. dtmf.send(tone, options);
  14767. timeout = duration + interToneGap;
  14768. }
  14769. // Set timeout for the next tone.
  14770. setTimeout(_sendDTMF.bind(this), timeout);
  14771. }
  14772. }
  14773. }, {
  14774. key: 'sendInfo',
  14775. value: function sendInfo(contentType, body) {
  14776. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  14777. debug('sendInfo()');
  14778. // Check Session Status.
  14779. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) {
  14780. throw new Exceptions.InvalidStateError(this._status);
  14781. }
  14782. var info = new RTCSession_Info(this);
  14783. info.send(contentType, body, options);
  14784. }
  14785. /**
  14786. * Mute
  14787. */
  14788. }, {
  14789. key: 'mute',
  14790. value: function mute() {
  14791. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { audio: true, video: false };
  14792. debug('mute()');
  14793. var audioMuted = false,
  14794. videoMuted = false;
  14795. if (this._audioMuted === false && options.audio) {
  14796. audioMuted = true;
  14797. this._audioMuted = true;
  14798. this._toogleMuteAudio(true);
  14799. }
  14800. if (this._videoMuted === false && options.video) {
  14801. videoMuted = true;
  14802. this._videoMuted = true;
  14803. this._toogleMuteVideo(true);
  14804. }
  14805. if (audioMuted === true || videoMuted === true) {
  14806. this._onmute({
  14807. audio: audioMuted,
  14808. video: videoMuted
  14809. });
  14810. }
  14811. }
  14812. /**
  14813. * Unmute
  14814. */
  14815. }, {
  14816. key: 'unmute',
  14817. value: function unmute() {
  14818. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { audio: true, video: true };
  14819. debug('unmute()');
  14820. var audioUnMuted = false,
  14821. videoUnMuted = false;
  14822. if (this._audioMuted === true && options.audio) {
  14823. audioUnMuted = true;
  14824. this._audioMuted = false;
  14825. if (this._localHold === false) {
  14826. this._toogleMuteAudio(false);
  14827. }
  14828. }
  14829. if (this._videoMuted === true && options.video) {
  14830. videoUnMuted = true;
  14831. this._videoMuted = false;
  14832. if (this._localHold === false) {
  14833. this._toogleMuteVideo(false);
  14834. }
  14835. }
  14836. if (audioUnMuted === true || videoUnMuted === true) {
  14837. this._onunmute({
  14838. audio: audioUnMuted,
  14839. video: videoUnMuted
  14840. });
  14841. }
  14842. }
  14843. /**
  14844. * Hold
  14845. */
  14846. }, {
  14847. key: 'hold',
  14848. value: function hold() {
  14849. var _this7 = this;
  14850. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14851. var done = arguments[1];
  14852. debug('hold()');
  14853. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  14854. return false;
  14855. }
  14856. if (this._localHold === true) {
  14857. return false;
  14858. }
  14859. if (!this._isReadyToReOffer()) {
  14860. return false;
  14861. }
  14862. this._localHold = true;
  14863. this._onhold('local');
  14864. var eventHandlers = {
  14865. succeeded: function succeeded() {
  14866. if (done) {
  14867. done();
  14868. }
  14869. },
  14870. failed: function failed() {
  14871. _this7.terminate({
  14872. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14873. status_code: 500,
  14874. reason_phrase: 'Hold Failed'
  14875. });
  14876. }
  14877. };
  14878. if (options.useUpdate) {
  14879. this._sendUpdate({
  14880. sdpOffer: true,
  14881. eventHandlers: eventHandlers,
  14882. extraHeaders: options.extraHeaders
  14883. });
  14884. } else {
  14885. this._sendReinvite({
  14886. eventHandlers: eventHandlers,
  14887. extraHeaders: options.extraHeaders
  14888. });
  14889. }
  14890. return true;
  14891. }
  14892. }, {
  14893. key: 'unhold',
  14894. value: function unhold() {
  14895. var _this8 = this;
  14896. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14897. var done = arguments[1];
  14898. debug('unhold()');
  14899. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  14900. return false;
  14901. }
  14902. if (this._localHold === false) {
  14903. return false;
  14904. }
  14905. if (!this._isReadyToReOffer()) {
  14906. return false;
  14907. }
  14908. this._localHold = false;
  14909. this._onunhold('local');
  14910. var eventHandlers = {
  14911. succeeded: function succeeded() {
  14912. if (done) {
  14913. done();
  14914. }
  14915. },
  14916. failed: function failed() {
  14917. _this8.terminate({
  14918. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14919. status_code: 500,
  14920. reason_phrase: 'Unhold Failed'
  14921. });
  14922. }
  14923. };
  14924. if (options.useUpdate) {
  14925. this._sendUpdate({
  14926. sdpOffer: true,
  14927. eventHandlers: eventHandlers,
  14928. extraHeaders: options.extraHeaders
  14929. });
  14930. } else {
  14931. this._sendReinvite({
  14932. eventHandlers: eventHandlers,
  14933. extraHeaders: options.extraHeaders
  14934. });
  14935. }
  14936. return true;
  14937. }
  14938. }, {
  14939. key: 'renegotiate',
  14940. value: function renegotiate() {
  14941. var _this9 = this;
  14942. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14943. var done = arguments[1];
  14944. debug('renegotiate()');
  14945. var rtcOfferConstraints = options.rtcOfferConstraints || null;
  14946. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  14947. return false;
  14948. }
  14949. if (!this._isReadyToReOffer()) {
  14950. return false;
  14951. }
  14952. var eventHandlers = {
  14953. succeeded: function succeeded() {
  14954. if (done) {
  14955. done();
  14956. }
  14957. },
  14958. failed: function failed() {
  14959. _this9.terminate({
  14960. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14961. status_code: 500,
  14962. reason_phrase: 'Media Renegotiation Failed'
  14963. });
  14964. }
  14965. };
  14966. this._setLocalMediaStatus();
  14967. if (options.useUpdate) {
  14968. this._sendUpdate({
  14969. sdpOffer: true,
  14970. eventHandlers: eventHandlers,
  14971. rtcOfferConstraints: rtcOfferConstraints,
  14972. extraHeaders: options.extraHeaders
  14973. });
  14974. } else {
  14975. this._sendReinvite({
  14976. eventHandlers: eventHandlers,
  14977. rtcOfferConstraints: rtcOfferConstraints,
  14978. extraHeaders: options.extraHeaders
  14979. });
  14980. }
  14981. return true;
  14982. }
  14983. /**
  14984. * Refer
  14985. */
  14986. }, {
  14987. key: 'refer',
  14988. value: function refer(target, options) {
  14989. var _this10 = this;
  14990. debug('refer()');
  14991. var originalTarget = target;
  14992. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  14993. return false;
  14994. }
  14995. // Check target validity.
  14996. target = this._ua.normalizeTarget(target);
  14997. if (!target) {
  14998. throw new TypeError('Invalid target: ' + originalTarget);
  14999. }
  15000. var referSubscriber = new RTCSession_ReferSubscriber(this);
  15001. referSubscriber.sendRefer(target, options);
  15002. // Store in the map.
  15003. var id = referSubscriber.id;
  15004. this._referSubscribers[id] = referSubscriber;
  15005. // Listen for ending events so we can remove it from the map.
  15006. referSubscriber.on('requestFailed', function () {
  15007. delete _this10._referSubscribers[id];
  15008. });
  15009. referSubscriber.on('accepted', function () {
  15010. delete _this10._referSubscribers[id];
  15011. });
  15012. referSubscriber.on('failed', function () {
  15013. delete _this10._referSubscribers[id];
  15014. });
  15015. return referSubscriber;
  15016. }
  15017. /**
  15018. * Send a generic in-dialog Request
  15019. */
  15020. }, {
  15021. key: 'sendRequest',
  15022. value: function sendRequest(method, options) {
  15023. debug('sendRequest()');
  15024. return this._dialog.sendRequest(method, options);
  15025. }
  15026. /**
  15027. * In dialog Request Reception
  15028. */
  15029. }, {
  15030. key: 'receiveRequest',
  15031. value: function receiveRequest(request) {
  15032. var _this11 = this;
  15033. debug('receiveRequest()');
  15034. if (request.method === JsSIP_C.CANCEL) {
  15035. /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL
  15036. * was in progress and that the UAC MAY continue with the session established by
  15037. * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the
  15038. * established session. So the CANCEL is processed only if the session is not yet
  15039. * established.
  15040. */
  15041. /*
  15042. * Terminate the whole session in case the user didn't accept (or yet send the answer)
  15043. * nor reject the request opening the session.
  15044. */
  15045. if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) {
  15046. this._status = C.STATUS_CANCELED;
  15047. this._request.reply(487);
  15048. this._failed('remote', request, JsSIP_C.causes.CANCELED);
  15049. }
  15050. } else {
  15051. // Requests arriving here are in-dialog requests.
  15052. switch (request.method) {
  15053. case JsSIP_C.ACK:
  15054. if (this._status !== C.STATUS_WAITING_FOR_ACK) {
  15055. return;
  15056. }
  15057. // Update signaling status.
  15058. this._status = C.STATUS_CONFIRMED;
  15059. clearTimeout(this._timers.ackTimer);
  15060. clearTimeout(this._timers.invite2xxTimer);
  15061. if (this._late_sdp) {
  15062. if (!request.body) {
  15063. this.terminate({
  15064. cause: JsSIP_C.causes.MISSING_SDP,
  15065. status_code: 400
  15066. });
  15067. break;
  15068. }
  15069. var e = { originator: 'remote', type: 'answer', sdp: request.body };
  15070. debug('emit "sdp"');
  15071. this.emit('sdp', e);
  15072. var answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp });
  15073. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15074. return _this11._connection.setRemoteDescription(answer);
  15075. }).then(function () {
  15076. if (!_this11._is_confirmed) {
  15077. _this11._confirmed('remote', request);
  15078. }
  15079. }).catch(function (error) {
  15080. _this11.terminate({
  15081. cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION,
  15082. status_code: 488
  15083. });
  15084. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15085. _this11.emit('peerconnection:setremotedescriptionfailed', error);
  15086. });
  15087. } else if (!this._is_confirmed) {
  15088. this._confirmed('remote', request);
  15089. }
  15090. break;
  15091. case JsSIP_C.BYE:
  15092. if (this._status === C.STATUS_CONFIRMED) {
  15093. request.reply(200);
  15094. this._ended('remote', request, JsSIP_C.causes.BYE);
  15095. } else if (this._status === C.STATUS_INVITE_RECEIVED) {
  15096. request.reply(200);
  15097. this._request.reply(487, 'BYE Received');
  15098. this._ended('remote', request, JsSIP_C.causes.BYE);
  15099. } else {
  15100. request.reply(403, 'Wrong Status');
  15101. }
  15102. break;
  15103. case JsSIP_C.INVITE:
  15104. if (this._status === C.STATUS_CONFIRMED) {
  15105. if (request.hasHeader('replaces')) {
  15106. this._receiveReplaces(request);
  15107. } else {
  15108. this._receiveReinvite(request);
  15109. }
  15110. } else {
  15111. request.reply(403, 'Wrong Status');
  15112. }
  15113. break;
  15114. case JsSIP_C.INFO:
  15115. 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) {
  15116. var contentType = request.getHeader('content-type');
  15117. if (contentType && contentType.match(/^application\/dtmf-relay/i)) {
  15118. new RTCSession_DTMF(this).init_incoming(request);
  15119. } else if (contentType !== undefined) {
  15120. new RTCSession_Info(this).init_incoming(request);
  15121. } else {
  15122. request.reply(415);
  15123. }
  15124. } else {
  15125. request.reply(403, 'Wrong Status');
  15126. }
  15127. break;
  15128. case JsSIP_C.UPDATE:
  15129. if (this._status === C.STATUS_CONFIRMED) {
  15130. this._receiveUpdate(request);
  15131. } else {
  15132. request.reply(403, 'Wrong Status');
  15133. }
  15134. break;
  15135. case JsSIP_C.REFER:
  15136. if (this._status === C.STATUS_CONFIRMED) {
  15137. this._receiveRefer(request);
  15138. } else {
  15139. request.reply(403, 'Wrong Status');
  15140. }
  15141. break;
  15142. case JsSIP_C.NOTIFY:
  15143. if (this._status === C.STATUS_CONFIRMED) {
  15144. this._receiveNotify(request);
  15145. } else {
  15146. request.reply(403, 'Wrong Status');
  15147. }
  15148. break;
  15149. default:
  15150. request.reply(501);
  15151. }
  15152. }
  15153. }
  15154. /**
  15155. * Session Callbacks
  15156. */
  15157. }, {
  15158. key: 'onTransportError',
  15159. value: function onTransportError() {
  15160. debugerror('onTransportError()');
  15161. if (this._status !== C.STATUS_TERMINATED) {
  15162. this.terminate({
  15163. status_code: 500,
  15164. reason_phrase: JsSIP_C.causes.CONNECTION_ERROR,
  15165. cause: JsSIP_C.causes.CONNECTION_ERROR
  15166. });
  15167. }
  15168. }
  15169. }, {
  15170. key: 'onRequestTimeout',
  15171. value: function onRequestTimeout() {
  15172. debugerror('onRequestTimeout()');
  15173. if (this._status !== C.STATUS_TERMINATED) {
  15174. this.terminate({
  15175. status_code: 408,
  15176. reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT,
  15177. cause: JsSIP_C.causes.REQUEST_TIMEOUT
  15178. });
  15179. }
  15180. }
  15181. }, {
  15182. key: 'onDialogError',
  15183. value: function onDialogError() {
  15184. debugerror('onDialogError()');
  15185. if (this._status !== C.STATUS_TERMINATED) {
  15186. this.terminate({
  15187. status_code: 500,
  15188. reason_phrase: JsSIP_C.causes.DIALOG_ERROR,
  15189. cause: JsSIP_C.causes.DIALOG_ERROR
  15190. });
  15191. }
  15192. }
  15193. // Called from DTMF handler.
  15194. }, {
  15195. key: 'newDTMF',
  15196. value: function newDTMF(data) {
  15197. debug('newDTMF()');
  15198. this.emit('newDTMF', data);
  15199. }
  15200. // Called from Info handler.
  15201. }, {
  15202. key: 'newInfo',
  15203. value: function newInfo(data) {
  15204. debug('newInfo()');
  15205. this.emit('newInfo', data);
  15206. }
  15207. /**
  15208. * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP.
  15209. */
  15210. }, {
  15211. key: '_isReadyToReOffer',
  15212. value: function _isReadyToReOffer() {
  15213. if (!this._rtcReady) {
  15214. debug('_isReadyToReOffer() | internal WebRTC status not ready');
  15215. return false;
  15216. }
  15217. // No established yet.
  15218. if (!this._dialog) {
  15219. debug('_isReadyToReOffer() | session not established yet');
  15220. return false;
  15221. }
  15222. // Another INVITE transaction is in progress.
  15223. if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) {
  15224. debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress');
  15225. return false;
  15226. }
  15227. return true;
  15228. }
  15229. }, {
  15230. key: '_close',
  15231. value: function _close() {
  15232. debug('close()');
  15233. if (this._status === C.STATUS_TERMINATED) {
  15234. return;
  15235. }
  15236. this._status = C.STATUS_TERMINATED;
  15237. // Terminate RTC.
  15238. if (this._connection) {
  15239. try {
  15240. this._connection.close();
  15241. } catch (error) {
  15242. debugerror('close() | error closing the RTCPeerConnection: %o', error);
  15243. }
  15244. }
  15245. // Close local MediaStream if it was not given by the user.
  15246. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) {
  15247. debug('close() | closing local MediaStream');
  15248. Utils.closeMediaStream(this._localMediaStream);
  15249. }
  15250. // Terminate signaling.
  15251. // Clear SIP timers.
  15252. for (var timer in this._timers) {
  15253. if (Object.prototype.hasOwnProperty.call(this._timers, timer)) {
  15254. clearTimeout(this._timers[timer]);
  15255. }
  15256. }
  15257. // Clear Session Timers.
  15258. clearTimeout(this._sessionTimers.timer);
  15259. // Terminate confirmed dialog.
  15260. if (this._dialog) {
  15261. this._dialog.terminate();
  15262. delete this._dialog;
  15263. }
  15264. // Terminate early dialogs.
  15265. for (var dialog in this._earlyDialogs) {
  15266. if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) {
  15267. this._earlyDialogs[dialog].terminate();
  15268. delete this._earlyDialogs[dialog];
  15269. }
  15270. }
  15271. // Terminate REFER subscribers.
  15272. for (var subscriber in this._referSubscribers) {
  15273. if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) {
  15274. delete this._referSubscribers[subscriber];
  15275. }
  15276. }
  15277. this._ua.destroyRTCSession(this);
  15278. }
  15279. /**
  15280. * Private API.
  15281. */
  15282. /**
  15283. * RFC3261 13.3.1.4
  15284. * Response retransmissions cannot be accomplished by transaction layer
  15285. * since it is destroyed when receiving the first 2xx answer
  15286. */
  15287. }, {
  15288. key: '_setInvite2xxTimer',
  15289. value: function _setInvite2xxTimer(request, body) {
  15290. var timeout = Timers.T1;
  15291. function invite2xxRetransmission() {
  15292. if (this._status !== C.STATUS_WAITING_FOR_ACK) {
  15293. return;
  15294. }
  15295. request.reply(200, null, ['Contact: ' + this._contact], body);
  15296. if (timeout < Timers.T2) {
  15297. timeout = timeout * 2;
  15298. if (timeout > Timers.T2) {
  15299. timeout = Timers.T2;
  15300. }
  15301. }
  15302. this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
  15303. }
  15304. this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
  15305. }
  15306. /**
  15307. * RFC3261 14.2
  15308. * If a UAS generates a 2xx response and never receives an ACK,
  15309. * it SHOULD generate a BYE to terminate the dialog.
  15310. */
  15311. }, {
  15312. key: '_setACKTimer',
  15313. value: function _setACKTimer() {
  15314. var _this12 = this;
  15315. this._timers.ackTimer = setTimeout(function () {
  15316. if (_this12._status === C.STATUS_WAITING_FOR_ACK) {
  15317. debug('no ACK received, terminating the session');
  15318. clearTimeout(_this12._timers.invite2xxTimer);
  15319. _this12.sendRequest(JsSIP_C.BYE);
  15320. _this12._ended('remote', null, JsSIP_C.causes.NO_ACK);
  15321. }
  15322. }, Timers.TIMER_H);
  15323. }
  15324. }, {
  15325. key: '_createRTCConnection',
  15326. value: function _createRTCConnection(pcConfig, rtcConstraints) {
  15327. var _this13 = this;
  15328. this._connection = new RTCPeerConnection(pcConfig, rtcConstraints);
  15329. this._connection.addEventListener('iceconnectionstatechange', function () {
  15330. var state = _this13._connection.iceConnectionState;
  15331. // TODO: Do more with different states.
  15332. if (state === 'failed') {
  15333. _this13.terminate({
  15334. cause: JsSIP_C.causes.RTP_TIMEOUT,
  15335. status_code: 408,
  15336. reason_phrase: JsSIP_C.causes.RTP_TIMEOUT
  15337. });
  15338. }
  15339. });
  15340. debug('emit "peerconnection"');
  15341. this.emit('peerconnection', {
  15342. peerconnection: this._connection
  15343. });
  15344. }
  15345. }, {
  15346. key: '_createLocalDescription',
  15347. value: function _createLocalDescription(type, onSuccess, onFailure, constraints) {
  15348. var _this14 = this;
  15349. debug('createLocalDescription()');
  15350. var connection = this._connection;
  15351. this._rtcReady = false;
  15352. if (type === 'offer') {
  15353. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15354. return connection.createOffer(constraints);
  15355. }).then(createSucceeded.bind(this)).catch(function (error) {
  15356. _this14._rtcReady = true;
  15357. if (onFailure) {
  15358. onFailure(error);
  15359. }
  15360. debugerror('emit "peerconnection:createofferfailed" [error:%o]', error);
  15361. _this14.emit('peerconnection:createofferfailed', error);
  15362. });
  15363. } else if (type === 'answer') {
  15364. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15365. return connection.createAnswer(constraints);
  15366. }).then(createSucceeded.bind(this)).catch(function (error) {
  15367. _this14._rtcReady = true;
  15368. if (onFailure) {
  15369. onFailure(error);
  15370. }
  15371. debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error);
  15372. _this14.emit('peerconnection:createanswerfailed', error);
  15373. });
  15374. } else {
  15375. throw new Error('createLocalDescription() | type must be "offer" or "answer", but "' + type + '" was given');
  15376. }
  15377. // CreateAnswer or createOffer succeeded.
  15378. function createSucceeded(desc) {
  15379. var _this15 = this;
  15380. var _listener = void 0;
  15381. connection.addEventListener('icecandidate', _listener = function listener(event) {
  15382. var candidate = event.candidate;
  15383. if (!candidate) {
  15384. connection.removeEventListener('icecandidate', _listener);
  15385. _this15._rtcReady = true;
  15386. if (onSuccess) {
  15387. var e = { originator: 'local', type: type, sdp: connection.localDescription.sdp };
  15388. debug('emit "sdp"');
  15389. _this15.emit('sdp', e);
  15390. onSuccess(e.sdp);
  15391. }
  15392. onSuccess = null;
  15393. }
  15394. });
  15395. connection.setLocalDescription(desc).then(function () {
  15396. if (connection.iceGatheringState === 'complete') {
  15397. _this15._rtcReady = true;
  15398. if (onSuccess) {
  15399. var e = { originator: 'local', type: type, sdp: connection.localDescription.sdp };
  15400. debug('emit "sdp"');
  15401. _this15.emit('sdp', e);
  15402. onSuccess(e.sdp);
  15403. onSuccess = null;
  15404. }
  15405. }
  15406. }).catch(function (error) {
  15407. _this15._rtcReady = true;
  15408. if (onFailure) {
  15409. onFailure(error);
  15410. }
  15411. debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error);
  15412. _this15.emit('peerconnection:setlocaldescriptionfailed', error);
  15413. });
  15414. }
  15415. }
  15416. /**
  15417. * Dialog Management
  15418. */
  15419. }, {
  15420. key: '_createDialog',
  15421. value: function _createDialog(message, type, early) {
  15422. var local_tag = type === 'UAS' ? message.to_tag : message.from_tag;
  15423. var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag;
  15424. var id = message.call_id + local_tag + remote_tag;
  15425. var early_dialog = this._earlyDialogs[id];
  15426. // Early Dialog.
  15427. if (early) {
  15428. if (early_dialog) {
  15429. return true;
  15430. } else {
  15431. early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY);
  15432. // Dialog has been successfully created.
  15433. if (early_dialog.error) {
  15434. debug(early_dialog.error);
  15435. this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  15436. return false;
  15437. } else {
  15438. this._earlyDialogs[id] = early_dialog;
  15439. return true;
  15440. }
  15441. }
  15442. }
  15443. // Confirmed Dialog.
  15444. else {
  15445. this._from_tag = message.from_tag;
  15446. this._to_tag = message.to_tag;
  15447. // In case the dialog is in _early_ state, update it.
  15448. if (early_dialog) {
  15449. early_dialog.update(message, type);
  15450. this._dialog = early_dialog;
  15451. delete this._earlyDialogs[id];
  15452. return true;
  15453. }
  15454. // Otherwise, create a _confirmed_ dialog.
  15455. var dialog = new Dialog(this, message, type);
  15456. if (dialog.error) {
  15457. debug(dialog.error);
  15458. this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  15459. return false;
  15460. } else {
  15461. this._dialog = dialog;
  15462. return true;
  15463. }
  15464. }
  15465. }
  15466. /**
  15467. * In dialog INVITE Reception
  15468. */
  15469. }, {
  15470. key: '_receiveReinvite',
  15471. value: function _receiveReinvite(request) {
  15472. var _this16 = this;
  15473. debug('receiveReinvite()');
  15474. var contentType = request.getHeader('Content-Type');
  15475. var data = {
  15476. request: request,
  15477. callback: undefined,
  15478. reject: reject.bind(this)
  15479. };
  15480. var hold = false;
  15481. var rejected = false;
  15482. function reject() {
  15483. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15484. rejected = true;
  15485. var status_code = options.status_code || 403;
  15486. var reason_phrase = options.reason_phrase || '';
  15487. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  15488. if (this._status !== C.STATUS_CONFIRMED) {
  15489. return false;
  15490. }
  15491. if (status_code < 300 || status_code >= 700) {
  15492. throw new TypeError('Invalid status_code: ' + status_code);
  15493. }
  15494. request.reply(status_code, reason_phrase, extraHeaders);
  15495. }
  15496. // Emit 'reinvite'.
  15497. this.emit('reinvite', data);
  15498. if (rejected) {
  15499. return;
  15500. }
  15501. if (request.body) {
  15502. this._late_sdp = false;
  15503. if (contentType !== 'application/sdp') {
  15504. debug('invalid Content-Type');
  15505. request.reply(415);
  15506. return;
  15507. }
  15508. var sdp = request.parseSDP();
  15509. var _iteratorNormalCompletion4 = true;
  15510. var _didIteratorError4 = false;
  15511. var _iteratorError4 = undefined;
  15512. try {
  15513. for (var _iterator4 = sdp.media[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  15514. var m = _step4.value;
  15515. if (holdMediaTypes.indexOf(m.type) === -1) {
  15516. continue;
  15517. }
  15518. var direction = m.direction || sdp.direction || 'sendrecv';
  15519. if (direction === 'sendonly' || direction === 'inactive') {
  15520. hold = true;
  15521. }
  15522. // If at least one of the streams is active don't emit 'hold'.
  15523. else {
  15524. hold = false;
  15525. break;
  15526. }
  15527. }
  15528. } catch (err) {
  15529. _didIteratorError4 = true;
  15530. _iteratorError4 = err;
  15531. } finally {
  15532. try {
  15533. if (!_iteratorNormalCompletion4 && _iterator4.return) {
  15534. _iterator4.return();
  15535. }
  15536. } finally {
  15537. if (_didIteratorError4) {
  15538. throw _iteratorError4;
  15539. }
  15540. }
  15541. }
  15542. var e = { originator: 'remote', type: 'offer', sdp: request.body };
  15543. debug('emit "sdp"');
  15544. this.emit('sdp', e);
  15545. var offer = new RTCSessionDescription({ type: 'offer', sdp: e.sdp });
  15546. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15547. return _this16._connection.setRemoteDescription(offer);
  15548. }).then(doAnswer.bind(this)).catch(function (error) {
  15549. request.reply(488);
  15550. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15551. _this16.emit('peerconnection:setremotedescriptionfailed', error);
  15552. });
  15553. } else {
  15554. this._late_sdp = true;
  15555. doAnswer.call(this);
  15556. }
  15557. function doAnswer() {
  15558. var _this17 = this;
  15559. createSdp.call(this, function (sdp) {
  15560. var extraHeaders = ['Contact: ' + _this17._contact];
  15561. _this17._handleSessionTimersInIncomingRequest(request, extraHeaders);
  15562. if (_this17._late_sdp) {
  15563. sdp = _this17._mangleOffer(sdp);
  15564. }
  15565. request.reply(200, null, extraHeaders, sdp, function () {
  15566. _this17._status = C.STATUS_WAITING_FOR_ACK;
  15567. _this17._setInvite2xxTimer(request, sdp);
  15568. _this17._setACKTimer();
  15569. });
  15570. // If callback is given execute it.
  15571. if (typeof data.callback === 'function') {
  15572. data.callback();
  15573. }
  15574. }, function () {
  15575. request.reply(500);
  15576. });
  15577. }
  15578. function createSdp(onSuccess, onFailure) {
  15579. if (!this._late_sdp) {
  15580. if (this._remoteHold === true && hold === false) {
  15581. this._remoteHold = false;
  15582. this._onunhold('remote');
  15583. } else if (this._remoteHold === false && hold === true) {
  15584. this._remoteHold = true;
  15585. this._onhold('remote');
  15586. }
  15587. this._createLocalDescription('answer', onSuccess, onFailure, this._rtcAnswerConstraints);
  15588. } else {
  15589. this._createLocalDescription('offer', onSuccess, onFailure, this._rtcOfferConstraints);
  15590. }
  15591. }
  15592. }
  15593. /**
  15594. * In dialog UPDATE Reception
  15595. */
  15596. }, {
  15597. key: '_receiveUpdate',
  15598. value: function _receiveUpdate(request) {
  15599. var _this18 = this;
  15600. debug('receiveUpdate()');
  15601. var contentType = request.getHeader('Content-Type');
  15602. var data = {
  15603. request: request,
  15604. callback: undefined,
  15605. reject: reject.bind(this)
  15606. };
  15607. var rejected = false;
  15608. var hold = false;
  15609. function reject() {
  15610. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15611. rejected = true;
  15612. var status_code = options.status_code || 403;
  15613. var reason_phrase = options.reason_phrase || '';
  15614. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  15615. if (this._status !== C.STATUS_CONFIRMED) {
  15616. return false;
  15617. }
  15618. if (status_code < 300 || status_code >= 700) {
  15619. throw new TypeError('Invalid status_code: ' + status_code);
  15620. }
  15621. request.reply(status_code, reason_phrase, extraHeaders);
  15622. }
  15623. // Emit 'update'.
  15624. this.emit('update', data);
  15625. if (rejected) {
  15626. return;
  15627. }
  15628. if (!request.body) {
  15629. var extraHeaders = [];
  15630. this._handleSessionTimersInIncomingRequest(request, extraHeaders);
  15631. request.reply(200, null, extraHeaders);
  15632. return;
  15633. }
  15634. if (contentType !== 'application/sdp') {
  15635. debug('invalid Content-Type');
  15636. request.reply(415);
  15637. return;
  15638. }
  15639. var sdp = request.parseSDP();
  15640. var _iteratorNormalCompletion5 = true;
  15641. var _didIteratorError5 = false;
  15642. var _iteratorError5 = undefined;
  15643. try {
  15644. for (var _iterator5 = sdp.media[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  15645. var m = _step5.value;
  15646. if (holdMediaTypes.indexOf(m.type) === -1) {
  15647. continue;
  15648. }
  15649. var direction = m.direction || sdp.direction || 'sendrecv';
  15650. if (direction === 'sendonly' || direction === 'inactive') {
  15651. hold = true;
  15652. }
  15653. // If at least one of the streams is active don't emit 'hold'.
  15654. else {
  15655. hold = false;
  15656. break;
  15657. }
  15658. }
  15659. } catch (err) {
  15660. _didIteratorError5 = true;
  15661. _iteratorError5 = err;
  15662. } finally {
  15663. try {
  15664. if (!_iteratorNormalCompletion5 && _iterator5.return) {
  15665. _iterator5.return();
  15666. }
  15667. } finally {
  15668. if (_didIteratorError5) {
  15669. throw _iteratorError5;
  15670. }
  15671. }
  15672. }
  15673. var e = { originator: 'remote', type: 'offer', sdp: request.body };
  15674. debug('emit "sdp"');
  15675. this.emit('sdp', e);
  15676. var offer = new RTCSessionDescription({ type: 'offer', sdp: e.sdp });
  15677. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15678. return _this18._connection.setRemoteDescription(offer);
  15679. }).then(function () {
  15680. if (_this18._remoteHold === true && hold === false) {
  15681. _this18._remoteHold = false;
  15682. _this18._onunhold('remote');
  15683. } else if (_this18._remoteHold === false && hold === true) {
  15684. _this18._remoteHold = true;
  15685. _this18._onhold('remote');
  15686. }
  15687. _this18._createLocalDescription('answer', function (answerSdp) {
  15688. var extraHeaders = ['Contact: ' + _this18._contact];
  15689. _this18._handleSessionTimersInIncomingRequest(request, extraHeaders);
  15690. request.reply(200, null, extraHeaders, answerSdp);
  15691. // If callback is given execute it.
  15692. if (typeof data.callback === 'function') {
  15693. data.callback();
  15694. }
  15695. }, function () {
  15696. request.reply(500);
  15697. });
  15698. }).catch(function (error) {
  15699. request.reply(488);
  15700. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15701. _this18.emit('peerconnection:setremotedescriptionfailed', error);
  15702. });
  15703. }
  15704. /**
  15705. * In dialog Refer Reception
  15706. */
  15707. }, {
  15708. key: '_receiveRefer',
  15709. value: function _receiveRefer(request) {
  15710. var _this19 = this;
  15711. debug('receiveRefer()');
  15712. if (_typeof(request.refer_to) === undefined) {
  15713. debug('no Refer-To header field present in REFER');
  15714. request.reply(400);
  15715. return;
  15716. }
  15717. if (request.refer_to.uri.scheme !== JsSIP_C.SIP) {
  15718. debug('Refer-To header field points to a non-SIP URI scheme');
  15719. request.reply(416);
  15720. return;
  15721. }
  15722. // Reply before the transaction timer expires.
  15723. request.reply(202);
  15724. var notifier = new RTCSession_ReferNotifier(this, request.cseq);
  15725. debug('emit "refer"');
  15726. // Emit 'refer'.
  15727. this.emit('refer', {
  15728. request: request,
  15729. accept: function accept(initCallback, options) {
  15730. _accept.call(_this19, initCallback, options);
  15731. },
  15732. reject: function reject() {
  15733. _reject.call(_this19);
  15734. }
  15735. });
  15736. function _accept(initCallback) {
  15737. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  15738. initCallback = typeof initCallback === 'function' ? initCallback : null;
  15739. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15740. return false;
  15741. }
  15742. var session = new RTCSession(this._ua);
  15743. session.on('progress', function (_ref2) {
  15744. var response = _ref2.response;
  15745. notifier.notify(response.status_code, response.reason_phrase);
  15746. });
  15747. session.on('accepted', function (_ref3) {
  15748. var response = _ref3.response;
  15749. notifier.notify(response.status_code, response.reason_phrase);
  15750. });
  15751. session.on('failed', function (_ref4) {
  15752. var message = _ref4.message,
  15753. cause = _ref4.cause;
  15754. if (message) {
  15755. notifier.notify(message.status_code, message.reason_phrase);
  15756. } else {
  15757. notifier.notify(487, cause);
  15758. }
  15759. });
  15760. // Consider the Replaces header present in the Refer-To URI.
  15761. if (request.refer_to.uri.hasHeader('replaces')) {
  15762. var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces'));
  15763. options.extraHeaders = Utils.cloneArray(options.extraHeaders);
  15764. options.extraHeaders.push('Replaces: ' + replaces);
  15765. }
  15766. session.connect(request.refer_to.uri.toAor(), options, initCallback);
  15767. }
  15768. function _reject() {
  15769. notifier.notify(603);
  15770. }
  15771. }
  15772. /**
  15773. * In dialog Notify Reception
  15774. */
  15775. }, {
  15776. key: '_receiveNotify',
  15777. value: function _receiveNotify(request) {
  15778. debug('receiveNotify()');
  15779. if (_typeof(request.event) === undefined) {
  15780. request.reply(400);
  15781. }
  15782. switch (request.event.event) {
  15783. case 'refer':
  15784. {
  15785. var id = void 0;
  15786. var referSubscriber = void 0;
  15787. if (request.event.params && request.event.params.id) {
  15788. id = request.event.params.id;
  15789. referSubscriber = this._referSubscribers[id];
  15790. } else if (Object.keys(this._referSubscribers).length === 1) {
  15791. referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]];
  15792. } else {
  15793. request.reply(400, 'Missing event id parameter');
  15794. return;
  15795. }
  15796. if (!referSubscriber) {
  15797. request.reply(481, 'Subscription does not exist');
  15798. return;
  15799. }
  15800. referSubscriber.receiveNotify(request);
  15801. request.reply(200);
  15802. break;
  15803. }
  15804. default:
  15805. {
  15806. request.reply(489);
  15807. }
  15808. }
  15809. }
  15810. /**
  15811. * INVITE with Replaces Reception
  15812. */
  15813. }, {
  15814. key: '_receiveReplaces',
  15815. value: function _receiveReplaces(request) {
  15816. var _this21 = this;
  15817. debug('receiveReplaces()');
  15818. function _accept2(initCallback) {
  15819. var _this20 = this;
  15820. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15821. return false;
  15822. }
  15823. var session = new RTCSession(this._ua);
  15824. // Terminate the current session when the new one is confirmed.
  15825. session.on('confirmed', function () {
  15826. _this20.terminate();
  15827. });
  15828. session.init_incoming(request, initCallback);
  15829. }
  15830. function _reject2() {
  15831. debug('Replaced INVITE rejected by the user');
  15832. request.reply(486);
  15833. }
  15834. // Emit 'replace'.
  15835. this.emit('replaces', {
  15836. request: request,
  15837. accept: function accept(initCallback) {
  15838. _accept2.call(_this21, initCallback);
  15839. },
  15840. reject: function reject() {
  15841. _reject2.call(_this21);
  15842. }
  15843. });
  15844. }
  15845. /**
  15846. * Initial Request Sender
  15847. */
  15848. }, {
  15849. key: '_sendInitialRequest',
  15850. value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) {
  15851. var _this22 = this;
  15852. var request_sender = new RequestSender(this._ua, this._request, {
  15853. onRequestTimeout: function onRequestTimeout() {
  15854. _this22.onRequestTimeout();
  15855. },
  15856. onTransportError: function onTransportError() {
  15857. _this22.onTransportError();
  15858. },
  15859. // Update the request on authentication.
  15860. onAuthenticated: function onAuthenticated(request) {
  15861. _this22._request = request;
  15862. },
  15863. onReceiveResponse: function onReceiveResponse(response) {
  15864. _this22._receiveInviteResponse(response);
  15865. }
  15866. });
  15867. // If a local MediaStream is given use it.
  15868. if (mediaStream) {
  15869. // Wait a bit so the app can set events such as 'peerconnection' and 'connecting'.
  15870. setTimeout(function () {
  15871. userMediaSucceeded.call(_this22, mediaStream);
  15872. });
  15873. // If at least audio or video is requested prompt getUserMedia.
  15874. } else if (mediaConstraints.audio || mediaConstraints.video) {
  15875. this._localMediaStreamLocallyGenerated = true;
  15876. navigator.mediaDevices.getUserMedia(mediaConstraints).then(userMediaSucceeded.bind(this)).catch(function (error) {
  15877. userMediaFailed.call(_this22, error);
  15878. debugerror('emit "getusermediafailed" [error:%o]', error);
  15879. _this22.emit('getusermediafailed', error);
  15880. });
  15881. // Otherwise don't prompt getUserMedia.
  15882. } else {
  15883. userMediaSucceeded.call(this, null);
  15884. }
  15885. // User media succeeded.
  15886. function userMediaSucceeded(stream) {
  15887. if (this._status === C.STATUS_TERMINATED) {
  15888. return;
  15889. }
  15890. this._localMediaStream = stream;
  15891. if (stream) {
  15892. this._connection.addStream(stream);
  15893. }
  15894. this._connecting(this._request);
  15895. this._createLocalDescription('offer', rtcSucceeded.bind(this), rtcFailed.bind(this), rtcOfferConstraints);
  15896. }
  15897. // User media failed.
  15898. function userMediaFailed() {
  15899. if (this._status === C.STATUS_TERMINATED) {
  15900. return;
  15901. }
  15902. this._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  15903. }
  15904. function rtcSucceeded(desc) {
  15905. if (this._is_canceled || this._status === C.STATUS_TERMINATED) {
  15906. return;
  15907. }
  15908. this._request.body = desc;
  15909. this._status = C.STATUS_INVITE_SENT;
  15910. debug('emit "sending" [request:%o]', this._request);
  15911. // Emit 'sending' so the app can mangle the body before the request is sent.
  15912. this.emit('sending', {
  15913. request: this._request
  15914. });
  15915. request_sender.send();
  15916. }
  15917. function rtcFailed() {
  15918. if (this._status === C.STATUS_TERMINATED) {
  15919. return;
  15920. }
  15921. this._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR);
  15922. }
  15923. }
  15924. /**
  15925. * Reception of Response for Initial INVITE
  15926. */
  15927. }, {
  15928. key: '_receiveInviteResponse',
  15929. value: function _receiveInviteResponse(response) {
  15930. var _this23 = this;
  15931. debug('receiveInviteResponse()');
  15932. // Handle 2XX retransmissions and responses from forked requests.
  15933. if (this._dialog && response.status_code >= 200 && response.status_code <= 299) {
  15934. /*
  15935. * If it is a retransmission from the endpoint that established
  15936. * the dialog, send an ACK
  15937. */
  15938. 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) {
  15939. this.sendRequest(JsSIP_C.ACK);
  15940. return;
  15941. }
  15942. // If not, send an ACK and terminate.
  15943. else {
  15944. var dialog = new Dialog(this, response, 'UAC');
  15945. if (dialog.error !== undefined) {
  15946. debug(dialog.error);
  15947. return;
  15948. }
  15949. this.sendRequest(JsSIP_C.ACK);
  15950. this.sendRequest(JsSIP_C.BYE);
  15951. return;
  15952. }
  15953. }
  15954. // Proceed to cancellation if the user requested.
  15955. if (this._is_canceled) {
  15956. if (response.status_code >= 100 && response.status_code < 200) {
  15957. this._request.cancel(this._cancel_reason);
  15958. } else if (response.status_code >= 200 && response.status_code < 299) {
  15959. this._acceptAndTerminate(response);
  15960. }
  15961. return;
  15962. }
  15963. if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) {
  15964. return;
  15965. }
  15966. switch (true) {
  15967. case /^100$/.test(response.status_code):
  15968. this._status = C.STATUS_1XX_RECEIVED;
  15969. break;
  15970. case /^1[0-9]{2}$/.test(response.status_code):
  15971. {
  15972. // Do nothing with 1xx responses without To tag.
  15973. if (!response.to_tag) {
  15974. debug('1xx response received without to tag');
  15975. break;
  15976. }
  15977. // Create Early Dialog if 1XX comes with contact.
  15978. if (response.hasHeader('contact')) {
  15979. // An error on dialog creation will fire 'failed' event.
  15980. if (!this._createDialog(response, 'UAC', true)) {
  15981. break;
  15982. }
  15983. }
  15984. this._status = C.STATUS_1XX_RECEIVED;
  15985. this._progress('remote', response);
  15986. if (!response.body) {
  15987. break;
  15988. }
  15989. var e = { originator: 'remote', type: 'answer', sdp: response.body };
  15990. debug('emit "sdp"');
  15991. this.emit('sdp', e);
  15992. var answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp });
  15993. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15994. return _this23._connection.setRemoteDescription(answer);
  15995. }).catch(function (error) {
  15996. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15997. _this23.emit('peerconnection:setremotedescriptionfailed', error);
  15998. });
  15999. break;
  16000. }
  16001. case /^2[0-9]{2}$/.test(response.status_code):
  16002. {
  16003. this._status = C.STATUS_CONFIRMED;
  16004. if (!response.body) {
  16005. this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP);
  16006. this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  16007. break;
  16008. }
  16009. // An error on dialog creation will fire 'failed' event.
  16010. if (!this._createDialog(response, 'UAC')) {
  16011. break;
  16012. }
  16013. var _e = { originator: 'remote', type: 'answer', sdp: response.body };
  16014. debug('emit "sdp"');
  16015. this.emit('sdp', _e);
  16016. var _answer = new RTCSessionDescription({ type: 'answer', sdp: _e.sdp });
  16017. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16018. // Be ready for 200 with SDP after a 180/183 with SDP.
  16019. // We created a SDP 'answer' for it, so check the current signaling state.
  16020. if (_this23._connection.signalingState === 'stable') {
  16021. return _this23._connection.createOffer().then(function (offer) {
  16022. return _this23._connection.setLocalDescription(offer);
  16023. }).catch(function (error) {
  16024. _this23._acceptAndTerminate(response, 500, error.toString());
  16025. _this23._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR);
  16026. debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error);
  16027. _this23.emit('peerconnection:setlocaldescriptionfailed', error);
  16028. });
  16029. }
  16030. }).then(function () {
  16031. _this23._connection.setRemoteDescription(_answer).then(function () {
  16032. // Handle Session Timers.
  16033. _this23._handleSessionTimersInIncomingResponse(response);
  16034. _this23._accepted('remote', response);
  16035. _this23.sendRequest(JsSIP_C.ACK);
  16036. _this23._confirmed('local', null);
  16037. }).catch(function (error) {
  16038. _this23._acceptAndTerminate(response, 488, 'Not Acceptable Here');
  16039. _this23._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  16040. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16041. _this23.emit('peerconnection:setremotedescriptionfailed', error);
  16042. });
  16043. });
  16044. break;
  16045. }
  16046. default:
  16047. {
  16048. var cause = Utils.sipErrorCause(response.status_code);
  16049. this._failed('remote', response, cause);
  16050. }
  16051. }
  16052. }
  16053. /**
  16054. * Send Re-INVITE
  16055. */
  16056. }, {
  16057. key: '_sendReinvite',
  16058. value: function _sendReinvite() {
  16059. var _this24 = this;
  16060. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16061. debug('sendReinvite()');
  16062. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16063. var eventHandlers = options.eventHandlers || {};
  16064. var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
  16065. var succeeded = false;
  16066. extraHeaders.push('Contact: ' + this._contact);
  16067. extraHeaders.push('Content-Type: application/sdp');
  16068. // Session Timers.
  16069. if (this._sessionTimers.running) {
  16070. extraHeaders.push('Session-Expires: ' + this._sessionTimers.currentExpires + ';refresher=' + (this._sessionTimers.refresher ? 'uac' : 'uas'));
  16071. }
  16072. this._createLocalDescription('offer', function (sdp) {
  16073. sdp = _this24._mangleOffer(sdp);
  16074. _this24.sendRequest(JsSIP_C.INVITE, {
  16075. extraHeaders: extraHeaders,
  16076. body: sdp,
  16077. eventHandlers: {
  16078. onSuccessResponse: function onSuccessResponse(response) {
  16079. onSucceeded.call(_this24, response);
  16080. succeeded = true;
  16081. },
  16082. onErrorResponse: function onErrorResponse(response) {
  16083. onFailed.call(_this24, response);
  16084. },
  16085. onTransportError: function onTransportError() {
  16086. _this24.onTransportError(); // Do nothing because session ends.
  16087. },
  16088. onRequestTimeout: function onRequestTimeout() {
  16089. _this24.onRequestTimeout(); // Do nothing because session ends.
  16090. },
  16091. onDialogError: function onDialogError() {
  16092. _this24.onDialogError(); // Do nothing because session ends.
  16093. }
  16094. }
  16095. });
  16096. }, function () {
  16097. onFailed();
  16098. },
  16099. // RTC constraints.
  16100. rtcOfferConstraints);
  16101. function onSucceeded(response) {
  16102. var _this25 = this;
  16103. if (this._status === C.STATUS_TERMINATED) {
  16104. return;
  16105. }
  16106. this.sendRequest(JsSIP_C.ACK);
  16107. // If it is a 2XX retransmission exit now.
  16108. if (succeeded) {
  16109. return;
  16110. }
  16111. // Handle Session Timers.
  16112. this._handleSessionTimersInIncomingResponse(response);
  16113. // Must have SDP answer.
  16114. if (!response.body) {
  16115. onFailed.call(this);
  16116. return;
  16117. } else if (response.getHeader('Content-Type') !== 'application/sdp') {
  16118. onFailed.call(this);
  16119. return;
  16120. }
  16121. var e = { originator: 'remote', type: 'answer', sdp: response.body };
  16122. debug('emit "sdp"');
  16123. this.emit('sdp', e);
  16124. var answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp });
  16125. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16126. return _this25._connection.setRemoteDescription(answer);
  16127. }).then(function () {
  16128. if (eventHandlers.succeeded) {
  16129. eventHandlers.succeeded(response);
  16130. }
  16131. }).catch(function (error) {
  16132. onFailed.call(_this25);
  16133. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16134. _this25.emit('peerconnection:setremotedescriptionfailed', error);
  16135. });
  16136. }
  16137. function onFailed(response) {
  16138. if (eventHandlers.failed) {
  16139. eventHandlers.failed(response);
  16140. }
  16141. }
  16142. }
  16143. /**
  16144. * Send UPDATE
  16145. */
  16146. }, {
  16147. key: '_sendUpdate',
  16148. value: function _sendUpdate() {
  16149. var _this26 = this;
  16150. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16151. debug('sendUpdate()');
  16152. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16153. var eventHandlers = options.eventHandlers || {};
  16154. var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
  16155. var sdpOffer = options.sdpOffer || false;
  16156. var succeeded = false;
  16157. extraHeaders.push('Contact: ' + this._contact);
  16158. // Session Timers.
  16159. if (this._sessionTimers.running) {
  16160. extraHeaders.push('Session-Expires: ' + this._sessionTimers.currentExpires + ';refresher=' + (this._sessionTimers.refresher ? 'uac' : 'uas'));
  16161. }
  16162. if (sdpOffer) {
  16163. extraHeaders.push('Content-Type: application/sdp');
  16164. this._createLocalDescription('offer', function (sdp) {
  16165. sdp = _this26._mangleOffer(sdp);
  16166. _this26.sendRequest(JsSIP_C.UPDATE, {
  16167. extraHeaders: extraHeaders,
  16168. body: sdp,
  16169. eventHandlers: {
  16170. onSuccessResponse: function onSuccessResponse(response) {
  16171. onSucceeded.call(_this26, response);
  16172. succeeded = true;
  16173. },
  16174. onErrorResponse: function onErrorResponse(response) {
  16175. onFailed.call(_this26, response);
  16176. },
  16177. onTransportError: function onTransportError() {
  16178. _this26.onTransportError(); // Do nothing because session ends.
  16179. },
  16180. onRequestTimeout: function onRequestTimeout() {
  16181. _this26.onRequestTimeout(); // Do nothing because session ends.
  16182. },
  16183. onDialogError: function onDialogError() {
  16184. _this26.onDialogError(); // Do nothing because session ends.
  16185. }
  16186. }
  16187. });
  16188. }, function () {
  16189. onFailed.call(_this26);
  16190. },
  16191. // RTC constraints.
  16192. rtcOfferConstraints);
  16193. }
  16194. // No SDP.
  16195. else {
  16196. this.sendRequest(JsSIP_C.UPDATE, {
  16197. extraHeaders: extraHeaders,
  16198. eventHandlers: {
  16199. onSuccessResponse: function onSuccessResponse(response) {
  16200. onSucceeded.call(_this26, response);
  16201. },
  16202. onErrorResponse: function onErrorResponse(response) {
  16203. onFailed.call(_this26, response);
  16204. },
  16205. onTransportError: function onTransportError() {
  16206. _this26.onTransportError(); // Do nothing because session ends.
  16207. },
  16208. onRequestTimeout: function onRequestTimeout() {
  16209. _this26.onRequestTimeout(); // Do nothing because session ends.
  16210. },
  16211. onDialogError: function onDialogError() {
  16212. _this26.onDialogError(); // Do nothing because session ends.
  16213. }
  16214. }
  16215. });
  16216. }
  16217. function onSucceeded(response) {
  16218. var _this27 = this;
  16219. if (this._status === C.STATUS_TERMINATED) {
  16220. return;
  16221. }
  16222. // If it is a 2XX retransmission exit now.
  16223. if (succeeded) {
  16224. return;
  16225. }
  16226. // Handle Session Timers.
  16227. this._handleSessionTimersInIncomingResponse(response);
  16228. // Must have SDP answer.
  16229. if (sdpOffer) {
  16230. if (!response.body) {
  16231. onFailed.call(this);
  16232. return;
  16233. } else if (response.getHeader('Content-Type') !== 'application/sdp') {
  16234. onFailed.call(this);
  16235. return;
  16236. }
  16237. var e = { originator: 'remote', type: 'answer', sdp: response.body };
  16238. debug('emit "sdp"');
  16239. this.emit('sdp', e);
  16240. var answer = new RTCSessionDescription({ type: 'answer', sdp: e.sdp });
  16241. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16242. return _this27._connection.setRemoteDescription(answer);
  16243. }).then(function () {
  16244. if (eventHandlers.succeeded) {
  16245. eventHandlers.succeeded(response);
  16246. }
  16247. }).catch(function (error) {
  16248. onFailed.call(_this27);
  16249. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16250. _this27.emit('peerconnection:setremotedescriptionfailed', error);
  16251. });
  16252. }
  16253. // No SDP answer.
  16254. else if (eventHandlers.succeeded) {
  16255. eventHandlers.succeeded(response);
  16256. }
  16257. }
  16258. function onFailed(response) {
  16259. if (eventHandlers.failed) {
  16260. eventHandlers.failed(response);
  16261. }
  16262. }
  16263. }
  16264. }, {
  16265. key: '_acceptAndTerminate',
  16266. value: function _acceptAndTerminate(response, status_code, reason_phrase) {
  16267. debug('acceptAndTerminate()');
  16268. var extraHeaders = [];
  16269. if (status_code) {
  16270. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  16271. extraHeaders.push('Reason: SIP ;cause=' + status_code + '; text="' + reason_phrase + '"');
  16272. }
  16273. // An error on dialog creation will fire 'failed' event.
  16274. if (this._dialog || this._createDialog(response, 'UAC')) {
  16275. this.sendRequest(JsSIP_C.ACK);
  16276. this.sendRequest(JsSIP_C.BYE, {
  16277. extraHeaders: extraHeaders
  16278. });
  16279. }
  16280. // Update session status.
  16281. this._status = C.STATUS_TERMINATED;
  16282. }
  16283. /**
  16284. * Correctly set the SDP direction attributes if the call is on local hold
  16285. */
  16286. }, {
  16287. key: '_mangleOffer',
  16288. value: function _mangleOffer(sdp) {
  16289. if (!this._localHold && !this._remoteHold) {
  16290. return sdp;
  16291. }
  16292. sdp = sdp_transform.parse(sdp);
  16293. // Local hold.
  16294. if (this._localHold && !this._remoteHold) {
  16295. debug('mangleOffer() | me on hold, mangling offer');
  16296. var _iteratorNormalCompletion6 = true;
  16297. var _didIteratorError6 = false;
  16298. var _iteratorError6 = undefined;
  16299. try {
  16300. for (var _iterator6 = sdp.media[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
  16301. var m = _step6.value;
  16302. if (holdMediaTypes.indexOf(m.type) === -1) {
  16303. continue;
  16304. }
  16305. if (!m.direction) {
  16306. m.direction = 'sendonly';
  16307. } else if (m.direction === 'sendrecv') {
  16308. m.direction = 'sendonly';
  16309. } else if (m.direction === 'recvonly') {
  16310. m.direction = 'inactive';
  16311. }
  16312. }
  16313. } catch (err) {
  16314. _didIteratorError6 = true;
  16315. _iteratorError6 = err;
  16316. } finally {
  16317. try {
  16318. if (!_iteratorNormalCompletion6 && _iterator6.return) {
  16319. _iterator6.return();
  16320. }
  16321. } finally {
  16322. if (_didIteratorError6) {
  16323. throw _iteratorError6;
  16324. }
  16325. }
  16326. }
  16327. }
  16328. // Local and remote hold.
  16329. else if (this._localHold && this._remoteHold) {
  16330. debug('mangleOffer() | both on hold, mangling offer');
  16331. var _iteratorNormalCompletion7 = true;
  16332. var _didIteratorError7 = false;
  16333. var _iteratorError7 = undefined;
  16334. try {
  16335. for (var _iterator7 = sdp.media[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
  16336. var _m = _step7.value;
  16337. if (holdMediaTypes.indexOf(_m.type) === -1) {
  16338. continue;
  16339. }
  16340. _m.direction = 'inactive';
  16341. }
  16342. } catch (err) {
  16343. _didIteratorError7 = true;
  16344. _iteratorError7 = err;
  16345. } finally {
  16346. try {
  16347. if (!_iteratorNormalCompletion7 && _iterator7.return) {
  16348. _iterator7.return();
  16349. }
  16350. } finally {
  16351. if (_didIteratorError7) {
  16352. throw _iteratorError7;
  16353. }
  16354. }
  16355. }
  16356. }
  16357. // Remote hold.
  16358. else if (this._remoteHold) {
  16359. debug('mangleOffer() | remote on hold, mangling offer');
  16360. var _iteratorNormalCompletion8 = true;
  16361. var _didIteratorError8 = false;
  16362. var _iteratorError8 = undefined;
  16363. try {
  16364. for (var _iterator8 = sdp.media[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
  16365. var _m2 = _step8.value;
  16366. if (holdMediaTypes.indexOf(_m2.type) === -1) {
  16367. continue;
  16368. }
  16369. if (!_m2.direction) {
  16370. _m2.direction = 'recvonly';
  16371. } else if (_m2.direction === 'sendrecv') {
  16372. _m2.direction = 'recvonly';
  16373. } else if (_m2.direction === 'recvonly') {
  16374. _m2.direction = 'inactive';
  16375. }
  16376. }
  16377. } catch (err) {
  16378. _didIteratorError8 = true;
  16379. _iteratorError8 = err;
  16380. } finally {
  16381. try {
  16382. if (!_iteratorNormalCompletion8 && _iterator8.return) {
  16383. _iterator8.return();
  16384. }
  16385. } finally {
  16386. if (_didIteratorError8) {
  16387. throw _iteratorError8;
  16388. }
  16389. }
  16390. }
  16391. }
  16392. return sdp_transform.write(sdp);
  16393. }
  16394. }, {
  16395. key: '_setLocalMediaStatus',
  16396. value: function _setLocalMediaStatus() {
  16397. var enableAudio = true,
  16398. enableVideo = true;
  16399. if (this._localHold || this._remoteHold) {
  16400. enableAudio = false;
  16401. enableVideo = false;
  16402. }
  16403. if (this._audioMuted) {
  16404. enableAudio = false;
  16405. }
  16406. if (this._videoMuted) {
  16407. enableVideo = false;
  16408. }
  16409. this._toogleMuteAudio(!enableAudio);
  16410. this._toogleMuteVideo(!enableVideo);
  16411. }
  16412. /**
  16413. * Handle SessionTimers for an incoming INVITE or UPDATE.
  16414. * @param {IncomingRequest} request
  16415. * @param {Array} responseExtraHeaders Extra headers for the 200 response.
  16416. */
  16417. }, {
  16418. key: '_handleSessionTimersInIncomingRequest',
  16419. value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) {
  16420. if (!this._sessionTimers.enabled) {
  16421. return;
  16422. }
  16423. var session_expires_refresher = void 0;
  16424. if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  16425. this._sessionTimers.currentExpires = request.session_expires;
  16426. session_expires_refresher = request.session_expires_refresher || 'uas';
  16427. } else {
  16428. this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
  16429. session_expires_refresher = 'uas';
  16430. }
  16431. responseExtraHeaders.push('Session-Expires: ' + this._sessionTimers.currentExpires + ';refresher=' + session_expires_refresher);
  16432. this._sessionTimers.refresher = session_expires_refresher === 'uas';
  16433. this._runSessionTimer();
  16434. }
  16435. /**
  16436. * Handle SessionTimers for an incoming response to INVITE or UPDATE.
  16437. * @param {IncomingResponse} response
  16438. */
  16439. }, {
  16440. key: '_handleSessionTimersInIncomingResponse',
  16441. value: function _handleSessionTimersInIncomingResponse(response) {
  16442. if (!this._sessionTimers.enabled) {
  16443. return;
  16444. }
  16445. var session_expires_refresher = void 0;
  16446. if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  16447. this._sessionTimers.currentExpires = response.session_expires;
  16448. session_expires_refresher = response.session_expires_refresher || 'uac';
  16449. } else {
  16450. this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
  16451. session_expires_refresher = 'uac';
  16452. }
  16453. this._sessionTimers.refresher = session_expires_refresher === 'uac';
  16454. this._runSessionTimer();
  16455. }
  16456. }, {
  16457. key: '_runSessionTimer',
  16458. value: function _runSessionTimer() {
  16459. var _this28 = this;
  16460. var expires = this._sessionTimers.currentExpires;
  16461. this._sessionTimers.running = true;
  16462. clearTimeout(this._sessionTimers.timer);
  16463. // I'm the refresher.
  16464. if (this._sessionTimers.refresher) {
  16465. this._sessionTimers.timer = setTimeout(function () {
  16466. if (_this28._status === C.STATUS_TERMINATED) {
  16467. return;
  16468. }
  16469. debug('runSessionTimer() | sending session refresh request');
  16470. if (_this28._sessionTimers.refreshMethod === JsSIP_C.UPDATE) {
  16471. _this28._sendUpdate();
  16472. } else {
  16473. _this28._sendReinvite();
  16474. }
  16475. }, expires * 500); // Half the given interval (as the RFC states).
  16476. }
  16477. // I'm not the refresher.
  16478. else {
  16479. this._sessionTimers.timer = setTimeout(function () {
  16480. if (_this28._status === C.STATUS_TERMINATED) {
  16481. return;
  16482. }
  16483. debugerror('runSessionTimer() | timer expired, terminating the session');
  16484. _this28.terminate({
  16485. cause: JsSIP_C.causes.REQUEST_TIMEOUT,
  16486. status_code: 408,
  16487. reason_phrase: 'Session Timer Expired'
  16488. });
  16489. }, expires * 1100);
  16490. }
  16491. }
  16492. }, {
  16493. key: '_toogleMuteAudio',
  16494. value: function _toogleMuteAudio(mute) {
  16495. var streams = this._connection.getLocalStreams();
  16496. var _iteratorNormalCompletion9 = true;
  16497. var _didIteratorError9 = false;
  16498. var _iteratorError9 = undefined;
  16499. try {
  16500. for (var _iterator9 = streams[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
  16501. var stream = _step9.value;
  16502. var tracks = stream.getAudioTracks();
  16503. var _iteratorNormalCompletion10 = true;
  16504. var _didIteratorError10 = false;
  16505. var _iteratorError10 = undefined;
  16506. try {
  16507. for (var _iterator10 = tracks[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
  16508. var track = _step10.value;
  16509. track.enabled = !mute;
  16510. }
  16511. } catch (err) {
  16512. _didIteratorError10 = true;
  16513. _iteratorError10 = err;
  16514. } finally {
  16515. try {
  16516. if (!_iteratorNormalCompletion10 && _iterator10.return) {
  16517. _iterator10.return();
  16518. }
  16519. } finally {
  16520. if (_didIteratorError10) {
  16521. throw _iteratorError10;
  16522. }
  16523. }
  16524. }
  16525. }
  16526. } catch (err) {
  16527. _didIteratorError9 = true;
  16528. _iteratorError9 = err;
  16529. } finally {
  16530. try {
  16531. if (!_iteratorNormalCompletion9 && _iterator9.return) {
  16532. _iterator9.return();
  16533. }
  16534. } finally {
  16535. if (_didIteratorError9) {
  16536. throw _iteratorError9;
  16537. }
  16538. }
  16539. }
  16540. }
  16541. }, {
  16542. key: '_toogleMuteVideo',
  16543. value: function _toogleMuteVideo(mute) {
  16544. var streams = this._connection.getLocalStreams();
  16545. var _iteratorNormalCompletion11 = true;
  16546. var _didIteratorError11 = false;
  16547. var _iteratorError11 = undefined;
  16548. try {
  16549. for (var _iterator11 = streams[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
  16550. var stream = _step11.value;
  16551. var tracks = stream.getVideoTracks();
  16552. var _iteratorNormalCompletion12 = true;
  16553. var _didIteratorError12 = false;
  16554. var _iteratorError12 = undefined;
  16555. try {
  16556. for (var _iterator12 = tracks[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
  16557. var track = _step12.value;
  16558. track.enabled = !mute;
  16559. }
  16560. } catch (err) {
  16561. _didIteratorError12 = true;
  16562. _iteratorError12 = err;
  16563. } finally {
  16564. try {
  16565. if (!_iteratorNormalCompletion12 && _iterator12.return) {
  16566. _iterator12.return();
  16567. }
  16568. } finally {
  16569. if (_didIteratorError12) {
  16570. throw _iteratorError12;
  16571. }
  16572. }
  16573. }
  16574. }
  16575. } catch (err) {
  16576. _didIteratorError11 = true;
  16577. _iteratorError11 = err;
  16578. } finally {
  16579. try {
  16580. if (!_iteratorNormalCompletion11 && _iterator11.return) {
  16581. _iterator11.return();
  16582. }
  16583. } finally {
  16584. if (_didIteratorError11) {
  16585. throw _iteratorError11;
  16586. }
  16587. }
  16588. }
  16589. }
  16590. }, {
  16591. key: '_newRTCSession',
  16592. value: function _newRTCSession(originator, request) {
  16593. debug('newRTCSession()');
  16594. this._ua.newRTCSession(this, {
  16595. originator: originator,
  16596. session: this,
  16597. request: request
  16598. });
  16599. }
  16600. }, {
  16601. key: '_connecting',
  16602. value: function _connecting(request) {
  16603. debug('session connecting');
  16604. debug('emit "connecting"');
  16605. this.emit('connecting', {
  16606. request: request
  16607. });
  16608. }
  16609. }, {
  16610. key: '_progress',
  16611. value: function _progress(originator, response) {
  16612. debug('session progress');
  16613. debug('emit "progress"');
  16614. this.emit('progress', {
  16615. originator: originator,
  16616. response: response || null
  16617. });
  16618. }
  16619. }, {
  16620. key: '_accepted',
  16621. value: function _accepted(originator, message) {
  16622. debug('session accepted');
  16623. this._start_time = new Date();
  16624. debug('emit "accepted"');
  16625. this.emit('accepted', {
  16626. originator: originator,
  16627. response: message || null
  16628. });
  16629. }
  16630. }, {
  16631. key: '_confirmed',
  16632. value: function _confirmed(originator, ack) {
  16633. debug('session confirmed');
  16634. this._is_confirmed = true;
  16635. debug('emit "confirmed"');
  16636. this.emit('confirmed', {
  16637. originator: originator,
  16638. ack: ack || null
  16639. });
  16640. }
  16641. }, {
  16642. key: '_ended',
  16643. value: function _ended(originator, message, cause) {
  16644. debug('session ended');
  16645. this._end_time = new Date();
  16646. this._close();
  16647. debug('emit "ended"');
  16648. this.emit('ended', {
  16649. originator: originator,
  16650. message: message || null,
  16651. cause: cause
  16652. });
  16653. }
  16654. }, {
  16655. key: '_failed',
  16656. value: function _failed(originator, message, cause) {
  16657. debug('session failed');
  16658. this._close();
  16659. debug('emit "failed"');
  16660. this.emit('failed', {
  16661. originator: originator,
  16662. message: message || null,
  16663. cause: cause
  16664. });
  16665. }
  16666. }, {
  16667. key: '_onhold',
  16668. value: function _onhold(originator) {
  16669. debug('session onhold');
  16670. this._setLocalMediaStatus();
  16671. debug('emit "hold"');
  16672. this.emit('hold', {
  16673. originator: originator
  16674. });
  16675. }
  16676. }, {
  16677. key: '_onunhold',
  16678. value: function _onunhold(originator) {
  16679. debug('session onunhold');
  16680. this._setLocalMediaStatus();
  16681. debug('emit "unhold"');
  16682. this.emit('unhold', {
  16683. originator: originator
  16684. });
  16685. }
  16686. }, {
  16687. key: '_onmute',
  16688. value: function _onmute(_ref5) {
  16689. var audio = _ref5.audio,
  16690. video = _ref5.video;
  16691. debug('session onmute');
  16692. this._setLocalMediaStatus();
  16693. debug('emit "muted"');
  16694. this.emit('muted', {
  16695. audio: audio,
  16696. video: video
  16697. });
  16698. }
  16699. }, {
  16700. key: '_onunmute',
  16701. value: function _onunmute(_ref6) {
  16702. var audio = _ref6.audio,
  16703. video = _ref6.video;
  16704. debug('session onunmute');
  16705. this._setLocalMediaStatus();
  16706. debug('emit "unmuted"');
  16707. this.emit('unmuted', {
  16708. audio: audio,
  16709. video: video
  16710. });
  16711. }
  16712. }, {
  16713. key: 'C',
  16714. get: function get() {
  16715. return C;
  16716. }
  16717. // Expose session failed/ended causes as a property of the RTCSession instance.
  16718. }, {
  16719. key: 'causes',
  16720. get: function get() {
  16721. return JsSIP_C.causes;
  16722. }
  16723. }, {
  16724. key: 'id',
  16725. get: function get() {
  16726. return this._id;
  16727. }
  16728. }, {
  16729. key: 'connection',
  16730. get: function get() {
  16731. return this._connection;
  16732. }
  16733. }, {
  16734. key: 'direction',
  16735. get: function get() {
  16736. return this._direction;
  16737. }
  16738. }, {
  16739. key: 'local_identity',
  16740. get: function get() {
  16741. return this._local_identity;
  16742. }
  16743. }, {
  16744. key: 'remote_identity',
  16745. get: function get() {
  16746. return this._remote_identity;
  16747. }
  16748. }, {
  16749. key: 'start_time',
  16750. get: function get() {
  16751. return this._start_time;
  16752. }
  16753. }, {
  16754. key: 'end_time',
  16755. get: function get() {
  16756. return this._end_time;
  16757. }
  16758. }, {
  16759. key: 'data',
  16760. get: function get() {
  16761. return this._data;
  16762. },
  16763. set: function set(_data) {
  16764. this._data = _data;
  16765. }
  16766. }, {
  16767. key: 'status',
  16768. get: function get() {
  16769. return this._status;
  16770. }
  16771. }]);
  16772. return RTCSession;
  16773. }(EventEmitter);
  16774. },{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":13,"./RTCSession/Info":14,"./RTCSession/ReferNotifier":15,"./RTCSession/ReferSubscriber":16,"./RequestSender":18,"./SIPMessage":19,"./Timers":21,"./Transactions":22,"./Utils":26,"debug":29,"events":31,"sdp-transform":36}],13:[function(require,module,exports){
  16775. 'use strict';
  16776. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  16777. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16778. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  16779. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  16780. var EventEmitter = require('events').EventEmitter;
  16781. var JsSIP_C = require('../Constants');
  16782. var Exceptions = require('../Exceptions');
  16783. var Utils = require('../Utils');
  16784. var debug = require('debug')('JsSIP:RTCSession:DTMF');
  16785. var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF');
  16786. debugerror.log = console.warn.bind(console);
  16787. var C = {
  16788. MIN_DURATION: 70,
  16789. MAX_DURATION: 6000,
  16790. DEFAULT_DURATION: 100,
  16791. MIN_INTER_TONE_GAP: 50,
  16792. DEFAULT_INTER_TONE_GAP: 500
  16793. };
  16794. module.exports = function (_EventEmitter) {
  16795. _inherits(DTMF, _EventEmitter);
  16796. function DTMF(session) {
  16797. _classCallCheck(this, DTMF);
  16798. var _this = _possibleConstructorReturn(this, (DTMF.__proto__ || Object.getPrototypeOf(DTMF)).call(this));
  16799. _this._session = session;
  16800. _this._direction = null;
  16801. _this._tone = null;
  16802. _this._duration = null;
  16803. _this._request = null;
  16804. return _this;
  16805. }
  16806. _createClass(DTMF, [{
  16807. key: 'send',
  16808. value: function send(tone) {
  16809. var _this2 = this;
  16810. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  16811. if (tone === undefined) {
  16812. throw new TypeError('Not enough arguments');
  16813. }
  16814. this._direction = 'outgoing';
  16815. // Check RTCSession Status.
  16816. if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
  16817. throw new Exceptions.InvalidStateError(this._session.status);
  16818. }
  16819. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16820. this.eventHandlers = options.eventHandlers || {};
  16821. // Check tone type.
  16822. if (typeof tone === 'string') {
  16823. tone = tone.toUpperCase();
  16824. } else if (typeof tone === 'number') {
  16825. tone = tone.toString();
  16826. } else {
  16827. throw new TypeError('Invalid tone: ' + tone);
  16828. }
  16829. // Check tone value.
  16830. if (!tone.match(/^[0-9A-DR#*]$/)) {
  16831. throw new TypeError('Invalid tone: ' + tone);
  16832. } else {
  16833. this._tone = tone;
  16834. }
  16835. // Duration is checked/corrected in RTCSession.
  16836. this._duration = options.duration;
  16837. extraHeaders.push('Content-Type: application/dtmf-relay');
  16838. var body = 'Signal=' + this._tone + '\r\n';
  16839. body += 'Duration=' + this._duration;
  16840. this._session.newDTMF({
  16841. originator: 'local',
  16842. dtmf: this,
  16843. request: this._request
  16844. });
  16845. this._session.sendRequest(JsSIP_C.INFO, {
  16846. extraHeaders: extraHeaders,
  16847. eventHandlers: {
  16848. onSuccessResponse: function onSuccessResponse(response) {
  16849. _this2.emit('succeeded', {
  16850. originator: 'remote',
  16851. response: response
  16852. });
  16853. },
  16854. onErrorResponse: function onErrorResponse(response) {
  16855. if (_this2.eventHandlers.onFailed) {
  16856. _this2.eventHandlers.onFailed();
  16857. }
  16858. _this2.emit('failed', {
  16859. originator: 'remote',
  16860. response: response
  16861. });
  16862. },
  16863. onRequestTimeout: function onRequestTimeout() {
  16864. _this2._session.onRequestTimeout();
  16865. },
  16866. onTransportError: function onTransportError() {
  16867. _this2._session.onTransportError();
  16868. },
  16869. onDialogError: function onDialogError() {
  16870. _this2._session.onDialogError();
  16871. }
  16872. },
  16873. body: body
  16874. });
  16875. }
  16876. }, {
  16877. key: 'init_incoming',
  16878. value: function init_incoming(request) {
  16879. var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;
  16880. var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;
  16881. this._direction = 'incoming';
  16882. this._request = request;
  16883. request.reply(200);
  16884. if (request.body) {
  16885. var body = request.body.split('\n');
  16886. if (body.length >= 1) {
  16887. if (reg_tone.test(body[0])) {
  16888. this._tone = body[0].replace(reg_tone, '$2');
  16889. }
  16890. }
  16891. if (body.length >= 2) {
  16892. if (reg_duration.test(body[1])) {
  16893. this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10);
  16894. }
  16895. }
  16896. }
  16897. if (!this._duration) {
  16898. this._duration = C.DEFAULT_DURATION;
  16899. }
  16900. if (!this._tone) {
  16901. debug('invalid INFO DTMF received, discarded');
  16902. } else {
  16903. this._session.newDTMF({
  16904. originator: 'remote',
  16905. dtmf: this,
  16906. request: request
  16907. });
  16908. }
  16909. }
  16910. }, {
  16911. key: 'tone',
  16912. get: function get() {
  16913. return this._tone;
  16914. }
  16915. }, {
  16916. key: 'duration',
  16917. get: function get() {
  16918. return this._duration;
  16919. }
  16920. }]);
  16921. return DTMF;
  16922. }(EventEmitter);
  16923. /**
  16924. * Expose C object.
  16925. */
  16926. module.exports.C = C;
  16927. },{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":29,"events":31}],14:[function(require,module,exports){
  16928. 'use strict';
  16929. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  16930. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16931. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  16932. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  16933. var EventEmitter = require('events').EventEmitter;
  16934. var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info');
  16935. debugerror.log = console.warn.bind(console);
  16936. var JsSIP_C = require('../Constants');
  16937. var Exceptions = require('../Exceptions');
  16938. var Utils = require('../Utils');
  16939. module.exports = function (_EventEmitter) {
  16940. _inherits(Info, _EventEmitter);
  16941. function Info(session) {
  16942. _classCallCheck(this, Info);
  16943. var _this = _possibleConstructorReturn(this, (Info.__proto__ || Object.getPrototypeOf(Info)).call(this));
  16944. _this._session = session;
  16945. _this._direction = null;
  16946. _this._contentType = null;
  16947. _this._body = null;
  16948. return _this;
  16949. }
  16950. _createClass(Info, [{
  16951. key: 'send',
  16952. value: function send(contentType, body) {
  16953. var _this2 = this;
  16954. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  16955. this._direction = 'outgoing';
  16956. if (contentType === undefined) {
  16957. throw new TypeError('Not enough arguments');
  16958. }
  16959. // Check RTCSession Status.
  16960. if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
  16961. throw new Exceptions.InvalidStateError(this._session.status);
  16962. }
  16963. this._contentType = contentType;
  16964. this._body = body;
  16965. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16966. extraHeaders.push('Content-Type: ' + contentType);
  16967. this._session.newInfo({
  16968. originator: 'local',
  16969. info: this,
  16970. request: this.request
  16971. });
  16972. this._session.sendRequest(JsSIP_C.INFO, {
  16973. extraHeaders: extraHeaders,
  16974. eventHandlers: {
  16975. onSuccessResponse: function onSuccessResponse(response) {
  16976. _this2.emit('succeeded', {
  16977. originator: 'remote',
  16978. response: response
  16979. });
  16980. },
  16981. onErrorResponse: function onErrorResponse(response) {
  16982. _this2.emit('failed', {
  16983. originator: 'remote',
  16984. response: response
  16985. });
  16986. },
  16987. onTransportError: function onTransportError() {
  16988. _this2._session.onTransportError();
  16989. },
  16990. onRequestTimeout: function onRequestTimeout() {
  16991. _this2._session.onRequestTimeout();
  16992. },
  16993. onDialogError: function onDialogError() {
  16994. _this2._session.onDialogError();
  16995. }
  16996. },
  16997. body: body
  16998. });
  16999. }
  17000. }, {
  17001. key: 'init_incoming',
  17002. value: function init_incoming(request) {
  17003. this._direction = 'incoming';
  17004. this.request = request;
  17005. request.reply(200);
  17006. this._contentType = request.getHeader('content-type');
  17007. this._body = request.body;
  17008. this._session.newInfo({
  17009. originator: 'remote',
  17010. info: this,
  17011. request: request
  17012. });
  17013. }
  17014. }, {
  17015. key: 'contentType',
  17016. get: function get() {
  17017. return this._contentType;
  17018. }
  17019. }, {
  17020. key: 'body',
  17021. get: function get() {
  17022. return this._body;
  17023. }
  17024. }]);
  17025. return Info;
  17026. }(EventEmitter);
  17027. },{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":29,"events":31}],15:[function(require,module,exports){
  17028. 'use strict';
  17029. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  17030. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17031. var JsSIP_C = require('../Constants');
  17032. var debug = require('debug')('JsSIP:RTCSession:ReferNotifier');
  17033. var C = {
  17034. event_type: 'refer',
  17035. body_type: 'message/sipfrag;version=2.0',
  17036. expires: 300
  17037. };
  17038. module.exports = function () {
  17039. function ReferNotifier(session, id, expires) {
  17040. _classCallCheck(this, ReferNotifier);
  17041. this._session = session;
  17042. this._id = id;
  17043. this._expires = expires || C.expires;
  17044. this._active = true;
  17045. // The creation of a Notifier results in an immediate NOTIFY.
  17046. this.notify(100);
  17047. }
  17048. _createClass(ReferNotifier, [{
  17049. key: 'notify',
  17050. value: function notify(code, reason) {
  17051. debug('notify()');
  17052. if (this._active === false) {
  17053. return;
  17054. }
  17055. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  17056. var state = void 0;
  17057. if (code >= 200) {
  17058. state = 'terminated;reason=noresource';
  17059. } else {
  17060. state = 'active;expires=' + this._expires;
  17061. }
  17062. // Put this in a try/catch block.
  17063. this._session.sendRequest(JsSIP_C.NOTIFY, {
  17064. extraHeaders: ['Event: ' + C.event_type + ';id=' + this._id, 'Subscription-State: ' + state, 'Content-Type: ' + C.body_type],
  17065. body: 'SIP/2.0 ' + code + ' ' + reason,
  17066. eventHandlers: {
  17067. // If a negative response is received, subscription is canceled.
  17068. onErrorResponse: function onErrorResponse() {
  17069. this._active = false;
  17070. }
  17071. }
  17072. });
  17073. }
  17074. }]);
  17075. return ReferNotifier;
  17076. }();
  17077. },{"../Constants":2,"debug":29}],16:[function(require,module,exports){
  17078. 'use strict';
  17079. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  17080. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17081. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  17082. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  17083. var EventEmitter = require('events').EventEmitter;
  17084. var JsSIP_C = require('../Constants');
  17085. var Grammar = require('../Grammar');
  17086. var Utils = require('../Utils');
  17087. var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber');
  17088. module.exports = function (_EventEmitter) {
  17089. _inherits(ReferSubscriber, _EventEmitter);
  17090. function ReferSubscriber(session) {
  17091. _classCallCheck(this, ReferSubscriber);
  17092. var _this = _possibleConstructorReturn(this, (ReferSubscriber.__proto__ || Object.getPrototypeOf(ReferSubscriber)).call(this));
  17093. _this._id = null;
  17094. _this._session = session;
  17095. return _this;
  17096. }
  17097. _createClass(ReferSubscriber, [{
  17098. key: 'sendRefer',
  17099. value: function sendRefer(target) {
  17100. var _this2 = this;
  17101. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  17102. debug('sendRefer()');
  17103. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  17104. var eventHandlers = options.eventHandlers || {};
  17105. // Set event handlers.
  17106. for (var event in eventHandlers) {
  17107. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  17108. this.on(event, eventHandlers[event]);
  17109. }
  17110. }
  17111. // Replaces URI header field.
  17112. var replaces = null;
  17113. if (options.replaces) {
  17114. replaces = options.replaces._request.call_id;
  17115. replaces += ';to-tag=' + options.replaces._to_tag;
  17116. replaces += ';from-tag=' + options.replaces._from_tag;
  17117. replaces = encodeURIComponent(replaces);
  17118. }
  17119. // Refer-To header field.
  17120. var referTo = 'Refer-To: <' + target + (replaces ? '?Replaces=' + replaces : '') + '>';
  17121. extraHeaders.push(referTo);
  17122. var request = this._session.sendRequest(JsSIP_C.REFER, {
  17123. extraHeaders: extraHeaders,
  17124. eventHandlers: {
  17125. onSuccessResponse: function onSuccessResponse(response) {
  17126. _this2._requestSucceeded(response);
  17127. },
  17128. onErrorResponse: function onErrorResponse(response) {
  17129. _this2._requestFailed(response, JsSIP_C.causes.REJECTED);
  17130. },
  17131. onTransportError: function onTransportError() {
  17132. _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR);
  17133. },
  17134. onRequestTimeout: function onRequestTimeout() {
  17135. _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17136. },
  17137. onDialogError: function onDialogError() {
  17138. _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR);
  17139. }
  17140. }
  17141. });
  17142. this._id = request.cseq;
  17143. }
  17144. }, {
  17145. key: 'receiveNotify',
  17146. value: function receiveNotify(request) {
  17147. debug('receiveNotify()');
  17148. if (!request.body) {
  17149. return;
  17150. }
  17151. var status_line = Grammar.parse(request.body.trim(), 'Status_Line');
  17152. if (status_line === -1) {
  17153. debug('receiveNotify() | error parsing NOTIFY body: "' + request.body + '"');
  17154. return;
  17155. }
  17156. switch (true) {
  17157. case /^100$/.test(status_line.status_code):
  17158. this.emit('trying', {
  17159. request: request,
  17160. status_line: status_line
  17161. });
  17162. break;
  17163. case /^1[0-9]{2}$/.test(status_line.status_code):
  17164. this.emit('progress', {
  17165. request: request,
  17166. status_line: status_line
  17167. });
  17168. break;
  17169. case /^2[0-9]{2}$/.test(status_line.status_code):
  17170. this.emit('accepted', {
  17171. request: request,
  17172. status_line: status_line
  17173. });
  17174. break;
  17175. default:
  17176. this.emit('failed', {
  17177. request: request,
  17178. status_line: status_line
  17179. });
  17180. break;
  17181. }
  17182. }
  17183. }, {
  17184. key: '_requestSucceeded',
  17185. value: function _requestSucceeded(response) {
  17186. debug('REFER succeeded');
  17187. debug('emit "requestSucceeded"');
  17188. this.emit('requestSucceeded', {
  17189. response: response
  17190. });
  17191. }
  17192. }, {
  17193. key: '_requestFailed',
  17194. value: function _requestFailed(response, cause) {
  17195. debug('REFER failed');
  17196. debug('emit "requestFailed"');
  17197. this.emit('requestFailed', {
  17198. response: response || null,
  17199. cause: cause
  17200. });
  17201. }
  17202. }, {
  17203. key: 'id',
  17204. get: function get() {
  17205. return this._id;
  17206. }
  17207. }]);
  17208. return ReferSubscriber;
  17209. }(EventEmitter);
  17210. },{"../Constants":2,"../Grammar":7,"../Utils":26,"debug":29,"events":31}],17:[function(require,module,exports){
  17211. 'use strict';
  17212. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  17213. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17214. var Utils = require('./Utils');
  17215. var JsSIP_C = require('./Constants');
  17216. var SIPMessage = require('./SIPMessage');
  17217. var RequestSender = require('./RequestSender');
  17218. var debug = require('debug')('JsSIP:Registrator');
  17219. var MIN_REGISTER_EXPIRES = 10; // In seconds.
  17220. module.exports = function () {
  17221. function Registrator(ua, transport) {
  17222. _classCallCheck(this, Registrator);
  17223. var reg_id = 1; // Force reg_id to 1.
  17224. this._ua = ua;
  17225. this._transport = transport;
  17226. this._registrar = ua.configuration.registrar_server;
  17227. this._expires = ua.configuration.register_expires;
  17228. // Call-ID and CSeq values RFC3261 10.2.
  17229. this._call_id = Utils.createRandomToken(22);
  17230. this._cseq = 0;
  17231. this._to_uri = ua.configuration.uri;
  17232. this._registrationTimer = null;
  17233. // Ongoing Register request.
  17234. this._registering = false;
  17235. // Set status.
  17236. this._registered = false;
  17237. // Contact header.
  17238. this._contact = this._ua.contact.toString();
  17239. // Sip.ice media feature tag (RFC 5768).
  17240. this._contact += ';+sip.ice';
  17241. // Custom headers for REGISTER and un-REGISTER.
  17242. this._extraHeaders = [];
  17243. // Custom Contact header params for REGISTER and un-REGISTER.
  17244. this._extraContactParams = '';
  17245. if (reg_id) {
  17246. this._contact += ';reg-id=' + reg_id;
  17247. this._contact += ';+sip.instance="<urn:uuid:' + this._ua.configuration.instance_id + '>"';
  17248. }
  17249. }
  17250. _createClass(Registrator, [{
  17251. key: 'setExtraHeaders',
  17252. value: function setExtraHeaders(extraHeaders) {
  17253. if (!Array.isArray(extraHeaders)) {
  17254. extraHeaders = [];
  17255. }
  17256. this._extraHeaders = extraHeaders.slice();
  17257. }
  17258. }, {
  17259. key: 'setExtraContactParams',
  17260. value: function setExtraContactParams(extraContactParams) {
  17261. if (!(extraContactParams instanceof Object)) {
  17262. extraContactParams = {};
  17263. }
  17264. // Reset it.
  17265. this._extraContactParams = '';
  17266. for (var param_key in extraContactParams) {
  17267. if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) {
  17268. var param_value = extraContactParams[param_key];
  17269. this._extraContactParams += ';' + param_key;
  17270. if (param_value) {
  17271. this._extraContactParams += '=' + param_value;
  17272. }
  17273. }
  17274. }
  17275. }
  17276. }, {
  17277. key: 'register',
  17278. value: function register() {
  17279. var _this = this;
  17280. if (this._registering) {
  17281. debug('Register request in progress...');
  17282. return;
  17283. }
  17284. var extraHeaders = this._extraHeaders.slice();
  17285. extraHeaders.push('Contact: ' + this._contact + ';expires=' + this._expires + this._extraContactParams);
  17286. extraHeaders.push('Expires: ' + this._expires);
  17287. var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
  17288. 'to_uri': this._to_uri,
  17289. 'call_id': this._call_id,
  17290. 'cseq': this._cseq += 1
  17291. }, extraHeaders);
  17292. var request_sender = new RequestSender(this._ua, request, {
  17293. onRequestTimeout: function onRequestTimeout() {
  17294. _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17295. },
  17296. onTransportError: function onTransportError() {
  17297. _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR);
  17298. },
  17299. // Increase the CSeq on authentication.
  17300. onAuthenticated: function onAuthenticated() {
  17301. _this._cseq += 1;
  17302. },
  17303. onReceiveResponse: function onReceiveResponse(response) {
  17304. var contact = void 0;
  17305. var expires = void 0;
  17306. var numContacts = response.getHeaders('contact').length;
  17307. // Discard responses to older REGISTER/un-REGISTER requests.
  17308. if (response.cseq !== _this._cseq) {
  17309. return;
  17310. }
  17311. // Clear registration timer.
  17312. if (_this._registrationTimer !== null) {
  17313. clearTimeout(_this._registrationTimer);
  17314. _this._registrationTimer = null;
  17315. }
  17316. switch (true) {
  17317. case /^1[0-9]{2}$/.test(response.status_code):
  17318. // Ignore provisional responses.
  17319. break;
  17320. case /^2[0-9]{2}$/.test(response.status_code):
  17321. _this._registering = false;
  17322. // Search the Contact pointing to us and update the expires value accordingly.
  17323. if (!numContacts) {
  17324. debug('no Contact header in response to REGISTER, response ignored');
  17325. break;
  17326. }
  17327. while (numContacts--) {
  17328. contact = response.parseHeader('contact', numContacts);
  17329. if (contact.uri.user === _this._ua.contact.uri.user) {
  17330. expires = contact.getParam('expires');
  17331. break;
  17332. } else {
  17333. contact = null;
  17334. }
  17335. }
  17336. if (!contact) {
  17337. debug('no Contact header pointing to us, response ignored');
  17338. break;
  17339. }
  17340. if (!expires && response.hasHeader('expires')) {
  17341. expires = response.getHeader('expires');
  17342. }
  17343. if (!expires) {
  17344. expires = _this._expires;
  17345. }
  17346. expires = Number(expires);
  17347. if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES;
  17348. // Re-Register or emit an event before the expiration interval has elapsed.
  17349. // For that, decrease the expires value. ie: 3 seconds.
  17350. _this._registrationTimer = setTimeout(function () {
  17351. _this._registrationTimer = null;
  17352. // If there are no listeners for registrationExpiring, renew registration.
  17353. // If there are listeners, let the function listening do the register call.
  17354. if (_this._ua.listeners('registrationExpiring').length === 0) {
  17355. _this.register();
  17356. } else {
  17357. _this._ua.emit('registrationExpiring');
  17358. }
  17359. }, expires * 1000 - 5000);
  17360. // Save gruu values.
  17361. if (contact.hasParam('temp-gruu')) {
  17362. _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, '');
  17363. }
  17364. if (contact.hasParam('pub-gruu')) {
  17365. _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, '');
  17366. }
  17367. if (!_this._registered) {
  17368. _this._registered = true;
  17369. _this._ua.registered({
  17370. response: response
  17371. });
  17372. }
  17373. break;
  17374. // Interval too brief RFC3261 10.2.8.
  17375. case /^423$/.test(response.status_code):
  17376. if (response.hasHeader('min-expires')) {
  17377. // Increase our registration interval to the suggested minimum.
  17378. _this._expires = Number(response.getHeader('min-expires'));
  17379. if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES;
  17380. // Attempt the registration again immediately.
  17381. _this.register();
  17382. } else {
  17383. // This response MUST contain a Min-Expires header field
  17384. debug('423 response received for REGISTER without Min-Expires');
  17385. _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE);
  17386. }
  17387. break;
  17388. default:
  17389. {
  17390. var cause = Utils.sipErrorCause(response.status_code);
  17391. _this._registrationFailure(response, cause);
  17392. }
  17393. }
  17394. }
  17395. });
  17396. this._registering = true;
  17397. request_sender.send();
  17398. }
  17399. }, {
  17400. key: 'unregister',
  17401. value: function unregister() {
  17402. var _this2 = this;
  17403. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17404. if (!this._registered) {
  17405. debug('already unregistered');
  17406. return;
  17407. }
  17408. this._registered = false;
  17409. // Clear the registration timer.
  17410. if (this._registrationTimer !== null) {
  17411. clearTimeout(this._registrationTimer);
  17412. this._registrationTimer = null;
  17413. }
  17414. var extraHeaders = this._extraHeaders.slice();
  17415. if (options.all) {
  17416. extraHeaders.push('Contact: *' + this._extraContactParams);
  17417. } else {
  17418. extraHeaders.push('Contact: ' + this._contact + ';expires=0' + this._extraContactParams);
  17419. }
  17420. extraHeaders.push('Expires: 0');
  17421. var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
  17422. 'to_uri': this._to_uri,
  17423. 'call_id': this._call_id,
  17424. 'cseq': this._cseq += 1
  17425. }, extraHeaders);
  17426. var request_sender = new RequestSender(this._ua, request, {
  17427. onRequestTimeout: function onRequestTimeout() {
  17428. _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17429. },
  17430. onTransportError: function onTransportError() {
  17431. _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR);
  17432. },
  17433. // Increase the CSeq on authentication.
  17434. onAuthenticated: function onAuthenticated() {
  17435. _this2._cseq += 1;
  17436. },
  17437. onReceiveResponse: function onReceiveResponse(response) {
  17438. switch (true) {
  17439. case /^1[0-9]{2}$/.test(response.status_code):
  17440. // Ignore provisional responses.
  17441. break;
  17442. case /^2[0-9]{2}$/.test(response.status_code):
  17443. _this2._unregistered(response);
  17444. break;
  17445. default:
  17446. {
  17447. var cause = Utils.sipErrorCause(response.status_code);
  17448. _this2._unregistered(response, cause);
  17449. }
  17450. }
  17451. }
  17452. });
  17453. request_sender.send();
  17454. }
  17455. }, {
  17456. key: 'close',
  17457. value: function close() {
  17458. if (this._registered) {
  17459. this.unregister();
  17460. }
  17461. }
  17462. }, {
  17463. key: 'onTransportClosed',
  17464. value: function onTransportClosed() {
  17465. this._registering = false;
  17466. if (this._registrationTimer !== null) {
  17467. clearTimeout(this._registrationTimer);
  17468. this._registrationTimer = null;
  17469. }
  17470. if (this._registered) {
  17471. this._registered = false;
  17472. this._ua.unregistered({});
  17473. }
  17474. }
  17475. }, {
  17476. key: '_registrationFailure',
  17477. value: function _registrationFailure(response, cause) {
  17478. this._registering = false;
  17479. this._ua.registrationFailed({
  17480. response: response || null,
  17481. cause: cause
  17482. });
  17483. if (this._registered) {
  17484. this._registered = false;
  17485. this._ua.unregistered({
  17486. response: response || null,
  17487. cause: cause
  17488. });
  17489. }
  17490. }
  17491. }, {
  17492. key: '_unregistered',
  17493. value: function _unregistered(response, cause) {
  17494. this._registering = false;
  17495. this._registered = false;
  17496. this._ua.unregistered({
  17497. response: response || null,
  17498. cause: cause || null
  17499. });
  17500. }
  17501. }, {
  17502. key: 'registered',
  17503. get: function get() {
  17504. return this._registered;
  17505. }
  17506. }]);
  17507. return Registrator;
  17508. }();
  17509. },{"./Constants":2,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":29}],18:[function(require,module,exports){
  17510. 'use strict';
  17511. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  17512. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17513. var JsSIP_C = require('./Constants');
  17514. var DigestAuthentication = require('./DigestAuthentication');
  17515. var Transactions = require('./Transactions');
  17516. var debug = require('debug')('JsSIP:RequestSender');
  17517. // Default event handlers.
  17518. var EventHandlers = {
  17519. onRequestTimeout: function onRequestTimeout() {},
  17520. onTransportError: function onTransportError() {},
  17521. onReceiveResponse: function onReceiveResponse() {},
  17522. onAuthenticated: function onAuthenticated() {}
  17523. };
  17524. module.exports = function () {
  17525. function RequestSender(ua, request, eventHandlers) {
  17526. _classCallCheck(this, RequestSender);
  17527. this._ua = ua;
  17528. this._eventHandlers = eventHandlers;
  17529. this._method = request.method;
  17530. this._request = request;
  17531. this._auth = null;
  17532. this._challenged = false;
  17533. this._staled = false;
  17534. // Define the undefined handlers.
  17535. for (var handler in EventHandlers) {
  17536. if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
  17537. if (!this._eventHandlers[handler]) {
  17538. this._eventHandlers[handler] = EventHandlers[handler];
  17539. }
  17540. }
  17541. }
  17542. // If ua is in closing process or even closed just allow sending Bye and ACK.
  17543. if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) {
  17544. this._eventHandlers.onTransportError();
  17545. }
  17546. }
  17547. /**
  17548. * Create the client transaction and send the message.
  17549. */
  17550. _createClass(RequestSender, [{
  17551. key: 'send',
  17552. value: function send() {
  17553. var _this = this;
  17554. var eventHandlers = {
  17555. onRequestTimeout: function onRequestTimeout() {
  17556. _this._eventHandlers.onRequestTimeout();
  17557. },
  17558. onTransportError: function onTransportError() {
  17559. _this._eventHandlers.onTransportError();
  17560. },
  17561. onReceiveResponse: function onReceiveResponse(response) {
  17562. _this._receiveResponse(response);
  17563. }
  17564. };
  17565. switch (this._method) {
  17566. case 'INVITE':
  17567. this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17568. break;
  17569. case 'ACK':
  17570. this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17571. break;
  17572. default:
  17573. this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17574. }
  17575. this.clientTransaction.send();
  17576. }
  17577. /**
  17578. * Called from client transaction when receiving a correct response to the request.
  17579. * Authenticate request if needed or pass the response back to the applicant.
  17580. */
  17581. }, {
  17582. key: '_receiveResponse',
  17583. value: function _receiveResponse(response) {
  17584. var challenge = void 0;
  17585. var authorization_header_name = void 0;
  17586. var status_code = response.status_code;
  17587. /*
  17588. * Authentication
  17589. * Authenticate once. _challenged_ flag used to avoid infinite authentications.
  17590. */
  17591. if ((status_code === 401 || status_code === 407) && (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) {
  17592. // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header.
  17593. if (response.status_code === 401) {
  17594. challenge = response.parseHeader('www-authenticate');
  17595. authorization_header_name = 'authorization';
  17596. } else {
  17597. challenge = response.parseHeader('proxy-authenticate');
  17598. authorization_header_name = 'proxy-authorization';
  17599. }
  17600. // Verify it seems a valid challenge.
  17601. if (!challenge) {
  17602. debug(response.status_code + ' with wrong or missing challenge, cannot authenticate');
  17603. this._eventHandlers.onReceiveResponse(response);
  17604. return;
  17605. }
  17606. if (!this._challenged || !this._staled && challenge.stale === true) {
  17607. if (!this._auth) {
  17608. this._auth = new DigestAuthentication({
  17609. username: this._ua.configuration.authorization_user,
  17610. password: this._ua.configuration.password,
  17611. realm: this._ua.configuration.realm,
  17612. ha1: this._ua.configuration.ha1
  17613. });
  17614. }
  17615. // Verify that the challenge is really valid.
  17616. if (!this._auth.authenticate(this._request, challenge)) {
  17617. this._eventHandlers.onReceiveResponse(response);
  17618. return;
  17619. }
  17620. this._challenged = true;
  17621. // Update ha1 and realm in the UA.
  17622. this._ua.set('realm', this._auth.get('realm'));
  17623. this._ua.set('ha1', this._auth.get('ha1'));
  17624. if (challenge.stale) {
  17625. this._staled = true;
  17626. }
  17627. this._request = this._request.clone();
  17628. this._request.cseq += 1;
  17629. this._request.setHeader('cseq', this._request.cseq + ' ' + this._method);
  17630. this._request.setHeader(authorization_header_name, this._auth.toString());
  17631. this._eventHandlers.onAuthenticated(this._request);
  17632. this.send();
  17633. } else {
  17634. this._eventHandlers.onReceiveResponse(response);
  17635. }
  17636. } else {
  17637. this._eventHandlers.onReceiveResponse(response);
  17638. }
  17639. }
  17640. }]);
  17641. return RequestSender;
  17642. }();
  17643. },{"./Constants":2,"./DigestAuthentication":5,"./Transactions":22,"debug":29}],19:[function(require,module,exports){
  17644. 'use strict';
  17645. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  17646. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  17647. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  17648. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17649. var sdp_transform = require('sdp-transform');
  17650. var JsSIP_C = require('./Constants');
  17651. var Utils = require('./Utils');
  17652. var NameAddrHeader = require('./NameAddrHeader');
  17653. var Grammar = require('./Grammar');
  17654. var debug = require('debug')('JsSIP:SIPMessage');
  17655. /**
  17656. * -param {String} method request method
  17657. * -param {String} ruri request uri
  17658. * -param {UA} ua
  17659. * -param {Object} params parameters that will have priority over ua.configuration parameters:
  17660. * <br>
  17661. * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set
  17662. * -param {Object} [headers] extra headers
  17663. * -param {String} [body]
  17664. */
  17665. var OutgoingRequest = function () {
  17666. function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) {
  17667. _classCallCheck(this, OutgoingRequest);
  17668. // Mandatory parameters check.
  17669. if (!method || !ruri || !ua) {
  17670. return null;
  17671. }
  17672. params = params || {};
  17673. this.ua = ua;
  17674. this.headers = {};
  17675. this.method = method;
  17676. this.ruri = ruri;
  17677. this.body = body;
  17678. this.extraHeaders = Utils.cloneArray(extraHeaders);
  17679. // Fill the Common SIP Request Headers.
  17680. // Route.
  17681. if (params.route_set) {
  17682. this.setHeader('route', params.route_set);
  17683. } else if (ua.configuration.use_preloaded_route) {
  17684. this.setHeader('route', '<' + ua.transport.sip_uri + ';lr>');
  17685. }
  17686. // Via.
  17687. // Empty Via header. Will be filled by the client transaction.
  17688. this.setHeader('via', '');
  17689. // Max-Forwards.
  17690. this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS);
  17691. // To
  17692. var to = params.to_display_name || params.to_display_name === 0 ? '"' + params.to_display_name + '" ' : '';
  17693. to += '<' + (params.to_uri || ruri) + '>';
  17694. to += params.to_tag ? ';tag=' + params.to_tag : '';
  17695. this.to = NameAddrHeader.parse(to);
  17696. this.setHeader('to', to);
  17697. // From.
  17698. var from = void 0;
  17699. if (params.from_display_name || params.from_display_name === 0) {
  17700. from = '"' + params.from_display_name + '" ';
  17701. } else if (ua.configuration.display_name) {
  17702. from = '"' + ua.configuration.display_name + '" ';
  17703. } else {
  17704. from = '';
  17705. }
  17706. from += '<' + (params.from_uri || ua.configuration.uri) + '>;tag=';
  17707. from += params.from_tag || Utils.newTag();
  17708. this.from = NameAddrHeader.parse(from);
  17709. this.setHeader('from', from);
  17710. // Call-ID.
  17711. var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15);
  17712. this.call_id = call_id;
  17713. this.setHeader('call-id', call_id);
  17714. // CSeq.
  17715. var cseq = params.cseq || Math.floor(Math.random() * 10000);
  17716. this.cseq = cseq;
  17717. this.setHeader('cseq', cseq + ' ' + method);
  17718. }
  17719. /**
  17720. * Replace the the given header by the given value.
  17721. * -param {String} name header name
  17722. * -param {String | Array} value header value
  17723. */
  17724. _createClass(OutgoingRequest, [{
  17725. key: 'setHeader',
  17726. value: function setHeader(name, value) {
  17727. // Remove the header from extraHeaders if present.
  17728. var regexp = new RegExp('^\\s*' + name + '\\s*:', 'i');
  17729. for (var idx = 0; idx < this.extraHeaders.length; idx++) {
  17730. if (regexp.test(this.extraHeaders[idx])) {
  17731. this.extraHeaders.splice(idx, 1);
  17732. }
  17733. }
  17734. this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
  17735. }
  17736. /**
  17737. * Get the value of the given header name at the given position.
  17738. * -param {String} name header name
  17739. * -returns {String|undefined} Returns the specified header, null if header doesn't exist.
  17740. */
  17741. }, {
  17742. key: 'getHeader',
  17743. value: function getHeader(name) {
  17744. var headers = this.headers[Utils.headerize(name)];
  17745. if (headers) {
  17746. if (headers[0]) {
  17747. return headers[0];
  17748. }
  17749. } else {
  17750. var regexp = new RegExp('^\\s*' + name + '\\s*:', 'i');
  17751. var _iteratorNormalCompletion = true;
  17752. var _didIteratorError = false;
  17753. var _iteratorError = undefined;
  17754. try {
  17755. for (var _iterator = this.extraHeaders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  17756. var header = _step.value;
  17757. if (regexp.test(header)) {
  17758. return header.substring(header.indexOf(':') + 1).trim();
  17759. }
  17760. }
  17761. } catch (err) {
  17762. _didIteratorError = true;
  17763. _iteratorError = err;
  17764. } finally {
  17765. try {
  17766. if (!_iteratorNormalCompletion && _iterator.return) {
  17767. _iterator.return();
  17768. }
  17769. } finally {
  17770. if (_didIteratorError) {
  17771. throw _iteratorError;
  17772. }
  17773. }
  17774. }
  17775. }
  17776. return;
  17777. }
  17778. /**
  17779. * Get the header/s of the given name.
  17780. * -param {String} name header name
  17781. * -returns {Array} Array with all the headers of the specified name.
  17782. */
  17783. }, {
  17784. key: 'getHeaders',
  17785. value: function getHeaders(name) {
  17786. var headers = this.headers[Utils.headerize(name)];
  17787. var result = [];
  17788. if (headers) {
  17789. var _iteratorNormalCompletion2 = true;
  17790. var _didIteratorError2 = false;
  17791. var _iteratorError2 = undefined;
  17792. try {
  17793. for (var _iterator2 = headers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  17794. var header = _step2.value;
  17795. result.push(header);
  17796. }
  17797. } catch (err) {
  17798. _didIteratorError2 = true;
  17799. _iteratorError2 = err;
  17800. } finally {
  17801. try {
  17802. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  17803. _iterator2.return();
  17804. }
  17805. } finally {
  17806. if (_didIteratorError2) {
  17807. throw _iteratorError2;
  17808. }
  17809. }
  17810. }
  17811. return result;
  17812. } else {
  17813. var regexp = new RegExp('^\\s*' + name + '\\s*:', 'i');
  17814. var _iteratorNormalCompletion3 = true;
  17815. var _didIteratorError3 = false;
  17816. var _iteratorError3 = undefined;
  17817. try {
  17818. for (var _iterator3 = this.extraHeaders[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  17819. var _header = _step3.value;
  17820. if (regexp.test(_header)) {
  17821. result.push(_header.substring(_header.indexOf(':') + 1).trim());
  17822. }
  17823. }
  17824. } catch (err) {
  17825. _didIteratorError3 = true;
  17826. _iteratorError3 = err;
  17827. } finally {
  17828. try {
  17829. if (!_iteratorNormalCompletion3 && _iterator3.return) {
  17830. _iterator3.return();
  17831. }
  17832. } finally {
  17833. if (_didIteratorError3) {
  17834. throw _iteratorError3;
  17835. }
  17836. }
  17837. }
  17838. return result;
  17839. }
  17840. }
  17841. /**
  17842. * Verify the existence of the given header.
  17843. * -param {String} name header name
  17844. * -returns {boolean} true if header with given name exists, false otherwise
  17845. */
  17846. }, {
  17847. key: 'hasHeader',
  17848. value: function hasHeader(name) {
  17849. if (this.headers[Utils.headerize(name)]) {
  17850. return true;
  17851. } else {
  17852. var regexp = new RegExp('^\\s*' + name + '\\s*:', 'i');
  17853. var _iteratorNormalCompletion4 = true;
  17854. var _didIteratorError4 = false;
  17855. var _iteratorError4 = undefined;
  17856. try {
  17857. for (var _iterator4 = this.extraHeaders[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  17858. var header = _step4.value;
  17859. if (regexp.test(header)) {
  17860. return true;
  17861. }
  17862. }
  17863. } catch (err) {
  17864. _didIteratorError4 = true;
  17865. _iteratorError4 = err;
  17866. } finally {
  17867. try {
  17868. if (!_iteratorNormalCompletion4 && _iterator4.return) {
  17869. _iterator4.return();
  17870. }
  17871. } finally {
  17872. if (_didIteratorError4) {
  17873. throw _iteratorError4;
  17874. }
  17875. }
  17876. }
  17877. }
  17878. return false;
  17879. }
  17880. /**
  17881. * Parse the current body as a SDP and store the resulting object
  17882. * into this.sdp.
  17883. * -param {Boolean} force: Parse even if this.sdp already exists.
  17884. *
  17885. * Returns this.sdp.
  17886. */
  17887. }, {
  17888. key: 'parseSDP',
  17889. value: function parseSDP(force) {
  17890. if (!force && this.sdp) {
  17891. return this.sdp;
  17892. } else {
  17893. this.sdp = sdp_transform.parse(this.body || '');
  17894. return this.sdp;
  17895. }
  17896. }
  17897. }, {
  17898. key: 'toString',
  17899. value: function toString() {
  17900. var msg = this.method + ' ' + this.ruri + ' SIP/2.0\r\n';
  17901. for (var headerName in this.headers) {
  17902. if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) {
  17903. var _iteratorNormalCompletion5 = true;
  17904. var _didIteratorError5 = false;
  17905. var _iteratorError5 = undefined;
  17906. try {
  17907. for (var _iterator5 = this.headers[headerName][Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  17908. var headerValue = _step5.value;
  17909. msg += headerName + ': ' + headerValue + '\r\n';
  17910. }
  17911. } catch (err) {
  17912. _didIteratorError5 = true;
  17913. _iteratorError5 = err;
  17914. } finally {
  17915. try {
  17916. if (!_iteratorNormalCompletion5 && _iterator5.return) {
  17917. _iterator5.return();
  17918. }
  17919. } finally {
  17920. if (_didIteratorError5) {
  17921. throw _iteratorError5;
  17922. }
  17923. }
  17924. }
  17925. }
  17926. }
  17927. var _iteratorNormalCompletion6 = true;
  17928. var _didIteratorError6 = false;
  17929. var _iteratorError6 = undefined;
  17930. try {
  17931. for (var _iterator6 = this.extraHeaders[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
  17932. var header = _step6.value;
  17933. msg += header.trim() + '\r\n';
  17934. }
  17935. // Supported.
  17936. } catch (err) {
  17937. _didIteratorError6 = true;
  17938. _iteratorError6 = err;
  17939. } finally {
  17940. try {
  17941. if (!_iteratorNormalCompletion6 && _iterator6.return) {
  17942. _iterator6.return();
  17943. }
  17944. } finally {
  17945. if (_didIteratorError6) {
  17946. throw _iteratorError6;
  17947. }
  17948. }
  17949. }
  17950. var supported = [];
  17951. switch (this.method) {
  17952. case JsSIP_C.REGISTER:
  17953. supported.push('path', 'gruu');
  17954. break;
  17955. case JsSIP_C.INVITE:
  17956. if (this.ua.configuration.session_timers) {
  17957. supported.push('timer');
  17958. }
  17959. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  17960. supported.push('gruu');
  17961. }
  17962. supported.push('ice', 'replaces');
  17963. break;
  17964. case JsSIP_C.UPDATE:
  17965. if (this.ua.configuration.session_timers) {
  17966. supported.push('timer');
  17967. }
  17968. supported.push('ice');
  17969. break;
  17970. }
  17971. supported.push('outbound');
  17972. var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT;
  17973. // Allow.
  17974. msg += 'Allow: ' + JsSIP_C.ALLOWED_METHODS + '\r\n';
  17975. msg += 'Supported: ' + supported + '\r\n';
  17976. msg += 'User-Agent: ' + userAgent + '\r\n';
  17977. if (this.body) {
  17978. var length = Utils.str_utf8_length(this.body);
  17979. msg += 'Content-Length: ' + length + '\r\n\r\n';
  17980. msg += this.body;
  17981. } else {
  17982. msg += 'Content-Length: 0\r\n\r\n';
  17983. }
  17984. return msg;
  17985. }
  17986. }, {
  17987. key: 'clone',
  17988. value: function clone() {
  17989. var request = new OutgoingRequest(this.method, this.ruri, this.ua);
  17990. Object.keys(this.headers).forEach(function (name) {
  17991. request.headers[name] = this.headers[name].slice();
  17992. }, this);
  17993. request.body = this.body;
  17994. request.extraHeaders = Utils.cloneArray(this.extraHeaders);
  17995. request.to = this.to;
  17996. request.from = this.from;
  17997. request.call_id = this.call_id;
  17998. request.cseq = this.cseq;
  17999. return request;
  18000. }
  18001. }]);
  18002. return OutgoingRequest;
  18003. }();
  18004. var InitialOutgoingInviteRequest = function (_OutgoingRequest) {
  18005. _inherits(InitialOutgoingInviteRequest, _OutgoingRequest);
  18006. function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) {
  18007. _classCallCheck(this, InitialOutgoingInviteRequest);
  18008. var _this = _possibleConstructorReturn(this, (InitialOutgoingInviteRequest.__proto__ || Object.getPrototypeOf(InitialOutgoingInviteRequest)).call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body));
  18009. _this.transaction = null;
  18010. return _this;
  18011. }
  18012. _createClass(InitialOutgoingInviteRequest, [{
  18013. key: 'cancel',
  18014. value: function cancel(reason) {
  18015. this.transaction.cancel(reason);
  18016. }
  18017. }, {
  18018. key: 'clone',
  18019. value: function clone() {
  18020. var request = new InitialOutgoingInviteRequest(this.ruri, this.ua);
  18021. Object.keys(this.headers).forEach(function (name) {
  18022. request.headers[name] = this.headers[name].slice();
  18023. }, this);
  18024. request.body = this.body;
  18025. request.extraHeaders = Utils.cloneArray(this.extraHeaders);
  18026. request.to = this.to;
  18027. request.from = this.from;
  18028. request.call_id = this.call_id;
  18029. request.cseq = this.cseq;
  18030. request.transaction = this.transaction;
  18031. return request;
  18032. }
  18033. }]);
  18034. return InitialOutgoingInviteRequest;
  18035. }(OutgoingRequest);
  18036. var IncomingMessage = function () {
  18037. function IncomingMessage() {
  18038. _classCallCheck(this, IncomingMessage);
  18039. this.data = null;
  18040. this.headers = null;
  18041. this.method = null;
  18042. this.via = null;
  18043. this.via_branch = null;
  18044. this.call_id = null;
  18045. this.cseq = null;
  18046. this.from = null;
  18047. this.from_tag = null;
  18048. this.to = null;
  18049. this.to_tag = null;
  18050. this.body = null;
  18051. this.sdp = null;
  18052. }
  18053. /**
  18054. * Insert a header of the given name and value into the last position of the
  18055. * header array.
  18056. */
  18057. _createClass(IncomingMessage, [{
  18058. key: 'addHeader',
  18059. value: function addHeader(name, value) {
  18060. var header = { raw: value };
  18061. name = Utils.headerize(name);
  18062. if (this.headers[name]) {
  18063. this.headers[name].push(header);
  18064. } else {
  18065. this.headers[name] = [header];
  18066. }
  18067. }
  18068. /**
  18069. * Get the value of the given header name at the given position.
  18070. */
  18071. }, {
  18072. key: 'getHeader',
  18073. value: function getHeader(name) {
  18074. var header = this.headers[Utils.headerize(name)];
  18075. if (header) {
  18076. if (header[0]) {
  18077. return header[0].raw;
  18078. }
  18079. } else {
  18080. return;
  18081. }
  18082. }
  18083. /**
  18084. * Get the header/s of the given name.
  18085. */
  18086. }, {
  18087. key: 'getHeaders',
  18088. value: function getHeaders(name) {
  18089. var headers = this.headers[Utils.headerize(name)];
  18090. var result = [];
  18091. if (!headers) {
  18092. return [];
  18093. }
  18094. var _iteratorNormalCompletion7 = true;
  18095. var _didIteratorError7 = false;
  18096. var _iteratorError7 = undefined;
  18097. try {
  18098. for (var _iterator7 = headers[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
  18099. var header = _step7.value;
  18100. result.push(header.raw);
  18101. }
  18102. } catch (err) {
  18103. _didIteratorError7 = true;
  18104. _iteratorError7 = err;
  18105. } finally {
  18106. try {
  18107. if (!_iteratorNormalCompletion7 && _iterator7.return) {
  18108. _iterator7.return();
  18109. }
  18110. } finally {
  18111. if (_didIteratorError7) {
  18112. throw _iteratorError7;
  18113. }
  18114. }
  18115. }
  18116. return result;
  18117. }
  18118. /**
  18119. * Verify the existence of the given header.
  18120. */
  18121. }, {
  18122. key: 'hasHeader',
  18123. value: function hasHeader(name) {
  18124. return this.headers[Utils.headerize(name)] ? true : false;
  18125. }
  18126. /**
  18127. * Parse the given header on the given index.
  18128. * -param {String} name header name
  18129. * -param {Number} [idx=0] header index
  18130. * -returns {Object|undefined} Parsed header object, undefined if the header
  18131. * is not present or in case of a parsing error.
  18132. */
  18133. }, {
  18134. key: 'parseHeader',
  18135. value: function parseHeader(name) {
  18136. var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  18137. name = Utils.headerize(name);
  18138. if (!this.headers[name]) {
  18139. debug('header "' + name + '" not present');
  18140. return;
  18141. } else if (idx >= this.headers[name].length) {
  18142. debug('not so many "' + name + '" headers present');
  18143. return;
  18144. }
  18145. var header = this.headers[name][idx];
  18146. var value = header.raw;
  18147. if (header.parsed) {
  18148. return header.parsed;
  18149. }
  18150. // Substitute '-' by '_' for grammar rule matching.
  18151. var parsed = Grammar.parse(value, name.replace(/-/g, '_'));
  18152. if (parsed === -1) {
  18153. this.headers[name].splice(idx, 1); // delete from headers
  18154. debug('error parsing "' + name + '" header field with value "' + value + '"');
  18155. return;
  18156. } else {
  18157. header.parsed = parsed;
  18158. return parsed;
  18159. }
  18160. }
  18161. /**
  18162. * Message Header attribute selector. Alias of parseHeader.
  18163. * -param {String} name header name
  18164. * -param {Number} [idx=0] header index
  18165. * -returns {Object|undefined} Parsed header object, undefined if the header
  18166. * is not present or in case of a parsing error.
  18167. *
  18168. * -example
  18169. * message.s('via',3).port
  18170. */
  18171. }, {
  18172. key: 's',
  18173. value: function s(name, idx) {
  18174. return this.parseHeader(name, idx);
  18175. }
  18176. /**
  18177. * Replace the value of the given header by the value.
  18178. * -param {String} name header name
  18179. * -param {String} value header value
  18180. */
  18181. }, {
  18182. key: 'setHeader',
  18183. value: function setHeader(name, value) {
  18184. var header = { raw: value };
  18185. this.headers[Utils.headerize(name)] = [header];
  18186. }
  18187. /**
  18188. * Parse the current body as a SDP and store the resulting object
  18189. * into this.sdp.
  18190. * -param {Boolean} force: Parse even if this.sdp already exists.
  18191. *
  18192. * Returns this.sdp.
  18193. */
  18194. }, {
  18195. key: 'parseSDP',
  18196. value: function parseSDP(force) {
  18197. if (!force && this.sdp) {
  18198. return this.sdp;
  18199. } else {
  18200. this.sdp = sdp_transform.parse(this.body || '');
  18201. return this.sdp;
  18202. }
  18203. }
  18204. }, {
  18205. key: 'toString',
  18206. value: function toString() {
  18207. return this.data;
  18208. }
  18209. }]);
  18210. return IncomingMessage;
  18211. }();
  18212. var IncomingRequest = function (_IncomingMessage) {
  18213. _inherits(IncomingRequest, _IncomingMessage);
  18214. function IncomingRequest(ua) {
  18215. _classCallCheck(this, IncomingRequest);
  18216. var _this2 = _possibleConstructorReturn(this, (IncomingRequest.__proto__ || Object.getPrototypeOf(IncomingRequest)).call(this));
  18217. _this2.ua = ua;
  18218. _this2.headers = {};
  18219. _this2.ruri = null;
  18220. _this2.transport = null;
  18221. _this2.server_transaction = null;
  18222. return _this2;
  18223. }
  18224. /**
  18225. * Stateful reply.
  18226. * -param {Number} code status code
  18227. * -param {String} reason reason phrase
  18228. * -param {Object} headers extra headers
  18229. * -param {String} body body
  18230. * -param {Function} [onSuccess] onSuccess callback
  18231. * -param {Function} [onFailure] onFailure callback
  18232. */
  18233. _createClass(IncomingRequest, [{
  18234. key: 'reply',
  18235. value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) {
  18236. var supported = [];
  18237. var to = this.getHeader('To');
  18238. code = code || null;
  18239. reason = reason || null;
  18240. // Validate code and reason values.
  18241. if (!code || code < 100 || code > 699) {
  18242. throw new TypeError('Invalid status_code: ' + code);
  18243. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  18244. throw new TypeError('Invalid reason_phrase: ' + reason);
  18245. }
  18246. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  18247. extraHeaders = Utils.cloneArray(extraHeaders);
  18248. var response = 'SIP/2.0 ' + code + ' ' + reason + '\r\n';
  18249. if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) {
  18250. var headers = this.getHeaders('record-route');
  18251. var _iteratorNormalCompletion8 = true;
  18252. var _didIteratorError8 = false;
  18253. var _iteratorError8 = undefined;
  18254. try {
  18255. for (var _iterator8 = headers[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
  18256. var header = _step8.value;
  18257. response += 'Record-Route: ' + header + '\r\n';
  18258. }
  18259. } catch (err) {
  18260. _didIteratorError8 = true;
  18261. _iteratorError8 = err;
  18262. } finally {
  18263. try {
  18264. if (!_iteratorNormalCompletion8 && _iterator8.return) {
  18265. _iterator8.return();
  18266. }
  18267. } finally {
  18268. if (_didIteratorError8) {
  18269. throw _iteratorError8;
  18270. }
  18271. }
  18272. }
  18273. }
  18274. var vias = this.getHeaders('via');
  18275. var _iteratorNormalCompletion9 = true;
  18276. var _didIteratorError9 = false;
  18277. var _iteratorError9 = undefined;
  18278. try {
  18279. for (var _iterator9 = vias[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
  18280. var via = _step9.value;
  18281. response += 'Via: ' + via + '\r\n';
  18282. }
  18283. } catch (err) {
  18284. _didIteratorError9 = true;
  18285. _iteratorError9 = err;
  18286. } finally {
  18287. try {
  18288. if (!_iteratorNormalCompletion9 && _iterator9.return) {
  18289. _iterator9.return();
  18290. }
  18291. } finally {
  18292. if (_didIteratorError9) {
  18293. throw _iteratorError9;
  18294. }
  18295. }
  18296. }
  18297. if (!this.to_tag && code > 100) {
  18298. to += ';tag=' + Utils.newTag();
  18299. } else if (this.to_tag && !this.s('to').hasParam('tag')) {
  18300. to += ';tag=' + this.to_tag;
  18301. }
  18302. response += 'To: ' + to + '\r\n';
  18303. response += 'From: ' + this.getHeader('From') + '\r\n';
  18304. response += 'Call-ID: ' + this.call_id + '\r\n';
  18305. response += 'CSeq: ' + this.cseq + ' ' + this.method + '\r\n';
  18306. var _iteratorNormalCompletion10 = true;
  18307. var _didIteratorError10 = false;
  18308. var _iteratorError10 = undefined;
  18309. try {
  18310. for (var _iterator10 = extraHeaders[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
  18311. var _header2 = _step10.value;
  18312. response += _header2.trim() + '\r\n';
  18313. }
  18314. // Supported.
  18315. } catch (err) {
  18316. _didIteratorError10 = true;
  18317. _iteratorError10 = err;
  18318. } finally {
  18319. try {
  18320. if (!_iteratorNormalCompletion10 && _iterator10.return) {
  18321. _iterator10.return();
  18322. }
  18323. } finally {
  18324. if (_didIteratorError10) {
  18325. throw _iteratorError10;
  18326. }
  18327. }
  18328. }
  18329. switch (this.method) {
  18330. case JsSIP_C.INVITE:
  18331. if (this.ua.configuration.session_timers) {
  18332. supported.push('timer');
  18333. }
  18334. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  18335. supported.push('gruu');
  18336. }
  18337. supported.push('ice', 'replaces');
  18338. break;
  18339. case JsSIP_C.UPDATE:
  18340. if (this.ua.configuration.session_timers) {
  18341. supported.push('timer');
  18342. }
  18343. if (body) {
  18344. supported.push('ice');
  18345. }
  18346. supported.push('replaces');
  18347. }
  18348. supported.push('outbound');
  18349. // Allow and Accept.
  18350. if (this.method === JsSIP_C.OPTIONS) {
  18351. response += 'Allow: ' + JsSIP_C.ALLOWED_METHODS + '\r\n';
  18352. response += 'Accept: ' + JsSIP_C.ACCEPTED_BODY_TYPES + '\r\n';
  18353. } else if (code === 405) {
  18354. response += 'Allow: ' + JsSIP_C.ALLOWED_METHODS + '\r\n';
  18355. } else if (code === 415) {
  18356. response += 'Accept: ' + JsSIP_C.ACCEPTED_BODY_TYPES + '\r\n';
  18357. }
  18358. response += 'Supported: ' + supported + '\r\n';
  18359. if (body) {
  18360. var length = Utils.str_utf8_length(body);
  18361. response += 'Content-Type: application/sdp\r\n';
  18362. response += 'Content-Length: ' + length + '\r\n\r\n';
  18363. response += body;
  18364. } else {
  18365. response += 'Content-Length: ' + 0 + '\r\n\r\n';
  18366. }
  18367. this.server_transaction.receiveResponse(code, response, onSuccess, onFailure);
  18368. }
  18369. /**
  18370. * Stateless reply.
  18371. * -param {Number} code status code
  18372. * -param {String} reason reason phrase
  18373. */
  18374. }, {
  18375. key: 'reply_sl',
  18376. value: function reply_sl() {
  18377. var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  18378. var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  18379. var vias = this.getHeaders('via');
  18380. // Validate code and reason values.
  18381. if (!code || code < 100 || code > 699) {
  18382. throw new TypeError('Invalid status_code: ' + code);
  18383. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  18384. throw new TypeError('Invalid reason_phrase: ' + reason);
  18385. }
  18386. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  18387. var response = 'SIP/2.0 ' + code + ' ' + reason + '\r\n';
  18388. var _iteratorNormalCompletion11 = true;
  18389. var _didIteratorError11 = false;
  18390. var _iteratorError11 = undefined;
  18391. try {
  18392. for (var _iterator11 = vias[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
  18393. var via = _step11.value;
  18394. response += 'Via: ' + via + '\r\n';
  18395. }
  18396. } catch (err) {
  18397. _didIteratorError11 = true;
  18398. _iteratorError11 = err;
  18399. } finally {
  18400. try {
  18401. if (!_iteratorNormalCompletion11 && _iterator11.return) {
  18402. _iterator11.return();
  18403. }
  18404. } finally {
  18405. if (_didIteratorError11) {
  18406. throw _iteratorError11;
  18407. }
  18408. }
  18409. }
  18410. var to = this.getHeader('To');
  18411. if (!this.to_tag && code > 100) {
  18412. to += ';tag=' + Utils.newTag();
  18413. } else if (this.to_tag && !this.s('to').hasParam('tag')) {
  18414. to += ';tag=' + this.to_tag;
  18415. }
  18416. response += 'To: ' + to + '\r\n';
  18417. response += 'From: ' + this.getHeader('From') + '\r\n';
  18418. response += 'Call-ID: ' + this.call_id + '\r\n';
  18419. response += 'CSeq: ' + this.cseq + ' ' + this.method + '\r\n';
  18420. response += 'Content-Length: ' + 0 + '\r\n\r\n';
  18421. this.transport.send(response);
  18422. }
  18423. }]);
  18424. return IncomingRequest;
  18425. }(IncomingMessage);
  18426. var IncomingResponse = function (_IncomingMessage2) {
  18427. _inherits(IncomingResponse, _IncomingMessage2);
  18428. function IncomingResponse() {
  18429. _classCallCheck(this, IncomingResponse);
  18430. var _this3 = _possibleConstructorReturn(this, (IncomingResponse.__proto__ || Object.getPrototypeOf(IncomingResponse)).call(this));
  18431. _this3.headers = {};
  18432. _this3.status_code = null;
  18433. _this3.reason_phrase = null;
  18434. return _this3;
  18435. }
  18436. return IncomingResponse;
  18437. }(IncomingMessage);
  18438. module.exports = {
  18439. OutgoingRequest: OutgoingRequest,
  18440. InitialOutgoingInviteRequest: InitialOutgoingInviteRequest,
  18441. IncomingRequest: IncomingRequest,
  18442. IncomingResponse: IncomingResponse
  18443. };
  18444. },{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":26,"debug":29,"sdp-transform":36}],20:[function(require,module,exports){
  18445. 'use strict';
  18446. var Utils = require('./Utils');
  18447. var Grammar = require('./Grammar');
  18448. var debugerror = require('debug')('JsSIP:ERROR:Socket');
  18449. debugerror.log = console.warn.bind(console);
  18450. /**
  18451. * Interface documentation: http://jssip.net/documentation/$last_version/api/socket/
  18452. *
  18453. * interface Socket {
  18454. * attribute String via_transport
  18455. * attribute String url
  18456. * attribute String sip_uri
  18457. *
  18458. * method connect();
  18459. * method disconnect();
  18460. * method send(data);
  18461. *
  18462. * attribute EventHandler onconnect
  18463. * attribute EventHandler ondisconnect
  18464. * attribute EventHandler ondata
  18465. * }
  18466. *
  18467. */
  18468. exports.isSocket = function (socket) {
  18469. // Ignore if an array is given.
  18470. if (Array.isArray(socket)) {
  18471. return false;
  18472. }
  18473. if (typeof socket === 'undefined') {
  18474. debugerror('undefined JsSIP.Socket instance');
  18475. return false;
  18476. }
  18477. // Check Properties.
  18478. try {
  18479. if (!Utils.isString(socket.url)) {
  18480. debugerror('missing or invalid JsSIP.Socket url property');
  18481. throw new Error();
  18482. }
  18483. if (!Utils.isString(socket.via_transport)) {
  18484. debugerror('missing or invalid JsSIP.Socket via_transport property');
  18485. throw new Error();
  18486. }
  18487. if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) {
  18488. debugerror('missing or invalid JsSIP.Socket sip_uri property');
  18489. throw new Error();
  18490. }
  18491. } catch (e) {
  18492. return false;
  18493. }
  18494. // Check Methods.
  18495. try {
  18496. ['connect', 'disconnect', 'send'].forEach(function (method) {
  18497. if (!Utils.isFunction(socket[method])) {
  18498. debugerror('missing or invalid JsSIP.Socket method: ' + method);
  18499. throw new Error();
  18500. }
  18501. });
  18502. } catch (e) {
  18503. return false;
  18504. }
  18505. return true;
  18506. };
  18507. },{"./Grammar":7,"./Utils":26,"debug":29}],21:[function(require,module,exports){
  18508. "use strict";
  18509. var T1 = 500,
  18510. T2 = 4000,
  18511. T4 = 5000;
  18512. module.exports = {
  18513. T1: T1,
  18514. T2: T2,
  18515. T4: T4,
  18516. TIMER_B: 64 * T1,
  18517. TIMER_D: 0 * T1,
  18518. TIMER_F: 64 * T1,
  18519. TIMER_H: 64 * T1,
  18520. TIMER_I: 0 * T1,
  18521. TIMER_J: 0 * T1,
  18522. TIMER_K: 0 * T4,
  18523. TIMER_L: 64 * T1,
  18524. TIMER_M: 64 * T1,
  18525. PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1
  18526. };
  18527. },{}],22:[function(require,module,exports){
  18528. 'use strict';
  18529. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  18530. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18531. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  18532. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  18533. var EventEmitter = require('events').EventEmitter;
  18534. var JsSIP_C = require('./Constants');
  18535. var SIPMessage = require('./SIPMessage');
  18536. var Timers = require('./Timers');
  18537. var debugnict = require('debug')('JsSIP:NonInviteClientTransaction');
  18538. var debugict = require('debug')('JsSIP:InviteClientTransaction');
  18539. var debugact = require('debug')('JsSIP:AckClientTransaction');
  18540. var debugnist = require('debug')('JsSIP:NonInviteServerTransaction');
  18541. var debugist = require('debug')('JsSIP:InviteServerTransaction');
  18542. var C = {
  18543. // Transaction states.
  18544. STATUS_TRYING: 1,
  18545. STATUS_PROCEEDING: 2,
  18546. STATUS_CALLING: 3,
  18547. STATUS_ACCEPTED: 4,
  18548. STATUS_COMPLETED: 5,
  18549. STATUS_TERMINATED: 6,
  18550. STATUS_CONFIRMED: 7,
  18551. // Transaction types.
  18552. NON_INVITE_CLIENT: 'nict',
  18553. NON_INVITE_SERVER: 'nist',
  18554. INVITE_CLIENT: 'ict',
  18555. INVITE_SERVER: 'ist'
  18556. };
  18557. var NonInviteClientTransaction = function (_EventEmitter) {
  18558. _inherits(NonInviteClientTransaction, _EventEmitter);
  18559. function NonInviteClientTransaction(ua, transport, request, eventHandlers) {
  18560. _classCallCheck(this, NonInviteClientTransaction);
  18561. var _this = _possibleConstructorReturn(this, (NonInviteClientTransaction.__proto__ || Object.getPrototypeOf(NonInviteClientTransaction)).call(this));
  18562. _this.type = C.NON_INVITE_CLIENT;
  18563. _this.id = 'z9hG4bK' + Math.floor(Math.random() * 10000000);
  18564. _this.ua = ua;
  18565. _this.transport = transport;
  18566. _this.request = request;
  18567. _this.eventHandlers = eventHandlers;
  18568. var via = 'SIP/2.0/' + transport.via_transport;
  18569. via += ' ' + ua.configuration.via_host + ';branch=' + _this.id;
  18570. _this.request.setHeader('via', via);
  18571. _this.ua.newTransaction(_this);
  18572. return _this;
  18573. }
  18574. _createClass(NonInviteClientTransaction, [{
  18575. key: 'stateChanged',
  18576. value: function stateChanged(state) {
  18577. this.state = state;
  18578. this.emit('stateChanged');
  18579. }
  18580. }, {
  18581. key: 'send',
  18582. value: function send() {
  18583. var _this2 = this;
  18584. this.stateChanged(C.STATUS_TRYING);
  18585. this.F = setTimeout(function () {
  18586. _this2.timer_F();
  18587. }, Timers.TIMER_F);
  18588. if (!this.transport.send(this.request)) {
  18589. this.onTransportError();
  18590. }
  18591. }
  18592. }, {
  18593. key: 'onTransportError',
  18594. value: function onTransportError() {
  18595. debugnict('transport error occurred, deleting transaction ' + this.id);
  18596. clearTimeout(this.F);
  18597. clearTimeout(this.K);
  18598. this.stateChanged(C.STATUS_TERMINATED);
  18599. this.ua.destroyTransaction(this);
  18600. this.eventHandlers.onTransportError();
  18601. }
  18602. }, {
  18603. key: 'timer_F',
  18604. value: function timer_F() {
  18605. debugnict('Timer F expired for transaction ' + this.id);
  18606. this.stateChanged(C.STATUS_TERMINATED);
  18607. this.ua.destroyTransaction(this);
  18608. this.eventHandlers.onRequestTimeout();
  18609. }
  18610. }, {
  18611. key: 'timer_K',
  18612. value: function timer_K() {
  18613. this.stateChanged(C.STATUS_TERMINATED);
  18614. this.ua.destroyTransaction(this);
  18615. }
  18616. }, {
  18617. key: 'receiveResponse',
  18618. value: function receiveResponse(response) {
  18619. var _this3 = this;
  18620. var status_code = response.status_code;
  18621. if (status_code < 200) {
  18622. switch (this.state) {
  18623. case C.STATUS_TRYING:
  18624. case C.STATUS_PROCEEDING:
  18625. this.stateChanged(C.STATUS_PROCEEDING);
  18626. this.eventHandlers.onReceiveResponse(response);
  18627. break;
  18628. }
  18629. } else {
  18630. switch (this.state) {
  18631. case C.STATUS_TRYING:
  18632. case C.STATUS_PROCEEDING:
  18633. this.stateChanged(C.STATUS_COMPLETED);
  18634. clearTimeout(this.F);
  18635. if (status_code === 408) {
  18636. this.eventHandlers.onRequestTimeout();
  18637. } else {
  18638. this.eventHandlers.onReceiveResponse(response);
  18639. }
  18640. this.K = setTimeout(function () {
  18641. _this3.timer_K();
  18642. }, Timers.TIMER_K);
  18643. break;
  18644. case C.STATUS_COMPLETED:
  18645. break;
  18646. }
  18647. }
  18648. }
  18649. }, {
  18650. key: 'C',
  18651. get: function get() {
  18652. return C;
  18653. }
  18654. }]);
  18655. return NonInviteClientTransaction;
  18656. }(EventEmitter);
  18657. var InviteClientTransaction = function (_EventEmitter2) {
  18658. _inherits(InviteClientTransaction, _EventEmitter2);
  18659. function InviteClientTransaction(ua, transport, request, eventHandlers) {
  18660. _classCallCheck(this, InviteClientTransaction);
  18661. var _this4 = _possibleConstructorReturn(this, (InviteClientTransaction.__proto__ || Object.getPrototypeOf(InviteClientTransaction)).call(this));
  18662. _this4.type = C.INVITE_CLIENT;
  18663. _this4.id = 'z9hG4bK' + Math.floor(Math.random() * 10000000);
  18664. _this4.ua = ua;
  18665. _this4.transport = transport;
  18666. _this4.request = request;
  18667. _this4.eventHandlers = eventHandlers;
  18668. request.transaction = _this4;
  18669. var via = 'SIP/2.0/' + transport.via_transport;
  18670. via += ' ' + ua.configuration.via_host + ';branch=' + _this4.id;
  18671. _this4.request.setHeader('via', via);
  18672. _this4.ua.newTransaction(_this4);
  18673. return _this4;
  18674. }
  18675. _createClass(InviteClientTransaction, [{
  18676. key: 'stateChanged',
  18677. value: function stateChanged(state) {
  18678. this.state = state;
  18679. this.emit('stateChanged');
  18680. }
  18681. }, {
  18682. key: 'send',
  18683. value: function send() {
  18684. var _this5 = this;
  18685. this.stateChanged(C.STATUS_CALLING);
  18686. this.B = setTimeout(function () {
  18687. _this5.timer_B();
  18688. }, Timers.TIMER_B);
  18689. if (!this.transport.send(this.request)) {
  18690. this.onTransportError();
  18691. }
  18692. }
  18693. }, {
  18694. key: 'onTransportError',
  18695. value: function onTransportError() {
  18696. clearTimeout(this.B);
  18697. clearTimeout(this.D);
  18698. clearTimeout(this.M);
  18699. if (this.state !== C.STATUS_ACCEPTED) {
  18700. debugict('transport error occurred, deleting transaction ' + this.id);
  18701. this.eventHandlers.onTransportError();
  18702. }
  18703. this.stateChanged(C.STATUS_TERMINATED);
  18704. this.ua.destroyTransaction(this);
  18705. }
  18706. // RFC 6026 7.2.
  18707. }, {
  18708. key: 'timer_M',
  18709. value: function timer_M() {
  18710. debugict('Timer M expired for transaction ' + this.id);
  18711. if (this.state === C.STATUS_ACCEPTED) {
  18712. clearTimeout(this.B);
  18713. this.stateChanged(C.STATUS_TERMINATED);
  18714. this.ua.destroyTransaction(this);
  18715. }
  18716. }
  18717. // RFC 3261 17.1.1.
  18718. }, {
  18719. key: 'timer_B',
  18720. value: function timer_B() {
  18721. debugict('Timer B expired for transaction ' + this.id);
  18722. if (this.state === C.STATUS_CALLING) {
  18723. this.stateChanged(C.STATUS_TERMINATED);
  18724. this.ua.destroyTransaction(this);
  18725. this.eventHandlers.onRequestTimeout();
  18726. }
  18727. }
  18728. }, {
  18729. key: 'timer_D',
  18730. value: function timer_D() {
  18731. debugict('Timer D expired for transaction ' + this.id);
  18732. clearTimeout(this.B);
  18733. this.stateChanged(C.STATUS_TERMINATED);
  18734. this.ua.destroyTransaction(this);
  18735. }
  18736. }, {
  18737. key: 'sendACK',
  18738. value: function sendACK(response) {
  18739. var _this6 = this;
  18740. var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, {
  18741. 'route_set': this.request.getHeader('route'),
  18742. 'call_id': this.request.getHeader('call-id'),
  18743. 'cseq': this.request.cseq
  18744. });
  18745. ack.setHeader('from', this.request.getHeader('from'));
  18746. ack.setHeader('via', this.request.getHeader('via'));
  18747. ack.setHeader('to', response.getHeader('to'));
  18748. this.D = setTimeout(function () {
  18749. _this6.timer_D();
  18750. }, Timers.TIMER_D);
  18751. this.transport.send(ack);
  18752. }
  18753. }, {
  18754. key: 'cancel',
  18755. value: function cancel(reason) {
  18756. // Send only if a provisional response (>100) has been received.
  18757. if (this.state !== C.STATUS_PROCEEDING) {
  18758. return;
  18759. }
  18760. var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, {
  18761. 'route_set': this.request.getHeader('route'),
  18762. 'call_id': this.request.getHeader('call-id'),
  18763. 'cseq': this.request.cseq
  18764. });
  18765. cancel.setHeader('from', this.request.getHeader('from'));
  18766. cancel.setHeader('via', this.request.getHeader('via'));
  18767. cancel.setHeader('to', this.request.getHeader('to'));
  18768. if (reason) {
  18769. cancel.setHeader('reason', reason);
  18770. }
  18771. this.transport.send(cancel);
  18772. }
  18773. }, {
  18774. key: 'receiveResponse',
  18775. value: function receiveResponse(response) {
  18776. var _this7 = this;
  18777. var status_code = response.status_code;
  18778. if (status_code >= 100 && status_code <= 199) {
  18779. switch (this.state) {
  18780. case C.STATUS_CALLING:
  18781. this.stateChanged(C.STATUS_PROCEEDING);
  18782. this.eventHandlers.onReceiveResponse(response);
  18783. break;
  18784. case C.STATUS_PROCEEDING:
  18785. this.eventHandlers.onReceiveResponse(response);
  18786. break;
  18787. }
  18788. } else if (status_code >= 200 && status_code <= 299) {
  18789. switch (this.state) {
  18790. case C.STATUS_CALLING:
  18791. case C.STATUS_PROCEEDING:
  18792. this.stateChanged(C.STATUS_ACCEPTED);
  18793. this.M = setTimeout(function () {
  18794. _this7.timer_M();
  18795. }, Timers.TIMER_M);
  18796. this.eventHandlers.onReceiveResponse(response);
  18797. break;
  18798. case C.STATUS_ACCEPTED:
  18799. this.eventHandlers.onReceiveResponse(response);
  18800. break;
  18801. }
  18802. } else if (status_code >= 300 && status_code <= 699) {
  18803. switch (this.state) {
  18804. case C.STATUS_CALLING:
  18805. case C.STATUS_PROCEEDING:
  18806. this.stateChanged(C.STATUS_COMPLETED);
  18807. this.sendACK(response);
  18808. this.eventHandlers.onReceiveResponse(response);
  18809. break;
  18810. case C.STATUS_COMPLETED:
  18811. this.sendACK(response);
  18812. break;
  18813. }
  18814. }
  18815. }
  18816. }, {
  18817. key: 'C',
  18818. get: function get() {
  18819. return C;
  18820. }
  18821. }]);
  18822. return InviteClientTransaction;
  18823. }(EventEmitter);
  18824. var AckClientTransaction = function (_EventEmitter3) {
  18825. _inherits(AckClientTransaction, _EventEmitter3);
  18826. function AckClientTransaction(ua, transport, request, eventHandlers) {
  18827. _classCallCheck(this, AckClientTransaction);
  18828. var _this8 = _possibleConstructorReturn(this, (AckClientTransaction.__proto__ || Object.getPrototypeOf(AckClientTransaction)).call(this));
  18829. _this8.id = 'z9hG4bK' + Math.floor(Math.random() * 10000000);
  18830. _this8.transport = transport;
  18831. _this8.request = request;
  18832. _this8.eventHandlers = eventHandlers;
  18833. var via = 'SIP/2.0/' + transport.via_transport;
  18834. via += ' ' + ua.configuration.via_host + ';branch=' + _this8.id;
  18835. _this8.request.setHeader('via', via);
  18836. return _this8;
  18837. }
  18838. _createClass(AckClientTransaction, [{
  18839. key: 'send',
  18840. value: function send() {
  18841. if (!this.transport.send(this.request)) {
  18842. this.onTransportError();
  18843. }
  18844. }
  18845. }, {
  18846. key: 'onTransportError',
  18847. value: function onTransportError() {
  18848. debugact('transport error occurred for transaction ' + this.id);
  18849. this.eventHandlers.onTransportError();
  18850. }
  18851. }, {
  18852. key: 'C',
  18853. get: function get() {
  18854. return C;
  18855. }
  18856. }]);
  18857. return AckClientTransaction;
  18858. }(EventEmitter);
  18859. var NonInviteServerTransaction = function (_EventEmitter4) {
  18860. _inherits(NonInviteServerTransaction, _EventEmitter4);
  18861. function NonInviteServerTransaction(ua, transport, request) {
  18862. _classCallCheck(this, NonInviteServerTransaction);
  18863. var _this9 = _possibleConstructorReturn(this, (NonInviteServerTransaction.__proto__ || Object.getPrototypeOf(NonInviteServerTransaction)).call(this));
  18864. _this9.type = C.NON_INVITE_SERVER;
  18865. _this9.id = request.via_branch;
  18866. _this9.ua = ua;
  18867. _this9.transport = transport;
  18868. _this9.request = request;
  18869. _this9.last_response = '';
  18870. request.server_transaction = _this9;
  18871. _this9.state = C.STATUS_TRYING;
  18872. ua.newTransaction(_this9);
  18873. return _this9;
  18874. }
  18875. _createClass(NonInviteServerTransaction, [{
  18876. key: 'stateChanged',
  18877. value: function stateChanged(state) {
  18878. this.state = state;
  18879. this.emit('stateChanged');
  18880. }
  18881. }, {
  18882. key: 'timer_J',
  18883. value: function timer_J() {
  18884. debugnist('Timer J expired for transaction ' + this.id);
  18885. this.stateChanged(C.STATUS_TERMINATED);
  18886. this.ua.destroyTransaction(this);
  18887. }
  18888. }, {
  18889. key: 'onTransportError',
  18890. value: function onTransportError() {
  18891. if (!this.transportError) {
  18892. this.transportError = true;
  18893. debugnist('transport error occurred, deleting transaction ' + this.id);
  18894. clearTimeout(this.J);
  18895. this.stateChanged(C.STATUS_TERMINATED);
  18896. this.ua.destroyTransaction(this);
  18897. }
  18898. }
  18899. }, {
  18900. key: 'receiveResponse',
  18901. value: function receiveResponse(status_code, response, onSuccess, onFailure) {
  18902. var _this10 = this;
  18903. if (status_code === 100) {
  18904. /* RFC 4320 4.1
  18905. * 'A SIP element MUST NOT
  18906. * send any provisional response with a
  18907. * Status-Code other than 100 to a non-INVITE request.'
  18908. */
  18909. switch (this.state) {
  18910. case C.STATUS_TRYING:
  18911. this.stateChanged(C.STATUS_PROCEEDING);
  18912. if (!this.transport.send(response)) {
  18913. this.onTransportError();
  18914. }
  18915. break;
  18916. case C.STATUS_PROCEEDING:
  18917. this.last_response = response;
  18918. if (!this.transport.send(response)) {
  18919. this.onTransportError();
  18920. if (onFailure) {
  18921. onFailure();
  18922. }
  18923. } else if (onSuccess) {
  18924. onSuccess();
  18925. }
  18926. break;
  18927. }
  18928. } else if (status_code >= 200 && status_code <= 699) {
  18929. switch (this.state) {
  18930. case C.STATUS_TRYING:
  18931. case C.STATUS_PROCEEDING:
  18932. this.stateChanged(C.STATUS_COMPLETED);
  18933. this.last_response = response;
  18934. this.J = setTimeout(function () {
  18935. _this10.timer_J();
  18936. }, Timers.TIMER_J);
  18937. if (!this.transport.send(response)) {
  18938. this.onTransportError();
  18939. if (onFailure) {
  18940. onFailure();
  18941. }
  18942. } else if (onSuccess) {
  18943. onSuccess();
  18944. }
  18945. break;
  18946. case C.STATUS_COMPLETED:
  18947. break;
  18948. }
  18949. }
  18950. }
  18951. }, {
  18952. key: 'C',
  18953. get: function get() {
  18954. return C;
  18955. }
  18956. }]);
  18957. return NonInviteServerTransaction;
  18958. }(EventEmitter);
  18959. var InviteServerTransaction = function (_EventEmitter5) {
  18960. _inherits(InviteServerTransaction, _EventEmitter5);
  18961. function InviteServerTransaction(ua, transport, request) {
  18962. _classCallCheck(this, InviteServerTransaction);
  18963. var _this11 = _possibleConstructorReturn(this, (InviteServerTransaction.__proto__ || Object.getPrototypeOf(InviteServerTransaction)).call(this));
  18964. _this11.type = C.INVITE_SERVER;
  18965. _this11.id = request.via_branch;
  18966. _this11.ua = ua;
  18967. _this11.transport = transport;
  18968. _this11.request = request;
  18969. _this11.last_response = '';
  18970. request.server_transaction = _this11;
  18971. _this11.state = C.STATUS_PROCEEDING;
  18972. ua.newTransaction(_this11);
  18973. _this11.resendProvisionalTimer = null;
  18974. request.reply(100);
  18975. return _this11;
  18976. }
  18977. _createClass(InviteServerTransaction, [{
  18978. key: 'stateChanged',
  18979. value: function stateChanged(state) {
  18980. this.state = state;
  18981. this.emit('stateChanged');
  18982. }
  18983. }, {
  18984. key: 'timer_H',
  18985. value: function timer_H() {
  18986. debugist('Timer H expired for transaction ' + this.id);
  18987. if (this.state === C.STATUS_COMPLETED) {
  18988. debugist('ACK not received, dialog will be terminated');
  18989. }
  18990. this.stateChanged(C.STATUS_TERMINATED);
  18991. this.ua.destroyTransaction(this);
  18992. }
  18993. }, {
  18994. key: 'timer_I',
  18995. value: function timer_I() {
  18996. this.stateChanged(C.STATUS_TERMINATED);
  18997. }
  18998. // RFC 6026 7.1.
  18999. }, {
  19000. key: 'timer_L',
  19001. value: function timer_L() {
  19002. debugist('Timer L expired for transaction ' + this.id);
  19003. if (this.state === C.STATUS_ACCEPTED) {
  19004. this.stateChanged(C.STATUS_TERMINATED);
  19005. this.ua.destroyTransaction(this);
  19006. }
  19007. }
  19008. }, {
  19009. key: 'onTransportError',
  19010. value: function onTransportError() {
  19011. if (!this.transportError) {
  19012. this.transportError = true;
  19013. debugist('transport error occurred, deleting transaction ' + this.id);
  19014. if (this.resendProvisionalTimer !== null) {
  19015. clearInterval(this.resendProvisionalTimer);
  19016. this.resendProvisionalTimer = null;
  19017. }
  19018. clearTimeout(this.L);
  19019. clearTimeout(this.H);
  19020. clearTimeout(this.I);
  19021. this.stateChanged(C.STATUS_TERMINATED);
  19022. this.ua.destroyTransaction(this);
  19023. }
  19024. }
  19025. }, {
  19026. key: 'resend_provisional',
  19027. value: function resend_provisional() {
  19028. if (!this.transport.send(this.last_response)) {
  19029. this.onTransportError();
  19030. }
  19031. }
  19032. // INVITE Server Transaction RFC 3261 17.2.1.
  19033. }, {
  19034. key: 'receiveResponse',
  19035. value: function receiveResponse(status_code, response, onSuccess, onFailure) {
  19036. var _this12 = this;
  19037. if (status_code >= 100 && status_code <= 199) {
  19038. switch (this.state) {
  19039. case C.STATUS_PROCEEDING:
  19040. if (!this.transport.send(response)) {
  19041. this.onTransportError();
  19042. }
  19043. this.last_response = response;
  19044. break;
  19045. }
  19046. }
  19047. if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) {
  19048. // Trigger the resendProvisionalTimer only for the first non 100 provisional response.
  19049. if (this.resendProvisionalTimer === null) {
  19050. this.resendProvisionalTimer = setInterval(function () {
  19051. _this12.resend_provisional();
  19052. }, Timers.PROVISIONAL_RESPONSE_INTERVAL);
  19053. }
  19054. } else if (status_code >= 200 && status_code <= 299) {
  19055. switch (this.state) {
  19056. case C.STATUS_PROCEEDING:
  19057. this.stateChanged(C.STATUS_ACCEPTED);
  19058. this.last_response = response;
  19059. this.L = setTimeout(function () {
  19060. _this12.timer_L();
  19061. }, Timers.TIMER_L);
  19062. if (this.resendProvisionalTimer !== null) {
  19063. clearInterval(this.resendProvisionalTimer);
  19064. this.resendProvisionalTimer = null;
  19065. }
  19066. /* falls through */
  19067. case C.STATUS_ACCEPTED:
  19068. // Note that this point will be reached for proceeding this.state also.
  19069. if (!this.transport.send(response)) {
  19070. this.onTransportError();
  19071. if (onFailure) {
  19072. onFailure();
  19073. }
  19074. } else if (onSuccess) {
  19075. onSuccess();
  19076. }
  19077. break;
  19078. }
  19079. } else if (status_code >= 300 && status_code <= 699) {
  19080. switch (this.state) {
  19081. case C.STATUS_PROCEEDING:
  19082. if (this.resendProvisionalTimer !== null) {
  19083. clearInterval(this.resendProvisionalTimer);
  19084. this.resendProvisionalTimer = null;
  19085. }
  19086. if (!this.transport.send(response)) {
  19087. this.onTransportError();
  19088. if (onFailure) {
  19089. onFailure();
  19090. }
  19091. } else {
  19092. this.stateChanged(C.STATUS_COMPLETED);
  19093. this.H = setTimeout(function () {
  19094. _this12.timer_H();
  19095. }, Timers.TIMER_H);
  19096. if (onSuccess) {
  19097. onSuccess();
  19098. }
  19099. }
  19100. break;
  19101. }
  19102. }
  19103. }
  19104. }, {
  19105. key: 'C',
  19106. get: function get() {
  19107. return C;
  19108. }
  19109. }]);
  19110. return InviteServerTransaction;
  19111. }(EventEmitter);
  19112. /**
  19113. * INVITE:
  19114. * _true_ if retransmission
  19115. * _false_ new request
  19116. *
  19117. * ACK:
  19118. * _true_ ACK to non2xx response
  19119. * _false_ ACK must be passed to TU (accepted state)
  19120. * ACK to 2xx response
  19121. *
  19122. * CANCEL:
  19123. * _true_ no matching invite transaction
  19124. * _false_ matching invite transaction and no final response sent
  19125. *
  19126. * OTHER:
  19127. * _true_ retransmission
  19128. * _false_ new request
  19129. */
  19130. function checkTransaction(_ref, request) {
  19131. var _transactions = _ref._transactions;
  19132. var tr = void 0;
  19133. switch (request.method) {
  19134. case JsSIP_C.INVITE:
  19135. tr = _transactions.ist[request.via_branch];
  19136. if (tr) {
  19137. switch (tr.state) {
  19138. case C.STATUS_PROCEEDING:
  19139. tr.transport.send(tr.last_response);
  19140. break;
  19141. // RFC 6026 7.1 Invite retransmission.
  19142. // Received while in C.STATUS_ACCEPTED state. Absorb it.
  19143. case C.STATUS_ACCEPTED:
  19144. break;
  19145. }
  19146. return true;
  19147. }
  19148. break;
  19149. case JsSIP_C.ACK:
  19150. tr = _transactions.ist[request.via_branch];
  19151. // RFC 6026 7.1.
  19152. if (tr) {
  19153. if (tr.state === C.STATUS_ACCEPTED) {
  19154. return false;
  19155. } else if (tr.state === C.STATUS_COMPLETED) {
  19156. tr.state = C.STATUS_CONFIRMED;
  19157. tr.I = setTimeout(function () {
  19158. tr.timer_I();
  19159. }, Timers.TIMER_I);
  19160. return true;
  19161. }
  19162. }
  19163. // ACK to 2XX Response.
  19164. else {
  19165. return false;
  19166. }
  19167. break;
  19168. case JsSIP_C.CANCEL:
  19169. tr = _transactions.ist[request.via_branch];
  19170. if (tr) {
  19171. request.reply_sl(200);
  19172. if (tr.state === C.STATUS_PROCEEDING) {
  19173. return false;
  19174. } else {
  19175. return true;
  19176. }
  19177. } else {
  19178. request.reply_sl(481);
  19179. return true;
  19180. }
  19181. default:
  19182. // Non-INVITE Server Transaction RFC 3261 17.2.2.
  19183. tr = _transactions.nist[request.via_branch];
  19184. if (tr) {
  19185. switch (tr.state) {
  19186. case C.STATUS_TRYING:
  19187. break;
  19188. case C.STATUS_PROCEEDING:
  19189. case C.STATUS_COMPLETED:
  19190. tr.transport.send(tr.last_response);
  19191. break;
  19192. }
  19193. return true;
  19194. }
  19195. break;
  19196. }
  19197. }
  19198. module.exports = {
  19199. C: C,
  19200. NonInviteClientTransaction: NonInviteClientTransaction,
  19201. InviteClientTransaction: InviteClientTransaction,
  19202. AckClientTransaction: AckClientTransaction,
  19203. NonInviteServerTransaction: NonInviteServerTransaction,
  19204. InviteServerTransaction: InviteServerTransaction,
  19205. checkTransaction: checkTransaction
  19206. };
  19207. },{"./Constants":2,"./SIPMessage":19,"./Timers":21,"debug":29,"events":31}],23:[function(require,module,exports){
  19208. 'use strict';
  19209. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  19210. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19211. var Socket = require('./Socket');
  19212. var debug = require('debug')('JsSIP:Transport');
  19213. var debugerror = require('debug')('JsSIP:ERROR:Transport');
  19214. debugerror.log = console.warn.bind(console);
  19215. /**
  19216. * Constants
  19217. */
  19218. var C = {
  19219. // Transport status.
  19220. STATUS_CONNECTED: 0,
  19221. STATUS_CONNECTING: 1,
  19222. STATUS_DISCONNECTED: 2,
  19223. // Socket status.
  19224. SOCKET_STATUS_READY: 0,
  19225. SOCKET_STATUS_ERROR: 1,
  19226. // Recovery options.
  19227. recovery_options: {
  19228. min_interval: 2, // minimum interval in seconds between recover attempts
  19229. max_interval: 30 // maximum interval in seconds between recover attempts
  19230. }
  19231. };
  19232. /*
  19233. * Manages one or multiple JsSIP.Socket instances.
  19234. * Is reponsible for transport recovery logic among all socket instances.
  19235. *
  19236. * @socket JsSIP::Socket instance
  19237. */
  19238. module.exports = function () {
  19239. function Transport(sockets) {
  19240. var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options;
  19241. _classCallCheck(this, Transport);
  19242. debug('new()');
  19243. this.status = C.STATUS_DISCONNECTED;
  19244. // Current socket.
  19245. this.socket = null;
  19246. // Socket collection.
  19247. this.sockets = [];
  19248. this.recovery_options = recovery_options;
  19249. this.recover_attempts = 0;
  19250. this.recovery_timer = null;
  19251. this.close_requested = false;
  19252. if (typeof sockets === 'undefined') {
  19253. throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument');
  19254. }
  19255. if (!(sockets instanceof Array)) {
  19256. sockets = [sockets];
  19257. }
  19258. sockets.forEach(function (socket) {
  19259. if (!Socket.isSocket(socket.socket)) {
  19260. throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance');
  19261. }
  19262. if (socket.weight && !Number(socket.weight)) {
  19263. throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number');
  19264. }
  19265. this.sockets.push({
  19266. socket: socket.socket,
  19267. weight: socket.weight || 0,
  19268. status: C.SOCKET_STATUS_READY
  19269. });
  19270. }, this);
  19271. // Get the socket with higher weight.
  19272. this._getSocket();
  19273. }
  19274. /**
  19275. * Instance Methods
  19276. */
  19277. _createClass(Transport, [{
  19278. key: 'connect',
  19279. value: function connect() {
  19280. debug('connect()');
  19281. if (this.isConnected()) {
  19282. debug('Transport is already connected');
  19283. return;
  19284. } else if (this.isConnecting()) {
  19285. debug('Transport is connecting');
  19286. return;
  19287. }
  19288. this.close_requested = false;
  19289. this.status = C.STATUS_CONNECTING;
  19290. this.onconnecting({ socket: this.socket, attempts: this.recover_attempts });
  19291. if (!this.close_requested) {
  19292. // Bind socket event callbacks.
  19293. this.socket.onconnect = this._onConnect.bind(this);
  19294. this.socket.ondisconnect = this._onDisconnect.bind(this);
  19295. this.socket.ondata = this._onData.bind(this);
  19296. this.socket.connect();
  19297. }
  19298. return;
  19299. }
  19300. }, {
  19301. key: 'disconnect',
  19302. value: function disconnect() {
  19303. debug('close()');
  19304. this.close_requested = true;
  19305. this.recover_attempts = 0;
  19306. this.status = C.STATUS_DISCONNECTED;
  19307. // Clear recovery_timer.
  19308. if (this.recovery_timer !== null) {
  19309. clearTimeout(this.recovery_timer);
  19310. this.recovery_timer = null;
  19311. }
  19312. // Unbind socket event callbacks.
  19313. this.socket.onconnect = function () {};
  19314. this.socket.ondisconnect = function () {};
  19315. this.socket.ondata = function () {};
  19316. this.socket.disconnect();
  19317. this.ondisconnect();
  19318. }
  19319. }, {
  19320. key: 'send',
  19321. value: function send(data) {
  19322. debug('send()');
  19323. if (!this.isConnected()) {
  19324. debugerror('unable to send message, transport is not connected');
  19325. return false;
  19326. }
  19327. var message = data.toString();
  19328. debug('sending message:\n\n' + message + '\n');
  19329. return this.socket.send(message);
  19330. }
  19331. }, {
  19332. key: 'isConnected',
  19333. value: function isConnected() {
  19334. return this.status === C.STATUS_CONNECTED;
  19335. }
  19336. }, {
  19337. key: 'isConnecting',
  19338. value: function isConnecting() {
  19339. return this.status === C.STATUS_CONNECTING;
  19340. }
  19341. /**
  19342. * Private API.
  19343. */
  19344. }, {
  19345. key: '_reconnect',
  19346. value: function _reconnect() {
  19347. var _this = this;
  19348. this.recover_attempts += 1;
  19349. var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1);
  19350. if (k < this.recovery_options.min_interval) {
  19351. k = this.recovery_options.min_interval;
  19352. } else if (k > this.recovery_options.max_interval) {
  19353. k = this.recovery_options.max_interval;
  19354. }
  19355. debug('reconnection attempt: ' + this.recover_attempts + '. next connection attempt in ' + k + ' seconds');
  19356. this.recovery_timer = setTimeout(function () {
  19357. if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) {
  19358. // Get the next available socket with higher weight.
  19359. _this._getSocket();
  19360. // Connect the socket.
  19361. _this.connect();
  19362. }
  19363. }, k * 1000);
  19364. }
  19365. /**
  19366. * get the next available socket with higher weight
  19367. */
  19368. }, {
  19369. key: '_getSocket',
  19370. value: function _getSocket() {
  19371. var candidates = [];
  19372. this.sockets.forEach(function (socket) {
  19373. if (socket.status === C.SOCKET_STATUS_ERROR) {
  19374. return; // continue the array iteration
  19375. } else if (candidates.length === 0) {
  19376. candidates.push(socket);
  19377. } else if (socket.weight > candidates[0].weight) {
  19378. candidates = [socket];
  19379. } else if (socket.weight === candidates[0].weight) {
  19380. candidates.push(socket);
  19381. }
  19382. });
  19383. if (candidates.length === 0) {
  19384. // All sockets have failed. reset sockets status.
  19385. this.sockets.forEach(function (socket) {
  19386. socket.status = C.SOCKET_STATUS_READY;
  19387. });
  19388. // Get next available socket.
  19389. this._getSocket();
  19390. return;
  19391. }
  19392. var idx = Math.floor(Math.random() * candidates.length);
  19393. this.socket = candidates[idx].socket;
  19394. }
  19395. /**
  19396. * Socket Event Handlers
  19397. */
  19398. }, {
  19399. key: '_onConnect',
  19400. value: function _onConnect() {
  19401. this.recover_attempts = 0;
  19402. this.status = C.STATUS_CONNECTED;
  19403. // Clear recovery_timer.
  19404. if (this.recovery_timer !== null) {
  19405. clearTimeout(this.recovery_timer);
  19406. this.recovery_timer = null;
  19407. }
  19408. this.onconnect({ socket: this });
  19409. }
  19410. }, {
  19411. key: '_onDisconnect',
  19412. value: function _onDisconnect(error, code, reason) {
  19413. this.status = C.STATUS_DISCONNECTED;
  19414. this.ondisconnect({
  19415. socket: this.socket,
  19416. error: error,
  19417. code: code,
  19418. reason: reason
  19419. });
  19420. if (this.close_requested) {
  19421. return;
  19422. }
  19423. // Update socket status.
  19424. else {
  19425. this.sockets.forEach(function (socket) {
  19426. if (this.socket === socket.socket) {
  19427. socket.status = C.SOCKET_STATUS_ERROR;
  19428. }
  19429. }, this);
  19430. }
  19431. this._reconnect(error);
  19432. }
  19433. }, {
  19434. key: '_onData',
  19435. value: function _onData(data) {
  19436. // CRLF Keep Alive response from server. Ignore it.
  19437. if (data === '\r\n') {
  19438. debug('received message with CRLF Keep Alive response');
  19439. return;
  19440. }
  19441. // Binary message.
  19442. else if (typeof data !== 'string') {
  19443. try {
  19444. data = String.fromCharCode.apply(null, new Uint8Array(data));
  19445. } catch (evt) {
  19446. debug('received binary message failed to be converted into string,' + ' message discarded');
  19447. return;
  19448. }
  19449. debug('received binary message:\n\n' + data + '\n');
  19450. }
  19451. // Text message.
  19452. else {
  19453. debug('received text message:\n\n' + data + '\n');
  19454. }
  19455. this.ondata({ transport: this, message: data });
  19456. }
  19457. }, {
  19458. key: 'via_transport',
  19459. get: function get() {
  19460. return this.socket.via_transport;
  19461. }
  19462. }, {
  19463. key: 'url',
  19464. get: function get() {
  19465. return this.socket.url;
  19466. }
  19467. }, {
  19468. key: 'sip_uri',
  19469. get: function get() {
  19470. return this.socket.sip_uri;
  19471. }
  19472. }]);
  19473. return Transport;
  19474. }();
  19475. },{"./Socket":20,"debug":29}],24:[function(require,module,exports){
  19476. 'use strict';
  19477. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  19478. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19479. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  19480. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  19481. var EventEmitter = require('events').EventEmitter;
  19482. var JsSIP_C = require('./Constants');
  19483. var Registrator = require('./Registrator');
  19484. var RTCSession = require('./RTCSession');
  19485. var Message = require('./Message');
  19486. var Transactions = require('./Transactions');
  19487. var Transport = require('./Transport');
  19488. var Utils = require('./Utils');
  19489. var Exceptions = require('./Exceptions');
  19490. var URI = require('./URI');
  19491. var Grammar = require('./Grammar');
  19492. var Parser = require('./Parser');
  19493. var SIPMessage = require('./SIPMessage');
  19494. var sanityCheck = require('./sanityCheck');
  19495. var config = require('./Config');
  19496. var debug = require('debug')('JsSIP:UA');
  19497. var debugerror = require('debug')('JsSIP:ERROR:UA');
  19498. debugerror.log = console.warn.bind(console);
  19499. var C = {
  19500. // UA status codes.
  19501. STATUS_INIT: 0,
  19502. STATUS_READY: 1,
  19503. STATUS_USER_CLOSED: 2,
  19504. STATUS_NOT_READY: 3,
  19505. // UA error codes.
  19506. CONFIGURATION_ERROR: 1,
  19507. NETWORK_ERROR: 2
  19508. };
  19509. /**
  19510. * The User-Agent class.
  19511. * @class JsSIP.UA
  19512. * @param {Object} configuration Configuration parameters.
  19513. * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid.
  19514. * @throws {TypeError} If no configuration is given.
  19515. */
  19516. module.exports = function (_EventEmitter) {
  19517. _inherits(UA, _EventEmitter);
  19518. _createClass(UA, null, [{
  19519. key: 'C',
  19520. // Expose C object.
  19521. get: function get() {
  19522. return C;
  19523. }
  19524. }]);
  19525. function UA(configuration) {
  19526. _classCallCheck(this, UA);
  19527. debug('new() [configuration:%o]', configuration);
  19528. var _this = _possibleConstructorReturn(this, (UA.__proto__ || Object.getPrototypeOf(UA)).call(this));
  19529. _this._cache = {
  19530. credentials: {}
  19531. };
  19532. _this._configuration = Object.assign({}, config.settings);
  19533. _this._dynConfiguration = {};
  19534. _this._dialogs = {};
  19535. // User actions outside any session/dialog (MESSAGE).
  19536. _this._applicants = {};
  19537. _this._sessions = {};
  19538. _this._transport = null;
  19539. _this._contact = null;
  19540. _this._status = C.STATUS_INIT;
  19541. _this._error = null;
  19542. _this._transactions = {
  19543. nist: {},
  19544. nict: {},
  19545. ist: {},
  19546. ict: {}
  19547. };
  19548. // Custom UA empty object for high level use.
  19549. _this._data = {};
  19550. _this._closeTimer = null;
  19551. // Check configuration argument.
  19552. if (configuration === undefined) {
  19553. throw new TypeError('Not enough arguments');
  19554. }
  19555. // Load configuration.
  19556. try {
  19557. _this._loadConfig(configuration);
  19558. } catch (e) {
  19559. _this._status = C.STATUS_NOT_READY;
  19560. _this._error = C.CONFIGURATION_ERROR;
  19561. throw e;
  19562. }
  19563. // Initialize registrator.
  19564. _this._registrator = new Registrator(_this);
  19565. return _this;
  19566. }
  19567. _createClass(UA, [{
  19568. key: 'start',
  19569. // =================
  19570. // High Level API
  19571. // =================
  19572. /**
  19573. * Connect to the server if status = STATUS_INIT.
  19574. * Resume UA after being closed.
  19575. */
  19576. value: function start() {
  19577. debug('start()');
  19578. if (this._status === C.STATUS_INIT) {
  19579. this._transport.connect();
  19580. } else if (this._status === C.STATUS_USER_CLOSED) {
  19581. debug('restarting UA');
  19582. // Disconnect.
  19583. if (this._closeTimer !== null) {
  19584. clearTimeout(this._closeTimer);
  19585. this._closeTimer = null;
  19586. this._transport.disconnect();
  19587. }
  19588. // Reconnect.
  19589. this._status = C.STATUS_INIT;
  19590. this._transport.connect();
  19591. } else if (this._status === C.STATUS_READY) {
  19592. debug('UA is in READY status, not restarted');
  19593. } else {
  19594. debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect');
  19595. }
  19596. // Set dynamic configuration.
  19597. this._dynConfiguration.register = this._configuration.register;
  19598. }
  19599. /**
  19600. * Register.
  19601. */
  19602. }, {
  19603. key: 'register',
  19604. value: function register() {
  19605. debug('register()');
  19606. this._dynConfiguration.register = true;
  19607. this._registrator.register();
  19608. }
  19609. /**
  19610. * Unregister.
  19611. */
  19612. }, {
  19613. key: 'unregister',
  19614. value: function unregister(options) {
  19615. debug('unregister()');
  19616. this._dynConfiguration.register = false;
  19617. this._registrator.unregister(options);
  19618. }
  19619. /**
  19620. * Get the Registrator instance.
  19621. */
  19622. }, {
  19623. key: 'registrator',
  19624. value: function registrator() {
  19625. return this._registrator;
  19626. }
  19627. /**
  19628. * Registration state.
  19629. */
  19630. }, {
  19631. key: 'isRegistered',
  19632. value: function isRegistered() {
  19633. return this._registrator.registered;
  19634. }
  19635. /**
  19636. * Connection state.
  19637. */
  19638. }, {
  19639. key: 'isConnected',
  19640. value: function isConnected() {
  19641. return this._transport.isConnected();
  19642. }
  19643. /**
  19644. * Make an outgoing call.
  19645. *
  19646. * -param {String} target
  19647. * -param {Object} views
  19648. * -param {Object} [options]
  19649. *
  19650. * -throws {TypeError}
  19651. *
  19652. */
  19653. }, {
  19654. key: 'call',
  19655. value: function call(target, options) {
  19656. debug('call()');
  19657. var session = new RTCSession(this);
  19658. session.connect(target, options);
  19659. return session;
  19660. }
  19661. /**
  19662. * Send a message.
  19663. *
  19664. * -param {String} target
  19665. * -param {String} body
  19666. * -param {Object} [options]
  19667. *
  19668. * -throws {TypeError}
  19669. *
  19670. */
  19671. }, {
  19672. key: 'sendMessage',
  19673. value: function sendMessage(target, body, options) {
  19674. debug('sendMessage()');
  19675. var message = new Message(this);
  19676. message.send(target, body, options);
  19677. return message;
  19678. }
  19679. /**
  19680. * Terminate ongoing sessions.
  19681. */
  19682. }, {
  19683. key: 'terminateSessions',
  19684. value: function terminateSessions(options) {
  19685. debug('terminateSessions()');
  19686. for (var idx in this._sessions) {
  19687. if (!this._sessions[idx].isEnded()) {
  19688. this._sessions[idx].terminate(options);
  19689. }
  19690. }
  19691. }
  19692. /**
  19693. * Gracefully close.
  19694. *
  19695. */
  19696. }, {
  19697. key: 'stop',
  19698. value: function stop() {
  19699. var _this2 = this;
  19700. debug('stop()');
  19701. // Remove dynamic settings.
  19702. this._dynConfiguration = {};
  19703. if (this._status === C.STATUS_USER_CLOSED) {
  19704. debug('UA already closed');
  19705. return;
  19706. }
  19707. // Close registrator.
  19708. this._registrator.close();
  19709. // If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
  19710. var num_sessions = Object.keys(this._sessions).length;
  19711. // Run _terminate_ on every Session.
  19712. for (var session in this._sessions) {
  19713. if (Object.prototype.hasOwnProperty.call(this._sessions, session)) {
  19714. debug('closing session ' + session);
  19715. try {
  19716. this._sessions[session].terminate();
  19717. } catch (error) {}
  19718. }
  19719. }
  19720. // Run _close_ on every applicant.
  19721. for (var applicant in this._applicants) {
  19722. if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try {
  19723. this._applicants[applicant].close();
  19724. } catch (error) {}
  19725. }
  19726. this._status = C.STATUS_USER_CLOSED;
  19727. 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;
  19728. if (num_transactions === 0 && num_sessions === 0) {
  19729. this._transport.disconnect();
  19730. } else {
  19731. this._closeTimer = setTimeout(function () {
  19732. _this2._closeTimer = null;
  19733. _this2._transport.disconnect();
  19734. }, 2000);
  19735. }
  19736. }
  19737. /**
  19738. * Normalice a string into a valid SIP request URI
  19739. * -param {String} target
  19740. * -returns {JsSIP.URI|undefined}
  19741. */
  19742. }, {
  19743. key: 'normalizeTarget',
  19744. value: function normalizeTarget(target) {
  19745. return Utils.normalizeTarget(target, this._configuration.hostport_params);
  19746. }
  19747. /**
  19748. * Allow retrieving configuration and autogenerated fields in runtime.
  19749. */
  19750. }, {
  19751. key: 'get',
  19752. value: function get(parameter) {
  19753. switch (parameter) {
  19754. case 'realm':
  19755. return this._configuration.realm;
  19756. case 'ha1':
  19757. return this._configuration.ha1;
  19758. default:
  19759. debugerror('get() | cannot get "%s" parameter in runtime', parameter);
  19760. return undefined;
  19761. }
  19762. }
  19763. /**
  19764. * Allow configuration changes in runtime.
  19765. * Returns true if the parameter could be set.
  19766. */
  19767. }, {
  19768. key: 'set',
  19769. value: function set(parameter, value) {
  19770. switch (parameter) {
  19771. case 'password':
  19772. {
  19773. this._configuration.password = String(value);
  19774. break;
  19775. }
  19776. case 'realm':
  19777. {
  19778. this._configuration.realm = String(value);
  19779. break;
  19780. }
  19781. case 'ha1':
  19782. {
  19783. this._configuration.ha1 = String(value);
  19784. // Delete the plain SIP password.
  19785. this._configuration.password = null;
  19786. break;
  19787. }
  19788. case 'display_name':
  19789. {
  19790. if (Grammar.parse('"' + value + '"', 'display_name') === -1) {
  19791. debugerror('set() | wrong "display_name"');
  19792. return false;
  19793. }
  19794. this._configuration.display_name = value;
  19795. break;
  19796. }
  19797. default:
  19798. debugerror('set() | cannot set "%s" parameter in runtime', parameter);
  19799. return false;
  19800. }
  19801. return true;
  19802. }
  19803. // ==========================
  19804. // Event Handlers.
  19805. // ==========================
  19806. /**
  19807. * new Transaction
  19808. */
  19809. }, {
  19810. key: 'newTransaction',
  19811. value: function newTransaction(transaction) {
  19812. this._transactions[transaction.type][transaction.id] = transaction;
  19813. this.emit('newTransaction', {
  19814. transaction: transaction
  19815. });
  19816. }
  19817. /**
  19818. * Transaction destroyed.
  19819. */
  19820. }, {
  19821. key: 'destroyTransaction',
  19822. value: function destroyTransaction(transaction) {
  19823. delete this._transactions[transaction.type][transaction.id];
  19824. this.emit('transactionDestroyed', {
  19825. transaction: transaction
  19826. });
  19827. }
  19828. /**
  19829. * new Dialog
  19830. */
  19831. }, {
  19832. key: 'newDialog',
  19833. value: function newDialog(dialog) {
  19834. this._dialogs[dialog.id] = dialog;
  19835. }
  19836. /**
  19837. * Dialog destroyed.
  19838. */
  19839. }, {
  19840. key: 'destroyDialog',
  19841. value: function destroyDialog(dialog) {
  19842. delete this._dialogs[dialog.id];
  19843. }
  19844. /**
  19845. * new Message
  19846. */
  19847. }, {
  19848. key: 'newMessage',
  19849. value: function newMessage(message, data) {
  19850. this._applicants[message] = message;
  19851. this.emit('newMessage', data);
  19852. }
  19853. /**
  19854. * Message destroyed.
  19855. */
  19856. }, {
  19857. key: 'destroyMessage',
  19858. value: function destroyMessage(message) {
  19859. delete this._applicants[message];
  19860. }
  19861. /**
  19862. * new RTCSession
  19863. */
  19864. }, {
  19865. key: 'newRTCSession',
  19866. value: function newRTCSession(session, data) {
  19867. this._sessions[session.id] = session;
  19868. this.emit('newRTCSession', data);
  19869. }
  19870. /**
  19871. * RTCSession destroyed.
  19872. */
  19873. }, {
  19874. key: 'destroyRTCSession',
  19875. value: function destroyRTCSession(session) {
  19876. delete this._sessions[session.id];
  19877. }
  19878. /**
  19879. * Registered
  19880. */
  19881. }, {
  19882. key: 'registered',
  19883. value: function registered(data) {
  19884. this.emit('registered', data);
  19885. }
  19886. /**
  19887. * Unregistered
  19888. */
  19889. }, {
  19890. key: 'unregistered',
  19891. value: function unregistered(data) {
  19892. this.emit('unregistered', data);
  19893. }
  19894. /**
  19895. * Registration Failed
  19896. */
  19897. }, {
  19898. key: 'registrationFailed',
  19899. value: function registrationFailed(data) {
  19900. this.emit('registrationFailed', data);
  19901. }
  19902. // =========================
  19903. // ReceiveRequest.
  19904. // =========================
  19905. /**
  19906. * Request reception
  19907. */
  19908. }, {
  19909. key: 'receiveRequest',
  19910. value: function receiveRequest(request) {
  19911. var method = request.method;
  19912. // Check that request URI points to us.
  19913. if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) {
  19914. debug('Request-URI does not point to us');
  19915. if (request.method !== JsSIP_C.ACK) {
  19916. request.reply_sl(404);
  19917. }
  19918. return;
  19919. }
  19920. // Check request URI scheme.
  19921. if (request.ruri.scheme === JsSIP_C.SIPS) {
  19922. request.reply_sl(416);
  19923. return;
  19924. }
  19925. // Check transaction.
  19926. if (Transactions.checkTransaction(this, request)) {
  19927. return;
  19928. }
  19929. // Create the server transaction.
  19930. if (method === JsSIP_C.INVITE) {
  19931. /* eslint-disable no-new */
  19932. new Transactions.InviteServerTransaction(this, this._transport, request);
  19933. /* eslint-enable no-new */
  19934. } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) {
  19935. /* eslint-disable no-new */
  19936. new Transactions.NonInviteServerTransaction(this, this._transport, request);
  19937. /* eslint-enable no-new */
  19938. }
  19939. /* RFC3261 12.2.2
  19940. * Requests that do not change in any way the state of a dialog may be
  19941. * received within a dialog (for example, an OPTIONS request).
  19942. * They are processed as if they had been received outside the dialog.
  19943. */
  19944. if (method === JsSIP_C.OPTIONS) {
  19945. request.reply(200);
  19946. } else if (method === JsSIP_C.MESSAGE) {
  19947. if (this.listeners('newMessage').length === 0) {
  19948. request.reply(405);
  19949. return;
  19950. }
  19951. var message = new Message(this);
  19952. message.init_incoming(request);
  19953. } else if (method === JsSIP_C.INVITE) {
  19954. // Initial INVITE.
  19955. if (!request.to_tag && this.listeners('newRTCSession').length === 0) {
  19956. request.reply(405);
  19957. return;
  19958. }
  19959. }
  19960. var dialog = void 0;
  19961. var session = void 0;
  19962. // Initial Request.
  19963. if (!request.to_tag) {
  19964. switch (method) {
  19965. case JsSIP_C.INVITE:
  19966. if (window.RTCPeerConnection) {
  19967. // TODO
  19968. if (request.hasHeader('replaces')) {
  19969. var replaces = request.replaces;
  19970. dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag);
  19971. if (dialog) {
  19972. session = dialog.owner;
  19973. if (!session.isEnded()) {
  19974. session.receiveRequest(request);
  19975. } else {
  19976. request.reply(603);
  19977. }
  19978. } else {
  19979. request.reply(481);
  19980. }
  19981. } else {
  19982. session = new RTCSession(this);
  19983. session.init_incoming(request);
  19984. }
  19985. } else {
  19986. debugerror('INVITE received but WebRTC is not supported');
  19987. request.reply(488);
  19988. }
  19989. break;
  19990. case JsSIP_C.BYE:
  19991. // Out of dialog BYE received.
  19992. request.reply(481);
  19993. break;
  19994. case JsSIP_C.CANCEL:
  19995. session = this._findSession(request);
  19996. if (session) {
  19997. session.receiveRequest(request);
  19998. } else {
  19999. debug('received CANCEL request for a non existent session');
  20000. }
  20001. break;
  20002. case JsSIP_C.ACK:
  20003. /* Absorb it.
  20004. * ACK request without a corresponding Invite Transaction
  20005. * and without To tag.
  20006. */
  20007. break;
  20008. default:
  20009. request.reply(405);
  20010. break;
  20011. }
  20012. }
  20013. // In-dialog request.
  20014. else {
  20015. dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag);
  20016. if (dialog) {
  20017. dialog.receiveRequest(request);
  20018. } else if (method === JsSIP_C.NOTIFY) {
  20019. session = this._findSession(request);
  20020. if (session) {
  20021. session.receiveRequest(request);
  20022. } else {
  20023. debug('received NOTIFY request for a non existent subscription');
  20024. request.reply(481, 'Subscription does not exist');
  20025. }
  20026. }
  20027. /* RFC3261 12.2.2
  20028. * Request with to tag, but no matching dialog found.
  20029. * Exception: ACK for an Invite request for which a dialog has not
  20030. * been created.
  20031. */
  20032. else if (method !== JsSIP_C.ACK) {
  20033. request.reply(481);
  20034. }
  20035. }
  20036. }
  20037. // =================
  20038. // Utils.
  20039. // =================
  20040. /**
  20041. * Get the session to which the request belongs to, if any.
  20042. */
  20043. }, {
  20044. key: '_findSession',
  20045. value: function _findSession(_ref) {
  20046. var call_id = _ref.call_id,
  20047. from_tag = _ref.from_tag,
  20048. to_tag = _ref.to_tag;
  20049. var sessionIDa = call_id + from_tag;
  20050. var sessionA = this._sessions[sessionIDa];
  20051. var sessionIDb = call_id + to_tag;
  20052. var sessionB = this._sessions[sessionIDb];
  20053. if (sessionA) {
  20054. return sessionA;
  20055. } else if (sessionB) {
  20056. return sessionB;
  20057. } else {
  20058. return null;
  20059. }
  20060. }
  20061. /**
  20062. * Get the dialog to which the request belongs to, if any.
  20063. */
  20064. }, {
  20065. key: '_findDialog',
  20066. value: function _findDialog(call_id, from_tag, to_tag) {
  20067. var id = call_id + from_tag + to_tag;
  20068. var dialog = this._dialogs[id];
  20069. if (dialog) {
  20070. return dialog;
  20071. } else {
  20072. id = call_id + to_tag + from_tag;
  20073. dialog = this._dialogs[id];
  20074. if (dialog) {
  20075. return dialog;
  20076. } else {
  20077. return null;
  20078. }
  20079. }
  20080. }
  20081. }, {
  20082. key: '_loadConfig',
  20083. value: function _loadConfig(configuration) {
  20084. // Check and load the given configuration.
  20085. try {
  20086. config.load(this._configuration, configuration);
  20087. } catch (e) {
  20088. throw e;
  20089. }
  20090. // Post Configuration Process.
  20091. // Allow passing 0 number as display_name.
  20092. if (this._configuration.display_name === 0) {
  20093. this._configuration.display_name = '0';
  20094. }
  20095. // Instance-id for GRUU.
  20096. if (!this._configuration.instance_id) {
  20097. this._configuration.instance_id = Utils.newUUID();
  20098. }
  20099. // Jssip_id instance parameter. Static random tag of length 5.
  20100. this._configuration.jssip_id = Utils.createRandomToken(5);
  20101. // String containing this._configuration.uri without scheme and user.
  20102. var hostport_params = this._configuration.uri.clone();
  20103. hostport_params.user = null;
  20104. this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, '');
  20105. // Transport.
  20106. try {
  20107. this._transport = new Transport(this._configuration.sockets, {
  20108. // Recovery options.
  20109. max_interval: this._configuration.connection_recovery_max_interval,
  20110. min_interval: this._configuration.connection_recovery_min_interval
  20111. });
  20112. // Transport event callbacks.
  20113. this._transport.onconnecting = onTransportConnecting.bind(this);
  20114. this._transport.onconnect = onTransportConnect.bind(this);
  20115. this._transport.ondisconnect = onTransportDisconnect.bind(this);
  20116. this._transport.ondata = onTransportData.bind(this);
  20117. } catch (e) {
  20118. debugerror(e);
  20119. throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets);
  20120. }
  20121. // Remove sockets instance from configuration object.
  20122. delete this._configuration.sockets;
  20123. // Check whether authorization_user is explicitly defined.
  20124. // Take 'this._configuration.uri.user' value if not.
  20125. if (!this._configuration.authorization_user) {
  20126. this._configuration.authorization_user = this._configuration.uri.user;
  20127. }
  20128. // If no 'registrar_server' is set use the 'uri' value without user portion and
  20129. // without URI params/headers.
  20130. if (!this._configuration.registrar_server) {
  20131. var registrar_server = this._configuration.uri.clone();
  20132. registrar_server.user = null;
  20133. registrar_server.clearParams();
  20134. registrar_server.clearHeaders();
  20135. this._configuration.registrar_server = registrar_server;
  20136. }
  20137. // User no_answer_timeout.
  20138. this._configuration.no_answer_timeout *= 1000;
  20139. // Via Host.
  20140. if (this._configuration.contact_uri) {
  20141. this._configuration.via_host = this._configuration.contact_uri.host;
  20142. }
  20143. // Contact URI.
  20144. else {
  20145. this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, { transport: 'ws' });
  20146. }
  20147. this._contact = {
  20148. pub_gruu: null,
  20149. temp_gruu: null,
  20150. uri: this._configuration.contact_uri,
  20151. toString: function toString() {
  20152. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20153. var anonymous = options.anonymous || null;
  20154. var outbound = options.outbound || null;
  20155. var contact = '<';
  20156. if (anonymous) {
  20157. contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
  20158. } else {
  20159. contact += this.pub_gruu || this.uri.toString();
  20160. }
  20161. if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) {
  20162. contact += ';ob';
  20163. }
  20164. contact += '>';
  20165. return contact;
  20166. }
  20167. };
  20168. // Seal the configuration.
  20169. var writable_parameters = ['password', 'realm', 'ha1', 'display_name', 'register'];
  20170. for (var parameter in this._configuration) {
  20171. if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) {
  20172. if (writable_parameters.indexOf(parameter) !== -1) {
  20173. Object.defineProperty(this._configuration, parameter, {
  20174. writable: true,
  20175. configurable: false
  20176. });
  20177. } else {
  20178. Object.defineProperty(this._configuration, parameter, {
  20179. writable: false,
  20180. configurable: false
  20181. });
  20182. }
  20183. }
  20184. }
  20185. debug('configuration parameters after validation:');
  20186. for (var _parameter in this._configuration) {
  20187. // Only show the user user configurable parameters.
  20188. if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) {
  20189. switch (_parameter) {
  20190. case 'uri':
  20191. case 'registrar_server':
  20192. debug('- ' + _parameter + ': ' + this._configuration[_parameter]);
  20193. break;
  20194. case 'password':
  20195. case 'ha1':
  20196. debug('- ' + _parameter + ': NOT SHOWN');
  20197. break;
  20198. default:
  20199. debug('- ' + _parameter + ': ' + JSON.stringify(this._configuration[_parameter]));
  20200. }
  20201. }
  20202. }
  20203. return;
  20204. }
  20205. }, {
  20206. key: 'C',
  20207. get: function get() {
  20208. return C;
  20209. }
  20210. }, {
  20211. key: 'status',
  20212. get: function get() {
  20213. return this._status;
  20214. }
  20215. }, {
  20216. key: 'contact',
  20217. get: function get() {
  20218. return this._contact;
  20219. }
  20220. }, {
  20221. key: 'configuration',
  20222. get: function get() {
  20223. return this._configuration;
  20224. }
  20225. }, {
  20226. key: 'transport',
  20227. get: function get() {
  20228. return this._transport;
  20229. }
  20230. }]);
  20231. return UA;
  20232. }(EventEmitter);
  20233. /**
  20234. * Transport event handlers
  20235. */
  20236. // Transport connecting event.
  20237. function onTransportConnecting(data) {
  20238. this.emit('connecting', data);
  20239. }
  20240. // Transport connected event.
  20241. function onTransportConnect(data) {
  20242. if (this._status === C.STATUS_USER_CLOSED) {
  20243. return;
  20244. }
  20245. this._status = C.STATUS_READY;
  20246. this._error = null;
  20247. this.emit('connected', data);
  20248. if (this._dynConfiguration.register) {
  20249. this._registrator.register();
  20250. }
  20251. }
  20252. // Transport disconnected event.
  20253. function onTransportDisconnect(data) {
  20254. // Run _onTransportError_ callback on every client transaction using _transport_.
  20255. var client_transactions = ['nict', 'ict', 'nist', 'ist'];
  20256. var _iteratorNormalCompletion = true;
  20257. var _didIteratorError = false;
  20258. var _iteratorError = undefined;
  20259. try {
  20260. for (var _iterator = client_transactions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  20261. var type = _step.value;
  20262. for (var id in this._transactions[type]) {
  20263. if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) {
  20264. this._transactions[type][id].onTransportError();
  20265. }
  20266. }
  20267. }
  20268. } catch (err) {
  20269. _didIteratorError = true;
  20270. _iteratorError = err;
  20271. } finally {
  20272. try {
  20273. if (!_iteratorNormalCompletion && _iterator.return) {
  20274. _iterator.return();
  20275. }
  20276. } finally {
  20277. if (_didIteratorError) {
  20278. throw _iteratorError;
  20279. }
  20280. }
  20281. }
  20282. this.emit('disconnected', data);
  20283. // Call registrator _onTransportClosed_.
  20284. this._registrator.onTransportClosed();
  20285. if (this._status !== C.STATUS_USER_CLOSED) {
  20286. this._status = C.STATUS_NOT_READY;
  20287. this._error = C.NETWORK_ERROR;
  20288. }
  20289. }
  20290. // Transport data event.
  20291. function onTransportData(data) {
  20292. var transport = data.transport;
  20293. var message = data.message;
  20294. message = Parser.parseMessage(message, this);
  20295. if (!message) {
  20296. return;
  20297. }
  20298. if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) {
  20299. return;
  20300. }
  20301. // Do some sanity check.
  20302. if (!sanityCheck(message, this, transport)) {
  20303. return;
  20304. }
  20305. if (message instanceof SIPMessage.IncomingRequest) {
  20306. message.transport = transport;
  20307. this.receiveRequest(message);
  20308. } else if (message instanceof SIPMessage.IncomingResponse) {
  20309. /* Unike stated in 18.1.2, if a response does not match
  20310. * any transaction, it is discarded here and no passed to the core
  20311. * in order to be discarded there.
  20312. */
  20313. var transaction = void 0;
  20314. switch (message.method) {
  20315. case JsSIP_C.INVITE:
  20316. transaction = this._transactions.ict[message.via_branch];
  20317. if (transaction) {
  20318. transaction.receiveResponse(message);
  20319. }
  20320. break;
  20321. case JsSIP_C.ACK:
  20322. // Just in case ;-).
  20323. break;
  20324. default:
  20325. transaction = this._transactions.nict[message.via_branch];
  20326. if (transaction) {
  20327. transaction.receiveResponse(message);
  20328. }
  20329. break;
  20330. }
  20331. }
  20332. }
  20333. },{"./Config":1,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":29,"events":31}],25:[function(require,module,exports){
  20334. 'use strict';
  20335. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  20336. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20337. var JsSIP_C = require('./Constants');
  20338. var Utils = require('./Utils');
  20339. var Grammar = require('./Grammar');
  20340. /**
  20341. * -param {String} [scheme]
  20342. * -param {String} [user]
  20343. * -param {String} host
  20344. * -param {String} [port]
  20345. * -param {Object} [parameters]
  20346. * -param {Object} [headers]
  20347. *
  20348. */
  20349. module.exports = function () {
  20350. _createClass(URI, null, [{
  20351. key: 'parse',
  20352. /**
  20353. * Parse the given string and returns a JsSIP.URI instance or undefined if
  20354. * it is an invalid URI.
  20355. */
  20356. value: function parse(uri) {
  20357. uri = Grammar.parse(uri, 'SIP_URI');
  20358. if (uri !== -1) {
  20359. return uri;
  20360. } else {
  20361. return undefined;
  20362. }
  20363. }
  20364. }]);
  20365. function URI(scheme, user, host, port) {
  20366. var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  20367. var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
  20368. _classCallCheck(this, URI);
  20369. // Checks.
  20370. if (!host) {
  20371. throw new TypeError('missing or invalid "host" parameter');
  20372. }
  20373. // Initialize parameters.
  20374. this._parameters = {};
  20375. this._headers = {};
  20376. this._scheme = scheme || JsSIP_C.SIP;
  20377. this._user = user;
  20378. this._host = host;
  20379. this._port = port;
  20380. for (var param in parameters) {
  20381. if (Object.prototype.hasOwnProperty.call(parameters, param)) {
  20382. this.setParam(param, parameters[param]);
  20383. }
  20384. }
  20385. for (var header in headers) {
  20386. if (Object.prototype.hasOwnProperty.call(headers, header)) {
  20387. this.setHeader(header, headers[header]);
  20388. }
  20389. }
  20390. }
  20391. _createClass(URI, [{
  20392. key: 'setParam',
  20393. value: function setParam(key, value) {
  20394. if (key) {
  20395. this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
  20396. }
  20397. }
  20398. }, {
  20399. key: 'getParam',
  20400. value: function getParam(key) {
  20401. if (key) {
  20402. return this._parameters[key.toLowerCase()];
  20403. }
  20404. }
  20405. }, {
  20406. key: 'hasParam',
  20407. value: function hasParam(key) {
  20408. if (key) {
  20409. return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
  20410. }
  20411. }
  20412. }, {
  20413. key: 'deleteParam',
  20414. value: function deleteParam(parameter) {
  20415. parameter = parameter.toLowerCase();
  20416. if (this._parameters.hasOwnProperty(parameter)) {
  20417. var value = this._parameters[parameter];
  20418. delete this._parameters[parameter];
  20419. return value;
  20420. }
  20421. }
  20422. }, {
  20423. key: 'clearParams',
  20424. value: function clearParams() {
  20425. this._parameters = {};
  20426. }
  20427. }, {
  20428. key: 'setHeader',
  20429. value: function setHeader(name, value) {
  20430. this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
  20431. }
  20432. }, {
  20433. key: 'getHeader',
  20434. value: function getHeader(name) {
  20435. if (name) {
  20436. return this._headers[Utils.headerize(name)];
  20437. }
  20438. }
  20439. }, {
  20440. key: 'hasHeader',
  20441. value: function hasHeader(name) {
  20442. if (name) {
  20443. return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false;
  20444. }
  20445. }
  20446. }, {
  20447. key: 'deleteHeader',
  20448. value: function deleteHeader(header) {
  20449. header = Utils.headerize(header);
  20450. if (this._headers.hasOwnProperty(header)) {
  20451. var value = this._headers[header];
  20452. delete this._headers[header];
  20453. return value;
  20454. }
  20455. }
  20456. }, {
  20457. key: 'clearHeaders',
  20458. value: function clearHeaders() {
  20459. this._headers = {};
  20460. }
  20461. }, {
  20462. key: 'clone',
  20463. value: function clone() {
  20464. return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers)));
  20465. }
  20466. }, {
  20467. key: 'toString',
  20468. value: function toString() {
  20469. var headers = [];
  20470. var uri = this._scheme + ':';
  20471. if (this._user) {
  20472. uri += Utils.escapeUser(this._user) + '@';
  20473. }
  20474. uri += this._host;
  20475. if (this._port || this._port === 0) {
  20476. uri += ':' + this._port;
  20477. }
  20478. for (var parameter in this._parameters) {
  20479. if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
  20480. uri += ';' + parameter;
  20481. if (this._parameters[parameter] !== null) {
  20482. uri += '=' + this._parameters[parameter];
  20483. }
  20484. }
  20485. }
  20486. for (var header in this._headers) {
  20487. if (Object.prototype.hasOwnProperty.call(this._headers, header)) {
  20488. var _iteratorNormalCompletion = true;
  20489. var _didIteratorError = false;
  20490. var _iteratorError = undefined;
  20491. try {
  20492. for (var _iterator = this._headers[header][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  20493. var item = _step.value;
  20494. headers.push(header + '=' + item);
  20495. }
  20496. } catch (err) {
  20497. _didIteratorError = true;
  20498. _iteratorError = err;
  20499. } finally {
  20500. try {
  20501. if (!_iteratorNormalCompletion && _iterator.return) {
  20502. _iterator.return();
  20503. }
  20504. } finally {
  20505. if (_didIteratorError) {
  20506. throw _iteratorError;
  20507. }
  20508. }
  20509. }
  20510. }
  20511. }
  20512. if (headers.length > 0) {
  20513. uri += '?' + headers.join('&');
  20514. }
  20515. return uri;
  20516. }
  20517. }, {
  20518. key: 'toAor',
  20519. value: function toAor(show_port) {
  20520. var aor = this._scheme + ':';
  20521. if (this._user) {
  20522. aor += Utils.escapeUser(this._user) + '@';
  20523. }
  20524. aor += this._host;
  20525. if (show_port && (this._port || this._port === 0)) {
  20526. aor += ':' + this._port;
  20527. }
  20528. return aor;
  20529. }
  20530. }, {
  20531. key: 'scheme',
  20532. get: function get() {
  20533. return this._scheme;
  20534. },
  20535. set: function set(value) {
  20536. this._scheme = value.toLowerCase();
  20537. }
  20538. }, {
  20539. key: 'user',
  20540. get: function get() {
  20541. return this._user;
  20542. },
  20543. set: function set(value) {
  20544. this._user = value;
  20545. }
  20546. }, {
  20547. key: 'host',
  20548. get: function get() {
  20549. return this._host;
  20550. },
  20551. set: function set(value) {
  20552. this._host = value.toLowerCase();
  20553. }
  20554. }, {
  20555. key: 'port',
  20556. get: function get() {
  20557. return this._port;
  20558. },
  20559. set: function set(value) {
  20560. this._port = value === 0 ? value : parseInt(value, 10) || null;
  20561. }
  20562. }]);
  20563. return URI;
  20564. }();
  20565. },{"./Constants":2,"./Grammar":7,"./Utils":26}],26:[function(require,module,exports){
  20566. 'use strict';
  20567. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  20568. var JsSIP_C = require('./Constants');
  20569. var URI = require('./URI');
  20570. var Grammar = require('./Grammar');
  20571. exports.str_utf8_length = function (string) {
  20572. return unescape(encodeURIComponent(string)).length;
  20573. };
  20574. // Used by 'hasMethods'.
  20575. var isFunction = exports.isFunction = function (fn) {
  20576. if (fn !== undefined) {
  20577. return Object.prototype.toString.call(fn) === '[object Function]' ? true : false;
  20578. } else {
  20579. return false;
  20580. }
  20581. };
  20582. exports.isString = function (str) {
  20583. if (str !== undefined) {
  20584. return Object.prototype.toString.call(str) === '[object String]' ? true : false;
  20585. } else {
  20586. return false;
  20587. }
  20588. };
  20589. exports.isDecimal = function (num) {
  20590. return !isNaN(num) && parseFloat(num) === parseInt(num, 10);
  20591. };
  20592. exports.isEmpty = function (value) {
  20593. return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value);
  20594. };
  20595. exports.hasMethods = function (obj) {
  20596. for (var _len = arguments.length, methodNames = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  20597. methodNames[_key - 1] = arguments[_key];
  20598. }
  20599. var _iteratorNormalCompletion = true;
  20600. var _didIteratorError = false;
  20601. var _iteratorError = undefined;
  20602. try {
  20603. for (var _iterator = methodNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  20604. var methodName = _step.value;
  20605. if (isFunction(obj[methodName])) {
  20606. return false;
  20607. }
  20608. }
  20609. } catch (err) {
  20610. _didIteratorError = true;
  20611. _iteratorError = err;
  20612. } finally {
  20613. try {
  20614. if (!_iteratorNormalCompletion && _iterator.return) {
  20615. _iterator.return();
  20616. }
  20617. } finally {
  20618. if (_didIteratorError) {
  20619. throw _iteratorError;
  20620. }
  20621. }
  20622. }
  20623. return true;
  20624. };
  20625. // Used by 'newTag'.
  20626. var createRandomToken = exports.createRandomToken = function (size) {
  20627. var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32;
  20628. var i = void 0,
  20629. r = void 0,
  20630. token = '';
  20631. for (i = 0; i < size; i++) {
  20632. r = Math.random() * base | 0;
  20633. token += r.toString(base);
  20634. }
  20635. return token;
  20636. };
  20637. exports.newTag = function () {
  20638. return createRandomToken(10);
  20639. };
  20640. // http://stackoverflow.com/users/109538/broofa.
  20641. exports.newUUID = function () {
  20642. var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  20643. var r = Math.random() * 16 | 0,
  20644. v = c === 'x' ? r : r & 0x3 | 0x8;
  20645. return v.toString(16);
  20646. });
  20647. return UUID;
  20648. };
  20649. exports.hostType = function (host) {
  20650. if (!host) {
  20651. return;
  20652. } else {
  20653. host = Grammar.parse(host, 'host');
  20654. if (host !== -1) {
  20655. return host.host_type;
  20656. }
  20657. }
  20658. };
  20659. /**
  20660. * Hex-escape a SIP URI user.
  20661. * Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F).
  20662. *
  20663. * Used by 'normalizeTarget'.
  20664. */
  20665. var escapeUser = exports.escapeUser = function (user) {
  20666. return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/');
  20667. };
  20668. /**
  20669. * Normalize SIP URI.
  20670. * NOTE: It does not allow a SIP URI without username.
  20671. * Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'.
  20672. * Detects the domain part (if given) and properly hex-escapes the user portion.
  20673. * If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators.
  20674. */
  20675. exports.normalizeTarget = function (target, domain) {
  20676. // If no target is given then raise an error.
  20677. if (!target) {
  20678. return;
  20679. // If a URI instance is given then return it.
  20680. } else if (target instanceof URI) {
  20681. return target;
  20682. // If a string is given split it by '@':
  20683. // - Last fragment is the desired domain.
  20684. // - Otherwise append the given domain argument.
  20685. } else if (typeof target === 'string') {
  20686. var target_array = target.split('@');
  20687. var target_user = void 0;
  20688. var target_domain = void 0;
  20689. switch (target_array.length) {
  20690. case 1:
  20691. if (!domain) {
  20692. return;
  20693. }
  20694. target_user = target;
  20695. target_domain = domain;
  20696. break;
  20697. case 2:
  20698. target_user = target_array[0];
  20699. target_domain = target_array[1];
  20700. break;
  20701. default:
  20702. target_user = target_array.slice(0, target_array.length - 1).join('@');
  20703. target_domain = target_array[target_array.length - 1];
  20704. }
  20705. // Remove the URI scheme (if present).
  20706. target_user = target_user.replace(/^(sips?|tel):/i, '');
  20707. // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols.
  20708. if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) {
  20709. target_user = target_user.replace(/[-.()]/g, '');
  20710. }
  20711. // Build the complete SIP URI.
  20712. target = JsSIP_C.SIP + ':' + escapeUser(target_user) + '@' + target_domain;
  20713. // Finally parse the resulting URI.
  20714. var uri = void 0;
  20715. if (uri = URI.parse(target)) {
  20716. return uri;
  20717. } else {
  20718. return;
  20719. }
  20720. } else {
  20721. return;
  20722. }
  20723. };
  20724. exports.headerize = function (string) {
  20725. var exceptions = {
  20726. 'Call-Id': 'Call-ID',
  20727. 'Cseq': 'CSeq',
  20728. 'Www-Authenticate': 'WWW-Authenticate'
  20729. };
  20730. var name = string.toLowerCase().replace(/_/g, '-').split('-');
  20731. var hname = '';
  20732. var parts = name.length;
  20733. var part = void 0;
  20734. for (part = 0; part < parts; part++) {
  20735. if (part !== 0) {
  20736. hname += '-';
  20737. }
  20738. hname += name[part].charAt(0).toUpperCase() + name[part].substring(1);
  20739. }
  20740. if (exceptions[hname]) {
  20741. hname = exceptions[hname];
  20742. }
  20743. return hname;
  20744. };
  20745. exports.sipErrorCause = function (status_code) {
  20746. for (var cause in JsSIP_C.SIP_ERROR_CAUSES) {
  20747. if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) {
  20748. return JsSIP_C.causes[cause];
  20749. }
  20750. }
  20751. return JsSIP_C.causes.SIP_FAILURE_CODE;
  20752. };
  20753. /**
  20754. * Generate a random Test-Net IP (http://tools.ietf.org/html/rfc5735)
  20755. */
  20756. exports.getRandomTestNetIP = function () {
  20757. function getOctet(from, to) {
  20758. return Math.floor(Math.random() * (to - from + 1) + from);
  20759. }
  20760. return '192.0.2.' + getOctet(1, 254);
  20761. };
  20762. // MD5 (Message-Digest Algorithm) http://www.webtoolkit.info.
  20763. exports.calculateMD5 = function (string) {
  20764. function rotateLeft(lValue, iShiftBits) {
  20765. return lValue << iShiftBits | lValue >>> 32 - iShiftBits;
  20766. }
  20767. function addUnsigned(lX, lY) {
  20768. var lX8 = lX & 0x80000000;
  20769. var lY8 = lY & 0x80000000;
  20770. var lX4 = lX & 0x40000000;
  20771. var lY4 = lY & 0x40000000;
  20772. var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
  20773. if (lX4 & lY4) {
  20774. return lResult ^ 0x80000000 ^ lX8 ^ lY8;
  20775. }
  20776. if (lX4 | lY4) {
  20777. if (lResult & 0x40000000) {
  20778. return lResult ^ 0xC0000000 ^ lX8 ^ lY8;
  20779. } else {
  20780. return lResult ^ 0x40000000 ^ lX8 ^ lY8;
  20781. }
  20782. } else {
  20783. return lResult ^ lX8 ^ lY8;
  20784. }
  20785. }
  20786. function doF(x, y, z) {
  20787. return x & y | ~x & z;
  20788. }
  20789. function doG(x, y, z) {
  20790. return x & z | y & ~z;
  20791. }
  20792. function doH(x, y, z) {
  20793. return x ^ y ^ z;
  20794. }
  20795. function doI(x, y, z) {
  20796. return y ^ (x | ~z);
  20797. }
  20798. function doFF(a, b, c, d, x, s, ac) {
  20799. a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac));
  20800. return addUnsigned(rotateLeft(a, s), b);
  20801. }
  20802. function doGG(a, b, c, d, x, s, ac) {
  20803. a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac));
  20804. return addUnsigned(rotateLeft(a, s), b);
  20805. }
  20806. function doHH(a, b, c, d, x, s, ac) {
  20807. a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac));
  20808. return addUnsigned(rotateLeft(a, s), b);
  20809. }
  20810. function doII(a, b, c, d, x, s, ac) {
  20811. a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac));
  20812. return addUnsigned(rotateLeft(a, s), b);
  20813. }
  20814. function convertToWordArray(str) {
  20815. var lWordCount = void 0;
  20816. var lMessageLength = str.length;
  20817. var lNumberOfWords_temp1 = lMessageLength + 8;
  20818. var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64;
  20819. var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
  20820. var lWordArray = new Array(lNumberOfWords - 1);
  20821. var lBytePosition = 0;
  20822. var lByteCount = 0;
  20823. while (lByteCount < lMessageLength) {
  20824. lWordCount = (lByteCount - lByteCount % 4) / 4;
  20825. lBytePosition = lByteCount % 4 * 8;
  20826. lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition;
  20827. lByteCount++;
  20828. }
  20829. lWordCount = (lByteCount - lByteCount % 4) / 4;
  20830. lBytePosition = lByteCount % 4 * 8;
  20831. lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition;
  20832. lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
  20833. lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
  20834. return lWordArray;
  20835. }
  20836. function wordToHex(lValue) {
  20837. var wordToHexValue = '',
  20838. wordToHexValue_temp = '',
  20839. lByte = void 0,
  20840. lCount = void 0;
  20841. for (lCount = 0; lCount <= 3; lCount++) {
  20842. lByte = lValue >>> lCount * 8 & 255;
  20843. wordToHexValue_temp = '0' + lByte.toString(16);
  20844. wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2);
  20845. }
  20846. return wordToHexValue;
  20847. }
  20848. function utf8Encode(str) {
  20849. str = str.replace(/\r\n/g, '\n');
  20850. var utftext = '';
  20851. for (var n = 0; n < str.length; n++) {
  20852. var _c = str.charCodeAt(n);
  20853. if (_c < 128) {
  20854. utftext += String.fromCharCode(_c);
  20855. } else if (_c > 127 && _c < 2048) {
  20856. utftext += String.fromCharCode(_c >> 6 | 192);
  20857. utftext += String.fromCharCode(_c & 63 | 128);
  20858. } else {
  20859. utftext += String.fromCharCode(_c >> 12 | 224);
  20860. utftext += String.fromCharCode(_c >> 6 & 63 | 128);
  20861. utftext += String.fromCharCode(_c & 63 | 128);
  20862. }
  20863. }
  20864. return utftext;
  20865. }
  20866. var x = [];
  20867. var k = void 0,
  20868. AA = void 0,
  20869. BB = void 0,
  20870. CC = void 0,
  20871. DD = void 0,
  20872. a = void 0,
  20873. b = void 0,
  20874. c = void 0,
  20875. d = void 0;
  20876. var S11 = 7,
  20877. S12 = 12,
  20878. S13 = 17,
  20879. S14 = 22;
  20880. var S21 = 5,
  20881. S22 = 9,
  20882. S23 = 14,
  20883. S24 = 20;
  20884. var S31 = 4,
  20885. S32 = 11,
  20886. S33 = 16,
  20887. S34 = 23;
  20888. var S41 = 6,
  20889. S42 = 10,
  20890. S43 = 15,
  20891. S44 = 21;
  20892. string = utf8Encode(string);
  20893. x = convertToWordArray(string);
  20894. a = 0x67452301;b = 0xEFCDAB89;c = 0x98BADCFE;d = 0x10325476;
  20895. for (k = 0; k < x.length; k += 16) {
  20896. AA = a;BB = b;CC = c;DD = d;
  20897. a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
  20898. d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
  20899. c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB);
  20900. b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
  20901. a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
  20902. d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
  20903. c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613);
  20904. b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501);
  20905. a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8);
  20906. d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
  20907. c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
  20908. b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
  20909. a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122);
  20910. d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193);
  20911. c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E);
  20912. b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821);
  20913. a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
  20914. d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340);
  20915. c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
  20916. b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
  20917. a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
  20918. d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453);
  20919. c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
  20920. b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
  20921. a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
  20922. d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
  20923. c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
  20924. b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
  20925. a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
  20926. d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
  20927. c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
  20928. b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
  20929. a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
  20930. d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681);
  20931. c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
  20932. b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
  20933. a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
  20934. d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
  20935. c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
  20936. b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
  20937. a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
  20938. d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
  20939. c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
  20940. b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05);
  20941. a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
  20942. d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
  20943. c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
  20944. b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
  20945. a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244);
  20946. d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97);
  20947. c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
  20948. b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039);
  20949. a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3);
  20950. d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
  20951. c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
  20952. b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1);
  20953. a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
  20954. d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
  20955. c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314);
  20956. b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
  20957. a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82);
  20958. d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
  20959. c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
  20960. b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391);
  20961. a = addUnsigned(a, AA);
  20962. b = addUnsigned(b, BB);
  20963. c = addUnsigned(c, CC);
  20964. d = addUnsigned(d, DD);
  20965. }
  20966. var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
  20967. return temp.toLowerCase();
  20968. };
  20969. exports.closeMediaStream = function (stream) {
  20970. if (!stream) {
  20971. return;
  20972. }
  20973. // Latest spec states that MediaStream has no stop() method and instead must
  20974. // call stop() on every MediaStreamTrack.
  20975. try {
  20976. var tracks = void 0;
  20977. if (stream.getTracks) {
  20978. tracks = stream.getTracks();
  20979. var _iteratorNormalCompletion2 = true;
  20980. var _didIteratorError2 = false;
  20981. var _iteratorError2 = undefined;
  20982. try {
  20983. for (var _iterator2 = tracks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  20984. var track = _step2.value;
  20985. track.stop();
  20986. }
  20987. } catch (err) {
  20988. _didIteratorError2 = true;
  20989. _iteratorError2 = err;
  20990. } finally {
  20991. try {
  20992. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  20993. _iterator2.return();
  20994. }
  20995. } finally {
  20996. if (_didIteratorError2) {
  20997. throw _iteratorError2;
  20998. }
  20999. }
  21000. }
  21001. } else {
  21002. tracks = stream.getAudioTracks();
  21003. var _iteratorNormalCompletion3 = true;
  21004. var _didIteratorError3 = false;
  21005. var _iteratorError3 = undefined;
  21006. try {
  21007. for (var _iterator3 = tracks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  21008. var _track = _step3.value;
  21009. _track.stop();
  21010. }
  21011. } catch (err) {
  21012. _didIteratorError3 = true;
  21013. _iteratorError3 = err;
  21014. } finally {
  21015. try {
  21016. if (!_iteratorNormalCompletion3 && _iterator3.return) {
  21017. _iterator3.return();
  21018. }
  21019. } finally {
  21020. if (_didIteratorError3) {
  21021. throw _iteratorError3;
  21022. }
  21023. }
  21024. }
  21025. tracks = stream.getVideoTracks();
  21026. var _iteratorNormalCompletion4 = true;
  21027. var _didIteratorError4 = false;
  21028. var _iteratorError4 = undefined;
  21029. try {
  21030. for (var _iterator4 = tracks[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  21031. var _track2 = _step4.value;
  21032. _track2.stop();
  21033. }
  21034. } catch (err) {
  21035. _didIteratorError4 = true;
  21036. _iteratorError4 = err;
  21037. } finally {
  21038. try {
  21039. if (!_iteratorNormalCompletion4 && _iterator4.return) {
  21040. _iterator4.return();
  21041. }
  21042. } finally {
  21043. if (_didIteratorError4) {
  21044. throw _iteratorError4;
  21045. }
  21046. }
  21047. }
  21048. }
  21049. } catch (error) {
  21050. // Deprecated by the spec, but still in use.
  21051. // NOTE: In Temasys IE plugin stream.stop is a callable 'object'.
  21052. if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') {
  21053. stream.stop();
  21054. }
  21055. }
  21056. };
  21057. exports.cloneArray = function (array) {
  21058. return array && array.slice() || [];
  21059. };
  21060. },{"./Constants":2,"./Grammar":7,"./URI":25}],27:[function(require,module,exports){
  21061. 'use strict';
  21062. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  21063. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21064. var Grammar = require('./Grammar');
  21065. var debug = require('debug')('JsSIP:WebSocketInterface');
  21066. var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface');
  21067. debugerror.log = console.warn.bind(console);
  21068. module.exports = function () {
  21069. function WebSocketInterface(url) {
  21070. _classCallCheck(this, WebSocketInterface);
  21071. debug('new() [url:"%s"]', url);
  21072. this._url = url;
  21073. this._sip_uri = null;
  21074. this._via_transport = null;
  21075. this._ws = null;
  21076. var parsed_url = Grammar.parse(url, 'absoluteURI');
  21077. if (parsed_url === -1) {
  21078. debugerror('invalid WebSocket URI: ' + url);
  21079. throw new TypeError('Invalid argument: ' + url);
  21080. } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') {
  21081. debugerror('invalid WebSocket URI scheme: ' + parsed_url.scheme);
  21082. throw new TypeError('Invalid argument: ' + url);
  21083. } else {
  21084. this._sip_uri = 'sip:' + parsed_url.host + (parsed_url.port ? ':' + parsed_url.port : '') + ';transport=ws';
  21085. this._via_transport = parsed_url.scheme.toUpperCase();
  21086. }
  21087. }
  21088. _createClass(WebSocketInterface, [{
  21089. key: 'connect',
  21090. value: function connect() {
  21091. debug('connect()');
  21092. if (this.isConnected()) {
  21093. debug('WebSocket ' + this._url + ' is already connected');
  21094. return;
  21095. } else if (this.isConnecting()) {
  21096. debug('WebSocket ' + this._url + ' is connecting');
  21097. return;
  21098. }
  21099. if (this._ws) {
  21100. this.disconnect();
  21101. }
  21102. debug('connecting to WebSocket ' + this._url);
  21103. try {
  21104. this._ws = new WebSocket(this._url, 'sip');
  21105. this._ws.binaryType = 'arraybuffer';
  21106. this._ws.onopen = this._onOpen.bind(this);
  21107. this._ws.onclose = this._onClose.bind(this);
  21108. this._ws.onmessage = this._onMessage.bind(this);
  21109. this._ws.onerror = this._onError.bind(this);
  21110. } catch (e) {
  21111. this._onError(e);
  21112. }
  21113. }
  21114. }, {
  21115. key: 'disconnect',
  21116. value: function disconnect() {
  21117. debug('disconnect()');
  21118. if (this._ws) {
  21119. // Unbind websocket event callbacks.
  21120. this._ws.onopen = function () {};
  21121. this._ws.onclose = function () {};
  21122. this._ws.onmessage = function () {};
  21123. this._ws.onerror = function () {};
  21124. this._ws.close();
  21125. this._ws = null;
  21126. }
  21127. }
  21128. }, {
  21129. key: 'send',
  21130. value: function send(message) {
  21131. debug('send()');
  21132. if (this.isConnected()) {
  21133. this._ws.send(message);
  21134. return true;
  21135. } else {
  21136. debugerror('unable to send message, WebSocket is not open');
  21137. return false;
  21138. }
  21139. }
  21140. }, {
  21141. key: 'isConnected',
  21142. value: function isConnected() {
  21143. return this._ws && this._ws.readyState === this._ws.OPEN;
  21144. }
  21145. }, {
  21146. key: 'isConnecting',
  21147. value: function isConnecting() {
  21148. return this._ws && this._ws.readyState === this._ws.CONNECTING;
  21149. }
  21150. /**
  21151. * WebSocket Event Handlers
  21152. */
  21153. }, {
  21154. key: '_onOpen',
  21155. value: function _onOpen() {
  21156. debug('WebSocket ' + this._url + ' connected');
  21157. this.onconnect();
  21158. }
  21159. }, {
  21160. key: '_onClose',
  21161. value: function _onClose(_ref) {
  21162. var wasClean = _ref.wasClean,
  21163. code = _ref.code,
  21164. reason = _ref.reason;
  21165. debug('WebSocket ' + this._url + ' closed');
  21166. if (wasClean === false) {
  21167. debug('WebSocket abrupt disconnection');
  21168. }
  21169. var data = {
  21170. socket: this,
  21171. error: !wasClean,
  21172. code: code,
  21173. reason: reason
  21174. };
  21175. this.ondisconnect(data);
  21176. }
  21177. }, {
  21178. key: '_onMessage',
  21179. value: function _onMessage(_ref2) {
  21180. var data = _ref2.data;
  21181. debug('received WebSocket message');
  21182. this.ondata(data);
  21183. }
  21184. }, {
  21185. key: '_onError',
  21186. value: function _onError(e) {
  21187. debugerror('WebSocket ' + this._url + ' error: ' + e);
  21188. }
  21189. }, {
  21190. key: 'via_transport',
  21191. get: function get() {
  21192. return this._via_transport;
  21193. },
  21194. set: function set(value) {
  21195. this._via_transport = value.toUpperCase();
  21196. }
  21197. }, {
  21198. key: 'sip_uri',
  21199. get: function get() {
  21200. return this._sip_uri;
  21201. }
  21202. }, {
  21203. key: 'url',
  21204. get: function get() {
  21205. return this._url;
  21206. }
  21207. }]);
  21208. return WebSocketInterface;
  21209. }();
  21210. },{"./Grammar":7,"debug":29}],28:[function(require,module,exports){
  21211. 'use strict';
  21212. var JsSIP_C = require('./Constants');
  21213. var SIPMessage = require('./SIPMessage');
  21214. var Utils = require('./Utils');
  21215. var debug = require('debug')('JsSIP:sanityCheck');
  21216. // Checks for requests and responses.
  21217. var all = [minimumHeaders];
  21218. // Checks for requests.
  21219. var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2];
  21220. // Checks for responses.
  21221. var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response];
  21222. // local variables.
  21223. var message = void 0;
  21224. var ua = void 0;
  21225. var transport = void 0;
  21226. module.exports = function (m, u, t) {
  21227. message = m;
  21228. ua = u;
  21229. transport = t;
  21230. var _iteratorNormalCompletion = true;
  21231. var _didIteratorError = false;
  21232. var _iteratorError = undefined;
  21233. try {
  21234. for (var _iterator = all[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  21235. var check = _step.value;
  21236. if (check() === false) {
  21237. return false;
  21238. }
  21239. }
  21240. } catch (err) {
  21241. _didIteratorError = true;
  21242. _iteratorError = err;
  21243. } finally {
  21244. try {
  21245. if (!_iteratorNormalCompletion && _iterator.return) {
  21246. _iterator.return();
  21247. }
  21248. } finally {
  21249. if (_didIteratorError) {
  21250. throw _iteratorError;
  21251. }
  21252. }
  21253. }
  21254. if (message instanceof SIPMessage.IncomingRequest) {
  21255. var _iteratorNormalCompletion2 = true;
  21256. var _didIteratorError2 = false;
  21257. var _iteratorError2 = undefined;
  21258. try {
  21259. for (var _iterator2 = requests[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  21260. var _check = _step2.value;
  21261. if (_check() === false) {
  21262. return false;
  21263. }
  21264. }
  21265. } catch (err) {
  21266. _didIteratorError2 = true;
  21267. _iteratorError2 = err;
  21268. } finally {
  21269. try {
  21270. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  21271. _iterator2.return();
  21272. }
  21273. } finally {
  21274. if (_didIteratorError2) {
  21275. throw _iteratorError2;
  21276. }
  21277. }
  21278. }
  21279. } else if (message instanceof SIPMessage.IncomingResponse) {
  21280. var _iteratorNormalCompletion3 = true;
  21281. var _didIteratorError3 = false;
  21282. var _iteratorError3 = undefined;
  21283. try {
  21284. for (var _iterator3 = responses[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  21285. var _check2 = _step3.value;
  21286. if (_check2() === false) {
  21287. return false;
  21288. }
  21289. }
  21290. } catch (err) {
  21291. _didIteratorError3 = true;
  21292. _iteratorError3 = err;
  21293. } finally {
  21294. try {
  21295. if (!_iteratorNormalCompletion3 && _iterator3.return) {
  21296. _iterator3.return();
  21297. }
  21298. } finally {
  21299. if (_didIteratorError3) {
  21300. throw _iteratorError3;
  21301. }
  21302. }
  21303. }
  21304. }
  21305. // Everything is OK.
  21306. return true;
  21307. };
  21308. /*
  21309. * Sanity Check for incoming Messages
  21310. *
  21311. * Requests:
  21312. * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme
  21313. * - _rfc3261_16_3_4_ Receive a Request already sent by us
  21314. * Does not look at via sent-by but at jssip_id, which is inserted as
  21315. * a prefix in all initial requests generated by the ua
  21316. * - _rfc3261_18_3_request_ Body Content-Length
  21317. * - _rfc3261_8_2_2_2_ Merged Requests
  21318. *
  21319. * Responses:
  21320. * - _rfc3261_8_1_3_3_ Multiple Via headers
  21321. * - _rfc3261_18_3_response_ Body Content-Length
  21322. *
  21323. * All:
  21324. * - Minimum headers in a SIP message
  21325. */
  21326. // Sanity Check functions for requests.
  21327. function rfc3261_8_2_2_1() {
  21328. if (message.s('to').uri.scheme !== 'sip') {
  21329. reply(416);
  21330. return false;
  21331. }
  21332. }
  21333. function rfc3261_16_3_4() {
  21334. if (!message.to_tag) {
  21335. if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) {
  21336. reply(482);
  21337. return false;
  21338. }
  21339. }
  21340. }
  21341. function rfc3261_18_3_request() {
  21342. var len = Utils.str_utf8_length(message.body);
  21343. var contentLength = message.getHeader('content-length');
  21344. if (len < contentLength) {
  21345. reply(400);
  21346. return false;
  21347. }
  21348. }
  21349. function rfc3261_8_2_2_2() {
  21350. var fromTag = message.from_tag;
  21351. var call_id = message.call_id;
  21352. var cseq = message.cseq;
  21353. var tr = void 0;
  21354. // Accept any in-dialog request.
  21355. if (message.to_tag) {
  21356. return;
  21357. }
  21358. // INVITE request.
  21359. if (message.method === JsSIP_C.INVITE) {
  21360. // If the branch matches the key of any IST then assume it is a retransmission
  21361. // and ignore the INVITE.
  21362. // TODO: we should reply the last response.
  21363. if (ua._transactions.ist[message.via_branch]) {
  21364. return false;
  21365. }
  21366. // Otherwise check whether it is a merged request.
  21367. else {
  21368. for (var transaction in ua._transactions.ist) {
  21369. if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) {
  21370. tr = ua._transactions.ist[transaction];
  21371. if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  21372. reply(482);
  21373. return false;
  21374. }
  21375. }
  21376. }
  21377. }
  21378. }
  21379. // Non INVITE request.
  21380. // If the branch matches the key of any NIST then assume it is a retransmission
  21381. // and ignore the request.
  21382. // TODO: we should reply the last response.
  21383. else if (ua._transactions.nist[message.via_branch]) {
  21384. return false;
  21385. }
  21386. // Otherwise check whether it is a merged request.
  21387. else {
  21388. for (var _transaction in ua._transactions.nist) {
  21389. if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) {
  21390. tr = ua._transactions.nist[_transaction];
  21391. if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  21392. reply(482);
  21393. return false;
  21394. }
  21395. }
  21396. }
  21397. }
  21398. }
  21399. // Sanity Check functions for responses.
  21400. function rfc3261_8_1_3_3() {
  21401. if (message.getHeaders('via').length > 1) {
  21402. debug('more than one Via header field present in the response, dropping the response');
  21403. return false;
  21404. }
  21405. }
  21406. function rfc3261_18_3_response() {
  21407. var len = Utils.str_utf8_length(message.body),
  21408. contentLength = message.getHeader('content-length');
  21409. if (len < contentLength) {
  21410. debug('message body length is lower than the value in Content-Length header field, dropping the response');
  21411. return false;
  21412. }
  21413. }
  21414. // Sanity Check functions for requests and responses.
  21415. function minimumHeaders() {
  21416. var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via'];
  21417. var _iteratorNormalCompletion4 = true;
  21418. var _didIteratorError4 = false;
  21419. var _iteratorError4 = undefined;
  21420. try {
  21421. for (var _iterator4 = mandatoryHeaders[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  21422. var header = _step4.value;
  21423. if (!message.hasHeader(header)) {
  21424. debug('missing mandatory header field : ' + header + ', dropping the response');
  21425. return false;
  21426. }
  21427. }
  21428. } catch (err) {
  21429. _didIteratorError4 = true;
  21430. _iteratorError4 = err;
  21431. } finally {
  21432. try {
  21433. if (!_iteratorNormalCompletion4 && _iterator4.return) {
  21434. _iterator4.return();
  21435. }
  21436. } finally {
  21437. if (_didIteratorError4) {
  21438. throw _iteratorError4;
  21439. }
  21440. }
  21441. }
  21442. }
  21443. // Reply.
  21444. function reply(status_code) {
  21445. var vias = message.getHeaders('via');
  21446. var to = void 0;
  21447. var response = 'SIP/2.0 ' + status_code + ' ' + JsSIP_C.REASON_PHRASE[status_code] + '\r\n';
  21448. var _iteratorNormalCompletion5 = true;
  21449. var _didIteratorError5 = false;
  21450. var _iteratorError5 = undefined;
  21451. try {
  21452. for (var _iterator5 = vias[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  21453. var via = _step5.value;
  21454. response += 'Via: ' + via + '\r\n';
  21455. }
  21456. } catch (err) {
  21457. _didIteratorError5 = true;
  21458. _iteratorError5 = err;
  21459. } finally {
  21460. try {
  21461. if (!_iteratorNormalCompletion5 && _iterator5.return) {
  21462. _iterator5.return();
  21463. }
  21464. } finally {
  21465. if (_didIteratorError5) {
  21466. throw _iteratorError5;
  21467. }
  21468. }
  21469. }
  21470. to = message.getHeader('To');
  21471. if (!message.to_tag) {
  21472. to += ';tag=' + Utils.newTag();
  21473. }
  21474. response += 'To: ' + to + '\r\n';
  21475. response += 'From: ' + message.getHeader('From') + '\r\n';
  21476. response += 'Call-ID: ' + message.call_id + '\r\n';
  21477. response += 'CSeq: ' + message.cseq + ' ' + message.method + '\r\n';
  21478. response += '\r\n';
  21479. transport.send(response);
  21480. }
  21481. },{"./Constants":2,"./SIPMessage":19,"./Utils":26,"debug":29}],29:[function(require,module,exports){
  21482. (function (process){
  21483. /**
  21484. * This is the web browser implementation of `debug()`.
  21485. *
  21486. * Expose `debug()` as the module.
  21487. */
  21488. exports = module.exports = require('./debug');
  21489. exports.log = log;
  21490. exports.formatArgs = formatArgs;
  21491. exports.save = save;
  21492. exports.load = load;
  21493. exports.useColors = useColors;
  21494. exports.storage = 'undefined' != typeof chrome
  21495. && 'undefined' != typeof chrome.storage
  21496. ? chrome.storage.local
  21497. : localstorage();
  21498. /**
  21499. * Colors.
  21500. */
  21501. exports.colors = [
  21502. '#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC',
  21503. '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF',
  21504. '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC',
  21505. '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF',
  21506. '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC',
  21507. '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033',
  21508. '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366',
  21509. '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933',
  21510. '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC',
  21511. '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF',
  21512. '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'
  21513. ];
  21514. /**
  21515. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  21516. * and the Firebug extension (any Firefox version) are known
  21517. * to support "%c" CSS customizations.
  21518. *
  21519. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  21520. */
  21521. function useColors() {
  21522. // NB: In an Electron preload script, document will be defined but not fully
  21523. // initialized. Since we know we're in Chrome, we'll just detect this case
  21524. // explicitly
  21525. if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
  21526. return true;
  21527. }
  21528. // Internet Explorer and Edge do not support colors.
  21529. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  21530. return false;
  21531. }
  21532. // is webkit? http://stackoverflow.com/a/16459606/376773
  21533. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  21534. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  21535. // is firebug? http://stackoverflow.com/a/398120/376773
  21536. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  21537. // is firefox >= v31?
  21538. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  21539. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  21540. // double check webkit in userAgent just in case we are in a worker
  21541. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  21542. }
  21543. /**
  21544. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  21545. */
  21546. exports.formatters.j = function(v) {
  21547. try {
  21548. return JSON.stringify(v);
  21549. } catch (err) {
  21550. return '[UnexpectedJSONParseError]: ' + err.message;
  21551. }
  21552. };
  21553. /**
  21554. * Colorize log arguments if enabled.
  21555. *
  21556. * @api public
  21557. */
  21558. function formatArgs(args) {
  21559. var useColors = this.useColors;
  21560. args[0] = (useColors ? '%c' : '')
  21561. + this.namespace
  21562. + (useColors ? ' %c' : ' ')
  21563. + args[0]
  21564. + (useColors ? '%c ' : ' ')
  21565. + '+' + exports.humanize(this.diff);
  21566. if (!useColors) return;
  21567. var c = 'color: ' + this.color;
  21568. args.splice(1, 0, c, 'color: inherit')
  21569. // the final "%c" is somewhat tricky, because there could be other
  21570. // arguments passed either before or after the %c, so we need to
  21571. // figure out the correct index to insert the CSS into
  21572. var index = 0;
  21573. var lastC = 0;
  21574. args[0].replace(/%[a-zA-Z%]/g, function(match) {
  21575. if ('%%' === match) return;
  21576. index++;
  21577. if ('%c' === match) {
  21578. // we only are interested in the *last* %c
  21579. // (the user may have provided their own)
  21580. lastC = index;
  21581. }
  21582. });
  21583. args.splice(lastC, 0, c);
  21584. }
  21585. /**
  21586. * Invokes `console.log()` when available.
  21587. * No-op when `console.log` is not a "function".
  21588. *
  21589. * @api public
  21590. */
  21591. function log() {
  21592. // this hackery is required for IE8/9, where
  21593. // the `console.log` function doesn't have 'apply'
  21594. return 'object' === typeof console
  21595. && console.log
  21596. && Function.prototype.apply.call(console.log, console, arguments);
  21597. }
  21598. /**
  21599. * Save `namespaces`.
  21600. *
  21601. * @param {String} namespaces
  21602. * @api private
  21603. */
  21604. function save(namespaces) {
  21605. try {
  21606. if (null == namespaces) {
  21607. exports.storage.removeItem('debug');
  21608. } else {
  21609. exports.storage.debug = namespaces;
  21610. }
  21611. } catch(e) {}
  21612. }
  21613. /**
  21614. * Load `namespaces`.
  21615. *
  21616. * @return {String} returns the previously persisted debug modes
  21617. * @api private
  21618. */
  21619. function load() {
  21620. var r;
  21621. try {
  21622. r = exports.storage.debug;
  21623. } catch(e) {}
  21624. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  21625. if (!r && typeof process !== 'undefined' && 'env' in process) {
  21626. r = process.env.DEBUG;
  21627. }
  21628. return r;
  21629. }
  21630. /**
  21631. * Enable namespaces listed in `localStorage.debug` initially.
  21632. */
  21633. exports.enable(load());
  21634. /**
  21635. * Localstorage attempts to return the localstorage.
  21636. *
  21637. * This is necessary because safari throws
  21638. * when a user disables cookies/localstorage
  21639. * and you attempt to access it.
  21640. *
  21641. * @return {LocalStorage}
  21642. * @api private
  21643. */
  21644. function localstorage() {
  21645. try {
  21646. return window.localStorage;
  21647. } catch (e) {}
  21648. }
  21649. }).call(this,require('_process'))
  21650. },{"./debug":30,"_process":33}],30:[function(require,module,exports){
  21651. /**
  21652. * This is the common logic for both the Node.js and web browser
  21653. * implementations of `debug()`.
  21654. *
  21655. * Expose `debug()` as the module.
  21656. */
  21657. exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
  21658. exports.coerce = coerce;
  21659. exports.disable = disable;
  21660. exports.enable = enable;
  21661. exports.enabled = enabled;
  21662. exports.humanize = require('ms');
  21663. /**
  21664. * Active `debug` instances.
  21665. */
  21666. exports.instances = [];
  21667. /**
  21668. * The currently active debug mode names, and names to skip.
  21669. */
  21670. exports.names = [];
  21671. exports.skips = [];
  21672. /**
  21673. * Map of special "%n" handling functions, for the debug "format" argument.
  21674. *
  21675. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  21676. */
  21677. exports.formatters = {};
  21678. /**
  21679. * Select a color.
  21680. * @param {String} namespace
  21681. * @return {Number}
  21682. * @api private
  21683. */
  21684. function selectColor(namespace) {
  21685. var hash = 0, i;
  21686. for (i in namespace) {
  21687. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  21688. hash |= 0; // Convert to 32bit integer
  21689. }
  21690. return exports.colors[Math.abs(hash) % exports.colors.length];
  21691. }
  21692. /**
  21693. * Create a debugger with the given `namespace`.
  21694. *
  21695. * @param {String} namespace
  21696. * @return {Function}
  21697. * @api public
  21698. */
  21699. function createDebug(namespace) {
  21700. var prevTime;
  21701. function debug() {
  21702. // disabled?
  21703. if (!debug.enabled) return;
  21704. var self = debug;
  21705. // set `diff` timestamp
  21706. var curr = +new Date();
  21707. var ms = curr - (prevTime || curr);
  21708. self.diff = ms;
  21709. self.prev = prevTime;
  21710. self.curr = curr;
  21711. prevTime = curr;
  21712. // turn the `arguments` into a proper Array
  21713. var args = new Array(arguments.length);
  21714. for (var i = 0; i < args.length; i++) {
  21715. args[i] = arguments[i];
  21716. }
  21717. args[0] = exports.coerce(args[0]);
  21718. if ('string' !== typeof args[0]) {
  21719. // anything else let's inspect with %O
  21720. args.unshift('%O');
  21721. }
  21722. // apply any `formatters` transformations
  21723. var index = 0;
  21724. args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
  21725. // if we encounter an escaped % then don't increase the array index
  21726. if (match === '%%') return match;
  21727. index++;
  21728. var formatter = exports.formatters[format];
  21729. if ('function' === typeof formatter) {
  21730. var val = args[index];
  21731. match = formatter.call(self, val);
  21732. // now we need to remove `args[index]` since it's inlined in the `format`
  21733. args.splice(index, 1);
  21734. index--;
  21735. }
  21736. return match;
  21737. });
  21738. // apply env-specific formatting (colors, etc.)
  21739. exports.formatArgs.call(self, args);
  21740. var logFn = debug.log || exports.log || console.log.bind(console);
  21741. logFn.apply(self, args);
  21742. }
  21743. debug.namespace = namespace;
  21744. debug.enabled = exports.enabled(namespace);
  21745. debug.useColors = exports.useColors();
  21746. debug.color = selectColor(namespace);
  21747. debug.destroy = destroy;
  21748. // env-specific initialization logic for debug instances
  21749. if ('function' === typeof exports.init) {
  21750. exports.init(debug);
  21751. }
  21752. exports.instances.push(debug);
  21753. return debug;
  21754. }
  21755. function destroy () {
  21756. var index = exports.instances.indexOf(this);
  21757. if (index !== -1) {
  21758. exports.instances.splice(index, 1);
  21759. return true;
  21760. } else {
  21761. return false;
  21762. }
  21763. }
  21764. /**
  21765. * Enables a debug mode by namespaces. This can include modes
  21766. * separated by a colon and wildcards.
  21767. *
  21768. * @param {String} namespaces
  21769. * @api public
  21770. */
  21771. function enable(namespaces) {
  21772. exports.save(namespaces);
  21773. exports.names = [];
  21774. exports.skips = [];
  21775. var i;
  21776. var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  21777. var len = split.length;
  21778. for (i = 0; i < len; i++) {
  21779. if (!split[i]) continue; // ignore empty strings
  21780. namespaces = split[i].replace(/\*/g, '.*?');
  21781. if (namespaces[0] === '-') {
  21782. exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  21783. } else {
  21784. exports.names.push(new RegExp('^' + namespaces + '$'));
  21785. }
  21786. }
  21787. for (i = 0; i < exports.instances.length; i++) {
  21788. var instance = exports.instances[i];
  21789. instance.enabled = exports.enabled(instance.namespace);
  21790. }
  21791. }
  21792. /**
  21793. * Disable debug output.
  21794. *
  21795. * @api public
  21796. */
  21797. function disable() {
  21798. exports.enable('');
  21799. }
  21800. /**
  21801. * Returns true if the given mode name is enabled, false otherwise.
  21802. *
  21803. * @param {String} name
  21804. * @return {Boolean}
  21805. * @api public
  21806. */
  21807. function enabled(name) {
  21808. if (name[name.length - 1] === '*') {
  21809. return true;
  21810. }
  21811. var i, len;
  21812. for (i = 0, len = exports.skips.length; i < len; i++) {
  21813. if (exports.skips[i].test(name)) {
  21814. return false;
  21815. }
  21816. }
  21817. for (i = 0, len = exports.names.length; i < len; i++) {
  21818. if (exports.names[i].test(name)) {
  21819. return true;
  21820. }
  21821. }
  21822. return false;
  21823. }
  21824. /**
  21825. * Coerce `val`.
  21826. *
  21827. * @param {Mixed} val
  21828. * @return {Mixed}
  21829. * @api private
  21830. */
  21831. function coerce(val) {
  21832. if (val instanceof Error) return val.stack || val.message;
  21833. return val;
  21834. }
  21835. },{"ms":32}],31:[function(require,module,exports){
  21836. // Copyright Joyent, Inc. and other Node contributors.
  21837. //
  21838. // Permission is hereby granted, free of charge, to any person obtaining a
  21839. // copy of this software and associated documentation files (the
  21840. // "Software"), to deal in the Software without restriction, including
  21841. // without limitation the rights to use, copy, modify, merge, publish,
  21842. // distribute, sublicense, and/or sell copies of the Software, and to permit
  21843. // persons to whom the Software is furnished to do so, subject to the
  21844. // following conditions:
  21845. //
  21846. // The above copyright notice and this permission notice shall be included
  21847. // in all copies or substantial portions of the Software.
  21848. //
  21849. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21850. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21851. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  21852. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  21853. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21854. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21855. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  21856. function EventEmitter() {
  21857. this._events = this._events || {};
  21858. this._maxListeners = this._maxListeners || undefined;
  21859. }
  21860. module.exports = EventEmitter;
  21861. // Backwards-compat with node 0.10.x
  21862. EventEmitter.EventEmitter = EventEmitter;
  21863. EventEmitter.prototype._events = undefined;
  21864. EventEmitter.prototype._maxListeners = undefined;
  21865. // By default EventEmitters will print a warning if more than 10 listeners are
  21866. // added to it. This is a useful default which helps finding memory leaks.
  21867. EventEmitter.defaultMaxListeners = 10;
  21868. // Obviously not all Emitters should be limited to 10. This function allows
  21869. // that to be increased. Set to zero for unlimited.
  21870. EventEmitter.prototype.setMaxListeners = function(n) {
  21871. if (!isNumber(n) || n < 0 || isNaN(n))
  21872. throw TypeError('n must be a positive number');
  21873. this._maxListeners = n;
  21874. return this;
  21875. };
  21876. EventEmitter.prototype.emit = function(type) {
  21877. var er, handler, len, args, i, listeners;
  21878. if (!this._events)
  21879. this._events = {};
  21880. // If there is no 'error' event listener then throw.
  21881. if (type === 'error') {
  21882. if (!this._events.error ||
  21883. (isObject(this._events.error) && !this._events.error.length)) {
  21884. er = arguments[1];
  21885. if (er instanceof Error) {
  21886. throw er; // Unhandled 'error' event
  21887. } else {
  21888. // At least give some kind of context to the user
  21889. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  21890. err.context = er;
  21891. throw err;
  21892. }
  21893. }
  21894. }
  21895. handler = this._events[type];
  21896. if (isUndefined(handler))
  21897. return false;
  21898. if (isFunction(handler)) {
  21899. switch (arguments.length) {
  21900. // fast cases
  21901. case 1:
  21902. handler.call(this);
  21903. break;
  21904. case 2:
  21905. handler.call(this, arguments[1]);
  21906. break;
  21907. case 3:
  21908. handler.call(this, arguments[1], arguments[2]);
  21909. break;
  21910. // slower
  21911. default:
  21912. args = Array.prototype.slice.call(arguments, 1);
  21913. handler.apply(this, args);
  21914. }
  21915. } else if (isObject(handler)) {
  21916. args = Array.prototype.slice.call(arguments, 1);
  21917. listeners = handler.slice();
  21918. len = listeners.length;
  21919. for (i = 0; i < len; i++)
  21920. listeners[i].apply(this, args);
  21921. }
  21922. return true;
  21923. };
  21924. EventEmitter.prototype.addListener = function(type, listener) {
  21925. var m;
  21926. if (!isFunction(listener))
  21927. throw TypeError('listener must be a function');
  21928. if (!this._events)
  21929. this._events = {};
  21930. // To avoid recursion in the case that type === "newListener"! Before
  21931. // adding it to the listeners, first emit "newListener".
  21932. if (this._events.newListener)
  21933. this.emit('newListener', type,
  21934. isFunction(listener.listener) ?
  21935. listener.listener : listener);
  21936. if (!this._events[type])
  21937. // Optimize the case of one listener. Don't need the extra array object.
  21938. this._events[type] = listener;
  21939. else if (isObject(this._events[type]))
  21940. // If we've already got an array, just append.
  21941. this._events[type].push(listener);
  21942. else
  21943. // Adding the second element, need to change to array.
  21944. this._events[type] = [this._events[type], listener];
  21945. // Check for listener leak
  21946. if (isObject(this._events[type]) && !this._events[type].warned) {
  21947. if (!isUndefined(this._maxListeners)) {
  21948. m = this._maxListeners;
  21949. } else {
  21950. m = EventEmitter.defaultMaxListeners;
  21951. }
  21952. if (m && m > 0 && this._events[type].length > m) {
  21953. this._events[type].warned = true;
  21954. console.error('(node) warning: possible EventEmitter memory ' +
  21955. 'leak detected. %d listeners added. ' +
  21956. 'Use emitter.setMaxListeners() to increase limit.',
  21957. this._events[type].length);
  21958. if (typeof console.trace === 'function') {
  21959. // not supported in IE 10
  21960. console.trace();
  21961. }
  21962. }
  21963. }
  21964. return this;
  21965. };
  21966. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  21967. EventEmitter.prototype.once = function(type, listener) {
  21968. if (!isFunction(listener))
  21969. throw TypeError('listener must be a function');
  21970. var fired = false;
  21971. function g() {
  21972. this.removeListener(type, g);
  21973. if (!fired) {
  21974. fired = true;
  21975. listener.apply(this, arguments);
  21976. }
  21977. }
  21978. g.listener = listener;
  21979. this.on(type, g);
  21980. return this;
  21981. };
  21982. // emits a 'removeListener' event iff the listener was removed
  21983. EventEmitter.prototype.removeListener = function(type, listener) {
  21984. var list, position, length, i;
  21985. if (!isFunction(listener))
  21986. throw TypeError('listener must be a function');
  21987. if (!this._events || !this._events[type])
  21988. return this;
  21989. list = this._events[type];
  21990. length = list.length;
  21991. position = -1;
  21992. if (list === listener ||
  21993. (isFunction(list.listener) && list.listener === listener)) {
  21994. delete this._events[type];
  21995. if (this._events.removeListener)
  21996. this.emit('removeListener', type, listener);
  21997. } else if (isObject(list)) {
  21998. for (i = length; i-- > 0;) {
  21999. if (list[i] === listener ||
  22000. (list[i].listener && list[i].listener === listener)) {
  22001. position = i;
  22002. break;
  22003. }
  22004. }
  22005. if (position < 0)
  22006. return this;
  22007. if (list.length === 1) {
  22008. list.length = 0;
  22009. delete this._events[type];
  22010. } else {
  22011. list.splice(position, 1);
  22012. }
  22013. if (this._events.removeListener)
  22014. this.emit('removeListener', type, listener);
  22015. }
  22016. return this;
  22017. };
  22018. EventEmitter.prototype.removeAllListeners = function(type) {
  22019. var key, listeners;
  22020. if (!this._events)
  22021. return this;
  22022. // not listening for removeListener, no need to emit
  22023. if (!this._events.removeListener) {
  22024. if (arguments.length === 0)
  22025. this._events = {};
  22026. else if (this._events[type])
  22027. delete this._events[type];
  22028. return this;
  22029. }
  22030. // emit removeListener for all listeners on all events
  22031. if (arguments.length === 0) {
  22032. for (key in this._events) {
  22033. if (key === 'removeListener') continue;
  22034. this.removeAllListeners(key);
  22035. }
  22036. this.removeAllListeners('removeListener');
  22037. this._events = {};
  22038. return this;
  22039. }
  22040. listeners = this._events[type];
  22041. if (isFunction(listeners)) {
  22042. this.removeListener(type, listeners);
  22043. } else if (listeners) {
  22044. // LIFO order
  22045. while (listeners.length)
  22046. this.removeListener(type, listeners[listeners.length - 1]);
  22047. }
  22048. delete this._events[type];
  22049. return this;
  22050. };
  22051. EventEmitter.prototype.listeners = function(type) {
  22052. var ret;
  22053. if (!this._events || !this._events[type])
  22054. ret = [];
  22055. else if (isFunction(this._events[type]))
  22056. ret = [this._events[type]];
  22057. else
  22058. ret = this._events[type].slice();
  22059. return ret;
  22060. };
  22061. EventEmitter.prototype.listenerCount = function(type) {
  22062. if (this._events) {
  22063. var evlistener = this._events[type];
  22064. if (isFunction(evlistener))
  22065. return 1;
  22066. else if (evlistener)
  22067. return evlistener.length;
  22068. }
  22069. return 0;
  22070. };
  22071. EventEmitter.listenerCount = function(emitter, type) {
  22072. return emitter.listenerCount(type);
  22073. };
  22074. function isFunction(arg) {
  22075. return typeof arg === 'function';
  22076. }
  22077. function isNumber(arg) {
  22078. return typeof arg === 'number';
  22079. }
  22080. function isObject(arg) {
  22081. return typeof arg === 'object' && arg !== null;
  22082. }
  22083. function isUndefined(arg) {
  22084. return arg === void 0;
  22085. }
  22086. },{}],32:[function(require,module,exports){
  22087. /**
  22088. * Helpers.
  22089. */
  22090. var s = 1000;
  22091. var m = s * 60;
  22092. var h = m * 60;
  22093. var d = h * 24;
  22094. var y = d * 365.25;
  22095. /**
  22096. * Parse or format the given `val`.
  22097. *
  22098. * Options:
  22099. *
  22100. * - `long` verbose formatting [false]
  22101. *
  22102. * @param {String|Number} val
  22103. * @param {Object} [options]
  22104. * @throws {Error} throw an error if val is not a non-empty string or a number
  22105. * @return {String|Number}
  22106. * @api public
  22107. */
  22108. module.exports = function(val, options) {
  22109. options = options || {};
  22110. var type = typeof val;
  22111. if (type === 'string' && val.length > 0) {
  22112. return parse(val);
  22113. } else if (type === 'number' && isNaN(val) === false) {
  22114. return options.long ? fmtLong(val) : fmtShort(val);
  22115. }
  22116. throw new Error(
  22117. 'val is not a non-empty string or a valid number. val=' +
  22118. JSON.stringify(val)
  22119. );
  22120. };
  22121. /**
  22122. * Parse the given `str` and return milliseconds.
  22123. *
  22124. * @param {String} str
  22125. * @return {Number}
  22126. * @api private
  22127. */
  22128. function parse(str) {
  22129. str = String(str);
  22130. if (str.length > 100) {
  22131. return;
  22132. }
  22133. var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
  22134. str
  22135. );
  22136. if (!match) {
  22137. return;
  22138. }
  22139. var n = parseFloat(match[1]);
  22140. var type = (match[2] || 'ms').toLowerCase();
  22141. switch (type) {
  22142. case 'years':
  22143. case 'year':
  22144. case 'yrs':
  22145. case 'yr':
  22146. case 'y':
  22147. return n * y;
  22148. case 'days':
  22149. case 'day':
  22150. case 'd':
  22151. return n * d;
  22152. case 'hours':
  22153. case 'hour':
  22154. case 'hrs':
  22155. case 'hr':
  22156. case 'h':
  22157. return n * h;
  22158. case 'minutes':
  22159. case 'minute':
  22160. case 'mins':
  22161. case 'min':
  22162. case 'm':
  22163. return n * m;
  22164. case 'seconds':
  22165. case 'second':
  22166. case 'secs':
  22167. case 'sec':
  22168. case 's':
  22169. return n * s;
  22170. case 'milliseconds':
  22171. case 'millisecond':
  22172. case 'msecs':
  22173. case 'msec':
  22174. case 'ms':
  22175. return n;
  22176. default:
  22177. return undefined;
  22178. }
  22179. }
  22180. /**
  22181. * Short format for `ms`.
  22182. *
  22183. * @param {Number} ms
  22184. * @return {String}
  22185. * @api private
  22186. */
  22187. function fmtShort(ms) {
  22188. if (ms >= d) {
  22189. return Math.round(ms / d) + 'd';
  22190. }
  22191. if (ms >= h) {
  22192. return Math.round(ms / h) + 'h';
  22193. }
  22194. if (ms >= m) {
  22195. return Math.round(ms / m) + 'm';
  22196. }
  22197. if (ms >= s) {
  22198. return Math.round(ms / s) + 's';
  22199. }
  22200. return ms + 'ms';
  22201. }
  22202. /**
  22203. * Long format for `ms`.
  22204. *
  22205. * @param {Number} ms
  22206. * @return {String}
  22207. * @api private
  22208. */
  22209. function fmtLong(ms) {
  22210. return plural(ms, d, 'day') ||
  22211. plural(ms, h, 'hour') ||
  22212. plural(ms, m, 'minute') ||
  22213. plural(ms, s, 'second') ||
  22214. ms + ' ms';
  22215. }
  22216. /**
  22217. * Pluralization helper.
  22218. */
  22219. function plural(ms, n, name) {
  22220. if (ms < n) {
  22221. return;
  22222. }
  22223. if (ms < n * 1.5) {
  22224. return Math.floor(ms / n) + ' ' + name;
  22225. }
  22226. return Math.ceil(ms / n) + ' ' + name + 's';
  22227. }
  22228. },{}],33:[function(require,module,exports){
  22229. // shim for using process in browser
  22230. var process = module.exports = {};
  22231. // cached from whatever global is present so that test runners that stub it
  22232. // don't break things. But we need to wrap it in a try catch in case it is
  22233. // wrapped in strict mode code which doesn't define any globals. It's inside a
  22234. // function because try/catches deoptimize in certain engines.
  22235. var cachedSetTimeout;
  22236. var cachedClearTimeout;
  22237. function defaultSetTimout() {
  22238. throw new Error('setTimeout has not been defined');
  22239. }
  22240. function defaultClearTimeout () {
  22241. throw new Error('clearTimeout has not been defined');
  22242. }
  22243. (function () {
  22244. try {
  22245. if (typeof setTimeout === 'function') {
  22246. cachedSetTimeout = setTimeout;
  22247. } else {
  22248. cachedSetTimeout = defaultSetTimout;
  22249. }
  22250. } catch (e) {
  22251. cachedSetTimeout = defaultSetTimout;
  22252. }
  22253. try {
  22254. if (typeof clearTimeout === 'function') {
  22255. cachedClearTimeout = clearTimeout;
  22256. } else {
  22257. cachedClearTimeout = defaultClearTimeout;
  22258. }
  22259. } catch (e) {
  22260. cachedClearTimeout = defaultClearTimeout;
  22261. }
  22262. } ())
  22263. function runTimeout(fun) {
  22264. if (cachedSetTimeout === setTimeout) {
  22265. //normal enviroments in sane situations
  22266. return setTimeout(fun, 0);
  22267. }
  22268. // if setTimeout wasn't available but was latter defined
  22269. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  22270. cachedSetTimeout = setTimeout;
  22271. return setTimeout(fun, 0);
  22272. }
  22273. try {
  22274. // when when somebody has screwed with setTimeout but no I.E. maddness
  22275. return cachedSetTimeout(fun, 0);
  22276. } catch(e){
  22277. try {
  22278. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  22279. return cachedSetTimeout.call(null, fun, 0);
  22280. } catch(e){
  22281. // 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
  22282. return cachedSetTimeout.call(this, fun, 0);
  22283. }
  22284. }
  22285. }
  22286. function runClearTimeout(marker) {
  22287. if (cachedClearTimeout === clearTimeout) {
  22288. //normal enviroments in sane situations
  22289. return clearTimeout(marker);
  22290. }
  22291. // if clearTimeout wasn't available but was latter defined
  22292. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  22293. cachedClearTimeout = clearTimeout;
  22294. return clearTimeout(marker);
  22295. }
  22296. try {
  22297. // when when somebody has screwed with setTimeout but no I.E. maddness
  22298. return cachedClearTimeout(marker);
  22299. } catch (e){
  22300. try {
  22301. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  22302. return cachedClearTimeout.call(null, marker);
  22303. } catch (e){
  22304. // 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.
  22305. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  22306. return cachedClearTimeout.call(this, marker);
  22307. }
  22308. }
  22309. }
  22310. var queue = [];
  22311. var draining = false;
  22312. var currentQueue;
  22313. var queueIndex = -1;
  22314. function cleanUpNextTick() {
  22315. if (!draining || !currentQueue) {
  22316. return;
  22317. }
  22318. draining = false;
  22319. if (currentQueue.length) {
  22320. queue = currentQueue.concat(queue);
  22321. } else {
  22322. queueIndex = -1;
  22323. }
  22324. if (queue.length) {
  22325. drainQueue();
  22326. }
  22327. }
  22328. function drainQueue() {
  22329. if (draining) {
  22330. return;
  22331. }
  22332. var timeout = runTimeout(cleanUpNextTick);
  22333. draining = true;
  22334. var len = queue.length;
  22335. while(len) {
  22336. currentQueue = queue;
  22337. queue = [];
  22338. while (++queueIndex < len) {
  22339. if (currentQueue) {
  22340. currentQueue[queueIndex].run();
  22341. }
  22342. }
  22343. queueIndex = -1;
  22344. len = queue.length;
  22345. }
  22346. currentQueue = null;
  22347. draining = false;
  22348. runClearTimeout(timeout);
  22349. }
  22350. process.nextTick = function (fun) {
  22351. var args = new Array(arguments.length - 1);
  22352. if (arguments.length > 1) {
  22353. for (var i = 1; i < arguments.length; i++) {
  22354. args[i - 1] = arguments[i];
  22355. }
  22356. }
  22357. queue.push(new Item(fun, args));
  22358. if (queue.length === 1 && !draining) {
  22359. runTimeout(drainQueue);
  22360. }
  22361. };
  22362. // v8 likes predictible objects
  22363. function Item(fun, array) {
  22364. this.fun = fun;
  22365. this.array = array;
  22366. }
  22367. Item.prototype.run = function () {
  22368. this.fun.apply(null, this.array);
  22369. };
  22370. process.title = 'browser';
  22371. process.browser = true;
  22372. process.env = {};
  22373. process.argv = [];
  22374. process.version = ''; // empty string to avoid regexp issues
  22375. process.versions = {};
  22376. function noop() {}
  22377. process.on = noop;
  22378. process.addListener = noop;
  22379. process.once = noop;
  22380. process.off = noop;
  22381. process.removeListener = noop;
  22382. process.removeAllListeners = noop;
  22383. process.emit = noop;
  22384. process.prependListener = noop;
  22385. process.prependOnceListener = noop;
  22386. process.listeners = function (name) { return [] }
  22387. process.binding = function (name) {
  22388. throw new Error('process.binding is not supported');
  22389. };
  22390. process.cwd = function () { return '/' };
  22391. process.chdir = function (dir) {
  22392. throw new Error('process.chdir is not supported');
  22393. };
  22394. process.umask = function() { return 0; };
  22395. },{}],34:[function(require,module,exports){
  22396. /*
  22397. * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  22398. *
  22399. * Use of this source code is governed by a BSD-style license
  22400. * that can be found in the LICENSE file in the root of the source
  22401. * tree.
  22402. */
  22403. /* eslint-env node */
  22404. 'use strict';
  22405. var SDPUtils = require('sdp');
  22406. function writeMediaSection(transceiver, caps, type, stream, dtlsRole) {
  22407. var sdp = SDPUtils.writeRtpDescription(transceiver.kind, caps);
  22408. // Map ICE parameters (ufrag, pwd) to SDP.
  22409. sdp += SDPUtils.writeIceParameters(
  22410. transceiver.iceGatherer.getLocalParameters());
  22411. // Map DTLS parameters to SDP.
  22412. sdp += SDPUtils.writeDtlsParameters(
  22413. transceiver.dtlsTransport.getLocalParameters(),
  22414. type === 'offer' ? 'actpass' : dtlsRole || 'active');
  22415. sdp += 'a=mid:' + transceiver.mid + '\r\n';
  22416. if (transceiver.rtpSender && transceiver.rtpReceiver) {
  22417. sdp += 'a=sendrecv\r\n';
  22418. } else if (transceiver.rtpSender) {
  22419. sdp += 'a=sendonly\r\n';
  22420. } else if (transceiver.rtpReceiver) {
  22421. sdp += 'a=recvonly\r\n';
  22422. } else {
  22423. sdp += 'a=inactive\r\n';
  22424. }
  22425. if (transceiver.rtpSender) {
  22426. // spec.
  22427. var msid = 'msid:' + stream.id + ' ' +
  22428. transceiver.rtpSender.track.id + '\r\n';
  22429. sdp += 'a=' + msid;
  22430. // for Chrome.
  22431. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +
  22432. ' ' + msid;
  22433. if (transceiver.sendEncodingParameters[0].rtx) {
  22434. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc +
  22435. ' ' + msid;
  22436. sdp += 'a=ssrc-group:FID ' +
  22437. transceiver.sendEncodingParameters[0].ssrc + ' ' +
  22438. transceiver.sendEncodingParameters[0].rtx.ssrc +
  22439. '\r\n';
  22440. }
  22441. }
  22442. // FIXME: this should be written by writeRtpDescription.
  22443. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +
  22444. ' cname:' + SDPUtils.localCName + '\r\n';
  22445. if (transceiver.rtpSender && transceiver.sendEncodingParameters[0].rtx) {
  22446. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc +
  22447. ' cname:' + SDPUtils.localCName + '\r\n';
  22448. }
  22449. return sdp;
  22450. }
  22451. // Edge does not like
  22452. // 1) stun: filtered after 14393 unless ?transport=udp is present
  22453. // 2) turn: that does not have all of turn:host:port?transport=udp
  22454. // 3) turn: with ipv6 addresses
  22455. // 4) turn: occurring muliple times
  22456. function filterIceServers(iceServers, edgeVersion) {
  22457. var hasTurn = false;
  22458. iceServers = JSON.parse(JSON.stringify(iceServers));
  22459. return iceServers.filter(function(server) {
  22460. if (server && (server.urls || server.url)) {
  22461. var urls = server.urls || server.url;
  22462. if (server.url && !server.urls) {
  22463. console.warn('RTCIceServer.url is deprecated! Use urls instead.');
  22464. }
  22465. var isString = typeof urls === 'string';
  22466. if (isString) {
  22467. urls = [urls];
  22468. }
  22469. urls = urls.filter(function(url) {
  22470. var validTurn = url.indexOf('turn:') === 0 &&
  22471. url.indexOf('transport=udp') !== -1 &&
  22472. url.indexOf('turn:[') === -1 &&
  22473. !hasTurn;
  22474. if (validTurn) {
  22475. hasTurn = true;
  22476. return true;
  22477. }
  22478. return url.indexOf('stun:') === 0 && edgeVersion >= 14393 &&
  22479. url.indexOf('?transport=udp') === -1;
  22480. });
  22481. delete server.url;
  22482. server.urls = isString ? urls[0] : urls;
  22483. return !!urls.length;
  22484. }
  22485. });
  22486. }
  22487. // Determines the intersection of local and remote capabilities.
  22488. function getCommonCapabilities(localCapabilities, remoteCapabilities) {
  22489. var commonCapabilities = {
  22490. codecs: [],
  22491. headerExtensions: [],
  22492. fecMechanisms: []
  22493. };
  22494. var findCodecByPayloadType = function(pt, codecs) {
  22495. pt = parseInt(pt, 10);
  22496. for (var i = 0; i < codecs.length; i++) {
  22497. if (codecs[i].payloadType === pt ||
  22498. codecs[i].preferredPayloadType === pt) {
  22499. return codecs[i];
  22500. }
  22501. }
  22502. };
  22503. var rtxCapabilityMatches = function(lRtx, rRtx, lCodecs, rCodecs) {
  22504. var lCodec = findCodecByPayloadType(lRtx.parameters.apt, lCodecs);
  22505. var rCodec = findCodecByPayloadType(rRtx.parameters.apt, rCodecs);
  22506. return lCodec && rCodec &&
  22507. lCodec.name.toLowerCase() === rCodec.name.toLowerCase();
  22508. };
  22509. localCapabilities.codecs.forEach(function(lCodec) {
  22510. for (var i = 0; i < remoteCapabilities.codecs.length; i++) {
  22511. var rCodec = remoteCapabilities.codecs[i];
  22512. if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() &&
  22513. lCodec.clockRate === rCodec.clockRate) {
  22514. if (lCodec.name.toLowerCase() === 'rtx' &&
  22515. lCodec.parameters && rCodec.parameters.apt) {
  22516. // for RTX we need to find the local rtx that has a apt
  22517. // which points to the same local codec as the remote one.
  22518. if (!rtxCapabilityMatches(lCodec, rCodec,
  22519. localCapabilities.codecs, remoteCapabilities.codecs)) {
  22520. continue;
  22521. }
  22522. }
  22523. rCodec = JSON.parse(JSON.stringify(rCodec)); // deepcopy
  22524. // number of channels is the highest common number of channels
  22525. rCodec.numChannels = Math.min(lCodec.numChannels,
  22526. rCodec.numChannels);
  22527. // push rCodec so we reply with offerer payload type
  22528. commonCapabilities.codecs.push(rCodec);
  22529. // determine common feedback mechanisms
  22530. rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function(fb) {
  22531. for (var j = 0; j < lCodec.rtcpFeedback.length; j++) {
  22532. if (lCodec.rtcpFeedback[j].type === fb.type &&
  22533. lCodec.rtcpFeedback[j].parameter === fb.parameter) {
  22534. return true;
  22535. }
  22536. }
  22537. return false;
  22538. });
  22539. // FIXME: also need to determine .parameters
  22540. // see https://github.com/openpeer/ortc/issues/569
  22541. break;
  22542. }
  22543. }
  22544. });
  22545. localCapabilities.headerExtensions.forEach(function(lHeaderExtension) {
  22546. for (var i = 0; i < remoteCapabilities.headerExtensions.length;
  22547. i++) {
  22548. var rHeaderExtension = remoteCapabilities.headerExtensions[i];
  22549. if (lHeaderExtension.uri === rHeaderExtension.uri) {
  22550. commonCapabilities.headerExtensions.push(rHeaderExtension);
  22551. break;
  22552. }
  22553. }
  22554. });
  22555. // FIXME: fecMechanisms
  22556. return commonCapabilities;
  22557. }
  22558. // is action=setLocalDescription with type allowed in signalingState
  22559. function isActionAllowedInSignalingState(action, type, signalingState) {
  22560. return {
  22561. offer: {
  22562. setLocalDescription: ['stable', 'have-local-offer'],
  22563. setRemoteDescription: ['stable', 'have-remote-offer']
  22564. },
  22565. answer: {
  22566. setLocalDescription: ['have-remote-offer', 'have-local-pranswer'],
  22567. setRemoteDescription: ['have-local-offer', 'have-remote-pranswer']
  22568. }
  22569. }[type][action].indexOf(signalingState) !== -1;
  22570. }
  22571. function maybeAddCandidate(iceTransport, candidate) {
  22572. // Edge's internal representation adds some fields therefore
  22573. // not all fieldѕ are taken into account.
  22574. var alreadyAdded = iceTransport.getRemoteCandidates()
  22575. .find(function(remoteCandidate) {
  22576. return candidate.foundation === remoteCandidate.foundation &&
  22577. candidate.ip === remoteCandidate.ip &&
  22578. candidate.port === remoteCandidate.port &&
  22579. candidate.priority === remoteCandidate.priority &&
  22580. candidate.protocol === remoteCandidate.protocol &&
  22581. candidate.type === remoteCandidate.type;
  22582. });
  22583. if (!alreadyAdded) {
  22584. iceTransport.addRemoteCandidate(candidate);
  22585. }
  22586. return !alreadyAdded;
  22587. }
  22588. // https://w3c.github.io/mediacapture-main/#mediastream
  22589. // Helper function to add the track to the stream and
  22590. // dispatch the event ourselves.
  22591. function addTrackToStreamAndFireEvent(track, stream) {
  22592. stream.addTrack(track);
  22593. var e = new Event('addtrack'); // TODO: MediaStreamTrackEvent
  22594. e.track = track;
  22595. stream.dispatchEvent(e);
  22596. }
  22597. function removeTrackFromStreamAndFireEvent(track, stream) {
  22598. stream.removeTrack(track);
  22599. var e = new Event('removetrack'); // TODO: MediaStreamTrackEvent
  22600. e.track = track;
  22601. stream.dispatchEvent(e);
  22602. }
  22603. function fireAddTrack(pc, track, receiver, streams) {
  22604. var trackEvent = new Event('track');
  22605. trackEvent.track = track;
  22606. trackEvent.receiver = receiver;
  22607. trackEvent.transceiver = {receiver: receiver};
  22608. trackEvent.streams = streams;
  22609. window.setTimeout(function() {
  22610. pc._dispatchEvent('track', trackEvent);
  22611. });
  22612. }
  22613. function makeError(name, description) {
  22614. var e = new Error(description);
  22615. e.name = name;
  22616. return e;
  22617. }
  22618. module.exports = function(window, edgeVersion) {
  22619. var RTCPeerConnection = function(config) {
  22620. var pc = this;
  22621. var _eventTarget = document.createDocumentFragment();
  22622. ['addEventListener', 'removeEventListener', 'dispatchEvent']
  22623. .forEach(function(method) {
  22624. pc[method] = _eventTarget[method].bind(_eventTarget);
  22625. });
  22626. this.canTrickleIceCandidates = null;
  22627. this.needNegotiation = false;
  22628. this.localStreams = [];
  22629. this.remoteStreams = [];
  22630. this.localDescription = null;
  22631. this.remoteDescription = null;
  22632. this.signalingState = 'stable';
  22633. this.iceConnectionState = 'new';
  22634. this.iceGatheringState = 'new';
  22635. config = JSON.parse(JSON.stringify(config || {}));
  22636. this.usingBundle = config.bundlePolicy === 'max-bundle';
  22637. if (config.rtcpMuxPolicy === 'negotiate') {
  22638. throw(makeError('NotSupportedError',
  22639. 'rtcpMuxPolicy \'negotiate\' is not supported'));
  22640. } else if (!config.rtcpMuxPolicy) {
  22641. config.rtcpMuxPolicy = 'require';
  22642. }
  22643. switch (config.iceTransportPolicy) {
  22644. case 'all':
  22645. case 'relay':
  22646. break;
  22647. default:
  22648. config.iceTransportPolicy = 'all';
  22649. break;
  22650. }
  22651. switch (config.bundlePolicy) {
  22652. case 'balanced':
  22653. case 'max-compat':
  22654. case 'max-bundle':
  22655. break;
  22656. default:
  22657. config.bundlePolicy = 'balanced';
  22658. break;
  22659. }
  22660. config.iceServers = filterIceServers(config.iceServers || [], edgeVersion);
  22661. this._iceGatherers = [];
  22662. if (config.iceCandidatePoolSize) {
  22663. for (var i = config.iceCandidatePoolSize; i > 0; i--) {
  22664. this._iceGatherers = new window.RTCIceGatherer({
  22665. iceServers: config.iceServers,
  22666. gatherPolicy: config.iceTransportPolicy
  22667. });
  22668. }
  22669. } else {
  22670. config.iceCandidatePoolSize = 0;
  22671. }
  22672. this._config = config;
  22673. // per-track iceGathers, iceTransports, dtlsTransports, rtpSenders, ...
  22674. // everything that is needed to describe a SDP m-line.
  22675. this.transceivers = [];
  22676. this._sdpSessionId = SDPUtils.generateSessionId();
  22677. this._sdpSessionVersion = 0;
  22678. this._dtlsRole = undefined; // role for a=setup to use in answers.
  22679. this._isClosed = false;
  22680. };
  22681. // set up event handlers on prototype
  22682. RTCPeerConnection.prototype.onicecandidate = null;
  22683. RTCPeerConnection.prototype.onaddstream = null;
  22684. RTCPeerConnection.prototype.ontrack = null;
  22685. RTCPeerConnection.prototype.onremovestream = null;
  22686. RTCPeerConnection.prototype.onsignalingstatechange = null;
  22687. RTCPeerConnection.prototype.oniceconnectionstatechange = null;
  22688. RTCPeerConnection.prototype.onicegatheringstatechange = null;
  22689. RTCPeerConnection.prototype.onnegotiationneeded = null;
  22690. RTCPeerConnection.prototype.ondatachannel = null;
  22691. RTCPeerConnection.prototype._dispatchEvent = function(name, event) {
  22692. if (this._isClosed) {
  22693. return;
  22694. }
  22695. this.dispatchEvent(event);
  22696. if (typeof this['on' + name] === 'function') {
  22697. this['on' + name](event);
  22698. }
  22699. };
  22700. RTCPeerConnection.prototype._emitGatheringStateChange = function() {
  22701. var event = new Event('icegatheringstatechange');
  22702. this._dispatchEvent('icegatheringstatechange', event);
  22703. };
  22704. RTCPeerConnection.prototype.getConfiguration = function() {
  22705. return this._config;
  22706. };
  22707. RTCPeerConnection.prototype.getLocalStreams = function() {
  22708. return this.localStreams;
  22709. };
  22710. RTCPeerConnection.prototype.getRemoteStreams = function() {
  22711. return this.remoteStreams;
  22712. };
  22713. // internal helper to create a transceiver object.
  22714. // (whih is not yet the same as the WebRTC 1.0 transceiver)
  22715. RTCPeerConnection.prototype._createTransceiver = function(kind) {
  22716. var hasBundleTransport = this.transceivers.length > 0;
  22717. var transceiver = {
  22718. track: null,
  22719. iceGatherer: null,
  22720. iceTransport: null,
  22721. dtlsTransport: null,
  22722. localCapabilities: null,
  22723. remoteCapabilities: null,
  22724. rtpSender: null,
  22725. rtpReceiver: null,
  22726. kind: kind,
  22727. mid: null,
  22728. sendEncodingParameters: null,
  22729. recvEncodingParameters: null,
  22730. stream: null,
  22731. associatedRemoteMediaStreams: [],
  22732. wantReceive: true
  22733. };
  22734. if (this.usingBundle && hasBundleTransport) {
  22735. transceiver.iceTransport = this.transceivers[0].iceTransport;
  22736. transceiver.dtlsTransport = this.transceivers[0].dtlsTransport;
  22737. } else {
  22738. var transports = this._createIceAndDtlsTransports();
  22739. transceiver.iceTransport = transports.iceTransport;
  22740. transceiver.dtlsTransport = transports.dtlsTransport;
  22741. }
  22742. this.transceivers.push(transceiver);
  22743. return transceiver;
  22744. };
  22745. RTCPeerConnection.prototype.addTrack = function(track, stream) {
  22746. var alreadyExists = this.transceivers.find(function(s) {
  22747. return s.track === track;
  22748. });
  22749. if (alreadyExists) {
  22750. throw makeError('InvalidAccessError', 'Track already exists.');
  22751. }
  22752. if (this.signalingState === 'closed') {
  22753. throw makeError('InvalidStateError',
  22754. 'Attempted to call addTrack on a closed peerconnection.');
  22755. }
  22756. var transceiver;
  22757. for (var i = 0; i < this.transceivers.length; i++) {
  22758. if (!this.transceivers[i].track &&
  22759. this.transceivers[i].kind === track.kind) {
  22760. transceiver = this.transceivers[i];
  22761. }
  22762. }
  22763. if (!transceiver) {
  22764. transceiver = this._createTransceiver(track.kind);
  22765. }
  22766. this._maybeFireNegotiationNeeded();
  22767. if (this.localStreams.indexOf(stream) === -1) {
  22768. this.localStreams.push(stream);
  22769. }
  22770. transceiver.track = track;
  22771. transceiver.stream = stream;
  22772. transceiver.rtpSender = new window.RTCRtpSender(track,
  22773. transceiver.dtlsTransport);
  22774. return transceiver.rtpSender;
  22775. };
  22776. RTCPeerConnection.prototype.addStream = function(stream) {
  22777. var pc = this;
  22778. if (edgeVersion >= 15025) {
  22779. stream.getTracks().forEach(function(track) {
  22780. pc.addTrack(track, stream);
  22781. });
  22782. } else {
  22783. // Clone is necessary for local demos mostly, attaching directly
  22784. // to two different senders does not work (build 10547).
  22785. // Fixed in 15025 (or earlier)
  22786. var clonedStream = stream.clone();
  22787. stream.getTracks().forEach(function(track, idx) {
  22788. var clonedTrack = clonedStream.getTracks()[idx];
  22789. track.addEventListener('enabled', function(event) {
  22790. clonedTrack.enabled = event.enabled;
  22791. });
  22792. });
  22793. clonedStream.getTracks().forEach(function(track) {
  22794. pc.addTrack(track, clonedStream);
  22795. });
  22796. }
  22797. };
  22798. RTCPeerConnection.prototype.removeTrack = function(sender) {
  22799. if (!(sender instanceof window.RTCRtpSender)) {
  22800. throw new TypeError('Argument 1 of RTCPeerConnection.removeTrack ' +
  22801. 'does not implement interface RTCRtpSender.');
  22802. }
  22803. var transceiver = this.transceivers.find(function(t) {
  22804. return t.rtpSender === sender;
  22805. });
  22806. if (!transceiver) {
  22807. throw makeError('InvalidAccessError',
  22808. 'Sender was not created by this connection.');
  22809. }
  22810. var stream = transceiver.stream;
  22811. transceiver.rtpSender.stop();
  22812. transceiver.rtpSender = null;
  22813. transceiver.track = null;
  22814. transceiver.stream = null;
  22815. // remove the stream from the set of local streams
  22816. var localStreams = this.transceivers.map(function(t) {
  22817. return t.stream;
  22818. });
  22819. if (localStreams.indexOf(stream) === -1 &&
  22820. this.localStreams.indexOf(stream) > -1) {
  22821. this.localStreams.splice(this.localStreams.indexOf(stream), 1);
  22822. }
  22823. this._maybeFireNegotiationNeeded();
  22824. };
  22825. RTCPeerConnection.prototype.removeStream = function(stream) {
  22826. var pc = this;
  22827. stream.getTracks().forEach(function(track) {
  22828. var sender = pc.getSenders().find(function(s) {
  22829. return s.track === track;
  22830. });
  22831. if (sender) {
  22832. pc.removeTrack(sender);
  22833. }
  22834. });
  22835. };
  22836. RTCPeerConnection.prototype.getSenders = function() {
  22837. return this.transceivers.filter(function(transceiver) {
  22838. return !!transceiver.rtpSender;
  22839. })
  22840. .map(function(transceiver) {
  22841. return transceiver.rtpSender;
  22842. });
  22843. };
  22844. RTCPeerConnection.prototype.getReceivers = function() {
  22845. return this.transceivers.filter(function(transceiver) {
  22846. return !!transceiver.rtpReceiver;
  22847. })
  22848. .map(function(transceiver) {
  22849. return transceiver.rtpReceiver;
  22850. });
  22851. };
  22852. RTCPeerConnection.prototype._createIceGatherer = function(sdpMLineIndex,
  22853. usingBundle) {
  22854. var pc = this;
  22855. if (usingBundle && sdpMLineIndex > 0) {
  22856. return this.transceivers[0].iceGatherer;
  22857. } else if (this._iceGatherers.length) {
  22858. return this._iceGatherers.shift();
  22859. }
  22860. var iceGatherer = new window.RTCIceGatherer({
  22861. iceServers: this._config.iceServers,
  22862. gatherPolicy: this._config.iceTransportPolicy
  22863. });
  22864. Object.defineProperty(iceGatherer, 'state',
  22865. {value: 'new', writable: true}
  22866. );
  22867. this.transceivers[sdpMLineIndex].candidates = [];
  22868. this.transceivers[sdpMLineIndex].bufferCandidates = function(event) {
  22869. var end = !event.candidate || Object.keys(event.candidate).length === 0;
  22870. // polyfill since RTCIceGatherer.state is not implemented in
  22871. // Edge 10547 yet.
  22872. iceGatherer.state = end ? 'completed' : 'gathering';
  22873. if (pc.transceivers[sdpMLineIndex].candidates !== null) {
  22874. pc.transceivers[sdpMLineIndex].candidates.push(event.candidate);
  22875. }
  22876. };
  22877. iceGatherer.addEventListener('localcandidate',
  22878. this.transceivers[sdpMLineIndex].bufferCandidates);
  22879. return iceGatherer;
  22880. };
  22881. // start gathering from an RTCIceGatherer.
  22882. RTCPeerConnection.prototype._gather = function(mid, sdpMLineIndex) {
  22883. var pc = this;
  22884. var iceGatherer = this.transceivers[sdpMLineIndex].iceGatherer;
  22885. if (iceGatherer.onlocalcandidate) {
  22886. return;
  22887. }
  22888. var candidates = this.transceivers[sdpMLineIndex].candidates;
  22889. this.transceivers[sdpMLineIndex].candidates = null;
  22890. iceGatherer.removeEventListener('localcandidate',
  22891. this.transceivers[sdpMLineIndex].bufferCandidates);
  22892. iceGatherer.onlocalcandidate = function(evt) {
  22893. if (pc.usingBundle && sdpMLineIndex > 0) {
  22894. // if we know that we use bundle we can drop candidates with
  22895. // ѕdpMLineIndex > 0. If we don't do this then our state gets
  22896. // confused since we dispose the extra ice gatherer.
  22897. return;
  22898. }
  22899. var event = new Event('icecandidate');
  22900. event.candidate = {sdpMid: mid, sdpMLineIndex: sdpMLineIndex};
  22901. var cand = evt.candidate;
  22902. // Edge emits an empty object for RTCIceCandidateComplete‥
  22903. var end = !cand || Object.keys(cand).length === 0;
  22904. if (end) {
  22905. // polyfill since RTCIceGatherer.state is not implemented in
  22906. // Edge 10547 yet.
  22907. if (iceGatherer.state === 'new' || iceGatherer.state === 'gathering') {
  22908. iceGatherer.state = 'completed';
  22909. }
  22910. } else {
  22911. if (iceGatherer.state === 'new') {
  22912. iceGatherer.state = 'gathering';
  22913. }
  22914. // RTCIceCandidate doesn't have a component, needs to be added
  22915. cand.component = 1;
  22916. event.candidate.candidate = SDPUtils.writeCandidate(cand);
  22917. }
  22918. // update local description.
  22919. var sections = SDPUtils.splitSections(pc.localDescription.sdp);
  22920. if (!end) {
  22921. sections[event.candidate.sdpMLineIndex + 1] +=
  22922. 'a=' + event.candidate.candidate + '\r\n';
  22923. } else {
  22924. sections[event.candidate.sdpMLineIndex + 1] +=
  22925. 'a=end-of-candidates\r\n';
  22926. }
  22927. pc.localDescription.sdp = sections.join('');
  22928. var complete = pc.transceivers.every(function(transceiver) {
  22929. return transceiver.iceGatherer &&
  22930. transceiver.iceGatherer.state === 'completed';
  22931. });
  22932. if (pc.iceGatheringState !== 'gathering') {
  22933. pc.iceGatheringState = 'gathering';
  22934. pc._emitGatheringStateChange();
  22935. }
  22936. // Emit candidate. Also emit null candidate when all gatherers are
  22937. // complete.
  22938. if (!end) {
  22939. pc._dispatchEvent('icecandidate', event);
  22940. }
  22941. if (complete) {
  22942. pc._dispatchEvent('icecandidate', new Event('icecandidate'));
  22943. pc.iceGatheringState = 'complete';
  22944. pc._emitGatheringStateChange();
  22945. }
  22946. };
  22947. // emit already gathered candidates.
  22948. window.setTimeout(function() {
  22949. candidates.forEach(function(candidate) {
  22950. var e = new Event('RTCIceGatherEvent');
  22951. e.candidate = candidate;
  22952. iceGatherer.onlocalcandidate(e);
  22953. });
  22954. }, 0);
  22955. };
  22956. // Create ICE transport and DTLS transport.
  22957. RTCPeerConnection.prototype._createIceAndDtlsTransports = function() {
  22958. var pc = this;
  22959. var iceTransport = new window.RTCIceTransport(null);
  22960. iceTransport.onicestatechange = function() {
  22961. pc._updateConnectionState();
  22962. };
  22963. var dtlsTransport = new window.RTCDtlsTransport(iceTransport);
  22964. dtlsTransport.ondtlsstatechange = function() {
  22965. pc._updateConnectionState();
  22966. };
  22967. dtlsTransport.onerror = function() {
  22968. // onerror does not set state to failed by itpc.
  22969. Object.defineProperty(dtlsTransport, 'state',
  22970. {value: 'failed', writable: true});
  22971. pc._updateConnectionState();
  22972. };
  22973. return {
  22974. iceTransport: iceTransport,
  22975. dtlsTransport: dtlsTransport
  22976. };
  22977. };
  22978. // Destroy ICE gatherer, ICE transport and DTLS transport.
  22979. // Without triggering the callbacks.
  22980. RTCPeerConnection.prototype._disposeIceAndDtlsTransports = function(
  22981. sdpMLineIndex) {
  22982. var iceGatherer = this.transceivers[sdpMLineIndex].iceGatherer;
  22983. if (iceGatherer) {
  22984. delete iceGatherer.onlocalcandidate;
  22985. delete this.transceivers[sdpMLineIndex].iceGatherer;
  22986. }
  22987. var iceTransport = this.transceivers[sdpMLineIndex].iceTransport;
  22988. if (iceTransport) {
  22989. delete iceTransport.onicestatechange;
  22990. delete this.transceivers[sdpMLineIndex].iceTransport;
  22991. }
  22992. var dtlsTransport = this.transceivers[sdpMLineIndex].dtlsTransport;
  22993. if (dtlsTransport) {
  22994. delete dtlsTransport.ondtlsstatechange;
  22995. delete dtlsTransport.onerror;
  22996. delete this.transceivers[sdpMLineIndex].dtlsTransport;
  22997. }
  22998. };
  22999. // Start the RTP Sender and Receiver for a transceiver.
  23000. RTCPeerConnection.prototype._transceive = function(transceiver,
  23001. send, recv) {
  23002. var params = getCommonCapabilities(transceiver.localCapabilities,
  23003. transceiver.remoteCapabilities);
  23004. if (send && transceiver.rtpSender) {
  23005. params.encodings = transceiver.sendEncodingParameters;
  23006. params.rtcp = {
  23007. cname: SDPUtils.localCName,
  23008. compound: transceiver.rtcpParameters.compound
  23009. };
  23010. if (transceiver.recvEncodingParameters.length) {
  23011. params.rtcp.ssrc = transceiver.recvEncodingParameters[0].ssrc;
  23012. }
  23013. transceiver.rtpSender.send(params);
  23014. }
  23015. if (recv && transceiver.rtpReceiver && params.codecs.length > 0) {
  23016. // remove RTX field in Edge 14942
  23017. if (transceiver.kind === 'video'
  23018. && transceiver.recvEncodingParameters
  23019. && edgeVersion < 15019) {
  23020. transceiver.recvEncodingParameters.forEach(function(p) {
  23021. delete p.rtx;
  23022. });
  23023. }
  23024. if (transceiver.recvEncodingParameters.length) {
  23025. params.encodings = transceiver.recvEncodingParameters;
  23026. }
  23027. params.rtcp = {
  23028. compound: transceiver.rtcpParameters.compound
  23029. };
  23030. if (transceiver.rtcpParameters.cname) {
  23031. params.rtcp.cname = transceiver.rtcpParameters.cname;
  23032. }
  23033. if (transceiver.sendEncodingParameters.length) {
  23034. params.rtcp.ssrc = transceiver.sendEncodingParameters[0].ssrc;
  23035. }
  23036. transceiver.rtpReceiver.receive(params);
  23037. }
  23038. };
  23039. RTCPeerConnection.prototype.setLocalDescription = function(description) {
  23040. var pc = this;
  23041. if (!isActionAllowedInSignalingState('setLocalDescription',
  23042. description.type, this.signalingState) || this._isClosed) {
  23043. return Promise.reject(makeError('InvalidStateError',
  23044. 'Can not set local ' + description.type +
  23045. ' in state ' + pc.signalingState));
  23046. }
  23047. var sections;
  23048. var sessionpart;
  23049. if (description.type === 'offer') {
  23050. // VERY limited support for SDP munging. Limited to:
  23051. // * changing the order of codecs
  23052. sections = SDPUtils.splitSections(description.sdp);
  23053. sessionpart = sections.shift();
  23054. sections.forEach(function(mediaSection, sdpMLineIndex) {
  23055. var caps = SDPUtils.parseRtpParameters(mediaSection);
  23056. pc.transceivers[sdpMLineIndex].localCapabilities = caps;
  23057. });
  23058. this.transceivers.forEach(function(transceiver, sdpMLineIndex) {
  23059. pc._gather(transceiver.mid, sdpMLineIndex);
  23060. });
  23061. } else if (description.type === 'answer') {
  23062. sections = SDPUtils.splitSections(pc.remoteDescription.sdp);
  23063. sessionpart = sections.shift();
  23064. var isIceLite = SDPUtils.matchPrefix(sessionpart,
  23065. 'a=ice-lite').length > 0;
  23066. sections.forEach(function(mediaSection, sdpMLineIndex) {
  23067. var transceiver = pc.transceivers[sdpMLineIndex];
  23068. var iceGatherer = transceiver.iceGatherer;
  23069. var iceTransport = transceiver.iceTransport;
  23070. var dtlsTransport = transceiver.dtlsTransport;
  23071. var localCapabilities = transceiver.localCapabilities;
  23072. var remoteCapabilities = transceiver.remoteCapabilities;
  23073. // treat bundle-only as not-rejected.
  23074. var rejected = SDPUtils.isRejected(mediaSection) &&
  23075. SDPUtils.matchPrefix(mediaSection, 'a=bundle-only').length === 0;
  23076. if (!rejected && !transceiver.isDatachannel) {
  23077. var remoteIceParameters = SDPUtils.getIceParameters(
  23078. mediaSection, sessionpart);
  23079. var remoteDtlsParameters = SDPUtils.getDtlsParameters(
  23080. mediaSection, sessionpart);
  23081. if (isIceLite) {
  23082. remoteDtlsParameters.role = 'server';
  23083. }
  23084. if (!pc.usingBundle || sdpMLineIndex === 0) {
  23085. pc._gather(transceiver.mid, sdpMLineIndex);
  23086. if (iceTransport.state === 'new') {
  23087. iceTransport.start(iceGatherer, remoteIceParameters,
  23088. isIceLite ? 'controlling' : 'controlled');
  23089. }
  23090. if (dtlsTransport.state === 'new') {
  23091. dtlsTransport.start(remoteDtlsParameters);
  23092. }
  23093. }
  23094. // Calculate intersection of capabilities.
  23095. var params = getCommonCapabilities(localCapabilities,
  23096. remoteCapabilities);
  23097. // Start the RTCRtpSender. The RTCRtpReceiver for this
  23098. // transceiver has already been started in setRemoteDescription.
  23099. pc._transceive(transceiver,
  23100. params.codecs.length > 0,
  23101. false);
  23102. }
  23103. });
  23104. }
  23105. this.localDescription = {
  23106. type: description.type,
  23107. sdp: description.sdp
  23108. };
  23109. switch (description.type) {
  23110. case 'offer':
  23111. this._updateSignalingState('have-local-offer');
  23112. break;
  23113. case 'answer':
  23114. this._updateSignalingState('stable');
  23115. break;
  23116. default:
  23117. throw new TypeError('unsupported type "' + description.type +
  23118. '"');
  23119. }
  23120. return Promise.resolve();
  23121. };
  23122. RTCPeerConnection.prototype.setRemoteDescription = function(description) {
  23123. var pc = this;
  23124. if (!isActionAllowedInSignalingState('setRemoteDescription',
  23125. description.type, this.signalingState) || this._isClosed) {
  23126. return Promise.reject(makeError('InvalidStateError',
  23127. 'Can not set remote ' + description.type +
  23128. ' in state ' + pc.signalingState));
  23129. }
  23130. var streams = {};
  23131. this.remoteStreams.forEach(function(stream) {
  23132. streams[stream.id] = stream;
  23133. });
  23134. var receiverList = [];
  23135. var sections = SDPUtils.splitSections(description.sdp);
  23136. var sessionpart = sections.shift();
  23137. var isIceLite = SDPUtils.matchPrefix(sessionpart,
  23138. 'a=ice-lite').length > 0;
  23139. var usingBundle = SDPUtils.matchPrefix(sessionpart,
  23140. 'a=group:BUNDLE ').length > 0;
  23141. this.usingBundle = usingBundle;
  23142. var iceOptions = SDPUtils.matchPrefix(sessionpart,
  23143. 'a=ice-options:')[0];
  23144. if (iceOptions) {
  23145. this.canTrickleIceCandidates = iceOptions.substr(14).split(' ')
  23146. .indexOf('trickle') >= 0;
  23147. } else {
  23148. this.canTrickleIceCandidates = false;
  23149. }
  23150. sections.forEach(function(mediaSection, sdpMLineIndex) {
  23151. var lines = SDPUtils.splitLines(mediaSection);
  23152. var kind = SDPUtils.getKind(mediaSection);
  23153. // treat bundle-only as not-rejected.
  23154. var rejected = SDPUtils.isRejected(mediaSection) &&
  23155. SDPUtils.matchPrefix(mediaSection, 'a=bundle-only').length === 0;
  23156. var protocol = lines[0].substr(2).split(' ')[2];
  23157. var direction = SDPUtils.getDirection(mediaSection, sessionpart);
  23158. var remoteMsid = SDPUtils.parseMsid(mediaSection);
  23159. var mid = SDPUtils.getMid(mediaSection) || SDPUtils.generateIdentifier();
  23160. // Reject datachannels which are not implemented yet.
  23161. if (kind === 'application' && protocol === 'DTLS/SCTP') {
  23162. pc.transceivers[sdpMLineIndex] = {
  23163. mid: mid,
  23164. isDatachannel: true
  23165. };
  23166. return;
  23167. }
  23168. var transceiver;
  23169. var iceGatherer;
  23170. var iceTransport;
  23171. var dtlsTransport;
  23172. var rtpReceiver;
  23173. var sendEncodingParameters;
  23174. var recvEncodingParameters;
  23175. var localCapabilities;
  23176. var track;
  23177. // FIXME: ensure the mediaSection has rtcp-mux set.
  23178. var remoteCapabilities = SDPUtils.parseRtpParameters(mediaSection);
  23179. var remoteIceParameters;
  23180. var remoteDtlsParameters;
  23181. if (!rejected) {
  23182. remoteIceParameters = SDPUtils.getIceParameters(mediaSection,
  23183. sessionpart);
  23184. remoteDtlsParameters = SDPUtils.getDtlsParameters(mediaSection,
  23185. sessionpart);
  23186. remoteDtlsParameters.role = 'client';
  23187. }
  23188. recvEncodingParameters =
  23189. SDPUtils.parseRtpEncodingParameters(mediaSection);
  23190. var rtcpParameters = SDPUtils.parseRtcpParameters(mediaSection);
  23191. var isComplete = SDPUtils.matchPrefix(mediaSection,
  23192. 'a=end-of-candidates', sessionpart).length > 0;
  23193. var cands = SDPUtils.matchPrefix(mediaSection, 'a=candidate:')
  23194. .map(function(cand) {
  23195. return SDPUtils.parseCandidate(cand);
  23196. })
  23197. .filter(function(cand) {
  23198. return cand.component === 1;
  23199. });
  23200. // Check if we can use BUNDLE and dispose transports.
  23201. if ((description.type === 'offer' || description.type === 'answer') &&
  23202. !rejected && usingBundle && sdpMLineIndex > 0 &&
  23203. pc.transceivers[sdpMLineIndex]) {
  23204. pc._disposeIceAndDtlsTransports(sdpMLineIndex);
  23205. pc.transceivers[sdpMLineIndex].iceGatherer =
  23206. pc.transceivers[0].iceGatherer;
  23207. pc.transceivers[sdpMLineIndex].iceTransport =
  23208. pc.transceivers[0].iceTransport;
  23209. pc.transceivers[sdpMLineIndex].dtlsTransport =
  23210. pc.transceivers[0].dtlsTransport;
  23211. if (pc.transceivers[sdpMLineIndex].rtpSender) {
  23212. pc.transceivers[sdpMLineIndex].rtpSender.setTransport(
  23213. pc.transceivers[0].dtlsTransport);
  23214. }
  23215. if (pc.transceivers[sdpMLineIndex].rtpReceiver) {
  23216. pc.transceivers[sdpMLineIndex].rtpReceiver.setTransport(
  23217. pc.transceivers[0].dtlsTransport);
  23218. }
  23219. }
  23220. if (description.type === 'offer' && !rejected) {
  23221. transceiver = pc.transceivers[sdpMLineIndex] ||
  23222. pc._createTransceiver(kind);
  23223. transceiver.mid = mid;
  23224. if (!transceiver.iceGatherer) {
  23225. transceiver.iceGatherer = pc._createIceGatherer(sdpMLineIndex,
  23226. usingBundle);
  23227. }
  23228. if (cands.length && transceiver.iceTransport.state === 'new') {
  23229. if (isComplete && (!usingBundle || sdpMLineIndex === 0)) {
  23230. transceiver.iceTransport.setRemoteCandidates(cands);
  23231. } else {
  23232. cands.forEach(function(candidate) {
  23233. maybeAddCandidate(transceiver.iceTransport, candidate);
  23234. });
  23235. }
  23236. }
  23237. localCapabilities = window.RTCRtpReceiver.getCapabilities(kind);
  23238. // filter RTX until additional stuff needed for RTX is implemented
  23239. // in adapter.js
  23240. if (edgeVersion < 15019) {
  23241. localCapabilities.codecs = localCapabilities.codecs.filter(
  23242. function(codec) {
  23243. return codec.name !== 'rtx';
  23244. });
  23245. }
  23246. sendEncodingParameters = transceiver.sendEncodingParameters || [{
  23247. ssrc: (2 * sdpMLineIndex + 2) * 1001
  23248. }];
  23249. // TODO: rewrite to use http://w3c.github.io/webrtc-pc/#set-associated-remote-streams
  23250. var isNewTrack = false;
  23251. if (direction === 'sendrecv' || direction === 'sendonly') {
  23252. isNewTrack = !transceiver.rtpReceiver;
  23253. rtpReceiver = transceiver.rtpReceiver ||
  23254. new window.RTCRtpReceiver(transceiver.dtlsTransport, kind);
  23255. if (isNewTrack) {
  23256. var stream;
  23257. track = rtpReceiver.track;
  23258. // FIXME: does not work with Plan B.
  23259. if (remoteMsid && remoteMsid.stream === '-') {
  23260. // no-op. a stream id of '-' means: no associated stream.
  23261. } else if (remoteMsid) {
  23262. if (!streams[remoteMsid.stream]) {
  23263. streams[remoteMsid.stream] = new window.MediaStream();
  23264. Object.defineProperty(streams[remoteMsid.stream], 'id', {
  23265. get: function() {
  23266. return remoteMsid.stream;
  23267. }
  23268. });
  23269. }
  23270. Object.defineProperty(track, 'id', {
  23271. get: function() {
  23272. return remoteMsid.track;
  23273. }
  23274. });
  23275. stream = streams[remoteMsid.stream];
  23276. } else {
  23277. if (!streams.default) {
  23278. streams.default = new window.MediaStream();
  23279. }
  23280. stream = streams.default;
  23281. }
  23282. if (stream) {
  23283. addTrackToStreamAndFireEvent(track, stream);
  23284. transceiver.associatedRemoteMediaStreams.push(stream);
  23285. }
  23286. receiverList.push([track, rtpReceiver, stream]);
  23287. }
  23288. } else if (transceiver.rtpReceiver && transceiver.rtpReceiver.track) {
  23289. transceiver.associatedRemoteMediaStreams.forEach(function(s) {
  23290. var nativeTrack = s.getTracks().find(function(t) {
  23291. return t.id === transceiver.rtpReceiver.track.id;
  23292. });
  23293. if (nativeTrack) {
  23294. removeTrackFromStreamAndFireEvent(nativeTrack, s);
  23295. }
  23296. });
  23297. transceiver.associatedRemoteMediaStreams = [];
  23298. }
  23299. transceiver.localCapabilities = localCapabilities;
  23300. transceiver.remoteCapabilities = remoteCapabilities;
  23301. transceiver.rtpReceiver = rtpReceiver;
  23302. transceiver.rtcpParameters = rtcpParameters;
  23303. transceiver.sendEncodingParameters = sendEncodingParameters;
  23304. transceiver.recvEncodingParameters = recvEncodingParameters;
  23305. // Start the RTCRtpReceiver now. The RTPSender is started in
  23306. // setLocalDescription.
  23307. pc._transceive(pc.transceivers[sdpMLineIndex],
  23308. false,
  23309. isNewTrack);
  23310. } else if (description.type === 'answer' && !rejected) {
  23311. transceiver = pc.transceivers[sdpMLineIndex];
  23312. iceGatherer = transceiver.iceGatherer;
  23313. iceTransport = transceiver.iceTransport;
  23314. dtlsTransport = transceiver.dtlsTransport;
  23315. rtpReceiver = transceiver.rtpReceiver;
  23316. sendEncodingParameters = transceiver.sendEncodingParameters;
  23317. localCapabilities = transceiver.localCapabilities;
  23318. pc.transceivers[sdpMLineIndex].recvEncodingParameters =
  23319. recvEncodingParameters;
  23320. pc.transceivers[sdpMLineIndex].remoteCapabilities =
  23321. remoteCapabilities;
  23322. pc.transceivers[sdpMLineIndex].rtcpParameters = rtcpParameters;
  23323. if (cands.length && iceTransport.state === 'new') {
  23324. if ((isIceLite || isComplete) &&
  23325. (!usingBundle || sdpMLineIndex === 0)) {
  23326. iceTransport.setRemoteCandidates(cands);
  23327. } else {
  23328. cands.forEach(function(candidate) {
  23329. maybeAddCandidate(transceiver.iceTransport, candidate);
  23330. });
  23331. }
  23332. }
  23333. if (!usingBundle || sdpMLineIndex === 0) {
  23334. if (iceTransport.state === 'new') {
  23335. iceTransport.start(iceGatherer, remoteIceParameters,
  23336. 'controlling');
  23337. }
  23338. if (dtlsTransport.state === 'new') {
  23339. dtlsTransport.start(remoteDtlsParameters);
  23340. }
  23341. }
  23342. pc._transceive(transceiver,
  23343. direction === 'sendrecv' || direction === 'recvonly',
  23344. direction === 'sendrecv' || direction === 'sendonly');
  23345. // TODO: rewrite to use http://w3c.github.io/webrtc-pc/#set-associated-remote-streams
  23346. if (rtpReceiver &&
  23347. (direction === 'sendrecv' || direction === 'sendonly')) {
  23348. track = rtpReceiver.track;
  23349. if (remoteMsid) {
  23350. if (!streams[remoteMsid.stream]) {
  23351. streams[remoteMsid.stream] = new window.MediaStream();
  23352. }
  23353. addTrackToStreamAndFireEvent(track, streams[remoteMsid.stream]);
  23354. receiverList.push([track, rtpReceiver, streams[remoteMsid.stream]]);
  23355. } else {
  23356. if (!streams.default) {
  23357. streams.default = new window.MediaStream();
  23358. }
  23359. addTrackToStreamAndFireEvent(track, streams.default);
  23360. receiverList.push([track, rtpReceiver, streams.default]);
  23361. }
  23362. } else {
  23363. // FIXME: actually the receiver should be created later.
  23364. delete transceiver.rtpReceiver;
  23365. }
  23366. }
  23367. });
  23368. if (this._dtlsRole === undefined) {
  23369. this._dtlsRole = description.type === 'offer' ? 'active' : 'passive';
  23370. }
  23371. this.remoteDescription = {
  23372. type: description.type,
  23373. sdp: description.sdp
  23374. };
  23375. switch (description.type) {
  23376. case 'offer':
  23377. this._updateSignalingState('have-remote-offer');
  23378. break;
  23379. case 'answer':
  23380. this._updateSignalingState('stable');
  23381. break;
  23382. default:
  23383. throw new TypeError('unsupported type "' + description.type +
  23384. '"');
  23385. }
  23386. Object.keys(streams).forEach(function(sid) {
  23387. var stream = streams[sid];
  23388. if (stream.getTracks().length) {
  23389. if (pc.remoteStreams.indexOf(stream) === -1) {
  23390. pc.remoteStreams.push(stream);
  23391. var event = new Event('addstream');
  23392. event.stream = stream;
  23393. window.setTimeout(function() {
  23394. pc._dispatchEvent('addstream', event);
  23395. });
  23396. }
  23397. receiverList.forEach(function(item) {
  23398. var track = item[0];
  23399. var receiver = item[1];
  23400. if (stream.id !== item[2].id) {
  23401. return;
  23402. }
  23403. fireAddTrack(pc, track, receiver, [stream]);
  23404. });
  23405. }
  23406. });
  23407. receiverList.forEach(function(item) {
  23408. if (item[2]) {
  23409. return;
  23410. }
  23411. fireAddTrack(pc, item[0], item[1], []);
  23412. });
  23413. // check whether addIceCandidate({}) was called within four seconds after
  23414. // setRemoteDescription.
  23415. window.setTimeout(function() {
  23416. if (!(pc && pc.transceivers)) {
  23417. return;
  23418. }
  23419. pc.transceivers.forEach(function(transceiver) {
  23420. if (transceiver.iceTransport &&
  23421. transceiver.iceTransport.state === 'new' &&
  23422. transceiver.iceTransport.getRemoteCandidates().length > 0) {
  23423. console.warn('Timeout for addRemoteCandidate. Consider sending ' +
  23424. 'an end-of-candidates notification');
  23425. transceiver.iceTransport.addRemoteCandidate({});
  23426. }
  23427. });
  23428. }, 4000);
  23429. return Promise.resolve();
  23430. };
  23431. RTCPeerConnection.prototype.close = function() {
  23432. this.transceivers.forEach(function(transceiver) {
  23433. /* not yet
  23434. if (transceiver.iceGatherer) {
  23435. transceiver.iceGatherer.close();
  23436. }
  23437. */
  23438. if (transceiver.iceTransport) {
  23439. transceiver.iceTransport.stop();
  23440. }
  23441. if (transceiver.dtlsTransport) {
  23442. transceiver.dtlsTransport.stop();
  23443. }
  23444. if (transceiver.rtpSender) {
  23445. transceiver.rtpSender.stop();
  23446. }
  23447. if (transceiver.rtpReceiver) {
  23448. transceiver.rtpReceiver.stop();
  23449. }
  23450. });
  23451. // FIXME: clean up tracks, local streams, remote streams, etc
  23452. this._isClosed = true;
  23453. this._updateSignalingState('closed');
  23454. };
  23455. // Update the signaling state.
  23456. RTCPeerConnection.prototype._updateSignalingState = function(newState) {
  23457. this.signalingState = newState;
  23458. var event = new Event('signalingstatechange');
  23459. this._dispatchEvent('signalingstatechange', event);
  23460. };
  23461. // Determine whether to fire the negotiationneeded event.
  23462. RTCPeerConnection.prototype._maybeFireNegotiationNeeded = function() {
  23463. var pc = this;
  23464. if (this.signalingState !== 'stable' || this.needNegotiation === true) {
  23465. return;
  23466. }
  23467. this.needNegotiation = true;
  23468. window.setTimeout(function() {
  23469. if (pc.needNegotiation === false) {
  23470. return;
  23471. }
  23472. pc.needNegotiation = false;
  23473. var event = new Event('negotiationneeded');
  23474. pc._dispatchEvent('negotiationneeded', event);
  23475. }, 0);
  23476. };
  23477. // Update the connection state.
  23478. RTCPeerConnection.prototype._updateConnectionState = function() {
  23479. var newState;
  23480. var states = {
  23481. 'new': 0,
  23482. closed: 0,
  23483. connecting: 0,
  23484. checking: 0,
  23485. connected: 0,
  23486. completed: 0,
  23487. disconnected: 0,
  23488. failed: 0
  23489. };
  23490. this.transceivers.forEach(function(transceiver) {
  23491. states[transceiver.iceTransport.state]++;
  23492. states[transceiver.dtlsTransport.state]++;
  23493. });
  23494. // ICETransport.completed and connected are the same for this purpose.
  23495. states.connected += states.completed;
  23496. newState = 'new';
  23497. if (states.failed > 0) {
  23498. newState = 'failed';
  23499. } else if (states.connecting > 0 || states.checking > 0) {
  23500. newState = 'connecting';
  23501. } else if (states.disconnected > 0) {
  23502. newState = 'disconnected';
  23503. } else if (states.new > 0) {
  23504. newState = 'new';
  23505. } else if (states.connected > 0 || states.completed > 0) {
  23506. newState = 'connected';
  23507. }
  23508. if (newState !== this.iceConnectionState) {
  23509. this.iceConnectionState = newState;
  23510. var event = new Event('iceconnectionstatechange');
  23511. this._dispatchEvent('iceconnectionstatechange', event);
  23512. }
  23513. };
  23514. RTCPeerConnection.prototype.createOffer = function() {
  23515. var pc = this;
  23516. if (this._isClosed) {
  23517. return Promise.reject(makeError('InvalidStateError',
  23518. 'Can not call createOffer after close'));
  23519. }
  23520. var numAudioTracks = this.transceivers.filter(function(t) {
  23521. return t.kind === 'audio';
  23522. }).length;
  23523. var numVideoTracks = this.transceivers.filter(function(t) {
  23524. return t.kind === 'video';
  23525. }).length;
  23526. // Determine number of audio and video tracks we need to send/recv.
  23527. var offerOptions = arguments[0];
  23528. if (offerOptions) {
  23529. // Reject Chrome legacy constraints.
  23530. if (offerOptions.mandatory || offerOptions.optional) {
  23531. throw new TypeError(
  23532. 'Legacy mandatory/optional constraints not supported.');
  23533. }
  23534. if (offerOptions.offerToReceiveAudio !== undefined) {
  23535. if (offerOptions.offerToReceiveAudio === true) {
  23536. numAudioTracks = 1;
  23537. } else if (offerOptions.offerToReceiveAudio === false) {
  23538. numAudioTracks = 0;
  23539. } else {
  23540. numAudioTracks = offerOptions.offerToReceiveAudio;
  23541. }
  23542. }
  23543. if (offerOptions.offerToReceiveVideo !== undefined) {
  23544. if (offerOptions.offerToReceiveVideo === true) {
  23545. numVideoTracks = 1;
  23546. } else if (offerOptions.offerToReceiveVideo === false) {
  23547. numVideoTracks = 0;
  23548. } else {
  23549. numVideoTracks = offerOptions.offerToReceiveVideo;
  23550. }
  23551. }
  23552. }
  23553. this.transceivers.forEach(function(transceiver) {
  23554. if (transceiver.kind === 'audio') {
  23555. numAudioTracks--;
  23556. if (numAudioTracks < 0) {
  23557. transceiver.wantReceive = false;
  23558. }
  23559. } else if (transceiver.kind === 'video') {
  23560. numVideoTracks--;
  23561. if (numVideoTracks < 0) {
  23562. transceiver.wantReceive = false;
  23563. }
  23564. }
  23565. });
  23566. // Create M-lines for recvonly streams.
  23567. while (numAudioTracks > 0 || numVideoTracks > 0) {
  23568. if (numAudioTracks > 0) {
  23569. this._createTransceiver('audio');
  23570. numAudioTracks--;
  23571. }
  23572. if (numVideoTracks > 0) {
  23573. this._createTransceiver('video');
  23574. numVideoTracks--;
  23575. }
  23576. }
  23577. var sdp = SDPUtils.writeSessionBoilerplate(this._sdpSessionId,
  23578. this._sdpSessionVersion++);
  23579. this.transceivers.forEach(function(transceiver, sdpMLineIndex) {
  23580. // For each track, create an ice gatherer, ice transport,
  23581. // dtls transport, potentially rtpsender and rtpreceiver.
  23582. var track = transceiver.track;
  23583. var kind = transceiver.kind;
  23584. var mid = SDPUtils.generateIdentifier();
  23585. transceiver.mid = mid;
  23586. if (!transceiver.iceGatherer) {
  23587. transceiver.iceGatherer = pc._createIceGatherer(sdpMLineIndex,
  23588. pc.usingBundle);
  23589. }
  23590. var localCapabilities = window.RTCRtpSender.getCapabilities(kind);
  23591. // filter RTX until additional stuff needed for RTX is implemented
  23592. // in adapter.js
  23593. if (edgeVersion < 15019) {
  23594. localCapabilities.codecs = localCapabilities.codecs.filter(
  23595. function(codec) {
  23596. return codec.name !== 'rtx';
  23597. });
  23598. }
  23599. localCapabilities.codecs.forEach(function(codec) {
  23600. // work around https://bugs.chromium.org/p/webrtc/issues/detail?id=6552
  23601. // by adding level-asymmetry-allowed=1
  23602. if (codec.name === 'H264' &&
  23603. codec.parameters['level-asymmetry-allowed'] === undefined) {
  23604. codec.parameters['level-asymmetry-allowed'] = '1';
  23605. }
  23606. });
  23607. // generate an ssrc now, to be used later in rtpSender.send
  23608. var sendEncodingParameters = transceiver.sendEncodingParameters || [{
  23609. ssrc: (2 * sdpMLineIndex + 1) * 1001
  23610. }];
  23611. if (track) {
  23612. // add RTX
  23613. if (edgeVersion >= 15019 && kind === 'video' &&
  23614. !sendEncodingParameters[0].rtx) {
  23615. sendEncodingParameters[0].rtx = {
  23616. ssrc: sendEncodingParameters[0].ssrc + 1
  23617. };
  23618. }
  23619. }
  23620. if (transceiver.wantReceive) {
  23621. transceiver.rtpReceiver = new window.RTCRtpReceiver(
  23622. transceiver.dtlsTransport, kind);
  23623. }
  23624. transceiver.localCapabilities = localCapabilities;
  23625. transceiver.sendEncodingParameters = sendEncodingParameters;
  23626. });
  23627. // always offer BUNDLE and dispose on return if not supported.
  23628. if (this._config.bundlePolicy !== 'max-compat') {
  23629. sdp += 'a=group:BUNDLE ' + this.transceivers.map(function(t) {
  23630. return t.mid;
  23631. }).join(' ') + '\r\n';
  23632. }
  23633. sdp += 'a=ice-options:trickle\r\n';
  23634. this.transceivers.forEach(function(transceiver, sdpMLineIndex) {
  23635. sdp += writeMediaSection(transceiver, transceiver.localCapabilities,
  23636. 'offer', transceiver.stream, pc._dtlsRole);
  23637. sdp += 'a=rtcp-rsize\r\n';
  23638. if (transceiver.iceGatherer && pc.iceGatheringState !== 'new' &&
  23639. (sdpMLineIndex === 0 || !pc.usingBundle)) {
  23640. transceiver.iceGatherer.getLocalCandidates().forEach(function(cand) {
  23641. cand.component = 1;
  23642. sdp += 'a=' + SDPUtils.writeCandidate(cand) + '\r\n';
  23643. });
  23644. if (transceiver.iceGatherer.state === 'completed') {
  23645. sdp += 'a=end-of-candidates\r\n';
  23646. }
  23647. }
  23648. });
  23649. var desc = new window.RTCSessionDescription({
  23650. type: 'offer',
  23651. sdp: sdp
  23652. });
  23653. return Promise.resolve(desc);
  23654. };
  23655. RTCPeerConnection.prototype.createAnswer = function() {
  23656. var pc = this;
  23657. if (this._isClosed) {
  23658. return Promise.reject(makeError('InvalidStateError',
  23659. 'Can not call createAnswer after close'));
  23660. }
  23661. var sdp = SDPUtils.writeSessionBoilerplate(this._sdpSessionId,
  23662. this._sdpSessionVersion++);
  23663. if (this.usingBundle) {
  23664. sdp += 'a=group:BUNDLE ' + this.transceivers.map(function(t) {
  23665. return t.mid;
  23666. }).join(' ') + '\r\n';
  23667. }
  23668. var mediaSectionsInOffer = SDPUtils.splitSections(
  23669. this.remoteDescription.sdp).length - 1;
  23670. this.transceivers.forEach(function(transceiver, sdpMLineIndex) {
  23671. if (sdpMLineIndex + 1 > mediaSectionsInOffer) {
  23672. return;
  23673. }
  23674. if (transceiver.isDatachannel) {
  23675. sdp += 'm=application 0 DTLS/SCTP 5000\r\n' +
  23676. 'c=IN IP4 0.0.0.0\r\n' +
  23677. 'a=mid:' + transceiver.mid + '\r\n';
  23678. return;
  23679. }
  23680. // FIXME: look at direction.
  23681. if (transceiver.stream) {
  23682. var localTrack;
  23683. if (transceiver.kind === 'audio') {
  23684. localTrack = transceiver.stream.getAudioTracks()[0];
  23685. } else if (transceiver.kind === 'video') {
  23686. localTrack = transceiver.stream.getVideoTracks()[0];
  23687. }
  23688. if (localTrack) {
  23689. // add RTX
  23690. if (edgeVersion >= 15019 && transceiver.kind === 'video' &&
  23691. !transceiver.sendEncodingParameters[0].rtx) {
  23692. transceiver.sendEncodingParameters[0].rtx = {
  23693. ssrc: transceiver.sendEncodingParameters[0].ssrc + 1
  23694. };
  23695. }
  23696. }
  23697. }
  23698. // Calculate intersection of capabilities.
  23699. var commonCapabilities = getCommonCapabilities(
  23700. transceiver.localCapabilities,
  23701. transceiver.remoteCapabilities);
  23702. var hasRtx = commonCapabilities.codecs.filter(function(c) {
  23703. return c.name.toLowerCase() === 'rtx';
  23704. }).length;
  23705. if (!hasRtx && transceiver.sendEncodingParameters[0].rtx) {
  23706. delete transceiver.sendEncodingParameters[0].rtx;
  23707. }
  23708. sdp += writeMediaSection(transceiver, commonCapabilities,
  23709. 'answer', transceiver.stream, pc._dtlsRole);
  23710. if (transceiver.rtcpParameters &&
  23711. transceiver.rtcpParameters.reducedSize) {
  23712. sdp += 'a=rtcp-rsize\r\n';
  23713. }
  23714. });
  23715. var desc = new window.RTCSessionDescription({
  23716. type: 'answer',
  23717. sdp: sdp
  23718. });
  23719. return Promise.resolve(desc);
  23720. };
  23721. RTCPeerConnection.prototype.addIceCandidate = function(candidate) {
  23722. var sections;
  23723. if (!candidate || candidate.candidate === '') {
  23724. for (var j = 0; j < this.transceivers.length; j++) {
  23725. if (this.transceivers[j].isDatachannel) {
  23726. continue;
  23727. }
  23728. this.transceivers[j].iceTransport.addRemoteCandidate({});
  23729. sections = SDPUtils.splitSections(this.remoteDescription.sdp);
  23730. sections[j + 1] += 'a=end-of-candidates\r\n';
  23731. this.remoteDescription.sdp = sections.join('');
  23732. if (this.usingBundle) {
  23733. break;
  23734. }
  23735. }
  23736. } else if (!(candidate.sdpMLineIndex !== undefined || candidate.sdpMid)) {
  23737. throw new TypeError('sdpMLineIndex or sdpMid required');
  23738. } else if (!this.remoteDescription) {
  23739. return Promise.reject(makeError('InvalidStateError',
  23740. 'Can not add ICE candidate without a remote description'));
  23741. } else {
  23742. var sdpMLineIndex = candidate.sdpMLineIndex;
  23743. if (candidate.sdpMid) {
  23744. for (var i = 0; i < this.transceivers.length; i++) {
  23745. if (this.transceivers[i].mid === candidate.sdpMid) {
  23746. sdpMLineIndex = i;
  23747. break;
  23748. }
  23749. }
  23750. }
  23751. var transceiver = this.transceivers[sdpMLineIndex];
  23752. if (transceiver) {
  23753. if (transceiver.isDatachannel) {
  23754. return Promise.resolve();
  23755. }
  23756. var cand = Object.keys(candidate.candidate).length > 0 ?
  23757. SDPUtils.parseCandidate(candidate.candidate) : {};
  23758. // Ignore Chrome's invalid candidates since Edge does not like them.
  23759. if (cand.protocol === 'tcp' && (cand.port === 0 || cand.port === 9)) {
  23760. return Promise.resolve();
  23761. }
  23762. // Ignore RTCP candidates, we assume RTCP-MUX.
  23763. if (cand.component && cand.component !== 1) {
  23764. return Promise.resolve();
  23765. }
  23766. // when using bundle, avoid adding candidates to the wrong
  23767. // ice transport. And avoid adding candidates added in the SDP.
  23768. if (sdpMLineIndex === 0 || (sdpMLineIndex > 0 &&
  23769. transceiver.iceTransport !== this.transceivers[0].iceTransport)) {
  23770. if (!maybeAddCandidate(transceiver.iceTransport, cand)) {
  23771. return Promise.reject(makeError('OperationError',
  23772. 'Can not add ICE candidate'));
  23773. }
  23774. }
  23775. // update the remoteDescription.
  23776. var candidateString = candidate.candidate.trim();
  23777. if (candidateString.indexOf('a=') === 0) {
  23778. candidateString = candidateString.substr(2);
  23779. }
  23780. sections = SDPUtils.splitSections(this.remoteDescription.sdp);
  23781. sections[sdpMLineIndex + 1] += 'a=' +
  23782. (cand.type ? candidateString : 'end-of-candidates')
  23783. + '\r\n';
  23784. this.remoteDescription.sdp = sections.join('');
  23785. } else {
  23786. return Promise.reject(makeError('OperationError',
  23787. 'Can not add ICE candidate'));
  23788. }
  23789. }
  23790. return Promise.resolve();
  23791. };
  23792. RTCPeerConnection.prototype.getStats = function() {
  23793. var promises = [];
  23794. this.transceivers.forEach(function(transceiver) {
  23795. ['rtpSender', 'rtpReceiver', 'iceGatherer', 'iceTransport',
  23796. 'dtlsTransport'].forEach(function(method) {
  23797. if (transceiver[method]) {
  23798. promises.push(transceiver[method].getStats());
  23799. }
  23800. });
  23801. });
  23802. var fixStatsType = function(stat) {
  23803. return {
  23804. inboundrtp: 'inbound-rtp',
  23805. outboundrtp: 'outbound-rtp',
  23806. candidatepair: 'candidate-pair',
  23807. localcandidate: 'local-candidate',
  23808. remotecandidate: 'remote-candidate'
  23809. }[stat.type] || stat.type;
  23810. };
  23811. return new Promise(function(resolve) {
  23812. // shim getStats with maplike support
  23813. var results = new Map();
  23814. Promise.all(promises).then(function(res) {
  23815. res.forEach(function(result) {
  23816. Object.keys(result).forEach(function(id) {
  23817. result[id].type = fixStatsType(result[id]);
  23818. results.set(id, result[id]);
  23819. });
  23820. });
  23821. resolve(results);
  23822. });
  23823. });
  23824. };
  23825. // legacy callback shims. Should be moved to adapter.js some days.
  23826. var methods = ['createOffer', 'createAnswer'];
  23827. methods.forEach(function(method) {
  23828. var nativeMethod = RTCPeerConnection.prototype[method];
  23829. RTCPeerConnection.prototype[method] = function() {
  23830. var args = arguments;
  23831. if (typeof args[0] === 'function' ||
  23832. typeof args[1] === 'function') { // legacy
  23833. return nativeMethod.apply(this, [arguments[2]])
  23834. .then(function(description) {
  23835. if (typeof args[0] === 'function') {
  23836. args[0].apply(null, [description]);
  23837. }
  23838. }, function(error) {
  23839. if (typeof args[1] === 'function') {
  23840. args[1].apply(null, [error]);
  23841. }
  23842. });
  23843. }
  23844. return nativeMethod.apply(this, arguments);
  23845. };
  23846. });
  23847. methods = ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate'];
  23848. methods.forEach(function(method) {
  23849. var nativeMethod = RTCPeerConnection.prototype[method];
  23850. RTCPeerConnection.prototype[method] = function() {
  23851. var args = arguments;
  23852. if (typeof args[1] === 'function' ||
  23853. typeof args[2] === 'function') { // legacy
  23854. return nativeMethod.apply(this, arguments)
  23855. .then(function() {
  23856. if (typeof args[1] === 'function') {
  23857. args[1].apply(null);
  23858. }
  23859. }, function(error) {
  23860. if (typeof args[2] === 'function') {
  23861. args[2].apply(null, [error]);
  23862. }
  23863. });
  23864. }
  23865. return nativeMethod.apply(this, arguments);
  23866. };
  23867. });
  23868. // getStats is special. It doesn't have a spec legacy method yet we support
  23869. // getStats(something, cb) without error callbacks.
  23870. ['getStats'].forEach(function(method) {
  23871. var nativeMethod = RTCPeerConnection.prototype[method];
  23872. RTCPeerConnection.prototype[method] = function() {
  23873. var args = arguments;
  23874. if (typeof args[1] === 'function') {
  23875. return nativeMethod.apply(this, arguments)
  23876. .then(function() {
  23877. if (typeof args[1] === 'function') {
  23878. args[1].apply(null);
  23879. }
  23880. });
  23881. }
  23882. return nativeMethod.apply(this, arguments);
  23883. };
  23884. });
  23885. return RTCPeerConnection;
  23886. };
  23887. },{"sdp":39}],35:[function(require,module,exports){
  23888. var grammar = module.exports = {
  23889. v: [{
  23890. name: 'version',
  23891. reg: /^(\d*)$/
  23892. }],
  23893. o: [{ //o=- 20518 0 IN IP4 203.0.113.1
  23894. // NB: sessionId will be a String in most cases because it is huge
  23895. name: 'origin',
  23896. reg: /^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,
  23897. names: ['username', 'sessionId', 'sessionVersion', 'netType', 'ipVer', 'address'],
  23898. format: '%s %s %d %s IP%d %s'
  23899. }],
  23900. // default parsing of these only (though some of these feel outdated)
  23901. s: [{ name: 'name' }],
  23902. i: [{ name: 'description' }],
  23903. u: [{ name: 'uri' }],
  23904. e: [{ name: 'email' }],
  23905. p: [{ name: 'phone' }],
  23906. z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly..
  23907. r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly
  23908. //k: [{}], // outdated thing ignored
  23909. t: [{ //t=0 0
  23910. name: 'timing',
  23911. reg: /^(\d*) (\d*)/,
  23912. names: ['start', 'stop'],
  23913. format: '%d %d'
  23914. }],
  23915. c: [{ //c=IN IP4 10.47.197.26
  23916. name: 'connection',
  23917. reg: /^IN IP(\d) (\S*)/,
  23918. names: ['version', 'ip'],
  23919. format: 'IN IP%d %s'
  23920. }],
  23921. b: [{ //b=AS:4000
  23922. push: 'bandwidth',
  23923. reg: /^(TIAS|AS|CT|RR|RS):(\d*)/,
  23924. names: ['type', 'limit'],
  23925. format: '%s:%s'
  23926. }],
  23927. m: [{ //m=video 51744 RTP/AVP 126 97 98 34 31
  23928. // NB: special - pushes to session
  23929. // TODO: rtp/fmtp should be filtered by the payloads found here?
  23930. reg: /^(\w*) (\d*) ([\w\/]*)(?: (.*))?/,
  23931. names: ['type', 'port', 'protocol', 'payloads'],
  23932. format: '%s %d %s %s'
  23933. }],
  23934. a: [
  23935. { //a=rtpmap:110 opus/48000/2
  23936. push: 'rtp',
  23937. reg: /^rtpmap:(\d*) ([\w\-\.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,
  23938. names: ['payload', 'codec', 'rate', 'encoding'],
  23939. format: function (o) {
  23940. return (o.encoding) ?
  23941. 'rtpmap:%d %s/%s/%s':
  23942. o.rate ?
  23943. 'rtpmap:%d %s/%s':
  23944. 'rtpmap:%d %s';
  23945. }
  23946. },
  23947. { //a=fmtp:108 profile-level-id=24;object=23;bitrate=64000
  23948. //a=fmtp:111 minptime=10; useinbandfec=1
  23949. push: 'fmtp',
  23950. reg: /^fmtp:(\d*) ([\S| ]*)/,
  23951. names: ['payload', 'config'],
  23952. format: 'fmtp:%d %s'
  23953. },
  23954. { //a=control:streamid=0
  23955. name: 'control',
  23956. reg: /^control:(.*)/,
  23957. format: 'control:%s'
  23958. },
  23959. { //a=rtcp:65179 IN IP4 193.84.77.194
  23960. name: 'rtcp',
  23961. reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,
  23962. names: ['port', 'netType', 'ipVer', 'address'],
  23963. format: function (o) {
  23964. return (o.address != null) ?
  23965. 'rtcp:%d %s IP%d %s':
  23966. 'rtcp:%d';
  23967. }
  23968. },
  23969. { //a=rtcp-fb:98 trr-int 100
  23970. push: 'rtcpFbTrrInt',
  23971. reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/,
  23972. names: ['payload', 'value'],
  23973. format: 'rtcp-fb:%d trr-int %d'
  23974. },
  23975. { //a=rtcp-fb:98 nack rpsi
  23976. push: 'rtcpFb',
  23977. reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,
  23978. names: ['payload', 'type', 'subtype'],
  23979. format: function (o) {
  23980. return (o.subtype != null) ?
  23981. 'rtcp-fb:%s %s %s':
  23982. 'rtcp-fb:%s %s';
  23983. }
  23984. },
  23985. { //a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  23986. //a=extmap:1/recvonly URI-gps-string
  23987. push: 'ext',
  23988. reg: /^extmap:(\d+)(?:\/(\w+))? (\S*)(?: (\S*))?/,
  23989. names: ['value', 'direction', 'uri', 'config'],
  23990. format: function (o) {
  23991. return 'extmap:%d' + (o.direction ? '/%s' : '%v') + ' %s' + (o.config ? ' %s' : '');
  23992. }
  23993. },
  23994. { //a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32
  23995. push: 'crypto',
  23996. reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,
  23997. names: ['id', 'suite', 'config', 'sessionConfig'],
  23998. format: function (o) {
  23999. return (o.sessionConfig != null) ?
  24000. 'crypto:%d %s %s %s':
  24001. 'crypto:%d %s %s';
  24002. }
  24003. },
  24004. { //a=setup:actpass
  24005. name: 'setup',
  24006. reg: /^setup:(\w*)/,
  24007. format: 'setup:%s'
  24008. },
  24009. { //a=mid:1
  24010. name: 'mid',
  24011. reg: /^mid:([^\s]*)/,
  24012. format: 'mid:%s'
  24013. },
  24014. { //a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a
  24015. name: 'msid',
  24016. reg: /^msid:(.*)/,
  24017. format: 'msid:%s'
  24018. },
  24019. { //a=ptime:20
  24020. name: 'ptime',
  24021. reg: /^ptime:(\d*)/,
  24022. format: 'ptime:%d'
  24023. },
  24024. { //a=maxptime:60
  24025. name: 'maxptime',
  24026. reg: /^maxptime:(\d*)/,
  24027. format: 'maxptime:%d'
  24028. },
  24029. { //a=sendrecv
  24030. name: 'direction',
  24031. reg: /^(sendrecv|recvonly|sendonly|inactive)/
  24032. },
  24033. { //a=ice-lite
  24034. name: 'icelite',
  24035. reg: /^(ice-lite)/
  24036. },
  24037. { //a=ice-ufrag:F7gI
  24038. name: 'iceUfrag',
  24039. reg: /^ice-ufrag:(\S*)/,
  24040. format: 'ice-ufrag:%s'
  24041. },
  24042. { //a=ice-pwd:x9cml/YzichV2+XlhiMu8g
  24043. name: 'icePwd',
  24044. reg: /^ice-pwd:(\S*)/,
  24045. format: 'ice-pwd:%s'
  24046. },
  24047. { //a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
  24048. name: 'fingerprint',
  24049. reg: /^fingerprint:(\S*) (\S*)/,
  24050. names: ['type', 'hash'],
  24051. format: 'fingerprint:%s %s'
  24052. },
  24053. { //a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
  24054. //a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10
  24055. //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
  24056. //a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10
  24057. //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
  24058. push:'candidates',
  24059. reg: /^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,
  24060. names: ['foundation', 'component', 'transport', 'priority', 'ip', 'port', 'type', 'raddr', 'rport', 'tcptype', 'generation', 'network-id', 'network-cost'],
  24061. format: function (o) {
  24062. var str = 'candidate:%s %d %s %d %s %d typ %s';
  24063. str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v';
  24064. // NB: candidate has three optional chunks, so %void middles one if it's missing
  24065. str += (o.tcptype != null) ? ' tcptype %s' : '%v';
  24066. if (o.generation != null) {
  24067. str += ' generation %d';
  24068. }
  24069. str += (o['network-id'] != null) ? ' network-id %d' : '%v';
  24070. str += (o['network-cost'] != null) ? ' network-cost %d' : '%v';
  24071. return str;
  24072. }
  24073. },
  24074. { //a=end-of-candidates (keep after the candidates line for readability)
  24075. name: 'endOfCandidates',
  24076. reg: /^(end-of-candidates)/
  24077. },
  24078. { //a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ...
  24079. name: 'remoteCandidates',
  24080. reg: /^remote-candidates:(.*)/,
  24081. format: 'remote-candidates:%s'
  24082. },
  24083. { //a=ice-options:google-ice
  24084. name: 'iceOptions',
  24085. reg: /^ice-options:(\S*)/,
  24086. format: 'ice-options:%s'
  24087. },
  24088. { //a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1
  24089. push: 'ssrcs',
  24090. reg: /^ssrc:(\d*) ([\w_]*)(?::(.*))?/,
  24091. names: ['id', 'attribute', 'value'],
  24092. format: function (o) {
  24093. var str = 'ssrc:%d';
  24094. if (o.attribute != null) {
  24095. str += ' %s';
  24096. if (o.value != null) {
  24097. str += ':%s';
  24098. }
  24099. }
  24100. return str;
  24101. }
  24102. },
  24103. { //a=ssrc-group:FEC 1 2
  24104. //a=ssrc-group:FEC-FR 3004364195 1080772241
  24105. push: 'ssrcGroups',
  24106. // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E
  24107. reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,
  24108. names: ['semantics', 'ssrcs'],
  24109. format: 'ssrc-group:%s %s'
  24110. },
  24111. { //a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV
  24112. name: 'msidSemantic',
  24113. reg: /^msid-semantic:\s?(\w*) (\S*)/,
  24114. names: ['semantic', 'token'],
  24115. format: 'msid-semantic: %s %s' // space after ':' is not accidental
  24116. },
  24117. { //a=group:BUNDLE audio video
  24118. push: 'groups',
  24119. reg: /^group:(\w*) (.*)/,
  24120. names: ['type', 'mids'],
  24121. format: 'group:%s %s'
  24122. },
  24123. { //a=rtcp-mux
  24124. name: 'rtcpMux',
  24125. reg: /^(rtcp-mux)/
  24126. },
  24127. { //a=rtcp-rsize
  24128. name: 'rtcpRsize',
  24129. reg: /^(rtcp-rsize)/
  24130. },
  24131. { //a=sctpmap:5000 webrtc-datachannel 1024
  24132. name: 'sctpmap',
  24133. reg: /^sctpmap:([\w_\/]*) (\S*)(?: (\S*))?/,
  24134. names: ['sctpmapNumber', 'app', 'maxMessageSize'],
  24135. format: function (o) {
  24136. return (o.maxMessageSize != null) ?
  24137. 'sctpmap:%s %s %s' :
  24138. 'sctpmap:%s %s';
  24139. }
  24140. },
  24141. { //a=x-google-flag:conference
  24142. name: 'xGoogleFlag',
  24143. reg: /^x-google-flag:([^\s]*)/,
  24144. format: 'x-google-flag:%s'
  24145. },
  24146. { //a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0
  24147. push: 'rids',
  24148. reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,
  24149. names: ['id', 'direction', 'params'],
  24150. format: function (o) {
  24151. return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s';
  24152. }
  24153. },
  24154. { //a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250]
  24155. //a=imageattr:* send [x=800,y=640] recv *
  24156. //a=imageattr:100 recv [x=320,y=240]
  24157. push: 'imageattrs',
  24158. reg: new RegExp(
  24159. //a=imageattr:97
  24160. '^imageattr:(\\d+|\\*)' +
  24161. //send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320]
  24162. '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' +
  24163. //recv [x=330,y=250]
  24164. '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?'
  24165. ),
  24166. names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'],
  24167. format: function (o) {
  24168. return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : '');
  24169. }
  24170. },
  24171. { //a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8
  24172. //a=simulcast:recv 1;4,5 send 6;7
  24173. name: 'simulcast',
  24174. reg: new RegExp(
  24175. //a=simulcast:
  24176. '^simulcast:' +
  24177. //send 1,2,3;~4,~5
  24178. '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' +
  24179. //space + recv 6;~7,~8
  24180. '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' +
  24181. //end
  24182. '$'
  24183. ),
  24184. names: ['dir1', 'list1', 'dir2', 'list2'],
  24185. format: function (o) {
  24186. return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : '');
  24187. }
  24188. },
  24189. { //Old simulcast draft 03 (implemented by Firefox)
  24190. // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03
  24191. //a=simulcast: recv pt=97;98 send pt=97
  24192. //a=simulcast: send rid=5;6;7 paused=6,7
  24193. name: 'simulcast_03',
  24194. reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/,
  24195. names: ['value'],
  24196. format: 'simulcast: %s'
  24197. },
  24198. {
  24199. //a=framerate:25
  24200. //a=framerate:29.97
  24201. name: 'framerate',
  24202. reg: /^framerate:(\d+(?:$|\.\d+))/,
  24203. format: 'framerate:%s'
  24204. },
  24205. { // any a= that we don't understand is kepts verbatim on media.invalid
  24206. push: 'invalid',
  24207. names: ['value']
  24208. }
  24209. ]
  24210. };
  24211. // set sensible defaults to avoid polluting the grammar with boring details
  24212. Object.keys(grammar).forEach(function (key) {
  24213. var objs = grammar[key];
  24214. objs.forEach(function (obj) {
  24215. if (!obj.reg) {
  24216. obj.reg = /(.*)/;
  24217. }
  24218. if (!obj.format) {
  24219. obj.format = '%s';
  24220. }
  24221. });
  24222. });
  24223. },{}],36:[function(require,module,exports){
  24224. var parser = require('./parser');
  24225. var writer = require('./writer');
  24226. exports.write = writer;
  24227. exports.parse = parser.parse;
  24228. exports.parseFmtpConfig = parser.parseFmtpConfig;
  24229. exports.parseParams = parser.parseParams;
  24230. exports.parsePayloads = parser.parsePayloads;
  24231. exports.parseRemoteCandidates = parser.parseRemoteCandidates;
  24232. exports.parseImageAttributes = parser.parseImageAttributes;
  24233. exports.parseSimulcastStreamList = parser.parseSimulcastStreamList;
  24234. },{"./parser":37,"./writer":38}],37:[function(require,module,exports){
  24235. var toIntIfInt = function (v) {
  24236. return String(Number(v)) === v ? Number(v) : v;
  24237. };
  24238. var attachProperties = function (match, location, names, rawName) {
  24239. if (rawName && !names) {
  24240. location[rawName] = toIntIfInt(match[1]);
  24241. }
  24242. else {
  24243. for (var i = 0; i < names.length; i += 1) {
  24244. if (match[i+1] != null) {
  24245. location[names[i]] = toIntIfInt(match[i+1]);
  24246. }
  24247. }
  24248. }
  24249. };
  24250. var parseReg = function (obj, location, content) {
  24251. var needsBlank = obj.name && obj.names;
  24252. if (obj.push && !location[obj.push]) {
  24253. location[obj.push] = [];
  24254. }
  24255. else if (needsBlank && !location[obj.name]) {
  24256. location[obj.name] = {};
  24257. }
  24258. var keyLocation = obj.push ?
  24259. {} : // blank object that will be pushed
  24260. needsBlank ? location[obj.name] : location; // otherwise, named location or root
  24261. attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name);
  24262. if (obj.push) {
  24263. location[obj.push].push(keyLocation);
  24264. }
  24265. };
  24266. var grammar = require('./grammar');
  24267. var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/);
  24268. exports.parse = function (sdp) {
  24269. var session = {}
  24270. , media = []
  24271. , location = session; // points at where properties go under (one of the above)
  24272. // parse lines we understand
  24273. sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) {
  24274. var type = l[0];
  24275. var content = l.slice(2);
  24276. if (type === 'm') {
  24277. media.push({rtp: [], fmtp: []});
  24278. location = media[media.length-1]; // point at latest media line
  24279. }
  24280. for (var j = 0; j < (grammar[type] || []).length; j += 1) {
  24281. var obj = grammar[type][j];
  24282. if (obj.reg.test(content)) {
  24283. return parseReg(obj, location, content);
  24284. }
  24285. }
  24286. });
  24287. session.media = media; // link it up
  24288. return session;
  24289. };
  24290. var paramReducer = function (acc, expr) {
  24291. var s = expr.split(/=(.+)/, 2);
  24292. if (s.length === 2) {
  24293. acc[s[0]] = toIntIfInt(s[1]);
  24294. }
  24295. return acc;
  24296. };
  24297. exports.parseParams = function (str) {
  24298. return str.split(/\;\s?/).reduce(paramReducer, {});
  24299. };
  24300. // For backward compatibility - alias will be removed in 3.0.0
  24301. exports.parseFmtpConfig = exports.parseParams;
  24302. exports.parsePayloads = function (str) {
  24303. return str.split(' ').map(Number);
  24304. };
  24305. exports.parseRemoteCandidates = function (str) {
  24306. var candidates = [];
  24307. var parts = str.split(' ').map(toIntIfInt);
  24308. for (var i = 0; i < parts.length; i += 3) {
  24309. candidates.push({
  24310. component: parts[i],
  24311. ip: parts[i + 1],
  24312. port: parts[i + 2]
  24313. });
  24314. }
  24315. return candidates;
  24316. };
  24317. exports.parseImageAttributes = function (str) {
  24318. return str.split(' ').map(function (item) {
  24319. return item.substring(1, item.length-1).split(',').reduce(paramReducer, {});
  24320. });
  24321. };
  24322. exports.parseSimulcastStreamList = function (str) {
  24323. return str.split(';').map(function (stream) {
  24324. return stream.split(',').map(function (format) {
  24325. var scid, paused = false;
  24326. if (format[0] !== '~') {
  24327. scid = toIntIfInt(format);
  24328. } else {
  24329. scid = toIntIfInt(format.substring(1, format.length));
  24330. paused = true;
  24331. }
  24332. return {
  24333. scid: scid,
  24334. paused: paused
  24335. };
  24336. });
  24337. });
  24338. };
  24339. },{"./grammar":35}],38:[function(require,module,exports){
  24340. var grammar = require('./grammar');
  24341. // customized util.format - discards excess arguments and can void middle ones
  24342. var formatRegExp = /%[sdv%]/g;
  24343. var format = function (formatStr) {
  24344. var i = 1;
  24345. var args = arguments;
  24346. var len = args.length;
  24347. return formatStr.replace(formatRegExp, function (x) {
  24348. if (i >= len) {
  24349. return x; // missing argument
  24350. }
  24351. var arg = args[i];
  24352. i += 1;
  24353. switch (x) {
  24354. case '%%':
  24355. return '%';
  24356. case '%s':
  24357. return String(arg);
  24358. case '%d':
  24359. return Number(arg);
  24360. case '%v':
  24361. return '';
  24362. }
  24363. });
  24364. // NB: we discard excess arguments - they are typically undefined from makeLine
  24365. };
  24366. var makeLine = function (type, obj, location) {
  24367. var str = obj.format instanceof Function ?
  24368. (obj.format(obj.push ? location : location[obj.name])) :
  24369. obj.format;
  24370. var args = [type + '=' + str];
  24371. if (obj.names) {
  24372. for (var i = 0; i < obj.names.length; i += 1) {
  24373. var n = obj.names[i];
  24374. if (obj.name) {
  24375. args.push(location[obj.name][n]);
  24376. }
  24377. else { // for mLine and push attributes
  24378. args.push(location[obj.names[i]]);
  24379. }
  24380. }
  24381. }
  24382. else {
  24383. args.push(location[obj.name]);
  24384. }
  24385. return format.apply(null, args);
  24386. };
  24387. // RFC specified order
  24388. // TODO: extend this with all the rest
  24389. var defaultOuterOrder = [
  24390. 'v', 'o', 's', 'i',
  24391. 'u', 'e', 'p', 'c',
  24392. 'b', 't', 'r', 'z', 'a'
  24393. ];
  24394. var defaultInnerOrder = ['i', 'c', 'b', 'a'];
  24395. module.exports = function (session, opts) {
  24396. opts = opts || {};
  24397. // ensure certain properties exist
  24398. if (session.version == null) {
  24399. session.version = 0; // 'v=0' must be there (only defined version atm)
  24400. }
  24401. if (session.name == null) {
  24402. session.name = ' '; // 's= ' must be there if no meaningful name set
  24403. }
  24404. session.media.forEach(function (mLine) {
  24405. if (mLine.payloads == null) {
  24406. mLine.payloads = '';
  24407. }
  24408. });
  24409. var outerOrder = opts.outerOrder || defaultOuterOrder;
  24410. var innerOrder = opts.innerOrder || defaultInnerOrder;
  24411. var sdp = [];
  24412. // loop through outerOrder for matching properties on session
  24413. outerOrder.forEach(function (type) {
  24414. grammar[type].forEach(function (obj) {
  24415. if (obj.name in session && session[obj.name] != null) {
  24416. sdp.push(makeLine(type, obj, session));
  24417. }
  24418. else if (obj.push in session && session[obj.push] != null) {
  24419. session[obj.push].forEach(function (el) {
  24420. sdp.push(makeLine(type, obj, el));
  24421. });
  24422. }
  24423. });
  24424. });
  24425. // then for each media line, follow the innerOrder
  24426. session.media.forEach(function (mLine) {
  24427. sdp.push(makeLine('m', grammar.m[0], mLine));
  24428. innerOrder.forEach(function (type) {
  24429. grammar[type].forEach(function (obj) {
  24430. if (obj.name in mLine && mLine[obj.name] != null) {
  24431. sdp.push(makeLine(type, obj, mLine));
  24432. }
  24433. else if (obj.push in mLine && mLine[obj.push] != null) {
  24434. mLine[obj.push].forEach(function (el) {
  24435. sdp.push(makeLine(type, obj, el));
  24436. });
  24437. }
  24438. });
  24439. });
  24440. });
  24441. return sdp.join('\r\n') + '\r\n';
  24442. };
  24443. },{"./grammar":35}],39:[function(require,module,exports){
  24444. /* eslint-env node */
  24445. 'use strict';
  24446. // SDP helpers.
  24447. var SDPUtils = {};
  24448. // Generate an alphanumeric identifier for cname or mids.
  24449. // TODO: use UUIDs instead? https://gist.github.com/jed/982883
  24450. SDPUtils.generateIdentifier = function() {
  24451. return Math.random().toString(36).substr(2, 10);
  24452. };
  24453. // The RTCP CNAME used by all peerconnections from the same JS.
  24454. SDPUtils.localCName = SDPUtils.generateIdentifier();
  24455. // Splits SDP into lines, dealing with both CRLF and LF.
  24456. SDPUtils.splitLines = function(blob) {
  24457. return blob.trim().split('\n').map(function(line) {
  24458. return line.trim();
  24459. });
  24460. };
  24461. // Splits SDP into sessionpart and mediasections. Ensures CRLF.
  24462. SDPUtils.splitSections = function(blob) {
  24463. var parts = blob.split('\nm=');
  24464. return parts.map(function(part, index) {
  24465. return (index > 0 ? 'm=' + part : part).trim() + '\r\n';
  24466. });
  24467. };
  24468. // Returns lines that start with a certain prefix.
  24469. SDPUtils.matchPrefix = function(blob, prefix) {
  24470. return SDPUtils.splitLines(blob).filter(function(line) {
  24471. return line.indexOf(prefix) === 0;
  24472. });
  24473. };
  24474. // Parses an ICE candidate line. Sample input:
  24475. // candidate:702786350 2 udp 41819902 8.8.8.8 60769 typ relay raddr 8.8.8.8
  24476. // rport 55996"
  24477. SDPUtils.parseCandidate = function(line) {
  24478. var parts;
  24479. // Parse both variants.
  24480. if (line.indexOf('a=candidate:') === 0) {
  24481. parts = line.substring(12).split(' ');
  24482. } else {
  24483. parts = line.substring(10).split(' ');
  24484. }
  24485. var candidate = {
  24486. foundation: parts[0],
  24487. component: parseInt(parts[1], 10),
  24488. protocol: parts[2].toLowerCase(),
  24489. priority: parseInt(parts[3], 10),
  24490. ip: parts[4],
  24491. port: parseInt(parts[5], 10),
  24492. // skip parts[6] == 'typ'
  24493. type: parts[7]
  24494. };
  24495. for (var i = 8; i < parts.length; i += 2) {
  24496. switch (parts[i]) {
  24497. case 'raddr':
  24498. candidate.relatedAddress = parts[i + 1];
  24499. break;
  24500. case 'rport':
  24501. candidate.relatedPort = parseInt(parts[i + 1], 10);
  24502. break;
  24503. case 'tcptype':
  24504. candidate.tcpType = parts[i + 1];
  24505. break;
  24506. case 'ufrag':
  24507. candidate.ufrag = parts[i + 1]; // for backward compability.
  24508. candidate.usernameFragment = parts[i + 1];
  24509. break;
  24510. default: // extension handling, in particular ufrag
  24511. candidate[parts[i]] = parts[i + 1];
  24512. break;
  24513. }
  24514. }
  24515. return candidate;
  24516. };
  24517. // Translates a candidate object into SDP candidate attribute.
  24518. SDPUtils.writeCandidate = function(candidate) {
  24519. var sdp = [];
  24520. sdp.push(candidate.foundation);
  24521. sdp.push(candidate.component);
  24522. sdp.push(candidate.protocol.toUpperCase());
  24523. sdp.push(candidate.priority);
  24524. sdp.push(candidate.ip);
  24525. sdp.push(candidate.port);
  24526. var type = candidate.type;
  24527. sdp.push('typ');
  24528. sdp.push(type);
  24529. if (type !== 'host' && candidate.relatedAddress &&
  24530. candidate.relatedPort) {
  24531. sdp.push('raddr');
  24532. sdp.push(candidate.relatedAddress); // was: relAddr
  24533. sdp.push('rport');
  24534. sdp.push(candidate.relatedPort); // was: relPort
  24535. }
  24536. if (candidate.tcpType && candidate.protocol.toLowerCase() === 'tcp') {
  24537. sdp.push('tcptype');
  24538. sdp.push(candidate.tcpType);
  24539. }
  24540. if (candidate.ufrag) {
  24541. sdp.push('ufrag');
  24542. sdp.push(candidate.ufrag);
  24543. }
  24544. return 'candidate:' + sdp.join(' ');
  24545. };
  24546. // Parses an ice-options line, returns an array of option tags.
  24547. // a=ice-options:foo bar
  24548. SDPUtils.parseIceOptions = function(line) {
  24549. return line.substr(14).split(' ');
  24550. }
  24551. // Parses an rtpmap line, returns RTCRtpCoddecParameters. Sample input:
  24552. // a=rtpmap:111 opus/48000/2
  24553. SDPUtils.parseRtpMap = function(line) {
  24554. var parts = line.substr(9).split(' ');
  24555. var parsed = {
  24556. payloadType: parseInt(parts.shift(), 10) // was: id
  24557. };
  24558. parts = parts[0].split('/');
  24559. parsed.name = parts[0];
  24560. parsed.clockRate = parseInt(parts[1], 10); // was: clockrate
  24561. // was: channels
  24562. parsed.numChannels = parts.length === 3 ? parseInt(parts[2], 10) : 1;
  24563. return parsed;
  24564. };
  24565. // Generate an a=rtpmap line from RTCRtpCodecCapability or
  24566. // RTCRtpCodecParameters.
  24567. SDPUtils.writeRtpMap = function(codec) {
  24568. var pt = codec.payloadType;
  24569. if (codec.preferredPayloadType !== undefined) {
  24570. pt = codec.preferredPayloadType;
  24571. }
  24572. return 'a=rtpmap:' + pt + ' ' + codec.name + '/' + codec.clockRate +
  24573. (codec.numChannels !== 1 ? '/' + codec.numChannels : '') + '\r\n';
  24574. };
  24575. // Parses an a=extmap line (headerextension from RFC 5285). Sample input:
  24576. // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  24577. // a=extmap:2/sendonly urn:ietf:params:rtp-hdrext:toffset
  24578. SDPUtils.parseExtmap = function(line) {
  24579. var parts = line.substr(9).split(' ');
  24580. return {
  24581. id: parseInt(parts[0], 10),
  24582. direction: parts[0].indexOf('/') > 0 ? parts[0].split('/')[1] : 'sendrecv',
  24583. uri: parts[1]
  24584. };
  24585. };
  24586. // Generates a=extmap line from RTCRtpHeaderExtensionParameters or
  24587. // RTCRtpHeaderExtension.
  24588. SDPUtils.writeExtmap = function(headerExtension) {
  24589. return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) +
  24590. (headerExtension.direction && headerExtension.direction !== 'sendrecv'
  24591. ? '/' + headerExtension.direction
  24592. : '') +
  24593. ' ' + headerExtension.uri + '\r\n';
  24594. };
  24595. // Parses an ftmp line, returns dictionary. Sample input:
  24596. // a=fmtp:96 vbr=on;cng=on
  24597. // Also deals with vbr=on; cng=on
  24598. SDPUtils.parseFmtp = function(line) {
  24599. var parsed = {};
  24600. var kv;
  24601. var parts = line.substr(line.indexOf(' ') + 1).split(';');
  24602. for (var j = 0; j < parts.length; j++) {
  24603. kv = parts[j].trim().split('=');
  24604. parsed[kv[0].trim()] = kv[1];
  24605. }
  24606. return parsed;
  24607. };
  24608. // Generates an a=ftmp line from RTCRtpCodecCapability or RTCRtpCodecParameters.
  24609. SDPUtils.writeFmtp = function(codec) {
  24610. var line = '';
  24611. var pt = codec.payloadType;
  24612. if (codec.preferredPayloadType !== undefined) {
  24613. pt = codec.preferredPayloadType;
  24614. }
  24615. if (codec.parameters && Object.keys(codec.parameters).length) {
  24616. var params = [];
  24617. Object.keys(codec.parameters).forEach(function(param) {
  24618. params.push(param + '=' + codec.parameters[param]);
  24619. });
  24620. line += 'a=fmtp:' + pt + ' ' + params.join(';') + '\r\n';
  24621. }
  24622. return line;
  24623. };
  24624. // Parses an rtcp-fb line, returns RTCPRtcpFeedback object. Sample input:
  24625. // a=rtcp-fb:98 nack rpsi
  24626. SDPUtils.parseRtcpFb = function(line) {
  24627. var parts = line.substr(line.indexOf(' ') + 1).split(' ');
  24628. return {
  24629. type: parts.shift(),
  24630. parameter: parts.join(' ')
  24631. };
  24632. };
  24633. // Generate a=rtcp-fb lines from RTCRtpCodecCapability or RTCRtpCodecParameters.
  24634. SDPUtils.writeRtcpFb = function(codec) {
  24635. var lines = '';
  24636. var pt = codec.payloadType;
  24637. if (codec.preferredPayloadType !== undefined) {
  24638. pt = codec.preferredPayloadType;
  24639. }
  24640. if (codec.rtcpFeedback && codec.rtcpFeedback.length) {
  24641. // FIXME: special handling for trr-int?
  24642. codec.rtcpFeedback.forEach(function(fb) {
  24643. lines += 'a=rtcp-fb:' + pt + ' ' + fb.type +
  24644. (fb.parameter && fb.parameter.length ? ' ' + fb.parameter : '') +
  24645. '\r\n';
  24646. });
  24647. }
  24648. return lines;
  24649. };
  24650. // Parses an RFC 5576 ssrc media attribute. Sample input:
  24651. // a=ssrc:3735928559 cname:something
  24652. SDPUtils.parseSsrcMedia = function(line) {
  24653. var sp = line.indexOf(' ');
  24654. var parts = {
  24655. ssrc: parseInt(line.substr(7, sp - 7), 10)
  24656. };
  24657. var colon = line.indexOf(':', sp);
  24658. if (colon > -1) {
  24659. parts.attribute = line.substr(sp + 1, colon - sp - 1);
  24660. parts.value = line.substr(colon + 1);
  24661. } else {
  24662. parts.attribute = line.substr(sp + 1);
  24663. }
  24664. return parts;
  24665. };
  24666. // Extracts the MID (RFC 5888) from a media section.
  24667. // returns the MID or undefined if no mid line was found.
  24668. SDPUtils.getMid = function(mediaSection) {
  24669. var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:')[0];
  24670. if (mid) {
  24671. return mid.substr(6);
  24672. }
  24673. }
  24674. SDPUtils.parseFingerprint = function(line) {
  24675. var parts = line.substr(14).split(' ');
  24676. return {
  24677. algorithm: parts[0].toLowerCase(), // algorithm is case-sensitive in Edge.
  24678. value: parts[1]
  24679. };
  24680. };
  24681. // Extracts DTLS parameters from SDP media section or sessionpart.
  24682. // FIXME: for consistency with other functions this should only
  24683. // get the fingerprint line as input. See also getIceParameters.
  24684. SDPUtils.getDtlsParameters = function(mediaSection, sessionpart) {
  24685. var lines = SDPUtils.matchPrefix(mediaSection + sessionpart,
  24686. 'a=fingerprint:');
  24687. // Note: a=setup line is ignored since we use the 'auto' role.
  24688. // Note2: 'algorithm' is not case sensitive except in Edge.
  24689. return {
  24690. role: 'auto',
  24691. fingerprints: lines.map(SDPUtils.parseFingerprint)
  24692. };
  24693. };
  24694. // Serializes DTLS parameters to SDP.
  24695. SDPUtils.writeDtlsParameters = function(params, setupType) {
  24696. var sdp = 'a=setup:' + setupType + '\r\n';
  24697. params.fingerprints.forEach(function(fp) {
  24698. sdp += 'a=fingerprint:' + fp.algorithm + ' ' + fp.value + '\r\n';
  24699. });
  24700. return sdp;
  24701. };
  24702. // Parses ICE information from SDP media section or sessionpart.
  24703. // FIXME: for consistency with other functions this should only
  24704. // get the ice-ufrag and ice-pwd lines as input.
  24705. SDPUtils.getIceParameters = function(mediaSection, sessionpart) {
  24706. var lines = SDPUtils.splitLines(mediaSection);
  24707. // Search in session part, too.
  24708. lines = lines.concat(SDPUtils.splitLines(sessionpart));
  24709. var iceParameters = {
  24710. usernameFragment: lines.filter(function(line) {
  24711. return line.indexOf('a=ice-ufrag:') === 0;
  24712. })[0].substr(12),
  24713. password: lines.filter(function(line) {
  24714. return line.indexOf('a=ice-pwd:') === 0;
  24715. })[0].substr(10)
  24716. };
  24717. return iceParameters;
  24718. };
  24719. // Serializes ICE parameters to SDP.
  24720. SDPUtils.writeIceParameters = function(params) {
  24721. return 'a=ice-ufrag:' + params.usernameFragment + '\r\n' +
  24722. 'a=ice-pwd:' + params.password + '\r\n';
  24723. };
  24724. // Parses the SDP media section and returns RTCRtpParameters.
  24725. SDPUtils.parseRtpParameters = function(mediaSection) {
  24726. var description = {
  24727. codecs: [],
  24728. headerExtensions: [],
  24729. fecMechanisms: [],
  24730. rtcp: []
  24731. };
  24732. var lines = SDPUtils.splitLines(mediaSection);
  24733. var mline = lines[0].split(' ');
  24734. for (var i = 3; i < mline.length; i++) { // find all codecs from mline[3..]
  24735. var pt = mline[i];
  24736. var rtpmapline = SDPUtils.matchPrefix(
  24737. mediaSection, 'a=rtpmap:' + pt + ' ')[0];
  24738. if (rtpmapline) {
  24739. var codec = SDPUtils.parseRtpMap(rtpmapline);
  24740. var fmtps = SDPUtils.matchPrefix(
  24741. mediaSection, 'a=fmtp:' + pt + ' ');
  24742. // Only the first a=fmtp:<pt> is considered.
  24743. codec.parameters = fmtps.length ? SDPUtils.parseFmtp(fmtps[0]) : {};
  24744. codec.rtcpFeedback = SDPUtils.matchPrefix(
  24745. mediaSection, 'a=rtcp-fb:' + pt + ' ')
  24746. .map(SDPUtils.parseRtcpFb);
  24747. description.codecs.push(codec);
  24748. // parse FEC mechanisms from rtpmap lines.
  24749. switch (codec.name.toUpperCase()) {
  24750. case 'RED':
  24751. case 'ULPFEC':
  24752. description.fecMechanisms.push(codec.name.toUpperCase());
  24753. break;
  24754. default: // only RED and ULPFEC are recognized as FEC mechanisms.
  24755. break;
  24756. }
  24757. }
  24758. }
  24759. SDPUtils.matchPrefix(mediaSection, 'a=extmap:').forEach(function(line) {
  24760. description.headerExtensions.push(SDPUtils.parseExtmap(line));
  24761. });
  24762. // FIXME: parse rtcp.
  24763. return description;
  24764. };
  24765. // Generates parts of the SDP media section describing the capabilities /
  24766. // parameters.
  24767. SDPUtils.writeRtpDescription = function(kind, caps) {
  24768. var sdp = '';
  24769. // Build the mline.
  24770. sdp += 'm=' + kind + ' ';
  24771. sdp += caps.codecs.length > 0 ? '9' : '0'; // reject if no codecs.
  24772. sdp += ' UDP/TLS/RTP/SAVPF ';
  24773. sdp += caps.codecs.map(function(codec) {
  24774. if (codec.preferredPayloadType !== undefined) {
  24775. return codec.preferredPayloadType;
  24776. }
  24777. return codec.payloadType;
  24778. }).join(' ') + '\r\n';
  24779. sdp += 'c=IN IP4 0.0.0.0\r\n';
  24780. sdp += 'a=rtcp:9 IN IP4 0.0.0.0\r\n';
  24781. // Add a=rtpmap lines for each codec. Also fmtp and rtcp-fb.
  24782. caps.codecs.forEach(function(codec) {
  24783. sdp += SDPUtils.writeRtpMap(codec);
  24784. sdp += SDPUtils.writeFmtp(codec);
  24785. sdp += SDPUtils.writeRtcpFb(codec);
  24786. });
  24787. var maxptime = 0;
  24788. caps.codecs.forEach(function(codec) {
  24789. if (codec.maxptime > maxptime) {
  24790. maxptime = codec.maxptime;
  24791. }
  24792. });
  24793. if (maxptime > 0) {
  24794. sdp += 'a=maxptime:' + maxptime + '\r\n';
  24795. }
  24796. sdp += 'a=rtcp-mux\r\n';
  24797. caps.headerExtensions.forEach(function(extension) {
  24798. sdp += SDPUtils.writeExtmap(extension);
  24799. });
  24800. // FIXME: write fecMechanisms.
  24801. return sdp;
  24802. };
  24803. // Parses the SDP media section and returns an array of
  24804. // RTCRtpEncodingParameters.
  24805. SDPUtils.parseRtpEncodingParameters = function(mediaSection) {
  24806. var encodingParameters = [];
  24807. var description = SDPUtils.parseRtpParameters(mediaSection);
  24808. var hasRed = description.fecMechanisms.indexOf('RED') !== -1;
  24809. var hasUlpfec = description.fecMechanisms.indexOf('ULPFEC') !== -1;
  24810. // filter a=ssrc:... cname:, ignore PlanB-msid
  24811. var ssrcs = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')
  24812. .map(function(line) {
  24813. return SDPUtils.parseSsrcMedia(line);
  24814. })
  24815. .filter(function(parts) {
  24816. return parts.attribute === 'cname';
  24817. });
  24818. var primarySsrc = ssrcs.length > 0 && ssrcs[0].ssrc;
  24819. var secondarySsrc;
  24820. var flows = SDPUtils.matchPrefix(mediaSection, 'a=ssrc-group:FID')
  24821. .map(function(line) {
  24822. var parts = line.split(' ');
  24823. parts.shift();
  24824. return parts.map(function(part) {
  24825. return parseInt(part, 10);
  24826. });
  24827. });
  24828. if (flows.length > 0 && flows[0].length > 1 && flows[0][0] === primarySsrc) {
  24829. secondarySsrc = flows[0][1];
  24830. }
  24831. description.codecs.forEach(function(codec) {
  24832. if (codec.name.toUpperCase() === 'RTX' && codec.parameters.apt) {
  24833. var encParam = {
  24834. ssrc: primarySsrc,
  24835. codecPayloadType: parseInt(codec.parameters.apt, 10),
  24836. rtx: {
  24837. ssrc: secondarySsrc
  24838. }
  24839. };
  24840. encodingParameters.push(encParam);
  24841. if (hasRed) {
  24842. encParam = JSON.parse(JSON.stringify(encParam));
  24843. encParam.fec = {
  24844. ssrc: secondarySsrc,
  24845. mechanism: hasUlpfec ? 'red+ulpfec' : 'red'
  24846. };
  24847. encodingParameters.push(encParam);
  24848. }
  24849. }
  24850. });
  24851. if (encodingParameters.length === 0 && primarySsrc) {
  24852. encodingParameters.push({
  24853. ssrc: primarySsrc
  24854. });
  24855. }
  24856. // we support both b=AS and b=TIAS but interpret AS as TIAS.
  24857. var bandwidth = SDPUtils.matchPrefix(mediaSection, 'b=');
  24858. if (bandwidth.length) {
  24859. if (bandwidth[0].indexOf('b=TIAS:') === 0) {
  24860. bandwidth = parseInt(bandwidth[0].substr(7), 10);
  24861. } else if (bandwidth[0].indexOf('b=AS:') === 0) {
  24862. // use formula from JSEP to convert b=AS to TIAS value.
  24863. bandwidth = parseInt(bandwidth[0].substr(5), 10) * 1000 * 0.95
  24864. - (50 * 40 * 8);
  24865. } else {
  24866. bandwidth = undefined;
  24867. }
  24868. encodingParameters.forEach(function(params) {
  24869. params.maxBitrate = bandwidth;
  24870. });
  24871. }
  24872. return encodingParameters;
  24873. };
  24874. // parses http://draft.ortc.org/#rtcrtcpparameters*
  24875. SDPUtils.parseRtcpParameters = function(mediaSection) {
  24876. var rtcpParameters = {};
  24877. var cname;
  24878. // Gets the first SSRC. Note that with RTX there might be multiple
  24879. // SSRCs.
  24880. var remoteSsrc = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')
  24881. .map(function(line) {
  24882. return SDPUtils.parseSsrcMedia(line);
  24883. })
  24884. .filter(function(obj) {
  24885. return obj.attribute === 'cname';
  24886. })[0];
  24887. if (remoteSsrc) {
  24888. rtcpParameters.cname = remoteSsrc.value;
  24889. rtcpParameters.ssrc = remoteSsrc.ssrc;
  24890. }
  24891. // Edge uses the compound attribute instead of reducedSize
  24892. // compound is !reducedSize
  24893. var rsize = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-rsize');
  24894. rtcpParameters.reducedSize = rsize.length > 0;
  24895. rtcpParameters.compound = rsize.length === 0;
  24896. // parses the rtcp-mux attrіbute.
  24897. // Note that Edge does not support unmuxed RTCP.
  24898. var mux = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-mux');
  24899. rtcpParameters.mux = mux.length > 0;
  24900. return rtcpParameters;
  24901. };
  24902. // parses either a=msid: or a=ssrc:... msid lines and returns
  24903. // the id of the MediaStream and MediaStreamTrack.
  24904. SDPUtils.parseMsid = function(mediaSection) {
  24905. var parts;
  24906. var spec = SDPUtils.matchPrefix(mediaSection, 'a=msid:');
  24907. if (spec.length === 1) {
  24908. parts = spec[0].substr(7).split(' ');
  24909. return {stream: parts[0], track: parts[1]};
  24910. }
  24911. var planB = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')
  24912. .map(function(line) {
  24913. return SDPUtils.parseSsrcMedia(line);
  24914. })
  24915. .filter(function(parts) {
  24916. return parts.attribute === 'msid';
  24917. });
  24918. if (planB.length > 0) {
  24919. parts = planB[0].value.split(' ');
  24920. return {stream: parts[0], track: parts[1]};
  24921. }
  24922. };
  24923. // Generate a session ID for SDP.
  24924. // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-20#section-5.2.1
  24925. // recommends using a cryptographically random +ve 64-bit value
  24926. // but right now this should be acceptable and within the right range
  24927. SDPUtils.generateSessionId = function() {
  24928. return Math.random().toString().substr(2, 21);
  24929. };
  24930. // Write boilder plate for start of SDP
  24931. // sessId argument is optional - if not supplied it will
  24932. // be generated randomly
  24933. // sessVersion is optional and defaults to 2
  24934. SDPUtils.writeSessionBoilerplate = function(sessId, sessVer) {
  24935. var sessionId;
  24936. var version = sessVer !== undefined ? sessVer : 2;
  24937. if (sessId) {
  24938. sessionId = sessId;
  24939. } else {
  24940. sessionId = SDPUtils.generateSessionId();
  24941. }
  24942. // FIXME: sess-id should be an NTP timestamp.
  24943. return 'v=0\r\n' +
  24944. 'o=thisisadapterortc ' + sessionId + ' ' + version + ' IN IP4 127.0.0.1\r\n' +
  24945. 's=-\r\n' +
  24946. 't=0 0\r\n';
  24947. };
  24948. SDPUtils.writeMediaSection = function(transceiver, caps, type, stream) {
  24949. var sdp = SDPUtils.writeRtpDescription(transceiver.kind, caps);
  24950. // Map ICE parameters (ufrag, pwd) to SDP.
  24951. sdp += SDPUtils.writeIceParameters(
  24952. transceiver.iceGatherer.getLocalParameters());
  24953. // Map DTLS parameters to SDP.
  24954. sdp += SDPUtils.writeDtlsParameters(
  24955. transceiver.dtlsTransport.getLocalParameters(),
  24956. type === 'offer' ? 'actpass' : 'active');
  24957. sdp += 'a=mid:' + transceiver.mid + '\r\n';
  24958. if (transceiver.direction) {
  24959. sdp += 'a=' + transceiver.direction + '\r\n';
  24960. } else if (transceiver.rtpSender && transceiver.rtpReceiver) {
  24961. sdp += 'a=sendrecv\r\n';
  24962. } else if (transceiver.rtpSender) {
  24963. sdp += 'a=sendonly\r\n';
  24964. } else if (transceiver.rtpReceiver) {
  24965. sdp += 'a=recvonly\r\n';
  24966. } else {
  24967. sdp += 'a=inactive\r\n';
  24968. }
  24969. if (transceiver.rtpSender) {
  24970. // spec.
  24971. var msid = 'msid:' + stream.id + ' ' +
  24972. transceiver.rtpSender.track.id + '\r\n';
  24973. sdp += 'a=' + msid;
  24974. // for Chrome.
  24975. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +
  24976. ' ' + msid;
  24977. if (transceiver.sendEncodingParameters[0].rtx) {
  24978. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc +
  24979. ' ' + msid;
  24980. sdp += 'a=ssrc-group:FID ' +
  24981. transceiver.sendEncodingParameters[0].ssrc + ' ' +
  24982. transceiver.sendEncodingParameters[0].rtx.ssrc +
  24983. '\r\n';
  24984. }
  24985. }
  24986. // FIXME: this should be written by writeRtpDescription.
  24987. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +
  24988. ' cname:' + SDPUtils.localCName + '\r\n';
  24989. if (transceiver.rtpSender && transceiver.sendEncodingParameters[0].rtx) {
  24990. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].rtx.ssrc +
  24991. ' cname:' + SDPUtils.localCName + '\r\n';
  24992. }
  24993. return sdp;
  24994. };
  24995. // Gets the direction from the mediaSection or the sessionpart.
  24996. SDPUtils.getDirection = function(mediaSection, sessionpart) {
  24997. // Look for sendrecv, sendonly, recvonly, inactive, default to sendrecv.
  24998. var lines = SDPUtils.splitLines(mediaSection);
  24999. for (var i = 0; i < lines.length; i++) {
  25000. switch (lines[i]) {
  25001. case 'a=sendrecv':
  25002. case 'a=sendonly':
  25003. case 'a=recvonly':
  25004. case 'a=inactive':
  25005. return lines[i].substr(2);
  25006. default:
  25007. // FIXME: What should happen here?
  25008. }
  25009. }
  25010. if (sessionpart) {
  25011. return SDPUtils.getDirection(sessionpart);
  25012. }
  25013. return 'sendrecv';
  25014. };
  25015. SDPUtils.getKind = function(mediaSection) {
  25016. var lines = SDPUtils.splitLines(mediaSection);
  25017. var mline = lines[0].split(' ');
  25018. return mline[0].substr(2);
  25019. };
  25020. SDPUtils.isRejected = function(mediaSection) {
  25021. return mediaSection.split(' ', 2)[1] === '0';
  25022. };
  25023. SDPUtils.parseMLine = function(mediaSection) {
  25024. var lines = SDPUtils.splitLines(mediaSection);
  25025. var mline = lines[0].split(' ');
  25026. return {
  25027. kind: mline[0].substr(2),
  25028. port: parseInt(mline[1], 10),
  25029. protocol: mline[2],
  25030. fmt: mline.slice(3).join(' ')
  25031. };
  25032. };
  25033. // Expose public methods.
  25034. if (typeof module === 'object') {
  25035. module.exports = SDPUtils;
  25036. }
  25037. },{}],40:[function(require,module,exports){
  25038. (function (global){
  25039. /*
  25040. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  25041. *
  25042. * Use of this source code is governed by a BSD-style license
  25043. * that can be found in the LICENSE file in the root of the source
  25044. * tree.
  25045. */
  25046. /* eslint-env node */
  25047. 'use strict';
  25048. var adapterFactory = require('./adapter_factory.js');
  25049. module.exports = adapterFactory({window: global.window});
  25050. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  25051. },{"./adapter_factory.js":41}],41:[function(require,module,exports){
  25052. /*
  25053. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  25054. *
  25055. * Use of this source code is governed by a BSD-style license
  25056. * that can be found in the LICENSE file in the root of the source
  25057. * tree.
  25058. */
  25059. /* eslint-env node */
  25060. 'use strict';
  25061. var utils = require('./utils');
  25062. // Shimming starts here.
  25063. module.exports = function(dependencies, opts) {
  25064. var window = dependencies && dependencies.window;
  25065. var options = {
  25066. shimChrome: true,
  25067. shimFirefox: true,
  25068. shimEdge: true,
  25069. shimSafari: true,
  25070. };
  25071. for (var key in opts) {
  25072. if (hasOwnProperty.call(opts, key)) {
  25073. options[key] = opts[key];
  25074. }
  25075. }
  25076. // Utils.
  25077. var logging = utils.log;
  25078. var browserDetails = utils.detectBrowser(window);
  25079. // Export to the adapter global object visible in the browser.
  25080. var adapter = {
  25081. browserDetails: browserDetails,
  25082. extractVersion: utils.extractVersion,
  25083. disableLog: utils.disableLog,
  25084. disableWarnings: utils.disableWarnings
  25085. };
  25086. // Uncomment the line below if you want logging to occur, including logging
  25087. // for the switch statement below. Can also be turned on in the browser via
  25088. // adapter.disableLog(false), but then logging from the switch statement below
  25089. // will not appear.
  25090. // require('./utils').disableLog(false);
  25091. // Browser shims.
  25092. var chromeShim = require('./chrome/chrome_shim') || null;
  25093. var edgeShim = require('./edge/edge_shim') || null;
  25094. var firefoxShim = require('./firefox/firefox_shim') || null;
  25095. var safariShim = require('./safari/safari_shim') || null;
  25096. var commonShim = require('./common_shim') || null;
  25097. // Shim browser if found.
  25098. switch (browserDetails.browser) {
  25099. case 'chrome':
  25100. if (!chromeShim || !chromeShim.shimPeerConnection ||
  25101. !options.shimChrome) {
  25102. logging('Chrome shim is not included in this adapter release.');
  25103. return adapter;
  25104. }
  25105. logging('adapter.js shimming chrome.');
  25106. // Export to the adapter global object visible in the browser.
  25107. adapter.browserShim = chromeShim;
  25108. commonShim.shimCreateObjectURL(window);
  25109. chromeShim.shimGetUserMedia(window);
  25110. chromeShim.shimMediaStream(window);
  25111. chromeShim.shimSourceObject(window);
  25112. chromeShim.shimPeerConnection(window);
  25113. chromeShim.shimOnTrack(window);
  25114. chromeShim.shimAddTrackRemoveTrack(window);
  25115. chromeShim.shimGetSendersWithDtmf(window);
  25116. commonShim.shimRTCIceCandidate(window);
  25117. break;
  25118. case 'firefox':
  25119. if (!firefoxShim || !firefoxShim.shimPeerConnection ||
  25120. !options.shimFirefox) {
  25121. logging('Firefox shim is not included in this adapter release.');
  25122. return adapter;
  25123. }
  25124. logging('adapter.js shimming firefox.');
  25125. // Export to the adapter global object visible in the browser.
  25126. adapter.browserShim = firefoxShim;
  25127. commonShim.shimCreateObjectURL(window);
  25128. firefoxShim.shimGetUserMedia(window);
  25129. firefoxShim.shimSourceObject(window);
  25130. firefoxShim.shimPeerConnection(window);
  25131. firefoxShim.shimOnTrack(window);
  25132. firefoxShim.shimRemoveStream(window);
  25133. commonShim.shimRTCIceCandidate(window);
  25134. break;
  25135. case 'edge':
  25136. if (!edgeShim || !edgeShim.shimPeerConnection || !options.shimEdge) {
  25137. logging('MS edge shim is not included in this adapter release.');
  25138. return adapter;
  25139. }
  25140. logging('adapter.js shimming edge.');
  25141. // Export to the adapter global object visible in the browser.
  25142. adapter.browserShim = edgeShim;
  25143. commonShim.shimCreateObjectURL(window);
  25144. edgeShim.shimGetUserMedia(window);
  25145. edgeShim.shimPeerConnection(window);
  25146. edgeShim.shimReplaceTrack(window);
  25147. // the edge shim implements the full RTCIceCandidate object.
  25148. break;
  25149. case 'safari':
  25150. if (!safariShim || !options.shimSafari) {
  25151. logging('Safari shim is not included in this adapter release.');
  25152. return adapter;
  25153. }
  25154. logging('adapter.js shimming safari.');
  25155. // Export to the adapter global object visible in the browser.
  25156. adapter.browserShim = safariShim;
  25157. commonShim.shimCreateObjectURL(window);
  25158. safariShim.shimRTCIceServerUrls(window);
  25159. safariShim.shimCallbacksAPI(window);
  25160. safariShim.shimLocalStreamsAPI(window);
  25161. safariShim.shimRemoteStreamsAPI(window);
  25162. safariShim.shimTrackEventTransceiver(window);
  25163. safariShim.shimGetUserMedia(window);
  25164. safariShim.shimCreateOfferLegacy(window);
  25165. commonShim.shimRTCIceCandidate(window);
  25166. break;
  25167. default:
  25168. logging('Unsupported browser!');
  25169. break;
  25170. }
  25171. return adapter;
  25172. };
  25173. },{"./chrome/chrome_shim":42,"./common_shim":44,"./edge/edge_shim":45,"./firefox/firefox_shim":47,"./safari/safari_shim":49,"./utils":50}],42:[function(require,module,exports){
  25174. /*
  25175. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  25176. *
  25177. * Use of this source code is governed by a BSD-style license
  25178. * that can be found in the LICENSE file in the root of the source
  25179. * tree.
  25180. */
  25181. /* eslint-env node */
  25182. 'use strict';
  25183. var utils = require('../utils.js');
  25184. var logging = utils.log;
  25185. var chromeShim = {
  25186. shimMediaStream: function(window) {
  25187. window.MediaStream = window.MediaStream || window.webkitMediaStream;
  25188. },
  25189. shimOnTrack: function(window) {
  25190. if (typeof window === 'object' && window.RTCPeerConnection && !('ontrack' in
  25191. window.RTCPeerConnection.prototype)) {
  25192. Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {
  25193. get: function() {
  25194. return this._ontrack;
  25195. },
  25196. set: function(f) {
  25197. if (this._ontrack) {
  25198. this.removeEventListener('track', this._ontrack);
  25199. }
  25200. this.addEventListener('track', this._ontrack = f);
  25201. }
  25202. });
  25203. var origSetRemoteDescription =
  25204. window.RTCPeerConnection.prototype.setRemoteDescription;
  25205. window.RTCPeerConnection.prototype.setRemoteDescription = function() {
  25206. var pc = this;
  25207. if (!pc._ontrackpoly) {
  25208. pc._ontrackpoly = function(e) {
  25209. // onaddstream does not fire when a track is added to an existing
  25210. // stream. But stream.onaddtrack is implemented so we use that.
  25211. e.stream.addEventListener('addtrack', function(te) {
  25212. var receiver;
  25213. if (window.RTCPeerConnection.prototype.getReceivers) {
  25214. receiver = pc.getReceivers().find(function(r) {
  25215. return r.track && r.track.id === te.track.id;
  25216. });
  25217. } else {
  25218. receiver = {track: te.track};
  25219. }
  25220. var event = new Event('track');
  25221. event.track = te.track;
  25222. event.receiver = receiver;
  25223. event.transceiver = {receiver: receiver};
  25224. event.streams = [e.stream];
  25225. pc.dispatchEvent(event);
  25226. });
  25227. e.stream.getTracks().forEach(function(track) {
  25228. var receiver;
  25229. if (window.RTCPeerConnection.prototype.getReceivers) {
  25230. receiver = pc.getReceivers().find(function(r) {
  25231. return r.track && r.track.id === track.id;
  25232. });
  25233. } else {
  25234. receiver = {track: track};
  25235. }
  25236. var event = new Event('track');
  25237. event.track = track;
  25238. event.receiver = receiver;
  25239. event.transceiver = {receiver: receiver};
  25240. event.streams = [e.stream];
  25241. pc.dispatchEvent(event);
  25242. });
  25243. };
  25244. pc.addEventListener('addstream', pc._ontrackpoly);
  25245. }
  25246. return origSetRemoteDescription.apply(pc, arguments);
  25247. };
  25248. }
  25249. },
  25250. shimGetSendersWithDtmf: function(window) {
  25251. // Overrides addTrack/removeTrack, depends on shimAddTrackRemoveTrack.
  25252. if (typeof window === 'object' && window.RTCPeerConnection &&
  25253. !('getSenders' in window.RTCPeerConnection.prototype) &&
  25254. 'createDTMFSender' in window.RTCPeerConnection.prototype) {
  25255. var shimSenderWithDtmf = function(pc, track) {
  25256. return {
  25257. track: track,
  25258. get dtmf() {
  25259. if (this._dtmf === undefined) {
  25260. if (track.kind === 'audio') {
  25261. this._dtmf = pc.createDTMFSender(track);
  25262. } else {
  25263. this._dtmf = null;
  25264. }
  25265. }
  25266. return this._dtmf;
  25267. },
  25268. _pc: pc
  25269. };
  25270. };
  25271. // augment addTrack when getSenders is not available.
  25272. if (!window.RTCPeerConnection.prototype.getSenders) {
  25273. window.RTCPeerConnection.prototype.getSenders = function() {
  25274. this._senders = this._senders || [];
  25275. return this._senders.slice(); // return a copy of the internal state.
  25276. };
  25277. var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
  25278. window.RTCPeerConnection.prototype.addTrack = function(track, stream) {
  25279. var pc = this;
  25280. var sender = origAddTrack.apply(pc, arguments);
  25281. if (!sender) {
  25282. sender = shimSenderWithDtmf(pc, track);
  25283. pc._senders.push(sender);
  25284. }
  25285. return sender;
  25286. };
  25287. var origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
  25288. window.RTCPeerConnection.prototype.removeTrack = function(sender) {
  25289. var pc = this;
  25290. origRemoveTrack.apply(pc, arguments);
  25291. var idx = pc._senders.indexOf(sender);
  25292. if (idx !== -1) {
  25293. pc._senders.splice(idx, 1);
  25294. }
  25295. };
  25296. }
  25297. var origAddStream = window.RTCPeerConnection.prototype.addStream;
  25298. window.RTCPeerConnection.prototype.addStream = function(stream) {
  25299. var pc = this;
  25300. pc._senders = pc._senders || [];
  25301. origAddStream.apply(pc, [stream]);
  25302. stream.getTracks().forEach(function(track) {
  25303. pc._senders.push(shimSenderWithDtmf(pc, track));
  25304. });
  25305. };
  25306. var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
  25307. window.RTCPeerConnection.prototype.removeStream = function(stream) {
  25308. var pc = this;
  25309. pc._senders = pc._senders || [];
  25310. origRemoveStream.apply(pc, [stream]);
  25311. stream.getTracks().forEach(function(track) {
  25312. var sender = pc._senders.find(function(s) {
  25313. return s.track === track;
  25314. });
  25315. if (sender) {
  25316. pc._senders.splice(pc._senders.indexOf(sender), 1); // remove sender
  25317. }
  25318. });
  25319. };
  25320. } else if (typeof window === 'object' && window.RTCPeerConnection &&
  25321. 'getSenders' in window.RTCPeerConnection.prototype &&
  25322. 'createDTMFSender' in window.RTCPeerConnection.prototype &&
  25323. window.RTCRtpSender &&
  25324. !('dtmf' in window.RTCRtpSender.prototype)) {
  25325. var origGetSenders = window.RTCPeerConnection.prototype.getSenders;
  25326. window.RTCPeerConnection.prototype.getSenders = function() {
  25327. var pc = this;
  25328. var senders = origGetSenders.apply(pc, []);
  25329. senders.forEach(function(sender) {
  25330. sender._pc = pc;
  25331. });
  25332. return senders;
  25333. };
  25334. Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', {
  25335. get: function() {
  25336. if (this._dtmf === undefined) {
  25337. if (this.track.kind === 'audio') {
  25338. this._dtmf = this._pc.createDTMFSender(this.track);
  25339. } else {
  25340. this._dtmf = null;
  25341. }
  25342. }
  25343. return this._dtmf;
  25344. }
  25345. });
  25346. }
  25347. },
  25348. shimSourceObject: function(window) {
  25349. var URL = window && window.URL;
  25350. if (typeof window === 'object') {
  25351. if (window.HTMLMediaElement &&
  25352. !('srcObject' in window.HTMLMediaElement.prototype)) {
  25353. // Shim the srcObject property, once, when HTMLMediaElement is found.
  25354. Object.defineProperty(window.HTMLMediaElement.prototype, 'srcObject', {
  25355. get: function() {
  25356. return this._srcObject;
  25357. },
  25358. set: function(stream) {
  25359. var self = this;
  25360. // Use _srcObject as a private property for this shim
  25361. this._srcObject = stream;
  25362. if (this.src) {
  25363. URL.revokeObjectURL(this.src);
  25364. }
  25365. if (!stream) {
  25366. this.src = '';
  25367. return undefined;
  25368. }
  25369. this.src = URL.createObjectURL(stream);
  25370. // We need to recreate the blob url when a track is added or
  25371. // removed. Doing it manually since we want to avoid a recursion.
  25372. stream.addEventListener('addtrack', function() {
  25373. if (self.src) {
  25374. URL.revokeObjectURL(self.src);
  25375. }
  25376. self.src = URL.createObjectURL(stream);
  25377. });
  25378. stream.addEventListener('removetrack', function() {
  25379. if (self.src) {
  25380. URL.revokeObjectURL(self.src);
  25381. }
  25382. self.src = URL.createObjectURL(stream);
  25383. });
  25384. }
  25385. });
  25386. }
  25387. }
  25388. },
  25389. shimAddTrackRemoveTrack: function(window) {
  25390. var browserDetails = utils.detectBrowser(window);
  25391. // shim addTrack and removeTrack.
  25392. if (window.RTCPeerConnection.prototype.addTrack &&
  25393. browserDetails.version >= 64) {
  25394. return;
  25395. }
  25396. // also shim pc.getLocalStreams when addTrack is shimmed
  25397. // to return the original streams.
  25398. var origGetLocalStreams = window.RTCPeerConnection.prototype
  25399. .getLocalStreams;
  25400. window.RTCPeerConnection.prototype.getLocalStreams = function() {
  25401. var self = this;
  25402. var nativeStreams = origGetLocalStreams.apply(this);
  25403. self._reverseStreams = self._reverseStreams || {};
  25404. return nativeStreams.map(function(stream) {
  25405. return self._reverseStreams[stream.id];
  25406. });
  25407. };
  25408. var origAddStream = window.RTCPeerConnection.prototype.addStream;
  25409. window.RTCPeerConnection.prototype.addStream = function(stream) {
  25410. var pc = this;
  25411. pc._streams = pc._streams || {};
  25412. pc._reverseStreams = pc._reverseStreams || {};
  25413. stream.getTracks().forEach(function(track) {
  25414. var alreadyExists = pc.getSenders().find(function(s) {
  25415. return s.track === track;
  25416. });
  25417. if (alreadyExists) {
  25418. throw new DOMException('Track already exists.',
  25419. 'InvalidAccessError');
  25420. }
  25421. });
  25422. // Add identity mapping for consistency with addTrack.
  25423. // Unless this is being used with a stream from addTrack.
  25424. if (!pc._reverseStreams[stream.id]) {
  25425. var newStream = new window.MediaStream(stream.getTracks());
  25426. pc._streams[stream.id] = newStream;
  25427. pc._reverseStreams[newStream.id] = stream;
  25428. stream = newStream;
  25429. }
  25430. origAddStream.apply(pc, [stream]);
  25431. };
  25432. var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
  25433. window.RTCPeerConnection.prototype.removeStream = function(stream) {
  25434. var pc = this;
  25435. pc._streams = pc._streams || {};
  25436. pc._reverseStreams = pc._reverseStreams || {};
  25437. origRemoveStream.apply(pc, [(pc._streams[stream.id] || stream)]);
  25438. delete pc._reverseStreams[(pc._streams[stream.id] ?
  25439. pc._streams[stream.id].id : stream.id)];
  25440. delete pc._streams[stream.id];
  25441. };
  25442. window.RTCPeerConnection.prototype.addTrack = function(track, stream) {
  25443. var pc = this;
  25444. if (pc.signalingState === 'closed') {
  25445. throw new DOMException(
  25446. 'The RTCPeerConnection\'s signalingState is \'closed\'.',
  25447. 'InvalidStateError');
  25448. }
  25449. var streams = [].slice.call(arguments, 1);
  25450. if (streams.length !== 1 ||
  25451. !streams[0].getTracks().find(function(t) {
  25452. return t === track;
  25453. })) {
  25454. // this is not fully correct but all we can manage without
  25455. // [[associated MediaStreams]] internal slot.
  25456. throw new DOMException(
  25457. 'The adapter.js addTrack polyfill only supports a single ' +
  25458. ' stream which is associated with the specified track.',
  25459. 'NotSupportedError');
  25460. }
  25461. var alreadyExists = pc.getSenders().find(function(s) {
  25462. return s.track === track;
  25463. });
  25464. if (alreadyExists) {
  25465. throw new DOMException('Track already exists.',
  25466. 'InvalidAccessError');
  25467. }
  25468. pc._streams = pc._streams || {};
  25469. pc._reverseStreams = pc._reverseStreams || {};
  25470. var oldStream = pc._streams[stream.id];
  25471. if (oldStream) {
  25472. // this is using odd Chrome behaviour, use with caution:
  25473. // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
  25474. // Note: we rely on the high-level addTrack/dtmf shim to
  25475. // create the sender with a dtmf sender.
  25476. oldStream.addTrack(track);
  25477. // Trigger ONN async.
  25478. Promise.resolve().then(function() {
  25479. pc.dispatchEvent(new Event('negotiationneeded'));
  25480. });
  25481. } else {
  25482. var newStream = new window.MediaStream([track]);
  25483. pc._streams[stream.id] = newStream;
  25484. pc._reverseStreams[newStream.id] = stream;
  25485. pc.addStream(newStream);
  25486. }
  25487. return pc.getSenders().find(function(s) {
  25488. return s.track === track;
  25489. });
  25490. };
  25491. // replace the internal stream id with the external one and
  25492. // vice versa.
  25493. function replaceInternalStreamId(pc, description) {
  25494. var sdp = description.sdp;
  25495. Object.keys(pc._reverseStreams || []).forEach(function(internalId) {
  25496. var externalStream = pc._reverseStreams[internalId];
  25497. var internalStream = pc._streams[externalStream.id];
  25498. sdp = sdp.replace(new RegExp(internalStream.id, 'g'),
  25499. externalStream.id);
  25500. });
  25501. return new RTCSessionDescription({
  25502. type: description.type,
  25503. sdp: sdp
  25504. });
  25505. }
  25506. function replaceExternalStreamId(pc, description) {
  25507. var sdp = description.sdp;
  25508. Object.keys(pc._reverseStreams || []).forEach(function(internalId) {
  25509. var externalStream = pc._reverseStreams[internalId];
  25510. var internalStream = pc._streams[externalStream.id];
  25511. sdp = sdp.replace(new RegExp(externalStream.id, 'g'),
  25512. internalStream.id);
  25513. });
  25514. return new RTCSessionDescription({
  25515. type: description.type,
  25516. sdp: sdp
  25517. });
  25518. }
  25519. ['createOffer', 'createAnswer'].forEach(function(method) {
  25520. var nativeMethod = window.RTCPeerConnection.prototype[method];
  25521. window.RTCPeerConnection.prototype[method] = function() {
  25522. var pc = this;
  25523. var args = arguments;
  25524. var isLegacyCall = arguments.length &&
  25525. typeof arguments[0] === 'function';
  25526. if (isLegacyCall) {
  25527. return nativeMethod.apply(pc, [
  25528. function(description) {
  25529. var desc = replaceInternalStreamId(pc, description);
  25530. args[0].apply(null, [desc]);
  25531. },
  25532. function(err) {
  25533. if (args[1]) {
  25534. args[1].apply(null, err);
  25535. }
  25536. }, arguments[2]
  25537. ]);
  25538. }
  25539. return nativeMethod.apply(pc, arguments)
  25540. .then(function(description) {
  25541. return replaceInternalStreamId(pc, description);
  25542. });
  25543. };
  25544. });
  25545. var origSetLocalDescription =
  25546. window.RTCPeerConnection.prototype.setLocalDescription;
  25547. window.RTCPeerConnection.prototype.setLocalDescription = function() {
  25548. var pc = this;
  25549. if (!arguments.length || !arguments[0].type) {
  25550. return origSetLocalDescription.apply(pc, arguments);
  25551. }
  25552. arguments[0] = replaceExternalStreamId(pc, arguments[0]);
  25553. return origSetLocalDescription.apply(pc, arguments);
  25554. };
  25555. // TODO: mangle getStats: https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamstats-streamidentifier
  25556. var origLocalDescription = Object.getOwnPropertyDescriptor(
  25557. window.RTCPeerConnection.prototype, 'localDescription');
  25558. Object.defineProperty(window.RTCPeerConnection.prototype,
  25559. 'localDescription', {
  25560. get: function() {
  25561. var pc = this;
  25562. var description = origLocalDescription.get.apply(this);
  25563. if (description.type === '') {
  25564. return description;
  25565. }
  25566. return replaceInternalStreamId(pc, description);
  25567. }
  25568. });
  25569. window.RTCPeerConnection.prototype.removeTrack = function(sender) {
  25570. var pc = this;
  25571. if (pc.signalingState === 'closed') {
  25572. throw new DOMException(
  25573. 'The RTCPeerConnection\'s signalingState is \'closed\'.',
  25574. 'InvalidStateError');
  25575. }
  25576. // We can not yet check for sender instanceof RTCRtpSender
  25577. // since we shim RTPSender. So we check if sender._pc is set.
  25578. if (!sender._pc) {
  25579. throw new DOMException('Argument 1 of RTCPeerConnection.removeTrack ' +
  25580. 'does not implement interface RTCRtpSender.', 'TypeError');
  25581. }
  25582. var isLocal = sender._pc === pc;
  25583. if (!isLocal) {
  25584. throw new DOMException('Sender was not created by this connection.',
  25585. 'InvalidAccessError');
  25586. }
  25587. // Search for the native stream the senders track belongs to.
  25588. pc._streams = pc._streams || {};
  25589. var stream;
  25590. Object.keys(pc._streams).forEach(function(streamid) {
  25591. var hasTrack = pc._streams[streamid].getTracks().find(function(track) {
  25592. return sender.track === track;
  25593. });
  25594. if (hasTrack) {
  25595. stream = pc._streams[streamid];
  25596. }
  25597. });
  25598. if (stream) {
  25599. if (stream.getTracks().length === 1) {
  25600. // if this is the last track of the stream, remove the stream. This
  25601. // takes care of any shimmed _senders.
  25602. pc.removeStream(pc._reverseStreams[stream.id]);
  25603. } else {
  25604. // relying on the same odd chrome behaviour as above.
  25605. stream.removeTrack(sender.track);
  25606. }
  25607. pc.dispatchEvent(new Event('negotiationneeded'));
  25608. }
  25609. };
  25610. },
  25611. shimPeerConnection: function(window) {
  25612. var browserDetails = utils.detectBrowser(window);
  25613. // The RTCPeerConnection object.
  25614. if (!window.RTCPeerConnection) {
  25615. window.RTCPeerConnection = function(pcConfig, pcConstraints) {
  25616. // Translate iceTransportPolicy to iceTransports,
  25617. // see https://code.google.com/p/webrtc/issues/detail?id=4869
  25618. // this was fixed in M56 along with unprefixing RTCPeerConnection.
  25619. logging('PeerConnection');
  25620. if (pcConfig && pcConfig.iceTransportPolicy) {
  25621. pcConfig.iceTransports = pcConfig.iceTransportPolicy;
  25622. }
  25623. return new window.webkitRTCPeerConnection(pcConfig, pcConstraints);
  25624. };
  25625. window.RTCPeerConnection.prototype =
  25626. window.webkitRTCPeerConnection.prototype;
  25627. // wrap static methods. Currently just generateCertificate.
  25628. if (window.webkitRTCPeerConnection.generateCertificate) {
  25629. Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
  25630. get: function() {
  25631. return window.webkitRTCPeerConnection.generateCertificate;
  25632. }
  25633. });
  25634. }
  25635. } else {
  25636. // migrate from non-spec RTCIceServer.url to RTCIceServer.urls
  25637. var OrigPeerConnection = window.RTCPeerConnection;
  25638. window.RTCPeerConnection = function(pcConfig, pcConstraints) {
  25639. if (pcConfig && pcConfig.iceServers) {
  25640. var newIceServers = [];
  25641. for (var i = 0; i < pcConfig.iceServers.length; i++) {
  25642. var server = pcConfig.iceServers[i];
  25643. if (!server.hasOwnProperty('urls') &&
  25644. server.hasOwnProperty('url')) {
  25645. utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls');
  25646. server = JSON.parse(JSON.stringify(server));
  25647. server.urls = server.url;
  25648. newIceServers.push(server);
  25649. } else {
  25650. newIceServers.push(pcConfig.iceServers[i]);
  25651. }
  25652. }
  25653. pcConfig.iceServers = newIceServers;
  25654. }
  25655. return new OrigPeerConnection(pcConfig, pcConstraints);
  25656. };
  25657. window.RTCPeerConnection.prototype = OrigPeerConnection.prototype;
  25658. // wrap static methods. Currently just generateCertificate.
  25659. Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
  25660. get: function() {
  25661. return OrigPeerConnection.generateCertificate;
  25662. }
  25663. });
  25664. }
  25665. var origGetStats = window.RTCPeerConnection.prototype.getStats;
  25666. window.RTCPeerConnection.prototype.getStats = function(selector,
  25667. successCallback, errorCallback) {
  25668. var self = this;
  25669. var args = arguments;
  25670. // If selector is a function then we are in the old style stats so just
  25671. // pass back the original getStats format to avoid breaking old users.
  25672. if (arguments.length > 0 && typeof selector === 'function') {
  25673. return origGetStats.apply(this, arguments);
  25674. }
  25675. // When spec-style getStats is supported, return those when called with
  25676. // either no arguments or the selector argument is null.
  25677. if (origGetStats.length === 0 && (arguments.length === 0 ||
  25678. typeof arguments[0] !== 'function')) {
  25679. return origGetStats.apply(this, []);
  25680. }
  25681. var fixChromeStats_ = function(response) {
  25682. var standardReport = {};
  25683. var reports = response.result();
  25684. reports.forEach(function(report) {
  25685. var standardStats = {
  25686. id: report.id,
  25687. timestamp: report.timestamp,
  25688. type: {
  25689. localcandidate: 'local-candidate',
  25690. remotecandidate: 'remote-candidate'
  25691. }[report.type] || report.type
  25692. };
  25693. report.names().forEach(function(name) {
  25694. standardStats[name] = report.stat(name);
  25695. });
  25696. standardReport[standardStats.id] = standardStats;
  25697. });
  25698. return standardReport;
  25699. };
  25700. // shim getStats with maplike support
  25701. var makeMapStats = function(stats) {
  25702. return new Map(Object.keys(stats).map(function(key) {
  25703. return [key, stats[key]];
  25704. }));
  25705. };
  25706. if (arguments.length >= 2) {
  25707. var successCallbackWrapper_ = function(response) {
  25708. args[1](makeMapStats(fixChromeStats_(response)));
  25709. };
  25710. return origGetStats.apply(this, [successCallbackWrapper_,
  25711. arguments[0]]);
  25712. }
  25713. // promise-support
  25714. return new Promise(function(resolve, reject) {
  25715. origGetStats.apply(self, [
  25716. function(response) {
  25717. resolve(makeMapStats(fixChromeStats_(response)));
  25718. }, reject]);
  25719. }).then(successCallback, errorCallback);
  25720. };
  25721. // add promise support -- natively available in Chrome 51
  25722. if (browserDetails.version < 51) {
  25723. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']
  25724. .forEach(function(method) {
  25725. var nativeMethod = window.RTCPeerConnection.prototype[method];
  25726. window.RTCPeerConnection.prototype[method] = function() {
  25727. var args = arguments;
  25728. var self = this;
  25729. var promise = new Promise(function(resolve, reject) {
  25730. nativeMethod.apply(self, [args[0], resolve, reject]);
  25731. });
  25732. if (args.length < 2) {
  25733. return promise;
  25734. }
  25735. return promise.then(function() {
  25736. args[1].apply(null, []);
  25737. },
  25738. function(err) {
  25739. if (args.length >= 3) {
  25740. args[2].apply(null, [err]);
  25741. }
  25742. });
  25743. };
  25744. });
  25745. }
  25746. // promise support for createOffer and createAnswer. Available (without
  25747. // bugs) since M52: crbug/619289
  25748. if (browserDetails.version < 52) {
  25749. ['createOffer', 'createAnswer'].forEach(function(method) {
  25750. var nativeMethod = window.RTCPeerConnection.prototype[method];
  25751. window.RTCPeerConnection.prototype[method] = function() {
  25752. var self = this;
  25753. if (arguments.length < 1 || (arguments.length === 1 &&
  25754. typeof arguments[0] === 'object')) {
  25755. var opts = arguments.length === 1 ? arguments[0] : undefined;
  25756. return new Promise(function(resolve, reject) {
  25757. nativeMethod.apply(self, [resolve, reject, opts]);
  25758. });
  25759. }
  25760. return nativeMethod.apply(this, arguments);
  25761. };
  25762. });
  25763. }
  25764. // shim implicit creation of RTCSessionDescription/RTCIceCandidate
  25765. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']
  25766. .forEach(function(method) {
  25767. var nativeMethod = window.RTCPeerConnection.prototype[method];
  25768. window.RTCPeerConnection.prototype[method] = function() {
  25769. arguments[0] = new ((method === 'addIceCandidate') ?
  25770. window.RTCIceCandidate :
  25771. window.RTCSessionDescription)(arguments[0]);
  25772. return nativeMethod.apply(this, arguments);
  25773. };
  25774. });
  25775. // support for addIceCandidate(null or undefined)
  25776. var nativeAddIceCandidate =
  25777. window.RTCPeerConnection.prototype.addIceCandidate;
  25778. window.RTCPeerConnection.prototype.addIceCandidate = function() {
  25779. if (!arguments[0]) {
  25780. if (arguments[1]) {
  25781. arguments[1].apply(null);
  25782. }
  25783. return Promise.resolve();
  25784. }
  25785. return nativeAddIceCandidate.apply(this, arguments);
  25786. };
  25787. }
  25788. };
  25789. // Expose public methods.
  25790. module.exports = {
  25791. shimMediaStream: chromeShim.shimMediaStream,
  25792. shimOnTrack: chromeShim.shimOnTrack,
  25793. shimAddTrackRemoveTrack: chromeShim.shimAddTrackRemoveTrack,
  25794. shimGetSendersWithDtmf: chromeShim.shimGetSendersWithDtmf,
  25795. shimSourceObject: chromeShim.shimSourceObject,
  25796. shimPeerConnection: chromeShim.shimPeerConnection,
  25797. shimGetUserMedia: require('./getusermedia')
  25798. };
  25799. },{"../utils.js":50,"./getusermedia":43}],43:[function(require,module,exports){
  25800. /*
  25801. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  25802. *
  25803. * Use of this source code is governed by a BSD-style license
  25804. * that can be found in the LICENSE file in the root of the source
  25805. * tree.
  25806. */
  25807. /* eslint-env node */
  25808. 'use strict';
  25809. var utils = require('../utils.js');
  25810. var logging = utils.log;
  25811. // Expose public methods.
  25812. module.exports = function(window) {
  25813. var browserDetails = utils.detectBrowser(window);
  25814. var navigator = window && window.navigator;
  25815. var constraintsToChrome_ = function(c) {
  25816. if (typeof c !== 'object' || c.mandatory || c.optional) {
  25817. return c;
  25818. }
  25819. var cc = {};
  25820. Object.keys(c).forEach(function(key) {
  25821. if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
  25822. return;
  25823. }
  25824. var r = (typeof c[key] === 'object') ? c[key] : {ideal: c[key]};
  25825. if (r.exact !== undefined && typeof r.exact === 'number') {
  25826. r.min = r.max = r.exact;
  25827. }
  25828. var oldname_ = function(prefix, name) {
  25829. if (prefix) {
  25830. return prefix + name.charAt(0).toUpperCase() + name.slice(1);
  25831. }
  25832. return (name === 'deviceId') ? 'sourceId' : name;
  25833. };
  25834. if (r.ideal !== undefined) {
  25835. cc.optional = cc.optional || [];
  25836. var oc = {};
  25837. if (typeof r.ideal === 'number') {
  25838. oc[oldname_('min', key)] = r.ideal;
  25839. cc.optional.push(oc);
  25840. oc = {};
  25841. oc[oldname_('max', key)] = r.ideal;
  25842. cc.optional.push(oc);
  25843. } else {
  25844. oc[oldname_('', key)] = r.ideal;
  25845. cc.optional.push(oc);
  25846. }
  25847. }
  25848. if (r.exact !== undefined && typeof r.exact !== 'number') {
  25849. cc.mandatory = cc.mandatory || {};
  25850. cc.mandatory[oldname_('', key)] = r.exact;
  25851. } else {
  25852. ['min', 'max'].forEach(function(mix) {
  25853. if (r[mix] !== undefined) {
  25854. cc.mandatory = cc.mandatory || {};
  25855. cc.mandatory[oldname_(mix, key)] = r[mix];
  25856. }
  25857. });
  25858. }
  25859. });
  25860. if (c.advanced) {
  25861. cc.optional = (cc.optional || []).concat(c.advanced);
  25862. }
  25863. return cc;
  25864. };
  25865. var shimConstraints_ = function(constraints, func) {
  25866. if (browserDetails.version >= 61) {
  25867. return func(constraints);
  25868. }
  25869. constraints = JSON.parse(JSON.stringify(constraints));
  25870. if (constraints && typeof constraints.audio === 'object') {
  25871. var remap = function(obj, a, b) {
  25872. if (a in obj && !(b in obj)) {
  25873. obj[b] = obj[a];
  25874. delete obj[a];
  25875. }
  25876. };
  25877. constraints = JSON.parse(JSON.stringify(constraints));
  25878. remap(constraints.audio, 'autoGainControl', 'googAutoGainControl');
  25879. remap(constraints.audio, 'noiseSuppression', 'googNoiseSuppression');
  25880. constraints.audio = constraintsToChrome_(constraints.audio);
  25881. }
  25882. if (constraints && typeof constraints.video === 'object') {
  25883. // Shim facingMode for mobile & surface pro.
  25884. var face = constraints.video.facingMode;
  25885. face = face && ((typeof face === 'object') ? face : {ideal: face});
  25886. var getSupportedFacingModeLies = browserDetails.version < 66;
  25887. if ((face && (face.exact === 'user' || face.exact === 'environment' ||
  25888. face.ideal === 'user' || face.ideal === 'environment')) &&
  25889. !(navigator.mediaDevices.getSupportedConstraints &&
  25890. navigator.mediaDevices.getSupportedConstraints().facingMode &&
  25891. !getSupportedFacingModeLies)) {
  25892. delete constraints.video.facingMode;
  25893. var matches;
  25894. if (face.exact === 'environment' || face.ideal === 'environment') {
  25895. matches = ['back', 'rear'];
  25896. } else if (face.exact === 'user' || face.ideal === 'user') {
  25897. matches = ['front'];
  25898. }
  25899. if (matches) {
  25900. // Look for matches in label, or use last cam for back (typical).
  25901. return navigator.mediaDevices.enumerateDevices()
  25902. .then(function(devices) {
  25903. devices = devices.filter(function(d) {
  25904. return d.kind === 'videoinput';
  25905. });
  25906. var dev = devices.find(function(d) {
  25907. return matches.some(function(match) {
  25908. return d.label.toLowerCase().indexOf(match) !== -1;
  25909. });
  25910. });
  25911. if (!dev && devices.length && matches.indexOf('back') !== -1) {
  25912. dev = devices[devices.length - 1]; // more likely the back cam
  25913. }
  25914. if (dev) {
  25915. constraints.video.deviceId = face.exact ? {exact: dev.deviceId} :
  25916. {ideal: dev.deviceId};
  25917. }
  25918. constraints.video = constraintsToChrome_(constraints.video);
  25919. logging('chrome: ' + JSON.stringify(constraints));
  25920. return func(constraints);
  25921. });
  25922. }
  25923. }
  25924. constraints.video = constraintsToChrome_(constraints.video);
  25925. }
  25926. logging('chrome: ' + JSON.stringify(constraints));
  25927. return func(constraints);
  25928. };
  25929. var shimError_ = function(e) {
  25930. return {
  25931. name: {
  25932. PermissionDeniedError: 'NotAllowedError',
  25933. InvalidStateError: 'NotReadableError',
  25934. DevicesNotFoundError: 'NotFoundError',
  25935. ConstraintNotSatisfiedError: 'OverconstrainedError',
  25936. TrackStartError: 'NotReadableError',
  25937. MediaDeviceFailedDueToShutdown: 'NotReadableError',
  25938. MediaDeviceKillSwitchOn: 'NotReadableError'
  25939. }[e.name] || e.name,
  25940. message: e.message,
  25941. constraint: e.constraintName,
  25942. toString: function() {
  25943. return this.name + (this.message && ': ') + this.message;
  25944. }
  25945. };
  25946. };
  25947. var getUserMedia_ = function(constraints, onSuccess, onError) {
  25948. shimConstraints_(constraints, function(c) {
  25949. navigator.webkitGetUserMedia(c, onSuccess, function(e) {
  25950. if (onError) {
  25951. onError(shimError_(e));
  25952. }
  25953. });
  25954. });
  25955. };
  25956. navigator.getUserMedia = getUserMedia_;
  25957. // Returns the result of getUserMedia as a Promise.
  25958. var getUserMediaPromise_ = function(constraints) {
  25959. return new Promise(function(resolve, reject) {
  25960. navigator.getUserMedia(constraints, resolve, reject);
  25961. });
  25962. };
  25963. if (!navigator.mediaDevices) {
  25964. navigator.mediaDevices = {
  25965. getUserMedia: getUserMediaPromise_,
  25966. enumerateDevices: function() {
  25967. return new Promise(function(resolve) {
  25968. var kinds = {audio: 'audioinput', video: 'videoinput'};
  25969. return window.MediaStreamTrack.getSources(function(devices) {
  25970. resolve(devices.map(function(device) {
  25971. return {label: device.label,
  25972. kind: kinds[device.kind],
  25973. deviceId: device.id,
  25974. groupId: ''};
  25975. }));
  25976. });
  25977. });
  25978. },
  25979. getSupportedConstraints: function() {
  25980. return {
  25981. deviceId: true, echoCancellation: true, facingMode: true,
  25982. frameRate: true, height: true, width: true
  25983. };
  25984. }
  25985. };
  25986. }
  25987. // A shim for getUserMedia method on the mediaDevices object.
  25988. // TODO(KaptenJansson) remove once implemented in Chrome stable.
  25989. if (!navigator.mediaDevices.getUserMedia) {
  25990. navigator.mediaDevices.getUserMedia = function(constraints) {
  25991. return getUserMediaPromise_(constraints);
  25992. };
  25993. } else {
  25994. // Even though Chrome 45 has navigator.mediaDevices and a getUserMedia
  25995. // function which returns a Promise, it does not accept spec-style
  25996. // constraints.
  25997. var origGetUserMedia = navigator.mediaDevices.getUserMedia.
  25998. bind(navigator.mediaDevices);
  25999. navigator.mediaDevices.getUserMedia = function(cs) {
  26000. return shimConstraints_(cs, function(c) {
  26001. return origGetUserMedia(c).then(function(stream) {
  26002. if (c.audio && !stream.getAudioTracks().length ||
  26003. c.video && !stream.getVideoTracks().length) {
  26004. stream.getTracks().forEach(function(track) {
  26005. track.stop();
  26006. });
  26007. throw new DOMException('', 'NotFoundError');
  26008. }
  26009. return stream;
  26010. }, function(e) {
  26011. return Promise.reject(shimError_(e));
  26012. });
  26013. });
  26014. };
  26015. }
  26016. // Dummy devicechange event methods.
  26017. // TODO(KaptenJansson) remove once implemented in Chrome stable.
  26018. if (typeof navigator.mediaDevices.addEventListener === 'undefined') {
  26019. navigator.mediaDevices.addEventListener = function() {
  26020. logging('Dummy mediaDevices.addEventListener called.');
  26021. };
  26022. }
  26023. if (typeof navigator.mediaDevices.removeEventListener === 'undefined') {
  26024. navigator.mediaDevices.removeEventListener = function() {
  26025. logging('Dummy mediaDevices.removeEventListener called.');
  26026. };
  26027. }
  26028. };
  26029. },{"../utils.js":50}],44:[function(require,module,exports){
  26030. /*
  26031. * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  26032. *
  26033. * Use of this source code is governed by a BSD-style license
  26034. * that can be found in the LICENSE file in the root of the source
  26035. * tree.
  26036. */
  26037. /* eslint-env node */
  26038. 'use strict';
  26039. var SDPUtils = require('sdp');
  26040. var utils = require('./utils');
  26041. // Wraps the peerconnection event eventNameToWrap in a function
  26042. // which returns the modified event object.
  26043. function wrapPeerConnectionEvent(window, eventNameToWrap, wrapper) {
  26044. if (!window.RTCPeerConnection) {
  26045. return;
  26046. }
  26047. var proto = window.RTCPeerConnection.prototype;
  26048. var nativeAddEventListener = proto.addEventListener;
  26049. proto.addEventListener = function(nativeEventName, cb) {
  26050. if (nativeEventName !== eventNameToWrap) {
  26051. return nativeAddEventListener.apply(this, arguments);
  26052. }
  26053. var wrappedCallback = function(e) {
  26054. cb(wrapper(e));
  26055. };
  26056. this._eventMap = this._eventMap || {};
  26057. this._eventMap[cb] = wrappedCallback;
  26058. return nativeAddEventListener.apply(this, [nativeEventName,
  26059. wrappedCallback]);
  26060. };
  26061. var nativeRemoveEventListener = proto.removeEventListener;
  26062. proto.removeEventListener = function(nativeEventName, cb) {
  26063. if (nativeEventName !== eventNameToWrap || !this._eventMap
  26064. || !this._eventMap[cb]) {
  26065. return nativeRemoveEventListener.apply(this, arguments);
  26066. }
  26067. var unwrappedCb = this._eventMap[cb];
  26068. delete this._eventMap[cb];
  26069. return nativeRemoveEventListener.apply(this, [nativeEventName,
  26070. unwrappedCb]);
  26071. };
  26072. Object.defineProperty(proto, 'on' + eventNameToWrap, {
  26073. get: function() {
  26074. return this['_on' + eventNameToWrap];
  26075. },
  26076. set: function(cb) {
  26077. if (this['_on' + eventNameToWrap]) {
  26078. this.removeEventListener(eventNameToWrap,
  26079. this['_on' + eventNameToWrap]);
  26080. delete this['_on' + eventNameToWrap];
  26081. }
  26082. if (cb) {
  26083. this.addEventListener(eventNameToWrap,
  26084. this['_on' + eventNameToWrap] = cb);
  26085. }
  26086. }
  26087. });
  26088. }
  26089. module.exports = {
  26090. shimRTCIceCandidate: function(window) {
  26091. // foundation is arbitrarily chosen as an indicator for full support for
  26092. // https://w3c.github.io/webrtc-pc/#rtcicecandidate-interface
  26093. if (window.RTCIceCandidate && 'foundation' in
  26094. window.RTCIceCandidate.prototype) {
  26095. return;
  26096. }
  26097. var NativeRTCIceCandidate = window.RTCIceCandidate;
  26098. window.RTCIceCandidate = function(args) {
  26099. // Remove the a= which shouldn't be part of the candidate string.
  26100. if (typeof args === 'object' && args.candidate &&
  26101. args.candidate.indexOf('a=') === 0) {
  26102. args = JSON.parse(JSON.stringify(args));
  26103. args.candidate = args.candidate.substr(2);
  26104. }
  26105. // Augment the native candidate with the parsed fields.
  26106. var nativeCandidate = new NativeRTCIceCandidate(args);
  26107. var parsedCandidate = SDPUtils.parseCandidate(args.candidate);
  26108. var augmentedCandidate = Object.assign(nativeCandidate,
  26109. parsedCandidate);
  26110. // Add a serializer that does not serialize the extra attributes.
  26111. augmentedCandidate.toJSON = function() {
  26112. return {
  26113. candidate: augmentedCandidate.candidate,
  26114. sdpMid: augmentedCandidate.sdpMid,
  26115. sdpMLineIndex: augmentedCandidate.sdpMLineIndex,
  26116. usernameFragment: augmentedCandidate.usernameFragment,
  26117. };
  26118. };
  26119. return augmentedCandidate;
  26120. };
  26121. // Hook up the augmented candidate in onicecandidate and
  26122. // addEventListener('icecandidate', ...)
  26123. wrapPeerConnectionEvent(window, 'icecandidate', function(e) {
  26124. if (e.candidate) {
  26125. Object.defineProperty(e, 'candidate', {
  26126. value: new window.RTCIceCandidate(e.candidate),
  26127. writable: 'false'
  26128. });
  26129. }
  26130. return e;
  26131. });
  26132. },
  26133. // shimCreateObjectURL must be called before shimSourceObject to avoid loop.
  26134. shimCreateObjectURL: function(window) {
  26135. var URL = window && window.URL;
  26136. if (!(typeof window === 'object' && window.HTMLMediaElement &&
  26137. 'srcObject' in window.HTMLMediaElement.prototype &&
  26138. URL.createObjectURL && URL.revokeObjectURL)) {
  26139. // Only shim CreateObjectURL using srcObject if srcObject exists.
  26140. return undefined;
  26141. }
  26142. var nativeCreateObjectURL = URL.createObjectURL.bind(URL);
  26143. var nativeRevokeObjectURL = URL.revokeObjectURL.bind(URL);
  26144. var streams = new Map(), newId = 0;
  26145. URL.createObjectURL = function(stream) {
  26146. if ('getTracks' in stream) {
  26147. var url = 'polyblob:' + (++newId);
  26148. streams.set(url, stream);
  26149. utils.deprecated('URL.createObjectURL(stream)',
  26150. 'elem.srcObject = stream');
  26151. return url;
  26152. }
  26153. return nativeCreateObjectURL(stream);
  26154. };
  26155. URL.revokeObjectURL = function(url) {
  26156. nativeRevokeObjectURL(url);
  26157. streams.delete(url);
  26158. };
  26159. var dsc = Object.getOwnPropertyDescriptor(window.HTMLMediaElement.prototype,
  26160. 'src');
  26161. Object.defineProperty(window.HTMLMediaElement.prototype, 'src', {
  26162. get: function() {
  26163. return dsc.get.apply(this);
  26164. },
  26165. set: function(url) {
  26166. this.srcObject = streams.get(url) || null;
  26167. return dsc.set.apply(this, [url]);
  26168. }
  26169. });
  26170. var nativeSetAttribute = window.HTMLMediaElement.prototype.setAttribute;
  26171. window.HTMLMediaElement.prototype.setAttribute = function() {
  26172. if (arguments.length === 2 &&
  26173. ('' + arguments[0]).toLowerCase() === 'src') {
  26174. this.srcObject = streams.get(arguments[1]) || null;
  26175. }
  26176. return nativeSetAttribute.apply(this, arguments);
  26177. };
  26178. }
  26179. };
  26180. },{"./utils":50,"sdp":39}],45:[function(require,module,exports){
  26181. /*
  26182. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  26183. *
  26184. * Use of this source code is governed by a BSD-style license
  26185. * that can be found in the LICENSE file in the root of the source
  26186. * tree.
  26187. */
  26188. /* eslint-env node */
  26189. 'use strict';
  26190. var utils = require('../utils');
  26191. var shimRTCPeerConnection = require('rtcpeerconnection-shim');
  26192. module.exports = {
  26193. shimGetUserMedia: require('./getusermedia'),
  26194. shimPeerConnection: function(window) {
  26195. var browserDetails = utils.detectBrowser(window);
  26196. if (window.RTCIceGatherer) {
  26197. // ORTC defines an RTCIceCandidate object but no constructor.
  26198. // Not implemented in Edge.
  26199. if (!window.RTCIceCandidate) {
  26200. window.RTCIceCandidate = function(args) {
  26201. return args;
  26202. };
  26203. }
  26204. // ORTC does not have a session description object but
  26205. // other browsers (i.e. Chrome) that will support both PC and ORTC
  26206. // in the future might have this defined already.
  26207. if (!window.RTCSessionDescription) {
  26208. window.RTCSessionDescription = function(args) {
  26209. return args;
  26210. };
  26211. }
  26212. // this adds an additional event listener to MediaStrackTrack that signals
  26213. // when a tracks enabled property was changed. Workaround for a bug in
  26214. // addStream, see below. No longer required in 15025+
  26215. if (browserDetails.version < 15025) {
  26216. var origMSTEnabled = Object.getOwnPropertyDescriptor(
  26217. window.MediaStreamTrack.prototype, 'enabled');
  26218. Object.defineProperty(window.MediaStreamTrack.prototype, 'enabled', {
  26219. set: function(value) {
  26220. origMSTEnabled.set.call(this, value);
  26221. var ev = new Event('enabled');
  26222. ev.enabled = value;
  26223. this.dispatchEvent(ev);
  26224. }
  26225. });
  26226. }
  26227. }
  26228. // ORTC defines the DTMF sender a bit different.
  26229. // https://github.com/w3c/ortc/issues/714
  26230. if (window.RTCRtpSender && !('dtmf' in window.RTCRtpSender.prototype)) {
  26231. Object.defineProperty(window.RTCRtpSender.prototype, 'dtmf', {
  26232. get: function() {
  26233. if (this._dtmf === undefined) {
  26234. if (this.track.kind === 'audio') {
  26235. this._dtmf = new window.RTCDtmfSender(this);
  26236. } else if (this.track.kind === 'video') {
  26237. this._dtmf = null;
  26238. }
  26239. }
  26240. return this._dtmf;
  26241. }
  26242. });
  26243. }
  26244. window.RTCPeerConnection =
  26245. shimRTCPeerConnection(window, browserDetails.version);
  26246. },
  26247. shimReplaceTrack: function(window) {
  26248. // ORTC has replaceTrack -- https://github.com/w3c/ortc/issues/614
  26249. if (window.RTCRtpSender &&
  26250. !('replaceTrack' in window.RTCRtpSender.prototype)) {
  26251. window.RTCRtpSender.prototype.replaceTrack =
  26252. window.RTCRtpSender.prototype.setTrack;
  26253. }
  26254. }
  26255. };
  26256. },{"../utils":50,"./getusermedia":46,"rtcpeerconnection-shim":34}],46:[function(require,module,exports){
  26257. /*
  26258. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  26259. *
  26260. * Use of this source code is governed by a BSD-style license
  26261. * that can be found in the LICENSE file in the root of the source
  26262. * tree.
  26263. */
  26264. /* eslint-env node */
  26265. 'use strict';
  26266. // Expose public methods.
  26267. module.exports = function(window) {
  26268. var navigator = window && window.navigator;
  26269. var shimError_ = function(e) {
  26270. return {
  26271. name: {PermissionDeniedError: 'NotAllowedError'}[e.name] || e.name,
  26272. message: e.message,
  26273. constraint: e.constraint,
  26274. toString: function() {
  26275. return this.name;
  26276. }
  26277. };
  26278. };
  26279. // getUserMedia error shim.
  26280. var origGetUserMedia = navigator.mediaDevices.getUserMedia.
  26281. bind(navigator.mediaDevices);
  26282. navigator.mediaDevices.getUserMedia = function(c) {
  26283. return origGetUserMedia(c).catch(function(e) {
  26284. return Promise.reject(shimError_(e));
  26285. });
  26286. };
  26287. };
  26288. },{}],47:[function(require,module,exports){
  26289. /*
  26290. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  26291. *
  26292. * Use of this source code is governed by a BSD-style license
  26293. * that can be found in the LICENSE file in the root of the source
  26294. * tree.
  26295. */
  26296. /* eslint-env node */
  26297. 'use strict';
  26298. var utils = require('../utils');
  26299. var firefoxShim = {
  26300. shimOnTrack: function(window) {
  26301. if (typeof window === 'object' && window.RTCPeerConnection && !('ontrack' in
  26302. window.RTCPeerConnection.prototype)) {
  26303. Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {
  26304. get: function() {
  26305. return this._ontrack;
  26306. },
  26307. set: function(f) {
  26308. if (this._ontrack) {
  26309. this.removeEventListener('track', this._ontrack);
  26310. this.removeEventListener('addstream', this._ontrackpoly);
  26311. }
  26312. this.addEventListener('track', this._ontrack = f);
  26313. this.addEventListener('addstream', this._ontrackpoly = function(e) {
  26314. e.stream.getTracks().forEach(function(track) {
  26315. var event = new Event('track');
  26316. event.track = track;
  26317. event.receiver = {track: track};
  26318. event.transceiver = {receiver: event.receiver};
  26319. event.streams = [e.stream];
  26320. this.dispatchEvent(event);
  26321. }.bind(this));
  26322. }.bind(this));
  26323. }
  26324. });
  26325. }
  26326. if (typeof window === 'object' && window.RTCTrackEvent &&
  26327. ('receiver' in window.RTCTrackEvent.prototype) &&
  26328. !('transceiver' in window.RTCTrackEvent.prototype)) {
  26329. Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {
  26330. get: function() {
  26331. return {receiver: this.receiver};
  26332. }
  26333. });
  26334. }
  26335. },
  26336. shimSourceObject: function(window) {
  26337. // Firefox has supported mozSrcObject since FF22, unprefixed in 42.
  26338. if (typeof window === 'object') {
  26339. if (window.HTMLMediaElement &&
  26340. !('srcObject' in window.HTMLMediaElement.prototype)) {
  26341. // Shim the srcObject property, once, when HTMLMediaElement is found.
  26342. Object.defineProperty(window.HTMLMediaElement.prototype, 'srcObject', {
  26343. get: function() {
  26344. return this.mozSrcObject;
  26345. },
  26346. set: function(stream) {
  26347. this.mozSrcObject = stream;
  26348. }
  26349. });
  26350. }
  26351. }
  26352. },
  26353. shimPeerConnection: function(window) {
  26354. var browserDetails = utils.detectBrowser(window);
  26355. if (typeof window !== 'object' || !(window.RTCPeerConnection ||
  26356. window.mozRTCPeerConnection)) {
  26357. return; // probably media.peerconnection.enabled=false in about:config
  26358. }
  26359. // The RTCPeerConnection object.
  26360. if (!window.RTCPeerConnection) {
  26361. window.RTCPeerConnection = function(pcConfig, pcConstraints) {
  26362. if (browserDetails.version < 38) {
  26363. // .urls is not supported in FF < 38.
  26364. // create RTCIceServers with a single url.
  26365. if (pcConfig && pcConfig.iceServers) {
  26366. var newIceServers = [];
  26367. for (var i = 0; i < pcConfig.iceServers.length; i++) {
  26368. var server = pcConfig.iceServers[i];
  26369. if (server.hasOwnProperty('urls')) {
  26370. for (var j = 0; j < server.urls.length; j++) {
  26371. var newServer = {
  26372. url: server.urls[j]
  26373. };
  26374. if (server.urls[j].indexOf('turn') === 0) {
  26375. newServer.username = server.username;
  26376. newServer.credential = server.credential;
  26377. }
  26378. newIceServers.push(newServer);
  26379. }
  26380. } else {
  26381. newIceServers.push(pcConfig.iceServers[i]);
  26382. }
  26383. }
  26384. pcConfig.iceServers = newIceServers;
  26385. }
  26386. }
  26387. return new window.mozRTCPeerConnection(pcConfig, pcConstraints);
  26388. };
  26389. window.RTCPeerConnection.prototype =
  26390. window.mozRTCPeerConnection.prototype;
  26391. // wrap static methods. Currently just generateCertificate.
  26392. if (window.mozRTCPeerConnection.generateCertificate) {
  26393. Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
  26394. get: function() {
  26395. return window.mozRTCPeerConnection.generateCertificate;
  26396. }
  26397. });
  26398. }
  26399. window.RTCSessionDescription = window.mozRTCSessionDescription;
  26400. window.RTCIceCandidate = window.mozRTCIceCandidate;
  26401. }
  26402. // shim away need for obsolete RTCIceCandidate/RTCSessionDescription.
  26403. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']
  26404. .forEach(function(method) {
  26405. var nativeMethod = window.RTCPeerConnection.prototype[method];
  26406. window.RTCPeerConnection.prototype[method] = function() {
  26407. arguments[0] = new ((method === 'addIceCandidate') ?
  26408. window.RTCIceCandidate :
  26409. window.RTCSessionDescription)(arguments[0]);
  26410. return nativeMethod.apply(this, arguments);
  26411. };
  26412. });
  26413. // support for addIceCandidate(null or undefined)
  26414. var nativeAddIceCandidate =
  26415. window.RTCPeerConnection.prototype.addIceCandidate;
  26416. window.RTCPeerConnection.prototype.addIceCandidate = function() {
  26417. if (!arguments[0]) {
  26418. if (arguments[1]) {
  26419. arguments[1].apply(null);
  26420. }
  26421. return Promise.resolve();
  26422. }
  26423. return nativeAddIceCandidate.apply(this, arguments);
  26424. };
  26425. // shim getStats with maplike support
  26426. var makeMapStats = function(stats) {
  26427. var map = new Map();
  26428. Object.keys(stats).forEach(function(key) {
  26429. map.set(key, stats[key]);
  26430. map[key] = stats[key];
  26431. });
  26432. return map;
  26433. };
  26434. var modernStatsTypes = {
  26435. inboundrtp: 'inbound-rtp',
  26436. outboundrtp: 'outbound-rtp',
  26437. candidatepair: 'candidate-pair',
  26438. localcandidate: 'local-candidate',
  26439. remotecandidate: 'remote-candidate'
  26440. };
  26441. var nativeGetStats = window.RTCPeerConnection.prototype.getStats;
  26442. window.RTCPeerConnection.prototype.getStats = function(
  26443. selector,
  26444. onSucc,
  26445. onErr
  26446. ) {
  26447. return nativeGetStats.apply(this, [selector || null])
  26448. .then(function(stats) {
  26449. if (browserDetails.version < 48) {
  26450. stats = makeMapStats(stats);
  26451. }
  26452. if (browserDetails.version < 53 && !onSucc) {
  26453. // Shim only promise getStats with spec-hyphens in type names
  26454. // Leave callback version alone; misc old uses of forEach before Map
  26455. try {
  26456. stats.forEach(function(stat) {
  26457. stat.type = modernStatsTypes[stat.type] || stat.type;
  26458. });
  26459. } catch (e) {
  26460. if (e.name !== 'TypeError') {
  26461. throw e;
  26462. }
  26463. // Avoid TypeError: "type" is read-only, in old versions. 34-43ish
  26464. stats.forEach(function(stat, i) {
  26465. stats.set(i, Object.assign({}, stat, {
  26466. type: modernStatsTypes[stat.type] || stat.type
  26467. }));
  26468. });
  26469. }
  26470. }
  26471. return stats;
  26472. })
  26473. .then(onSucc, onErr);
  26474. };
  26475. },
  26476. shimRemoveStream: function(window) {
  26477. if (!window.RTCPeerConnection ||
  26478. 'removeStream' in window.RTCPeerConnection.prototype) {
  26479. return;
  26480. }
  26481. window.RTCPeerConnection.prototype.removeStream = function(stream) {
  26482. var pc = this;
  26483. utils.deprecated('removeStream', 'removeTrack');
  26484. this.getSenders().forEach(function(sender) {
  26485. if (sender.track && stream.getTracks().indexOf(sender.track) !== -1) {
  26486. pc.removeTrack(sender);
  26487. }
  26488. });
  26489. };
  26490. }
  26491. };
  26492. // Expose public methods.
  26493. module.exports = {
  26494. shimOnTrack: firefoxShim.shimOnTrack,
  26495. shimSourceObject: firefoxShim.shimSourceObject,
  26496. shimPeerConnection: firefoxShim.shimPeerConnection,
  26497. shimRemoveStream: firefoxShim.shimRemoveStream,
  26498. shimGetUserMedia: require('./getusermedia')
  26499. };
  26500. },{"../utils":50,"./getusermedia":48}],48:[function(require,module,exports){
  26501. /*
  26502. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  26503. *
  26504. * Use of this source code is governed by a BSD-style license
  26505. * that can be found in the LICENSE file in the root of the source
  26506. * tree.
  26507. */
  26508. /* eslint-env node */
  26509. 'use strict';
  26510. var utils = require('../utils');
  26511. var logging = utils.log;
  26512. // Expose public methods.
  26513. module.exports = function(window) {
  26514. var browserDetails = utils.detectBrowser(window);
  26515. var navigator = window && window.navigator;
  26516. var MediaStreamTrack = window && window.MediaStreamTrack;
  26517. var shimError_ = function(e) {
  26518. return {
  26519. name: {
  26520. InternalError: 'NotReadableError',
  26521. NotSupportedError: 'TypeError',
  26522. PermissionDeniedError: 'NotAllowedError',
  26523. SecurityError: 'NotAllowedError'
  26524. }[e.name] || e.name,
  26525. message: {
  26526. 'The operation is insecure.': 'The request is not allowed by the ' +
  26527. 'user agent or the platform in the current context.'
  26528. }[e.message] || e.message,
  26529. constraint: e.constraint,
  26530. toString: function() {
  26531. return this.name + (this.message && ': ') + this.message;
  26532. }
  26533. };
  26534. };
  26535. // getUserMedia constraints shim.
  26536. var getUserMedia_ = function(constraints, onSuccess, onError) {
  26537. var constraintsToFF37_ = function(c) {
  26538. if (typeof c !== 'object' || c.require) {
  26539. return c;
  26540. }
  26541. var require = [];
  26542. Object.keys(c).forEach(function(key) {
  26543. if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
  26544. return;
  26545. }
  26546. var r = c[key] = (typeof c[key] === 'object') ?
  26547. c[key] : {ideal: c[key]};
  26548. if (r.min !== undefined ||
  26549. r.max !== undefined || r.exact !== undefined) {
  26550. require.push(key);
  26551. }
  26552. if (r.exact !== undefined) {
  26553. if (typeof r.exact === 'number') {
  26554. r. min = r.max = r.exact;
  26555. } else {
  26556. c[key] = r.exact;
  26557. }
  26558. delete r.exact;
  26559. }
  26560. if (r.ideal !== undefined) {
  26561. c.advanced = c.advanced || [];
  26562. var oc = {};
  26563. if (typeof r.ideal === 'number') {
  26564. oc[key] = {min: r.ideal, max: r.ideal};
  26565. } else {
  26566. oc[key] = r.ideal;
  26567. }
  26568. c.advanced.push(oc);
  26569. delete r.ideal;
  26570. if (!Object.keys(r).length) {
  26571. delete c[key];
  26572. }
  26573. }
  26574. });
  26575. if (require.length) {
  26576. c.require = require;
  26577. }
  26578. return c;
  26579. };
  26580. constraints = JSON.parse(JSON.stringify(constraints));
  26581. if (browserDetails.version < 38) {
  26582. logging('spec: ' + JSON.stringify(constraints));
  26583. if (constraints.audio) {
  26584. constraints.audio = constraintsToFF37_(constraints.audio);
  26585. }
  26586. if (constraints.video) {
  26587. constraints.video = constraintsToFF37_(constraints.video);
  26588. }
  26589. logging('ff37: ' + JSON.stringify(constraints));
  26590. }
  26591. return navigator.mozGetUserMedia(constraints, onSuccess, function(e) {
  26592. onError(shimError_(e));
  26593. });
  26594. };
  26595. // Returns the result of getUserMedia as a Promise.
  26596. var getUserMediaPromise_ = function(constraints) {
  26597. return new Promise(function(resolve, reject) {
  26598. getUserMedia_(constraints, resolve, reject);
  26599. });
  26600. };
  26601. // Shim for mediaDevices on older versions.
  26602. if (!navigator.mediaDevices) {
  26603. navigator.mediaDevices = {getUserMedia: getUserMediaPromise_,
  26604. addEventListener: function() { },
  26605. removeEventListener: function() { }
  26606. };
  26607. }
  26608. navigator.mediaDevices.enumerateDevices =
  26609. navigator.mediaDevices.enumerateDevices || function() {
  26610. return new Promise(function(resolve) {
  26611. var infos = [
  26612. {kind: 'audioinput', deviceId: 'default', label: '', groupId: ''},
  26613. {kind: 'videoinput', deviceId: 'default', label: '', groupId: ''}
  26614. ];
  26615. resolve(infos);
  26616. });
  26617. };
  26618. if (browserDetails.version < 41) {
  26619. // Work around http://bugzil.la/1169665
  26620. var orgEnumerateDevices =
  26621. navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices);
  26622. navigator.mediaDevices.enumerateDevices = function() {
  26623. return orgEnumerateDevices().then(undefined, function(e) {
  26624. if (e.name === 'NotFoundError') {
  26625. return [];
  26626. }
  26627. throw e;
  26628. });
  26629. };
  26630. }
  26631. if (browserDetails.version < 49) {
  26632. var origGetUserMedia = navigator.mediaDevices.getUserMedia.
  26633. bind(navigator.mediaDevices);
  26634. navigator.mediaDevices.getUserMedia = function(c) {
  26635. return origGetUserMedia(c).then(function(stream) {
  26636. // Work around https://bugzil.la/802326
  26637. if (c.audio && !stream.getAudioTracks().length ||
  26638. c.video && !stream.getVideoTracks().length) {
  26639. stream.getTracks().forEach(function(track) {
  26640. track.stop();
  26641. });
  26642. throw new DOMException('The object can not be found here.',
  26643. 'NotFoundError');
  26644. }
  26645. return stream;
  26646. }, function(e) {
  26647. return Promise.reject(shimError_(e));
  26648. });
  26649. };
  26650. }
  26651. if (!(browserDetails.version > 55 &&
  26652. 'autoGainControl' in navigator.mediaDevices.getSupportedConstraints())) {
  26653. var remap = function(obj, a, b) {
  26654. if (a in obj && !(b in obj)) {
  26655. obj[b] = obj[a];
  26656. delete obj[a];
  26657. }
  26658. };
  26659. var nativeGetUserMedia = navigator.mediaDevices.getUserMedia.
  26660. bind(navigator.mediaDevices);
  26661. navigator.mediaDevices.getUserMedia = function(c) {
  26662. if (typeof c === 'object' && typeof c.audio === 'object') {
  26663. c = JSON.parse(JSON.stringify(c));
  26664. remap(c.audio, 'autoGainControl', 'mozAutoGainControl');
  26665. remap(c.audio, 'noiseSuppression', 'mozNoiseSuppression');
  26666. }
  26667. return nativeGetUserMedia(c);
  26668. };
  26669. if (MediaStreamTrack && MediaStreamTrack.prototype.getSettings) {
  26670. var nativeGetSettings = MediaStreamTrack.prototype.getSettings;
  26671. MediaStreamTrack.prototype.getSettings = function() {
  26672. var obj = nativeGetSettings.apply(this, arguments);
  26673. remap(obj, 'mozAutoGainControl', 'autoGainControl');
  26674. remap(obj, 'mozNoiseSuppression', 'noiseSuppression');
  26675. return obj;
  26676. };
  26677. }
  26678. if (MediaStreamTrack && MediaStreamTrack.prototype.applyConstraints) {
  26679. var nativeApplyConstraints = MediaStreamTrack.prototype.applyConstraints;
  26680. MediaStreamTrack.prototype.applyConstraints = function(c) {
  26681. if (this.kind === 'audio' && typeof c === 'object') {
  26682. c = JSON.parse(JSON.stringify(c));
  26683. remap(c, 'autoGainControl', 'mozAutoGainControl');
  26684. remap(c, 'noiseSuppression', 'mozNoiseSuppression');
  26685. }
  26686. return nativeApplyConstraints.apply(this, [c]);
  26687. };
  26688. }
  26689. }
  26690. navigator.getUserMedia = function(constraints, onSuccess, onError) {
  26691. if (browserDetails.version < 44) {
  26692. return getUserMedia_(constraints, onSuccess, onError);
  26693. }
  26694. // Replace Firefox 44+'s deprecation warning with unprefixed version.
  26695. utils.deprecated('navigator.getUserMedia',
  26696. 'navigator.mediaDevices.getUserMedia');
  26697. navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
  26698. };
  26699. };
  26700. },{"../utils":50}],49:[function(require,module,exports){
  26701. /*
  26702. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  26703. *
  26704. * Use of this source code is governed by a BSD-style license
  26705. * that can be found in the LICENSE file in the root of the source
  26706. * tree.
  26707. */
  26708. 'use strict';
  26709. var utils = require('../utils');
  26710. var safariShim = {
  26711. // TODO: DrAlex, should be here, double check against LayoutTests
  26712. // TODO: once the back-end for the mac port is done, add.
  26713. // TODO: check for webkitGTK+
  26714. // shimPeerConnection: function() { },
  26715. shimLocalStreamsAPI: function(window) {
  26716. if (typeof window !== 'object' || !window.RTCPeerConnection) {
  26717. return;
  26718. }
  26719. if (!('getLocalStreams' in window.RTCPeerConnection.prototype)) {
  26720. window.RTCPeerConnection.prototype.getLocalStreams = function() {
  26721. if (!this._localStreams) {
  26722. this._localStreams = [];
  26723. }
  26724. return this._localStreams;
  26725. };
  26726. }
  26727. if (!('getStreamById' in window.RTCPeerConnection.prototype)) {
  26728. window.RTCPeerConnection.prototype.getStreamById = function(id) {
  26729. var result = null;
  26730. if (this._localStreams) {
  26731. this._localStreams.forEach(function(stream) {
  26732. if (stream.id === id) {
  26733. result = stream;
  26734. }
  26735. });
  26736. }
  26737. if (this._remoteStreams) {
  26738. this._remoteStreams.forEach(function(stream) {
  26739. if (stream.id === id) {
  26740. result = stream;
  26741. }
  26742. });
  26743. }
  26744. return result;
  26745. };
  26746. }
  26747. if (!('addStream' in window.RTCPeerConnection.prototype)) {
  26748. var _addTrack = window.RTCPeerConnection.prototype.addTrack;
  26749. window.RTCPeerConnection.prototype.addStream = function(stream) {
  26750. if (!this._localStreams) {
  26751. this._localStreams = [];
  26752. }
  26753. if (this._localStreams.indexOf(stream) === -1) {
  26754. this._localStreams.push(stream);
  26755. }
  26756. var self = this;
  26757. stream.getTracks().forEach(function(track) {
  26758. _addTrack.call(self, track, stream);
  26759. });
  26760. };
  26761. window.RTCPeerConnection.prototype.addTrack = function(track, stream) {
  26762. if (stream) {
  26763. if (!this._localStreams) {
  26764. this._localStreams = [stream];
  26765. } else if (this._localStreams.indexOf(stream) === -1) {
  26766. this._localStreams.push(stream);
  26767. }
  26768. }
  26769. return _addTrack.call(this, track, stream);
  26770. };
  26771. }
  26772. if (!('removeStream' in window.RTCPeerConnection.prototype)) {
  26773. window.RTCPeerConnection.prototype.removeStream = function(stream) {
  26774. if (!this._localStreams) {
  26775. this._localStreams = [];
  26776. }
  26777. var index = this._localStreams.indexOf(stream);
  26778. if (index === -1) {
  26779. return;
  26780. }
  26781. this._localStreams.splice(index, 1);
  26782. var self = this;
  26783. var tracks = stream.getTracks();
  26784. this.getSenders().forEach(function(sender) {
  26785. if (tracks.indexOf(sender.track) !== -1) {
  26786. self.removeTrack(sender);
  26787. }
  26788. });
  26789. };
  26790. }
  26791. },
  26792. shimRemoteStreamsAPI: function(window) {
  26793. if (typeof window !== 'object' || !window.RTCPeerConnection) {
  26794. return;
  26795. }
  26796. if (!('getRemoteStreams' in window.RTCPeerConnection.prototype)) {
  26797. window.RTCPeerConnection.prototype.getRemoteStreams = function() {
  26798. return this._remoteStreams ? this._remoteStreams : [];
  26799. };
  26800. }
  26801. if (!('onaddstream' in window.RTCPeerConnection.prototype)) {
  26802. Object.defineProperty(window.RTCPeerConnection.prototype, 'onaddstream', {
  26803. get: function() {
  26804. return this._onaddstream;
  26805. },
  26806. set: function(f) {
  26807. if (this._onaddstream) {
  26808. this.removeEventListener('addstream', this._onaddstream);
  26809. this.removeEventListener('track', this._onaddstreampoly);
  26810. }
  26811. this.addEventListener('addstream', this._onaddstream = f);
  26812. this.addEventListener('track', this._onaddstreampoly = function(e) {
  26813. var stream = e.streams[0];
  26814. if (!this._remoteStreams) {
  26815. this._remoteStreams = [];
  26816. }
  26817. if (this._remoteStreams.indexOf(stream) >= 0) {
  26818. return;
  26819. }
  26820. this._remoteStreams.push(stream);
  26821. var event = new Event('addstream');
  26822. event.stream = e.streams[0];
  26823. this.dispatchEvent(event);
  26824. }.bind(this));
  26825. }
  26826. });
  26827. }
  26828. },
  26829. shimCallbacksAPI: function(window) {
  26830. if (typeof window !== 'object' || !window.RTCPeerConnection) {
  26831. return;
  26832. }
  26833. var prototype = window.RTCPeerConnection.prototype;
  26834. var createOffer = prototype.createOffer;
  26835. var createAnswer = prototype.createAnswer;
  26836. var setLocalDescription = prototype.setLocalDescription;
  26837. var setRemoteDescription = prototype.setRemoteDescription;
  26838. var addIceCandidate = prototype.addIceCandidate;
  26839. prototype.createOffer = function(successCallback, failureCallback) {
  26840. var options = (arguments.length >= 2) ? arguments[2] : arguments[0];
  26841. var promise = createOffer.apply(this, [options]);
  26842. if (!failureCallback) {
  26843. return promise;
  26844. }
  26845. promise.then(successCallback, failureCallback);
  26846. return Promise.resolve();
  26847. };
  26848. prototype.createAnswer = function(successCallback, failureCallback) {
  26849. var options = (arguments.length >= 2) ? arguments[2] : arguments[0];
  26850. var promise = createAnswer.apply(this, [options]);
  26851. if (!failureCallback) {
  26852. return promise;
  26853. }
  26854. promise.then(successCallback, failureCallback);
  26855. return Promise.resolve();
  26856. };
  26857. var withCallback = function(description, successCallback, failureCallback) {
  26858. var promise = setLocalDescription.apply(this, [description]);
  26859. if (!failureCallback) {
  26860. return promise;
  26861. }
  26862. promise.then(successCallback, failureCallback);
  26863. return Promise.resolve();
  26864. };
  26865. prototype.setLocalDescription = withCallback;
  26866. withCallback = function(description, successCallback, failureCallback) {
  26867. var promise = setRemoteDescription.apply(this, [description]);
  26868. if (!failureCallback) {
  26869. return promise;
  26870. }
  26871. promise.then(successCallback, failureCallback);
  26872. return Promise.resolve();
  26873. };
  26874. prototype.setRemoteDescription = withCallback;
  26875. withCallback = function(candidate, successCallback, failureCallback) {
  26876. var promise = addIceCandidate.apply(this, [candidate]);
  26877. if (!failureCallback) {
  26878. return promise;
  26879. }
  26880. promise.then(successCallback, failureCallback);
  26881. return Promise.resolve();
  26882. };
  26883. prototype.addIceCandidate = withCallback;
  26884. },
  26885. shimGetUserMedia: function(window) {
  26886. var navigator = window && window.navigator;
  26887. if (!navigator.getUserMedia) {
  26888. if (navigator.webkitGetUserMedia) {
  26889. navigator.getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
  26890. } else if (navigator.mediaDevices &&
  26891. navigator.mediaDevices.getUserMedia) {
  26892. navigator.getUserMedia = function(constraints, cb, errcb) {
  26893. navigator.mediaDevices.getUserMedia(constraints)
  26894. .then(cb, errcb);
  26895. }.bind(navigator);
  26896. }
  26897. }
  26898. },
  26899. shimRTCIceServerUrls: function(window) {
  26900. // migrate from non-spec RTCIceServer.url to RTCIceServer.urls
  26901. var OrigPeerConnection = window.RTCPeerConnection;
  26902. window.RTCPeerConnection = function(pcConfig, pcConstraints) {
  26903. if (pcConfig && pcConfig.iceServers) {
  26904. var newIceServers = [];
  26905. for (var i = 0; i < pcConfig.iceServers.length; i++) {
  26906. var server = pcConfig.iceServers[i];
  26907. if (!server.hasOwnProperty('urls') &&
  26908. server.hasOwnProperty('url')) {
  26909. utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls');
  26910. server = JSON.parse(JSON.stringify(server));
  26911. server.urls = server.url;
  26912. delete server.url;
  26913. newIceServers.push(server);
  26914. } else {
  26915. newIceServers.push(pcConfig.iceServers[i]);
  26916. }
  26917. }
  26918. pcConfig.iceServers = newIceServers;
  26919. }
  26920. return new OrigPeerConnection(pcConfig, pcConstraints);
  26921. };
  26922. window.RTCPeerConnection.prototype = OrigPeerConnection.prototype;
  26923. // wrap static methods. Currently just generateCertificate.
  26924. if ('generateCertificate' in window.RTCPeerConnection) {
  26925. Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
  26926. get: function() {
  26927. return OrigPeerConnection.generateCertificate;
  26928. }
  26929. });
  26930. }
  26931. },
  26932. shimTrackEventTransceiver: function(window) {
  26933. // Add event.transceiver member over deprecated event.receiver
  26934. if (typeof window === 'object' && window.RTCPeerConnection &&
  26935. ('receiver' in window.RTCTrackEvent.prototype) &&
  26936. // can't check 'transceiver' in window.RTCTrackEvent.prototype, as it is
  26937. // defined for some reason even when window.RTCTransceiver is not.
  26938. !window.RTCTransceiver) {
  26939. Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {
  26940. get: function() {
  26941. return {receiver: this.receiver};
  26942. }
  26943. });
  26944. }
  26945. },
  26946. shimCreateOfferLegacy: function(window) {
  26947. var origCreateOffer = window.RTCPeerConnection.prototype.createOffer;
  26948. window.RTCPeerConnection.prototype.createOffer = function(offerOptions) {
  26949. var pc = this;
  26950. if (offerOptions) {
  26951. var audioTransceiver = pc.getTransceivers().find(function(transceiver) {
  26952. return transceiver.sender.track &&
  26953. transceiver.sender.track.kind === 'audio';
  26954. });
  26955. if (offerOptions.offerToReceiveAudio === false && audioTransceiver) {
  26956. if (audioTransceiver.direction === 'sendrecv') {
  26957. audioTransceiver.setDirection('sendonly');
  26958. } else if (audioTransceiver.direction === 'recvonly') {
  26959. audioTransceiver.setDirection('inactive');
  26960. }
  26961. } else if (offerOptions.offerToReceiveAudio === true &&
  26962. !audioTransceiver) {
  26963. pc.addTransceiver('audio');
  26964. }
  26965. var videoTransceiver = pc.getTransceivers().find(function(transceiver) {
  26966. return transceiver.sender.track &&
  26967. transceiver.sender.track.kind === 'video';
  26968. });
  26969. if (offerOptions.offerToReceiveVideo === false && videoTransceiver) {
  26970. if (videoTransceiver.direction === 'sendrecv') {
  26971. videoTransceiver.setDirection('sendonly');
  26972. } else if (videoTransceiver.direction === 'recvonly') {
  26973. videoTransceiver.setDirection('inactive');
  26974. }
  26975. } else if (offerOptions.offerToReceiveVideo === true &&
  26976. !videoTransceiver) {
  26977. pc.addTransceiver('video');
  26978. }
  26979. }
  26980. return origCreateOffer.apply(pc, arguments);
  26981. };
  26982. }
  26983. };
  26984. // Expose public methods.
  26985. module.exports = {
  26986. shimCallbacksAPI: safariShim.shimCallbacksAPI,
  26987. shimLocalStreamsAPI: safariShim.shimLocalStreamsAPI,
  26988. shimRemoteStreamsAPI: safariShim.shimRemoteStreamsAPI,
  26989. shimGetUserMedia: safariShim.shimGetUserMedia,
  26990. shimRTCIceServerUrls: safariShim.shimRTCIceServerUrls,
  26991. shimTrackEventTransceiver: safariShim.shimTrackEventTransceiver,
  26992. shimCreateOfferLegacy: safariShim.shimCreateOfferLegacy
  26993. // TODO
  26994. // shimPeerConnection: safariShim.shimPeerConnection
  26995. };
  26996. },{"../utils":50}],50:[function(require,module,exports){
  26997. /*
  26998. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  26999. *
  27000. * Use of this source code is governed by a BSD-style license
  27001. * that can be found in the LICENSE file in the root of the source
  27002. * tree.
  27003. */
  27004. /* eslint-env node */
  27005. 'use strict';
  27006. var logDisabled_ = true;
  27007. var deprecationWarnings_ = true;
  27008. // Utility methods.
  27009. var utils = {
  27010. disableLog: function(bool) {
  27011. if (typeof bool !== 'boolean') {
  27012. return new Error('Argument type: ' + typeof bool +
  27013. '. Please use a boolean.');
  27014. }
  27015. logDisabled_ = bool;
  27016. return (bool) ? 'adapter.js logging disabled' :
  27017. 'adapter.js logging enabled';
  27018. },
  27019. /**
  27020. * Disable or enable deprecation warnings
  27021. * @param {!boolean} bool set to true to disable warnings.
  27022. */
  27023. disableWarnings: function(bool) {
  27024. if (typeof bool !== 'boolean') {
  27025. return new Error('Argument type: ' + typeof bool +
  27026. '. Please use a boolean.');
  27027. }
  27028. deprecationWarnings_ = !bool;
  27029. return 'adapter.js deprecation warnings ' + (bool ? 'disabled' : 'enabled');
  27030. },
  27031. log: function() {
  27032. if (typeof window === 'object') {
  27033. if (logDisabled_) {
  27034. return;
  27035. }
  27036. if (typeof console !== 'undefined' && typeof console.log === 'function') {
  27037. console.log.apply(console, arguments);
  27038. }
  27039. }
  27040. },
  27041. /**
  27042. * Shows a deprecation warning suggesting the modern and spec-compatible API.
  27043. */
  27044. deprecated: function(oldMethod, newMethod) {
  27045. if (!deprecationWarnings_) {
  27046. return;
  27047. }
  27048. console.warn(oldMethod + ' is deprecated, please use ' + newMethod +
  27049. ' instead.');
  27050. },
  27051. /**
  27052. * Extract browser version out of the provided user agent string.
  27053. *
  27054. * @param {!string} uastring userAgent string.
  27055. * @param {!string} expr Regular expression used as match criteria.
  27056. * @param {!number} pos position in the version string to be returned.
  27057. * @return {!number} browser version.
  27058. */
  27059. extractVersion: function(uastring, expr, pos) {
  27060. var match = uastring.match(expr);
  27061. return match && match.length >= pos && parseInt(match[pos], 10);
  27062. },
  27063. /**
  27064. * Browser detector.
  27065. *
  27066. * @return {object} result containing browser and version
  27067. * properties.
  27068. */
  27069. detectBrowser: function(window) {
  27070. var navigator = window && window.navigator;
  27071. // Returned result object.
  27072. var result = {};
  27073. result.browser = null;
  27074. result.version = null;
  27075. // Fail early if it's not a browser
  27076. if (typeof window === 'undefined' || !window.navigator) {
  27077. result.browser = 'Not a browser.';
  27078. return result;
  27079. }
  27080. // Firefox.
  27081. if (navigator.mozGetUserMedia) {
  27082. result.browser = 'firefox';
  27083. result.version = this.extractVersion(navigator.userAgent,
  27084. /Firefox\/(\d+)\./, 1);
  27085. } else if (navigator.webkitGetUserMedia) {
  27086. // Chrome, Chromium, Webview, Opera, all use the chrome shim for now
  27087. if (window.webkitRTCPeerConnection) {
  27088. result.browser = 'chrome';
  27089. result.version = this.extractVersion(navigator.userAgent,
  27090. /Chrom(e|ium)\/(\d+)\./, 2);
  27091. } else { // Safari (in an unpublished version) or unknown webkit-based.
  27092. if (navigator.userAgent.match(/Version\/(\d+).(\d+)/)) {
  27093. result.browser = 'safari';
  27094. result.version = this.extractVersion(navigator.userAgent,
  27095. /AppleWebKit\/(\d+)\./, 1);
  27096. } else { // unknown webkit-based browser.
  27097. result.browser = 'Unsupported webkit-based browser ' +
  27098. 'with GUM support but no WebRTC support.';
  27099. return result;
  27100. }
  27101. }
  27102. } else if (navigator.mediaDevices &&
  27103. navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) { // Edge.
  27104. result.browser = 'edge';
  27105. result.version = this.extractVersion(navigator.userAgent,
  27106. /Edge\/(\d+).(\d+)$/, 2);
  27107. } else if (navigator.mediaDevices &&
  27108. navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) {
  27109. // Safari, with webkitGetUserMedia removed.
  27110. result.browser = 'safari';
  27111. result.version = this.extractVersion(navigator.userAgent,
  27112. /AppleWebKit\/(\d+)\./, 1);
  27113. } else { // Default fallthrough: not supported.
  27114. result.browser = 'Not a supported browser.';
  27115. return result;
  27116. }
  27117. return result;
  27118. },
  27119. };
  27120. // Export.
  27121. module.exports = {
  27122. log: utils.log,
  27123. deprecated: utils.deprecated,
  27124. disableLog: utils.disableLog,
  27125. disableWarnings: utils.disableWarnings,
  27126. extractVersion: utils.extractVersion,
  27127. shimCreateObjectURL: utils.shimCreateObjectURL,
  27128. detectBrowser: utils.detectBrowser.bind(utils)
  27129. };
  27130. },{}],51:[function(require,module,exports){
  27131. module.exports={
  27132. "name": "jssip",
  27133. "title": "JsSIP",
  27134. "description": "the Javascript SIP library",
  27135. "version": "3.2.4",
  27136. "homepage": "http://jssip.net",
  27137. "author": "José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)",
  27138. "contributors": [
  27139. "Iñaki Baz Castillo <ibc@aliax.net> (https://github.com/ibc)",
  27140. "Saúl Ibarra Corretgé <saghul@gmail.com> (https://github.com/saghul)"
  27141. ],
  27142. "main": "lib-es5/JsSIP.js",
  27143. "keywords": [
  27144. "sip",
  27145. "websocket",
  27146. "webrtc",
  27147. "node",
  27148. "browser",
  27149. "library"
  27150. ],
  27151. "license": "MIT",
  27152. "repository": {
  27153. "type": "git",
  27154. "url": "https://github.com/versatica/JsSIP.git"
  27155. },
  27156. "bugs": {
  27157. "url": "https://github.com/versatica/JsSIP/issues"
  27158. },
  27159. "dependencies": {
  27160. "debug": "^3.1.0",
  27161. "sdp-transform": "^2.3.1",
  27162. "webrtc-adapter": "^6.0.4"
  27163. },
  27164. "devDependencies": {
  27165. "ansi-colors": "^1.0.1",
  27166. "babel-core": "^6.26.0",
  27167. "babel-preset-env": "^1.6.1",
  27168. "browserify": "^14.5.0",
  27169. "eslint": "^4.15.0",
  27170. "fancy-log": "^1.3.2",
  27171. "gulp": "^4.0.0",
  27172. "gulp-babel": "^7.0.0",
  27173. "gulp-eslint": "^4.0.1",
  27174. "gulp-expect-file": "0.0.7",
  27175. "gulp-header": "1.8.9",
  27176. "gulp-nodeunit-runner": "^0.2.2",
  27177. "gulp-plumber": "^1.2.0",
  27178. "gulp-rename": "^1.2.2",
  27179. "gulp-uglify": "^3.0.0",
  27180. "pegjs": "^0.7.0",
  27181. "vinyl-buffer": "^1.0.1",
  27182. "vinyl-source-stream": "^2.0.0"
  27183. },
  27184. "scripts": {
  27185. "test": "gulp test",
  27186. "prepublishOnly": "gulp babel"
  27187. }
  27188. }
  27189. },{}]},{},[8])(8)
  27190. });