Bez popisu

jssip-3.0.13.js 786KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550
  1. /*
  2. * JsSIP v3.0.13
  3. * the Javascript SIP library
  4. * Copyright: 2012-2017 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. var pkg = require('../package.json');
  10. var C = {
  11. USER_AGENT: pkg.title + ' ' + pkg.version,
  12. // SIP scheme
  13. SIP: 'sip',
  14. SIPS: 'sips',
  15. // End and Failure causes
  16. causes: {
  17. // Generic error causes
  18. CONNECTION_ERROR: 'Connection Error',
  19. REQUEST_TIMEOUT: 'Request Timeout',
  20. SIP_FAILURE_CODE: 'SIP Failure Code',
  21. INTERNAL_ERROR: 'Internal Error',
  22. // SIP error causes
  23. BUSY: 'Busy',
  24. REJECTED: 'Rejected',
  25. REDIRECTED: 'Redirected',
  26. UNAVAILABLE: 'Unavailable',
  27. NOT_FOUND: 'Not Found',
  28. ADDRESS_INCOMPLETE: 'Address Incomplete',
  29. INCOMPATIBLE_SDP: 'Incompatible SDP',
  30. MISSING_SDP: 'Missing SDP',
  31. AUTHENTICATION_ERROR: 'Authentication Error',
  32. // Session error causes
  33. BYE: 'Terminated',
  34. WEBRTC_ERROR: 'WebRTC Error',
  35. CANCELED: 'Canceled',
  36. NO_ANSWER: 'No Answer',
  37. EXPIRES: 'Expires',
  38. NO_ACK: 'No ACK',
  39. DIALOG_ERROR: 'Dialog Error',
  40. USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access',
  41. BAD_MEDIA_DESCRIPTION: 'Bad Media Description',
  42. RTP_TIMEOUT: 'RTP Timeout'
  43. },
  44. SIP_ERROR_CAUSES: {
  45. REDIRECTED: [300,301,302,305,380],
  46. BUSY: [486,600],
  47. REJECTED: [403,603],
  48. NOT_FOUND: [404,604],
  49. UNAVAILABLE: [480,410,408,430],
  50. ADDRESS_INCOMPLETE: [484, 424],
  51. INCOMPATIBLE_SDP: [488,606],
  52. AUTHENTICATION_ERROR:[401,407]
  53. },
  54. // SIP Methods
  55. ACK: 'ACK',
  56. BYE: 'BYE',
  57. CANCEL: 'CANCEL',
  58. INFO: 'INFO',
  59. INVITE: 'INVITE',
  60. MESSAGE: 'MESSAGE',
  61. NOTIFY: 'NOTIFY',
  62. OPTIONS: 'OPTIONS',
  63. REGISTER: 'REGISTER',
  64. REFER: 'REFER',
  65. UPDATE: 'UPDATE',
  66. SUBSCRIBE: 'SUBSCRIBE',
  67. /* SIP Response Reasons
  68. * DOC: http://www.iana.org/assignments/sip-parameters
  69. * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7
  70. */
  71. REASON_PHRASE: {
  72. 100: 'Trying',
  73. 180: 'Ringing',
  74. 181: 'Call Is Being Forwarded',
  75. 182: 'Queued',
  76. 183: 'Session Progress',
  77. 199: 'Early Dialog Terminated', // draft-ietf-sipcore-199
  78. 200: 'OK',
  79. 202: 'Accepted', // RFC 3265
  80. 204: 'No Notification', //RFC 5839
  81. 300: 'Multiple Choices',
  82. 301: 'Moved Permanently',
  83. 302: 'Moved Temporarily',
  84. 305: 'Use Proxy',
  85. 380: 'Alternative Service',
  86. 400: 'Bad Request',
  87. 401: 'Unauthorized',
  88. 402: 'Payment Required',
  89. 403: 'Forbidden',
  90. 404: 'Not Found',
  91. 405: 'Method Not Allowed',
  92. 406: 'Not Acceptable',
  93. 407: 'Proxy Authentication Required',
  94. 408: 'Request Timeout',
  95. 410: 'Gone',
  96. 412: 'Conditional Request Failed', // RFC 3903
  97. 413: 'Request Entity Too Large',
  98. 414: 'Request-URI Too Long',
  99. 415: 'Unsupported Media Type',
  100. 416: 'Unsupported URI Scheme',
  101. 417: 'Unknown Resource-Priority', // RFC 4412
  102. 420: 'Bad Extension',
  103. 421: 'Extension Required',
  104. 422: 'Session Interval Too Small', // RFC 4028
  105. 423: 'Interval Too Brief',
  106. 424: 'Bad Location Information', // RFC 6442
  107. 428: 'Use Identity Header', // RFC 4474
  108. 429: 'Provide Referrer Identity', // RFC 3892
  109. 430: 'Flow Failed', // RFC 5626
  110. 433: 'Anonymity Disallowed', // RFC 5079
  111. 436: 'Bad Identity-Info', // RFC 4474
  112. 437: 'Unsupported Certificate', // RFC 4744
  113. 438: 'Invalid Identity Header', // RFC 4744
  114. 439: 'First Hop Lacks Outbound Support', // RFC 5626
  115. 440: 'Max-Breadth Exceeded', // RFC 5393
  116. 469: 'Bad Info Package', // draft-ietf-sipcore-info-events
  117. 470: 'Consent Needed', // RFC 5360
  118. 478: 'Unresolvable Destination', // Custom code copied from Kamailio.
  119. 480: 'Temporarily Unavailable',
  120. 481: 'Call/Transaction Does Not Exist',
  121. 482: 'Loop Detected',
  122. 483: 'Too Many Hops',
  123. 484: 'Address Incomplete',
  124. 485: 'Ambiguous',
  125. 486: 'Busy Here',
  126. 487: 'Request Terminated',
  127. 488: 'Not Acceptable Here',
  128. 489: 'Bad Event', // RFC 3265
  129. 491: 'Request Pending',
  130. 493: 'Undecipherable',
  131. 494: 'Security Agreement Required', // RFC 3329
  132. 500: 'JsSIP Internal Error',
  133. 501: 'Not Implemented',
  134. 502: 'Bad Gateway',
  135. 503: 'Service Unavailable',
  136. 504: 'Server Time-out',
  137. 505: 'Version Not Supported',
  138. 513: 'Message Too Large',
  139. 580: 'Precondition Failure', // RFC 3312
  140. 600: 'Busy Everywhere',
  141. 603: 'Decline',
  142. 604: 'Does Not Exist Anywhere',
  143. 606: 'Not Acceptable'
  144. },
  145. ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO',
  146. ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay',
  147. MAX_FORWARDS: 69,
  148. SESSION_EXPIRES: 90,
  149. MIN_SESSION_EXPIRES: 60
  150. };
  151. module.exports = C;
  152. },{"../package.json":51}],2:[function(require,module,exports){
  153. module.exports = Dialog;
  154. var C = {
  155. // Dialog states
  156. STATUS_EARLY: 1,
  157. STATUS_CONFIRMED: 2
  158. };
  159. /**
  160. * Expose C object.
  161. */
  162. Dialog.C = C;
  163. /**
  164. * Dependencies.
  165. */
  166. var debug = require('debug')('JsSIP:Dialog');
  167. var SIPMessage = require('./SIPMessage');
  168. var JsSIP_C = require('./Constants');
  169. var Transactions = require('./Transactions');
  170. var Dialog_RequestSender = require('./Dialog/RequestSender');
  171. // RFC 3261 12.1
  172. function Dialog(owner, message, type, state) {
  173. var contact;
  174. this.uac_pending_reply = false;
  175. this.uas_pending_reply = false;
  176. if(!message.hasHeader('contact')) {
  177. return {
  178. error: 'unable to create a Dialog without Contact header field'
  179. };
  180. }
  181. if(message instanceof SIPMessage.IncomingResponse) {
  182. state = (message.status_code < 200) ? C.STATUS_EARLY : C.STATUS_CONFIRMED;
  183. } else {
  184. // Create confirmed dialog if state is not defined
  185. state = state || C.STATUS_CONFIRMED;
  186. }
  187. contact = message.parseHeader('contact');
  188. // RFC 3261 12.1.1
  189. if(type === 'UAS') {
  190. this.id = {
  191. call_id: message.call_id,
  192. local_tag: message.to_tag,
  193. remote_tag: message.from_tag,
  194. toString: function() {
  195. return this.call_id + this.local_tag + this.remote_tag;
  196. }
  197. };
  198. this.state = state;
  199. this.remote_seqnum = message.cseq;
  200. this.local_uri = message.parseHeader('to').uri;
  201. this.remote_uri = message.parseHeader('from').uri;
  202. this.remote_target = contact.uri;
  203. this.route_set = message.getHeaders('record-route');
  204. }
  205. // RFC 3261 12.1.2
  206. else if(type === 'UAC') {
  207. this.id = {
  208. call_id: message.call_id,
  209. local_tag: message.from_tag,
  210. remote_tag: message.to_tag,
  211. toString: function() {
  212. return this.call_id + this.local_tag + this.remote_tag;
  213. }
  214. };
  215. this.state = state;
  216. this.local_seqnum = message.cseq;
  217. this.local_uri = message.parseHeader('from').uri;
  218. this.remote_uri = message.parseHeader('to').uri;
  219. this.remote_target = contact.uri;
  220. this.route_set = message.getHeaders('record-route').reverse();
  221. }
  222. this.owner = owner;
  223. owner.ua.dialogs[this.id.toString()] = this;
  224. debug('new ' + type + ' dialog created with status ' + (this.state === C.STATUS_EARLY ? 'EARLY': 'CONFIRMED'));
  225. }
  226. Dialog.prototype = {
  227. update: function(message, type) {
  228. this.state = C.STATUS_CONFIRMED;
  229. debug('dialog '+ this.id.toString() +' changed to CONFIRMED state');
  230. if(type === 'UAC') {
  231. // RFC 3261 13.2.2.4
  232. this.route_set = message.getHeaders('record-route').reverse();
  233. }
  234. },
  235. terminate: function() {
  236. debug('dialog ' + this.id.toString() + ' deleted');
  237. delete this.owner.ua.dialogs[this.id.toString()];
  238. },
  239. // RFC 3261 12.2.1.1
  240. createRequest: function(method, extraHeaders, body) {
  241. var cseq, request;
  242. extraHeaders = extraHeaders && extraHeaders.slice() || [];
  243. if(!this.local_seqnum) { this.local_seqnum = Math.floor(Math.random() * 10000); }
  244. cseq = (method === JsSIP_C.CANCEL || method === JsSIP_C.ACK) ? this.local_seqnum : this.local_seqnum += 1;
  245. request = new SIPMessage.OutgoingRequest(
  246. method,
  247. this.remote_target,
  248. this.owner.ua, {
  249. 'cseq': cseq,
  250. 'call_id': this.id.call_id,
  251. 'from_uri': this.local_uri,
  252. 'from_tag': this.id.local_tag,
  253. 'to_uri': this.remote_uri,
  254. 'to_tag': this.id.remote_tag,
  255. 'route_set': this.route_set
  256. }, extraHeaders, body);
  257. request.dialog = this;
  258. return request;
  259. },
  260. // RFC 3261 12.2.2
  261. checkInDialogRequest: function(request) {
  262. var self = this;
  263. if(!this.remote_seqnum) {
  264. this.remote_seqnum = request.cseq;
  265. } else if(request.cseq < this.remote_seqnum) {
  266. //Do not try to reply to an ACK request.
  267. if (request.method !== JsSIP_C.ACK) {
  268. request.reply(500);
  269. }
  270. return false;
  271. } else if(request.cseq > this.remote_seqnum) {
  272. this.remote_seqnum = request.cseq;
  273. }
  274. // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-
  275. if (request.method === JsSIP_C.INVITE || (request.method === JsSIP_C.UPDATE && request.body)) {
  276. if (this.uac_pending_reply === true) {
  277. request.reply(491);
  278. } else if (this.uas_pending_reply === true) {
  279. var retryAfter = (Math.random() * 10 | 0) + 1;
  280. request.reply(500, null, ['Retry-After:'+ retryAfter]);
  281. return false;
  282. } else {
  283. this.uas_pending_reply = true;
  284. request.server_transaction.on('stateChanged', function stateChanged(){
  285. if (this.state === Transactions.C.STATUS_ACCEPTED ||
  286. this.state === Transactions.C.STATUS_COMPLETED ||
  287. this.state === Transactions.C.STATUS_TERMINATED) {
  288. request.server_transaction.removeListener('stateChanged', stateChanged);
  289. self.uas_pending_reply = false;
  290. }
  291. });
  292. }
  293. // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted
  294. if(request.hasHeader('contact')) {
  295. request.server_transaction.on('stateChanged', function(){
  296. if (this.state === Transactions.C.STATUS_ACCEPTED) {
  297. self.remote_target = request.parseHeader('contact').uri;
  298. }
  299. });
  300. }
  301. }
  302. else if (request.method === JsSIP_C.NOTIFY) {
  303. // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted
  304. if(request.hasHeader('contact')) {
  305. request.server_transaction.on('stateChanged', function(){
  306. if (this.state === Transactions.C.STATUS_COMPLETED) {
  307. self.remote_target = request.parseHeader('contact').uri;
  308. }
  309. });
  310. }
  311. }
  312. return true;
  313. },
  314. sendRequest: function(applicant, method, options) {
  315. options = options || {};
  316. var
  317. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
  318. body = options.body || null,
  319. request = this.createRequest(method, extraHeaders, body),
  320. request_sender = new Dialog_RequestSender(this, applicant, request);
  321. request_sender.send();
  322. // Return the instance of OutgoingRequest
  323. return request;
  324. },
  325. receiveRequest: function(request) {
  326. //Check in-dialog request
  327. if(!this.checkInDialogRequest(request)) {
  328. return;
  329. }
  330. this.owner.receiveRequest(request);
  331. }
  332. };
  333. },{"./Constants":1,"./Dialog/RequestSender":3,"./SIPMessage":19,"./Transactions":22,"debug":35}],3:[function(require,module,exports){
  334. module.exports = DialogRequestSender;
  335. /**
  336. * Dependencies.
  337. */
  338. var JsSIP_C = require('../Constants');
  339. var Transactions = require('../Transactions');
  340. var RTCSession = require('../RTCSession');
  341. var RequestSender = require('../RequestSender');
  342. function DialogRequestSender(dialog, applicant, request) {
  343. this.dialog = dialog;
  344. this.applicant = applicant;
  345. this.request = request;
  346. // RFC3261 14.1 Modifying an Existing Session. UAC Behavior.
  347. this.reattempt = false;
  348. this.reattemptTimer = null;
  349. }
  350. DialogRequestSender.prototype = {
  351. send: function() {
  352. var
  353. self = this,
  354. request_sender = new RequestSender(this, this.dialog.owner.ua);
  355. request_sender.send();
  356. // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-
  357. if ((this.request.method === JsSIP_C.INVITE || (this.request.method === JsSIP_C.UPDATE && this.request.body)) &&
  358. request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) {
  359. this.dialog.uac_pending_reply = true;
  360. request_sender.clientTransaction.on('stateChanged', function stateChanged(){
  361. if (this.state === Transactions.C.STATUS_ACCEPTED ||
  362. this.state === Transactions.C.STATUS_COMPLETED ||
  363. this.state === Transactions.C.STATUS_TERMINATED) {
  364. request_sender.clientTransaction.removeListener('stateChanged', stateChanged);
  365. self.dialog.uac_pending_reply = false;
  366. }
  367. });
  368. }
  369. },
  370. onRequestTimeout: function() {
  371. this.applicant.onRequestTimeout();
  372. },
  373. onTransportError: function() {
  374. this.applicant.onTransportError();
  375. },
  376. receiveResponse: function(response) {
  377. var self = this;
  378. // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog.
  379. if (response.status_code === 408 || response.status_code === 481) {
  380. this.applicant.onDialogError(response);
  381. } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) {
  382. if (this.reattempt) {
  383. this.applicant.receiveResponse(response);
  384. } else {
  385. this.request.cseq.value = this.dialog.local_seqnum += 1;
  386. this.reattemptTimer = setTimeout(function() {
  387. if (self.applicant.owner.status !== RTCSession.C.STATUS_TERMINATED) {
  388. self.reattempt = true;
  389. self.request_sender.send();
  390. }
  391. }, 1000);
  392. }
  393. } else {
  394. this.applicant.receiveResponse(response);
  395. }
  396. }
  397. };
  398. },{"../Constants":1,"../RTCSession":11,"../RequestSender":18,"../Transactions":22}],4:[function(require,module,exports){
  399. module.exports = DigestAuthentication;
  400. /**
  401. * Dependencies.
  402. */
  403. var debug = require('debug')('JsSIP:DigestAuthentication');
  404. var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication');
  405. debugerror.log = console.warn.bind(console);
  406. var Utils = require('./Utils');
  407. function DigestAuthentication(credentials) {
  408. this.credentials = credentials;
  409. this.cnonce = null;
  410. this.nc = 0;
  411. this.ncHex = '00000000';
  412. this.algorithm = null;
  413. this.realm = null;
  414. this.nonce = null;
  415. this.opaque = null;
  416. this.stale = null;
  417. this.qop = null;
  418. this.method = null;
  419. this.uri = null;
  420. this.ha1 = null;
  421. this.response = null;
  422. }
  423. DigestAuthentication.prototype.get = function(parameter) {
  424. switch (parameter) {
  425. case 'realm':
  426. return this.realm;
  427. case 'ha1':
  428. return this.ha1;
  429. default:
  430. debugerror('get() | cannot get "%s" parameter', parameter);
  431. return undefined;
  432. }
  433. };
  434. /**
  435. * Performs Digest authentication given a SIP request and the challenge
  436. * received in a response to that request.
  437. * Returns true if auth was successfully generated, false otherwise.
  438. */
  439. DigestAuthentication.prototype.authenticate = function(request, challenge) {
  440. var ha2, hex;
  441. this.algorithm = challenge.algorithm;
  442. this.realm = challenge.realm;
  443. this.nonce = challenge.nonce;
  444. this.opaque = challenge.opaque;
  445. this.stale = challenge.stale;
  446. if (this.algorithm) {
  447. if (this.algorithm !== 'MD5') {
  448. debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');
  449. return false;
  450. }
  451. } else {
  452. this.algorithm = 'MD5';
  453. }
  454. if (!this.nonce) {
  455. debugerror('authenticate() | challenge without Digest nonce, authentication aborted');
  456. return false;
  457. }
  458. if (!this.realm) {
  459. debugerror('authenticate() | challenge without Digest realm, authentication aborted');
  460. return false;
  461. }
  462. // If no plain SIP password is provided.
  463. if (!this.credentials.password) {
  464. // If ha1 is not provided we cannot authenticate.
  465. if (!this.credentials.ha1) {
  466. debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted');
  467. return false;
  468. }
  469. // If the realm does not match the stored realm we cannot authenticate.
  470. if (this.credentials.realm !== this.realm) {
  471. 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);
  472. return false;
  473. }
  474. }
  475. // 'qop' can contain a list of values (Array). Let's choose just one.
  476. if (challenge.qop) {
  477. if (challenge.qop.indexOf('auth') > -1) {
  478. this.qop = 'auth';
  479. } else if (challenge.qop.indexOf('auth-int') > -1) {
  480. this.qop = 'auth-int';
  481. } else {
  482. // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here.
  483. debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');
  484. return false;
  485. }
  486. } else {
  487. this.qop = null;
  488. }
  489. // Fill other attributes.
  490. this.method = request.method;
  491. this.uri = request.ruri;
  492. this.cnonce = Utils.createRandomToken(12);
  493. this.nc += 1;
  494. hex = Number(this.nc).toString(16);
  495. this.ncHex = '00000000'.substr(0, 8-hex.length) + hex;
  496. // nc-value = 8LHEX. Max value = 'FFFFFFFF'.
  497. if (this.nc === 4294967296) {
  498. this.nc = 1;
  499. this.ncHex = '00000001';
  500. }
  501. // Calculate the Digest "response" value.
  502. // If we have plain SIP password then regenerate ha1.
  503. if (this.credentials.password) {
  504. // HA1 = MD5(A1) = MD5(username:realm:password)
  505. this.ha1 = Utils.calculateMD5(this.credentials.username + ':' + this.realm + ':' + this.credentials.password);
  506. //
  507. // Otherwise reuse the stored ha1.
  508. } else {
  509. this.ha1 = this.credentials.ha1;
  510. }
  511. if (this.qop === 'auth') {
  512. // HA2 = MD5(A2) = MD5(method:digestURI)
  513. ha2 = Utils.calculateMD5(this.method + ':' + this.uri);
  514. // response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2)
  515. this.response = Utils.calculateMD5(this.ha1 + ':' + this.nonce + ':' + this.ncHex + ':' + this.cnonce + ':auth:' + ha2);
  516. } else if (this.qop === 'auth-int') {
  517. // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody))
  518. ha2 = Utils.calculateMD5(this.method + ':' + this.uri + ':' + Utils.calculateMD5(this.body ? this.body : ''));
  519. // response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2)
  520. this.response = Utils.calculateMD5(this.ha1 + ':' + this.nonce + ':' + this.ncHex + ':' + this.cnonce + ':auth-int:' + ha2);
  521. } else if (this.qop === null) {
  522. // HA2 = MD5(A2) = MD5(method:digestURI)
  523. ha2 = Utils.calculateMD5(this.method + ':' + this.uri);
  524. // response = MD5(HA1:nonce:HA2)
  525. this.response = Utils.calculateMD5(this.ha1 + ':' + this.nonce + ':' + ha2);
  526. }
  527. debug('authenticate() | response generated');
  528. return true;
  529. };
  530. /**
  531. * Return the Proxy-Authorization or WWW-Authorization header value.
  532. */
  533. DigestAuthentication.prototype.toString = function() {
  534. var auth_params = [];
  535. if (!this.response) {
  536. throw new Error('response field does not exist, cannot generate Authorization header');
  537. }
  538. auth_params.push('algorithm=' + this.algorithm);
  539. auth_params.push('username="' + this.credentials.username + '"');
  540. auth_params.push('realm="' + this.realm + '"');
  541. auth_params.push('nonce="' + this.nonce + '"');
  542. auth_params.push('uri="' + this.uri + '"');
  543. auth_params.push('response="' + this.response + '"');
  544. if (this.opaque) {
  545. auth_params.push('opaque="' + this.opaque + '"');
  546. }
  547. if (this.qop) {
  548. auth_params.push('qop=' + this.qop);
  549. auth_params.push('cnonce="' + this.cnonce + '"');
  550. auth_params.push('nc=' + this.ncHex);
  551. }
  552. return 'Digest ' + auth_params.join(', ');
  553. };
  554. },{"./Utils":26,"debug":35}],5:[function(require,module,exports){
  555. /**
  556. * @namespace Exceptions
  557. * @memberOf JsSIP
  558. */
  559. var Exceptions = {
  560. /**
  561. * Exception thrown when a valid parameter is given to the JsSIP.UA constructor.
  562. * @class ConfigurationError
  563. * @memberOf JsSIP.Exceptions
  564. */
  565. ConfigurationError: (function(){
  566. var exception = function(parameter, value) {
  567. this.code = 1;
  568. this.name = 'CONFIGURATION_ERROR';
  569. this.parameter = parameter;
  570. this.value = value;
  571. this.message = (!this.value)? 'Missing parameter: '+ this.parameter : 'Invalid value '+ JSON.stringify(this.value) +' for parameter "'+ this.parameter +'"';
  572. };
  573. exception.prototype = new Error();
  574. return exception;
  575. }()),
  576. InvalidStateError: (function(){
  577. var exception = function(status) {
  578. this.code = 2;
  579. this.name = 'INVALID_STATE_ERROR';
  580. this.status = status;
  581. this.message = 'Invalid status: '+ status;
  582. };
  583. exception.prototype = new Error();
  584. return exception;
  585. }()),
  586. NotSupportedError: (function(){
  587. var exception = function(message) {
  588. this.code = 3;
  589. this.name = 'NOT_SUPPORTED_ERROR';
  590. this.message = message;
  591. };
  592. exception.prototype = new Error();
  593. return exception;
  594. }()),
  595. NotReadyError: (function(){
  596. var exception = function(message) {
  597. this.code = 4;
  598. this.name = 'NOT_READY_ERROR';
  599. this.message = message;
  600. };
  601. exception.prototype = new Error();
  602. return exception;
  603. }())
  604. };
  605. module.exports = Exceptions;
  606. },{}],6:[function(require,module,exports){
  607. module.exports = (function(){
  608. /*
  609. * Generated by PEG.js 0.7.0.
  610. *
  611. * http://pegjs.majda.cz/
  612. */
  613. function quote(s) {
  614. /*
  615. * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
  616. * string literal except for the closing quote character, backslash,
  617. * carriage return, line separator, paragraph separator, and line feed.
  618. * Any character may appear in the form of an escape sequence.
  619. *
  620. * For portability, we also escape escape all control and non-ASCII
  621. * characters. Note that "\0" and "\v" escape sequences are not used
  622. * because JSHint does not like the first and IE the second.
  623. */
  624. return '"' + s
  625. .replace(/\\/g, '\\\\') // backslash
  626. .replace(/"/g, '\\"') // closing quote character
  627. .replace(/\x08/g, '\\b') // backspace
  628. .replace(/\t/g, '\\t') // horizontal tab
  629. .replace(/\n/g, '\\n') // line feed
  630. .replace(/\f/g, '\\f') // form feed
  631. .replace(/\r/g, '\\r') // carriage return
  632. .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape)
  633. + '"';
  634. }
  635. var result = {
  636. /*
  637. * Parses the input with a generated parser. If the parsing is successfull,
  638. * returns a value explicitly or implicitly specified by the grammar from
  639. * which the parser was generated (see |PEG.buildParser|). If the parsing is
  640. * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
  641. */
  642. parse: function(input, startRule) {
  643. var parseFunctions = {
  644. "CRLF": parse_CRLF,
  645. "DIGIT": parse_DIGIT,
  646. "ALPHA": parse_ALPHA,
  647. "HEXDIG": parse_HEXDIG,
  648. "WSP": parse_WSP,
  649. "OCTET": parse_OCTET,
  650. "DQUOTE": parse_DQUOTE,
  651. "SP": parse_SP,
  652. "HTAB": parse_HTAB,
  653. "alphanum": parse_alphanum,
  654. "reserved": parse_reserved,
  655. "unreserved": parse_unreserved,
  656. "mark": parse_mark,
  657. "escaped": parse_escaped,
  658. "LWS": parse_LWS,
  659. "SWS": parse_SWS,
  660. "HCOLON": parse_HCOLON,
  661. "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM,
  662. "TEXT_UTF8char": parse_TEXT_UTF8char,
  663. "UTF8_NONASCII": parse_UTF8_NONASCII,
  664. "UTF8_CONT": parse_UTF8_CONT,
  665. "LHEX": parse_LHEX,
  666. "token": parse_token,
  667. "token_nodot": parse_token_nodot,
  668. "separators": parse_separators,
  669. "word": parse_word,
  670. "STAR": parse_STAR,
  671. "SLASH": parse_SLASH,
  672. "EQUAL": parse_EQUAL,
  673. "LPAREN": parse_LPAREN,
  674. "RPAREN": parse_RPAREN,
  675. "RAQUOT": parse_RAQUOT,
  676. "LAQUOT": parse_LAQUOT,
  677. "COMMA": parse_COMMA,
  678. "SEMI": parse_SEMI,
  679. "COLON": parse_COLON,
  680. "LDQUOT": parse_LDQUOT,
  681. "RDQUOT": parse_RDQUOT,
  682. "comment": parse_comment,
  683. "ctext": parse_ctext,
  684. "quoted_string": parse_quoted_string,
  685. "quoted_string_clean": parse_quoted_string_clean,
  686. "qdtext": parse_qdtext,
  687. "quoted_pair": parse_quoted_pair,
  688. "SIP_URI_noparams": parse_SIP_URI_noparams,
  689. "SIP_URI": parse_SIP_URI,
  690. "uri_scheme": parse_uri_scheme,
  691. "uri_scheme_sips": parse_uri_scheme_sips,
  692. "uri_scheme_sip": parse_uri_scheme_sip,
  693. "userinfo": parse_userinfo,
  694. "user": parse_user,
  695. "user_unreserved": parse_user_unreserved,
  696. "password": parse_password,
  697. "hostport": parse_hostport,
  698. "host": parse_host,
  699. "hostname": parse_hostname,
  700. "domainlabel": parse_domainlabel,
  701. "toplabel": parse_toplabel,
  702. "IPv6reference": parse_IPv6reference,
  703. "IPv6address": parse_IPv6address,
  704. "h16": parse_h16,
  705. "ls32": parse_ls32,
  706. "IPv4address": parse_IPv4address,
  707. "dec_octet": parse_dec_octet,
  708. "port": parse_port,
  709. "uri_parameters": parse_uri_parameters,
  710. "uri_parameter": parse_uri_parameter,
  711. "transport_param": parse_transport_param,
  712. "user_param": parse_user_param,
  713. "method_param": parse_method_param,
  714. "ttl_param": parse_ttl_param,
  715. "maddr_param": parse_maddr_param,
  716. "lr_param": parse_lr_param,
  717. "other_param": parse_other_param,
  718. "pname": parse_pname,
  719. "pvalue": parse_pvalue,
  720. "paramchar": parse_paramchar,
  721. "param_unreserved": parse_param_unreserved,
  722. "headers": parse_headers,
  723. "header": parse_header,
  724. "hname": parse_hname,
  725. "hvalue": parse_hvalue,
  726. "hnv_unreserved": parse_hnv_unreserved,
  727. "Request_Response": parse_Request_Response,
  728. "Request_Line": parse_Request_Line,
  729. "Request_URI": parse_Request_URI,
  730. "absoluteURI": parse_absoluteURI,
  731. "hier_part": parse_hier_part,
  732. "net_path": parse_net_path,
  733. "abs_path": parse_abs_path,
  734. "opaque_part": parse_opaque_part,
  735. "uric": parse_uric,
  736. "uric_no_slash": parse_uric_no_slash,
  737. "path_segments": parse_path_segments,
  738. "segment": parse_segment,
  739. "param": parse_param,
  740. "pchar": parse_pchar,
  741. "scheme": parse_scheme,
  742. "authority": parse_authority,
  743. "srvr": parse_srvr,
  744. "reg_name": parse_reg_name,
  745. "query": parse_query,
  746. "SIP_Version": parse_SIP_Version,
  747. "INVITEm": parse_INVITEm,
  748. "ACKm": parse_ACKm,
  749. "OPTIONSm": parse_OPTIONSm,
  750. "BYEm": parse_BYEm,
  751. "CANCELm": parse_CANCELm,
  752. "REGISTERm": parse_REGISTERm,
  753. "SUBSCRIBEm": parse_SUBSCRIBEm,
  754. "NOTIFYm": parse_NOTIFYm,
  755. "REFERm": parse_REFERm,
  756. "Method": parse_Method,
  757. "Status_Line": parse_Status_Line,
  758. "Status_Code": parse_Status_Code,
  759. "extension_code": parse_extension_code,
  760. "Reason_Phrase": parse_Reason_Phrase,
  761. "Allow_Events": parse_Allow_Events,
  762. "Call_ID": parse_Call_ID,
  763. "Contact": parse_Contact,
  764. "contact_param": parse_contact_param,
  765. "name_addr": parse_name_addr,
  766. "display_name": parse_display_name,
  767. "contact_params": parse_contact_params,
  768. "c_p_q": parse_c_p_q,
  769. "c_p_expires": parse_c_p_expires,
  770. "delta_seconds": parse_delta_seconds,
  771. "qvalue": parse_qvalue,
  772. "generic_param": parse_generic_param,
  773. "gen_value": parse_gen_value,
  774. "Content_Disposition": parse_Content_Disposition,
  775. "disp_type": parse_disp_type,
  776. "disp_param": parse_disp_param,
  777. "handling_param": parse_handling_param,
  778. "Content_Encoding": parse_Content_Encoding,
  779. "Content_Length": parse_Content_Length,
  780. "Content_Type": parse_Content_Type,
  781. "media_type": parse_media_type,
  782. "m_type": parse_m_type,
  783. "discrete_type": parse_discrete_type,
  784. "composite_type": parse_composite_type,
  785. "extension_token": parse_extension_token,
  786. "x_token": parse_x_token,
  787. "m_subtype": parse_m_subtype,
  788. "m_parameter": parse_m_parameter,
  789. "m_value": parse_m_value,
  790. "CSeq": parse_CSeq,
  791. "CSeq_value": parse_CSeq_value,
  792. "Expires": parse_Expires,
  793. "Event": parse_Event,
  794. "event_type": parse_event_type,
  795. "From": parse_From,
  796. "from_param": parse_from_param,
  797. "tag_param": parse_tag_param,
  798. "Max_Forwards": parse_Max_Forwards,
  799. "Min_Expires": parse_Min_Expires,
  800. "Name_Addr_Header": parse_Name_Addr_Header,
  801. "Proxy_Authenticate": parse_Proxy_Authenticate,
  802. "challenge": parse_challenge,
  803. "other_challenge": parse_other_challenge,
  804. "auth_param": parse_auth_param,
  805. "digest_cln": parse_digest_cln,
  806. "realm": parse_realm,
  807. "realm_value": parse_realm_value,
  808. "domain": parse_domain,
  809. "URI": parse_URI,
  810. "nonce": parse_nonce,
  811. "nonce_value": parse_nonce_value,
  812. "opaque": parse_opaque,
  813. "stale": parse_stale,
  814. "algorithm": parse_algorithm,
  815. "qop_options": parse_qop_options,
  816. "qop_value": parse_qop_value,
  817. "Proxy_Require": parse_Proxy_Require,
  818. "Record_Route": parse_Record_Route,
  819. "rec_route": parse_rec_route,
  820. "Reason": parse_Reason,
  821. "reason_param": parse_reason_param,
  822. "reason_cause": parse_reason_cause,
  823. "Require": parse_Require,
  824. "Route": parse_Route,
  825. "route_param": parse_route_param,
  826. "Subscription_State": parse_Subscription_State,
  827. "substate_value": parse_substate_value,
  828. "subexp_params": parse_subexp_params,
  829. "event_reason_value": parse_event_reason_value,
  830. "Subject": parse_Subject,
  831. "Supported": parse_Supported,
  832. "To": parse_To,
  833. "to_param": parse_to_param,
  834. "Via": parse_Via,
  835. "via_param": parse_via_param,
  836. "via_params": parse_via_params,
  837. "via_ttl": parse_via_ttl,
  838. "via_maddr": parse_via_maddr,
  839. "via_received": parse_via_received,
  840. "via_branch": parse_via_branch,
  841. "response_port": parse_response_port,
  842. "sent_protocol": parse_sent_protocol,
  843. "protocol_name": parse_protocol_name,
  844. "transport": parse_transport,
  845. "sent_by": parse_sent_by,
  846. "via_host": parse_via_host,
  847. "via_port": parse_via_port,
  848. "ttl": parse_ttl,
  849. "WWW_Authenticate": parse_WWW_Authenticate,
  850. "Session_Expires": parse_Session_Expires,
  851. "s_e_expires": parse_s_e_expires,
  852. "s_e_params": parse_s_e_params,
  853. "s_e_refresher": parse_s_e_refresher,
  854. "extension_header": parse_extension_header,
  855. "header_value": parse_header_value,
  856. "message_body": parse_message_body,
  857. "uuid_URI": parse_uuid_URI,
  858. "uuid": parse_uuid,
  859. "hex4": parse_hex4,
  860. "hex8": parse_hex8,
  861. "hex12": parse_hex12,
  862. "Refer_To": parse_Refer_To,
  863. "Replaces": parse_Replaces,
  864. "call_id": parse_call_id,
  865. "replaces_param": parse_replaces_param,
  866. "to_tag": parse_to_tag,
  867. "from_tag": parse_from_tag,
  868. "early_flag": parse_early_flag
  869. };
  870. if (startRule !== undefined) {
  871. if (parseFunctions[startRule] === undefined) {
  872. throw new Error("Invalid rule name: " + quote(startRule) + ".");
  873. }
  874. } else {
  875. startRule = "CRLF";
  876. }
  877. var pos = 0;
  878. var reportFailures = 0;
  879. var rightmostFailuresPos = 0;
  880. var rightmostFailuresExpected = [];
  881. function padLeft(input, padding, length) {
  882. var result = input;
  883. var padLength = length - input.length;
  884. for (var i = 0; i < padLength; i++) {
  885. result = padding + result;
  886. }
  887. return result;
  888. }
  889. function escape(ch) {
  890. var charCode = ch.charCodeAt(0);
  891. var escapeChar;
  892. var length;
  893. if (charCode <= 0xFF) {
  894. escapeChar = 'x';
  895. length = 2;
  896. } else {
  897. escapeChar = 'u';
  898. length = 4;
  899. }
  900. return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
  901. }
  902. function matchFailed(failure) {
  903. if (pos < rightmostFailuresPos) {
  904. return;
  905. }
  906. if (pos > rightmostFailuresPos) {
  907. rightmostFailuresPos = pos;
  908. rightmostFailuresExpected = [];
  909. }
  910. rightmostFailuresExpected.push(failure);
  911. }
  912. function parse_CRLF() {
  913. var result0;
  914. if (input.substr(pos, 2) === "\r\n") {
  915. result0 = "\r\n";
  916. pos += 2;
  917. } else {
  918. result0 = null;
  919. if (reportFailures === 0) {
  920. matchFailed("\"\\r\\n\"");
  921. }
  922. }
  923. return result0;
  924. }
  925. function parse_DIGIT() {
  926. var result0;
  927. if (/^[0-9]/.test(input.charAt(pos))) {
  928. result0 = input.charAt(pos);
  929. pos++;
  930. } else {
  931. result0 = null;
  932. if (reportFailures === 0) {
  933. matchFailed("[0-9]");
  934. }
  935. }
  936. return result0;
  937. }
  938. function parse_ALPHA() {
  939. var result0;
  940. if (/^[a-zA-Z]/.test(input.charAt(pos))) {
  941. result0 = input.charAt(pos);
  942. pos++;
  943. } else {
  944. result0 = null;
  945. if (reportFailures === 0) {
  946. matchFailed("[a-zA-Z]");
  947. }
  948. }
  949. return result0;
  950. }
  951. function parse_HEXDIG() {
  952. var result0;
  953. if (/^[0-9a-fA-F]/.test(input.charAt(pos))) {
  954. result0 = input.charAt(pos);
  955. pos++;
  956. } else {
  957. result0 = null;
  958. if (reportFailures === 0) {
  959. matchFailed("[0-9a-fA-F]");
  960. }
  961. }
  962. return result0;
  963. }
  964. function parse_WSP() {
  965. var result0;
  966. result0 = parse_SP();
  967. if (result0 === null) {
  968. result0 = parse_HTAB();
  969. }
  970. return result0;
  971. }
  972. function parse_OCTET() {
  973. var result0;
  974. if (/^[\0-\xFF]/.test(input.charAt(pos))) {
  975. result0 = input.charAt(pos);
  976. pos++;
  977. } else {
  978. result0 = null;
  979. if (reportFailures === 0) {
  980. matchFailed("[\\0-\\xFF]");
  981. }
  982. }
  983. return result0;
  984. }
  985. function parse_DQUOTE() {
  986. var result0;
  987. if (/^["]/.test(input.charAt(pos))) {
  988. result0 = input.charAt(pos);
  989. pos++;
  990. } else {
  991. result0 = null;
  992. if (reportFailures === 0) {
  993. matchFailed("[\"]");
  994. }
  995. }
  996. return result0;
  997. }
  998. function parse_SP() {
  999. var result0;
  1000. if (input.charCodeAt(pos) === 32) {
  1001. result0 = " ";
  1002. pos++;
  1003. } else {
  1004. result0 = null;
  1005. if (reportFailures === 0) {
  1006. matchFailed("\" \"");
  1007. }
  1008. }
  1009. return result0;
  1010. }
  1011. function parse_HTAB() {
  1012. var result0;
  1013. if (input.charCodeAt(pos) === 9) {
  1014. result0 = "\t";
  1015. pos++;
  1016. } else {
  1017. result0 = null;
  1018. if (reportFailures === 0) {
  1019. matchFailed("\"\\t\"");
  1020. }
  1021. }
  1022. return result0;
  1023. }
  1024. function parse_alphanum() {
  1025. var result0;
  1026. if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) {
  1027. result0 = input.charAt(pos);
  1028. pos++;
  1029. } else {
  1030. result0 = null;
  1031. if (reportFailures === 0) {
  1032. matchFailed("[a-zA-Z0-9]");
  1033. }
  1034. }
  1035. return result0;
  1036. }
  1037. function parse_reserved() {
  1038. var result0;
  1039. if (input.charCodeAt(pos) === 59) {
  1040. result0 = ";";
  1041. pos++;
  1042. } else {
  1043. result0 = null;
  1044. if (reportFailures === 0) {
  1045. matchFailed("\";\"");
  1046. }
  1047. }
  1048. if (result0 === null) {
  1049. if (input.charCodeAt(pos) === 47) {
  1050. result0 = "/";
  1051. pos++;
  1052. } else {
  1053. result0 = null;
  1054. if (reportFailures === 0) {
  1055. matchFailed("\"/\"");
  1056. }
  1057. }
  1058. if (result0 === null) {
  1059. if (input.charCodeAt(pos) === 63) {
  1060. result0 = "?";
  1061. pos++;
  1062. } else {
  1063. result0 = null;
  1064. if (reportFailures === 0) {
  1065. matchFailed("\"?\"");
  1066. }
  1067. }
  1068. if (result0 === null) {
  1069. if (input.charCodeAt(pos) === 58) {
  1070. result0 = ":";
  1071. pos++;
  1072. } else {
  1073. result0 = null;
  1074. if (reportFailures === 0) {
  1075. matchFailed("\":\"");
  1076. }
  1077. }
  1078. if (result0 === null) {
  1079. if (input.charCodeAt(pos) === 64) {
  1080. result0 = "@";
  1081. pos++;
  1082. } else {
  1083. result0 = null;
  1084. if (reportFailures === 0) {
  1085. matchFailed("\"@\"");
  1086. }
  1087. }
  1088. if (result0 === null) {
  1089. if (input.charCodeAt(pos) === 38) {
  1090. result0 = "&";
  1091. pos++;
  1092. } else {
  1093. result0 = null;
  1094. if (reportFailures === 0) {
  1095. matchFailed("\"&\"");
  1096. }
  1097. }
  1098. if (result0 === null) {
  1099. if (input.charCodeAt(pos) === 61) {
  1100. result0 = "=";
  1101. pos++;
  1102. } else {
  1103. result0 = null;
  1104. if (reportFailures === 0) {
  1105. matchFailed("\"=\"");
  1106. }
  1107. }
  1108. if (result0 === null) {
  1109. if (input.charCodeAt(pos) === 43) {
  1110. result0 = "+";
  1111. pos++;
  1112. } else {
  1113. result0 = null;
  1114. if (reportFailures === 0) {
  1115. matchFailed("\"+\"");
  1116. }
  1117. }
  1118. if (result0 === null) {
  1119. if (input.charCodeAt(pos) === 36) {
  1120. result0 = "$";
  1121. pos++;
  1122. } else {
  1123. result0 = null;
  1124. if (reportFailures === 0) {
  1125. matchFailed("\"$\"");
  1126. }
  1127. }
  1128. if (result0 === null) {
  1129. if (input.charCodeAt(pos) === 44) {
  1130. result0 = ",";
  1131. pos++;
  1132. } else {
  1133. result0 = null;
  1134. if (reportFailures === 0) {
  1135. matchFailed("\",\"");
  1136. }
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. }
  1144. }
  1145. }
  1146. }
  1147. return result0;
  1148. }
  1149. function parse_unreserved() {
  1150. var result0;
  1151. result0 = parse_alphanum();
  1152. if (result0 === null) {
  1153. result0 = parse_mark();
  1154. }
  1155. return result0;
  1156. }
  1157. function parse_mark() {
  1158. var result0;
  1159. if (input.charCodeAt(pos) === 45) {
  1160. result0 = "-";
  1161. pos++;
  1162. } else {
  1163. result0 = null;
  1164. if (reportFailures === 0) {
  1165. matchFailed("\"-\"");
  1166. }
  1167. }
  1168. if (result0 === null) {
  1169. if (input.charCodeAt(pos) === 95) {
  1170. result0 = "_";
  1171. pos++;
  1172. } else {
  1173. result0 = null;
  1174. if (reportFailures === 0) {
  1175. matchFailed("\"_\"");
  1176. }
  1177. }
  1178. if (result0 === null) {
  1179. if (input.charCodeAt(pos) === 46) {
  1180. result0 = ".";
  1181. pos++;
  1182. } else {
  1183. result0 = null;
  1184. if (reportFailures === 0) {
  1185. matchFailed("\".\"");
  1186. }
  1187. }
  1188. if (result0 === null) {
  1189. if (input.charCodeAt(pos) === 33) {
  1190. result0 = "!";
  1191. pos++;
  1192. } else {
  1193. result0 = null;
  1194. if (reportFailures === 0) {
  1195. matchFailed("\"!\"");
  1196. }
  1197. }
  1198. if (result0 === null) {
  1199. if (input.charCodeAt(pos) === 126) {
  1200. result0 = "~";
  1201. pos++;
  1202. } else {
  1203. result0 = null;
  1204. if (reportFailures === 0) {
  1205. matchFailed("\"~\"");
  1206. }
  1207. }
  1208. if (result0 === null) {
  1209. if (input.charCodeAt(pos) === 42) {
  1210. result0 = "*";
  1211. pos++;
  1212. } else {
  1213. result0 = null;
  1214. if (reportFailures === 0) {
  1215. matchFailed("\"*\"");
  1216. }
  1217. }
  1218. if (result0 === null) {
  1219. if (input.charCodeAt(pos) === 39) {
  1220. result0 = "'";
  1221. pos++;
  1222. } else {
  1223. result0 = null;
  1224. if (reportFailures === 0) {
  1225. matchFailed("\"'\"");
  1226. }
  1227. }
  1228. if (result0 === null) {
  1229. if (input.charCodeAt(pos) === 40) {
  1230. result0 = "(";
  1231. pos++;
  1232. } else {
  1233. result0 = null;
  1234. if (reportFailures === 0) {
  1235. matchFailed("\"(\"");
  1236. }
  1237. }
  1238. if (result0 === null) {
  1239. if (input.charCodeAt(pos) === 41) {
  1240. result0 = ")";
  1241. pos++;
  1242. } else {
  1243. result0 = null;
  1244. if (reportFailures === 0) {
  1245. matchFailed("\")\"");
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. return result0;
  1257. }
  1258. function parse_escaped() {
  1259. var result0, result1, result2;
  1260. var pos0, pos1;
  1261. pos0 = pos;
  1262. pos1 = pos;
  1263. if (input.charCodeAt(pos) === 37) {
  1264. result0 = "%";
  1265. pos++;
  1266. } else {
  1267. result0 = null;
  1268. if (reportFailures === 0) {
  1269. matchFailed("\"%\"");
  1270. }
  1271. }
  1272. if (result0 !== null) {
  1273. result1 = parse_HEXDIG();
  1274. if (result1 !== null) {
  1275. result2 = parse_HEXDIG();
  1276. if (result2 !== null) {
  1277. result0 = [result0, result1, result2];
  1278. } else {
  1279. result0 = null;
  1280. pos = pos1;
  1281. }
  1282. } else {
  1283. result0 = null;
  1284. pos = pos1;
  1285. }
  1286. } else {
  1287. result0 = null;
  1288. pos = pos1;
  1289. }
  1290. if (result0 !== null) {
  1291. result0 = (function(offset, escaped) {return escaped.join(''); })(pos0, result0);
  1292. }
  1293. if (result0 === null) {
  1294. pos = pos0;
  1295. }
  1296. return result0;
  1297. }
  1298. function parse_LWS() {
  1299. var result0, result1, result2;
  1300. var pos0, pos1, pos2;
  1301. pos0 = pos;
  1302. pos1 = pos;
  1303. pos2 = pos;
  1304. result0 = [];
  1305. result1 = parse_WSP();
  1306. while (result1 !== null) {
  1307. result0.push(result1);
  1308. result1 = parse_WSP();
  1309. }
  1310. if (result0 !== null) {
  1311. result1 = parse_CRLF();
  1312. if (result1 !== null) {
  1313. result0 = [result0, result1];
  1314. } else {
  1315. result0 = null;
  1316. pos = pos2;
  1317. }
  1318. } else {
  1319. result0 = null;
  1320. pos = pos2;
  1321. }
  1322. result0 = result0 !== null ? result0 : "";
  1323. if (result0 !== null) {
  1324. result2 = parse_WSP();
  1325. if (result2 !== null) {
  1326. result1 = [];
  1327. while (result2 !== null) {
  1328. result1.push(result2);
  1329. result2 = parse_WSP();
  1330. }
  1331. } else {
  1332. result1 = null;
  1333. }
  1334. if (result1 !== null) {
  1335. result0 = [result0, result1];
  1336. } else {
  1337. result0 = null;
  1338. pos = pos1;
  1339. }
  1340. } else {
  1341. result0 = null;
  1342. pos = pos1;
  1343. }
  1344. if (result0 !== null) {
  1345. result0 = (function(offset) {return " "; })(pos0);
  1346. }
  1347. if (result0 === null) {
  1348. pos = pos0;
  1349. }
  1350. return result0;
  1351. }
  1352. function parse_SWS() {
  1353. var result0;
  1354. result0 = parse_LWS();
  1355. result0 = result0 !== null ? result0 : "";
  1356. return result0;
  1357. }
  1358. function parse_HCOLON() {
  1359. var result0, result1, result2;
  1360. var pos0, pos1;
  1361. pos0 = pos;
  1362. pos1 = pos;
  1363. result0 = [];
  1364. result1 = parse_SP();
  1365. if (result1 === null) {
  1366. result1 = parse_HTAB();
  1367. }
  1368. while (result1 !== null) {
  1369. result0.push(result1);
  1370. result1 = parse_SP();
  1371. if (result1 === null) {
  1372. result1 = parse_HTAB();
  1373. }
  1374. }
  1375. if (result0 !== null) {
  1376. if (input.charCodeAt(pos) === 58) {
  1377. result1 = ":";
  1378. pos++;
  1379. } else {
  1380. result1 = null;
  1381. if (reportFailures === 0) {
  1382. matchFailed("\":\"");
  1383. }
  1384. }
  1385. if (result1 !== null) {
  1386. result2 = parse_SWS();
  1387. if (result2 !== null) {
  1388. result0 = [result0, result1, result2];
  1389. } else {
  1390. result0 = null;
  1391. pos = pos1;
  1392. }
  1393. } else {
  1394. result0 = null;
  1395. pos = pos1;
  1396. }
  1397. } else {
  1398. result0 = null;
  1399. pos = pos1;
  1400. }
  1401. if (result0 !== null) {
  1402. result0 = (function(offset) {return ':'; })(pos0);
  1403. }
  1404. if (result0 === null) {
  1405. pos = pos0;
  1406. }
  1407. return result0;
  1408. }
  1409. function parse_TEXT_UTF8_TRIM() {
  1410. var result0, result1, result2, result3;
  1411. var pos0, pos1, pos2;
  1412. pos0 = pos;
  1413. pos1 = pos;
  1414. result1 = parse_TEXT_UTF8char();
  1415. if (result1 !== null) {
  1416. result0 = [];
  1417. while (result1 !== null) {
  1418. result0.push(result1);
  1419. result1 = parse_TEXT_UTF8char();
  1420. }
  1421. } else {
  1422. result0 = null;
  1423. }
  1424. if (result0 !== null) {
  1425. result1 = [];
  1426. pos2 = pos;
  1427. result2 = [];
  1428. result3 = parse_LWS();
  1429. while (result3 !== null) {
  1430. result2.push(result3);
  1431. result3 = parse_LWS();
  1432. }
  1433. if (result2 !== null) {
  1434. result3 = parse_TEXT_UTF8char();
  1435. if (result3 !== null) {
  1436. result2 = [result2, result3];
  1437. } else {
  1438. result2 = null;
  1439. pos = pos2;
  1440. }
  1441. } else {
  1442. result2 = null;
  1443. pos = pos2;
  1444. }
  1445. while (result2 !== null) {
  1446. result1.push(result2);
  1447. pos2 = pos;
  1448. result2 = [];
  1449. result3 = parse_LWS();
  1450. while (result3 !== null) {
  1451. result2.push(result3);
  1452. result3 = parse_LWS();
  1453. }
  1454. if (result2 !== null) {
  1455. result3 = parse_TEXT_UTF8char();
  1456. if (result3 !== null) {
  1457. result2 = [result2, result3];
  1458. } else {
  1459. result2 = null;
  1460. pos = pos2;
  1461. }
  1462. } else {
  1463. result2 = null;
  1464. pos = pos2;
  1465. }
  1466. }
  1467. if (result1 !== null) {
  1468. result0 = [result0, result1];
  1469. } else {
  1470. result0 = null;
  1471. pos = pos1;
  1472. }
  1473. } else {
  1474. result0 = null;
  1475. pos = pos1;
  1476. }
  1477. if (result0 !== null) {
  1478. result0 = (function(offset) {
  1479. return input.substring(pos, offset); })(pos0);
  1480. }
  1481. if (result0 === null) {
  1482. pos = pos0;
  1483. }
  1484. return result0;
  1485. }
  1486. function parse_TEXT_UTF8char() {
  1487. var result0;
  1488. if (/^[!-~]/.test(input.charAt(pos))) {
  1489. result0 = input.charAt(pos);
  1490. pos++;
  1491. } else {
  1492. result0 = null;
  1493. if (reportFailures === 0) {
  1494. matchFailed("[!-~]");
  1495. }
  1496. }
  1497. if (result0 === null) {
  1498. result0 = parse_UTF8_NONASCII();
  1499. }
  1500. return result0;
  1501. }
  1502. function parse_UTF8_NONASCII() {
  1503. var result0;
  1504. if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) {
  1505. result0 = input.charAt(pos);
  1506. pos++;
  1507. } else {
  1508. result0 = null;
  1509. if (reportFailures === 0) {
  1510. matchFailed("[\\x80-\\uFFFF]");
  1511. }
  1512. }
  1513. return result0;
  1514. }
  1515. function parse_UTF8_CONT() {
  1516. var result0;
  1517. if (/^[\x80-\xBF]/.test(input.charAt(pos))) {
  1518. result0 = input.charAt(pos);
  1519. pos++;
  1520. } else {
  1521. result0 = null;
  1522. if (reportFailures === 0) {
  1523. matchFailed("[\\x80-\\xBF]");
  1524. }
  1525. }
  1526. return result0;
  1527. }
  1528. function parse_LHEX() {
  1529. var result0;
  1530. result0 = parse_DIGIT();
  1531. if (result0 === null) {
  1532. if (/^[a-f]/.test(input.charAt(pos))) {
  1533. result0 = input.charAt(pos);
  1534. pos++;
  1535. } else {
  1536. result0 = null;
  1537. if (reportFailures === 0) {
  1538. matchFailed("[a-f]");
  1539. }
  1540. }
  1541. }
  1542. return result0;
  1543. }
  1544. function parse_token() {
  1545. var result0, result1;
  1546. var pos0;
  1547. pos0 = pos;
  1548. result1 = parse_alphanum();
  1549. if (result1 === null) {
  1550. if (input.charCodeAt(pos) === 45) {
  1551. result1 = "-";
  1552. pos++;
  1553. } else {
  1554. result1 = null;
  1555. if (reportFailures === 0) {
  1556. matchFailed("\"-\"");
  1557. }
  1558. }
  1559. if (result1 === null) {
  1560. if (input.charCodeAt(pos) === 46) {
  1561. result1 = ".";
  1562. pos++;
  1563. } else {
  1564. result1 = null;
  1565. if (reportFailures === 0) {
  1566. matchFailed("\".\"");
  1567. }
  1568. }
  1569. if (result1 === null) {
  1570. if (input.charCodeAt(pos) === 33) {
  1571. result1 = "!";
  1572. pos++;
  1573. } else {
  1574. result1 = null;
  1575. if (reportFailures === 0) {
  1576. matchFailed("\"!\"");
  1577. }
  1578. }
  1579. if (result1 === null) {
  1580. if (input.charCodeAt(pos) === 37) {
  1581. result1 = "%";
  1582. pos++;
  1583. } else {
  1584. result1 = null;
  1585. if (reportFailures === 0) {
  1586. matchFailed("\"%\"");
  1587. }
  1588. }
  1589. if (result1 === null) {
  1590. if (input.charCodeAt(pos) === 42) {
  1591. result1 = "*";
  1592. pos++;
  1593. } else {
  1594. result1 = null;
  1595. if (reportFailures === 0) {
  1596. matchFailed("\"*\"");
  1597. }
  1598. }
  1599. if (result1 === null) {
  1600. if (input.charCodeAt(pos) === 95) {
  1601. result1 = "_";
  1602. pos++;
  1603. } else {
  1604. result1 = null;
  1605. if (reportFailures === 0) {
  1606. matchFailed("\"_\"");
  1607. }
  1608. }
  1609. if (result1 === null) {
  1610. if (input.charCodeAt(pos) === 43) {
  1611. result1 = "+";
  1612. pos++;
  1613. } else {
  1614. result1 = null;
  1615. if (reportFailures === 0) {
  1616. matchFailed("\"+\"");
  1617. }
  1618. }
  1619. if (result1 === null) {
  1620. if (input.charCodeAt(pos) === 96) {
  1621. result1 = "`";
  1622. pos++;
  1623. } else {
  1624. result1 = null;
  1625. if (reportFailures === 0) {
  1626. matchFailed("\"`\"");
  1627. }
  1628. }
  1629. if (result1 === null) {
  1630. if (input.charCodeAt(pos) === 39) {
  1631. result1 = "'";
  1632. pos++;
  1633. } else {
  1634. result1 = null;
  1635. if (reportFailures === 0) {
  1636. matchFailed("\"'\"");
  1637. }
  1638. }
  1639. if (result1 === null) {
  1640. if (input.charCodeAt(pos) === 126) {
  1641. result1 = "~";
  1642. pos++;
  1643. } else {
  1644. result1 = null;
  1645. if (reportFailures === 0) {
  1646. matchFailed("\"~\"");
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. if (result1 !== null) {
  1660. result0 = [];
  1661. while (result1 !== null) {
  1662. result0.push(result1);
  1663. result1 = parse_alphanum();
  1664. if (result1 === null) {
  1665. if (input.charCodeAt(pos) === 45) {
  1666. result1 = "-";
  1667. pos++;
  1668. } else {
  1669. result1 = null;
  1670. if (reportFailures === 0) {
  1671. matchFailed("\"-\"");
  1672. }
  1673. }
  1674. if (result1 === null) {
  1675. if (input.charCodeAt(pos) === 46) {
  1676. result1 = ".";
  1677. pos++;
  1678. } else {
  1679. result1 = null;
  1680. if (reportFailures === 0) {
  1681. matchFailed("\".\"");
  1682. }
  1683. }
  1684. if (result1 === null) {
  1685. if (input.charCodeAt(pos) === 33) {
  1686. result1 = "!";
  1687. pos++;
  1688. } else {
  1689. result1 = null;
  1690. if (reportFailures === 0) {
  1691. matchFailed("\"!\"");
  1692. }
  1693. }
  1694. if (result1 === null) {
  1695. if (input.charCodeAt(pos) === 37) {
  1696. result1 = "%";
  1697. pos++;
  1698. } else {
  1699. result1 = null;
  1700. if (reportFailures === 0) {
  1701. matchFailed("\"%\"");
  1702. }
  1703. }
  1704. if (result1 === null) {
  1705. if (input.charCodeAt(pos) === 42) {
  1706. result1 = "*";
  1707. pos++;
  1708. } else {
  1709. result1 = null;
  1710. if (reportFailures === 0) {
  1711. matchFailed("\"*\"");
  1712. }
  1713. }
  1714. if (result1 === null) {
  1715. if (input.charCodeAt(pos) === 95) {
  1716. result1 = "_";
  1717. pos++;
  1718. } else {
  1719. result1 = null;
  1720. if (reportFailures === 0) {
  1721. matchFailed("\"_\"");
  1722. }
  1723. }
  1724. if (result1 === null) {
  1725. if (input.charCodeAt(pos) === 43) {
  1726. result1 = "+";
  1727. pos++;
  1728. } else {
  1729. result1 = null;
  1730. if (reportFailures === 0) {
  1731. matchFailed("\"+\"");
  1732. }
  1733. }
  1734. if (result1 === null) {
  1735. if (input.charCodeAt(pos) === 96) {
  1736. result1 = "`";
  1737. pos++;
  1738. } else {
  1739. result1 = null;
  1740. if (reportFailures === 0) {
  1741. matchFailed("\"`\"");
  1742. }
  1743. }
  1744. if (result1 === null) {
  1745. if (input.charCodeAt(pos) === 39) {
  1746. result1 = "'";
  1747. pos++;
  1748. } else {
  1749. result1 = null;
  1750. if (reportFailures === 0) {
  1751. matchFailed("\"'\"");
  1752. }
  1753. }
  1754. if (result1 === null) {
  1755. if (input.charCodeAt(pos) === 126) {
  1756. result1 = "~";
  1757. pos++;
  1758. } else {
  1759. result1 = null;
  1760. if (reportFailures === 0) {
  1761. matchFailed("\"~\"");
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. }
  1775. } else {
  1776. result0 = null;
  1777. }
  1778. if (result0 !== null) {
  1779. result0 = (function(offset) {
  1780. return input.substring(pos, offset); })(pos0);
  1781. }
  1782. if (result0 === null) {
  1783. pos = pos0;
  1784. }
  1785. return result0;
  1786. }
  1787. function parse_token_nodot() {
  1788. var result0, result1;
  1789. var pos0;
  1790. pos0 = pos;
  1791. result1 = parse_alphanum();
  1792. if (result1 === null) {
  1793. if (input.charCodeAt(pos) === 45) {
  1794. result1 = "-";
  1795. pos++;
  1796. } else {
  1797. result1 = null;
  1798. if (reportFailures === 0) {
  1799. matchFailed("\"-\"");
  1800. }
  1801. }
  1802. if (result1 === null) {
  1803. if (input.charCodeAt(pos) === 33) {
  1804. result1 = "!";
  1805. pos++;
  1806. } else {
  1807. result1 = null;
  1808. if (reportFailures === 0) {
  1809. matchFailed("\"!\"");
  1810. }
  1811. }
  1812. if (result1 === null) {
  1813. if (input.charCodeAt(pos) === 37) {
  1814. result1 = "%";
  1815. pos++;
  1816. } else {
  1817. result1 = null;
  1818. if (reportFailures === 0) {
  1819. matchFailed("\"%\"");
  1820. }
  1821. }
  1822. if (result1 === null) {
  1823. if (input.charCodeAt(pos) === 42) {
  1824. result1 = "*";
  1825. pos++;
  1826. } else {
  1827. result1 = null;
  1828. if (reportFailures === 0) {
  1829. matchFailed("\"*\"");
  1830. }
  1831. }
  1832. if (result1 === null) {
  1833. if (input.charCodeAt(pos) === 95) {
  1834. result1 = "_";
  1835. pos++;
  1836. } else {
  1837. result1 = null;
  1838. if (reportFailures === 0) {
  1839. matchFailed("\"_\"");
  1840. }
  1841. }
  1842. if (result1 === null) {
  1843. if (input.charCodeAt(pos) === 43) {
  1844. result1 = "+";
  1845. pos++;
  1846. } else {
  1847. result1 = null;
  1848. if (reportFailures === 0) {
  1849. matchFailed("\"+\"");
  1850. }
  1851. }
  1852. if (result1 === null) {
  1853. if (input.charCodeAt(pos) === 96) {
  1854. result1 = "`";
  1855. pos++;
  1856. } else {
  1857. result1 = null;
  1858. if (reportFailures === 0) {
  1859. matchFailed("\"`\"");
  1860. }
  1861. }
  1862. if (result1 === null) {
  1863. if (input.charCodeAt(pos) === 39) {
  1864. result1 = "'";
  1865. pos++;
  1866. } else {
  1867. result1 = null;
  1868. if (reportFailures === 0) {
  1869. matchFailed("\"'\"");
  1870. }
  1871. }
  1872. if (result1 === null) {
  1873. if (input.charCodeAt(pos) === 126) {
  1874. result1 = "~";
  1875. pos++;
  1876. } else {
  1877. result1 = null;
  1878. if (reportFailures === 0) {
  1879. matchFailed("\"~\"");
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. }
  1887. }
  1888. }
  1889. }
  1890. }
  1891. if (result1 !== null) {
  1892. result0 = [];
  1893. while (result1 !== null) {
  1894. result0.push(result1);
  1895. result1 = parse_alphanum();
  1896. if (result1 === null) {
  1897. if (input.charCodeAt(pos) === 45) {
  1898. result1 = "-";
  1899. pos++;
  1900. } else {
  1901. result1 = null;
  1902. if (reportFailures === 0) {
  1903. matchFailed("\"-\"");
  1904. }
  1905. }
  1906. if (result1 === null) {
  1907. if (input.charCodeAt(pos) === 33) {
  1908. result1 = "!";
  1909. pos++;
  1910. } else {
  1911. result1 = null;
  1912. if (reportFailures === 0) {
  1913. matchFailed("\"!\"");
  1914. }
  1915. }
  1916. if (result1 === null) {
  1917. if (input.charCodeAt(pos) === 37) {
  1918. result1 = "%";
  1919. pos++;
  1920. } else {
  1921. result1 = null;
  1922. if (reportFailures === 0) {
  1923. matchFailed("\"%\"");
  1924. }
  1925. }
  1926. if (result1 === null) {
  1927. if (input.charCodeAt(pos) === 42) {
  1928. result1 = "*";
  1929. pos++;
  1930. } else {
  1931. result1 = null;
  1932. if (reportFailures === 0) {
  1933. matchFailed("\"*\"");
  1934. }
  1935. }
  1936. if (result1 === null) {
  1937. if (input.charCodeAt(pos) === 95) {
  1938. result1 = "_";
  1939. pos++;
  1940. } else {
  1941. result1 = null;
  1942. if (reportFailures === 0) {
  1943. matchFailed("\"_\"");
  1944. }
  1945. }
  1946. if (result1 === null) {
  1947. if (input.charCodeAt(pos) === 43) {
  1948. result1 = "+";
  1949. pos++;
  1950. } else {
  1951. result1 = null;
  1952. if (reportFailures === 0) {
  1953. matchFailed("\"+\"");
  1954. }
  1955. }
  1956. if (result1 === null) {
  1957. if (input.charCodeAt(pos) === 96) {
  1958. result1 = "`";
  1959. pos++;
  1960. } else {
  1961. result1 = null;
  1962. if (reportFailures === 0) {
  1963. matchFailed("\"`\"");
  1964. }
  1965. }
  1966. if (result1 === null) {
  1967. if (input.charCodeAt(pos) === 39) {
  1968. result1 = "'";
  1969. pos++;
  1970. } else {
  1971. result1 = null;
  1972. if (reportFailures === 0) {
  1973. matchFailed("\"'\"");
  1974. }
  1975. }
  1976. if (result1 === null) {
  1977. if (input.charCodeAt(pos) === 126) {
  1978. result1 = "~";
  1979. pos++;
  1980. } else {
  1981. result1 = null;
  1982. if (reportFailures === 0) {
  1983. matchFailed("\"~\"");
  1984. }
  1985. }
  1986. }
  1987. }
  1988. }
  1989. }
  1990. }
  1991. }
  1992. }
  1993. }
  1994. }
  1995. }
  1996. } else {
  1997. result0 = null;
  1998. }
  1999. if (result0 !== null) {
  2000. result0 = (function(offset) {
  2001. return input.substring(pos, offset); })(pos0);
  2002. }
  2003. if (result0 === null) {
  2004. pos = pos0;
  2005. }
  2006. return result0;
  2007. }
  2008. function parse_separators() {
  2009. var result0;
  2010. if (input.charCodeAt(pos) === 40) {
  2011. result0 = "(";
  2012. pos++;
  2013. } else {
  2014. result0 = null;
  2015. if (reportFailures === 0) {
  2016. matchFailed("\"(\"");
  2017. }
  2018. }
  2019. if (result0 === null) {
  2020. if (input.charCodeAt(pos) === 41) {
  2021. result0 = ")";
  2022. pos++;
  2023. } else {
  2024. result0 = null;
  2025. if (reportFailures === 0) {
  2026. matchFailed("\")\"");
  2027. }
  2028. }
  2029. if (result0 === null) {
  2030. if (input.charCodeAt(pos) === 60) {
  2031. result0 = "<";
  2032. pos++;
  2033. } else {
  2034. result0 = null;
  2035. if (reportFailures === 0) {
  2036. matchFailed("\"<\"");
  2037. }
  2038. }
  2039. if (result0 === null) {
  2040. if (input.charCodeAt(pos) === 62) {
  2041. result0 = ">";
  2042. pos++;
  2043. } else {
  2044. result0 = null;
  2045. if (reportFailures === 0) {
  2046. matchFailed("\">\"");
  2047. }
  2048. }
  2049. if (result0 === null) {
  2050. if (input.charCodeAt(pos) === 64) {
  2051. result0 = "@";
  2052. pos++;
  2053. } else {
  2054. result0 = null;
  2055. if (reportFailures === 0) {
  2056. matchFailed("\"@\"");
  2057. }
  2058. }
  2059. if (result0 === null) {
  2060. if (input.charCodeAt(pos) === 44) {
  2061. result0 = ",";
  2062. pos++;
  2063. } else {
  2064. result0 = null;
  2065. if (reportFailures === 0) {
  2066. matchFailed("\",\"");
  2067. }
  2068. }
  2069. if (result0 === null) {
  2070. if (input.charCodeAt(pos) === 59) {
  2071. result0 = ";";
  2072. pos++;
  2073. } else {
  2074. result0 = null;
  2075. if (reportFailures === 0) {
  2076. matchFailed("\";\"");
  2077. }
  2078. }
  2079. if (result0 === null) {
  2080. if (input.charCodeAt(pos) === 58) {
  2081. result0 = ":";
  2082. pos++;
  2083. } else {
  2084. result0 = null;
  2085. if (reportFailures === 0) {
  2086. matchFailed("\":\"");
  2087. }
  2088. }
  2089. if (result0 === null) {
  2090. if (input.charCodeAt(pos) === 92) {
  2091. result0 = "\\";
  2092. pos++;
  2093. } else {
  2094. result0 = null;
  2095. if (reportFailures === 0) {
  2096. matchFailed("\"\\\\\"");
  2097. }
  2098. }
  2099. if (result0 === null) {
  2100. result0 = parse_DQUOTE();
  2101. if (result0 === null) {
  2102. if (input.charCodeAt(pos) === 47) {
  2103. result0 = "/";
  2104. pos++;
  2105. } else {
  2106. result0 = null;
  2107. if (reportFailures === 0) {
  2108. matchFailed("\"/\"");
  2109. }
  2110. }
  2111. if (result0 === null) {
  2112. if (input.charCodeAt(pos) === 91) {
  2113. result0 = "[";
  2114. pos++;
  2115. } else {
  2116. result0 = null;
  2117. if (reportFailures === 0) {
  2118. matchFailed("\"[\"");
  2119. }
  2120. }
  2121. if (result0 === null) {
  2122. if (input.charCodeAt(pos) === 93) {
  2123. result0 = "]";
  2124. pos++;
  2125. } else {
  2126. result0 = null;
  2127. if (reportFailures === 0) {
  2128. matchFailed("\"]\"");
  2129. }
  2130. }
  2131. if (result0 === null) {
  2132. if (input.charCodeAt(pos) === 63) {
  2133. result0 = "?";
  2134. pos++;
  2135. } else {
  2136. result0 = null;
  2137. if (reportFailures === 0) {
  2138. matchFailed("\"?\"");
  2139. }
  2140. }
  2141. if (result0 === null) {
  2142. if (input.charCodeAt(pos) === 61) {
  2143. result0 = "=";
  2144. pos++;
  2145. } else {
  2146. result0 = null;
  2147. if (reportFailures === 0) {
  2148. matchFailed("\"=\"");
  2149. }
  2150. }
  2151. if (result0 === null) {
  2152. if (input.charCodeAt(pos) === 123) {
  2153. result0 = "{";
  2154. pos++;
  2155. } else {
  2156. result0 = null;
  2157. if (reportFailures === 0) {
  2158. matchFailed("\"{\"");
  2159. }
  2160. }
  2161. if (result0 === null) {
  2162. if (input.charCodeAt(pos) === 125) {
  2163. result0 = "}";
  2164. pos++;
  2165. } else {
  2166. result0 = null;
  2167. if (reportFailures === 0) {
  2168. matchFailed("\"}\"");
  2169. }
  2170. }
  2171. if (result0 === null) {
  2172. result0 = parse_SP();
  2173. if (result0 === null) {
  2174. result0 = parse_HTAB();
  2175. }
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. }
  2192. }
  2193. return result0;
  2194. }
  2195. function parse_word() {
  2196. var result0, result1;
  2197. var pos0;
  2198. pos0 = pos;
  2199. result1 = parse_alphanum();
  2200. if (result1 === null) {
  2201. if (input.charCodeAt(pos) === 45) {
  2202. result1 = "-";
  2203. pos++;
  2204. } else {
  2205. result1 = null;
  2206. if (reportFailures === 0) {
  2207. matchFailed("\"-\"");
  2208. }
  2209. }
  2210. if (result1 === null) {
  2211. if (input.charCodeAt(pos) === 46) {
  2212. result1 = ".";
  2213. pos++;
  2214. } else {
  2215. result1 = null;
  2216. if (reportFailures === 0) {
  2217. matchFailed("\".\"");
  2218. }
  2219. }
  2220. if (result1 === null) {
  2221. if (input.charCodeAt(pos) === 33) {
  2222. result1 = "!";
  2223. pos++;
  2224. } else {
  2225. result1 = null;
  2226. if (reportFailures === 0) {
  2227. matchFailed("\"!\"");
  2228. }
  2229. }
  2230. if (result1 === null) {
  2231. if (input.charCodeAt(pos) === 37) {
  2232. result1 = "%";
  2233. pos++;
  2234. } else {
  2235. result1 = null;
  2236. if (reportFailures === 0) {
  2237. matchFailed("\"%\"");
  2238. }
  2239. }
  2240. if (result1 === null) {
  2241. if (input.charCodeAt(pos) === 42) {
  2242. result1 = "*";
  2243. pos++;
  2244. } else {
  2245. result1 = null;
  2246. if (reportFailures === 0) {
  2247. matchFailed("\"*\"");
  2248. }
  2249. }
  2250. if (result1 === null) {
  2251. if (input.charCodeAt(pos) === 95) {
  2252. result1 = "_";
  2253. pos++;
  2254. } else {
  2255. result1 = null;
  2256. if (reportFailures === 0) {
  2257. matchFailed("\"_\"");
  2258. }
  2259. }
  2260. if (result1 === null) {
  2261. if (input.charCodeAt(pos) === 43) {
  2262. result1 = "+";
  2263. pos++;
  2264. } else {
  2265. result1 = null;
  2266. if (reportFailures === 0) {
  2267. matchFailed("\"+\"");
  2268. }
  2269. }
  2270. if (result1 === null) {
  2271. if (input.charCodeAt(pos) === 96) {
  2272. result1 = "`";
  2273. pos++;
  2274. } else {
  2275. result1 = null;
  2276. if (reportFailures === 0) {
  2277. matchFailed("\"`\"");
  2278. }
  2279. }
  2280. if (result1 === null) {
  2281. if (input.charCodeAt(pos) === 39) {
  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) === 126) {
  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) === 40) {
  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) === 41) {
  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) === 60) {
  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) === 62) {
  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) === 58) {
  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) === 92) {
  2352. result1 = "\\";
  2353. pos++;
  2354. } else {
  2355. result1 = null;
  2356. if (reportFailures === 0) {
  2357. matchFailed("\"\\\\\"");
  2358. }
  2359. }
  2360. if (result1 === null) {
  2361. result1 = parse_DQUOTE();
  2362. if (result1 === null) {
  2363. if (input.charCodeAt(pos) === 47) {
  2364. result1 = "/";
  2365. pos++;
  2366. } else {
  2367. result1 = null;
  2368. if (reportFailures === 0) {
  2369. matchFailed("\"/\"");
  2370. }
  2371. }
  2372. if (result1 === null) {
  2373. if (input.charCodeAt(pos) === 91) {
  2374. result1 = "[";
  2375. pos++;
  2376. } else {
  2377. result1 = null;
  2378. if (reportFailures === 0) {
  2379. matchFailed("\"[\"");
  2380. }
  2381. }
  2382. if (result1 === null) {
  2383. if (input.charCodeAt(pos) === 93) {
  2384. result1 = "]";
  2385. pos++;
  2386. } else {
  2387. result1 = null;
  2388. if (reportFailures === 0) {
  2389. matchFailed("\"]\"");
  2390. }
  2391. }
  2392. if (result1 === null) {
  2393. if (input.charCodeAt(pos) === 63) {
  2394. result1 = "?";
  2395. pos++;
  2396. } else {
  2397. result1 = null;
  2398. if (reportFailures === 0) {
  2399. matchFailed("\"?\"");
  2400. }
  2401. }
  2402. if (result1 === null) {
  2403. if (input.charCodeAt(pos) === 123) {
  2404. result1 = "{";
  2405. pos++;
  2406. } else {
  2407. result1 = null;
  2408. if (reportFailures === 0) {
  2409. matchFailed("\"{\"");
  2410. }
  2411. }
  2412. if (result1 === null) {
  2413. if (input.charCodeAt(pos) === 125) {
  2414. result1 = "}";
  2415. pos++;
  2416. } else {
  2417. result1 = null;
  2418. if (reportFailures === 0) {
  2419. matchFailed("\"}\"");
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. }
  2444. }
  2445. if (result1 !== null) {
  2446. result0 = [];
  2447. while (result1 !== null) {
  2448. result0.push(result1);
  2449. result1 = parse_alphanum();
  2450. if (result1 === null) {
  2451. if (input.charCodeAt(pos) === 45) {
  2452. result1 = "-";
  2453. pos++;
  2454. } else {
  2455. result1 = null;
  2456. if (reportFailures === 0) {
  2457. matchFailed("\"-\"");
  2458. }
  2459. }
  2460. if (result1 === null) {
  2461. if (input.charCodeAt(pos) === 46) {
  2462. result1 = ".";
  2463. pos++;
  2464. } else {
  2465. result1 = null;
  2466. if (reportFailures === 0) {
  2467. matchFailed("\".\"");
  2468. }
  2469. }
  2470. if (result1 === null) {
  2471. if (input.charCodeAt(pos) === 33) {
  2472. result1 = "!";
  2473. pos++;
  2474. } else {
  2475. result1 = null;
  2476. if (reportFailures === 0) {
  2477. matchFailed("\"!\"");
  2478. }
  2479. }
  2480. if (result1 === null) {
  2481. if (input.charCodeAt(pos) === 37) {
  2482. result1 = "%";
  2483. pos++;
  2484. } else {
  2485. result1 = null;
  2486. if (reportFailures === 0) {
  2487. matchFailed("\"%\"");
  2488. }
  2489. }
  2490. if (result1 === null) {
  2491. if (input.charCodeAt(pos) === 42) {
  2492. result1 = "*";
  2493. pos++;
  2494. } else {
  2495. result1 = null;
  2496. if (reportFailures === 0) {
  2497. matchFailed("\"*\"");
  2498. }
  2499. }
  2500. if (result1 === null) {
  2501. if (input.charCodeAt(pos) === 95) {
  2502. result1 = "_";
  2503. pos++;
  2504. } else {
  2505. result1 = null;
  2506. if (reportFailures === 0) {
  2507. matchFailed("\"_\"");
  2508. }
  2509. }
  2510. if (result1 === null) {
  2511. if (input.charCodeAt(pos) === 43) {
  2512. result1 = "+";
  2513. pos++;
  2514. } else {
  2515. result1 = null;
  2516. if (reportFailures === 0) {
  2517. matchFailed("\"+\"");
  2518. }
  2519. }
  2520. if (result1 === null) {
  2521. if (input.charCodeAt(pos) === 96) {
  2522. result1 = "`";
  2523. pos++;
  2524. } else {
  2525. result1 = null;
  2526. if (reportFailures === 0) {
  2527. matchFailed("\"`\"");
  2528. }
  2529. }
  2530. if (result1 === null) {
  2531. if (input.charCodeAt(pos) === 39) {
  2532. result1 = "'";
  2533. pos++;
  2534. } else {
  2535. result1 = null;
  2536. if (reportFailures === 0) {
  2537. matchFailed("\"'\"");
  2538. }
  2539. }
  2540. if (result1 === null) {
  2541. if (input.charCodeAt(pos) === 126) {
  2542. result1 = "~";
  2543. pos++;
  2544. } else {
  2545. result1 = null;
  2546. if (reportFailures === 0) {
  2547. matchFailed("\"~\"");
  2548. }
  2549. }
  2550. if (result1 === null) {
  2551. if (input.charCodeAt(pos) === 40) {
  2552. result1 = "(";
  2553. pos++;
  2554. } else {
  2555. result1 = null;
  2556. if (reportFailures === 0) {
  2557. matchFailed("\"(\"");
  2558. }
  2559. }
  2560. if (result1 === null) {
  2561. if (input.charCodeAt(pos) === 41) {
  2562. result1 = ")";
  2563. pos++;
  2564. } else {
  2565. result1 = null;
  2566. if (reportFailures === 0) {
  2567. matchFailed("\")\"");
  2568. }
  2569. }
  2570. if (result1 === null) {
  2571. if (input.charCodeAt(pos) === 60) {
  2572. result1 = "<";
  2573. pos++;
  2574. } else {
  2575. result1 = null;
  2576. if (reportFailures === 0) {
  2577. matchFailed("\"<\"");
  2578. }
  2579. }
  2580. if (result1 === null) {
  2581. if (input.charCodeAt(pos) === 62) {
  2582. result1 = ">";
  2583. pos++;
  2584. } else {
  2585. result1 = null;
  2586. if (reportFailures === 0) {
  2587. matchFailed("\">\"");
  2588. }
  2589. }
  2590. if (result1 === null) {
  2591. if (input.charCodeAt(pos) === 58) {
  2592. result1 = ":";
  2593. pos++;
  2594. } else {
  2595. result1 = null;
  2596. if (reportFailures === 0) {
  2597. matchFailed("\":\"");
  2598. }
  2599. }
  2600. if (result1 === null) {
  2601. if (input.charCodeAt(pos) === 92) {
  2602. result1 = "\\";
  2603. pos++;
  2604. } else {
  2605. result1 = null;
  2606. if (reportFailures === 0) {
  2607. matchFailed("\"\\\\\"");
  2608. }
  2609. }
  2610. if (result1 === null) {
  2611. result1 = parse_DQUOTE();
  2612. if (result1 === null) {
  2613. if (input.charCodeAt(pos) === 47) {
  2614. result1 = "/";
  2615. pos++;
  2616. } else {
  2617. result1 = null;
  2618. if (reportFailures === 0) {
  2619. matchFailed("\"/\"");
  2620. }
  2621. }
  2622. if (result1 === null) {
  2623. if (input.charCodeAt(pos) === 91) {
  2624. result1 = "[";
  2625. pos++;
  2626. } else {
  2627. result1 = null;
  2628. if (reportFailures === 0) {
  2629. matchFailed("\"[\"");
  2630. }
  2631. }
  2632. if (result1 === null) {
  2633. if (input.charCodeAt(pos) === 93) {
  2634. result1 = "]";
  2635. pos++;
  2636. } else {
  2637. result1 = null;
  2638. if (reportFailures === 0) {
  2639. matchFailed("\"]\"");
  2640. }
  2641. }
  2642. if (result1 === null) {
  2643. if (input.charCodeAt(pos) === 63) {
  2644. result1 = "?";
  2645. pos++;
  2646. } else {
  2647. result1 = null;
  2648. if (reportFailures === 0) {
  2649. matchFailed("\"?\"");
  2650. }
  2651. }
  2652. if (result1 === null) {
  2653. if (input.charCodeAt(pos) === 123) {
  2654. result1 = "{";
  2655. pos++;
  2656. } else {
  2657. result1 = null;
  2658. if (reportFailures === 0) {
  2659. matchFailed("\"{\"");
  2660. }
  2661. }
  2662. if (result1 === null) {
  2663. if (input.charCodeAt(pos) === 125) {
  2664. result1 = "}";
  2665. pos++;
  2666. } else {
  2667. result1 = null;
  2668. if (reportFailures === 0) {
  2669. matchFailed("\"}\"");
  2670. }
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. }
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. }
  2695. }
  2696. } else {
  2697. result0 = null;
  2698. }
  2699. if (result0 !== null) {
  2700. result0 = (function(offset) {
  2701. return input.substring(pos, offset); })(pos0);
  2702. }
  2703. if (result0 === null) {
  2704. pos = pos0;
  2705. }
  2706. return result0;
  2707. }
  2708. function parse_STAR() {
  2709. var result0, result1, result2;
  2710. var pos0, pos1;
  2711. pos0 = pos;
  2712. pos1 = pos;
  2713. result0 = parse_SWS();
  2714. if (result0 !== null) {
  2715. if (input.charCodeAt(pos) === 42) {
  2716. result1 = "*";
  2717. pos++;
  2718. } else {
  2719. result1 = null;
  2720. if (reportFailures === 0) {
  2721. matchFailed("\"*\"");
  2722. }
  2723. }
  2724. if (result1 !== null) {
  2725. result2 = parse_SWS();
  2726. if (result2 !== null) {
  2727. result0 = [result0, result1, result2];
  2728. } else {
  2729. result0 = null;
  2730. pos = pos1;
  2731. }
  2732. } else {
  2733. result0 = null;
  2734. pos = pos1;
  2735. }
  2736. } else {
  2737. result0 = null;
  2738. pos = pos1;
  2739. }
  2740. if (result0 !== null) {
  2741. result0 = (function(offset) {return "*"; })(pos0);
  2742. }
  2743. if (result0 === null) {
  2744. pos = pos0;
  2745. }
  2746. return result0;
  2747. }
  2748. function parse_SLASH() {
  2749. var result0, result1, result2;
  2750. var pos0, pos1;
  2751. pos0 = pos;
  2752. pos1 = pos;
  2753. result0 = parse_SWS();
  2754. if (result0 !== null) {
  2755. if (input.charCodeAt(pos) === 47) {
  2756. result1 = "/";
  2757. pos++;
  2758. } else {
  2759. result1 = null;
  2760. if (reportFailures === 0) {
  2761. matchFailed("\"/\"");
  2762. }
  2763. }
  2764. if (result1 !== null) {
  2765. result2 = parse_SWS();
  2766. if (result2 !== null) {
  2767. result0 = [result0, result1, result2];
  2768. } else {
  2769. result0 = null;
  2770. pos = pos1;
  2771. }
  2772. } else {
  2773. result0 = null;
  2774. pos = pos1;
  2775. }
  2776. } else {
  2777. result0 = null;
  2778. pos = pos1;
  2779. }
  2780. if (result0 !== null) {
  2781. result0 = (function(offset) {return "/"; })(pos0);
  2782. }
  2783. if (result0 === null) {
  2784. pos = pos0;
  2785. }
  2786. return result0;
  2787. }
  2788. function parse_EQUAL() {
  2789. var result0, result1, result2;
  2790. var pos0, pos1;
  2791. pos0 = pos;
  2792. pos1 = pos;
  2793. result0 = parse_SWS();
  2794. if (result0 !== null) {
  2795. if (input.charCodeAt(pos) === 61) {
  2796. result1 = "=";
  2797. pos++;
  2798. } else {
  2799. result1 = null;
  2800. if (reportFailures === 0) {
  2801. matchFailed("\"=\"");
  2802. }
  2803. }
  2804. if (result1 !== null) {
  2805. result2 = parse_SWS();
  2806. if (result2 !== null) {
  2807. result0 = [result0, result1, result2];
  2808. } else {
  2809. result0 = null;
  2810. pos = pos1;
  2811. }
  2812. } else {
  2813. result0 = null;
  2814. pos = pos1;
  2815. }
  2816. } else {
  2817. result0 = null;
  2818. pos = pos1;
  2819. }
  2820. if (result0 !== null) {
  2821. result0 = (function(offset) {return "="; })(pos0);
  2822. }
  2823. if (result0 === null) {
  2824. pos = pos0;
  2825. }
  2826. return result0;
  2827. }
  2828. function parse_LPAREN() {
  2829. var result0, result1, result2;
  2830. var pos0, pos1;
  2831. pos0 = pos;
  2832. pos1 = pos;
  2833. result0 = parse_SWS();
  2834. if (result0 !== null) {
  2835. if (input.charCodeAt(pos) === 40) {
  2836. result1 = "(";
  2837. pos++;
  2838. } else {
  2839. result1 = null;
  2840. if (reportFailures === 0) {
  2841. matchFailed("\"(\"");
  2842. }
  2843. }
  2844. if (result1 !== null) {
  2845. result2 = parse_SWS();
  2846. if (result2 !== null) {
  2847. result0 = [result0, result1, result2];
  2848. } else {
  2849. result0 = null;
  2850. pos = pos1;
  2851. }
  2852. } else {
  2853. result0 = null;
  2854. pos = pos1;
  2855. }
  2856. } else {
  2857. result0 = null;
  2858. pos = pos1;
  2859. }
  2860. if (result0 !== null) {
  2861. result0 = (function(offset) {return "("; })(pos0);
  2862. }
  2863. if (result0 === null) {
  2864. pos = pos0;
  2865. }
  2866. return result0;
  2867. }
  2868. function parse_RPAREN() {
  2869. var result0, result1, result2;
  2870. var pos0, pos1;
  2871. pos0 = pos;
  2872. pos1 = pos;
  2873. result0 = parse_SWS();
  2874. if (result0 !== null) {
  2875. if (input.charCodeAt(pos) === 41) {
  2876. result1 = ")";
  2877. pos++;
  2878. } else {
  2879. result1 = null;
  2880. if (reportFailures === 0) {
  2881. matchFailed("\")\"");
  2882. }
  2883. }
  2884. if (result1 !== null) {
  2885. result2 = parse_SWS();
  2886. if (result2 !== null) {
  2887. result0 = [result0, result1, result2];
  2888. } else {
  2889. result0 = null;
  2890. pos = pos1;
  2891. }
  2892. } else {
  2893. result0 = null;
  2894. pos = pos1;
  2895. }
  2896. } else {
  2897. result0 = null;
  2898. pos = pos1;
  2899. }
  2900. if (result0 !== null) {
  2901. result0 = (function(offset) {return ")"; })(pos0);
  2902. }
  2903. if (result0 === null) {
  2904. pos = pos0;
  2905. }
  2906. return result0;
  2907. }
  2908. function parse_RAQUOT() {
  2909. var result0, result1;
  2910. var pos0, pos1;
  2911. pos0 = pos;
  2912. pos1 = pos;
  2913. if (input.charCodeAt(pos) === 62) {
  2914. result0 = ">";
  2915. pos++;
  2916. } else {
  2917. result0 = null;
  2918. if (reportFailures === 0) {
  2919. matchFailed("\">\"");
  2920. }
  2921. }
  2922. if (result0 !== null) {
  2923. result1 = parse_SWS();
  2924. if (result1 !== null) {
  2925. result0 = [result0, result1];
  2926. } else {
  2927. result0 = null;
  2928. pos = pos1;
  2929. }
  2930. } else {
  2931. result0 = null;
  2932. pos = pos1;
  2933. }
  2934. if (result0 !== null) {
  2935. result0 = (function(offset) {return ">"; })(pos0);
  2936. }
  2937. if (result0 === null) {
  2938. pos = pos0;
  2939. }
  2940. return result0;
  2941. }
  2942. function parse_LAQUOT() {
  2943. var result0, result1;
  2944. var pos0, pos1;
  2945. pos0 = pos;
  2946. pos1 = pos;
  2947. result0 = parse_SWS();
  2948. if (result0 !== null) {
  2949. if (input.charCodeAt(pos) === 60) {
  2950. result1 = "<";
  2951. pos++;
  2952. } else {
  2953. result1 = null;
  2954. if (reportFailures === 0) {
  2955. matchFailed("\"<\"");
  2956. }
  2957. }
  2958. if (result1 !== null) {
  2959. result0 = [result0, result1];
  2960. } else {
  2961. result0 = null;
  2962. pos = pos1;
  2963. }
  2964. } else {
  2965. result0 = null;
  2966. pos = pos1;
  2967. }
  2968. if (result0 !== null) {
  2969. result0 = (function(offset) {return "<"; })(pos0);
  2970. }
  2971. if (result0 === null) {
  2972. pos = pos0;
  2973. }
  2974. return result0;
  2975. }
  2976. function parse_COMMA() {
  2977. var result0, result1, result2;
  2978. var pos0, pos1;
  2979. pos0 = pos;
  2980. pos1 = pos;
  2981. result0 = parse_SWS();
  2982. if (result0 !== null) {
  2983. if (input.charCodeAt(pos) === 44) {
  2984. result1 = ",";
  2985. pos++;
  2986. } else {
  2987. result1 = null;
  2988. if (reportFailures === 0) {
  2989. matchFailed("\",\"");
  2990. }
  2991. }
  2992. if (result1 !== null) {
  2993. result2 = parse_SWS();
  2994. if (result2 !== null) {
  2995. result0 = [result0, result1, result2];
  2996. } else {
  2997. result0 = null;
  2998. pos = pos1;
  2999. }
  3000. } else {
  3001. result0 = null;
  3002. pos = pos1;
  3003. }
  3004. } else {
  3005. result0 = null;
  3006. pos = pos1;
  3007. }
  3008. if (result0 !== null) {
  3009. result0 = (function(offset) {return ","; })(pos0);
  3010. }
  3011. if (result0 === null) {
  3012. pos = pos0;
  3013. }
  3014. return result0;
  3015. }
  3016. function parse_SEMI() {
  3017. var result0, result1, result2;
  3018. var pos0, pos1;
  3019. pos0 = pos;
  3020. pos1 = pos;
  3021. result0 = parse_SWS();
  3022. if (result0 !== null) {
  3023. if (input.charCodeAt(pos) === 59) {
  3024. result1 = ";";
  3025. pos++;
  3026. } else {
  3027. result1 = null;
  3028. if (reportFailures === 0) {
  3029. matchFailed("\";\"");
  3030. }
  3031. }
  3032. if (result1 !== null) {
  3033. result2 = parse_SWS();
  3034. if (result2 !== null) {
  3035. result0 = [result0, result1, result2];
  3036. } else {
  3037. result0 = null;
  3038. pos = pos1;
  3039. }
  3040. } else {
  3041. result0 = null;
  3042. pos = pos1;
  3043. }
  3044. } else {
  3045. result0 = null;
  3046. pos = pos1;
  3047. }
  3048. if (result0 !== null) {
  3049. result0 = (function(offset) {return ";"; })(pos0);
  3050. }
  3051. if (result0 === null) {
  3052. pos = pos0;
  3053. }
  3054. return result0;
  3055. }
  3056. function parse_COLON() {
  3057. var result0, result1, result2;
  3058. var pos0, pos1;
  3059. pos0 = pos;
  3060. pos1 = pos;
  3061. result0 = parse_SWS();
  3062. if (result0 !== null) {
  3063. if (input.charCodeAt(pos) === 58) {
  3064. result1 = ":";
  3065. pos++;
  3066. } else {
  3067. result1 = null;
  3068. if (reportFailures === 0) {
  3069. matchFailed("\":\"");
  3070. }
  3071. }
  3072. if (result1 !== null) {
  3073. result2 = parse_SWS();
  3074. if (result2 !== null) {
  3075. result0 = [result0, result1, result2];
  3076. } else {
  3077. result0 = null;
  3078. pos = pos1;
  3079. }
  3080. } else {
  3081. result0 = null;
  3082. pos = pos1;
  3083. }
  3084. } else {
  3085. result0 = null;
  3086. pos = pos1;
  3087. }
  3088. if (result0 !== null) {
  3089. result0 = (function(offset) {return ":"; })(pos0);
  3090. }
  3091. if (result0 === null) {
  3092. pos = pos0;
  3093. }
  3094. return result0;
  3095. }
  3096. function parse_LDQUOT() {
  3097. var result0, result1;
  3098. var pos0, pos1;
  3099. pos0 = pos;
  3100. pos1 = pos;
  3101. result0 = parse_SWS();
  3102. if (result0 !== null) {
  3103. result1 = parse_DQUOTE();
  3104. if (result1 !== null) {
  3105. result0 = [result0, result1];
  3106. } else {
  3107. result0 = null;
  3108. pos = pos1;
  3109. }
  3110. } else {
  3111. result0 = null;
  3112. pos = pos1;
  3113. }
  3114. if (result0 !== null) {
  3115. result0 = (function(offset) {return "\""; })(pos0);
  3116. }
  3117. if (result0 === null) {
  3118. pos = pos0;
  3119. }
  3120. return result0;
  3121. }
  3122. function parse_RDQUOT() {
  3123. var result0, result1;
  3124. var pos0, pos1;
  3125. pos0 = pos;
  3126. pos1 = pos;
  3127. result0 = parse_DQUOTE();
  3128. if (result0 !== null) {
  3129. result1 = parse_SWS();
  3130. if (result1 !== null) {
  3131. result0 = [result0, result1];
  3132. } else {
  3133. result0 = null;
  3134. pos = pos1;
  3135. }
  3136. } else {
  3137. result0 = null;
  3138. pos = pos1;
  3139. }
  3140. if (result0 !== null) {
  3141. result0 = (function(offset) {return "\""; })(pos0);
  3142. }
  3143. if (result0 === null) {
  3144. pos = pos0;
  3145. }
  3146. return result0;
  3147. }
  3148. function parse_comment() {
  3149. var result0, result1, result2;
  3150. var pos0;
  3151. pos0 = pos;
  3152. result0 = parse_LPAREN();
  3153. if (result0 !== null) {
  3154. result1 = [];
  3155. result2 = parse_ctext();
  3156. if (result2 === null) {
  3157. result2 = parse_quoted_pair();
  3158. if (result2 === null) {
  3159. result2 = parse_comment();
  3160. }
  3161. }
  3162. while (result2 !== null) {
  3163. result1.push(result2);
  3164. result2 = parse_ctext();
  3165. if (result2 === null) {
  3166. result2 = parse_quoted_pair();
  3167. if (result2 === null) {
  3168. result2 = parse_comment();
  3169. }
  3170. }
  3171. }
  3172. if (result1 !== null) {
  3173. result2 = parse_RPAREN();
  3174. if (result2 !== null) {
  3175. result0 = [result0, result1, result2];
  3176. } else {
  3177. result0 = null;
  3178. pos = pos0;
  3179. }
  3180. } else {
  3181. result0 = null;
  3182. pos = pos0;
  3183. }
  3184. } else {
  3185. result0 = null;
  3186. pos = pos0;
  3187. }
  3188. return result0;
  3189. }
  3190. function parse_ctext() {
  3191. var result0;
  3192. if (/^[!-']/.test(input.charAt(pos))) {
  3193. result0 = input.charAt(pos);
  3194. pos++;
  3195. } else {
  3196. result0 = null;
  3197. if (reportFailures === 0) {
  3198. matchFailed("[!-']");
  3199. }
  3200. }
  3201. if (result0 === null) {
  3202. if (/^[*-[]/.test(input.charAt(pos))) {
  3203. result0 = input.charAt(pos);
  3204. pos++;
  3205. } else {
  3206. result0 = null;
  3207. if (reportFailures === 0) {
  3208. matchFailed("[*-[]");
  3209. }
  3210. }
  3211. if (result0 === null) {
  3212. if (/^[\]-~]/.test(input.charAt(pos))) {
  3213. result0 = input.charAt(pos);
  3214. pos++;
  3215. } else {
  3216. result0 = null;
  3217. if (reportFailures === 0) {
  3218. matchFailed("[\\]-~]");
  3219. }
  3220. }
  3221. if (result0 === null) {
  3222. result0 = parse_UTF8_NONASCII();
  3223. if (result0 === null) {
  3224. result0 = parse_LWS();
  3225. }
  3226. }
  3227. }
  3228. }
  3229. return result0;
  3230. }
  3231. function parse_quoted_string() {
  3232. var result0, result1, result2, result3;
  3233. var pos0, pos1;
  3234. pos0 = pos;
  3235. pos1 = pos;
  3236. result0 = parse_SWS();
  3237. if (result0 !== null) {
  3238. result1 = parse_DQUOTE();
  3239. if (result1 !== null) {
  3240. result2 = [];
  3241. result3 = parse_qdtext();
  3242. if (result3 === null) {
  3243. result3 = parse_quoted_pair();
  3244. }
  3245. while (result3 !== null) {
  3246. result2.push(result3);
  3247. result3 = parse_qdtext();
  3248. if (result3 === null) {
  3249. result3 = parse_quoted_pair();
  3250. }
  3251. }
  3252. if (result2 !== null) {
  3253. result3 = parse_DQUOTE();
  3254. if (result3 !== null) {
  3255. result0 = [result0, result1, result2, result3];
  3256. } else {
  3257. result0 = null;
  3258. pos = pos1;
  3259. }
  3260. } else {
  3261. result0 = null;
  3262. pos = pos1;
  3263. }
  3264. } else {
  3265. result0 = null;
  3266. pos = pos1;
  3267. }
  3268. } else {
  3269. result0 = null;
  3270. pos = pos1;
  3271. }
  3272. if (result0 !== null) {
  3273. result0 = (function(offset) {
  3274. return input.substring(pos, offset); })(pos0);
  3275. }
  3276. if (result0 === null) {
  3277. pos = pos0;
  3278. }
  3279. return result0;
  3280. }
  3281. function parse_quoted_string_clean() {
  3282. var result0, result1, result2, result3;
  3283. var pos0, pos1;
  3284. pos0 = pos;
  3285. pos1 = pos;
  3286. result0 = parse_SWS();
  3287. if (result0 !== null) {
  3288. result1 = parse_DQUOTE();
  3289. if (result1 !== null) {
  3290. result2 = [];
  3291. result3 = parse_qdtext();
  3292. if (result3 === null) {
  3293. result3 = parse_quoted_pair();
  3294. }
  3295. while (result3 !== null) {
  3296. result2.push(result3);
  3297. result3 = parse_qdtext();
  3298. if (result3 === null) {
  3299. result3 = parse_quoted_pair();
  3300. }
  3301. }
  3302. if (result2 !== null) {
  3303. result3 = parse_DQUOTE();
  3304. if (result3 !== null) {
  3305. result0 = [result0, result1, result2, result3];
  3306. } else {
  3307. result0 = null;
  3308. pos = pos1;
  3309. }
  3310. } else {
  3311. result0 = null;
  3312. pos = pos1;
  3313. }
  3314. } else {
  3315. result0 = null;
  3316. pos = pos1;
  3317. }
  3318. } else {
  3319. result0 = null;
  3320. pos = pos1;
  3321. }
  3322. if (result0 !== null) {
  3323. result0 = (function(offset) {
  3324. return input.substring(pos-1, offset+1); })(pos0);
  3325. }
  3326. if (result0 === null) {
  3327. pos = pos0;
  3328. }
  3329. return result0;
  3330. }
  3331. function parse_qdtext() {
  3332. var result0;
  3333. result0 = parse_LWS();
  3334. if (result0 === null) {
  3335. if (input.charCodeAt(pos) === 33) {
  3336. result0 = "!";
  3337. pos++;
  3338. } else {
  3339. result0 = null;
  3340. if (reportFailures === 0) {
  3341. matchFailed("\"!\"");
  3342. }
  3343. }
  3344. if (result0 === null) {
  3345. if (/^[#-[]/.test(input.charAt(pos))) {
  3346. result0 = input.charAt(pos);
  3347. pos++;
  3348. } else {
  3349. result0 = null;
  3350. if (reportFailures === 0) {
  3351. matchFailed("[#-[]");
  3352. }
  3353. }
  3354. if (result0 === null) {
  3355. if (/^[\]-~]/.test(input.charAt(pos))) {
  3356. result0 = input.charAt(pos);
  3357. pos++;
  3358. } else {
  3359. result0 = null;
  3360. if (reportFailures === 0) {
  3361. matchFailed("[\\]-~]");
  3362. }
  3363. }
  3364. if (result0 === null) {
  3365. result0 = parse_UTF8_NONASCII();
  3366. }
  3367. }
  3368. }
  3369. }
  3370. return result0;
  3371. }
  3372. function parse_quoted_pair() {
  3373. var result0, result1;
  3374. var pos0;
  3375. pos0 = pos;
  3376. if (input.charCodeAt(pos) === 92) {
  3377. result0 = "\\";
  3378. pos++;
  3379. } else {
  3380. result0 = null;
  3381. if (reportFailures === 0) {
  3382. matchFailed("\"\\\\\"");
  3383. }
  3384. }
  3385. if (result0 !== null) {
  3386. if (/^[\0-\t]/.test(input.charAt(pos))) {
  3387. result1 = input.charAt(pos);
  3388. pos++;
  3389. } else {
  3390. result1 = null;
  3391. if (reportFailures === 0) {
  3392. matchFailed("[\\0-\\t]");
  3393. }
  3394. }
  3395. if (result1 === null) {
  3396. if (/^[\x0B-\f]/.test(input.charAt(pos))) {
  3397. result1 = input.charAt(pos);
  3398. pos++;
  3399. } else {
  3400. result1 = null;
  3401. if (reportFailures === 0) {
  3402. matchFailed("[\\x0B-\\f]");
  3403. }
  3404. }
  3405. if (result1 === null) {
  3406. if (/^[\x0E-]/.test(input.charAt(pos))) {
  3407. result1 = input.charAt(pos);
  3408. pos++;
  3409. } else {
  3410. result1 = null;
  3411. if (reportFailures === 0) {
  3412. matchFailed("[\\x0E-]");
  3413. }
  3414. }
  3415. }
  3416. }
  3417. if (result1 !== null) {
  3418. result0 = [result0, result1];
  3419. } else {
  3420. result0 = null;
  3421. pos = pos0;
  3422. }
  3423. } else {
  3424. result0 = null;
  3425. pos = pos0;
  3426. }
  3427. return result0;
  3428. }
  3429. function parse_SIP_URI_noparams() {
  3430. var result0, result1, result2, result3;
  3431. var pos0, pos1;
  3432. pos0 = pos;
  3433. pos1 = pos;
  3434. result0 = parse_uri_scheme();
  3435. if (result0 !== null) {
  3436. if (input.charCodeAt(pos) === 58) {
  3437. result1 = ":";
  3438. pos++;
  3439. } else {
  3440. result1 = null;
  3441. if (reportFailures === 0) {
  3442. matchFailed("\":\"");
  3443. }
  3444. }
  3445. if (result1 !== null) {
  3446. result2 = parse_userinfo();
  3447. result2 = result2 !== null ? result2 : "";
  3448. if (result2 !== null) {
  3449. result3 = parse_hostport();
  3450. if (result3 !== null) {
  3451. result0 = [result0, result1, result2, result3];
  3452. } else {
  3453. result0 = null;
  3454. pos = pos1;
  3455. }
  3456. } else {
  3457. result0 = null;
  3458. pos = pos1;
  3459. }
  3460. } else {
  3461. result0 = null;
  3462. pos = pos1;
  3463. }
  3464. } else {
  3465. result0 = null;
  3466. pos = pos1;
  3467. }
  3468. if (result0 !== null) {
  3469. result0 = (function(offset) {
  3470. try {
  3471. data.uri = new URI(data.scheme, data.user, data.host, data.port);
  3472. delete data.scheme;
  3473. delete data.user;
  3474. delete data.host;
  3475. delete data.host_type;
  3476. delete data.port;
  3477. } catch(e) {
  3478. data = -1;
  3479. }})(pos0);
  3480. }
  3481. if (result0 === null) {
  3482. pos = pos0;
  3483. }
  3484. return result0;
  3485. }
  3486. function parse_SIP_URI() {
  3487. var result0, result1, result2, result3, result4, result5;
  3488. var pos0, pos1;
  3489. pos0 = pos;
  3490. pos1 = pos;
  3491. result0 = parse_uri_scheme();
  3492. if (result0 !== null) {
  3493. if (input.charCodeAt(pos) === 58) {
  3494. result1 = ":";
  3495. pos++;
  3496. } else {
  3497. result1 = null;
  3498. if (reportFailures === 0) {
  3499. matchFailed("\":\"");
  3500. }
  3501. }
  3502. if (result1 !== null) {
  3503. result2 = parse_userinfo();
  3504. result2 = result2 !== null ? result2 : "";
  3505. if (result2 !== null) {
  3506. result3 = parse_hostport();
  3507. if (result3 !== null) {
  3508. result4 = parse_uri_parameters();
  3509. if (result4 !== null) {
  3510. result5 = parse_headers();
  3511. result5 = result5 !== null ? result5 : "";
  3512. if (result5 !== null) {
  3513. result0 = [result0, result1, result2, result3, result4, result5];
  3514. } else {
  3515. result0 = null;
  3516. pos = pos1;
  3517. }
  3518. } else {
  3519. result0 = null;
  3520. pos = pos1;
  3521. }
  3522. } else {
  3523. result0 = null;
  3524. pos = pos1;
  3525. }
  3526. } else {
  3527. result0 = null;
  3528. pos = pos1;
  3529. }
  3530. } else {
  3531. result0 = null;
  3532. pos = pos1;
  3533. }
  3534. } else {
  3535. result0 = null;
  3536. pos = pos1;
  3537. }
  3538. if (result0 !== null) {
  3539. result0 = (function(offset) {
  3540. var header;
  3541. try {
  3542. data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers);
  3543. delete data.scheme;
  3544. delete data.user;
  3545. delete data.host;
  3546. delete data.host_type;
  3547. delete data.port;
  3548. delete data.uri_params;
  3549. if (startRule === 'SIP_URI') { data = data.uri;}
  3550. } catch(e) {
  3551. data = -1;
  3552. }})(pos0);
  3553. }
  3554. if (result0 === null) {
  3555. pos = pos0;
  3556. }
  3557. return result0;
  3558. }
  3559. function parse_uri_scheme() {
  3560. var result0;
  3561. result0 = parse_uri_scheme_sips();
  3562. if (result0 === null) {
  3563. result0 = parse_uri_scheme_sip();
  3564. }
  3565. return result0;
  3566. }
  3567. function parse_uri_scheme_sips() {
  3568. var result0;
  3569. var pos0;
  3570. pos0 = pos;
  3571. if (input.substr(pos, 4).toLowerCase() === "sips") {
  3572. result0 = input.substr(pos, 4);
  3573. pos += 4;
  3574. } else {
  3575. result0 = null;
  3576. if (reportFailures === 0) {
  3577. matchFailed("\"sips\"");
  3578. }
  3579. }
  3580. if (result0 !== null) {
  3581. result0 = (function(offset, scheme) {
  3582. data.scheme = scheme.toLowerCase(); })(pos0, result0);
  3583. }
  3584. if (result0 === null) {
  3585. pos = pos0;
  3586. }
  3587. return result0;
  3588. }
  3589. function parse_uri_scheme_sip() {
  3590. var result0;
  3591. var pos0;
  3592. pos0 = pos;
  3593. if (input.substr(pos, 3).toLowerCase() === "sip") {
  3594. result0 = input.substr(pos, 3);
  3595. pos += 3;
  3596. } else {
  3597. result0 = null;
  3598. if (reportFailures === 0) {
  3599. matchFailed("\"sip\"");
  3600. }
  3601. }
  3602. if (result0 !== null) {
  3603. result0 = (function(offset, scheme) {
  3604. data.scheme = scheme.toLowerCase(); })(pos0, result0);
  3605. }
  3606. if (result0 === null) {
  3607. pos = pos0;
  3608. }
  3609. return result0;
  3610. }
  3611. function parse_userinfo() {
  3612. var result0, result1, result2;
  3613. var pos0, pos1, pos2;
  3614. pos0 = pos;
  3615. pos1 = pos;
  3616. result0 = parse_user();
  3617. if (result0 !== null) {
  3618. pos2 = pos;
  3619. if (input.charCodeAt(pos) === 58) {
  3620. result1 = ":";
  3621. pos++;
  3622. } else {
  3623. result1 = null;
  3624. if (reportFailures === 0) {
  3625. matchFailed("\":\"");
  3626. }
  3627. }
  3628. if (result1 !== null) {
  3629. result2 = parse_password();
  3630. if (result2 !== null) {
  3631. result1 = [result1, result2];
  3632. } else {
  3633. result1 = null;
  3634. pos = pos2;
  3635. }
  3636. } else {
  3637. result1 = null;
  3638. pos = pos2;
  3639. }
  3640. result1 = result1 !== null ? result1 : "";
  3641. if (result1 !== null) {
  3642. if (input.charCodeAt(pos) === 64) {
  3643. result2 = "@";
  3644. pos++;
  3645. } else {
  3646. result2 = null;
  3647. if (reportFailures === 0) {
  3648. matchFailed("\"@\"");
  3649. }
  3650. }
  3651. if (result2 !== null) {
  3652. result0 = [result0, result1, result2];
  3653. } else {
  3654. result0 = null;
  3655. pos = pos1;
  3656. }
  3657. } else {
  3658. result0 = null;
  3659. pos = pos1;
  3660. }
  3661. } else {
  3662. result0 = null;
  3663. pos = pos1;
  3664. }
  3665. if (result0 !== null) {
  3666. result0 = (function(offset) {
  3667. data.user = decodeURIComponent(input.substring(pos-1, offset));})(pos0);
  3668. }
  3669. if (result0 === null) {
  3670. pos = pos0;
  3671. }
  3672. return result0;
  3673. }
  3674. function parse_user() {
  3675. var result0, result1;
  3676. result1 = parse_unreserved();
  3677. if (result1 === null) {
  3678. result1 = parse_escaped();
  3679. if (result1 === null) {
  3680. result1 = parse_user_unreserved();
  3681. }
  3682. }
  3683. if (result1 !== null) {
  3684. result0 = [];
  3685. while (result1 !== null) {
  3686. result0.push(result1);
  3687. result1 = parse_unreserved();
  3688. if (result1 === null) {
  3689. result1 = parse_escaped();
  3690. if (result1 === null) {
  3691. result1 = parse_user_unreserved();
  3692. }
  3693. }
  3694. }
  3695. } else {
  3696. result0 = null;
  3697. }
  3698. return result0;
  3699. }
  3700. function parse_user_unreserved() {
  3701. var result0;
  3702. if (input.charCodeAt(pos) === 38) {
  3703. result0 = "&";
  3704. pos++;
  3705. } else {
  3706. result0 = null;
  3707. if (reportFailures === 0) {
  3708. matchFailed("\"&\"");
  3709. }
  3710. }
  3711. if (result0 === null) {
  3712. if (input.charCodeAt(pos) === 61) {
  3713. result0 = "=";
  3714. pos++;
  3715. } else {
  3716. result0 = null;
  3717. if (reportFailures === 0) {
  3718. matchFailed("\"=\"");
  3719. }
  3720. }
  3721. if (result0 === null) {
  3722. if (input.charCodeAt(pos) === 43) {
  3723. result0 = "+";
  3724. pos++;
  3725. } else {
  3726. result0 = null;
  3727. if (reportFailures === 0) {
  3728. matchFailed("\"+\"");
  3729. }
  3730. }
  3731. if (result0 === null) {
  3732. if (input.charCodeAt(pos) === 36) {
  3733. result0 = "$";
  3734. pos++;
  3735. } else {
  3736. result0 = null;
  3737. if (reportFailures === 0) {
  3738. matchFailed("\"$\"");
  3739. }
  3740. }
  3741. if (result0 === null) {
  3742. if (input.charCodeAt(pos) === 44) {
  3743. result0 = ",";
  3744. pos++;
  3745. } else {
  3746. result0 = null;
  3747. if (reportFailures === 0) {
  3748. matchFailed("\",\"");
  3749. }
  3750. }
  3751. if (result0 === null) {
  3752. if (input.charCodeAt(pos) === 59) {
  3753. result0 = ";";
  3754. pos++;
  3755. } else {
  3756. result0 = null;
  3757. if (reportFailures === 0) {
  3758. matchFailed("\";\"");
  3759. }
  3760. }
  3761. if (result0 === null) {
  3762. if (input.charCodeAt(pos) === 63) {
  3763. result0 = "?";
  3764. pos++;
  3765. } else {
  3766. result0 = null;
  3767. if (reportFailures === 0) {
  3768. matchFailed("\"?\"");
  3769. }
  3770. }
  3771. if (result0 === null) {
  3772. if (input.charCodeAt(pos) === 47) {
  3773. result0 = "/";
  3774. pos++;
  3775. } else {
  3776. result0 = null;
  3777. if (reportFailures === 0) {
  3778. matchFailed("\"/\"");
  3779. }
  3780. }
  3781. }
  3782. }
  3783. }
  3784. }
  3785. }
  3786. }
  3787. }
  3788. return result0;
  3789. }
  3790. function parse_password() {
  3791. var result0, result1;
  3792. var pos0;
  3793. pos0 = pos;
  3794. result0 = [];
  3795. result1 = parse_unreserved();
  3796. if (result1 === null) {
  3797. result1 = parse_escaped();
  3798. if (result1 === null) {
  3799. if (input.charCodeAt(pos) === 38) {
  3800. result1 = "&";
  3801. pos++;
  3802. } else {
  3803. result1 = null;
  3804. if (reportFailures === 0) {
  3805. matchFailed("\"&\"");
  3806. }
  3807. }
  3808. if (result1 === null) {
  3809. if (input.charCodeAt(pos) === 61) {
  3810. result1 = "=";
  3811. pos++;
  3812. } else {
  3813. result1 = null;
  3814. if (reportFailures === 0) {
  3815. matchFailed("\"=\"");
  3816. }
  3817. }
  3818. if (result1 === null) {
  3819. if (input.charCodeAt(pos) === 43) {
  3820. result1 = "+";
  3821. pos++;
  3822. } else {
  3823. result1 = null;
  3824. if (reportFailures === 0) {
  3825. matchFailed("\"+\"");
  3826. }
  3827. }
  3828. if (result1 === null) {
  3829. if (input.charCodeAt(pos) === 36) {
  3830. result1 = "$";
  3831. pos++;
  3832. } else {
  3833. result1 = null;
  3834. if (reportFailures === 0) {
  3835. matchFailed("\"$\"");
  3836. }
  3837. }
  3838. if (result1 === null) {
  3839. if (input.charCodeAt(pos) === 44) {
  3840. result1 = ",";
  3841. pos++;
  3842. } else {
  3843. result1 = null;
  3844. if (reportFailures === 0) {
  3845. matchFailed("\",\"");
  3846. }
  3847. }
  3848. }
  3849. }
  3850. }
  3851. }
  3852. }
  3853. }
  3854. while (result1 !== null) {
  3855. result0.push(result1);
  3856. result1 = parse_unreserved();
  3857. if (result1 === null) {
  3858. result1 = parse_escaped();
  3859. if (result1 === null) {
  3860. if (input.charCodeAt(pos) === 38) {
  3861. result1 = "&";
  3862. pos++;
  3863. } else {
  3864. result1 = null;
  3865. if (reportFailures === 0) {
  3866. matchFailed("\"&\"");
  3867. }
  3868. }
  3869. if (result1 === null) {
  3870. if (input.charCodeAt(pos) === 61) {
  3871. result1 = "=";
  3872. pos++;
  3873. } else {
  3874. result1 = null;
  3875. if (reportFailures === 0) {
  3876. matchFailed("\"=\"");
  3877. }
  3878. }
  3879. if (result1 === null) {
  3880. if (input.charCodeAt(pos) === 43) {
  3881. result1 = "+";
  3882. pos++;
  3883. } else {
  3884. result1 = null;
  3885. if (reportFailures === 0) {
  3886. matchFailed("\"+\"");
  3887. }
  3888. }
  3889. if (result1 === null) {
  3890. if (input.charCodeAt(pos) === 36) {
  3891. result1 = "$";
  3892. pos++;
  3893. } else {
  3894. result1 = null;
  3895. if (reportFailures === 0) {
  3896. matchFailed("\"$\"");
  3897. }
  3898. }
  3899. if (result1 === null) {
  3900. if (input.charCodeAt(pos) === 44) {
  3901. result1 = ",";
  3902. pos++;
  3903. } else {
  3904. result1 = null;
  3905. if (reportFailures === 0) {
  3906. matchFailed("\",\"");
  3907. }
  3908. }
  3909. }
  3910. }
  3911. }
  3912. }
  3913. }
  3914. }
  3915. }
  3916. if (result0 !== null) {
  3917. result0 = (function(offset) {
  3918. data.password = input.substring(pos, offset); })(pos0);
  3919. }
  3920. if (result0 === null) {
  3921. pos = pos0;
  3922. }
  3923. return result0;
  3924. }
  3925. function parse_hostport() {
  3926. var result0, result1, result2;
  3927. var pos0, pos1;
  3928. pos0 = pos;
  3929. result0 = parse_host();
  3930. if (result0 !== null) {
  3931. pos1 = pos;
  3932. if (input.charCodeAt(pos) === 58) {
  3933. result1 = ":";
  3934. pos++;
  3935. } else {
  3936. result1 = null;
  3937. if (reportFailures === 0) {
  3938. matchFailed("\":\"");
  3939. }
  3940. }
  3941. if (result1 !== null) {
  3942. result2 = parse_port();
  3943. if (result2 !== null) {
  3944. result1 = [result1, result2];
  3945. } else {
  3946. result1 = null;
  3947. pos = pos1;
  3948. }
  3949. } else {
  3950. result1 = null;
  3951. pos = pos1;
  3952. }
  3953. result1 = result1 !== null ? result1 : "";
  3954. if (result1 !== null) {
  3955. result0 = [result0, result1];
  3956. } else {
  3957. result0 = null;
  3958. pos = pos0;
  3959. }
  3960. } else {
  3961. result0 = null;
  3962. pos = pos0;
  3963. }
  3964. return result0;
  3965. }
  3966. function parse_host() {
  3967. var result0;
  3968. var pos0;
  3969. pos0 = pos;
  3970. result0 = parse_hostname();
  3971. if (result0 === null) {
  3972. result0 = parse_IPv4address();
  3973. if (result0 === null) {
  3974. result0 = parse_IPv6reference();
  3975. }
  3976. }
  3977. if (result0 !== null) {
  3978. result0 = (function(offset) {
  3979. data.host = input.substring(pos, offset).toLowerCase();
  3980. return data.host; })(pos0);
  3981. }
  3982. if (result0 === null) {
  3983. pos = pos0;
  3984. }
  3985. return result0;
  3986. }
  3987. function parse_hostname() {
  3988. var result0, result1, result2;
  3989. var pos0, pos1, pos2;
  3990. pos0 = pos;
  3991. pos1 = pos;
  3992. result0 = [];
  3993. pos2 = pos;
  3994. result1 = parse_domainlabel();
  3995. if (result1 !== null) {
  3996. if (input.charCodeAt(pos) === 46) {
  3997. result2 = ".";
  3998. pos++;
  3999. } else {
  4000. result2 = null;
  4001. if (reportFailures === 0) {
  4002. matchFailed("\".\"");
  4003. }
  4004. }
  4005. if (result2 !== null) {
  4006. result1 = [result1, result2];
  4007. } else {
  4008. result1 = null;
  4009. pos = pos2;
  4010. }
  4011. } else {
  4012. result1 = null;
  4013. pos = pos2;
  4014. }
  4015. while (result1 !== null) {
  4016. result0.push(result1);
  4017. pos2 = pos;
  4018. result1 = parse_domainlabel();
  4019. if (result1 !== null) {
  4020. if (input.charCodeAt(pos) === 46) {
  4021. result2 = ".";
  4022. pos++;
  4023. } else {
  4024. result2 = null;
  4025. if (reportFailures === 0) {
  4026. matchFailed("\".\"");
  4027. }
  4028. }
  4029. if (result2 !== null) {
  4030. result1 = [result1, result2];
  4031. } else {
  4032. result1 = null;
  4033. pos = pos2;
  4034. }
  4035. } else {
  4036. result1 = null;
  4037. pos = pos2;
  4038. }
  4039. }
  4040. if (result0 !== null) {
  4041. result1 = parse_toplabel();
  4042. if (result1 !== null) {
  4043. if (input.charCodeAt(pos) === 46) {
  4044. result2 = ".";
  4045. pos++;
  4046. } else {
  4047. result2 = null;
  4048. if (reportFailures === 0) {
  4049. matchFailed("\".\"");
  4050. }
  4051. }
  4052. result2 = result2 !== null ? result2 : "";
  4053. if (result2 !== null) {
  4054. result0 = [result0, result1, result2];
  4055. } else {
  4056. result0 = null;
  4057. pos = pos1;
  4058. }
  4059. } else {
  4060. result0 = null;
  4061. pos = pos1;
  4062. }
  4063. } else {
  4064. result0 = null;
  4065. pos = pos1;
  4066. }
  4067. if (result0 !== null) {
  4068. result0 = (function(offset) {
  4069. data.host_type = 'domain';
  4070. return input.substring(pos, offset); })(pos0);
  4071. }
  4072. if (result0 === null) {
  4073. pos = pos0;
  4074. }
  4075. return result0;
  4076. }
  4077. function parse_domainlabel() {
  4078. var result0, result1, result2;
  4079. var pos0;
  4080. pos0 = pos;
  4081. result0 = parse_alphanum();
  4082. if (result0 !== null) {
  4083. result1 = [];
  4084. result2 = parse_alphanum();
  4085. if (result2 === null) {
  4086. if (input.charCodeAt(pos) === 45) {
  4087. result2 = "-";
  4088. pos++;
  4089. } else {
  4090. result2 = null;
  4091. if (reportFailures === 0) {
  4092. matchFailed("\"-\"");
  4093. }
  4094. }
  4095. if (result2 === null) {
  4096. if (input.charCodeAt(pos) === 95) {
  4097. result2 = "_";
  4098. pos++;
  4099. } else {
  4100. result2 = null;
  4101. if (reportFailures === 0) {
  4102. matchFailed("\"_\"");
  4103. }
  4104. }
  4105. }
  4106. }
  4107. while (result2 !== null) {
  4108. result1.push(result2);
  4109. result2 = parse_alphanum();
  4110. if (result2 === null) {
  4111. if (input.charCodeAt(pos) === 45) {
  4112. result2 = "-";
  4113. pos++;
  4114. } else {
  4115. result2 = null;
  4116. if (reportFailures === 0) {
  4117. matchFailed("\"-\"");
  4118. }
  4119. }
  4120. if (result2 === null) {
  4121. if (input.charCodeAt(pos) === 95) {
  4122. result2 = "_";
  4123. pos++;
  4124. } else {
  4125. result2 = null;
  4126. if (reportFailures === 0) {
  4127. matchFailed("\"_\"");
  4128. }
  4129. }
  4130. }
  4131. }
  4132. }
  4133. if (result1 !== null) {
  4134. result0 = [result0, result1];
  4135. } else {
  4136. result0 = null;
  4137. pos = pos0;
  4138. }
  4139. } else {
  4140. result0 = null;
  4141. pos = pos0;
  4142. }
  4143. return result0;
  4144. }
  4145. function parse_toplabel() {
  4146. var result0, result1, result2;
  4147. var pos0;
  4148. pos0 = pos;
  4149. result0 = parse_ALPHA();
  4150. if (result0 !== null) {
  4151. result1 = [];
  4152. result2 = parse_alphanum();
  4153. if (result2 === null) {
  4154. if (input.charCodeAt(pos) === 45) {
  4155. result2 = "-";
  4156. pos++;
  4157. } else {
  4158. result2 = null;
  4159. if (reportFailures === 0) {
  4160. matchFailed("\"-\"");
  4161. }
  4162. }
  4163. if (result2 === null) {
  4164. if (input.charCodeAt(pos) === 95) {
  4165. result2 = "_";
  4166. pos++;
  4167. } else {
  4168. result2 = null;
  4169. if (reportFailures === 0) {
  4170. matchFailed("\"_\"");
  4171. }
  4172. }
  4173. }
  4174. }
  4175. while (result2 !== null) {
  4176. result1.push(result2);
  4177. result2 = parse_alphanum();
  4178. if (result2 === null) {
  4179. if (input.charCodeAt(pos) === 45) {
  4180. result2 = "-";
  4181. pos++;
  4182. } else {
  4183. result2 = null;
  4184. if (reportFailures === 0) {
  4185. matchFailed("\"-\"");
  4186. }
  4187. }
  4188. if (result2 === null) {
  4189. if (input.charCodeAt(pos) === 95) {
  4190. result2 = "_";
  4191. pos++;
  4192. } else {
  4193. result2 = null;
  4194. if (reportFailures === 0) {
  4195. matchFailed("\"_\"");
  4196. }
  4197. }
  4198. }
  4199. }
  4200. }
  4201. if (result1 !== null) {
  4202. result0 = [result0, result1];
  4203. } else {
  4204. result0 = null;
  4205. pos = pos0;
  4206. }
  4207. } else {
  4208. result0 = null;
  4209. pos = pos0;
  4210. }
  4211. return result0;
  4212. }
  4213. function parse_IPv6reference() {
  4214. var result0, result1, result2;
  4215. var pos0, pos1;
  4216. pos0 = pos;
  4217. pos1 = pos;
  4218. if (input.charCodeAt(pos) === 91) {
  4219. result0 = "[";
  4220. pos++;
  4221. } else {
  4222. result0 = null;
  4223. if (reportFailures === 0) {
  4224. matchFailed("\"[\"");
  4225. }
  4226. }
  4227. if (result0 !== null) {
  4228. result1 = parse_IPv6address();
  4229. if (result1 !== null) {
  4230. if (input.charCodeAt(pos) === 93) {
  4231. result2 = "]";
  4232. pos++;
  4233. } else {
  4234. result2 = null;
  4235. if (reportFailures === 0) {
  4236. matchFailed("\"]\"");
  4237. }
  4238. }
  4239. if (result2 !== null) {
  4240. result0 = [result0, result1, result2];
  4241. } else {
  4242. result0 = null;
  4243. pos = pos1;
  4244. }
  4245. } else {
  4246. result0 = null;
  4247. pos = pos1;
  4248. }
  4249. } else {
  4250. result0 = null;
  4251. pos = pos1;
  4252. }
  4253. if (result0 !== null) {
  4254. result0 = (function(offset) {
  4255. data.host_type = 'IPv6';
  4256. return input.substring(pos, offset); })(pos0);
  4257. }
  4258. if (result0 === null) {
  4259. pos = pos0;
  4260. }
  4261. return result0;
  4262. }
  4263. function parse_IPv6address() {
  4264. var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12;
  4265. var pos0, pos1, pos2;
  4266. pos0 = pos;
  4267. pos1 = pos;
  4268. result0 = parse_h16();
  4269. if (result0 !== null) {
  4270. if (input.charCodeAt(pos) === 58) {
  4271. result1 = ":";
  4272. pos++;
  4273. } else {
  4274. result1 = null;
  4275. if (reportFailures === 0) {
  4276. matchFailed("\":\"");
  4277. }
  4278. }
  4279. if (result1 !== null) {
  4280. result2 = parse_h16();
  4281. if (result2 !== null) {
  4282. if (input.charCodeAt(pos) === 58) {
  4283. result3 = ":";
  4284. pos++;
  4285. } else {
  4286. result3 = null;
  4287. if (reportFailures === 0) {
  4288. matchFailed("\":\"");
  4289. }
  4290. }
  4291. if (result3 !== null) {
  4292. result4 = parse_h16();
  4293. if (result4 !== null) {
  4294. if (input.charCodeAt(pos) === 58) {
  4295. result5 = ":";
  4296. pos++;
  4297. } else {
  4298. result5 = null;
  4299. if (reportFailures === 0) {
  4300. matchFailed("\":\"");
  4301. }
  4302. }
  4303. if (result5 !== null) {
  4304. result6 = parse_h16();
  4305. if (result6 !== null) {
  4306. if (input.charCodeAt(pos) === 58) {
  4307. result7 = ":";
  4308. pos++;
  4309. } else {
  4310. result7 = null;
  4311. if (reportFailures === 0) {
  4312. matchFailed("\":\"");
  4313. }
  4314. }
  4315. if (result7 !== null) {
  4316. result8 = parse_h16();
  4317. if (result8 !== null) {
  4318. if (input.charCodeAt(pos) === 58) {
  4319. result9 = ":";
  4320. pos++;
  4321. } else {
  4322. result9 = null;
  4323. if (reportFailures === 0) {
  4324. matchFailed("\":\"");
  4325. }
  4326. }
  4327. if (result9 !== null) {
  4328. result10 = parse_h16();
  4329. if (result10 !== null) {
  4330. if (input.charCodeAt(pos) === 58) {
  4331. result11 = ":";
  4332. pos++;
  4333. } else {
  4334. result11 = null;
  4335. if (reportFailures === 0) {
  4336. matchFailed("\":\"");
  4337. }
  4338. }
  4339. if (result11 !== null) {
  4340. result12 = parse_ls32();
  4341. if (result12 !== null) {
  4342. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
  4343. } else {
  4344. result0 = null;
  4345. pos = pos1;
  4346. }
  4347. } else {
  4348. result0 = null;
  4349. pos = pos1;
  4350. }
  4351. } else {
  4352. result0 = null;
  4353. pos = pos1;
  4354. }
  4355. } else {
  4356. result0 = null;
  4357. pos = pos1;
  4358. }
  4359. } else {
  4360. result0 = null;
  4361. pos = pos1;
  4362. }
  4363. } else {
  4364. result0 = null;
  4365. pos = pos1;
  4366. }
  4367. } else {
  4368. result0 = null;
  4369. pos = pos1;
  4370. }
  4371. } else {
  4372. result0 = null;
  4373. pos = pos1;
  4374. }
  4375. } else {
  4376. result0 = null;
  4377. pos = pos1;
  4378. }
  4379. } else {
  4380. result0 = null;
  4381. pos = pos1;
  4382. }
  4383. } else {
  4384. result0 = null;
  4385. pos = pos1;
  4386. }
  4387. } else {
  4388. result0 = null;
  4389. pos = pos1;
  4390. }
  4391. } else {
  4392. result0 = null;
  4393. pos = pos1;
  4394. }
  4395. if (result0 === null) {
  4396. pos1 = pos;
  4397. if (input.substr(pos, 2) === "::") {
  4398. result0 = "::";
  4399. pos += 2;
  4400. } else {
  4401. result0 = null;
  4402. if (reportFailures === 0) {
  4403. matchFailed("\"::\"");
  4404. }
  4405. }
  4406. if (result0 !== null) {
  4407. result1 = parse_h16();
  4408. if (result1 !== null) {
  4409. if (input.charCodeAt(pos) === 58) {
  4410. result2 = ":";
  4411. pos++;
  4412. } else {
  4413. result2 = null;
  4414. if (reportFailures === 0) {
  4415. matchFailed("\":\"");
  4416. }
  4417. }
  4418. if (result2 !== null) {
  4419. result3 = parse_h16();
  4420. if (result3 !== null) {
  4421. if (input.charCodeAt(pos) === 58) {
  4422. result4 = ":";
  4423. pos++;
  4424. } else {
  4425. result4 = null;
  4426. if (reportFailures === 0) {
  4427. matchFailed("\":\"");
  4428. }
  4429. }
  4430. if (result4 !== null) {
  4431. result5 = parse_h16();
  4432. if (result5 !== null) {
  4433. if (input.charCodeAt(pos) === 58) {
  4434. result6 = ":";
  4435. pos++;
  4436. } else {
  4437. result6 = null;
  4438. if (reportFailures === 0) {
  4439. matchFailed("\":\"");
  4440. }
  4441. }
  4442. if (result6 !== null) {
  4443. result7 = parse_h16();
  4444. if (result7 !== null) {
  4445. if (input.charCodeAt(pos) === 58) {
  4446. result8 = ":";
  4447. pos++;
  4448. } else {
  4449. result8 = null;
  4450. if (reportFailures === 0) {
  4451. matchFailed("\":\"");
  4452. }
  4453. }
  4454. if (result8 !== null) {
  4455. result9 = parse_h16();
  4456. if (result9 !== null) {
  4457. if (input.charCodeAt(pos) === 58) {
  4458. result10 = ":";
  4459. pos++;
  4460. } else {
  4461. result10 = null;
  4462. if (reportFailures === 0) {
  4463. matchFailed("\":\"");
  4464. }
  4465. }
  4466. if (result10 !== null) {
  4467. result11 = parse_ls32();
  4468. if (result11 !== null) {
  4469. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11];
  4470. } else {
  4471. result0 = null;
  4472. pos = pos1;
  4473. }
  4474. } else {
  4475. result0 = null;
  4476. pos = pos1;
  4477. }
  4478. } else {
  4479. result0 = null;
  4480. pos = pos1;
  4481. }
  4482. } else {
  4483. result0 = null;
  4484. pos = pos1;
  4485. }
  4486. } else {
  4487. result0 = null;
  4488. pos = pos1;
  4489. }
  4490. } else {
  4491. result0 = null;
  4492. pos = pos1;
  4493. }
  4494. } else {
  4495. result0 = null;
  4496. pos = pos1;
  4497. }
  4498. } else {
  4499. result0 = null;
  4500. pos = pos1;
  4501. }
  4502. } else {
  4503. result0 = null;
  4504. pos = pos1;
  4505. }
  4506. } else {
  4507. result0 = null;
  4508. pos = pos1;
  4509. }
  4510. } else {
  4511. result0 = null;
  4512. pos = pos1;
  4513. }
  4514. } else {
  4515. result0 = null;
  4516. pos = pos1;
  4517. }
  4518. if (result0 === null) {
  4519. pos1 = pos;
  4520. if (input.substr(pos, 2) === "::") {
  4521. result0 = "::";
  4522. pos += 2;
  4523. } else {
  4524. result0 = null;
  4525. if (reportFailures === 0) {
  4526. matchFailed("\"::\"");
  4527. }
  4528. }
  4529. if (result0 !== null) {
  4530. result1 = parse_h16();
  4531. if (result1 !== null) {
  4532. if (input.charCodeAt(pos) === 58) {
  4533. result2 = ":";
  4534. pos++;
  4535. } else {
  4536. result2 = null;
  4537. if (reportFailures === 0) {
  4538. matchFailed("\":\"");
  4539. }
  4540. }
  4541. if (result2 !== null) {
  4542. result3 = parse_h16();
  4543. if (result3 !== null) {
  4544. if (input.charCodeAt(pos) === 58) {
  4545. result4 = ":";
  4546. pos++;
  4547. } else {
  4548. result4 = null;
  4549. if (reportFailures === 0) {
  4550. matchFailed("\":\"");
  4551. }
  4552. }
  4553. if (result4 !== null) {
  4554. result5 = parse_h16();
  4555. if (result5 !== null) {
  4556. if (input.charCodeAt(pos) === 58) {
  4557. result6 = ":";
  4558. pos++;
  4559. } else {
  4560. result6 = null;
  4561. if (reportFailures === 0) {
  4562. matchFailed("\":\"");
  4563. }
  4564. }
  4565. if (result6 !== null) {
  4566. result7 = parse_h16();
  4567. if (result7 !== null) {
  4568. if (input.charCodeAt(pos) === 58) {
  4569. result8 = ":";
  4570. pos++;
  4571. } else {
  4572. result8 = null;
  4573. if (reportFailures === 0) {
  4574. matchFailed("\":\"");
  4575. }
  4576. }
  4577. if (result8 !== null) {
  4578. result9 = parse_ls32();
  4579. if (result9 !== null) {
  4580. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  4581. } else {
  4582. result0 = null;
  4583. pos = pos1;
  4584. }
  4585. } else {
  4586. result0 = null;
  4587. pos = pos1;
  4588. }
  4589. } else {
  4590. result0 = null;
  4591. pos = pos1;
  4592. }
  4593. } else {
  4594. result0 = null;
  4595. pos = pos1;
  4596. }
  4597. } else {
  4598. result0 = null;
  4599. pos = pos1;
  4600. }
  4601. } else {
  4602. result0 = null;
  4603. pos = pos1;
  4604. }
  4605. } else {
  4606. result0 = null;
  4607. pos = pos1;
  4608. }
  4609. } else {
  4610. result0 = null;
  4611. pos = pos1;
  4612. }
  4613. } else {
  4614. result0 = null;
  4615. pos = pos1;
  4616. }
  4617. } else {
  4618. result0 = null;
  4619. pos = pos1;
  4620. }
  4621. if (result0 === null) {
  4622. pos1 = pos;
  4623. if (input.substr(pos, 2) === "::") {
  4624. result0 = "::";
  4625. pos += 2;
  4626. } else {
  4627. result0 = null;
  4628. if (reportFailures === 0) {
  4629. matchFailed("\"::\"");
  4630. }
  4631. }
  4632. if (result0 !== null) {
  4633. result1 = parse_h16();
  4634. if (result1 !== null) {
  4635. if (input.charCodeAt(pos) === 58) {
  4636. result2 = ":";
  4637. pos++;
  4638. } else {
  4639. result2 = null;
  4640. if (reportFailures === 0) {
  4641. matchFailed("\":\"");
  4642. }
  4643. }
  4644. if (result2 !== null) {
  4645. result3 = parse_h16();
  4646. if (result3 !== null) {
  4647. if (input.charCodeAt(pos) === 58) {
  4648. result4 = ":";
  4649. pos++;
  4650. } else {
  4651. result4 = null;
  4652. if (reportFailures === 0) {
  4653. matchFailed("\":\"");
  4654. }
  4655. }
  4656. if (result4 !== null) {
  4657. result5 = parse_h16();
  4658. if (result5 !== null) {
  4659. if (input.charCodeAt(pos) === 58) {
  4660. result6 = ":";
  4661. pos++;
  4662. } else {
  4663. result6 = null;
  4664. if (reportFailures === 0) {
  4665. matchFailed("\":\"");
  4666. }
  4667. }
  4668. if (result6 !== null) {
  4669. result7 = parse_ls32();
  4670. if (result7 !== null) {
  4671. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  4672. } else {
  4673. result0 = null;
  4674. pos = pos1;
  4675. }
  4676. } else {
  4677. result0 = null;
  4678. pos = pos1;
  4679. }
  4680. } else {
  4681. result0 = null;
  4682. pos = pos1;
  4683. }
  4684. } else {
  4685. result0 = null;
  4686. pos = pos1;
  4687. }
  4688. } else {
  4689. result0 = null;
  4690. pos = pos1;
  4691. }
  4692. } else {
  4693. result0 = null;
  4694. pos = pos1;
  4695. }
  4696. } else {
  4697. result0 = null;
  4698. pos = pos1;
  4699. }
  4700. } else {
  4701. result0 = null;
  4702. pos = pos1;
  4703. }
  4704. if (result0 === null) {
  4705. pos1 = pos;
  4706. if (input.substr(pos, 2) === "::") {
  4707. result0 = "::";
  4708. pos += 2;
  4709. } else {
  4710. result0 = null;
  4711. if (reportFailures === 0) {
  4712. matchFailed("\"::\"");
  4713. }
  4714. }
  4715. if (result0 !== null) {
  4716. result1 = parse_h16();
  4717. if (result1 !== null) {
  4718. if (input.charCodeAt(pos) === 58) {
  4719. result2 = ":";
  4720. pos++;
  4721. } else {
  4722. result2 = null;
  4723. if (reportFailures === 0) {
  4724. matchFailed("\":\"");
  4725. }
  4726. }
  4727. if (result2 !== null) {
  4728. result3 = parse_h16();
  4729. if (result3 !== null) {
  4730. if (input.charCodeAt(pos) === 58) {
  4731. result4 = ":";
  4732. pos++;
  4733. } else {
  4734. result4 = null;
  4735. if (reportFailures === 0) {
  4736. matchFailed("\":\"");
  4737. }
  4738. }
  4739. if (result4 !== null) {
  4740. result5 = parse_ls32();
  4741. if (result5 !== null) {
  4742. result0 = [result0, result1, result2, result3, result4, result5];
  4743. } else {
  4744. result0 = null;
  4745. pos = pos1;
  4746. }
  4747. } else {
  4748. result0 = null;
  4749. pos = pos1;
  4750. }
  4751. } else {
  4752. result0 = null;
  4753. pos = pos1;
  4754. }
  4755. } else {
  4756. result0 = null;
  4757. pos = pos1;
  4758. }
  4759. } else {
  4760. result0 = null;
  4761. pos = pos1;
  4762. }
  4763. } else {
  4764. result0 = null;
  4765. pos = pos1;
  4766. }
  4767. if (result0 === null) {
  4768. pos1 = pos;
  4769. if (input.substr(pos, 2) === "::") {
  4770. result0 = "::";
  4771. pos += 2;
  4772. } else {
  4773. result0 = null;
  4774. if (reportFailures === 0) {
  4775. matchFailed("\"::\"");
  4776. }
  4777. }
  4778. if (result0 !== null) {
  4779. result1 = parse_h16();
  4780. if (result1 !== null) {
  4781. if (input.charCodeAt(pos) === 58) {
  4782. result2 = ":";
  4783. pos++;
  4784. } else {
  4785. result2 = null;
  4786. if (reportFailures === 0) {
  4787. matchFailed("\":\"");
  4788. }
  4789. }
  4790. if (result2 !== null) {
  4791. result3 = parse_ls32();
  4792. if (result3 !== null) {
  4793. result0 = [result0, result1, result2, result3];
  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. if (result0 === null) {
  4811. pos1 = pos;
  4812. if (input.substr(pos, 2) === "::") {
  4813. result0 = "::";
  4814. pos += 2;
  4815. } else {
  4816. result0 = null;
  4817. if (reportFailures === 0) {
  4818. matchFailed("\"::\"");
  4819. }
  4820. }
  4821. if (result0 !== null) {
  4822. result1 = parse_ls32();
  4823. if (result1 !== null) {
  4824. result0 = [result0, result1];
  4825. } else {
  4826. result0 = null;
  4827. pos = pos1;
  4828. }
  4829. } else {
  4830. result0 = null;
  4831. pos = pos1;
  4832. }
  4833. if (result0 === null) {
  4834. pos1 = pos;
  4835. if (input.substr(pos, 2) === "::") {
  4836. result0 = "::";
  4837. pos += 2;
  4838. } else {
  4839. result0 = null;
  4840. if (reportFailures === 0) {
  4841. matchFailed("\"::\"");
  4842. }
  4843. }
  4844. if (result0 !== null) {
  4845. result1 = parse_h16();
  4846. if (result1 !== null) {
  4847. result0 = [result0, result1];
  4848. } else {
  4849. result0 = null;
  4850. pos = pos1;
  4851. }
  4852. } else {
  4853. result0 = null;
  4854. pos = pos1;
  4855. }
  4856. if (result0 === null) {
  4857. pos1 = pos;
  4858. result0 = parse_h16();
  4859. if (result0 !== null) {
  4860. if (input.substr(pos, 2) === "::") {
  4861. result1 = "::";
  4862. pos += 2;
  4863. } else {
  4864. result1 = null;
  4865. if (reportFailures === 0) {
  4866. matchFailed("\"::\"");
  4867. }
  4868. }
  4869. if (result1 !== null) {
  4870. result2 = parse_h16();
  4871. if (result2 !== null) {
  4872. if (input.charCodeAt(pos) === 58) {
  4873. result3 = ":";
  4874. pos++;
  4875. } else {
  4876. result3 = null;
  4877. if (reportFailures === 0) {
  4878. matchFailed("\":\"");
  4879. }
  4880. }
  4881. if (result3 !== null) {
  4882. result4 = parse_h16();
  4883. if (result4 !== null) {
  4884. if (input.charCodeAt(pos) === 58) {
  4885. result5 = ":";
  4886. pos++;
  4887. } else {
  4888. result5 = null;
  4889. if (reportFailures === 0) {
  4890. matchFailed("\":\"");
  4891. }
  4892. }
  4893. if (result5 !== null) {
  4894. result6 = parse_h16();
  4895. if (result6 !== null) {
  4896. if (input.charCodeAt(pos) === 58) {
  4897. result7 = ":";
  4898. pos++;
  4899. } else {
  4900. result7 = null;
  4901. if (reportFailures === 0) {
  4902. matchFailed("\":\"");
  4903. }
  4904. }
  4905. if (result7 !== null) {
  4906. result8 = parse_h16();
  4907. if (result8 !== null) {
  4908. if (input.charCodeAt(pos) === 58) {
  4909. result9 = ":";
  4910. pos++;
  4911. } else {
  4912. result9 = null;
  4913. if (reportFailures === 0) {
  4914. matchFailed("\":\"");
  4915. }
  4916. }
  4917. if (result9 !== null) {
  4918. result10 = parse_ls32();
  4919. if (result10 !== null) {
  4920. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10];
  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. } else {
  4942. result0 = null;
  4943. pos = pos1;
  4944. }
  4945. } else {
  4946. result0 = null;
  4947. pos = pos1;
  4948. }
  4949. } else {
  4950. result0 = null;
  4951. pos = pos1;
  4952. }
  4953. } else {
  4954. result0 = null;
  4955. pos = pos1;
  4956. }
  4957. } else {
  4958. result0 = null;
  4959. pos = pos1;
  4960. }
  4961. } else {
  4962. result0 = null;
  4963. pos = pos1;
  4964. }
  4965. if (result0 === null) {
  4966. pos1 = pos;
  4967. result0 = parse_h16();
  4968. if (result0 !== null) {
  4969. pos2 = pos;
  4970. if (input.charCodeAt(pos) === 58) {
  4971. result1 = ":";
  4972. pos++;
  4973. } else {
  4974. result1 = null;
  4975. if (reportFailures === 0) {
  4976. matchFailed("\":\"");
  4977. }
  4978. }
  4979. if (result1 !== null) {
  4980. result2 = parse_h16();
  4981. if (result2 !== null) {
  4982. result1 = [result1, result2];
  4983. } else {
  4984. result1 = null;
  4985. pos = pos2;
  4986. }
  4987. } else {
  4988. result1 = null;
  4989. pos = pos2;
  4990. }
  4991. result1 = result1 !== null ? result1 : "";
  4992. if (result1 !== null) {
  4993. if (input.substr(pos, 2) === "::") {
  4994. result2 = "::";
  4995. pos += 2;
  4996. } else {
  4997. result2 = null;
  4998. if (reportFailures === 0) {
  4999. matchFailed("\"::\"");
  5000. }
  5001. }
  5002. if (result2 !== null) {
  5003. result3 = parse_h16();
  5004. if (result3 !== null) {
  5005. if (input.charCodeAt(pos) === 58) {
  5006. result4 = ":";
  5007. pos++;
  5008. } else {
  5009. result4 = null;
  5010. if (reportFailures === 0) {
  5011. matchFailed("\":\"");
  5012. }
  5013. }
  5014. if (result4 !== null) {
  5015. result5 = parse_h16();
  5016. if (result5 !== null) {
  5017. if (input.charCodeAt(pos) === 58) {
  5018. result6 = ":";
  5019. pos++;
  5020. } else {
  5021. result6 = null;
  5022. if (reportFailures === 0) {
  5023. matchFailed("\":\"");
  5024. }
  5025. }
  5026. if (result6 !== null) {
  5027. result7 = parse_h16();
  5028. if (result7 !== null) {
  5029. if (input.charCodeAt(pos) === 58) {
  5030. result8 = ":";
  5031. pos++;
  5032. } else {
  5033. result8 = null;
  5034. if (reportFailures === 0) {
  5035. matchFailed("\":\"");
  5036. }
  5037. }
  5038. if (result8 !== null) {
  5039. result9 = parse_ls32();
  5040. if (result9 !== null) {
  5041. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  5042. } else {
  5043. result0 = null;
  5044. pos = pos1;
  5045. }
  5046. } else {
  5047. result0 = null;
  5048. pos = pos1;
  5049. }
  5050. } else {
  5051. result0 = null;
  5052. pos = pos1;
  5053. }
  5054. } else {
  5055. result0 = null;
  5056. pos = pos1;
  5057. }
  5058. } else {
  5059. result0 = null;
  5060. pos = pos1;
  5061. }
  5062. } else {
  5063. result0 = null;
  5064. pos = pos1;
  5065. }
  5066. } else {
  5067. result0 = null;
  5068. pos = pos1;
  5069. }
  5070. } else {
  5071. result0 = null;
  5072. pos = pos1;
  5073. }
  5074. } else {
  5075. result0 = null;
  5076. pos = pos1;
  5077. }
  5078. } else {
  5079. result0 = null;
  5080. pos = pos1;
  5081. }
  5082. if (result0 === null) {
  5083. pos1 = pos;
  5084. result0 = parse_h16();
  5085. if (result0 !== null) {
  5086. pos2 = pos;
  5087. if (input.charCodeAt(pos) === 58) {
  5088. result1 = ":";
  5089. pos++;
  5090. } else {
  5091. result1 = null;
  5092. if (reportFailures === 0) {
  5093. matchFailed("\":\"");
  5094. }
  5095. }
  5096. if (result1 !== null) {
  5097. result2 = parse_h16();
  5098. if (result2 !== null) {
  5099. result1 = [result1, result2];
  5100. } else {
  5101. result1 = null;
  5102. pos = pos2;
  5103. }
  5104. } else {
  5105. result1 = null;
  5106. pos = pos2;
  5107. }
  5108. result1 = result1 !== null ? result1 : "";
  5109. if (result1 !== null) {
  5110. pos2 = pos;
  5111. if (input.charCodeAt(pos) === 58) {
  5112. result2 = ":";
  5113. pos++;
  5114. } else {
  5115. result2 = null;
  5116. if (reportFailures === 0) {
  5117. matchFailed("\":\"");
  5118. }
  5119. }
  5120. if (result2 !== null) {
  5121. result3 = parse_h16();
  5122. if (result3 !== null) {
  5123. result2 = [result2, result3];
  5124. } else {
  5125. result2 = null;
  5126. pos = pos2;
  5127. }
  5128. } else {
  5129. result2 = null;
  5130. pos = pos2;
  5131. }
  5132. result2 = result2 !== null ? result2 : "";
  5133. if (result2 !== null) {
  5134. if (input.substr(pos, 2) === "::") {
  5135. result3 = "::";
  5136. pos += 2;
  5137. } else {
  5138. result3 = null;
  5139. if (reportFailures === 0) {
  5140. matchFailed("\"::\"");
  5141. }
  5142. }
  5143. if (result3 !== null) {
  5144. result4 = parse_h16();
  5145. if (result4 !== null) {
  5146. if (input.charCodeAt(pos) === 58) {
  5147. result5 = ":";
  5148. pos++;
  5149. } else {
  5150. result5 = null;
  5151. if (reportFailures === 0) {
  5152. matchFailed("\":\"");
  5153. }
  5154. }
  5155. if (result5 !== null) {
  5156. result6 = parse_h16();
  5157. if (result6 !== null) {
  5158. if (input.charCodeAt(pos) === 58) {
  5159. result7 = ":";
  5160. pos++;
  5161. } else {
  5162. result7 = null;
  5163. if (reportFailures === 0) {
  5164. matchFailed("\":\"");
  5165. }
  5166. }
  5167. if (result7 !== null) {
  5168. result8 = parse_ls32();
  5169. if (result8 !== null) {
  5170. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  5171. } else {
  5172. result0 = null;
  5173. pos = pos1;
  5174. }
  5175. } else {
  5176. result0 = null;
  5177. pos = pos1;
  5178. }
  5179. } else {
  5180. result0 = null;
  5181. pos = pos1;
  5182. }
  5183. } else {
  5184. result0 = null;
  5185. pos = pos1;
  5186. }
  5187. } else {
  5188. result0 = null;
  5189. pos = pos1;
  5190. }
  5191. } else {
  5192. result0 = null;
  5193. pos = pos1;
  5194. }
  5195. } else {
  5196. result0 = null;
  5197. pos = pos1;
  5198. }
  5199. } else {
  5200. result0 = null;
  5201. pos = pos1;
  5202. }
  5203. } else {
  5204. result0 = null;
  5205. pos = pos1;
  5206. }
  5207. if (result0 === null) {
  5208. pos1 = pos;
  5209. result0 = parse_h16();
  5210. if (result0 !== null) {
  5211. pos2 = pos;
  5212. if (input.charCodeAt(pos) === 58) {
  5213. result1 = ":";
  5214. pos++;
  5215. } else {
  5216. result1 = null;
  5217. if (reportFailures === 0) {
  5218. matchFailed("\":\"");
  5219. }
  5220. }
  5221. if (result1 !== null) {
  5222. result2 = parse_h16();
  5223. if (result2 !== null) {
  5224. result1 = [result1, result2];
  5225. } else {
  5226. result1 = null;
  5227. pos = pos2;
  5228. }
  5229. } else {
  5230. result1 = null;
  5231. pos = pos2;
  5232. }
  5233. result1 = result1 !== null ? result1 : "";
  5234. if (result1 !== null) {
  5235. pos2 = pos;
  5236. if (input.charCodeAt(pos) === 58) {
  5237. result2 = ":";
  5238. pos++;
  5239. } else {
  5240. result2 = null;
  5241. if (reportFailures === 0) {
  5242. matchFailed("\":\"");
  5243. }
  5244. }
  5245. if (result2 !== null) {
  5246. result3 = parse_h16();
  5247. if (result3 !== null) {
  5248. result2 = [result2, result3];
  5249. } else {
  5250. result2 = null;
  5251. pos = pos2;
  5252. }
  5253. } else {
  5254. result2 = null;
  5255. pos = pos2;
  5256. }
  5257. result2 = result2 !== null ? result2 : "";
  5258. if (result2 !== null) {
  5259. pos2 = pos;
  5260. if (input.charCodeAt(pos) === 58) {
  5261. result3 = ":";
  5262. pos++;
  5263. } else {
  5264. result3 = null;
  5265. if (reportFailures === 0) {
  5266. matchFailed("\":\"");
  5267. }
  5268. }
  5269. if (result3 !== null) {
  5270. result4 = parse_h16();
  5271. if (result4 !== null) {
  5272. result3 = [result3, result4];
  5273. } else {
  5274. result3 = null;
  5275. pos = pos2;
  5276. }
  5277. } else {
  5278. result3 = null;
  5279. pos = pos2;
  5280. }
  5281. result3 = result3 !== null ? result3 : "";
  5282. if (result3 !== null) {
  5283. if (input.substr(pos, 2) === "::") {
  5284. result4 = "::";
  5285. pos += 2;
  5286. } else {
  5287. result4 = null;
  5288. if (reportFailures === 0) {
  5289. matchFailed("\"::\"");
  5290. }
  5291. }
  5292. if (result4 !== null) {
  5293. result5 = parse_h16();
  5294. if (result5 !== null) {
  5295. if (input.charCodeAt(pos) === 58) {
  5296. result6 = ":";
  5297. pos++;
  5298. } else {
  5299. result6 = null;
  5300. if (reportFailures === 0) {
  5301. matchFailed("\":\"");
  5302. }
  5303. }
  5304. if (result6 !== null) {
  5305. result7 = parse_ls32();
  5306. if (result7 !== null) {
  5307. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5308. } else {
  5309. result0 = null;
  5310. pos = pos1;
  5311. }
  5312. } else {
  5313. result0 = null;
  5314. pos = pos1;
  5315. }
  5316. } else {
  5317. result0 = null;
  5318. pos = pos1;
  5319. }
  5320. } else {
  5321. result0 = null;
  5322. pos = pos1;
  5323. }
  5324. } else {
  5325. result0 = null;
  5326. pos = pos1;
  5327. }
  5328. } else {
  5329. result0 = null;
  5330. pos = pos1;
  5331. }
  5332. } else {
  5333. result0 = null;
  5334. pos = pos1;
  5335. }
  5336. } else {
  5337. result0 = null;
  5338. pos = pos1;
  5339. }
  5340. if (result0 === null) {
  5341. pos1 = pos;
  5342. result0 = parse_h16();
  5343. if (result0 !== null) {
  5344. pos2 = pos;
  5345. if (input.charCodeAt(pos) === 58) {
  5346. result1 = ":";
  5347. pos++;
  5348. } else {
  5349. result1 = null;
  5350. if (reportFailures === 0) {
  5351. matchFailed("\":\"");
  5352. }
  5353. }
  5354. if (result1 !== null) {
  5355. result2 = parse_h16();
  5356. if (result2 !== null) {
  5357. result1 = [result1, result2];
  5358. } else {
  5359. result1 = null;
  5360. pos = pos2;
  5361. }
  5362. } else {
  5363. result1 = null;
  5364. pos = pos2;
  5365. }
  5366. result1 = result1 !== null ? result1 : "";
  5367. if (result1 !== null) {
  5368. pos2 = pos;
  5369. if (input.charCodeAt(pos) === 58) {
  5370. result2 = ":";
  5371. pos++;
  5372. } else {
  5373. result2 = null;
  5374. if (reportFailures === 0) {
  5375. matchFailed("\":\"");
  5376. }
  5377. }
  5378. if (result2 !== null) {
  5379. result3 = parse_h16();
  5380. if (result3 !== null) {
  5381. result2 = [result2, result3];
  5382. } else {
  5383. result2 = null;
  5384. pos = pos2;
  5385. }
  5386. } else {
  5387. result2 = null;
  5388. pos = pos2;
  5389. }
  5390. result2 = result2 !== null ? result2 : "";
  5391. if (result2 !== null) {
  5392. pos2 = pos;
  5393. if (input.charCodeAt(pos) === 58) {
  5394. result3 = ":";
  5395. pos++;
  5396. } else {
  5397. result3 = null;
  5398. if (reportFailures === 0) {
  5399. matchFailed("\":\"");
  5400. }
  5401. }
  5402. if (result3 !== null) {
  5403. result4 = parse_h16();
  5404. if (result4 !== null) {
  5405. result3 = [result3, result4];
  5406. } else {
  5407. result3 = null;
  5408. pos = pos2;
  5409. }
  5410. } else {
  5411. result3 = null;
  5412. pos = pos2;
  5413. }
  5414. result3 = result3 !== null ? result3 : "";
  5415. if (result3 !== null) {
  5416. pos2 = pos;
  5417. if (input.charCodeAt(pos) === 58) {
  5418. result4 = ":";
  5419. pos++;
  5420. } else {
  5421. result4 = null;
  5422. if (reportFailures === 0) {
  5423. matchFailed("\":\"");
  5424. }
  5425. }
  5426. if (result4 !== null) {
  5427. result5 = parse_h16();
  5428. if (result5 !== null) {
  5429. result4 = [result4, result5];
  5430. } else {
  5431. result4 = null;
  5432. pos = pos2;
  5433. }
  5434. } else {
  5435. result4 = null;
  5436. pos = pos2;
  5437. }
  5438. result4 = result4 !== null ? result4 : "";
  5439. if (result4 !== null) {
  5440. if (input.substr(pos, 2) === "::") {
  5441. result5 = "::";
  5442. pos += 2;
  5443. } else {
  5444. result5 = null;
  5445. if (reportFailures === 0) {
  5446. matchFailed("\"::\"");
  5447. }
  5448. }
  5449. if (result5 !== null) {
  5450. result6 = parse_ls32();
  5451. if (result6 !== null) {
  5452. result0 = [result0, result1, result2, result3, result4, result5, result6];
  5453. } else {
  5454. result0 = null;
  5455. pos = pos1;
  5456. }
  5457. } else {
  5458. result0 = null;
  5459. pos = pos1;
  5460. }
  5461. } else {
  5462. result0 = null;
  5463. pos = pos1;
  5464. }
  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. if (result0 === null) {
  5482. pos1 = pos;
  5483. result0 = parse_h16();
  5484. if (result0 !== null) {
  5485. pos2 = pos;
  5486. if (input.charCodeAt(pos) === 58) {
  5487. result1 = ":";
  5488. pos++;
  5489. } else {
  5490. result1 = null;
  5491. if (reportFailures === 0) {
  5492. matchFailed("\":\"");
  5493. }
  5494. }
  5495. if (result1 !== null) {
  5496. result2 = parse_h16();
  5497. if (result2 !== null) {
  5498. result1 = [result1, result2];
  5499. } else {
  5500. result1 = null;
  5501. pos = pos2;
  5502. }
  5503. } else {
  5504. result1 = null;
  5505. pos = pos2;
  5506. }
  5507. result1 = result1 !== null ? result1 : "";
  5508. if (result1 !== null) {
  5509. pos2 = pos;
  5510. if (input.charCodeAt(pos) === 58) {
  5511. result2 = ":";
  5512. pos++;
  5513. } else {
  5514. result2 = null;
  5515. if (reportFailures === 0) {
  5516. matchFailed("\":\"");
  5517. }
  5518. }
  5519. if (result2 !== null) {
  5520. result3 = parse_h16();
  5521. if (result3 !== null) {
  5522. result2 = [result2, result3];
  5523. } else {
  5524. result2 = null;
  5525. pos = pos2;
  5526. }
  5527. } else {
  5528. result2 = null;
  5529. pos = pos2;
  5530. }
  5531. result2 = result2 !== null ? result2 : "";
  5532. if (result2 !== null) {
  5533. pos2 = pos;
  5534. if (input.charCodeAt(pos) === 58) {
  5535. result3 = ":";
  5536. pos++;
  5537. } else {
  5538. result3 = null;
  5539. if (reportFailures === 0) {
  5540. matchFailed("\":\"");
  5541. }
  5542. }
  5543. if (result3 !== null) {
  5544. result4 = parse_h16();
  5545. if (result4 !== null) {
  5546. result3 = [result3, result4];
  5547. } else {
  5548. result3 = null;
  5549. pos = pos2;
  5550. }
  5551. } else {
  5552. result3 = null;
  5553. pos = pos2;
  5554. }
  5555. result3 = result3 !== null ? result3 : "";
  5556. if (result3 !== null) {
  5557. pos2 = pos;
  5558. if (input.charCodeAt(pos) === 58) {
  5559. result4 = ":";
  5560. pos++;
  5561. } else {
  5562. result4 = null;
  5563. if (reportFailures === 0) {
  5564. matchFailed("\":\"");
  5565. }
  5566. }
  5567. if (result4 !== null) {
  5568. result5 = parse_h16();
  5569. if (result5 !== null) {
  5570. result4 = [result4, result5];
  5571. } else {
  5572. result4 = null;
  5573. pos = pos2;
  5574. }
  5575. } else {
  5576. result4 = null;
  5577. pos = pos2;
  5578. }
  5579. result4 = result4 !== null ? result4 : "";
  5580. if (result4 !== null) {
  5581. pos2 = pos;
  5582. if (input.charCodeAt(pos) === 58) {
  5583. result5 = ":";
  5584. pos++;
  5585. } else {
  5586. result5 = null;
  5587. if (reportFailures === 0) {
  5588. matchFailed("\":\"");
  5589. }
  5590. }
  5591. if (result5 !== null) {
  5592. result6 = parse_h16();
  5593. if (result6 !== null) {
  5594. result5 = [result5, result6];
  5595. } else {
  5596. result5 = null;
  5597. pos = pos2;
  5598. }
  5599. } else {
  5600. result5 = null;
  5601. pos = pos2;
  5602. }
  5603. result5 = result5 !== null ? result5 : "";
  5604. if (result5 !== null) {
  5605. if (input.substr(pos, 2) === "::") {
  5606. result6 = "::";
  5607. pos += 2;
  5608. } else {
  5609. result6 = null;
  5610. if (reportFailures === 0) {
  5611. matchFailed("\"::\"");
  5612. }
  5613. }
  5614. if (result6 !== null) {
  5615. result7 = parse_h16();
  5616. if (result7 !== null) {
  5617. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  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. } else {
  5631. result0 = null;
  5632. pos = pos1;
  5633. }
  5634. } else {
  5635. result0 = null;
  5636. pos = pos1;
  5637. }
  5638. } else {
  5639. result0 = null;
  5640. pos = pos1;
  5641. }
  5642. } else {
  5643. result0 = null;
  5644. pos = pos1;
  5645. }
  5646. } else {
  5647. result0 = null;
  5648. pos = pos1;
  5649. }
  5650. if (result0 === null) {
  5651. pos1 = pos;
  5652. result0 = parse_h16();
  5653. if (result0 !== null) {
  5654. pos2 = pos;
  5655. if (input.charCodeAt(pos) === 58) {
  5656. result1 = ":";
  5657. pos++;
  5658. } else {
  5659. result1 = null;
  5660. if (reportFailures === 0) {
  5661. matchFailed("\":\"");
  5662. }
  5663. }
  5664. if (result1 !== null) {
  5665. result2 = parse_h16();
  5666. if (result2 !== null) {
  5667. result1 = [result1, result2];
  5668. } else {
  5669. result1 = null;
  5670. pos = pos2;
  5671. }
  5672. } else {
  5673. result1 = null;
  5674. pos = pos2;
  5675. }
  5676. result1 = result1 !== null ? result1 : "";
  5677. if (result1 !== null) {
  5678. pos2 = pos;
  5679. if (input.charCodeAt(pos) === 58) {
  5680. result2 = ":";
  5681. pos++;
  5682. } else {
  5683. result2 = null;
  5684. if (reportFailures === 0) {
  5685. matchFailed("\":\"");
  5686. }
  5687. }
  5688. if (result2 !== null) {
  5689. result3 = parse_h16();
  5690. if (result3 !== null) {
  5691. result2 = [result2, result3];
  5692. } else {
  5693. result2 = null;
  5694. pos = pos2;
  5695. }
  5696. } else {
  5697. result2 = null;
  5698. pos = pos2;
  5699. }
  5700. result2 = result2 !== null ? result2 : "";
  5701. if (result2 !== null) {
  5702. pos2 = pos;
  5703. if (input.charCodeAt(pos) === 58) {
  5704. result3 = ":";
  5705. pos++;
  5706. } else {
  5707. result3 = null;
  5708. if (reportFailures === 0) {
  5709. matchFailed("\":\"");
  5710. }
  5711. }
  5712. if (result3 !== null) {
  5713. result4 = parse_h16();
  5714. if (result4 !== null) {
  5715. result3 = [result3, result4];
  5716. } else {
  5717. result3 = null;
  5718. pos = pos2;
  5719. }
  5720. } else {
  5721. result3 = null;
  5722. pos = pos2;
  5723. }
  5724. result3 = result3 !== null ? result3 : "";
  5725. if (result3 !== null) {
  5726. pos2 = pos;
  5727. if (input.charCodeAt(pos) === 58) {
  5728. result4 = ":";
  5729. pos++;
  5730. } else {
  5731. result4 = null;
  5732. if (reportFailures === 0) {
  5733. matchFailed("\":\"");
  5734. }
  5735. }
  5736. if (result4 !== null) {
  5737. result5 = parse_h16();
  5738. if (result5 !== null) {
  5739. result4 = [result4, result5];
  5740. } else {
  5741. result4 = null;
  5742. pos = pos2;
  5743. }
  5744. } else {
  5745. result4 = null;
  5746. pos = pos2;
  5747. }
  5748. result4 = result4 !== null ? result4 : "";
  5749. if (result4 !== null) {
  5750. pos2 = pos;
  5751. if (input.charCodeAt(pos) === 58) {
  5752. result5 = ":";
  5753. pos++;
  5754. } else {
  5755. result5 = null;
  5756. if (reportFailures === 0) {
  5757. matchFailed("\":\"");
  5758. }
  5759. }
  5760. if (result5 !== null) {
  5761. result6 = parse_h16();
  5762. if (result6 !== null) {
  5763. result5 = [result5, result6];
  5764. } else {
  5765. result5 = null;
  5766. pos = pos2;
  5767. }
  5768. } else {
  5769. result5 = null;
  5770. pos = pos2;
  5771. }
  5772. result5 = result5 !== null ? result5 : "";
  5773. if (result5 !== null) {
  5774. pos2 = pos;
  5775. if (input.charCodeAt(pos) === 58) {
  5776. result6 = ":";
  5777. pos++;
  5778. } else {
  5779. result6 = null;
  5780. if (reportFailures === 0) {
  5781. matchFailed("\":\"");
  5782. }
  5783. }
  5784. if (result6 !== null) {
  5785. result7 = parse_h16();
  5786. if (result7 !== null) {
  5787. result6 = [result6, result7];
  5788. } else {
  5789. result6 = null;
  5790. pos = pos2;
  5791. }
  5792. } else {
  5793. result6 = null;
  5794. pos = pos2;
  5795. }
  5796. result6 = result6 !== null ? result6 : "";
  5797. if (result6 !== null) {
  5798. if (input.substr(pos, 2) === "::") {
  5799. result7 = "::";
  5800. pos += 2;
  5801. } else {
  5802. result7 = null;
  5803. if (reportFailures === 0) {
  5804. matchFailed("\"::\"");
  5805. }
  5806. }
  5807. if (result7 !== null) {
  5808. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5809. } else {
  5810. result0 = null;
  5811. pos = pos1;
  5812. }
  5813. } else {
  5814. result0 = null;
  5815. pos = pos1;
  5816. }
  5817. } else {
  5818. result0 = null;
  5819. pos = pos1;
  5820. }
  5821. } else {
  5822. result0 = null;
  5823. pos = pos1;
  5824. }
  5825. } else {
  5826. result0 = null;
  5827. pos = pos1;
  5828. }
  5829. } else {
  5830. result0 = null;
  5831. pos = pos1;
  5832. }
  5833. } else {
  5834. result0 = null;
  5835. pos = pos1;
  5836. }
  5837. } else {
  5838. result0 = null;
  5839. pos = pos1;
  5840. }
  5841. }
  5842. }
  5843. }
  5844. }
  5845. }
  5846. }
  5847. }
  5848. }
  5849. }
  5850. }
  5851. }
  5852. }
  5853. }
  5854. }
  5855. if (result0 !== null) {
  5856. result0 = (function(offset) {
  5857. data.host_type = 'IPv6';
  5858. return input.substring(pos, offset); })(pos0);
  5859. }
  5860. if (result0 === null) {
  5861. pos = pos0;
  5862. }
  5863. return result0;
  5864. }
  5865. function parse_h16() {
  5866. var result0, result1, result2, result3;
  5867. var pos0;
  5868. pos0 = pos;
  5869. result0 = parse_HEXDIG();
  5870. if (result0 !== null) {
  5871. result1 = parse_HEXDIG();
  5872. result1 = result1 !== null ? result1 : "";
  5873. if (result1 !== null) {
  5874. result2 = parse_HEXDIG();
  5875. result2 = result2 !== null ? result2 : "";
  5876. if (result2 !== null) {
  5877. result3 = parse_HEXDIG();
  5878. result3 = result3 !== null ? result3 : "";
  5879. if (result3 !== null) {
  5880. result0 = [result0, result1, result2, result3];
  5881. } else {
  5882. result0 = null;
  5883. pos = pos0;
  5884. }
  5885. } else {
  5886. result0 = null;
  5887. pos = pos0;
  5888. }
  5889. } else {
  5890. result0 = null;
  5891. pos = pos0;
  5892. }
  5893. } else {
  5894. result0 = null;
  5895. pos = pos0;
  5896. }
  5897. return result0;
  5898. }
  5899. function parse_ls32() {
  5900. var result0, result1, result2;
  5901. var pos0;
  5902. pos0 = pos;
  5903. result0 = parse_h16();
  5904. if (result0 !== null) {
  5905. if (input.charCodeAt(pos) === 58) {
  5906. result1 = ":";
  5907. pos++;
  5908. } else {
  5909. result1 = null;
  5910. if (reportFailures === 0) {
  5911. matchFailed("\":\"");
  5912. }
  5913. }
  5914. if (result1 !== null) {
  5915. result2 = parse_h16();
  5916. if (result2 !== null) {
  5917. result0 = [result0, result1, result2];
  5918. } else {
  5919. result0 = null;
  5920. pos = pos0;
  5921. }
  5922. } else {
  5923. result0 = null;
  5924. pos = pos0;
  5925. }
  5926. } else {
  5927. result0 = null;
  5928. pos = pos0;
  5929. }
  5930. if (result0 === null) {
  5931. result0 = parse_IPv4address();
  5932. }
  5933. return result0;
  5934. }
  5935. function parse_IPv4address() {
  5936. var result0, result1, result2, result3, result4, result5, result6;
  5937. var pos0, pos1;
  5938. pos0 = pos;
  5939. pos1 = pos;
  5940. result0 = parse_dec_octet();
  5941. if (result0 !== null) {
  5942. if (input.charCodeAt(pos) === 46) {
  5943. result1 = ".";
  5944. pos++;
  5945. } else {
  5946. result1 = null;
  5947. if (reportFailures === 0) {
  5948. matchFailed("\".\"");
  5949. }
  5950. }
  5951. if (result1 !== null) {
  5952. result2 = parse_dec_octet();
  5953. if (result2 !== null) {
  5954. if (input.charCodeAt(pos) === 46) {
  5955. result3 = ".";
  5956. pos++;
  5957. } else {
  5958. result3 = null;
  5959. if (reportFailures === 0) {
  5960. matchFailed("\".\"");
  5961. }
  5962. }
  5963. if (result3 !== null) {
  5964. result4 = parse_dec_octet();
  5965. if (result4 !== null) {
  5966. if (input.charCodeAt(pos) === 46) {
  5967. result5 = ".";
  5968. pos++;
  5969. } else {
  5970. result5 = null;
  5971. if (reportFailures === 0) {
  5972. matchFailed("\".\"");
  5973. }
  5974. }
  5975. if (result5 !== null) {
  5976. result6 = parse_dec_octet();
  5977. if (result6 !== null) {
  5978. result0 = [result0, result1, result2, result3, result4, result5, result6];
  5979. } else {
  5980. result0 = null;
  5981. pos = pos1;
  5982. }
  5983. } else {
  5984. result0 = null;
  5985. pos = pos1;
  5986. }
  5987. } else {
  5988. result0 = null;
  5989. pos = pos1;
  5990. }
  5991. } else {
  5992. result0 = null;
  5993. pos = pos1;
  5994. }
  5995. } else {
  5996. result0 = null;
  5997. pos = pos1;
  5998. }
  5999. } else {
  6000. result0 = null;
  6001. pos = pos1;
  6002. }
  6003. } else {
  6004. result0 = null;
  6005. pos = pos1;
  6006. }
  6007. if (result0 !== null) {
  6008. result0 = (function(offset) {
  6009. data.host_type = 'IPv4';
  6010. return input.substring(pos, offset); })(pos0);
  6011. }
  6012. if (result0 === null) {
  6013. pos = pos0;
  6014. }
  6015. return result0;
  6016. }
  6017. function parse_dec_octet() {
  6018. var result0, result1, result2;
  6019. var pos0;
  6020. pos0 = pos;
  6021. if (input.substr(pos, 2) === "25") {
  6022. result0 = "25";
  6023. pos += 2;
  6024. } else {
  6025. result0 = null;
  6026. if (reportFailures === 0) {
  6027. matchFailed("\"25\"");
  6028. }
  6029. }
  6030. if (result0 !== null) {
  6031. if (/^[0-5]/.test(input.charAt(pos))) {
  6032. result1 = input.charAt(pos);
  6033. pos++;
  6034. } else {
  6035. result1 = null;
  6036. if (reportFailures === 0) {
  6037. matchFailed("[0-5]");
  6038. }
  6039. }
  6040. if (result1 !== null) {
  6041. result0 = [result0, result1];
  6042. } else {
  6043. result0 = null;
  6044. pos = pos0;
  6045. }
  6046. } else {
  6047. result0 = null;
  6048. pos = pos0;
  6049. }
  6050. if (result0 === null) {
  6051. pos0 = pos;
  6052. if (input.charCodeAt(pos) === 50) {
  6053. result0 = "2";
  6054. pos++;
  6055. } else {
  6056. result0 = null;
  6057. if (reportFailures === 0) {
  6058. matchFailed("\"2\"");
  6059. }
  6060. }
  6061. if (result0 !== null) {
  6062. if (/^[0-4]/.test(input.charAt(pos))) {
  6063. result1 = input.charAt(pos);
  6064. pos++;
  6065. } else {
  6066. result1 = null;
  6067. if (reportFailures === 0) {
  6068. matchFailed("[0-4]");
  6069. }
  6070. }
  6071. if (result1 !== null) {
  6072. result2 = parse_DIGIT();
  6073. if (result2 !== null) {
  6074. result0 = [result0, result1, result2];
  6075. } else {
  6076. result0 = null;
  6077. pos = pos0;
  6078. }
  6079. } else {
  6080. result0 = null;
  6081. pos = pos0;
  6082. }
  6083. } else {
  6084. result0 = null;
  6085. pos = pos0;
  6086. }
  6087. if (result0 === null) {
  6088. pos0 = pos;
  6089. if (input.charCodeAt(pos) === 49) {
  6090. result0 = "1";
  6091. pos++;
  6092. } else {
  6093. result0 = null;
  6094. if (reportFailures === 0) {
  6095. matchFailed("\"1\"");
  6096. }
  6097. }
  6098. if (result0 !== null) {
  6099. result1 = parse_DIGIT();
  6100. if (result1 !== null) {
  6101. result2 = parse_DIGIT();
  6102. if (result2 !== null) {
  6103. result0 = [result0, result1, result2];
  6104. } else {
  6105. result0 = null;
  6106. pos = pos0;
  6107. }
  6108. } else {
  6109. result0 = null;
  6110. pos = pos0;
  6111. }
  6112. } else {
  6113. result0 = null;
  6114. pos = pos0;
  6115. }
  6116. if (result0 === null) {
  6117. pos0 = pos;
  6118. if (/^[1-9]/.test(input.charAt(pos))) {
  6119. result0 = input.charAt(pos);
  6120. pos++;
  6121. } else {
  6122. result0 = null;
  6123. if (reportFailures === 0) {
  6124. matchFailed("[1-9]");
  6125. }
  6126. }
  6127. if (result0 !== null) {
  6128. result1 = parse_DIGIT();
  6129. if (result1 !== null) {
  6130. result0 = [result0, result1];
  6131. } else {
  6132. result0 = null;
  6133. pos = pos0;
  6134. }
  6135. } else {
  6136. result0 = null;
  6137. pos = pos0;
  6138. }
  6139. if (result0 === null) {
  6140. result0 = parse_DIGIT();
  6141. }
  6142. }
  6143. }
  6144. }
  6145. return result0;
  6146. }
  6147. function parse_port() {
  6148. var result0, result1, result2, result3, result4;
  6149. var pos0, pos1;
  6150. pos0 = pos;
  6151. pos1 = pos;
  6152. result0 = parse_DIGIT();
  6153. result0 = result0 !== null ? result0 : "";
  6154. if (result0 !== null) {
  6155. result1 = parse_DIGIT();
  6156. result1 = result1 !== null ? result1 : "";
  6157. if (result1 !== null) {
  6158. result2 = parse_DIGIT();
  6159. result2 = result2 !== null ? result2 : "";
  6160. if (result2 !== null) {
  6161. result3 = parse_DIGIT();
  6162. result3 = result3 !== null ? result3 : "";
  6163. if (result3 !== null) {
  6164. result4 = parse_DIGIT();
  6165. result4 = result4 !== null ? result4 : "";
  6166. if (result4 !== null) {
  6167. result0 = [result0, result1, result2, result3, result4];
  6168. } else {
  6169. result0 = null;
  6170. pos = pos1;
  6171. }
  6172. } else {
  6173. result0 = null;
  6174. pos = pos1;
  6175. }
  6176. } else {
  6177. result0 = null;
  6178. pos = pos1;
  6179. }
  6180. } else {
  6181. result0 = null;
  6182. pos = pos1;
  6183. }
  6184. } else {
  6185. result0 = null;
  6186. pos = pos1;
  6187. }
  6188. if (result0 !== null) {
  6189. result0 = (function(offset, port) {
  6190. port = parseInt(port.join(''));
  6191. data.port = port;
  6192. return port; })(pos0, result0);
  6193. }
  6194. if (result0 === null) {
  6195. pos = pos0;
  6196. }
  6197. return result0;
  6198. }
  6199. function parse_uri_parameters() {
  6200. var result0, result1, result2;
  6201. var pos0;
  6202. result0 = [];
  6203. pos0 = pos;
  6204. if (input.charCodeAt(pos) === 59) {
  6205. result1 = ";";
  6206. pos++;
  6207. } else {
  6208. result1 = null;
  6209. if (reportFailures === 0) {
  6210. matchFailed("\";\"");
  6211. }
  6212. }
  6213. if (result1 !== null) {
  6214. result2 = parse_uri_parameter();
  6215. if (result2 !== null) {
  6216. result1 = [result1, result2];
  6217. } else {
  6218. result1 = null;
  6219. pos = pos0;
  6220. }
  6221. } else {
  6222. result1 = null;
  6223. pos = pos0;
  6224. }
  6225. while (result1 !== null) {
  6226. result0.push(result1);
  6227. pos0 = pos;
  6228. if (input.charCodeAt(pos) === 59) {
  6229. result1 = ";";
  6230. pos++;
  6231. } else {
  6232. result1 = null;
  6233. if (reportFailures === 0) {
  6234. matchFailed("\";\"");
  6235. }
  6236. }
  6237. if (result1 !== null) {
  6238. result2 = parse_uri_parameter();
  6239. if (result2 !== null) {
  6240. result1 = [result1, result2];
  6241. } else {
  6242. result1 = null;
  6243. pos = pos0;
  6244. }
  6245. } else {
  6246. result1 = null;
  6247. pos = pos0;
  6248. }
  6249. }
  6250. return result0;
  6251. }
  6252. function parse_uri_parameter() {
  6253. var result0;
  6254. result0 = parse_transport_param();
  6255. if (result0 === null) {
  6256. result0 = parse_user_param();
  6257. if (result0 === null) {
  6258. result0 = parse_method_param();
  6259. if (result0 === null) {
  6260. result0 = parse_ttl_param();
  6261. if (result0 === null) {
  6262. result0 = parse_maddr_param();
  6263. if (result0 === null) {
  6264. result0 = parse_lr_param();
  6265. if (result0 === null) {
  6266. result0 = parse_other_param();
  6267. }
  6268. }
  6269. }
  6270. }
  6271. }
  6272. }
  6273. return result0;
  6274. }
  6275. function parse_transport_param() {
  6276. var result0, result1;
  6277. var pos0, pos1;
  6278. pos0 = pos;
  6279. pos1 = pos;
  6280. if (input.substr(pos, 10).toLowerCase() === "transport=") {
  6281. result0 = input.substr(pos, 10);
  6282. pos += 10;
  6283. } else {
  6284. result0 = null;
  6285. if (reportFailures === 0) {
  6286. matchFailed("\"transport=\"");
  6287. }
  6288. }
  6289. if (result0 !== null) {
  6290. if (input.substr(pos, 3).toLowerCase() === "udp") {
  6291. result1 = input.substr(pos, 3);
  6292. pos += 3;
  6293. } else {
  6294. result1 = null;
  6295. if (reportFailures === 0) {
  6296. matchFailed("\"udp\"");
  6297. }
  6298. }
  6299. if (result1 === null) {
  6300. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  6301. result1 = input.substr(pos, 3);
  6302. pos += 3;
  6303. } else {
  6304. result1 = null;
  6305. if (reportFailures === 0) {
  6306. matchFailed("\"tcp\"");
  6307. }
  6308. }
  6309. if (result1 === null) {
  6310. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  6311. result1 = input.substr(pos, 4);
  6312. pos += 4;
  6313. } else {
  6314. result1 = null;
  6315. if (reportFailures === 0) {
  6316. matchFailed("\"sctp\"");
  6317. }
  6318. }
  6319. if (result1 === null) {
  6320. if (input.substr(pos, 3).toLowerCase() === "tls") {
  6321. result1 = input.substr(pos, 3);
  6322. pos += 3;
  6323. } else {
  6324. result1 = null;
  6325. if (reportFailures === 0) {
  6326. matchFailed("\"tls\"");
  6327. }
  6328. }
  6329. if (result1 === null) {
  6330. result1 = parse_token();
  6331. }
  6332. }
  6333. }
  6334. }
  6335. if (result1 !== null) {
  6336. result0 = [result0, result1];
  6337. } else {
  6338. result0 = null;
  6339. pos = pos1;
  6340. }
  6341. } else {
  6342. result0 = null;
  6343. pos = pos1;
  6344. }
  6345. if (result0 !== null) {
  6346. result0 = (function(offset, transport) {
  6347. if(!data.uri_params) data.uri_params={};
  6348. data.uri_params['transport'] = transport.toLowerCase(); })(pos0, result0[1]);
  6349. }
  6350. if (result0 === null) {
  6351. pos = pos0;
  6352. }
  6353. return result0;
  6354. }
  6355. function parse_user_param() {
  6356. var result0, result1;
  6357. var pos0, pos1;
  6358. pos0 = pos;
  6359. pos1 = pos;
  6360. if (input.substr(pos, 5).toLowerCase() === "user=") {
  6361. result0 = input.substr(pos, 5);
  6362. pos += 5;
  6363. } else {
  6364. result0 = null;
  6365. if (reportFailures === 0) {
  6366. matchFailed("\"user=\"");
  6367. }
  6368. }
  6369. if (result0 !== null) {
  6370. if (input.substr(pos, 5).toLowerCase() === "phone") {
  6371. result1 = input.substr(pos, 5);
  6372. pos += 5;
  6373. } else {
  6374. result1 = null;
  6375. if (reportFailures === 0) {
  6376. matchFailed("\"phone\"");
  6377. }
  6378. }
  6379. if (result1 === null) {
  6380. if (input.substr(pos, 2).toLowerCase() === "ip") {
  6381. result1 = input.substr(pos, 2);
  6382. pos += 2;
  6383. } else {
  6384. result1 = null;
  6385. if (reportFailures === 0) {
  6386. matchFailed("\"ip\"");
  6387. }
  6388. }
  6389. if (result1 === null) {
  6390. result1 = parse_token();
  6391. }
  6392. }
  6393. if (result1 !== null) {
  6394. result0 = [result0, result1];
  6395. } else {
  6396. result0 = null;
  6397. pos = pos1;
  6398. }
  6399. } else {
  6400. result0 = null;
  6401. pos = pos1;
  6402. }
  6403. if (result0 !== null) {
  6404. result0 = (function(offset, user) {
  6405. if(!data.uri_params) data.uri_params={};
  6406. data.uri_params['user'] = user.toLowerCase(); })(pos0, result0[1]);
  6407. }
  6408. if (result0 === null) {
  6409. pos = pos0;
  6410. }
  6411. return result0;
  6412. }
  6413. function parse_method_param() {
  6414. var result0, result1;
  6415. var pos0, pos1;
  6416. pos0 = pos;
  6417. pos1 = pos;
  6418. if (input.substr(pos, 7).toLowerCase() === "method=") {
  6419. result0 = input.substr(pos, 7);
  6420. pos += 7;
  6421. } else {
  6422. result0 = null;
  6423. if (reportFailures === 0) {
  6424. matchFailed("\"method=\"");
  6425. }
  6426. }
  6427. if (result0 !== null) {
  6428. result1 = parse_Method();
  6429. if (result1 !== null) {
  6430. result0 = [result0, result1];
  6431. } else {
  6432. result0 = null;
  6433. pos = pos1;
  6434. }
  6435. } else {
  6436. result0 = null;
  6437. pos = pos1;
  6438. }
  6439. if (result0 !== null) {
  6440. result0 = (function(offset, method) {
  6441. if(!data.uri_params) data.uri_params={};
  6442. data.uri_params['method'] = method; })(pos0, result0[1]);
  6443. }
  6444. if (result0 === null) {
  6445. pos = pos0;
  6446. }
  6447. return result0;
  6448. }
  6449. function parse_ttl_param() {
  6450. var result0, result1;
  6451. var pos0, pos1;
  6452. pos0 = pos;
  6453. pos1 = pos;
  6454. if (input.substr(pos, 4).toLowerCase() === "ttl=") {
  6455. result0 = input.substr(pos, 4);
  6456. pos += 4;
  6457. } else {
  6458. result0 = null;
  6459. if (reportFailures === 0) {
  6460. matchFailed("\"ttl=\"");
  6461. }
  6462. }
  6463. if (result0 !== null) {
  6464. result1 = parse_ttl();
  6465. if (result1 !== null) {
  6466. result0 = [result0, result1];
  6467. } else {
  6468. result0 = null;
  6469. pos = pos1;
  6470. }
  6471. } else {
  6472. result0 = null;
  6473. pos = pos1;
  6474. }
  6475. if (result0 !== null) {
  6476. result0 = (function(offset, ttl) {
  6477. if(!data.params) data.params={};
  6478. data.params['ttl'] = ttl; })(pos0, result0[1]);
  6479. }
  6480. if (result0 === null) {
  6481. pos = pos0;
  6482. }
  6483. return result0;
  6484. }
  6485. function parse_maddr_param() {
  6486. var result0, result1;
  6487. var pos0, pos1;
  6488. pos0 = pos;
  6489. pos1 = pos;
  6490. if (input.substr(pos, 6).toLowerCase() === "maddr=") {
  6491. result0 = input.substr(pos, 6);
  6492. pos += 6;
  6493. } else {
  6494. result0 = null;
  6495. if (reportFailures === 0) {
  6496. matchFailed("\"maddr=\"");
  6497. }
  6498. }
  6499. if (result0 !== null) {
  6500. result1 = parse_host();
  6501. if (result1 !== null) {
  6502. result0 = [result0, result1];
  6503. } else {
  6504. result0 = null;
  6505. pos = pos1;
  6506. }
  6507. } else {
  6508. result0 = null;
  6509. pos = pos1;
  6510. }
  6511. if (result0 !== null) {
  6512. result0 = (function(offset, maddr) {
  6513. if(!data.uri_params) data.uri_params={};
  6514. data.uri_params['maddr'] = maddr; })(pos0, result0[1]);
  6515. }
  6516. if (result0 === null) {
  6517. pos = pos0;
  6518. }
  6519. return result0;
  6520. }
  6521. function parse_lr_param() {
  6522. var result0, result1, result2;
  6523. var pos0, pos1, pos2;
  6524. pos0 = pos;
  6525. pos1 = pos;
  6526. if (input.substr(pos, 2).toLowerCase() === "lr") {
  6527. result0 = input.substr(pos, 2);
  6528. pos += 2;
  6529. } else {
  6530. result0 = null;
  6531. if (reportFailures === 0) {
  6532. matchFailed("\"lr\"");
  6533. }
  6534. }
  6535. if (result0 !== null) {
  6536. pos2 = pos;
  6537. if (input.charCodeAt(pos) === 61) {
  6538. result1 = "=";
  6539. pos++;
  6540. } else {
  6541. result1 = null;
  6542. if (reportFailures === 0) {
  6543. matchFailed("\"=\"");
  6544. }
  6545. }
  6546. if (result1 !== null) {
  6547. result2 = parse_token();
  6548. if (result2 !== null) {
  6549. result1 = [result1, result2];
  6550. } else {
  6551. result1 = null;
  6552. pos = pos2;
  6553. }
  6554. } else {
  6555. result1 = null;
  6556. pos = pos2;
  6557. }
  6558. result1 = result1 !== null ? result1 : "";
  6559. if (result1 !== null) {
  6560. result0 = [result0, result1];
  6561. } else {
  6562. result0 = null;
  6563. pos = pos1;
  6564. }
  6565. } else {
  6566. result0 = null;
  6567. pos = pos1;
  6568. }
  6569. if (result0 !== null) {
  6570. result0 = (function(offset) {
  6571. if(!data.uri_params) data.uri_params={};
  6572. data.uri_params['lr'] = undefined; })(pos0);
  6573. }
  6574. if (result0 === null) {
  6575. pos = pos0;
  6576. }
  6577. return result0;
  6578. }
  6579. function parse_other_param() {
  6580. var result0, result1, result2;
  6581. var pos0, pos1, pos2;
  6582. pos0 = pos;
  6583. pos1 = pos;
  6584. result0 = parse_pname();
  6585. if (result0 !== null) {
  6586. pos2 = pos;
  6587. if (input.charCodeAt(pos) === 61) {
  6588. result1 = "=";
  6589. pos++;
  6590. } else {
  6591. result1 = null;
  6592. if (reportFailures === 0) {
  6593. matchFailed("\"=\"");
  6594. }
  6595. }
  6596. if (result1 !== null) {
  6597. result2 = parse_pvalue();
  6598. if (result2 !== null) {
  6599. result1 = [result1, result2];
  6600. } else {
  6601. result1 = null;
  6602. pos = pos2;
  6603. }
  6604. } else {
  6605. result1 = null;
  6606. pos = pos2;
  6607. }
  6608. result1 = result1 !== null ? result1 : "";
  6609. if (result1 !== null) {
  6610. result0 = [result0, result1];
  6611. } else {
  6612. result0 = null;
  6613. pos = pos1;
  6614. }
  6615. } else {
  6616. result0 = null;
  6617. pos = pos1;
  6618. }
  6619. if (result0 !== null) {
  6620. result0 = (function(offset, param, value) {
  6621. if(!data.uri_params) data.uri_params = {};
  6622. if (typeof value === 'undefined'){
  6623. value = undefined;
  6624. }
  6625. else {
  6626. value = value[1];
  6627. }
  6628. data.uri_params[param.toLowerCase()] = value;})(pos0, result0[0], result0[1]);
  6629. }
  6630. if (result0 === null) {
  6631. pos = pos0;
  6632. }
  6633. return result0;
  6634. }
  6635. function parse_pname() {
  6636. var result0, result1;
  6637. var pos0;
  6638. pos0 = pos;
  6639. result1 = parse_paramchar();
  6640. if (result1 !== null) {
  6641. result0 = [];
  6642. while (result1 !== null) {
  6643. result0.push(result1);
  6644. result1 = parse_paramchar();
  6645. }
  6646. } else {
  6647. result0 = null;
  6648. }
  6649. if (result0 !== null) {
  6650. result0 = (function(offset, pname) {return pname.join(''); })(pos0, result0);
  6651. }
  6652. if (result0 === null) {
  6653. pos = pos0;
  6654. }
  6655. return result0;
  6656. }
  6657. function parse_pvalue() {
  6658. var result0, result1;
  6659. var pos0;
  6660. pos0 = pos;
  6661. result1 = parse_paramchar();
  6662. if (result1 !== null) {
  6663. result0 = [];
  6664. while (result1 !== null) {
  6665. result0.push(result1);
  6666. result1 = parse_paramchar();
  6667. }
  6668. } else {
  6669. result0 = null;
  6670. }
  6671. if (result0 !== null) {
  6672. result0 = (function(offset, pvalue) {return pvalue.join(''); })(pos0, result0);
  6673. }
  6674. if (result0 === null) {
  6675. pos = pos0;
  6676. }
  6677. return result0;
  6678. }
  6679. function parse_paramchar() {
  6680. var result0;
  6681. result0 = parse_param_unreserved();
  6682. if (result0 === null) {
  6683. result0 = parse_unreserved();
  6684. if (result0 === null) {
  6685. result0 = parse_escaped();
  6686. }
  6687. }
  6688. return result0;
  6689. }
  6690. function parse_param_unreserved() {
  6691. var result0;
  6692. if (input.charCodeAt(pos) === 91) {
  6693. result0 = "[";
  6694. pos++;
  6695. } else {
  6696. result0 = null;
  6697. if (reportFailures === 0) {
  6698. matchFailed("\"[\"");
  6699. }
  6700. }
  6701. if (result0 === null) {
  6702. if (input.charCodeAt(pos) === 93) {
  6703. result0 = "]";
  6704. pos++;
  6705. } else {
  6706. result0 = null;
  6707. if (reportFailures === 0) {
  6708. matchFailed("\"]\"");
  6709. }
  6710. }
  6711. if (result0 === null) {
  6712. if (input.charCodeAt(pos) === 47) {
  6713. result0 = "/";
  6714. pos++;
  6715. } else {
  6716. result0 = null;
  6717. if (reportFailures === 0) {
  6718. matchFailed("\"/\"");
  6719. }
  6720. }
  6721. if (result0 === null) {
  6722. if (input.charCodeAt(pos) === 58) {
  6723. result0 = ":";
  6724. pos++;
  6725. } else {
  6726. result0 = null;
  6727. if (reportFailures === 0) {
  6728. matchFailed("\":\"");
  6729. }
  6730. }
  6731. if (result0 === null) {
  6732. if (input.charCodeAt(pos) === 38) {
  6733. result0 = "&";
  6734. pos++;
  6735. } else {
  6736. result0 = null;
  6737. if (reportFailures === 0) {
  6738. matchFailed("\"&\"");
  6739. }
  6740. }
  6741. if (result0 === null) {
  6742. if (input.charCodeAt(pos) === 43) {
  6743. result0 = "+";
  6744. pos++;
  6745. } else {
  6746. result0 = null;
  6747. if (reportFailures === 0) {
  6748. matchFailed("\"+\"");
  6749. }
  6750. }
  6751. if (result0 === null) {
  6752. if (input.charCodeAt(pos) === 36) {
  6753. result0 = "$";
  6754. pos++;
  6755. } else {
  6756. result0 = null;
  6757. if (reportFailures === 0) {
  6758. matchFailed("\"$\"");
  6759. }
  6760. }
  6761. }
  6762. }
  6763. }
  6764. }
  6765. }
  6766. }
  6767. return result0;
  6768. }
  6769. function parse_headers() {
  6770. var result0, result1, result2, result3, result4;
  6771. var pos0, pos1;
  6772. pos0 = pos;
  6773. if (input.charCodeAt(pos) === 63) {
  6774. result0 = "?";
  6775. pos++;
  6776. } else {
  6777. result0 = null;
  6778. if (reportFailures === 0) {
  6779. matchFailed("\"?\"");
  6780. }
  6781. }
  6782. if (result0 !== null) {
  6783. result1 = parse_header();
  6784. if (result1 !== null) {
  6785. result2 = [];
  6786. pos1 = pos;
  6787. if (input.charCodeAt(pos) === 38) {
  6788. result3 = "&";
  6789. pos++;
  6790. } else {
  6791. result3 = null;
  6792. if (reportFailures === 0) {
  6793. matchFailed("\"&\"");
  6794. }
  6795. }
  6796. if (result3 !== null) {
  6797. result4 = parse_header();
  6798. if (result4 !== null) {
  6799. result3 = [result3, result4];
  6800. } else {
  6801. result3 = null;
  6802. pos = pos1;
  6803. }
  6804. } else {
  6805. result3 = null;
  6806. pos = pos1;
  6807. }
  6808. while (result3 !== null) {
  6809. result2.push(result3);
  6810. pos1 = pos;
  6811. if (input.charCodeAt(pos) === 38) {
  6812. result3 = "&";
  6813. pos++;
  6814. } else {
  6815. result3 = null;
  6816. if (reportFailures === 0) {
  6817. matchFailed("\"&\"");
  6818. }
  6819. }
  6820. if (result3 !== null) {
  6821. result4 = parse_header();
  6822. if (result4 !== null) {
  6823. result3 = [result3, result4];
  6824. } else {
  6825. result3 = null;
  6826. pos = pos1;
  6827. }
  6828. } else {
  6829. result3 = null;
  6830. pos = pos1;
  6831. }
  6832. }
  6833. if (result2 !== null) {
  6834. result0 = [result0, result1, result2];
  6835. } else {
  6836. result0 = null;
  6837. pos = pos0;
  6838. }
  6839. } else {
  6840. result0 = null;
  6841. pos = pos0;
  6842. }
  6843. } else {
  6844. result0 = null;
  6845. pos = pos0;
  6846. }
  6847. return result0;
  6848. }
  6849. function parse_header() {
  6850. var result0, result1, result2;
  6851. var pos0, pos1;
  6852. pos0 = pos;
  6853. pos1 = pos;
  6854. result0 = parse_hname();
  6855. if (result0 !== null) {
  6856. if (input.charCodeAt(pos) === 61) {
  6857. result1 = "=";
  6858. pos++;
  6859. } else {
  6860. result1 = null;
  6861. if (reportFailures === 0) {
  6862. matchFailed("\"=\"");
  6863. }
  6864. }
  6865. if (result1 !== null) {
  6866. result2 = parse_hvalue();
  6867. if (result2 !== null) {
  6868. result0 = [result0, result1, result2];
  6869. } else {
  6870. result0 = null;
  6871. pos = pos1;
  6872. }
  6873. } else {
  6874. result0 = null;
  6875. pos = pos1;
  6876. }
  6877. } else {
  6878. result0 = null;
  6879. pos = pos1;
  6880. }
  6881. if (result0 !== null) {
  6882. result0 = (function(offset, hname, hvalue) {
  6883. hname = hname.join('').toLowerCase();
  6884. hvalue = hvalue.join('');
  6885. if(!data.uri_headers) data.uri_headers = {};
  6886. if (!data.uri_headers[hname]) {
  6887. data.uri_headers[hname] = [hvalue];
  6888. } else {
  6889. data.uri_headers[hname].push(hvalue);
  6890. }})(pos0, result0[0], result0[2]);
  6891. }
  6892. if (result0 === null) {
  6893. pos = pos0;
  6894. }
  6895. return result0;
  6896. }
  6897. function parse_hname() {
  6898. var result0, result1;
  6899. result1 = parse_hnv_unreserved();
  6900. if (result1 === null) {
  6901. result1 = parse_unreserved();
  6902. if (result1 === null) {
  6903. result1 = parse_escaped();
  6904. }
  6905. }
  6906. if (result1 !== null) {
  6907. result0 = [];
  6908. while (result1 !== null) {
  6909. result0.push(result1);
  6910. result1 = parse_hnv_unreserved();
  6911. if (result1 === null) {
  6912. result1 = parse_unreserved();
  6913. if (result1 === null) {
  6914. result1 = parse_escaped();
  6915. }
  6916. }
  6917. }
  6918. } else {
  6919. result0 = null;
  6920. }
  6921. return result0;
  6922. }
  6923. function parse_hvalue() {
  6924. var result0, result1;
  6925. result0 = [];
  6926. result1 = parse_hnv_unreserved();
  6927. if (result1 === null) {
  6928. result1 = parse_unreserved();
  6929. if (result1 === null) {
  6930. result1 = parse_escaped();
  6931. }
  6932. }
  6933. while (result1 !== null) {
  6934. result0.push(result1);
  6935. result1 = parse_hnv_unreserved();
  6936. if (result1 === null) {
  6937. result1 = parse_unreserved();
  6938. if (result1 === null) {
  6939. result1 = parse_escaped();
  6940. }
  6941. }
  6942. }
  6943. return result0;
  6944. }
  6945. function parse_hnv_unreserved() {
  6946. var result0;
  6947. if (input.charCodeAt(pos) === 91) {
  6948. result0 = "[";
  6949. pos++;
  6950. } else {
  6951. result0 = null;
  6952. if (reportFailures === 0) {
  6953. matchFailed("\"[\"");
  6954. }
  6955. }
  6956. if (result0 === null) {
  6957. if (input.charCodeAt(pos) === 93) {
  6958. result0 = "]";
  6959. pos++;
  6960. } else {
  6961. result0 = null;
  6962. if (reportFailures === 0) {
  6963. matchFailed("\"]\"");
  6964. }
  6965. }
  6966. if (result0 === null) {
  6967. if (input.charCodeAt(pos) === 47) {
  6968. result0 = "/";
  6969. pos++;
  6970. } else {
  6971. result0 = null;
  6972. if (reportFailures === 0) {
  6973. matchFailed("\"/\"");
  6974. }
  6975. }
  6976. if (result0 === null) {
  6977. if (input.charCodeAt(pos) === 63) {
  6978. result0 = "?";
  6979. pos++;
  6980. } else {
  6981. result0 = null;
  6982. if (reportFailures === 0) {
  6983. matchFailed("\"?\"");
  6984. }
  6985. }
  6986. if (result0 === null) {
  6987. if (input.charCodeAt(pos) === 58) {
  6988. result0 = ":";
  6989. pos++;
  6990. } else {
  6991. result0 = null;
  6992. if (reportFailures === 0) {
  6993. matchFailed("\":\"");
  6994. }
  6995. }
  6996. if (result0 === null) {
  6997. if (input.charCodeAt(pos) === 43) {
  6998. result0 = "+";
  6999. pos++;
  7000. } else {
  7001. result0 = null;
  7002. if (reportFailures === 0) {
  7003. matchFailed("\"+\"");
  7004. }
  7005. }
  7006. if (result0 === null) {
  7007. if (input.charCodeAt(pos) === 36) {
  7008. result0 = "$";
  7009. pos++;
  7010. } else {
  7011. result0 = null;
  7012. if (reportFailures === 0) {
  7013. matchFailed("\"$\"");
  7014. }
  7015. }
  7016. }
  7017. }
  7018. }
  7019. }
  7020. }
  7021. }
  7022. return result0;
  7023. }
  7024. function parse_Request_Response() {
  7025. var result0;
  7026. result0 = parse_Status_Line();
  7027. if (result0 === null) {
  7028. result0 = parse_Request_Line();
  7029. }
  7030. return result0;
  7031. }
  7032. function parse_Request_Line() {
  7033. var result0, result1, result2, result3, result4;
  7034. var pos0;
  7035. pos0 = pos;
  7036. result0 = parse_Method();
  7037. if (result0 !== null) {
  7038. result1 = parse_SP();
  7039. if (result1 !== null) {
  7040. result2 = parse_Request_URI();
  7041. if (result2 !== null) {
  7042. result3 = parse_SP();
  7043. if (result3 !== null) {
  7044. result4 = parse_SIP_Version();
  7045. if (result4 !== null) {
  7046. result0 = [result0, result1, result2, result3, result4];
  7047. } else {
  7048. result0 = null;
  7049. pos = pos0;
  7050. }
  7051. } else {
  7052. result0 = null;
  7053. pos = pos0;
  7054. }
  7055. } else {
  7056. result0 = null;
  7057. pos = pos0;
  7058. }
  7059. } else {
  7060. result0 = null;
  7061. pos = pos0;
  7062. }
  7063. } else {
  7064. result0 = null;
  7065. pos = pos0;
  7066. }
  7067. return result0;
  7068. }
  7069. function parse_Request_URI() {
  7070. var result0;
  7071. result0 = parse_SIP_URI();
  7072. if (result0 === null) {
  7073. result0 = parse_absoluteURI();
  7074. }
  7075. return result0;
  7076. }
  7077. function parse_absoluteURI() {
  7078. var result0, result1, result2;
  7079. var pos0;
  7080. pos0 = pos;
  7081. result0 = parse_scheme();
  7082. if (result0 !== null) {
  7083. if (input.charCodeAt(pos) === 58) {
  7084. result1 = ":";
  7085. pos++;
  7086. } else {
  7087. result1 = null;
  7088. if (reportFailures === 0) {
  7089. matchFailed("\":\"");
  7090. }
  7091. }
  7092. if (result1 !== null) {
  7093. result2 = parse_hier_part();
  7094. if (result2 === null) {
  7095. result2 = parse_opaque_part();
  7096. }
  7097. if (result2 !== null) {
  7098. result0 = [result0, result1, result2];
  7099. } else {
  7100. result0 = null;
  7101. pos = pos0;
  7102. }
  7103. } else {
  7104. result0 = null;
  7105. pos = pos0;
  7106. }
  7107. } else {
  7108. result0 = null;
  7109. pos = pos0;
  7110. }
  7111. return result0;
  7112. }
  7113. function parse_hier_part() {
  7114. var result0, result1, result2;
  7115. var pos0, pos1;
  7116. pos0 = pos;
  7117. result0 = parse_net_path();
  7118. if (result0 === null) {
  7119. result0 = parse_abs_path();
  7120. }
  7121. if (result0 !== null) {
  7122. pos1 = pos;
  7123. if (input.charCodeAt(pos) === 63) {
  7124. result1 = "?";
  7125. pos++;
  7126. } else {
  7127. result1 = null;
  7128. if (reportFailures === 0) {
  7129. matchFailed("\"?\"");
  7130. }
  7131. }
  7132. if (result1 !== null) {
  7133. result2 = parse_query();
  7134. if (result2 !== null) {
  7135. result1 = [result1, result2];
  7136. } else {
  7137. result1 = null;
  7138. pos = pos1;
  7139. }
  7140. } else {
  7141. result1 = null;
  7142. pos = pos1;
  7143. }
  7144. result1 = result1 !== null ? result1 : "";
  7145. if (result1 !== null) {
  7146. result0 = [result0, result1];
  7147. } else {
  7148. result0 = null;
  7149. pos = pos0;
  7150. }
  7151. } else {
  7152. result0 = null;
  7153. pos = pos0;
  7154. }
  7155. return result0;
  7156. }
  7157. function parse_net_path() {
  7158. var result0, result1, result2;
  7159. var pos0;
  7160. pos0 = pos;
  7161. if (input.substr(pos, 2) === "//") {
  7162. result0 = "//";
  7163. pos += 2;
  7164. } else {
  7165. result0 = null;
  7166. if (reportFailures === 0) {
  7167. matchFailed("\"//\"");
  7168. }
  7169. }
  7170. if (result0 !== null) {
  7171. result1 = parse_authority();
  7172. if (result1 !== null) {
  7173. result2 = parse_abs_path();
  7174. result2 = result2 !== null ? result2 : "";
  7175. if (result2 !== null) {
  7176. result0 = [result0, result1, result2];
  7177. } else {
  7178. result0 = null;
  7179. pos = pos0;
  7180. }
  7181. } else {
  7182. result0 = null;
  7183. pos = pos0;
  7184. }
  7185. } else {
  7186. result0 = null;
  7187. pos = pos0;
  7188. }
  7189. return result0;
  7190. }
  7191. function parse_abs_path() {
  7192. var result0, result1;
  7193. var pos0;
  7194. pos0 = pos;
  7195. if (input.charCodeAt(pos) === 47) {
  7196. result0 = "/";
  7197. pos++;
  7198. } else {
  7199. result0 = null;
  7200. if (reportFailures === 0) {
  7201. matchFailed("\"/\"");
  7202. }
  7203. }
  7204. if (result0 !== null) {
  7205. result1 = parse_path_segments();
  7206. if (result1 !== null) {
  7207. result0 = [result0, result1];
  7208. } else {
  7209. result0 = null;
  7210. pos = pos0;
  7211. }
  7212. } else {
  7213. result0 = null;
  7214. pos = pos0;
  7215. }
  7216. return result0;
  7217. }
  7218. function parse_opaque_part() {
  7219. var result0, result1, result2;
  7220. var pos0;
  7221. pos0 = pos;
  7222. result0 = parse_uric_no_slash();
  7223. if (result0 !== null) {
  7224. result1 = [];
  7225. result2 = parse_uric();
  7226. while (result2 !== null) {
  7227. result1.push(result2);
  7228. result2 = parse_uric();
  7229. }
  7230. if (result1 !== null) {
  7231. result0 = [result0, result1];
  7232. } else {
  7233. result0 = null;
  7234. pos = pos0;
  7235. }
  7236. } else {
  7237. result0 = null;
  7238. pos = pos0;
  7239. }
  7240. return result0;
  7241. }
  7242. function parse_uric() {
  7243. var result0;
  7244. result0 = parse_reserved();
  7245. if (result0 === null) {
  7246. result0 = parse_unreserved();
  7247. if (result0 === null) {
  7248. result0 = parse_escaped();
  7249. }
  7250. }
  7251. return result0;
  7252. }
  7253. function parse_uric_no_slash() {
  7254. var result0;
  7255. result0 = parse_unreserved();
  7256. if (result0 === null) {
  7257. result0 = parse_escaped();
  7258. if (result0 === null) {
  7259. if (input.charCodeAt(pos) === 59) {
  7260. result0 = ";";
  7261. pos++;
  7262. } else {
  7263. result0 = null;
  7264. if (reportFailures === 0) {
  7265. matchFailed("\";\"");
  7266. }
  7267. }
  7268. if (result0 === null) {
  7269. if (input.charCodeAt(pos) === 63) {
  7270. result0 = "?";
  7271. pos++;
  7272. } else {
  7273. result0 = null;
  7274. if (reportFailures === 0) {
  7275. matchFailed("\"?\"");
  7276. }
  7277. }
  7278. if (result0 === null) {
  7279. if (input.charCodeAt(pos) === 58) {
  7280. result0 = ":";
  7281. pos++;
  7282. } else {
  7283. result0 = null;
  7284. if (reportFailures === 0) {
  7285. matchFailed("\":\"");
  7286. }
  7287. }
  7288. if (result0 === null) {
  7289. if (input.charCodeAt(pos) === 64) {
  7290. result0 = "@";
  7291. pos++;
  7292. } else {
  7293. result0 = null;
  7294. if (reportFailures === 0) {
  7295. matchFailed("\"@\"");
  7296. }
  7297. }
  7298. if (result0 === null) {
  7299. if (input.charCodeAt(pos) === 38) {
  7300. result0 = "&";
  7301. pos++;
  7302. } else {
  7303. result0 = null;
  7304. if (reportFailures === 0) {
  7305. matchFailed("\"&\"");
  7306. }
  7307. }
  7308. if (result0 === null) {
  7309. if (input.charCodeAt(pos) === 61) {
  7310. result0 = "=";
  7311. pos++;
  7312. } else {
  7313. result0 = null;
  7314. if (reportFailures === 0) {
  7315. matchFailed("\"=\"");
  7316. }
  7317. }
  7318. if (result0 === null) {
  7319. if (input.charCodeAt(pos) === 43) {
  7320. result0 = "+";
  7321. pos++;
  7322. } else {
  7323. result0 = null;
  7324. if (reportFailures === 0) {
  7325. matchFailed("\"+\"");
  7326. }
  7327. }
  7328. if (result0 === null) {
  7329. if (input.charCodeAt(pos) === 36) {
  7330. result0 = "$";
  7331. pos++;
  7332. } else {
  7333. result0 = null;
  7334. if (reportFailures === 0) {
  7335. matchFailed("\"$\"");
  7336. }
  7337. }
  7338. if (result0 === null) {
  7339. if (input.charCodeAt(pos) === 44) {
  7340. result0 = ",";
  7341. pos++;
  7342. } else {
  7343. result0 = null;
  7344. if (reportFailures === 0) {
  7345. matchFailed("\",\"");
  7346. }
  7347. }
  7348. }
  7349. }
  7350. }
  7351. }
  7352. }
  7353. }
  7354. }
  7355. }
  7356. }
  7357. }
  7358. return result0;
  7359. }
  7360. function parse_path_segments() {
  7361. var result0, result1, result2, result3;
  7362. var pos0, pos1;
  7363. pos0 = pos;
  7364. result0 = parse_segment();
  7365. if (result0 !== null) {
  7366. result1 = [];
  7367. pos1 = pos;
  7368. if (input.charCodeAt(pos) === 47) {
  7369. result2 = "/";
  7370. pos++;
  7371. } else {
  7372. result2 = null;
  7373. if (reportFailures === 0) {
  7374. matchFailed("\"/\"");
  7375. }
  7376. }
  7377. if (result2 !== null) {
  7378. result3 = parse_segment();
  7379. if (result3 !== null) {
  7380. result2 = [result2, result3];
  7381. } else {
  7382. result2 = null;
  7383. pos = pos1;
  7384. }
  7385. } else {
  7386. result2 = null;
  7387. pos = pos1;
  7388. }
  7389. while (result2 !== null) {
  7390. result1.push(result2);
  7391. pos1 = pos;
  7392. if (input.charCodeAt(pos) === 47) {
  7393. result2 = "/";
  7394. pos++;
  7395. } else {
  7396. result2 = null;
  7397. if (reportFailures === 0) {
  7398. matchFailed("\"/\"");
  7399. }
  7400. }
  7401. if (result2 !== null) {
  7402. result3 = parse_segment();
  7403. if (result3 !== null) {
  7404. result2 = [result2, result3];
  7405. } else {
  7406. result2 = null;
  7407. pos = pos1;
  7408. }
  7409. } else {
  7410. result2 = null;
  7411. pos = pos1;
  7412. }
  7413. }
  7414. if (result1 !== null) {
  7415. result0 = [result0, result1];
  7416. } else {
  7417. result0 = null;
  7418. pos = pos0;
  7419. }
  7420. } else {
  7421. result0 = null;
  7422. pos = pos0;
  7423. }
  7424. return result0;
  7425. }
  7426. function parse_segment() {
  7427. var result0, result1, result2, result3;
  7428. var pos0, pos1;
  7429. pos0 = pos;
  7430. result0 = [];
  7431. result1 = parse_pchar();
  7432. while (result1 !== null) {
  7433. result0.push(result1);
  7434. result1 = parse_pchar();
  7435. }
  7436. if (result0 !== null) {
  7437. result1 = [];
  7438. pos1 = pos;
  7439. if (input.charCodeAt(pos) === 59) {
  7440. result2 = ";";
  7441. pos++;
  7442. } else {
  7443. result2 = null;
  7444. if (reportFailures === 0) {
  7445. matchFailed("\";\"");
  7446. }
  7447. }
  7448. if (result2 !== null) {
  7449. result3 = parse_param();
  7450. if (result3 !== null) {
  7451. result2 = [result2, result3];
  7452. } else {
  7453. result2 = null;
  7454. pos = pos1;
  7455. }
  7456. } else {
  7457. result2 = null;
  7458. pos = pos1;
  7459. }
  7460. while (result2 !== null) {
  7461. result1.push(result2);
  7462. pos1 = pos;
  7463. if (input.charCodeAt(pos) === 59) {
  7464. result2 = ";";
  7465. pos++;
  7466. } else {
  7467. result2 = null;
  7468. if (reportFailures === 0) {
  7469. matchFailed("\";\"");
  7470. }
  7471. }
  7472. if (result2 !== null) {
  7473. result3 = parse_param();
  7474. if (result3 !== null) {
  7475. result2 = [result2, result3];
  7476. } else {
  7477. result2 = null;
  7478. pos = pos1;
  7479. }
  7480. } else {
  7481. result2 = null;
  7482. pos = pos1;
  7483. }
  7484. }
  7485. if (result1 !== null) {
  7486. result0 = [result0, result1];
  7487. } else {
  7488. result0 = null;
  7489. pos = pos0;
  7490. }
  7491. } else {
  7492. result0 = null;
  7493. pos = pos0;
  7494. }
  7495. return result0;
  7496. }
  7497. function parse_param() {
  7498. var result0, result1;
  7499. result0 = [];
  7500. result1 = parse_pchar();
  7501. while (result1 !== null) {
  7502. result0.push(result1);
  7503. result1 = parse_pchar();
  7504. }
  7505. return result0;
  7506. }
  7507. function parse_pchar() {
  7508. var result0;
  7509. result0 = parse_unreserved();
  7510. if (result0 === null) {
  7511. result0 = parse_escaped();
  7512. if (result0 === null) {
  7513. if (input.charCodeAt(pos) === 58) {
  7514. result0 = ":";
  7515. pos++;
  7516. } else {
  7517. result0 = null;
  7518. if (reportFailures === 0) {
  7519. matchFailed("\":\"");
  7520. }
  7521. }
  7522. if (result0 === null) {
  7523. if (input.charCodeAt(pos) === 64) {
  7524. result0 = "@";
  7525. pos++;
  7526. } else {
  7527. result0 = null;
  7528. if (reportFailures === 0) {
  7529. matchFailed("\"@\"");
  7530. }
  7531. }
  7532. if (result0 === null) {
  7533. if (input.charCodeAt(pos) === 38) {
  7534. result0 = "&";
  7535. pos++;
  7536. } else {
  7537. result0 = null;
  7538. if (reportFailures === 0) {
  7539. matchFailed("\"&\"");
  7540. }
  7541. }
  7542. if (result0 === null) {
  7543. if (input.charCodeAt(pos) === 61) {
  7544. result0 = "=";
  7545. pos++;
  7546. } else {
  7547. result0 = null;
  7548. if (reportFailures === 0) {
  7549. matchFailed("\"=\"");
  7550. }
  7551. }
  7552. if (result0 === null) {
  7553. if (input.charCodeAt(pos) === 43) {
  7554. result0 = "+";
  7555. pos++;
  7556. } else {
  7557. result0 = null;
  7558. if (reportFailures === 0) {
  7559. matchFailed("\"+\"");
  7560. }
  7561. }
  7562. if (result0 === null) {
  7563. if (input.charCodeAt(pos) === 36) {
  7564. result0 = "$";
  7565. pos++;
  7566. } else {
  7567. result0 = null;
  7568. if (reportFailures === 0) {
  7569. matchFailed("\"$\"");
  7570. }
  7571. }
  7572. if (result0 === null) {
  7573. if (input.charCodeAt(pos) === 44) {
  7574. result0 = ",";
  7575. pos++;
  7576. } else {
  7577. result0 = null;
  7578. if (reportFailures === 0) {
  7579. matchFailed("\",\"");
  7580. }
  7581. }
  7582. }
  7583. }
  7584. }
  7585. }
  7586. }
  7587. }
  7588. }
  7589. }
  7590. return result0;
  7591. }
  7592. function parse_scheme() {
  7593. var result0, result1, result2;
  7594. var pos0, pos1;
  7595. pos0 = pos;
  7596. pos1 = pos;
  7597. result0 = parse_ALPHA();
  7598. if (result0 !== null) {
  7599. result1 = [];
  7600. result2 = parse_ALPHA();
  7601. if (result2 === null) {
  7602. result2 = parse_DIGIT();
  7603. if (result2 === null) {
  7604. if (input.charCodeAt(pos) === 43) {
  7605. result2 = "+";
  7606. pos++;
  7607. } else {
  7608. result2 = null;
  7609. if (reportFailures === 0) {
  7610. matchFailed("\"+\"");
  7611. }
  7612. }
  7613. if (result2 === null) {
  7614. if (input.charCodeAt(pos) === 45) {
  7615. result2 = "-";
  7616. pos++;
  7617. } else {
  7618. result2 = null;
  7619. if (reportFailures === 0) {
  7620. matchFailed("\"-\"");
  7621. }
  7622. }
  7623. if (result2 === null) {
  7624. if (input.charCodeAt(pos) === 46) {
  7625. result2 = ".";
  7626. pos++;
  7627. } else {
  7628. result2 = null;
  7629. if (reportFailures === 0) {
  7630. matchFailed("\".\"");
  7631. }
  7632. }
  7633. }
  7634. }
  7635. }
  7636. }
  7637. while (result2 !== null) {
  7638. result1.push(result2);
  7639. result2 = parse_ALPHA();
  7640. if (result2 === null) {
  7641. result2 = parse_DIGIT();
  7642. if (result2 === null) {
  7643. if (input.charCodeAt(pos) === 43) {
  7644. result2 = "+";
  7645. pos++;
  7646. } else {
  7647. result2 = null;
  7648. if (reportFailures === 0) {
  7649. matchFailed("\"+\"");
  7650. }
  7651. }
  7652. if (result2 === null) {
  7653. if (input.charCodeAt(pos) === 45) {
  7654. result2 = "-";
  7655. pos++;
  7656. } else {
  7657. result2 = null;
  7658. if (reportFailures === 0) {
  7659. matchFailed("\"-\"");
  7660. }
  7661. }
  7662. if (result2 === null) {
  7663. if (input.charCodeAt(pos) === 46) {
  7664. result2 = ".";
  7665. pos++;
  7666. } else {
  7667. result2 = null;
  7668. if (reportFailures === 0) {
  7669. matchFailed("\".\"");
  7670. }
  7671. }
  7672. }
  7673. }
  7674. }
  7675. }
  7676. }
  7677. if (result1 !== null) {
  7678. result0 = [result0, result1];
  7679. } else {
  7680. result0 = null;
  7681. pos = pos1;
  7682. }
  7683. } else {
  7684. result0 = null;
  7685. pos = pos1;
  7686. }
  7687. if (result0 !== null) {
  7688. result0 = (function(offset) {
  7689. data.scheme= input.substring(pos, offset); })(pos0);
  7690. }
  7691. if (result0 === null) {
  7692. pos = pos0;
  7693. }
  7694. return result0;
  7695. }
  7696. function parse_authority() {
  7697. var result0;
  7698. result0 = parse_srvr();
  7699. if (result0 === null) {
  7700. result0 = parse_reg_name();
  7701. }
  7702. return result0;
  7703. }
  7704. function parse_srvr() {
  7705. var result0, result1;
  7706. var pos0, pos1;
  7707. pos0 = pos;
  7708. pos1 = pos;
  7709. result0 = parse_userinfo();
  7710. if (result0 !== null) {
  7711. if (input.charCodeAt(pos) === 64) {
  7712. result1 = "@";
  7713. pos++;
  7714. } else {
  7715. result1 = null;
  7716. if (reportFailures === 0) {
  7717. matchFailed("\"@\"");
  7718. }
  7719. }
  7720. if (result1 !== null) {
  7721. result0 = [result0, result1];
  7722. } else {
  7723. result0 = null;
  7724. pos = pos1;
  7725. }
  7726. } else {
  7727. result0 = null;
  7728. pos = pos1;
  7729. }
  7730. result0 = result0 !== null ? result0 : "";
  7731. if (result0 !== null) {
  7732. result1 = parse_hostport();
  7733. if (result1 !== null) {
  7734. result0 = [result0, result1];
  7735. } else {
  7736. result0 = null;
  7737. pos = pos0;
  7738. }
  7739. } else {
  7740. result0 = null;
  7741. pos = pos0;
  7742. }
  7743. result0 = result0 !== null ? result0 : "";
  7744. return result0;
  7745. }
  7746. function parse_reg_name() {
  7747. var result0, result1;
  7748. result1 = parse_unreserved();
  7749. if (result1 === null) {
  7750. result1 = parse_escaped();
  7751. if (result1 === null) {
  7752. if (input.charCodeAt(pos) === 36) {
  7753. result1 = "$";
  7754. pos++;
  7755. } else {
  7756. result1 = null;
  7757. if (reportFailures === 0) {
  7758. matchFailed("\"$\"");
  7759. }
  7760. }
  7761. if (result1 === null) {
  7762. if (input.charCodeAt(pos) === 44) {
  7763. result1 = ",";
  7764. pos++;
  7765. } else {
  7766. result1 = null;
  7767. if (reportFailures === 0) {
  7768. matchFailed("\",\"");
  7769. }
  7770. }
  7771. if (result1 === null) {
  7772. if (input.charCodeAt(pos) === 59) {
  7773. result1 = ";";
  7774. pos++;
  7775. } else {
  7776. result1 = null;
  7777. if (reportFailures === 0) {
  7778. matchFailed("\";\"");
  7779. }
  7780. }
  7781. if (result1 === null) {
  7782. if (input.charCodeAt(pos) === 58) {
  7783. result1 = ":";
  7784. pos++;
  7785. } else {
  7786. result1 = null;
  7787. if (reportFailures === 0) {
  7788. matchFailed("\":\"");
  7789. }
  7790. }
  7791. if (result1 === null) {
  7792. if (input.charCodeAt(pos) === 64) {
  7793. result1 = "@";
  7794. pos++;
  7795. } else {
  7796. result1 = null;
  7797. if (reportFailures === 0) {
  7798. matchFailed("\"@\"");
  7799. }
  7800. }
  7801. if (result1 === null) {
  7802. if (input.charCodeAt(pos) === 38) {
  7803. result1 = "&";
  7804. pos++;
  7805. } else {
  7806. result1 = null;
  7807. if (reportFailures === 0) {
  7808. matchFailed("\"&\"");
  7809. }
  7810. }
  7811. if (result1 === null) {
  7812. if (input.charCodeAt(pos) === 61) {
  7813. result1 = "=";
  7814. pos++;
  7815. } else {
  7816. result1 = null;
  7817. if (reportFailures === 0) {
  7818. matchFailed("\"=\"");
  7819. }
  7820. }
  7821. if (result1 === null) {
  7822. if (input.charCodeAt(pos) === 43) {
  7823. result1 = "+";
  7824. pos++;
  7825. } else {
  7826. result1 = null;
  7827. if (reportFailures === 0) {
  7828. matchFailed("\"+\"");
  7829. }
  7830. }
  7831. }
  7832. }
  7833. }
  7834. }
  7835. }
  7836. }
  7837. }
  7838. }
  7839. }
  7840. if (result1 !== null) {
  7841. result0 = [];
  7842. while (result1 !== null) {
  7843. result0.push(result1);
  7844. result1 = parse_unreserved();
  7845. if (result1 === null) {
  7846. result1 = parse_escaped();
  7847. if (result1 === null) {
  7848. if (input.charCodeAt(pos) === 36) {
  7849. result1 = "$";
  7850. pos++;
  7851. } else {
  7852. result1 = null;
  7853. if (reportFailures === 0) {
  7854. matchFailed("\"$\"");
  7855. }
  7856. }
  7857. if (result1 === null) {
  7858. if (input.charCodeAt(pos) === 44) {
  7859. result1 = ",";
  7860. pos++;
  7861. } else {
  7862. result1 = null;
  7863. if (reportFailures === 0) {
  7864. matchFailed("\",\"");
  7865. }
  7866. }
  7867. if (result1 === null) {
  7868. if (input.charCodeAt(pos) === 59) {
  7869. result1 = ";";
  7870. pos++;
  7871. } else {
  7872. result1 = null;
  7873. if (reportFailures === 0) {
  7874. matchFailed("\";\"");
  7875. }
  7876. }
  7877. if (result1 === null) {
  7878. if (input.charCodeAt(pos) === 58) {
  7879. result1 = ":";
  7880. pos++;
  7881. } else {
  7882. result1 = null;
  7883. if (reportFailures === 0) {
  7884. matchFailed("\":\"");
  7885. }
  7886. }
  7887. if (result1 === null) {
  7888. if (input.charCodeAt(pos) === 64) {
  7889. result1 = "@";
  7890. pos++;
  7891. } else {
  7892. result1 = null;
  7893. if (reportFailures === 0) {
  7894. matchFailed("\"@\"");
  7895. }
  7896. }
  7897. if (result1 === null) {
  7898. if (input.charCodeAt(pos) === 38) {
  7899. result1 = "&";
  7900. pos++;
  7901. } else {
  7902. result1 = null;
  7903. if (reportFailures === 0) {
  7904. matchFailed("\"&\"");
  7905. }
  7906. }
  7907. if (result1 === null) {
  7908. if (input.charCodeAt(pos) === 61) {
  7909. result1 = "=";
  7910. pos++;
  7911. } else {
  7912. result1 = null;
  7913. if (reportFailures === 0) {
  7914. matchFailed("\"=\"");
  7915. }
  7916. }
  7917. if (result1 === null) {
  7918. if (input.charCodeAt(pos) === 43) {
  7919. result1 = "+";
  7920. pos++;
  7921. } else {
  7922. result1 = null;
  7923. if (reportFailures === 0) {
  7924. matchFailed("\"+\"");
  7925. }
  7926. }
  7927. }
  7928. }
  7929. }
  7930. }
  7931. }
  7932. }
  7933. }
  7934. }
  7935. }
  7936. }
  7937. } else {
  7938. result0 = null;
  7939. }
  7940. return result0;
  7941. }
  7942. function parse_query() {
  7943. var result0, result1;
  7944. result0 = [];
  7945. result1 = parse_uric();
  7946. while (result1 !== null) {
  7947. result0.push(result1);
  7948. result1 = parse_uric();
  7949. }
  7950. return result0;
  7951. }
  7952. function parse_SIP_Version() {
  7953. var result0, result1, result2, result3, result4, result5;
  7954. var pos0, pos1;
  7955. pos0 = pos;
  7956. pos1 = pos;
  7957. if (input.substr(pos, 3).toLowerCase() === "sip") {
  7958. result0 = input.substr(pos, 3);
  7959. pos += 3;
  7960. } else {
  7961. result0 = null;
  7962. if (reportFailures === 0) {
  7963. matchFailed("\"SIP\"");
  7964. }
  7965. }
  7966. if (result0 !== null) {
  7967. if (input.charCodeAt(pos) === 47) {
  7968. result1 = "/";
  7969. pos++;
  7970. } else {
  7971. result1 = null;
  7972. if (reportFailures === 0) {
  7973. matchFailed("\"/\"");
  7974. }
  7975. }
  7976. if (result1 !== null) {
  7977. result3 = parse_DIGIT();
  7978. if (result3 !== null) {
  7979. result2 = [];
  7980. while (result3 !== null) {
  7981. result2.push(result3);
  7982. result3 = parse_DIGIT();
  7983. }
  7984. } else {
  7985. result2 = null;
  7986. }
  7987. if (result2 !== null) {
  7988. if (input.charCodeAt(pos) === 46) {
  7989. result3 = ".";
  7990. pos++;
  7991. } else {
  7992. result3 = null;
  7993. if (reportFailures === 0) {
  7994. matchFailed("\".\"");
  7995. }
  7996. }
  7997. if (result3 !== null) {
  7998. result5 = parse_DIGIT();
  7999. if (result5 !== null) {
  8000. result4 = [];
  8001. while (result5 !== null) {
  8002. result4.push(result5);
  8003. result5 = parse_DIGIT();
  8004. }
  8005. } else {
  8006. result4 = null;
  8007. }
  8008. if (result4 !== null) {
  8009. result0 = [result0, result1, result2, result3, result4];
  8010. } else {
  8011. result0 = null;
  8012. pos = pos1;
  8013. }
  8014. } else {
  8015. result0 = null;
  8016. pos = pos1;
  8017. }
  8018. } else {
  8019. result0 = null;
  8020. pos = pos1;
  8021. }
  8022. } else {
  8023. result0 = null;
  8024. pos = pos1;
  8025. }
  8026. } else {
  8027. result0 = null;
  8028. pos = pos1;
  8029. }
  8030. if (result0 !== null) {
  8031. result0 = (function(offset) {
  8032. data.sip_version = input.substring(pos, offset); })(pos0);
  8033. }
  8034. if (result0 === null) {
  8035. pos = pos0;
  8036. }
  8037. return result0;
  8038. }
  8039. function parse_INVITEm() {
  8040. var result0;
  8041. if (input.substr(pos, 6) === "INVITE") {
  8042. result0 = "INVITE";
  8043. pos += 6;
  8044. } else {
  8045. result0 = null;
  8046. if (reportFailures === 0) {
  8047. matchFailed("\"INVITE\"");
  8048. }
  8049. }
  8050. return result0;
  8051. }
  8052. function parse_ACKm() {
  8053. var result0;
  8054. if (input.substr(pos, 3) === "ACK") {
  8055. result0 = "ACK";
  8056. pos += 3;
  8057. } else {
  8058. result0 = null;
  8059. if (reportFailures === 0) {
  8060. matchFailed("\"ACK\"");
  8061. }
  8062. }
  8063. return result0;
  8064. }
  8065. function parse_OPTIONSm() {
  8066. var result0;
  8067. if (input.substr(pos, 7) === "OPTIONS") {
  8068. result0 = "OPTIONS";
  8069. pos += 7;
  8070. } else {
  8071. result0 = null;
  8072. if (reportFailures === 0) {
  8073. matchFailed("\"OPTIONS\"");
  8074. }
  8075. }
  8076. return result0;
  8077. }
  8078. function parse_BYEm() {
  8079. var result0;
  8080. if (input.substr(pos, 3) === "BYE") {
  8081. result0 = "BYE";
  8082. pos += 3;
  8083. } else {
  8084. result0 = null;
  8085. if (reportFailures === 0) {
  8086. matchFailed("\"BYE\"");
  8087. }
  8088. }
  8089. return result0;
  8090. }
  8091. function parse_CANCELm() {
  8092. var result0;
  8093. if (input.substr(pos, 6) === "CANCEL") {
  8094. result0 = "CANCEL";
  8095. pos += 6;
  8096. } else {
  8097. result0 = null;
  8098. if (reportFailures === 0) {
  8099. matchFailed("\"CANCEL\"");
  8100. }
  8101. }
  8102. return result0;
  8103. }
  8104. function parse_REGISTERm() {
  8105. var result0;
  8106. if (input.substr(pos, 8) === "REGISTER") {
  8107. result0 = "REGISTER";
  8108. pos += 8;
  8109. } else {
  8110. result0 = null;
  8111. if (reportFailures === 0) {
  8112. matchFailed("\"REGISTER\"");
  8113. }
  8114. }
  8115. return result0;
  8116. }
  8117. function parse_SUBSCRIBEm() {
  8118. var result0;
  8119. if (input.substr(pos, 9) === "SUBSCRIBE") {
  8120. result0 = "SUBSCRIBE";
  8121. pos += 9;
  8122. } else {
  8123. result0 = null;
  8124. if (reportFailures === 0) {
  8125. matchFailed("\"SUBSCRIBE\"");
  8126. }
  8127. }
  8128. return result0;
  8129. }
  8130. function parse_NOTIFYm() {
  8131. var result0;
  8132. if (input.substr(pos, 6) === "NOTIFY") {
  8133. result0 = "NOTIFY";
  8134. pos += 6;
  8135. } else {
  8136. result0 = null;
  8137. if (reportFailures === 0) {
  8138. matchFailed("\"NOTIFY\"");
  8139. }
  8140. }
  8141. return result0;
  8142. }
  8143. function parse_REFERm() {
  8144. var result0;
  8145. if (input.substr(pos, 5) === "REFER") {
  8146. result0 = "REFER";
  8147. pos += 5;
  8148. } else {
  8149. result0 = null;
  8150. if (reportFailures === 0) {
  8151. matchFailed("\"REFER\"");
  8152. }
  8153. }
  8154. return result0;
  8155. }
  8156. function parse_Method() {
  8157. var result0;
  8158. var pos0;
  8159. pos0 = pos;
  8160. result0 = parse_INVITEm();
  8161. if (result0 === null) {
  8162. result0 = parse_ACKm();
  8163. if (result0 === null) {
  8164. result0 = parse_OPTIONSm();
  8165. if (result0 === null) {
  8166. result0 = parse_BYEm();
  8167. if (result0 === null) {
  8168. result0 = parse_CANCELm();
  8169. if (result0 === null) {
  8170. result0 = parse_REGISTERm();
  8171. if (result0 === null) {
  8172. result0 = parse_SUBSCRIBEm();
  8173. if (result0 === null) {
  8174. result0 = parse_NOTIFYm();
  8175. if (result0 === null) {
  8176. result0 = parse_REFERm();
  8177. if (result0 === null) {
  8178. result0 = parse_token();
  8179. }
  8180. }
  8181. }
  8182. }
  8183. }
  8184. }
  8185. }
  8186. }
  8187. }
  8188. if (result0 !== null) {
  8189. result0 = (function(offset) {
  8190. data.method = input.substring(pos, offset);
  8191. return data.method; })(pos0);
  8192. }
  8193. if (result0 === null) {
  8194. pos = pos0;
  8195. }
  8196. return result0;
  8197. }
  8198. function parse_Status_Line() {
  8199. var result0, result1, result2, result3, result4;
  8200. var pos0;
  8201. pos0 = pos;
  8202. result0 = parse_SIP_Version();
  8203. if (result0 !== null) {
  8204. result1 = parse_SP();
  8205. if (result1 !== null) {
  8206. result2 = parse_Status_Code();
  8207. if (result2 !== null) {
  8208. result3 = parse_SP();
  8209. if (result3 !== null) {
  8210. result4 = parse_Reason_Phrase();
  8211. if (result4 !== null) {
  8212. result0 = [result0, result1, result2, result3, result4];
  8213. } else {
  8214. result0 = null;
  8215. pos = pos0;
  8216. }
  8217. } else {
  8218. result0 = null;
  8219. pos = pos0;
  8220. }
  8221. } else {
  8222. result0 = null;
  8223. pos = pos0;
  8224. }
  8225. } else {
  8226. result0 = null;
  8227. pos = pos0;
  8228. }
  8229. } else {
  8230. result0 = null;
  8231. pos = pos0;
  8232. }
  8233. return result0;
  8234. }
  8235. function parse_Status_Code() {
  8236. var result0;
  8237. var pos0;
  8238. pos0 = pos;
  8239. result0 = parse_extension_code();
  8240. if (result0 !== null) {
  8241. result0 = (function(offset, status_code) {
  8242. data.status_code = parseInt(status_code.join('')); })(pos0, result0);
  8243. }
  8244. if (result0 === null) {
  8245. pos = pos0;
  8246. }
  8247. return result0;
  8248. }
  8249. function parse_extension_code() {
  8250. var result0, result1, result2;
  8251. var pos0;
  8252. pos0 = pos;
  8253. result0 = parse_DIGIT();
  8254. if (result0 !== null) {
  8255. result1 = parse_DIGIT();
  8256. if (result1 !== null) {
  8257. result2 = parse_DIGIT();
  8258. if (result2 !== null) {
  8259. result0 = [result0, result1, result2];
  8260. } else {
  8261. result0 = null;
  8262. pos = pos0;
  8263. }
  8264. } else {
  8265. result0 = null;
  8266. pos = pos0;
  8267. }
  8268. } else {
  8269. result0 = null;
  8270. pos = pos0;
  8271. }
  8272. return result0;
  8273. }
  8274. function parse_Reason_Phrase() {
  8275. var result0, result1;
  8276. var pos0;
  8277. pos0 = pos;
  8278. result0 = [];
  8279. result1 = parse_reserved();
  8280. if (result1 === null) {
  8281. result1 = parse_unreserved();
  8282. if (result1 === null) {
  8283. result1 = parse_escaped();
  8284. if (result1 === null) {
  8285. result1 = parse_UTF8_NONASCII();
  8286. if (result1 === null) {
  8287. result1 = parse_UTF8_CONT();
  8288. if (result1 === null) {
  8289. result1 = parse_SP();
  8290. if (result1 === null) {
  8291. result1 = parse_HTAB();
  8292. }
  8293. }
  8294. }
  8295. }
  8296. }
  8297. }
  8298. while (result1 !== null) {
  8299. result0.push(result1);
  8300. result1 = parse_reserved();
  8301. if (result1 === null) {
  8302. result1 = parse_unreserved();
  8303. if (result1 === null) {
  8304. result1 = parse_escaped();
  8305. if (result1 === null) {
  8306. result1 = parse_UTF8_NONASCII();
  8307. if (result1 === null) {
  8308. result1 = parse_UTF8_CONT();
  8309. if (result1 === null) {
  8310. result1 = parse_SP();
  8311. if (result1 === null) {
  8312. result1 = parse_HTAB();
  8313. }
  8314. }
  8315. }
  8316. }
  8317. }
  8318. }
  8319. }
  8320. if (result0 !== null) {
  8321. result0 = (function(offset) {
  8322. data.reason_phrase = input.substring(pos, offset); })(pos0);
  8323. }
  8324. if (result0 === null) {
  8325. pos = pos0;
  8326. }
  8327. return result0;
  8328. }
  8329. function parse_Allow_Events() {
  8330. var result0, result1, result2, result3;
  8331. var pos0, pos1;
  8332. pos0 = pos;
  8333. result0 = parse_event_type();
  8334. if (result0 !== null) {
  8335. result1 = [];
  8336. pos1 = pos;
  8337. result2 = parse_COMMA();
  8338. if (result2 !== null) {
  8339. result3 = parse_event_type();
  8340. if (result3 !== null) {
  8341. result2 = [result2, result3];
  8342. } else {
  8343. result2 = null;
  8344. pos = pos1;
  8345. }
  8346. } else {
  8347. result2 = null;
  8348. pos = pos1;
  8349. }
  8350. while (result2 !== null) {
  8351. result1.push(result2);
  8352. pos1 = pos;
  8353. result2 = parse_COMMA();
  8354. if (result2 !== null) {
  8355. result3 = parse_event_type();
  8356. if (result3 !== null) {
  8357. result2 = [result2, result3];
  8358. } else {
  8359. result2 = null;
  8360. pos = pos1;
  8361. }
  8362. } else {
  8363. result2 = null;
  8364. pos = pos1;
  8365. }
  8366. }
  8367. if (result1 !== null) {
  8368. result0 = [result0, result1];
  8369. } else {
  8370. result0 = null;
  8371. pos = pos0;
  8372. }
  8373. } else {
  8374. result0 = null;
  8375. pos = pos0;
  8376. }
  8377. return result0;
  8378. }
  8379. function parse_Call_ID() {
  8380. var result0, result1, result2;
  8381. var pos0, pos1, pos2;
  8382. pos0 = pos;
  8383. pos1 = pos;
  8384. result0 = parse_word();
  8385. if (result0 !== null) {
  8386. pos2 = pos;
  8387. if (input.charCodeAt(pos) === 64) {
  8388. result1 = "@";
  8389. pos++;
  8390. } else {
  8391. result1 = null;
  8392. if (reportFailures === 0) {
  8393. matchFailed("\"@\"");
  8394. }
  8395. }
  8396. if (result1 !== null) {
  8397. result2 = parse_word();
  8398. if (result2 !== null) {
  8399. result1 = [result1, result2];
  8400. } else {
  8401. result1 = null;
  8402. pos = pos2;
  8403. }
  8404. } else {
  8405. result1 = null;
  8406. pos = pos2;
  8407. }
  8408. result1 = result1 !== null ? result1 : "";
  8409. if (result1 !== null) {
  8410. result0 = [result0, result1];
  8411. } else {
  8412. result0 = null;
  8413. pos = pos1;
  8414. }
  8415. } else {
  8416. result0 = null;
  8417. pos = pos1;
  8418. }
  8419. if (result0 !== null) {
  8420. result0 = (function(offset) {
  8421. data = input.substring(pos, offset); })(pos0);
  8422. }
  8423. if (result0 === null) {
  8424. pos = pos0;
  8425. }
  8426. return result0;
  8427. }
  8428. function parse_Contact() {
  8429. var result0, result1, result2, result3;
  8430. var pos0, pos1, pos2;
  8431. pos0 = pos;
  8432. result0 = parse_STAR();
  8433. if (result0 === null) {
  8434. pos1 = pos;
  8435. result0 = parse_contact_param();
  8436. if (result0 !== null) {
  8437. result1 = [];
  8438. pos2 = pos;
  8439. result2 = parse_COMMA();
  8440. if (result2 !== null) {
  8441. result3 = parse_contact_param();
  8442. if (result3 !== null) {
  8443. result2 = [result2, result3];
  8444. } else {
  8445. result2 = null;
  8446. pos = pos2;
  8447. }
  8448. } else {
  8449. result2 = null;
  8450. pos = pos2;
  8451. }
  8452. while (result2 !== null) {
  8453. result1.push(result2);
  8454. pos2 = pos;
  8455. result2 = parse_COMMA();
  8456. if (result2 !== null) {
  8457. result3 = parse_contact_param();
  8458. if (result3 !== null) {
  8459. result2 = [result2, result3];
  8460. } else {
  8461. result2 = null;
  8462. pos = pos2;
  8463. }
  8464. } else {
  8465. result2 = null;
  8466. pos = pos2;
  8467. }
  8468. }
  8469. if (result1 !== null) {
  8470. result0 = [result0, result1];
  8471. } else {
  8472. result0 = null;
  8473. pos = pos1;
  8474. }
  8475. } else {
  8476. result0 = null;
  8477. pos = pos1;
  8478. }
  8479. }
  8480. if (result0 !== null) {
  8481. result0 = (function(offset) {
  8482. var idx, length;
  8483. length = data.multi_header.length;
  8484. for (idx = 0; idx < length; idx++) {
  8485. if (data.multi_header[idx].parsed === null) {
  8486. data = null;
  8487. break;
  8488. }
  8489. }
  8490. if (data !== null) {
  8491. data = data.multi_header;
  8492. } else {
  8493. data = -1;
  8494. }})(pos0);
  8495. }
  8496. if (result0 === null) {
  8497. pos = pos0;
  8498. }
  8499. return result0;
  8500. }
  8501. function parse_contact_param() {
  8502. var result0, result1, result2, result3;
  8503. var pos0, pos1, pos2;
  8504. pos0 = pos;
  8505. pos1 = pos;
  8506. result0 = parse_SIP_URI_noparams();
  8507. if (result0 === null) {
  8508. result0 = parse_name_addr();
  8509. }
  8510. if (result0 !== null) {
  8511. result1 = [];
  8512. pos2 = pos;
  8513. result2 = parse_SEMI();
  8514. if (result2 !== null) {
  8515. result3 = parse_contact_params();
  8516. if (result3 !== null) {
  8517. result2 = [result2, result3];
  8518. } else {
  8519. result2 = null;
  8520. pos = pos2;
  8521. }
  8522. } else {
  8523. result2 = null;
  8524. pos = pos2;
  8525. }
  8526. while (result2 !== null) {
  8527. result1.push(result2);
  8528. pos2 = pos;
  8529. result2 = parse_SEMI();
  8530. if (result2 !== null) {
  8531. result3 = parse_contact_params();
  8532. if (result3 !== null) {
  8533. result2 = [result2, result3];
  8534. } else {
  8535. result2 = null;
  8536. pos = pos2;
  8537. }
  8538. } else {
  8539. result2 = null;
  8540. pos = pos2;
  8541. }
  8542. }
  8543. if (result1 !== null) {
  8544. result0 = [result0, result1];
  8545. } else {
  8546. result0 = null;
  8547. pos = pos1;
  8548. }
  8549. } else {
  8550. result0 = null;
  8551. pos = pos1;
  8552. }
  8553. if (result0 !== null) {
  8554. result0 = (function(offset) {
  8555. var header;
  8556. if(!data.multi_header) data.multi_header = [];
  8557. try {
  8558. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  8559. delete data.uri;
  8560. delete data.display_name;
  8561. delete data.params;
  8562. } catch(e) {
  8563. header = null;
  8564. }
  8565. data.multi_header.push( { 'possition': pos,
  8566. 'offset': offset,
  8567. 'parsed': header
  8568. });})(pos0);
  8569. }
  8570. if (result0 === null) {
  8571. pos = pos0;
  8572. }
  8573. return result0;
  8574. }
  8575. function parse_name_addr() {
  8576. var result0, result1, result2, result3;
  8577. var pos0;
  8578. pos0 = pos;
  8579. result0 = parse_display_name();
  8580. result0 = result0 !== null ? result0 : "";
  8581. if (result0 !== null) {
  8582. result1 = parse_LAQUOT();
  8583. if (result1 !== null) {
  8584. result2 = parse_SIP_URI();
  8585. if (result2 !== null) {
  8586. result3 = parse_RAQUOT();
  8587. if (result3 !== null) {
  8588. result0 = [result0, result1, result2, result3];
  8589. } else {
  8590. result0 = null;
  8591. pos = pos0;
  8592. }
  8593. } else {
  8594. result0 = null;
  8595. pos = pos0;
  8596. }
  8597. } else {
  8598. result0 = null;
  8599. pos = pos0;
  8600. }
  8601. } else {
  8602. result0 = null;
  8603. pos = pos0;
  8604. }
  8605. return result0;
  8606. }
  8607. function parse_display_name() {
  8608. var result0, result1, result2, result3;
  8609. var pos0, pos1, pos2;
  8610. pos0 = pos;
  8611. pos1 = pos;
  8612. result0 = parse_token();
  8613. if (result0 !== null) {
  8614. result1 = [];
  8615. pos2 = pos;
  8616. result2 = parse_LWS();
  8617. if (result2 !== null) {
  8618. result3 = parse_token();
  8619. if (result3 !== null) {
  8620. result2 = [result2, result3];
  8621. } else {
  8622. result2 = null;
  8623. pos = pos2;
  8624. }
  8625. } else {
  8626. result2 = null;
  8627. pos = pos2;
  8628. }
  8629. while (result2 !== null) {
  8630. result1.push(result2);
  8631. pos2 = pos;
  8632. result2 = parse_LWS();
  8633. if (result2 !== null) {
  8634. result3 = parse_token();
  8635. if (result3 !== null) {
  8636. result2 = [result2, result3];
  8637. } else {
  8638. result2 = null;
  8639. pos = pos2;
  8640. }
  8641. } else {
  8642. result2 = null;
  8643. pos = pos2;
  8644. }
  8645. }
  8646. if (result1 !== null) {
  8647. result0 = [result0, result1];
  8648. } else {
  8649. result0 = null;
  8650. pos = pos1;
  8651. }
  8652. } else {
  8653. result0 = null;
  8654. pos = pos1;
  8655. }
  8656. if (result0 === null) {
  8657. result0 = parse_quoted_string();
  8658. }
  8659. if (result0 !== null) {
  8660. result0 = (function(offset, display_name) {
  8661. display_name = input.substring(pos, offset).trim();
  8662. if (display_name[0] === '\"') {
  8663. display_name = display_name.substring(1, display_name.length-1);
  8664. }
  8665. data.display_name = display_name; })(pos0, result0);
  8666. }
  8667. if (result0 === null) {
  8668. pos = pos0;
  8669. }
  8670. return result0;
  8671. }
  8672. function parse_contact_params() {
  8673. var result0;
  8674. result0 = parse_c_p_q();
  8675. if (result0 === null) {
  8676. result0 = parse_c_p_expires();
  8677. if (result0 === null) {
  8678. result0 = parse_generic_param();
  8679. }
  8680. }
  8681. return result0;
  8682. }
  8683. function parse_c_p_q() {
  8684. var result0, result1, result2;
  8685. var pos0, pos1;
  8686. pos0 = pos;
  8687. pos1 = pos;
  8688. if (input.substr(pos, 1).toLowerCase() === "q") {
  8689. result0 = input.substr(pos, 1);
  8690. pos++;
  8691. } else {
  8692. result0 = null;
  8693. if (reportFailures === 0) {
  8694. matchFailed("\"q\"");
  8695. }
  8696. }
  8697. if (result0 !== null) {
  8698. result1 = parse_EQUAL();
  8699. if (result1 !== null) {
  8700. result2 = parse_qvalue();
  8701. if (result2 !== null) {
  8702. result0 = [result0, result1, result2];
  8703. } else {
  8704. result0 = null;
  8705. pos = pos1;
  8706. }
  8707. } else {
  8708. result0 = null;
  8709. pos = pos1;
  8710. }
  8711. } else {
  8712. result0 = null;
  8713. pos = pos1;
  8714. }
  8715. if (result0 !== null) {
  8716. result0 = (function(offset, q) {
  8717. if(!data.params) data.params = {};
  8718. data.params['q'] = q; })(pos0, result0[2]);
  8719. }
  8720. if (result0 === null) {
  8721. pos = pos0;
  8722. }
  8723. return result0;
  8724. }
  8725. function parse_c_p_expires() {
  8726. var result0, result1, result2;
  8727. var pos0, pos1;
  8728. pos0 = pos;
  8729. pos1 = pos;
  8730. if (input.substr(pos, 7).toLowerCase() === "expires") {
  8731. result0 = input.substr(pos, 7);
  8732. pos += 7;
  8733. } else {
  8734. result0 = null;
  8735. if (reportFailures === 0) {
  8736. matchFailed("\"expires\"");
  8737. }
  8738. }
  8739. if (result0 !== null) {
  8740. result1 = parse_EQUAL();
  8741. if (result1 !== null) {
  8742. result2 = parse_delta_seconds();
  8743. if (result2 !== null) {
  8744. result0 = [result0, result1, result2];
  8745. } else {
  8746. result0 = null;
  8747. pos = pos1;
  8748. }
  8749. } else {
  8750. result0 = null;
  8751. pos = pos1;
  8752. }
  8753. } else {
  8754. result0 = null;
  8755. pos = pos1;
  8756. }
  8757. if (result0 !== null) {
  8758. result0 = (function(offset, expires) {
  8759. if(!data.params) data.params = {};
  8760. data.params['expires'] = expires; })(pos0, result0[2]);
  8761. }
  8762. if (result0 === null) {
  8763. pos = pos0;
  8764. }
  8765. return result0;
  8766. }
  8767. function parse_delta_seconds() {
  8768. var result0, result1;
  8769. var pos0;
  8770. pos0 = pos;
  8771. result1 = parse_DIGIT();
  8772. if (result1 !== null) {
  8773. result0 = [];
  8774. while (result1 !== null) {
  8775. result0.push(result1);
  8776. result1 = parse_DIGIT();
  8777. }
  8778. } else {
  8779. result0 = null;
  8780. }
  8781. if (result0 !== null) {
  8782. result0 = (function(offset, delta_seconds) {
  8783. return parseInt(delta_seconds.join('')); })(pos0, result0);
  8784. }
  8785. if (result0 === null) {
  8786. pos = pos0;
  8787. }
  8788. return result0;
  8789. }
  8790. function parse_qvalue() {
  8791. var result0, result1, result2, result3, result4;
  8792. var pos0, pos1, pos2;
  8793. pos0 = pos;
  8794. pos1 = pos;
  8795. if (input.charCodeAt(pos) === 48) {
  8796. result0 = "0";
  8797. pos++;
  8798. } else {
  8799. result0 = null;
  8800. if (reportFailures === 0) {
  8801. matchFailed("\"0\"");
  8802. }
  8803. }
  8804. if (result0 !== null) {
  8805. pos2 = pos;
  8806. if (input.charCodeAt(pos) === 46) {
  8807. result1 = ".";
  8808. pos++;
  8809. } else {
  8810. result1 = null;
  8811. if (reportFailures === 0) {
  8812. matchFailed("\".\"");
  8813. }
  8814. }
  8815. if (result1 !== null) {
  8816. result2 = parse_DIGIT();
  8817. result2 = result2 !== null ? result2 : "";
  8818. if (result2 !== null) {
  8819. result3 = parse_DIGIT();
  8820. result3 = result3 !== null ? result3 : "";
  8821. if (result3 !== null) {
  8822. result4 = parse_DIGIT();
  8823. result4 = result4 !== null ? result4 : "";
  8824. if (result4 !== null) {
  8825. result1 = [result1, result2, result3, result4];
  8826. } else {
  8827. result1 = null;
  8828. pos = pos2;
  8829. }
  8830. } else {
  8831. result1 = null;
  8832. pos = pos2;
  8833. }
  8834. } else {
  8835. result1 = null;
  8836. pos = pos2;
  8837. }
  8838. } else {
  8839. result1 = null;
  8840. pos = pos2;
  8841. }
  8842. result1 = result1 !== null ? result1 : "";
  8843. if (result1 !== null) {
  8844. result0 = [result0, result1];
  8845. } else {
  8846. result0 = null;
  8847. pos = pos1;
  8848. }
  8849. } else {
  8850. result0 = null;
  8851. pos = pos1;
  8852. }
  8853. if (result0 !== null) {
  8854. result0 = (function(offset) {
  8855. return parseFloat(input.substring(pos, offset)); })(pos0);
  8856. }
  8857. if (result0 === null) {
  8858. pos = pos0;
  8859. }
  8860. return result0;
  8861. }
  8862. function parse_generic_param() {
  8863. var result0, result1, result2;
  8864. var pos0, pos1, pos2;
  8865. pos0 = pos;
  8866. pos1 = pos;
  8867. result0 = parse_token();
  8868. if (result0 !== null) {
  8869. pos2 = pos;
  8870. result1 = parse_EQUAL();
  8871. if (result1 !== null) {
  8872. result2 = parse_gen_value();
  8873. if (result2 !== null) {
  8874. result1 = [result1, result2];
  8875. } else {
  8876. result1 = null;
  8877. pos = pos2;
  8878. }
  8879. } else {
  8880. result1 = null;
  8881. pos = pos2;
  8882. }
  8883. result1 = result1 !== null ? result1 : "";
  8884. if (result1 !== null) {
  8885. result0 = [result0, result1];
  8886. } else {
  8887. result0 = null;
  8888. pos = pos1;
  8889. }
  8890. } else {
  8891. result0 = null;
  8892. pos = pos1;
  8893. }
  8894. if (result0 !== null) {
  8895. result0 = (function(offset, param, value) {
  8896. if(!data.params) data.params = {};
  8897. if (typeof value === 'undefined'){
  8898. value = undefined;
  8899. }
  8900. else {
  8901. value = value[1];
  8902. }
  8903. data.params[param.toLowerCase()] = value;})(pos0, result0[0], result0[1]);
  8904. }
  8905. if (result0 === null) {
  8906. pos = pos0;
  8907. }
  8908. return result0;
  8909. }
  8910. function parse_gen_value() {
  8911. var result0;
  8912. result0 = parse_token();
  8913. if (result0 === null) {
  8914. result0 = parse_host();
  8915. if (result0 === null) {
  8916. result0 = parse_quoted_string();
  8917. }
  8918. }
  8919. return result0;
  8920. }
  8921. function parse_Content_Disposition() {
  8922. var result0, result1, result2, result3;
  8923. var pos0, pos1;
  8924. pos0 = pos;
  8925. result0 = parse_disp_type();
  8926. if (result0 !== null) {
  8927. result1 = [];
  8928. pos1 = pos;
  8929. result2 = parse_SEMI();
  8930. if (result2 !== null) {
  8931. result3 = parse_disp_param();
  8932. if (result3 !== null) {
  8933. result2 = [result2, result3];
  8934. } else {
  8935. result2 = null;
  8936. pos = pos1;
  8937. }
  8938. } else {
  8939. result2 = null;
  8940. pos = pos1;
  8941. }
  8942. while (result2 !== null) {
  8943. result1.push(result2);
  8944. pos1 = pos;
  8945. result2 = parse_SEMI();
  8946. if (result2 !== null) {
  8947. result3 = parse_disp_param();
  8948. if (result3 !== null) {
  8949. result2 = [result2, result3];
  8950. } else {
  8951. result2 = null;
  8952. pos = pos1;
  8953. }
  8954. } else {
  8955. result2 = null;
  8956. pos = pos1;
  8957. }
  8958. }
  8959. if (result1 !== null) {
  8960. result0 = [result0, result1];
  8961. } else {
  8962. result0 = null;
  8963. pos = pos0;
  8964. }
  8965. } else {
  8966. result0 = null;
  8967. pos = pos0;
  8968. }
  8969. return result0;
  8970. }
  8971. function parse_disp_type() {
  8972. var result0;
  8973. if (input.substr(pos, 6).toLowerCase() === "render") {
  8974. result0 = input.substr(pos, 6);
  8975. pos += 6;
  8976. } else {
  8977. result0 = null;
  8978. if (reportFailures === 0) {
  8979. matchFailed("\"render\"");
  8980. }
  8981. }
  8982. if (result0 === null) {
  8983. if (input.substr(pos, 7).toLowerCase() === "session") {
  8984. result0 = input.substr(pos, 7);
  8985. pos += 7;
  8986. } else {
  8987. result0 = null;
  8988. if (reportFailures === 0) {
  8989. matchFailed("\"session\"");
  8990. }
  8991. }
  8992. if (result0 === null) {
  8993. if (input.substr(pos, 4).toLowerCase() === "icon") {
  8994. result0 = input.substr(pos, 4);
  8995. pos += 4;
  8996. } else {
  8997. result0 = null;
  8998. if (reportFailures === 0) {
  8999. matchFailed("\"icon\"");
  9000. }
  9001. }
  9002. if (result0 === null) {
  9003. if (input.substr(pos, 5).toLowerCase() === "alert") {
  9004. result0 = input.substr(pos, 5);
  9005. pos += 5;
  9006. } else {
  9007. result0 = null;
  9008. if (reportFailures === 0) {
  9009. matchFailed("\"alert\"");
  9010. }
  9011. }
  9012. if (result0 === null) {
  9013. result0 = parse_token();
  9014. }
  9015. }
  9016. }
  9017. }
  9018. return result0;
  9019. }
  9020. function parse_disp_param() {
  9021. var result0;
  9022. result0 = parse_handling_param();
  9023. if (result0 === null) {
  9024. result0 = parse_generic_param();
  9025. }
  9026. return result0;
  9027. }
  9028. function parse_handling_param() {
  9029. var result0, result1, result2;
  9030. var pos0;
  9031. pos0 = pos;
  9032. if (input.substr(pos, 8).toLowerCase() === "handling") {
  9033. result0 = input.substr(pos, 8);
  9034. pos += 8;
  9035. } else {
  9036. result0 = null;
  9037. if (reportFailures === 0) {
  9038. matchFailed("\"handling\"");
  9039. }
  9040. }
  9041. if (result0 !== null) {
  9042. result1 = parse_EQUAL();
  9043. if (result1 !== null) {
  9044. if (input.substr(pos, 8).toLowerCase() === "optional") {
  9045. result2 = input.substr(pos, 8);
  9046. pos += 8;
  9047. } else {
  9048. result2 = null;
  9049. if (reportFailures === 0) {
  9050. matchFailed("\"optional\"");
  9051. }
  9052. }
  9053. if (result2 === null) {
  9054. if (input.substr(pos, 8).toLowerCase() === "required") {
  9055. result2 = input.substr(pos, 8);
  9056. pos += 8;
  9057. } else {
  9058. result2 = null;
  9059. if (reportFailures === 0) {
  9060. matchFailed("\"required\"");
  9061. }
  9062. }
  9063. if (result2 === null) {
  9064. result2 = parse_token();
  9065. }
  9066. }
  9067. if (result2 !== null) {
  9068. result0 = [result0, result1, result2];
  9069. } else {
  9070. result0 = null;
  9071. pos = pos0;
  9072. }
  9073. } else {
  9074. result0 = null;
  9075. pos = pos0;
  9076. }
  9077. } else {
  9078. result0 = null;
  9079. pos = pos0;
  9080. }
  9081. return result0;
  9082. }
  9083. function parse_Content_Encoding() {
  9084. var result0, result1, result2, result3;
  9085. var pos0, pos1;
  9086. pos0 = pos;
  9087. result0 = parse_token();
  9088. if (result0 !== null) {
  9089. result1 = [];
  9090. pos1 = pos;
  9091. result2 = parse_COMMA();
  9092. if (result2 !== null) {
  9093. result3 = parse_token();
  9094. if (result3 !== null) {
  9095. result2 = [result2, result3];
  9096. } else {
  9097. result2 = null;
  9098. pos = pos1;
  9099. }
  9100. } else {
  9101. result2 = null;
  9102. pos = pos1;
  9103. }
  9104. while (result2 !== null) {
  9105. result1.push(result2);
  9106. pos1 = pos;
  9107. result2 = parse_COMMA();
  9108. if (result2 !== null) {
  9109. result3 = parse_token();
  9110. if (result3 !== null) {
  9111. result2 = [result2, result3];
  9112. } else {
  9113. result2 = null;
  9114. pos = pos1;
  9115. }
  9116. } else {
  9117. result2 = null;
  9118. pos = pos1;
  9119. }
  9120. }
  9121. if (result1 !== null) {
  9122. result0 = [result0, result1];
  9123. } else {
  9124. result0 = null;
  9125. pos = pos0;
  9126. }
  9127. } else {
  9128. result0 = null;
  9129. pos = pos0;
  9130. }
  9131. return result0;
  9132. }
  9133. function parse_Content_Length() {
  9134. var result0, result1;
  9135. var pos0;
  9136. pos0 = pos;
  9137. result1 = parse_DIGIT();
  9138. if (result1 !== null) {
  9139. result0 = [];
  9140. while (result1 !== null) {
  9141. result0.push(result1);
  9142. result1 = parse_DIGIT();
  9143. }
  9144. } else {
  9145. result0 = null;
  9146. }
  9147. if (result0 !== null) {
  9148. result0 = (function(offset, length) {
  9149. data = parseInt(length.join('')); })(pos0, result0);
  9150. }
  9151. if (result0 === null) {
  9152. pos = pos0;
  9153. }
  9154. return result0;
  9155. }
  9156. function parse_Content_Type() {
  9157. var result0;
  9158. var pos0;
  9159. pos0 = pos;
  9160. result0 = parse_media_type();
  9161. if (result0 !== null) {
  9162. result0 = (function(offset) {
  9163. data = input.substring(pos, offset); })(pos0);
  9164. }
  9165. if (result0 === null) {
  9166. pos = pos0;
  9167. }
  9168. return result0;
  9169. }
  9170. function parse_media_type() {
  9171. var result0, result1, result2, result3, result4, result5;
  9172. var pos0, pos1;
  9173. pos0 = pos;
  9174. result0 = parse_m_type();
  9175. if (result0 !== null) {
  9176. result1 = parse_SLASH();
  9177. if (result1 !== null) {
  9178. result2 = parse_m_subtype();
  9179. if (result2 !== null) {
  9180. result3 = [];
  9181. pos1 = pos;
  9182. result4 = parse_SEMI();
  9183. if (result4 !== null) {
  9184. result5 = parse_m_parameter();
  9185. if (result5 !== null) {
  9186. result4 = [result4, result5];
  9187. } else {
  9188. result4 = null;
  9189. pos = pos1;
  9190. }
  9191. } else {
  9192. result4 = null;
  9193. pos = pos1;
  9194. }
  9195. while (result4 !== null) {
  9196. result3.push(result4);
  9197. pos1 = pos;
  9198. result4 = parse_SEMI();
  9199. if (result4 !== null) {
  9200. result5 = parse_m_parameter();
  9201. if (result5 !== null) {
  9202. result4 = [result4, result5];
  9203. } else {
  9204. result4 = null;
  9205. pos = pos1;
  9206. }
  9207. } else {
  9208. result4 = null;
  9209. pos = pos1;
  9210. }
  9211. }
  9212. if (result3 !== null) {
  9213. result0 = [result0, result1, result2, result3];
  9214. } else {
  9215. result0 = null;
  9216. pos = pos0;
  9217. }
  9218. } else {
  9219. result0 = null;
  9220. pos = pos0;
  9221. }
  9222. } else {
  9223. result0 = null;
  9224. pos = pos0;
  9225. }
  9226. } else {
  9227. result0 = null;
  9228. pos = pos0;
  9229. }
  9230. return result0;
  9231. }
  9232. function parse_m_type() {
  9233. var result0;
  9234. result0 = parse_discrete_type();
  9235. if (result0 === null) {
  9236. result0 = parse_composite_type();
  9237. }
  9238. return result0;
  9239. }
  9240. function parse_discrete_type() {
  9241. var result0;
  9242. if (input.substr(pos, 4).toLowerCase() === "text") {
  9243. result0 = input.substr(pos, 4);
  9244. pos += 4;
  9245. } else {
  9246. result0 = null;
  9247. if (reportFailures === 0) {
  9248. matchFailed("\"text\"");
  9249. }
  9250. }
  9251. if (result0 === null) {
  9252. if (input.substr(pos, 5).toLowerCase() === "image") {
  9253. result0 = input.substr(pos, 5);
  9254. pos += 5;
  9255. } else {
  9256. result0 = null;
  9257. if (reportFailures === 0) {
  9258. matchFailed("\"image\"");
  9259. }
  9260. }
  9261. if (result0 === null) {
  9262. if (input.substr(pos, 5).toLowerCase() === "audio") {
  9263. result0 = input.substr(pos, 5);
  9264. pos += 5;
  9265. } else {
  9266. result0 = null;
  9267. if (reportFailures === 0) {
  9268. matchFailed("\"audio\"");
  9269. }
  9270. }
  9271. if (result0 === null) {
  9272. if (input.substr(pos, 5).toLowerCase() === "video") {
  9273. result0 = input.substr(pos, 5);
  9274. pos += 5;
  9275. } else {
  9276. result0 = null;
  9277. if (reportFailures === 0) {
  9278. matchFailed("\"video\"");
  9279. }
  9280. }
  9281. if (result0 === null) {
  9282. if (input.substr(pos, 11).toLowerCase() === "application") {
  9283. result0 = input.substr(pos, 11);
  9284. pos += 11;
  9285. } else {
  9286. result0 = null;
  9287. if (reportFailures === 0) {
  9288. matchFailed("\"application\"");
  9289. }
  9290. }
  9291. if (result0 === null) {
  9292. result0 = parse_extension_token();
  9293. }
  9294. }
  9295. }
  9296. }
  9297. }
  9298. return result0;
  9299. }
  9300. function parse_composite_type() {
  9301. var result0;
  9302. if (input.substr(pos, 7).toLowerCase() === "message") {
  9303. result0 = input.substr(pos, 7);
  9304. pos += 7;
  9305. } else {
  9306. result0 = null;
  9307. if (reportFailures === 0) {
  9308. matchFailed("\"message\"");
  9309. }
  9310. }
  9311. if (result0 === null) {
  9312. if (input.substr(pos, 9).toLowerCase() === "multipart") {
  9313. result0 = input.substr(pos, 9);
  9314. pos += 9;
  9315. } else {
  9316. result0 = null;
  9317. if (reportFailures === 0) {
  9318. matchFailed("\"multipart\"");
  9319. }
  9320. }
  9321. if (result0 === null) {
  9322. result0 = parse_extension_token();
  9323. }
  9324. }
  9325. return result0;
  9326. }
  9327. function parse_extension_token() {
  9328. var result0;
  9329. result0 = parse_token();
  9330. if (result0 === null) {
  9331. result0 = parse_x_token();
  9332. }
  9333. return result0;
  9334. }
  9335. function parse_x_token() {
  9336. var result0, result1;
  9337. var pos0;
  9338. pos0 = pos;
  9339. if (input.substr(pos, 2).toLowerCase() === "x-") {
  9340. result0 = input.substr(pos, 2);
  9341. pos += 2;
  9342. } else {
  9343. result0 = null;
  9344. if (reportFailures === 0) {
  9345. matchFailed("\"x-\"");
  9346. }
  9347. }
  9348. if (result0 !== null) {
  9349. result1 = parse_token();
  9350. if (result1 !== null) {
  9351. result0 = [result0, result1];
  9352. } else {
  9353. result0 = null;
  9354. pos = pos0;
  9355. }
  9356. } else {
  9357. result0 = null;
  9358. pos = pos0;
  9359. }
  9360. return result0;
  9361. }
  9362. function parse_m_subtype() {
  9363. var result0;
  9364. result0 = parse_extension_token();
  9365. if (result0 === null) {
  9366. result0 = parse_token();
  9367. }
  9368. return result0;
  9369. }
  9370. function parse_m_parameter() {
  9371. var result0, result1, result2;
  9372. var pos0;
  9373. pos0 = pos;
  9374. result0 = parse_token();
  9375. if (result0 !== null) {
  9376. result1 = parse_EQUAL();
  9377. if (result1 !== null) {
  9378. result2 = parse_m_value();
  9379. if (result2 !== null) {
  9380. result0 = [result0, result1, result2];
  9381. } else {
  9382. result0 = null;
  9383. pos = pos0;
  9384. }
  9385. } else {
  9386. result0 = null;
  9387. pos = pos0;
  9388. }
  9389. } else {
  9390. result0 = null;
  9391. pos = pos0;
  9392. }
  9393. return result0;
  9394. }
  9395. function parse_m_value() {
  9396. var result0;
  9397. result0 = parse_token();
  9398. if (result0 === null) {
  9399. result0 = parse_quoted_string();
  9400. }
  9401. return result0;
  9402. }
  9403. function parse_CSeq() {
  9404. var result0, result1, result2;
  9405. var pos0;
  9406. pos0 = pos;
  9407. result0 = parse_CSeq_value();
  9408. if (result0 !== null) {
  9409. result1 = parse_LWS();
  9410. if (result1 !== null) {
  9411. result2 = parse_Method();
  9412. if (result2 !== null) {
  9413. result0 = [result0, result1, result2];
  9414. } else {
  9415. result0 = null;
  9416. pos = pos0;
  9417. }
  9418. } else {
  9419. result0 = null;
  9420. pos = pos0;
  9421. }
  9422. } else {
  9423. result0 = null;
  9424. pos = pos0;
  9425. }
  9426. return result0;
  9427. }
  9428. function parse_CSeq_value() {
  9429. var result0, result1;
  9430. var pos0;
  9431. pos0 = pos;
  9432. result1 = parse_DIGIT();
  9433. if (result1 !== null) {
  9434. result0 = [];
  9435. while (result1 !== null) {
  9436. result0.push(result1);
  9437. result1 = parse_DIGIT();
  9438. }
  9439. } else {
  9440. result0 = null;
  9441. }
  9442. if (result0 !== null) {
  9443. result0 = (function(offset, cseq_value) {
  9444. data.value=parseInt(cseq_value.join('')); })(pos0, result0);
  9445. }
  9446. if (result0 === null) {
  9447. pos = pos0;
  9448. }
  9449. return result0;
  9450. }
  9451. function parse_Expires() {
  9452. var result0;
  9453. var pos0;
  9454. pos0 = pos;
  9455. result0 = parse_delta_seconds();
  9456. if (result0 !== null) {
  9457. result0 = (function(offset, expires) {data = expires; })(pos0, result0);
  9458. }
  9459. if (result0 === null) {
  9460. pos = pos0;
  9461. }
  9462. return result0;
  9463. }
  9464. function parse_Event() {
  9465. var result0, result1, result2, result3;
  9466. var pos0, pos1, pos2;
  9467. pos0 = pos;
  9468. pos1 = pos;
  9469. result0 = parse_event_type();
  9470. if (result0 !== null) {
  9471. result1 = [];
  9472. pos2 = pos;
  9473. result2 = parse_SEMI();
  9474. if (result2 !== null) {
  9475. result3 = parse_generic_param();
  9476. if (result3 !== null) {
  9477. result2 = [result2, result3];
  9478. } else {
  9479. result2 = null;
  9480. pos = pos2;
  9481. }
  9482. } else {
  9483. result2 = null;
  9484. pos = pos2;
  9485. }
  9486. while (result2 !== null) {
  9487. result1.push(result2);
  9488. pos2 = pos;
  9489. result2 = parse_SEMI();
  9490. if (result2 !== null) {
  9491. result3 = parse_generic_param();
  9492. if (result3 !== null) {
  9493. result2 = [result2, result3];
  9494. } else {
  9495. result2 = null;
  9496. pos = pos2;
  9497. }
  9498. } else {
  9499. result2 = null;
  9500. pos = pos2;
  9501. }
  9502. }
  9503. if (result1 !== null) {
  9504. result0 = [result0, result1];
  9505. } else {
  9506. result0 = null;
  9507. pos = pos1;
  9508. }
  9509. } else {
  9510. result0 = null;
  9511. pos = pos1;
  9512. }
  9513. if (result0 !== null) {
  9514. result0 = (function(offset, event_type) {
  9515. data.event = event_type.join('').toLowerCase(); })(pos0, result0[0]);
  9516. }
  9517. if (result0 === null) {
  9518. pos = pos0;
  9519. }
  9520. return result0;
  9521. }
  9522. function parse_event_type() {
  9523. var result0, result1, result2, result3;
  9524. var pos0, pos1;
  9525. pos0 = pos;
  9526. result0 = parse_token_nodot();
  9527. if (result0 !== null) {
  9528. result1 = [];
  9529. pos1 = pos;
  9530. if (input.charCodeAt(pos) === 46) {
  9531. result2 = ".";
  9532. pos++;
  9533. } else {
  9534. result2 = null;
  9535. if (reportFailures === 0) {
  9536. matchFailed("\".\"");
  9537. }
  9538. }
  9539. if (result2 !== null) {
  9540. result3 = parse_token_nodot();
  9541. if (result3 !== null) {
  9542. result2 = [result2, result3];
  9543. } else {
  9544. result2 = null;
  9545. pos = pos1;
  9546. }
  9547. } else {
  9548. result2 = null;
  9549. pos = pos1;
  9550. }
  9551. while (result2 !== null) {
  9552. result1.push(result2);
  9553. pos1 = pos;
  9554. if (input.charCodeAt(pos) === 46) {
  9555. result2 = ".";
  9556. pos++;
  9557. } else {
  9558. result2 = null;
  9559. if (reportFailures === 0) {
  9560. matchFailed("\".\"");
  9561. }
  9562. }
  9563. if (result2 !== null) {
  9564. result3 = parse_token_nodot();
  9565. if (result3 !== null) {
  9566. result2 = [result2, result3];
  9567. } else {
  9568. result2 = null;
  9569. pos = pos1;
  9570. }
  9571. } else {
  9572. result2 = null;
  9573. pos = pos1;
  9574. }
  9575. }
  9576. if (result1 !== null) {
  9577. result0 = [result0, result1];
  9578. } else {
  9579. result0 = null;
  9580. pos = pos0;
  9581. }
  9582. } else {
  9583. result0 = null;
  9584. pos = pos0;
  9585. }
  9586. return result0;
  9587. }
  9588. function parse_From() {
  9589. var result0, result1, result2, result3;
  9590. var pos0, pos1, pos2;
  9591. pos0 = pos;
  9592. pos1 = pos;
  9593. result0 = parse_SIP_URI_noparams();
  9594. if (result0 === null) {
  9595. result0 = parse_name_addr();
  9596. }
  9597. if (result0 !== null) {
  9598. result1 = [];
  9599. pos2 = pos;
  9600. result2 = parse_SEMI();
  9601. if (result2 !== null) {
  9602. result3 = parse_from_param();
  9603. if (result3 !== null) {
  9604. result2 = [result2, result3];
  9605. } else {
  9606. result2 = null;
  9607. pos = pos2;
  9608. }
  9609. } else {
  9610. result2 = null;
  9611. pos = pos2;
  9612. }
  9613. while (result2 !== null) {
  9614. result1.push(result2);
  9615. pos2 = pos;
  9616. result2 = parse_SEMI();
  9617. if (result2 !== null) {
  9618. result3 = parse_from_param();
  9619. if (result3 !== null) {
  9620. result2 = [result2, result3];
  9621. } else {
  9622. result2 = null;
  9623. pos = pos2;
  9624. }
  9625. } else {
  9626. result2 = null;
  9627. pos = pos2;
  9628. }
  9629. }
  9630. if (result1 !== null) {
  9631. result0 = [result0, result1];
  9632. } else {
  9633. result0 = null;
  9634. pos = pos1;
  9635. }
  9636. } else {
  9637. result0 = null;
  9638. pos = pos1;
  9639. }
  9640. if (result0 !== null) {
  9641. result0 = (function(offset) {
  9642. var tag = data.tag;
  9643. try {
  9644. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  9645. if (tag) {data.setParam('tag',tag)}
  9646. } catch(e) {
  9647. data = -1;
  9648. }})(pos0);
  9649. }
  9650. if (result0 === null) {
  9651. pos = pos0;
  9652. }
  9653. return result0;
  9654. }
  9655. function parse_from_param() {
  9656. var result0;
  9657. result0 = parse_tag_param();
  9658. if (result0 === null) {
  9659. result0 = parse_generic_param();
  9660. }
  9661. return result0;
  9662. }
  9663. function parse_tag_param() {
  9664. var result0, result1, result2;
  9665. var pos0, pos1;
  9666. pos0 = pos;
  9667. pos1 = pos;
  9668. if (input.substr(pos, 3).toLowerCase() === "tag") {
  9669. result0 = input.substr(pos, 3);
  9670. pos += 3;
  9671. } else {
  9672. result0 = null;
  9673. if (reportFailures === 0) {
  9674. matchFailed("\"tag\"");
  9675. }
  9676. }
  9677. if (result0 !== null) {
  9678. result1 = parse_EQUAL();
  9679. if (result1 !== null) {
  9680. result2 = parse_token();
  9681. if (result2 !== null) {
  9682. result0 = [result0, result1, result2];
  9683. } else {
  9684. result0 = null;
  9685. pos = pos1;
  9686. }
  9687. } else {
  9688. result0 = null;
  9689. pos = pos1;
  9690. }
  9691. } else {
  9692. result0 = null;
  9693. pos = pos1;
  9694. }
  9695. if (result0 !== null) {
  9696. result0 = (function(offset, tag) {data.tag = tag; })(pos0, result0[2]);
  9697. }
  9698. if (result0 === null) {
  9699. pos = pos0;
  9700. }
  9701. return result0;
  9702. }
  9703. function parse_Max_Forwards() {
  9704. var result0, result1;
  9705. var pos0;
  9706. pos0 = pos;
  9707. result1 = parse_DIGIT();
  9708. if (result1 !== null) {
  9709. result0 = [];
  9710. while (result1 !== null) {
  9711. result0.push(result1);
  9712. result1 = parse_DIGIT();
  9713. }
  9714. } else {
  9715. result0 = null;
  9716. }
  9717. if (result0 !== null) {
  9718. result0 = (function(offset, forwards) {
  9719. data = parseInt(forwards.join('')); })(pos0, result0);
  9720. }
  9721. if (result0 === null) {
  9722. pos = pos0;
  9723. }
  9724. return result0;
  9725. }
  9726. function parse_Min_Expires() {
  9727. var result0;
  9728. var pos0;
  9729. pos0 = pos;
  9730. result0 = parse_delta_seconds();
  9731. if (result0 !== null) {
  9732. result0 = (function(offset, min_expires) {data = min_expires; })(pos0, result0);
  9733. }
  9734. if (result0 === null) {
  9735. pos = pos0;
  9736. }
  9737. return result0;
  9738. }
  9739. function parse_Name_Addr_Header() {
  9740. var result0, result1, result2, result3, result4, result5, result6;
  9741. var pos0, pos1, pos2;
  9742. pos0 = pos;
  9743. pos1 = pos;
  9744. result0 = [];
  9745. result1 = parse_display_name();
  9746. while (result1 !== null) {
  9747. result0.push(result1);
  9748. result1 = parse_display_name();
  9749. }
  9750. if (result0 !== null) {
  9751. result1 = parse_LAQUOT();
  9752. if (result1 !== null) {
  9753. result2 = parse_SIP_URI();
  9754. if (result2 !== null) {
  9755. result3 = parse_RAQUOT();
  9756. if (result3 !== null) {
  9757. result4 = [];
  9758. pos2 = pos;
  9759. result5 = parse_SEMI();
  9760. if (result5 !== null) {
  9761. result6 = parse_generic_param();
  9762. if (result6 !== null) {
  9763. result5 = [result5, result6];
  9764. } else {
  9765. result5 = null;
  9766. pos = pos2;
  9767. }
  9768. } else {
  9769. result5 = null;
  9770. pos = pos2;
  9771. }
  9772. while (result5 !== null) {
  9773. result4.push(result5);
  9774. pos2 = pos;
  9775. result5 = parse_SEMI();
  9776. if (result5 !== null) {
  9777. result6 = parse_generic_param();
  9778. if (result6 !== null) {
  9779. result5 = [result5, result6];
  9780. } else {
  9781. result5 = null;
  9782. pos = pos2;
  9783. }
  9784. } else {
  9785. result5 = null;
  9786. pos = pos2;
  9787. }
  9788. }
  9789. if (result4 !== null) {
  9790. result0 = [result0, result1, result2, result3, result4];
  9791. } else {
  9792. result0 = null;
  9793. pos = pos1;
  9794. }
  9795. } else {
  9796. result0 = null;
  9797. pos = pos1;
  9798. }
  9799. } else {
  9800. result0 = null;
  9801. pos = pos1;
  9802. }
  9803. } else {
  9804. result0 = null;
  9805. pos = pos1;
  9806. }
  9807. } else {
  9808. result0 = null;
  9809. pos = pos1;
  9810. }
  9811. if (result0 !== null) {
  9812. result0 = (function(offset) {
  9813. try {
  9814. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  9815. } catch(e) {
  9816. data = -1;
  9817. }})(pos0);
  9818. }
  9819. if (result0 === null) {
  9820. pos = pos0;
  9821. }
  9822. return result0;
  9823. }
  9824. function parse_Proxy_Authenticate() {
  9825. var result0;
  9826. result0 = parse_challenge();
  9827. return result0;
  9828. }
  9829. function parse_challenge() {
  9830. var result0, result1, result2, result3, result4, result5;
  9831. var pos0, pos1;
  9832. pos0 = pos;
  9833. if (input.substr(pos, 6).toLowerCase() === "digest") {
  9834. result0 = input.substr(pos, 6);
  9835. pos += 6;
  9836. } else {
  9837. result0 = null;
  9838. if (reportFailures === 0) {
  9839. matchFailed("\"Digest\"");
  9840. }
  9841. }
  9842. if (result0 !== null) {
  9843. result1 = parse_LWS();
  9844. if (result1 !== null) {
  9845. result2 = parse_digest_cln();
  9846. if (result2 !== null) {
  9847. result3 = [];
  9848. pos1 = pos;
  9849. result4 = parse_COMMA();
  9850. if (result4 !== null) {
  9851. result5 = parse_digest_cln();
  9852. if (result5 !== null) {
  9853. result4 = [result4, result5];
  9854. } else {
  9855. result4 = null;
  9856. pos = pos1;
  9857. }
  9858. } else {
  9859. result4 = null;
  9860. pos = pos1;
  9861. }
  9862. while (result4 !== null) {
  9863. result3.push(result4);
  9864. pos1 = pos;
  9865. result4 = parse_COMMA();
  9866. if (result4 !== null) {
  9867. result5 = parse_digest_cln();
  9868. if (result5 !== null) {
  9869. result4 = [result4, result5];
  9870. } else {
  9871. result4 = null;
  9872. pos = pos1;
  9873. }
  9874. } else {
  9875. result4 = null;
  9876. pos = pos1;
  9877. }
  9878. }
  9879. if (result3 !== null) {
  9880. result0 = [result0, result1, result2, result3];
  9881. } else {
  9882. result0 = null;
  9883. pos = pos0;
  9884. }
  9885. } else {
  9886. result0 = null;
  9887. pos = pos0;
  9888. }
  9889. } else {
  9890. result0 = null;
  9891. pos = pos0;
  9892. }
  9893. } else {
  9894. result0 = null;
  9895. pos = pos0;
  9896. }
  9897. if (result0 === null) {
  9898. result0 = parse_other_challenge();
  9899. }
  9900. return result0;
  9901. }
  9902. function parse_other_challenge() {
  9903. var result0, result1, result2, result3, result4, result5;
  9904. var pos0, pos1;
  9905. pos0 = pos;
  9906. result0 = parse_token();
  9907. if (result0 !== null) {
  9908. result1 = parse_LWS();
  9909. if (result1 !== null) {
  9910. result2 = parse_auth_param();
  9911. if (result2 !== null) {
  9912. result3 = [];
  9913. pos1 = pos;
  9914. result4 = parse_COMMA();
  9915. if (result4 !== null) {
  9916. result5 = parse_auth_param();
  9917. if (result5 !== null) {
  9918. result4 = [result4, result5];
  9919. } else {
  9920. result4 = null;
  9921. pos = pos1;
  9922. }
  9923. } else {
  9924. result4 = null;
  9925. pos = pos1;
  9926. }
  9927. while (result4 !== null) {
  9928. result3.push(result4);
  9929. pos1 = pos;
  9930. result4 = parse_COMMA();
  9931. if (result4 !== null) {
  9932. result5 = parse_auth_param();
  9933. if (result5 !== null) {
  9934. result4 = [result4, result5];
  9935. } else {
  9936. result4 = null;
  9937. pos = pos1;
  9938. }
  9939. } else {
  9940. result4 = null;
  9941. pos = pos1;
  9942. }
  9943. }
  9944. if (result3 !== null) {
  9945. result0 = [result0, result1, result2, result3];
  9946. } else {
  9947. result0 = null;
  9948. pos = pos0;
  9949. }
  9950. } else {
  9951. result0 = null;
  9952. pos = pos0;
  9953. }
  9954. } else {
  9955. result0 = null;
  9956. pos = pos0;
  9957. }
  9958. } else {
  9959. result0 = null;
  9960. pos = pos0;
  9961. }
  9962. return result0;
  9963. }
  9964. function parse_auth_param() {
  9965. var result0, result1, result2;
  9966. var pos0;
  9967. pos0 = pos;
  9968. result0 = parse_token();
  9969. if (result0 !== null) {
  9970. result1 = parse_EQUAL();
  9971. if (result1 !== null) {
  9972. result2 = parse_token();
  9973. if (result2 === null) {
  9974. result2 = parse_quoted_string();
  9975. }
  9976. if (result2 !== null) {
  9977. result0 = [result0, result1, result2];
  9978. } else {
  9979. result0 = null;
  9980. pos = pos0;
  9981. }
  9982. } else {
  9983. result0 = null;
  9984. pos = pos0;
  9985. }
  9986. } else {
  9987. result0 = null;
  9988. pos = pos0;
  9989. }
  9990. return result0;
  9991. }
  9992. function parse_digest_cln() {
  9993. var result0;
  9994. result0 = parse_realm();
  9995. if (result0 === null) {
  9996. result0 = parse_domain();
  9997. if (result0 === null) {
  9998. result0 = parse_nonce();
  9999. if (result0 === null) {
  10000. result0 = parse_opaque();
  10001. if (result0 === null) {
  10002. result0 = parse_stale();
  10003. if (result0 === null) {
  10004. result0 = parse_algorithm();
  10005. if (result0 === null) {
  10006. result0 = parse_qop_options();
  10007. if (result0 === null) {
  10008. result0 = parse_auth_param();
  10009. }
  10010. }
  10011. }
  10012. }
  10013. }
  10014. }
  10015. }
  10016. return result0;
  10017. }
  10018. function parse_realm() {
  10019. var result0, result1, result2;
  10020. var pos0;
  10021. pos0 = pos;
  10022. if (input.substr(pos, 5).toLowerCase() === "realm") {
  10023. result0 = input.substr(pos, 5);
  10024. pos += 5;
  10025. } else {
  10026. result0 = null;
  10027. if (reportFailures === 0) {
  10028. matchFailed("\"realm\"");
  10029. }
  10030. }
  10031. if (result0 !== null) {
  10032. result1 = parse_EQUAL();
  10033. if (result1 !== null) {
  10034. result2 = parse_realm_value();
  10035. if (result2 !== null) {
  10036. result0 = [result0, result1, result2];
  10037. } else {
  10038. result0 = null;
  10039. pos = pos0;
  10040. }
  10041. } else {
  10042. result0 = null;
  10043. pos = pos0;
  10044. }
  10045. } else {
  10046. result0 = null;
  10047. pos = pos0;
  10048. }
  10049. return result0;
  10050. }
  10051. function parse_realm_value() {
  10052. var result0;
  10053. var pos0;
  10054. pos0 = pos;
  10055. result0 = parse_quoted_string_clean();
  10056. if (result0 !== null) {
  10057. result0 = (function(offset, realm) { data.realm = realm; })(pos0, result0);
  10058. }
  10059. if (result0 === null) {
  10060. pos = pos0;
  10061. }
  10062. return result0;
  10063. }
  10064. function parse_domain() {
  10065. var result0, result1, result2, result3, result4, result5, result6;
  10066. var pos0, pos1;
  10067. pos0 = pos;
  10068. if (input.substr(pos, 6).toLowerCase() === "domain") {
  10069. result0 = input.substr(pos, 6);
  10070. pos += 6;
  10071. } else {
  10072. result0 = null;
  10073. if (reportFailures === 0) {
  10074. matchFailed("\"domain\"");
  10075. }
  10076. }
  10077. if (result0 !== null) {
  10078. result1 = parse_EQUAL();
  10079. if (result1 !== null) {
  10080. result2 = parse_LDQUOT();
  10081. if (result2 !== null) {
  10082. result3 = parse_URI();
  10083. if (result3 !== null) {
  10084. result4 = [];
  10085. pos1 = pos;
  10086. result6 = parse_SP();
  10087. if (result6 !== null) {
  10088. result5 = [];
  10089. while (result6 !== null) {
  10090. result5.push(result6);
  10091. result6 = parse_SP();
  10092. }
  10093. } else {
  10094. result5 = null;
  10095. }
  10096. if (result5 !== null) {
  10097. result6 = parse_URI();
  10098. if (result6 !== null) {
  10099. result5 = [result5, result6];
  10100. } else {
  10101. result5 = null;
  10102. pos = pos1;
  10103. }
  10104. } else {
  10105. result5 = null;
  10106. pos = pos1;
  10107. }
  10108. while (result5 !== null) {
  10109. result4.push(result5);
  10110. pos1 = pos;
  10111. result6 = parse_SP();
  10112. if (result6 !== null) {
  10113. result5 = [];
  10114. while (result6 !== null) {
  10115. result5.push(result6);
  10116. result6 = parse_SP();
  10117. }
  10118. } else {
  10119. result5 = null;
  10120. }
  10121. if (result5 !== null) {
  10122. result6 = parse_URI();
  10123. if (result6 !== null) {
  10124. result5 = [result5, result6];
  10125. } else {
  10126. result5 = null;
  10127. pos = pos1;
  10128. }
  10129. } else {
  10130. result5 = null;
  10131. pos = pos1;
  10132. }
  10133. }
  10134. if (result4 !== null) {
  10135. result5 = parse_RDQUOT();
  10136. if (result5 !== null) {
  10137. result0 = [result0, result1, result2, result3, result4, result5];
  10138. } else {
  10139. result0 = null;
  10140. pos = pos0;
  10141. }
  10142. } else {
  10143. result0 = null;
  10144. pos = pos0;
  10145. }
  10146. } else {
  10147. result0 = null;
  10148. pos = pos0;
  10149. }
  10150. } else {
  10151. result0 = null;
  10152. pos = pos0;
  10153. }
  10154. } else {
  10155. result0 = null;
  10156. pos = pos0;
  10157. }
  10158. } else {
  10159. result0 = null;
  10160. pos = pos0;
  10161. }
  10162. return result0;
  10163. }
  10164. function parse_URI() {
  10165. var result0;
  10166. result0 = parse_absoluteURI();
  10167. if (result0 === null) {
  10168. result0 = parse_abs_path();
  10169. }
  10170. return result0;
  10171. }
  10172. function parse_nonce() {
  10173. var result0, result1, result2;
  10174. var pos0;
  10175. pos0 = pos;
  10176. if (input.substr(pos, 5).toLowerCase() === "nonce") {
  10177. result0 = input.substr(pos, 5);
  10178. pos += 5;
  10179. } else {
  10180. result0 = null;
  10181. if (reportFailures === 0) {
  10182. matchFailed("\"nonce\"");
  10183. }
  10184. }
  10185. if (result0 !== null) {
  10186. result1 = parse_EQUAL();
  10187. if (result1 !== null) {
  10188. result2 = parse_nonce_value();
  10189. if (result2 !== null) {
  10190. result0 = [result0, result1, result2];
  10191. } else {
  10192. result0 = null;
  10193. pos = pos0;
  10194. }
  10195. } else {
  10196. result0 = null;
  10197. pos = pos0;
  10198. }
  10199. } else {
  10200. result0 = null;
  10201. pos = pos0;
  10202. }
  10203. return result0;
  10204. }
  10205. function parse_nonce_value() {
  10206. var result0;
  10207. var pos0;
  10208. pos0 = pos;
  10209. result0 = parse_quoted_string_clean();
  10210. if (result0 !== null) {
  10211. result0 = (function(offset, nonce) { data.nonce=nonce; })(pos0, result0);
  10212. }
  10213. if (result0 === null) {
  10214. pos = pos0;
  10215. }
  10216. return result0;
  10217. }
  10218. function parse_opaque() {
  10219. var result0, result1, result2;
  10220. var pos0, pos1;
  10221. pos0 = pos;
  10222. pos1 = pos;
  10223. if (input.substr(pos, 6).toLowerCase() === "opaque") {
  10224. result0 = input.substr(pos, 6);
  10225. pos += 6;
  10226. } else {
  10227. result0 = null;
  10228. if (reportFailures === 0) {
  10229. matchFailed("\"opaque\"");
  10230. }
  10231. }
  10232. if (result0 !== null) {
  10233. result1 = parse_EQUAL();
  10234. if (result1 !== null) {
  10235. result2 = parse_quoted_string_clean();
  10236. if (result2 !== null) {
  10237. result0 = [result0, result1, result2];
  10238. } else {
  10239. result0 = null;
  10240. pos = pos1;
  10241. }
  10242. } else {
  10243. result0 = null;
  10244. pos = pos1;
  10245. }
  10246. } else {
  10247. result0 = null;
  10248. pos = pos1;
  10249. }
  10250. if (result0 !== null) {
  10251. result0 = (function(offset, opaque) { data.opaque=opaque; })(pos0, result0[2]);
  10252. }
  10253. if (result0 === null) {
  10254. pos = pos0;
  10255. }
  10256. return result0;
  10257. }
  10258. function parse_stale() {
  10259. var result0, result1, result2;
  10260. var pos0, pos1;
  10261. pos0 = pos;
  10262. if (input.substr(pos, 5).toLowerCase() === "stale") {
  10263. result0 = input.substr(pos, 5);
  10264. pos += 5;
  10265. } else {
  10266. result0 = null;
  10267. if (reportFailures === 0) {
  10268. matchFailed("\"stale\"");
  10269. }
  10270. }
  10271. if (result0 !== null) {
  10272. result1 = parse_EQUAL();
  10273. if (result1 !== null) {
  10274. pos1 = pos;
  10275. if (input.substr(pos, 4).toLowerCase() === "true") {
  10276. result2 = input.substr(pos, 4);
  10277. pos += 4;
  10278. } else {
  10279. result2 = null;
  10280. if (reportFailures === 0) {
  10281. matchFailed("\"true\"");
  10282. }
  10283. }
  10284. if (result2 !== null) {
  10285. result2 = (function(offset) { data.stale=true; })(pos1);
  10286. }
  10287. if (result2 === null) {
  10288. pos = pos1;
  10289. }
  10290. if (result2 === null) {
  10291. pos1 = pos;
  10292. if (input.substr(pos, 5).toLowerCase() === "false") {
  10293. result2 = input.substr(pos, 5);
  10294. pos += 5;
  10295. } else {
  10296. result2 = null;
  10297. if (reportFailures === 0) {
  10298. matchFailed("\"false\"");
  10299. }
  10300. }
  10301. if (result2 !== null) {
  10302. result2 = (function(offset) { data.stale=false; })(pos1);
  10303. }
  10304. if (result2 === null) {
  10305. pos = pos1;
  10306. }
  10307. }
  10308. if (result2 !== null) {
  10309. result0 = [result0, result1, result2];
  10310. } else {
  10311. result0 = null;
  10312. pos = pos0;
  10313. }
  10314. } else {
  10315. result0 = null;
  10316. pos = pos0;
  10317. }
  10318. } else {
  10319. result0 = null;
  10320. pos = pos0;
  10321. }
  10322. return result0;
  10323. }
  10324. function parse_algorithm() {
  10325. var result0, result1, result2;
  10326. var pos0, pos1;
  10327. pos0 = pos;
  10328. pos1 = pos;
  10329. if (input.substr(pos, 9).toLowerCase() === "algorithm") {
  10330. result0 = input.substr(pos, 9);
  10331. pos += 9;
  10332. } else {
  10333. result0 = null;
  10334. if (reportFailures === 0) {
  10335. matchFailed("\"algorithm\"");
  10336. }
  10337. }
  10338. if (result0 !== null) {
  10339. result1 = parse_EQUAL();
  10340. if (result1 !== null) {
  10341. if (input.substr(pos, 3).toLowerCase() === "md5") {
  10342. result2 = input.substr(pos, 3);
  10343. pos += 3;
  10344. } else {
  10345. result2 = null;
  10346. if (reportFailures === 0) {
  10347. matchFailed("\"MD5\"");
  10348. }
  10349. }
  10350. if (result2 === null) {
  10351. if (input.substr(pos, 8).toLowerCase() === "md5-sess") {
  10352. result2 = input.substr(pos, 8);
  10353. pos += 8;
  10354. } else {
  10355. result2 = null;
  10356. if (reportFailures === 0) {
  10357. matchFailed("\"MD5-sess\"");
  10358. }
  10359. }
  10360. if (result2 === null) {
  10361. result2 = parse_token();
  10362. }
  10363. }
  10364. if (result2 !== null) {
  10365. result0 = [result0, result1, result2];
  10366. } else {
  10367. result0 = null;
  10368. pos = pos1;
  10369. }
  10370. } else {
  10371. result0 = null;
  10372. pos = pos1;
  10373. }
  10374. } else {
  10375. result0 = null;
  10376. pos = pos1;
  10377. }
  10378. if (result0 !== null) {
  10379. result0 = (function(offset, algorithm) {
  10380. data.algorithm=algorithm.toUpperCase(); })(pos0, result0[2]);
  10381. }
  10382. if (result0 === null) {
  10383. pos = pos0;
  10384. }
  10385. return result0;
  10386. }
  10387. function parse_qop_options() {
  10388. var result0, result1, result2, result3, result4, result5, result6;
  10389. var pos0, pos1, pos2;
  10390. pos0 = pos;
  10391. if (input.substr(pos, 3).toLowerCase() === "qop") {
  10392. result0 = input.substr(pos, 3);
  10393. pos += 3;
  10394. } else {
  10395. result0 = null;
  10396. if (reportFailures === 0) {
  10397. matchFailed("\"qop\"");
  10398. }
  10399. }
  10400. if (result0 !== null) {
  10401. result1 = parse_EQUAL();
  10402. if (result1 !== null) {
  10403. result2 = parse_LDQUOT();
  10404. if (result2 !== null) {
  10405. pos1 = pos;
  10406. result3 = parse_qop_value();
  10407. if (result3 !== null) {
  10408. result4 = [];
  10409. pos2 = pos;
  10410. if (input.charCodeAt(pos) === 44) {
  10411. result5 = ",";
  10412. pos++;
  10413. } else {
  10414. result5 = null;
  10415. if (reportFailures === 0) {
  10416. matchFailed("\",\"");
  10417. }
  10418. }
  10419. if (result5 !== null) {
  10420. result6 = parse_qop_value();
  10421. if (result6 !== null) {
  10422. result5 = [result5, result6];
  10423. } else {
  10424. result5 = null;
  10425. pos = pos2;
  10426. }
  10427. } else {
  10428. result5 = null;
  10429. pos = pos2;
  10430. }
  10431. while (result5 !== null) {
  10432. result4.push(result5);
  10433. pos2 = pos;
  10434. if (input.charCodeAt(pos) === 44) {
  10435. result5 = ",";
  10436. pos++;
  10437. } else {
  10438. result5 = null;
  10439. if (reportFailures === 0) {
  10440. matchFailed("\",\"");
  10441. }
  10442. }
  10443. if (result5 !== null) {
  10444. result6 = parse_qop_value();
  10445. if (result6 !== null) {
  10446. result5 = [result5, result6];
  10447. } else {
  10448. result5 = null;
  10449. pos = pos2;
  10450. }
  10451. } else {
  10452. result5 = null;
  10453. pos = pos2;
  10454. }
  10455. }
  10456. if (result4 !== null) {
  10457. result3 = [result3, result4];
  10458. } else {
  10459. result3 = null;
  10460. pos = pos1;
  10461. }
  10462. } else {
  10463. result3 = null;
  10464. pos = pos1;
  10465. }
  10466. if (result3 !== null) {
  10467. result4 = parse_RDQUOT();
  10468. if (result4 !== null) {
  10469. result0 = [result0, result1, result2, result3, result4];
  10470. } else {
  10471. result0 = null;
  10472. pos = pos0;
  10473. }
  10474. } else {
  10475. result0 = null;
  10476. pos = pos0;
  10477. }
  10478. } else {
  10479. result0 = null;
  10480. pos = pos0;
  10481. }
  10482. } else {
  10483. result0 = null;
  10484. pos = pos0;
  10485. }
  10486. } else {
  10487. result0 = null;
  10488. pos = pos0;
  10489. }
  10490. return result0;
  10491. }
  10492. function parse_qop_value() {
  10493. var result0;
  10494. var pos0;
  10495. pos0 = pos;
  10496. if (input.substr(pos, 8).toLowerCase() === "auth-int") {
  10497. result0 = input.substr(pos, 8);
  10498. pos += 8;
  10499. } else {
  10500. result0 = null;
  10501. if (reportFailures === 0) {
  10502. matchFailed("\"auth-int\"");
  10503. }
  10504. }
  10505. if (result0 === null) {
  10506. if (input.substr(pos, 4).toLowerCase() === "auth") {
  10507. result0 = input.substr(pos, 4);
  10508. pos += 4;
  10509. } else {
  10510. result0 = null;
  10511. if (reportFailures === 0) {
  10512. matchFailed("\"auth\"");
  10513. }
  10514. }
  10515. if (result0 === null) {
  10516. result0 = parse_token();
  10517. }
  10518. }
  10519. if (result0 !== null) {
  10520. result0 = (function(offset, qop_value) {
  10521. data.qop || (data.qop=[]);
  10522. data.qop.push(qop_value.toLowerCase()); })(pos0, result0);
  10523. }
  10524. if (result0 === null) {
  10525. pos = pos0;
  10526. }
  10527. return result0;
  10528. }
  10529. function parse_Proxy_Require() {
  10530. var result0, result1, result2, result3;
  10531. var pos0, pos1;
  10532. pos0 = pos;
  10533. result0 = parse_token();
  10534. if (result0 !== null) {
  10535. result1 = [];
  10536. pos1 = pos;
  10537. result2 = parse_COMMA();
  10538. if (result2 !== null) {
  10539. result3 = parse_token();
  10540. if (result3 !== null) {
  10541. result2 = [result2, result3];
  10542. } else {
  10543. result2 = null;
  10544. pos = pos1;
  10545. }
  10546. } else {
  10547. result2 = null;
  10548. pos = pos1;
  10549. }
  10550. while (result2 !== null) {
  10551. result1.push(result2);
  10552. pos1 = pos;
  10553. result2 = parse_COMMA();
  10554. if (result2 !== null) {
  10555. result3 = parse_token();
  10556. if (result3 !== null) {
  10557. result2 = [result2, result3];
  10558. } else {
  10559. result2 = null;
  10560. pos = pos1;
  10561. }
  10562. } else {
  10563. result2 = null;
  10564. pos = pos1;
  10565. }
  10566. }
  10567. if (result1 !== null) {
  10568. result0 = [result0, result1];
  10569. } else {
  10570. result0 = null;
  10571. pos = pos0;
  10572. }
  10573. } else {
  10574. result0 = null;
  10575. pos = pos0;
  10576. }
  10577. return result0;
  10578. }
  10579. function parse_Record_Route() {
  10580. var result0, result1, result2, result3;
  10581. var pos0, pos1, pos2;
  10582. pos0 = pos;
  10583. pos1 = pos;
  10584. result0 = parse_rec_route();
  10585. if (result0 !== null) {
  10586. result1 = [];
  10587. pos2 = pos;
  10588. result2 = parse_COMMA();
  10589. if (result2 !== null) {
  10590. result3 = parse_rec_route();
  10591. if (result3 !== null) {
  10592. result2 = [result2, result3];
  10593. } else {
  10594. result2 = null;
  10595. pos = pos2;
  10596. }
  10597. } else {
  10598. result2 = null;
  10599. pos = pos2;
  10600. }
  10601. while (result2 !== null) {
  10602. result1.push(result2);
  10603. pos2 = pos;
  10604. result2 = parse_COMMA();
  10605. if (result2 !== null) {
  10606. result3 = parse_rec_route();
  10607. if (result3 !== null) {
  10608. result2 = [result2, result3];
  10609. } else {
  10610. result2 = null;
  10611. pos = pos2;
  10612. }
  10613. } else {
  10614. result2 = null;
  10615. pos = pos2;
  10616. }
  10617. }
  10618. if (result1 !== null) {
  10619. result0 = [result0, result1];
  10620. } else {
  10621. result0 = null;
  10622. pos = pos1;
  10623. }
  10624. } else {
  10625. result0 = null;
  10626. pos = pos1;
  10627. }
  10628. if (result0 !== null) {
  10629. result0 = (function(offset) {
  10630. var idx, length;
  10631. length = data.multi_header.length;
  10632. for (idx = 0; idx < length; idx++) {
  10633. if (data.multi_header[idx].parsed === null) {
  10634. data = null;
  10635. break;
  10636. }
  10637. }
  10638. if (data !== null) {
  10639. data = data.multi_header;
  10640. } else {
  10641. data = -1;
  10642. }})(pos0);
  10643. }
  10644. if (result0 === null) {
  10645. pos = pos0;
  10646. }
  10647. return result0;
  10648. }
  10649. function parse_rec_route() {
  10650. var result0, result1, result2, result3;
  10651. var pos0, pos1, pos2;
  10652. pos0 = pos;
  10653. pos1 = pos;
  10654. result0 = parse_name_addr();
  10655. if (result0 !== null) {
  10656. result1 = [];
  10657. pos2 = pos;
  10658. result2 = parse_SEMI();
  10659. if (result2 !== null) {
  10660. result3 = parse_generic_param();
  10661. if (result3 !== null) {
  10662. result2 = [result2, result3];
  10663. } else {
  10664. result2 = null;
  10665. pos = pos2;
  10666. }
  10667. } else {
  10668. result2 = null;
  10669. pos = pos2;
  10670. }
  10671. while (result2 !== null) {
  10672. result1.push(result2);
  10673. pos2 = pos;
  10674. result2 = parse_SEMI();
  10675. if (result2 !== null) {
  10676. result3 = parse_generic_param();
  10677. if (result3 !== null) {
  10678. result2 = [result2, result3];
  10679. } else {
  10680. result2 = null;
  10681. pos = pos2;
  10682. }
  10683. } else {
  10684. result2 = null;
  10685. pos = pos2;
  10686. }
  10687. }
  10688. if (result1 !== null) {
  10689. result0 = [result0, result1];
  10690. } else {
  10691. result0 = null;
  10692. pos = pos1;
  10693. }
  10694. } else {
  10695. result0 = null;
  10696. pos = pos1;
  10697. }
  10698. if (result0 !== null) {
  10699. result0 = (function(offset) {
  10700. var header;
  10701. if(!data.multi_header) data.multi_header = [];
  10702. try {
  10703. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  10704. delete data.uri;
  10705. delete data.display_name;
  10706. delete data.params;
  10707. } catch(e) {
  10708. header = null;
  10709. }
  10710. data.multi_header.push( { 'possition': pos,
  10711. 'offset': offset,
  10712. 'parsed': header
  10713. });})(pos0);
  10714. }
  10715. if (result0 === null) {
  10716. pos = pos0;
  10717. }
  10718. return result0;
  10719. }
  10720. function parse_Reason() {
  10721. var result0, result1, result2, result3;
  10722. var pos0, pos1, pos2;
  10723. pos0 = pos;
  10724. pos1 = pos;
  10725. if (input.substr(pos, 3).toLowerCase() === "sip") {
  10726. result0 = input.substr(pos, 3);
  10727. pos += 3;
  10728. } else {
  10729. result0 = null;
  10730. if (reportFailures === 0) {
  10731. matchFailed("\"SIP\"");
  10732. }
  10733. }
  10734. if (result0 === null) {
  10735. result0 = parse_token();
  10736. }
  10737. if (result0 !== null) {
  10738. result1 = [];
  10739. pos2 = pos;
  10740. result2 = parse_SEMI();
  10741. if (result2 !== null) {
  10742. result3 = parse_reason_param();
  10743. if (result3 !== null) {
  10744. result2 = [result2, result3];
  10745. } else {
  10746. result2 = null;
  10747. pos = pos2;
  10748. }
  10749. } else {
  10750. result2 = null;
  10751. pos = pos2;
  10752. }
  10753. while (result2 !== null) {
  10754. result1.push(result2);
  10755. pos2 = pos;
  10756. result2 = parse_SEMI();
  10757. if (result2 !== null) {
  10758. result3 = parse_reason_param();
  10759. if (result3 !== null) {
  10760. result2 = [result2, result3];
  10761. } else {
  10762. result2 = null;
  10763. pos = pos2;
  10764. }
  10765. } else {
  10766. result2 = null;
  10767. pos = pos2;
  10768. }
  10769. }
  10770. if (result1 !== null) {
  10771. result0 = [result0, result1];
  10772. } else {
  10773. result0 = null;
  10774. pos = pos1;
  10775. }
  10776. } else {
  10777. result0 = null;
  10778. pos = pos1;
  10779. }
  10780. if (result0 !== null) {
  10781. result0 = (function(offset, protocol) {
  10782. data.protocol = protocol.toLowerCase();
  10783. if (!data.params) data.params = {};
  10784. if (data.params.text && data.params.text[0] === '"') {
  10785. var text = data.params.text;
  10786. data.text = text.substring(1, text.length-1);
  10787. delete data.params.text;
  10788. }
  10789. })(pos0, result0[0]);
  10790. }
  10791. if (result0 === null) {
  10792. pos = pos0;
  10793. }
  10794. return result0;
  10795. }
  10796. function parse_reason_param() {
  10797. var result0;
  10798. result0 = parse_reason_cause();
  10799. if (result0 === null) {
  10800. result0 = parse_generic_param();
  10801. }
  10802. return result0;
  10803. }
  10804. function parse_reason_cause() {
  10805. var result0, result1, result2, result3;
  10806. var pos0, pos1;
  10807. pos0 = pos;
  10808. pos1 = pos;
  10809. if (input.substr(pos, 5).toLowerCase() === "cause") {
  10810. result0 = input.substr(pos, 5);
  10811. pos += 5;
  10812. } else {
  10813. result0 = null;
  10814. if (reportFailures === 0) {
  10815. matchFailed("\"cause\"");
  10816. }
  10817. }
  10818. if (result0 !== null) {
  10819. result1 = parse_EQUAL();
  10820. if (result1 !== null) {
  10821. result3 = parse_DIGIT();
  10822. if (result3 !== null) {
  10823. result2 = [];
  10824. while (result3 !== null) {
  10825. result2.push(result3);
  10826. result3 = parse_DIGIT();
  10827. }
  10828. } else {
  10829. result2 = null;
  10830. }
  10831. if (result2 !== null) {
  10832. result0 = [result0, result1, result2];
  10833. } else {
  10834. result0 = null;
  10835. pos = pos1;
  10836. }
  10837. } else {
  10838. result0 = null;
  10839. pos = pos1;
  10840. }
  10841. } else {
  10842. result0 = null;
  10843. pos = pos1;
  10844. }
  10845. if (result0 !== null) {
  10846. result0 = (function(offset, cause) {
  10847. data.cause = parseInt(cause.join(''));
  10848. })(pos0, result0[2]);
  10849. }
  10850. if (result0 === null) {
  10851. pos = pos0;
  10852. }
  10853. return result0;
  10854. }
  10855. function parse_Require() {
  10856. var result0, result1, result2, result3;
  10857. var pos0, pos1;
  10858. pos0 = pos;
  10859. result0 = parse_token();
  10860. if (result0 !== null) {
  10861. result1 = [];
  10862. pos1 = pos;
  10863. result2 = parse_COMMA();
  10864. if (result2 !== null) {
  10865. result3 = parse_token();
  10866. if (result3 !== null) {
  10867. result2 = [result2, result3];
  10868. } else {
  10869. result2 = null;
  10870. pos = pos1;
  10871. }
  10872. } else {
  10873. result2 = null;
  10874. pos = pos1;
  10875. }
  10876. while (result2 !== null) {
  10877. result1.push(result2);
  10878. pos1 = pos;
  10879. result2 = parse_COMMA();
  10880. if (result2 !== null) {
  10881. result3 = parse_token();
  10882. if (result3 !== null) {
  10883. result2 = [result2, result3];
  10884. } else {
  10885. result2 = null;
  10886. pos = pos1;
  10887. }
  10888. } else {
  10889. result2 = null;
  10890. pos = pos1;
  10891. }
  10892. }
  10893. if (result1 !== null) {
  10894. result0 = [result0, result1];
  10895. } else {
  10896. result0 = null;
  10897. pos = pos0;
  10898. }
  10899. } else {
  10900. result0 = null;
  10901. pos = pos0;
  10902. }
  10903. return result0;
  10904. }
  10905. function parse_Route() {
  10906. var result0, result1, result2, result3;
  10907. var pos0, pos1;
  10908. pos0 = pos;
  10909. result0 = parse_route_param();
  10910. if (result0 !== null) {
  10911. result1 = [];
  10912. pos1 = pos;
  10913. result2 = parse_COMMA();
  10914. if (result2 !== null) {
  10915. result3 = parse_route_param();
  10916. if (result3 !== null) {
  10917. result2 = [result2, result3];
  10918. } else {
  10919. result2 = null;
  10920. pos = pos1;
  10921. }
  10922. } else {
  10923. result2 = null;
  10924. pos = pos1;
  10925. }
  10926. while (result2 !== null) {
  10927. result1.push(result2);
  10928. pos1 = pos;
  10929. result2 = parse_COMMA();
  10930. if (result2 !== null) {
  10931. result3 = parse_route_param();
  10932. if (result3 !== null) {
  10933. result2 = [result2, result3];
  10934. } else {
  10935. result2 = null;
  10936. pos = pos1;
  10937. }
  10938. } else {
  10939. result2 = null;
  10940. pos = pos1;
  10941. }
  10942. }
  10943. if (result1 !== null) {
  10944. result0 = [result0, result1];
  10945. } else {
  10946. result0 = null;
  10947. pos = pos0;
  10948. }
  10949. } else {
  10950. result0 = null;
  10951. pos = pos0;
  10952. }
  10953. return result0;
  10954. }
  10955. function parse_route_param() {
  10956. var result0, result1, result2, result3;
  10957. var pos0, pos1;
  10958. pos0 = pos;
  10959. result0 = parse_name_addr();
  10960. if (result0 !== null) {
  10961. result1 = [];
  10962. pos1 = pos;
  10963. result2 = parse_SEMI();
  10964. if (result2 !== null) {
  10965. result3 = parse_generic_param();
  10966. if (result3 !== null) {
  10967. result2 = [result2, result3];
  10968. } else {
  10969. result2 = null;
  10970. pos = pos1;
  10971. }
  10972. } else {
  10973. result2 = null;
  10974. pos = pos1;
  10975. }
  10976. while (result2 !== null) {
  10977. result1.push(result2);
  10978. pos1 = pos;
  10979. result2 = parse_SEMI();
  10980. if (result2 !== null) {
  10981. result3 = parse_generic_param();
  10982. if (result3 !== null) {
  10983. result2 = [result2, result3];
  10984. } else {
  10985. result2 = null;
  10986. pos = pos1;
  10987. }
  10988. } else {
  10989. result2 = null;
  10990. pos = pos1;
  10991. }
  10992. }
  10993. if (result1 !== null) {
  10994. result0 = [result0, result1];
  10995. } else {
  10996. result0 = null;
  10997. pos = pos0;
  10998. }
  10999. } else {
  11000. result0 = null;
  11001. pos = pos0;
  11002. }
  11003. return result0;
  11004. }
  11005. function parse_Subscription_State() {
  11006. var result0, result1, result2, result3;
  11007. var pos0, pos1;
  11008. pos0 = pos;
  11009. result0 = parse_substate_value();
  11010. if (result0 !== null) {
  11011. result1 = [];
  11012. pos1 = pos;
  11013. result2 = parse_SEMI();
  11014. if (result2 !== null) {
  11015. result3 = parse_subexp_params();
  11016. if (result3 !== null) {
  11017. result2 = [result2, result3];
  11018. } else {
  11019. result2 = null;
  11020. pos = pos1;
  11021. }
  11022. } else {
  11023. result2 = null;
  11024. pos = pos1;
  11025. }
  11026. while (result2 !== null) {
  11027. result1.push(result2);
  11028. pos1 = pos;
  11029. result2 = parse_SEMI();
  11030. if (result2 !== null) {
  11031. result3 = parse_subexp_params();
  11032. if (result3 !== null) {
  11033. result2 = [result2, result3];
  11034. } else {
  11035. result2 = null;
  11036. pos = pos1;
  11037. }
  11038. } else {
  11039. result2 = null;
  11040. pos = pos1;
  11041. }
  11042. }
  11043. if (result1 !== null) {
  11044. result0 = [result0, result1];
  11045. } else {
  11046. result0 = null;
  11047. pos = pos0;
  11048. }
  11049. } else {
  11050. result0 = null;
  11051. pos = pos0;
  11052. }
  11053. return result0;
  11054. }
  11055. function parse_substate_value() {
  11056. var result0;
  11057. var pos0;
  11058. pos0 = pos;
  11059. if (input.substr(pos, 6).toLowerCase() === "active") {
  11060. result0 = input.substr(pos, 6);
  11061. pos += 6;
  11062. } else {
  11063. result0 = null;
  11064. if (reportFailures === 0) {
  11065. matchFailed("\"active\"");
  11066. }
  11067. }
  11068. if (result0 === null) {
  11069. if (input.substr(pos, 7).toLowerCase() === "pending") {
  11070. result0 = input.substr(pos, 7);
  11071. pos += 7;
  11072. } else {
  11073. result0 = null;
  11074. if (reportFailures === 0) {
  11075. matchFailed("\"pending\"");
  11076. }
  11077. }
  11078. if (result0 === null) {
  11079. if (input.substr(pos, 10).toLowerCase() === "terminated") {
  11080. result0 = input.substr(pos, 10);
  11081. pos += 10;
  11082. } else {
  11083. result0 = null;
  11084. if (reportFailures === 0) {
  11085. matchFailed("\"terminated\"");
  11086. }
  11087. }
  11088. if (result0 === null) {
  11089. result0 = parse_token();
  11090. }
  11091. }
  11092. }
  11093. if (result0 !== null) {
  11094. result0 = (function(offset) {
  11095. data.state = input.substring(pos, offset); })(pos0);
  11096. }
  11097. if (result0 === null) {
  11098. pos = pos0;
  11099. }
  11100. return result0;
  11101. }
  11102. function parse_subexp_params() {
  11103. var result0, result1, result2;
  11104. var pos0, pos1;
  11105. pos0 = pos;
  11106. pos1 = pos;
  11107. if (input.substr(pos, 6).toLowerCase() === "reason") {
  11108. result0 = input.substr(pos, 6);
  11109. pos += 6;
  11110. } else {
  11111. result0 = null;
  11112. if (reportFailures === 0) {
  11113. matchFailed("\"reason\"");
  11114. }
  11115. }
  11116. if (result0 !== null) {
  11117. result1 = parse_EQUAL();
  11118. if (result1 !== null) {
  11119. result2 = parse_event_reason_value();
  11120. if (result2 !== null) {
  11121. result0 = [result0, result1, result2];
  11122. } else {
  11123. result0 = null;
  11124. pos = pos1;
  11125. }
  11126. } else {
  11127. result0 = null;
  11128. pos = pos1;
  11129. }
  11130. } else {
  11131. result0 = null;
  11132. pos = pos1;
  11133. }
  11134. if (result0 !== null) {
  11135. result0 = (function(offset, reason) {
  11136. if (typeof reason !== 'undefined') data.reason = reason; })(pos0, result0[2]);
  11137. }
  11138. if (result0 === null) {
  11139. pos = pos0;
  11140. }
  11141. if (result0 === null) {
  11142. pos0 = pos;
  11143. pos1 = pos;
  11144. if (input.substr(pos, 7).toLowerCase() === "expires") {
  11145. result0 = input.substr(pos, 7);
  11146. pos += 7;
  11147. } else {
  11148. result0 = null;
  11149. if (reportFailures === 0) {
  11150. matchFailed("\"expires\"");
  11151. }
  11152. }
  11153. if (result0 !== null) {
  11154. result1 = parse_EQUAL();
  11155. if (result1 !== null) {
  11156. result2 = parse_delta_seconds();
  11157. if (result2 !== null) {
  11158. result0 = [result0, result1, result2];
  11159. } else {
  11160. result0 = null;
  11161. pos = pos1;
  11162. }
  11163. } else {
  11164. result0 = null;
  11165. pos = pos1;
  11166. }
  11167. } else {
  11168. result0 = null;
  11169. pos = pos1;
  11170. }
  11171. if (result0 !== null) {
  11172. result0 = (function(offset, expires) {
  11173. if (typeof expires !== 'undefined') data.expires = expires; })(pos0, result0[2]);
  11174. }
  11175. if (result0 === null) {
  11176. pos = pos0;
  11177. }
  11178. if (result0 === null) {
  11179. pos0 = pos;
  11180. pos1 = pos;
  11181. if (input.substr(pos, 11).toLowerCase() === "retry_after") {
  11182. result0 = input.substr(pos, 11);
  11183. pos += 11;
  11184. } else {
  11185. result0 = null;
  11186. if (reportFailures === 0) {
  11187. matchFailed("\"retry_after\"");
  11188. }
  11189. }
  11190. if (result0 !== null) {
  11191. result1 = parse_EQUAL();
  11192. if (result1 !== null) {
  11193. result2 = parse_delta_seconds();
  11194. if (result2 !== null) {
  11195. result0 = [result0, result1, result2];
  11196. } else {
  11197. result0 = null;
  11198. pos = pos1;
  11199. }
  11200. } else {
  11201. result0 = null;
  11202. pos = pos1;
  11203. }
  11204. } else {
  11205. result0 = null;
  11206. pos = pos1;
  11207. }
  11208. if (result0 !== null) {
  11209. result0 = (function(offset, retry_after) {
  11210. if (typeof retry_after !== 'undefined') data.retry_after = retry_after; })(pos0, result0[2]);
  11211. }
  11212. if (result0 === null) {
  11213. pos = pos0;
  11214. }
  11215. if (result0 === null) {
  11216. result0 = parse_generic_param();
  11217. }
  11218. }
  11219. }
  11220. return result0;
  11221. }
  11222. function parse_event_reason_value() {
  11223. var result0;
  11224. if (input.substr(pos, 11).toLowerCase() === "deactivated") {
  11225. result0 = input.substr(pos, 11);
  11226. pos += 11;
  11227. } else {
  11228. result0 = null;
  11229. if (reportFailures === 0) {
  11230. matchFailed("\"deactivated\"");
  11231. }
  11232. }
  11233. if (result0 === null) {
  11234. if (input.substr(pos, 9).toLowerCase() === "probation") {
  11235. result0 = input.substr(pos, 9);
  11236. pos += 9;
  11237. } else {
  11238. result0 = null;
  11239. if (reportFailures === 0) {
  11240. matchFailed("\"probation\"");
  11241. }
  11242. }
  11243. if (result0 === null) {
  11244. if (input.substr(pos, 8).toLowerCase() === "rejected") {
  11245. result0 = input.substr(pos, 8);
  11246. pos += 8;
  11247. } else {
  11248. result0 = null;
  11249. if (reportFailures === 0) {
  11250. matchFailed("\"rejected\"");
  11251. }
  11252. }
  11253. if (result0 === null) {
  11254. if (input.substr(pos, 7).toLowerCase() === "timeout") {
  11255. result0 = input.substr(pos, 7);
  11256. pos += 7;
  11257. } else {
  11258. result0 = null;
  11259. if (reportFailures === 0) {
  11260. matchFailed("\"timeout\"");
  11261. }
  11262. }
  11263. if (result0 === null) {
  11264. if (input.substr(pos, 6).toLowerCase() === "giveup") {
  11265. result0 = input.substr(pos, 6);
  11266. pos += 6;
  11267. } else {
  11268. result0 = null;
  11269. if (reportFailures === 0) {
  11270. matchFailed("\"giveup\"");
  11271. }
  11272. }
  11273. if (result0 === null) {
  11274. if (input.substr(pos, 10).toLowerCase() === "noresource") {
  11275. result0 = input.substr(pos, 10);
  11276. pos += 10;
  11277. } else {
  11278. result0 = null;
  11279. if (reportFailures === 0) {
  11280. matchFailed("\"noresource\"");
  11281. }
  11282. }
  11283. if (result0 === null) {
  11284. if (input.substr(pos, 9).toLowerCase() === "invariant") {
  11285. result0 = input.substr(pos, 9);
  11286. pos += 9;
  11287. } else {
  11288. result0 = null;
  11289. if (reportFailures === 0) {
  11290. matchFailed("\"invariant\"");
  11291. }
  11292. }
  11293. if (result0 === null) {
  11294. result0 = parse_token();
  11295. }
  11296. }
  11297. }
  11298. }
  11299. }
  11300. }
  11301. }
  11302. return result0;
  11303. }
  11304. function parse_Subject() {
  11305. var result0;
  11306. result0 = parse_TEXT_UTF8_TRIM();
  11307. result0 = result0 !== null ? result0 : "";
  11308. return result0;
  11309. }
  11310. function parse_Supported() {
  11311. var result0, result1, result2, result3;
  11312. var pos0, pos1;
  11313. pos0 = pos;
  11314. result0 = parse_token();
  11315. if (result0 !== null) {
  11316. result1 = [];
  11317. pos1 = pos;
  11318. result2 = parse_COMMA();
  11319. if (result2 !== null) {
  11320. result3 = parse_token();
  11321. if (result3 !== null) {
  11322. result2 = [result2, result3];
  11323. } else {
  11324. result2 = null;
  11325. pos = pos1;
  11326. }
  11327. } else {
  11328. result2 = null;
  11329. pos = pos1;
  11330. }
  11331. while (result2 !== null) {
  11332. result1.push(result2);
  11333. pos1 = pos;
  11334. result2 = parse_COMMA();
  11335. if (result2 !== null) {
  11336. result3 = parse_token();
  11337. if (result3 !== null) {
  11338. result2 = [result2, result3];
  11339. } else {
  11340. result2 = null;
  11341. pos = pos1;
  11342. }
  11343. } else {
  11344. result2 = null;
  11345. pos = pos1;
  11346. }
  11347. }
  11348. if (result1 !== null) {
  11349. result0 = [result0, result1];
  11350. } else {
  11351. result0 = null;
  11352. pos = pos0;
  11353. }
  11354. } else {
  11355. result0 = null;
  11356. pos = pos0;
  11357. }
  11358. result0 = result0 !== null ? result0 : "";
  11359. return result0;
  11360. }
  11361. function parse_To() {
  11362. var result0, result1, result2, result3;
  11363. var pos0, pos1, pos2;
  11364. pos0 = pos;
  11365. pos1 = pos;
  11366. result0 = parse_SIP_URI_noparams();
  11367. if (result0 === null) {
  11368. result0 = parse_name_addr();
  11369. }
  11370. if (result0 !== null) {
  11371. result1 = [];
  11372. pos2 = pos;
  11373. result2 = parse_SEMI();
  11374. if (result2 !== null) {
  11375. result3 = parse_to_param();
  11376. if (result3 !== null) {
  11377. result2 = [result2, result3];
  11378. } else {
  11379. result2 = null;
  11380. pos = pos2;
  11381. }
  11382. } else {
  11383. result2 = null;
  11384. pos = pos2;
  11385. }
  11386. while (result2 !== null) {
  11387. result1.push(result2);
  11388. pos2 = pos;
  11389. result2 = parse_SEMI();
  11390. if (result2 !== null) {
  11391. result3 = parse_to_param();
  11392. if (result3 !== null) {
  11393. result2 = [result2, result3];
  11394. } else {
  11395. result2 = null;
  11396. pos = pos2;
  11397. }
  11398. } else {
  11399. result2 = null;
  11400. pos = pos2;
  11401. }
  11402. }
  11403. if (result1 !== null) {
  11404. result0 = [result0, result1];
  11405. } else {
  11406. result0 = null;
  11407. pos = pos1;
  11408. }
  11409. } else {
  11410. result0 = null;
  11411. pos = pos1;
  11412. }
  11413. if (result0 !== null) {
  11414. result0 = (function(offset) {
  11415. var tag = data.tag;
  11416. try {
  11417. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  11418. if (tag) {data.setParam('tag',tag)}
  11419. } catch(e) {
  11420. data = -1;
  11421. }})(pos0);
  11422. }
  11423. if (result0 === null) {
  11424. pos = pos0;
  11425. }
  11426. return result0;
  11427. }
  11428. function parse_to_param() {
  11429. var result0;
  11430. result0 = parse_tag_param();
  11431. if (result0 === null) {
  11432. result0 = parse_generic_param();
  11433. }
  11434. return result0;
  11435. }
  11436. function parse_Via() {
  11437. var result0, result1, result2, result3;
  11438. var pos0, pos1;
  11439. pos0 = pos;
  11440. result0 = parse_via_param();
  11441. if (result0 !== null) {
  11442. result1 = [];
  11443. pos1 = pos;
  11444. result2 = parse_COMMA();
  11445. if (result2 !== null) {
  11446. result3 = parse_via_param();
  11447. if (result3 !== null) {
  11448. result2 = [result2, result3];
  11449. } else {
  11450. result2 = null;
  11451. pos = pos1;
  11452. }
  11453. } else {
  11454. result2 = null;
  11455. pos = pos1;
  11456. }
  11457. while (result2 !== null) {
  11458. result1.push(result2);
  11459. pos1 = pos;
  11460. result2 = parse_COMMA();
  11461. if (result2 !== null) {
  11462. result3 = parse_via_param();
  11463. if (result3 !== null) {
  11464. result2 = [result2, result3];
  11465. } else {
  11466. result2 = null;
  11467. pos = pos1;
  11468. }
  11469. } else {
  11470. result2 = null;
  11471. pos = pos1;
  11472. }
  11473. }
  11474. if (result1 !== null) {
  11475. result0 = [result0, result1];
  11476. } else {
  11477. result0 = null;
  11478. pos = pos0;
  11479. }
  11480. } else {
  11481. result0 = null;
  11482. pos = pos0;
  11483. }
  11484. return result0;
  11485. }
  11486. function parse_via_param() {
  11487. var result0, result1, result2, result3, result4, result5;
  11488. var pos0, pos1;
  11489. pos0 = pos;
  11490. result0 = parse_sent_protocol();
  11491. if (result0 !== null) {
  11492. result1 = parse_LWS();
  11493. if (result1 !== null) {
  11494. result2 = parse_sent_by();
  11495. if (result2 !== null) {
  11496. result3 = [];
  11497. pos1 = pos;
  11498. result4 = parse_SEMI();
  11499. if (result4 !== null) {
  11500. result5 = parse_via_params();
  11501. if (result5 !== null) {
  11502. result4 = [result4, result5];
  11503. } else {
  11504. result4 = null;
  11505. pos = pos1;
  11506. }
  11507. } else {
  11508. result4 = null;
  11509. pos = pos1;
  11510. }
  11511. while (result4 !== null) {
  11512. result3.push(result4);
  11513. pos1 = pos;
  11514. result4 = parse_SEMI();
  11515. if (result4 !== null) {
  11516. result5 = parse_via_params();
  11517. if (result5 !== null) {
  11518. result4 = [result4, result5];
  11519. } else {
  11520. result4 = null;
  11521. pos = pos1;
  11522. }
  11523. } else {
  11524. result4 = null;
  11525. pos = pos1;
  11526. }
  11527. }
  11528. if (result3 !== null) {
  11529. result0 = [result0, result1, result2, result3];
  11530. } else {
  11531. result0 = null;
  11532. pos = pos0;
  11533. }
  11534. } else {
  11535. result0 = null;
  11536. pos = pos0;
  11537. }
  11538. } else {
  11539. result0 = null;
  11540. pos = pos0;
  11541. }
  11542. } else {
  11543. result0 = null;
  11544. pos = pos0;
  11545. }
  11546. return result0;
  11547. }
  11548. function parse_via_params() {
  11549. var result0;
  11550. result0 = parse_via_ttl();
  11551. if (result0 === null) {
  11552. result0 = parse_via_maddr();
  11553. if (result0 === null) {
  11554. result0 = parse_via_received();
  11555. if (result0 === null) {
  11556. result0 = parse_via_branch();
  11557. if (result0 === null) {
  11558. result0 = parse_response_port();
  11559. if (result0 === null) {
  11560. result0 = parse_generic_param();
  11561. }
  11562. }
  11563. }
  11564. }
  11565. }
  11566. return result0;
  11567. }
  11568. function parse_via_ttl() {
  11569. var result0, result1, result2;
  11570. var pos0, pos1;
  11571. pos0 = pos;
  11572. pos1 = pos;
  11573. if (input.substr(pos, 3).toLowerCase() === "ttl") {
  11574. result0 = input.substr(pos, 3);
  11575. pos += 3;
  11576. } else {
  11577. result0 = null;
  11578. if (reportFailures === 0) {
  11579. matchFailed("\"ttl\"");
  11580. }
  11581. }
  11582. if (result0 !== null) {
  11583. result1 = parse_EQUAL();
  11584. if (result1 !== null) {
  11585. result2 = parse_ttl();
  11586. if (result2 !== null) {
  11587. result0 = [result0, result1, result2];
  11588. } else {
  11589. result0 = null;
  11590. pos = pos1;
  11591. }
  11592. } else {
  11593. result0 = null;
  11594. pos = pos1;
  11595. }
  11596. } else {
  11597. result0 = null;
  11598. pos = pos1;
  11599. }
  11600. if (result0 !== null) {
  11601. result0 = (function(offset, via_ttl_value) {
  11602. data.ttl = via_ttl_value; })(pos0, result0[2]);
  11603. }
  11604. if (result0 === null) {
  11605. pos = pos0;
  11606. }
  11607. return result0;
  11608. }
  11609. function parse_via_maddr() {
  11610. var result0, result1, result2;
  11611. var pos0, pos1;
  11612. pos0 = pos;
  11613. pos1 = pos;
  11614. if (input.substr(pos, 5).toLowerCase() === "maddr") {
  11615. result0 = input.substr(pos, 5);
  11616. pos += 5;
  11617. } else {
  11618. result0 = null;
  11619. if (reportFailures === 0) {
  11620. matchFailed("\"maddr\"");
  11621. }
  11622. }
  11623. if (result0 !== null) {
  11624. result1 = parse_EQUAL();
  11625. if (result1 !== null) {
  11626. result2 = parse_host();
  11627. if (result2 !== null) {
  11628. result0 = [result0, result1, result2];
  11629. } else {
  11630. result0 = null;
  11631. pos = pos1;
  11632. }
  11633. } else {
  11634. result0 = null;
  11635. pos = pos1;
  11636. }
  11637. } else {
  11638. result0 = null;
  11639. pos = pos1;
  11640. }
  11641. if (result0 !== null) {
  11642. result0 = (function(offset, via_maddr) {
  11643. data.maddr = via_maddr; })(pos0, result0[2]);
  11644. }
  11645. if (result0 === null) {
  11646. pos = pos0;
  11647. }
  11648. return result0;
  11649. }
  11650. function parse_via_received() {
  11651. var result0, result1, result2;
  11652. var pos0, pos1;
  11653. pos0 = pos;
  11654. pos1 = pos;
  11655. if (input.substr(pos, 8).toLowerCase() === "received") {
  11656. result0 = input.substr(pos, 8);
  11657. pos += 8;
  11658. } else {
  11659. result0 = null;
  11660. if (reportFailures === 0) {
  11661. matchFailed("\"received\"");
  11662. }
  11663. }
  11664. if (result0 !== null) {
  11665. result1 = parse_EQUAL();
  11666. if (result1 !== null) {
  11667. result2 = parse_IPv4address();
  11668. if (result2 === null) {
  11669. result2 = parse_IPv6address();
  11670. }
  11671. if (result2 !== null) {
  11672. result0 = [result0, result1, result2];
  11673. } else {
  11674. result0 = null;
  11675. pos = pos1;
  11676. }
  11677. } else {
  11678. result0 = null;
  11679. pos = pos1;
  11680. }
  11681. } else {
  11682. result0 = null;
  11683. pos = pos1;
  11684. }
  11685. if (result0 !== null) {
  11686. result0 = (function(offset, via_received) {
  11687. data.received = via_received; })(pos0, result0[2]);
  11688. }
  11689. if (result0 === null) {
  11690. pos = pos0;
  11691. }
  11692. return result0;
  11693. }
  11694. function parse_via_branch() {
  11695. var result0, result1, result2;
  11696. var pos0, pos1;
  11697. pos0 = pos;
  11698. pos1 = pos;
  11699. if (input.substr(pos, 6).toLowerCase() === "branch") {
  11700. result0 = input.substr(pos, 6);
  11701. pos += 6;
  11702. } else {
  11703. result0 = null;
  11704. if (reportFailures === 0) {
  11705. matchFailed("\"branch\"");
  11706. }
  11707. }
  11708. if (result0 !== null) {
  11709. result1 = parse_EQUAL();
  11710. if (result1 !== null) {
  11711. result2 = parse_token();
  11712. if (result2 !== null) {
  11713. result0 = [result0, result1, result2];
  11714. } else {
  11715. result0 = null;
  11716. pos = pos1;
  11717. }
  11718. } else {
  11719. result0 = null;
  11720. pos = pos1;
  11721. }
  11722. } else {
  11723. result0 = null;
  11724. pos = pos1;
  11725. }
  11726. if (result0 !== null) {
  11727. result0 = (function(offset, via_branch) {
  11728. data.branch = via_branch; })(pos0, result0[2]);
  11729. }
  11730. if (result0 === null) {
  11731. pos = pos0;
  11732. }
  11733. return result0;
  11734. }
  11735. function parse_response_port() {
  11736. var result0, result1, result2, result3;
  11737. var pos0, pos1, pos2;
  11738. pos0 = pos;
  11739. pos1 = pos;
  11740. if (input.substr(pos, 5).toLowerCase() === "rport") {
  11741. result0 = input.substr(pos, 5);
  11742. pos += 5;
  11743. } else {
  11744. result0 = null;
  11745. if (reportFailures === 0) {
  11746. matchFailed("\"rport\"");
  11747. }
  11748. }
  11749. if (result0 !== null) {
  11750. pos2 = pos;
  11751. result1 = parse_EQUAL();
  11752. if (result1 !== null) {
  11753. result2 = [];
  11754. result3 = parse_DIGIT();
  11755. while (result3 !== null) {
  11756. result2.push(result3);
  11757. result3 = parse_DIGIT();
  11758. }
  11759. if (result2 !== null) {
  11760. result1 = [result1, result2];
  11761. } else {
  11762. result1 = null;
  11763. pos = pos2;
  11764. }
  11765. } else {
  11766. result1 = null;
  11767. pos = pos2;
  11768. }
  11769. result1 = result1 !== null ? result1 : "";
  11770. if (result1 !== null) {
  11771. result0 = [result0, result1];
  11772. } else {
  11773. result0 = null;
  11774. pos = pos1;
  11775. }
  11776. } else {
  11777. result0 = null;
  11778. pos = pos1;
  11779. }
  11780. if (result0 !== null) {
  11781. result0 = (function(offset) {
  11782. if(typeof response_port !== 'undefined')
  11783. data.rport = response_port.join(''); })(pos0);
  11784. }
  11785. if (result0 === null) {
  11786. pos = pos0;
  11787. }
  11788. return result0;
  11789. }
  11790. function parse_sent_protocol() {
  11791. var result0, result1, result2, result3, result4;
  11792. var pos0;
  11793. pos0 = pos;
  11794. result0 = parse_protocol_name();
  11795. if (result0 !== null) {
  11796. result1 = parse_SLASH();
  11797. if (result1 !== null) {
  11798. result2 = parse_token();
  11799. if (result2 !== null) {
  11800. result3 = parse_SLASH();
  11801. if (result3 !== null) {
  11802. result4 = parse_transport();
  11803. if (result4 !== null) {
  11804. result0 = [result0, result1, result2, result3, result4];
  11805. } else {
  11806. result0 = null;
  11807. pos = pos0;
  11808. }
  11809. } else {
  11810. result0 = null;
  11811. pos = pos0;
  11812. }
  11813. } else {
  11814. result0 = null;
  11815. pos = pos0;
  11816. }
  11817. } else {
  11818. result0 = null;
  11819. pos = pos0;
  11820. }
  11821. } else {
  11822. result0 = null;
  11823. pos = pos0;
  11824. }
  11825. return result0;
  11826. }
  11827. function parse_protocol_name() {
  11828. var result0;
  11829. var pos0;
  11830. pos0 = pos;
  11831. if (input.substr(pos, 3).toLowerCase() === "sip") {
  11832. result0 = input.substr(pos, 3);
  11833. pos += 3;
  11834. } else {
  11835. result0 = null;
  11836. if (reportFailures === 0) {
  11837. matchFailed("\"SIP\"");
  11838. }
  11839. }
  11840. if (result0 === null) {
  11841. result0 = parse_token();
  11842. }
  11843. if (result0 !== null) {
  11844. result0 = (function(offset, via_protocol) {
  11845. data.protocol = via_protocol; })(pos0, result0);
  11846. }
  11847. if (result0 === null) {
  11848. pos = pos0;
  11849. }
  11850. return result0;
  11851. }
  11852. function parse_transport() {
  11853. var result0;
  11854. var pos0;
  11855. pos0 = pos;
  11856. if (input.substr(pos, 3).toLowerCase() === "udp") {
  11857. result0 = input.substr(pos, 3);
  11858. pos += 3;
  11859. } else {
  11860. result0 = null;
  11861. if (reportFailures === 0) {
  11862. matchFailed("\"UDP\"");
  11863. }
  11864. }
  11865. if (result0 === null) {
  11866. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  11867. result0 = input.substr(pos, 3);
  11868. pos += 3;
  11869. } else {
  11870. result0 = null;
  11871. if (reportFailures === 0) {
  11872. matchFailed("\"TCP\"");
  11873. }
  11874. }
  11875. if (result0 === null) {
  11876. if (input.substr(pos, 3).toLowerCase() === "tls") {
  11877. result0 = input.substr(pos, 3);
  11878. pos += 3;
  11879. } else {
  11880. result0 = null;
  11881. if (reportFailures === 0) {
  11882. matchFailed("\"TLS\"");
  11883. }
  11884. }
  11885. if (result0 === null) {
  11886. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  11887. result0 = input.substr(pos, 4);
  11888. pos += 4;
  11889. } else {
  11890. result0 = null;
  11891. if (reportFailures === 0) {
  11892. matchFailed("\"SCTP\"");
  11893. }
  11894. }
  11895. if (result0 === null) {
  11896. result0 = parse_token();
  11897. }
  11898. }
  11899. }
  11900. }
  11901. if (result0 !== null) {
  11902. result0 = (function(offset, via_transport) {
  11903. data.transport = via_transport; })(pos0, result0);
  11904. }
  11905. if (result0 === null) {
  11906. pos = pos0;
  11907. }
  11908. return result0;
  11909. }
  11910. function parse_sent_by() {
  11911. var result0, result1, result2;
  11912. var pos0, pos1;
  11913. pos0 = pos;
  11914. result0 = parse_via_host();
  11915. if (result0 !== null) {
  11916. pos1 = pos;
  11917. result1 = parse_COLON();
  11918. if (result1 !== null) {
  11919. result2 = parse_via_port();
  11920. if (result2 !== null) {
  11921. result1 = [result1, result2];
  11922. } else {
  11923. result1 = null;
  11924. pos = pos1;
  11925. }
  11926. } else {
  11927. result1 = null;
  11928. pos = pos1;
  11929. }
  11930. result1 = result1 !== null ? result1 : "";
  11931. if (result1 !== null) {
  11932. result0 = [result0, result1];
  11933. } else {
  11934. result0 = null;
  11935. pos = pos0;
  11936. }
  11937. } else {
  11938. result0 = null;
  11939. pos = pos0;
  11940. }
  11941. return result0;
  11942. }
  11943. function parse_via_host() {
  11944. var result0;
  11945. var pos0;
  11946. pos0 = pos;
  11947. result0 = parse_IPv4address();
  11948. if (result0 === null) {
  11949. result0 = parse_IPv6reference();
  11950. if (result0 === null) {
  11951. result0 = parse_hostname();
  11952. }
  11953. }
  11954. if (result0 !== null) {
  11955. result0 = (function(offset) {
  11956. data.host = input.substring(pos, offset); })(pos0);
  11957. }
  11958. if (result0 === null) {
  11959. pos = pos0;
  11960. }
  11961. return result0;
  11962. }
  11963. function parse_via_port() {
  11964. var result0, result1, result2, result3, result4;
  11965. var pos0, pos1;
  11966. pos0 = pos;
  11967. pos1 = pos;
  11968. result0 = parse_DIGIT();
  11969. result0 = result0 !== null ? result0 : "";
  11970. if (result0 !== null) {
  11971. result1 = parse_DIGIT();
  11972. result1 = result1 !== null ? result1 : "";
  11973. if (result1 !== null) {
  11974. result2 = parse_DIGIT();
  11975. result2 = result2 !== null ? result2 : "";
  11976. if (result2 !== null) {
  11977. result3 = parse_DIGIT();
  11978. result3 = result3 !== null ? result3 : "";
  11979. if (result3 !== null) {
  11980. result4 = parse_DIGIT();
  11981. result4 = result4 !== null ? result4 : "";
  11982. if (result4 !== null) {
  11983. result0 = [result0, result1, result2, result3, result4];
  11984. } else {
  11985. result0 = null;
  11986. pos = pos1;
  11987. }
  11988. } else {
  11989. result0 = null;
  11990. pos = pos1;
  11991. }
  11992. } else {
  11993. result0 = null;
  11994. pos = pos1;
  11995. }
  11996. } else {
  11997. result0 = null;
  11998. pos = pos1;
  11999. }
  12000. } else {
  12001. result0 = null;
  12002. pos = pos1;
  12003. }
  12004. if (result0 !== null) {
  12005. result0 = (function(offset, via_sent_by_port) {
  12006. data.port = parseInt(via_sent_by_port.join('')); })(pos0, result0);
  12007. }
  12008. if (result0 === null) {
  12009. pos = pos0;
  12010. }
  12011. return result0;
  12012. }
  12013. function parse_ttl() {
  12014. var result0, result1, result2;
  12015. var pos0, pos1;
  12016. pos0 = pos;
  12017. pos1 = pos;
  12018. result0 = parse_DIGIT();
  12019. if (result0 !== null) {
  12020. result1 = parse_DIGIT();
  12021. result1 = result1 !== null ? result1 : "";
  12022. if (result1 !== null) {
  12023. result2 = parse_DIGIT();
  12024. result2 = result2 !== null ? result2 : "";
  12025. if (result2 !== null) {
  12026. result0 = [result0, result1, result2];
  12027. } else {
  12028. result0 = null;
  12029. pos = pos1;
  12030. }
  12031. } else {
  12032. result0 = null;
  12033. pos = pos1;
  12034. }
  12035. } else {
  12036. result0 = null;
  12037. pos = pos1;
  12038. }
  12039. if (result0 !== null) {
  12040. result0 = (function(offset, ttl) {
  12041. return parseInt(ttl.join('')); })(pos0, result0);
  12042. }
  12043. if (result0 === null) {
  12044. pos = pos0;
  12045. }
  12046. return result0;
  12047. }
  12048. function parse_WWW_Authenticate() {
  12049. var result0;
  12050. result0 = parse_challenge();
  12051. return result0;
  12052. }
  12053. function parse_Session_Expires() {
  12054. var result0, result1, result2, result3;
  12055. var pos0, pos1;
  12056. pos0 = pos;
  12057. result0 = parse_s_e_expires();
  12058. if (result0 !== null) {
  12059. result1 = [];
  12060. pos1 = pos;
  12061. result2 = parse_SEMI();
  12062. if (result2 !== null) {
  12063. result3 = parse_s_e_params();
  12064. if (result3 !== null) {
  12065. result2 = [result2, result3];
  12066. } else {
  12067. result2 = null;
  12068. pos = pos1;
  12069. }
  12070. } else {
  12071. result2 = null;
  12072. pos = pos1;
  12073. }
  12074. while (result2 !== null) {
  12075. result1.push(result2);
  12076. pos1 = pos;
  12077. result2 = parse_SEMI();
  12078. if (result2 !== null) {
  12079. result3 = parse_s_e_params();
  12080. if (result3 !== null) {
  12081. result2 = [result2, result3];
  12082. } else {
  12083. result2 = null;
  12084. pos = pos1;
  12085. }
  12086. } else {
  12087. result2 = null;
  12088. pos = pos1;
  12089. }
  12090. }
  12091. if (result1 !== null) {
  12092. result0 = [result0, result1];
  12093. } else {
  12094. result0 = null;
  12095. pos = pos0;
  12096. }
  12097. } else {
  12098. result0 = null;
  12099. pos = pos0;
  12100. }
  12101. return result0;
  12102. }
  12103. function parse_s_e_expires() {
  12104. var result0;
  12105. var pos0;
  12106. pos0 = pos;
  12107. result0 = parse_delta_seconds();
  12108. if (result0 !== null) {
  12109. result0 = (function(offset, expires) { data.expires = expires; })(pos0, result0);
  12110. }
  12111. if (result0 === null) {
  12112. pos = pos0;
  12113. }
  12114. return result0;
  12115. }
  12116. function parse_s_e_params() {
  12117. var result0;
  12118. result0 = parse_s_e_refresher();
  12119. if (result0 === null) {
  12120. result0 = parse_generic_param();
  12121. }
  12122. return result0;
  12123. }
  12124. function parse_s_e_refresher() {
  12125. var result0, result1, result2;
  12126. var pos0, pos1;
  12127. pos0 = pos;
  12128. pos1 = pos;
  12129. if (input.substr(pos, 9).toLowerCase() === "refresher") {
  12130. result0 = input.substr(pos, 9);
  12131. pos += 9;
  12132. } else {
  12133. result0 = null;
  12134. if (reportFailures === 0) {
  12135. matchFailed("\"refresher\"");
  12136. }
  12137. }
  12138. if (result0 !== null) {
  12139. result1 = parse_EQUAL();
  12140. if (result1 !== null) {
  12141. if (input.substr(pos, 3).toLowerCase() === "uac") {
  12142. result2 = input.substr(pos, 3);
  12143. pos += 3;
  12144. } else {
  12145. result2 = null;
  12146. if (reportFailures === 0) {
  12147. matchFailed("\"uac\"");
  12148. }
  12149. }
  12150. if (result2 === null) {
  12151. if (input.substr(pos, 3).toLowerCase() === "uas") {
  12152. result2 = input.substr(pos, 3);
  12153. pos += 3;
  12154. } else {
  12155. result2 = null;
  12156. if (reportFailures === 0) {
  12157. matchFailed("\"uas\"");
  12158. }
  12159. }
  12160. }
  12161. if (result2 !== null) {
  12162. result0 = [result0, result1, result2];
  12163. } else {
  12164. result0 = null;
  12165. pos = pos1;
  12166. }
  12167. } else {
  12168. result0 = null;
  12169. pos = pos1;
  12170. }
  12171. } else {
  12172. result0 = null;
  12173. pos = pos1;
  12174. }
  12175. if (result0 !== null) {
  12176. result0 = (function(offset, s_e_refresher_value) { data.refresher = s_e_refresher_value.toLowerCase(); })(pos0, result0[2]);
  12177. }
  12178. if (result0 === null) {
  12179. pos = pos0;
  12180. }
  12181. return result0;
  12182. }
  12183. function parse_extension_header() {
  12184. var result0, result1, result2;
  12185. var pos0;
  12186. pos0 = pos;
  12187. result0 = parse_token();
  12188. if (result0 !== null) {
  12189. result1 = parse_HCOLON();
  12190. if (result1 !== null) {
  12191. result2 = parse_header_value();
  12192. if (result2 !== null) {
  12193. result0 = [result0, result1, result2];
  12194. } else {
  12195. result0 = null;
  12196. pos = pos0;
  12197. }
  12198. } else {
  12199. result0 = null;
  12200. pos = pos0;
  12201. }
  12202. } else {
  12203. result0 = null;
  12204. pos = pos0;
  12205. }
  12206. return result0;
  12207. }
  12208. function parse_header_value() {
  12209. var result0, result1;
  12210. result0 = [];
  12211. result1 = parse_TEXT_UTF8char();
  12212. if (result1 === null) {
  12213. result1 = parse_UTF8_CONT();
  12214. if (result1 === null) {
  12215. result1 = parse_LWS();
  12216. }
  12217. }
  12218. while (result1 !== null) {
  12219. result0.push(result1);
  12220. result1 = parse_TEXT_UTF8char();
  12221. if (result1 === null) {
  12222. result1 = parse_UTF8_CONT();
  12223. if (result1 === null) {
  12224. result1 = parse_LWS();
  12225. }
  12226. }
  12227. }
  12228. return result0;
  12229. }
  12230. function parse_message_body() {
  12231. var result0, result1;
  12232. result0 = [];
  12233. result1 = parse_OCTET();
  12234. while (result1 !== null) {
  12235. result0.push(result1);
  12236. result1 = parse_OCTET();
  12237. }
  12238. return result0;
  12239. }
  12240. function parse_uuid_URI() {
  12241. var result0, result1;
  12242. var pos0;
  12243. pos0 = pos;
  12244. if (input.substr(pos, 5) === "uuid:") {
  12245. result0 = "uuid:";
  12246. pos += 5;
  12247. } else {
  12248. result0 = null;
  12249. if (reportFailures === 0) {
  12250. matchFailed("\"uuid:\"");
  12251. }
  12252. }
  12253. if (result0 !== null) {
  12254. result1 = parse_uuid();
  12255. if (result1 !== null) {
  12256. result0 = [result0, result1];
  12257. } else {
  12258. result0 = null;
  12259. pos = pos0;
  12260. }
  12261. } else {
  12262. result0 = null;
  12263. pos = pos0;
  12264. }
  12265. return result0;
  12266. }
  12267. function parse_uuid() {
  12268. var result0, result1, result2, result3, result4, result5, result6, result7, result8;
  12269. var pos0, pos1;
  12270. pos0 = pos;
  12271. pos1 = pos;
  12272. result0 = parse_hex8();
  12273. if (result0 !== null) {
  12274. if (input.charCodeAt(pos) === 45) {
  12275. result1 = "-";
  12276. pos++;
  12277. } else {
  12278. result1 = null;
  12279. if (reportFailures === 0) {
  12280. matchFailed("\"-\"");
  12281. }
  12282. }
  12283. if (result1 !== null) {
  12284. result2 = parse_hex4();
  12285. if (result2 !== null) {
  12286. if (input.charCodeAt(pos) === 45) {
  12287. result3 = "-";
  12288. pos++;
  12289. } else {
  12290. result3 = null;
  12291. if (reportFailures === 0) {
  12292. matchFailed("\"-\"");
  12293. }
  12294. }
  12295. if (result3 !== null) {
  12296. result4 = parse_hex4();
  12297. if (result4 !== null) {
  12298. if (input.charCodeAt(pos) === 45) {
  12299. result5 = "-";
  12300. pos++;
  12301. } else {
  12302. result5 = null;
  12303. if (reportFailures === 0) {
  12304. matchFailed("\"-\"");
  12305. }
  12306. }
  12307. if (result5 !== null) {
  12308. result6 = parse_hex4();
  12309. if (result6 !== null) {
  12310. if (input.charCodeAt(pos) === 45) {
  12311. result7 = "-";
  12312. pos++;
  12313. } else {
  12314. result7 = null;
  12315. if (reportFailures === 0) {
  12316. matchFailed("\"-\"");
  12317. }
  12318. }
  12319. if (result7 !== null) {
  12320. result8 = parse_hex12();
  12321. if (result8 !== null) {
  12322. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  12323. } else {
  12324. result0 = null;
  12325. pos = pos1;
  12326. }
  12327. } else {
  12328. result0 = null;
  12329. pos = pos1;
  12330. }
  12331. } else {
  12332. result0 = null;
  12333. pos = pos1;
  12334. }
  12335. } else {
  12336. result0 = null;
  12337. pos = pos1;
  12338. }
  12339. } else {
  12340. result0 = null;
  12341. pos = pos1;
  12342. }
  12343. } else {
  12344. result0 = null;
  12345. pos = pos1;
  12346. }
  12347. } else {
  12348. result0 = null;
  12349. pos = pos1;
  12350. }
  12351. } else {
  12352. result0 = null;
  12353. pos = pos1;
  12354. }
  12355. } else {
  12356. result0 = null;
  12357. pos = pos1;
  12358. }
  12359. if (result0 !== null) {
  12360. result0 = (function(offset, uuid) {
  12361. data = input.substring(pos+5, offset); })(pos0, result0[0]);
  12362. }
  12363. if (result0 === null) {
  12364. pos = pos0;
  12365. }
  12366. return result0;
  12367. }
  12368. function parse_hex4() {
  12369. var result0, result1, result2, result3;
  12370. var pos0;
  12371. pos0 = pos;
  12372. result0 = parse_HEXDIG();
  12373. if (result0 !== null) {
  12374. result1 = parse_HEXDIG();
  12375. if (result1 !== null) {
  12376. result2 = parse_HEXDIG();
  12377. if (result2 !== null) {
  12378. result3 = parse_HEXDIG();
  12379. if (result3 !== null) {
  12380. result0 = [result0, result1, result2, result3];
  12381. } else {
  12382. result0 = null;
  12383. pos = pos0;
  12384. }
  12385. } else {
  12386. result0 = null;
  12387. pos = pos0;
  12388. }
  12389. } else {
  12390. result0 = null;
  12391. pos = pos0;
  12392. }
  12393. } else {
  12394. result0 = null;
  12395. pos = pos0;
  12396. }
  12397. return result0;
  12398. }
  12399. function parse_hex8() {
  12400. var result0, result1;
  12401. var pos0;
  12402. pos0 = pos;
  12403. result0 = parse_hex4();
  12404. if (result0 !== null) {
  12405. result1 = parse_hex4();
  12406. if (result1 !== null) {
  12407. result0 = [result0, result1];
  12408. } else {
  12409. result0 = null;
  12410. pos = pos0;
  12411. }
  12412. } else {
  12413. result0 = null;
  12414. pos = pos0;
  12415. }
  12416. return result0;
  12417. }
  12418. function parse_hex12() {
  12419. var result0, result1, result2;
  12420. var pos0;
  12421. pos0 = pos;
  12422. result0 = parse_hex4();
  12423. if (result0 !== null) {
  12424. result1 = parse_hex4();
  12425. if (result1 !== null) {
  12426. result2 = parse_hex4();
  12427. if (result2 !== null) {
  12428. result0 = [result0, result1, result2];
  12429. } else {
  12430. result0 = null;
  12431. pos = pos0;
  12432. }
  12433. } else {
  12434. result0 = null;
  12435. pos = pos0;
  12436. }
  12437. } else {
  12438. result0 = null;
  12439. pos = pos0;
  12440. }
  12441. return result0;
  12442. }
  12443. function parse_Refer_To() {
  12444. var result0, result1, result2, result3;
  12445. var pos0, pos1, pos2;
  12446. pos0 = pos;
  12447. pos1 = pos;
  12448. result0 = parse_SIP_URI_noparams();
  12449. if (result0 === null) {
  12450. result0 = parse_name_addr();
  12451. }
  12452. if (result0 !== null) {
  12453. result1 = [];
  12454. pos2 = pos;
  12455. result2 = parse_SEMI();
  12456. if (result2 !== null) {
  12457. result3 = parse_generic_param();
  12458. if (result3 !== null) {
  12459. result2 = [result2, result3];
  12460. } else {
  12461. result2 = null;
  12462. pos = pos2;
  12463. }
  12464. } else {
  12465. result2 = null;
  12466. pos = pos2;
  12467. }
  12468. while (result2 !== null) {
  12469. result1.push(result2);
  12470. pos2 = pos;
  12471. result2 = parse_SEMI();
  12472. if (result2 !== null) {
  12473. result3 = parse_generic_param();
  12474. if (result3 !== null) {
  12475. result2 = [result2, result3];
  12476. } else {
  12477. result2 = null;
  12478. pos = pos2;
  12479. }
  12480. } else {
  12481. result2 = null;
  12482. pos = pos2;
  12483. }
  12484. }
  12485. if (result1 !== null) {
  12486. result0 = [result0, result1];
  12487. } else {
  12488. result0 = null;
  12489. pos = pos1;
  12490. }
  12491. } else {
  12492. result0 = null;
  12493. pos = pos1;
  12494. }
  12495. if (result0 !== null) {
  12496. result0 = (function(offset) {
  12497. try {
  12498. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  12499. } catch(e) {
  12500. data = -1;
  12501. }})(pos0);
  12502. }
  12503. if (result0 === null) {
  12504. pos = pos0;
  12505. }
  12506. return result0;
  12507. }
  12508. function parse_Replaces() {
  12509. var result0, result1, result2, result3;
  12510. var pos0, pos1;
  12511. pos0 = pos;
  12512. result0 = parse_call_id();
  12513. if (result0 !== null) {
  12514. result1 = [];
  12515. pos1 = pos;
  12516. result2 = parse_SEMI();
  12517. if (result2 !== null) {
  12518. result3 = parse_replaces_param();
  12519. if (result3 !== null) {
  12520. result2 = [result2, result3];
  12521. } else {
  12522. result2 = null;
  12523. pos = pos1;
  12524. }
  12525. } else {
  12526. result2 = null;
  12527. pos = pos1;
  12528. }
  12529. while (result2 !== null) {
  12530. result1.push(result2);
  12531. pos1 = pos;
  12532. result2 = parse_SEMI();
  12533. if (result2 !== null) {
  12534. result3 = parse_replaces_param();
  12535. if (result3 !== null) {
  12536. result2 = [result2, result3];
  12537. } else {
  12538. result2 = null;
  12539. pos = pos1;
  12540. }
  12541. } else {
  12542. result2 = null;
  12543. pos = pos1;
  12544. }
  12545. }
  12546. if (result1 !== null) {
  12547. result0 = [result0, result1];
  12548. } else {
  12549. result0 = null;
  12550. pos = pos0;
  12551. }
  12552. } else {
  12553. result0 = null;
  12554. pos = pos0;
  12555. }
  12556. return result0;
  12557. }
  12558. function parse_call_id() {
  12559. var result0, result1, result2;
  12560. var pos0, pos1, pos2;
  12561. pos0 = pos;
  12562. pos1 = pos;
  12563. result0 = parse_word();
  12564. if (result0 !== null) {
  12565. pos2 = pos;
  12566. if (input.charCodeAt(pos) === 64) {
  12567. result1 = "@";
  12568. pos++;
  12569. } else {
  12570. result1 = null;
  12571. if (reportFailures === 0) {
  12572. matchFailed("\"@\"");
  12573. }
  12574. }
  12575. if (result1 !== null) {
  12576. result2 = parse_word();
  12577. if (result2 !== null) {
  12578. result1 = [result1, result2];
  12579. } else {
  12580. result1 = null;
  12581. pos = pos2;
  12582. }
  12583. } else {
  12584. result1 = null;
  12585. pos = pos2;
  12586. }
  12587. result1 = result1 !== null ? result1 : "";
  12588. if (result1 !== null) {
  12589. result0 = [result0, result1];
  12590. } else {
  12591. result0 = null;
  12592. pos = pos1;
  12593. }
  12594. } else {
  12595. result0 = null;
  12596. pos = pos1;
  12597. }
  12598. if (result0 !== null) {
  12599. result0 = (function(offset) {
  12600. data.call_id = input.substring(pos, offset); })(pos0);
  12601. }
  12602. if (result0 === null) {
  12603. pos = pos0;
  12604. }
  12605. return result0;
  12606. }
  12607. function parse_replaces_param() {
  12608. var result0;
  12609. result0 = parse_to_tag();
  12610. if (result0 === null) {
  12611. result0 = parse_from_tag();
  12612. if (result0 === null) {
  12613. result0 = parse_early_flag();
  12614. if (result0 === null) {
  12615. result0 = parse_generic_param();
  12616. }
  12617. }
  12618. }
  12619. return result0;
  12620. }
  12621. function parse_to_tag() {
  12622. var result0, result1, result2;
  12623. var pos0, pos1;
  12624. pos0 = pos;
  12625. pos1 = pos;
  12626. if (input.substr(pos, 6) === "to-tag") {
  12627. result0 = "to-tag";
  12628. pos += 6;
  12629. } else {
  12630. result0 = null;
  12631. if (reportFailures === 0) {
  12632. matchFailed("\"to-tag\"");
  12633. }
  12634. }
  12635. if (result0 !== null) {
  12636. result1 = parse_EQUAL();
  12637. if (result1 !== null) {
  12638. result2 = parse_token();
  12639. if (result2 !== null) {
  12640. result0 = [result0, result1, result2];
  12641. } else {
  12642. result0 = null;
  12643. pos = pos1;
  12644. }
  12645. } else {
  12646. result0 = null;
  12647. pos = pos1;
  12648. }
  12649. } else {
  12650. result0 = null;
  12651. pos = pos1;
  12652. }
  12653. if (result0 !== null) {
  12654. result0 = (function(offset, to_tag) {
  12655. data.to_tag = to_tag; })(pos0, result0[2]);
  12656. }
  12657. if (result0 === null) {
  12658. pos = pos0;
  12659. }
  12660. return result0;
  12661. }
  12662. function parse_from_tag() {
  12663. var result0, result1, result2;
  12664. var pos0, pos1;
  12665. pos0 = pos;
  12666. pos1 = pos;
  12667. if (input.substr(pos, 8) === "from-tag") {
  12668. result0 = "from-tag";
  12669. pos += 8;
  12670. } else {
  12671. result0 = null;
  12672. if (reportFailures === 0) {
  12673. matchFailed("\"from-tag\"");
  12674. }
  12675. }
  12676. if (result0 !== null) {
  12677. result1 = parse_EQUAL();
  12678. if (result1 !== null) {
  12679. result2 = parse_token();
  12680. if (result2 !== null) {
  12681. result0 = [result0, result1, result2];
  12682. } else {
  12683. result0 = null;
  12684. pos = pos1;
  12685. }
  12686. } else {
  12687. result0 = null;
  12688. pos = pos1;
  12689. }
  12690. } else {
  12691. result0 = null;
  12692. pos = pos1;
  12693. }
  12694. if (result0 !== null) {
  12695. result0 = (function(offset, from_tag) {
  12696. data.from_tag = from_tag; })(pos0, result0[2]);
  12697. }
  12698. if (result0 === null) {
  12699. pos = pos0;
  12700. }
  12701. return result0;
  12702. }
  12703. function parse_early_flag() {
  12704. var result0;
  12705. var pos0;
  12706. pos0 = pos;
  12707. if (input.substr(pos, 10) === "early-only") {
  12708. result0 = "early-only";
  12709. pos += 10;
  12710. } else {
  12711. result0 = null;
  12712. if (reportFailures === 0) {
  12713. matchFailed("\"early-only\"");
  12714. }
  12715. }
  12716. if (result0 !== null) {
  12717. result0 = (function(offset) {
  12718. data.early_only = true; })(pos0);
  12719. }
  12720. if (result0 === null) {
  12721. pos = pos0;
  12722. }
  12723. return result0;
  12724. }
  12725. function cleanupExpected(expected) {
  12726. expected.sort();
  12727. var lastExpected = null;
  12728. var cleanExpected = [];
  12729. for (var i = 0; i < expected.length; i++) {
  12730. if (expected[i] !== lastExpected) {
  12731. cleanExpected.push(expected[i]);
  12732. lastExpected = expected[i];
  12733. }
  12734. }
  12735. return cleanExpected;
  12736. }
  12737. function computeErrorPosition() {
  12738. /*
  12739. * The first idea was to use |String.split| to break the input up to the
  12740. * error position along newlines and derive the line and column from
  12741. * there. However IE's |split| implementation is so broken that it was
  12742. * enough to prevent it.
  12743. */
  12744. var line = 1;
  12745. var column = 1;
  12746. var seenCR = false;
  12747. for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
  12748. var ch = input.charAt(i);
  12749. if (ch === "\n") {
  12750. if (!seenCR) { line++; }
  12751. column = 1;
  12752. seenCR = false;
  12753. } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
  12754. line++;
  12755. column = 1;
  12756. seenCR = true;
  12757. } else {
  12758. column++;
  12759. seenCR = false;
  12760. }
  12761. }
  12762. return { line: line, column: column };
  12763. }
  12764. var URI = require('./URI');
  12765. var NameAddrHeader = require('./NameAddrHeader');
  12766. var data = {};
  12767. var result = parseFunctions[startRule]();
  12768. /*
  12769. * The parser is now in one of the following three states:
  12770. *
  12771. * 1. The parser successfully parsed the whole input.
  12772. *
  12773. * - |result !== null|
  12774. * - |pos === input.length|
  12775. * - |rightmostFailuresExpected| may or may not contain something
  12776. *
  12777. * 2. The parser successfully parsed only a part of the input.
  12778. *
  12779. * - |result !== null|
  12780. * - |pos < input.length|
  12781. * - |rightmostFailuresExpected| may or may not contain something
  12782. *
  12783. * 3. The parser did not successfully parse any part of the input.
  12784. *
  12785. * - |result === null|
  12786. * - |pos === 0|
  12787. * - |rightmostFailuresExpected| contains at least one failure
  12788. *
  12789. * All code following this comment (including called functions) must
  12790. * handle these states.
  12791. */
  12792. if (result === null || pos !== input.length) {
  12793. var offset = Math.max(pos, rightmostFailuresPos);
  12794. var found = offset < input.length ? input.charAt(offset) : null;
  12795. var errorPosition = computeErrorPosition();
  12796. new this.SyntaxError(
  12797. cleanupExpected(rightmostFailuresExpected),
  12798. found,
  12799. offset,
  12800. errorPosition.line,
  12801. errorPosition.column
  12802. );
  12803. return -1;
  12804. }
  12805. return data;
  12806. },
  12807. /* Returns the parser source code. */
  12808. toSource: function() { return this._source; }
  12809. };
  12810. /* Thrown when a parser encounters a syntax error. */
  12811. result.SyntaxError = function(expected, found, offset, line, column) {
  12812. function buildMessage(expected, found) {
  12813. var expectedHumanized, foundHumanized;
  12814. switch (expected.length) {
  12815. case 0:
  12816. expectedHumanized = "end of input";
  12817. break;
  12818. case 1:
  12819. expectedHumanized = expected[0];
  12820. break;
  12821. default:
  12822. expectedHumanized = expected.slice(0, expected.length - 1).join(", ")
  12823. + " or "
  12824. + expected[expected.length - 1];
  12825. }
  12826. foundHumanized = found ? quote(found) : "end of input";
  12827. return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
  12828. }
  12829. this.name = "SyntaxError";
  12830. this.expected = expected;
  12831. this.found = found;
  12832. this.message = buildMessage(expected, found);
  12833. this.offset = offset;
  12834. this.line = line;
  12835. this.column = column;
  12836. };
  12837. result.SyntaxError.prototype = Error.prototype;
  12838. return result;
  12839. })();
  12840. },{"./NameAddrHeader":9,"./URI":25}],7:[function(require,module,exports){
  12841. /**
  12842. * Dependencies.
  12843. */
  12844. var debug = require('debug')('JsSIP');
  12845. var adapter = require('webrtc-adapter');
  12846. var pkg = require('../package.json');
  12847. debug('version %s', pkg.version);
  12848. var C = require('./Constants');
  12849. var Exceptions = require('./Exceptions');
  12850. var Utils = require('./Utils');
  12851. var UA = require('./UA');
  12852. var URI = require('./URI');
  12853. var NameAddrHeader = require('./NameAddrHeader');
  12854. var Grammar = require('./Grammar');
  12855. var WebSocketInterface = require('./WebSocketInterface');
  12856. /**
  12857. * Expose the JsSIP module.
  12858. */
  12859. var JsSIP = module.exports = {
  12860. C: C,
  12861. Exceptions: Exceptions,
  12862. Utils: Utils,
  12863. UA: UA,
  12864. URI: URI,
  12865. NameAddrHeader: NameAddrHeader,
  12866. WebSocketInterface: WebSocketInterface,
  12867. Grammar: Grammar,
  12868. // Expose the debug module.
  12869. debug: require('debug'),
  12870. // Expose the adapter module.
  12871. adapter: adapter
  12872. };
  12873. Object.defineProperties(JsSIP, {
  12874. name: {
  12875. get: function() { return pkg.title; }
  12876. },
  12877. version: {
  12878. get: function() { return pkg.version; }
  12879. }
  12880. });
  12881. },{"../package.json":51,"./Constants":1,"./Exceptions":5,"./Grammar":6,"./NameAddrHeader":9,"./UA":24,"./URI":25,"./Utils":26,"./WebSocketInterface":27,"debug":35,"webrtc-adapter":42}],8:[function(require,module,exports){
  12882. module.exports = Message;
  12883. /**
  12884. * Dependencies.
  12885. */
  12886. var util = require('util');
  12887. var events = require('events');
  12888. var JsSIP_C = require('./Constants');
  12889. var SIPMessage = require('./SIPMessage');
  12890. var Utils = require('./Utils');
  12891. var RequestSender = require('./RequestSender');
  12892. var Transactions = require('./Transactions');
  12893. var Exceptions = require('./Exceptions');
  12894. function Message(ua) {
  12895. this.ua = ua;
  12896. // Custom message empty object for high level use
  12897. this.data = {};
  12898. events.EventEmitter.call(this);
  12899. }
  12900. util.inherits(Message, events.EventEmitter);
  12901. Message.prototype.send = function(target, body, options) {
  12902. var request_sender, event, contentType, eventHandlers, extraHeaders,
  12903. originalTarget = target;
  12904. if (target === undefined || body === undefined) {
  12905. throw new TypeError('Not enough arguments');
  12906. }
  12907. // Check target validity
  12908. target = this.ua.normalizeTarget(target);
  12909. if (!target) {
  12910. throw new TypeError('Invalid target: '+ originalTarget);
  12911. }
  12912. // Get call options
  12913. options = options || {};
  12914. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [];
  12915. eventHandlers = options.eventHandlers || {};
  12916. contentType = options.contentType || 'text/plain';
  12917. this.content_type = contentType;
  12918. // Set event handlers
  12919. for (event in eventHandlers) {
  12920. this.on(event, eventHandlers[event]);
  12921. }
  12922. this.closed = false;
  12923. this.ua.applicants[this] = this;
  12924. extraHeaders.push('Content-Type: '+ contentType);
  12925. this.request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this.ua, null, extraHeaders);
  12926. if(body) {
  12927. this.request.body = body;
  12928. this.content = body;
  12929. } else {
  12930. this.content = null;
  12931. }
  12932. request_sender = new RequestSender(this, this.ua);
  12933. this.newMessage('local', this.request);
  12934. request_sender.send();
  12935. };
  12936. Message.prototype.receiveResponse = function(response) {
  12937. var cause;
  12938. if(this.closed) {
  12939. return;
  12940. }
  12941. switch(true) {
  12942. case /^1[0-9]{2}$/.test(response.status_code):
  12943. // Ignore provisional responses.
  12944. break;
  12945. case /^2[0-9]{2}$/.test(response.status_code):
  12946. delete this.ua.applicants[this];
  12947. this.emit('succeeded', {
  12948. originator: 'remote',
  12949. response: response
  12950. });
  12951. break;
  12952. default:
  12953. delete this.ua.applicants[this];
  12954. cause = Utils.sipErrorCause(response.status_code);
  12955. this.emit('failed', {
  12956. originator: 'remote',
  12957. response: response,
  12958. cause: cause
  12959. });
  12960. break;
  12961. }
  12962. };
  12963. Message.prototype.onRequestTimeout = function() {
  12964. if(this.closed) {
  12965. return;
  12966. }
  12967. this.emit('failed', {
  12968. originator: 'system',
  12969. cause: JsSIP_C.causes.REQUEST_TIMEOUT
  12970. });
  12971. };
  12972. Message.prototype.onTransportError = function() {
  12973. if(this.closed) {
  12974. return;
  12975. }
  12976. this.emit('failed', {
  12977. originator: 'system',
  12978. cause: JsSIP_C.causes.CONNECTION_ERROR
  12979. });
  12980. };
  12981. Message.prototype.close = function() {
  12982. this.closed = true;
  12983. delete this.ua.applicants[this];
  12984. };
  12985. Message.prototype.init_incoming = function(request) {
  12986. var transaction;
  12987. this.request = request;
  12988. this.content_type = request.getHeader('Content-Type');
  12989. if (request.body) {
  12990. this.content = request.body;
  12991. } else {
  12992. this.content = null;
  12993. }
  12994. this.newMessage('remote', request);
  12995. transaction = this.ua.transactions.nist[request.via_branch];
  12996. if (transaction && (transaction.state === Transactions.C.STATUS_TRYING || transaction.state === Transactions.C.STATUS_PROCEEDING)) {
  12997. request.reply(200);
  12998. }
  12999. };
  13000. /**
  13001. * Accept the incoming Message
  13002. * Only valid for incoming Messages
  13003. */
  13004. Message.prototype.accept = function(options) {
  13005. options = options || {};
  13006. var
  13007. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
  13008. body = options.body;
  13009. if (this.direction !== 'incoming') {
  13010. throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message');
  13011. }
  13012. this.request.reply(200, null, extraHeaders, body);
  13013. };
  13014. /**
  13015. * Reject the incoming Message
  13016. * Only valid for incoming Messages
  13017. */
  13018. Message.prototype.reject = function(options) {
  13019. options = options || {};
  13020. var
  13021. status_code = options.status_code || 480,
  13022. reason_phrase = options.reason_phrase,
  13023. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
  13024. body = options.body;
  13025. if (this.direction !== 'incoming') {
  13026. throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message');
  13027. }
  13028. if (status_code < 300 || status_code >= 700) {
  13029. throw new TypeError('Invalid status_code: '+ status_code);
  13030. }
  13031. this.request.reply(status_code, reason_phrase, extraHeaders, body);
  13032. };
  13033. /**
  13034. * Internal Callbacks
  13035. */
  13036. Message.prototype.newMessage = function(originator, request) {
  13037. if (originator === 'remote') {
  13038. this.direction = 'incoming';
  13039. this.local_identity = request.to;
  13040. this.remote_identity = request.from;
  13041. } else if (originator === 'local'){
  13042. this.direction = 'outgoing';
  13043. this.local_identity = request.from;
  13044. this.remote_identity = request.to;
  13045. }
  13046. this.ua.newMessage({
  13047. originator: originator,
  13048. message: this,
  13049. request: request
  13050. });
  13051. };
  13052. },{"./Constants":1,"./Exceptions":5,"./RequestSender":18,"./SIPMessage":19,"./Transactions":22,"./Utils":26,"events":29,"util":33}],9:[function(require,module,exports){
  13053. module.exports = NameAddrHeader;
  13054. /**
  13055. * Dependencies.
  13056. */
  13057. var URI = require('./URI');
  13058. var Grammar = require('./Grammar');
  13059. function NameAddrHeader(uri, display_name, parameters) {
  13060. var param;
  13061. // Checks
  13062. if(!uri || !(uri instanceof URI)) {
  13063. throw new TypeError('missing or invalid "uri" parameter');
  13064. }
  13065. // Initialize parameters
  13066. this.uri = uri;
  13067. this.parameters = {};
  13068. for (param in parameters) {
  13069. this.setParam(param, parameters[param]);
  13070. }
  13071. Object.defineProperties(this, {
  13072. display_name: {
  13073. get: function() { return display_name; },
  13074. set: function(value) {
  13075. display_name = (value === 0) ? '0' : value;
  13076. }
  13077. }
  13078. });
  13079. }
  13080. NameAddrHeader.prototype = {
  13081. setParam: function(key, value) {
  13082. if (key) {
  13083. this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null) ? null : value.toString();
  13084. }
  13085. },
  13086. getParam: function(key) {
  13087. if(key) {
  13088. return this.parameters[key.toLowerCase()];
  13089. }
  13090. },
  13091. hasParam: function(key) {
  13092. if(key) {
  13093. return (this.parameters.hasOwnProperty(key.toLowerCase()) && true) || false;
  13094. }
  13095. },
  13096. deleteParam: function(parameter) {
  13097. var value;
  13098. parameter = parameter.toLowerCase();
  13099. if (this.parameters.hasOwnProperty(parameter)) {
  13100. value = this.parameters[parameter];
  13101. delete this.parameters[parameter];
  13102. return value;
  13103. }
  13104. },
  13105. clearParams: function() {
  13106. this.parameters = {};
  13107. },
  13108. clone: function() {
  13109. return new NameAddrHeader(
  13110. this.uri.clone(),
  13111. this.display_name,
  13112. JSON.parse(JSON.stringify(this.parameters)));
  13113. },
  13114. toString: function() {
  13115. var body, parameter;
  13116. body = (this.display_name || this.display_name === 0) ? '"' + this.display_name + '" ' : '';
  13117. body += '<' + this.uri.toString() + '>';
  13118. for (parameter in this.parameters) {
  13119. body += ';' + parameter;
  13120. if (this.parameters[parameter] !== null) {
  13121. body += '='+ this.parameters[parameter];
  13122. }
  13123. }
  13124. return body;
  13125. }
  13126. };
  13127. /**
  13128. * Parse the given string and returns a NameAddrHeader instance or undefined if
  13129. * it is an invalid NameAddrHeader.
  13130. */
  13131. NameAddrHeader.parse = function(name_addr_header) {
  13132. name_addr_header = Grammar.parse(name_addr_header,'Name_Addr_Header');
  13133. if (name_addr_header !== -1) {
  13134. return name_addr_header;
  13135. } else {
  13136. return undefined;
  13137. }
  13138. };
  13139. },{"./Grammar":6,"./URI":25}],10:[function(require,module,exports){
  13140. var Parser = {};
  13141. module.exports = Parser;
  13142. /**
  13143. * Dependencies.
  13144. */
  13145. var debugerror = require('debug')('JsSIP:ERROR:Parser');
  13146. debugerror.log = console.warn.bind(console);
  13147. var Grammar = require('./Grammar');
  13148. var SIPMessage = require('./SIPMessage');
  13149. /**
  13150. * Extract and parse every header of a SIP message.
  13151. */
  13152. function getHeader(data, headerStart) {
  13153. var
  13154. // 'start' position of the header.
  13155. start = headerStart,
  13156. // 'end' position of the header.
  13157. end = 0,
  13158. // 'partial end' position of the header.
  13159. partialEnd = 0;
  13160. //End of message.
  13161. if (data.substring(start, start + 2).match(/(^\r\n)/)) {
  13162. return -2;
  13163. }
  13164. while(end === 0) {
  13165. // Partial End of Header.
  13166. partialEnd = data.indexOf('\r\n', start);
  13167. // 'indexOf' returns -1 if the value to be found never occurs.
  13168. if (partialEnd === -1) {
  13169. return partialEnd;
  13170. }
  13171. if(!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) {
  13172. // Not the end of the message. Continue from the next position.
  13173. start = partialEnd + 2;
  13174. } else {
  13175. end = partialEnd;
  13176. }
  13177. }
  13178. return end;
  13179. }
  13180. function parseHeader(message, data, headerStart, headerEnd) {
  13181. var header, idx, length, parsed,
  13182. hcolonIndex = data.indexOf(':', headerStart),
  13183. headerName = data.substring(headerStart, hcolonIndex).trim(),
  13184. headerValue = data.substring(hcolonIndex + 1, headerEnd).trim();
  13185. // If header-field is well-known, parse it.
  13186. switch(headerName.toLowerCase()) {
  13187. case 'via':
  13188. case 'v':
  13189. message.addHeader('via', headerValue);
  13190. if(message.getHeaders('via').length === 1) {
  13191. parsed = message.parseHeader('Via');
  13192. if(parsed) {
  13193. message.via = parsed;
  13194. message.via_branch = parsed.branch;
  13195. }
  13196. } else {
  13197. parsed = 0;
  13198. }
  13199. break;
  13200. case 'from':
  13201. case 'f':
  13202. message.setHeader('from', headerValue);
  13203. parsed = message.parseHeader('from');
  13204. if(parsed) {
  13205. message.from = parsed;
  13206. message.from_tag = parsed.getParam('tag');
  13207. }
  13208. break;
  13209. case 'to':
  13210. case 't':
  13211. message.setHeader('to', headerValue);
  13212. parsed = message.parseHeader('to');
  13213. if(parsed) {
  13214. message.to = parsed;
  13215. message.to_tag = parsed.getParam('tag');
  13216. }
  13217. break;
  13218. case 'record-route':
  13219. parsed = Grammar.parse(headerValue, 'Record_Route');
  13220. if (parsed === -1) {
  13221. parsed = undefined;
  13222. } else {
  13223. length = parsed.length;
  13224. for (idx = 0; idx < length; idx++) {
  13225. header = parsed[idx];
  13226. message.addHeader('record-route', headerValue.substring(header.possition, header.offset));
  13227. message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed;
  13228. }
  13229. }
  13230. break;
  13231. case 'call-id':
  13232. case 'i':
  13233. message.setHeader('call-id', headerValue);
  13234. parsed = message.parseHeader('call-id');
  13235. if(parsed) {
  13236. message.call_id = headerValue;
  13237. }
  13238. break;
  13239. case 'contact':
  13240. case 'm':
  13241. parsed = Grammar.parse(headerValue, 'Contact');
  13242. if (parsed === -1) {
  13243. parsed = undefined;
  13244. } else {
  13245. length = parsed.length;
  13246. for (idx = 0; idx < length; idx++) {
  13247. header = parsed[idx];
  13248. message.addHeader('contact', headerValue.substring(header.possition, header.offset));
  13249. message.headers.Contact[message.getHeaders('contact').length - 1].parsed = header.parsed;
  13250. }
  13251. }
  13252. break;
  13253. case 'content-length':
  13254. case 'l':
  13255. message.setHeader('content-length', headerValue);
  13256. parsed = message.parseHeader('content-length');
  13257. break;
  13258. case 'content-type':
  13259. case 'c':
  13260. message.setHeader('content-type', headerValue);
  13261. parsed = message.parseHeader('content-type');
  13262. break;
  13263. case 'cseq':
  13264. message.setHeader('cseq', headerValue);
  13265. parsed = message.parseHeader('cseq');
  13266. if(parsed) {
  13267. message.cseq = parsed.value;
  13268. }
  13269. if(message instanceof SIPMessage.IncomingResponse) {
  13270. message.method = parsed.method;
  13271. }
  13272. break;
  13273. case 'max-forwards':
  13274. message.setHeader('max-forwards', headerValue);
  13275. parsed = message.parseHeader('max-forwards');
  13276. break;
  13277. case 'www-authenticate':
  13278. message.setHeader('www-authenticate', headerValue);
  13279. parsed = message.parseHeader('www-authenticate');
  13280. break;
  13281. case 'proxy-authenticate':
  13282. message.setHeader('proxy-authenticate', headerValue);
  13283. parsed = message.parseHeader('proxy-authenticate');
  13284. break;
  13285. case 'session-expires':
  13286. case 'x':
  13287. message.setHeader('session-expires', headerValue);
  13288. parsed = message.parseHeader('session-expires');
  13289. if (parsed) {
  13290. message.session_expires = parsed.expires;
  13291. message.session_expires_refresher = parsed.refresher;
  13292. }
  13293. break;
  13294. case 'refer-to':
  13295. case 'r':
  13296. message.setHeader('refer-to', headerValue);
  13297. parsed = message.parseHeader('refer-to');
  13298. if(parsed) {
  13299. message.refer_to = parsed;
  13300. }
  13301. break;
  13302. case 'replaces':
  13303. message.setHeader('replaces', headerValue);
  13304. parsed = message.parseHeader('replaces');
  13305. if(parsed) {
  13306. message.replaces = parsed;
  13307. }
  13308. break;
  13309. case 'event':
  13310. case 'o':
  13311. message.setHeader('event', headerValue);
  13312. parsed = message.parseHeader('event');
  13313. if(parsed) {
  13314. message.event = parsed;
  13315. }
  13316. break;
  13317. default:
  13318. // Do not parse this header.
  13319. message.setHeader(headerName, headerValue);
  13320. parsed = 0;
  13321. }
  13322. if (parsed === undefined) {
  13323. return {
  13324. error: 'error parsing header "'+ headerName +'"'
  13325. };
  13326. } else {
  13327. return true;
  13328. }
  13329. }
  13330. /**
  13331. * Parse SIP Message
  13332. */
  13333. Parser.parseMessage = function(data, ua) {
  13334. var message, firstLine, contentLength, bodyStart, parsed,
  13335. headerStart = 0,
  13336. headerEnd = data.indexOf('\r\n');
  13337. if(headerEnd === -1) {
  13338. debugerror('parseMessage() | no CRLF found, not a SIP message');
  13339. return;
  13340. }
  13341. // Parse first line. Check if it is a Request or a Reply.
  13342. firstLine = data.substring(0, headerEnd);
  13343. parsed = Grammar.parse(firstLine, 'Request_Response');
  13344. if(parsed === -1) {
  13345. debugerror('parseMessage() | error parsing first line of SIP message: "' + firstLine + '"');
  13346. return;
  13347. } else if(!parsed.status_code) {
  13348. message = new SIPMessage.IncomingRequest(ua);
  13349. message.method = parsed.method;
  13350. message.ruri = parsed.uri;
  13351. } else {
  13352. message = new SIPMessage.IncomingResponse();
  13353. message.status_code = parsed.status_code;
  13354. message.reason_phrase = parsed.reason_phrase;
  13355. }
  13356. message.data = data;
  13357. headerStart = headerEnd + 2;
  13358. /* Loop over every line in data. Detect the end of each header and parse
  13359. * it or simply add to the headers collection.
  13360. */
  13361. while(true) {
  13362. headerEnd = getHeader(data, headerStart);
  13363. // The SIP message has normally finished.
  13364. if(headerEnd === -2) {
  13365. bodyStart = headerStart + 2;
  13366. break;
  13367. }
  13368. // data.indexOf returned -1 due to a malformed message.
  13369. else if(headerEnd === -1) {
  13370. debugerror('parseMessage() | malformed message');
  13371. return;
  13372. }
  13373. parsed = parseHeader(message, data, headerStart, headerEnd);
  13374. if(parsed !== true) {
  13375. debugerror('parseMessage() |', parsed.error);
  13376. return;
  13377. }
  13378. headerStart = headerEnd + 2;
  13379. }
  13380. /* RFC3261 18.3.
  13381. * If there are additional bytes in the transport packet
  13382. * beyond the end of the body, they MUST be discarded.
  13383. */
  13384. if(message.hasHeader('content-length')) {
  13385. contentLength = message.getHeader('content-length');
  13386. message.body = data.substr(bodyStart, contentLength);
  13387. } else {
  13388. message.body = data.substring(bodyStart);
  13389. }
  13390. return message;
  13391. };
  13392. },{"./Grammar":6,"./SIPMessage":19,"debug":35}],11:[function(require,module,exports){
  13393. /* globals RTCPeerConnection: false, RTCSessionDescription: false */
  13394. module.exports = RTCSession;
  13395. var C = {
  13396. // RTCSession states
  13397. STATUS_NULL: 0,
  13398. STATUS_INVITE_SENT: 1,
  13399. STATUS_1XX_RECEIVED: 2,
  13400. STATUS_INVITE_RECEIVED: 3,
  13401. STATUS_WAITING_FOR_ANSWER: 4,
  13402. STATUS_ANSWERED: 5,
  13403. STATUS_WAITING_FOR_ACK: 6,
  13404. STATUS_CANCELED: 7,
  13405. STATUS_TERMINATED: 8,
  13406. STATUS_CONFIRMED: 9
  13407. };
  13408. /**
  13409. * Expose C object.
  13410. */
  13411. RTCSession.C = C;
  13412. /**
  13413. * Dependencies.
  13414. */
  13415. var util = require('util');
  13416. var events = require('events');
  13417. var debug = require('debug')('JsSIP:RTCSession');
  13418. var debugerror = require('debug')('JsSIP:ERROR:RTCSession');
  13419. debugerror.log = console.warn.bind(console);
  13420. var sdp_transform = require('sdp-transform');
  13421. var JsSIP_C = require('./Constants');
  13422. var Exceptions = require('./Exceptions');
  13423. var Transactions = require('./Transactions');
  13424. var Utils = require('./Utils');
  13425. var Timers = require('./Timers');
  13426. var SIPMessage = require('./SIPMessage');
  13427. var Dialog = require('./Dialog');
  13428. var RequestSender = require('./RequestSender');
  13429. var RTCSession_Request = require('./RTCSession/Request');
  13430. var RTCSession_DTMF = require('./RTCSession/DTMF');
  13431. var RTCSession_Info = require('./RTCSession/Info');
  13432. var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier');
  13433. var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber');
  13434. /**
  13435. * Local variables.
  13436. */
  13437. var holdMediaTypes = ['audio', 'video'];
  13438. function RTCSession(ua) {
  13439. debug('new');
  13440. this.ua = ua;
  13441. this.status = C.STATUS_NULL;
  13442. this.dialog = null;
  13443. this.earlyDialogs = {};
  13444. this.connection = null; // The RTCPeerConnection instance (public attribute).
  13445. // RTCSession confirmation flag
  13446. this.is_confirmed = false;
  13447. // is late SDP being negotiated
  13448. this.late_sdp = false;
  13449. // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()).
  13450. this.rtcOfferConstraints = null;
  13451. this.rtcAnswerConstraints = null;
  13452. // Local MediaStream.
  13453. this.localMediaStream = null;
  13454. this.localMediaStreamLocallyGenerated = false;
  13455. // Flag to indicate PeerConnection ready for new actions.
  13456. this.rtcReady = true;
  13457. // SIP Timers
  13458. this.timers = {
  13459. ackTimer: null,
  13460. expiresTimer: null,
  13461. invite2xxTimer: null,
  13462. userNoAnswerTimer: null
  13463. };
  13464. // Session info
  13465. this.direction = null;
  13466. this.local_identity = null;
  13467. this.remote_identity = null;
  13468. this.start_time = null;
  13469. this.end_time = null;
  13470. this.tones = null;
  13471. // Mute/Hold state
  13472. this.audioMuted = false;
  13473. this.videoMuted = false;
  13474. this.localHold = false;
  13475. this.remoteHold = false;
  13476. // Session Timers (RFC 4028)
  13477. this.sessionTimers = {
  13478. enabled: this.ua.configuration.session_timers,
  13479. defaultExpires: JsSIP_C.SESSION_EXPIRES,
  13480. currentExpires: null,
  13481. running: false,
  13482. refresher: false,
  13483. timer: null // A setTimeout.
  13484. };
  13485. // Map of ReferSubscriber instances indexed by the REFER's CSeq number
  13486. this.referSubscribers = {};
  13487. // Custom session empty object for high level use
  13488. this.data = {};
  13489. // Expose session failed/ended causes as a property of the RTCSession instance
  13490. this.causes = JsSIP_C.causes;
  13491. events.EventEmitter.call(this);
  13492. }
  13493. util.inherits(RTCSession, events.EventEmitter);
  13494. /**
  13495. * User API
  13496. */
  13497. RTCSession.prototype.isInProgress = function() {
  13498. switch(this.status) {
  13499. case C.STATUS_NULL:
  13500. case C.STATUS_INVITE_SENT:
  13501. case C.STATUS_1XX_RECEIVED:
  13502. case C.STATUS_INVITE_RECEIVED:
  13503. case C.STATUS_WAITING_FOR_ANSWER:
  13504. return true;
  13505. default:
  13506. return false;
  13507. }
  13508. };
  13509. RTCSession.prototype.isEstablished = function() {
  13510. switch(this.status) {
  13511. case C.STATUS_ANSWERED:
  13512. case C.STATUS_WAITING_FOR_ACK:
  13513. case C.STATUS_CONFIRMED:
  13514. return true;
  13515. default:
  13516. return false;
  13517. }
  13518. };
  13519. RTCSession.prototype.isEnded = function() {
  13520. switch(this.status) {
  13521. case C.STATUS_CANCELED:
  13522. case C.STATUS_TERMINATED:
  13523. return true;
  13524. default:
  13525. return false;
  13526. }
  13527. };
  13528. RTCSession.prototype.isMuted = function() {
  13529. return {
  13530. audio: this.audioMuted,
  13531. video: this.videoMuted
  13532. };
  13533. };
  13534. RTCSession.prototype.isOnHold = function() {
  13535. return {
  13536. local: this.localHold,
  13537. remote: this.remoteHold
  13538. };
  13539. };
  13540. /**
  13541. * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP.
  13542. */
  13543. RTCSession.prototype.isReadyToReOffer = function() {
  13544. if (! this.rtcReady) {
  13545. debug('isReadyToReOffer() | internal WebRTC status not ready');
  13546. return false;
  13547. }
  13548. // No established yet.
  13549. if (! this.dialog) {
  13550. debug('isReadyToReOffer() | session not established yet');
  13551. return false;
  13552. }
  13553. // Another INVITE transaction is in progress
  13554. if (this.dialog.uac_pending_reply === true || this.dialog.uas_pending_reply === true) {
  13555. debug('isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress');
  13556. return false;
  13557. }
  13558. return true;
  13559. };
  13560. RTCSession.prototype.connect = function(target, options, initCallback) {
  13561. debug('connect()');
  13562. options = options || {};
  13563. var event, requestParams,
  13564. originalTarget = target,
  13565. eventHandlers = options.eventHandlers || {},
  13566. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
  13567. mediaConstraints = options.mediaConstraints || {audio: true, video: true},
  13568. mediaStream = options.mediaStream || null,
  13569. pcConfig = options.pcConfig || {iceServers:[]},
  13570. rtcConstraints = options.rtcConstraints || null,
  13571. rtcOfferConstraints = options.rtcOfferConstraints || null;
  13572. this.rtcOfferConstraints = rtcOfferConstraints;
  13573. this.rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  13574. // Session Timers.
  13575. if (this.sessionTimers.enabled) {
  13576. if (Utils.isDecimal(options.sessionTimersExpires)) {
  13577. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  13578. this.sessionTimers.defaultExpires = options.sessionTimersExpires;
  13579. }
  13580. else {
  13581. this.sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  13582. }
  13583. }
  13584. }
  13585. this.data = options.data || this.data;
  13586. if (target === undefined) {
  13587. throw new TypeError('Not enough arguments');
  13588. }
  13589. // Check WebRTC support.
  13590. if (!window.RTCPeerConnection) {
  13591. throw new Exceptions.NotSupportedError('WebRTC not supported');
  13592. }
  13593. // Check target validity
  13594. target = this.ua.normalizeTarget(target);
  13595. if (!target) {
  13596. throw new TypeError('Invalid target: '+ originalTarget);
  13597. }
  13598. // Check Session Status
  13599. if (this.status !== C.STATUS_NULL) {
  13600. throw new Exceptions.InvalidStateError(this.status);
  13601. }
  13602. // Set event handlers
  13603. for (event in eventHandlers) {
  13604. this.on(event, eventHandlers[event]);
  13605. }
  13606. // Session parameter initialization
  13607. this.from_tag = Utils.newTag();
  13608. // Set anonymous property
  13609. this.anonymous = options.anonymous || false;
  13610. // OutgoingSession specific parameters
  13611. this.isCanceled = false;
  13612. requestParams = {from_tag: this.from_tag};
  13613. this.contact = this.ua.contact.toString({
  13614. anonymous: this.anonymous,
  13615. outbound: true
  13616. });
  13617. if (this.anonymous) {
  13618. requestParams.from_display_name = 'Anonymous';
  13619. requestParams.from_uri = 'sip:anonymous@anonymous.invalid';
  13620. extraHeaders.push('P-Preferred-Identity: '+ this.ua.configuration.uri.toString());
  13621. extraHeaders.push('Privacy: id');
  13622. }
  13623. extraHeaders.push('Contact: '+ this.contact);
  13624. extraHeaders.push('Content-Type: application/sdp');
  13625. if (this.sessionTimers.enabled) {
  13626. extraHeaders.push('Session-Expires: ' + this.sessionTimers.defaultExpires);
  13627. }
  13628. this.request = new SIPMessage.OutgoingRequest(JsSIP_C.INVITE, target, this.ua, requestParams, extraHeaders);
  13629. this.id = this.request.call_id + this.from_tag;
  13630. // Create a new RTCPeerConnection instance.
  13631. createRTCConnection.call(this, pcConfig, rtcConstraints);
  13632. // Save the session into the ua sessions collection.
  13633. this.ua.sessions[this.id] = this;
  13634. // Set internal properties
  13635. this.direction = 'outgoing';
  13636. this.local_identity = this.request.from;
  13637. this.remote_identity = this.request.to;
  13638. // User explicitly provided a newRTCSession callback for this session
  13639. if (initCallback) {
  13640. initCallback(this);
  13641. } else {
  13642. newRTCSession.call(this, 'local', this.request);
  13643. }
  13644. sendInitialRequest.call(this, mediaConstraints, rtcOfferConstraints, mediaStream);
  13645. };
  13646. RTCSession.prototype.init_incoming = function(request, initCallback) {
  13647. debug('init_incoming()');
  13648. var expires,
  13649. self = this,
  13650. contentType = request.getHeader('Content-Type');
  13651. // Check body and content type
  13652. if (request.body && (contentType !== 'application/sdp')) {
  13653. request.reply(415);
  13654. return;
  13655. }
  13656. // Session parameter initialization
  13657. this.status = C.STATUS_INVITE_RECEIVED;
  13658. this.from_tag = request.from_tag;
  13659. this.id = request.call_id + this.from_tag;
  13660. this.request = request;
  13661. this.contact = this.ua.contact.toString();
  13662. // Save the session into the ua sessions collection.
  13663. this.ua.sessions[this.id] = this;
  13664. // Get the Expires header value if exists
  13665. if (request.hasHeader('expires')) {
  13666. expires = request.getHeader('expires') * 1000;
  13667. }
  13668. /* Set the to_tag before
  13669. * replying a response code that will create a dialog.
  13670. */
  13671. request.to_tag = Utils.newTag();
  13672. // An error on dialog creation will fire 'failed' event
  13673. if (! createDialog.call(this, request, 'UAS', true)) {
  13674. request.reply(500, 'Missing Contact header field');
  13675. return;
  13676. }
  13677. if (request.body) {
  13678. this.late_sdp = false;
  13679. }
  13680. else {
  13681. this.late_sdp = true;
  13682. }
  13683. this.status = C.STATUS_WAITING_FOR_ANSWER;
  13684. // Set userNoAnswerTimer
  13685. this.timers.userNoAnswerTimer = setTimeout(function() {
  13686. request.reply(408);
  13687. failed.call(self, 'local',null, JsSIP_C.causes.NO_ANSWER);
  13688. }, this.ua.configuration.no_answer_timeout
  13689. );
  13690. /* Set expiresTimer
  13691. * RFC3261 13.3.1
  13692. */
  13693. if (expires) {
  13694. this.timers.expiresTimer = setTimeout(function() {
  13695. if(self.status === C.STATUS_WAITING_FOR_ANSWER) {
  13696. request.reply(487);
  13697. failed.call(self, 'system', null, JsSIP_C.causes.EXPIRES);
  13698. }
  13699. }, expires
  13700. );
  13701. }
  13702. // Set internal properties
  13703. this.direction = 'incoming';
  13704. this.local_identity = request.to;
  13705. this.remote_identity = request.from;
  13706. // A init callback was specifically defined
  13707. if (initCallback) {
  13708. initCallback(this);
  13709. // Fire 'newRTCSession' event.
  13710. } else {
  13711. newRTCSession.call(this, 'remote', request);
  13712. }
  13713. // The user may have rejected the call in the 'newRTCSession' event.
  13714. if (this.status === C.STATUS_TERMINATED) {
  13715. return;
  13716. }
  13717. // Reply 180.
  13718. request.reply(180, null, ['Contact: ' + self.contact]);
  13719. // Fire 'progress' event.
  13720. // TODO: Document that 'response' field in 'progress' event is null for
  13721. // incoming calls.
  13722. progress.call(self, 'local', null);
  13723. };
  13724. /**
  13725. * Answer the call.
  13726. */
  13727. RTCSession.prototype.answer = function(options) {
  13728. debug('answer()');
  13729. options = options || {};
  13730. var idx, length, sdp, tracks,
  13731. peerHasAudioLine = false,
  13732. peerHasVideoLine = false,
  13733. peerOffersFullAudio = false,
  13734. peerOffersFullVideo = false,
  13735. self = this,
  13736. request = this.request,
  13737. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
  13738. mediaConstraints = options.mediaConstraints || {},
  13739. mediaStream = options.mediaStream || null,
  13740. pcConfig = options.pcConfig || {iceServers:[]},
  13741. rtcConstraints = options.rtcConstraints || null,
  13742. rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  13743. this.rtcAnswerConstraints = rtcAnswerConstraints;
  13744. this.rtcOfferConstraints = options.rtcOfferConstraints || null;
  13745. // Session Timers.
  13746. if (this.sessionTimers.enabled) {
  13747. if (Utils.isDecimal(options.sessionTimersExpires)) {
  13748. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  13749. this.sessionTimers.defaultExpires = options.sessionTimersExpires;
  13750. }
  13751. else {
  13752. this.sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  13753. }
  13754. }
  13755. }
  13756. this.data = options.data || this.data;
  13757. // Check Session Direction and Status
  13758. if (this.direction !== 'incoming') {
  13759. throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession');
  13760. } else if (this.status !== C.STATUS_WAITING_FOR_ANSWER) {
  13761. throw new Exceptions.InvalidStateError(this.status);
  13762. }
  13763. this.status = C.STATUS_ANSWERED;
  13764. // An error on dialog creation will fire 'failed' event
  13765. if (! createDialog.call(this, request, 'UAS')) {
  13766. request.reply(500, 'Error creating dialog');
  13767. return;
  13768. }
  13769. clearTimeout(this.timers.userNoAnswerTimer);
  13770. extraHeaders.unshift('Contact: ' + self.contact);
  13771. // Determine incoming media from incoming SDP offer (if any).
  13772. sdp = request.parseSDP();
  13773. // Make sure sdp.media is an array, not the case if there is only one media
  13774. if (! Array.isArray(sdp.media)) {
  13775. sdp.media = [sdp.media];
  13776. }
  13777. // Go through all medias in SDP to find offered capabilities to answer with
  13778. idx = sdp.media.length;
  13779. while(idx--) {
  13780. var m = sdp.media[idx];
  13781. if (m.type === 'audio') {
  13782. peerHasAudioLine = true;
  13783. if (!m.direction || m.direction === 'sendrecv') {
  13784. peerOffersFullAudio = true;
  13785. }
  13786. }
  13787. if (m.type === 'video') {
  13788. peerHasVideoLine = true;
  13789. if (!m.direction || m.direction === 'sendrecv') {
  13790. peerOffersFullVideo = true;
  13791. }
  13792. }
  13793. }
  13794. // Remove audio from mediaStream if suggested by mediaConstraints
  13795. if (mediaStream && mediaConstraints.audio === false) {
  13796. tracks = mediaStream.getAudioTracks();
  13797. length = tracks.length;
  13798. for (idx=0; idx<length; idx++) {
  13799. mediaStream.removeTrack(tracks[idx]);
  13800. }
  13801. }
  13802. // Remove video from mediaStream if suggested by mediaConstraints
  13803. if (mediaStream && mediaConstraints.video === false) {
  13804. tracks = mediaStream.getVideoTracks();
  13805. length = tracks.length;
  13806. for (idx=0; idx<length; idx++) {
  13807. mediaStream.removeTrack(tracks[idx]);
  13808. }
  13809. }
  13810. // Set audio constraints based on incoming stream if not supplied
  13811. if (!mediaStream && mediaConstraints.audio === undefined) {
  13812. mediaConstraints.audio = peerOffersFullAudio;
  13813. }
  13814. // Set video constraints based on incoming stream if not supplied
  13815. if (!mediaStream && mediaConstraints.video === undefined) {
  13816. mediaConstraints.video = peerOffersFullVideo;
  13817. }
  13818. // Don't ask for audio if the incoming offer has no audio section
  13819. if (!mediaStream && !peerHasAudioLine) {
  13820. mediaConstraints.audio = false;
  13821. }
  13822. // Don't ask for video if the incoming offer has no video section
  13823. if (!mediaStream && !peerHasVideoLine) {
  13824. mediaConstraints.video = false;
  13825. }
  13826. // Create a new RTCPeerConnection instance.
  13827. // TODO: This may throw an error, should react.
  13828. createRTCConnection.call(this, pcConfig, rtcConstraints);
  13829. // If a local MediaStream is given use it.
  13830. if (mediaStream) {
  13831. userMediaSucceeded(mediaStream);
  13832. // If at least audio or video is requested prompt getUserMedia.
  13833. } else if (mediaConstraints.audio || mediaConstraints.video) {
  13834. self.localMediaStreamLocallyGenerated = true;
  13835. navigator.mediaDevices.getUserMedia(mediaConstraints)
  13836. .then(userMediaSucceeded)
  13837. .catch(function(error) {
  13838. userMediaFailed(error);
  13839. debugerror('emit "getusermediafailed" [error:%o]', error);
  13840. self.emit('getusermediafailed', error);
  13841. });
  13842. // Otherwise don't prompt getUserMedia.
  13843. } else {
  13844. userMediaSucceeded(null);
  13845. }
  13846. // User media succeeded
  13847. function userMediaSucceeded(stream) {
  13848. if (self.status === C.STATUS_TERMINATED) { return; }
  13849. self.localMediaStream = stream;
  13850. if (stream) {
  13851. self.connection.addStream(stream);
  13852. }
  13853. debug('emit "peerconnection"');
  13854. self.emit('peerconnection', {
  13855. peerconnection: self.connection
  13856. });
  13857. if (! self.late_sdp) {
  13858. var e = {originator:'remote', type:'offer', sdp:request.body};
  13859. debug('emit "sdp"');
  13860. self.emit('sdp', e);
  13861. var offer = new RTCSessionDescription({type:'offer', sdp:e.sdp});
  13862. self.connection.setRemoteDescription(offer)
  13863. .then(remoteDescriptionSucceededOrNotNeeded)
  13864. .catch(function(error) {
  13865. request.reply(488);
  13866. failed.call(self, 'system', null, JsSIP_C.causes.WEBRTC_ERROR);
  13867. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  13868. self.emit('peerconnection:setremotedescriptionfailed', error);
  13869. });
  13870. }
  13871. else {
  13872. remoteDescriptionSucceededOrNotNeeded();
  13873. }
  13874. }
  13875. // User media failed
  13876. function userMediaFailed() {
  13877. if (self.status === C.STATUS_TERMINATED) { return; }
  13878. request.reply(480);
  13879. failed.call(self, 'local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  13880. }
  13881. function remoteDescriptionSucceededOrNotNeeded() {
  13882. connecting.call(self, request);
  13883. if (! self.late_sdp) {
  13884. createLocalDescription.call(self, 'answer', rtcSucceeded, rtcFailed, rtcAnswerConstraints);
  13885. } else {
  13886. createLocalDescription.call(self, 'offer', rtcSucceeded, rtcFailed, self.rtcOfferConstraints);
  13887. }
  13888. }
  13889. function rtcSucceeded(desc) {
  13890. if (self.status === C.STATUS_TERMINATED) { return; }
  13891. // run for reply success callback
  13892. function replySucceeded() {
  13893. self.status = C.STATUS_WAITING_FOR_ACK;
  13894. setInvite2xxTimer.call(self, request, desc);
  13895. setACKTimer.call(self);
  13896. accepted.call(self, 'local');
  13897. }
  13898. // run for reply failure callback
  13899. function replyFailed() {
  13900. failed.call(self, 'system', null, JsSIP_C.causes.CONNECTION_ERROR);
  13901. }
  13902. handleSessionTimersInIncomingRequest.call(self, request, extraHeaders);
  13903. request.reply(200, null, extraHeaders,
  13904. desc,
  13905. replySucceeded,
  13906. replyFailed
  13907. );
  13908. }
  13909. function rtcFailed() {
  13910. if (self.status === C.STATUS_TERMINATED) { return; }
  13911. request.reply(500);
  13912. failed.call(self, 'system', null, JsSIP_C.causes.WEBRTC_ERROR);
  13913. }
  13914. };
  13915. /**
  13916. * Terminate the call.
  13917. */
  13918. RTCSession.prototype.terminate = function(options) {
  13919. debug('terminate()');
  13920. options = options || {};
  13921. var cancel_reason, dialog,
  13922. cause = options.cause || JsSIP_C.causes.BYE,
  13923. status_code = options.status_code,
  13924. reason_phrase = options.reason_phrase,
  13925. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
  13926. body = options.body,
  13927. self = this;
  13928. // Check Session Status
  13929. if (this.status === C.STATUS_TERMINATED) {
  13930. throw new Exceptions.InvalidStateError(this.status);
  13931. }
  13932. switch(this.status) {
  13933. // - UAC -
  13934. case C.STATUS_NULL:
  13935. case C.STATUS_INVITE_SENT:
  13936. case C.STATUS_1XX_RECEIVED:
  13937. debug('canceling session');
  13938. if (status_code && (status_code < 200 || status_code >= 700)) {
  13939. throw new TypeError('Invalid status_code: '+ status_code);
  13940. } else if (status_code) {
  13941. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  13942. cancel_reason = 'SIP ;cause=' + status_code + ' ;text="' + reason_phrase + '"';
  13943. }
  13944. // Check Session Status
  13945. if (this.status === C.STATUS_NULL) {
  13946. this.isCanceled = true;
  13947. this.cancelReason = cancel_reason;
  13948. } else if (this.status === C.STATUS_INVITE_SENT) {
  13949. this.isCanceled = true;
  13950. this.cancelReason = cancel_reason;
  13951. } else if(this.status === C.STATUS_1XX_RECEIVED) {
  13952. this.request.cancel(cancel_reason);
  13953. }
  13954. this.status = C.STATUS_CANCELED;
  13955. failed.call(this, 'local', null, JsSIP_C.causes.CANCELED);
  13956. break;
  13957. // - UAS -
  13958. case C.STATUS_WAITING_FOR_ANSWER:
  13959. case C.STATUS_ANSWERED:
  13960. debug('rejecting session');
  13961. status_code = status_code || 480;
  13962. if (status_code < 300 || status_code >= 700) {
  13963. throw new TypeError('Invalid status_code: '+ status_code);
  13964. }
  13965. this.request.reply(status_code, reason_phrase, extraHeaders, body);
  13966. failed.call(this, 'local', null, JsSIP_C.causes.REJECTED);
  13967. break;
  13968. case C.STATUS_WAITING_FOR_ACK:
  13969. case C.STATUS_CONFIRMED:
  13970. debug('terminating session');
  13971. reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  13972. if (status_code && (status_code < 200 || status_code >= 700)) {
  13973. throw new TypeError('Invalid status_code: '+ status_code);
  13974. } else if (status_code) {
  13975. extraHeaders.push('Reason: SIP ;cause=' + status_code + '; text="' + reason_phrase + '"');
  13976. }
  13977. /* RFC 3261 section 15 (Terminating a session):
  13978. *
  13979. * "...the callee's UA MUST NOT send a BYE on a confirmed dialog
  13980. * until it has received an ACK for its 2xx response or until the server
  13981. * transaction times out."
  13982. */
  13983. if (this.status === C.STATUS_WAITING_FOR_ACK &&
  13984. this.direction === 'incoming' &&
  13985. this.request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) {
  13986. // Save the dialog for later restoration
  13987. dialog = this.dialog;
  13988. // Send the BYE as soon as the ACK is received...
  13989. this.receiveRequest = function(request) {
  13990. if(request.method === JsSIP_C.ACK) {
  13991. sendRequest.call(this, JsSIP_C.BYE, {
  13992. extraHeaders: extraHeaders,
  13993. body: body
  13994. });
  13995. dialog.terminate();
  13996. }
  13997. };
  13998. // .., or when the INVITE transaction times out
  13999. this.request.server_transaction.on('stateChanged', function(){
  14000. if (this.state === Transactions.C.STATUS_TERMINATED) {
  14001. sendRequest.call(self, JsSIP_C.BYE, {
  14002. extraHeaders: extraHeaders,
  14003. body: body
  14004. });
  14005. dialog.terminate();
  14006. }
  14007. });
  14008. ended.call(this, 'local', null, cause);
  14009. // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-)
  14010. this.dialog = dialog;
  14011. // Restore the dialog into 'ua' so the ACK can reach 'this' session
  14012. this.ua.dialogs[dialog.id.toString()] = dialog;
  14013. } else {
  14014. sendRequest.call(this, JsSIP_C.BYE, {
  14015. extraHeaders: extraHeaders,
  14016. body: body
  14017. });
  14018. ended.call(this, 'local', null, cause);
  14019. }
  14020. }
  14021. };
  14022. RTCSession.prototype.close = function() {
  14023. debug('close()');
  14024. var idx;
  14025. if (this.status === C.STATUS_TERMINATED) {
  14026. return;
  14027. }
  14028. // Terminate RTC.
  14029. if (this.connection) {
  14030. try {
  14031. this.connection.close();
  14032. } catch(error) {
  14033. debugerror('close() | error closing the RTCPeerConnection: %o', error);
  14034. }
  14035. }
  14036. // Close local MediaStream if it was not given by the user.
  14037. if (this.localMediaStream && this.localMediaStreamLocallyGenerated) {
  14038. debug('close() | closing local MediaStream');
  14039. Utils.closeMediaStream(this.localMediaStream);
  14040. }
  14041. // Terminate signaling.
  14042. // Clear SIP timers
  14043. for(idx in this.timers) {
  14044. clearTimeout(this.timers[idx]);
  14045. }
  14046. // Clear Session Timers.
  14047. clearTimeout(this.sessionTimers.timer);
  14048. // Terminate confirmed dialog
  14049. if (this.dialog) {
  14050. this.dialog.terminate();
  14051. delete this.dialog;
  14052. }
  14053. // Terminate early dialogs
  14054. for(idx in this.earlyDialogs) {
  14055. this.earlyDialogs[idx].terminate();
  14056. delete this.earlyDialogs[idx];
  14057. }
  14058. this.status = C.STATUS_TERMINATED;
  14059. delete this.ua.sessions[this.id];
  14060. };
  14061. RTCSession.prototype.sendDTMF = function(tones, options) {
  14062. debug('sendDTMF() | tones: %s', tones);
  14063. var duration, interToneGap,
  14064. position = 0,
  14065. self = this;
  14066. options = options || {};
  14067. duration = options.duration || null;
  14068. interToneGap = options.interToneGap || null;
  14069. if (tones === undefined) {
  14070. throw new TypeError('Not enough arguments');
  14071. }
  14072. // Check Session Status
  14073. if (this.status !== C.STATUS_CONFIRMED && this.status !== C.STATUS_WAITING_FOR_ACK) {
  14074. throw new Exceptions.InvalidStateError(this.status);
  14075. }
  14076. // Convert to string
  14077. if(typeof tones === 'number') {
  14078. tones = tones.toString();
  14079. }
  14080. // Check tones
  14081. if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) {
  14082. throw new TypeError('Invalid tones: '+ tones);
  14083. }
  14084. // Check duration
  14085. if (duration && !Utils.isDecimal(duration)) {
  14086. throw new TypeError('Invalid tone duration: '+ duration);
  14087. } else if (!duration) {
  14088. duration = RTCSession_DTMF.C.DEFAULT_DURATION;
  14089. } else if (duration < RTCSession_DTMF.C.MIN_DURATION) {
  14090. debug('"duration" value is lower than the minimum allowed, setting it to '+ RTCSession_DTMF.C.MIN_DURATION+ ' milliseconds');
  14091. duration = RTCSession_DTMF.C.MIN_DURATION;
  14092. } else if (duration > RTCSession_DTMF.C.MAX_DURATION) {
  14093. debug('"duration" value is greater than the maximum allowed, setting it to '+ RTCSession_DTMF.C.MAX_DURATION +' milliseconds');
  14094. duration = RTCSession_DTMF.C.MAX_DURATION;
  14095. } else {
  14096. duration = Math.abs(duration);
  14097. }
  14098. options.duration = duration;
  14099. // Check interToneGap
  14100. if (interToneGap && !Utils.isDecimal(interToneGap)) {
  14101. throw new TypeError('Invalid interToneGap: '+ interToneGap);
  14102. } else if (!interToneGap) {
  14103. interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP;
  14104. } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) {
  14105. debug('"interToneGap" value is lower than the minimum allowed, setting it to '+ RTCSession_DTMF.C.MIN_INTER_TONE_GAP +' milliseconds');
  14106. interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP;
  14107. } else {
  14108. interToneGap = Math.abs(interToneGap);
  14109. }
  14110. if (this.tones) {
  14111. // Tones are already queued, just add to the queue
  14112. this.tones += tones;
  14113. return;
  14114. }
  14115. this.tones = tones;
  14116. // Send the first tone
  14117. _sendDTMF();
  14118. function _sendDTMF() {
  14119. var tone, timeout;
  14120. if (self.status === C.STATUS_TERMINATED || !self.tones || position >= self.tones.length) {
  14121. // Stop sending DTMF
  14122. self.tones = null;
  14123. return;
  14124. }
  14125. tone = self.tones[position];
  14126. position += 1;
  14127. if (tone === ',') {
  14128. timeout = 2000;
  14129. } else {
  14130. var dtmf = new RTCSession_DTMF(self);
  14131. options.eventHandlers = {
  14132. onFailed: function() { self.tones = null; }
  14133. };
  14134. dtmf.send(tone, options);
  14135. timeout = duration + interToneGap;
  14136. }
  14137. // Set timeout for the next tone
  14138. setTimeout(_sendDTMF, timeout);
  14139. }
  14140. };
  14141. RTCSession.prototype.sendInfo = function(contentType, body, options) {
  14142. debug('sendInfo()');
  14143. options = options || {};
  14144. // Check Session Status
  14145. if (this.status !== C.STATUS_CONFIRMED && this.status !== C.STATUS_WAITING_FOR_ACK) {
  14146. throw new Exceptions.InvalidStateError(this.status);
  14147. }
  14148. var info = new RTCSession_Info(this);
  14149. info.send(contentType, body, options);
  14150. };
  14151. /**
  14152. * Mute
  14153. */
  14154. RTCSession.prototype.mute = function(options) {
  14155. debug('mute()');
  14156. options = options || {audio:true, video:false};
  14157. var
  14158. audioMuted = false,
  14159. videoMuted = false;
  14160. if (this.audioMuted === false && options.audio) {
  14161. audioMuted = true;
  14162. this.audioMuted = true;
  14163. toogleMuteAudio.call(this, true);
  14164. }
  14165. if (this.videoMuted === false && options.video) {
  14166. videoMuted = true;
  14167. this.videoMuted = true;
  14168. toogleMuteVideo.call(this, true);
  14169. }
  14170. if (audioMuted === true || videoMuted === true) {
  14171. onmute.call(this, {
  14172. audio: audioMuted,
  14173. video: videoMuted
  14174. });
  14175. }
  14176. };
  14177. /**
  14178. * Unmute
  14179. */
  14180. RTCSession.prototype.unmute = function(options) {
  14181. debug('unmute()');
  14182. options = options || {audio:true, video:true};
  14183. var
  14184. audioUnMuted = false,
  14185. videoUnMuted = false;
  14186. if (this.audioMuted === true && options.audio) {
  14187. audioUnMuted = true;
  14188. this.audioMuted = false;
  14189. if (this.localHold === false) {
  14190. toogleMuteAudio.call(this, false);
  14191. }
  14192. }
  14193. if (this.videoMuted === true && options.video) {
  14194. videoUnMuted = true;
  14195. this.videoMuted = false;
  14196. if (this.localHold === false) {
  14197. toogleMuteVideo.call(this, false);
  14198. }
  14199. }
  14200. if (audioUnMuted === true || videoUnMuted === true) {
  14201. onunmute.call(this, {
  14202. audio: audioUnMuted,
  14203. video: videoUnMuted
  14204. });
  14205. }
  14206. };
  14207. /**
  14208. * Hold
  14209. */
  14210. RTCSession.prototype.hold = function(options, done) {
  14211. debug('hold()');
  14212. options = options || {};
  14213. var self = this,
  14214. eventHandlers;
  14215. if (this.status !== C.STATUS_WAITING_FOR_ACK && this.status !== C.STATUS_CONFIRMED) {
  14216. return false;
  14217. }
  14218. if (this.localHold === true) {
  14219. return false;
  14220. }
  14221. if (! this.isReadyToReOffer()) {
  14222. return false;
  14223. }
  14224. this.localHold = true;
  14225. onhold.call(this, 'local');
  14226. eventHandlers = {
  14227. succeeded: function() {
  14228. if (done) { done(); }
  14229. },
  14230. failed: function() {
  14231. self.terminate({
  14232. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14233. status_code: 500,
  14234. reason_phrase: 'Hold Failed'
  14235. });
  14236. }
  14237. };
  14238. if (options.useUpdate) {
  14239. sendUpdate.call(this, {
  14240. sdpOffer: true,
  14241. eventHandlers: eventHandlers,
  14242. extraHeaders: options.extraHeaders
  14243. });
  14244. } else {
  14245. sendReinvite.call(this, {
  14246. eventHandlers: eventHandlers,
  14247. extraHeaders: options.extraHeaders
  14248. });
  14249. }
  14250. return true;
  14251. };
  14252. RTCSession.prototype.unhold = function(options, done) {
  14253. debug('unhold()');
  14254. options = options || {};
  14255. var self = this,
  14256. eventHandlers;
  14257. if (this.status !== C.STATUS_WAITING_FOR_ACK && this.status !== C.STATUS_CONFIRMED) {
  14258. return false;
  14259. }
  14260. if (this.localHold === false) {
  14261. return false;
  14262. }
  14263. if (! this.isReadyToReOffer()) {
  14264. return false;
  14265. }
  14266. this.localHold = false;
  14267. onunhold.call(this, 'local');
  14268. eventHandlers = {
  14269. succeeded: function() {
  14270. if (done) { done(); }
  14271. },
  14272. failed: function() {
  14273. self.terminate({
  14274. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14275. status_code: 500,
  14276. reason_phrase: 'Unhold Failed'
  14277. });
  14278. }
  14279. };
  14280. if (options.useUpdate) {
  14281. sendUpdate.call(this, {
  14282. sdpOffer: true,
  14283. eventHandlers: eventHandlers,
  14284. extraHeaders: options.extraHeaders
  14285. });
  14286. } else {
  14287. sendReinvite.call(this, {
  14288. eventHandlers: eventHandlers,
  14289. extraHeaders: options.extraHeaders
  14290. });
  14291. }
  14292. return true;
  14293. };
  14294. RTCSession.prototype.renegotiate = function(options, done) {
  14295. debug('renegotiate()');
  14296. options = options || {};
  14297. var self = this,
  14298. eventHandlers,
  14299. rtcOfferConstraints = options.rtcOfferConstraints || null;
  14300. if (this.status !== C.STATUS_WAITING_FOR_ACK && this.status !== C.STATUS_CONFIRMED) {
  14301. return false;
  14302. }
  14303. if (! this.isReadyToReOffer()) {
  14304. return false;
  14305. }
  14306. eventHandlers = {
  14307. succeeded: function() {
  14308. if (done) { done(); }
  14309. },
  14310. failed: function() {
  14311. self.terminate({
  14312. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14313. status_code: 500,
  14314. reason_phrase: 'Media Renegotiation Failed'
  14315. });
  14316. }
  14317. };
  14318. setLocalMediaStatus.call(this);
  14319. if (options.useUpdate) {
  14320. sendUpdate.call(this, {
  14321. sdpOffer: true,
  14322. eventHandlers: eventHandlers,
  14323. rtcOfferConstraints: rtcOfferConstraints,
  14324. extraHeaders: options.extraHeaders
  14325. });
  14326. } else {
  14327. sendReinvite.call(this, {
  14328. eventHandlers: eventHandlers,
  14329. rtcOfferConstraints: rtcOfferConstraints,
  14330. extraHeaders: options.extraHeaders
  14331. });
  14332. }
  14333. return true;
  14334. };
  14335. /**
  14336. * Refer
  14337. */
  14338. RTCSession.prototype.refer = function(target, options) {
  14339. debug('refer()');
  14340. var self = this,
  14341. originalTarget = target,
  14342. referSubscriber,
  14343. id;
  14344. if (this.status !== C.STATUS_WAITING_FOR_ACK && this.status !== C.STATUS_CONFIRMED) {
  14345. return false;
  14346. }
  14347. // Check target validity
  14348. target = this.ua.normalizeTarget(target);
  14349. if (!target) {
  14350. throw new TypeError('Invalid target: '+ originalTarget);
  14351. }
  14352. referSubscriber = new RTCSession_ReferSubscriber(this);
  14353. referSubscriber.sendRefer(target, options);
  14354. // Store in the map
  14355. id = referSubscriber.outgoingRequest.cseq;
  14356. this.referSubscribers[id] = referSubscriber;
  14357. // Listen for ending events so we can remove it from the map
  14358. referSubscriber.on('requestFailed', function() {
  14359. delete self.referSubscribers[id];
  14360. });
  14361. referSubscriber.on('accepted', function() {
  14362. delete self.referSubscribers[id];
  14363. });
  14364. referSubscriber.on('failed', function() {
  14365. delete self.referSubscribers[id];
  14366. });
  14367. return referSubscriber;
  14368. };
  14369. /**
  14370. * In dialog Request Reception
  14371. */
  14372. RTCSession.prototype.receiveRequest = function(request) {
  14373. debug('receiveRequest()');
  14374. var contentType,
  14375. self = this;
  14376. if(request.method === JsSIP_C.CANCEL) {
  14377. /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL
  14378. * was in progress and that the UAC MAY continue with the session established by
  14379. * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the
  14380. * established session. So the CANCEL is processed only if the session is not yet
  14381. * established.
  14382. */
  14383. /*
  14384. * Terminate the whole session in case the user didn't accept (or yet send the answer)
  14385. * nor reject the request opening the session.
  14386. */
  14387. if(this.status === C.STATUS_WAITING_FOR_ANSWER || this.status === C.STATUS_ANSWERED) {
  14388. this.status = C.STATUS_CANCELED;
  14389. this.request.reply(487);
  14390. failed.call(this, 'remote', request, JsSIP_C.causes.CANCELED);
  14391. }
  14392. } else {
  14393. // Requests arriving here are in-dialog requests.
  14394. switch(request.method) {
  14395. case JsSIP_C.ACK:
  14396. if (this.status !== C.STATUS_WAITING_FOR_ACK) {
  14397. return;
  14398. }
  14399. // Update signaling status.
  14400. this.status = C.STATUS_CONFIRMED;
  14401. clearTimeout(this.timers.ackTimer);
  14402. clearTimeout(this.timers.invite2xxTimer);
  14403. if (this.late_sdp) {
  14404. if (!request.body) {
  14405. this.terminate({
  14406. cause: JsSIP_C.causes.MISSING_SDP,
  14407. status_code: 400
  14408. });
  14409. break;
  14410. }
  14411. var e = {originator:'remote', type:'answer', sdp:request.body};
  14412. var answer = new RTCSessionDescription({type:'answer', sdp:e.sdp});
  14413. this.emit('sdp', e);
  14414. this.connection.setRemoteDescription(answer)
  14415. .then(function() {
  14416. if (!self.is_confirmed) {
  14417. confirmed.call(self, 'remote', request);
  14418. }
  14419. })
  14420. .catch(function(error) {
  14421. self.terminate({
  14422. cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION,
  14423. status_code: 488
  14424. });
  14425. self.emit('peerconnection:setremotedescriptionfailed', error);
  14426. });
  14427. }
  14428. else {
  14429. if (!this.is_confirmed) {
  14430. confirmed.call(this, 'remote', request);
  14431. }
  14432. }
  14433. break;
  14434. case JsSIP_C.BYE:
  14435. if(this.status === C.STATUS_CONFIRMED) {
  14436. request.reply(200);
  14437. ended.call(this, 'remote', request, JsSIP_C.causes.BYE);
  14438. }
  14439. else if (this.status === C.STATUS_INVITE_RECEIVED) {
  14440. request.reply(200);
  14441. this.request.reply(487, 'BYE Received');
  14442. ended.call(this, 'remote', request, JsSIP_C.causes.BYE);
  14443. }
  14444. else {
  14445. request.reply(403, 'Wrong Status');
  14446. }
  14447. break;
  14448. case JsSIP_C.INVITE:
  14449. if(this.status === C.STATUS_CONFIRMED) {
  14450. if (request.hasHeader('replaces')) {
  14451. receiveReplaces.call(this, request);
  14452. } else {
  14453. receiveReinvite.call(this, request);
  14454. }
  14455. }
  14456. else {
  14457. request.reply(403, 'Wrong Status');
  14458. }
  14459. break;
  14460. case JsSIP_C.INFO:
  14461. if(this.status === C.STATUS_CONFIRMED || this.status === C.STATUS_WAITING_FOR_ACK || this.status === C.STATUS_INVITE_RECEIVED) {
  14462. contentType = request.getHeader('content-type');
  14463. if (contentType && (contentType.match(/^application\/dtmf-relay/i))) {
  14464. new RTCSession_DTMF(this).init_incoming(request);
  14465. }
  14466. else if (contentType !== undefined) {
  14467. new RTCSession_Info(this).init_incoming(request);
  14468. }
  14469. else {
  14470. request.reply(415);
  14471. }
  14472. }
  14473. else {
  14474. request.reply(403, 'Wrong Status');
  14475. }
  14476. break;
  14477. case JsSIP_C.UPDATE:
  14478. if(this.status === C.STATUS_CONFIRMED) {
  14479. receiveUpdate.call(this, request);
  14480. }
  14481. else {
  14482. request.reply(403, 'Wrong Status');
  14483. }
  14484. break;
  14485. case JsSIP_C.REFER:
  14486. if(this.status === C.STATUS_CONFIRMED) {
  14487. receiveRefer.call(this, request);
  14488. }
  14489. else {
  14490. request.reply(403, 'Wrong Status');
  14491. }
  14492. break;
  14493. case JsSIP_C.NOTIFY:
  14494. if(this.status === C.STATUS_CONFIRMED) {
  14495. receiveNotify.call(this, request);
  14496. }
  14497. else {
  14498. request.reply(403, 'Wrong Status');
  14499. }
  14500. break;
  14501. default:
  14502. request.reply(501);
  14503. }
  14504. }
  14505. };
  14506. /**
  14507. * Session Callbacks
  14508. */
  14509. RTCSession.prototype.onTransportError = function() {
  14510. debugerror('onTransportError()');
  14511. if(this.status !== C.STATUS_TERMINATED) {
  14512. this.terminate({
  14513. status_code: 500,
  14514. reason_phrase: JsSIP_C.causes.CONNECTION_ERROR,
  14515. cause: JsSIP_C.causes.CONNECTION_ERROR
  14516. });
  14517. }
  14518. };
  14519. RTCSession.prototype.onRequestTimeout = function() {
  14520. debugerror('onRequestTimeout()');
  14521. if(this.status !== C.STATUS_TERMINATED) {
  14522. this.terminate({
  14523. status_code: 408,
  14524. reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT,
  14525. cause: JsSIP_C.causes.REQUEST_TIMEOUT
  14526. });
  14527. }
  14528. };
  14529. RTCSession.prototype.onDialogError = function() {
  14530. debugerror('onDialogError()');
  14531. if(this.status !== C.STATUS_TERMINATED) {
  14532. this.terminate({
  14533. status_code: 500,
  14534. reason_phrase: JsSIP_C.causes.DIALOG_ERROR,
  14535. cause: JsSIP_C.causes.DIALOG_ERROR
  14536. });
  14537. }
  14538. };
  14539. // Called from DTMF handler.
  14540. RTCSession.prototype.newDTMF = function(data) {
  14541. debug('newDTMF()');
  14542. this.emit('newDTMF', data);
  14543. };
  14544. // Called from Info handler.
  14545. RTCSession.prototype.newInfo = function(data) {
  14546. debug('newInfo()');
  14547. this.emit('newInfo', data);
  14548. };
  14549. RTCSession.prototype.resetLocalMedia = function() {
  14550. debug('resetLocalMedia()');
  14551. // Reset all but remoteHold.
  14552. this.localHold = false;
  14553. this.audioMuted = false;
  14554. this.videoMuted = false;
  14555. setLocalMediaStatus.call(this);
  14556. };
  14557. /**
  14558. * Private API.
  14559. */
  14560. /**
  14561. * RFC3261 13.3.1.4
  14562. * Response retransmissions cannot be accomplished by transaction layer
  14563. * since it is destroyed when receiving the first 2xx answer
  14564. */
  14565. function setInvite2xxTimer(request, body) {
  14566. var
  14567. self = this,
  14568. timeout = Timers.T1;
  14569. this.timers.invite2xxTimer = setTimeout(function invite2xxRetransmission() {
  14570. if (self.status !== C.STATUS_WAITING_FOR_ACK) {
  14571. return;
  14572. }
  14573. request.reply(200, null, ['Contact: '+ self.contact], body);
  14574. if (timeout < Timers.T2) {
  14575. timeout = timeout * 2;
  14576. if (timeout > Timers.T2) {
  14577. timeout = Timers.T2;
  14578. }
  14579. }
  14580. self.timers.invite2xxTimer = setTimeout(
  14581. invite2xxRetransmission, timeout
  14582. );
  14583. }, timeout);
  14584. }
  14585. /**
  14586. * RFC3261 14.2
  14587. * If a UAS generates a 2xx response and never receives an ACK,
  14588. * it SHOULD generate a BYE to terminate the dialog.
  14589. */
  14590. function setACKTimer() {
  14591. var self = this;
  14592. this.timers.ackTimer = setTimeout(function() {
  14593. if(self.status === C.STATUS_WAITING_FOR_ACK) {
  14594. debug('no ACK received, terminating the session');
  14595. clearTimeout(self.timers.invite2xxTimer);
  14596. sendRequest.call(self, JsSIP_C.BYE);
  14597. ended.call(self, 'remote', null, JsSIP_C.causes.NO_ACK);
  14598. }
  14599. }, Timers.TIMER_H);
  14600. }
  14601. function createRTCConnection(pcConfig, rtcConstraints) {
  14602. var self = this;
  14603. this.connection = new RTCPeerConnection(pcConfig, rtcConstraints);
  14604. this.connection.addEventListener('iceconnectionstatechange', function() {
  14605. var state = self.connection.iceConnectionState;
  14606. // TODO: Do more with different states.
  14607. if (state === 'failed') {
  14608. self.terminate({
  14609. cause: JsSIP_C.causes.RTP_TIMEOUT,
  14610. status_code: 408,
  14611. reason_phrase: JsSIP_C.causes.RTP_TIMEOUT
  14612. });
  14613. }
  14614. });
  14615. }
  14616. function createLocalDescription(type, onSuccess, onFailure, constraints) {
  14617. debug('createLocalDescription()');
  14618. var self = this;
  14619. var connection = this.connection;
  14620. this.rtcReady = false;
  14621. if (type === 'offer') {
  14622. connection.createOffer(constraints)
  14623. .then(createSucceeded)
  14624. .catch(function(error) {
  14625. self.rtcReady = true;
  14626. if (onFailure) { onFailure(error); }
  14627. debugerror('emit "peerconnection:createofferfailed" [error:%o]', error);
  14628. self.emit('peerconnection:createofferfailed', error);
  14629. });
  14630. }
  14631. else if (type === 'answer') {
  14632. connection.createAnswer(constraints)
  14633. .then(createSucceeded)
  14634. .catch(function(error) {
  14635. self.rtcReady = true;
  14636. if (onFailure) { onFailure(error); }
  14637. debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error);
  14638. self.emit('peerconnection:createanswerfailed', error);
  14639. });
  14640. }
  14641. else {
  14642. throw new Error('createLocalDescription() | type must be "offer" or "answer", but "' +type+ '" was given');
  14643. }
  14644. // createAnswer or createOffer succeeded
  14645. function createSucceeded(desc) {
  14646. var listener;
  14647. connection.addEventListener('icecandidate', listener = function(event) {
  14648. var candidate = event.candidate;
  14649. if (! candidate) {
  14650. connection.removeEventListener('icecandidate', listener);
  14651. self.rtcReady = true;
  14652. if (onSuccess) {
  14653. var e = {originator:'local', type:type, sdp:connection.localDescription.sdp};
  14654. debug('emit "sdp"');
  14655. self.emit('sdp', e);
  14656. onSuccess(e.sdp);
  14657. }
  14658. onSuccess = null;
  14659. }
  14660. });
  14661. connection.setLocalDescription(desc)
  14662. .then(function() {
  14663. if (connection.iceGatheringState === 'complete') {
  14664. self.rtcReady = true;
  14665. if (onSuccess) {
  14666. var e = {originator:'local', type:type, sdp:connection.localDescription.sdp};
  14667. debug('emit "sdp"');
  14668. self.emit('sdp', e);
  14669. onSuccess(e.sdp);
  14670. onSuccess = null;
  14671. }
  14672. }
  14673. })
  14674. .catch(function(error) {
  14675. self.rtcReady = true;
  14676. if (onFailure) { onFailure(error); }
  14677. debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error);
  14678. self.emit('peerconnection:setlocaldescriptionfailed', error);
  14679. });
  14680. }
  14681. }
  14682. /**
  14683. * Dialog Management
  14684. */
  14685. function createDialog(message, type, early) {
  14686. var dialog, early_dialog,
  14687. local_tag = (type === 'UAS') ? message.to_tag : message.from_tag,
  14688. remote_tag = (type === 'UAS') ? message.from_tag : message.to_tag,
  14689. id = message.call_id + local_tag + remote_tag;
  14690. early_dialog = this.earlyDialogs[id];
  14691. // Early Dialog
  14692. if (early) {
  14693. if (early_dialog) {
  14694. return true;
  14695. } else {
  14696. early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY);
  14697. // Dialog has been successfully created.
  14698. if(early_dialog.error) {
  14699. debug(early_dialog.error);
  14700. failed.call(this, 'remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  14701. return false;
  14702. } else {
  14703. this.earlyDialogs[id] = early_dialog;
  14704. return true;
  14705. }
  14706. }
  14707. }
  14708. // Confirmed Dialog
  14709. else {
  14710. this.from_tag = message.from_tag;
  14711. this.to_tag = message.to_tag;
  14712. // In case the dialog is in _early_ state, update it
  14713. if (early_dialog) {
  14714. early_dialog.update(message, type);
  14715. this.dialog = early_dialog;
  14716. delete this.earlyDialogs[id];
  14717. return true;
  14718. }
  14719. // Otherwise, create a _confirmed_ dialog
  14720. dialog = new Dialog(this, message, type);
  14721. if(dialog.error) {
  14722. debug(dialog.error);
  14723. failed.call(this, 'remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  14724. return false;
  14725. } else {
  14726. this.dialog = dialog;
  14727. return true;
  14728. }
  14729. }
  14730. }
  14731. /**
  14732. * In dialog INVITE Reception
  14733. */
  14734. function receiveReinvite(request) {
  14735. debug('receiveReinvite()');
  14736. var
  14737. sdp, idx, direction, m,
  14738. self = this,
  14739. contentType = request.getHeader('Content-Type'),
  14740. hold = false,
  14741. rejected = false,
  14742. data = {
  14743. request: request,
  14744. callback: undefined,
  14745. reject: reject.bind(this)
  14746. };
  14747. function reject(options) {
  14748. options = options || {};
  14749. rejected = true;
  14750. var
  14751. status_code = options.status_code || 403,
  14752. reason_phrase = options.reason_phrase || '',
  14753. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [];
  14754. if (this.status !== C.STATUS_CONFIRMED) {
  14755. return false;
  14756. }
  14757. if (status_code < 300 || status_code >= 700) {
  14758. throw new TypeError('Invalid status_code: '+ status_code);
  14759. }
  14760. request.reply(status_code, reason_phrase, extraHeaders);
  14761. }
  14762. // Emit 'reinvite'.
  14763. this.emit('reinvite', data);
  14764. if (rejected) {
  14765. return;
  14766. }
  14767. if (request.body) {
  14768. this.late_sdp = false;
  14769. if (contentType !== 'application/sdp') {
  14770. debug('invalid Content-Type');
  14771. request.reply(415);
  14772. return;
  14773. }
  14774. sdp = request.parseSDP();
  14775. for (idx=0; idx < sdp.media.length; idx++) {
  14776. m = sdp.media[idx];
  14777. if (holdMediaTypes.indexOf(m.type) === -1) {
  14778. continue;
  14779. }
  14780. direction = m.direction || sdp.direction || 'sendrecv';
  14781. if (direction === 'sendonly' || direction === 'inactive') {
  14782. hold = true;
  14783. }
  14784. // If at least one of the streams is active don't emit 'hold'.
  14785. else {
  14786. hold = false;
  14787. break;
  14788. }
  14789. }
  14790. var e = {originator:'remote', type:'offer', sdp:request.body};
  14791. var offer = new RTCSessionDescription({type:'offer', sdp:e.sdp});
  14792. this.emit('sdp', e);
  14793. this.connection.setRemoteDescription(offer)
  14794. .then(doAnswer)
  14795. .catch(function(error) {
  14796. request.reply(488);
  14797. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  14798. self.emit('peerconnection:setremotedescriptionfailed', error);
  14799. });
  14800. }
  14801. else {
  14802. this.late_sdp = true;
  14803. doAnswer();
  14804. }
  14805. function doAnswer() {
  14806. createSdp(
  14807. // onSuccess
  14808. function(sdp) {
  14809. var extraHeaders = ['Contact: ' + self.contact];
  14810. handleSessionTimersInIncomingRequest.call(self, request, extraHeaders);
  14811. if (self.late_sdp) {
  14812. sdp = mangleOffer.call(self, sdp);
  14813. }
  14814. request.reply(200, null, extraHeaders, sdp,
  14815. function() {
  14816. self.status = C.STATUS_WAITING_FOR_ACK;
  14817. setInvite2xxTimer.call(self, request, sdp);
  14818. setACKTimer.call(self);
  14819. }
  14820. );
  14821. // If callback is given execute it.
  14822. if (typeof data.callback === 'function') {
  14823. data.callback();
  14824. }
  14825. },
  14826. // onFailure
  14827. function() {
  14828. request.reply(500);
  14829. }
  14830. );
  14831. }
  14832. function createSdp(onSuccess, onFailure) {
  14833. if (! self.late_sdp) {
  14834. if (self.remoteHold === true && hold === false) {
  14835. self.remoteHold = false;
  14836. onunhold.call(self, 'remote');
  14837. } else if (self.remoteHold === false && hold === true) {
  14838. self.remoteHold = true;
  14839. onhold.call(self, 'remote');
  14840. }
  14841. createLocalDescription.call(self, 'answer', onSuccess, onFailure, self.rtcAnswerConstraints);
  14842. } else {
  14843. createLocalDescription.call(self, 'offer', onSuccess, onFailure, self.rtcOfferConstraints);
  14844. }
  14845. }
  14846. }
  14847. /**
  14848. * In dialog UPDATE Reception
  14849. */
  14850. function receiveUpdate(request) {
  14851. debug('receiveUpdate()');
  14852. var
  14853. sdp, idx, direction, m,
  14854. self = this,
  14855. contentType = request.getHeader('Content-Type'),
  14856. rejected = false,
  14857. hold = false,
  14858. data = {
  14859. request: request,
  14860. callback: undefined,
  14861. reject: reject.bind(this)
  14862. };
  14863. function reject(options) {
  14864. options = options || {};
  14865. rejected = true;
  14866. var
  14867. status_code = options.status_code || 403,
  14868. reason_phrase = options.reason_phrase || '',
  14869. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [];
  14870. if (this.status !== C.STATUS_CONFIRMED) {
  14871. return false;
  14872. }
  14873. if (status_code < 300 || status_code >= 700) {
  14874. throw new TypeError('Invalid status_code: '+ status_code);
  14875. }
  14876. request.reply(status_code, reason_phrase, extraHeaders);
  14877. }
  14878. // Emit 'update'.
  14879. this.emit('update', data);
  14880. if (rejected) {
  14881. return;
  14882. }
  14883. if (! request.body) {
  14884. var extraHeaders = [];
  14885. handleSessionTimersInIncomingRequest.call(this, request, extraHeaders);
  14886. request.reply(200, null, extraHeaders);
  14887. return;
  14888. }
  14889. if (contentType !== 'application/sdp') {
  14890. debug('invalid Content-Type');
  14891. request.reply(415);
  14892. return;
  14893. }
  14894. sdp = request.parseSDP();
  14895. for (idx=0; idx < sdp.media.length; idx++) {
  14896. m = sdp.media[idx];
  14897. if (holdMediaTypes.indexOf(m.type) === -1) {
  14898. continue;
  14899. }
  14900. direction = m.direction || sdp.direction || 'sendrecv';
  14901. if (direction === 'sendonly' || direction === 'inactive') {
  14902. hold = true;
  14903. }
  14904. // If at least one of the streams is active don't emit 'hold'.
  14905. else {
  14906. hold = false;
  14907. break;
  14908. }
  14909. }
  14910. var e = {originator:'remote', type:'offer', sdp:request.body};
  14911. debug('emit "sdp"');
  14912. this.emit('sdp', e);
  14913. var offer = new RTCSessionDescription({type:'offer', sdp:e.sdp});
  14914. this.connection.setRemoteDescription(offer)
  14915. .then(function() {
  14916. if (self.remoteHold === true && hold === false) {
  14917. self.remoteHold = false;
  14918. onunhold.call(self, 'remote');
  14919. } else if (self.remoteHold === false && hold === true) {
  14920. self.remoteHold = true;
  14921. onhold.call(self, 'remote');
  14922. }
  14923. createLocalDescription.call(self, 'answer',
  14924. // success
  14925. function(sdp) {
  14926. var extraHeaders = ['Contact: ' + self.contact];
  14927. handleSessionTimersInIncomingRequest.call(self, request, extraHeaders);
  14928. request.reply(200, null, extraHeaders, sdp);
  14929. // If callback is given execute it.
  14930. if (typeof data.callback === 'function') {
  14931. data.callback();
  14932. }
  14933. },
  14934. // failure
  14935. function() {
  14936. request.reply(500);
  14937. }
  14938. );
  14939. })
  14940. .catch(function(error) {
  14941. request.reply(488);
  14942. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  14943. self.emit('peerconnection:setremotedescriptionfailed', error);
  14944. });
  14945. }
  14946. /**
  14947. * In dialog Refer Reception
  14948. */
  14949. function receiveRefer(request) {
  14950. debug('receiveRefer()');
  14951. var notifier,
  14952. self = this;
  14953. function accept(initCallback, options) {
  14954. var session, replaces;
  14955. options = options || {};
  14956. initCallback = (typeof initCallback === 'function')? initCallback : null;
  14957. if (this.status !== C.STATUS_WAITING_FOR_ACK && this.status !== C.STATUS_CONFIRMED) {
  14958. return false;
  14959. }
  14960. session = new RTCSession(this.ua);
  14961. session.on('progress', function(e) {
  14962. notifier.notify(e.response.status_code, e.response.reason_phrase);
  14963. });
  14964. session.on('accepted', function(e) {
  14965. notifier.notify(e.response.status_code, e.response.reason_phrase);
  14966. });
  14967. session.on('failed', function(e) {
  14968. if (e.message) {
  14969. notifier.notify(e.message.status_code, e.message.reason_phrase);
  14970. } else {
  14971. notifier.notify(487, e.cause);
  14972. }
  14973. });
  14974. // Consider the Replaces header present in the Refer-To URI
  14975. if (request.refer_to.uri.hasHeader('replaces')) {
  14976. replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces'));
  14977. options.extraHeaders = options.extraHeaders || [];
  14978. options.extraHeaders.push('Replaces: '+ replaces);
  14979. }
  14980. session.connect(request.refer_to.uri.toAor(), options, initCallback);
  14981. }
  14982. function reject() {
  14983. notifier.notify(603);
  14984. }
  14985. if (typeof request.refer_to === undefined) {
  14986. debug('no Refer-To header field present in REFER');
  14987. request.reply(400);
  14988. return;
  14989. }
  14990. if (request.refer_to.uri.scheme !== JsSIP_C.SIP) {
  14991. debug('Refer-To header field points to a non-SIP URI scheme');
  14992. request.reply(416);
  14993. return;
  14994. }
  14995. // reply before the transaction timer expires
  14996. request.reply(202);
  14997. notifier = new RTCSession_ReferNotifier(this, request.cseq);
  14998. debug('emit "refer"');
  14999. // Emit 'refer'.
  15000. this.emit('refer', {
  15001. request: request,
  15002. accept: function(initCallback, options) { accept.call(self, initCallback, options); },
  15003. reject: function() { reject.call(self); }
  15004. });
  15005. }
  15006. /**
  15007. * In dialog Notify Reception
  15008. */
  15009. function receiveNotify(request) {
  15010. debug('receiveNotify()');
  15011. if (typeof request.event === undefined) {
  15012. request.reply(400);
  15013. }
  15014. switch (request.event.event) {
  15015. case 'refer': {
  15016. var id = request.event.params.id;
  15017. var referSubscriber = this.referSubscribers[id];
  15018. if (!referSubscriber) {
  15019. request.reply(481, 'Subscription does not exist');
  15020. return;
  15021. }
  15022. referSubscriber.receiveNotify(request);
  15023. request.reply(200);
  15024. break;
  15025. }
  15026. default: {
  15027. request.reply(489);
  15028. }
  15029. }
  15030. }
  15031. /**
  15032. * INVITE with Replaces Reception
  15033. */
  15034. function receiveReplaces(request) {
  15035. debug('receiveReplaces()');
  15036. var self = this;
  15037. function accept(initCallback) {
  15038. var session;
  15039. if (this.status !== C.STATUS_WAITING_FOR_ACK && this.status !== C.STATUS_CONFIRMED) {
  15040. return false;
  15041. }
  15042. session = new RTCSession(this.ua);
  15043. // terminate the current session when the new one is confirmed
  15044. session.on('confirmed', function() {
  15045. self.terminate();
  15046. });
  15047. session.init_incoming(request, initCallback);
  15048. }
  15049. function reject() {
  15050. debug('Replaced INVITE rejected by the user');
  15051. request.reply(486);
  15052. }
  15053. // Emit 'replace'.
  15054. this.emit('replaces', {
  15055. request: request,
  15056. accept: function(initCallback) { accept.call(self, initCallback); },
  15057. reject: function() { reject.call(self); }
  15058. });
  15059. }
  15060. /**
  15061. * Initial Request Sender
  15062. */
  15063. function sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) {
  15064. var self = this;
  15065. var request_sender = new RequestSender(self, this.ua);
  15066. this.receiveResponse = function(response) {
  15067. receiveInviteResponse.call(self, response);
  15068. };
  15069. // If a local MediaStream is given use it.
  15070. if (mediaStream) {
  15071. // Wait a bit so the app can set events such as 'peerconnection' and 'connecting'.
  15072. setTimeout(function() {
  15073. userMediaSucceeded(mediaStream);
  15074. });
  15075. // If at least audio or video is requested prompt getUserMedia.
  15076. } else if (mediaConstraints.audio || mediaConstraints.video) {
  15077. this.localMediaStreamLocallyGenerated = true;
  15078. navigator.mediaDevices.getUserMedia(mediaConstraints)
  15079. .then(userMediaSucceeded)
  15080. .catch(function(error)
  15081. {
  15082. userMediaFailed(error);
  15083. debugerror('emit "getusermediafailed" [error:%o]', error);
  15084. self.emit('getusermediafailed', error);
  15085. });
  15086. // Otherwise don't prompt getUserMedia.
  15087. } else {
  15088. userMediaSucceeded(null);
  15089. }
  15090. // User media succeeded
  15091. function userMediaSucceeded(stream) {
  15092. if (self.status === C.STATUS_TERMINATED) { return; }
  15093. self.localMediaStream = stream;
  15094. if (stream) {
  15095. self.connection.addStream(stream);
  15096. }
  15097. debug('emit "peerconnection"');
  15098. // Notify the app with the RTCPeerConnection so it can do stuff on it
  15099. // before generating the offer.
  15100. self.emit('peerconnection', {
  15101. peerconnection: self.connection
  15102. });
  15103. connecting.call(self, self.request);
  15104. createLocalDescription.call(self, 'offer', rtcSucceeded, rtcFailed, rtcOfferConstraints);
  15105. }
  15106. // User media failed
  15107. function userMediaFailed() {
  15108. if (self.status === C.STATUS_TERMINATED) { return; }
  15109. failed.call(self, 'local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  15110. }
  15111. function rtcSucceeded(desc) {
  15112. if (self.isCanceled || self.status === C.STATUS_TERMINATED) { return; }
  15113. self.request.body = desc;
  15114. self.status = C.STATUS_INVITE_SENT;
  15115. debug('emit "sending" [request:%o]', self.request);
  15116. // Emit 'sending' so the app can mangle the body before the request
  15117. // is sent.
  15118. self.emit('sending', {
  15119. request: self.request
  15120. });
  15121. request_sender.send();
  15122. }
  15123. function rtcFailed() {
  15124. if (self.status === C.STATUS_TERMINATED) { return; }
  15125. failed.call(self, 'system', null, JsSIP_C.causes.WEBRTC_ERROR);
  15126. }
  15127. }
  15128. /**
  15129. * Reception of Response for Initial INVITE
  15130. */
  15131. function receiveInviteResponse(response) {
  15132. debug('receiveInviteResponse()');
  15133. var cause, dialog, e, answer,
  15134. self = this;
  15135. // Handle 2XX retransmissions and responses from forked requests
  15136. if (this.dialog && (response.status_code >=200 && response.status_code <=299)) {
  15137. /*
  15138. * If it is a retransmission from the endpoint that established
  15139. * the dialog, send an ACK
  15140. */
  15141. if (this.dialog.id.call_id === response.call_id &&
  15142. this.dialog.id.local_tag === response.from_tag &&
  15143. this.dialog.id.remote_tag === response.to_tag) {
  15144. sendRequest.call(this, JsSIP_C.ACK);
  15145. return;
  15146. }
  15147. // If not, send an ACK and terminate
  15148. else {
  15149. dialog = new Dialog(this, response, 'UAC');
  15150. if (dialog.error !== undefined) {
  15151. debug(dialog.error);
  15152. return;
  15153. }
  15154. dialog.sendRequest({
  15155. owner: {status: C.STATUS_TERMINATED},
  15156. onRequestTimeout: function(){},
  15157. onTransportError: function(){},
  15158. onDialogError: function(){},
  15159. receiveResponse: function(){}
  15160. }, JsSIP_C.ACK);
  15161. dialog.sendRequest({
  15162. owner: {status: C.STATUS_TERMINATED},
  15163. onRequestTimeout: function(){},
  15164. onTransportError: function(){},
  15165. onDialogError: function(){},
  15166. receiveResponse: function(){}
  15167. }, JsSIP_C.BYE);
  15168. return;
  15169. }
  15170. }
  15171. // Proceed to cancellation if the user requested.
  15172. if(this.isCanceled) {
  15173. // Remove the flag. We are done.
  15174. this.isCanceled = false;
  15175. if(response.status_code >= 100 && response.status_code < 200) {
  15176. this.request.cancel(this.cancelReason);
  15177. } else if(response.status_code >= 200 && response.status_code < 299) {
  15178. acceptAndTerminate.call(this, response);
  15179. }
  15180. return;
  15181. }
  15182. if(this.status !== C.STATUS_INVITE_SENT && this.status !== C.STATUS_1XX_RECEIVED) {
  15183. return;
  15184. }
  15185. switch(true) {
  15186. case /^100$/.test(response.status_code):
  15187. this.status = C.STATUS_1XX_RECEIVED;
  15188. break;
  15189. case /^1[0-9]{2}$/.test(response.status_code):
  15190. // Do nothing with 1xx responses without To tag.
  15191. if (!response.to_tag) {
  15192. debug('1xx response received without to tag');
  15193. break;
  15194. }
  15195. // Create Early Dialog if 1XX comes with contact
  15196. if (response.hasHeader('contact')) {
  15197. // An error on dialog creation will fire 'failed' event
  15198. if(! createDialog.call(this, response, 'UAC', true)) {
  15199. break;
  15200. }
  15201. }
  15202. this.status = C.STATUS_1XX_RECEIVED;
  15203. progress.call(this, 'remote', response);
  15204. if (!response.body) {
  15205. break;
  15206. }
  15207. e = {originator:'remote', type:'answer', sdp:response.body};
  15208. debug('emit "sdp"');
  15209. this.emit('sdp', e);
  15210. answer = new RTCSessionDescription({type:'answer', sdp:e.sdp});
  15211. this.connection.setRemoteDescription(answer)
  15212. .catch(function(error) {
  15213. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15214. self.emit('peerconnection:setremotedescriptionfailed', error);
  15215. });
  15216. break;
  15217. case /^2[0-9]{2}$/.test(response.status_code):
  15218. this.status = C.STATUS_CONFIRMED;
  15219. if(!response.body) {
  15220. acceptAndTerminate.call(this, response, 400, JsSIP_C.causes.MISSING_SDP);
  15221. failed.call(this, 'remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  15222. break;
  15223. }
  15224. // An error on dialog creation will fire 'failed' event
  15225. if (! createDialog.call(this, response, 'UAC')) {
  15226. break;
  15227. }
  15228. e = {originator:'remote', type:'answer', sdp:response.body};
  15229. debug('emit "sdp"');
  15230. this.emit('sdp', e);
  15231. answer = new RTCSessionDescription({type:'answer', sdp:e.sdp});
  15232. Promise.resolve()
  15233. .then(function() {
  15234. // Be ready for 200 with SDP after a 180/183 with SDP. We created a SDP 'answer'
  15235. // for it, so check the current signaling state.
  15236. if (self.connection.signalingState === 'stable') {
  15237. return self.connection.createOffer()
  15238. .then(function(offer) {
  15239. return self.connection.setLocalDescription(offer);
  15240. })
  15241. .catch(function(error) {
  15242. acceptAndTerminate.call(self, response, 500, error.toString());
  15243. failed.call(self, 'local', response, JsSIP_C.causes.WEBRTC_ERROR);
  15244. debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error);
  15245. self.emit('peerconnection:setlocaldescriptionfailed', error);
  15246. });
  15247. }
  15248. })
  15249. .then(function() {
  15250. self.connection.setRemoteDescription(answer)
  15251. .then(function() {
  15252. // Handle Session Timers.
  15253. handleSessionTimersInIncomingResponse.call(self, response);
  15254. accepted.call(self, 'remote', response);
  15255. sendRequest.call(self, JsSIP_C.ACK);
  15256. confirmed.call(self, 'local', null);
  15257. })
  15258. .catch(function(error) {
  15259. acceptAndTerminate.call(self, response, 488, 'Not Acceptable Here');
  15260. failed.call(self, 'remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  15261. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15262. self.emit('peerconnection:setremotedescriptionfailed', error);
  15263. });
  15264. });
  15265. break;
  15266. default:
  15267. cause = Utils.sipErrorCause(response.status_code);
  15268. failed.call(this, 'remote', response, cause);
  15269. }
  15270. }
  15271. /**
  15272. * Send Re-INVITE
  15273. */
  15274. function sendReinvite(options) {
  15275. debug('sendReinvite()');
  15276. options = options || {};
  15277. var
  15278. self = this,
  15279. extraHeaders = options.extraHeaders || [],
  15280. eventHandlers = options.eventHandlers || {},
  15281. rtcOfferConstraints = options.rtcOfferConstraints || this.rtcOfferConstraints || null,
  15282. succeeded = false;
  15283. extraHeaders.push('Contact: ' + this.contact);
  15284. extraHeaders.push('Content-Type: application/sdp');
  15285. // Session Timers.
  15286. if (this.sessionTimers.running) {
  15287. extraHeaders.push('Session-Expires: ' + this.sessionTimers.currentExpires + ';refresher=' + (this.sessionTimers.refresher ? 'uac' : 'uas'));
  15288. }
  15289. createLocalDescription.call(this, 'offer',
  15290. // success
  15291. function(sdp) {
  15292. sdp = mangleOffer.call(self, sdp);
  15293. var request = new RTCSession_Request(self, JsSIP_C.INVITE);
  15294. request.send({
  15295. extraHeaders: extraHeaders,
  15296. body: sdp,
  15297. eventHandlers: {
  15298. onSuccessResponse: function(response) {
  15299. onSucceeded(response);
  15300. succeeded = true;
  15301. },
  15302. onErrorResponse: function(response) {
  15303. onFailed(response);
  15304. },
  15305. onTransportError: function() {
  15306. self.onTransportError(); // Do nothing because session ends.
  15307. },
  15308. onRequestTimeout: function() {
  15309. self.onRequestTimeout(); // Do nothing because session ends.
  15310. },
  15311. onDialogError: function() {
  15312. self.onDialogError(); // Do nothing because session ends.
  15313. }
  15314. }
  15315. });
  15316. },
  15317. // failure
  15318. function() {
  15319. onFailed();
  15320. },
  15321. // RTC constraints.
  15322. rtcOfferConstraints
  15323. );
  15324. function onSucceeded(response) {
  15325. if (self.status === C.STATUS_TERMINATED) {
  15326. return;
  15327. }
  15328. sendRequest.call(self, JsSIP_C.ACK);
  15329. // If it is a 2XX retransmission exit now.
  15330. if (succeeded) { return; }
  15331. // Handle Session Timers.
  15332. handleSessionTimersInIncomingResponse.call(self, response);
  15333. // Must have SDP answer.
  15334. if(! response.body) {
  15335. onFailed();
  15336. return;
  15337. } else if (response.getHeader('Content-Type') !== 'application/sdp') {
  15338. onFailed();
  15339. return;
  15340. }
  15341. var e = {originator:'remote', type:'answer', sdp:response.body};
  15342. debug('emit "sdp"');
  15343. self.emit('sdp', e);
  15344. var answer = new RTCSessionDescription({type:'answer', sdp:e.sdp});
  15345. self.connection.setRemoteDescription(answer)
  15346. .then(function() {
  15347. if (eventHandlers.succeeded) {
  15348. eventHandlers.succeeded(response);
  15349. }
  15350. })
  15351. .catch(function(error) {
  15352. onFailed();
  15353. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15354. self.emit('peerconnection:setremotedescriptionfailed', error);
  15355. });
  15356. }
  15357. function onFailed(response) {
  15358. if (eventHandlers.failed) {
  15359. eventHandlers.failed(response);
  15360. }
  15361. }
  15362. }
  15363. /**
  15364. * Send UPDATE
  15365. */
  15366. function sendUpdate(options) {
  15367. debug('sendUpdate()');
  15368. options = options || {};
  15369. var
  15370. self = this,
  15371. extraHeaders = options.extraHeaders || [],
  15372. eventHandlers = options.eventHandlers || {},
  15373. rtcOfferConstraints = options.rtcOfferConstraints || this.rtcOfferConstraints || null,
  15374. sdpOffer = options.sdpOffer || false,
  15375. succeeded = false;
  15376. extraHeaders.push('Contact: ' + this.contact);
  15377. // Session Timers.
  15378. if (this.sessionTimers.running) {
  15379. extraHeaders.push('Session-Expires: ' + this.sessionTimers.currentExpires + ';refresher=' + (this.sessionTimers.refresher ? 'uac' : 'uas'));
  15380. }
  15381. if (sdpOffer) {
  15382. extraHeaders.push('Content-Type: application/sdp');
  15383. createLocalDescription.call(this, 'offer',
  15384. // success
  15385. function(sdp) {
  15386. sdp = mangleOffer.call(self, sdp);
  15387. var request = new RTCSession_Request(self, JsSIP_C.UPDATE);
  15388. request.send({
  15389. extraHeaders: extraHeaders,
  15390. body: sdp,
  15391. eventHandlers: {
  15392. onSuccessResponse: function(response) {
  15393. onSucceeded(response);
  15394. succeeded = true;
  15395. },
  15396. onErrorResponse: function(response) {
  15397. onFailed(response);
  15398. },
  15399. onTransportError: function() {
  15400. self.onTransportError(); // Do nothing because session ends.
  15401. },
  15402. onRequestTimeout: function() {
  15403. self.onRequestTimeout(); // Do nothing because session ends.
  15404. },
  15405. onDialogError: function() {
  15406. self.onDialogError(); // Do nothing because session ends.
  15407. }
  15408. }
  15409. });
  15410. },
  15411. // failure
  15412. function() {
  15413. onFailed();
  15414. },
  15415. // RTC constraints.
  15416. rtcOfferConstraints
  15417. );
  15418. }
  15419. // No SDP.
  15420. else {
  15421. var request = new RTCSession_Request(self, JsSIP_C.UPDATE);
  15422. request.send({
  15423. extraHeaders: extraHeaders,
  15424. eventHandlers: {
  15425. onSuccessResponse: function(response) {
  15426. onSucceeded(response);
  15427. },
  15428. onErrorResponse: function(response) {
  15429. onFailed(response);
  15430. },
  15431. onTransportError: function() {
  15432. self.onTransportError(); // Do nothing because session ends.
  15433. },
  15434. onRequestTimeout: function() {
  15435. self.onRequestTimeout(); // Do nothing because session ends.
  15436. },
  15437. onDialogError: function() {
  15438. self.onDialogError(); // Do nothing because session ends.
  15439. }
  15440. }
  15441. });
  15442. }
  15443. function onSucceeded(response) {
  15444. if (self.status === C.STATUS_TERMINATED) {
  15445. return;
  15446. }
  15447. // If it is a 2XX retransmission exit now.
  15448. if (succeeded) { return; }
  15449. // Handle Session Timers.
  15450. handleSessionTimersInIncomingResponse.call(self, response);
  15451. // Must have SDP answer.
  15452. if (sdpOffer) {
  15453. if(! response.body) {
  15454. onFailed();
  15455. return;
  15456. } else if (response.getHeader('Content-Type') !== 'application/sdp') {
  15457. onFailed();
  15458. return;
  15459. }
  15460. var e = {originator:'remote', type:'answer', sdp:response.body};
  15461. debug('emit "sdp"');
  15462. self.emit('sdp', e);
  15463. var answer = new RTCSessionDescription({type:'answer', sdp:e.sdp});
  15464. self.connection.setRemoteDescription(answer)
  15465. .then(function() {
  15466. if (eventHandlers.succeeded) {
  15467. eventHandlers.succeeded(response);
  15468. }
  15469. })
  15470. .catch(function(error) {
  15471. onFailed();
  15472. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15473. self.emit('peerconnection:setremotedescriptionfailed', error);
  15474. });
  15475. }
  15476. // No SDP answer.
  15477. else {
  15478. if (eventHandlers.succeeded) {
  15479. eventHandlers.succeeded(response);
  15480. }
  15481. }
  15482. }
  15483. function onFailed(response) {
  15484. if (eventHandlers.failed) { eventHandlers.failed(response); }
  15485. }
  15486. }
  15487. function acceptAndTerminate(response, status_code, reason_phrase) {
  15488. debug('acceptAndTerminate()');
  15489. var extraHeaders = [];
  15490. if (status_code) {
  15491. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  15492. extraHeaders.push('Reason: SIP ;cause=' + status_code + '; text="' + reason_phrase + '"');
  15493. }
  15494. // An error on dialog creation will fire 'failed' event
  15495. if (this.dialog || createDialog.call(this, response, 'UAC')) {
  15496. sendRequest.call(this, JsSIP_C.ACK);
  15497. sendRequest.call(this, JsSIP_C.BYE, {
  15498. extraHeaders: extraHeaders
  15499. });
  15500. }
  15501. // Update session status.
  15502. this.status = C.STATUS_TERMINATED;
  15503. }
  15504. /**
  15505. * Send a generic in-dialog Request
  15506. */
  15507. function sendRequest(method, options) {
  15508. debug('sendRequest()');
  15509. var request = new RTCSession_Request(this, method);
  15510. request.send(options);
  15511. }
  15512. /**
  15513. * Correctly set the SDP direction attributes if the call is on local hold
  15514. */
  15515. function mangleOffer(sdp) {
  15516. var idx, length, m;
  15517. if (! this.localHold && ! this.remoteHold) {
  15518. return sdp;
  15519. }
  15520. sdp = sdp_transform.parse(sdp);
  15521. // Local hold.
  15522. if (this.localHold && ! this.remoteHold) {
  15523. debug('mangleOffer() | me on hold, mangling offer');
  15524. length = sdp.media.length;
  15525. for (idx=0; idx<length; idx++) {
  15526. m = sdp.media[idx];
  15527. if (holdMediaTypes.indexOf(m.type) === -1) {
  15528. continue;
  15529. }
  15530. if (!m.direction) {
  15531. m.direction = 'sendonly';
  15532. } else if (m.direction === 'sendrecv') {
  15533. m.direction = 'sendonly';
  15534. } else if (m.direction === 'recvonly') {
  15535. m.direction = 'inactive';
  15536. }
  15537. }
  15538. }
  15539. // Local and remote hold.
  15540. else if (this.localHold && this.remoteHold) {
  15541. debug('mangleOffer() | both on hold, mangling offer');
  15542. length = sdp.media.length;
  15543. for (idx=0; idx<length; idx++) {
  15544. m = sdp.media[idx];
  15545. if (holdMediaTypes.indexOf(m.type) === -1) {
  15546. continue;
  15547. }
  15548. m.direction = 'inactive';
  15549. }
  15550. }
  15551. // Remote hold.
  15552. else if (this.remoteHold) {
  15553. debug('mangleOffer() | remote on hold, mangling offer');
  15554. length = sdp.media.length;
  15555. for (idx=0; idx<length; idx++) {
  15556. m = sdp.media[idx];
  15557. if (holdMediaTypes.indexOf(m.type) === -1) {
  15558. continue;
  15559. }
  15560. if (!m.direction) {
  15561. m.direction = 'recvonly';
  15562. } else if (m.direction === 'sendrecv') {
  15563. m.direction = 'recvonly';
  15564. } else if (m.direction === 'recvonly') {
  15565. m.direction = 'inactive';
  15566. }
  15567. }
  15568. }
  15569. return sdp_transform.write(sdp);
  15570. }
  15571. function setLocalMediaStatus() {
  15572. var enableAudio = true,
  15573. enableVideo = true;
  15574. if (this.localHold || this.remoteHold) {
  15575. enableAudio = false;
  15576. enableVideo = false;
  15577. }
  15578. if (this.audioMuted) {
  15579. enableAudio = false;
  15580. }
  15581. if (this.videoMuted) {
  15582. enableVideo = false;
  15583. }
  15584. toogleMuteAudio.call(this, !enableAudio);
  15585. toogleMuteVideo.call(this, !enableVideo);
  15586. }
  15587. /**
  15588. * Handle SessionTimers for an incoming INVITE or UPDATE.
  15589. * @param {IncomingRequest} request
  15590. * @param {Array} responseExtraHeaders Extra headers for the 200 response.
  15591. */
  15592. function handleSessionTimersInIncomingRequest(request, responseExtraHeaders) {
  15593. if (! this.sessionTimers.enabled) { return; }
  15594. var session_expires_refresher;
  15595. if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  15596. this.sessionTimers.currentExpires = request.session_expires;
  15597. session_expires_refresher = request.session_expires_refresher || 'uas';
  15598. }
  15599. else {
  15600. this.sessionTimers.currentExpires = this.sessionTimers.defaultExpires;
  15601. session_expires_refresher = 'uas';
  15602. }
  15603. responseExtraHeaders.push('Session-Expires: ' + this.sessionTimers.currentExpires + ';refresher=' + session_expires_refresher);
  15604. this.sessionTimers.refresher = (session_expires_refresher === 'uas');
  15605. runSessionTimer.call(this);
  15606. }
  15607. /**
  15608. * Handle SessionTimers for an incoming response to INVITE or UPDATE.
  15609. * @param {IncomingResponse} response
  15610. */
  15611. function handleSessionTimersInIncomingResponse(response) {
  15612. if (! this.sessionTimers.enabled) { return; }
  15613. var session_expires_refresher;
  15614. if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  15615. this.sessionTimers.currentExpires = response.session_expires;
  15616. session_expires_refresher = response.session_expires_refresher || 'uac';
  15617. }
  15618. else {
  15619. this.sessionTimers.currentExpires = this.sessionTimers.defaultExpires;
  15620. session_expires_refresher = 'uac';
  15621. }
  15622. this.sessionTimers.refresher = (session_expires_refresher === 'uac');
  15623. runSessionTimer.call(this);
  15624. }
  15625. function runSessionTimer() {
  15626. var self = this;
  15627. var expires = this.sessionTimers.currentExpires;
  15628. this.sessionTimers.running = true;
  15629. clearTimeout(this.sessionTimers.timer);
  15630. // I'm the refresher.
  15631. if (this.sessionTimers.refresher) {
  15632. this.sessionTimers.timer = setTimeout(function() {
  15633. if (self.status === C.STATUS_TERMINATED) { return; }
  15634. debug('runSessionTimer() | sending session refresh request');
  15635. sendUpdate.call(self, {
  15636. eventHandlers: {
  15637. succeeded: function(response) {
  15638. handleSessionTimersInIncomingResponse.call(self, response);
  15639. }
  15640. }
  15641. });
  15642. }, expires * 500); // Half the given interval (as the RFC states).
  15643. }
  15644. // I'm not the refresher.
  15645. else {
  15646. this.sessionTimers.timer = setTimeout(function() {
  15647. if (self.status === C.STATUS_TERMINATED) { return; }
  15648. debugerror('runSessionTimer() | timer expired, terminating the session');
  15649. self.terminate({
  15650. cause: JsSIP_C.causes.REQUEST_TIMEOUT,
  15651. status_code: 408,
  15652. reason_phrase: 'Session Timer Expired'
  15653. });
  15654. }, expires * 1100);
  15655. }
  15656. }
  15657. function toogleMuteAudio(mute) {
  15658. var streamIdx, trackIdx, streamsLength, tracksLength, tracks,
  15659. localStreams = this.connection.getLocalStreams();
  15660. streamsLength = localStreams.length;
  15661. for (streamIdx = 0; streamIdx < streamsLength; streamIdx++) {
  15662. tracks = localStreams[streamIdx].getAudioTracks();
  15663. tracksLength = tracks.length;
  15664. for (trackIdx = 0; trackIdx < tracksLength; trackIdx++) {
  15665. tracks[trackIdx].enabled = !mute;
  15666. }
  15667. }
  15668. }
  15669. function toogleMuteVideo(mute) {
  15670. var streamIdx, trackIdx, streamsLength, tracksLength, tracks,
  15671. localStreams = this.connection.getLocalStreams();
  15672. streamsLength = localStreams.length;
  15673. for (streamIdx = 0; streamIdx < streamsLength; streamIdx++) {
  15674. tracks = localStreams[streamIdx].getVideoTracks();
  15675. tracksLength = tracks.length;
  15676. for (trackIdx = 0; trackIdx < tracksLength; trackIdx++) {
  15677. tracks[trackIdx].enabled = !mute;
  15678. }
  15679. }
  15680. }
  15681. function newRTCSession(originator, request) {
  15682. debug('newRTCSession()');
  15683. this.ua.newRTCSession({
  15684. originator: originator,
  15685. session: this,
  15686. request: request
  15687. });
  15688. }
  15689. function connecting(request) {
  15690. debug('session connecting');
  15691. debug('emit "connecting"');
  15692. this.emit('connecting', {
  15693. request: request
  15694. });
  15695. }
  15696. function progress(originator, response) {
  15697. debug('session progress');
  15698. debug('emit "progress"');
  15699. this.emit('progress', {
  15700. originator: originator,
  15701. response: response || null
  15702. });
  15703. }
  15704. function accepted(originator, message) {
  15705. debug('session accepted');
  15706. this.start_time = new Date();
  15707. debug('emit "accepted"');
  15708. this.emit('accepted', {
  15709. originator: originator,
  15710. response: message || null
  15711. });
  15712. }
  15713. function confirmed(originator, ack) {
  15714. debug('session confirmed');
  15715. this.is_confirmed = true;
  15716. debug('emit "confirmed"');
  15717. this.emit('confirmed', {
  15718. originator: originator,
  15719. ack: ack || null
  15720. });
  15721. }
  15722. function ended(originator, message, cause) {
  15723. debug('session ended');
  15724. this.end_time = new Date();
  15725. this.close();
  15726. debug('emit "ended"');
  15727. this.emit('ended', {
  15728. originator: originator,
  15729. message: message || null,
  15730. cause: cause
  15731. });
  15732. }
  15733. function failed(originator, message, cause) {
  15734. debug('session failed');
  15735. this.close();
  15736. debug('emit "failed"');
  15737. this.emit('failed', {
  15738. originator: originator,
  15739. message: message || null,
  15740. cause: cause
  15741. });
  15742. }
  15743. function onhold(originator) {
  15744. debug('session onhold');
  15745. setLocalMediaStatus.call(this);
  15746. debug('emit "hold"');
  15747. this.emit('hold', {
  15748. originator: originator
  15749. });
  15750. }
  15751. function onunhold(originator) {
  15752. debug('session onunhold');
  15753. setLocalMediaStatus.call(this);
  15754. debug('emit "unhold"');
  15755. this.emit('unhold', {
  15756. originator: originator
  15757. });
  15758. }
  15759. function onmute(options) {
  15760. debug('session onmute');
  15761. setLocalMediaStatus.call(this);
  15762. debug('emit "muted"');
  15763. this.emit('muted', {
  15764. audio: options.audio,
  15765. video: options.video
  15766. });
  15767. }
  15768. function onunmute(options) {
  15769. debug('session onunmute');
  15770. setLocalMediaStatus.call(this);
  15771. debug('emit "unmuted"');
  15772. this.emit('unmuted', {
  15773. audio: options.audio,
  15774. video: options.video
  15775. });
  15776. }
  15777. },{"./Constants":1,"./Dialog":2,"./Exceptions":5,"./RTCSession/DTMF":12,"./RTCSession/Info":13,"./RTCSession/ReferNotifier":14,"./RTCSession/ReferSubscriber":15,"./RTCSession/Request":16,"./RequestSender":18,"./SIPMessage":19,"./Timers":21,"./Transactions":22,"./Utils":26,"debug":35,"events":29,"sdp-transform":38,"util":33}],12:[function(require,module,exports){
  15778. module.exports = DTMF;
  15779. var C = {
  15780. MIN_DURATION: 70,
  15781. MAX_DURATION: 6000,
  15782. DEFAULT_DURATION: 100,
  15783. MIN_INTER_TONE_GAP: 50,
  15784. DEFAULT_INTER_TONE_GAP: 500
  15785. };
  15786. /**
  15787. * Expose C object.
  15788. */
  15789. DTMF.C = C;
  15790. /**
  15791. * Dependencies.
  15792. */
  15793. var util = require('util');
  15794. var events = require('events');
  15795. var debug = require('debug')('JsSIP:RTCSession:DTMF');
  15796. var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF');
  15797. debugerror.log = console.warn.bind(console);
  15798. var JsSIP_C = require('../Constants');
  15799. var Exceptions = require('../Exceptions');
  15800. var RTCSession = require('../RTCSession');
  15801. function DTMF(session) {
  15802. this.owner = session;
  15803. this.direction = null;
  15804. this.tone = null;
  15805. this.duration = null;
  15806. events.EventEmitter.call(this);
  15807. }
  15808. util.inherits(DTMF, events.EventEmitter);
  15809. DTMF.prototype.send = function(tone, options) {
  15810. var extraHeaders, body;
  15811. if (tone === undefined) {
  15812. throw new TypeError('Not enough arguments');
  15813. }
  15814. this.direction = 'outgoing';
  15815. // Check RTCSession Status
  15816. if (this.owner.status !== RTCSession.C.STATUS_CONFIRMED &&
  15817. this.owner.status !== RTCSession.C.STATUS_WAITING_FOR_ACK) {
  15818. throw new Exceptions.InvalidStateError(this.owner.status);
  15819. }
  15820. // Get DTMF options
  15821. options = options || {};
  15822. extraHeaders = options.extraHeaders ? options.extraHeaders.slice() : [];
  15823. this.eventHandlers = options.eventHandlers || {};
  15824. // Check tone type
  15825. if (typeof tone === 'string' ) {
  15826. tone = tone.toUpperCase();
  15827. } else if (typeof tone === 'number') {
  15828. tone = tone.toString();
  15829. } else {
  15830. throw new TypeError('Invalid tone: '+ tone);
  15831. }
  15832. // Check tone value
  15833. if (!tone.match(/^[0-9A-DR#*]$/)) {
  15834. throw new TypeError('Invalid tone: '+ tone);
  15835. } else {
  15836. this.tone = tone;
  15837. }
  15838. // Duration is checked/corrected in RTCSession
  15839. this.duration = options.duration;
  15840. extraHeaders.push('Content-Type: application/dtmf-relay');
  15841. body = 'Signal=' + this.tone + '\r\n';
  15842. body += 'Duration=' + this.duration;
  15843. this.owner.newDTMF({
  15844. originator: 'local',
  15845. dtmf: this,
  15846. request: this.request
  15847. });
  15848. this.owner.dialog.sendRequest(this, JsSIP_C.INFO, {
  15849. extraHeaders: extraHeaders,
  15850. body: body
  15851. });
  15852. };
  15853. DTMF.prototype.receiveResponse = function(response) {
  15854. switch(true) {
  15855. case /^1[0-9]{2}$/.test(response.status_code):
  15856. // Ignore provisional responses.
  15857. break;
  15858. case /^2[0-9]{2}$/.test(response.status_code):
  15859. this.emit('succeeded', {
  15860. originator: 'remote',
  15861. response: response
  15862. });
  15863. break;
  15864. default:
  15865. if (this.eventHandlers.onFailed) {
  15866. this.eventHandlers.onFailed();
  15867. }
  15868. this.emit('failed', {
  15869. originator: 'remote',
  15870. response: response
  15871. });
  15872. break;
  15873. }
  15874. };
  15875. DTMF.prototype.onRequestTimeout = function() {
  15876. debugerror('onRequestTimeout');
  15877. this.owner.onRequestTimeout();
  15878. };
  15879. DTMF.prototype.onTransportError = function() {
  15880. debugerror('onTransportError');
  15881. this.owner.onTransportError();
  15882. };
  15883. DTMF.prototype.onDialogError = function() {
  15884. debugerror('onDialogError');
  15885. this.owner.onDialogError();
  15886. };
  15887. DTMF.prototype.init_incoming = function(request) {
  15888. var body,
  15889. reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/,
  15890. reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;
  15891. this.direction = 'incoming';
  15892. this.request = request;
  15893. request.reply(200);
  15894. if (request.body) {
  15895. body = request.body.split('\n');
  15896. if (body.length >= 1) {
  15897. if (reg_tone.test(body[0])) {
  15898. this.tone = body[0].replace(reg_tone,'$2');
  15899. }
  15900. }
  15901. if (body.length >=2) {
  15902. if (reg_duration.test(body[1])) {
  15903. this.duration = parseInt(body[1].replace(reg_duration,'$2'), 10);
  15904. }
  15905. }
  15906. }
  15907. if (!this.duration) {
  15908. this.duration = C.DEFAULT_DURATION;
  15909. }
  15910. if (!this.tone) {
  15911. debug('invalid INFO DTMF received, discarded');
  15912. } else {
  15913. this.owner.newDTMF({
  15914. originator: 'remote',
  15915. dtmf: this,
  15916. request: request
  15917. });
  15918. }
  15919. };
  15920. },{"../Constants":1,"../Exceptions":5,"../RTCSession":11,"debug":35,"events":29,"util":33}],13:[function(require,module,exports){
  15921. module.exports = Info;
  15922. /**
  15923. * Dependencies.
  15924. */
  15925. var util = require('util');
  15926. var events = require('events');
  15927. var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info');
  15928. debugerror.log = console.warn.bind(console);
  15929. var JsSIP_C = require('../Constants');
  15930. var Exceptions = require('../Exceptions');
  15931. var RTCSession = require('../RTCSession');
  15932. function Info(session) {
  15933. this.owner = session;
  15934. this.direction = null;
  15935. this.contentType = null;
  15936. this.body = null;
  15937. events.EventEmitter.call(this);
  15938. }
  15939. util.inherits(Info, events.EventEmitter);
  15940. Info.prototype.send = function(contentType, body, options) {
  15941. var extraHeaders;
  15942. this.direction = 'outgoing';
  15943. if (contentType === undefined) {
  15944. throw new TypeError('Not enough arguments');
  15945. }
  15946. // Check RTCSession Status
  15947. if (this.owner.status !== RTCSession.C.STATUS_CONFIRMED &&
  15948. this.owner.status !== RTCSession.C.STATUS_WAITING_FOR_ACK) {
  15949. throw new Exceptions.InvalidStateError(this.owner.status);
  15950. }
  15951. this.contentType = contentType;
  15952. this.body = body;
  15953. // Get Info options
  15954. options = options || {};
  15955. extraHeaders = options.extraHeaders ? options.extraHeaders.slice() : [];
  15956. extraHeaders.push('Content-Type: '+ contentType);
  15957. this.owner.newInfo({
  15958. originator: 'local',
  15959. info: this,
  15960. request: this.request
  15961. });
  15962. this.owner.dialog.sendRequest(this, JsSIP_C.INFO, {
  15963. extraHeaders: extraHeaders,
  15964. body: body
  15965. });
  15966. };
  15967. Info.prototype.receiveResponse = function(response) {
  15968. switch(true) {
  15969. case /^1[0-9]{2}$/.test(response.status_code):
  15970. // Ignore provisional responses.
  15971. break;
  15972. case /^2[0-9]{2}$/.test(response.status_code):
  15973. this.emit('succeeded', {
  15974. originator: 'remote',
  15975. response: response
  15976. });
  15977. break;
  15978. default:
  15979. this.emit('failed', {
  15980. originator: 'remote',
  15981. response: response
  15982. });
  15983. break;
  15984. }
  15985. };
  15986. Info.prototype.onRequestTimeout = function() {
  15987. debugerror('onRequestTimeout');
  15988. this.owner.onRequestTimeout();
  15989. };
  15990. Info.prototype.onTransportError = function() {
  15991. debugerror('onTransportError');
  15992. this.owner.onTransportError();
  15993. };
  15994. Info.prototype.onDialogError = function() {
  15995. debugerror('onDialogError');
  15996. this.owner.onDialogError();
  15997. };
  15998. Info.prototype.init_incoming = function(request) {
  15999. this.direction = 'incoming';
  16000. this.request = request;
  16001. request.reply(200);
  16002. this.contentType = request.getHeader('content-type');
  16003. this.body = request.body;
  16004. this.owner.newInfo({
  16005. originator: 'remote',
  16006. info: this,
  16007. request: request
  16008. });
  16009. };
  16010. },{"../Constants":1,"../Exceptions":5,"../RTCSession":11,"debug":35,"events":29,"util":33}],14:[function(require,module,exports){
  16011. module.exports = ReferNotifier;
  16012. var C = {
  16013. event_type: 'refer',
  16014. body_type: 'message/sipfrag;version=2.0',
  16015. expires: 300
  16016. };
  16017. /**
  16018. * Dependencies.
  16019. */
  16020. var debug = require('debug')('JsSIP:RTCSession:ReferNotifier');
  16021. var JsSIP_C = require('../Constants');
  16022. var RTCSession_Request = require('./Request');
  16023. function ReferNotifier(session, id, expires) {
  16024. this.session = session;
  16025. this.id = id;
  16026. this.expires = expires || C.expires;
  16027. this.active = true;
  16028. // The creation of a Notifier results in an immediate NOTIFY
  16029. this.notify(100);
  16030. }
  16031. ReferNotifier.prototype.notify = function(code, reason) {
  16032. debug('notify()');
  16033. var state,
  16034. self = this;
  16035. if (this.active === false) {
  16036. return;
  16037. }
  16038. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  16039. if (code >= 200) {
  16040. state = 'terminated;reason=noresource';
  16041. } else {
  16042. state = 'active;expires='+ this.expires;
  16043. }
  16044. // put this in a try/catch block
  16045. var request = new RTCSession_Request(this.session, JsSIP_C.NOTIFY);
  16046. request.send({
  16047. extraHeaders: [
  16048. 'Event: '+ C.event_type +';id='+ self.id,
  16049. 'Subscription-State: '+ state,
  16050. 'Content-Type: '+ C.body_type
  16051. ],
  16052. body: 'SIP/2.0 ' + code + ' ' + reason,
  16053. eventHandlers: {
  16054. // if a negative response is received, subscription is canceled
  16055. onErrorResponse: function() { self.active = false; }
  16056. }
  16057. });
  16058. };
  16059. },{"../Constants":1,"./Request":16,"debug":35}],15:[function(require,module,exports){
  16060. module.exports = ReferSubscriber;
  16061. var C = {
  16062. expires: 120
  16063. };
  16064. /**
  16065. * Dependencies.
  16066. */
  16067. var util = require('util');
  16068. var events = require('events');
  16069. var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber');
  16070. var JsSIP_C = require('../Constants');
  16071. var Grammar = require('../Grammar');
  16072. var RTCSession_Request = require('./Request');
  16073. function ReferSubscriber(session) {
  16074. this.session = session;
  16075. this.timer = null;
  16076. // Instance of REFER OutgoingRequest
  16077. this.outgoingRequest = null;
  16078. events.EventEmitter.call(this);
  16079. }
  16080. util.inherits(ReferSubscriber, events.EventEmitter);
  16081. ReferSubscriber.prototype.sendRefer = function(target, options) {
  16082. debug('sendRefer()');
  16083. var extraHeaders, eventHandlers, referTo,
  16084. replaces = null,
  16085. self = this;
  16086. // Get REFER options
  16087. options = options || {};
  16088. extraHeaders = options.extraHeaders ? options.extraHeaders.slice() : [];
  16089. eventHandlers = options.eventHandlers || {};
  16090. // Set event handlers
  16091. for (var event in eventHandlers) {
  16092. this.on(event, eventHandlers[event]);
  16093. }
  16094. // Replaces URI header field
  16095. if (options.replaces) {
  16096. replaces = options.replaces.request.call_id;
  16097. replaces += ';to-tag='+ options.replaces.to_tag;
  16098. replaces += ';from-tag='+ options.replaces.from_tag;
  16099. replaces = encodeURIComponent(replaces);
  16100. }
  16101. // Refer-To header field
  16102. referTo = 'Refer-To: <'+ target + (replaces?'?Replaces='+ replaces:'') +'>';
  16103. extraHeaders.push(referTo);
  16104. var request = new RTCSession_Request(this.session, JsSIP_C.REFER);
  16105. this.timer = setTimeout(function() {
  16106. removeSubscriber.call(self);
  16107. }, C.expires * 1000);
  16108. request.send({
  16109. extraHeaders: extraHeaders,
  16110. eventHandlers: {
  16111. onSuccessResponse: function(response) {
  16112. self.emit('requestSucceeded', {
  16113. response: response
  16114. });
  16115. },
  16116. onErrorResponse: function(response) {
  16117. self.emit('requestFailed', {
  16118. response: response,
  16119. cause: JsSIP_C.causes.REJECTED
  16120. });
  16121. },
  16122. onTransportError: function() {
  16123. removeSubscriber.call(self);
  16124. self.emit('requestFailed', {
  16125. response: null,
  16126. cause: JsSIP_C.causes.CONNECTION_ERROR
  16127. });
  16128. },
  16129. onRequestTimeout: function() {
  16130. removeSubscriber.call(self);
  16131. self.emit('requestFailed', {
  16132. response: null,
  16133. cause: JsSIP_C.causes.REQUEST_TIMEOUT
  16134. });
  16135. },
  16136. onDialogError: function() {
  16137. removeSubscriber.call(self);
  16138. self.emit('requestFailed', {
  16139. response: null,
  16140. cause: JsSIP_C.causes.DIALOG_ERROR
  16141. });
  16142. }
  16143. }
  16144. });
  16145. this.outgoingRequest = request.outgoingRequest;
  16146. };
  16147. ReferSubscriber.prototype.receiveNotify = function(request) {
  16148. debug('receiveNotify()');
  16149. var status_line;
  16150. if (!request.body) {
  16151. return;
  16152. }
  16153. status_line = Grammar.parse(request.body, 'Status_Line');
  16154. if(status_line === -1) {
  16155. debug('receiveNotify() | error parsing NOTIFY body: "' + request.body + '"');
  16156. return;
  16157. }
  16158. switch(true) {
  16159. case /^100$/.test(status_line.status_code):
  16160. this.emit('trying', {
  16161. request: request,
  16162. status_line: status_line
  16163. });
  16164. break;
  16165. case /^1[0-9]{2}$/.test(status_line.status_code):
  16166. this.emit('progress', {
  16167. request: request,
  16168. status_line: status_line
  16169. });
  16170. break;
  16171. case /^2[0-9]{2}$/.test(status_line.status_code):
  16172. removeSubscriber.call(this);
  16173. this.emit('accepted', {
  16174. request: request,
  16175. status_line: status_line
  16176. });
  16177. break;
  16178. default:
  16179. removeSubscriber.call(this);
  16180. this.emit('failed', {
  16181. request: request,
  16182. status_line: status_line
  16183. });
  16184. break;
  16185. }
  16186. };
  16187. // remove refer subscriber from the session
  16188. function removeSubscriber() {
  16189. console.log('removeSubscriber()');
  16190. clearTimeout(this.timer);
  16191. this.session.referSubscriber = null;
  16192. }
  16193. },{"../Constants":1,"../Grammar":6,"./Request":16,"debug":35,"events":29,"util":33}],16:[function(require,module,exports){
  16194. module.exports = Request;
  16195. /**
  16196. * Dependencies.
  16197. */
  16198. var debug = require('debug')('JsSIP:RTCSession:Request');
  16199. var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Request');
  16200. debugerror.log = console.warn.bind(console);
  16201. var JsSIP_C = require('../Constants');
  16202. var Exceptions = require('../Exceptions');
  16203. var RTCSession = require('../RTCSession');
  16204. function Request(session, method) {
  16205. debug('new | %s', method);
  16206. this.session = session;
  16207. this.method = method;
  16208. // Instance of OutgoingRequest
  16209. this.outgoingRequest = null;
  16210. // Check RTCSession Status
  16211. if (this.session.status !== RTCSession.C.STATUS_1XX_RECEIVED &&
  16212. this.session.status !== RTCSession.C.STATUS_WAITING_FOR_ANSWER &&
  16213. this.session.status !== RTCSession.C.STATUS_WAITING_FOR_ACK &&
  16214. this.session.status !== RTCSession.C.STATUS_CONFIRMED &&
  16215. this.session.status !== RTCSession.C.STATUS_TERMINATED) {
  16216. throw new Exceptions.InvalidStateError(this.session.status);
  16217. }
  16218. /*
  16219. * Allow sending BYE in TERMINATED status since the RTCSession
  16220. * could had been terminated before the ACK had arrived.
  16221. * RFC3261 Section 15, Paragraph 2
  16222. */
  16223. else if (this.session.status === RTCSession.C.STATUS_TERMINATED && method !== JsSIP_C.BYE) {
  16224. throw new Exceptions.InvalidStateError(this.session.status);
  16225. }
  16226. }
  16227. Request.prototype.send = function(options) {
  16228. options = options || {};
  16229. var
  16230. extraHeaders = options.extraHeaders && options.extraHeaders.slice() || [],
  16231. body = options.body || null;
  16232. this.eventHandlers = options.eventHandlers || {};
  16233. this.outgoingRequest = this.session.dialog.sendRequest(this, this.method, {
  16234. extraHeaders: extraHeaders,
  16235. body: body
  16236. });
  16237. };
  16238. Request.prototype.receiveResponse = function(response) {
  16239. switch(true) {
  16240. case /^1[0-9]{2}$/.test(response.status_code):
  16241. debug('onProgressResponse');
  16242. if (this.eventHandlers.onProgressResponse) { this.eventHandlers.onProgressResponse(response); }
  16243. break;
  16244. case /^2[0-9]{2}$/.test(response.status_code):
  16245. debug('onSuccessResponse');
  16246. if (this.eventHandlers.onSuccessResponse) { this.eventHandlers.onSuccessResponse(response); }
  16247. break;
  16248. default:
  16249. debug('onErrorResponse');
  16250. if (this.eventHandlers.onErrorResponse) { this.eventHandlers.onErrorResponse(response); }
  16251. break;
  16252. }
  16253. };
  16254. Request.prototype.onRequestTimeout = function() {
  16255. debugerror('onRequestTimeout');
  16256. if (this.eventHandlers.onRequestTimeout) { this.eventHandlers.onRequestTimeout(); }
  16257. };
  16258. Request.prototype.onTransportError = function() {
  16259. debugerror('onTransportError');
  16260. if (this.eventHandlers.onTransportError) { this.eventHandlers.onTransportError(); }
  16261. };
  16262. Request.prototype.onDialogError = function() {
  16263. debugerror('onDialogError');
  16264. if (this.eventHandlers.onDialogError) { this.eventHandlers.onDialogError(); }
  16265. };
  16266. },{"../Constants":1,"../Exceptions":5,"../RTCSession":11,"debug":35}],17:[function(require,module,exports){
  16267. module.exports = Registrator;
  16268. /**
  16269. * Dependecies
  16270. */
  16271. var debug = require('debug')('JsSIP:Registrator');
  16272. var Utils = require('./Utils');
  16273. var JsSIP_C = require('./Constants');
  16274. var SIPMessage = require('./SIPMessage');
  16275. var RequestSender = require('./RequestSender');
  16276. function Registrator(ua, transport) {
  16277. var reg_id=1; //Force reg_id to 1.
  16278. this.ua = ua;
  16279. this.transport = transport;
  16280. this.registrar = ua.configuration.registrar_server;
  16281. this.expires = ua.configuration.register_expires;
  16282. // Call-ID and CSeq values RFC3261 10.2
  16283. this.call_id = Utils.createRandomToken(22);
  16284. this.cseq = 0;
  16285. // this.to_uri
  16286. this.to_uri = ua.configuration.uri;
  16287. this.registrationTimer = null;
  16288. // Ongoing Register request
  16289. this.registering = false;
  16290. // Set status
  16291. this.registered = false;
  16292. // Contact header
  16293. this.contact = this.ua.contact.toString();
  16294. // sip.ice media feature tag (RFC 5768)
  16295. this.contact += ';+sip.ice';
  16296. // Custom headers for REGISTER and un-REGISTER.
  16297. this.extraHeaders = [];
  16298. // Custom Contact header params for REGISTER and un-REGISTER.
  16299. this.extraContactParams = '';
  16300. if(reg_id) {
  16301. this.contact += ';reg-id='+ reg_id;
  16302. this.contact += ';+sip.instance="<urn:uuid:'+ this.ua.configuration.instance_id+'>"';
  16303. }
  16304. }
  16305. Registrator.prototype = {
  16306. setExtraHeaders: function(extraHeaders) {
  16307. if (! Array.isArray(extraHeaders)) {
  16308. extraHeaders = [];
  16309. }
  16310. this.extraHeaders = extraHeaders.slice();
  16311. },
  16312. setExtraContactParams: function(extraContactParams) {
  16313. if (! (extraContactParams instanceof Object)) {
  16314. extraContactParams = {};
  16315. }
  16316. // Reset it.
  16317. this.extraContactParams = '';
  16318. for(var param_key in extraContactParams) {
  16319. var param_value = extraContactParams[param_key];
  16320. this.extraContactParams += (';' + param_key);
  16321. if (param_value) {
  16322. this.extraContactParams += ('=' + param_value);
  16323. }
  16324. }
  16325. },
  16326. register: function() {
  16327. var request_sender, cause, extraHeaders,
  16328. self = this;
  16329. if (this.registering) {
  16330. debug('Register request in progress...');
  16331. return;
  16332. }
  16333. extraHeaders = this.extraHeaders.slice();
  16334. extraHeaders.push('Contact: ' + this.contact + ';expires=' + this.expires + this.extraContactParams);
  16335. extraHeaders.push('Expires: '+ this.expires);
  16336. this.request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this.registrar, this.ua, {
  16337. 'to_uri': this.to_uri,
  16338. 'call_id': this.call_id,
  16339. 'cseq': (this.cseq += 1)
  16340. }, extraHeaders);
  16341. request_sender = new RequestSender(this, this.ua);
  16342. this.receiveResponse = function(response) {
  16343. var contact, expires,
  16344. contacts = response.getHeaders('contact').length;
  16345. // Discard responses to older REGISTER/un-REGISTER requests.
  16346. if(response.cseq !== this.cseq) {
  16347. return;
  16348. }
  16349. // Clear registration timer
  16350. if (this.registrationTimer !== null) {
  16351. clearTimeout(this.registrationTimer);
  16352. this.registrationTimer = null;
  16353. }
  16354. switch(true) {
  16355. case /^1[0-9]{2}$/.test(response.status_code):
  16356. // Ignore provisional responses.
  16357. break;
  16358. case /^2[0-9]{2}$/.test(response.status_code):
  16359. this.registering = false;
  16360. if(response.hasHeader('expires')) {
  16361. expires = response.getHeader('expires');
  16362. }
  16363. // Search the Contact pointing to us and update the expires value accordingly.
  16364. if (!contacts) {
  16365. debug('no Contact header in response to REGISTER, response ignored');
  16366. break;
  16367. }
  16368. while(contacts--) {
  16369. contact = response.parseHeader('contact', contacts);
  16370. if(contact.uri.user === this.ua.contact.uri.user) {
  16371. expires = contact.getParam('expires');
  16372. break;
  16373. } else {
  16374. contact = null;
  16375. }
  16376. }
  16377. if (!contact) {
  16378. debug('no Contact header pointing to us, response ignored');
  16379. break;
  16380. }
  16381. if(!expires) {
  16382. expires = this.expires;
  16383. }
  16384. // Re-Register or emit an event before the expiration interval has elapsed.
  16385. // For that, decrease the expires value. ie: 3 seconds
  16386. this.registrationTimer = setTimeout(function() {
  16387. self.registrationTimer = null;
  16388. // If there are no listeners for registrationExpiring, renew registration
  16389. // If there are listeners, let the function listening do the register call
  16390. if (self.ua.listeners('registrationExpiring').length === 0) {
  16391. self.register();
  16392. } else {
  16393. self.ua.emit('registrationExpiring');
  16394. }
  16395. }, (expires * 1000) - 5000);
  16396. //Save gruu values
  16397. if (contact.hasParam('temp-gruu')) {
  16398. this.ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g,'');
  16399. }
  16400. if (contact.hasParam('pub-gruu')) {
  16401. this.ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g,'');
  16402. }
  16403. if (! this.registered) {
  16404. this.registered = true;
  16405. this.ua.registered({
  16406. response: response
  16407. });
  16408. }
  16409. break;
  16410. // Interval too brief RFC3261 10.2.8
  16411. case /^423$/.test(response.status_code):
  16412. if(response.hasHeader('min-expires')) {
  16413. // Increase our registration interval to the suggested minimum
  16414. this.expires = response.getHeader('min-expires');
  16415. // Attempt the registration again immediately
  16416. this.register();
  16417. } else { //This response MUST contain a Min-Expires header field
  16418. debug('423 response received for REGISTER without Min-Expires');
  16419. this.registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE);
  16420. }
  16421. break;
  16422. default:
  16423. cause = Utils.sipErrorCause(response.status_code);
  16424. this.registrationFailure(response, cause);
  16425. }
  16426. };
  16427. this.onRequestTimeout = function() {
  16428. this.registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  16429. };
  16430. this.onTransportError = function() {
  16431. this.registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR);
  16432. };
  16433. this.registering = true;
  16434. request_sender.send();
  16435. },
  16436. unregister: function(options) {
  16437. var extraHeaders;
  16438. if(!this.registered) {
  16439. debug('already unregistered');
  16440. return;
  16441. }
  16442. options = options || {};
  16443. this.registered = false;
  16444. // Clear the registration timer.
  16445. if (this.registrationTimer !== null) {
  16446. clearTimeout(this.registrationTimer);
  16447. this.registrationTimer = null;
  16448. }
  16449. extraHeaders = this.extraHeaders.slice();
  16450. if(options.all) {
  16451. extraHeaders.push('Contact: *' + this.extraContactParams);
  16452. extraHeaders.push('Expires: 0');
  16453. this.request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this.registrar, this.ua, {
  16454. 'to_uri': this.to_uri,
  16455. 'call_id': this.call_id,
  16456. 'cseq': (this.cseq += 1)
  16457. }, extraHeaders);
  16458. } else {
  16459. extraHeaders.push('Contact: '+ this.contact + ';expires=0' + this.extraContactParams);
  16460. extraHeaders.push('Expires: 0');
  16461. this.request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this.registrar, this.ua, {
  16462. 'to_uri': this.to_uri,
  16463. 'call_id': this.call_id,
  16464. 'cseq': (this.cseq += 1)
  16465. }, extraHeaders);
  16466. }
  16467. var request_sender = new RequestSender(this, this.ua);
  16468. this.receiveResponse = function(response) {
  16469. var cause;
  16470. switch(true) {
  16471. case /^1[0-9]{2}$/.test(response.status_code):
  16472. // Ignore provisional responses.
  16473. break;
  16474. case /^2[0-9]{2}$/.test(response.status_code):
  16475. this.unregistered(response);
  16476. break;
  16477. default:
  16478. cause = Utils.sipErrorCause(response.status_code);
  16479. this.unregistered(response, cause);
  16480. }
  16481. };
  16482. this.onRequestTimeout = function() {
  16483. this.unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  16484. };
  16485. this.onTransportError = function() {
  16486. this.unregistered(null, JsSIP_C.causes.CONNECTION_ERROR);
  16487. };
  16488. request_sender.send();
  16489. },
  16490. registrationFailure: function(response, cause) {
  16491. this.registering = false;
  16492. this.ua.registrationFailed({
  16493. response: response || null,
  16494. cause: cause
  16495. });
  16496. if (this.registered) {
  16497. this.registered = false;
  16498. this.ua.unregistered({
  16499. response: response || null,
  16500. cause: cause
  16501. });
  16502. }
  16503. },
  16504. unregistered: function(response, cause) {
  16505. this.registering = false;
  16506. this.registered = false;
  16507. this.ua.unregistered({
  16508. response: response || null,
  16509. cause: cause || null
  16510. });
  16511. },
  16512. onTransportClosed: function() {
  16513. this.registering = false;
  16514. if (this.registrationTimer !== null) {
  16515. clearTimeout(this.registrationTimer);
  16516. this.registrationTimer = null;
  16517. }
  16518. if(this.registered) {
  16519. this.registered = false;
  16520. this.ua.unregistered({});
  16521. }
  16522. },
  16523. close: function() {
  16524. if (this.registered) {
  16525. this.unregister();
  16526. }
  16527. }
  16528. };
  16529. },{"./Constants":1,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":35}],18:[function(require,module,exports){
  16530. module.exports = RequestSender;
  16531. /**
  16532. * Dependencies.
  16533. */
  16534. var debug = require('debug')('JsSIP:RequestSender');
  16535. var JsSIP_C = require('./Constants');
  16536. var UA = require('./UA');
  16537. var DigestAuthentication = require('./DigestAuthentication');
  16538. var Transactions = require('./Transactions');
  16539. function RequestSender(applicant, ua) {
  16540. this.ua = ua;
  16541. this.applicant = applicant;
  16542. this.method = applicant.request.method;
  16543. this.request = applicant.request;
  16544. this.auth = null;
  16545. this.challenged = false;
  16546. this.staled = false;
  16547. // If ua is in closing process or even closed just allow sending Bye and ACK
  16548. if (ua.status === UA.C.STATUS_USER_CLOSED && (this.method !== JsSIP_C.BYE || this.method !== JsSIP_C.ACK)) {
  16549. this.onTransportError();
  16550. }
  16551. }
  16552. /**
  16553. * Create the client transaction and send the message.
  16554. */
  16555. RequestSender.prototype = {
  16556. send: function() {
  16557. switch(this.method) {
  16558. case 'INVITE':
  16559. this.clientTransaction = new Transactions.InviteClientTransaction(this, this.request, this.ua.transport);
  16560. break;
  16561. case 'ACK':
  16562. this.clientTransaction = new Transactions.AckClientTransaction(this, this.request, this.ua.transport);
  16563. break;
  16564. default:
  16565. this.clientTransaction = new Transactions.NonInviteClientTransaction(this, this.request, this.ua.transport);
  16566. }
  16567. this.clientTransaction.send();
  16568. },
  16569. /**
  16570. * Callback fired when receiving a request timeout error from the client transaction.
  16571. * To be re-defined by the applicant.
  16572. */
  16573. onRequestTimeout: function() {
  16574. this.applicant.onRequestTimeout();
  16575. },
  16576. /**
  16577. * Callback fired when receiving a transport error from the client transaction.
  16578. * To be re-defined by the applicant.
  16579. */
  16580. onTransportError: function() {
  16581. this.applicant.onTransportError();
  16582. },
  16583. /**
  16584. * Called from client transaction when receiving a correct response to the request.
  16585. * Authenticate request if needed or pass the response back to the applicant.
  16586. */
  16587. receiveResponse: function(response) {
  16588. var
  16589. cseq, challenge, authorization_header_name,
  16590. status_code = response.status_code;
  16591. /*
  16592. * Authentication
  16593. * Authenticate once. _challenged_ flag used to avoid infinite authentications.
  16594. */
  16595. if ((status_code === 401 || status_code === 407) &&
  16596. (this.ua.configuration.password !== null || this.ua.configuration.ha1 !== null)) {
  16597. // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header.
  16598. if (response.status_code === 401) {
  16599. challenge = response.parseHeader('www-authenticate');
  16600. authorization_header_name = 'authorization';
  16601. } else {
  16602. challenge = response.parseHeader('proxy-authenticate');
  16603. authorization_header_name = 'proxy-authorization';
  16604. }
  16605. // Verify it seems a valid challenge.
  16606. if (!challenge) {
  16607. debug(response.status_code + ' with wrong or missing challenge, cannot authenticate');
  16608. this.applicant.receiveResponse(response);
  16609. return;
  16610. }
  16611. if (!this.challenged || (!this.staled && challenge.stale === true)) {
  16612. if (!this.auth) {
  16613. this.auth = new DigestAuthentication({
  16614. username : this.ua.configuration.authorization_user,
  16615. password : this.ua.configuration.password,
  16616. realm : this.ua.configuration.realm,
  16617. ha1 : this.ua.configuration.ha1
  16618. });
  16619. }
  16620. // Verify that the challenge is really valid.
  16621. if (!this.auth.authenticate(this.request, challenge)) {
  16622. this.applicant.receiveResponse(response);
  16623. return;
  16624. }
  16625. this.challenged = true;
  16626. // Update ha1 and realm in the UA.
  16627. this.ua.set('realm', this.auth.get('realm'));
  16628. this.ua.set('ha1', this.auth.get('ha1'));
  16629. if (challenge.stale) {
  16630. this.staled = true;
  16631. }
  16632. if (response.method === JsSIP_C.REGISTER) {
  16633. cseq = this.applicant.cseq += 1;
  16634. } else if (this.request.dialog) {
  16635. cseq = this.request.dialog.local_seqnum += 1;
  16636. } else {
  16637. cseq = this.request.cseq + 1;
  16638. }
  16639. this.request = this.applicant.request = this.request.clone();
  16640. this.request.cseq = cseq;
  16641. this.request.setHeader('cseq', cseq +' '+ this.method);
  16642. this.request.setHeader(authorization_header_name, this.auth.toString());
  16643. this.send();
  16644. } else {
  16645. this.applicant.receiveResponse(response);
  16646. }
  16647. } else {
  16648. this.applicant.receiveResponse(response);
  16649. }
  16650. }
  16651. };
  16652. },{"./Constants":1,"./DigestAuthentication":4,"./Transactions":22,"./UA":24,"debug":35}],19:[function(require,module,exports){
  16653. module.exports = {
  16654. OutgoingRequest: OutgoingRequest,
  16655. IncomingRequest: IncomingRequest,
  16656. IncomingResponse: IncomingResponse
  16657. };
  16658. /**
  16659. * Dependencies.
  16660. */
  16661. var debug = require('debug')('JsSIP:SIPMessage');
  16662. var sdp_transform = require('sdp-transform');
  16663. var JsSIP_C = require('./Constants');
  16664. var Utils = require('./Utils');
  16665. var NameAddrHeader = require('./NameAddrHeader');
  16666. var Grammar = require('./Grammar');
  16667. /**
  16668. * -param {String} method request method
  16669. * -param {String} ruri request uri
  16670. * -param {UA} ua
  16671. * -param {Object} params parameters that will have priority over ua.configuration parameters:
  16672. * <br>
  16673. * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set
  16674. * -param {Object} [headers] extra headers
  16675. * -param {String} [body]
  16676. */
  16677. function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) {
  16678. var
  16679. to,
  16680. from,
  16681. call_id,
  16682. cseq;
  16683. params = params || {};
  16684. // Mandatory parameters check
  16685. if(!method || !ruri || !ua) {
  16686. return null;
  16687. }
  16688. this.ua = ua;
  16689. this.headers = {};
  16690. this.method = method;
  16691. this.ruri = ruri;
  16692. this.body = body;
  16693. this.extraHeaders = extraHeaders && extraHeaders.slice() || [];
  16694. // Fill the Common SIP Request Headers
  16695. // Route
  16696. if (params.route_set) {
  16697. this.setHeader('route', params.route_set);
  16698. } else if (ua.configuration.use_preloaded_route) {
  16699. this.setHeader('route', '<' + ua.transport.sip_uri + ';lr>');
  16700. }
  16701. // Via
  16702. // Empty Via header. Will be filled by the client transaction.
  16703. this.setHeader('via', '');
  16704. // Max-Forwards
  16705. this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS);
  16706. // To
  16707. to = (params.to_display_name || params.to_display_name === 0) ? '"' + params.to_display_name + '" ' : '';
  16708. to += '<' + (params.to_uri || ruri) + '>';
  16709. to += params.to_tag ? ';tag=' + params.to_tag : '';
  16710. this.to = new NameAddrHeader.parse(to);
  16711. this.setHeader('to', to);
  16712. // From
  16713. if (params.from_display_name || params.from_display_name === 0) {
  16714. from = '"' + params.from_display_name + '" ';
  16715. } else if (ua.configuration.display_name) {
  16716. from = '"' + ua.configuration.display_name + '" ';
  16717. } else {
  16718. from = '';
  16719. }
  16720. from += '<' + (params.from_uri || ua.configuration.uri) + '>;tag=';
  16721. from += params.from_tag || Utils.newTag();
  16722. this.from = new NameAddrHeader.parse(from);
  16723. this.setHeader('from', from);
  16724. // Call-ID
  16725. call_id = params.call_id || (ua.configuration.jssip_id + Utils.createRandomToken(15));
  16726. this.call_id = call_id;
  16727. this.setHeader('call-id', call_id);
  16728. // CSeq
  16729. cseq = params.cseq || Math.floor(Math.random() * 10000);
  16730. this.cseq = cseq;
  16731. this.setHeader('cseq', cseq + ' ' + method);
  16732. }
  16733. OutgoingRequest.prototype = {
  16734. /**
  16735. * Replace the the given header by the given value.
  16736. * -param {String} name header name
  16737. * -param {String | Array} value header value
  16738. */
  16739. setHeader: function(name, value) {
  16740. var regexp, idx;
  16741. // Remove the header from extraHeaders if present.
  16742. regexp = new RegExp('^\\s*'+ name +'\\s*:','i');
  16743. for (idx=0; idx<this.extraHeaders.length; idx++) {
  16744. if (regexp.test(this.extraHeaders[idx])) {
  16745. this.extraHeaders.splice(idx, 1);
  16746. }
  16747. }
  16748. this.headers[Utils.headerize(name)] = (Array.isArray(value)) ? value : [value];
  16749. },
  16750. /**
  16751. * Get the value of the given header name at the given position.
  16752. * -param {String} name header name
  16753. * -returns {String|undefined} Returns the specified header, null if header doesn't exist.
  16754. */
  16755. getHeader: function(name) {
  16756. var regexp, idx,
  16757. length = this.extraHeaders.length,
  16758. header = this.headers[Utils.headerize(name)];
  16759. if(header) {
  16760. if(header[0]) {
  16761. return header[0];
  16762. }
  16763. } else {
  16764. regexp = new RegExp('^\\s*'+ name +'\\s*:','i');
  16765. for (idx=0; idx<length; idx++) {
  16766. header = this.extraHeaders[idx];
  16767. if (regexp.test(header)) {
  16768. return header.substring(header.indexOf(':')+1).trim();
  16769. }
  16770. }
  16771. }
  16772. return;
  16773. },
  16774. /**
  16775. * Get the header/s of the given name.
  16776. * -param {String} name header name
  16777. * -returns {Array} Array with all the headers of the specified name.
  16778. */
  16779. getHeaders: function(name) {
  16780. var idx, length, regexp,
  16781. header = this.headers[Utils.headerize(name)],
  16782. result = [];
  16783. if (header) {
  16784. length = header.length;
  16785. for (idx = 0; idx < length; idx++) {
  16786. result.push(header[idx]);
  16787. }
  16788. return result;
  16789. } else {
  16790. length = this.extraHeaders.length;
  16791. regexp = new RegExp('^\\s*'+ name +'\\s*:','i');
  16792. for (idx=0; idx<length; idx++) {
  16793. header = this.extraHeaders[idx];
  16794. if (regexp.test(header)) {
  16795. result.push(header.substring(header.indexOf(':')+1).trim());
  16796. }
  16797. }
  16798. return result;
  16799. }
  16800. },
  16801. /**
  16802. * Verify the existence of the given header.
  16803. * -param {String} name header name
  16804. * -returns {boolean} true if header with given name exists, false otherwise
  16805. */
  16806. hasHeader: function(name) {
  16807. var regexp, idx,
  16808. length = this.extraHeaders.length;
  16809. if (this.headers[Utils.headerize(name)]) {
  16810. return true;
  16811. } else {
  16812. regexp = new RegExp('^\\s*'+ name +'\\s*:','i');
  16813. for (idx=0; idx<length; idx++) {
  16814. if (regexp.test(this.extraHeaders[idx])) {
  16815. return true;
  16816. }
  16817. }
  16818. }
  16819. return false;
  16820. },
  16821. /**
  16822. * Parse the current body as a SDP and store the resulting object
  16823. * into this.sdp.
  16824. * -param {Boolean} force: Parse even if this.sdp already exists.
  16825. *
  16826. * Returns this.sdp.
  16827. */
  16828. parseSDP: function(force) {
  16829. if (!force && this.sdp) {
  16830. return this.sdp;
  16831. } else {
  16832. this.sdp = sdp_transform.parse(this.body || '');
  16833. return this.sdp;
  16834. }
  16835. },
  16836. toString: function() {
  16837. var msg = '', header, length, idx,
  16838. supported = [];
  16839. msg += this.method + ' ' + this.ruri + ' SIP/2.0\r\n';
  16840. for (header in this.headers) {
  16841. length = this.headers[header].length;
  16842. for (idx = 0; idx < length; idx++) {
  16843. msg += header + ': ' + this.headers[header][idx] + '\r\n';
  16844. }
  16845. }
  16846. length = this.extraHeaders.length;
  16847. for (idx = 0; idx < length; idx++) {
  16848. msg += this.extraHeaders[idx].trim() +'\r\n';
  16849. }
  16850. // Supported
  16851. switch (this.method) {
  16852. case JsSIP_C.REGISTER:
  16853. supported.push('path', 'gruu');
  16854. break;
  16855. case JsSIP_C.INVITE:
  16856. if (this.ua.configuration.session_timers) {
  16857. supported.push('timer');
  16858. }
  16859. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  16860. supported.push('gruu');
  16861. }
  16862. supported.push('ice','replaces');
  16863. break;
  16864. case JsSIP_C.UPDATE:
  16865. if (this.ua.configuration.session_timers) {
  16866. supported.push('timer');
  16867. }
  16868. supported.push('ice');
  16869. break;
  16870. }
  16871. supported.push('outbound');
  16872. // Allow
  16873. msg += 'Allow: '+ JsSIP_C.ALLOWED_METHODS +'\r\n';
  16874. msg += 'Supported: ' + supported +'\r\n';
  16875. msg += 'User-Agent: ' + JsSIP_C.USER_AGENT +'\r\n';
  16876. if (this.body) {
  16877. length = Utils.str_utf8_length(this.body);
  16878. msg += 'Content-Length: ' + length + '\r\n\r\n';
  16879. msg += this.body;
  16880. } else {
  16881. msg += 'Content-Length: 0\r\n\r\n';
  16882. }
  16883. return msg;
  16884. },
  16885. clone: function() {
  16886. var request = new OutgoingRequest(this.method, this.ruri, this.ua);
  16887. Object.keys(this.headers).forEach(function(name) {
  16888. request.headers[name] = this.headers[name].slice();
  16889. }, this);
  16890. request.body = this.body;
  16891. request.extraHeaders = this.extraHeaders && this.extraHeaders.slice() || [];
  16892. request.to = this.to;
  16893. request.from = this.from;
  16894. request.call_id = this.call_id;
  16895. request.cseq = this.cseq;
  16896. return request;
  16897. }
  16898. };
  16899. function IncomingMessage(){
  16900. this.data = null;
  16901. this.headers = null;
  16902. this.method = null;
  16903. this.via = null;
  16904. this.via_branch = null;
  16905. this.call_id = null;
  16906. this.cseq = null;
  16907. this.from = null;
  16908. this.from_tag = null;
  16909. this.to = null;
  16910. this.to_tag = null;
  16911. this.body = null;
  16912. this.sdp = null;
  16913. }
  16914. IncomingMessage.prototype = {
  16915. /**
  16916. * Insert a header of the given name and value into the last position of the
  16917. * header array.
  16918. */
  16919. addHeader: function(name, value) {
  16920. var header = { raw: value };
  16921. name = Utils.headerize(name);
  16922. if(this.headers[name]) {
  16923. this.headers[name].push(header);
  16924. } else {
  16925. this.headers[name] = [header];
  16926. }
  16927. },
  16928. /**
  16929. * Get the value of the given header name at the given position.
  16930. */
  16931. getHeader: function(name) {
  16932. var header = this.headers[Utils.headerize(name)];
  16933. if(header) {
  16934. if(header[0]) {
  16935. return header[0].raw;
  16936. }
  16937. } else {
  16938. return;
  16939. }
  16940. },
  16941. /**
  16942. * Get the header/s of the given name.
  16943. */
  16944. getHeaders: function(name) {
  16945. var idx, length,
  16946. header = this.headers[Utils.headerize(name)],
  16947. result = [];
  16948. if(!header) {
  16949. return [];
  16950. }
  16951. length = header.length;
  16952. for (idx = 0; idx < length; idx++) {
  16953. result.push(header[idx].raw);
  16954. }
  16955. return result;
  16956. },
  16957. /**
  16958. * Verify the existence of the given header.
  16959. */
  16960. hasHeader: function(name) {
  16961. return(this.headers[Utils.headerize(name)]) ? true : false;
  16962. },
  16963. /**
  16964. * Parse the given header on the given index.
  16965. * -param {String} name header name
  16966. * -param {Number} [idx=0] header index
  16967. * -returns {Object|undefined} Parsed header object, undefined if the header is not present or in case of a parsing error.
  16968. */
  16969. parseHeader: function(name, idx) {
  16970. var header, value, parsed;
  16971. name = Utils.headerize(name);
  16972. idx = idx || 0;
  16973. if(!this.headers[name]) {
  16974. debug('header "' + name + '" not present');
  16975. return;
  16976. } else if(idx >= this.headers[name].length) {
  16977. debug('not so many "' + name + '" headers present');
  16978. return;
  16979. }
  16980. header = this.headers[name][idx];
  16981. value = header.raw;
  16982. if(header.parsed) {
  16983. return header.parsed;
  16984. }
  16985. //substitute '-' by '_' for grammar rule matching.
  16986. parsed = Grammar.parse(value, name.replace(/-/g, '_'));
  16987. if(parsed === -1) {
  16988. this.headers[name].splice(idx, 1); //delete from headers
  16989. debug('error parsing "' + name + '" header field with value "' + value + '"');
  16990. return;
  16991. } else {
  16992. header.parsed = parsed;
  16993. return parsed;
  16994. }
  16995. },
  16996. /**
  16997. * Message Header attribute selector. Alias of parseHeader.
  16998. * -param {String} name header name
  16999. * -param {Number} [idx=0] header index
  17000. * -returns {Object|undefined} Parsed header object, undefined if the header is not present or in case of a parsing error.
  17001. *
  17002. * -example
  17003. * message.s('via',3).port
  17004. */
  17005. s: function(name, idx) {
  17006. return this.parseHeader(name, idx);
  17007. },
  17008. /**
  17009. * Replace the value of the given header by the value.
  17010. * -param {String} name header name
  17011. * -param {String} value header value
  17012. */
  17013. setHeader: function(name, value) {
  17014. var header = { raw: value };
  17015. this.headers[Utils.headerize(name)] = [header];
  17016. },
  17017. /**
  17018. * Parse the current body as a SDP and store the resulting object
  17019. * into this.sdp.
  17020. * -param {Boolean} force: Parse even if this.sdp already exists.
  17021. *
  17022. * Returns this.sdp.
  17023. */
  17024. parseSDP: function(force) {
  17025. if (!force && this.sdp) {
  17026. return this.sdp;
  17027. } else {
  17028. this.sdp = sdp_transform.parse(this.body || '');
  17029. return this.sdp;
  17030. }
  17031. },
  17032. toString: function() {
  17033. return this.data;
  17034. }
  17035. };
  17036. function IncomingRequest(ua) {
  17037. this.ua = ua;
  17038. this.headers = {};
  17039. this.ruri = null;
  17040. this.transport = null;
  17041. this.server_transaction = null;
  17042. }
  17043. IncomingRequest.prototype = new IncomingMessage();
  17044. /**
  17045. * Stateful reply.
  17046. * -param {Number} code status code
  17047. * -param {String} reason reason phrase
  17048. * -param {Object} headers extra headers
  17049. * -param {String} body body
  17050. * -param {Function} [onSuccess] onSuccess callback
  17051. * -param {Function} [onFailure] onFailure callback
  17052. */
  17053. IncomingRequest.prototype.reply = function(code, reason, extraHeaders, body, onSuccess, onFailure) {
  17054. var rr, vias, length, idx, response,
  17055. supported = [],
  17056. to = this.getHeader('To'),
  17057. r = 0,
  17058. v = 0;
  17059. code = code || null;
  17060. reason = reason || null;
  17061. // Validate code and reason values
  17062. if (!code || (code < 100 || code > 699)) {
  17063. throw new TypeError('Invalid status_code: '+ code);
  17064. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  17065. throw new TypeError('Invalid reason_phrase: '+ reason);
  17066. }
  17067. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  17068. extraHeaders = extraHeaders && extraHeaders.slice() || [];
  17069. response = 'SIP/2.0 ' + code + ' ' + reason + '\r\n';
  17070. if(this.method === JsSIP_C.INVITE && code > 100 && code <= 200) {
  17071. rr = this.getHeaders('record-route');
  17072. length = rr.length;
  17073. for(r; r < length; r++) {
  17074. response += 'Record-Route: ' + rr[r] + '\r\n';
  17075. }
  17076. }
  17077. vias = this.getHeaders('via');
  17078. length = vias.length;
  17079. for(v; v < length; v++) {
  17080. response += 'Via: ' + vias[v] + '\r\n';
  17081. }
  17082. if(!this.to_tag && code > 100) {
  17083. to += ';tag=' + Utils.newTag();
  17084. } else if(this.to_tag && !this.s('to').hasParam('tag')) {
  17085. to += ';tag=' + this.to_tag;
  17086. }
  17087. response += 'To: ' + to + '\r\n';
  17088. response += 'From: ' + this.getHeader('From') + '\r\n';
  17089. response += 'Call-ID: ' + this.call_id + '\r\n';
  17090. response += 'CSeq: ' + this.cseq + ' ' + this.method + '\r\n';
  17091. length = extraHeaders.length;
  17092. for (idx = 0; idx < length; idx++) {
  17093. response += extraHeaders[idx].trim() +'\r\n';
  17094. }
  17095. // Supported
  17096. switch (this.method) {
  17097. case JsSIP_C.INVITE:
  17098. if (this.ua.configuration.session_timers) {
  17099. supported.push('timer');
  17100. }
  17101. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  17102. supported.push('gruu');
  17103. }
  17104. supported.push('ice','replaces');
  17105. break;
  17106. case JsSIP_C.UPDATE:
  17107. if (this.ua.configuration.session_timers) {
  17108. supported.push('timer');
  17109. }
  17110. if (body) {
  17111. supported.push('ice');
  17112. }
  17113. supported.push('replaces');
  17114. }
  17115. supported.push('outbound');
  17116. // Allow and Accept
  17117. if (this.method === JsSIP_C.OPTIONS) {
  17118. response += 'Allow: '+ JsSIP_C.ALLOWED_METHODS +'\r\n';
  17119. response += 'Accept: '+ JsSIP_C.ACCEPTED_BODY_TYPES +'\r\n';
  17120. } else if (code === 405) {
  17121. response += 'Allow: '+ JsSIP_C.ALLOWED_METHODS +'\r\n';
  17122. } else if (code === 415 ) {
  17123. response += 'Accept: '+ JsSIP_C.ACCEPTED_BODY_TYPES +'\r\n';
  17124. }
  17125. response += 'Supported: ' + supported +'\r\n';
  17126. if(body) {
  17127. length = Utils.str_utf8_length(body);
  17128. response += 'Content-Type: application/sdp\r\n';
  17129. response += 'Content-Length: ' + length + '\r\n\r\n';
  17130. response += body;
  17131. } else {
  17132. response += 'Content-Length: ' + 0 + '\r\n\r\n';
  17133. }
  17134. this.server_transaction.receiveResponse(code, response, onSuccess, onFailure);
  17135. };
  17136. /**
  17137. * Stateless reply.
  17138. * -param {Number} code status code
  17139. * -param {String} reason reason phrase
  17140. */
  17141. IncomingRequest.prototype.reply_sl = function(code, reason) {
  17142. var to, response,
  17143. v = 0,
  17144. vias = this.getHeaders('via'),
  17145. length = vias.length;
  17146. code = code || null;
  17147. reason = reason || null;
  17148. // Validate code and reason values
  17149. if (!code || (code < 100 || code > 699)) {
  17150. throw new TypeError('Invalid status_code: '+ code);
  17151. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  17152. throw new TypeError('Invalid reason_phrase: '+ reason);
  17153. }
  17154. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  17155. response = 'SIP/2.0 ' + code + ' ' + reason + '\r\n';
  17156. for(v; v < length; v++) {
  17157. response += 'Via: ' + vias[v] + '\r\n';
  17158. }
  17159. to = this.getHeader('To');
  17160. if(!this.to_tag && code > 100) {
  17161. to += ';tag=' + Utils.newTag();
  17162. } else if(this.to_tag && !this.s('to').hasParam('tag')) {
  17163. to += ';tag=' + this.to_tag;
  17164. }
  17165. response += 'To: ' + to + '\r\n';
  17166. response += 'From: ' + this.getHeader('From') + '\r\n';
  17167. response += 'Call-ID: ' + this.call_id + '\r\n';
  17168. response += 'CSeq: ' + this.cseq + ' ' + this.method + '\r\n';
  17169. response += 'Content-Length: ' + 0 + '\r\n\r\n';
  17170. this.transport.send(response);
  17171. };
  17172. function IncomingResponse() {
  17173. this.headers = {};
  17174. this.status_code = null;
  17175. this.reason_phrase = null;
  17176. }
  17177. IncomingResponse.prototype = new IncomingMessage();
  17178. },{"./Constants":1,"./Grammar":6,"./NameAddrHeader":9,"./Utils":26,"debug":35,"sdp-transform":38}],20:[function(require,module,exports){
  17179. module.exports = Socket;
  17180. /**
  17181. * Interface documentation: http://jssip.net/documentation/$last_version/api/socket/
  17182. *
  17183. * interface Socket {
  17184. * attribute String via_transport
  17185. * attribute String url
  17186. * attribute String sip_uri
  17187. *
  17188. * method connect();
  17189. * method disconnect();
  17190. * method send(data);
  17191. *
  17192. * attribute EventHandler onconnect
  17193. * attribute EventHandler ondisconnect
  17194. * attribute EventHandler ondata
  17195. * }
  17196. *
  17197. */
  17198. /**
  17199. * Dependencies.
  17200. */
  17201. var Utils = require('./Utils');
  17202. var Grammar = require('./Grammar');
  17203. var debugerror = require('debug')('JsSIP:ERROR:Socket');
  17204. debugerror.log = console.warn.bind(console);
  17205. function Socket() {}
  17206. Socket.isSocket = function(socket) {
  17207. // Ignore if an array is given
  17208. if (Array.isArray(socket)) {
  17209. return false;
  17210. }
  17211. if (typeof socket === 'undefined') {
  17212. debugerror('undefined JsSIP.Socket instance');
  17213. return false;
  17214. }
  17215. // Check Properties
  17216. try {
  17217. if (!Utils.isString(socket.url)) {
  17218. debugerror('missing or invalid JsSIP.Socket url property');
  17219. throw new Error();
  17220. }
  17221. if (!Utils.isString(socket.via_transport)) {
  17222. debugerror('missing or invalid JsSIP.Socket via_transport property');
  17223. throw new Error();
  17224. }
  17225. if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) {
  17226. debugerror('missing or invalid JsSIP.Socket sip_uri property');
  17227. throw new Error();
  17228. }
  17229. } catch(e) {
  17230. return false;
  17231. }
  17232. // Check Methods
  17233. try {
  17234. ['connect', 'disconnect', 'send'].forEach(function(method) {
  17235. if (!Utils.isFunction(socket[method])) {
  17236. debugerror('missing or invalid JsSIP.Socket method: ' + method);
  17237. throw new Error();
  17238. }
  17239. });
  17240. } catch(e) {
  17241. return false;
  17242. }
  17243. return true;
  17244. };
  17245. },{"./Grammar":6,"./Utils":26,"debug":35}],21:[function(require,module,exports){
  17246. var T1 = 500,
  17247. T2 = 4000,
  17248. T4 = 5000;
  17249. var Timers = {
  17250. T1: T1,
  17251. T2: T2,
  17252. T4: T4,
  17253. TIMER_B: 64 * T1,
  17254. TIMER_D: 0 * T1,
  17255. TIMER_F: 64 * T1,
  17256. TIMER_H: 64 * T1,
  17257. TIMER_I: 0 * T1,
  17258. TIMER_J: 0 * T1,
  17259. TIMER_K: 0 * T4,
  17260. TIMER_L: 64 * T1,
  17261. TIMER_M: 64 * T1,
  17262. PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1
  17263. };
  17264. module.exports = Timers;
  17265. },{}],22:[function(require,module,exports){
  17266. module.exports = {
  17267. C: null,
  17268. NonInviteClientTransaction: NonInviteClientTransaction,
  17269. InviteClientTransaction: InviteClientTransaction,
  17270. AckClientTransaction: AckClientTransaction,
  17271. NonInviteServerTransaction: NonInviteServerTransaction,
  17272. InviteServerTransaction: InviteServerTransaction,
  17273. checkTransaction: checkTransaction
  17274. };
  17275. var C = {
  17276. // Transaction states
  17277. STATUS_TRYING: 1,
  17278. STATUS_PROCEEDING: 2,
  17279. STATUS_CALLING: 3,
  17280. STATUS_ACCEPTED: 4,
  17281. STATUS_COMPLETED: 5,
  17282. STATUS_TERMINATED: 6,
  17283. STATUS_CONFIRMED: 7,
  17284. // Transaction types
  17285. NON_INVITE_CLIENT: 'nict',
  17286. NON_INVITE_SERVER: 'nist',
  17287. INVITE_CLIENT: 'ict',
  17288. INVITE_SERVER: 'ist'
  17289. };
  17290. /**
  17291. * Expose C object.
  17292. */
  17293. module.exports.C = C;
  17294. /**
  17295. * Dependencies.
  17296. */
  17297. var util = require('util');
  17298. var events = require('events');
  17299. var debugnict = require('debug')('JsSIP:NonInviteClientTransaction');
  17300. var debugict = require('debug')('JsSIP:InviteClientTransaction');
  17301. var debugact = require('debug')('JsSIP:AckClientTransaction');
  17302. var debugnist = require('debug')('JsSIP:NonInviteServerTransaction');
  17303. var debugist = require('debug')('JsSIP:InviteServerTransaction');
  17304. var JsSIP_C = require('./Constants');
  17305. var Timers = require('./Timers');
  17306. function NonInviteClientTransaction(request_sender, request, transport) {
  17307. var via;
  17308. this.type = C.NON_INVITE_CLIENT;
  17309. this.transport = transport;
  17310. this.id = 'z9hG4bK' + Math.floor(Math.random() * 10000000);
  17311. this.request_sender = request_sender;
  17312. this.request = request;
  17313. via = 'SIP/2.0/' + transport.via_transport;
  17314. via += ' ' + request_sender.ua.configuration.via_host + ';branch=' + this.id;
  17315. this.request.setHeader('via', via);
  17316. this.request_sender.ua.newTransaction(this);
  17317. events.EventEmitter.call(this);
  17318. }
  17319. util.inherits(NonInviteClientTransaction, events.EventEmitter);
  17320. NonInviteClientTransaction.prototype.stateChanged = function(state) {
  17321. this.state = state;
  17322. this.emit('stateChanged');
  17323. };
  17324. NonInviteClientTransaction.prototype.send = function() {
  17325. var tr = this;
  17326. this.stateChanged(C.STATUS_TRYING);
  17327. this.F = setTimeout(function() {tr.timer_F();}, Timers.TIMER_F);
  17328. if(!this.transport.send(this.request)) {
  17329. this.onTransportError();
  17330. }
  17331. };
  17332. NonInviteClientTransaction.prototype.onTransportError = function() {
  17333. debugnict('transport error occurred, deleting transaction ' + this.id);
  17334. clearTimeout(this.F);
  17335. clearTimeout(this.K);
  17336. this.stateChanged(C.STATUS_TERMINATED);
  17337. this.request_sender.ua.destroyTransaction(this);
  17338. this.request_sender.onTransportError();
  17339. };
  17340. NonInviteClientTransaction.prototype.timer_F = function() {
  17341. debugnict('Timer F expired for transaction ' + this.id);
  17342. this.stateChanged(C.STATUS_TERMINATED);
  17343. this.request_sender.ua.destroyTransaction(this);
  17344. this.request_sender.onRequestTimeout();
  17345. };
  17346. NonInviteClientTransaction.prototype.timer_K = function() {
  17347. this.stateChanged(C.STATUS_TERMINATED);
  17348. this.request_sender.ua.destroyTransaction(this);
  17349. };
  17350. NonInviteClientTransaction.prototype.receiveResponse = function(response) {
  17351. var
  17352. tr = this,
  17353. status_code = response.status_code;
  17354. if(status_code < 200) {
  17355. switch(this.state) {
  17356. case C.STATUS_TRYING:
  17357. case C.STATUS_PROCEEDING:
  17358. this.stateChanged(C.STATUS_PROCEEDING);
  17359. this.request_sender.receiveResponse(response);
  17360. break;
  17361. }
  17362. } else {
  17363. switch(this.state) {
  17364. case C.STATUS_TRYING:
  17365. case C.STATUS_PROCEEDING:
  17366. this.stateChanged(C.STATUS_COMPLETED);
  17367. clearTimeout(this.F);
  17368. if(status_code === 408) {
  17369. this.request_sender.onRequestTimeout();
  17370. } else {
  17371. this.request_sender.receiveResponse(response);
  17372. }
  17373. this.K = setTimeout(function() {tr.timer_K();}, Timers.TIMER_K);
  17374. break;
  17375. case C.STATUS_COMPLETED:
  17376. break;
  17377. }
  17378. }
  17379. };
  17380. function InviteClientTransaction(request_sender, request, transport) {
  17381. var via,
  17382. tr = this;
  17383. this.type = C.INVITE_CLIENT;
  17384. this.transport = transport;
  17385. this.id = 'z9hG4bK' + Math.floor(Math.random() * 10000000);
  17386. this.request_sender = request_sender;
  17387. this.request = request;
  17388. via = 'SIP/2.0/' + transport.via_transport;
  17389. via += ' ' + request_sender.ua.configuration.via_host + ';branch=' + this.id;
  17390. this.request.setHeader('via', via);
  17391. this.request_sender.ua.newTransaction(this);
  17392. // TODO: Adding here the cancel() method is a hack that must be fixed.
  17393. // Add the cancel property to the request.
  17394. //Will be called from the request instance, not the transaction itself.
  17395. this.request.cancel = function(reason) {
  17396. tr.cancel_request(tr, reason);
  17397. };
  17398. events.EventEmitter.call(this);
  17399. }
  17400. util.inherits(InviteClientTransaction, events.EventEmitter);
  17401. InviteClientTransaction.prototype.stateChanged = function(state) {
  17402. this.state = state;
  17403. this.emit('stateChanged');
  17404. };
  17405. InviteClientTransaction.prototype.send = function() {
  17406. var tr = this;
  17407. this.stateChanged(C.STATUS_CALLING);
  17408. this.B = setTimeout(function() {
  17409. tr.timer_B();
  17410. }, Timers.TIMER_B);
  17411. if(!this.transport.send(this.request)) {
  17412. this.onTransportError();
  17413. }
  17414. };
  17415. InviteClientTransaction.prototype.onTransportError = function() {
  17416. clearTimeout(this.B);
  17417. clearTimeout(this.D);
  17418. clearTimeout(this.M);
  17419. if (this.state !== C.STATUS_ACCEPTED) {
  17420. debugict('transport error occurred, deleting transaction ' + this.id);
  17421. this.request_sender.onTransportError();
  17422. }
  17423. this.stateChanged(C.STATUS_TERMINATED);
  17424. this.request_sender.ua.destroyTransaction(this);
  17425. };
  17426. // RFC 6026 7.2
  17427. InviteClientTransaction.prototype.timer_M = function() {
  17428. debugict('Timer M expired for transaction ' + this.id);
  17429. if(this.state === C.STATUS_ACCEPTED) {
  17430. clearTimeout(this.B);
  17431. this.stateChanged(C.STATUS_TERMINATED);
  17432. this.request_sender.ua.destroyTransaction(this);
  17433. }
  17434. };
  17435. // RFC 3261 17.1.1
  17436. InviteClientTransaction.prototype.timer_B = function() {
  17437. debugict('Timer B expired for transaction ' + this.id);
  17438. if(this.state === C.STATUS_CALLING) {
  17439. this.stateChanged(C.STATUS_TERMINATED);
  17440. this.request_sender.ua.destroyTransaction(this);
  17441. this.request_sender.onRequestTimeout();
  17442. }
  17443. };
  17444. InviteClientTransaction.prototype.timer_D = function() {
  17445. debugict('Timer D expired for transaction ' + this.id);
  17446. clearTimeout(this.B);
  17447. this.stateChanged(C.STATUS_TERMINATED);
  17448. this.request_sender.ua.destroyTransaction(this);
  17449. };
  17450. InviteClientTransaction.prototype.sendACK = function(response) {
  17451. var tr = this;
  17452. this.ack = 'ACK ' + this.request.ruri + ' SIP/2.0\r\n';
  17453. this.ack += 'Via: ' + this.request.headers.Via.toString() + '\r\n';
  17454. if(this.request.headers.Route) {
  17455. this.ack += 'Route: ' + this.request.headers.Route.toString() + '\r\n';
  17456. }
  17457. this.ack += 'To: ' + response.getHeader('to') + '\r\n';
  17458. this.ack += 'From: ' + this.request.headers.From.toString() + '\r\n';
  17459. this.ack += 'Call-ID: ' + this.request.headers['Call-ID'].toString() + '\r\n';
  17460. this.ack += 'CSeq: ' + this.request.headers.CSeq.toString().split(' ')[0];
  17461. this.ack += ' ACK\r\n';
  17462. this.ack += 'Content-Length: 0\r\n\r\n';
  17463. this.D = setTimeout(function() {tr.timer_D();}, Timers.TIMER_D);
  17464. this.transport.send(this.ack);
  17465. };
  17466. InviteClientTransaction.prototype.cancel_request = function(tr, reason) {
  17467. var request = tr.request;
  17468. this.cancel = JsSIP_C.CANCEL + ' ' + request.ruri + ' SIP/2.0\r\n';
  17469. this.cancel += 'Via: ' + request.headers.Via.toString() + '\r\n';
  17470. if(this.request.headers.Route) {
  17471. this.cancel += 'Route: ' + request.headers.Route.toString() + '\r\n';
  17472. }
  17473. this.cancel += 'To: ' + request.headers.To.toString() + '\r\n';
  17474. this.cancel += 'From: ' + request.headers.From.toString() + '\r\n';
  17475. this.cancel += 'Call-ID: ' + request.headers['Call-ID'].toString() + '\r\n';
  17476. this.cancel += 'CSeq: ' + request.headers.CSeq.toString().split(' ')[0] +
  17477. ' CANCEL\r\n';
  17478. if(reason) {
  17479. this.cancel += 'Reason: ' + reason + '\r\n';
  17480. }
  17481. this.cancel += 'Content-Length: 0\r\n\r\n';
  17482. // Send only if a provisional response (>100) has been received.
  17483. if(this.state === C.STATUS_PROCEEDING) {
  17484. this.transport.send(this.cancel);
  17485. }
  17486. };
  17487. InviteClientTransaction.prototype.receiveResponse = function(response) {
  17488. var
  17489. tr = this,
  17490. status_code = response.status_code;
  17491. if(status_code >= 100 && status_code <= 199) {
  17492. switch(this.state) {
  17493. case C.STATUS_CALLING:
  17494. this.stateChanged(C.STATUS_PROCEEDING);
  17495. this.request_sender.receiveResponse(response);
  17496. break;
  17497. case C.STATUS_PROCEEDING:
  17498. this.request_sender.receiveResponse(response);
  17499. break;
  17500. }
  17501. } else if(status_code >= 200 && status_code <= 299) {
  17502. switch(this.state) {
  17503. case C.STATUS_CALLING:
  17504. case C.STATUS_PROCEEDING:
  17505. this.stateChanged(C.STATUS_ACCEPTED);
  17506. this.M = setTimeout(function() {
  17507. tr.timer_M();
  17508. }, Timers.TIMER_M);
  17509. this.request_sender.receiveResponse(response);
  17510. break;
  17511. case C.STATUS_ACCEPTED:
  17512. this.request_sender.receiveResponse(response);
  17513. break;
  17514. }
  17515. } else if(status_code >= 300 && status_code <= 699) {
  17516. switch(this.state) {
  17517. case C.STATUS_CALLING:
  17518. case C.STATUS_PROCEEDING:
  17519. this.stateChanged(C.STATUS_COMPLETED);
  17520. this.sendACK(response);
  17521. this.request_sender.receiveResponse(response);
  17522. break;
  17523. case C.STATUS_COMPLETED:
  17524. this.sendACK(response);
  17525. break;
  17526. }
  17527. }
  17528. };
  17529. function AckClientTransaction(request_sender, request, transport) {
  17530. var via;
  17531. this.transport = transport;
  17532. this.id = 'z9hG4bK' + Math.floor(Math.random() * 10000000);
  17533. this.request_sender = request_sender;
  17534. this.request = request;
  17535. via = 'SIP/2.0/' + transport.via_transport;
  17536. via += ' ' + request_sender.ua.configuration.via_host + ';branch=' + this.id;
  17537. this.request.setHeader('via', via);
  17538. events.EventEmitter.call(this);
  17539. }
  17540. util.inherits(AckClientTransaction, events.EventEmitter);
  17541. AckClientTransaction.prototype.send = function() {
  17542. if(!this.transport.send(this.request)) {
  17543. this.onTransportError();
  17544. }
  17545. };
  17546. AckClientTransaction.prototype.onTransportError = function() {
  17547. debugact('transport error occurred for transaction ' + this.id);
  17548. this.request_sender.onTransportError();
  17549. };
  17550. function NonInviteServerTransaction(request, ua) {
  17551. this.type = C.NON_INVITE_SERVER;
  17552. this.id = request.via_branch;
  17553. this.request = request;
  17554. this.transport = request.transport;
  17555. this.ua = ua;
  17556. this.last_response = '';
  17557. request.server_transaction = this;
  17558. this.state = C.STATUS_TRYING;
  17559. ua.newTransaction(this);
  17560. events.EventEmitter.call(this);
  17561. }
  17562. util.inherits(NonInviteServerTransaction, events.EventEmitter);
  17563. NonInviteServerTransaction.prototype.stateChanged = function(state) {
  17564. this.state = state;
  17565. this.emit('stateChanged');
  17566. };
  17567. NonInviteServerTransaction.prototype.timer_J = function() {
  17568. debugnist('Timer J expired for transaction ' + this.id);
  17569. this.stateChanged(C.STATUS_TERMINATED);
  17570. this.ua.destroyTransaction(this);
  17571. };
  17572. NonInviteServerTransaction.prototype.onTransportError = function() {
  17573. if (!this.transportError) {
  17574. this.transportError = true;
  17575. debugnist('transport error occurred, deleting transaction ' + this.id);
  17576. clearTimeout(this.J);
  17577. this.stateChanged(C.STATUS_TERMINATED);
  17578. this.ua.destroyTransaction(this);
  17579. }
  17580. };
  17581. NonInviteServerTransaction.prototype.receiveResponse = function(status_code, response, onSuccess, onFailure) {
  17582. var tr = this;
  17583. if(status_code === 100) {
  17584. /* RFC 4320 4.1
  17585. * 'A SIP element MUST NOT
  17586. * send any provisional response with a
  17587. * Status-Code other than 100 to a non-INVITE request.'
  17588. */
  17589. switch(this.state) {
  17590. case C.STATUS_TRYING:
  17591. this.stateChanged(C.STATUS_PROCEEDING);
  17592. if(!this.transport.send(response)) {
  17593. this.onTransportError();
  17594. }
  17595. break;
  17596. case C.STATUS_PROCEEDING:
  17597. this.last_response = response;
  17598. if(!this.transport.send(response)) {
  17599. this.onTransportError();
  17600. if (onFailure) {
  17601. onFailure();
  17602. }
  17603. } else if (onSuccess) {
  17604. onSuccess();
  17605. }
  17606. break;
  17607. }
  17608. } else if(status_code >= 200 && status_code <= 699) {
  17609. switch(this.state) {
  17610. case C.STATUS_TRYING:
  17611. case C.STATUS_PROCEEDING:
  17612. this.stateChanged(C.STATUS_COMPLETED);
  17613. this.last_response = response;
  17614. this.J = setTimeout(function() {
  17615. tr.timer_J();
  17616. }, Timers.TIMER_J);
  17617. if(!this.transport.send(response)) {
  17618. this.onTransportError();
  17619. if (onFailure) {
  17620. onFailure();
  17621. }
  17622. } else if (onSuccess) {
  17623. onSuccess();
  17624. }
  17625. break;
  17626. case C.STATUS_COMPLETED:
  17627. break;
  17628. }
  17629. }
  17630. };
  17631. function InviteServerTransaction(request, ua) {
  17632. this.type = C.INVITE_SERVER;
  17633. this.id = request.via_branch;
  17634. this.request = request;
  17635. this.transport = request.transport;
  17636. this.ua = ua;
  17637. this.last_response = '';
  17638. request.server_transaction = this;
  17639. this.state = C.STATUS_PROCEEDING;
  17640. ua.newTransaction(this);
  17641. this.resendProvisionalTimer = null;
  17642. request.reply(100);
  17643. events.EventEmitter.call(this);
  17644. }
  17645. util.inherits(InviteServerTransaction, events.EventEmitter);
  17646. InviteServerTransaction.prototype.stateChanged = function(state) {
  17647. this.state = state;
  17648. this.emit('stateChanged');
  17649. };
  17650. InviteServerTransaction.prototype.timer_H = function() {
  17651. debugist('Timer H expired for transaction ' + this.id);
  17652. if(this.state === C.STATUS_COMPLETED) {
  17653. debugist('ACK not received, dialog will be terminated');
  17654. }
  17655. this.stateChanged(C.STATUS_TERMINATED);
  17656. this.ua.destroyTransaction(this);
  17657. };
  17658. InviteServerTransaction.prototype.timer_I = function() {
  17659. this.stateChanged(C.STATUS_TERMINATED);
  17660. };
  17661. // RFC 6026 7.1
  17662. InviteServerTransaction.prototype.timer_L = function() {
  17663. debugist('Timer L expired for transaction ' + this.id);
  17664. if(this.state === C.STATUS_ACCEPTED) {
  17665. this.stateChanged(C.STATUS_TERMINATED);
  17666. this.ua.destroyTransaction(this);
  17667. }
  17668. };
  17669. InviteServerTransaction.prototype.onTransportError = function() {
  17670. if (!this.transportError) {
  17671. this.transportError = true;
  17672. debugist('transport error occurred, deleting transaction ' + this.id);
  17673. if (this.resendProvisionalTimer !== null) {
  17674. clearInterval(this.resendProvisionalTimer);
  17675. this.resendProvisionalTimer = null;
  17676. }
  17677. clearTimeout(this.L);
  17678. clearTimeout(this.H);
  17679. clearTimeout(this.I);
  17680. this.stateChanged(C.STATUS_TERMINATED);
  17681. this.ua.destroyTransaction(this);
  17682. }
  17683. };
  17684. InviteServerTransaction.prototype.resend_provisional = function() {
  17685. if(!this.transport.send(this.last_response)) {
  17686. this.onTransportError();
  17687. }
  17688. };
  17689. // INVITE Server Transaction RFC 3261 17.2.1
  17690. InviteServerTransaction.prototype.receiveResponse = function(status_code, response, onSuccess, onFailure) {
  17691. var tr = this;
  17692. if(status_code >= 100 && status_code <= 199) {
  17693. switch(this.state) {
  17694. case C.STATUS_PROCEEDING:
  17695. if(!this.transport.send(response)) {
  17696. this.onTransportError();
  17697. }
  17698. this.last_response = response;
  17699. break;
  17700. }
  17701. }
  17702. if(status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) {
  17703. // Trigger the resendProvisionalTimer only for the first non 100 provisional response.
  17704. if(this.resendProvisionalTimer === null) {
  17705. this.resendProvisionalTimer = setInterval(function() {
  17706. tr.resend_provisional();}, Timers.PROVISIONAL_RESPONSE_INTERVAL);
  17707. }
  17708. } else if(status_code >= 200 && status_code <= 299) {
  17709. switch(this.state) {
  17710. case C.STATUS_PROCEEDING:
  17711. this.stateChanged(C.STATUS_ACCEPTED);
  17712. this.last_response = response;
  17713. this.L = setTimeout(function() {
  17714. tr.timer_L();
  17715. }, Timers.TIMER_L);
  17716. if (this.resendProvisionalTimer !== null) {
  17717. clearInterval(this.resendProvisionalTimer);
  17718. this.resendProvisionalTimer = null;
  17719. }
  17720. /* falls through */
  17721. case C.STATUS_ACCEPTED:
  17722. // Note that this point will be reached for proceeding tr.state also.
  17723. if(!this.transport.send(response)) {
  17724. this.onTransportError();
  17725. if (onFailure) {
  17726. onFailure();
  17727. }
  17728. } else if (onSuccess) {
  17729. onSuccess();
  17730. }
  17731. break;
  17732. }
  17733. } else if(status_code >= 300 && status_code <= 699) {
  17734. switch(this.state) {
  17735. case C.STATUS_PROCEEDING:
  17736. if (this.resendProvisionalTimer !== null) {
  17737. clearInterval(this.resendProvisionalTimer);
  17738. this.resendProvisionalTimer = null;
  17739. }
  17740. if(!this.transport.send(response)) {
  17741. this.onTransportError();
  17742. if (onFailure) {
  17743. onFailure();
  17744. }
  17745. } else {
  17746. this.stateChanged(C.STATUS_COMPLETED);
  17747. this.H = setTimeout(function() {
  17748. tr.timer_H();
  17749. }, Timers.TIMER_H);
  17750. if (onSuccess) {
  17751. onSuccess();
  17752. }
  17753. }
  17754. break;
  17755. }
  17756. }
  17757. };
  17758. /**
  17759. * INVITE:
  17760. * _true_ if retransmission
  17761. * _false_ new request
  17762. *
  17763. * ACK:
  17764. * _true_ ACK to non2xx response
  17765. * _false_ ACK must be passed to TU (accepted state)
  17766. * ACK to 2xx response
  17767. *
  17768. * CANCEL:
  17769. * _true_ no matching invite transaction
  17770. * _false_ matching invite transaction and no final response sent
  17771. *
  17772. * OTHER:
  17773. * _true_ retransmission
  17774. * _false_ new request
  17775. */
  17776. function checkTransaction(ua, request) {
  17777. var tr;
  17778. switch(request.method) {
  17779. case JsSIP_C.INVITE:
  17780. tr = ua.transactions.ist[request.via_branch];
  17781. if(tr) {
  17782. switch(tr.state) {
  17783. case C.STATUS_PROCEEDING:
  17784. tr.transport.send(tr.last_response);
  17785. break;
  17786. // RFC 6026 7.1 Invite retransmission
  17787. //received while in C.STATUS_ACCEPTED state. Absorb it.
  17788. case C.STATUS_ACCEPTED:
  17789. break;
  17790. }
  17791. return true;
  17792. }
  17793. break;
  17794. case JsSIP_C.ACK:
  17795. tr = ua.transactions.ist[request.via_branch];
  17796. // RFC 6026 7.1
  17797. if(tr) {
  17798. if(tr.state === C.STATUS_ACCEPTED) {
  17799. return false;
  17800. } else if(tr.state === C.STATUS_COMPLETED) {
  17801. tr.state = C.STATUS_CONFIRMED;
  17802. tr.I = setTimeout(function() {tr.timer_I();}, Timers.TIMER_I);
  17803. return true;
  17804. }
  17805. }
  17806. // ACK to 2XX Response.
  17807. else {
  17808. return false;
  17809. }
  17810. break;
  17811. case JsSIP_C.CANCEL:
  17812. tr = ua.transactions.ist[request.via_branch];
  17813. if(tr) {
  17814. request.reply_sl(200);
  17815. if(tr.state === C.STATUS_PROCEEDING) {
  17816. return false;
  17817. } else {
  17818. return true;
  17819. }
  17820. } else {
  17821. request.reply_sl(481);
  17822. return true;
  17823. }
  17824. break;
  17825. default:
  17826. // Non-INVITE Server Transaction RFC 3261 17.2.2
  17827. tr = ua.transactions.nist[request.via_branch];
  17828. if(tr) {
  17829. switch(tr.state) {
  17830. case C.STATUS_TRYING:
  17831. break;
  17832. case C.STATUS_PROCEEDING:
  17833. case C.STATUS_COMPLETED:
  17834. tr.transport.send(tr.last_response);
  17835. break;
  17836. }
  17837. return true;
  17838. }
  17839. break;
  17840. }
  17841. }
  17842. },{"./Constants":1,"./Timers":21,"debug":35,"events":29,"util":33}],23:[function(require,module,exports){
  17843. module.exports = Transport;
  17844. /**
  17845. * Dependencies.
  17846. */
  17847. var Socket = require('./Socket');
  17848. var debug = require('debug')('JsSIP:Transport');
  17849. var debugerror = require('debug')('JsSIP:ERROR:Transport');
  17850. /**
  17851. * Constants
  17852. */
  17853. var C = {
  17854. // Transport status
  17855. STATUS_CONNECTED: 0,
  17856. STATUS_CONNECTING: 1,
  17857. STATUS_DISCONNECTED: 2,
  17858. // Socket status
  17859. SOCKET_STATUS_READY: 0,
  17860. SOCKET_STATUS_ERROR: 1,
  17861. // Recovery options
  17862. recovery_options: {
  17863. min_interval: 2, // minimum interval in seconds between recover attempts
  17864. max_interval: 30 // maximum interval in seconds between recover attempts
  17865. }
  17866. };
  17867. /*
  17868. * Manages one or multiple JsSIP.Socket instances.
  17869. * Is reponsible for transport recovery logic among all socket instances.
  17870. *
  17871. * @socket JsSIP::Socket instance
  17872. */
  17873. function Transport(sockets, recovery_options) {
  17874. debug('new()');
  17875. this.status = C.STATUS_DISCONNECTED;
  17876. // current socket
  17877. this.socket = null;
  17878. // socket collection
  17879. this.sockets = [];
  17880. this.recovery_options = recovery_options || C.recovery_options;
  17881. this.recover_attempts = 0;
  17882. this.recovery_timer = null;
  17883. this.close_requested = false;
  17884. if (typeof sockets === 'undefined') {
  17885. throw new TypeError('Invalid argument.' +
  17886. ' undefined \'sockets\' argument');
  17887. }
  17888. if (!(sockets instanceof Array)) {
  17889. sockets = [ sockets ];
  17890. }
  17891. sockets.forEach(function(socket) {
  17892. if (!Socket.isSocket(socket.socket)) {
  17893. throw new TypeError('Invalid argument.' +
  17894. ' invalid \'JsSIP.Socket\' instance');
  17895. }
  17896. if (socket.weight && !Number(socket.weight)) {
  17897. throw new TypeError('Invalid argument.' +
  17898. ' \'weight\' attribute is not a number');
  17899. }
  17900. this.sockets.push({
  17901. socket: socket.socket,
  17902. weight: socket.weight || 0,
  17903. status: C.SOCKET_STATUS_READY
  17904. });
  17905. }, this);
  17906. // read only properties
  17907. Object.defineProperties(this, {
  17908. via_transport: { get: function() { return this.socket.via_transport; } },
  17909. url: { get: function() { return this.socket.url; } },
  17910. sip_uri: { get: function() { return this.socket.sip_uri; } }
  17911. });
  17912. // get the socket with higher weight
  17913. getSocket.call(this);
  17914. }
  17915. /**
  17916. * Instance Methods
  17917. */
  17918. Transport.prototype.connect = function() {
  17919. debug('connect()');
  17920. if (this.isConnected()) {
  17921. debug('Transport is already connected');
  17922. return;
  17923. } else if (this.isConnecting()) {
  17924. debug('Transport is connecting');
  17925. return;
  17926. }
  17927. this.close_requested = false;
  17928. this.status = C.STATUS_CONNECTING;
  17929. this.onconnecting({ socket:this.socket, attempts:this.recover_attempts });
  17930. if (!this.close_requested) {
  17931. // bind socket event callbacks
  17932. this.socket.onconnect = onConnect.bind(this);
  17933. this.socket.ondisconnect = onDisconnect.bind(this);
  17934. this.socket.ondata = onData.bind(this);
  17935. this.socket.connect();
  17936. }
  17937. return;
  17938. };
  17939. Transport.prototype.disconnect = function() {
  17940. debug('close()');
  17941. this.close_requested = true;
  17942. this.recover_attempts = 0;
  17943. this.status = C.STATUS_DISCONNECTED;
  17944. // clear recovery_timer
  17945. if (this.recovery_timer !== null) {
  17946. clearTimeout(this.recovery_timer);
  17947. this.recovery_timer = null;
  17948. }
  17949. // unbind socket event callbacks
  17950. this.socket.onconnect = function() {};
  17951. this.socket.ondisconnect = function() {};
  17952. this.socket.ondata = function() {};
  17953. this.socket.disconnect();
  17954. this.ondisconnect();
  17955. };
  17956. Transport.prototype.send = function(data) {
  17957. debug('send()');
  17958. if (!this.isConnected()) {
  17959. debugerror('unable to send message, transport is not connected');
  17960. return false;
  17961. }
  17962. var message = data.toString();
  17963. debug('sending message:\n\n' + message + '\n');
  17964. return this.socket.send(message);
  17965. };
  17966. Transport.prototype.isConnected = function() {
  17967. return this.status === C.STATUS_CONNECTED;
  17968. };
  17969. Transport.prototype.isConnecting = function() {
  17970. return this.status === C.STATUS_CONNECTING;
  17971. };
  17972. /**
  17973. * Socket Event Handlers
  17974. */
  17975. function onConnect() {
  17976. this.recover_attempts = 0;
  17977. this.status = C.STATUS_CONNECTED;
  17978. // clear recovery_timer
  17979. if (this.recovery_timer !== null) {
  17980. clearTimeout(this.recovery_timer);
  17981. this.recovery_timer = null;
  17982. }
  17983. this.onconnect( {socket:this} );
  17984. }
  17985. function onDisconnect(error, code, reason) {
  17986. this.status = C.STATUS_DISCONNECTED;
  17987. this.ondisconnect({ socket:this.socket, error:error, code:code, reason:reason });
  17988. if (this.close_requested) {
  17989. return;
  17990. }
  17991. // update socket status
  17992. else {
  17993. this.sockets.forEach(function(socket) {
  17994. if (this.socket === socket.socket) {
  17995. socket.status = C.SOCKET_STATUS_ERROR;
  17996. }
  17997. }, this);
  17998. }
  17999. reconnect.call(this, error);
  18000. }
  18001. function onData(data) {
  18002. // CRLF Keep Alive response from server. Ignore it.
  18003. if(data === '\r\n') {
  18004. debug('received message with CRLF Keep Alive response');
  18005. return;
  18006. }
  18007. // binary message.
  18008. else if (typeof data !== 'string') {
  18009. try {
  18010. data = String.fromCharCode.apply(null, new Uint8Array(data));
  18011. } catch(evt) {
  18012. debug('received binary message failed to be converted into string,' +
  18013. ' message discarded');
  18014. return;
  18015. }
  18016. debug('received binary message:\n\n' + data + '\n');
  18017. }
  18018. // text message.
  18019. else {
  18020. debug('received text message:\n\n' + data + '\n');
  18021. }
  18022. this.ondata({ transport:this, message:data });
  18023. }
  18024. function reconnect() {
  18025. var k,
  18026. self = this;
  18027. this.recover_attempts+=1;
  18028. k = Math.floor((Math.random() * Math.pow(2,this.recover_attempts)) +1);
  18029. if (k < this.recovery_options.min_interval) {
  18030. k = this.recovery_options.min_interval;
  18031. }
  18032. else if (k > this.recovery_options.max_interval) {
  18033. k = this.recovery_options.max_interval;
  18034. }
  18035. debug('reconnection attempt: '+ this.recover_attempts +
  18036. '. next connection attempt in '+ k +' seconds');
  18037. this.recovery_timer = setTimeout(function() {
  18038. if (!self.close_requested && !(self.isConnected() || self.isConnecting())) {
  18039. // get the next available socket with higher weight
  18040. getSocket.call(self);
  18041. // connect the socket
  18042. self.connect();
  18043. }
  18044. }, k * 1000);
  18045. }
  18046. /**
  18047. * get the next available socket with higher weight
  18048. */
  18049. function getSocket() {
  18050. var candidates = [];
  18051. this.sockets.forEach(function(socket) {
  18052. if (socket.status === C.SOCKET_STATUS_ERROR) {
  18053. return; // continue the array iteration
  18054. } else if (candidates.length === 0) {
  18055. candidates.push(socket);
  18056. } else if (socket.weight > candidates[0].weight) {
  18057. candidates = [socket];
  18058. } else if (socket.weight === candidates[0].weight) {
  18059. candidates.push(socket);
  18060. }
  18061. });
  18062. if (candidates.length === 0) {
  18063. // all sockets have failed. reset sockets status
  18064. this.sockets.forEach(function(socket) {
  18065. socket.status = C.SOCKET_STATUS_READY;
  18066. });
  18067. // get next available socket
  18068. getSocket.call(this);
  18069. return;
  18070. }
  18071. var idx = Math.floor((Math.random()* candidates.length));
  18072. this.socket = candidates[idx].socket;
  18073. }
  18074. },{"./Socket":20,"debug":35}],24:[function(require,module,exports){
  18075. module.exports = UA;
  18076. var C = {
  18077. // UA status codes
  18078. STATUS_INIT : 0,
  18079. STATUS_READY: 1,
  18080. STATUS_USER_CLOSED: 2,
  18081. STATUS_NOT_READY: 3,
  18082. // UA error codes
  18083. CONFIGURATION_ERROR: 1,
  18084. NETWORK_ERROR: 2
  18085. };
  18086. /**
  18087. * Expose C object.
  18088. */
  18089. UA.C = C;
  18090. /**
  18091. * Dependencies.
  18092. */
  18093. var util = require('util');
  18094. var events = require('events');
  18095. var debug = require('debug')('JsSIP:UA');
  18096. var debugerror = require('debug')('JsSIP:ERROR:UA');
  18097. debugerror.log = console.warn.bind(console);
  18098. var JsSIP_C = require('./Constants');
  18099. var Registrator = require('./Registrator');
  18100. var RTCSession = require('./RTCSession');
  18101. var Message = require('./Message');
  18102. var Transactions = require('./Transactions');
  18103. var Transport = require('./Transport');
  18104. var Socket = require('./Socket');
  18105. var Utils = require('./Utils');
  18106. var Exceptions = require('./Exceptions');
  18107. var URI = require('./URI');
  18108. var Grammar = require('./Grammar');
  18109. var Parser = require('./Parser');
  18110. var SIPMessage = require('./SIPMessage');
  18111. var sanityCheck = require('./sanityCheck');
  18112. /**
  18113. * The User-Agent class.
  18114. * @class JsSIP.UA
  18115. * @param {Object} configuration Configuration parameters.
  18116. * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid.
  18117. * @throws {TypeError} If no configuration is given.
  18118. */
  18119. function UA(configuration) {
  18120. debug('new() [configuration:%o]', configuration);
  18121. this.cache = {
  18122. credentials: {}
  18123. };
  18124. this.configuration = {};
  18125. this.dynConfiguration = {};
  18126. this.dialogs = {};
  18127. //User actions outside any session/dialog (MESSAGE)
  18128. this.applicants = {};
  18129. this.sessions = {};
  18130. this.transport = null;
  18131. this.contact = null;
  18132. this.status = C.STATUS_INIT;
  18133. this.error = null;
  18134. this.transactions = {
  18135. nist: {},
  18136. nict: {},
  18137. ist: {},
  18138. ict: {}
  18139. };
  18140. // Custom UA empty object for high level use
  18141. this.data = {};
  18142. this.closeTimer = null;
  18143. Object.defineProperties(this, {
  18144. transactionsCount: {
  18145. get: function() {
  18146. var type,
  18147. transactions = ['nist','nict','ist','ict'],
  18148. count = 0;
  18149. for (type in transactions) {
  18150. count += Object.keys(this.transactions[transactions[type]]).length;
  18151. }
  18152. return count;
  18153. }
  18154. },
  18155. nictTransactionsCount: {
  18156. get: function() {
  18157. return Object.keys(this.transactions.nict).length;
  18158. }
  18159. },
  18160. nistTransactionsCount: {
  18161. get: function() {
  18162. return Object.keys(this.transactions.nist).length;
  18163. }
  18164. },
  18165. ictTransactionsCount: {
  18166. get: function() {
  18167. return Object.keys(this.transactions.ict).length;
  18168. }
  18169. },
  18170. istTransactionsCount: {
  18171. get: function() {
  18172. return Object.keys(this.transactions.ist).length;
  18173. }
  18174. }
  18175. });
  18176. /**
  18177. * Load configuration
  18178. */
  18179. if(configuration === undefined) {
  18180. throw new TypeError('Not enough arguments');
  18181. }
  18182. try {
  18183. this.loadConfig(configuration);
  18184. } catch(e) {
  18185. this.status = C.STATUS_NOT_READY;
  18186. this.error = C.CONFIGURATION_ERROR;
  18187. throw e;
  18188. }
  18189. // Initialize registrator
  18190. this._registrator = new Registrator(this);
  18191. events.EventEmitter.call(this);
  18192. }
  18193. util.inherits(UA, events.EventEmitter);
  18194. //=================
  18195. // High Level API
  18196. //=================
  18197. /**
  18198. * Connect to the server if status = STATUS_INIT.
  18199. * Resume UA after being closed.
  18200. */
  18201. UA.prototype.start = function() {
  18202. debug('start()');
  18203. if (this.status === C.STATUS_INIT) {
  18204. this.transport.connect();
  18205. } else if(this.status === C.STATUS_USER_CLOSED) {
  18206. debug('restarting UA');
  18207. // disconnect
  18208. if (this.closeTimer !== null) {
  18209. clearTimeout(this.closeTimer);
  18210. this.closeTimer = null;
  18211. this.transport.disconnect();
  18212. }
  18213. // reconnect
  18214. this.status = C.STATUS_INIT;
  18215. this.transport.connect();
  18216. } else if (this.status === C.STATUS_READY) {
  18217. debug('UA is in READY status, not restarted');
  18218. } else {
  18219. debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect');
  18220. }
  18221. // Set dynamic configuration.
  18222. this.dynConfiguration.register = this.configuration.register;
  18223. };
  18224. /**
  18225. * Register.
  18226. */
  18227. UA.prototype.register = function() {
  18228. debug('register()');
  18229. this.dynConfiguration.register = true;
  18230. this._registrator.register();
  18231. };
  18232. /**
  18233. * Unregister.
  18234. */
  18235. UA.prototype.unregister = function(options) {
  18236. debug('unregister()');
  18237. this.dynConfiguration.register = false;
  18238. this._registrator.unregister(options);
  18239. };
  18240. /**
  18241. * Get the Registrator instance.
  18242. */
  18243. UA.prototype.registrator = function() {
  18244. return this._registrator;
  18245. };
  18246. /**
  18247. * Registration state.
  18248. */
  18249. UA.prototype.isRegistered = function() {
  18250. if(this._registrator.registered) {
  18251. return true;
  18252. } else {
  18253. return false;
  18254. }
  18255. };
  18256. /**
  18257. * Connection state.
  18258. */
  18259. UA.prototype.isConnected = function() {
  18260. return this.transport.isConnected();
  18261. };
  18262. /**
  18263. * Make an outgoing call.
  18264. *
  18265. * -param {String} target
  18266. * -param {Object} views
  18267. * -param {Object} [options]
  18268. *
  18269. * -throws {TypeError}
  18270. *
  18271. */
  18272. UA.prototype.call = function(target, options) {
  18273. debug('call()');
  18274. var session;
  18275. session = new RTCSession(this);
  18276. session.connect(target, options);
  18277. return session;
  18278. };
  18279. /**
  18280. * Send a message.
  18281. *
  18282. * -param {String} target
  18283. * -param {String} body
  18284. * -param {Object} [options]
  18285. *
  18286. * -throws {TypeError}
  18287. *
  18288. */
  18289. UA.prototype.sendMessage = function(target, body, options) {
  18290. debug('sendMessage()');
  18291. var message;
  18292. message = new Message(this);
  18293. message.send(target, body, options);
  18294. return message;
  18295. };
  18296. /**
  18297. * Terminate ongoing sessions.
  18298. */
  18299. UA.prototype.terminateSessions = function(options) {
  18300. debug('terminateSessions()');
  18301. for(var idx in this.sessions) {
  18302. if (!this.sessions[idx].isEnded()) {
  18303. this.sessions[idx].terminate(options);
  18304. }
  18305. }
  18306. };
  18307. /**
  18308. * Gracefully close.
  18309. *
  18310. */
  18311. UA.prototype.stop = function() {
  18312. debug('stop()');
  18313. var session;
  18314. var applicant;
  18315. var num_sessions;
  18316. var ua = this;
  18317. // Remove dynamic settings.
  18318. this.dynConfiguration = {};
  18319. if(this.status === C.STATUS_USER_CLOSED) {
  18320. debug('UA already closed');
  18321. return;
  18322. }
  18323. // Close registrator
  18324. this._registrator.close();
  18325. // If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
  18326. num_sessions = Object.keys(this.sessions).length;
  18327. // Run _terminate_ on every Session
  18328. for(session in this.sessions) {
  18329. debug('closing session ' + session);
  18330. try { this.sessions[session].terminate(); } catch(error) {}
  18331. }
  18332. // Run _close_ on every applicant
  18333. for(applicant in this.applicants) {
  18334. try { this.applicants[applicant].close(); } catch(error) {}
  18335. }
  18336. this.status = C.STATUS_USER_CLOSED;
  18337. if (this.nistTransactionsCount === 0 &&
  18338. this.nictTransactionsCount === 0 &&
  18339. this.ictTransactionsCount === 0 &&
  18340. this.istTransactionsCount === 0 &&
  18341. num_sessions === 0) {
  18342. ua.transport.disconnect();
  18343. }
  18344. else {
  18345. this.closeTimer = setTimeout(function() {
  18346. ua.closeTimer = null;
  18347. ua.transport.disconnect();
  18348. }, 2000);
  18349. }
  18350. };
  18351. /**
  18352. * Normalice a string into a valid SIP request URI
  18353. * -param {String} target
  18354. * -returns {JsSIP.URI|undefined}
  18355. */
  18356. UA.prototype.normalizeTarget = function(target) {
  18357. return Utils.normalizeTarget(target, this.configuration.hostport_params);
  18358. };
  18359. /**
  18360. * Allow retrieving configuration and autogenerated fields in runtime.
  18361. */
  18362. UA.prototype.get = function(parameter) {
  18363. switch(parameter) {
  18364. case 'realm':
  18365. return this.configuration.realm;
  18366. case 'ha1':
  18367. return this.configuration.ha1;
  18368. default:
  18369. debugerror('get() | cannot get "%s" parameter in runtime', parameter);
  18370. return undefined;
  18371. }
  18372. return true;
  18373. };
  18374. /**
  18375. * Allow configuration changes in runtime.
  18376. * Returns true if the parameter could be set.
  18377. */
  18378. UA.prototype.set = function(parameter, value) {
  18379. switch(parameter) {
  18380. case 'password': {
  18381. this.configuration.password = String(value);
  18382. break;
  18383. }
  18384. case 'realm': {
  18385. this.configuration.realm = String(value);
  18386. break;
  18387. }
  18388. case 'ha1': {
  18389. this.configuration.ha1 = String(value);
  18390. // Delete the plain SIP password.
  18391. this.configuration.password = null;
  18392. break;
  18393. }
  18394. case 'display_name': {
  18395. if (Grammar.parse('"' + value + '"', 'display_name') === -1) {
  18396. debugerror('set() | wrong "display_name"');
  18397. return false;
  18398. }
  18399. this.configuration.display_name = value;
  18400. break;
  18401. }
  18402. default:
  18403. debugerror('set() | cannot set "%s" parameter in runtime', parameter);
  18404. return false;
  18405. }
  18406. return true;
  18407. };
  18408. //===============================
  18409. // Private (For internal use)
  18410. //===============================
  18411. // UA.prototype.saveCredentials = function(credentials) {
  18412. // this.cache.credentials[credentials.realm] = this.cache.credentials[credentials.realm] || {};
  18413. // this.cache.credentials[credentials.realm][credentials.uri] = credentials;
  18414. // };
  18415. // UA.prototype.getCredentials = function(request) {
  18416. // var realm, credentials;
  18417. // realm = request.ruri.host;
  18418. // if (this.cache.credentials[realm] && this.cache.credentials[realm][request.ruri]) {
  18419. // credentials = this.cache.credentials[realm][request.ruri];
  18420. // credentials.method = request.method;
  18421. // }
  18422. // return credentials;
  18423. // };
  18424. //==========================
  18425. // Event Handlers
  18426. //==========================
  18427. /**
  18428. * new Transaction
  18429. */
  18430. UA.prototype.newTransaction = function(transaction) {
  18431. this.transactions[transaction.type][transaction.id] = transaction;
  18432. this.emit('newTransaction', {
  18433. transaction: transaction
  18434. });
  18435. };
  18436. /**
  18437. * Transaction destroyed.
  18438. */
  18439. UA.prototype.destroyTransaction = function(transaction) {
  18440. delete this.transactions[transaction.type][transaction.id];
  18441. this.emit('transactionDestroyed', {
  18442. transaction: transaction
  18443. });
  18444. };
  18445. /**
  18446. * new Message
  18447. */
  18448. UA.prototype.newMessage = function(data) {
  18449. this.emit('newMessage', data);
  18450. };
  18451. /**
  18452. * new RTCSession
  18453. */
  18454. UA.prototype.newRTCSession = function(data) {
  18455. this.emit('newRTCSession', data);
  18456. };
  18457. /**
  18458. * Registered
  18459. */
  18460. UA.prototype.registered = function(data) {
  18461. this.emit('registered', data);
  18462. };
  18463. /**
  18464. * Unregistered
  18465. */
  18466. UA.prototype.unregistered = function(data) {
  18467. this.emit('unregistered', data);
  18468. };
  18469. /**
  18470. * Registration Failed
  18471. */
  18472. UA.prototype.registrationFailed = function(data) {
  18473. this.emit('registrationFailed', data);
  18474. };
  18475. //=========================
  18476. // receiveRequest
  18477. //=========================
  18478. /**
  18479. * Request reception
  18480. */
  18481. UA.prototype.receiveRequest = function(request) {
  18482. var dialog, session, message, replaces,
  18483. method = request.method;
  18484. // Check that request URI points to us
  18485. if(request.ruri.user !== this.configuration.uri.user && request.ruri.user !== this.contact.uri.user) {
  18486. debug('Request-URI does not point to us');
  18487. if (request.method !== JsSIP_C.ACK) {
  18488. request.reply_sl(404);
  18489. }
  18490. return;
  18491. }
  18492. // Check request URI scheme
  18493. if(request.ruri.scheme === JsSIP_C.SIPS) {
  18494. request.reply_sl(416);
  18495. return;
  18496. }
  18497. // Check transaction
  18498. if(Transactions.checkTransaction(this, request)) {
  18499. return;
  18500. }
  18501. // Create the server transaction
  18502. if(method === JsSIP_C.INVITE) {
  18503. new Transactions.InviteServerTransaction(request, this);
  18504. } else if(method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) {
  18505. new Transactions.NonInviteServerTransaction(request, this);
  18506. }
  18507. /* RFC3261 12.2.2
  18508. * Requests that do not change in any way the state of a dialog may be
  18509. * received within a dialog (for example, an OPTIONS request).
  18510. * They are processed as if they had been received outside the dialog.
  18511. */
  18512. if(method === JsSIP_C.OPTIONS) {
  18513. request.reply(200);
  18514. } else if (method === JsSIP_C.MESSAGE) {
  18515. if (this.listeners('newMessage').length === 0) {
  18516. request.reply(405);
  18517. return;
  18518. }
  18519. message = new Message(this);
  18520. message.init_incoming(request);
  18521. } else if (method === JsSIP_C.INVITE) {
  18522. // Initial INVITE
  18523. if(!request.to_tag && this.listeners('newRTCSession').length === 0) {
  18524. request.reply(405);
  18525. return;
  18526. }
  18527. }
  18528. // Initial Request
  18529. if(!request.to_tag) {
  18530. switch(method) {
  18531. case JsSIP_C.INVITE:
  18532. if (window.RTCPeerConnection) { // TODO
  18533. if (request.hasHeader('replaces')) {
  18534. replaces = request.replaces;
  18535. dialog = this.findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag);
  18536. if (dialog) {
  18537. session = dialog.owner;
  18538. if (!session.isEnded()) {
  18539. session.receiveRequest(request);
  18540. } else {
  18541. request.reply(603);
  18542. }
  18543. } else {
  18544. request.reply(481);
  18545. }
  18546. } else {
  18547. session = new RTCSession(this);
  18548. session.init_incoming(request);
  18549. }
  18550. } else {
  18551. debugerror('INVITE received but WebRTC is not supported');
  18552. request.reply(488);
  18553. }
  18554. break;
  18555. case JsSIP_C.BYE:
  18556. // Out of dialog BYE received
  18557. request.reply(481);
  18558. break;
  18559. case JsSIP_C.CANCEL:
  18560. session = this.findSession(request);
  18561. if (session) {
  18562. session.receiveRequest(request);
  18563. } else {
  18564. debug('received CANCEL request for a non existent session');
  18565. }
  18566. break;
  18567. case JsSIP_C.ACK:
  18568. /* Absorb it.
  18569. * ACK request without a corresponding Invite Transaction
  18570. * and without To tag.
  18571. */
  18572. break;
  18573. default:
  18574. request.reply(405);
  18575. break;
  18576. }
  18577. }
  18578. // In-dialog request
  18579. else {
  18580. dialog = this.findDialog(request.call_id, request.from_tag, request.to_tag);
  18581. if(dialog) {
  18582. dialog.receiveRequest(request);
  18583. } else if (method === JsSIP_C.NOTIFY) {
  18584. session = this.findSession(request);
  18585. if(session) {
  18586. session.receiveRequest(request);
  18587. } else {
  18588. debug('received NOTIFY request for a non existent subscription');
  18589. request.reply(481, 'Subscription does not exist');
  18590. }
  18591. }
  18592. /* RFC3261 12.2.2
  18593. * Request with to tag, but no matching dialog found.
  18594. * Exception: ACK for an Invite request for which a dialog has not
  18595. * been created.
  18596. */
  18597. else {
  18598. if(method !== JsSIP_C.ACK) {
  18599. request.reply(481);
  18600. }
  18601. }
  18602. }
  18603. };
  18604. //=================
  18605. // Utils
  18606. //=================
  18607. /**
  18608. * Get the session to which the request belongs to, if any.
  18609. */
  18610. UA.prototype.findSession = function(request) {
  18611. var
  18612. sessionIDa = request.call_id + request.from_tag,
  18613. sessionA = this.sessions[sessionIDa],
  18614. sessionIDb = request.call_id + request.to_tag,
  18615. sessionB = this.sessions[sessionIDb];
  18616. if(sessionA) {
  18617. return sessionA;
  18618. } else if(sessionB) {
  18619. return sessionB;
  18620. } else {
  18621. return null;
  18622. }
  18623. };
  18624. /**
  18625. * Get the dialog to which the request belongs to, if any.
  18626. */
  18627. UA.prototype.findDialog = function(call_id, from_tag, to_tag) {
  18628. var
  18629. id = call_id + from_tag + to_tag,
  18630. dialog = this.dialogs[id];
  18631. if(dialog) {
  18632. return dialog;
  18633. } else {
  18634. id = call_id + to_tag + from_tag;
  18635. dialog = this.dialogs[id];
  18636. if(dialog) {
  18637. return dialog;
  18638. } else {
  18639. return null;
  18640. }
  18641. }
  18642. };
  18643. UA.prototype.loadConfig = function(configuration) {
  18644. // Settings and default values
  18645. var parameter, value, checked_value, hostport_params, registrar_server,
  18646. settings = {
  18647. /* Host address
  18648. * Value to be set in Via sent_by and host part of Contact FQDN
  18649. */
  18650. via_host: Utils.createRandomToken(12) + '.invalid',
  18651. // SIP Contact URI
  18652. contact_uri: null,
  18653. // SIP authentication password
  18654. password: null,
  18655. // SIP authentication realm
  18656. realm: null,
  18657. // SIP authentication HA1 hash
  18658. ha1: null,
  18659. // Registration parameters
  18660. register_expires: 600,
  18661. register: true,
  18662. registrar_server: null,
  18663. use_preloaded_route: false,
  18664. // Session parameters
  18665. no_answer_timeout: 60,
  18666. session_timers: true,
  18667. };
  18668. // Pre-Configuration
  18669. // Check Mandatory parameters
  18670. for(parameter in UA.configuration_check.mandatory) {
  18671. if(!configuration.hasOwnProperty(parameter)) {
  18672. throw new Exceptions.ConfigurationError(parameter);
  18673. } else {
  18674. value = configuration[parameter];
  18675. checked_value = UA.configuration_check.mandatory[parameter].call(this, value);
  18676. if (checked_value !== undefined) {
  18677. settings[parameter] = checked_value;
  18678. } else {
  18679. throw new Exceptions.ConfigurationError(parameter, value);
  18680. }
  18681. }
  18682. }
  18683. // Check Optional parameters
  18684. for(parameter in UA.configuration_check.optional) {
  18685. if(configuration.hasOwnProperty(parameter)) {
  18686. value = configuration[parameter];
  18687. /* If the parameter value is null, empty string, undefined, empty array
  18688. * or it's a number with NaN value, then apply its default value.
  18689. */
  18690. if (Utils.isEmpty(value)) {
  18691. continue;
  18692. }
  18693. checked_value = UA.configuration_check.optional[parameter].call(this, value, configuration);
  18694. if (checked_value !== undefined) {
  18695. settings[parameter] = checked_value;
  18696. } else {
  18697. throw new Exceptions.ConfigurationError(parameter, value);
  18698. }
  18699. }
  18700. }
  18701. // Post Configuration Process
  18702. // Allow passing 0 number as display_name.
  18703. if (settings.display_name === 0) {
  18704. settings.display_name = '0';
  18705. }
  18706. // Instance-id for GRUU.
  18707. if (!settings.instance_id) {
  18708. settings.instance_id = Utils.newUUID();
  18709. }
  18710. // jssip_id instance parameter. Static random tag of length 5.
  18711. settings.jssip_id = Utils.createRandomToken(5);
  18712. // String containing settings.uri without scheme and user.
  18713. hostport_params = settings.uri.clone();
  18714. hostport_params.user = null;
  18715. settings.hostport_params = hostport_params.toString().replace(/^sip:/i, '');
  18716. // Transport
  18717. var sockets = [];
  18718. if (settings.sockets && Array.isArray(settings.sockets)) {
  18719. sockets = sockets.concat(settings.sockets);
  18720. }
  18721. if (sockets.length === 0) {
  18722. throw new Exceptions.ConfigurationError('sockets');
  18723. }
  18724. try {
  18725. this.transport = new Transport(sockets, { /* recovery options */
  18726. max_interval: settings.connection_recovery_max_interval,
  18727. min_interval: settings.connection_recovery_min_interval
  18728. });
  18729. // Transport event callbacks
  18730. this.transport.onconnecting = onTransportConnecting.bind(this);
  18731. this.transport.onconnect = onTransportConnect.bind(this);
  18732. this.transport.ondisconnect = onTransportDisconnect.bind(this);
  18733. this.transport.ondata = onTransportData.bind(this);
  18734. // transport options not needed here anymore
  18735. delete settings.connection_recovery_max_interval;
  18736. delete settings.connection_recovery_min_interval;
  18737. delete settings.sockets;
  18738. } catch (e) {
  18739. debugerror(e);
  18740. throw new Exceptions.ConfigurationError('sockets', sockets);
  18741. }
  18742. // Check whether authorization_user is explicitly defined.
  18743. // Take 'settings.uri.user' value if not.
  18744. if (!settings.authorization_user) {
  18745. settings.authorization_user = settings.uri.user;
  18746. }
  18747. // If no 'registrar_server' is set use the 'uri' value without user portion and
  18748. // without URI params/headers.
  18749. if (!settings.registrar_server) {
  18750. registrar_server = settings.uri.clone();
  18751. registrar_server.user = null;
  18752. registrar_server.clearParams();
  18753. registrar_server.clearHeaders();
  18754. settings.registrar_server = registrar_server;
  18755. }
  18756. // User no_answer_timeout.
  18757. settings.no_answer_timeout = settings.no_answer_timeout * 1000;
  18758. // Via Host
  18759. if (settings.contact_uri) {
  18760. settings.via_host = settings.contact_uri.host;
  18761. }
  18762. // Contact URI
  18763. else {
  18764. settings.contact_uri = new URI('sip', Utils.createRandomToken(8), settings.via_host, null, {transport: 'ws'});
  18765. }
  18766. this.contact = {
  18767. pub_gruu: null,
  18768. temp_gruu: null,
  18769. uri: settings.contact_uri,
  18770. toString: function(options) {
  18771. options = options || {};
  18772. var
  18773. anonymous = options.anonymous || null,
  18774. outbound = options.outbound || null,
  18775. contact = '<';
  18776. if (anonymous) {
  18777. contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
  18778. } else {
  18779. contact += this.pub_gruu || this.uri.toString();
  18780. }
  18781. if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) {
  18782. contact += ';ob';
  18783. }
  18784. contact += '>';
  18785. return contact;
  18786. }
  18787. };
  18788. // Fill the value of the configuration_skeleton
  18789. for(parameter in settings) {
  18790. UA.configuration_skeleton[parameter].value = settings[parameter];
  18791. }
  18792. Object.defineProperties(this.configuration, UA.configuration_skeleton);
  18793. // Clean UA.configuration_skeleton
  18794. for(parameter in settings) {
  18795. UA.configuration_skeleton[parameter].value = '';
  18796. }
  18797. debug('configuration parameters after validation:');
  18798. for(parameter in settings) {
  18799. switch(parameter) {
  18800. case 'uri':
  18801. case 'registrar_server':
  18802. debug('- ' + parameter + ': ' + settings[parameter]);
  18803. break;
  18804. case 'password':
  18805. case 'ha1':
  18806. debug('- ' + parameter + ': ' + 'NOT SHOWN');
  18807. break;
  18808. default:
  18809. debug('- ' + parameter + ': ' + JSON.stringify(settings[parameter]));
  18810. }
  18811. }
  18812. return;
  18813. };
  18814. /**
  18815. * Configuration Object skeleton.
  18816. */
  18817. UA.configuration_skeleton = (function() {
  18818. var
  18819. idx, parameter, writable,
  18820. skeleton = {},
  18821. parameters = [
  18822. // Internal parameters
  18823. 'jssip_id',
  18824. 'hostport_params',
  18825. // Mandatory user configurable parameters
  18826. 'uri',
  18827. // Optional user configurable parameters
  18828. 'authorization_user',
  18829. 'contact_uri',
  18830. 'display_name',
  18831. 'instance_id',
  18832. 'no_answer_timeout', // 30 seconds
  18833. 'session_timers', // true
  18834. 'password',
  18835. 'realm',
  18836. 'ha1',
  18837. 'register_expires', // 600 seconds
  18838. 'registrar_server',
  18839. 'sockets',
  18840. 'use_preloaded_route',
  18841. // Post-configuration generated parameters
  18842. 'via_core_value',
  18843. 'via_host'
  18844. ];
  18845. var writable_parameters = [
  18846. 'password', 'realm', 'ha1', 'display_name'
  18847. ];
  18848. for(idx in parameters) {
  18849. parameter = parameters[idx];
  18850. if (writable_parameters.indexOf(parameter) !== -1) {
  18851. writable = true;
  18852. } else {
  18853. writable = false;
  18854. }
  18855. skeleton[parameter] = {
  18856. value: '',
  18857. writable: writable,
  18858. configurable: false
  18859. };
  18860. }
  18861. skeleton.register = {
  18862. value: '',
  18863. writable: true,
  18864. configurable: false
  18865. };
  18866. return skeleton;
  18867. }());
  18868. /**
  18869. * Configuration checker.
  18870. */
  18871. UA.configuration_check = {
  18872. mandatory: {
  18873. uri: function(uri) {
  18874. var parsed;
  18875. if (!/^sip:/i.test(uri)) {
  18876. uri = JsSIP_C.SIP + ':' + uri;
  18877. }
  18878. parsed = URI.parse(uri);
  18879. if(!parsed) {
  18880. return;
  18881. } else if(!parsed.user) {
  18882. return;
  18883. } else {
  18884. return parsed;
  18885. }
  18886. }
  18887. },
  18888. optional: {
  18889. authorization_user: function(authorization_user) {
  18890. if(Grammar.parse('"'+ authorization_user +'"', 'quoted_string') === -1) {
  18891. return;
  18892. } else {
  18893. return authorization_user;
  18894. }
  18895. },
  18896. connection_recovery_max_interval: function(connection_recovery_max_interval) {
  18897. var value;
  18898. if(Utils.isDecimal(connection_recovery_max_interval)) {
  18899. value = Number(connection_recovery_max_interval);
  18900. if(value > 0) {
  18901. return value;
  18902. }
  18903. }
  18904. },
  18905. connection_recovery_min_interval: function(connection_recovery_min_interval) {
  18906. var value;
  18907. if(Utils.isDecimal(connection_recovery_min_interval)) {
  18908. value = Number(connection_recovery_min_interval);
  18909. if(value > 0) {
  18910. return value;
  18911. }
  18912. }
  18913. },
  18914. contact_uri: function(contact_uri) {
  18915. if (typeof contact_uri === 'string') {
  18916. var uri = Grammar.parse(contact_uri,'SIP_URI');
  18917. if (uri !== -1) {
  18918. return uri;
  18919. }
  18920. }
  18921. },
  18922. display_name: function(display_name) {
  18923. if (Grammar.parse('"' + display_name + '"', 'display_name') === -1) {
  18924. return;
  18925. } else {
  18926. return display_name;
  18927. }
  18928. },
  18929. instance_id: function(instance_id) {
  18930. if ((/^uuid:/i.test(instance_id))) {
  18931. instance_id = instance_id.substr(5);
  18932. }
  18933. if(Grammar.parse(instance_id, 'uuid') === -1) {
  18934. return;
  18935. } else {
  18936. return instance_id;
  18937. }
  18938. },
  18939. no_answer_timeout: function(no_answer_timeout) {
  18940. var value;
  18941. if (Utils.isDecimal(no_answer_timeout)) {
  18942. value = Number(no_answer_timeout);
  18943. if (value > 0) {
  18944. return value;
  18945. }
  18946. }
  18947. },
  18948. session_timers: function(session_timers) {
  18949. if (typeof session_timers === 'boolean') {
  18950. return session_timers;
  18951. }
  18952. },
  18953. password: function(password) {
  18954. return String(password);
  18955. },
  18956. realm: function(realm) {
  18957. return String(realm);
  18958. },
  18959. ha1: function(ha1) {
  18960. return String(ha1);
  18961. },
  18962. register: function(register) {
  18963. if (typeof register === 'boolean') {
  18964. return register;
  18965. }
  18966. },
  18967. register_expires: function(register_expires) {
  18968. var value;
  18969. if (Utils.isDecimal(register_expires)) {
  18970. value = Number(register_expires);
  18971. if (value > 0) {
  18972. return value;
  18973. }
  18974. }
  18975. },
  18976. registrar_server: function(registrar_server) {
  18977. var parsed;
  18978. if (!/^sip:/i.test(registrar_server)) {
  18979. registrar_server = JsSIP_C.SIP + ':' + registrar_server;
  18980. }
  18981. parsed = URI.parse(registrar_server);
  18982. if(!parsed) {
  18983. return;
  18984. } else if(parsed.user) {
  18985. return;
  18986. } else {
  18987. return parsed;
  18988. }
  18989. },
  18990. sockets: function(sockets) {
  18991. var idx, length;
  18992. /* Allow defining sockets parameter as:
  18993. * Socket: socket
  18994. * Array of Socket: [socket1, socket2]
  18995. * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}]
  18996. * Array of Objects and Socket: [{socket: socket1}, socket2]
  18997. */
  18998. if (Socket.isSocket(sockets)) {
  18999. sockets = [{socket: sockets}];
  19000. } else if (Array.isArray(sockets) && sockets.length) {
  19001. length = sockets.length;
  19002. for (idx = 0; idx < length; idx++) {
  19003. if (Socket.isSocket(sockets[idx])) {
  19004. sockets[idx] = {socket: sockets[idx]};
  19005. }
  19006. }
  19007. } else {
  19008. return;
  19009. }
  19010. return sockets;
  19011. },
  19012. use_preloaded_route: function(use_preloaded_route) {
  19013. if (typeof use_preloaded_route === 'boolean') {
  19014. return use_preloaded_route;
  19015. }
  19016. }
  19017. }
  19018. };
  19019. /**
  19020. * Transport event handlers
  19021. */
  19022. // Transport connecting event
  19023. function onTransportConnecting(data) {
  19024. this.emit('connecting', data);
  19025. }
  19026. // Transport connected event.
  19027. function onTransportConnect(data) {
  19028. if(this.status === C.STATUS_USER_CLOSED) {
  19029. return;
  19030. }
  19031. this.status = C.STATUS_READY;
  19032. this.error = null;
  19033. this.emit('connected', data);
  19034. if(this.dynConfiguration.register) {
  19035. this._registrator.register();
  19036. }
  19037. }
  19038. // Transport disconnected event.
  19039. function onTransportDisconnect(data) {
  19040. // Run _onTransportError_ callback on every client transaction using _transport_
  19041. var type, idx, length,
  19042. client_transactions = ['nict', 'ict', 'nist', 'ist'];
  19043. length = client_transactions.length;
  19044. for (type = 0; type < length; type++) {
  19045. for(idx in this.transactions[client_transactions[type]]) {
  19046. this.transactions[client_transactions[type]][idx].onTransportError();
  19047. }
  19048. }
  19049. this.emit('disconnected', data);
  19050. // Call registrator _onTransportClosed_
  19051. this._registrator.onTransportClosed();
  19052. if (this.status !== C.STATUS_USER_CLOSED) {
  19053. this.status = C.STATUS_NOT_READY;
  19054. this.error = C.NETWORK_ERROR;
  19055. }
  19056. }
  19057. // Transport data event
  19058. function onTransportData(data) {
  19059. var transaction,
  19060. transport = data.transport,
  19061. message = data.message;
  19062. message = Parser.parseMessage(message, this);
  19063. if (! message) {
  19064. return;
  19065. }
  19066. if (this.status === UA.C.STATUS_USER_CLOSED &&
  19067. message instanceof SIPMessage.IncomingRequest) {
  19068. return;
  19069. }
  19070. // Do some sanity check
  19071. if(! sanityCheck(message, this, transport)) {
  19072. return;
  19073. }
  19074. if(message instanceof SIPMessage.IncomingRequest) {
  19075. message.transport = transport;
  19076. this.receiveRequest(message);
  19077. } else if(message instanceof SIPMessage.IncomingResponse) {
  19078. /* Unike stated in 18.1.2, if a response does not match
  19079. * any transaction, it is discarded here and no passed to the core
  19080. * in order to be discarded there.
  19081. */
  19082. switch(message.method) {
  19083. case JsSIP_C.INVITE:
  19084. transaction = this.transactions.ict[message.via_branch];
  19085. if(transaction) {
  19086. transaction.receiveResponse(message);
  19087. }
  19088. break;
  19089. case JsSIP_C.ACK:
  19090. // Just in case ;-)
  19091. break;
  19092. default:
  19093. transaction = this.transactions.nict[message.via_branch];
  19094. if(transaction) {
  19095. transaction.receiveResponse(message);
  19096. }
  19097. break;
  19098. }
  19099. }
  19100. }
  19101. },{"./Constants":1,"./Exceptions":5,"./Grammar":6,"./Message":8,"./Parser":10,"./RTCSession":11,"./Registrator":17,"./SIPMessage":19,"./Socket":20,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":35,"events":29,"util":33}],25:[function(require,module,exports){
  19102. module.exports = URI;
  19103. /**
  19104. * Dependencies.
  19105. */
  19106. var JsSIP_C = require('./Constants');
  19107. var Utils = require('./Utils');
  19108. var Grammar = require('./Grammar');
  19109. /**
  19110. * -param {String} [scheme]
  19111. * -param {String} [user]
  19112. * -param {String} host
  19113. * -param {String} [port]
  19114. * -param {Object} [parameters]
  19115. * -param {Object} [headers]
  19116. *
  19117. */
  19118. function URI(scheme, user, host, port, parameters, headers) {
  19119. var param, header;
  19120. // Checks
  19121. if(!host) {
  19122. throw new TypeError('missing or invalid "host" parameter');
  19123. }
  19124. // Initialize parameters
  19125. scheme = scheme || JsSIP_C.SIP;
  19126. this.parameters = {};
  19127. this.headers = {};
  19128. for (param in parameters) {
  19129. this.setParam(param, parameters[param]);
  19130. }
  19131. for (header in headers) {
  19132. this.setHeader(header, headers[header]);
  19133. }
  19134. Object.defineProperties(this, {
  19135. scheme: {
  19136. get: function(){ return scheme; },
  19137. set: function(value){
  19138. scheme = value.toLowerCase();
  19139. }
  19140. },
  19141. user: {
  19142. get: function(){ return user; },
  19143. set: function(value){
  19144. user = value;
  19145. }
  19146. },
  19147. host: {
  19148. get: function(){ return host; },
  19149. set: function(value){
  19150. host = value.toLowerCase();
  19151. }
  19152. },
  19153. port: {
  19154. get: function(){ return port; },
  19155. set: function(value){
  19156. port = value === 0 ? value : (parseInt(value,10) || null);
  19157. }
  19158. }
  19159. });
  19160. }
  19161. URI.prototype = {
  19162. setParam: function(key, value) {
  19163. if(key) {
  19164. this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null) ? null : value.toString();
  19165. }
  19166. },
  19167. getParam: function(key) {
  19168. if(key) {
  19169. return this.parameters[key.toLowerCase()];
  19170. }
  19171. },
  19172. hasParam: function(key) {
  19173. if(key) {
  19174. return (this.parameters.hasOwnProperty(key.toLowerCase()) && true) || false;
  19175. }
  19176. },
  19177. deleteParam: function(parameter) {
  19178. var value;
  19179. parameter = parameter.toLowerCase();
  19180. if (this.parameters.hasOwnProperty(parameter)) {
  19181. value = this.parameters[parameter];
  19182. delete this.parameters[parameter];
  19183. return value;
  19184. }
  19185. },
  19186. clearParams: function() {
  19187. this.parameters = {};
  19188. },
  19189. setHeader: function(name, value) {
  19190. this.headers[Utils.headerize(name)] = (Array.isArray(value)) ? value : [value];
  19191. },
  19192. getHeader: function(name) {
  19193. if(name) {
  19194. return this.headers[Utils.headerize(name)];
  19195. }
  19196. },
  19197. hasHeader: function(name) {
  19198. if(name) {
  19199. return (this.headers.hasOwnProperty(Utils.headerize(name)) && true) || false;
  19200. }
  19201. },
  19202. deleteHeader: function(header) {
  19203. var value;
  19204. header = Utils.headerize(header);
  19205. if(this.headers.hasOwnProperty(header)) {
  19206. value = this.headers[header];
  19207. delete this.headers[header];
  19208. return value;
  19209. }
  19210. },
  19211. clearHeaders: function() {
  19212. this.headers = {};
  19213. },
  19214. clone: function() {
  19215. return new URI(
  19216. this.scheme,
  19217. this.user,
  19218. this.host,
  19219. this.port,
  19220. JSON.parse(JSON.stringify(this.parameters)),
  19221. JSON.parse(JSON.stringify(this.headers)));
  19222. },
  19223. toString: function(){
  19224. var header, parameter, idx, uri,
  19225. headers = [];
  19226. uri = this.scheme + ':';
  19227. if (this.user) {
  19228. uri += Utils.escapeUser(this.user) + '@';
  19229. }
  19230. uri += this.host;
  19231. if (this.port || this.port === 0) {
  19232. uri += ':' + this.port;
  19233. }
  19234. for (parameter in this.parameters) {
  19235. uri += ';' + parameter;
  19236. if (this.parameters[parameter] !== null) {
  19237. uri += '='+ this.parameters[parameter];
  19238. }
  19239. }
  19240. for(header in this.headers) {
  19241. for(idx = 0; idx < this.headers[header].length; idx++) {
  19242. headers.push(header + '=' + this.headers[header][idx]);
  19243. }
  19244. }
  19245. if (headers.length > 0) {
  19246. uri += '?' + headers.join('&');
  19247. }
  19248. return uri;
  19249. },
  19250. toAor: function(show_port){
  19251. var aor;
  19252. aor = this.scheme + ':';
  19253. if (this.user) {
  19254. aor += Utils.escapeUser(this.user) + '@';
  19255. }
  19256. aor += this.host;
  19257. if (show_port && (this.port || this.port === 0)) {
  19258. aor += ':' + this.port;
  19259. }
  19260. return aor;
  19261. }
  19262. };
  19263. /**
  19264. * Parse the given string and returns a JsSIP.URI instance or undefined if
  19265. * it is an invalid URI.
  19266. */
  19267. URI.parse = function(uri) {
  19268. uri = Grammar.parse(uri,'SIP_URI');
  19269. if (uri !== -1) {
  19270. return uri;
  19271. } else {
  19272. return undefined;
  19273. }
  19274. };
  19275. },{"./Constants":1,"./Grammar":6,"./Utils":26}],26:[function(require,module,exports){
  19276. var Utils = {};
  19277. module.exports = Utils;
  19278. /**
  19279. * Dependencies.
  19280. */
  19281. var JsSIP_C = require('./Constants');
  19282. var URI = require('./URI');
  19283. var Grammar = require('./Grammar');
  19284. Utils.str_utf8_length = function(string) {
  19285. return unescape(encodeURIComponent(string)).length;
  19286. };
  19287. Utils.isFunction = function(fn) {
  19288. if (fn !== undefined) {
  19289. return (Object.prototype.toString.call(fn) === '[object Function]')? true : false;
  19290. } else {
  19291. return false;
  19292. }
  19293. };
  19294. Utils.isString = function(str) {
  19295. if (str !== undefined) {
  19296. return (Object.prototype.toString.call(str) === '[object String]')? true : false;
  19297. } else {
  19298. return false;
  19299. }
  19300. };
  19301. Utils.isDecimal = function(num) {
  19302. return !isNaN(num) && (parseFloat(num) === parseInt(num,10));
  19303. };
  19304. Utils.isEmpty = function(value) {
  19305. if (value === null || value === '' || value === undefined || (Array.isArray(value) && value.length === 0) || (typeof(value) === 'number' && isNaN(value))) {
  19306. return true;
  19307. }
  19308. };
  19309. Utils.hasMethods = function(obj /*, method list as strings */){
  19310. var i = 1, methodName;
  19311. while((methodName = arguments[i++])){
  19312. if(this.isFunction(obj[methodName])) {
  19313. return false;
  19314. }
  19315. }
  19316. return true;
  19317. };
  19318. Utils.createRandomToken = function(size, base) {
  19319. var i, r,
  19320. token = '';
  19321. base = base || 32;
  19322. for( i=0; i < size; i++ ) {
  19323. r = Math.random() * base|0;
  19324. token += r.toString(base);
  19325. }
  19326. return token;
  19327. };
  19328. Utils.newTag = function() {
  19329. return Utils.createRandomToken(10);
  19330. };
  19331. // http://stackoverflow.com/users/109538/broofa
  19332. Utils.newUUID = function() {
  19333. var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  19334. var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
  19335. return v.toString(16);
  19336. });
  19337. return UUID;
  19338. };
  19339. Utils.hostType = function(host) {
  19340. if (!host) {
  19341. return;
  19342. } else {
  19343. host = Grammar.parse(host,'host');
  19344. if (host !== -1) {
  19345. return host.host_type;
  19346. }
  19347. }
  19348. };
  19349. /**
  19350. * Normalize SIP URI.
  19351. * NOTE: It does not allow a SIP URI without username.
  19352. * Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'.
  19353. * Detects the domain part (if given) and properly hex-escapes the user portion.
  19354. * If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators.
  19355. */
  19356. Utils.normalizeTarget = function(target, domain) {
  19357. var uri, target_array, target_user, target_domain;
  19358. // If no target is given then raise an error.
  19359. if (!target) {
  19360. return;
  19361. // If a URI instance is given then return it.
  19362. } else if (target instanceof URI) {
  19363. return target;
  19364. // If a string is given split it by '@':
  19365. // - Last fragment is the desired domain.
  19366. // - Otherwise append the given domain argument.
  19367. } else if (typeof target === 'string') {
  19368. target_array = target.split('@');
  19369. switch(target_array.length) {
  19370. case 1:
  19371. if (!domain) {
  19372. return;
  19373. }
  19374. target_user = target;
  19375. target_domain = domain;
  19376. break;
  19377. case 2:
  19378. target_user = target_array[0];
  19379. target_domain = target_array[1];
  19380. break;
  19381. default:
  19382. target_user = target_array.slice(0, target_array.length-1).join('@');
  19383. target_domain = target_array[target_array.length-1];
  19384. }
  19385. // Remove the URI scheme (if present).
  19386. target_user = target_user.replace(/^(sips?|tel):/i, '');
  19387. // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols.
  19388. if (/^[\-\.\(\)]*\+?[0-9\-\.\(\)]+$/.test(target_user)) {
  19389. target_user = target_user.replace(/[\-\.\(\)]/g, '');
  19390. }
  19391. // Build the complete SIP URI.
  19392. target = JsSIP_C.SIP + ':' + Utils.escapeUser(target_user) + '@' + target_domain;
  19393. // Finally parse the resulting URI.
  19394. if ((uri = URI.parse(target))) {
  19395. return uri;
  19396. } else {
  19397. return;
  19398. }
  19399. } else {
  19400. return;
  19401. }
  19402. };
  19403. /**
  19404. * Hex-escape a SIP URI user.
  19405. */
  19406. Utils.escapeUser = function(user) {
  19407. // Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F).
  19408. return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/');
  19409. };
  19410. Utils.headerize = function(string) {
  19411. var exceptions = {
  19412. 'Call-Id': 'Call-ID',
  19413. 'Cseq': 'CSeq',
  19414. 'Www-Authenticate': 'WWW-Authenticate'
  19415. },
  19416. name = string.toLowerCase().replace(/_/g,'-').split('-'),
  19417. hname = '',
  19418. parts = name.length, part;
  19419. for (part = 0; part < parts; part++) {
  19420. if (part !== 0) {
  19421. hname +='-';
  19422. }
  19423. hname += name[part].charAt(0).toUpperCase()+name[part].substring(1);
  19424. }
  19425. if (exceptions[hname]) {
  19426. hname = exceptions[hname];
  19427. }
  19428. return hname;
  19429. };
  19430. Utils.sipErrorCause = function(status_code) {
  19431. var cause;
  19432. for (cause in JsSIP_C.SIP_ERROR_CAUSES) {
  19433. if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) {
  19434. return JsSIP_C.causes[cause];
  19435. }
  19436. }
  19437. return JsSIP_C.causes.SIP_FAILURE_CODE;
  19438. };
  19439. /**
  19440. * Generate a random Test-Net IP (http://tools.ietf.org/html/rfc5735)
  19441. */
  19442. Utils.getRandomTestNetIP = function() {
  19443. function getOctet(from,to) {
  19444. return Math.floor(Math.random()*(to-from+1)+from);
  19445. }
  19446. return '192.0.2.' + getOctet(1, 254);
  19447. };
  19448. // MD5 (Message-Digest Algorithm) http://www.webtoolkit.info
  19449. Utils.calculateMD5 = function(string) {
  19450. function rotateLeft(lValue, iShiftBits) {
  19451. return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
  19452. }
  19453. function addUnsigned(lX,lY) {
  19454. var lX4,lY4,lX8,lY8,lResult;
  19455. lX8 = (lX & 0x80000000);
  19456. lY8 = (lY & 0x80000000);
  19457. lX4 = (lX & 0x40000000);
  19458. lY4 = (lY & 0x40000000);
  19459. lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
  19460. if (lX4 & lY4) {
  19461. return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
  19462. }
  19463. if (lX4 | lY4) {
  19464. if (lResult & 0x40000000) {
  19465. return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
  19466. } else {
  19467. return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
  19468. }
  19469. } else {
  19470. return (lResult ^ lX8 ^ lY8);
  19471. }
  19472. }
  19473. function doF(x,y,z) {
  19474. return (x & y) | ((~x) & z);
  19475. }
  19476. function doG(x,y,z) {
  19477. return (x & z) | (y & (~z));
  19478. }
  19479. function doH(x,y,z) {
  19480. return (x ^ y ^ z);
  19481. }
  19482. function doI(x,y,z) {
  19483. return (y ^ (x | (~z)));
  19484. }
  19485. function doFF(a,b,c,d,x,s,ac) {
  19486. a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac));
  19487. return addUnsigned(rotateLeft(a, s), b);
  19488. }
  19489. function doGG(a,b,c,d,x,s,ac) {
  19490. a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac));
  19491. return addUnsigned(rotateLeft(a, s), b);
  19492. }
  19493. function doHH(a,b,c,d,x,s,ac) {
  19494. a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac));
  19495. return addUnsigned(rotateLeft(a, s), b);
  19496. }
  19497. function doII(a,b,c,d,x,s,ac) {
  19498. a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac));
  19499. return addUnsigned(rotateLeft(a, s), b);
  19500. }
  19501. function convertToWordArray(string) {
  19502. var lWordCount;
  19503. var lMessageLength = string.length;
  19504. var lNumberOfWords_temp1=lMessageLength + 8;
  19505. var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
  19506. var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
  19507. var lWordArray = new Array(lNumberOfWords-1);
  19508. var lBytePosition = 0;
  19509. var lByteCount = 0;
  19510. while ( lByteCount < lMessageLength ) {
  19511. lWordCount = (lByteCount-(lByteCount % 4))/4;
  19512. lBytePosition = (lByteCount % 4)*8;
  19513. lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
  19514. lByteCount++;
  19515. }
  19516. lWordCount = (lByteCount-(lByteCount % 4))/4;
  19517. lBytePosition = (lByteCount % 4)*8;
  19518. lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
  19519. lWordArray[lNumberOfWords-2] = lMessageLength<<3;
  19520. lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
  19521. return lWordArray;
  19522. }
  19523. function wordToHex(lValue) {
  19524. var wordToHexValue='',wordToHexValue_temp='',lByte,lCount;
  19525. for (lCount = 0;lCount<=3;lCount++) {
  19526. lByte = (lValue>>>(lCount*8)) & 255;
  19527. wordToHexValue_temp = '0' + lByte.toString(16);
  19528. wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length-2,2);
  19529. }
  19530. return wordToHexValue;
  19531. }
  19532. function utf8Encode(string) {
  19533. string = string.replace(/\r\n/g, '\n');
  19534. var utftext = '';
  19535. for (var n = 0; n < string.length; n++) {
  19536. var c = string.charCodeAt(n);
  19537. if (c < 128) {
  19538. utftext += String.fromCharCode(c);
  19539. }
  19540. else if((c > 127) && (c < 2048)) {
  19541. utftext += String.fromCharCode((c >> 6) | 192);
  19542. utftext += String.fromCharCode((c & 63) | 128);
  19543. }
  19544. else {
  19545. utftext += String.fromCharCode((c >> 12) | 224);
  19546. utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  19547. utftext += String.fromCharCode((c & 63) | 128);
  19548. }
  19549. }
  19550. return utftext;
  19551. }
  19552. var x=[];
  19553. var k,AA,BB,CC,DD,a,b,c,d;
  19554. var S11=7, S12=12, S13=17, S14=22;
  19555. var S21=5, S22=9 , S23=14, S24=20;
  19556. var S31=4, S32=11, S33=16, S34=23;
  19557. var S41=6, S42=10, S43=15, S44=21;
  19558. string = utf8Encode(string);
  19559. x = convertToWordArray(string);
  19560. a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
  19561. for (k=0;k<x.length;k+=16) {
  19562. AA=a; BB=b; CC=c; DD=d;
  19563. a=doFF(a,b,c,d,x[k+0], S11,0xD76AA478);
  19564. d=doFF(d,a,b,c,x[k+1], S12,0xE8C7B756);
  19565. c=doFF(c,d,a,b,x[k+2], S13,0x242070DB);
  19566. b=doFF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
  19567. a=doFF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
  19568. d=doFF(d,a,b,c,x[k+5], S12,0x4787C62A);
  19569. c=doFF(c,d,a,b,x[k+6], S13,0xA8304613);
  19570. b=doFF(b,c,d,a,x[k+7], S14,0xFD469501);
  19571. a=doFF(a,b,c,d,x[k+8], S11,0x698098D8);
  19572. d=doFF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
  19573. c=doFF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
  19574. b=doFF(b,c,d,a,x[k+11],S14,0x895CD7BE);
  19575. a=doFF(a,b,c,d,x[k+12],S11,0x6B901122);
  19576. d=doFF(d,a,b,c,x[k+13],S12,0xFD987193);
  19577. c=doFF(c,d,a,b,x[k+14],S13,0xA679438E);
  19578. b=doFF(b,c,d,a,x[k+15],S14,0x49B40821);
  19579. a=doGG(a,b,c,d,x[k+1], S21,0xF61E2562);
  19580. d=doGG(d,a,b,c,x[k+6], S22,0xC040B340);
  19581. c=doGG(c,d,a,b,x[k+11],S23,0x265E5A51);
  19582. b=doGG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
  19583. a=doGG(a,b,c,d,x[k+5], S21,0xD62F105D);
  19584. d=doGG(d,a,b,c,x[k+10],S22,0x2441453);
  19585. c=doGG(c,d,a,b,x[k+15],S23,0xD8A1E681);
  19586. b=doGG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
  19587. a=doGG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
  19588. d=doGG(d,a,b,c,x[k+14],S22,0xC33707D6);
  19589. c=doGG(c,d,a,b,x[k+3], S23,0xF4D50D87);
  19590. b=doGG(b,c,d,a,x[k+8], S24,0x455A14ED);
  19591. a=doGG(a,b,c,d,x[k+13],S21,0xA9E3E905);
  19592. d=doGG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
  19593. c=doGG(c,d,a,b,x[k+7], S23,0x676F02D9);
  19594. b=doGG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
  19595. a=doHH(a,b,c,d,x[k+5], S31,0xFFFA3942);
  19596. d=doHH(d,a,b,c,x[k+8], S32,0x8771F681);
  19597. c=doHH(c,d,a,b,x[k+11],S33,0x6D9D6122);
  19598. b=doHH(b,c,d,a,x[k+14],S34,0xFDE5380C);
  19599. a=doHH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
  19600. d=doHH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
  19601. c=doHH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
  19602. b=doHH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
  19603. a=doHH(a,b,c,d,x[k+13],S31,0x289B7EC6);
  19604. d=doHH(d,a,b,c,x[k+0], S32,0xEAA127FA);
  19605. c=doHH(c,d,a,b,x[k+3], S33,0xD4EF3085);
  19606. b=doHH(b,c,d,a,x[k+6], S34,0x4881D05);
  19607. a=doHH(a,b,c,d,x[k+9], S31,0xD9D4D039);
  19608. d=doHH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
  19609. c=doHH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
  19610. b=doHH(b,c,d,a,x[k+2], S34,0xC4AC5665);
  19611. a=doII(a,b,c,d,x[k+0], S41,0xF4292244);
  19612. d=doII(d,a,b,c,x[k+7], S42,0x432AFF97);
  19613. c=doII(c,d,a,b,x[k+14],S43,0xAB9423A7);
  19614. b=doII(b,c,d,a,x[k+5], S44,0xFC93A039);
  19615. a=doII(a,b,c,d,x[k+12],S41,0x655B59C3);
  19616. d=doII(d,a,b,c,x[k+3], S42,0x8F0CCC92);
  19617. c=doII(c,d,a,b,x[k+10],S43,0xFFEFF47D);
  19618. b=doII(b,c,d,a,x[k+1], S44,0x85845DD1);
  19619. a=doII(a,b,c,d,x[k+8], S41,0x6FA87E4F);
  19620. d=doII(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
  19621. c=doII(c,d,a,b,x[k+6], S43,0xA3014314);
  19622. b=doII(b,c,d,a,x[k+13],S44,0x4E0811A1);
  19623. a=doII(a,b,c,d,x[k+4], S41,0xF7537E82);
  19624. d=doII(d,a,b,c,x[k+11],S42,0xBD3AF235);
  19625. c=doII(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
  19626. b=doII(b,c,d,a,x[k+9], S44,0xEB86D391);
  19627. a=addUnsigned(a,AA);
  19628. b=addUnsigned(b,BB);
  19629. c=addUnsigned(c,CC);
  19630. d=addUnsigned(d,DD);
  19631. }
  19632. var temp = wordToHex(a)+wordToHex(b)+wordToHex(c)+wordToHex(d);
  19633. return temp.toLowerCase();
  19634. };
  19635. Utils.closeMediaStream = function(stream) {
  19636. if (!stream) {
  19637. return;
  19638. }
  19639. // Latest spec states that MediaStream has no stop() method and instead must
  19640. // call stop() on every MediaStreamTrack.
  19641. try {
  19642. var tracks, i, len;
  19643. if (stream.getTracks) {
  19644. tracks = stream.getTracks();
  19645. for (i = 0, len = tracks.length; i < len; i += 1) {
  19646. tracks[i].stop();
  19647. }
  19648. } else {
  19649. tracks = stream.getAudioTracks();
  19650. for (i = 0, len = tracks.length; i < len; i += 1) {
  19651. tracks[i].stop();
  19652. }
  19653. tracks = stream.getVideoTracks();
  19654. for (i = 0, len = tracks.length; i < len; i += 1) {
  19655. tracks[i].stop();
  19656. }
  19657. }
  19658. } catch (error) {
  19659. // Deprecated by the spec, but still in use.
  19660. // NOTE: In Temasys IE plugin stream.stop is a callable 'object'.
  19661. if (typeof stream.stop === 'function' || typeof stream.stop === 'object') {
  19662. stream.stop();
  19663. }
  19664. }
  19665. };
  19666. },{"./Constants":1,"./Grammar":6,"./URI":25}],27:[function(require,module,exports){
  19667. module.exports = WebSocketInterface;
  19668. /**
  19669. * Dependencies.
  19670. */
  19671. var Grammar = require('./Grammar');
  19672. var debug = require('debug')('JsSIP:WebSocketInterface');
  19673. var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface');
  19674. debugerror.log = console.warn.bind(console);
  19675. function WebSocketInterface(url) {
  19676. debug('new() [url:"%s"]', url);
  19677. var sip_uri = null;
  19678. var via_transport = null;
  19679. this.ws = null;
  19680. // setting the 'scheme' alters the sip_uri too (used in SIP Route header field)
  19681. Object.defineProperties(this, {
  19682. via_transport: {
  19683. get: function() { return via_transport; },
  19684. set: function(transport) {
  19685. via_transport = transport.toUpperCase();
  19686. }
  19687. },
  19688. sip_uri: { get: function() { return sip_uri; }},
  19689. url: { get: function() { return url; }}
  19690. });
  19691. var parsed_url = Grammar.parse(url, 'absoluteURI');
  19692. if (parsed_url === -1) {
  19693. debugerror('invalid WebSocket URI: ' + url);
  19694. throw new TypeError('Invalid argument: ' + url);
  19695. } else if(parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') {
  19696. debugerror('invalid WebSocket URI scheme: ' + parsed_url.scheme);
  19697. throw new TypeError('Invalid argument: ' + url);
  19698. } else {
  19699. sip_uri = 'sip:' + parsed_url.host +
  19700. (parsed_url.port ? ':' + parsed_url.port : '') + ';transport=ws';
  19701. this.via_transport = parsed_url.scheme;
  19702. }
  19703. }
  19704. WebSocketInterface.prototype.connect = function () {
  19705. debug('connect()');
  19706. if (this.isConnected()) {
  19707. debug('WebSocket ' + this.url + ' is already connected');
  19708. return;
  19709. } else if (this.isConnecting()) {
  19710. debug('WebSocket ' + this.url + ' is connecting');
  19711. return;
  19712. }
  19713. if (this.ws) {
  19714. this.disconnect();
  19715. }
  19716. debug('connecting to WebSocket ' + this.url);
  19717. try {
  19718. this.ws = new WebSocket(this.url, 'sip');
  19719. this.ws.binaryType = 'arraybuffer';
  19720. this.ws.onopen = onOpen.bind(this);
  19721. this.ws.onclose = onClose.bind(this);
  19722. this.ws.onmessage = onMessage.bind(this);
  19723. this.ws.onerror = onError.bind(this);
  19724. } catch(e) {
  19725. onError.call(this, e);
  19726. }
  19727. };
  19728. WebSocketInterface.prototype.disconnect = function() {
  19729. debug('disconnect()');
  19730. if (this.ws) {
  19731. // unbind websocket event callbacks
  19732. this.ws.onopen = function() {};
  19733. this.ws.onclose = function() {};
  19734. this.ws.onmessage = function() {};
  19735. this.ws.onerror = function() {};
  19736. this.ws.close();
  19737. this.ws = null;
  19738. }
  19739. };
  19740. WebSocketInterface.prototype.send = function(message) {
  19741. debug('send()');
  19742. if (this.isConnected()) {
  19743. this.ws.send(message);
  19744. return true;
  19745. } else {
  19746. debugerror('unable to send message, WebSocket is not open');
  19747. return false;
  19748. }
  19749. };
  19750. WebSocketInterface.prototype.isConnected = function() {
  19751. return this.ws && this.ws.readyState === this.ws.OPEN;
  19752. };
  19753. WebSocketInterface.prototype.isConnecting = function() {
  19754. return this.ws && this.ws.readyState === this.ws.CONNECTING;
  19755. };
  19756. /**
  19757. * WebSocket Event Handlers
  19758. */
  19759. function onOpen() {
  19760. debug('WebSocket ' + this.url + ' connected');
  19761. this.onconnect();
  19762. }
  19763. function onClose(e) {
  19764. debug('WebSocket ' + this.url + ' closed');
  19765. if (e.wasClean === false) {
  19766. debug('WebSocket abrupt disconnection');
  19767. }
  19768. var data = {
  19769. socket: this,
  19770. error: !e.wasClean,
  19771. code: e.code,
  19772. reason: e.reason
  19773. };
  19774. this.ondisconnect(data);
  19775. }
  19776. function onMessage(e) {
  19777. debug('received WebSocket message');
  19778. this.ondata(e.data);
  19779. }
  19780. function onError(e) {
  19781. debugerror('WebSocket ' + this.url + ' error: '+ e);
  19782. }
  19783. },{"./Grammar":6,"debug":35}],28:[function(require,module,exports){
  19784. module.exports = sanityCheck;
  19785. /**
  19786. * Dependencies.
  19787. */
  19788. var debug = require('debug')('JsSIP:sanityCheck');
  19789. var JsSIP_C = require('./Constants');
  19790. var SIPMessage = require('./SIPMessage');
  19791. var Utils = require('./Utils');
  19792. var message, ua, transport,
  19793. requests = [],
  19794. responses = [],
  19795. all = [];
  19796. requests.push(rfc3261_8_2_2_1);
  19797. requests.push(rfc3261_16_3_4);
  19798. requests.push(rfc3261_18_3_request);
  19799. requests.push(rfc3261_8_2_2_2);
  19800. responses.push(rfc3261_8_1_3_3);
  19801. responses.push(rfc3261_18_3_response);
  19802. all.push(minimumHeaders);
  19803. function sanityCheck(m, u, t) {
  19804. var len, pass;
  19805. message = m;
  19806. ua = u;
  19807. transport = t;
  19808. len = all.length;
  19809. while(len--) {
  19810. pass = all[len](message);
  19811. if(pass === false) {
  19812. return false;
  19813. }
  19814. }
  19815. if(message instanceof SIPMessage.IncomingRequest) {
  19816. len = requests.length;
  19817. while(len--) {
  19818. pass = requests[len](message);
  19819. if(pass === false) {
  19820. return false;
  19821. }
  19822. }
  19823. }
  19824. else if(message instanceof SIPMessage.IncomingResponse) {
  19825. len = responses.length;
  19826. while(len--) {
  19827. pass = responses[len](message);
  19828. if(pass === false) {
  19829. return false;
  19830. }
  19831. }
  19832. }
  19833. //Everything is OK
  19834. return true;
  19835. }
  19836. /*
  19837. * Sanity Check for incoming Messages
  19838. *
  19839. * Requests:
  19840. * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme
  19841. * - _rfc3261_16_3_4_ Receive a Request already sent by us
  19842. * Does not look at via sent-by but at jssip_id, which is inserted as
  19843. * a prefix in all initial requests generated by the ua
  19844. * - _rfc3261_18_3_request_ Body Content-Length
  19845. * - _rfc3261_8_2_2_2_ Merged Requests
  19846. *
  19847. * Responses:
  19848. * - _rfc3261_8_1_3_3_ Multiple Via headers
  19849. * - _rfc3261_18_3_response_ Body Content-Length
  19850. *
  19851. * All:
  19852. * - Minimum headers in a SIP message
  19853. */
  19854. // Sanity Check functions for requests
  19855. function rfc3261_8_2_2_1() {
  19856. if(message.s('to').uri.scheme !== 'sip') {
  19857. reply(416);
  19858. return false;
  19859. }
  19860. }
  19861. function rfc3261_16_3_4() {
  19862. if(!message.to_tag) {
  19863. if(message.call_id.substr(0, 5) === ua.configuration.jssip_id) {
  19864. reply(482);
  19865. return false;
  19866. }
  19867. }
  19868. }
  19869. function rfc3261_18_3_request() {
  19870. var len = Utils.str_utf8_length(message.body),
  19871. contentLength = message.getHeader('content-length');
  19872. if(len < contentLength) {
  19873. reply(400);
  19874. return false;
  19875. }
  19876. }
  19877. function rfc3261_8_2_2_2() {
  19878. var tr, idx,
  19879. fromTag = message.from_tag,
  19880. call_id = message.call_id,
  19881. cseq = message.cseq;
  19882. // Accept any in-dialog request.
  19883. if(message.to_tag) {
  19884. return;
  19885. }
  19886. // INVITE request.
  19887. if (message.method === JsSIP_C.INVITE) {
  19888. // If the branch matches the key of any IST then assume it is a retransmission
  19889. // and ignore the INVITE.
  19890. // TODO: we should reply the last response.
  19891. if (ua.transactions.ist[message.via_branch]) {
  19892. return false;
  19893. }
  19894. // Otherwise check whether it is a merged request.
  19895. else {
  19896. for(idx in ua.transactions.ist) {
  19897. tr = ua.transactions.ist[idx];
  19898. if(tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  19899. reply(482);
  19900. return false;
  19901. }
  19902. }
  19903. }
  19904. }
  19905. // Non INVITE request.
  19906. else {
  19907. // If the branch matches the key of any NIST then assume it is a retransmission
  19908. // and ignore the request.
  19909. // TODO: we should reply the last response.
  19910. if (ua.transactions.nist[message.via_branch]) {
  19911. return false;
  19912. }
  19913. // Otherwise check whether it is a merged request.
  19914. else {
  19915. for(idx in ua.transactions.nist) {
  19916. tr = ua.transactions.nist[idx];
  19917. if(tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  19918. reply(482);
  19919. return false;
  19920. }
  19921. }
  19922. }
  19923. }
  19924. }
  19925. // Sanity Check functions for responses
  19926. function rfc3261_8_1_3_3() {
  19927. if(message.getHeaders('via').length > 1) {
  19928. debug('more than one Via header field present in the response, dropping the response');
  19929. return false;
  19930. }
  19931. }
  19932. function rfc3261_18_3_response() {
  19933. var
  19934. len = Utils.str_utf8_length(message.body),
  19935. contentLength = message.getHeader('content-length');
  19936. if(len < contentLength) {
  19937. debug('message body length is lower than the value in Content-Length header field, dropping the response');
  19938. return false;
  19939. }
  19940. }
  19941. // Sanity Check functions for requests and responses
  19942. function minimumHeaders() {
  19943. var
  19944. mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via'],
  19945. idx = mandatoryHeaders.length;
  19946. while(idx--) {
  19947. if(!message.hasHeader(mandatoryHeaders[idx])) {
  19948. debug('missing mandatory header field : ' + mandatoryHeaders[idx] + ', dropping the response');
  19949. return false;
  19950. }
  19951. }
  19952. }
  19953. // Reply
  19954. function reply(status_code) {
  19955. var to,
  19956. response = 'SIP/2.0 ' + status_code + ' ' + JsSIP_C.REASON_PHRASE[status_code] + '\r\n',
  19957. vias = message.getHeaders('via'),
  19958. length = vias.length,
  19959. idx = 0;
  19960. for(idx; idx < length; idx++) {
  19961. response += 'Via: ' + vias[idx] + '\r\n';
  19962. }
  19963. to = message.getHeader('To');
  19964. if(!message.to_tag) {
  19965. to += ';tag=' + Utils.newTag();
  19966. }
  19967. response += 'To: ' + to + '\r\n';
  19968. response += 'From: ' + message.getHeader('From') + '\r\n';
  19969. response += 'Call-ID: ' + message.call_id + '\r\n';
  19970. response += 'CSeq: ' + message.cseq + ' ' + message.method + '\r\n';
  19971. response += '\r\n';
  19972. transport.send(response);
  19973. }
  19974. },{"./Constants":1,"./SIPMessage":19,"./Utils":26,"debug":35}],29:[function(require,module,exports){
  19975. // Copyright Joyent, Inc. and other Node contributors.
  19976. //
  19977. // Permission is hereby granted, free of charge, to any person obtaining a
  19978. // copy of this software and associated documentation files (the
  19979. // "Software"), to deal in the Software without restriction, including
  19980. // without limitation the rights to use, copy, modify, merge, publish,
  19981. // distribute, sublicense, and/or sell copies of the Software, and to permit
  19982. // persons to whom the Software is furnished to do so, subject to the
  19983. // following conditions:
  19984. //
  19985. // The above copyright notice and this permission notice shall be included
  19986. // in all copies or substantial portions of the Software.
  19987. //
  19988. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19989. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19990. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  19991. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  19992. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19993. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  19994. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  19995. function EventEmitter() {
  19996. this._events = this._events || {};
  19997. this._maxListeners = this._maxListeners || undefined;
  19998. }
  19999. module.exports = EventEmitter;
  20000. // Backwards-compat with node 0.10.x
  20001. EventEmitter.EventEmitter = EventEmitter;
  20002. EventEmitter.prototype._events = undefined;
  20003. EventEmitter.prototype._maxListeners = undefined;
  20004. // By default EventEmitters will print a warning if more than 10 listeners are
  20005. // added to it. This is a useful default which helps finding memory leaks.
  20006. EventEmitter.defaultMaxListeners = 10;
  20007. // Obviously not all Emitters should be limited to 10. This function allows
  20008. // that to be increased. Set to zero for unlimited.
  20009. EventEmitter.prototype.setMaxListeners = function(n) {
  20010. if (!isNumber(n) || n < 0 || isNaN(n))
  20011. throw TypeError('n must be a positive number');
  20012. this._maxListeners = n;
  20013. return this;
  20014. };
  20015. EventEmitter.prototype.emit = function(type) {
  20016. var er, handler, len, args, i, listeners;
  20017. if (!this._events)
  20018. this._events = {};
  20019. // If there is no 'error' event listener then throw.
  20020. if (type === 'error') {
  20021. if (!this._events.error ||
  20022. (isObject(this._events.error) && !this._events.error.length)) {
  20023. er = arguments[1];
  20024. if (er instanceof Error) {
  20025. throw er; // Unhandled 'error' event
  20026. } else {
  20027. // At least give some kind of context to the user
  20028. var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
  20029. err.context = er;
  20030. throw err;
  20031. }
  20032. }
  20033. }
  20034. handler = this._events[type];
  20035. if (isUndefined(handler))
  20036. return false;
  20037. if (isFunction(handler)) {
  20038. switch (arguments.length) {
  20039. // fast cases
  20040. case 1:
  20041. handler.call(this);
  20042. break;
  20043. case 2:
  20044. handler.call(this, arguments[1]);
  20045. break;
  20046. case 3:
  20047. handler.call(this, arguments[1], arguments[2]);
  20048. break;
  20049. // slower
  20050. default:
  20051. args = Array.prototype.slice.call(arguments, 1);
  20052. handler.apply(this, args);
  20053. }
  20054. } else if (isObject(handler)) {
  20055. args = Array.prototype.slice.call(arguments, 1);
  20056. listeners = handler.slice();
  20057. len = listeners.length;
  20058. for (i = 0; i < len; i++)
  20059. listeners[i].apply(this, args);
  20060. }
  20061. return true;
  20062. };
  20063. EventEmitter.prototype.addListener = function(type, listener) {
  20064. var m;
  20065. if (!isFunction(listener))
  20066. throw TypeError('listener must be a function');
  20067. if (!this._events)
  20068. this._events = {};
  20069. // To avoid recursion in the case that type === "newListener"! Before
  20070. // adding it to the listeners, first emit "newListener".
  20071. if (this._events.newListener)
  20072. this.emit('newListener', type,
  20073. isFunction(listener.listener) ?
  20074. listener.listener : listener);
  20075. if (!this._events[type])
  20076. // Optimize the case of one listener. Don't need the extra array object.
  20077. this._events[type] = listener;
  20078. else if (isObject(this._events[type]))
  20079. // If we've already got an array, just append.
  20080. this._events[type].push(listener);
  20081. else
  20082. // Adding the second element, need to change to array.
  20083. this._events[type] = [this._events[type], listener];
  20084. // Check for listener leak
  20085. if (isObject(this._events[type]) && !this._events[type].warned) {
  20086. if (!isUndefined(this._maxListeners)) {
  20087. m = this._maxListeners;
  20088. } else {
  20089. m = EventEmitter.defaultMaxListeners;
  20090. }
  20091. if (m && m > 0 && this._events[type].length > m) {
  20092. this._events[type].warned = true;
  20093. console.error('(node) warning: possible EventEmitter memory ' +
  20094. 'leak detected. %d listeners added. ' +
  20095. 'Use emitter.setMaxListeners() to increase limit.',
  20096. this._events[type].length);
  20097. if (typeof console.trace === 'function') {
  20098. // not supported in IE 10
  20099. console.trace();
  20100. }
  20101. }
  20102. }
  20103. return this;
  20104. };
  20105. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  20106. EventEmitter.prototype.once = function(type, listener) {
  20107. if (!isFunction(listener))
  20108. throw TypeError('listener must be a function');
  20109. var fired = false;
  20110. function g() {
  20111. this.removeListener(type, g);
  20112. if (!fired) {
  20113. fired = true;
  20114. listener.apply(this, arguments);
  20115. }
  20116. }
  20117. g.listener = listener;
  20118. this.on(type, g);
  20119. return this;
  20120. };
  20121. // emits a 'removeListener' event iff the listener was removed
  20122. EventEmitter.prototype.removeListener = function(type, listener) {
  20123. var list, position, length, i;
  20124. if (!isFunction(listener))
  20125. throw TypeError('listener must be a function');
  20126. if (!this._events || !this._events[type])
  20127. return this;
  20128. list = this._events[type];
  20129. length = list.length;
  20130. position = -1;
  20131. if (list === listener ||
  20132. (isFunction(list.listener) && list.listener === listener)) {
  20133. delete this._events[type];
  20134. if (this._events.removeListener)
  20135. this.emit('removeListener', type, listener);
  20136. } else if (isObject(list)) {
  20137. for (i = length; i-- > 0;) {
  20138. if (list[i] === listener ||
  20139. (list[i].listener && list[i].listener === listener)) {
  20140. position = i;
  20141. break;
  20142. }
  20143. }
  20144. if (position < 0)
  20145. return this;
  20146. if (list.length === 1) {
  20147. list.length = 0;
  20148. delete this._events[type];
  20149. } else {
  20150. list.splice(position, 1);
  20151. }
  20152. if (this._events.removeListener)
  20153. this.emit('removeListener', type, listener);
  20154. }
  20155. return this;
  20156. };
  20157. EventEmitter.prototype.removeAllListeners = function(type) {
  20158. var key, listeners;
  20159. if (!this._events)
  20160. return this;
  20161. // not listening for removeListener, no need to emit
  20162. if (!this._events.removeListener) {
  20163. if (arguments.length === 0)
  20164. this._events = {};
  20165. else if (this._events[type])
  20166. delete this._events[type];
  20167. return this;
  20168. }
  20169. // emit removeListener for all listeners on all events
  20170. if (arguments.length === 0) {
  20171. for (key in this._events) {
  20172. if (key === 'removeListener') continue;
  20173. this.removeAllListeners(key);
  20174. }
  20175. this.removeAllListeners('removeListener');
  20176. this._events = {};
  20177. return this;
  20178. }
  20179. listeners = this._events[type];
  20180. if (isFunction(listeners)) {
  20181. this.removeListener(type, listeners);
  20182. } else if (listeners) {
  20183. // LIFO order
  20184. while (listeners.length)
  20185. this.removeListener(type, listeners[listeners.length - 1]);
  20186. }
  20187. delete this._events[type];
  20188. return this;
  20189. };
  20190. EventEmitter.prototype.listeners = function(type) {
  20191. var ret;
  20192. if (!this._events || !this._events[type])
  20193. ret = [];
  20194. else if (isFunction(this._events[type]))
  20195. ret = [this._events[type]];
  20196. else
  20197. ret = this._events[type].slice();
  20198. return ret;
  20199. };
  20200. EventEmitter.prototype.listenerCount = function(type) {
  20201. if (this._events) {
  20202. var evlistener = this._events[type];
  20203. if (isFunction(evlistener))
  20204. return 1;
  20205. else if (evlistener)
  20206. return evlistener.length;
  20207. }
  20208. return 0;
  20209. };
  20210. EventEmitter.listenerCount = function(emitter, type) {
  20211. return emitter.listenerCount(type);
  20212. };
  20213. function isFunction(arg) {
  20214. return typeof arg === 'function';
  20215. }
  20216. function isNumber(arg) {
  20217. return typeof arg === 'number';
  20218. }
  20219. function isObject(arg) {
  20220. return typeof arg === 'object' && arg !== null;
  20221. }
  20222. function isUndefined(arg) {
  20223. return arg === void 0;
  20224. }
  20225. },{}],30:[function(require,module,exports){
  20226. // shim for using process in browser
  20227. var process = module.exports = {};
  20228. // cached from whatever global is present so that test runners that stub it
  20229. // don't break things. But we need to wrap it in a try catch in case it is
  20230. // wrapped in strict mode code which doesn't define any globals. It's inside a
  20231. // function because try/catches deoptimize in certain engines.
  20232. var cachedSetTimeout;
  20233. var cachedClearTimeout;
  20234. function defaultSetTimout() {
  20235. throw new Error('setTimeout has not been defined');
  20236. }
  20237. function defaultClearTimeout () {
  20238. throw new Error('clearTimeout has not been defined');
  20239. }
  20240. (function () {
  20241. try {
  20242. if (typeof setTimeout === 'function') {
  20243. cachedSetTimeout = setTimeout;
  20244. } else {
  20245. cachedSetTimeout = defaultSetTimout;
  20246. }
  20247. } catch (e) {
  20248. cachedSetTimeout = defaultSetTimout;
  20249. }
  20250. try {
  20251. if (typeof clearTimeout === 'function') {
  20252. cachedClearTimeout = clearTimeout;
  20253. } else {
  20254. cachedClearTimeout = defaultClearTimeout;
  20255. }
  20256. } catch (e) {
  20257. cachedClearTimeout = defaultClearTimeout;
  20258. }
  20259. } ())
  20260. function runTimeout(fun) {
  20261. if (cachedSetTimeout === setTimeout) {
  20262. //normal enviroments in sane situations
  20263. return setTimeout(fun, 0);
  20264. }
  20265. // if setTimeout wasn't available but was latter defined
  20266. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  20267. cachedSetTimeout = setTimeout;
  20268. return setTimeout(fun, 0);
  20269. }
  20270. try {
  20271. // when when somebody has screwed with setTimeout but no I.E. maddness
  20272. return cachedSetTimeout(fun, 0);
  20273. } catch(e){
  20274. try {
  20275. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  20276. return cachedSetTimeout.call(null, fun, 0);
  20277. } catch(e){
  20278. // 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
  20279. return cachedSetTimeout.call(this, fun, 0);
  20280. }
  20281. }
  20282. }
  20283. function runClearTimeout(marker) {
  20284. if (cachedClearTimeout === clearTimeout) {
  20285. //normal enviroments in sane situations
  20286. return clearTimeout(marker);
  20287. }
  20288. // if clearTimeout wasn't available but was latter defined
  20289. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  20290. cachedClearTimeout = clearTimeout;
  20291. return clearTimeout(marker);
  20292. }
  20293. try {
  20294. // when when somebody has screwed with setTimeout but no I.E. maddness
  20295. return cachedClearTimeout(marker);
  20296. } catch (e){
  20297. try {
  20298. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  20299. return cachedClearTimeout.call(null, marker);
  20300. } catch (e){
  20301. // 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.
  20302. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  20303. return cachedClearTimeout.call(this, marker);
  20304. }
  20305. }
  20306. }
  20307. var queue = [];
  20308. var draining = false;
  20309. var currentQueue;
  20310. var queueIndex = -1;
  20311. function cleanUpNextTick() {
  20312. if (!draining || !currentQueue) {
  20313. return;
  20314. }
  20315. draining = false;
  20316. if (currentQueue.length) {
  20317. queue = currentQueue.concat(queue);
  20318. } else {
  20319. queueIndex = -1;
  20320. }
  20321. if (queue.length) {
  20322. drainQueue();
  20323. }
  20324. }
  20325. function drainQueue() {
  20326. if (draining) {
  20327. return;
  20328. }
  20329. var timeout = runTimeout(cleanUpNextTick);
  20330. draining = true;
  20331. var len = queue.length;
  20332. while(len) {
  20333. currentQueue = queue;
  20334. queue = [];
  20335. while (++queueIndex < len) {
  20336. if (currentQueue) {
  20337. currentQueue[queueIndex].run();
  20338. }
  20339. }
  20340. queueIndex = -1;
  20341. len = queue.length;
  20342. }
  20343. currentQueue = null;
  20344. draining = false;
  20345. runClearTimeout(timeout);
  20346. }
  20347. process.nextTick = function (fun) {
  20348. var args = new Array(arguments.length - 1);
  20349. if (arguments.length > 1) {
  20350. for (var i = 1; i < arguments.length; i++) {
  20351. args[i - 1] = arguments[i];
  20352. }
  20353. }
  20354. queue.push(new Item(fun, args));
  20355. if (queue.length === 1 && !draining) {
  20356. runTimeout(drainQueue);
  20357. }
  20358. };
  20359. // v8 likes predictible objects
  20360. function Item(fun, array) {
  20361. this.fun = fun;
  20362. this.array = array;
  20363. }
  20364. Item.prototype.run = function () {
  20365. this.fun.apply(null, this.array);
  20366. };
  20367. process.title = 'browser';
  20368. process.browser = true;
  20369. process.env = {};
  20370. process.argv = [];
  20371. process.version = ''; // empty string to avoid regexp issues
  20372. process.versions = {};
  20373. function noop() {}
  20374. process.on = noop;
  20375. process.addListener = noop;
  20376. process.once = noop;
  20377. process.off = noop;
  20378. process.removeListener = noop;
  20379. process.removeAllListeners = noop;
  20380. process.emit = noop;
  20381. process.binding = function (name) {
  20382. throw new Error('process.binding is not supported');
  20383. };
  20384. process.cwd = function () { return '/' };
  20385. process.chdir = function (dir) {
  20386. throw new Error('process.chdir is not supported');
  20387. };
  20388. process.umask = function() { return 0; };
  20389. },{}],31:[function(require,module,exports){
  20390. if (typeof Object.create === 'function') {
  20391. // implementation from standard node.js 'util' module
  20392. module.exports = function inherits(ctor, superCtor) {
  20393. ctor.super_ = superCtor
  20394. ctor.prototype = Object.create(superCtor.prototype, {
  20395. constructor: {
  20396. value: ctor,
  20397. enumerable: false,
  20398. writable: true,
  20399. configurable: true
  20400. }
  20401. });
  20402. };
  20403. } else {
  20404. // old school shim for old browsers
  20405. module.exports = function inherits(ctor, superCtor) {
  20406. ctor.super_ = superCtor
  20407. var TempCtor = function () {}
  20408. TempCtor.prototype = superCtor.prototype
  20409. ctor.prototype = new TempCtor()
  20410. ctor.prototype.constructor = ctor
  20411. }
  20412. }
  20413. },{}],32:[function(require,module,exports){
  20414. module.exports = function isBuffer(arg) {
  20415. return arg && typeof arg === 'object'
  20416. && typeof arg.copy === 'function'
  20417. && typeof arg.fill === 'function'
  20418. && typeof arg.readUInt8 === 'function';
  20419. }
  20420. },{}],33:[function(require,module,exports){
  20421. (function (process,global){
  20422. // Copyright Joyent, Inc. and other Node contributors.
  20423. //
  20424. // Permission is hereby granted, free of charge, to any person obtaining a
  20425. // copy of this software and associated documentation files (the
  20426. // "Software"), to deal in the Software without restriction, including
  20427. // without limitation the rights to use, copy, modify, merge, publish,
  20428. // distribute, sublicense, and/or sell copies of the Software, and to permit
  20429. // persons to whom the Software is furnished to do so, subject to the
  20430. // following conditions:
  20431. //
  20432. // The above copyright notice and this permission notice shall be included
  20433. // in all copies or substantial portions of the Software.
  20434. //
  20435. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20436. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20437. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  20438. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  20439. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20440. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20441. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  20442. var formatRegExp = /%[sdj%]/g;
  20443. exports.format = function(f) {
  20444. if (!isString(f)) {
  20445. var objects = [];
  20446. for (var i = 0; i < arguments.length; i++) {
  20447. objects.push(inspect(arguments[i]));
  20448. }
  20449. return objects.join(' ');
  20450. }
  20451. var i = 1;
  20452. var args = arguments;
  20453. var len = args.length;
  20454. var str = String(f).replace(formatRegExp, function(x) {
  20455. if (x === '%%') return '%';
  20456. if (i >= len) return x;
  20457. switch (x) {
  20458. case '%s': return String(args[i++]);
  20459. case '%d': return Number(args[i++]);
  20460. case '%j':
  20461. try {
  20462. return JSON.stringify(args[i++]);
  20463. } catch (_) {
  20464. return '[Circular]';
  20465. }
  20466. default:
  20467. return x;
  20468. }
  20469. });
  20470. for (var x = args[i]; i < len; x = args[++i]) {
  20471. if (isNull(x) || !isObject(x)) {
  20472. str += ' ' + x;
  20473. } else {
  20474. str += ' ' + inspect(x);
  20475. }
  20476. }
  20477. return str;
  20478. };
  20479. // Mark that a method should not be used.
  20480. // Returns a modified function which warns once by default.
  20481. // If --no-deprecation is set, then it is a no-op.
  20482. exports.deprecate = function(fn, msg) {
  20483. // Allow for deprecating things in the process of starting up.
  20484. if (isUndefined(global.process)) {
  20485. return function() {
  20486. return exports.deprecate(fn, msg).apply(this, arguments);
  20487. };
  20488. }
  20489. if (process.noDeprecation === true) {
  20490. return fn;
  20491. }
  20492. var warned = false;
  20493. function deprecated() {
  20494. if (!warned) {
  20495. if (process.throwDeprecation) {
  20496. throw new Error(msg);
  20497. } else if (process.traceDeprecation) {
  20498. console.trace(msg);
  20499. } else {
  20500. console.error(msg);
  20501. }
  20502. warned = true;
  20503. }
  20504. return fn.apply(this, arguments);
  20505. }
  20506. return deprecated;
  20507. };
  20508. var debugs = {};
  20509. var debugEnviron;
  20510. exports.debuglog = function(set) {
  20511. if (isUndefined(debugEnviron))
  20512. debugEnviron = process.env.NODE_DEBUG || '';
  20513. set = set.toUpperCase();
  20514. if (!debugs[set]) {
  20515. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  20516. var pid = process.pid;
  20517. debugs[set] = function() {
  20518. var msg = exports.format.apply(exports, arguments);
  20519. console.error('%s %d: %s', set, pid, msg);
  20520. };
  20521. } else {
  20522. debugs[set] = function() {};
  20523. }
  20524. }
  20525. return debugs[set];
  20526. };
  20527. /**
  20528. * Echos the value of a value. Trys to print the value out
  20529. * in the best way possible given the different types.
  20530. *
  20531. * @param {Object} obj The object to print out.
  20532. * @param {Object} opts Optional options object that alters the output.
  20533. */
  20534. /* legacy: obj, showHidden, depth, colors*/
  20535. function inspect(obj, opts) {
  20536. // default options
  20537. var ctx = {
  20538. seen: [],
  20539. stylize: stylizeNoColor
  20540. };
  20541. // legacy...
  20542. if (arguments.length >= 3) ctx.depth = arguments[2];
  20543. if (arguments.length >= 4) ctx.colors = arguments[3];
  20544. if (isBoolean(opts)) {
  20545. // legacy...
  20546. ctx.showHidden = opts;
  20547. } else if (opts) {
  20548. // got an "options" object
  20549. exports._extend(ctx, opts);
  20550. }
  20551. // set default options
  20552. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  20553. if (isUndefined(ctx.depth)) ctx.depth = 2;
  20554. if (isUndefined(ctx.colors)) ctx.colors = false;
  20555. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  20556. if (ctx.colors) ctx.stylize = stylizeWithColor;
  20557. return formatValue(ctx, obj, ctx.depth);
  20558. }
  20559. exports.inspect = inspect;
  20560. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  20561. inspect.colors = {
  20562. 'bold' : [1, 22],
  20563. 'italic' : [3, 23],
  20564. 'underline' : [4, 24],
  20565. 'inverse' : [7, 27],
  20566. 'white' : [37, 39],
  20567. 'grey' : [90, 39],
  20568. 'black' : [30, 39],
  20569. 'blue' : [34, 39],
  20570. 'cyan' : [36, 39],
  20571. 'green' : [32, 39],
  20572. 'magenta' : [35, 39],
  20573. 'red' : [31, 39],
  20574. 'yellow' : [33, 39]
  20575. };
  20576. // Don't use 'blue' not visible on cmd.exe
  20577. inspect.styles = {
  20578. 'special': 'cyan',
  20579. 'number': 'yellow',
  20580. 'boolean': 'yellow',
  20581. 'undefined': 'grey',
  20582. 'null': 'bold',
  20583. 'string': 'green',
  20584. 'date': 'magenta',
  20585. // "name": intentionally not styling
  20586. 'regexp': 'red'
  20587. };
  20588. function stylizeWithColor(str, styleType) {
  20589. var style = inspect.styles[styleType];
  20590. if (style) {
  20591. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  20592. '\u001b[' + inspect.colors[style][1] + 'm';
  20593. } else {
  20594. return str;
  20595. }
  20596. }
  20597. function stylizeNoColor(str, styleType) {
  20598. return str;
  20599. }
  20600. function arrayToHash(array) {
  20601. var hash = {};
  20602. array.forEach(function(val, idx) {
  20603. hash[val] = true;
  20604. });
  20605. return hash;
  20606. }
  20607. function formatValue(ctx, value, recurseTimes) {
  20608. // Provide a hook for user-specified inspect functions.
  20609. // Check that value is an object with an inspect function on it
  20610. if (ctx.customInspect &&
  20611. value &&
  20612. isFunction(value.inspect) &&
  20613. // Filter out the util module, it's inspect function is special
  20614. value.inspect !== exports.inspect &&
  20615. // Also filter out any prototype objects using the circular check.
  20616. !(value.constructor && value.constructor.prototype === value)) {
  20617. var ret = value.inspect(recurseTimes, ctx);
  20618. if (!isString(ret)) {
  20619. ret = formatValue(ctx, ret, recurseTimes);
  20620. }
  20621. return ret;
  20622. }
  20623. // Primitive types cannot have properties
  20624. var primitive = formatPrimitive(ctx, value);
  20625. if (primitive) {
  20626. return primitive;
  20627. }
  20628. // Look up the keys of the object.
  20629. var keys = Object.keys(value);
  20630. var visibleKeys = arrayToHash(keys);
  20631. if (ctx.showHidden) {
  20632. keys = Object.getOwnPropertyNames(value);
  20633. }
  20634. // IE doesn't make error fields non-enumerable
  20635. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  20636. if (isError(value)
  20637. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  20638. return formatError(value);
  20639. }
  20640. // Some type of object without properties can be shortcutted.
  20641. if (keys.length === 0) {
  20642. if (isFunction(value)) {
  20643. var name = value.name ? ': ' + value.name : '';
  20644. return ctx.stylize('[Function' + name + ']', 'special');
  20645. }
  20646. if (isRegExp(value)) {
  20647. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  20648. }
  20649. if (isDate(value)) {
  20650. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  20651. }
  20652. if (isError(value)) {
  20653. return formatError(value);
  20654. }
  20655. }
  20656. var base = '', array = false, braces = ['{', '}'];
  20657. // Make Array say that they are Array
  20658. if (isArray(value)) {
  20659. array = true;
  20660. braces = ['[', ']'];
  20661. }
  20662. // Make functions say that they are functions
  20663. if (isFunction(value)) {
  20664. var n = value.name ? ': ' + value.name : '';
  20665. base = ' [Function' + n + ']';
  20666. }
  20667. // Make RegExps say that they are RegExps
  20668. if (isRegExp(value)) {
  20669. base = ' ' + RegExp.prototype.toString.call(value);
  20670. }
  20671. // Make dates with properties first say the date
  20672. if (isDate(value)) {
  20673. base = ' ' + Date.prototype.toUTCString.call(value);
  20674. }
  20675. // Make error with message first say the error
  20676. if (isError(value)) {
  20677. base = ' ' + formatError(value);
  20678. }
  20679. if (keys.length === 0 && (!array || value.length == 0)) {
  20680. return braces[0] + base + braces[1];
  20681. }
  20682. if (recurseTimes < 0) {
  20683. if (isRegExp(value)) {
  20684. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  20685. } else {
  20686. return ctx.stylize('[Object]', 'special');
  20687. }
  20688. }
  20689. ctx.seen.push(value);
  20690. var output;
  20691. if (array) {
  20692. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  20693. } else {
  20694. output = keys.map(function(key) {
  20695. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  20696. });
  20697. }
  20698. ctx.seen.pop();
  20699. return reduceToSingleString(output, base, braces);
  20700. }
  20701. function formatPrimitive(ctx, value) {
  20702. if (isUndefined(value))
  20703. return ctx.stylize('undefined', 'undefined');
  20704. if (isString(value)) {
  20705. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  20706. .replace(/'/g, "\\'")
  20707. .replace(/\\"/g, '"') + '\'';
  20708. return ctx.stylize(simple, 'string');
  20709. }
  20710. if (isNumber(value))
  20711. return ctx.stylize('' + value, 'number');
  20712. if (isBoolean(value))
  20713. return ctx.stylize('' + value, 'boolean');
  20714. // For some reason typeof null is "object", so special case here.
  20715. if (isNull(value))
  20716. return ctx.stylize('null', 'null');
  20717. }
  20718. function formatError(value) {
  20719. return '[' + Error.prototype.toString.call(value) + ']';
  20720. }
  20721. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  20722. var output = [];
  20723. for (var i = 0, l = value.length; i < l; ++i) {
  20724. if (hasOwnProperty(value, String(i))) {
  20725. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  20726. String(i), true));
  20727. } else {
  20728. output.push('');
  20729. }
  20730. }
  20731. keys.forEach(function(key) {
  20732. if (!key.match(/^\d+$/)) {
  20733. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  20734. key, true));
  20735. }
  20736. });
  20737. return output;
  20738. }
  20739. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  20740. var name, str, desc;
  20741. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  20742. if (desc.get) {
  20743. if (desc.set) {
  20744. str = ctx.stylize('[Getter/Setter]', 'special');
  20745. } else {
  20746. str = ctx.stylize('[Getter]', 'special');
  20747. }
  20748. } else {
  20749. if (desc.set) {
  20750. str = ctx.stylize('[Setter]', 'special');
  20751. }
  20752. }
  20753. if (!hasOwnProperty(visibleKeys, key)) {
  20754. name = '[' + key + ']';
  20755. }
  20756. if (!str) {
  20757. if (ctx.seen.indexOf(desc.value) < 0) {
  20758. if (isNull(recurseTimes)) {
  20759. str = formatValue(ctx, desc.value, null);
  20760. } else {
  20761. str = formatValue(ctx, desc.value, recurseTimes - 1);
  20762. }
  20763. if (str.indexOf('\n') > -1) {
  20764. if (array) {
  20765. str = str.split('\n').map(function(line) {
  20766. return ' ' + line;
  20767. }).join('\n').substr(2);
  20768. } else {
  20769. str = '\n' + str.split('\n').map(function(line) {
  20770. return ' ' + line;
  20771. }).join('\n');
  20772. }
  20773. }
  20774. } else {
  20775. str = ctx.stylize('[Circular]', 'special');
  20776. }
  20777. }
  20778. if (isUndefined(name)) {
  20779. if (array && key.match(/^\d+$/)) {
  20780. return str;
  20781. }
  20782. name = JSON.stringify('' + key);
  20783. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  20784. name = name.substr(1, name.length - 2);
  20785. name = ctx.stylize(name, 'name');
  20786. } else {
  20787. name = name.replace(/'/g, "\\'")
  20788. .replace(/\\"/g, '"')
  20789. .replace(/(^"|"$)/g, "'");
  20790. name = ctx.stylize(name, 'string');
  20791. }
  20792. }
  20793. return name + ': ' + str;
  20794. }
  20795. function reduceToSingleString(output, base, braces) {
  20796. var numLinesEst = 0;
  20797. var length = output.reduce(function(prev, cur) {
  20798. numLinesEst++;
  20799. if (cur.indexOf('\n') >= 0) numLinesEst++;
  20800. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  20801. }, 0);
  20802. if (length > 60) {
  20803. return braces[0] +
  20804. (base === '' ? '' : base + '\n ') +
  20805. ' ' +
  20806. output.join(',\n ') +
  20807. ' ' +
  20808. braces[1];
  20809. }
  20810. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  20811. }
  20812. // NOTE: These type checking functions intentionally don't use `instanceof`
  20813. // because it is fragile and can be easily faked with `Object.create()`.
  20814. function isArray(ar) {
  20815. return Array.isArray(ar);
  20816. }
  20817. exports.isArray = isArray;
  20818. function isBoolean(arg) {
  20819. return typeof arg === 'boolean';
  20820. }
  20821. exports.isBoolean = isBoolean;
  20822. function isNull(arg) {
  20823. return arg === null;
  20824. }
  20825. exports.isNull = isNull;
  20826. function isNullOrUndefined(arg) {
  20827. return arg == null;
  20828. }
  20829. exports.isNullOrUndefined = isNullOrUndefined;
  20830. function isNumber(arg) {
  20831. return typeof arg === 'number';
  20832. }
  20833. exports.isNumber = isNumber;
  20834. function isString(arg) {
  20835. return typeof arg === 'string';
  20836. }
  20837. exports.isString = isString;
  20838. function isSymbol(arg) {
  20839. return typeof arg === 'symbol';
  20840. }
  20841. exports.isSymbol = isSymbol;
  20842. function isUndefined(arg) {
  20843. return arg === void 0;
  20844. }
  20845. exports.isUndefined = isUndefined;
  20846. function isRegExp(re) {
  20847. return isObject(re) && objectToString(re) === '[object RegExp]';
  20848. }
  20849. exports.isRegExp = isRegExp;
  20850. function isObject(arg) {
  20851. return typeof arg === 'object' && arg !== null;
  20852. }
  20853. exports.isObject = isObject;
  20854. function isDate(d) {
  20855. return isObject(d) && objectToString(d) === '[object Date]';
  20856. }
  20857. exports.isDate = isDate;
  20858. function isError(e) {
  20859. return isObject(e) &&
  20860. (objectToString(e) === '[object Error]' || e instanceof Error);
  20861. }
  20862. exports.isError = isError;
  20863. function isFunction(arg) {
  20864. return typeof arg === 'function';
  20865. }
  20866. exports.isFunction = isFunction;
  20867. function isPrimitive(arg) {
  20868. return arg === null ||
  20869. typeof arg === 'boolean' ||
  20870. typeof arg === 'number' ||
  20871. typeof arg === 'string' ||
  20872. typeof arg === 'symbol' || // ES6 symbol
  20873. typeof arg === 'undefined';
  20874. }
  20875. exports.isPrimitive = isPrimitive;
  20876. exports.isBuffer = require('./support/isBuffer');
  20877. function objectToString(o) {
  20878. return Object.prototype.toString.call(o);
  20879. }
  20880. function pad(n) {
  20881. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  20882. }
  20883. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  20884. 'Oct', 'Nov', 'Dec'];
  20885. // 26 Feb 16:19:34
  20886. function timestamp() {
  20887. var d = new Date();
  20888. var time = [pad(d.getHours()),
  20889. pad(d.getMinutes()),
  20890. pad(d.getSeconds())].join(':');
  20891. return [d.getDate(), months[d.getMonth()], time].join(' ');
  20892. }
  20893. // log is just a thin wrapper to console.log that prepends a timestamp
  20894. exports.log = function() {
  20895. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  20896. };
  20897. /**
  20898. * Inherit the prototype methods from one constructor into another.
  20899. *
  20900. * The Function.prototype.inherits from lang.js rewritten as a standalone
  20901. * function (not on Function.prototype). NOTE: If this file is to be loaded
  20902. * during bootstrapping this function needs to be rewritten using some native
  20903. * functions as prototype setup using normal JavaScript does not work as
  20904. * expected during bootstrapping (see mirror.js in r114903).
  20905. *
  20906. * @param {function} ctor Constructor function which needs to inherit the
  20907. * prototype.
  20908. * @param {function} superCtor Constructor function to inherit prototype from.
  20909. */
  20910. exports.inherits = require('inherits');
  20911. exports._extend = function(origin, add) {
  20912. // Don't do anything if add isn't an object
  20913. if (!add || !isObject(add)) return origin;
  20914. var keys = Object.keys(add);
  20915. var i = keys.length;
  20916. while (i--) {
  20917. origin[keys[i]] = add[keys[i]];
  20918. }
  20919. return origin;
  20920. };
  20921. function hasOwnProperty(obj, prop) {
  20922. return Object.prototype.hasOwnProperty.call(obj, prop);
  20923. }
  20924. }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  20925. },{"./support/isBuffer":32,"_process":30,"inherits":31}],34:[function(require,module,exports){
  20926. /**
  20927. * Helpers.
  20928. */
  20929. var s = 1000
  20930. var m = s * 60
  20931. var h = m * 60
  20932. var d = h * 24
  20933. var y = d * 365.25
  20934. /**
  20935. * Parse or format the given `val`.
  20936. *
  20937. * Options:
  20938. *
  20939. * - `long` verbose formatting [false]
  20940. *
  20941. * @param {String|Number} val
  20942. * @param {Object} options
  20943. * @throws {Error} throw an error if val is not a non-empty string or a number
  20944. * @return {String|Number}
  20945. * @api public
  20946. */
  20947. module.exports = function (val, options) {
  20948. options = options || {}
  20949. var type = typeof val
  20950. if (type === 'string' && val.length > 0) {
  20951. return parse(val)
  20952. } else if (type === 'number' && isNaN(val) === false) {
  20953. return options.long ?
  20954. fmtLong(val) :
  20955. fmtShort(val)
  20956. }
  20957. throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val))
  20958. }
  20959. /**
  20960. * Parse the given `str` and return milliseconds.
  20961. *
  20962. * @param {String} str
  20963. * @return {Number}
  20964. * @api private
  20965. */
  20966. function parse(str) {
  20967. str = String(str)
  20968. if (str.length > 10000) {
  20969. return
  20970. }
  20971. var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str)
  20972. if (!match) {
  20973. return
  20974. }
  20975. var n = parseFloat(match[1])
  20976. var type = (match[2] || 'ms').toLowerCase()
  20977. switch (type) {
  20978. case 'years':
  20979. case 'year':
  20980. case 'yrs':
  20981. case 'yr':
  20982. case 'y':
  20983. return n * y
  20984. case 'days':
  20985. case 'day':
  20986. case 'd':
  20987. return n * d
  20988. case 'hours':
  20989. case 'hour':
  20990. case 'hrs':
  20991. case 'hr':
  20992. case 'h':
  20993. return n * h
  20994. case 'minutes':
  20995. case 'minute':
  20996. case 'mins':
  20997. case 'min':
  20998. case 'm':
  20999. return n * m
  21000. case 'seconds':
  21001. case 'second':
  21002. case 'secs':
  21003. case 'sec':
  21004. case 's':
  21005. return n * s
  21006. case 'milliseconds':
  21007. case 'millisecond':
  21008. case 'msecs':
  21009. case 'msec':
  21010. case 'ms':
  21011. return n
  21012. default:
  21013. return undefined
  21014. }
  21015. }
  21016. /**
  21017. * Short format for `ms`.
  21018. *
  21019. * @param {Number} ms
  21020. * @return {String}
  21021. * @api private
  21022. */
  21023. function fmtShort(ms) {
  21024. if (ms >= d) {
  21025. return Math.round(ms / d) + 'd'
  21026. }
  21027. if (ms >= h) {
  21028. return Math.round(ms / h) + 'h'
  21029. }
  21030. if (ms >= m) {
  21031. return Math.round(ms / m) + 'm'
  21032. }
  21033. if (ms >= s) {
  21034. return Math.round(ms / s) + 's'
  21035. }
  21036. return ms + 'ms'
  21037. }
  21038. /**
  21039. * Long format for `ms`.
  21040. *
  21041. * @param {Number} ms
  21042. * @return {String}
  21043. * @api private
  21044. */
  21045. function fmtLong(ms) {
  21046. return plural(ms, d, 'day') ||
  21047. plural(ms, h, 'hour') ||
  21048. plural(ms, m, 'minute') ||
  21049. plural(ms, s, 'second') ||
  21050. ms + ' ms'
  21051. }
  21052. /**
  21053. * Pluralization helper.
  21054. */
  21055. function plural(ms, n, name) {
  21056. if (ms < n) {
  21057. return
  21058. }
  21059. if (ms < n * 1.5) {
  21060. return Math.floor(ms / n) + ' ' + name
  21061. }
  21062. return Math.ceil(ms / n) + ' ' + name + 's'
  21063. }
  21064. },{}],35:[function(require,module,exports){
  21065. (function (process){
  21066. /**
  21067. * This is the web browser implementation of `debug()`.
  21068. *
  21069. * Expose `debug()` as the module.
  21070. */
  21071. exports = module.exports = require('./debug');
  21072. exports.log = log;
  21073. exports.formatArgs = formatArgs;
  21074. exports.save = save;
  21075. exports.load = load;
  21076. exports.useColors = useColors;
  21077. exports.storage = 'undefined' != typeof chrome
  21078. && 'undefined' != typeof chrome.storage
  21079. ? chrome.storage.local
  21080. : localstorage();
  21081. /**
  21082. * Colors.
  21083. */
  21084. exports.colors = [
  21085. 'lightseagreen',
  21086. 'forestgreen',
  21087. 'goldenrod',
  21088. 'dodgerblue',
  21089. 'darkorchid',
  21090. 'crimson'
  21091. ];
  21092. /**
  21093. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  21094. * and the Firebug extension (any Firefox version) are known
  21095. * to support "%c" CSS customizations.
  21096. *
  21097. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  21098. */
  21099. function useColors() {
  21100. // NB: In an Electron preload script, document will be defined but not fully
  21101. // initialized. Since we know we're in Chrome, we'll just detect this case
  21102. // explicitly
  21103. if (typeof window !== 'undefined' && window && typeof window.process !== 'undefined' && window.process.type === 'renderer') {
  21104. return true;
  21105. }
  21106. // is webkit? http://stackoverflow.com/a/16459606/376773
  21107. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  21108. return (typeof document !== 'undefined' && document && 'WebkitAppearance' in document.documentElement.style) ||
  21109. // is firebug? http://stackoverflow.com/a/398120/376773
  21110. (typeof window !== 'undefined' && window && window.console && (console.firebug || (console.exception && console.table))) ||
  21111. // is firefox >= v31?
  21112. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  21113. (typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  21114. // double check webkit in userAgent just in case we are in a worker
  21115. (typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  21116. }
  21117. /**
  21118. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  21119. */
  21120. exports.formatters.j = function(v) {
  21121. try {
  21122. return JSON.stringify(v);
  21123. } catch (err) {
  21124. return '[UnexpectedJSONParseError]: ' + err.message;
  21125. }
  21126. };
  21127. /**
  21128. * Colorize log arguments if enabled.
  21129. *
  21130. * @api public
  21131. */
  21132. function formatArgs(args) {
  21133. var useColors = this.useColors;
  21134. args[0] = (useColors ? '%c' : '')
  21135. + this.namespace
  21136. + (useColors ? ' %c' : ' ')
  21137. + args[0]
  21138. + (useColors ? '%c ' : ' ')
  21139. + '+' + exports.humanize(this.diff);
  21140. if (!useColors) return;
  21141. var c = 'color: ' + this.color;
  21142. args.splice(1, 0, c, 'color: inherit')
  21143. // the final "%c" is somewhat tricky, because there could be other
  21144. // arguments passed either before or after the %c, so we need to
  21145. // figure out the correct index to insert the CSS into
  21146. var index = 0;
  21147. var lastC = 0;
  21148. args[0].replace(/%[a-zA-Z%]/g, function(match) {
  21149. if ('%%' === match) return;
  21150. index++;
  21151. if ('%c' === match) {
  21152. // we only are interested in the *last* %c
  21153. // (the user may have provided their own)
  21154. lastC = index;
  21155. }
  21156. });
  21157. args.splice(lastC, 0, c);
  21158. }
  21159. /**
  21160. * Invokes `console.log()` when available.
  21161. * No-op when `console.log` is not a "function".
  21162. *
  21163. * @api public
  21164. */
  21165. function log() {
  21166. // this hackery is required for IE8/9, where
  21167. // the `console.log` function doesn't have 'apply'
  21168. return 'object' === typeof console
  21169. && console.log
  21170. && Function.prototype.apply.call(console.log, console, arguments);
  21171. }
  21172. /**
  21173. * Save `namespaces`.
  21174. *
  21175. * @param {String} namespaces
  21176. * @api private
  21177. */
  21178. function save(namespaces) {
  21179. try {
  21180. if (null == namespaces) {
  21181. exports.storage.removeItem('debug');
  21182. } else {
  21183. exports.storage.debug = namespaces;
  21184. }
  21185. } catch(e) {}
  21186. }
  21187. /**
  21188. * Load `namespaces`.
  21189. *
  21190. * @return {String} returns the previously persisted debug modes
  21191. * @api private
  21192. */
  21193. function load() {
  21194. try {
  21195. return exports.storage.debug;
  21196. } catch(e) {}
  21197. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  21198. if (typeof process !== 'undefined' && 'env' in process) {
  21199. return process.env.DEBUG;
  21200. }
  21201. }
  21202. /**
  21203. * Enable namespaces listed in `localStorage.debug` initially.
  21204. */
  21205. exports.enable(load());
  21206. /**
  21207. * Localstorage attempts to return the localstorage.
  21208. *
  21209. * This is necessary because safari throws
  21210. * when a user disables cookies/localstorage
  21211. * and you attempt to access it.
  21212. *
  21213. * @return {LocalStorage}
  21214. * @api private
  21215. */
  21216. function localstorage() {
  21217. try {
  21218. return window.localStorage;
  21219. } catch (e) {}
  21220. }
  21221. }).call(this,require('_process'))
  21222. },{"./debug":36,"_process":30}],36:[function(require,module,exports){
  21223. /**
  21224. * This is the common logic for both the Node.js and web browser
  21225. * implementations of `debug()`.
  21226. *
  21227. * Expose `debug()` as the module.
  21228. */
  21229. exports = module.exports = createDebug.debug = createDebug.default = createDebug;
  21230. exports.coerce = coerce;
  21231. exports.disable = disable;
  21232. exports.enable = enable;
  21233. exports.enabled = enabled;
  21234. exports.humanize = require('ms');
  21235. /**
  21236. * The currently active debug mode names, and names to skip.
  21237. */
  21238. exports.names = [];
  21239. exports.skips = [];
  21240. /**
  21241. * Map of special "%n" handling functions, for the debug "format" argument.
  21242. *
  21243. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  21244. */
  21245. exports.formatters = {};
  21246. /**
  21247. * Previous log timestamp.
  21248. */
  21249. var prevTime;
  21250. /**
  21251. * Select a color.
  21252. * @param {String} namespace
  21253. * @return {Number}
  21254. * @api private
  21255. */
  21256. function selectColor(namespace) {
  21257. var hash = 0, i;
  21258. for (i in namespace) {
  21259. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  21260. hash |= 0; // Convert to 32bit integer
  21261. }
  21262. return exports.colors[Math.abs(hash) % exports.colors.length];
  21263. }
  21264. /**
  21265. * Create a debugger with the given `namespace`.
  21266. *
  21267. * @param {String} namespace
  21268. * @return {Function}
  21269. * @api public
  21270. */
  21271. function createDebug(namespace) {
  21272. function debug() {
  21273. // disabled?
  21274. if (!debug.enabled) return;
  21275. var self = debug;
  21276. // set `diff` timestamp
  21277. var curr = +new Date();
  21278. var ms = curr - (prevTime || curr);
  21279. self.diff = ms;
  21280. self.prev = prevTime;
  21281. self.curr = curr;
  21282. prevTime = curr;
  21283. // turn the `arguments` into a proper Array
  21284. var args = new Array(arguments.length);
  21285. for (var i = 0; i < args.length; i++) {
  21286. args[i] = arguments[i];
  21287. }
  21288. args[0] = exports.coerce(args[0]);
  21289. if ('string' !== typeof args[0]) {
  21290. // anything else let's inspect with %O
  21291. args.unshift('%O');
  21292. }
  21293. // apply any `formatters` transformations
  21294. var index = 0;
  21295. args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
  21296. // if we encounter an escaped % then don't increase the array index
  21297. if (match === '%%') return match;
  21298. index++;
  21299. var formatter = exports.formatters[format];
  21300. if ('function' === typeof formatter) {
  21301. var val = args[index];
  21302. match = formatter.call(self, val);
  21303. // now we need to remove `args[index]` since it's inlined in the `format`
  21304. args.splice(index, 1);
  21305. index--;
  21306. }
  21307. return match;
  21308. });
  21309. // apply env-specific formatting (colors, etc.)
  21310. exports.formatArgs.call(self, args);
  21311. var logFn = debug.log || exports.log || console.log.bind(console);
  21312. logFn.apply(self, args);
  21313. }
  21314. debug.namespace = namespace;
  21315. debug.enabled = exports.enabled(namespace);
  21316. debug.useColors = exports.useColors();
  21317. debug.color = selectColor(namespace);
  21318. // env-specific initialization logic for debug instances
  21319. if ('function' === typeof exports.init) {
  21320. exports.init(debug);
  21321. }
  21322. return debug;
  21323. }
  21324. /**
  21325. * Enables a debug mode by namespaces. This can include modes
  21326. * separated by a colon and wildcards.
  21327. *
  21328. * @param {String} namespaces
  21329. * @api public
  21330. */
  21331. function enable(namespaces) {
  21332. exports.save(namespaces);
  21333. var split = (namespaces || '').split(/[\s,]+/);
  21334. var len = split.length;
  21335. for (var i = 0; i < len; i++) {
  21336. if (!split[i]) continue; // ignore empty strings
  21337. namespaces = split[i].replace(/\*/g, '.*?');
  21338. if (namespaces[0] === '-') {
  21339. exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  21340. } else {
  21341. exports.names.push(new RegExp('^' + namespaces + '$'));
  21342. }
  21343. }
  21344. }
  21345. /**
  21346. * Disable debug output.
  21347. *
  21348. * @api public
  21349. */
  21350. function disable() {
  21351. exports.enable('');
  21352. }
  21353. /**
  21354. * Returns true if the given mode name is enabled, false otherwise.
  21355. *
  21356. * @param {String} name
  21357. * @return {Boolean}
  21358. * @api public
  21359. */
  21360. function enabled(name) {
  21361. var i, len;
  21362. for (i = 0, len = exports.skips.length; i < len; i++) {
  21363. if (exports.skips[i].test(name)) {
  21364. return false;
  21365. }
  21366. }
  21367. for (i = 0, len = exports.names.length; i < len; i++) {
  21368. if (exports.names[i].test(name)) {
  21369. return true;
  21370. }
  21371. }
  21372. return false;
  21373. }
  21374. /**
  21375. * Coerce `val`.
  21376. *
  21377. * @param {Mixed} val
  21378. * @return {Mixed}
  21379. * @api private
  21380. */
  21381. function coerce(val) {
  21382. if (val instanceof Error) return val.stack || val.message;
  21383. return val;
  21384. }
  21385. },{"ms":34}],37:[function(require,module,exports){
  21386. var grammar = module.exports = {
  21387. v: [{
  21388. name: 'version',
  21389. reg: /^(\d*)$/
  21390. }],
  21391. o: [{ //o=- 20518 0 IN IP4 203.0.113.1
  21392. // NB: sessionId will be a String in most cases because it is huge
  21393. name: 'origin',
  21394. reg: /^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,
  21395. names: ['username', 'sessionId', 'sessionVersion', 'netType', 'ipVer', 'address'],
  21396. format: "%s %s %d %s IP%d %s"
  21397. }],
  21398. // default parsing of these only (though some of these feel outdated)
  21399. s: [{ name: 'name' }],
  21400. i: [{ name: 'description' }],
  21401. u: [{ name: 'uri' }],
  21402. e: [{ name: 'email' }],
  21403. p: [{ name: 'phone' }],
  21404. z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly..
  21405. r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly
  21406. //k: [{}], // outdated thing ignored
  21407. t: [{ //t=0 0
  21408. name: 'timing',
  21409. reg: /^(\d*) (\d*)/,
  21410. names: ['start', 'stop'],
  21411. format: "%d %d"
  21412. }],
  21413. c: [{ //c=IN IP4 10.47.197.26
  21414. name: 'connection',
  21415. reg: /^IN IP(\d) (\S*)/,
  21416. names: ['version', 'ip'],
  21417. format: "IN IP%d %s"
  21418. }],
  21419. b: [{ //b=AS:4000
  21420. push: 'bandwidth',
  21421. reg: /^(TIAS|AS|CT|RR|RS):(\d*)/,
  21422. names: ['type', 'limit'],
  21423. format: "%s:%s"
  21424. }],
  21425. m: [{ //m=video 51744 RTP/AVP 126 97 98 34 31
  21426. // NB: special - pushes to session
  21427. // TODO: rtp/fmtp should be filtered by the payloads found here?
  21428. reg: /^(\w*) (\d*) ([\w\/]*)(?: (.*))?/,
  21429. names: ['type', 'port', 'protocol', 'payloads'],
  21430. format: "%s %d %s %s"
  21431. }],
  21432. a: [
  21433. { //a=rtpmap:110 opus/48000/2
  21434. push: 'rtp',
  21435. reg: /^rtpmap:(\d*) ([\w\-\.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,
  21436. names: ['payload', 'codec', 'rate', 'encoding'],
  21437. format: function (o) {
  21438. return (o.encoding) ?
  21439. "rtpmap:%d %s/%s/%s":
  21440. o.rate ?
  21441. "rtpmap:%d %s/%s":
  21442. "rtpmap:%d %s";
  21443. }
  21444. },
  21445. {
  21446. //a=fmtp:108 profile-level-id=24;object=23;bitrate=64000
  21447. //a=fmtp:111 minptime=10; useinbandfec=1
  21448. push: 'fmtp',
  21449. reg: /^fmtp:(\d*) ([\S| ]*)/,
  21450. names: ['payload', 'config'],
  21451. format: "fmtp:%d %s"
  21452. },
  21453. { //a=control:streamid=0
  21454. name: 'control',
  21455. reg: /^control:(.*)/,
  21456. format: "control:%s"
  21457. },
  21458. { //a=rtcp:65179 IN IP4 193.84.77.194
  21459. name: 'rtcp',
  21460. reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,
  21461. names: ['port', 'netType', 'ipVer', 'address'],
  21462. format: function (o) {
  21463. return (o.address != null) ?
  21464. "rtcp:%d %s IP%d %s":
  21465. "rtcp:%d";
  21466. }
  21467. },
  21468. { //a=rtcp-fb:98 trr-int 100
  21469. push: 'rtcpFbTrrInt',
  21470. reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/,
  21471. names: ['payload', 'value'],
  21472. format: "rtcp-fb:%d trr-int %d"
  21473. },
  21474. { //a=rtcp-fb:98 nack rpsi
  21475. push: 'rtcpFb',
  21476. reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,
  21477. names: ['payload', 'type', 'subtype'],
  21478. format: function (o) {
  21479. return (o.subtype != null) ?
  21480. "rtcp-fb:%s %s %s":
  21481. "rtcp-fb:%s %s";
  21482. }
  21483. },
  21484. { //a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  21485. //a=extmap:1/recvonly URI-gps-string
  21486. push: 'ext',
  21487. reg: /^extmap:([\w_\/]*) (\S*)(?: (\S*))?/,
  21488. names: ['value', 'uri', 'config'], // value may include "/direction" suffix
  21489. format: function (o) {
  21490. return (o.config != null) ?
  21491. "extmap:%s %s %s":
  21492. "extmap:%s %s";
  21493. }
  21494. },
  21495. {
  21496. //a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32
  21497. push: 'crypto',
  21498. reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,
  21499. names: ['id', 'suite', 'config', 'sessionConfig'],
  21500. format: function (o) {
  21501. return (o.sessionConfig != null) ?
  21502. "crypto:%d %s %s %s":
  21503. "crypto:%d %s %s";
  21504. }
  21505. },
  21506. { //a=setup:actpass
  21507. name: 'setup',
  21508. reg: /^setup:(\w*)/,
  21509. format: "setup:%s"
  21510. },
  21511. { //a=mid:1
  21512. name: 'mid',
  21513. reg: /^mid:([^\s]*)/,
  21514. format: "mid:%s"
  21515. },
  21516. { //a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a
  21517. name: 'msid',
  21518. reg: /^msid:(.*)/,
  21519. format: "msid:%s"
  21520. },
  21521. { //a=ptime:20
  21522. name: 'ptime',
  21523. reg: /^ptime:(\d*)/,
  21524. format: "ptime:%d"
  21525. },
  21526. { //a=maxptime:60
  21527. name: 'maxptime',
  21528. reg: /^maxptime:(\d*)/,
  21529. format: "maxptime:%d"
  21530. },
  21531. { //a=sendrecv
  21532. name: 'direction',
  21533. reg: /^(sendrecv|recvonly|sendonly|inactive)/
  21534. },
  21535. { //a=ice-lite
  21536. name: 'icelite',
  21537. reg: /^(ice-lite)/
  21538. },
  21539. { //a=ice-ufrag:F7gI
  21540. name: 'iceUfrag',
  21541. reg: /^ice-ufrag:(\S*)/,
  21542. format: "ice-ufrag:%s"
  21543. },
  21544. { //a=ice-pwd:x9cml/YzichV2+XlhiMu8g
  21545. name: 'icePwd',
  21546. reg: /^ice-pwd:(\S*)/,
  21547. format: "ice-pwd:%s"
  21548. },
  21549. { //a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
  21550. name: 'fingerprint',
  21551. reg: /^fingerprint:(\S*) (\S*)/,
  21552. names: ['type', 'hash'],
  21553. format: "fingerprint:%s %s"
  21554. },
  21555. {
  21556. //a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
  21557. //a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0
  21558. //a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0
  21559. //a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0
  21560. //a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0
  21561. push:'candidates',
  21562. reg: /^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?/,
  21563. names: ['foundation', 'component', 'transport', 'priority', 'ip', 'port', 'type', 'raddr', 'rport', 'tcptype', 'generation'],
  21564. format: function (o) {
  21565. var str = "candidate:%s %d %s %d %s %d typ %s";
  21566. str += (o.raddr != null) ? " raddr %s rport %d" : "%v%v";
  21567. // NB: candidate has three optional chunks, so %void middles one if it's missing
  21568. str += (o.tcptype != null) ? " tcptype %s" : "%v";
  21569. if (o.generation != null) {
  21570. str += " generation %d";
  21571. }
  21572. return str;
  21573. }
  21574. },
  21575. { //a=end-of-candidates (keep after the candidates line for readability)
  21576. name: 'endOfCandidates',
  21577. reg: /^(end-of-candidates)/
  21578. },
  21579. { //a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ...
  21580. name: 'remoteCandidates',
  21581. reg: /^remote-candidates:(.*)/,
  21582. format: "remote-candidates:%s"
  21583. },
  21584. { //a=ice-options:google-ice
  21585. name: 'iceOptions',
  21586. reg: /^ice-options:(\S*)/,
  21587. format: "ice-options:%s"
  21588. },
  21589. { //a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1
  21590. push: "ssrcs",
  21591. reg: /^ssrc:(\d*) ([\w_]*):(.*)/,
  21592. names: ['id', 'attribute', 'value'],
  21593. format: "ssrc:%d %s:%s"
  21594. },
  21595. { //a=ssrc-group:FEC 1 2
  21596. push: "ssrcGroups",
  21597. reg: /^ssrc-group:(\w*) (.*)/,
  21598. names: ['semantics', 'ssrcs'],
  21599. format: "ssrc-group:%s %s"
  21600. },
  21601. { //a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV
  21602. name: "msidSemantic",
  21603. reg: /^msid-semantic:\s?(\w*) (\S*)/,
  21604. names: ['semantic', 'token'],
  21605. format: "msid-semantic: %s %s" // space after ":" is not accidental
  21606. },
  21607. { //a=group:BUNDLE audio video
  21608. push: 'groups',
  21609. reg: /^group:(\w*) (.*)/,
  21610. names: ['type', 'mids'],
  21611. format: "group:%s %s"
  21612. },
  21613. { //a=rtcp-mux
  21614. name: 'rtcpMux',
  21615. reg: /^(rtcp-mux)/
  21616. },
  21617. { //a=rtcp-rsize
  21618. name: 'rtcpRsize',
  21619. reg: /^(rtcp-rsize)/
  21620. },
  21621. { //a=sctpmap:5000 webrtc-datachannel 1024
  21622. name: 'sctpmap',
  21623. reg: /^sctpmap:([\w_\/]*) (\S*)(?: (\S*))?/,
  21624. names: ['sctpmapNumber', 'app', 'maxMessageSize'],
  21625. format: function (o) {
  21626. return (o.maxMessageSize != null) ?
  21627. "sctpmap:%s %s %s" :
  21628. "sctpmap:%s %s";
  21629. }
  21630. },
  21631. { // any a= that we don't understand is kepts verbatim on media.invalid
  21632. push: 'invalid',
  21633. names: ["value"]
  21634. }
  21635. ]
  21636. };
  21637. // set sensible defaults to avoid polluting the grammar with boring details
  21638. Object.keys(grammar).forEach(function (key) {
  21639. var objs = grammar[key];
  21640. objs.forEach(function (obj) {
  21641. if (!obj.reg) {
  21642. obj.reg = /(.*)/;
  21643. }
  21644. if (!obj.format) {
  21645. obj.format = "%s";
  21646. }
  21647. });
  21648. });
  21649. },{}],38:[function(require,module,exports){
  21650. var parser = require('./parser');
  21651. var writer = require('./writer');
  21652. exports.write = writer;
  21653. exports.parse = parser.parse;
  21654. exports.parseFmtpConfig = parser.parseFmtpConfig;
  21655. exports.parsePayloads = parser.parsePayloads;
  21656. exports.parseRemoteCandidates = parser.parseRemoteCandidates;
  21657. },{"./parser":39,"./writer":40}],39:[function(require,module,exports){
  21658. var toIntIfInt = function (v) {
  21659. return String(Number(v)) === v ? Number(v) : v;
  21660. };
  21661. var attachProperties = function (match, location, names, rawName) {
  21662. if (rawName && !names) {
  21663. location[rawName] = toIntIfInt(match[1]);
  21664. }
  21665. else {
  21666. for (var i = 0; i < names.length; i += 1) {
  21667. if (match[i+1] != null) {
  21668. location[names[i]] = toIntIfInt(match[i+1]);
  21669. }
  21670. }
  21671. }
  21672. };
  21673. var parseReg = function (obj, location, content) {
  21674. var needsBlank = obj.name && obj.names;
  21675. if (obj.push && !location[obj.push]) {
  21676. location[obj.push] = [];
  21677. }
  21678. else if (needsBlank && !location[obj.name]) {
  21679. location[obj.name] = {};
  21680. }
  21681. var keyLocation = obj.push ?
  21682. {} : // blank object that will be pushed
  21683. needsBlank ? location[obj.name] : location; // otherwise, named location or root
  21684. attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name);
  21685. if (obj.push) {
  21686. location[obj.push].push(keyLocation);
  21687. }
  21688. };
  21689. var grammar = require('./grammar');
  21690. var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/);
  21691. exports.parse = function (sdp) {
  21692. var session = {}
  21693. , media = []
  21694. , location = session; // points at where properties go under (one of the above)
  21695. // parse lines we understand
  21696. sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) {
  21697. var type = l[0];
  21698. var content = l.slice(2);
  21699. if (type === 'm') {
  21700. media.push({rtp: [], fmtp: []});
  21701. location = media[media.length-1]; // point at latest media line
  21702. }
  21703. for (var j = 0; j < (grammar[type] || []).length; j += 1) {
  21704. var obj = grammar[type][j];
  21705. if (obj.reg.test(content)) {
  21706. return parseReg(obj, location, content);
  21707. }
  21708. }
  21709. });
  21710. session.media = media; // link it up
  21711. return session;
  21712. };
  21713. var fmtpReducer = function (acc, expr) {
  21714. var s = expr.split(/=(.+)/, 2);
  21715. if (s.length === 2) {
  21716. acc[s[0]] = toIntIfInt(s[1]);
  21717. }
  21718. return acc;
  21719. };
  21720. exports.parseFmtpConfig = function (str) {
  21721. return str.split(/\;\s?/).reduce(fmtpReducer, {});
  21722. };
  21723. exports.parsePayloads = function (str) {
  21724. return str.split(' ').map(Number);
  21725. };
  21726. exports.parseRemoteCandidates = function (str) {
  21727. var candidates = [];
  21728. var parts = str.split(' ').map(toIntIfInt);
  21729. for (var i = 0; i < parts.length; i += 3) {
  21730. candidates.push({
  21731. component: parts[i],
  21732. ip: parts[i + 1],
  21733. port: parts[i + 2]
  21734. });
  21735. }
  21736. return candidates;
  21737. };
  21738. },{"./grammar":37}],40:[function(require,module,exports){
  21739. var grammar = require('./grammar');
  21740. // customized util.format - discards excess arguments and can void middle ones
  21741. var formatRegExp = /%[sdv%]/g;
  21742. var format = function (formatStr) {
  21743. var i = 1;
  21744. var args = arguments;
  21745. var len = args.length;
  21746. return formatStr.replace(formatRegExp, function (x) {
  21747. if (i >= len) {
  21748. return x; // missing argument
  21749. }
  21750. var arg = args[i];
  21751. i += 1;
  21752. switch (x) {
  21753. case '%%':
  21754. return '%';
  21755. case '%s':
  21756. return String(arg);
  21757. case '%d':
  21758. return Number(arg);
  21759. case '%v':
  21760. return '';
  21761. }
  21762. });
  21763. // NB: we discard excess arguments - they are typically undefined from makeLine
  21764. };
  21765. var makeLine = function (type, obj, location) {
  21766. var str = obj.format instanceof Function ?
  21767. (obj.format(obj.push ? location : location[obj.name])) :
  21768. obj.format;
  21769. var args = [type + '=' + str];
  21770. if (obj.names) {
  21771. for (var i = 0; i < obj.names.length; i += 1) {
  21772. var n = obj.names[i];
  21773. if (obj.name) {
  21774. args.push(location[obj.name][n]);
  21775. }
  21776. else { // for mLine and push attributes
  21777. args.push(location[obj.names[i]]);
  21778. }
  21779. }
  21780. }
  21781. else {
  21782. args.push(location[obj.name]);
  21783. }
  21784. return format.apply(null, args);
  21785. };
  21786. // RFC specified order
  21787. // TODO: extend this with all the rest
  21788. var defaultOuterOrder = [
  21789. 'v', 'o', 's', 'i',
  21790. 'u', 'e', 'p', 'c',
  21791. 'b', 't', 'r', 'z', 'a'
  21792. ];
  21793. var defaultInnerOrder = ['i', 'c', 'b', 'a'];
  21794. module.exports = function (session, opts) {
  21795. opts = opts || {};
  21796. // ensure certain properties exist
  21797. if (session.version == null) {
  21798. session.version = 0; // "v=0" must be there (only defined version atm)
  21799. }
  21800. if (session.name == null) {
  21801. session.name = " "; // "s= " must be there if no meaningful name set
  21802. }
  21803. session.media.forEach(function (mLine) {
  21804. if (mLine.payloads == null) {
  21805. mLine.payloads = "";
  21806. }
  21807. });
  21808. var outerOrder = opts.outerOrder || defaultOuterOrder;
  21809. var innerOrder = opts.innerOrder || defaultInnerOrder;
  21810. var sdp = [];
  21811. // loop through outerOrder for matching properties on session
  21812. outerOrder.forEach(function (type) {
  21813. grammar[type].forEach(function (obj) {
  21814. if (obj.name in session && session[obj.name] != null) {
  21815. sdp.push(makeLine(type, obj, session));
  21816. }
  21817. else if (obj.push in session && session[obj.push] != null) {
  21818. session[obj.push].forEach(function (el) {
  21819. sdp.push(makeLine(type, obj, el));
  21820. });
  21821. }
  21822. });
  21823. });
  21824. // then for each media line, follow the innerOrder
  21825. session.media.forEach(function (mLine) {
  21826. sdp.push(makeLine('m', grammar.m[0], mLine));
  21827. innerOrder.forEach(function (type) {
  21828. grammar[type].forEach(function (obj) {
  21829. if (obj.name in mLine && mLine[obj.name] != null) {
  21830. sdp.push(makeLine(type, obj, mLine));
  21831. }
  21832. else if (obj.push in mLine && mLine[obj.push] != null) {
  21833. mLine[obj.push].forEach(function (el) {
  21834. sdp.push(makeLine(type, obj, el));
  21835. });
  21836. }
  21837. });
  21838. });
  21839. });
  21840. return sdp.join('\r\n') + '\r\n';
  21841. };
  21842. },{"./grammar":37}],41:[function(require,module,exports){
  21843. /* eslint-env node */
  21844. 'use strict';
  21845. // SDP helpers.
  21846. var SDPUtils = {};
  21847. // Generate an alphanumeric identifier for cname or mids.
  21848. // TODO: use UUIDs instead? https://gist.github.com/jed/982883
  21849. SDPUtils.generateIdentifier = function() {
  21850. return Math.random().toString(36).substr(2, 10);
  21851. };
  21852. // The RTCP CNAME used by all peerconnections from the same JS.
  21853. SDPUtils.localCName = SDPUtils.generateIdentifier();
  21854. // Splits SDP into lines, dealing with both CRLF and LF.
  21855. SDPUtils.splitLines = function(blob) {
  21856. return blob.trim().split('\n').map(function(line) {
  21857. return line.trim();
  21858. });
  21859. };
  21860. // Splits SDP into sessionpart and mediasections. Ensures CRLF.
  21861. SDPUtils.splitSections = function(blob) {
  21862. var parts = blob.split('\nm=');
  21863. return parts.map(function(part, index) {
  21864. return (index > 0 ? 'm=' + part : part).trim() + '\r\n';
  21865. });
  21866. };
  21867. // Returns lines that start with a certain prefix.
  21868. SDPUtils.matchPrefix = function(blob, prefix) {
  21869. return SDPUtils.splitLines(blob).filter(function(line) {
  21870. return line.indexOf(prefix) === 0;
  21871. });
  21872. };
  21873. // Parses an ICE candidate line. Sample input:
  21874. // candidate:702786350 2 udp 41819902 8.8.8.8 60769 typ relay raddr 8.8.8.8
  21875. // rport 55996"
  21876. SDPUtils.parseCandidate = function(line) {
  21877. var parts;
  21878. // Parse both variants.
  21879. if (line.indexOf('a=candidate:') === 0) {
  21880. parts = line.substring(12).split(' ');
  21881. } else {
  21882. parts = line.substring(10).split(' ');
  21883. }
  21884. var candidate = {
  21885. foundation: parts[0],
  21886. component: parts[1],
  21887. protocol: parts[2].toLowerCase(),
  21888. priority: parseInt(parts[3], 10),
  21889. ip: parts[4],
  21890. port: parseInt(parts[5], 10),
  21891. // skip parts[6] == 'typ'
  21892. type: parts[7]
  21893. };
  21894. for (var i = 8; i < parts.length; i += 2) {
  21895. switch (parts[i]) {
  21896. case 'raddr':
  21897. candidate.relatedAddress = parts[i + 1];
  21898. break;
  21899. case 'rport':
  21900. candidate.relatedPort = parseInt(parts[i + 1], 10);
  21901. break;
  21902. case 'tcptype':
  21903. candidate.tcpType = parts[i + 1];
  21904. break;
  21905. default: // Unknown extensions are silently ignored.
  21906. break;
  21907. }
  21908. }
  21909. return candidate;
  21910. };
  21911. // Translates a candidate object into SDP candidate attribute.
  21912. SDPUtils.writeCandidate = function(candidate) {
  21913. var sdp = [];
  21914. sdp.push(candidate.foundation);
  21915. sdp.push(candidate.component);
  21916. sdp.push(candidate.protocol.toUpperCase());
  21917. sdp.push(candidate.priority);
  21918. sdp.push(candidate.ip);
  21919. sdp.push(candidate.port);
  21920. var type = candidate.type;
  21921. sdp.push('typ');
  21922. sdp.push(type);
  21923. if (type !== 'host' && candidate.relatedAddress &&
  21924. candidate.relatedPort) {
  21925. sdp.push('raddr');
  21926. sdp.push(candidate.relatedAddress); // was: relAddr
  21927. sdp.push('rport');
  21928. sdp.push(candidate.relatedPort); // was: relPort
  21929. }
  21930. if (candidate.tcpType && candidate.protocol.toLowerCase() === 'tcp') {
  21931. sdp.push('tcptype');
  21932. sdp.push(candidate.tcpType);
  21933. }
  21934. return 'candidate:' + sdp.join(' ');
  21935. };
  21936. // Parses an rtpmap line, returns RTCRtpCoddecParameters. Sample input:
  21937. // a=rtpmap:111 opus/48000/2
  21938. SDPUtils.parseRtpMap = function(line) {
  21939. var parts = line.substr(9).split(' ');
  21940. var parsed = {
  21941. payloadType: parseInt(parts.shift(), 10) // was: id
  21942. };
  21943. parts = parts[0].split('/');
  21944. parsed.name = parts[0];
  21945. parsed.clockRate = parseInt(parts[1], 10); // was: clockrate
  21946. // was: channels
  21947. parsed.numChannels = parts.length === 3 ? parseInt(parts[2], 10) : 1;
  21948. return parsed;
  21949. };
  21950. // Generate an a=rtpmap line from RTCRtpCodecCapability or
  21951. // RTCRtpCodecParameters.
  21952. SDPUtils.writeRtpMap = function(codec) {
  21953. var pt = codec.payloadType;
  21954. if (codec.preferredPayloadType !== undefined) {
  21955. pt = codec.preferredPayloadType;
  21956. }
  21957. return 'a=rtpmap:' + pt + ' ' + codec.name + '/' + codec.clockRate +
  21958. (codec.numChannels !== 1 ? '/' + codec.numChannels : '') + '\r\n';
  21959. };
  21960. // Parses an a=extmap line (headerextension from RFC 5285). Sample input:
  21961. // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  21962. SDPUtils.parseExtmap = function(line) {
  21963. var parts = line.substr(9).split(' ');
  21964. return {
  21965. id: parseInt(parts[0], 10),
  21966. uri: parts[1]
  21967. };
  21968. };
  21969. // Generates a=extmap line from RTCRtpHeaderExtensionParameters or
  21970. // RTCRtpHeaderExtension.
  21971. SDPUtils.writeExtmap = function(headerExtension) {
  21972. return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) +
  21973. ' ' + headerExtension.uri + '\r\n';
  21974. };
  21975. // Parses an ftmp line, returns dictionary. Sample input:
  21976. // a=fmtp:96 vbr=on;cng=on
  21977. // Also deals with vbr=on; cng=on
  21978. SDPUtils.parseFmtp = function(line) {
  21979. var parsed = {};
  21980. var kv;
  21981. var parts = line.substr(line.indexOf(' ') + 1).split(';');
  21982. for (var j = 0; j < parts.length; j++) {
  21983. kv = parts[j].trim().split('=');
  21984. parsed[kv[0].trim()] = kv[1];
  21985. }
  21986. return parsed;
  21987. };
  21988. // Generates an a=ftmp line from RTCRtpCodecCapability or RTCRtpCodecParameters.
  21989. SDPUtils.writeFmtp = function(codec) {
  21990. var line = '';
  21991. var pt = codec.payloadType;
  21992. if (codec.preferredPayloadType !== undefined) {
  21993. pt = codec.preferredPayloadType;
  21994. }
  21995. if (codec.parameters && Object.keys(codec.parameters).length) {
  21996. var params = [];
  21997. Object.keys(codec.parameters).forEach(function(param) {
  21998. params.push(param + '=' + codec.parameters[param]);
  21999. });
  22000. line += 'a=fmtp:' + pt + ' ' + params.join(';') + '\r\n';
  22001. }
  22002. return line;
  22003. };
  22004. // Parses an rtcp-fb line, returns RTCPRtcpFeedback object. Sample input:
  22005. // a=rtcp-fb:98 nack rpsi
  22006. SDPUtils.parseRtcpFb = function(line) {
  22007. var parts = line.substr(line.indexOf(' ') + 1).split(' ');
  22008. return {
  22009. type: parts.shift(),
  22010. parameter: parts.join(' ')
  22011. };
  22012. };
  22013. // Generate a=rtcp-fb lines from RTCRtpCodecCapability or RTCRtpCodecParameters.
  22014. SDPUtils.writeRtcpFb = function(codec) {
  22015. var lines = '';
  22016. var pt = codec.payloadType;
  22017. if (codec.preferredPayloadType !== undefined) {
  22018. pt = codec.preferredPayloadType;
  22019. }
  22020. if (codec.rtcpFeedback && codec.rtcpFeedback.length) {
  22021. // FIXME: special handling for trr-int?
  22022. codec.rtcpFeedback.forEach(function(fb) {
  22023. lines += 'a=rtcp-fb:' + pt + ' ' + fb.type +
  22024. (fb.parameter && fb.parameter.length ? ' ' + fb.parameter : '') +
  22025. '\r\n';
  22026. });
  22027. }
  22028. return lines;
  22029. };
  22030. // Parses an RFC 5576 ssrc media attribute. Sample input:
  22031. // a=ssrc:3735928559 cname:something
  22032. SDPUtils.parseSsrcMedia = function(line) {
  22033. var sp = line.indexOf(' ');
  22034. var parts = {
  22035. ssrc: parseInt(line.substr(7, sp - 7), 10)
  22036. };
  22037. var colon = line.indexOf(':', sp);
  22038. if (colon > -1) {
  22039. parts.attribute = line.substr(sp + 1, colon - sp - 1);
  22040. parts.value = line.substr(colon + 1);
  22041. } else {
  22042. parts.attribute = line.substr(sp + 1);
  22043. }
  22044. return parts;
  22045. };
  22046. // Extracts DTLS parameters from SDP media section or sessionpart.
  22047. // FIXME: for consistency with other functions this should only
  22048. // get the fingerprint line as input. See also getIceParameters.
  22049. SDPUtils.getDtlsParameters = function(mediaSection, sessionpart) {
  22050. var lines = SDPUtils.splitLines(mediaSection);
  22051. // Search in session part, too.
  22052. lines = lines.concat(SDPUtils.splitLines(sessionpart));
  22053. var fpLine = lines.filter(function(line) {
  22054. return line.indexOf('a=fingerprint:') === 0;
  22055. })[0].substr(14);
  22056. // Note: a=setup line is ignored since we use the 'auto' role.
  22057. var dtlsParameters = {
  22058. role: 'auto',
  22059. fingerprints: [{
  22060. algorithm: fpLine.split(' ')[0],
  22061. value: fpLine.split(' ')[1]
  22062. }]
  22063. };
  22064. return dtlsParameters;
  22065. };
  22066. // Serializes DTLS parameters to SDP.
  22067. SDPUtils.writeDtlsParameters = function(params, setupType) {
  22068. var sdp = 'a=setup:' + setupType + '\r\n';
  22069. params.fingerprints.forEach(function(fp) {
  22070. sdp += 'a=fingerprint:' + fp.algorithm + ' ' + fp.value + '\r\n';
  22071. });
  22072. return sdp;
  22073. };
  22074. // Parses ICE information from SDP media section or sessionpart.
  22075. // FIXME: for consistency with other functions this should only
  22076. // get the ice-ufrag and ice-pwd lines as input.
  22077. SDPUtils.getIceParameters = function(mediaSection, sessionpart) {
  22078. var lines = SDPUtils.splitLines(mediaSection);
  22079. // Search in session part, too.
  22080. lines = lines.concat(SDPUtils.splitLines(sessionpart));
  22081. var iceParameters = {
  22082. usernameFragment: lines.filter(function(line) {
  22083. return line.indexOf('a=ice-ufrag:') === 0;
  22084. })[0].substr(12),
  22085. password: lines.filter(function(line) {
  22086. return line.indexOf('a=ice-pwd:') === 0;
  22087. })[0].substr(10)
  22088. };
  22089. return iceParameters;
  22090. };
  22091. // Serializes ICE parameters to SDP.
  22092. SDPUtils.writeIceParameters = function(params) {
  22093. return 'a=ice-ufrag:' + params.usernameFragment + '\r\n' +
  22094. 'a=ice-pwd:' + params.password + '\r\n';
  22095. };
  22096. // Parses the SDP media section and returns RTCRtpParameters.
  22097. SDPUtils.parseRtpParameters = function(mediaSection) {
  22098. var description = {
  22099. codecs: [],
  22100. headerExtensions: [],
  22101. fecMechanisms: [],
  22102. rtcp: []
  22103. };
  22104. var lines = SDPUtils.splitLines(mediaSection);
  22105. var mline = lines[0].split(' ');
  22106. for (var i = 3; i < mline.length; i++) { // find all codecs from mline[3..]
  22107. var pt = mline[i];
  22108. var rtpmapline = SDPUtils.matchPrefix(
  22109. mediaSection, 'a=rtpmap:' + pt + ' ')[0];
  22110. if (rtpmapline) {
  22111. var codec = SDPUtils.parseRtpMap(rtpmapline);
  22112. var fmtps = SDPUtils.matchPrefix(
  22113. mediaSection, 'a=fmtp:' + pt + ' ');
  22114. // Only the first a=fmtp:<pt> is considered.
  22115. codec.parameters = fmtps.length ? SDPUtils.parseFmtp(fmtps[0]) : {};
  22116. codec.rtcpFeedback = SDPUtils.matchPrefix(
  22117. mediaSection, 'a=rtcp-fb:' + pt + ' ')
  22118. .map(SDPUtils.parseRtcpFb);
  22119. description.codecs.push(codec);
  22120. // parse FEC mechanisms from rtpmap lines.
  22121. switch (codec.name.toUpperCase()) {
  22122. case 'RED':
  22123. case 'ULPFEC':
  22124. description.fecMechanisms.push(codec.name.toUpperCase());
  22125. break;
  22126. default: // only RED and ULPFEC are recognized as FEC mechanisms.
  22127. break;
  22128. }
  22129. }
  22130. }
  22131. SDPUtils.matchPrefix(mediaSection, 'a=extmap:').forEach(function(line) {
  22132. description.headerExtensions.push(SDPUtils.parseExtmap(line));
  22133. });
  22134. // FIXME: parse rtcp.
  22135. return description;
  22136. };
  22137. // Generates parts of the SDP media section describing the capabilities /
  22138. // parameters.
  22139. SDPUtils.writeRtpDescription = function(kind, caps) {
  22140. var sdp = '';
  22141. // Build the mline.
  22142. sdp += 'm=' + kind + ' ';
  22143. sdp += caps.codecs.length > 0 ? '9' : '0'; // reject if no codecs.
  22144. sdp += ' UDP/TLS/RTP/SAVPF ';
  22145. sdp += caps.codecs.map(function(codec) {
  22146. if (codec.preferredPayloadType !== undefined) {
  22147. return codec.preferredPayloadType;
  22148. }
  22149. return codec.payloadType;
  22150. }).join(' ') + '\r\n';
  22151. sdp += 'c=IN IP4 0.0.0.0\r\n';
  22152. sdp += 'a=rtcp:9 IN IP4 0.0.0.0\r\n';
  22153. // Add a=rtpmap lines for each codec. Also fmtp and rtcp-fb.
  22154. caps.codecs.forEach(function(codec) {
  22155. sdp += SDPUtils.writeRtpMap(codec);
  22156. sdp += SDPUtils.writeFmtp(codec);
  22157. sdp += SDPUtils.writeRtcpFb(codec);
  22158. });
  22159. sdp += 'a=rtcp-mux\r\n';
  22160. caps.headerExtensions.forEach(function(extension) {
  22161. sdp += SDPUtils.writeExtmap(extension);
  22162. });
  22163. // FIXME: write fecMechanisms.
  22164. return sdp;
  22165. };
  22166. // Parses the SDP media section and returns an array of
  22167. // RTCRtpEncodingParameters.
  22168. SDPUtils.parseRtpEncodingParameters = function(mediaSection) {
  22169. var encodingParameters = [];
  22170. var description = SDPUtils.parseRtpParameters(mediaSection);
  22171. var hasRed = description.fecMechanisms.indexOf('RED') !== -1;
  22172. var hasUlpfec = description.fecMechanisms.indexOf('ULPFEC') !== -1;
  22173. // filter a=ssrc:... cname:, ignore PlanB-msid
  22174. var ssrcs = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')
  22175. .map(function(line) {
  22176. return SDPUtils.parseSsrcMedia(line);
  22177. })
  22178. .filter(function(parts) {
  22179. return parts.attribute === 'cname';
  22180. });
  22181. var primarySsrc = ssrcs.length > 0 && ssrcs[0].ssrc;
  22182. var secondarySsrc;
  22183. var flows = SDPUtils.matchPrefix(mediaSection, 'a=ssrc-group:FID')
  22184. .map(function(line) {
  22185. var parts = line.split(' ');
  22186. parts.shift();
  22187. return parts.map(function(part) {
  22188. return parseInt(part, 10);
  22189. });
  22190. });
  22191. if (flows.length > 0 && flows[0].length > 1 && flows[0][0] === primarySsrc) {
  22192. secondarySsrc = flows[0][1];
  22193. }
  22194. description.codecs.forEach(function(codec) {
  22195. if (codec.name.toUpperCase() === 'RTX' && codec.parameters.apt) {
  22196. var encParam = {
  22197. ssrc: primarySsrc,
  22198. codecPayloadType: parseInt(codec.parameters.apt, 10),
  22199. rtx: {
  22200. payloadType: codec.payloadType,
  22201. ssrc: secondarySsrc
  22202. }
  22203. };
  22204. encodingParameters.push(encParam);
  22205. if (hasRed) {
  22206. encParam = JSON.parse(JSON.stringify(encParam));
  22207. encParam.fec = {
  22208. ssrc: secondarySsrc,
  22209. mechanism: hasUlpfec ? 'red+ulpfec' : 'red'
  22210. };
  22211. encodingParameters.push(encParam);
  22212. }
  22213. }
  22214. });
  22215. if (encodingParameters.length === 0 && primarySsrc) {
  22216. encodingParameters.push({
  22217. ssrc: primarySsrc
  22218. });
  22219. }
  22220. // we support both b=AS and b=TIAS but interpret AS as TIAS.
  22221. var bandwidth = SDPUtils.matchPrefix(mediaSection, 'b=');
  22222. if (bandwidth.length) {
  22223. if (bandwidth[0].indexOf('b=TIAS:') === 0) {
  22224. bandwidth = parseInt(bandwidth[0].substr(7), 10);
  22225. } else if (bandwidth[0].indexOf('b=AS:') === 0) {
  22226. bandwidth = parseInt(bandwidth[0].substr(5), 10);
  22227. }
  22228. encodingParameters.forEach(function(params) {
  22229. params.maxBitrate = bandwidth;
  22230. });
  22231. }
  22232. return encodingParameters;
  22233. };
  22234. SDPUtils.writeSessionBoilerplate = function() {
  22235. // FIXME: sess-id should be an NTP timestamp.
  22236. return 'v=0\r\n' +
  22237. 'o=thisisadapterortc 8169639915646943137 2 IN IP4 127.0.0.1\r\n' +
  22238. 's=-\r\n' +
  22239. 't=0 0\r\n';
  22240. };
  22241. SDPUtils.writeMediaSection = function(transceiver, caps, type, stream) {
  22242. var sdp = SDPUtils.writeRtpDescription(transceiver.kind, caps);
  22243. // Map ICE parameters (ufrag, pwd) to SDP.
  22244. sdp += SDPUtils.writeIceParameters(
  22245. transceiver.iceGatherer.getLocalParameters());
  22246. // Map DTLS parameters to SDP.
  22247. sdp += SDPUtils.writeDtlsParameters(
  22248. transceiver.dtlsTransport.getLocalParameters(),
  22249. type === 'offer' ? 'actpass' : 'active');
  22250. sdp += 'a=mid:' + transceiver.mid + '\r\n';
  22251. if (transceiver.rtpSender && transceiver.rtpReceiver) {
  22252. sdp += 'a=sendrecv\r\n';
  22253. } else if (transceiver.rtpSender) {
  22254. sdp += 'a=sendonly\r\n';
  22255. } else if (transceiver.rtpReceiver) {
  22256. sdp += 'a=recvonly\r\n';
  22257. } else {
  22258. sdp += 'a=inactive\r\n';
  22259. }
  22260. // FIXME: for RTX there might be multiple SSRCs. Not implemented in Edge yet.
  22261. if (transceiver.rtpSender) {
  22262. var msid = 'msid:' + stream.id + ' ' +
  22263. transceiver.rtpSender.track.id + '\r\n';
  22264. sdp += 'a=' + msid;
  22265. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +
  22266. ' ' + msid;
  22267. }
  22268. // FIXME: this should be written by writeRtpDescription.
  22269. sdp += 'a=ssrc:' + transceiver.sendEncodingParameters[0].ssrc +
  22270. ' cname:' + SDPUtils.localCName + '\r\n';
  22271. return sdp;
  22272. };
  22273. // Gets the direction from the mediaSection or the sessionpart.
  22274. SDPUtils.getDirection = function(mediaSection, sessionpart) {
  22275. // Look for sendrecv, sendonly, recvonly, inactive, default to sendrecv.
  22276. var lines = SDPUtils.splitLines(mediaSection);
  22277. for (var i = 0; i < lines.length; i++) {
  22278. switch (lines[i]) {
  22279. case 'a=sendrecv':
  22280. case 'a=sendonly':
  22281. case 'a=recvonly':
  22282. case 'a=inactive':
  22283. return lines[i].substr(2);
  22284. default:
  22285. // FIXME: What should happen here?
  22286. }
  22287. }
  22288. if (sessionpart) {
  22289. return SDPUtils.getDirection(sessionpart);
  22290. }
  22291. return 'sendrecv';
  22292. };
  22293. // Expose public methods.
  22294. module.exports = SDPUtils;
  22295. },{}],42:[function(require,module,exports){
  22296. /*
  22297. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  22298. *
  22299. * Use of this source code is governed by a BSD-style license
  22300. * that can be found in the LICENSE file in the root of the source
  22301. * tree.
  22302. */
  22303. /* eslint-env node */
  22304. 'use strict';
  22305. // Shimming starts here.
  22306. (function() {
  22307. // Utils.
  22308. var logging = require('./utils').log;
  22309. var browserDetails = require('./utils').browserDetails;
  22310. // Export to the adapter global object visible in the browser.
  22311. module.exports.browserDetails = browserDetails;
  22312. module.exports.extractVersion = require('./utils').extractVersion;
  22313. module.exports.disableLog = require('./utils').disableLog;
  22314. // Uncomment the line below if you want logging to occur, including logging
  22315. // for the switch statement below. Can also be turned on in the browser via
  22316. // adapter.disableLog(false), but then logging from the switch statement below
  22317. // will not appear.
  22318. // require('./utils').disableLog(false);
  22319. // Browser shims.
  22320. var chromeShim = require('./chrome/chrome_shim') || null;
  22321. var edgeShim = require('./edge/edge_shim') || null;
  22322. var firefoxShim = require('./firefox/firefox_shim') || null;
  22323. var safariShim = require('./safari/safari_shim') || null;
  22324. // Shim browser if found.
  22325. switch (browserDetails.browser) {
  22326. case 'opera': // fallthrough as it uses chrome shims
  22327. case 'chrome':
  22328. if (!chromeShim || !chromeShim.shimPeerConnection) {
  22329. logging('Chrome shim is not included in this adapter release.');
  22330. return;
  22331. }
  22332. logging('adapter.js shimming chrome.');
  22333. // Export to the adapter global object visible in the browser.
  22334. module.exports.browserShim = chromeShim;
  22335. chromeShim.shimGetUserMedia();
  22336. chromeShim.shimMediaStream();
  22337. chromeShim.shimSourceObject();
  22338. chromeShim.shimPeerConnection();
  22339. chromeShim.shimOnTrack();
  22340. break;
  22341. case 'firefox':
  22342. if (!firefoxShim || !firefoxShim.shimPeerConnection) {
  22343. logging('Firefox shim is not included in this adapter release.');
  22344. return;
  22345. }
  22346. logging('adapter.js shimming firefox.');
  22347. // Export to the adapter global object visible in the browser.
  22348. module.exports.browserShim = firefoxShim;
  22349. firefoxShim.shimGetUserMedia();
  22350. firefoxShim.shimSourceObject();
  22351. firefoxShim.shimPeerConnection();
  22352. firefoxShim.shimOnTrack();
  22353. break;
  22354. case 'edge':
  22355. if (!edgeShim || !edgeShim.shimPeerConnection) {
  22356. logging('MS edge shim is not included in this adapter release.');
  22357. return;
  22358. }
  22359. logging('adapter.js shimming edge.');
  22360. // Export to the adapter global object visible in the browser.
  22361. module.exports.browserShim = edgeShim;
  22362. edgeShim.shimGetUserMedia();
  22363. edgeShim.shimPeerConnection();
  22364. break;
  22365. case 'safari':
  22366. if (!safariShim) {
  22367. logging('Safari shim is not included in this adapter release.');
  22368. return;
  22369. }
  22370. logging('adapter.js shimming safari.');
  22371. // Export to the adapter global object visible in the browser.
  22372. module.exports.browserShim = safariShim;
  22373. safariShim.shimGetUserMedia();
  22374. break;
  22375. default:
  22376. logging('Unsupported browser!');
  22377. }
  22378. })();
  22379. },{"./chrome/chrome_shim":43,"./edge/edge_shim":45,"./firefox/firefox_shim":47,"./safari/safari_shim":49,"./utils":50}],43:[function(require,module,exports){
  22380. /*
  22381. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  22382. *
  22383. * Use of this source code is governed by a BSD-style license
  22384. * that can be found in the LICENSE file in the root of the source
  22385. * tree.
  22386. */
  22387. /* eslint-env node */
  22388. 'use strict';
  22389. var logging = require('../utils.js').log;
  22390. var browserDetails = require('../utils.js').browserDetails;
  22391. var chromeShim = {
  22392. shimMediaStream: function() {
  22393. window.MediaStream = window.MediaStream || window.webkitMediaStream;
  22394. },
  22395. shimOnTrack: function() {
  22396. if (typeof window === 'object' && window.RTCPeerConnection && !('ontrack' in
  22397. window.RTCPeerConnection.prototype)) {
  22398. Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {
  22399. get: function() {
  22400. return this._ontrack;
  22401. },
  22402. set: function(f) {
  22403. var self = this;
  22404. if (this._ontrack) {
  22405. this.removeEventListener('track', this._ontrack);
  22406. this.removeEventListener('addstream', this._ontrackpoly);
  22407. }
  22408. this.addEventListener('track', this._ontrack = f);
  22409. this.addEventListener('addstream', this._ontrackpoly = function(e) {
  22410. // onaddstream does not fire when a track is added to an existing
  22411. // stream. But stream.onaddtrack is implemented so we use that.
  22412. e.stream.addEventListener('addtrack', function(te) {
  22413. var event = new Event('track');
  22414. event.track = te.track;
  22415. event.receiver = {track: te.track};
  22416. event.streams = [e.stream];
  22417. self.dispatchEvent(event);
  22418. });
  22419. e.stream.getTracks().forEach(function(track) {
  22420. var event = new Event('track');
  22421. event.track = track;
  22422. event.receiver = {track: track};
  22423. event.streams = [e.stream];
  22424. this.dispatchEvent(event);
  22425. }.bind(this));
  22426. }.bind(this));
  22427. }
  22428. });
  22429. }
  22430. },
  22431. shimSourceObject: function() {
  22432. if (typeof window === 'object') {
  22433. if (window.HTMLMediaElement &&
  22434. !('srcObject' in window.HTMLMediaElement.prototype)) {
  22435. // Shim the srcObject property, once, when HTMLMediaElement is found.
  22436. Object.defineProperty(window.HTMLMediaElement.prototype, 'srcObject', {
  22437. get: function() {
  22438. return this._srcObject;
  22439. },
  22440. set: function(stream) {
  22441. var self = this;
  22442. // Use _srcObject as a private property for this shim
  22443. this._srcObject = stream;
  22444. if (this.src) {
  22445. URL.revokeObjectURL(this.src);
  22446. }
  22447. if (!stream) {
  22448. this.src = '';
  22449. return;
  22450. }
  22451. this.src = URL.createObjectURL(stream);
  22452. // We need to recreate the blob url when a track is added or
  22453. // removed. Doing it manually since we want to avoid a recursion.
  22454. stream.addEventListener('addtrack', function() {
  22455. if (self.src) {
  22456. URL.revokeObjectURL(self.src);
  22457. }
  22458. self.src = URL.createObjectURL(stream);
  22459. });
  22460. stream.addEventListener('removetrack', function() {
  22461. if (self.src) {
  22462. URL.revokeObjectURL(self.src);
  22463. }
  22464. self.src = URL.createObjectURL(stream);
  22465. });
  22466. }
  22467. });
  22468. }
  22469. }
  22470. },
  22471. shimPeerConnection: function() {
  22472. // The RTCPeerConnection object.
  22473. window.RTCPeerConnection = function(pcConfig, pcConstraints) {
  22474. // Translate iceTransportPolicy to iceTransports,
  22475. // see https://code.google.com/p/webrtc/issues/detail?id=4869
  22476. logging('PeerConnection');
  22477. if (pcConfig && pcConfig.iceTransportPolicy) {
  22478. pcConfig.iceTransports = pcConfig.iceTransportPolicy;
  22479. }
  22480. var pc = new webkitRTCPeerConnection(pcConfig, pcConstraints);
  22481. var origGetStats = pc.getStats.bind(pc);
  22482. pc.getStats = function(selector, successCallback, errorCallback) {
  22483. var self = this;
  22484. var args = arguments;
  22485. // If selector is a function then we are in the old style stats so just
  22486. // pass back the original getStats format to avoid breaking old users.
  22487. if (arguments.length > 0 && typeof selector === 'function') {
  22488. return origGetStats(selector, successCallback);
  22489. }
  22490. var fixChromeStats_ = function(response) {
  22491. var standardReport = {};
  22492. var reports = response.result();
  22493. reports.forEach(function(report) {
  22494. var standardStats = {
  22495. id: report.id,
  22496. timestamp: report.timestamp,
  22497. type: report.type
  22498. };
  22499. report.names().forEach(function(name) {
  22500. standardStats[name] = report.stat(name);
  22501. });
  22502. standardReport[standardStats.id] = standardStats;
  22503. });
  22504. return standardReport;
  22505. };
  22506. // shim getStats with maplike support
  22507. var makeMapStats = function(stats, legacyStats) {
  22508. var map = new Map(Object.keys(stats).map(function(key) {
  22509. return[key, stats[key]];
  22510. }));
  22511. legacyStats = legacyStats || stats;
  22512. Object.keys(legacyStats).forEach(function(key) {
  22513. map[key] = legacyStats[key];
  22514. });
  22515. return map;
  22516. };
  22517. if (arguments.length >= 2) {
  22518. var successCallbackWrapper_ = function(response) {
  22519. args[1](makeMapStats(fixChromeStats_(response)));
  22520. };
  22521. return origGetStats.apply(this, [successCallbackWrapper_,
  22522. arguments[0]]);
  22523. }
  22524. // promise-support
  22525. return new Promise(function(resolve, reject) {
  22526. if (args.length === 1 && typeof selector === 'object') {
  22527. origGetStats.apply(self, [
  22528. function(response) {
  22529. resolve(makeMapStats(fixChromeStats_(response)));
  22530. }, reject]);
  22531. } else {
  22532. // Preserve legacy chrome stats only on legacy access of stats obj
  22533. origGetStats.apply(self, [
  22534. function(response) {
  22535. resolve(makeMapStats(fixChromeStats_(response),
  22536. response.result()));
  22537. }, reject]);
  22538. }
  22539. }).then(successCallback, errorCallback);
  22540. };
  22541. return pc;
  22542. };
  22543. window.RTCPeerConnection.prototype = webkitRTCPeerConnection.prototype;
  22544. // wrap static methods. Currently just generateCertificate.
  22545. if (webkitRTCPeerConnection.generateCertificate) {
  22546. Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
  22547. get: function() {
  22548. return webkitRTCPeerConnection.generateCertificate;
  22549. }
  22550. });
  22551. }
  22552. ['createOffer', 'createAnswer'].forEach(function(method) {
  22553. var nativeMethod = webkitRTCPeerConnection.prototype[method];
  22554. webkitRTCPeerConnection.prototype[method] = function() {
  22555. var self = this;
  22556. if (arguments.length < 1 || (arguments.length === 1 &&
  22557. typeof arguments[0] === 'object')) {
  22558. var opts = arguments.length === 1 ? arguments[0] : undefined;
  22559. return new Promise(function(resolve, reject) {
  22560. nativeMethod.apply(self, [resolve, reject, opts]);
  22561. });
  22562. }
  22563. return nativeMethod.apply(this, arguments);
  22564. };
  22565. });
  22566. // add promise support -- natively available in Chrome 51
  22567. if (browserDetails.version < 51) {
  22568. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']
  22569. .forEach(function(method) {
  22570. var nativeMethod = webkitRTCPeerConnection.prototype[method];
  22571. webkitRTCPeerConnection.prototype[method] = function() {
  22572. var args = arguments;
  22573. var self = this;
  22574. var promise = new Promise(function(resolve, reject) {
  22575. nativeMethod.apply(self, [args[0], resolve, reject]);
  22576. });
  22577. if (args.length < 2) {
  22578. return promise;
  22579. }
  22580. return promise.then(function() {
  22581. args[1].apply(null, []);
  22582. },
  22583. function(err) {
  22584. if (args.length >= 3) {
  22585. args[2].apply(null, [err]);
  22586. }
  22587. });
  22588. };
  22589. });
  22590. }
  22591. // shim implicit creation of RTCSessionDescription/RTCIceCandidate
  22592. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']
  22593. .forEach(function(method) {
  22594. var nativeMethod = webkitRTCPeerConnection.prototype[method];
  22595. webkitRTCPeerConnection.prototype[method] = function() {
  22596. arguments[0] = new ((method === 'addIceCandidate') ?
  22597. RTCIceCandidate : RTCSessionDescription)(arguments[0]);
  22598. return nativeMethod.apply(this, arguments);
  22599. };
  22600. });
  22601. // support for addIceCandidate(null or undefined)
  22602. var nativeAddIceCandidate =
  22603. RTCPeerConnection.prototype.addIceCandidate;
  22604. RTCPeerConnection.prototype.addIceCandidate = function() {
  22605. if (!arguments[0]) {
  22606. if (arguments[1]) {
  22607. arguments[1].apply(null);
  22608. }
  22609. return Promise.resolve();
  22610. }
  22611. return nativeAddIceCandidate.apply(this, arguments);
  22612. };
  22613. }
  22614. };
  22615. // Expose public methods.
  22616. module.exports = {
  22617. shimMediaStream: chromeShim.shimMediaStream,
  22618. shimOnTrack: chromeShim.shimOnTrack,
  22619. shimSourceObject: chromeShim.shimSourceObject,
  22620. shimPeerConnection: chromeShim.shimPeerConnection,
  22621. shimGetUserMedia: require('./getusermedia')
  22622. };
  22623. },{"../utils.js":50,"./getusermedia":44}],44:[function(require,module,exports){
  22624. /*
  22625. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  22626. *
  22627. * Use of this source code is governed by a BSD-style license
  22628. * that can be found in the LICENSE file in the root of the source
  22629. * tree.
  22630. */
  22631. /* eslint-env node */
  22632. 'use strict';
  22633. var logging = require('../utils.js').log;
  22634. // Expose public methods.
  22635. module.exports = function() {
  22636. var constraintsToChrome_ = function(c) {
  22637. if (typeof c !== 'object' || c.mandatory || c.optional) {
  22638. return c;
  22639. }
  22640. var cc = {};
  22641. Object.keys(c).forEach(function(key) {
  22642. if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
  22643. return;
  22644. }
  22645. var r = (typeof c[key] === 'object') ? c[key] : {ideal: c[key]};
  22646. if (r.exact !== undefined && typeof r.exact === 'number') {
  22647. r.min = r.max = r.exact;
  22648. }
  22649. var oldname_ = function(prefix, name) {
  22650. if (prefix) {
  22651. return prefix + name.charAt(0).toUpperCase() + name.slice(1);
  22652. }
  22653. return (name === 'deviceId') ? 'sourceId' : name;
  22654. };
  22655. if (r.ideal !== undefined) {
  22656. cc.optional = cc.optional || [];
  22657. var oc = {};
  22658. if (typeof r.ideal === 'number') {
  22659. oc[oldname_('min', key)] = r.ideal;
  22660. cc.optional.push(oc);
  22661. oc = {};
  22662. oc[oldname_('max', key)] = r.ideal;
  22663. cc.optional.push(oc);
  22664. } else {
  22665. oc[oldname_('', key)] = r.ideal;
  22666. cc.optional.push(oc);
  22667. }
  22668. }
  22669. if (r.exact !== undefined && typeof r.exact !== 'number') {
  22670. cc.mandatory = cc.mandatory || {};
  22671. cc.mandatory[oldname_('', key)] = r.exact;
  22672. } else {
  22673. ['min', 'max'].forEach(function(mix) {
  22674. if (r[mix] !== undefined) {
  22675. cc.mandatory = cc.mandatory || {};
  22676. cc.mandatory[oldname_(mix, key)] = r[mix];
  22677. }
  22678. });
  22679. }
  22680. });
  22681. if (c.advanced) {
  22682. cc.optional = (cc.optional || []).concat(c.advanced);
  22683. }
  22684. return cc;
  22685. };
  22686. var shimConstraints_ = function(constraints, func) {
  22687. constraints = JSON.parse(JSON.stringify(constraints));
  22688. if (constraints && constraints.audio) {
  22689. constraints.audio = constraintsToChrome_(constraints.audio);
  22690. }
  22691. if (constraints && typeof constraints.video === 'object') {
  22692. // Shim facingMode for mobile, where it defaults to "user".
  22693. var face = constraints.video.facingMode;
  22694. face = face && ((typeof face === 'object') ? face : {ideal: face});
  22695. if ((face && (face.exact === 'user' || face.exact === 'environment' ||
  22696. face.ideal === 'user' || face.ideal === 'environment')) &&
  22697. !(navigator.mediaDevices.getSupportedConstraints &&
  22698. navigator.mediaDevices.getSupportedConstraints().facingMode)) {
  22699. delete constraints.video.facingMode;
  22700. if (face.exact === 'environment' || face.ideal === 'environment') {
  22701. // Look for "back" in label, or use last cam (typically back cam).
  22702. return navigator.mediaDevices.enumerateDevices()
  22703. .then(function(devices) {
  22704. devices = devices.filter(function(d) {
  22705. return d.kind === 'videoinput';
  22706. });
  22707. var back = devices.find(function(d) {
  22708. return d.label.toLowerCase().indexOf('back') !== -1;
  22709. }) || (devices.length && devices[devices.length - 1]);
  22710. if (back) {
  22711. constraints.video.deviceId = face.exact ? {exact: back.deviceId} :
  22712. {ideal: back.deviceId};
  22713. }
  22714. constraints.video = constraintsToChrome_(constraints.video);
  22715. logging('chrome: ' + JSON.stringify(constraints));
  22716. return func(constraints);
  22717. });
  22718. }
  22719. }
  22720. constraints.video = constraintsToChrome_(constraints.video);
  22721. }
  22722. logging('chrome: ' + JSON.stringify(constraints));
  22723. return func(constraints);
  22724. };
  22725. var shimError_ = function(e) {
  22726. return {
  22727. name: {
  22728. PermissionDeniedError: 'NotAllowedError',
  22729. ConstraintNotSatisfiedError: 'OverconstrainedError'
  22730. }[e.name] || e.name,
  22731. message: e.message,
  22732. constraint: e.constraintName,
  22733. toString: function() {
  22734. return this.name + (this.message && ': ') + this.message;
  22735. }
  22736. };
  22737. };
  22738. var getUserMedia_ = function(constraints, onSuccess, onError) {
  22739. shimConstraints_(constraints, function(c) {
  22740. navigator.webkitGetUserMedia(c, onSuccess, function(e) {
  22741. onError(shimError_(e));
  22742. });
  22743. });
  22744. };
  22745. navigator.getUserMedia = getUserMedia_;
  22746. // Returns the result of getUserMedia as a Promise.
  22747. var getUserMediaPromise_ = function(constraints) {
  22748. return new Promise(function(resolve, reject) {
  22749. navigator.getUserMedia(constraints, resolve, reject);
  22750. });
  22751. };
  22752. if (!navigator.mediaDevices) {
  22753. navigator.mediaDevices = {
  22754. getUserMedia: getUserMediaPromise_,
  22755. enumerateDevices: function() {
  22756. return new Promise(function(resolve) {
  22757. var kinds = {audio: 'audioinput', video: 'videoinput'};
  22758. return MediaStreamTrack.getSources(function(devices) {
  22759. resolve(devices.map(function(device) {
  22760. return {label: device.label,
  22761. kind: kinds[device.kind],
  22762. deviceId: device.id,
  22763. groupId: ''};
  22764. }));
  22765. });
  22766. });
  22767. }
  22768. };
  22769. }
  22770. // A shim for getUserMedia method on the mediaDevices object.
  22771. // TODO(KaptenJansson) remove once implemented in Chrome stable.
  22772. if (!navigator.mediaDevices.getUserMedia) {
  22773. navigator.mediaDevices.getUserMedia = function(constraints) {
  22774. return getUserMediaPromise_(constraints);
  22775. };
  22776. } else {
  22777. // Even though Chrome 45 has navigator.mediaDevices and a getUserMedia
  22778. // function which returns a Promise, it does not accept spec-style
  22779. // constraints.
  22780. var origGetUserMedia = navigator.mediaDevices.getUserMedia.
  22781. bind(navigator.mediaDevices);
  22782. navigator.mediaDevices.getUserMedia = function(cs) {
  22783. return shimConstraints_(cs, function(c) {
  22784. return origGetUserMedia(c).then(function(stream) {
  22785. if (c.audio && !stream.getAudioTracks().length ||
  22786. c.video && !stream.getVideoTracks().length) {
  22787. stream.getTracks().forEach(function(track) {
  22788. track.stop();
  22789. });
  22790. throw new DOMException('', 'NotFoundError');
  22791. }
  22792. return stream;
  22793. }, function(e) {
  22794. return Promise.reject(shimError_(e));
  22795. });
  22796. });
  22797. };
  22798. }
  22799. // Dummy devicechange event methods.
  22800. // TODO(KaptenJansson) remove once implemented in Chrome stable.
  22801. if (typeof navigator.mediaDevices.addEventListener === 'undefined') {
  22802. navigator.mediaDevices.addEventListener = function() {
  22803. logging('Dummy mediaDevices.addEventListener called.');
  22804. };
  22805. }
  22806. if (typeof navigator.mediaDevices.removeEventListener === 'undefined') {
  22807. navigator.mediaDevices.removeEventListener = function() {
  22808. logging('Dummy mediaDevices.removeEventListener called.');
  22809. };
  22810. }
  22811. };
  22812. },{"../utils.js":50}],45:[function(require,module,exports){
  22813. /*
  22814. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  22815. *
  22816. * Use of this source code is governed by a BSD-style license
  22817. * that can be found in the LICENSE file in the root of the source
  22818. * tree.
  22819. */
  22820. /* eslint-env node */
  22821. 'use strict';
  22822. var SDPUtils = require('sdp');
  22823. var browserDetails = require('../utils').browserDetails;
  22824. var edgeShim = {
  22825. shimPeerConnection: function() {
  22826. if (window.RTCIceGatherer) {
  22827. // ORTC defines an RTCIceCandidate object but no constructor.
  22828. // Not implemented in Edge.
  22829. if (!window.RTCIceCandidate) {
  22830. window.RTCIceCandidate = function(args) {
  22831. return args;
  22832. };
  22833. }
  22834. // ORTC does not have a session description object but
  22835. // other browsers (i.e. Chrome) that will support both PC and ORTC
  22836. // in the future might have this defined already.
  22837. if (!window.RTCSessionDescription) {
  22838. window.RTCSessionDescription = function(args) {
  22839. return args;
  22840. };
  22841. }
  22842. // this adds an additional event listener to MediaStrackTrack that signals
  22843. // when a tracks enabled property was changed.
  22844. var origMSTEnabled = Object.getOwnPropertyDescriptor(
  22845. MediaStreamTrack.prototype, 'enabled');
  22846. Object.defineProperty(MediaStreamTrack.prototype, 'enabled', {
  22847. set: function(value) {
  22848. origMSTEnabled.set.call(this, value);
  22849. var ev = new Event('enabled');
  22850. ev.enabled = value;
  22851. this.dispatchEvent(ev);
  22852. }
  22853. });
  22854. }
  22855. window.RTCPeerConnection = function(config) {
  22856. var self = this;
  22857. var _eventTarget = document.createDocumentFragment();
  22858. ['addEventListener', 'removeEventListener', 'dispatchEvent']
  22859. .forEach(function(method) {
  22860. self[method] = _eventTarget[method].bind(_eventTarget);
  22861. });
  22862. this.onicecandidate = null;
  22863. this.onaddstream = null;
  22864. this.ontrack = null;
  22865. this.onremovestream = null;
  22866. this.onsignalingstatechange = null;
  22867. this.oniceconnectionstatechange = null;
  22868. this.onnegotiationneeded = null;
  22869. this.ondatachannel = null;
  22870. this.localStreams = [];
  22871. this.remoteStreams = [];
  22872. this.getLocalStreams = function() {
  22873. return self.localStreams;
  22874. };
  22875. this.getRemoteStreams = function() {
  22876. return self.remoteStreams;
  22877. };
  22878. this.localDescription = new RTCSessionDescription({
  22879. type: '',
  22880. sdp: ''
  22881. });
  22882. this.remoteDescription = new RTCSessionDescription({
  22883. type: '',
  22884. sdp: ''
  22885. });
  22886. this.signalingState = 'stable';
  22887. this.iceConnectionState = 'new';
  22888. this.iceGatheringState = 'new';
  22889. this.iceOptions = {
  22890. gatherPolicy: 'all',
  22891. iceServers: []
  22892. };
  22893. if (config && config.iceTransportPolicy) {
  22894. switch (config.iceTransportPolicy) {
  22895. case 'all':
  22896. case 'relay':
  22897. this.iceOptions.gatherPolicy = config.iceTransportPolicy;
  22898. break;
  22899. case 'none':
  22900. // FIXME: remove once implementation and spec have added this.
  22901. throw new TypeError('iceTransportPolicy "none" not supported');
  22902. default:
  22903. // don't set iceTransportPolicy.
  22904. break;
  22905. }
  22906. }
  22907. this.usingBundle = config && config.bundlePolicy === 'max-bundle';
  22908. if (config && config.iceServers) {
  22909. // Edge does not like
  22910. // 1) stun:
  22911. // 2) turn: that does not have all of turn:host:port?transport=udp
  22912. // 3) turn: with ipv6 addresses
  22913. var iceServers = JSON.parse(JSON.stringify(config.iceServers));
  22914. this.iceOptions.iceServers = iceServers.filter(function(server) {
  22915. if (server && server.urls) {
  22916. var urls = server.urls;
  22917. if (typeof urls === 'string') {
  22918. urls = [urls];
  22919. }
  22920. urls = urls.filter(function(url) {
  22921. return (url.indexOf('turn:') === 0 &&
  22922. url.indexOf('transport=udp') !== -1 &&
  22923. url.indexOf('turn:[') === -1) ||
  22924. (url.indexOf('stun:') === 0 &&
  22925. browserDetails.version >= 14393);
  22926. })[0];
  22927. return !!urls;
  22928. }
  22929. return false;
  22930. });
  22931. }
  22932. this._config = config;
  22933. // per-track iceGathers, iceTransports, dtlsTransports, rtpSenders, ...
  22934. // everything that is needed to describe a SDP m-line.
  22935. this.transceivers = [];
  22936. // since the iceGatherer is currently created in createOffer but we
  22937. // must not emit candidates until after setLocalDescription we buffer
  22938. // them in this array.
  22939. this._localIceCandidatesBuffer = [];
  22940. };
  22941. window.RTCPeerConnection.prototype._emitBufferedCandidates = function() {
  22942. var self = this;
  22943. var sections = SDPUtils.splitSections(self.localDescription.sdp);
  22944. // FIXME: need to apply ice candidates in a way which is async but
  22945. // in-order
  22946. this._localIceCandidatesBuffer.forEach(function(event) {
  22947. var end = !event.candidate || Object.keys(event.candidate).length === 0;
  22948. if (end) {
  22949. for (var j = 1; j < sections.length; j++) {
  22950. if (sections[j].indexOf('\r\na=end-of-candidates\r\n') === -1) {
  22951. sections[j] += 'a=end-of-candidates\r\n';
  22952. }
  22953. }
  22954. } else if (event.candidate.candidate.indexOf('typ endOfCandidates')
  22955. === -1) {
  22956. sections[event.candidate.sdpMLineIndex + 1] +=
  22957. 'a=' + event.candidate.candidate + '\r\n';
  22958. }
  22959. self.localDescription.sdp = sections.join('');
  22960. self.dispatchEvent(event);
  22961. if (self.onicecandidate !== null) {
  22962. self.onicecandidate(event);
  22963. }
  22964. if (!event.candidate && self.iceGatheringState !== 'complete') {
  22965. var complete = self.transceivers.every(function(transceiver) {
  22966. return transceiver.iceGatherer &&
  22967. transceiver.iceGatherer.state === 'completed';
  22968. });
  22969. if (complete) {
  22970. self.iceGatheringState = 'complete';
  22971. }
  22972. }
  22973. });
  22974. this._localIceCandidatesBuffer = [];
  22975. };
  22976. window.RTCPeerConnection.prototype.getConfiguration = function() {
  22977. return this._config;
  22978. };
  22979. window.RTCPeerConnection.prototype.addStream = function(stream) {
  22980. // Clone is necessary for local demos mostly, attaching directly
  22981. // to two different senders does not work (build 10547).
  22982. var clonedStream = stream.clone();
  22983. stream.getTracks().forEach(function(track, idx) {
  22984. var clonedTrack = clonedStream.getTracks()[idx];
  22985. track.addEventListener('enabled', function(event) {
  22986. clonedTrack.enabled = event.enabled;
  22987. });
  22988. });
  22989. this.localStreams.push(clonedStream);
  22990. this._maybeFireNegotiationNeeded();
  22991. };
  22992. window.RTCPeerConnection.prototype.removeStream = function(stream) {
  22993. var idx = this.localStreams.indexOf(stream);
  22994. if (idx > -1) {
  22995. this.localStreams.splice(idx, 1);
  22996. this._maybeFireNegotiationNeeded();
  22997. }
  22998. };
  22999. window.RTCPeerConnection.prototype.getSenders = function() {
  23000. return this.transceivers.filter(function(transceiver) {
  23001. return !!transceiver.rtpSender;
  23002. })
  23003. .map(function(transceiver) {
  23004. return transceiver.rtpSender;
  23005. });
  23006. };
  23007. window.RTCPeerConnection.prototype.getReceivers = function() {
  23008. return this.transceivers.filter(function(transceiver) {
  23009. return !!transceiver.rtpReceiver;
  23010. })
  23011. .map(function(transceiver) {
  23012. return transceiver.rtpReceiver;
  23013. });
  23014. };
  23015. // Determines the intersection of local and remote capabilities.
  23016. window.RTCPeerConnection.prototype._getCommonCapabilities =
  23017. function(localCapabilities, remoteCapabilities) {
  23018. var commonCapabilities = {
  23019. codecs: [],
  23020. headerExtensions: [],
  23021. fecMechanisms: []
  23022. };
  23023. localCapabilities.codecs.forEach(function(lCodec) {
  23024. for (var i = 0; i < remoteCapabilities.codecs.length; i++) {
  23025. var rCodec = remoteCapabilities.codecs[i];
  23026. if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() &&
  23027. lCodec.clockRate === rCodec.clockRate) {
  23028. // number of channels is the highest common number of channels
  23029. rCodec.numChannels = Math.min(lCodec.numChannels,
  23030. rCodec.numChannels);
  23031. // push rCodec so we reply with offerer payload type
  23032. commonCapabilities.codecs.push(rCodec);
  23033. // determine common feedback mechanisms
  23034. rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function(fb) {
  23035. for (var j = 0; j < lCodec.rtcpFeedback.length; j++) {
  23036. if (lCodec.rtcpFeedback[j].type === fb.type &&
  23037. lCodec.rtcpFeedback[j].parameter === fb.parameter) {
  23038. return true;
  23039. }
  23040. }
  23041. return false;
  23042. });
  23043. // FIXME: also need to determine .parameters
  23044. // see https://github.com/openpeer/ortc/issues/569
  23045. break;
  23046. }
  23047. }
  23048. });
  23049. localCapabilities.headerExtensions
  23050. .forEach(function(lHeaderExtension) {
  23051. for (var i = 0; i < remoteCapabilities.headerExtensions.length;
  23052. i++) {
  23053. var rHeaderExtension = remoteCapabilities.headerExtensions[i];
  23054. if (lHeaderExtension.uri === rHeaderExtension.uri) {
  23055. commonCapabilities.headerExtensions.push(rHeaderExtension);
  23056. break;
  23057. }
  23058. }
  23059. });
  23060. // FIXME: fecMechanisms
  23061. return commonCapabilities;
  23062. };
  23063. // Create ICE gatherer, ICE transport and DTLS transport.
  23064. window.RTCPeerConnection.prototype._createIceAndDtlsTransports =
  23065. function(mid, sdpMLineIndex) {
  23066. var self = this;
  23067. var iceGatherer = new RTCIceGatherer(self.iceOptions);
  23068. var iceTransport = new RTCIceTransport(iceGatherer);
  23069. iceGatherer.onlocalcandidate = function(evt) {
  23070. var event = new Event('icecandidate');
  23071. event.candidate = {sdpMid: mid, sdpMLineIndex: sdpMLineIndex};
  23072. var cand = evt.candidate;
  23073. var end = !cand || Object.keys(cand).length === 0;
  23074. // Edge emits an empty object for RTCIceCandidateComplete‥
  23075. if (end) {
  23076. // polyfill since RTCIceGatherer.state is not implemented in
  23077. // Edge 10547 yet.
  23078. if (iceGatherer.state === undefined) {
  23079. iceGatherer.state = 'completed';
  23080. }
  23081. // Emit a candidate with type endOfCandidates to make the samples
  23082. // work. Edge requires addIceCandidate with this empty candidate
  23083. // to start checking. The real solution is to signal
  23084. // end-of-candidates to the other side when getting the null
  23085. // candidate but some apps (like the samples) don't do that.
  23086. event.candidate.candidate =
  23087. 'candidate:1 1 udp 1 0.0.0.0 9 typ endOfCandidates';
  23088. } else {
  23089. // RTCIceCandidate doesn't have a component, needs to be added
  23090. cand.component = iceTransport.component === 'RTCP' ? 2 : 1;
  23091. event.candidate.candidate = SDPUtils.writeCandidate(cand);
  23092. }
  23093. // update local description.
  23094. var sections = SDPUtils.splitSections(self.localDescription.sdp);
  23095. if (event.candidate.candidate.indexOf('typ endOfCandidates')
  23096. === -1) {
  23097. sections[event.candidate.sdpMLineIndex + 1] +=
  23098. 'a=' + event.candidate.candidate + '\r\n';
  23099. } else {
  23100. sections[event.candidate.sdpMLineIndex + 1] +=
  23101. 'a=end-of-candidates\r\n';
  23102. }
  23103. self.localDescription.sdp = sections.join('');
  23104. var complete = self.transceivers.every(function(transceiver) {
  23105. return transceiver.iceGatherer &&
  23106. transceiver.iceGatherer.state === 'completed';
  23107. });
  23108. // Emit candidate if localDescription is set.
  23109. // Also emits null candidate when all gatherers are complete.
  23110. switch (self.iceGatheringState) {
  23111. case 'new':
  23112. self._localIceCandidatesBuffer.push(event);
  23113. if (end && complete) {
  23114. self._localIceCandidatesBuffer.push(
  23115. new Event('icecandidate'));
  23116. }
  23117. break;
  23118. case 'gathering':
  23119. self._emitBufferedCandidates();
  23120. self.dispatchEvent(event);
  23121. if (self.onicecandidate !== null) {
  23122. self.onicecandidate(event);
  23123. }
  23124. if (complete) {
  23125. self.dispatchEvent(new Event('icecandidate'));
  23126. if (self.onicecandidate !== null) {
  23127. self.onicecandidate(new Event('icecandidate'));
  23128. }
  23129. self.iceGatheringState = 'complete';
  23130. }
  23131. break;
  23132. case 'complete':
  23133. // should not happen... currently!
  23134. break;
  23135. default: // no-op.
  23136. break;
  23137. }
  23138. };
  23139. iceTransport.onicestatechange = function() {
  23140. self._updateConnectionState();
  23141. };
  23142. var dtlsTransport = new RTCDtlsTransport(iceTransport);
  23143. dtlsTransport.ondtlsstatechange = function() {
  23144. self._updateConnectionState();
  23145. };
  23146. dtlsTransport.onerror = function() {
  23147. // onerror does not set state to failed by itself.
  23148. dtlsTransport.state = 'failed';
  23149. self._updateConnectionState();
  23150. };
  23151. return {
  23152. iceGatherer: iceGatherer,
  23153. iceTransport: iceTransport,
  23154. dtlsTransport: dtlsTransport
  23155. };
  23156. };
  23157. // Start the RTP Sender and Receiver for a transceiver.
  23158. window.RTCPeerConnection.prototype._transceive = function(transceiver,
  23159. send, recv) {
  23160. var params = this._getCommonCapabilities(transceiver.localCapabilities,
  23161. transceiver.remoteCapabilities);
  23162. if (send && transceiver.rtpSender) {
  23163. params.encodings = transceiver.sendEncodingParameters;
  23164. params.rtcp = {
  23165. cname: SDPUtils.localCName
  23166. };
  23167. if (transceiver.recvEncodingParameters.length) {
  23168. params.rtcp.ssrc = transceiver.recvEncodingParameters[0].ssrc;
  23169. }
  23170. transceiver.rtpSender.send(params);
  23171. }
  23172. if (recv && transceiver.rtpReceiver) {
  23173. // remove RTX field in Edge 14942
  23174. if (transceiver.kind === 'video'
  23175. && transceiver.recvEncodingParameters) {
  23176. transceiver.recvEncodingParameters.forEach(function(p) {
  23177. delete p.rtx;
  23178. });
  23179. }
  23180. params.encodings = transceiver.recvEncodingParameters;
  23181. params.rtcp = {
  23182. cname: transceiver.cname
  23183. };
  23184. if (transceiver.sendEncodingParameters.length) {
  23185. params.rtcp.ssrc = transceiver.sendEncodingParameters[0].ssrc;
  23186. }
  23187. transceiver.rtpReceiver.receive(params);
  23188. }
  23189. };
  23190. window.RTCPeerConnection.prototype.setLocalDescription =
  23191. function(description) {
  23192. var self = this;
  23193. var sections;
  23194. var sessionpart;
  23195. if (description.type === 'offer') {
  23196. // FIXME: What was the purpose of this empty if statement?
  23197. // if (!this._pendingOffer) {
  23198. // } else {
  23199. if (this._pendingOffer) {
  23200. // VERY limited support for SDP munging. Limited to:
  23201. // * changing the order of codecs
  23202. sections = SDPUtils.splitSections(description.sdp);
  23203. sessionpart = sections.shift();
  23204. sections.forEach(function(mediaSection, sdpMLineIndex) {
  23205. var caps = SDPUtils.parseRtpParameters(mediaSection);
  23206. self._pendingOffer[sdpMLineIndex].localCapabilities = caps;
  23207. });
  23208. this.transceivers = this._pendingOffer;
  23209. delete this._pendingOffer;
  23210. }
  23211. } else if (description.type === 'answer') {
  23212. sections = SDPUtils.splitSections(self.remoteDescription.sdp);
  23213. sessionpart = sections.shift();
  23214. var isIceLite = SDPUtils.matchPrefix(sessionpart,
  23215. 'a=ice-lite').length > 0;
  23216. sections.forEach(function(mediaSection, sdpMLineIndex) {
  23217. var transceiver = self.transceivers[sdpMLineIndex];
  23218. var iceGatherer = transceiver.iceGatherer;
  23219. var iceTransport = transceiver.iceTransport;
  23220. var dtlsTransport = transceiver.dtlsTransport;
  23221. var localCapabilities = transceiver.localCapabilities;
  23222. var remoteCapabilities = transceiver.remoteCapabilities;
  23223. var rejected = mediaSection.split('\n', 1)[0]
  23224. .split(' ', 2)[1] === '0';
  23225. if (!rejected && !transceiver.isDatachannel) {
  23226. var remoteIceParameters = SDPUtils.getIceParameters(
  23227. mediaSection, sessionpart);
  23228. if (isIceLite) {
  23229. var cands = SDPUtils.matchPrefix(mediaSection, 'a=candidate:')
  23230. .map(function(cand) {
  23231. return SDPUtils.parseCandidate(cand);
  23232. })
  23233. .filter(function(cand) {
  23234. return cand.component === '1';
  23235. });
  23236. // ice-lite only includes host candidates in the SDP so we can
  23237. // use setRemoteCandidates (which implies an
  23238. // RTCIceCandidateComplete)
  23239. if (cands.length) {
  23240. iceTransport.setRemoteCandidates(cands);
  23241. }
  23242. }
  23243. var remoteDtlsParameters = SDPUtils.getDtlsParameters(
  23244. mediaSection, sessionpart);
  23245. if (isIceLite) {
  23246. remoteDtlsParameters.role = 'server';
  23247. }
  23248. if (!self.usingBundle || sdpMLineIndex === 0) {
  23249. iceTransport.start(iceGatherer, remoteIceParameters,
  23250. isIceLite ? 'controlling' : 'controlled');
  23251. dtlsTransport.start(remoteDtlsParameters);
  23252. }
  23253. // Calculate intersection of capabilities.
  23254. var params = self._getCommonCapabilities(localCapabilities,
  23255. remoteCapabilities);
  23256. // Start the RTCRtpSender. The RTCRtpReceiver for this
  23257. // transceiver has already been started in setRemoteDescription.
  23258. self._transceive(transceiver,
  23259. params.codecs.length > 0,
  23260. false);
  23261. }
  23262. });
  23263. }
  23264. this.localDescription = {
  23265. type: description.type,
  23266. sdp: description.sdp
  23267. };
  23268. switch (description.type) {
  23269. case 'offer':
  23270. this._updateSignalingState('have-local-offer');
  23271. break;
  23272. case 'answer':
  23273. this._updateSignalingState('stable');
  23274. break;
  23275. default:
  23276. throw new TypeError('unsupported type "' + description.type +
  23277. '"');
  23278. }
  23279. // If a success callback was provided, emit ICE candidates after it
  23280. // has been executed. Otherwise, emit callback after the Promise is
  23281. // resolved.
  23282. var hasCallback = arguments.length > 1 &&
  23283. typeof arguments[1] === 'function';
  23284. if (hasCallback) {
  23285. var cb = arguments[1];
  23286. window.setTimeout(function() {
  23287. cb();
  23288. if (self.iceGatheringState === 'new') {
  23289. self.iceGatheringState = 'gathering';
  23290. }
  23291. self._emitBufferedCandidates();
  23292. }, 0);
  23293. }
  23294. var p = Promise.resolve();
  23295. p.then(function() {
  23296. if (!hasCallback) {
  23297. if (self.iceGatheringState === 'new') {
  23298. self.iceGatheringState = 'gathering';
  23299. }
  23300. // Usually candidates will be emitted earlier.
  23301. window.setTimeout(self._emitBufferedCandidates.bind(self), 500);
  23302. }
  23303. });
  23304. return p;
  23305. };
  23306. window.RTCPeerConnection.prototype.setRemoteDescription =
  23307. function(description) {
  23308. var self = this;
  23309. var stream = new MediaStream();
  23310. var receiverList = [];
  23311. var sections = SDPUtils.splitSections(description.sdp);
  23312. var sessionpart = sections.shift();
  23313. var isIceLite = SDPUtils.matchPrefix(sessionpart,
  23314. 'a=ice-lite').length > 0;
  23315. this.usingBundle = SDPUtils.matchPrefix(sessionpart,
  23316. 'a=group:BUNDLE ').length > 0;
  23317. sections.forEach(function(mediaSection, sdpMLineIndex) {
  23318. var lines = SDPUtils.splitLines(mediaSection);
  23319. var mline = lines[0].substr(2).split(' ');
  23320. var kind = mline[0];
  23321. var rejected = mline[1] === '0';
  23322. var direction = SDPUtils.getDirection(mediaSection, sessionpart);
  23323. var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:');
  23324. if (mid.length) {
  23325. mid = mid[0].substr(6);
  23326. } else {
  23327. mid = SDPUtils.generateIdentifier();
  23328. }
  23329. // Reject datachannels which are not implemented yet.
  23330. if (kind === 'application' && mline[2] === 'DTLS/SCTP') {
  23331. self.transceivers[sdpMLineIndex] = {
  23332. mid: mid,
  23333. isDatachannel: true
  23334. };
  23335. return;
  23336. }
  23337. var transceiver;
  23338. var iceGatherer;
  23339. var iceTransport;
  23340. var dtlsTransport;
  23341. var rtpSender;
  23342. var rtpReceiver;
  23343. var sendEncodingParameters;
  23344. var recvEncodingParameters;
  23345. var localCapabilities;
  23346. var track;
  23347. // FIXME: ensure the mediaSection has rtcp-mux set.
  23348. var remoteCapabilities = SDPUtils.parseRtpParameters(mediaSection);
  23349. var remoteIceParameters;
  23350. var remoteDtlsParameters;
  23351. if (!rejected) {
  23352. remoteIceParameters = SDPUtils.getIceParameters(mediaSection,
  23353. sessionpart);
  23354. remoteDtlsParameters = SDPUtils.getDtlsParameters(mediaSection,
  23355. sessionpart);
  23356. remoteDtlsParameters.role = 'client';
  23357. }
  23358. recvEncodingParameters =
  23359. SDPUtils.parseRtpEncodingParameters(mediaSection);
  23360. var cname;
  23361. // Gets the first SSRC. Note that with RTX there might be multiple
  23362. // SSRCs.
  23363. var remoteSsrc = SDPUtils.matchPrefix(mediaSection, 'a=ssrc:')
  23364. .map(function(line) {
  23365. return SDPUtils.parseSsrcMedia(line);
  23366. })
  23367. .filter(function(obj) {
  23368. return obj.attribute === 'cname';
  23369. })[0];
  23370. if (remoteSsrc) {
  23371. cname = remoteSsrc.value;
  23372. }
  23373. var isComplete = SDPUtils.matchPrefix(mediaSection,
  23374. 'a=end-of-candidates', sessionpart).length > 0;
  23375. var cands = SDPUtils.matchPrefix(mediaSection, 'a=candidate:')
  23376. .map(function(cand) {
  23377. return SDPUtils.parseCandidate(cand);
  23378. })
  23379. .filter(function(cand) {
  23380. return cand.component === '1';
  23381. });
  23382. if (description.type === 'offer' && !rejected) {
  23383. var transports = self.usingBundle && sdpMLineIndex > 0 ? {
  23384. iceGatherer: self.transceivers[0].iceGatherer,
  23385. iceTransport: self.transceivers[0].iceTransport,
  23386. dtlsTransport: self.transceivers[0].dtlsTransport
  23387. } : self._createIceAndDtlsTransports(mid, sdpMLineIndex);
  23388. if (isComplete) {
  23389. transports.iceTransport.setRemoteCandidates(cands);
  23390. }
  23391. localCapabilities = RTCRtpReceiver.getCapabilities(kind);
  23392. // filter RTX until additional stuff needed for RTX is implemented
  23393. // in adapter.js
  23394. localCapabilities.codecs = localCapabilities.codecs.filter(
  23395. function(codec) {
  23396. return codec.name !== 'rtx';
  23397. });
  23398. sendEncodingParameters = [{
  23399. ssrc: (2 * sdpMLineIndex + 2) * 1001
  23400. }];
  23401. rtpReceiver = new RTCRtpReceiver(transports.dtlsTransport, kind);
  23402. track = rtpReceiver.track;
  23403. receiverList.push([track, rtpReceiver]);
  23404. // FIXME: not correct when there are multiple streams but that is
  23405. // not currently supported in this shim.
  23406. stream.addTrack(track);
  23407. // FIXME: look at direction.
  23408. if (self.localStreams.length > 0 &&
  23409. self.localStreams[0].getTracks().length >= sdpMLineIndex) {
  23410. var localTrack;
  23411. if (kind === 'audio') {
  23412. localTrack = self.localStreams[0].getAudioTracks()[0];
  23413. } else if (kind === 'video') {
  23414. localTrack = self.localStreams[0].getVideoTracks()[0];
  23415. }
  23416. if (localTrack) {
  23417. rtpSender = new RTCRtpSender(localTrack,
  23418. transports.dtlsTransport);
  23419. }
  23420. }
  23421. self.transceivers[sdpMLineIndex] = {
  23422. iceGatherer: transports.iceGatherer,
  23423. iceTransport: transports.iceTransport,
  23424. dtlsTransport: transports.dtlsTransport,
  23425. localCapabilities: localCapabilities,
  23426. remoteCapabilities: remoteCapabilities,
  23427. rtpSender: rtpSender,
  23428. rtpReceiver: rtpReceiver,
  23429. kind: kind,
  23430. mid: mid,
  23431. cname: cname,
  23432. sendEncodingParameters: sendEncodingParameters,
  23433. recvEncodingParameters: recvEncodingParameters
  23434. };
  23435. // Start the RTCRtpReceiver now. The RTPSender is started in
  23436. // setLocalDescription.
  23437. self._transceive(self.transceivers[sdpMLineIndex],
  23438. false,
  23439. direction === 'sendrecv' || direction === 'sendonly');
  23440. } else if (description.type === 'answer' && !rejected) {
  23441. transceiver = self.transceivers[sdpMLineIndex];
  23442. iceGatherer = transceiver.iceGatherer;
  23443. iceTransport = transceiver.iceTransport;
  23444. dtlsTransport = transceiver.dtlsTransport;
  23445. rtpSender = transceiver.rtpSender;
  23446. rtpReceiver = transceiver.rtpReceiver;
  23447. sendEncodingParameters = transceiver.sendEncodingParameters;
  23448. localCapabilities = transceiver.localCapabilities;
  23449. self.transceivers[sdpMLineIndex].recvEncodingParameters =
  23450. recvEncodingParameters;
  23451. self.transceivers[sdpMLineIndex].remoteCapabilities =
  23452. remoteCapabilities;
  23453. self.transceivers[sdpMLineIndex].cname = cname;
  23454. if ((isIceLite || isComplete) && cands.length) {
  23455. iceTransport.setRemoteCandidates(cands);
  23456. }
  23457. if (!self.usingBundle || sdpMLineIndex === 0) {
  23458. iceTransport.start(iceGatherer, remoteIceParameters,
  23459. 'controlling');
  23460. dtlsTransport.start(remoteDtlsParameters);
  23461. }
  23462. self._transceive(transceiver,
  23463. direction === 'sendrecv' || direction === 'recvonly',
  23464. direction === 'sendrecv' || direction === 'sendonly');
  23465. if (rtpReceiver &&
  23466. (direction === 'sendrecv' || direction === 'sendonly')) {
  23467. track = rtpReceiver.track;
  23468. receiverList.push([track, rtpReceiver]);
  23469. stream.addTrack(track);
  23470. } else {
  23471. // FIXME: actually the receiver should be created later.
  23472. delete transceiver.rtpReceiver;
  23473. }
  23474. }
  23475. });
  23476. this.remoteDescription = {
  23477. type: description.type,
  23478. sdp: description.sdp
  23479. };
  23480. switch (description.type) {
  23481. case 'offer':
  23482. this._updateSignalingState('have-remote-offer');
  23483. break;
  23484. case 'answer':
  23485. this._updateSignalingState('stable');
  23486. break;
  23487. default:
  23488. throw new TypeError('unsupported type "' + description.type +
  23489. '"');
  23490. }
  23491. if (stream.getTracks().length) {
  23492. self.remoteStreams.push(stream);
  23493. window.setTimeout(function() {
  23494. var event = new Event('addstream');
  23495. event.stream = stream;
  23496. self.dispatchEvent(event);
  23497. if (self.onaddstream !== null) {
  23498. window.setTimeout(function() {
  23499. self.onaddstream(event);
  23500. }, 0);
  23501. }
  23502. receiverList.forEach(function(item) {
  23503. var track = item[0];
  23504. var receiver = item[1];
  23505. var trackEvent = new Event('track');
  23506. trackEvent.track = track;
  23507. trackEvent.receiver = receiver;
  23508. trackEvent.streams = [stream];
  23509. self.dispatchEvent(event);
  23510. if (self.ontrack !== null) {
  23511. window.setTimeout(function() {
  23512. self.ontrack(trackEvent);
  23513. }, 0);
  23514. }
  23515. });
  23516. }, 0);
  23517. }
  23518. if (arguments.length > 1 && typeof arguments[1] === 'function') {
  23519. window.setTimeout(arguments[1], 0);
  23520. }
  23521. return Promise.resolve();
  23522. };
  23523. window.RTCPeerConnection.prototype.close = function() {
  23524. this.transceivers.forEach(function(transceiver) {
  23525. /* not yet
  23526. if (transceiver.iceGatherer) {
  23527. transceiver.iceGatherer.close();
  23528. }
  23529. */
  23530. if (transceiver.iceTransport) {
  23531. transceiver.iceTransport.stop();
  23532. }
  23533. if (transceiver.dtlsTransport) {
  23534. transceiver.dtlsTransport.stop();
  23535. }
  23536. if (transceiver.rtpSender) {
  23537. transceiver.rtpSender.stop();
  23538. }
  23539. if (transceiver.rtpReceiver) {
  23540. transceiver.rtpReceiver.stop();
  23541. }
  23542. });
  23543. // FIXME: clean up tracks, local streams, remote streams, etc
  23544. this._updateSignalingState('closed');
  23545. };
  23546. // Update the signaling state.
  23547. window.RTCPeerConnection.prototype._updateSignalingState =
  23548. function(newState) {
  23549. this.signalingState = newState;
  23550. var event = new Event('signalingstatechange');
  23551. this.dispatchEvent(event);
  23552. if (this.onsignalingstatechange !== null) {
  23553. this.onsignalingstatechange(event);
  23554. }
  23555. };
  23556. // Determine whether to fire the negotiationneeded event.
  23557. window.RTCPeerConnection.prototype._maybeFireNegotiationNeeded =
  23558. function() {
  23559. // Fire away (for now).
  23560. var event = new Event('negotiationneeded');
  23561. this.dispatchEvent(event);
  23562. if (this.onnegotiationneeded !== null) {
  23563. this.onnegotiationneeded(event);
  23564. }
  23565. };
  23566. // Update the connection state.
  23567. window.RTCPeerConnection.prototype._updateConnectionState = function() {
  23568. var self = this;
  23569. var newState;
  23570. var states = {
  23571. 'new': 0,
  23572. closed: 0,
  23573. connecting: 0,
  23574. checking: 0,
  23575. connected: 0,
  23576. completed: 0,
  23577. failed: 0
  23578. };
  23579. this.transceivers.forEach(function(transceiver) {
  23580. states[transceiver.iceTransport.state]++;
  23581. states[transceiver.dtlsTransport.state]++;
  23582. });
  23583. // ICETransport.completed and connected are the same for this purpose.
  23584. states.connected += states.completed;
  23585. newState = 'new';
  23586. if (states.failed > 0) {
  23587. newState = 'failed';
  23588. } else if (states.connecting > 0 || states.checking > 0) {
  23589. newState = 'connecting';
  23590. } else if (states.disconnected > 0) {
  23591. newState = 'disconnected';
  23592. } else if (states.new > 0) {
  23593. newState = 'new';
  23594. } else if (states.connected > 0 || states.completed > 0) {
  23595. newState = 'connected';
  23596. }
  23597. if (newState !== self.iceConnectionState) {
  23598. self.iceConnectionState = newState;
  23599. var event = new Event('iceconnectionstatechange');
  23600. this.dispatchEvent(event);
  23601. if (this.oniceconnectionstatechange !== null) {
  23602. this.oniceconnectionstatechange(event);
  23603. }
  23604. }
  23605. };
  23606. window.RTCPeerConnection.prototype.createOffer = function() {
  23607. var self = this;
  23608. if (this._pendingOffer) {
  23609. throw new Error('createOffer called while there is a pending offer.');
  23610. }
  23611. var offerOptions;
  23612. if (arguments.length === 1 && typeof arguments[0] !== 'function') {
  23613. offerOptions = arguments[0];
  23614. } else if (arguments.length === 3) {
  23615. offerOptions = arguments[2];
  23616. }
  23617. var tracks = [];
  23618. var numAudioTracks = 0;
  23619. var numVideoTracks = 0;
  23620. // Default to sendrecv.
  23621. if (this.localStreams.length) {
  23622. numAudioTracks = this.localStreams[0].getAudioTracks().length;
  23623. numVideoTracks = this.localStreams[0].getVideoTracks().length;
  23624. }
  23625. // Determine number of audio and video tracks we need to send/recv.
  23626. if (offerOptions) {
  23627. // Reject Chrome legacy constraints.
  23628. if (offerOptions.mandatory || offerOptions.optional) {
  23629. throw new TypeError(
  23630. 'Legacy mandatory/optional constraints not supported.');
  23631. }
  23632. if (offerOptions.offerToReceiveAudio !== undefined) {
  23633. numAudioTracks = offerOptions.offerToReceiveAudio;
  23634. }
  23635. if (offerOptions.offerToReceiveVideo !== undefined) {
  23636. numVideoTracks = offerOptions.offerToReceiveVideo;
  23637. }
  23638. }
  23639. if (this.localStreams.length) {
  23640. // Push local streams.
  23641. this.localStreams[0].getTracks().forEach(function(track) {
  23642. tracks.push({
  23643. kind: track.kind,
  23644. track: track,
  23645. wantReceive: track.kind === 'audio' ?
  23646. numAudioTracks > 0 : numVideoTracks > 0
  23647. });
  23648. if (track.kind === 'audio') {
  23649. numAudioTracks--;
  23650. } else if (track.kind === 'video') {
  23651. numVideoTracks--;
  23652. }
  23653. });
  23654. }
  23655. // Create M-lines for recvonly streams.
  23656. while (numAudioTracks > 0 || numVideoTracks > 0) {
  23657. if (numAudioTracks > 0) {
  23658. tracks.push({
  23659. kind: 'audio',
  23660. wantReceive: true
  23661. });
  23662. numAudioTracks--;
  23663. }
  23664. if (numVideoTracks > 0) {
  23665. tracks.push({
  23666. kind: 'video',
  23667. wantReceive: true
  23668. });
  23669. numVideoTracks--;
  23670. }
  23671. }
  23672. var sdp = SDPUtils.writeSessionBoilerplate();
  23673. var transceivers = [];
  23674. tracks.forEach(function(mline, sdpMLineIndex) {
  23675. // For each track, create an ice gatherer, ice transport,
  23676. // dtls transport, potentially rtpsender and rtpreceiver.
  23677. var track = mline.track;
  23678. var kind = mline.kind;
  23679. var mid = SDPUtils.generateIdentifier();
  23680. var transports = self.usingBundle && sdpMLineIndex > 0 ? {
  23681. iceGatherer: transceivers[0].iceGatherer,
  23682. iceTransport: transceivers[0].iceTransport,
  23683. dtlsTransport: transceivers[0].dtlsTransport
  23684. } : self._createIceAndDtlsTransports(mid, sdpMLineIndex);
  23685. var localCapabilities = RTCRtpSender.getCapabilities(kind);
  23686. // filter RTX until additional stuff needed for RTX is implemented
  23687. // in adapter.js
  23688. localCapabilities.codecs = localCapabilities.codecs.filter(
  23689. function(codec) {
  23690. return codec.name !== 'rtx';
  23691. });
  23692. localCapabilities.codecs.forEach(function(codec) {
  23693. // work around https://bugs.chromium.org/p/webrtc/issues/detail?id=6552
  23694. // by adding level-asymmetry-allowed=1
  23695. if (codec.name === 'H264' &&
  23696. codec.parameters['level-asymmetry-allowed'] === undefined) {
  23697. codec.parameters['level-asymmetry-allowed'] = '1';
  23698. }
  23699. });
  23700. var rtpSender;
  23701. var rtpReceiver;
  23702. // generate an ssrc now, to be used later in rtpSender.send
  23703. var sendEncodingParameters = [{
  23704. ssrc: (2 * sdpMLineIndex + 1) * 1001
  23705. }];
  23706. if (track) {
  23707. rtpSender = new RTCRtpSender(track, transports.dtlsTransport);
  23708. }
  23709. if (mline.wantReceive) {
  23710. rtpReceiver = new RTCRtpReceiver(transports.dtlsTransport, kind);
  23711. }
  23712. transceivers[sdpMLineIndex] = {
  23713. iceGatherer: transports.iceGatherer,
  23714. iceTransport: transports.iceTransport,
  23715. dtlsTransport: transports.dtlsTransport,
  23716. localCapabilities: localCapabilities,
  23717. remoteCapabilities: null,
  23718. rtpSender: rtpSender,
  23719. rtpReceiver: rtpReceiver,
  23720. kind: kind,
  23721. mid: mid,
  23722. sendEncodingParameters: sendEncodingParameters,
  23723. recvEncodingParameters: null
  23724. };
  23725. });
  23726. if (this.usingBundle) {
  23727. sdp += 'a=group:BUNDLE ' + transceivers.map(function(t) {
  23728. return t.mid;
  23729. }).join(' ') + '\r\n';
  23730. }
  23731. tracks.forEach(function(mline, sdpMLineIndex) {
  23732. var transceiver = transceivers[sdpMLineIndex];
  23733. sdp += SDPUtils.writeMediaSection(transceiver,
  23734. transceiver.localCapabilities, 'offer', self.localStreams[0]);
  23735. });
  23736. this._pendingOffer = transceivers;
  23737. var desc = new RTCSessionDescription({
  23738. type: 'offer',
  23739. sdp: sdp
  23740. });
  23741. if (arguments.length && typeof arguments[0] === 'function') {
  23742. window.setTimeout(arguments[0], 0, desc);
  23743. }
  23744. return Promise.resolve(desc);
  23745. };
  23746. window.RTCPeerConnection.prototype.createAnswer = function() {
  23747. var self = this;
  23748. var sdp = SDPUtils.writeSessionBoilerplate();
  23749. if (this.usingBundle) {
  23750. sdp += 'a=group:BUNDLE ' + this.transceivers.map(function(t) {
  23751. return t.mid;
  23752. }).join(' ') + '\r\n';
  23753. }
  23754. this.transceivers.forEach(function(transceiver) {
  23755. if (transceiver.isDatachannel) {
  23756. sdp += 'm=application 0 DTLS/SCTP 5000\r\n' +
  23757. 'c=IN IP4 0.0.0.0\r\n' +
  23758. 'a=mid:' + transceiver.mid + '\r\n';
  23759. return;
  23760. }
  23761. // Calculate intersection of capabilities.
  23762. var commonCapabilities = self._getCommonCapabilities(
  23763. transceiver.localCapabilities,
  23764. transceiver.remoteCapabilities);
  23765. sdp += SDPUtils.writeMediaSection(transceiver, commonCapabilities,
  23766. 'answer', self.localStreams[0]);
  23767. });
  23768. var desc = new RTCSessionDescription({
  23769. type: 'answer',
  23770. sdp: sdp
  23771. });
  23772. if (arguments.length && typeof arguments[0] === 'function') {
  23773. window.setTimeout(arguments[0], 0, desc);
  23774. }
  23775. return Promise.resolve(desc);
  23776. };
  23777. window.RTCPeerConnection.prototype.addIceCandidate = function(candidate) {
  23778. if (!candidate) {
  23779. this.transceivers.forEach(function(transceiver) {
  23780. transceiver.iceTransport.addRemoteCandidate({});
  23781. });
  23782. } else {
  23783. var mLineIndex = candidate.sdpMLineIndex;
  23784. if (candidate.sdpMid) {
  23785. for (var i = 0; i < this.transceivers.length; i++) {
  23786. if (this.transceivers[i].mid === candidate.sdpMid) {
  23787. mLineIndex = i;
  23788. break;
  23789. }
  23790. }
  23791. }
  23792. var transceiver = this.transceivers[mLineIndex];
  23793. if (transceiver) {
  23794. var cand = Object.keys(candidate.candidate).length > 0 ?
  23795. SDPUtils.parseCandidate(candidate.candidate) : {};
  23796. // Ignore Chrome's invalid candidates since Edge does not like them.
  23797. if (cand.protocol === 'tcp' && (cand.port === 0 || cand.port === 9)) {
  23798. return;
  23799. }
  23800. // Ignore RTCP candidates, we assume RTCP-MUX.
  23801. if (cand.component !== '1') {
  23802. return;
  23803. }
  23804. // A dirty hack to make samples work.
  23805. if (cand.type === 'endOfCandidates') {
  23806. cand = {};
  23807. }
  23808. transceiver.iceTransport.addRemoteCandidate(cand);
  23809. // update the remoteDescription.
  23810. var sections = SDPUtils.splitSections(this.remoteDescription.sdp);
  23811. sections[mLineIndex + 1] += (cand.type ? candidate.candidate.trim()
  23812. : 'a=end-of-candidates') + '\r\n';
  23813. this.remoteDescription.sdp = sections.join('');
  23814. }
  23815. }
  23816. if (arguments.length > 1 && typeof arguments[1] === 'function') {
  23817. window.setTimeout(arguments[1], 0);
  23818. }
  23819. return Promise.resolve();
  23820. };
  23821. window.RTCPeerConnection.prototype.getStats = function() {
  23822. var promises = [];
  23823. this.transceivers.forEach(function(transceiver) {
  23824. ['rtpSender', 'rtpReceiver', 'iceGatherer', 'iceTransport',
  23825. 'dtlsTransport'].forEach(function(method) {
  23826. if (transceiver[method]) {
  23827. promises.push(transceiver[method].getStats());
  23828. }
  23829. });
  23830. });
  23831. var cb = arguments.length > 1 && typeof arguments[1] === 'function' &&
  23832. arguments[1];
  23833. return new Promise(function(resolve) {
  23834. // shim getStats with maplike support
  23835. var results = new Map();
  23836. Promise.all(promises).then(function(res) {
  23837. res.forEach(function(result) {
  23838. Object.keys(result).forEach(function(id) {
  23839. results.set(id, result[id]);
  23840. results[id] = result[id];
  23841. });
  23842. });
  23843. if (cb) {
  23844. window.setTimeout(cb, 0, results);
  23845. }
  23846. resolve(results);
  23847. });
  23848. });
  23849. };
  23850. }
  23851. };
  23852. // Expose public methods.
  23853. module.exports = {
  23854. shimPeerConnection: edgeShim.shimPeerConnection,
  23855. shimGetUserMedia: require('./getusermedia')
  23856. };
  23857. },{"../utils":50,"./getusermedia":46,"sdp":41}],46:[function(require,module,exports){
  23858. /*
  23859. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  23860. *
  23861. * Use of this source code is governed by a BSD-style license
  23862. * that can be found in the LICENSE file in the root of the source
  23863. * tree.
  23864. */
  23865. /* eslint-env node */
  23866. 'use strict';
  23867. // Expose public methods.
  23868. module.exports = function() {
  23869. var shimError_ = function(e) {
  23870. return {
  23871. name: {PermissionDeniedError: 'NotAllowedError'}[e.name] || e.name,
  23872. message: e.message,
  23873. constraint: e.constraint,
  23874. toString: function() {
  23875. return this.name;
  23876. }
  23877. };
  23878. };
  23879. // getUserMedia error shim.
  23880. var origGetUserMedia = navigator.mediaDevices.getUserMedia.
  23881. bind(navigator.mediaDevices);
  23882. navigator.mediaDevices.getUserMedia = function(c) {
  23883. return origGetUserMedia(c).catch(function(e) {
  23884. return Promise.reject(shimError_(e));
  23885. });
  23886. };
  23887. };
  23888. },{}],47:[function(require,module,exports){
  23889. /*
  23890. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  23891. *
  23892. * Use of this source code is governed by a BSD-style license
  23893. * that can be found in the LICENSE file in the root of the source
  23894. * tree.
  23895. */
  23896. /* eslint-env node */
  23897. 'use strict';
  23898. var browserDetails = require('../utils').browserDetails;
  23899. var firefoxShim = {
  23900. shimOnTrack: function() {
  23901. if (typeof window === 'object' && window.RTCPeerConnection && !('ontrack' in
  23902. window.RTCPeerConnection.prototype)) {
  23903. Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {
  23904. get: function() {
  23905. return this._ontrack;
  23906. },
  23907. set: function(f) {
  23908. if (this._ontrack) {
  23909. this.removeEventListener('track', this._ontrack);
  23910. this.removeEventListener('addstream', this._ontrackpoly);
  23911. }
  23912. this.addEventListener('track', this._ontrack = f);
  23913. this.addEventListener('addstream', this._ontrackpoly = function(e) {
  23914. e.stream.getTracks().forEach(function(track) {
  23915. var event = new Event('track');
  23916. event.track = track;
  23917. event.receiver = {track: track};
  23918. event.streams = [e.stream];
  23919. this.dispatchEvent(event);
  23920. }.bind(this));
  23921. }.bind(this));
  23922. }
  23923. });
  23924. }
  23925. },
  23926. shimSourceObject: function() {
  23927. // Firefox has supported mozSrcObject since FF22, unprefixed in 42.
  23928. if (typeof window === 'object') {
  23929. if (window.HTMLMediaElement &&
  23930. !('srcObject' in window.HTMLMediaElement.prototype)) {
  23931. // Shim the srcObject property, once, when HTMLMediaElement is found.
  23932. Object.defineProperty(window.HTMLMediaElement.prototype, 'srcObject', {
  23933. get: function() {
  23934. return this.mozSrcObject;
  23935. },
  23936. set: function(stream) {
  23937. this.mozSrcObject = stream;
  23938. }
  23939. });
  23940. }
  23941. }
  23942. },
  23943. shimPeerConnection: function() {
  23944. if (typeof window !== 'object' || !(window.RTCPeerConnection ||
  23945. window.mozRTCPeerConnection)) {
  23946. return; // probably media.peerconnection.enabled=false in about:config
  23947. }
  23948. // The RTCPeerConnection object.
  23949. if (!window.RTCPeerConnection) {
  23950. window.RTCPeerConnection = function(pcConfig, pcConstraints) {
  23951. if (browserDetails.version < 38) {
  23952. // .urls is not supported in FF < 38.
  23953. // create RTCIceServers with a single url.
  23954. if (pcConfig && pcConfig.iceServers) {
  23955. var newIceServers = [];
  23956. for (var i = 0; i < pcConfig.iceServers.length; i++) {
  23957. var server = pcConfig.iceServers[i];
  23958. if (server.hasOwnProperty('urls')) {
  23959. for (var j = 0; j < server.urls.length; j++) {
  23960. var newServer = {
  23961. url: server.urls[j]
  23962. };
  23963. if (server.urls[j].indexOf('turn') === 0) {
  23964. newServer.username = server.username;
  23965. newServer.credential = server.credential;
  23966. }
  23967. newIceServers.push(newServer);
  23968. }
  23969. } else {
  23970. newIceServers.push(pcConfig.iceServers[i]);
  23971. }
  23972. }
  23973. pcConfig.iceServers = newIceServers;
  23974. }
  23975. }
  23976. return new mozRTCPeerConnection(pcConfig, pcConstraints);
  23977. };
  23978. window.RTCPeerConnection.prototype = mozRTCPeerConnection.prototype;
  23979. // wrap static methods. Currently just generateCertificate.
  23980. if (mozRTCPeerConnection.generateCertificate) {
  23981. Object.defineProperty(window.RTCPeerConnection, 'generateCertificate', {
  23982. get: function() {
  23983. return mozRTCPeerConnection.generateCertificate;
  23984. }
  23985. });
  23986. }
  23987. window.RTCSessionDescription = mozRTCSessionDescription;
  23988. window.RTCIceCandidate = mozRTCIceCandidate;
  23989. }
  23990. // shim away need for obsolete RTCIceCandidate/RTCSessionDescription.
  23991. ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']
  23992. .forEach(function(method) {
  23993. var nativeMethod = RTCPeerConnection.prototype[method];
  23994. RTCPeerConnection.prototype[method] = function() {
  23995. arguments[0] = new ((method === 'addIceCandidate') ?
  23996. RTCIceCandidate : RTCSessionDescription)(arguments[0]);
  23997. return nativeMethod.apply(this, arguments);
  23998. };
  23999. });
  24000. // support for addIceCandidate(null or undefined)
  24001. var nativeAddIceCandidate =
  24002. RTCPeerConnection.prototype.addIceCandidate;
  24003. RTCPeerConnection.prototype.addIceCandidate = function() {
  24004. if (!arguments[0]) {
  24005. if (arguments[1]) {
  24006. arguments[1].apply(null);
  24007. }
  24008. return Promise.resolve();
  24009. }
  24010. return nativeAddIceCandidate.apply(this, arguments);
  24011. };
  24012. if (browserDetails.version < 48) {
  24013. // shim getStats with maplike support
  24014. var makeMapStats = function(stats) {
  24015. var map = new Map();
  24016. Object.keys(stats).forEach(function(key) {
  24017. map.set(key, stats[key]);
  24018. map[key] = stats[key];
  24019. });
  24020. return map;
  24021. };
  24022. var nativeGetStats = RTCPeerConnection.prototype.getStats;
  24023. RTCPeerConnection.prototype.getStats = function(selector, onSucc, onErr) {
  24024. return nativeGetStats.apply(this, [selector || null])
  24025. .then(function(stats) {
  24026. return makeMapStats(stats);
  24027. })
  24028. .then(onSucc, onErr);
  24029. };
  24030. }
  24031. }
  24032. };
  24033. // Expose public methods.
  24034. module.exports = {
  24035. shimOnTrack: firefoxShim.shimOnTrack,
  24036. shimSourceObject: firefoxShim.shimSourceObject,
  24037. shimPeerConnection: firefoxShim.shimPeerConnection,
  24038. shimGetUserMedia: require('./getusermedia')
  24039. };
  24040. },{"../utils":50,"./getusermedia":48}],48:[function(require,module,exports){
  24041. /*
  24042. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  24043. *
  24044. * Use of this source code is governed by a BSD-style license
  24045. * that can be found in the LICENSE file in the root of the source
  24046. * tree.
  24047. */
  24048. /* eslint-env node */
  24049. 'use strict';
  24050. var logging = require('../utils').log;
  24051. var browserDetails = require('../utils').browserDetails;
  24052. // Expose public methods.
  24053. module.exports = function() {
  24054. var shimError_ = function(e) {
  24055. return {
  24056. name: {
  24057. SecurityError: 'NotAllowedError',
  24058. PermissionDeniedError: 'NotAllowedError'
  24059. }[e.name] || e.name,
  24060. message: {
  24061. 'The operation is insecure.': 'The request is not allowed by the ' +
  24062. 'user agent or the platform in the current context.'
  24063. }[e.message] || e.message,
  24064. constraint: e.constraint,
  24065. toString: function() {
  24066. return this.name + (this.message && ': ') + this.message;
  24067. }
  24068. };
  24069. };
  24070. // getUserMedia constraints shim.
  24071. var getUserMedia_ = function(constraints, onSuccess, onError) {
  24072. var constraintsToFF37_ = function(c) {
  24073. if (typeof c !== 'object' || c.require) {
  24074. return c;
  24075. }
  24076. var require = [];
  24077. Object.keys(c).forEach(function(key) {
  24078. if (key === 'require' || key === 'advanced' || key === 'mediaSource') {
  24079. return;
  24080. }
  24081. var r = c[key] = (typeof c[key] === 'object') ?
  24082. c[key] : {ideal: c[key]};
  24083. if (r.min !== undefined ||
  24084. r.max !== undefined || r.exact !== undefined) {
  24085. require.push(key);
  24086. }
  24087. if (r.exact !== undefined) {
  24088. if (typeof r.exact === 'number') {
  24089. r. min = r.max = r.exact;
  24090. } else {
  24091. c[key] = r.exact;
  24092. }
  24093. delete r.exact;
  24094. }
  24095. if (r.ideal !== undefined) {
  24096. c.advanced = c.advanced || [];
  24097. var oc = {};
  24098. if (typeof r.ideal === 'number') {
  24099. oc[key] = {min: r.ideal, max: r.ideal};
  24100. } else {
  24101. oc[key] = r.ideal;
  24102. }
  24103. c.advanced.push(oc);
  24104. delete r.ideal;
  24105. if (!Object.keys(r).length) {
  24106. delete c[key];
  24107. }
  24108. }
  24109. });
  24110. if (require.length) {
  24111. c.require = require;
  24112. }
  24113. return c;
  24114. };
  24115. constraints = JSON.parse(JSON.stringify(constraints));
  24116. if (browserDetails.version < 38) {
  24117. logging('spec: ' + JSON.stringify(constraints));
  24118. if (constraints.audio) {
  24119. constraints.audio = constraintsToFF37_(constraints.audio);
  24120. }
  24121. if (constraints.video) {
  24122. constraints.video = constraintsToFF37_(constraints.video);
  24123. }
  24124. logging('ff37: ' + JSON.stringify(constraints));
  24125. }
  24126. return navigator.mozGetUserMedia(constraints, onSuccess, function(e) {
  24127. onError(shimError_(e));
  24128. });
  24129. };
  24130. // Returns the result of getUserMedia as a Promise.
  24131. var getUserMediaPromise_ = function(constraints) {
  24132. return new Promise(function(resolve, reject) {
  24133. getUserMedia_(constraints, resolve, reject);
  24134. });
  24135. };
  24136. // Shim for mediaDevices on older versions.
  24137. if (!navigator.mediaDevices) {
  24138. navigator.mediaDevices = {getUserMedia: getUserMediaPromise_,
  24139. addEventListener: function() { },
  24140. removeEventListener: function() { }
  24141. };
  24142. }
  24143. navigator.mediaDevices.enumerateDevices =
  24144. navigator.mediaDevices.enumerateDevices || function() {
  24145. return new Promise(function(resolve) {
  24146. var infos = [
  24147. {kind: 'audioinput', deviceId: 'default', label: '', groupId: ''},
  24148. {kind: 'videoinput', deviceId: 'default', label: '', groupId: ''}
  24149. ];
  24150. resolve(infos);
  24151. });
  24152. };
  24153. if (browserDetails.version < 41) {
  24154. // Work around http://bugzil.la/1169665
  24155. var orgEnumerateDevices =
  24156. navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices);
  24157. navigator.mediaDevices.enumerateDevices = function() {
  24158. return orgEnumerateDevices().then(undefined, function(e) {
  24159. if (e.name === 'NotFoundError') {
  24160. return [];
  24161. }
  24162. throw e;
  24163. });
  24164. };
  24165. }
  24166. if (browserDetails.version < 49) {
  24167. var origGetUserMedia = navigator.mediaDevices.getUserMedia.
  24168. bind(navigator.mediaDevices);
  24169. navigator.mediaDevices.getUserMedia = function(c) {
  24170. return origGetUserMedia(c).then(function(stream) {
  24171. // Work around https://bugzil.la/802326
  24172. if (c.audio && !stream.getAudioTracks().length ||
  24173. c.video && !stream.getVideoTracks().length) {
  24174. stream.getTracks().forEach(function(track) {
  24175. track.stop();
  24176. });
  24177. throw new DOMException('The object can not be found here.',
  24178. 'NotFoundError');
  24179. }
  24180. return stream;
  24181. }, function(e) {
  24182. return Promise.reject(shimError_(e));
  24183. });
  24184. };
  24185. }
  24186. navigator.getUserMedia = function(constraints, onSuccess, onError) {
  24187. if (browserDetails.version < 44) {
  24188. return getUserMedia_(constraints, onSuccess, onError);
  24189. }
  24190. // Replace Firefox 44+'s deprecation warning with unprefixed version.
  24191. console.warn('navigator.getUserMedia has been replaced by ' +
  24192. 'navigator.mediaDevices.getUserMedia');
  24193. navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
  24194. };
  24195. };
  24196. },{"../utils":50}],49:[function(require,module,exports){
  24197. /*
  24198. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  24199. *
  24200. * Use of this source code is governed by a BSD-style license
  24201. * that can be found in the LICENSE file in the root of the source
  24202. * tree.
  24203. */
  24204. 'use strict';
  24205. var safariShim = {
  24206. // TODO: DrAlex, should be here, double check against LayoutTests
  24207. // shimOnTrack: function() { },
  24208. // TODO: once the back-end for the mac port is done, add.
  24209. // TODO: check for webkitGTK+
  24210. // shimPeerConnection: function() { },
  24211. shimGetUserMedia: function() {
  24212. navigator.getUserMedia = navigator.webkitGetUserMedia;
  24213. }
  24214. };
  24215. // Expose public methods.
  24216. module.exports = {
  24217. shimGetUserMedia: safariShim.shimGetUserMedia
  24218. // TODO
  24219. // shimOnTrack: safariShim.shimOnTrack,
  24220. // shimPeerConnection: safariShim.shimPeerConnection
  24221. };
  24222. },{}],50:[function(require,module,exports){
  24223. /*
  24224. * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
  24225. *
  24226. * Use of this source code is governed by a BSD-style license
  24227. * that can be found in the LICENSE file in the root of the source
  24228. * tree.
  24229. */
  24230. /* eslint-env node */
  24231. 'use strict';
  24232. var logDisabled_ = true;
  24233. // Utility methods.
  24234. var utils = {
  24235. disableLog: function(bool) {
  24236. if (typeof bool !== 'boolean') {
  24237. return new Error('Argument type: ' + typeof bool +
  24238. '. Please use a boolean.');
  24239. }
  24240. logDisabled_ = bool;
  24241. return (bool) ? 'adapter.js logging disabled' :
  24242. 'adapter.js logging enabled';
  24243. },
  24244. log: function() {
  24245. if (typeof window === 'object') {
  24246. if (logDisabled_) {
  24247. return;
  24248. }
  24249. if (typeof console !== 'undefined' && typeof console.log === 'function') {
  24250. console.log.apply(console, arguments);
  24251. }
  24252. }
  24253. },
  24254. /**
  24255. * Extract browser version out of the provided user agent string.
  24256. *
  24257. * @param {!string} uastring userAgent string.
  24258. * @param {!string} expr Regular expression used as match criteria.
  24259. * @param {!number} pos position in the version string to be returned.
  24260. * @return {!number} browser version.
  24261. */
  24262. extractVersion: function(uastring, expr, pos) {
  24263. var match = uastring.match(expr);
  24264. return match && match.length >= pos && parseInt(match[pos], 10);
  24265. },
  24266. /**
  24267. * Browser detector.
  24268. *
  24269. * @return {object} result containing browser and version
  24270. * properties.
  24271. */
  24272. detectBrowser: function() {
  24273. // Returned result object.
  24274. var result = {};
  24275. result.browser = null;
  24276. result.version = null;
  24277. // Fail early if it's not a browser
  24278. if (typeof window === 'undefined' || !window.navigator) {
  24279. result.browser = 'Not a browser.';
  24280. return result;
  24281. }
  24282. // Firefox.
  24283. if (navigator.mozGetUserMedia) {
  24284. result.browser = 'firefox';
  24285. result.version = this.extractVersion(navigator.userAgent,
  24286. /Firefox\/([0-9]+)\./, 1);
  24287. // all webkit-based browsers
  24288. } else if (navigator.webkitGetUserMedia) {
  24289. // Chrome, Chromium, Webview, Opera, all use the chrome shim for now
  24290. if (window.webkitRTCPeerConnection) {
  24291. result.browser = 'chrome';
  24292. result.version = this.extractVersion(navigator.userAgent,
  24293. /Chrom(e|ium)\/([0-9]+)\./, 2);
  24294. // Safari or unknown webkit-based
  24295. // for the time being Safari has support for MediaStreams but not webRTC
  24296. } else {
  24297. // Safari UA substrings of interest for reference:
  24298. // - webkit version: AppleWebKit/602.1.25 (also used in Op,Cr)
  24299. // - safari UI version: Version/9.0.3 (unique to Safari)
  24300. // - safari UI webkit version: Safari/601.4.4 (also used in Op,Cr)
  24301. //
  24302. // if the webkit version and safari UI webkit versions are equals,
  24303. // ... this is a stable version.
  24304. //
  24305. // only the internal webkit version is important today to know if
  24306. // media streams are supported
  24307. //
  24308. if (navigator.userAgent.match(/Version\/(\d+).(\d+)/)) {
  24309. result.browser = 'safari';
  24310. result.version = this.extractVersion(navigator.userAgent,
  24311. /AppleWebKit\/([0-9]+)\./, 1);
  24312. // unknown webkit-based browser
  24313. } else {
  24314. result.browser = 'Unsupported webkit-based browser ' +
  24315. 'with GUM support but no WebRTC support.';
  24316. return result;
  24317. }
  24318. }
  24319. // Edge.
  24320. } else if (navigator.mediaDevices &&
  24321. navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)) {
  24322. result.browser = 'edge';
  24323. result.version = this.extractVersion(navigator.userAgent,
  24324. /Edge\/(\d+).(\d+)$/, 2);
  24325. // Default fallthrough: not supported.
  24326. } else {
  24327. result.browser = 'Not a supported browser.';
  24328. return result;
  24329. }
  24330. return result;
  24331. }
  24332. };
  24333. // Export.
  24334. module.exports = {
  24335. log: utils.log,
  24336. disableLog: utils.disableLog,
  24337. browserDetails: utils.detectBrowser(),
  24338. extractVersion: utils.extractVersion
  24339. };
  24340. },{}],51:[function(require,module,exports){
  24341. module.exports={
  24342. "name": "jssip",
  24343. "title": "JsSIP",
  24344. "description": "the Javascript SIP library",
  24345. "version": "3.0.13",
  24346. "homepage": "http://jssip.net",
  24347. "author": "José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)",
  24348. "contributors": [
  24349. "Iñaki Baz Castillo <ibc@aliax.net> (https://github.com/ibc)",
  24350. "Saúl Ibarra Corretgé <saghul@gmail.com> (https://github.com/saghul)"
  24351. ],
  24352. "main": "lib/JsSIP.js",
  24353. "keywords": [
  24354. "sip",
  24355. "websocket",
  24356. "webrtc",
  24357. "node",
  24358. "browser",
  24359. "library"
  24360. ],
  24361. "license": "MIT",
  24362. "repository": {
  24363. "type": "git",
  24364. "url": "https://github.com/versatica/JsSIP.git"
  24365. },
  24366. "bugs": {
  24367. "url": "https://github.com/versatica/JsSIP/issues"
  24368. },
  24369. "dependencies": {
  24370. "debug": "^2.6.8",
  24371. "sdp-transform": "^2.3.0",
  24372. "webrtc-adapter": "^3.4.3"
  24373. },
  24374. "devDependencies": {
  24375. "browserify": "^14.3.0",
  24376. "gulp": "git+https://github.com/gulpjs/gulp.git#4.0",
  24377. "gulp-expect-file": "0.0.7",
  24378. "gulp-header": "1.8.8",
  24379. "gulp-jshint": "^2.0.4",
  24380. "gulp-nodeunit-runner": "^0.2.2",
  24381. "gulp-rename": "^1.2.2",
  24382. "gulp-uglify": "^3.0.0",
  24383. "gulp-util": "^3.0.8",
  24384. "jshint": "^2.9.4",
  24385. "jshint-stylish": "^2.2.1",
  24386. "pegjs": "0.7.0",
  24387. "vinyl-buffer": "^1.0.0",
  24388. "vinyl-source-stream": "^1.1.0"
  24389. },
  24390. "scripts": {
  24391. "test": "gulp test"
  24392. }
  24393. }
  24394. },{}]},{},[7])(7)
  24395. });