jssip-3.3.11.js 806 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814
  1. /*
  2. * JsSIP v3.3.11
  3. * the Javascript SIP library
  4. * Copyright: 2012-2019 JosĂŠ Luis MillĂĄn <jmillan@aliax.net> (https://github.com/jmillan)
  5. * Homepage: https://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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  9. "use strict";
  10. var Utils = require('./Utils');
  11. var JsSIP_C = require('./Constants');
  12. var Grammar = require('./Grammar');
  13. var URI = require('./URI');
  14. var Socket = require('./Socket');
  15. var Exceptions = require('./Exceptions'); // Default settings.
  16. exports.settings = {
  17. // SIP authentication.
  18. authorization_user: null,
  19. password: null,
  20. realm: null,
  21. ha1: null,
  22. // SIP account.
  23. display_name: null,
  24. uri: null,
  25. contact_uri: null,
  26. // SIP instance id (GRUU).
  27. instance_id: null,
  28. // Preloaded SIP Route header field.
  29. use_preloaded_route: false,
  30. // Session parameters.
  31. session_timers: true,
  32. session_timers_refresh_method: JsSIP_C.UPDATE,
  33. no_answer_timeout: 60,
  34. // Registration parameters.
  35. register: true,
  36. register_expires: 600,
  37. registrar_server: null,
  38. // Connection options.
  39. sockets: null,
  40. connection_recovery_max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL,
  41. connection_recovery_min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL,
  42. /*
  43. * Host address.
  44. * Value to be set in Via sent_by and host part of Contact FQDN.
  45. */
  46. via_host: "".concat(Utils.createRandomToken(12), ".invalid")
  47. }; // Configuration checks.
  48. var checks = {
  49. mandatory: {
  50. sockets: function sockets(_sockets2) {
  51. /* Allow defining sockets parameter as:
  52. * Socket: socket
  53. * Array of Socket: [socket1, socket2]
  54. * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}]
  55. * Array of Objects and Socket: [{socket: socket1}, socket2]
  56. */
  57. var _sockets = [];
  58. if (Socket.isSocket(_sockets2)) {
  59. _sockets.push({
  60. socket: _sockets2
  61. });
  62. } else if (Array.isArray(_sockets2) && _sockets2.length) {
  63. var _iteratorNormalCompletion = true;
  64. var _didIteratorError = false;
  65. var _iteratorError = undefined;
  66. try {
  67. for (var _iterator = _sockets2[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  68. var socket = _step.value;
  69. if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) {
  70. _sockets.push(socket);
  71. } else if (Socket.isSocket(socket)) {
  72. _sockets.push({
  73. socket: socket
  74. });
  75. }
  76. }
  77. } catch (err) {
  78. _didIteratorError = true;
  79. _iteratorError = err;
  80. } finally {
  81. try {
  82. if (!_iteratorNormalCompletion && _iterator.return != null) {
  83. _iterator.return();
  84. }
  85. } finally {
  86. if (_didIteratorError) {
  87. throw _iteratorError;
  88. }
  89. }
  90. }
  91. } else {
  92. return;
  93. }
  94. return _sockets;
  95. },
  96. uri: function uri(_uri) {
  97. if (!/^sip:/i.test(_uri)) {
  98. _uri = "".concat(JsSIP_C.SIP, ":").concat(_uri);
  99. }
  100. var parsed = URI.parse(_uri);
  101. if (!parsed) {
  102. return;
  103. } else if (!parsed.user) {
  104. return;
  105. } else {
  106. return parsed;
  107. }
  108. }
  109. },
  110. optional: {
  111. authorization_user: function authorization_user(_authorization_user) {
  112. if (Grammar.parse("\"".concat(_authorization_user, "\""), 'quoted_string') === -1) {
  113. return;
  114. } else {
  115. return _authorization_user;
  116. }
  117. },
  118. user_agent: function user_agent(_user_agent) {
  119. if (typeof _user_agent === 'string') {
  120. return _user_agent;
  121. }
  122. },
  123. connection_recovery_max_interval: function connection_recovery_max_interval(_connection_recovery_max_interval) {
  124. if (Utils.isDecimal(_connection_recovery_max_interval)) {
  125. var value = Number(_connection_recovery_max_interval);
  126. if (value > 0) {
  127. return value;
  128. }
  129. }
  130. },
  131. connection_recovery_min_interval: function connection_recovery_min_interval(_connection_recovery_min_interval) {
  132. if (Utils.isDecimal(_connection_recovery_min_interval)) {
  133. var value = Number(_connection_recovery_min_interval);
  134. if (value > 0) {
  135. return value;
  136. }
  137. }
  138. },
  139. contact_uri: function contact_uri(_contact_uri) {
  140. if (typeof _contact_uri === 'string') {
  141. var uri = Grammar.parse(_contact_uri, 'SIP_URI');
  142. if (uri !== -1) {
  143. return uri;
  144. }
  145. }
  146. },
  147. display_name: function display_name(_display_name) {
  148. return _display_name;
  149. },
  150. instance_id: function instance_id(_instance_id) {
  151. if (/^uuid:/i.test(_instance_id)) {
  152. _instance_id = _instance_id.substr(5);
  153. }
  154. if (Grammar.parse(_instance_id, 'uuid') === -1) {
  155. return;
  156. } else {
  157. return _instance_id;
  158. }
  159. },
  160. no_answer_timeout: function no_answer_timeout(_no_answer_timeout) {
  161. if (Utils.isDecimal(_no_answer_timeout)) {
  162. var value = Number(_no_answer_timeout);
  163. if (value > 0) {
  164. return value;
  165. }
  166. }
  167. },
  168. session_timers: function session_timers(_session_timers) {
  169. if (typeof _session_timers === 'boolean') {
  170. return _session_timers;
  171. }
  172. },
  173. session_timers_refresh_method: function session_timers_refresh_method(method) {
  174. if (typeof method === 'string') {
  175. method = method.toUpperCase();
  176. if (method === JsSIP_C.INVITE || method === JsSIP_C.UPDATE) {
  177. return method;
  178. }
  179. }
  180. },
  181. password: function password(_password) {
  182. return String(_password);
  183. },
  184. realm: function realm(_realm) {
  185. return String(_realm);
  186. },
  187. ha1: function ha1(_ha) {
  188. return String(_ha);
  189. },
  190. register: function register(_register) {
  191. if (typeof _register === 'boolean') {
  192. return _register;
  193. }
  194. },
  195. register_expires: function register_expires(_register_expires) {
  196. if (Utils.isDecimal(_register_expires)) {
  197. var value = Number(_register_expires);
  198. if (value > 0) {
  199. return value;
  200. }
  201. }
  202. },
  203. registrar_server: function registrar_server(_registrar_server) {
  204. if (!/^sip:/i.test(_registrar_server)) {
  205. _registrar_server = "".concat(JsSIP_C.SIP, ":").concat(_registrar_server);
  206. }
  207. var parsed = URI.parse(_registrar_server);
  208. if (!parsed) {
  209. return;
  210. } else if (parsed.user) {
  211. return;
  212. } else {
  213. return parsed;
  214. }
  215. },
  216. use_preloaded_route: function use_preloaded_route(_use_preloaded_route) {
  217. if (typeof _use_preloaded_route === 'boolean') {
  218. return _use_preloaded_route;
  219. }
  220. }
  221. }
  222. };
  223. exports.load = function (dst, src) {
  224. // Check Mandatory parameters.
  225. for (var parameter in checks.mandatory) {
  226. if (!src.hasOwnProperty(parameter)) {
  227. throw new Exceptions.ConfigurationError(parameter);
  228. } else {
  229. var value = src[parameter];
  230. var checked_value = checks.mandatory[parameter](value);
  231. if (checked_value !== undefined) {
  232. dst[parameter] = checked_value;
  233. } else {
  234. throw new Exceptions.ConfigurationError(parameter, value);
  235. }
  236. }
  237. } // Check Optional parameters.
  238. for (var _parameter in checks.optional) {
  239. if (src.hasOwnProperty(_parameter)) {
  240. var _value = src[_parameter];
  241. /* If the parameter value is null, empty string, undefined, empty array
  242. * or it's a number with NaN value, then apply its default value.
  243. */
  244. if (Utils.isEmpty(_value)) {
  245. continue;
  246. }
  247. var _checked_value = checks.optional[_parameter](_value);
  248. if (_checked_value !== undefined) {
  249. dst[_parameter] = _checked_value;
  250. } else {
  251. throw new Exceptions.ConfigurationError(_parameter, _value);
  252. }
  253. }
  254. }
  255. };
  256. },{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":20,"./URI":25,"./Utils":26}],2:[function(require,module,exports){
  257. "use strict";
  258. var pkg = require('../package.json');
  259. module.exports = {
  260. USER_AGENT: "".concat(pkg.title, " ").concat(pkg.version),
  261. // SIP scheme.
  262. SIP: 'sip',
  263. SIPS: 'sips',
  264. // End and Failure causes.
  265. causes: {
  266. // Generic error causes.
  267. CONNECTION_ERROR: 'Connection Error',
  268. REQUEST_TIMEOUT: 'Request Timeout',
  269. SIP_FAILURE_CODE: 'SIP Failure Code',
  270. INTERNAL_ERROR: 'Internal Error',
  271. // SIP error causes.
  272. BUSY: 'Busy',
  273. REJECTED: 'Rejected',
  274. REDIRECTED: 'Redirected',
  275. UNAVAILABLE: 'Unavailable',
  276. NOT_FOUND: 'Not Found',
  277. ADDRESS_INCOMPLETE: 'Address Incomplete',
  278. INCOMPATIBLE_SDP: 'Incompatible SDP',
  279. MISSING_SDP: 'Missing SDP',
  280. AUTHENTICATION_ERROR: 'Authentication Error',
  281. // Session error causes.
  282. BYE: 'Terminated',
  283. WEBRTC_ERROR: 'WebRTC Error',
  284. CANCELED: 'Canceled',
  285. NO_ANSWER: 'No Answer',
  286. EXPIRES: 'Expires',
  287. NO_ACK: 'No ACK',
  288. DIALOG_ERROR: 'Dialog Error',
  289. USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access',
  290. BAD_MEDIA_DESCRIPTION: 'Bad Media Description',
  291. RTP_TIMEOUT: 'RTP Timeout'
  292. },
  293. SIP_ERROR_CAUSES: {
  294. REDIRECTED: [300, 301, 302, 305, 380],
  295. BUSY: [486, 600],
  296. REJECTED: [403, 603],
  297. NOT_FOUND: [404, 604],
  298. UNAVAILABLE: [480, 410, 408, 430],
  299. ADDRESS_INCOMPLETE: [484, 424],
  300. INCOMPATIBLE_SDP: [488, 606],
  301. AUTHENTICATION_ERROR: [401, 407]
  302. },
  303. // SIP Methods.
  304. ACK: 'ACK',
  305. BYE: 'BYE',
  306. CANCEL: 'CANCEL',
  307. INFO: 'INFO',
  308. INVITE: 'INVITE',
  309. MESSAGE: 'MESSAGE',
  310. NOTIFY: 'NOTIFY',
  311. OPTIONS: 'OPTIONS',
  312. REGISTER: 'REGISTER',
  313. REFER: 'REFER',
  314. UPDATE: 'UPDATE',
  315. SUBSCRIBE: 'SUBSCRIBE',
  316. /* SIP Response Reasons
  317. * DOC: https://www.iana.org/assignments/sip-parameters
  318. * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7
  319. */
  320. REASON_PHRASE: {
  321. 100: 'Trying',
  322. 180: 'Ringing',
  323. 181: 'Call Is Being Forwarded',
  324. 182: 'Queued',
  325. 183: 'Session Progress',
  326. 199: 'Early Dialog Terminated',
  327. // draft-ietf-sipcore-199
  328. 200: 'OK',
  329. 202: 'Accepted',
  330. // RFC 3265
  331. 204: 'No Notification',
  332. // RFC 5839
  333. 300: 'Multiple Choices',
  334. 301: 'Moved Permanently',
  335. 302: 'Moved Temporarily',
  336. 305: 'Use Proxy',
  337. 380: 'Alternative Service',
  338. 400: 'Bad Request',
  339. 401: 'Unauthorized',
  340. 402: 'Payment Required',
  341. 403: 'Forbidden',
  342. 404: 'Not Found',
  343. 405: 'Method Not Allowed',
  344. 406: 'Not Acceptable',
  345. 407: 'Proxy Authentication Required',
  346. 408: 'Request Timeout',
  347. 410: 'Gone',
  348. 412: 'Conditional Request Failed',
  349. // RFC 3903
  350. 413: 'Request Entity Too Large',
  351. 414: 'Request-URI Too Long',
  352. 415: 'Unsupported Media Type',
  353. 416: 'Unsupported URI Scheme',
  354. 417: 'Unknown Resource-Priority',
  355. // RFC 4412
  356. 420: 'Bad Extension',
  357. 421: 'Extension Required',
  358. 422: 'Session Interval Too Small',
  359. // RFC 4028
  360. 423: 'Interval Too Brief',
  361. 424: 'Bad Location Information',
  362. // RFC 6442
  363. 428: 'Use Identity Header',
  364. // RFC 4474
  365. 429: 'Provide Referrer Identity',
  366. // RFC 3892
  367. 430: 'Flow Failed',
  368. // RFC 5626
  369. 433: 'Anonymity Disallowed',
  370. // RFC 5079
  371. 436: 'Bad Identity-Info',
  372. // RFC 4474
  373. 437: 'Unsupported Certificate',
  374. // RFC 4744
  375. 438: 'Invalid Identity Header',
  376. // RFC 4744
  377. 439: 'First Hop Lacks Outbound Support',
  378. // RFC 5626
  379. 440: 'Max-Breadth Exceeded',
  380. // RFC 5393
  381. 469: 'Bad Info Package',
  382. // draft-ietf-sipcore-info-events
  383. 470: 'Consent Needed',
  384. // RFC 5360
  385. 478: 'Unresolvable Destination',
  386. // Custom code copied from Kamailio.
  387. 480: 'Temporarily Unavailable',
  388. 481: 'Call/Transaction Does Not Exist',
  389. 482: 'Loop Detected',
  390. 483: 'Too Many Hops',
  391. 484: 'Address Incomplete',
  392. 485: 'Ambiguous',
  393. 486: 'Busy Here',
  394. 487: 'Request Terminated',
  395. 488: 'Not Acceptable Here',
  396. 489: 'Bad Event',
  397. // RFC 3265
  398. 491: 'Request Pending',
  399. 493: 'Undecipherable',
  400. 494: 'Security Agreement Required',
  401. // RFC 3329
  402. 500: 'JsSIP Internal Error',
  403. 501: 'Not Implemented',
  404. 502: 'Bad Gateway',
  405. 503: 'Service Unavailable',
  406. 504: 'Server Time-out',
  407. 505: 'Version Not Supported',
  408. 513: 'Message Too Large',
  409. 580: 'Precondition Failure',
  410. // RFC 3312
  411. 600: 'Busy Everywhere',
  412. 603: 'Decline',
  413. 604: 'Does Not Exist Anywhere',
  414. 606: 'Not Acceptable'
  415. },
  416. ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY',
  417. ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay',
  418. MAX_FORWARDS: 69,
  419. SESSION_EXPIRES: 90,
  420. MIN_SESSION_EXPIRES: 60,
  421. CONNECTION_RECOVERY_MAX_INTERVAL: 30,
  422. CONNECTION_RECOVERY_MIN_INTERVAL: 2
  423. };
  424. },{"../package.json":38}],3:[function(require,module,exports){
  425. "use strict";
  426. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  427. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  428. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  429. var SIPMessage = require('./SIPMessage');
  430. var JsSIP_C = require('./Constants');
  431. var Transactions = require('./Transactions');
  432. var Dialog_RequestSender = require('./Dialog/RequestSender');
  433. var Utils = require('./Utils');
  434. var debug = require('debug')('JsSIP:Dialog');
  435. var C = {
  436. // Dialog states.
  437. STATUS_EARLY: 1,
  438. STATUS_CONFIRMED: 2
  439. }; // RFC 3261 12.1.
  440. module.exports =
  441. /*#__PURE__*/
  442. function () {
  443. _createClass(Dialog, null, [{
  444. key: "C",
  445. // Expose C object.
  446. get: function get() {
  447. return C;
  448. }
  449. }]);
  450. function Dialog(owner, message, type) {
  451. var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED;
  452. _classCallCheck(this, Dialog);
  453. this._owner = owner;
  454. this._ua = owner._ua;
  455. this._uac_pending_reply = false;
  456. this._uas_pending_reply = false;
  457. if (!message.hasHeader('contact')) {
  458. return {
  459. error: 'unable to create a Dialog without Contact header field'
  460. };
  461. }
  462. if (message instanceof SIPMessage.IncomingResponse) {
  463. state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED;
  464. }
  465. var contact = message.parseHeader('contact'); // RFC 3261 12.1.1.
  466. if (type === 'UAS') {
  467. this._id = {
  468. call_id: message.call_id,
  469. local_tag: message.to_tag,
  470. remote_tag: message.from_tag,
  471. toString: function toString() {
  472. return this.call_id + this.local_tag + this.remote_tag;
  473. }
  474. };
  475. this._state = state;
  476. this._remote_seqnum = message.cseq;
  477. this._local_uri = message.parseHeader('to').uri;
  478. this._remote_uri = message.parseHeader('from').uri;
  479. this._remote_target = contact.uri;
  480. this._route_set = message.getHeaders('record-route');
  481. this._ack_seqnum = this._remote_seqnum;
  482. } // RFC 3261 12.1.2.
  483. else if (type === 'UAC') {
  484. this._id = {
  485. call_id: message.call_id,
  486. local_tag: message.from_tag,
  487. remote_tag: message.to_tag,
  488. toString: function toString() {
  489. return this.call_id + this.local_tag + this.remote_tag;
  490. }
  491. };
  492. this._state = state;
  493. this._local_seqnum = message.cseq;
  494. this._local_uri = message.parseHeader('from').uri;
  495. this._remote_uri = message.parseHeader('to').uri;
  496. this._remote_target = contact.uri;
  497. this._route_set = message.getHeaders('record-route').reverse();
  498. this._ack_seqnum = null;
  499. }
  500. this._ua.newDialog(this);
  501. debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED'));
  502. }
  503. _createClass(Dialog, [{
  504. key: "update",
  505. value: function update(message, type) {
  506. this._state = C.STATUS_CONFIRMED;
  507. debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state"));
  508. if (type === 'UAC') {
  509. // RFC 3261 13.2.2.4.
  510. this._route_set = message.getHeaders('record-route').reverse();
  511. }
  512. }
  513. }, {
  514. key: "terminate",
  515. value: function terminate() {
  516. debug("dialog ".concat(this._id.toString(), " deleted"));
  517. this._ua.destroyDialog(this);
  518. }
  519. }, {
  520. key: "sendRequest",
  521. value: function sendRequest(method) {
  522. var _this = this;
  523. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  524. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  525. var eventHandlers = options.eventHandlers || {};
  526. var body = options.body || null;
  527. var request = this._createRequest(method, extraHeaders, body); // Increase the local CSeq on authentication.
  528. eventHandlers.onAuthenticated = function () {
  529. _this._local_seqnum += 1;
  530. };
  531. var request_sender = new Dialog_RequestSender(this, request, eventHandlers);
  532. request_sender.send(); // Return the instance of OutgoingRequest.
  533. return request;
  534. }
  535. }, {
  536. key: "receiveRequest",
  537. value: function receiveRequest(request) {
  538. // Check in-dialog request.
  539. if (!this._checkInDialogRequest(request)) {
  540. return;
  541. } // ACK received. Cleanup this._ack_seqnum.
  542. if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) {
  543. this._ack_seqnum = null;
  544. } // INVITE received. Set this._ack_seqnum.
  545. else if (request.method === JsSIP_C.INVITE) {
  546. this._ack_seqnum = request.cseq;
  547. }
  548. this._owner.receiveRequest(request);
  549. } // RFC 3261 12.2.1.1.
  550. }, {
  551. key: "_createRequest",
  552. value: function _createRequest(method, extraHeaders, body) {
  553. extraHeaders = Utils.cloneArray(extraHeaders);
  554. if (!this._local_seqnum) {
  555. this._local_seqnum = Math.floor(Math.random() * 10000);
  556. }
  557. var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1;
  558. var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, {
  559. 'cseq': cseq,
  560. 'call_id': this._id.call_id,
  561. 'from_uri': this._local_uri,
  562. 'from_tag': this._id.local_tag,
  563. 'to_uri': this._remote_uri,
  564. 'to_tag': this._id.remote_tag,
  565. 'route_set': this._route_set
  566. }, extraHeaders, body);
  567. return request;
  568. } // RFC 3261 12.2.2.
  569. }, {
  570. key: "_checkInDialogRequest",
  571. value: function _checkInDialogRequest(request) {
  572. var _this2 = this;
  573. if (!this._remote_seqnum) {
  574. this._remote_seqnum = request.cseq;
  575. } else if (request.cseq < this._remote_seqnum) {
  576. if (request.method === JsSIP_C.ACK) {
  577. // We are not expecting any ACK with lower seqnum than the current one.
  578. // Or this is not the ACK we are waiting for.
  579. if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) {
  580. return false;
  581. }
  582. } else {
  583. request.reply(500);
  584. return false;
  585. }
  586. } else if (request.cseq > this._remote_seqnum) {
  587. this._remote_seqnum = request.cseq;
  588. } // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-.
  589. if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) {
  590. if (this._uac_pending_reply === true) {
  591. request.reply(491);
  592. } else if (this._uas_pending_reply === true) {
  593. var retryAfter = (Math.random() * 10 | 0) + 1;
  594. request.reply(500, null, ["Retry-After:".concat(retryAfter)]);
  595. return false;
  596. } else {
  597. this._uas_pending_reply = true;
  598. var stateChanged = function stateChanged() {
  599. if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED || request.server_transaction.state === Transactions.C.STATUS_COMPLETED || request.server_transaction.state === Transactions.C.STATUS_TERMINATED) {
  600. request.server_transaction.removeListener('stateChanged', stateChanged);
  601. _this2._uas_pending_reply = false;
  602. }
  603. };
  604. request.server_transaction.on('stateChanged', stateChanged);
  605. } // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted.
  606. if (request.hasHeader('contact')) {
  607. request.server_transaction.on('stateChanged', function () {
  608. if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED) {
  609. _this2._remote_target = request.parseHeader('contact').uri;
  610. }
  611. });
  612. }
  613. } else if (request.method === JsSIP_C.NOTIFY) {
  614. // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted.
  615. if (request.hasHeader('contact')) {
  616. request.server_transaction.on('stateChanged', function () {
  617. if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) {
  618. _this2._remote_target = request.parseHeader('contact').uri;
  619. }
  620. });
  621. }
  622. }
  623. return true;
  624. }
  625. }, {
  626. key: "id",
  627. get: function get() {
  628. return this._id;
  629. }
  630. }, {
  631. key: "local_seqnum",
  632. get: function get() {
  633. return this._local_seqnum;
  634. },
  635. set: function set(num) {
  636. this._local_seqnum = num;
  637. }
  638. }, {
  639. key: "owner",
  640. get: function get() {
  641. return this._owner;
  642. }
  643. }, {
  644. key: "uac_pending_reply",
  645. get: function get() {
  646. return this._uac_pending_reply;
  647. },
  648. set: function set(pending) {
  649. this._uac_pending_reply = pending;
  650. }
  651. }, {
  652. key: "uas_pending_reply",
  653. get: function get() {
  654. return this._uas_pending_reply;
  655. }
  656. }]);
  657. return Dialog;
  658. }();
  659. },{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":19,"./Transactions":22,"./Utils":26,"debug":30}],4:[function(require,module,exports){
  660. "use strict";
  661. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  662. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  663. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  664. var JsSIP_C = require('../Constants');
  665. var Transactions = require('../Transactions');
  666. var RTCSession = require('../RTCSession');
  667. var RequestSender = require('../RequestSender'); // Default event handlers.
  668. var EventHandlers = {
  669. onRequestTimeout: function onRequestTimeout() {},
  670. onTransportError: function onTransportError() {},
  671. onSuccessResponse: function onSuccessResponse() {},
  672. onErrorResponse: function onErrorResponse() {},
  673. onAuthenticated: function onAuthenticated() {},
  674. onDialogError: function onDialogError() {}
  675. };
  676. module.exports =
  677. /*#__PURE__*/
  678. function () {
  679. function DialogRequestSender(dialog, request, eventHandlers) {
  680. _classCallCheck(this, DialogRequestSender);
  681. this._dialog = dialog;
  682. this._ua = dialog._ua;
  683. this._request = request;
  684. this._eventHandlers = eventHandlers; // RFC3261 14.1 Modifying an Existing Session. UAC Behavior.
  685. this._reattempt = false;
  686. this._reattemptTimer = null; // Define the undefined handlers.
  687. for (var handler in EventHandlers) {
  688. if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
  689. if (!this._eventHandlers[handler]) {
  690. this._eventHandlers[handler] = EventHandlers[handler];
  691. }
  692. }
  693. }
  694. }
  695. _createClass(DialogRequestSender, [{
  696. key: "send",
  697. value: function send() {
  698. var _this = this;
  699. var request_sender = new RequestSender(this._ua, this._request, {
  700. onRequestTimeout: function onRequestTimeout() {
  701. _this._eventHandlers.onRequestTimeout();
  702. },
  703. onTransportError: function onTransportError() {
  704. _this._eventHandlers.onTransportError();
  705. },
  706. onAuthenticated: function onAuthenticated(request) {
  707. _this._eventHandlers.onAuthenticated(request);
  708. },
  709. onReceiveResponse: function onReceiveResponse(response) {
  710. _this._receiveResponse(response);
  711. }
  712. });
  713. request_sender.send(); // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-.
  714. if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) {
  715. this._dialog.uac_pending_reply = true;
  716. var stateChanged = function stateChanged() {
  717. if (request_sender.clientTransaction.state === Transactions.C.STATUS_ACCEPTED || request_sender.clientTransaction.state === Transactions.C.STATUS_COMPLETED || request_sender.clientTransaction.state === Transactions.C.STATUS_TERMINATED) {
  718. request_sender.clientTransaction.removeListener('stateChanged', stateChanged);
  719. _this._dialog.uac_pending_reply = false;
  720. }
  721. };
  722. request_sender.clientTransaction.on('stateChanged', stateChanged);
  723. }
  724. }
  725. }, {
  726. key: "_receiveResponse",
  727. value: function _receiveResponse(response) {
  728. var _this2 = this;
  729. // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog.
  730. if (response.status_code === 408 || response.status_code === 481) {
  731. this._eventHandlers.onDialogError(response);
  732. } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) {
  733. if (this._reattempt) {
  734. if (response.status_code >= 200 && response.status_code < 300) {
  735. this._eventHandlers.onSuccessResponse(response);
  736. } else if (response.status_code >= 300) {
  737. this._eventHandlers.onErrorResponse(response);
  738. }
  739. } else {
  740. this._request.cseq.value = this._dialog.local_seqnum += 1;
  741. this._reattemptTimer = setTimeout(function () {
  742. // TODO: look at dialog state instead.
  743. if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) {
  744. _this2._reattempt = true;
  745. _this2._request_sender.send();
  746. }
  747. }, 1000);
  748. }
  749. } else if (response.status_code >= 200 && response.status_code < 300) {
  750. this._eventHandlers.onSuccessResponse(response);
  751. } else if (response.status_code >= 300) {
  752. this._eventHandlers.onErrorResponse(response);
  753. }
  754. }
  755. }, {
  756. key: "request",
  757. get: function get() {
  758. return this._request;
  759. }
  760. }]);
  761. return DialogRequestSender;
  762. }();
  763. },{"../Constants":2,"../RTCSession":12,"../RequestSender":18,"../Transactions":22}],5:[function(require,module,exports){
  764. "use strict";
  765. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  766. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  767. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  768. var Utils = require('./Utils');
  769. var debug = require('debug')('JsSIP:DigestAuthentication');
  770. var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication');
  771. debugerror.log = console.warn.bind(console);
  772. module.exports =
  773. /*#__PURE__*/
  774. function () {
  775. function DigestAuthentication(credentials) {
  776. _classCallCheck(this, DigestAuthentication);
  777. this._credentials = credentials;
  778. this._cnonce = null;
  779. this._nc = 0;
  780. this._ncHex = '00000000';
  781. this._algorithm = null;
  782. this._realm = null;
  783. this._nonce = null;
  784. this._opaque = null;
  785. this._stale = null;
  786. this._qop = null;
  787. this._method = null;
  788. this._uri = null;
  789. this._ha1 = null;
  790. this._response = null;
  791. }
  792. _createClass(DigestAuthentication, [{
  793. key: "get",
  794. value: function get(parameter) {
  795. switch (parameter) {
  796. case 'realm':
  797. return this._realm;
  798. case 'ha1':
  799. return this._ha1;
  800. default:
  801. debugerror('get() | cannot get "%s" parameter', parameter);
  802. return undefined;
  803. }
  804. }
  805. /**
  806. * Performs Digest authentication given a SIP request and the challenge
  807. * received in a response to that request.
  808. * Returns true if auth was successfully generated, false otherwise.
  809. */
  810. }, {
  811. key: "authenticate",
  812. value: function authenticate(_ref, challenge)
  813. /* test interface */
  814. {
  815. var method = _ref.method,
  816. ruri = _ref.ruri,
  817. body = _ref.body;
  818. var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  819. this._algorithm = challenge.algorithm;
  820. this._realm = challenge.realm;
  821. this._nonce = challenge.nonce;
  822. this._opaque = challenge.opaque;
  823. this._stale = challenge.stale;
  824. if (this._algorithm) {
  825. if (this._algorithm !== 'MD5') {
  826. debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');
  827. return false;
  828. }
  829. } else {
  830. this._algorithm = 'MD5';
  831. }
  832. if (!this._nonce) {
  833. debugerror('authenticate() | challenge without Digest nonce, authentication aborted');
  834. return false;
  835. }
  836. if (!this._realm) {
  837. debugerror('authenticate() | challenge without Digest realm, authentication aborted');
  838. return false;
  839. } // If no plain SIP password is provided.
  840. if (!this._credentials.password) {
  841. // If ha1 is not provided we cannot authenticate.
  842. if (!this._credentials.ha1) {
  843. debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted');
  844. return false;
  845. } // If the realm does not match the stored realm we cannot authenticate.
  846. if (this._credentials.realm !== this._realm) {
  847. 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);
  848. return false;
  849. }
  850. } // 'qop' can contain a list of values (Array). Let's choose just one.
  851. if (challenge.qop) {
  852. if (challenge.qop.indexOf('auth-int') > -1) {
  853. this._qop = 'auth-int';
  854. } else if (challenge.qop.indexOf('auth') > -1) {
  855. this._qop = 'auth';
  856. } else {
  857. // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here.
  858. debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');
  859. return false;
  860. }
  861. } else {
  862. this._qop = null;
  863. } // Fill other attributes.
  864. this._method = method;
  865. this._uri = ruri;
  866. this._cnonce = cnonce || Utils.createRandomToken(12);
  867. this._nc += 1;
  868. var hex = Number(this._nc).toString(16);
  869. this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex; // Nc-value = 8LHEX. Max value = 'FFFFFFFF'.
  870. if (this._nc === 4294967296) {
  871. this._nc = 1;
  872. this._ncHex = '00000001';
  873. } // Calculate the Digest "response" value.
  874. // If we have plain SIP password then regenerate ha1.
  875. if (this._credentials.password) {
  876. // HA1 = MD5(A1) = MD5(username:realm:password).
  877. this._ha1 = Utils.calculateMD5("".concat(this._credentials.username, ":").concat(this._realm, ":").concat(this._credentials.password));
  878. } // Otherwise reuse the stored ha1.
  879. else {
  880. this._ha1 = this._credentials.ha1;
  881. }
  882. var a2;
  883. var ha2;
  884. if (this._qop === 'auth') {
  885. // HA2 = MD5(A2) = MD5(method:digestURI).
  886. a2 = "".concat(this._method, ":").concat(this._uri);
  887. ha2 = Utils.calculateMD5(a2);
  888. debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
  889. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2));
  890. } else if (this._qop === 'auth-int') {
  891. // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)).
  892. a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : ''));
  893. ha2 = Utils.calculateMD5(a2);
  894. debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
  895. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2));
  896. } else if (this._qop === null) {
  897. // HA2 = MD5(A2) = MD5(method:digestURI).
  898. a2 = "".concat(this._method, ":").concat(this._uri);
  899. ha2 = Utils.calculateMD5(a2);
  900. debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2).
  901. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2));
  902. }
  903. debug('authenticate() | response generated');
  904. return true;
  905. }
  906. /**
  907. * Return the Proxy-Authorization or WWW-Authorization header value.
  908. */
  909. }, {
  910. key: "toString",
  911. value: function toString() {
  912. var auth_params = [];
  913. if (!this._response) {
  914. throw new Error('response field does not exist, cannot generate Authorization header');
  915. }
  916. auth_params.push("algorithm=".concat(this._algorithm));
  917. auth_params.push("username=\"".concat(this._credentials.username, "\""));
  918. auth_params.push("realm=\"".concat(this._realm, "\""));
  919. auth_params.push("nonce=\"".concat(this._nonce, "\""));
  920. auth_params.push("uri=\"".concat(this._uri, "\""));
  921. auth_params.push("response=\"".concat(this._response, "\""));
  922. if (this._opaque) {
  923. auth_params.push("opaque=\"".concat(this._opaque, "\""));
  924. }
  925. if (this._qop) {
  926. auth_params.push("qop=".concat(this._qop));
  927. auth_params.push("cnonce=\"".concat(this._cnonce, "\""));
  928. auth_params.push("nc=".concat(this._ncHex));
  929. }
  930. return "Digest ".concat(auth_params.join(', '));
  931. }
  932. }]);
  933. return DigestAuthentication;
  934. }();
  935. },{"./Utils":26,"debug":30}],6:[function(require,module,exports){
  936. "use strict";
  937. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  938. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  939. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  940. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  941. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  942. function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
  943. function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  944. function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
  945. function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
  946. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  947. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  948. var ConfigurationError =
  949. /*#__PURE__*/
  950. function (_Error) {
  951. _inherits(ConfigurationError, _Error);
  952. function ConfigurationError(parameter, value) {
  953. var _this;
  954. _classCallCheck(this, ConfigurationError);
  955. _this = _possibleConstructorReturn(this, _getPrototypeOf(ConfigurationError).call(this));
  956. _this.code = 1;
  957. _this.name = 'CONFIGURATION_ERROR';
  958. _this.parameter = parameter;
  959. _this.value = value;
  960. _this.message = !_this.value ? "Missing parameter: ".concat(_this.parameter) : "Invalid value ".concat(JSON.stringify(_this.value), " for parameter \"").concat(_this.parameter, "\"");
  961. return _this;
  962. }
  963. return ConfigurationError;
  964. }(_wrapNativeSuper(Error));
  965. var InvalidStateError =
  966. /*#__PURE__*/
  967. function (_Error2) {
  968. _inherits(InvalidStateError, _Error2);
  969. function InvalidStateError(status) {
  970. var _this2;
  971. _classCallCheck(this, InvalidStateError);
  972. _this2 = _possibleConstructorReturn(this, _getPrototypeOf(InvalidStateError).call(this));
  973. _this2.code = 2;
  974. _this2.name = 'INVALID_STATE_ERROR';
  975. _this2.status = status;
  976. _this2.message = "Invalid status: ".concat(status);
  977. return _this2;
  978. }
  979. return InvalidStateError;
  980. }(_wrapNativeSuper(Error));
  981. var NotSupportedError =
  982. /*#__PURE__*/
  983. function (_Error3) {
  984. _inherits(NotSupportedError, _Error3);
  985. function NotSupportedError(message) {
  986. var _this3;
  987. _classCallCheck(this, NotSupportedError);
  988. _this3 = _possibleConstructorReturn(this, _getPrototypeOf(NotSupportedError).call(this));
  989. _this3.code = 3;
  990. _this3.name = 'NOT_SUPPORTED_ERROR';
  991. _this3.message = message;
  992. return _this3;
  993. }
  994. return NotSupportedError;
  995. }(_wrapNativeSuper(Error));
  996. var NotReadyError =
  997. /*#__PURE__*/
  998. function (_Error4) {
  999. _inherits(NotReadyError, _Error4);
  1000. function NotReadyError(message) {
  1001. var _this4;
  1002. _classCallCheck(this, NotReadyError);
  1003. _this4 = _possibleConstructorReturn(this, _getPrototypeOf(NotReadyError).call(this));
  1004. _this4.code = 4;
  1005. _this4.name = 'NOT_READY_ERROR';
  1006. _this4.message = message;
  1007. return _this4;
  1008. }
  1009. return NotReadyError;
  1010. }(_wrapNativeSuper(Error));
  1011. module.exports = {
  1012. ConfigurationError: ConfigurationError,
  1013. InvalidStateError: InvalidStateError,
  1014. NotSupportedError: NotSupportedError,
  1015. NotReadyError: NotReadyError
  1016. };
  1017. },{}],7:[function(require,module,exports){
  1018. "use strict";
  1019. module.exports = function () {
  1020. /*
  1021. * Generated by PEG.js 0.7.0.
  1022. *
  1023. * http://pegjs.majda.cz/
  1024. */
  1025. function quote(s) {
  1026. /*
  1027. * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
  1028. * string literal except for the closing quote character, backslash,
  1029. * carriage return, line separator, paragraph separator, and line feed.
  1030. * Any character may appear in the form of an escape sequence.
  1031. *
  1032. * For portability, we also escape escape all control and non-ASCII
  1033. * characters. Note that "\0" and "\v" escape sequences are not used
  1034. * because JSHint does not like the first and IE the second.
  1035. */
  1036. return '"' + s.replace(/\\/g, '\\\\') // backslash
  1037. .replace(/"/g, '\\"') // closing quote character
  1038. .replace(/\x08/g, '\\b') // backspace
  1039. .replace(/\t/g, '\\t') // horizontal tab
  1040. .replace(/\n/g, '\\n') // line feed
  1041. .replace(/\f/g, '\\f') // form feed
  1042. .replace(/\r/g, '\\r') // carriage return
  1043. .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"';
  1044. }
  1045. var result = {
  1046. /*
  1047. * Parses the input with a generated parser. If the parsing is successfull,
  1048. * returns a value explicitly or implicitly specified by the grammar from
  1049. * which the parser was generated (see |PEG.buildParser|). If the parsing is
  1050. * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
  1051. */
  1052. parse: function parse(input, startRule) {
  1053. var parseFunctions = {
  1054. "CRLF": parse_CRLF,
  1055. "DIGIT": parse_DIGIT,
  1056. "ALPHA": parse_ALPHA,
  1057. "HEXDIG": parse_HEXDIG,
  1058. "WSP": parse_WSP,
  1059. "OCTET": parse_OCTET,
  1060. "DQUOTE": parse_DQUOTE,
  1061. "SP": parse_SP,
  1062. "HTAB": parse_HTAB,
  1063. "alphanum": parse_alphanum,
  1064. "reserved": parse_reserved,
  1065. "unreserved": parse_unreserved,
  1066. "mark": parse_mark,
  1067. "escaped": parse_escaped,
  1068. "LWS": parse_LWS,
  1069. "SWS": parse_SWS,
  1070. "HCOLON": parse_HCOLON,
  1071. "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM,
  1072. "TEXT_UTF8char": parse_TEXT_UTF8char,
  1073. "UTF8_NONASCII": parse_UTF8_NONASCII,
  1074. "UTF8_CONT": parse_UTF8_CONT,
  1075. "LHEX": parse_LHEX,
  1076. "token": parse_token,
  1077. "token_nodot": parse_token_nodot,
  1078. "separators": parse_separators,
  1079. "word": parse_word,
  1080. "STAR": parse_STAR,
  1081. "SLASH": parse_SLASH,
  1082. "EQUAL": parse_EQUAL,
  1083. "LPAREN": parse_LPAREN,
  1084. "RPAREN": parse_RPAREN,
  1085. "RAQUOT": parse_RAQUOT,
  1086. "LAQUOT": parse_LAQUOT,
  1087. "COMMA": parse_COMMA,
  1088. "SEMI": parse_SEMI,
  1089. "COLON": parse_COLON,
  1090. "LDQUOT": parse_LDQUOT,
  1091. "RDQUOT": parse_RDQUOT,
  1092. "comment": parse_comment,
  1093. "ctext": parse_ctext,
  1094. "quoted_string": parse_quoted_string,
  1095. "quoted_string_clean": parse_quoted_string_clean,
  1096. "qdtext": parse_qdtext,
  1097. "quoted_pair": parse_quoted_pair,
  1098. "SIP_URI_noparams": parse_SIP_URI_noparams,
  1099. "SIP_URI": parse_SIP_URI,
  1100. "uri_scheme": parse_uri_scheme,
  1101. "uri_scheme_sips": parse_uri_scheme_sips,
  1102. "uri_scheme_sip": parse_uri_scheme_sip,
  1103. "userinfo": parse_userinfo,
  1104. "user": parse_user,
  1105. "user_unreserved": parse_user_unreserved,
  1106. "password": parse_password,
  1107. "hostport": parse_hostport,
  1108. "host": parse_host,
  1109. "hostname": parse_hostname,
  1110. "domainlabel": parse_domainlabel,
  1111. "toplabel": parse_toplabel,
  1112. "IPv6reference": parse_IPv6reference,
  1113. "IPv6address": parse_IPv6address,
  1114. "h16": parse_h16,
  1115. "ls32": parse_ls32,
  1116. "IPv4address": parse_IPv4address,
  1117. "dec_octet": parse_dec_octet,
  1118. "port": parse_port,
  1119. "uri_parameters": parse_uri_parameters,
  1120. "uri_parameter": parse_uri_parameter,
  1121. "transport_param": parse_transport_param,
  1122. "user_param": parse_user_param,
  1123. "method_param": parse_method_param,
  1124. "ttl_param": parse_ttl_param,
  1125. "maddr_param": parse_maddr_param,
  1126. "lr_param": parse_lr_param,
  1127. "other_param": parse_other_param,
  1128. "pname": parse_pname,
  1129. "pvalue": parse_pvalue,
  1130. "paramchar": parse_paramchar,
  1131. "param_unreserved": parse_param_unreserved,
  1132. "headers": parse_headers,
  1133. "header": parse_header,
  1134. "hname": parse_hname,
  1135. "hvalue": parse_hvalue,
  1136. "hnv_unreserved": parse_hnv_unreserved,
  1137. "Request_Response": parse_Request_Response,
  1138. "Request_Line": parse_Request_Line,
  1139. "Request_URI": parse_Request_URI,
  1140. "absoluteURI": parse_absoluteURI,
  1141. "hier_part": parse_hier_part,
  1142. "net_path": parse_net_path,
  1143. "abs_path": parse_abs_path,
  1144. "opaque_part": parse_opaque_part,
  1145. "uric": parse_uric,
  1146. "uric_no_slash": parse_uric_no_slash,
  1147. "path_segments": parse_path_segments,
  1148. "segment": parse_segment,
  1149. "param": parse_param,
  1150. "pchar": parse_pchar,
  1151. "scheme": parse_scheme,
  1152. "authority": parse_authority,
  1153. "srvr": parse_srvr,
  1154. "reg_name": parse_reg_name,
  1155. "query": parse_query,
  1156. "SIP_Version": parse_SIP_Version,
  1157. "INVITEm": parse_INVITEm,
  1158. "ACKm": parse_ACKm,
  1159. "OPTIONSm": parse_OPTIONSm,
  1160. "BYEm": parse_BYEm,
  1161. "CANCELm": parse_CANCELm,
  1162. "REGISTERm": parse_REGISTERm,
  1163. "SUBSCRIBEm": parse_SUBSCRIBEm,
  1164. "NOTIFYm": parse_NOTIFYm,
  1165. "REFERm": parse_REFERm,
  1166. "Method": parse_Method,
  1167. "Status_Line": parse_Status_Line,
  1168. "Status_Code": parse_Status_Code,
  1169. "extension_code": parse_extension_code,
  1170. "Reason_Phrase": parse_Reason_Phrase,
  1171. "Allow_Events": parse_Allow_Events,
  1172. "Call_ID": parse_Call_ID,
  1173. "Contact": parse_Contact,
  1174. "contact_param": parse_contact_param,
  1175. "name_addr": parse_name_addr,
  1176. "display_name": parse_display_name,
  1177. "contact_params": parse_contact_params,
  1178. "c_p_q": parse_c_p_q,
  1179. "c_p_expires": parse_c_p_expires,
  1180. "delta_seconds": parse_delta_seconds,
  1181. "qvalue": parse_qvalue,
  1182. "generic_param": parse_generic_param,
  1183. "gen_value": parse_gen_value,
  1184. "Content_Disposition": parse_Content_Disposition,
  1185. "disp_type": parse_disp_type,
  1186. "disp_param": parse_disp_param,
  1187. "handling_param": parse_handling_param,
  1188. "Content_Encoding": parse_Content_Encoding,
  1189. "Content_Length": parse_Content_Length,
  1190. "Content_Type": parse_Content_Type,
  1191. "media_type": parse_media_type,
  1192. "m_type": parse_m_type,
  1193. "discrete_type": parse_discrete_type,
  1194. "composite_type": parse_composite_type,
  1195. "extension_token": parse_extension_token,
  1196. "x_token": parse_x_token,
  1197. "m_subtype": parse_m_subtype,
  1198. "m_parameter": parse_m_parameter,
  1199. "m_value": parse_m_value,
  1200. "CSeq": parse_CSeq,
  1201. "CSeq_value": parse_CSeq_value,
  1202. "Expires": parse_Expires,
  1203. "Event": parse_Event,
  1204. "event_type": parse_event_type,
  1205. "From": parse_From,
  1206. "from_param": parse_from_param,
  1207. "tag_param": parse_tag_param,
  1208. "Max_Forwards": parse_Max_Forwards,
  1209. "Min_Expires": parse_Min_Expires,
  1210. "Name_Addr_Header": parse_Name_Addr_Header,
  1211. "Proxy_Authenticate": parse_Proxy_Authenticate,
  1212. "challenge": parse_challenge,
  1213. "other_challenge": parse_other_challenge,
  1214. "auth_param": parse_auth_param,
  1215. "digest_cln": parse_digest_cln,
  1216. "realm": parse_realm,
  1217. "realm_value": parse_realm_value,
  1218. "domain": parse_domain,
  1219. "URI": parse_URI,
  1220. "nonce": parse_nonce,
  1221. "nonce_value": parse_nonce_value,
  1222. "opaque": parse_opaque,
  1223. "stale": parse_stale,
  1224. "algorithm": parse_algorithm,
  1225. "qop_options": parse_qop_options,
  1226. "qop_value": parse_qop_value,
  1227. "Proxy_Require": parse_Proxy_Require,
  1228. "Record_Route": parse_Record_Route,
  1229. "rec_route": parse_rec_route,
  1230. "Reason": parse_Reason,
  1231. "reason_param": parse_reason_param,
  1232. "reason_cause": parse_reason_cause,
  1233. "Require": parse_Require,
  1234. "Route": parse_Route,
  1235. "route_param": parse_route_param,
  1236. "Subscription_State": parse_Subscription_State,
  1237. "substate_value": parse_substate_value,
  1238. "subexp_params": parse_subexp_params,
  1239. "event_reason_value": parse_event_reason_value,
  1240. "Subject": parse_Subject,
  1241. "Supported": parse_Supported,
  1242. "To": parse_To,
  1243. "to_param": parse_to_param,
  1244. "Via": parse_Via,
  1245. "via_param": parse_via_param,
  1246. "via_params": parse_via_params,
  1247. "via_ttl": parse_via_ttl,
  1248. "via_maddr": parse_via_maddr,
  1249. "via_received": parse_via_received,
  1250. "via_branch": parse_via_branch,
  1251. "response_port": parse_response_port,
  1252. "sent_protocol": parse_sent_protocol,
  1253. "protocol_name": parse_protocol_name,
  1254. "transport": parse_transport,
  1255. "sent_by": parse_sent_by,
  1256. "via_host": parse_via_host,
  1257. "via_port": parse_via_port,
  1258. "ttl": parse_ttl,
  1259. "WWW_Authenticate": parse_WWW_Authenticate,
  1260. "Session_Expires": parse_Session_Expires,
  1261. "s_e_expires": parse_s_e_expires,
  1262. "s_e_params": parse_s_e_params,
  1263. "s_e_refresher": parse_s_e_refresher,
  1264. "extension_header": parse_extension_header,
  1265. "header_value": parse_header_value,
  1266. "message_body": parse_message_body,
  1267. "uuid_URI": parse_uuid_URI,
  1268. "uuid": parse_uuid,
  1269. "hex4": parse_hex4,
  1270. "hex8": parse_hex8,
  1271. "hex12": parse_hex12,
  1272. "Refer_To": parse_Refer_To,
  1273. "Replaces": parse_Replaces,
  1274. "call_id": parse_call_id,
  1275. "replaces_param": parse_replaces_param,
  1276. "to_tag": parse_to_tag,
  1277. "from_tag": parse_from_tag,
  1278. "early_flag": parse_early_flag
  1279. };
  1280. if (startRule !== undefined) {
  1281. if (parseFunctions[startRule] === undefined) {
  1282. throw new Error("Invalid rule name: " + quote(startRule) + ".");
  1283. }
  1284. } else {
  1285. startRule = "CRLF";
  1286. }
  1287. var pos = 0;
  1288. var reportFailures = 0;
  1289. var rightmostFailuresPos = 0;
  1290. var rightmostFailuresExpected = [];
  1291. function padLeft(input, padding, length) {
  1292. var result = input;
  1293. var padLength = length - input.length;
  1294. for (var i = 0; i < padLength; i++) {
  1295. result = padding + result;
  1296. }
  1297. return result;
  1298. }
  1299. function escape(ch) {
  1300. var charCode = ch.charCodeAt(0);
  1301. var escapeChar;
  1302. var length;
  1303. if (charCode <= 0xFF) {
  1304. escapeChar = 'x';
  1305. length = 2;
  1306. } else {
  1307. escapeChar = 'u';
  1308. length = 4;
  1309. }
  1310. return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
  1311. }
  1312. function matchFailed(failure) {
  1313. if (pos < rightmostFailuresPos) {
  1314. return;
  1315. }
  1316. if (pos > rightmostFailuresPos) {
  1317. rightmostFailuresPos = pos;
  1318. rightmostFailuresExpected = [];
  1319. }
  1320. rightmostFailuresExpected.push(failure);
  1321. }
  1322. function parse_CRLF() {
  1323. var result0;
  1324. if (input.substr(pos, 2) === "\r\n") {
  1325. result0 = "\r\n";
  1326. pos += 2;
  1327. } else {
  1328. result0 = null;
  1329. if (reportFailures === 0) {
  1330. matchFailed("\"\\r\\n\"");
  1331. }
  1332. }
  1333. return result0;
  1334. }
  1335. function parse_DIGIT() {
  1336. var result0;
  1337. if (/^[0-9]/.test(input.charAt(pos))) {
  1338. result0 = input.charAt(pos);
  1339. pos++;
  1340. } else {
  1341. result0 = null;
  1342. if (reportFailures === 0) {
  1343. matchFailed("[0-9]");
  1344. }
  1345. }
  1346. return result0;
  1347. }
  1348. function parse_ALPHA() {
  1349. var result0;
  1350. if (/^[a-zA-Z]/.test(input.charAt(pos))) {
  1351. result0 = input.charAt(pos);
  1352. pos++;
  1353. } else {
  1354. result0 = null;
  1355. if (reportFailures === 0) {
  1356. matchFailed("[a-zA-Z]");
  1357. }
  1358. }
  1359. return result0;
  1360. }
  1361. function parse_HEXDIG() {
  1362. var result0;
  1363. if (/^[0-9a-fA-F]/.test(input.charAt(pos))) {
  1364. result0 = input.charAt(pos);
  1365. pos++;
  1366. } else {
  1367. result0 = null;
  1368. if (reportFailures === 0) {
  1369. matchFailed("[0-9a-fA-F]");
  1370. }
  1371. }
  1372. return result0;
  1373. }
  1374. function parse_WSP() {
  1375. var result0;
  1376. result0 = parse_SP();
  1377. if (result0 === null) {
  1378. result0 = parse_HTAB();
  1379. }
  1380. return result0;
  1381. }
  1382. function parse_OCTET() {
  1383. var result0;
  1384. if (/^[\0-\xFF]/.test(input.charAt(pos))) {
  1385. result0 = input.charAt(pos);
  1386. pos++;
  1387. } else {
  1388. result0 = null;
  1389. if (reportFailures === 0) {
  1390. matchFailed("[\\0-\\xFF]");
  1391. }
  1392. }
  1393. return result0;
  1394. }
  1395. function parse_DQUOTE() {
  1396. var result0;
  1397. if (/^["]/.test(input.charAt(pos))) {
  1398. result0 = input.charAt(pos);
  1399. pos++;
  1400. } else {
  1401. result0 = null;
  1402. if (reportFailures === 0) {
  1403. matchFailed("[\"]");
  1404. }
  1405. }
  1406. return result0;
  1407. }
  1408. function parse_SP() {
  1409. var result0;
  1410. if (input.charCodeAt(pos) === 32) {
  1411. result0 = " ";
  1412. pos++;
  1413. } else {
  1414. result0 = null;
  1415. if (reportFailures === 0) {
  1416. matchFailed("\" \"");
  1417. }
  1418. }
  1419. return result0;
  1420. }
  1421. function parse_HTAB() {
  1422. var result0;
  1423. if (input.charCodeAt(pos) === 9) {
  1424. result0 = "\t";
  1425. pos++;
  1426. } else {
  1427. result0 = null;
  1428. if (reportFailures === 0) {
  1429. matchFailed("\"\\t\"");
  1430. }
  1431. }
  1432. return result0;
  1433. }
  1434. function parse_alphanum() {
  1435. var result0;
  1436. if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) {
  1437. result0 = input.charAt(pos);
  1438. pos++;
  1439. } else {
  1440. result0 = null;
  1441. if (reportFailures === 0) {
  1442. matchFailed("[a-zA-Z0-9]");
  1443. }
  1444. }
  1445. return result0;
  1446. }
  1447. function parse_reserved() {
  1448. var result0;
  1449. if (input.charCodeAt(pos) === 59) {
  1450. result0 = ";";
  1451. pos++;
  1452. } else {
  1453. result0 = null;
  1454. if (reportFailures === 0) {
  1455. matchFailed("\";\"");
  1456. }
  1457. }
  1458. if (result0 === null) {
  1459. if (input.charCodeAt(pos) === 47) {
  1460. result0 = "/";
  1461. pos++;
  1462. } else {
  1463. result0 = null;
  1464. if (reportFailures === 0) {
  1465. matchFailed("\"/\"");
  1466. }
  1467. }
  1468. if (result0 === null) {
  1469. if (input.charCodeAt(pos) === 63) {
  1470. result0 = "?";
  1471. pos++;
  1472. } else {
  1473. result0 = null;
  1474. if (reportFailures === 0) {
  1475. matchFailed("\"?\"");
  1476. }
  1477. }
  1478. if (result0 === null) {
  1479. if (input.charCodeAt(pos) === 58) {
  1480. result0 = ":";
  1481. pos++;
  1482. } else {
  1483. result0 = null;
  1484. if (reportFailures === 0) {
  1485. matchFailed("\":\"");
  1486. }
  1487. }
  1488. if (result0 === null) {
  1489. if (input.charCodeAt(pos) === 64) {
  1490. result0 = "@";
  1491. pos++;
  1492. } else {
  1493. result0 = null;
  1494. if (reportFailures === 0) {
  1495. matchFailed("\"@\"");
  1496. }
  1497. }
  1498. if (result0 === null) {
  1499. if (input.charCodeAt(pos) === 38) {
  1500. result0 = "&";
  1501. pos++;
  1502. } else {
  1503. result0 = null;
  1504. if (reportFailures === 0) {
  1505. matchFailed("\"&\"");
  1506. }
  1507. }
  1508. if (result0 === null) {
  1509. if (input.charCodeAt(pos) === 61) {
  1510. result0 = "=";
  1511. pos++;
  1512. } else {
  1513. result0 = null;
  1514. if (reportFailures === 0) {
  1515. matchFailed("\"=\"");
  1516. }
  1517. }
  1518. if (result0 === null) {
  1519. if (input.charCodeAt(pos) === 43) {
  1520. result0 = "+";
  1521. pos++;
  1522. } else {
  1523. result0 = null;
  1524. if (reportFailures === 0) {
  1525. matchFailed("\"+\"");
  1526. }
  1527. }
  1528. if (result0 === null) {
  1529. if (input.charCodeAt(pos) === 36) {
  1530. result0 = "$";
  1531. pos++;
  1532. } else {
  1533. result0 = null;
  1534. if (reportFailures === 0) {
  1535. matchFailed("\"$\"");
  1536. }
  1537. }
  1538. if (result0 === null) {
  1539. if (input.charCodeAt(pos) === 44) {
  1540. result0 = ",";
  1541. pos++;
  1542. } else {
  1543. result0 = null;
  1544. if (reportFailures === 0) {
  1545. matchFailed("\",\"");
  1546. }
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. return result0;
  1558. }
  1559. function parse_unreserved() {
  1560. var result0;
  1561. result0 = parse_alphanum();
  1562. if (result0 === null) {
  1563. result0 = parse_mark();
  1564. }
  1565. return result0;
  1566. }
  1567. function parse_mark() {
  1568. var result0;
  1569. if (input.charCodeAt(pos) === 45) {
  1570. result0 = "-";
  1571. pos++;
  1572. } else {
  1573. result0 = null;
  1574. if (reportFailures === 0) {
  1575. matchFailed("\"-\"");
  1576. }
  1577. }
  1578. if (result0 === null) {
  1579. if (input.charCodeAt(pos) === 95) {
  1580. result0 = "_";
  1581. pos++;
  1582. } else {
  1583. result0 = null;
  1584. if (reportFailures === 0) {
  1585. matchFailed("\"_\"");
  1586. }
  1587. }
  1588. if (result0 === null) {
  1589. if (input.charCodeAt(pos) === 46) {
  1590. result0 = ".";
  1591. pos++;
  1592. } else {
  1593. result0 = null;
  1594. if (reportFailures === 0) {
  1595. matchFailed("\".\"");
  1596. }
  1597. }
  1598. if (result0 === null) {
  1599. if (input.charCodeAt(pos) === 33) {
  1600. result0 = "!";
  1601. pos++;
  1602. } else {
  1603. result0 = null;
  1604. if (reportFailures === 0) {
  1605. matchFailed("\"!\"");
  1606. }
  1607. }
  1608. if (result0 === null) {
  1609. if (input.charCodeAt(pos) === 126) {
  1610. result0 = "~";
  1611. pos++;
  1612. } else {
  1613. result0 = null;
  1614. if (reportFailures === 0) {
  1615. matchFailed("\"~\"");
  1616. }
  1617. }
  1618. if (result0 === null) {
  1619. if (input.charCodeAt(pos) === 42) {
  1620. result0 = "*";
  1621. pos++;
  1622. } else {
  1623. result0 = null;
  1624. if (reportFailures === 0) {
  1625. matchFailed("\"*\"");
  1626. }
  1627. }
  1628. if (result0 === null) {
  1629. if (input.charCodeAt(pos) === 39) {
  1630. result0 = "'";
  1631. pos++;
  1632. } else {
  1633. result0 = null;
  1634. if (reportFailures === 0) {
  1635. matchFailed("\"'\"");
  1636. }
  1637. }
  1638. if (result0 === null) {
  1639. if (input.charCodeAt(pos) === 40) {
  1640. result0 = "(";
  1641. pos++;
  1642. } else {
  1643. result0 = null;
  1644. if (reportFailures === 0) {
  1645. matchFailed("\"(\"");
  1646. }
  1647. }
  1648. if (result0 === null) {
  1649. if (input.charCodeAt(pos) === 41) {
  1650. result0 = ")";
  1651. pos++;
  1652. } else {
  1653. result0 = null;
  1654. if (reportFailures === 0) {
  1655. matchFailed("\")\"");
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. return result0;
  1667. }
  1668. function parse_escaped() {
  1669. var result0, result1, result2;
  1670. var pos0, pos1;
  1671. pos0 = pos;
  1672. pos1 = pos;
  1673. if (input.charCodeAt(pos) === 37) {
  1674. result0 = "%";
  1675. pos++;
  1676. } else {
  1677. result0 = null;
  1678. if (reportFailures === 0) {
  1679. matchFailed("\"%\"");
  1680. }
  1681. }
  1682. if (result0 !== null) {
  1683. result1 = parse_HEXDIG();
  1684. if (result1 !== null) {
  1685. result2 = parse_HEXDIG();
  1686. if (result2 !== null) {
  1687. result0 = [result0, result1, result2];
  1688. } else {
  1689. result0 = null;
  1690. pos = pos1;
  1691. }
  1692. } else {
  1693. result0 = null;
  1694. pos = pos1;
  1695. }
  1696. } else {
  1697. result0 = null;
  1698. pos = pos1;
  1699. }
  1700. if (result0 !== null) {
  1701. result0 = function (offset, escaped) {
  1702. return escaped.join('');
  1703. }(pos0, result0);
  1704. }
  1705. if (result0 === null) {
  1706. pos = pos0;
  1707. }
  1708. return result0;
  1709. }
  1710. function parse_LWS() {
  1711. var result0, result1, result2;
  1712. var pos0, pos1, pos2;
  1713. pos0 = pos;
  1714. pos1 = pos;
  1715. pos2 = pos;
  1716. result0 = [];
  1717. result1 = parse_WSP();
  1718. while (result1 !== null) {
  1719. result0.push(result1);
  1720. result1 = parse_WSP();
  1721. }
  1722. if (result0 !== null) {
  1723. result1 = parse_CRLF();
  1724. if (result1 !== null) {
  1725. result0 = [result0, result1];
  1726. } else {
  1727. result0 = null;
  1728. pos = pos2;
  1729. }
  1730. } else {
  1731. result0 = null;
  1732. pos = pos2;
  1733. }
  1734. result0 = result0 !== null ? result0 : "";
  1735. if (result0 !== null) {
  1736. result2 = parse_WSP();
  1737. if (result2 !== null) {
  1738. result1 = [];
  1739. while (result2 !== null) {
  1740. result1.push(result2);
  1741. result2 = parse_WSP();
  1742. }
  1743. } else {
  1744. result1 = null;
  1745. }
  1746. if (result1 !== null) {
  1747. result0 = [result0, result1];
  1748. } else {
  1749. result0 = null;
  1750. pos = pos1;
  1751. }
  1752. } else {
  1753. result0 = null;
  1754. pos = pos1;
  1755. }
  1756. if (result0 !== null) {
  1757. result0 = function (offset) {
  1758. return " ";
  1759. }(pos0);
  1760. }
  1761. if (result0 === null) {
  1762. pos = pos0;
  1763. }
  1764. return result0;
  1765. }
  1766. function parse_SWS() {
  1767. var result0;
  1768. result0 = parse_LWS();
  1769. result0 = result0 !== null ? result0 : "";
  1770. return result0;
  1771. }
  1772. function parse_HCOLON() {
  1773. var result0, result1, result2;
  1774. var pos0, pos1;
  1775. pos0 = pos;
  1776. pos1 = pos;
  1777. result0 = [];
  1778. result1 = parse_SP();
  1779. if (result1 === null) {
  1780. result1 = parse_HTAB();
  1781. }
  1782. while (result1 !== null) {
  1783. result0.push(result1);
  1784. result1 = parse_SP();
  1785. if (result1 === null) {
  1786. result1 = parse_HTAB();
  1787. }
  1788. }
  1789. if (result0 !== null) {
  1790. if (input.charCodeAt(pos) === 58) {
  1791. result1 = ":";
  1792. pos++;
  1793. } else {
  1794. result1 = null;
  1795. if (reportFailures === 0) {
  1796. matchFailed("\":\"");
  1797. }
  1798. }
  1799. if (result1 !== null) {
  1800. result2 = parse_SWS();
  1801. if (result2 !== null) {
  1802. result0 = [result0, result1, result2];
  1803. } else {
  1804. result0 = null;
  1805. pos = pos1;
  1806. }
  1807. } else {
  1808. result0 = null;
  1809. pos = pos1;
  1810. }
  1811. } else {
  1812. result0 = null;
  1813. pos = pos1;
  1814. }
  1815. if (result0 !== null) {
  1816. result0 = function (offset) {
  1817. return ':';
  1818. }(pos0);
  1819. }
  1820. if (result0 === null) {
  1821. pos = pos0;
  1822. }
  1823. return result0;
  1824. }
  1825. function parse_TEXT_UTF8_TRIM() {
  1826. var result0, result1, result2, result3;
  1827. var pos0, pos1, pos2;
  1828. pos0 = pos;
  1829. pos1 = pos;
  1830. result1 = parse_TEXT_UTF8char();
  1831. if (result1 !== null) {
  1832. result0 = [];
  1833. while (result1 !== null) {
  1834. result0.push(result1);
  1835. result1 = parse_TEXT_UTF8char();
  1836. }
  1837. } else {
  1838. result0 = null;
  1839. }
  1840. if (result0 !== null) {
  1841. result1 = [];
  1842. pos2 = pos;
  1843. result2 = [];
  1844. result3 = parse_LWS();
  1845. while (result3 !== null) {
  1846. result2.push(result3);
  1847. result3 = parse_LWS();
  1848. }
  1849. if (result2 !== null) {
  1850. result3 = parse_TEXT_UTF8char();
  1851. if (result3 !== null) {
  1852. result2 = [result2, result3];
  1853. } else {
  1854. result2 = null;
  1855. pos = pos2;
  1856. }
  1857. } else {
  1858. result2 = null;
  1859. pos = pos2;
  1860. }
  1861. while (result2 !== null) {
  1862. result1.push(result2);
  1863. pos2 = pos;
  1864. result2 = [];
  1865. result3 = parse_LWS();
  1866. while (result3 !== null) {
  1867. result2.push(result3);
  1868. result3 = parse_LWS();
  1869. }
  1870. if (result2 !== null) {
  1871. result3 = parse_TEXT_UTF8char();
  1872. if (result3 !== null) {
  1873. result2 = [result2, result3];
  1874. } else {
  1875. result2 = null;
  1876. pos = pos2;
  1877. }
  1878. } else {
  1879. result2 = null;
  1880. pos = pos2;
  1881. }
  1882. }
  1883. if (result1 !== null) {
  1884. result0 = [result0, result1];
  1885. } else {
  1886. result0 = null;
  1887. pos = pos1;
  1888. }
  1889. } else {
  1890. result0 = null;
  1891. pos = pos1;
  1892. }
  1893. if (result0 !== null) {
  1894. result0 = function (offset) {
  1895. return input.substring(pos, offset);
  1896. }(pos0);
  1897. }
  1898. if (result0 === null) {
  1899. pos = pos0;
  1900. }
  1901. return result0;
  1902. }
  1903. function parse_TEXT_UTF8char() {
  1904. var result0;
  1905. if (/^[!-~]/.test(input.charAt(pos))) {
  1906. result0 = input.charAt(pos);
  1907. pos++;
  1908. } else {
  1909. result0 = null;
  1910. if (reportFailures === 0) {
  1911. matchFailed("[!-~]");
  1912. }
  1913. }
  1914. if (result0 === null) {
  1915. result0 = parse_UTF8_NONASCII();
  1916. }
  1917. return result0;
  1918. }
  1919. function parse_UTF8_NONASCII() {
  1920. var result0;
  1921. if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) {
  1922. result0 = input.charAt(pos);
  1923. pos++;
  1924. } else {
  1925. result0 = null;
  1926. if (reportFailures === 0) {
  1927. matchFailed("[\\x80-\\uFFFF]");
  1928. }
  1929. }
  1930. return result0;
  1931. }
  1932. function parse_UTF8_CONT() {
  1933. var result0;
  1934. if (/^[\x80-\xBF]/.test(input.charAt(pos))) {
  1935. result0 = input.charAt(pos);
  1936. pos++;
  1937. } else {
  1938. result0 = null;
  1939. if (reportFailures === 0) {
  1940. matchFailed("[\\x80-\\xBF]");
  1941. }
  1942. }
  1943. return result0;
  1944. }
  1945. function parse_LHEX() {
  1946. var result0;
  1947. result0 = parse_DIGIT();
  1948. if (result0 === null) {
  1949. if (/^[a-f]/.test(input.charAt(pos))) {
  1950. result0 = input.charAt(pos);
  1951. pos++;
  1952. } else {
  1953. result0 = null;
  1954. if (reportFailures === 0) {
  1955. matchFailed("[a-f]");
  1956. }
  1957. }
  1958. }
  1959. return result0;
  1960. }
  1961. function parse_token() {
  1962. var result0, result1;
  1963. var pos0;
  1964. pos0 = pos;
  1965. result1 = parse_alphanum();
  1966. if (result1 === null) {
  1967. if (input.charCodeAt(pos) === 45) {
  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) === 46) {
  1978. result1 = ".";
  1979. pos++;
  1980. } else {
  1981. result1 = null;
  1982. if (reportFailures === 0) {
  1983. matchFailed("\".\"");
  1984. }
  1985. }
  1986. if (result1 === null) {
  1987. if (input.charCodeAt(pos) === 33) {
  1988. result1 = "!";
  1989. pos++;
  1990. } else {
  1991. result1 = null;
  1992. if (reportFailures === 0) {
  1993. matchFailed("\"!\"");
  1994. }
  1995. }
  1996. if (result1 === null) {
  1997. if (input.charCodeAt(pos) === 37) {
  1998. result1 = "%";
  1999. pos++;
  2000. } else {
  2001. result1 = null;
  2002. if (reportFailures === 0) {
  2003. matchFailed("\"%\"");
  2004. }
  2005. }
  2006. if (result1 === null) {
  2007. if (input.charCodeAt(pos) === 42) {
  2008. result1 = "*";
  2009. pos++;
  2010. } else {
  2011. result1 = null;
  2012. if (reportFailures === 0) {
  2013. matchFailed("\"*\"");
  2014. }
  2015. }
  2016. if (result1 === null) {
  2017. if (input.charCodeAt(pos) === 95) {
  2018. result1 = "_";
  2019. pos++;
  2020. } else {
  2021. result1 = null;
  2022. if (reportFailures === 0) {
  2023. matchFailed("\"_\"");
  2024. }
  2025. }
  2026. if (result1 === null) {
  2027. if (input.charCodeAt(pos) === 43) {
  2028. result1 = "+";
  2029. pos++;
  2030. } else {
  2031. result1 = null;
  2032. if (reportFailures === 0) {
  2033. matchFailed("\"+\"");
  2034. }
  2035. }
  2036. if (result1 === null) {
  2037. if (input.charCodeAt(pos) === 96) {
  2038. result1 = "`";
  2039. pos++;
  2040. } else {
  2041. result1 = null;
  2042. if (reportFailures === 0) {
  2043. matchFailed("\"`\"");
  2044. }
  2045. }
  2046. if (result1 === null) {
  2047. if (input.charCodeAt(pos) === 39) {
  2048. result1 = "'";
  2049. pos++;
  2050. } else {
  2051. result1 = null;
  2052. if (reportFailures === 0) {
  2053. matchFailed("\"'\"");
  2054. }
  2055. }
  2056. if (result1 === null) {
  2057. if (input.charCodeAt(pos) === 126) {
  2058. result1 = "~";
  2059. pos++;
  2060. } else {
  2061. result1 = null;
  2062. if (reportFailures === 0) {
  2063. matchFailed("\"~\"");
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. }
  2073. }
  2074. }
  2075. }
  2076. if (result1 !== null) {
  2077. result0 = [];
  2078. while (result1 !== null) {
  2079. result0.push(result1);
  2080. result1 = parse_alphanum();
  2081. if (result1 === null) {
  2082. if (input.charCodeAt(pos) === 45) {
  2083. result1 = "-";
  2084. pos++;
  2085. } else {
  2086. result1 = null;
  2087. if (reportFailures === 0) {
  2088. matchFailed("\"-\"");
  2089. }
  2090. }
  2091. if (result1 === null) {
  2092. if (input.charCodeAt(pos) === 46) {
  2093. result1 = ".";
  2094. pos++;
  2095. } else {
  2096. result1 = null;
  2097. if (reportFailures === 0) {
  2098. matchFailed("\".\"");
  2099. }
  2100. }
  2101. if (result1 === null) {
  2102. if (input.charCodeAt(pos) === 33) {
  2103. result1 = "!";
  2104. pos++;
  2105. } else {
  2106. result1 = null;
  2107. if (reportFailures === 0) {
  2108. matchFailed("\"!\"");
  2109. }
  2110. }
  2111. if (result1 === null) {
  2112. if (input.charCodeAt(pos) === 37) {
  2113. result1 = "%";
  2114. pos++;
  2115. } else {
  2116. result1 = null;
  2117. if (reportFailures === 0) {
  2118. matchFailed("\"%\"");
  2119. }
  2120. }
  2121. if (result1 === null) {
  2122. if (input.charCodeAt(pos) === 42) {
  2123. result1 = "*";
  2124. pos++;
  2125. } else {
  2126. result1 = null;
  2127. if (reportFailures === 0) {
  2128. matchFailed("\"*\"");
  2129. }
  2130. }
  2131. if (result1 === null) {
  2132. if (input.charCodeAt(pos) === 95) {
  2133. result1 = "_";
  2134. pos++;
  2135. } else {
  2136. result1 = null;
  2137. if (reportFailures === 0) {
  2138. matchFailed("\"_\"");
  2139. }
  2140. }
  2141. if (result1 === null) {
  2142. if (input.charCodeAt(pos) === 43) {
  2143. result1 = "+";
  2144. pos++;
  2145. } else {
  2146. result1 = null;
  2147. if (reportFailures === 0) {
  2148. matchFailed("\"+\"");
  2149. }
  2150. }
  2151. if (result1 === null) {
  2152. if (input.charCodeAt(pos) === 96) {
  2153. result1 = "`";
  2154. pos++;
  2155. } else {
  2156. result1 = null;
  2157. if (reportFailures === 0) {
  2158. matchFailed("\"`\"");
  2159. }
  2160. }
  2161. if (result1 === null) {
  2162. if (input.charCodeAt(pos) === 39) {
  2163. result1 = "'";
  2164. pos++;
  2165. } else {
  2166. result1 = null;
  2167. if (reportFailures === 0) {
  2168. matchFailed("\"'\"");
  2169. }
  2170. }
  2171. if (result1 === null) {
  2172. if (input.charCodeAt(pos) === 126) {
  2173. result1 = "~";
  2174. pos++;
  2175. } else {
  2176. result1 = null;
  2177. if (reportFailures === 0) {
  2178. matchFailed("\"~\"");
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. }
  2192. } else {
  2193. result0 = null;
  2194. }
  2195. if (result0 !== null) {
  2196. result0 = function (offset) {
  2197. return input.substring(pos, offset);
  2198. }(pos0);
  2199. }
  2200. if (result0 === null) {
  2201. pos = pos0;
  2202. }
  2203. return result0;
  2204. }
  2205. function parse_token_nodot() {
  2206. var result0, result1;
  2207. var pos0;
  2208. pos0 = pos;
  2209. result1 = parse_alphanum();
  2210. if (result1 === null) {
  2211. if (input.charCodeAt(pos) === 45) {
  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. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. if (result1 !== null) {
  2310. result0 = [];
  2311. while (result1 !== null) {
  2312. result0.push(result1);
  2313. result1 = parse_alphanum();
  2314. if (result1 === null) {
  2315. if (input.charCodeAt(pos) === 45) {
  2316. result1 = "-";
  2317. pos++;
  2318. } else {
  2319. result1 = null;
  2320. if (reportFailures === 0) {
  2321. matchFailed("\"-\"");
  2322. }
  2323. }
  2324. if (result1 === null) {
  2325. if (input.charCodeAt(pos) === 33) {
  2326. result1 = "!";
  2327. pos++;
  2328. } else {
  2329. result1 = null;
  2330. if (reportFailures === 0) {
  2331. matchFailed("\"!\"");
  2332. }
  2333. }
  2334. if (result1 === null) {
  2335. if (input.charCodeAt(pos) === 37) {
  2336. result1 = "%";
  2337. pos++;
  2338. } else {
  2339. result1 = null;
  2340. if (reportFailures === 0) {
  2341. matchFailed("\"%\"");
  2342. }
  2343. }
  2344. if (result1 === null) {
  2345. if (input.charCodeAt(pos) === 42) {
  2346. result1 = "*";
  2347. pos++;
  2348. } else {
  2349. result1 = null;
  2350. if (reportFailures === 0) {
  2351. matchFailed("\"*\"");
  2352. }
  2353. }
  2354. if (result1 === null) {
  2355. if (input.charCodeAt(pos) === 95) {
  2356. result1 = "_";
  2357. pos++;
  2358. } else {
  2359. result1 = null;
  2360. if (reportFailures === 0) {
  2361. matchFailed("\"_\"");
  2362. }
  2363. }
  2364. if (result1 === null) {
  2365. if (input.charCodeAt(pos) === 43) {
  2366. result1 = "+";
  2367. pos++;
  2368. } else {
  2369. result1 = null;
  2370. if (reportFailures === 0) {
  2371. matchFailed("\"+\"");
  2372. }
  2373. }
  2374. if (result1 === null) {
  2375. if (input.charCodeAt(pos) === 96) {
  2376. result1 = "`";
  2377. pos++;
  2378. } else {
  2379. result1 = null;
  2380. if (reportFailures === 0) {
  2381. matchFailed("\"`\"");
  2382. }
  2383. }
  2384. if (result1 === null) {
  2385. if (input.charCodeAt(pos) === 39) {
  2386. result1 = "'";
  2387. pos++;
  2388. } else {
  2389. result1 = null;
  2390. if (reportFailures === 0) {
  2391. matchFailed("\"'\"");
  2392. }
  2393. }
  2394. if (result1 === null) {
  2395. if (input.charCodeAt(pos) === 126) {
  2396. result1 = "~";
  2397. pos++;
  2398. } else {
  2399. result1 = null;
  2400. if (reportFailures === 0) {
  2401. matchFailed("\"~\"");
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. } else {
  2415. result0 = null;
  2416. }
  2417. if (result0 !== null) {
  2418. result0 = function (offset) {
  2419. return input.substring(pos, offset);
  2420. }(pos0);
  2421. }
  2422. if (result0 === null) {
  2423. pos = pos0;
  2424. }
  2425. return result0;
  2426. }
  2427. function parse_separators() {
  2428. var result0;
  2429. if (input.charCodeAt(pos) === 40) {
  2430. result0 = "(";
  2431. pos++;
  2432. } else {
  2433. result0 = null;
  2434. if (reportFailures === 0) {
  2435. matchFailed("\"(\"");
  2436. }
  2437. }
  2438. if (result0 === null) {
  2439. if (input.charCodeAt(pos) === 41) {
  2440. result0 = ")";
  2441. pos++;
  2442. } else {
  2443. result0 = null;
  2444. if (reportFailures === 0) {
  2445. matchFailed("\")\"");
  2446. }
  2447. }
  2448. if (result0 === null) {
  2449. if (input.charCodeAt(pos) === 60) {
  2450. result0 = "<";
  2451. pos++;
  2452. } else {
  2453. result0 = null;
  2454. if (reportFailures === 0) {
  2455. matchFailed("\"<\"");
  2456. }
  2457. }
  2458. if (result0 === null) {
  2459. if (input.charCodeAt(pos) === 62) {
  2460. result0 = ">";
  2461. pos++;
  2462. } else {
  2463. result0 = null;
  2464. if (reportFailures === 0) {
  2465. matchFailed("\">\"");
  2466. }
  2467. }
  2468. if (result0 === null) {
  2469. if (input.charCodeAt(pos) === 64) {
  2470. result0 = "@";
  2471. pos++;
  2472. } else {
  2473. result0 = null;
  2474. if (reportFailures === 0) {
  2475. matchFailed("\"@\"");
  2476. }
  2477. }
  2478. if (result0 === null) {
  2479. if (input.charCodeAt(pos) === 44) {
  2480. result0 = ",";
  2481. pos++;
  2482. } else {
  2483. result0 = null;
  2484. if (reportFailures === 0) {
  2485. matchFailed("\",\"");
  2486. }
  2487. }
  2488. if (result0 === null) {
  2489. if (input.charCodeAt(pos) === 59) {
  2490. result0 = ";";
  2491. pos++;
  2492. } else {
  2493. result0 = null;
  2494. if (reportFailures === 0) {
  2495. matchFailed("\";\"");
  2496. }
  2497. }
  2498. if (result0 === null) {
  2499. if (input.charCodeAt(pos) === 58) {
  2500. result0 = ":";
  2501. pos++;
  2502. } else {
  2503. result0 = null;
  2504. if (reportFailures === 0) {
  2505. matchFailed("\":\"");
  2506. }
  2507. }
  2508. if (result0 === null) {
  2509. if (input.charCodeAt(pos) === 92) {
  2510. result0 = "\\";
  2511. pos++;
  2512. } else {
  2513. result0 = null;
  2514. if (reportFailures === 0) {
  2515. matchFailed("\"\\\\\"");
  2516. }
  2517. }
  2518. if (result0 === null) {
  2519. result0 = parse_DQUOTE();
  2520. if (result0 === null) {
  2521. if (input.charCodeAt(pos) === 47) {
  2522. result0 = "/";
  2523. pos++;
  2524. } else {
  2525. result0 = null;
  2526. if (reportFailures === 0) {
  2527. matchFailed("\"/\"");
  2528. }
  2529. }
  2530. if (result0 === null) {
  2531. if (input.charCodeAt(pos) === 91) {
  2532. result0 = "[";
  2533. pos++;
  2534. } else {
  2535. result0 = null;
  2536. if (reportFailures === 0) {
  2537. matchFailed("\"[\"");
  2538. }
  2539. }
  2540. if (result0 === null) {
  2541. if (input.charCodeAt(pos) === 93) {
  2542. result0 = "]";
  2543. pos++;
  2544. } else {
  2545. result0 = null;
  2546. if (reportFailures === 0) {
  2547. matchFailed("\"]\"");
  2548. }
  2549. }
  2550. if (result0 === null) {
  2551. if (input.charCodeAt(pos) === 63) {
  2552. result0 = "?";
  2553. pos++;
  2554. } else {
  2555. result0 = null;
  2556. if (reportFailures === 0) {
  2557. matchFailed("\"?\"");
  2558. }
  2559. }
  2560. if (result0 === null) {
  2561. if (input.charCodeAt(pos) === 61) {
  2562. result0 = "=";
  2563. pos++;
  2564. } else {
  2565. result0 = null;
  2566. if (reportFailures === 0) {
  2567. matchFailed("\"=\"");
  2568. }
  2569. }
  2570. if (result0 === null) {
  2571. if (input.charCodeAt(pos) === 123) {
  2572. result0 = "{";
  2573. pos++;
  2574. } else {
  2575. result0 = null;
  2576. if (reportFailures === 0) {
  2577. matchFailed("\"{\"");
  2578. }
  2579. }
  2580. if (result0 === null) {
  2581. if (input.charCodeAt(pos) === 125) {
  2582. result0 = "}";
  2583. pos++;
  2584. } else {
  2585. result0 = null;
  2586. if (reportFailures === 0) {
  2587. matchFailed("\"}\"");
  2588. }
  2589. }
  2590. if (result0 === null) {
  2591. result0 = parse_SP();
  2592. if (result0 === null) {
  2593. result0 = parse_HTAB();
  2594. }
  2595. }
  2596. }
  2597. }
  2598. }
  2599. }
  2600. }
  2601. }
  2602. }
  2603. }
  2604. }
  2605. }
  2606. }
  2607. }
  2608. }
  2609. }
  2610. }
  2611. }
  2612. return result0;
  2613. }
  2614. function parse_word() {
  2615. var result0, result1;
  2616. var pos0;
  2617. pos0 = pos;
  2618. result1 = parse_alphanum();
  2619. if (result1 === null) {
  2620. if (input.charCodeAt(pos) === 45) {
  2621. result1 = "-";
  2622. pos++;
  2623. } else {
  2624. result1 = null;
  2625. if (reportFailures === 0) {
  2626. matchFailed("\"-\"");
  2627. }
  2628. }
  2629. if (result1 === null) {
  2630. if (input.charCodeAt(pos) === 46) {
  2631. result1 = ".";
  2632. pos++;
  2633. } else {
  2634. result1 = null;
  2635. if (reportFailures === 0) {
  2636. matchFailed("\".\"");
  2637. }
  2638. }
  2639. if (result1 === null) {
  2640. if (input.charCodeAt(pos) === 33) {
  2641. result1 = "!";
  2642. pos++;
  2643. } else {
  2644. result1 = null;
  2645. if (reportFailures === 0) {
  2646. matchFailed("\"!\"");
  2647. }
  2648. }
  2649. if (result1 === null) {
  2650. if (input.charCodeAt(pos) === 37) {
  2651. result1 = "%";
  2652. pos++;
  2653. } else {
  2654. result1 = null;
  2655. if (reportFailures === 0) {
  2656. matchFailed("\"%\"");
  2657. }
  2658. }
  2659. if (result1 === null) {
  2660. if (input.charCodeAt(pos) === 42) {
  2661. result1 = "*";
  2662. pos++;
  2663. } else {
  2664. result1 = null;
  2665. if (reportFailures === 0) {
  2666. matchFailed("\"*\"");
  2667. }
  2668. }
  2669. if (result1 === null) {
  2670. if (input.charCodeAt(pos) === 95) {
  2671. result1 = "_";
  2672. pos++;
  2673. } else {
  2674. result1 = null;
  2675. if (reportFailures === 0) {
  2676. matchFailed("\"_\"");
  2677. }
  2678. }
  2679. if (result1 === null) {
  2680. if (input.charCodeAt(pos) === 43) {
  2681. result1 = "+";
  2682. pos++;
  2683. } else {
  2684. result1 = null;
  2685. if (reportFailures === 0) {
  2686. matchFailed("\"+\"");
  2687. }
  2688. }
  2689. if (result1 === null) {
  2690. if (input.charCodeAt(pos) === 96) {
  2691. result1 = "`";
  2692. pos++;
  2693. } else {
  2694. result1 = null;
  2695. if (reportFailures === 0) {
  2696. matchFailed("\"`\"");
  2697. }
  2698. }
  2699. if (result1 === null) {
  2700. if (input.charCodeAt(pos) === 39) {
  2701. result1 = "'";
  2702. pos++;
  2703. } else {
  2704. result1 = null;
  2705. if (reportFailures === 0) {
  2706. matchFailed("\"'\"");
  2707. }
  2708. }
  2709. if (result1 === null) {
  2710. if (input.charCodeAt(pos) === 126) {
  2711. result1 = "~";
  2712. pos++;
  2713. } else {
  2714. result1 = null;
  2715. if (reportFailures === 0) {
  2716. matchFailed("\"~\"");
  2717. }
  2718. }
  2719. if (result1 === null) {
  2720. if (input.charCodeAt(pos) === 40) {
  2721. result1 = "(";
  2722. pos++;
  2723. } else {
  2724. result1 = null;
  2725. if (reportFailures === 0) {
  2726. matchFailed("\"(\"");
  2727. }
  2728. }
  2729. if (result1 === null) {
  2730. if (input.charCodeAt(pos) === 41) {
  2731. result1 = ")";
  2732. pos++;
  2733. } else {
  2734. result1 = null;
  2735. if (reportFailures === 0) {
  2736. matchFailed("\")\"");
  2737. }
  2738. }
  2739. if (result1 === null) {
  2740. if (input.charCodeAt(pos) === 60) {
  2741. result1 = "<";
  2742. pos++;
  2743. } else {
  2744. result1 = null;
  2745. if (reportFailures === 0) {
  2746. matchFailed("\"<\"");
  2747. }
  2748. }
  2749. if (result1 === null) {
  2750. if (input.charCodeAt(pos) === 62) {
  2751. result1 = ">";
  2752. pos++;
  2753. } else {
  2754. result1 = null;
  2755. if (reportFailures === 0) {
  2756. matchFailed("\">\"");
  2757. }
  2758. }
  2759. if (result1 === null) {
  2760. if (input.charCodeAt(pos) === 58) {
  2761. result1 = ":";
  2762. pos++;
  2763. } else {
  2764. result1 = null;
  2765. if (reportFailures === 0) {
  2766. matchFailed("\":\"");
  2767. }
  2768. }
  2769. if (result1 === null) {
  2770. if (input.charCodeAt(pos) === 92) {
  2771. result1 = "\\";
  2772. pos++;
  2773. } else {
  2774. result1 = null;
  2775. if (reportFailures === 0) {
  2776. matchFailed("\"\\\\\"");
  2777. }
  2778. }
  2779. if (result1 === null) {
  2780. result1 = parse_DQUOTE();
  2781. if (result1 === null) {
  2782. if (input.charCodeAt(pos) === 47) {
  2783. result1 = "/";
  2784. pos++;
  2785. } else {
  2786. result1 = null;
  2787. if (reportFailures === 0) {
  2788. matchFailed("\"/\"");
  2789. }
  2790. }
  2791. if (result1 === null) {
  2792. if (input.charCodeAt(pos) === 91) {
  2793. result1 = "[";
  2794. pos++;
  2795. } else {
  2796. result1 = null;
  2797. if (reportFailures === 0) {
  2798. matchFailed("\"[\"");
  2799. }
  2800. }
  2801. if (result1 === null) {
  2802. if (input.charCodeAt(pos) === 93) {
  2803. result1 = "]";
  2804. pos++;
  2805. } else {
  2806. result1 = null;
  2807. if (reportFailures === 0) {
  2808. matchFailed("\"]\"");
  2809. }
  2810. }
  2811. if (result1 === null) {
  2812. if (input.charCodeAt(pos) === 63) {
  2813. result1 = "?";
  2814. pos++;
  2815. } else {
  2816. result1 = null;
  2817. if (reportFailures === 0) {
  2818. matchFailed("\"?\"");
  2819. }
  2820. }
  2821. if (result1 === null) {
  2822. if (input.charCodeAt(pos) === 123) {
  2823. result1 = "{";
  2824. pos++;
  2825. } else {
  2826. result1 = null;
  2827. if (reportFailures === 0) {
  2828. matchFailed("\"{\"");
  2829. }
  2830. }
  2831. if (result1 === null) {
  2832. if (input.charCodeAt(pos) === 125) {
  2833. result1 = "}";
  2834. pos++;
  2835. } else {
  2836. result1 = null;
  2837. if (reportFailures === 0) {
  2838. matchFailed("\"}\"");
  2839. }
  2840. }
  2841. }
  2842. }
  2843. }
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. }
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. if (result1 !== null) {
  2865. result0 = [];
  2866. while (result1 !== null) {
  2867. result0.push(result1);
  2868. result1 = parse_alphanum();
  2869. if (result1 === null) {
  2870. if (input.charCodeAt(pos) === 45) {
  2871. result1 = "-";
  2872. pos++;
  2873. } else {
  2874. result1 = null;
  2875. if (reportFailures === 0) {
  2876. matchFailed("\"-\"");
  2877. }
  2878. }
  2879. if (result1 === null) {
  2880. if (input.charCodeAt(pos) === 46) {
  2881. result1 = ".";
  2882. pos++;
  2883. } else {
  2884. result1 = null;
  2885. if (reportFailures === 0) {
  2886. matchFailed("\".\"");
  2887. }
  2888. }
  2889. if (result1 === null) {
  2890. if (input.charCodeAt(pos) === 33) {
  2891. result1 = "!";
  2892. pos++;
  2893. } else {
  2894. result1 = null;
  2895. if (reportFailures === 0) {
  2896. matchFailed("\"!\"");
  2897. }
  2898. }
  2899. if (result1 === null) {
  2900. if (input.charCodeAt(pos) === 37) {
  2901. result1 = "%";
  2902. pos++;
  2903. } else {
  2904. result1 = null;
  2905. if (reportFailures === 0) {
  2906. matchFailed("\"%\"");
  2907. }
  2908. }
  2909. if (result1 === null) {
  2910. if (input.charCodeAt(pos) === 42) {
  2911. result1 = "*";
  2912. pos++;
  2913. } else {
  2914. result1 = null;
  2915. if (reportFailures === 0) {
  2916. matchFailed("\"*\"");
  2917. }
  2918. }
  2919. if (result1 === null) {
  2920. if (input.charCodeAt(pos) === 95) {
  2921. result1 = "_";
  2922. pos++;
  2923. } else {
  2924. result1 = null;
  2925. if (reportFailures === 0) {
  2926. matchFailed("\"_\"");
  2927. }
  2928. }
  2929. if (result1 === null) {
  2930. if (input.charCodeAt(pos) === 43) {
  2931. result1 = "+";
  2932. pos++;
  2933. } else {
  2934. result1 = null;
  2935. if (reportFailures === 0) {
  2936. matchFailed("\"+\"");
  2937. }
  2938. }
  2939. if (result1 === null) {
  2940. if (input.charCodeAt(pos) === 96) {
  2941. result1 = "`";
  2942. pos++;
  2943. } else {
  2944. result1 = null;
  2945. if (reportFailures === 0) {
  2946. matchFailed("\"`\"");
  2947. }
  2948. }
  2949. if (result1 === null) {
  2950. if (input.charCodeAt(pos) === 39) {
  2951. result1 = "'";
  2952. pos++;
  2953. } else {
  2954. result1 = null;
  2955. if (reportFailures === 0) {
  2956. matchFailed("\"'\"");
  2957. }
  2958. }
  2959. if (result1 === null) {
  2960. if (input.charCodeAt(pos) === 126) {
  2961. result1 = "~";
  2962. pos++;
  2963. } else {
  2964. result1 = null;
  2965. if (reportFailures === 0) {
  2966. matchFailed("\"~\"");
  2967. }
  2968. }
  2969. if (result1 === null) {
  2970. if (input.charCodeAt(pos) === 40) {
  2971. result1 = "(";
  2972. pos++;
  2973. } else {
  2974. result1 = null;
  2975. if (reportFailures === 0) {
  2976. matchFailed("\"(\"");
  2977. }
  2978. }
  2979. if (result1 === null) {
  2980. if (input.charCodeAt(pos) === 41) {
  2981. result1 = ")";
  2982. pos++;
  2983. } else {
  2984. result1 = null;
  2985. if (reportFailures === 0) {
  2986. matchFailed("\")\"");
  2987. }
  2988. }
  2989. if (result1 === null) {
  2990. if (input.charCodeAt(pos) === 60) {
  2991. result1 = "<";
  2992. pos++;
  2993. } else {
  2994. result1 = null;
  2995. if (reportFailures === 0) {
  2996. matchFailed("\"<\"");
  2997. }
  2998. }
  2999. if (result1 === null) {
  3000. if (input.charCodeAt(pos) === 62) {
  3001. result1 = ">";
  3002. pos++;
  3003. } else {
  3004. result1 = null;
  3005. if (reportFailures === 0) {
  3006. matchFailed("\">\"");
  3007. }
  3008. }
  3009. if (result1 === null) {
  3010. if (input.charCodeAt(pos) === 58) {
  3011. result1 = ":";
  3012. pos++;
  3013. } else {
  3014. result1 = null;
  3015. if (reportFailures === 0) {
  3016. matchFailed("\":\"");
  3017. }
  3018. }
  3019. if (result1 === null) {
  3020. if (input.charCodeAt(pos) === 92) {
  3021. result1 = "\\";
  3022. pos++;
  3023. } else {
  3024. result1 = null;
  3025. if (reportFailures === 0) {
  3026. matchFailed("\"\\\\\"");
  3027. }
  3028. }
  3029. if (result1 === null) {
  3030. result1 = parse_DQUOTE();
  3031. if (result1 === null) {
  3032. if (input.charCodeAt(pos) === 47) {
  3033. result1 = "/";
  3034. pos++;
  3035. } else {
  3036. result1 = null;
  3037. if (reportFailures === 0) {
  3038. matchFailed("\"/\"");
  3039. }
  3040. }
  3041. if (result1 === null) {
  3042. if (input.charCodeAt(pos) === 91) {
  3043. result1 = "[";
  3044. pos++;
  3045. } else {
  3046. result1 = null;
  3047. if (reportFailures === 0) {
  3048. matchFailed("\"[\"");
  3049. }
  3050. }
  3051. if (result1 === null) {
  3052. if (input.charCodeAt(pos) === 93) {
  3053. result1 = "]";
  3054. pos++;
  3055. } else {
  3056. result1 = null;
  3057. if (reportFailures === 0) {
  3058. matchFailed("\"]\"");
  3059. }
  3060. }
  3061. if (result1 === null) {
  3062. if (input.charCodeAt(pos) === 63) {
  3063. result1 = "?";
  3064. pos++;
  3065. } else {
  3066. result1 = null;
  3067. if (reportFailures === 0) {
  3068. matchFailed("\"?\"");
  3069. }
  3070. }
  3071. if (result1 === null) {
  3072. if (input.charCodeAt(pos) === 123) {
  3073. result1 = "{";
  3074. pos++;
  3075. } else {
  3076. result1 = null;
  3077. if (reportFailures === 0) {
  3078. matchFailed("\"{\"");
  3079. }
  3080. }
  3081. if (result1 === null) {
  3082. if (input.charCodeAt(pos) === 125) {
  3083. result1 = "}";
  3084. pos++;
  3085. } else {
  3086. result1 = null;
  3087. if (reportFailures === 0) {
  3088. matchFailed("\"}\"");
  3089. }
  3090. }
  3091. }
  3092. }
  3093. }
  3094. }
  3095. }
  3096. }
  3097. }
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. }
  3104. }
  3105. }
  3106. }
  3107. }
  3108. }
  3109. }
  3110. }
  3111. }
  3112. }
  3113. }
  3114. }
  3115. } else {
  3116. result0 = null;
  3117. }
  3118. if (result0 !== null) {
  3119. result0 = function (offset) {
  3120. return input.substring(pos, offset);
  3121. }(pos0);
  3122. }
  3123. if (result0 === null) {
  3124. pos = pos0;
  3125. }
  3126. return result0;
  3127. }
  3128. function parse_STAR() {
  3129. var result0, result1, result2;
  3130. var pos0, pos1;
  3131. pos0 = pos;
  3132. pos1 = pos;
  3133. result0 = parse_SWS();
  3134. if (result0 !== null) {
  3135. if (input.charCodeAt(pos) === 42) {
  3136. result1 = "*";
  3137. pos++;
  3138. } else {
  3139. result1 = null;
  3140. if (reportFailures === 0) {
  3141. matchFailed("\"*\"");
  3142. }
  3143. }
  3144. if (result1 !== null) {
  3145. result2 = parse_SWS();
  3146. if (result2 !== null) {
  3147. result0 = [result0, result1, result2];
  3148. } else {
  3149. result0 = null;
  3150. pos = pos1;
  3151. }
  3152. } else {
  3153. result0 = null;
  3154. pos = pos1;
  3155. }
  3156. } else {
  3157. result0 = null;
  3158. pos = pos1;
  3159. }
  3160. if (result0 !== null) {
  3161. result0 = function (offset) {
  3162. return "*";
  3163. }(pos0);
  3164. }
  3165. if (result0 === null) {
  3166. pos = pos0;
  3167. }
  3168. return result0;
  3169. }
  3170. function parse_SLASH() {
  3171. var result0, result1, result2;
  3172. var pos0, pos1;
  3173. pos0 = pos;
  3174. pos1 = pos;
  3175. result0 = parse_SWS();
  3176. if (result0 !== null) {
  3177. if (input.charCodeAt(pos) === 47) {
  3178. result1 = "/";
  3179. pos++;
  3180. } else {
  3181. result1 = null;
  3182. if (reportFailures === 0) {
  3183. matchFailed("\"/\"");
  3184. }
  3185. }
  3186. if (result1 !== null) {
  3187. result2 = parse_SWS();
  3188. if (result2 !== null) {
  3189. result0 = [result0, result1, result2];
  3190. } else {
  3191. result0 = null;
  3192. pos = pos1;
  3193. }
  3194. } else {
  3195. result0 = null;
  3196. pos = pos1;
  3197. }
  3198. } else {
  3199. result0 = null;
  3200. pos = pos1;
  3201. }
  3202. if (result0 !== null) {
  3203. result0 = function (offset) {
  3204. return "/";
  3205. }(pos0);
  3206. }
  3207. if (result0 === null) {
  3208. pos = pos0;
  3209. }
  3210. return result0;
  3211. }
  3212. function parse_EQUAL() {
  3213. var result0, result1, result2;
  3214. var pos0, pos1;
  3215. pos0 = pos;
  3216. pos1 = pos;
  3217. result0 = parse_SWS();
  3218. if (result0 !== null) {
  3219. if (input.charCodeAt(pos) === 61) {
  3220. result1 = "=";
  3221. pos++;
  3222. } else {
  3223. result1 = null;
  3224. if (reportFailures === 0) {
  3225. matchFailed("\"=\"");
  3226. }
  3227. }
  3228. if (result1 !== null) {
  3229. result2 = parse_SWS();
  3230. if (result2 !== null) {
  3231. result0 = [result0, result1, result2];
  3232. } else {
  3233. result0 = null;
  3234. pos = pos1;
  3235. }
  3236. } else {
  3237. result0 = null;
  3238. pos = pos1;
  3239. }
  3240. } else {
  3241. result0 = null;
  3242. pos = pos1;
  3243. }
  3244. if (result0 !== null) {
  3245. result0 = function (offset) {
  3246. return "=";
  3247. }(pos0);
  3248. }
  3249. if (result0 === null) {
  3250. pos = pos0;
  3251. }
  3252. return result0;
  3253. }
  3254. function parse_LPAREN() {
  3255. var result0, result1, result2;
  3256. var pos0, pos1;
  3257. pos0 = pos;
  3258. pos1 = pos;
  3259. result0 = parse_SWS();
  3260. if (result0 !== null) {
  3261. if (input.charCodeAt(pos) === 40) {
  3262. result1 = "(";
  3263. pos++;
  3264. } else {
  3265. result1 = null;
  3266. if (reportFailures === 0) {
  3267. matchFailed("\"(\"");
  3268. }
  3269. }
  3270. if (result1 !== null) {
  3271. result2 = parse_SWS();
  3272. if (result2 !== null) {
  3273. result0 = [result0, result1, result2];
  3274. } else {
  3275. result0 = null;
  3276. pos = pos1;
  3277. }
  3278. } else {
  3279. result0 = null;
  3280. pos = pos1;
  3281. }
  3282. } else {
  3283. result0 = null;
  3284. pos = pos1;
  3285. }
  3286. if (result0 !== null) {
  3287. result0 = function (offset) {
  3288. return "(";
  3289. }(pos0);
  3290. }
  3291. if (result0 === null) {
  3292. pos = pos0;
  3293. }
  3294. return result0;
  3295. }
  3296. function parse_RPAREN() {
  3297. var result0, result1, result2;
  3298. var pos0, pos1;
  3299. pos0 = pos;
  3300. pos1 = pos;
  3301. result0 = parse_SWS();
  3302. if (result0 !== null) {
  3303. if (input.charCodeAt(pos) === 41) {
  3304. result1 = ")";
  3305. pos++;
  3306. } else {
  3307. result1 = null;
  3308. if (reportFailures === 0) {
  3309. matchFailed("\")\"");
  3310. }
  3311. }
  3312. if (result1 !== null) {
  3313. result2 = parse_SWS();
  3314. if (result2 !== null) {
  3315. result0 = [result0, result1, result2];
  3316. } else {
  3317. result0 = null;
  3318. pos = pos1;
  3319. }
  3320. } else {
  3321. result0 = null;
  3322. pos = pos1;
  3323. }
  3324. } else {
  3325. result0 = null;
  3326. pos = pos1;
  3327. }
  3328. if (result0 !== null) {
  3329. result0 = function (offset) {
  3330. return ")";
  3331. }(pos0);
  3332. }
  3333. if (result0 === null) {
  3334. pos = pos0;
  3335. }
  3336. return result0;
  3337. }
  3338. function parse_RAQUOT() {
  3339. var result0, result1;
  3340. var pos0, pos1;
  3341. pos0 = pos;
  3342. pos1 = pos;
  3343. if (input.charCodeAt(pos) === 62) {
  3344. result0 = ">";
  3345. pos++;
  3346. } else {
  3347. result0 = null;
  3348. if (reportFailures === 0) {
  3349. matchFailed("\">\"");
  3350. }
  3351. }
  3352. if (result0 !== null) {
  3353. result1 = parse_SWS();
  3354. if (result1 !== null) {
  3355. result0 = [result0, result1];
  3356. } else {
  3357. result0 = null;
  3358. pos = pos1;
  3359. }
  3360. } else {
  3361. result0 = null;
  3362. pos = pos1;
  3363. }
  3364. if (result0 !== null) {
  3365. result0 = function (offset) {
  3366. return ">";
  3367. }(pos0);
  3368. }
  3369. if (result0 === null) {
  3370. pos = pos0;
  3371. }
  3372. return result0;
  3373. }
  3374. function parse_LAQUOT() {
  3375. var result0, result1;
  3376. var pos0, pos1;
  3377. pos0 = pos;
  3378. pos1 = pos;
  3379. result0 = parse_SWS();
  3380. if (result0 !== null) {
  3381. if (input.charCodeAt(pos) === 60) {
  3382. result1 = "<";
  3383. pos++;
  3384. } else {
  3385. result1 = null;
  3386. if (reportFailures === 0) {
  3387. matchFailed("\"<\"");
  3388. }
  3389. }
  3390. if (result1 !== null) {
  3391. result0 = [result0, result1];
  3392. } else {
  3393. result0 = null;
  3394. pos = pos1;
  3395. }
  3396. } else {
  3397. result0 = null;
  3398. pos = pos1;
  3399. }
  3400. if (result0 !== null) {
  3401. result0 = function (offset) {
  3402. return "<";
  3403. }(pos0);
  3404. }
  3405. if (result0 === null) {
  3406. pos = pos0;
  3407. }
  3408. return result0;
  3409. }
  3410. function parse_COMMA() {
  3411. var result0, result1, result2;
  3412. var pos0, pos1;
  3413. pos0 = pos;
  3414. pos1 = pos;
  3415. result0 = parse_SWS();
  3416. if (result0 !== null) {
  3417. if (input.charCodeAt(pos) === 44) {
  3418. result1 = ",";
  3419. pos++;
  3420. } else {
  3421. result1 = null;
  3422. if (reportFailures === 0) {
  3423. matchFailed("\",\"");
  3424. }
  3425. }
  3426. if (result1 !== null) {
  3427. result2 = parse_SWS();
  3428. if (result2 !== null) {
  3429. result0 = [result0, result1, result2];
  3430. } else {
  3431. result0 = null;
  3432. pos = pos1;
  3433. }
  3434. } else {
  3435. result0 = null;
  3436. pos = pos1;
  3437. }
  3438. } else {
  3439. result0 = null;
  3440. pos = pos1;
  3441. }
  3442. if (result0 !== null) {
  3443. result0 = function (offset) {
  3444. return ",";
  3445. }(pos0);
  3446. }
  3447. if (result0 === null) {
  3448. pos = pos0;
  3449. }
  3450. return result0;
  3451. }
  3452. function parse_SEMI() {
  3453. var result0, result1, result2;
  3454. var pos0, pos1;
  3455. pos0 = pos;
  3456. pos1 = pos;
  3457. result0 = parse_SWS();
  3458. if (result0 !== null) {
  3459. if (input.charCodeAt(pos) === 59) {
  3460. result1 = ";";
  3461. pos++;
  3462. } else {
  3463. result1 = null;
  3464. if (reportFailures === 0) {
  3465. matchFailed("\";\"");
  3466. }
  3467. }
  3468. if (result1 !== null) {
  3469. result2 = parse_SWS();
  3470. if (result2 !== null) {
  3471. result0 = [result0, result1, result2];
  3472. } else {
  3473. result0 = null;
  3474. pos = pos1;
  3475. }
  3476. } else {
  3477. result0 = null;
  3478. pos = pos1;
  3479. }
  3480. } else {
  3481. result0 = null;
  3482. pos = pos1;
  3483. }
  3484. if (result0 !== null) {
  3485. result0 = function (offset) {
  3486. return ";";
  3487. }(pos0);
  3488. }
  3489. if (result0 === null) {
  3490. pos = pos0;
  3491. }
  3492. return result0;
  3493. }
  3494. function parse_COLON() {
  3495. var result0, result1, result2;
  3496. var pos0, pos1;
  3497. pos0 = pos;
  3498. pos1 = pos;
  3499. result0 = parse_SWS();
  3500. if (result0 !== null) {
  3501. if (input.charCodeAt(pos) === 58) {
  3502. result1 = ":";
  3503. pos++;
  3504. } else {
  3505. result1 = null;
  3506. if (reportFailures === 0) {
  3507. matchFailed("\":\"");
  3508. }
  3509. }
  3510. if (result1 !== null) {
  3511. result2 = parse_SWS();
  3512. if (result2 !== null) {
  3513. result0 = [result0, result1, result2];
  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. if (result0 !== null) {
  3527. result0 = function (offset) {
  3528. return ":";
  3529. }(pos0);
  3530. }
  3531. if (result0 === null) {
  3532. pos = pos0;
  3533. }
  3534. return result0;
  3535. }
  3536. function parse_LDQUOT() {
  3537. var result0, result1;
  3538. var pos0, pos1;
  3539. pos0 = pos;
  3540. pos1 = pos;
  3541. result0 = parse_SWS();
  3542. if (result0 !== null) {
  3543. result1 = parse_DQUOTE();
  3544. if (result1 !== null) {
  3545. result0 = [result0, result1];
  3546. } else {
  3547. result0 = null;
  3548. pos = pos1;
  3549. }
  3550. } else {
  3551. result0 = null;
  3552. pos = pos1;
  3553. }
  3554. if (result0 !== null) {
  3555. result0 = function (offset) {
  3556. return "\"";
  3557. }(pos0);
  3558. }
  3559. if (result0 === null) {
  3560. pos = pos0;
  3561. }
  3562. return result0;
  3563. }
  3564. function parse_RDQUOT() {
  3565. var result0, result1;
  3566. var pos0, pos1;
  3567. pos0 = pos;
  3568. pos1 = pos;
  3569. result0 = parse_DQUOTE();
  3570. if (result0 !== null) {
  3571. result1 = parse_SWS();
  3572. if (result1 !== null) {
  3573. result0 = [result0, result1];
  3574. } else {
  3575. result0 = null;
  3576. pos = pos1;
  3577. }
  3578. } else {
  3579. result0 = null;
  3580. pos = pos1;
  3581. }
  3582. if (result0 !== null) {
  3583. result0 = function (offset) {
  3584. return "\"";
  3585. }(pos0);
  3586. }
  3587. if (result0 === null) {
  3588. pos = pos0;
  3589. }
  3590. return result0;
  3591. }
  3592. function parse_comment() {
  3593. var result0, result1, result2;
  3594. var pos0;
  3595. pos0 = pos;
  3596. result0 = parse_LPAREN();
  3597. if (result0 !== null) {
  3598. result1 = [];
  3599. result2 = parse_ctext();
  3600. if (result2 === null) {
  3601. result2 = parse_quoted_pair();
  3602. if (result2 === null) {
  3603. result2 = parse_comment();
  3604. }
  3605. }
  3606. while (result2 !== null) {
  3607. result1.push(result2);
  3608. result2 = parse_ctext();
  3609. if (result2 === null) {
  3610. result2 = parse_quoted_pair();
  3611. if (result2 === null) {
  3612. result2 = parse_comment();
  3613. }
  3614. }
  3615. }
  3616. if (result1 !== null) {
  3617. result2 = parse_RPAREN();
  3618. if (result2 !== null) {
  3619. result0 = [result0, result1, result2];
  3620. } else {
  3621. result0 = null;
  3622. pos = pos0;
  3623. }
  3624. } else {
  3625. result0 = null;
  3626. pos = pos0;
  3627. }
  3628. } else {
  3629. result0 = null;
  3630. pos = pos0;
  3631. }
  3632. return result0;
  3633. }
  3634. function parse_ctext() {
  3635. var result0;
  3636. if (/^[!-']/.test(input.charAt(pos))) {
  3637. result0 = input.charAt(pos);
  3638. pos++;
  3639. } else {
  3640. result0 = null;
  3641. if (reportFailures === 0) {
  3642. matchFailed("[!-']");
  3643. }
  3644. }
  3645. if (result0 === null) {
  3646. if (/^[*-[]/.test(input.charAt(pos))) {
  3647. result0 = input.charAt(pos);
  3648. pos++;
  3649. } else {
  3650. result0 = null;
  3651. if (reportFailures === 0) {
  3652. matchFailed("[*-[]");
  3653. }
  3654. }
  3655. if (result0 === null) {
  3656. if (/^[\]-~]/.test(input.charAt(pos))) {
  3657. result0 = input.charAt(pos);
  3658. pos++;
  3659. } else {
  3660. result0 = null;
  3661. if (reportFailures === 0) {
  3662. matchFailed("[\\]-~]");
  3663. }
  3664. }
  3665. if (result0 === null) {
  3666. result0 = parse_UTF8_NONASCII();
  3667. if (result0 === null) {
  3668. result0 = parse_LWS();
  3669. }
  3670. }
  3671. }
  3672. }
  3673. return result0;
  3674. }
  3675. function parse_quoted_string() {
  3676. var result0, result1, result2, result3;
  3677. var pos0, pos1;
  3678. pos0 = pos;
  3679. pos1 = pos;
  3680. result0 = parse_SWS();
  3681. if (result0 !== null) {
  3682. result1 = parse_DQUOTE();
  3683. if (result1 !== null) {
  3684. result2 = [];
  3685. result3 = parse_qdtext();
  3686. if (result3 === null) {
  3687. result3 = parse_quoted_pair();
  3688. }
  3689. while (result3 !== null) {
  3690. result2.push(result3);
  3691. result3 = parse_qdtext();
  3692. if (result3 === null) {
  3693. result3 = parse_quoted_pair();
  3694. }
  3695. }
  3696. if (result2 !== null) {
  3697. result3 = parse_DQUOTE();
  3698. if (result3 !== null) {
  3699. result0 = [result0, result1, result2, result3];
  3700. } else {
  3701. result0 = null;
  3702. pos = pos1;
  3703. }
  3704. } else {
  3705. result0 = null;
  3706. pos = pos1;
  3707. }
  3708. } else {
  3709. result0 = null;
  3710. pos = pos1;
  3711. }
  3712. } else {
  3713. result0 = null;
  3714. pos = pos1;
  3715. }
  3716. if (result0 !== null) {
  3717. result0 = function (offset) {
  3718. return input.substring(pos, offset);
  3719. }(pos0);
  3720. }
  3721. if (result0 === null) {
  3722. pos = pos0;
  3723. }
  3724. return result0;
  3725. }
  3726. function parse_quoted_string_clean() {
  3727. var result0, result1, result2, result3;
  3728. var pos0, pos1;
  3729. pos0 = pos;
  3730. pos1 = pos;
  3731. result0 = parse_SWS();
  3732. if (result0 !== null) {
  3733. result1 = parse_DQUOTE();
  3734. if (result1 !== null) {
  3735. result2 = [];
  3736. result3 = parse_qdtext();
  3737. if (result3 === null) {
  3738. result3 = parse_quoted_pair();
  3739. }
  3740. while (result3 !== null) {
  3741. result2.push(result3);
  3742. result3 = parse_qdtext();
  3743. if (result3 === null) {
  3744. result3 = parse_quoted_pair();
  3745. }
  3746. }
  3747. if (result2 !== null) {
  3748. result3 = parse_DQUOTE();
  3749. if (result3 !== null) {
  3750. result0 = [result0, result1, result2, result3];
  3751. } else {
  3752. result0 = null;
  3753. pos = pos1;
  3754. }
  3755. } else {
  3756. result0 = null;
  3757. pos = pos1;
  3758. }
  3759. } else {
  3760. result0 = null;
  3761. pos = pos1;
  3762. }
  3763. } else {
  3764. result0 = null;
  3765. pos = pos1;
  3766. }
  3767. if (result0 !== null) {
  3768. result0 = function (offset) {
  3769. var trimmed = input.substring(pos, offset).trim();
  3770. return trimmed.substring(1, trimmed.length - 1) // remove outer quotes
  3771. .replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g, '$1');
  3772. }(pos0);
  3773. }
  3774. if (result0 === null) {
  3775. pos = pos0;
  3776. }
  3777. return result0;
  3778. }
  3779. function parse_qdtext() {
  3780. var result0;
  3781. result0 = parse_LWS();
  3782. if (result0 === null) {
  3783. if (input.charCodeAt(pos) === 33) {
  3784. result0 = "!";
  3785. pos++;
  3786. } else {
  3787. result0 = null;
  3788. if (reportFailures === 0) {
  3789. matchFailed("\"!\"");
  3790. }
  3791. }
  3792. if (result0 === null) {
  3793. if (/^[#-[]/.test(input.charAt(pos))) {
  3794. result0 = input.charAt(pos);
  3795. pos++;
  3796. } else {
  3797. result0 = null;
  3798. if (reportFailures === 0) {
  3799. matchFailed("[#-[]");
  3800. }
  3801. }
  3802. if (result0 === null) {
  3803. if (/^[\]-~]/.test(input.charAt(pos))) {
  3804. result0 = input.charAt(pos);
  3805. pos++;
  3806. } else {
  3807. result0 = null;
  3808. if (reportFailures === 0) {
  3809. matchFailed("[\\]-~]");
  3810. }
  3811. }
  3812. if (result0 === null) {
  3813. result0 = parse_UTF8_NONASCII();
  3814. }
  3815. }
  3816. }
  3817. }
  3818. return result0;
  3819. }
  3820. function parse_quoted_pair() {
  3821. var result0, result1;
  3822. var pos0;
  3823. pos0 = pos;
  3824. if (input.charCodeAt(pos) === 92) {
  3825. result0 = "\\";
  3826. pos++;
  3827. } else {
  3828. result0 = null;
  3829. if (reportFailures === 0) {
  3830. matchFailed("\"\\\\\"");
  3831. }
  3832. }
  3833. if (result0 !== null) {
  3834. if (/^[\0-\t]/.test(input.charAt(pos))) {
  3835. result1 = input.charAt(pos);
  3836. pos++;
  3837. } else {
  3838. result1 = null;
  3839. if (reportFailures === 0) {
  3840. matchFailed("[\\0-\\t]");
  3841. }
  3842. }
  3843. if (result1 === null) {
  3844. if (/^[\x0B-\f]/.test(input.charAt(pos))) {
  3845. result1 = input.charAt(pos);
  3846. pos++;
  3847. } else {
  3848. result1 = null;
  3849. if (reportFailures === 0) {
  3850. matchFailed("[\\x0B-\\f]");
  3851. }
  3852. }
  3853. if (result1 === null) {
  3854. if (/^[\x0E-]/.test(input.charAt(pos))) {
  3855. result1 = input.charAt(pos);
  3856. pos++;
  3857. } else {
  3858. result1 = null;
  3859. if (reportFailures === 0) {
  3860. matchFailed("[\\x0E-]");
  3861. }
  3862. }
  3863. }
  3864. }
  3865. if (result1 !== null) {
  3866. result0 = [result0, result1];
  3867. } else {
  3868. result0 = null;
  3869. pos = pos0;
  3870. }
  3871. } else {
  3872. result0 = null;
  3873. pos = pos0;
  3874. }
  3875. return result0;
  3876. }
  3877. function parse_SIP_URI_noparams() {
  3878. var result0, result1, result2, result3;
  3879. var pos0, pos1;
  3880. pos0 = pos;
  3881. pos1 = pos;
  3882. result0 = parse_uri_scheme();
  3883. if (result0 !== null) {
  3884. if (input.charCodeAt(pos) === 58) {
  3885. result1 = ":";
  3886. pos++;
  3887. } else {
  3888. result1 = null;
  3889. if (reportFailures === 0) {
  3890. matchFailed("\":\"");
  3891. }
  3892. }
  3893. if (result1 !== null) {
  3894. result2 = parse_userinfo();
  3895. result2 = result2 !== null ? result2 : "";
  3896. if (result2 !== null) {
  3897. result3 = parse_hostport();
  3898. if (result3 !== null) {
  3899. result0 = [result0, result1, result2, result3];
  3900. } else {
  3901. result0 = null;
  3902. pos = pos1;
  3903. }
  3904. } else {
  3905. result0 = null;
  3906. pos = pos1;
  3907. }
  3908. } else {
  3909. result0 = null;
  3910. pos = pos1;
  3911. }
  3912. } else {
  3913. result0 = null;
  3914. pos = pos1;
  3915. }
  3916. if (result0 !== null) {
  3917. result0 = function (offset) {
  3918. try {
  3919. data.uri = new URI(data.scheme, data.user, data.host, data.port);
  3920. delete data.scheme;
  3921. delete data.user;
  3922. delete data.host;
  3923. delete data.host_type;
  3924. delete data.port;
  3925. } catch (e) {
  3926. data = -1;
  3927. }
  3928. }(pos0);
  3929. }
  3930. if (result0 === null) {
  3931. pos = pos0;
  3932. }
  3933. return result0;
  3934. }
  3935. function parse_SIP_URI() {
  3936. var result0, result1, result2, result3, result4, result5;
  3937. var pos0, pos1;
  3938. pos0 = pos;
  3939. pos1 = pos;
  3940. result0 = parse_uri_scheme();
  3941. if (result0 !== null) {
  3942. if (input.charCodeAt(pos) === 58) {
  3943. result1 = ":";
  3944. pos++;
  3945. } else {
  3946. result1 = null;
  3947. if (reportFailures === 0) {
  3948. matchFailed("\":\"");
  3949. }
  3950. }
  3951. if (result1 !== null) {
  3952. result2 = parse_userinfo();
  3953. result2 = result2 !== null ? result2 : "";
  3954. if (result2 !== null) {
  3955. result3 = parse_hostport();
  3956. if (result3 !== null) {
  3957. result4 = parse_uri_parameters();
  3958. if (result4 !== null) {
  3959. result5 = parse_headers();
  3960. result5 = result5 !== null ? result5 : "";
  3961. if (result5 !== null) {
  3962. result0 = [result0, result1, result2, result3, result4, result5];
  3963. } else {
  3964. result0 = null;
  3965. pos = pos1;
  3966. }
  3967. } else {
  3968. result0 = null;
  3969. pos = pos1;
  3970. }
  3971. } else {
  3972. result0 = null;
  3973. pos = pos1;
  3974. }
  3975. } else {
  3976. result0 = null;
  3977. pos = pos1;
  3978. }
  3979. } else {
  3980. result0 = null;
  3981. pos = pos1;
  3982. }
  3983. } else {
  3984. result0 = null;
  3985. pos = pos1;
  3986. }
  3987. if (result0 !== null) {
  3988. result0 = function (offset) {
  3989. var header;
  3990. try {
  3991. data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers);
  3992. delete data.scheme;
  3993. delete data.user;
  3994. delete data.host;
  3995. delete data.host_type;
  3996. delete data.port;
  3997. delete data.uri_params;
  3998. if (startRule === 'SIP_URI') {
  3999. data = data.uri;
  4000. }
  4001. } catch (e) {
  4002. data = -1;
  4003. }
  4004. }(pos0);
  4005. }
  4006. if (result0 === null) {
  4007. pos = pos0;
  4008. }
  4009. return result0;
  4010. }
  4011. function parse_uri_scheme() {
  4012. var result0;
  4013. result0 = parse_uri_scheme_sips();
  4014. if (result0 === null) {
  4015. result0 = parse_uri_scheme_sip();
  4016. }
  4017. return result0;
  4018. }
  4019. function parse_uri_scheme_sips() {
  4020. var result0;
  4021. var pos0;
  4022. pos0 = pos;
  4023. if (input.substr(pos, 4).toLowerCase() === "sips") {
  4024. result0 = input.substr(pos, 4);
  4025. pos += 4;
  4026. } else {
  4027. result0 = null;
  4028. if (reportFailures === 0) {
  4029. matchFailed("\"sips\"");
  4030. }
  4031. }
  4032. if (result0 !== null) {
  4033. result0 = function (offset, scheme) {
  4034. data.scheme = scheme.toLowerCase();
  4035. }(pos0, result0);
  4036. }
  4037. if (result0 === null) {
  4038. pos = pos0;
  4039. }
  4040. return result0;
  4041. }
  4042. function parse_uri_scheme_sip() {
  4043. var result0;
  4044. var pos0;
  4045. pos0 = pos;
  4046. if (input.substr(pos, 3).toLowerCase() === "sip") {
  4047. result0 = input.substr(pos, 3);
  4048. pos += 3;
  4049. } else {
  4050. result0 = null;
  4051. if (reportFailures === 0) {
  4052. matchFailed("\"sip\"");
  4053. }
  4054. }
  4055. if (result0 !== null) {
  4056. result0 = function (offset, scheme) {
  4057. data.scheme = scheme.toLowerCase();
  4058. }(pos0, result0);
  4059. }
  4060. if (result0 === null) {
  4061. pos = pos0;
  4062. }
  4063. return result0;
  4064. }
  4065. function parse_userinfo() {
  4066. var result0, result1, result2;
  4067. var pos0, pos1, pos2;
  4068. pos0 = pos;
  4069. pos1 = pos;
  4070. result0 = parse_user();
  4071. if (result0 !== null) {
  4072. pos2 = pos;
  4073. if (input.charCodeAt(pos) === 58) {
  4074. result1 = ":";
  4075. pos++;
  4076. } else {
  4077. result1 = null;
  4078. if (reportFailures === 0) {
  4079. matchFailed("\":\"");
  4080. }
  4081. }
  4082. if (result1 !== null) {
  4083. result2 = parse_password();
  4084. if (result2 !== null) {
  4085. result1 = [result1, result2];
  4086. } else {
  4087. result1 = null;
  4088. pos = pos2;
  4089. }
  4090. } else {
  4091. result1 = null;
  4092. pos = pos2;
  4093. }
  4094. result1 = result1 !== null ? result1 : "";
  4095. if (result1 !== null) {
  4096. if (input.charCodeAt(pos) === 64) {
  4097. result2 = "@";
  4098. pos++;
  4099. } else {
  4100. result2 = null;
  4101. if (reportFailures === 0) {
  4102. matchFailed("\"@\"");
  4103. }
  4104. }
  4105. if (result2 !== null) {
  4106. result0 = [result0, result1, result2];
  4107. } else {
  4108. result0 = null;
  4109. pos = pos1;
  4110. }
  4111. } else {
  4112. result0 = null;
  4113. pos = pos1;
  4114. }
  4115. } else {
  4116. result0 = null;
  4117. pos = pos1;
  4118. }
  4119. if (result0 !== null) {
  4120. result0 = function (offset) {
  4121. data.user = decodeURIComponent(input.substring(pos - 1, offset));
  4122. }(pos0);
  4123. }
  4124. if (result0 === null) {
  4125. pos = pos0;
  4126. }
  4127. return result0;
  4128. }
  4129. function parse_user() {
  4130. var result0, result1;
  4131. result1 = parse_unreserved();
  4132. if (result1 === null) {
  4133. result1 = parse_escaped();
  4134. if (result1 === null) {
  4135. result1 = parse_user_unreserved();
  4136. }
  4137. }
  4138. if (result1 !== null) {
  4139. result0 = [];
  4140. while (result1 !== null) {
  4141. result0.push(result1);
  4142. result1 = parse_unreserved();
  4143. if (result1 === null) {
  4144. result1 = parse_escaped();
  4145. if (result1 === null) {
  4146. result1 = parse_user_unreserved();
  4147. }
  4148. }
  4149. }
  4150. } else {
  4151. result0 = null;
  4152. }
  4153. return result0;
  4154. }
  4155. function parse_user_unreserved() {
  4156. var result0;
  4157. if (input.charCodeAt(pos) === 38) {
  4158. result0 = "&";
  4159. pos++;
  4160. } else {
  4161. result0 = null;
  4162. if (reportFailures === 0) {
  4163. matchFailed("\"&\"");
  4164. }
  4165. }
  4166. if (result0 === null) {
  4167. if (input.charCodeAt(pos) === 61) {
  4168. result0 = "=";
  4169. pos++;
  4170. } else {
  4171. result0 = null;
  4172. if (reportFailures === 0) {
  4173. matchFailed("\"=\"");
  4174. }
  4175. }
  4176. if (result0 === null) {
  4177. if (input.charCodeAt(pos) === 43) {
  4178. result0 = "+";
  4179. pos++;
  4180. } else {
  4181. result0 = null;
  4182. if (reportFailures === 0) {
  4183. matchFailed("\"+\"");
  4184. }
  4185. }
  4186. if (result0 === null) {
  4187. if (input.charCodeAt(pos) === 36) {
  4188. result0 = "$";
  4189. pos++;
  4190. } else {
  4191. result0 = null;
  4192. if (reportFailures === 0) {
  4193. matchFailed("\"$\"");
  4194. }
  4195. }
  4196. if (result0 === null) {
  4197. if (input.charCodeAt(pos) === 44) {
  4198. result0 = ",";
  4199. pos++;
  4200. } else {
  4201. result0 = null;
  4202. if (reportFailures === 0) {
  4203. matchFailed("\",\"");
  4204. }
  4205. }
  4206. if (result0 === null) {
  4207. if (input.charCodeAt(pos) === 59) {
  4208. result0 = ";";
  4209. pos++;
  4210. } else {
  4211. result0 = null;
  4212. if (reportFailures === 0) {
  4213. matchFailed("\";\"");
  4214. }
  4215. }
  4216. if (result0 === null) {
  4217. if (input.charCodeAt(pos) === 63) {
  4218. result0 = "?";
  4219. pos++;
  4220. } else {
  4221. result0 = null;
  4222. if (reportFailures === 0) {
  4223. matchFailed("\"?\"");
  4224. }
  4225. }
  4226. if (result0 === null) {
  4227. if (input.charCodeAt(pos) === 47) {
  4228. result0 = "/";
  4229. pos++;
  4230. } else {
  4231. result0 = null;
  4232. if (reportFailures === 0) {
  4233. matchFailed("\"/\"");
  4234. }
  4235. }
  4236. }
  4237. }
  4238. }
  4239. }
  4240. }
  4241. }
  4242. }
  4243. return result0;
  4244. }
  4245. function parse_password() {
  4246. var result0, result1;
  4247. var pos0;
  4248. pos0 = pos;
  4249. result0 = [];
  4250. result1 = parse_unreserved();
  4251. if (result1 === null) {
  4252. result1 = parse_escaped();
  4253. if (result1 === null) {
  4254. if (input.charCodeAt(pos) === 38) {
  4255. result1 = "&";
  4256. pos++;
  4257. } else {
  4258. result1 = null;
  4259. if (reportFailures === 0) {
  4260. matchFailed("\"&\"");
  4261. }
  4262. }
  4263. if (result1 === null) {
  4264. if (input.charCodeAt(pos) === 61) {
  4265. result1 = "=";
  4266. pos++;
  4267. } else {
  4268. result1 = null;
  4269. if (reportFailures === 0) {
  4270. matchFailed("\"=\"");
  4271. }
  4272. }
  4273. if (result1 === null) {
  4274. if (input.charCodeAt(pos) === 43) {
  4275. result1 = "+";
  4276. pos++;
  4277. } else {
  4278. result1 = null;
  4279. if (reportFailures === 0) {
  4280. matchFailed("\"+\"");
  4281. }
  4282. }
  4283. if (result1 === null) {
  4284. if (input.charCodeAt(pos) === 36) {
  4285. result1 = "$";
  4286. pos++;
  4287. } else {
  4288. result1 = null;
  4289. if (reportFailures === 0) {
  4290. matchFailed("\"$\"");
  4291. }
  4292. }
  4293. if (result1 === null) {
  4294. if (input.charCodeAt(pos) === 44) {
  4295. result1 = ",";
  4296. pos++;
  4297. } else {
  4298. result1 = null;
  4299. if (reportFailures === 0) {
  4300. matchFailed("\",\"");
  4301. }
  4302. }
  4303. }
  4304. }
  4305. }
  4306. }
  4307. }
  4308. }
  4309. while (result1 !== null) {
  4310. result0.push(result1);
  4311. result1 = parse_unreserved();
  4312. if (result1 === null) {
  4313. result1 = parse_escaped();
  4314. if (result1 === null) {
  4315. if (input.charCodeAt(pos) === 38) {
  4316. result1 = "&";
  4317. pos++;
  4318. } else {
  4319. result1 = null;
  4320. if (reportFailures === 0) {
  4321. matchFailed("\"&\"");
  4322. }
  4323. }
  4324. if (result1 === null) {
  4325. if (input.charCodeAt(pos) === 61) {
  4326. result1 = "=";
  4327. pos++;
  4328. } else {
  4329. result1 = null;
  4330. if (reportFailures === 0) {
  4331. matchFailed("\"=\"");
  4332. }
  4333. }
  4334. if (result1 === null) {
  4335. if (input.charCodeAt(pos) === 43) {
  4336. result1 = "+";
  4337. pos++;
  4338. } else {
  4339. result1 = null;
  4340. if (reportFailures === 0) {
  4341. matchFailed("\"+\"");
  4342. }
  4343. }
  4344. if (result1 === null) {
  4345. if (input.charCodeAt(pos) === 36) {
  4346. result1 = "$";
  4347. pos++;
  4348. } else {
  4349. result1 = null;
  4350. if (reportFailures === 0) {
  4351. matchFailed("\"$\"");
  4352. }
  4353. }
  4354. if (result1 === null) {
  4355. if (input.charCodeAt(pos) === 44) {
  4356. result1 = ",";
  4357. pos++;
  4358. } else {
  4359. result1 = null;
  4360. if (reportFailures === 0) {
  4361. matchFailed("\",\"");
  4362. }
  4363. }
  4364. }
  4365. }
  4366. }
  4367. }
  4368. }
  4369. }
  4370. }
  4371. if (result0 !== null) {
  4372. result0 = function (offset) {
  4373. data.password = input.substring(pos, offset);
  4374. }(pos0);
  4375. }
  4376. if (result0 === null) {
  4377. pos = pos0;
  4378. }
  4379. return result0;
  4380. }
  4381. function parse_hostport() {
  4382. var result0, result1, result2;
  4383. var pos0, pos1;
  4384. pos0 = pos;
  4385. result0 = parse_host();
  4386. if (result0 !== null) {
  4387. pos1 = pos;
  4388. if (input.charCodeAt(pos) === 58) {
  4389. result1 = ":";
  4390. pos++;
  4391. } else {
  4392. result1 = null;
  4393. if (reportFailures === 0) {
  4394. matchFailed("\":\"");
  4395. }
  4396. }
  4397. if (result1 !== null) {
  4398. result2 = parse_port();
  4399. if (result2 !== null) {
  4400. result1 = [result1, result2];
  4401. } else {
  4402. result1 = null;
  4403. pos = pos1;
  4404. }
  4405. } else {
  4406. result1 = null;
  4407. pos = pos1;
  4408. }
  4409. result1 = result1 !== null ? result1 : "";
  4410. if (result1 !== null) {
  4411. result0 = [result0, result1];
  4412. } else {
  4413. result0 = null;
  4414. pos = pos0;
  4415. }
  4416. } else {
  4417. result0 = null;
  4418. pos = pos0;
  4419. }
  4420. return result0;
  4421. }
  4422. function parse_host() {
  4423. var result0;
  4424. var pos0;
  4425. pos0 = pos;
  4426. result0 = parse_hostname();
  4427. if (result0 === null) {
  4428. result0 = parse_IPv4address();
  4429. if (result0 === null) {
  4430. result0 = parse_IPv6reference();
  4431. }
  4432. }
  4433. if (result0 !== null) {
  4434. result0 = function (offset) {
  4435. data.host = input.substring(pos, offset).toLowerCase();
  4436. return data.host;
  4437. }(pos0);
  4438. }
  4439. if (result0 === null) {
  4440. pos = pos0;
  4441. }
  4442. return result0;
  4443. }
  4444. function parse_hostname() {
  4445. var result0, result1, result2;
  4446. var pos0, pos1, pos2;
  4447. pos0 = pos;
  4448. pos1 = pos;
  4449. result0 = [];
  4450. pos2 = pos;
  4451. result1 = parse_domainlabel();
  4452. if (result1 !== null) {
  4453. if (input.charCodeAt(pos) === 46) {
  4454. result2 = ".";
  4455. pos++;
  4456. } else {
  4457. result2 = null;
  4458. if (reportFailures === 0) {
  4459. matchFailed("\".\"");
  4460. }
  4461. }
  4462. if (result2 !== null) {
  4463. result1 = [result1, result2];
  4464. } else {
  4465. result1 = null;
  4466. pos = pos2;
  4467. }
  4468. } else {
  4469. result1 = null;
  4470. pos = pos2;
  4471. }
  4472. while (result1 !== null) {
  4473. result0.push(result1);
  4474. pos2 = pos;
  4475. result1 = parse_domainlabel();
  4476. if (result1 !== null) {
  4477. if (input.charCodeAt(pos) === 46) {
  4478. result2 = ".";
  4479. pos++;
  4480. } else {
  4481. result2 = null;
  4482. if (reportFailures === 0) {
  4483. matchFailed("\".\"");
  4484. }
  4485. }
  4486. if (result2 !== null) {
  4487. result1 = [result1, result2];
  4488. } else {
  4489. result1 = null;
  4490. pos = pos2;
  4491. }
  4492. } else {
  4493. result1 = null;
  4494. pos = pos2;
  4495. }
  4496. }
  4497. if (result0 !== null) {
  4498. result1 = parse_toplabel();
  4499. if (result1 !== null) {
  4500. if (input.charCodeAt(pos) === 46) {
  4501. result2 = ".";
  4502. pos++;
  4503. } else {
  4504. result2 = null;
  4505. if (reportFailures === 0) {
  4506. matchFailed("\".\"");
  4507. }
  4508. }
  4509. result2 = result2 !== null ? result2 : "";
  4510. if (result2 !== null) {
  4511. result0 = [result0, result1, result2];
  4512. } else {
  4513. result0 = null;
  4514. pos = pos1;
  4515. }
  4516. } else {
  4517. result0 = null;
  4518. pos = pos1;
  4519. }
  4520. } else {
  4521. result0 = null;
  4522. pos = pos1;
  4523. }
  4524. if (result0 !== null) {
  4525. result0 = function (offset) {
  4526. data.host_type = 'domain';
  4527. return input.substring(pos, offset);
  4528. }(pos0);
  4529. }
  4530. if (result0 === null) {
  4531. pos = pos0;
  4532. }
  4533. return result0;
  4534. }
  4535. function parse_domainlabel() {
  4536. var result0, result1, result2;
  4537. var pos0;
  4538. pos0 = pos;
  4539. result0 = parse_alphanum();
  4540. if (result0 !== null) {
  4541. result1 = [];
  4542. result2 = parse_alphanum();
  4543. if (result2 === null) {
  4544. if (input.charCodeAt(pos) === 45) {
  4545. result2 = "-";
  4546. pos++;
  4547. } else {
  4548. result2 = null;
  4549. if (reportFailures === 0) {
  4550. matchFailed("\"-\"");
  4551. }
  4552. }
  4553. if (result2 === null) {
  4554. if (input.charCodeAt(pos) === 95) {
  4555. result2 = "_";
  4556. pos++;
  4557. } else {
  4558. result2 = null;
  4559. if (reportFailures === 0) {
  4560. matchFailed("\"_\"");
  4561. }
  4562. }
  4563. }
  4564. }
  4565. while (result2 !== null) {
  4566. result1.push(result2);
  4567. result2 = parse_alphanum();
  4568. if (result2 === null) {
  4569. if (input.charCodeAt(pos) === 45) {
  4570. result2 = "-";
  4571. pos++;
  4572. } else {
  4573. result2 = null;
  4574. if (reportFailures === 0) {
  4575. matchFailed("\"-\"");
  4576. }
  4577. }
  4578. if (result2 === null) {
  4579. if (input.charCodeAt(pos) === 95) {
  4580. result2 = "_";
  4581. pos++;
  4582. } else {
  4583. result2 = null;
  4584. if (reportFailures === 0) {
  4585. matchFailed("\"_\"");
  4586. }
  4587. }
  4588. }
  4589. }
  4590. }
  4591. if (result1 !== null) {
  4592. result0 = [result0, result1];
  4593. } else {
  4594. result0 = null;
  4595. pos = pos0;
  4596. }
  4597. } else {
  4598. result0 = null;
  4599. pos = pos0;
  4600. }
  4601. return result0;
  4602. }
  4603. function parse_toplabel() {
  4604. var result0, result1, result2;
  4605. var pos0;
  4606. pos0 = pos;
  4607. result0 = parse_ALPHA();
  4608. if (result0 !== null) {
  4609. result1 = [];
  4610. result2 = parse_alphanum();
  4611. if (result2 === null) {
  4612. if (input.charCodeAt(pos) === 45) {
  4613. result2 = "-";
  4614. pos++;
  4615. } else {
  4616. result2 = null;
  4617. if (reportFailures === 0) {
  4618. matchFailed("\"-\"");
  4619. }
  4620. }
  4621. if (result2 === null) {
  4622. if (input.charCodeAt(pos) === 95) {
  4623. result2 = "_";
  4624. pos++;
  4625. } else {
  4626. result2 = null;
  4627. if (reportFailures === 0) {
  4628. matchFailed("\"_\"");
  4629. }
  4630. }
  4631. }
  4632. }
  4633. while (result2 !== null) {
  4634. result1.push(result2);
  4635. result2 = parse_alphanum();
  4636. if (result2 === null) {
  4637. if (input.charCodeAt(pos) === 45) {
  4638. result2 = "-";
  4639. pos++;
  4640. } else {
  4641. result2 = null;
  4642. if (reportFailures === 0) {
  4643. matchFailed("\"-\"");
  4644. }
  4645. }
  4646. if (result2 === null) {
  4647. if (input.charCodeAt(pos) === 95) {
  4648. result2 = "_";
  4649. pos++;
  4650. } else {
  4651. result2 = null;
  4652. if (reportFailures === 0) {
  4653. matchFailed("\"_\"");
  4654. }
  4655. }
  4656. }
  4657. }
  4658. }
  4659. if (result1 !== null) {
  4660. result0 = [result0, result1];
  4661. } else {
  4662. result0 = null;
  4663. pos = pos0;
  4664. }
  4665. } else {
  4666. result0 = null;
  4667. pos = pos0;
  4668. }
  4669. return result0;
  4670. }
  4671. function parse_IPv6reference() {
  4672. var result0, result1, result2;
  4673. var pos0, pos1;
  4674. pos0 = pos;
  4675. pos1 = pos;
  4676. if (input.charCodeAt(pos) === 91) {
  4677. result0 = "[";
  4678. pos++;
  4679. } else {
  4680. result0 = null;
  4681. if (reportFailures === 0) {
  4682. matchFailed("\"[\"");
  4683. }
  4684. }
  4685. if (result0 !== null) {
  4686. result1 = parse_IPv6address();
  4687. if (result1 !== null) {
  4688. if (input.charCodeAt(pos) === 93) {
  4689. result2 = "]";
  4690. pos++;
  4691. } else {
  4692. result2 = null;
  4693. if (reportFailures === 0) {
  4694. matchFailed("\"]\"");
  4695. }
  4696. }
  4697. if (result2 !== null) {
  4698. result0 = [result0, result1, result2];
  4699. } else {
  4700. result0 = null;
  4701. pos = pos1;
  4702. }
  4703. } else {
  4704. result0 = null;
  4705. pos = pos1;
  4706. }
  4707. } else {
  4708. result0 = null;
  4709. pos = pos1;
  4710. }
  4711. if (result0 !== null) {
  4712. result0 = function (offset) {
  4713. data.host_type = 'IPv6';
  4714. return input.substring(pos, offset);
  4715. }(pos0);
  4716. }
  4717. if (result0 === null) {
  4718. pos = pos0;
  4719. }
  4720. return result0;
  4721. }
  4722. function parse_IPv6address() {
  4723. var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12;
  4724. var pos0, pos1, pos2;
  4725. pos0 = pos;
  4726. pos1 = pos;
  4727. result0 = parse_h16();
  4728. if (result0 !== null) {
  4729. if (input.charCodeAt(pos) === 58) {
  4730. result1 = ":";
  4731. pos++;
  4732. } else {
  4733. result1 = null;
  4734. if (reportFailures === 0) {
  4735. matchFailed("\":\"");
  4736. }
  4737. }
  4738. if (result1 !== null) {
  4739. result2 = parse_h16();
  4740. if (result2 !== null) {
  4741. if (input.charCodeAt(pos) === 58) {
  4742. result3 = ":";
  4743. pos++;
  4744. } else {
  4745. result3 = null;
  4746. if (reportFailures === 0) {
  4747. matchFailed("\":\"");
  4748. }
  4749. }
  4750. if (result3 !== null) {
  4751. result4 = parse_h16();
  4752. if (result4 !== null) {
  4753. if (input.charCodeAt(pos) === 58) {
  4754. result5 = ":";
  4755. pos++;
  4756. } else {
  4757. result5 = null;
  4758. if (reportFailures === 0) {
  4759. matchFailed("\":\"");
  4760. }
  4761. }
  4762. if (result5 !== null) {
  4763. result6 = parse_h16();
  4764. if (result6 !== null) {
  4765. if (input.charCodeAt(pos) === 58) {
  4766. result7 = ":";
  4767. pos++;
  4768. } else {
  4769. result7 = null;
  4770. if (reportFailures === 0) {
  4771. matchFailed("\":\"");
  4772. }
  4773. }
  4774. if (result7 !== null) {
  4775. result8 = parse_h16();
  4776. if (result8 !== null) {
  4777. if (input.charCodeAt(pos) === 58) {
  4778. result9 = ":";
  4779. pos++;
  4780. } else {
  4781. result9 = null;
  4782. if (reportFailures === 0) {
  4783. matchFailed("\":\"");
  4784. }
  4785. }
  4786. if (result9 !== null) {
  4787. result10 = parse_h16();
  4788. if (result10 !== null) {
  4789. if (input.charCodeAt(pos) === 58) {
  4790. result11 = ":";
  4791. pos++;
  4792. } else {
  4793. result11 = null;
  4794. if (reportFailures === 0) {
  4795. matchFailed("\":\"");
  4796. }
  4797. }
  4798. if (result11 !== null) {
  4799. result12 = parse_ls32();
  4800. if (result12 !== null) {
  4801. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
  4802. } else {
  4803. result0 = null;
  4804. pos = pos1;
  4805. }
  4806. } else {
  4807. result0 = null;
  4808. pos = pos1;
  4809. }
  4810. } else {
  4811. result0 = null;
  4812. pos = pos1;
  4813. }
  4814. } else {
  4815. result0 = null;
  4816. pos = pos1;
  4817. }
  4818. } else {
  4819. result0 = null;
  4820. pos = pos1;
  4821. }
  4822. } else {
  4823. result0 = null;
  4824. pos = pos1;
  4825. }
  4826. } else {
  4827. result0 = null;
  4828. pos = pos1;
  4829. }
  4830. } else {
  4831. result0 = null;
  4832. pos = pos1;
  4833. }
  4834. } else {
  4835. result0 = null;
  4836. pos = pos1;
  4837. }
  4838. } else {
  4839. result0 = null;
  4840. pos = pos1;
  4841. }
  4842. } else {
  4843. result0 = null;
  4844. pos = pos1;
  4845. }
  4846. } else {
  4847. result0 = null;
  4848. pos = pos1;
  4849. }
  4850. } else {
  4851. result0 = null;
  4852. pos = pos1;
  4853. }
  4854. if (result0 === null) {
  4855. pos1 = pos;
  4856. if (input.substr(pos, 2) === "::") {
  4857. result0 = "::";
  4858. pos += 2;
  4859. } else {
  4860. result0 = null;
  4861. if (reportFailures === 0) {
  4862. matchFailed("\"::\"");
  4863. }
  4864. }
  4865. if (result0 !== null) {
  4866. result1 = parse_h16();
  4867. if (result1 !== null) {
  4868. if (input.charCodeAt(pos) === 58) {
  4869. result2 = ":";
  4870. pos++;
  4871. } else {
  4872. result2 = null;
  4873. if (reportFailures === 0) {
  4874. matchFailed("\":\"");
  4875. }
  4876. }
  4877. if (result2 !== null) {
  4878. result3 = parse_h16();
  4879. if (result3 !== null) {
  4880. if (input.charCodeAt(pos) === 58) {
  4881. result4 = ":";
  4882. pos++;
  4883. } else {
  4884. result4 = null;
  4885. if (reportFailures === 0) {
  4886. matchFailed("\":\"");
  4887. }
  4888. }
  4889. if (result4 !== null) {
  4890. result5 = parse_h16();
  4891. if (result5 !== null) {
  4892. if (input.charCodeAt(pos) === 58) {
  4893. result6 = ":";
  4894. pos++;
  4895. } else {
  4896. result6 = null;
  4897. if (reportFailures === 0) {
  4898. matchFailed("\":\"");
  4899. }
  4900. }
  4901. if (result6 !== null) {
  4902. result7 = parse_h16();
  4903. if (result7 !== null) {
  4904. if (input.charCodeAt(pos) === 58) {
  4905. result8 = ":";
  4906. pos++;
  4907. } else {
  4908. result8 = null;
  4909. if (reportFailures === 0) {
  4910. matchFailed("\":\"");
  4911. }
  4912. }
  4913. if (result8 !== null) {
  4914. result9 = parse_h16();
  4915. if (result9 !== null) {
  4916. if (input.charCodeAt(pos) === 58) {
  4917. result10 = ":";
  4918. pos++;
  4919. } else {
  4920. result10 = null;
  4921. if (reportFailures === 0) {
  4922. matchFailed("\":\"");
  4923. }
  4924. }
  4925. if (result10 !== null) {
  4926. result11 = parse_ls32();
  4927. if (result11 !== null) {
  4928. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11];
  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. } else {
  4966. result0 = null;
  4967. pos = pos1;
  4968. }
  4969. } else {
  4970. result0 = null;
  4971. pos = pos1;
  4972. }
  4973. } else {
  4974. result0 = null;
  4975. pos = pos1;
  4976. }
  4977. if (result0 === null) {
  4978. pos1 = pos;
  4979. if (input.substr(pos, 2) === "::") {
  4980. result0 = "::";
  4981. pos += 2;
  4982. } else {
  4983. result0 = null;
  4984. if (reportFailures === 0) {
  4985. matchFailed("\"::\"");
  4986. }
  4987. }
  4988. if (result0 !== null) {
  4989. result1 = parse_h16();
  4990. if (result1 !== null) {
  4991. if (input.charCodeAt(pos) === 58) {
  4992. result2 = ":";
  4993. pos++;
  4994. } else {
  4995. result2 = null;
  4996. if (reportFailures === 0) {
  4997. matchFailed("\":\"");
  4998. }
  4999. }
  5000. if (result2 !== null) {
  5001. result3 = parse_h16();
  5002. if (result3 !== null) {
  5003. if (input.charCodeAt(pos) === 58) {
  5004. result4 = ":";
  5005. pos++;
  5006. } else {
  5007. result4 = null;
  5008. if (reportFailures === 0) {
  5009. matchFailed("\":\"");
  5010. }
  5011. }
  5012. if (result4 !== null) {
  5013. result5 = parse_h16();
  5014. if (result5 !== null) {
  5015. if (input.charCodeAt(pos) === 58) {
  5016. result6 = ":";
  5017. pos++;
  5018. } else {
  5019. result6 = null;
  5020. if (reportFailures === 0) {
  5021. matchFailed("\":\"");
  5022. }
  5023. }
  5024. if (result6 !== null) {
  5025. result7 = parse_h16();
  5026. if (result7 !== null) {
  5027. if (input.charCodeAt(pos) === 58) {
  5028. result8 = ":";
  5029. pos++;
  5030. } else {
  5031. result8 = null;
  5032. if (reportFailures === 0) {
  5033. matchFailed("\":\"");
  5034. }
  5035. }
  5036. if (result8 !== null) {
  5037. result9 = parse_ls32();
  5038. if (result9 !== null) {
  5039. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  5040. } else {
  5041. result0 = null;
  5042. pos = pos1;
  5043. }
  5044. } else {
  5045. result0 = null;
  5046. pos = pos1;
  5047. }
  5048. } else {
  5049. result0 = null;
  5050. pos = pos1;
  5051. }
  5052. } else {
  5053. result0 = null;
  5054. pos = pos1;
  5055. }
  5056. } else {
  5057. result0 = null;
  5058. pos = pos1;
  5059. }
  5060. } else {
  5061. result0 = null;
  5062. pos = pos1;
  5063. }
  5064. } else {
  5065. result0 = null;
  5066. pos = pos1;
  5067. }
  5068. } else {
  5069. result0 = null;
  5070. pos = pos1;
  5071. }
  5072. } else {
  5073. result0 = null;
  5074. pos = pos1;
  5075. }
  5076. } else {
  5077. result0 = null;
  5078. pos = pos1;
  5079. }
  5080. if (result0 === null) {
  5081. pos1 = pos;
  5082. if (input.substr(pos, 2) === "::") {
  5083. result0 = "::";
  5084. pos += 2;
  5085. } else {
  5086. result0 = null;
  5087. if (reportFailures === 0) {
  5088. matchFailed("\"::\"");
  5089. }
  5090. }
  5091. if (result0 !== null) {
  5092. result1 = parse_h16();
  5093. if (result1 !== null) {
  5094. if (input.charCodeAt(pos) === 58) {
  5095. result2 = ":";
  5096. pos++;
  5097. } else {
  5098. result2 = null;
  5099. if (reportFailures === 0) {
  5100. matchFailed("\":\"");
  5101. }
  5102. }
  5103. if (result2 !== null) {
  5104. result3 = parse_h16();
  5105. if (result3 !== null) {
  5106. if (input.charCodeAt(pos) === 58) {
  5107. result4 = ":";
  5108. pos++;
  5109. } else {
  5110. result4 = null;
  5111. if (reportFailures === 0) {
  5112. matchFailed("\":\"");
  5113. }
  5114. }
  5115. if (result4 !== null) {
  5116. result5 = parse_h16();
  5117. if (result5 !== null) {
  5118. if (input.charCodeAt(pos) === 58) {
  5119. result6 = ":";
  5120. pos++;
  5121. } else {
  5122. result6 = null;
  5123. if (reportFailures === 0) {
  5124. matchFailed("\":\"");
  5125. }
  5126. }
  5127. if (result6 !== null) {
  5128. result7 = parse_ls32();
  5129. if (result7 !== null) {
  5130. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5131. } else {
  5132. result0 = null;
  5133. pos = pos1;
  5134. }
  5135. } else {
  5136. result0 = null;
  5137. pos = pos1;
  5138. }
  5139. } else {
  5140. result0 = null;
  5141. pos = pos1;
  5142. }
  5143. } else {
  5144. result0 = null;
  5145. pos = pos1;
  5146. }
  5147. } else {
  5148. result0 = null;
  5149. pos = pos1;
  5150. }
  5151. } else {
  5152. result0 = null;
  5153. pos = pos1;
  5154. }
  5155. } else {
  5156. result0 = null;
  5157. pos = pos1;
  5158. }
  5159. } else {
  5160. result0 = null;
  5161. pos = pos1;
  5162. }
  5163. if (result0 === null) {
  5164. pos1 = pos;
  5165. if (input.substr(pos, 2) === "::") {
  5166. result0 = "::";
  5167. pos += 2;
  5168. } else {
  5169. result0 = null;
  5170. if (reportFailures === 0) {
  5171. matchFailed("\"::\"");
  5172. }
  5173. }
  5174. if (result0 !== null) {
  5175. result1 = parse_h16();
  5176. if (result1 !== null) {
  5177. if (input.charCodeAt(pos) === 58) {
  5178. result2 = ":";
  5179. pos++;
  5180. } else {
  5181. result2 = null;
  5182. if (reportFailures === 0) {
  5183. matchFailed("\":\"");
  5184. }
  5185. }
  5186. if (result2 !== null) {
  5187. result3 = parse_h16();
  5188. if (result3 !== null) {
  5189. if (input.charCodeAt(pos) === 58) {
  5190. result4 = ":";
  5191. pos++;
  5192. } else {
  5193. result4 = null;
  5194. if (reportFailures === 0) {
  5195. matchFailed("\":\"");
  5196. }
  5197. }
  5198. if (result4 !== null) {
  5199. result5 = parse_ls32();
  5200. if (result5 !== null) {
  5201. result0 = [result0, result1, result2, result3, result4, result5];
  5202. } else {
  5203. result0 = null;
  5204. pos = pos1;
  5205. }
  5206. } else {
  5207. result0 = null;
  5208. pos = pos1;
  5209. }
  5210. } else {
  5211. result0 = null;
  5212. pos = pos1;
  5213. }
  5214. } else {
  5215. result0 = null;
  5216. pos = pos1;
  5217. }
  5218. } else {
  5219. result0 = null;
  5220. pos = pos1;
  5221. }
  5222. } else {
  5223. result0 = null;
  5224. pos = pos1;
  5225. }
  5226. if (result0 === null) {
  5227. pos1 = pos;
  5228. if (input.substr(pos, 2) === "::") {
  5229. result0 = "::";
  5230. pos += 2;
  5231. } else {
  5232. result0 = null;
  5233. if (reportFailures === 0) {
  5234. matchFailed("\"::\"");
  5235. }
  5236. }
  5237. if (result0 !== null) {
  5238. result1 = parse_h16();
  5239. if (result1 !== null) {
  5240. if (input.charCodeAt(pos) === 58) {
  5241. result2 = ":";
  5242. pos++;
  5243. } else {
  5244. result2 = null;
  5245. if (reportFailures === 0) {
  5246. matchFailed("\":\"");
  5247. }
  5248. }
  5249. if (result2 !== null) {
  5250. result3 = parse_ls32();
  5251. if (result3 !== null) {
  5252. result0 = [result0, result1, result2, result3];
  5253. } else {
  5254. result0 = null;
  5255. pos = pos1;
  5256. }
  5257. } else {
  5258. result0 = null;
  5259. pos = pos1;
  5260. }
  5261. } else {
  5262. result0 = null;
  5263. pos = pos1;
  5264. }
  5265. } else {
  5266. result0 = null;
  5267. pos = pos1;
  5268. }
  5269. if (result0 === null) {
  5270. pos1 = pos;
  5271. if (input.substr(pos, 2) === "::") {
  5272. result0 = "::";
  5273. pos += 2;
  5274. } else {
  5275. result0 = null;
  5276. if (reportFailures === 0) {
  5277. matchFailed("\"::\"");
  5278. }
  5279. }
  5280. if (result0 !== null) {
  5281. result1 = parse_ls32();
  5282. if (result1 !== null) {
  5283. result0 = [result0, result1];
  5284. } else {
  5285. result0 = null;
  5286. pos = pos1;
  5287. }
  5288. } else {
  5289. result0 = null;
  5290. pos = pos1;
  5291. }
  5292. if (result0 === null) {
  5293. pos1 = pos;
  5294. if (input.substr(pos, 2) === "::") {
  5295. result0 = "::";
  5296. pos += 2;
  5297. } else {
  5298. result0 = null;
  5299. if (reportFailures === 0) {
  5300. matchFailed("\"::\"");
  5301. }
  5302. }
  5303. if (result0 !== null) {
  5304. result1 = parse_h16();
  5305. if (result1 !== null) {
  5306. result0 = [result0, result1];
  5307. } else {
  5308. result0 = null;
  5309. pos = pos1;
  5310. }
  5311. } else {
  5312. result0 = null;
  5313. pos = pos1;
  5314. }
  5315. if (result0 === null) {
  5316. pos1 = pos;
  5317. result0 = parse_h16();
  5318. if (result0 !== null) {
  5319. if (input.substr(pos, 2) === "::") {
  5320. result1 = "::";
  5321. pos += 2;
  5322. } else {
  5323. result1 = null;
  5324. if (reportFailures === 0) {
  5325. matchFailed("\"::\"");
  5326. }
  5327. }
  5328. if (result1 !== null) {
  5329. result2 = parse_h16();
  5330. if (result2 !== null) {
  5331. if (input.charCodeAt(pos) === 58) {
  5332. result3 = ":";
  5333. pos++;
  5334. } else {
  5335. result3 = null;
  5336. if (reportFailures === 0) {
  5337. matchFailed("\":\"");
  5338. }
  5339. }
  5340. if (result3 !== null) {
  5341. result4 = parse_h16();
  5342. if (result4 !== null) {
  5343. if (input.charCodeAt(pos) === 58) {
  5344. result5 = ":";
  5345. pos++;
  5346. } else {
  5347. result5 = null;
  5348. if (reportFailures === 0) {
  5349. matchFailed("\":\"");
  5350. }
  5351. }
  5352. if (result5 !== null) {
  5353. result6 = parse_h16();
  5354. if (result6 !== null) {
  5355. if (input.charCodeAt(pos) === 58) {
  5356. result7 = ":";
  5357. pos++;
  5358. } else {
  5359. result7 = null;
  5360. if (reportFailures === 0) {
  5361. matchFailed("\":\"");
  5362. }
  5363. }
  5364. if (result7 !== null) {
  5365. result8 = parse_h16();
  5366. if (result8 !== null) {
  5367. if (input.charCodeAt(pos) === 58) {
  5368. result9 = ":";
  5369. pos++;
  5370. } else {
  5371. result9 = null;
  5372. if (reportFailures === 0) {
  5373. matchFailed("\":\"");
  5374. }
  5375. }
  5376. if (result9 !== null) {
  5377. result10 = parse_ls32();
  5378. if (result10 !== null) {
  5379. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10];
  5380. } else {
  5381. result0 = null;
  5382. pos = pos1;
  5383. }
  5384. } else {
  5385. result0 = null;
  5386. pos = pos1;
  5387. }
  5388. } else {
  5389. result0 = null;
  5390. pos = pos1;
  5391. }
  5392. } else {
  5393. result0 = null;
  5394. pos = pos1;
  5395. }
  5396. } else {
  5397. result0 = null;
  5398. pos = pos1;
  5399. }
  5400. } else {
  5401. result0 = null;
  5402. pos = pos1;
  5403. }
  5404. } else {
  5405. result0 = null;
  5406. pos = pos1;
  5407. }
  5408. } else {
  5409. result0 = null;
  5410. pos = pos1;
  5411. }
  5412. } else {
  5413. result0 = null;
  5414. pos = pos1;
  5415. }
  5416. } else {
  5417. result0 = null;
  5418. pos = pos1;
  5419. }
  5420. } else {
  5421. result0 = null;
  5422. pos = pos1;
  5423. }
  5424. if (result0 === null) {
  5425. pos1 = pos;
  5426. result0 = parse_h16();
  5427. if (result0 !== null) {
  5428. pos2 = pos;
  5429. if (input.charCodeAt(pos) === 58) {
  5430. result1 = ":";
  5431. pos++;
  5432. } else {
  5433. result1 = null;
  5434. if (reportFailures === 0) {
  5435. matchFailed("\":\"");
  5436. }
  5437. }
  5438. if (result1 !== null) {
  5439. result2 = parse_h16();
  5440. if (result2 !== null) {
  5441. result1 = [result1, result2];
  5442. } else {
  5443. result1 = null;
  5444. pos = pos2;
  5445. }
  5446. } else {
  5447. result1 = null;
  5448. pos = pos2;
  5449. }
  5450. result1 = result1 !== null ? result1 : "";
  5451. if (result1 !== null) {
  5452. if (input.substr(pos, 2) === "::") {
  5453. result2 = "::";
  5454. pos += 2;
  5455. } else {
  5456. result2 = null;
  5457. if (reportFailures === 0) {
  5458. matchFailed("\"::\"");
  5459. }
  5460. }
  5461. if (result2 !== null) {
  5462. result3 = parse_h16();
  5463. if (result3 !== null) {
  5464. if (input.charCodeAt(pos) === 58) {
  5465. result4 = ":";
  5466. pos++;
  5467. } else {
  5468. result4 = null;
  5469. if (reportFailures === 0) {
  5470. matchFailed("\":\"");
  5471. }
  5472. }
  5473. if (result4 !== null) {
  5474. result5 = parse_h16();
  5475. if (result5 !== null) {
  5476. if (input.charCodeAt(pos) === 58) {
  5477. result6 = ":";
  5478. pos++;
  5479. } else {
  5480. result6 = null;
  5481. if (reportFailures === 0) {
  5482. matchFailed("\":\"");
  5483. }
  5484. }
  5485. if (result6 !== null) {
  5486. result7 = parse_h16();
  5487. if (result7 !== null) {
  5488. if (input.charCodeAt(pos) === 58) {
  5489. result8 = ":";
  5490. pos++;
  5491. } else {
  5492. result8 = null;
  5493. if (reportFailures === 0) {
  5494. matchFailed("\":\"");
  5495. }
  5496. }
  5497. if (result8 !== null) {
  5498. result9 = parse_ls32();
  5499. if (result9 !== null) {
  5500. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  5501. } else {
  5502. result0 = null;
  5503. pos = pos1;
  5504. }
  5505. } else {
  5506. result0 = null;
  5507. pos = pos1;
  5508. }
  5509. } else {
  5510. result0 = null;
  5511. pos = pos1;
  5512. }
  5513. } else {
  5514. result0 = null;
  5515. pos = pos1;
  5516. }
  5517. } else {
  5518. result0 = null;
  5519. pos = pos1;
  5520. }
  5521. } else {
  5522. result0 = null;
  5523. pos = pos1;
  5524. }
  5525. } else {
  5526. result0 = null;
  5527. pos = pos1;
  5528. }
  5529. } else {
  5530. result0 = null;
  5531. pos = pos1;
  5532. }
  5533. } else {
  5534. result0 = null;
  5535. pos = pos1;
  5536. }
  5537. } else {
  5538. result0 = null;
  5539. pos = pos1;
  5540. }
  5541. if (result0 === null) {
  5542. pos1 = pos;
  5543. result0 = parse_h16();
  5544. if (result0 !== null) {
  5545. pos2 = pos;
  5546. if (input.charCodeAt(pos) === 58) {
  5547. result1 = ":";
  5548. pos++;
  5549. } else {
  5550. result1 = null;
  5551. if (reportFailures === 0) {
  5552. matchFailed("\":\"");
  5553. }
  5554. }
  5555. if (result1 !== null) {
  5556. result2 = parse_h16();
  5557. if (result2 !== null) {
  5558. result1 = [result1, result2];
  5559. } else {
  5560. result1 = null;
  5561. pos = pos2;
  5562. }
  5563. } else {
  5564. result1 = null;
  5565. pos = pos2;
  5566. }
  5567. result1 = result1 !== null ? result1 : "";
  5568. if (result1 !== null) {
  5569. pos2 = pos;
  5570. if (input.charCodeAt(pos) === 58) {
  5571. result2 = ":";
  5572. pos++;
  5573. } else {
  5574. result2 = null;
  5575. if (reportFailures === 0) {
  5576. matchFailed("\":\"");
  5577. }
  5578. }
  5579. if (result2 !== null) {
  5580. result3 = parse_h16();
  5581. if (result3 !== null) {
  5582. result2 = [result2, result3];
  5583. } else {
  5584. result2 = null;
  5585. pos = pos2;
  5586. }
  5587. } else {
  5588. result2 = null;
  5589. pos = pos2;
  5590. }
  5591. result2 = result2 !== null ? result2 : "";
  5592. if (result2 !== null) {
  5593. if (input.substr(pos, 2) === "::") {
  5594. result3 = "::";
  5595. pos += 2;
  5596. } else {
  5597. result3 = null;
  5598. if (reportFailures === 0) {
  5599. matchFailed("\"::\"");
  5600. }
  5601. }
  5602. if (result3 !== null) {
  5603. result4 = parse_h16();
  5604. if (result4 !== null) {
  5605. if (input.charCodeAt(pos) === 58) {
  5606. result5 = ":";
  5607. pos++;
  5608. } else {
  5609. result5 = null;
  5610. if (reportFailures === 0) {
  5611. matchFailed("\":\"");
  5612. }
  5613. }
  5614. if (result5 !== null) {
  5615. result6 = parse_h16();
  5616. if (result6 !== null) {
  5617. if (input.charCodeAt(pos) === 58) {
  5618. result7 = ":";
  5619. pos++;
  5620. } else {
  5621. result7 = null;
  5622. if (reportFailures === 0) {
  5623. matchFailed("\":\"");
  5624. }
  5625. }
  5626. if (result7 !== null) {
  5627. result8 = parse_ls32();
  5628. if (result8 !== null) {
  5629. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  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. } else {
  5651. result0 = null;
  5652. pos = pos1;
  5653. }
  5654. } else {
  5655. result0 = null;
  5656. pos = pos1;
  5657. }
  5658. } else {
  5659. result0 = null;
  5660. pos = pos1;
  5661. }
  5662. } else {
  5663. result0 = null;
  5664. pos = pos1;
  5665. }
  5666. if (result0 === null) {
  5667. pos1 = pos;
  5668. result0 = parse_h16();
  5669. if (result0 !== null) {
  5670. pos2 = pos;
  5671. if (input.charCodeAt(pos) === 58) {
  5672. result1 = ":";
  5673. pos++;
  5674. } else {
  5675. result1 = null;
  5676. if (reportFailures === 0) {
  5677. matchFailed("\":\"");
  5678. }
  5679. }
  5680. if (result1 !== null) {
  5681. result2 = parse_h16();
  5682. if (result2 !== null) {
  5683. result1 = [result1, result2];
  5684. } else {
  5685. result1 = null;
  5686. pos = pos2;
  5687. }
  5688. } else {
  5689. result1 = null;
  5690. pos = pos2;
  5691. }
  5692. result1 = result1 !== null ? result1 : "";
  5693. if (result1 !== null) {
  5694. pos2 = pos;
  5695. if (input.charCodeAt(pos) === 58) {
  5696. result2 = ":";
  5697. pos++;
  5698. } else {
  5699. result2 = null;
  5700. if (reportFailures === 0) {
  5701. matchFailed("\":\"");
  5702. }
  5703. }
  5704. if (result2 !== null) {
  5705. result3 = parse_h16();
  5706. if (result3 !== null) {
  5707. result2 = [result2, result3];
  5708. } else {
  5709. result2 = null;
  5710. pos = pos2;
  5711. }
  5712. } else {
  5713. result2 = null;
  5714. pos = pos2;
  5715. }
  5716. result2 = result2 !== null ? result2 : "";
  5717. if (result2 !== null) {
  5718. pos2 = pos;
  5719. if (input.charCodeAt(pos) === 58) {
  5720. result3 = ":";
  5721. pos++;
  5722. } else {
  5723. result3 = null;
  5724. if (reportFailures === 0) {
  5725. matchFailed("\":\"");
  5726. }
  5727. }
  5728. if (result3 !== null) {
  5729. result4 = parse_h16();
  5730. if (result4 !== null) {
  5731. result3 = [result3, result4];
  5732. } else {
  5733. result3 = null;
  5734. pos = pos2;
  5735. }
  5736. } else {
  5737. result3 = null;
  5738. pos = pos2;
  5739. }
  5740. result3 = result3 !== null ? result3 : "";
  5741. if (result3 !== null) {
  5742. if (input.substr(pos, 2) === "::") {
  5743. result4 = "::";
  5744. pos += 2;
  5745. } else {
  5746. result4 = null;
  5747. if (reportFailures === 0) {
  5748. matchFailed("\"::\"");
  5749. }
  5750. }
  5751. if (result4 !== null) {
  5752. result5 = parse_h16();
  5753. if (result5 !== null) {
  5754. if (input.charCodeAt(pos) === 58) {
  5755. result6 = ":";
  5756. pos++;
  5757. } else {
  5758. result6 = null;
  5759. if (reportFailures === 0) {
  5760. matchFailed("\":\"");
  5761. }
  5762. }
  5763. if (result6 !== null) {
  5764. result7 = parse_ls32();
  5765. if (result7 !== null) {
  5766. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5767. } else {
  5768. result0 = null;
  5769. pos = pos1;
  5770. }
  5771. } else {
  5772. result0 = null;
  5773. pos = pos1;
  5774. }
  5775. } else {
  5776. result0 = null;
  5777. pos = pos1;
  5778. }
  5779. } else {
  5780. result0 = null;
  5781. pos = pos1;
  5782. }
  5783. } else {
  5784. result0 = null;
  5785. pos = pos1;
  5786. }
  5787. } else {
  5788. result0 = null;
  5789. pos = pos1;
  5790. }
  5791. } else {
  5792. result0 = null;
  5793. pos = pos1;
  5794. }
  5795. } else {
  5796. result0 = null;
  5797. pos = pos1;
  5798. }
  5799. if (result0 === null) {
  5800. pos1 = pos;
  5801. result0 = parse_h16();
  5802. if (result0 !== null) {
  5803. pos2 = pos;
  5804. if (input.charCodeAt(pos) === 58) {
  5805. result1 = ":";
  5806. pos++;
  5807. } else {
  5808. result1 = null;
  5809. if (reportFailures === 0) {
  5810. matchFailed("\":\"");
  5811. }
  5812. }
  5813. if (result1 !== null) {
  5814. result2 = parse_h16();
  5815. if (result2 !== null) {
  5816. result1 = [result1, result2];
  5817. } else {
  5818. result1 = null;
  5819. pos = pos2;
  5820. }
  5821. } else {
  5822. result1 = null;
  5823. pos = pos2;
  5824. }
  5825. result1 = result1 !== null ? result1 : "";
  5826. if (result1 !== null) {
  5827. pos2 = pos;
  5828. if (input.charCodeAt(pos) === 58) {
  5829. result2 = ":";
  5830. pos++;
  5831. } else {
  5832. result2 = null;
  5833. if (reportFailures === 0) {
  5834. matchFailed("\":\"");
  5835. }
  5836. }
  5837. if (result2 !== null) {
  5838. result3 = parse_h16();
  5839. if (result3 !== null) {
  5840. result2 = [result2, result3];
  5841. } else {
  5842. result2 = null;
  5843. pos = pos2;
  5844. }
  5845. } else {
  5846. result2 = null;
  5847. pos = pos2;
  5848. }
  5849. result2 = result2 !== null ? result2 : "";
  5850. if (result2 !== null) {
  5851. pos2 = pos;
  5852. if (input.charCodeAt(pos) === 58) {
  5853. result3 = ":";
  5854. pos++;
  5855. } else {
  5856. result3 = null;
  5857. if (reportFailures === 0) {
  5858. matchFailed("\":\"");
  5859. }
  5860. }
  5861. if (result3 !== null) {
  5862. result4 = parse_h16();
  5863. if (result4 !== null) {
  5864. result3 = [result3, result4];
  5865. } else {
  5866. result3 = null;
  5867. pos = pos2;
  5868. }
  5869. } else {
  5870. result3 = null;
  5871. pos = pos2;
  5872. }
  5873. result3 = result3 !== null ? result3 : "";
  5874. if (result3 !== null) {
  5875. pos2 = pos;
  5876. if (input.charCodeAt(pos) === 58) {
  5877. result4 = ":";
  5878. pos++;
  5879. } else {
  5880. result4 = null;
  5881. if (reportFailures === 0) {
  5882. matchFailed("\":\"");
  5883. }
  5884. }
  5885. if (result4 !== null) {
  5886. result5 = parse_h16();
  5887. if (result5 !== null) {
  5888. result4 = [result4, result5];
  5889. } else {
  5890. result4 = null;
  5891. pos = pos2;
  5892. }
  5893. } else {
  5894. result4 = null;
  5895. pos = pos2;
  5896. }
  5897. result4 = result4 !== null ? result4 : "";
  5898. if (result4 !== null) {
  5899. if (input.substr(pos, 2) === "::") {
  5900. result5 = "::";
  5901. pos += 2;
  5902. } else {
  5903. result5 = null;
  5904. if (reportFailures === 0) {
  5905. matchFailed("\"::\"");
  5906. }
  5907. }
  5908. if (result5 !== null) {
  5909. result6 = parse_ls32();
  5910. if (result6 !== null) {
  5911. result0 = [result0, result1, result2, result3, result4, result5, result6];
  5912. } else {
  5913. result0 = null;
  5914. pos = pos1;
  5915. }
  5916. } else {
  5917. result0 = null;
  5918. pos = pos1;
  5919. }
  5920. } else {
  5921. result0 = null;
  5922. pos = pos1;
  5923. }
  5924. } else {
  5925. result0 = null;
  5926. pos = pos1;
  5927. }
  5928. } else {
  5929. result0 = null;
  5930. pos = pos1;
  5931. }
  5932. } else {
  5933. result0 = null;
  5934. pos = pos1;
  5935. }
  5936. } else {
  5937. result0 = null;
  5938. pos = pos1;
  5939. }
  5940. if (result0 === null) {
  5941. pos1 = pos;
  5942. result0 = parse_h16();
  5943. if (result0 !== null) {
  5944. pos2 = pos;
  5945. if (input.charCodeAt(pos) === 58) {
  5946. result1 = ":";
  5947. pos++;
  5948. } else {
  5949. result1 = null;
  5950. if (reportFailures === 0) {
  5951. matchFailed("\":\"");
  5952. }
  5953. }
  5954. if (result1 !== null) {
  5955. result2 = parse_h16();
  5956. if (result2 !== null) {
  5957. result1 = [result1, result2];
  5958. } else {
  5959. result1 = null;
  5960. pos = pos2;
  5961. }
  5962. } else {
  5963. result1 = null;
  5964. pos = pos2;
  5965. }
  5966. result1 = result1 !== null ? result1 : "";
  5967. if (result1 !== null) {
  5968. pos2 = pos;
  5969. if (input.charCodeAt(pos) === 58) {
  5970. result2 = ":";
  5971. pos++;
  5972. } else {
  5973. result2 = null;
  5974. if (reportFailures === 0) {
  5975. matchFailed("\":\"");
  5976. }
  5977. }
  5978. if (result2 !== null) {
  5979. result3 = parse_h16();
  5980. if (result3 !== null) {
  5981. result2 = [result2, result3];
  5982. } else {
  5983. result2 = null;
  5984. pos = pos2;
  5985. }
  5986. } else {
  5987. result2 = null;
  5988. pos = pos2;
  5989. }
  5990. result2 = result2 !== null ? result2 : "";
  5991. if (result2 !== null) {
  5992. pos2 = pos;
  5993. if (input.charCodeAt(pos) === 58) {
  5994. result3 = ":";
  5995. pos++;
  5996. } else {
  5997. result3 = null;
  5998. if (reportFailures === 0) {
  5999. matchFailed("\":\"");
  6000. }
  6001. }
  6002. if (result3 !== null) {
  6003. result4 = parse_h16();
  6004. if (result4 !== null) {
  6005. result3 = [result3, result4];
  6006. } else {
  6007. result3 = null;
  6008. pos = pos2;
  6009. }
  6010. } else {
  6011. result3 = null;
  6012. pos = pos2;
  6013. }
  6014. result3 = result3 !== null ? result3 : "";
  6015. if (result3 !== null) {
  6016. pos2 = pos;
  6017. if (input.charCodeAt(pos) === 58) {
  6018. result4 = ":";
  6019. pos++;
  6020. } else {
  6021. result4 = null;
  6022. if (reportFailures === 0) {
  6023. matchFailed("\":\"");
  6024. }
  6025. }
  6026. if (result4 !== null) {
  6027. result5 = parse_h16();
  6028. if (result5 !== null) {
  6029. result4 = [result4, result5];
  6030. } else {
  6031. result4 = null;
  6032. pos = pos2;
  6033. }
  6034. } else {
  6035. result4 = null;
  6036. pos = pos2;
  6037. }
  6038. result4 = result4 !== null ? result4 : "";
  6039. if (result4 !== null) {
  6040. pos2 = pos;
  6041. if (input.charCodeAt(pos) === 58) {
  6042. result5 = ":";
  6043. pos++;
  6044. } else {
  6045. result5 = null;
  6046. if (reportFailures === 0) {
  6047. matchFailed("\":\"");
  6048. }
  6049. }
  6050. if (result5 !== null) {
  6051. result6 = parse_h16();
  6052. if (result6 !== null) {
  6053. result5 = [result5, result6];
  6054. } else {
  6055. result5 = null;
  6056. pos = pos2;
  6057. }
  6058. } else {
  6059. result5 = null;
  6060. pos = pos2;
  6061. }
  6062. result5 = result5 !== null ? result5 : "";
  6063. if (result5 !== null) {
  6064. if (input.substr(pos, 2) === "::") {
  6065. result6 = "::";
  6066. pos += 2;
  6067. } else {
  6068. result6 = null;
  6069. if (reportFailures === 0) {
  6070. matchFailed("\"::\"");
  6071. }
  6072. }
  6073. if (result6 !== null) {
  6074. result7 = parse_h16();
  6075. if (result7 !== null) {
  6076. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  6077. } else {
  6078. result0 = null;
  6079. pos = pos1;
  6080. }
  6081. } else {
  6082. result0 = null;
  6083. pos = pos1;
  6084. }
  6085. } else {
  6086. result0 = null;
  6087. pos = pos1;
  6088. }
  6089. } else {
  6090. result0 = null;
  6091. pos = pos1;
  6092. }
  6093. } else {
  6094. result0 = null;
  6095. pos = pos1;
  6096. }
  6097. } else {
  6098. result0 = null;
  6099. pos = pos1;
  6100. }
  6101. } else {
  6102. result0 = null;
  6103. pos = pos1;
  6104. }
  6105. } else {
  6106. result0 = null;
  6107. pos = pos1;
  6108. }
  6109. if (result0 === null) {
  6110. pos1 = pos;
  6111. result0 = parse_h16();
  6112. if (result0 !== null) {
  6113. pos2 = pos;
  6114. if (input.charCodeAt(pos) === 58) {
  6115. result1 = ":";
  6116. pos++;
  6117. } else {
  6118. result1 = null;
  6119. if (reportFailures === 0) {
  6120. matchFailed("\":\"");
  6121. }
  6122. }
  6123. if (result1 !== null) {
  6124. result2 = parse_h16();
  6125. if (result2 !== null) {
  6126. result1 = [result1, result2];
  6127. } else {
  6128. result1 = null;
  6129. pos = pos2;
  6130. }
  6131. } else {
  6132. result1 = null;
  6133. pos = pos2;
  6134. }
  6135. result1 = result1 !== null ? result1 : "";
  6136. if (result1 !== null) {
  6137. pos2 = pos;
  6138. if (input.charCodeAt(pos) === 58) {
  6139. result2 = ":";
  6140. pos++;
  6141. } else {
  6142. result2 = null;
  6143. if (reportFailures === 0) {
  6144. matchFailed("\":\"");
  6145. }
  6146. }
  6147. if (result2 !== null) {
  6148. result3 = parse_h16();
  6149. if (result3 !== null) {
  6150. result2 = [result2, result3];
  6151. } else {
  6152. result2 = null;
  6153. pos = pos2;
  6154. }
  6155. } else {
  6156. result2 = null;
  6157. pos = pos2;
  6158. }
  6159. result2 = result2 !== null ? result2 : "";
  6160. if (result2 !== null) {
  6161. pos2 = pos;
  6162. if (input.charCodeAt(pos) === 58) {
  6163. result3 = ":";
  6164. pos++;
  6165. } else {
  6166. result3 = null;
  6167. if (reportFailures === 0) {
  6168. matchFailed("\":\"");
  6169. }
  6170. }
  6171. if (result3 !== null) {
  6172. result4 = parse_h16();
  6173. if (result4 !== null) {
  6174. result3 = [result3, result4];
  6175. } else {
  6176. result3 = null;
  6177. pos = pos2;
  6178. }
  6179. } else {
  6180. result3 = null;
  6181. pos = pos2;
  6182. }
  6183. result3 = result3 !== null ? result3 : "";
  6184. if (result3 !== null) {
  6185. pos2 = pos;
  6186. if (input.charCodeAt(pos) === 58) {
  6187. result4 = ":";
  6188. pos++;
  6189. } else {
  6190. result4 = null;
  6191. if (reportFailures === 0) {
  6192. matchFailed("\":\"");
  6193. }
  6194. }
  6195. if (result4 !== null) {
  6196. result5 = parse_h16();
  6197. if (result5 !== null) {
  6198. result4 = [result4, result5];
  6199. } else {
  6200. result4 = null;
  6201. pos = pos2;
  6202. }
  6203. } else {
  6204. result4 = null;
  6205. pos = pos2;
  6206. }
  6207. result4 = result4 !== null ? result4 : "";
  6208. if (result4 !== null) {
  6209. pos2 = pos;
  6210. if (input.charCodeAt(pos) === 58) {
  6211. result5 = ":";
  6212. pos++;
  6213. } else {
  6214. result5 = null;
  6215. if (reportFailures === 0) {
  6216. matchFailed("\":\"");
  6217. }
  6218. }
  6219. if (result5 !== null) {
  6220. result6 = parse_h16();
  6221. if (result6 !== null) {
  6222. result5 = [result5, result6];
  6223. } else {
  6224. result5 = null;
  6225. pos = pos2;
  6226. }
  6227. } else {
  6228. result5 = null;
  6229. pos = pos2;
  6230. }
  6231. result5 = result5 !== null ? result5 : "";
  6232. if (result5 !== null) {
  6233. pos2 = pos;
  6234. if (input.charCodeAt(pos) === 58) {
  6235. result6 = ":";
  6236. pos++;
  6237. } else {
  6238. result6 = null;
  6239. if (reportFailures === 0) {
  6240. matchFailed("\":\"");
  6241. }
  6242. }
  6243. if (result6 !== null) {
  6244. result7 = parse_h16();
  6245. if (result7 !== null) {
  6246. result6 = [result6, result7];
  6247. } else {
  6248. result6 = null;
  6249. pos = pos2;
  6250. }
  6251. } else {
  6252. result6 = null;
  6253. pos = pos2;
  6254. }
  6255. result6 = result6 !== null ? result6 : "";
  6256. if (result6 !== null) {
  6257. if (input.substr(pos, 2) === "::") {
  6258. result7 = "::";
  6259. pos += 2;
  6260. } else {
  6261. result7 = null;
  6262. if (reportFailures === 0) {
  6263. matchFailed("\"::\"");
  6264. }
  6265. }
  6266. if (result7 !== null) {
  6267. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  6268. } else {
  6269. result0 = null;
  6270. pos = pos1;
  6271. }
  6272. } else {
  6273. result0 = null;
  6274. pos = pos1;
  6275. }
  6276. } else {
  6277. result0 = null;
  6278. pos = pos1;
  6279. }
  6280. } else {
  6281. result0 = null;
  6282. pos = pos1;
  6283. }
  6284. } else {
  6285. result0 = null;
  6286. pos = pos1;
  6287. }
  6288. } else {
  6289. result0 = null;
  6290. pos = pos1;
  6291. }
  6292. } else {
  6293. result0 = null;
  6294. pos = pos1;
  6295. }
  6296. } else {
  6297. result0 = null;
  6298. pos = pos1;
  6299. }
  6300. }
  6301. }
  6302. }
  6303. }
  6304. }
  6305. }
  6306. }
  6307. }
  6308. }
  6309. }
  6310. }
  6311. }
  6312. }
  6313. }
  6314. if (result0 !== null) {
  6315. result0 = function (offset) {
  6316. data.host_type = 'IPv6';
  6317. return input.substring(pos, offset);
  6318. }(pos0);
  6319. }
  6320. if (result0 === null) {
  6321. pos = pos0;
  6322. }
  6323. return result0;
  6324. }
  6325. function parse_h16() {
  6326. var result0, result1, result2, result3;
  6327. var pos0;
  6328. pos0 = pos;
  6329. result0 = parse_HEXDIG();
  6330. if (result0 !== null) {
  6331. result1 = parse_HEXDIG();
  6332. result1 = result1 !== null ? result1 : "";
  6333. if (result1 !== null) {
  6334. result2 = parse_HEXDIG();
  6335. result2 = result2 !== null ? result2 : "";
  6336. if (result2 !== null) {
  6337. result3 = parse_HEXDIG();
  6338. result3 = result3 !== null ? result3 : "";
  6339. if (result3 !== null) {
  6340. result0 = [result0, result1, result2, result3];
  6341. } else {
  6342. result0 = null;
  6343. pos = pos0;
  6344. }
  6345. } else {
  6346. result0 = null;
  6347. pos = pos0;
  6348. }
  6349. } else {
  6350. result0 = null;
  6351. pos = pos0;
  6352. }
  6353. } else {
  6354. result0 = null;
  6355. pos = pos0;
  6356. }
  6357. return result0;
  6358. }
  6359. function parse_ls32() {
  6360. var result0, result1, result2;
  6361. var pos0;
  6362. pos0 = pos;
  6363. result0 = parse_h16();
  6364. if (result0 !== null) {
  6365. if (input.charCodeAt(pos) === 58) {
  6366. result1 = ":";
  6367. pos++;
  6368. } else {
  6369. result1 = null;
  6370. if (reportFailures === 0) {
  6371. matchFailed("\":\"");
  6372. }
  6373. }
  6374. if (result1 !== null) {
  6375. result2 = parse_h16();
  6376. if (result2 !== null) {
  6377. result0 = [result0, result1, result2];
  6378. } else {
  6379. result0 = null;
  6380. pos = pos0;
  6381. }
  6382. } else {
  6383. result0 = null;
  6384. pos = pos0;
  6385. }
  6386. } else {
  6387. result0 = null;
  6388. pos = pos0;
  6389. }
  6390. if (result0 === null) {
  6391. result0 = parse_IPv4address();
  6392. }
  6393. return result0;
  6394. }
  6395. function parse_IPv4address() {
  6396. var result0, result1, result2, result3, result4, result5, result6;
  6397. var pos0, pos1;
  6398. pos0 = pos;
  6399. pos1 = pos;
  6400. result0 = parse_dec_octet();
  6401. if (result0 !== null) {
  6402. if (input.charCodeAt(pos) === 46) {
  6403. result1 = ".";
  6404. pos++;
  6405. } else {
  6406. result1 = null;
  6407. if (reportFailures === 0) {
  6408. matchFailed("\".\"");
  6409. }
  6410. }
  6411. if (result1 !== null) {
  6412. result2 = parse_dec_octet();
  6413. if (result2 !== null) {
  6414. if (input.charCodeAt(pos) === 46) {
  6415. result3 = ".";
  6416. pos++;
  6417. } else {
  6418. result3 = null;
  6419. if (reportFailures === 0) {
  6420. matchFailed("\".\"");
  6421. }
  6422. }
  6423. if (result3 !== null) {
  6424. result4 = parse_dec_octet();
  6425. if (result4 !== null) {
  6426. if (input.charCodeAt(pos) === 46) {
  6427. result5 = ".";
  6428. pos++;
  6429. } else {
  6430. result5 = null;
  6431. if (reportFailures === 0) {
  6432. matchFailed("\".\"");
  6433. }
  6434. }
  6435. if (result5 !== null) {
  6436. result6 = parse_dec_octet();
  6437. if (result6 !== null) {
  6438. result0 = [result0, result1, result2, result3, result4, result5, result6];
  6439. } else {
  6440. result0 = null;
  6441. pos = pos1;
  6442. }
  6443. } else {
  6444. result0 = null;
  6445. pos = pos1;
  6446. }
  6447. } else {
  6448. result0 = null;
  6449. pos = pos1;
  6450. }
  6451. } else {
  6452. result0 = null;
  6453. pos = pos1;
  6454. }
  6455. } else {
  6456. result0 = null;
  6457. pos = pos1;
  6458. }
  6459. } else {
  6460. result0 = null;
  6461. pos = pos1;
  6462. }
  6463. } else {
  6464. result0 = null;
  6465. pos = pos1;
  6466. }
  6467. if (result0 !== null) {
  6468. result0 = function (offset) {
  6469. data.host_type = 'IPv4';
  6470. return input.substring(pos, offset);
  6471. }(pos0);
  6472. }
  6473. if (result0 === null) {
  6474. pos = pos0;
  6475. }
  6476. return result0;
  6477. }
  6478. function parse_dec_octet() {
  6479. var result0, result1, result2;
  6480. var pos0;
  6481. pos0 = pos;
  6482. if (input.substr(pos, 2) === "25") {
  6483. result0 = "25";
  6484. pos += 2;
  6485. } else {
  6486. result0 = null;
  6487. if (reportFailures === 0) {
  6488. matchFailed("\"25\"");
  6489. }
  6490. }
  6491. if (result0 !== null) {
  6492. if (/^[0-5]/.test(input.charAt(pos))) {
  6493. result1 = input.charAt(pos);
  6494. pos++;
  6495. } else {
  6496. result1 = null;
  6497. if (reportFailures === 0) {
  6498. matchFailed("[0-5]");
  6499. }
  6500. }
  6501. if (result1 !== null) {
  6502. result0 = [result0, result1];
  6503. } else {
  6504. result0 = null;
  6505. pos = pos0;
  6506. }
  6507. } else {
  6508. result0 = null;
  6509. pos = pos0;
  6510. }
  6511. if (result0 === null) {
  6512. pos0 = pos;
  6513. if (input.charCodeAt(pos) === 50) {
  6514. result0 = "2";
  6515. pos++;
  6516. } else {
  6517. result0 = null;
  6518. if (reportFailures === 0) {
  6519. matchFailed("\"2\"");
  6520. }
  6521. }
  6522. if (result0 !== null) {
  6523. if (/^[0-4]/.test(input.charAt(pos))) {
  6524. result1 = input.charAt(pos);
  6525. pos++;
  6526. } else {
  6527. result1 = null;
  6528. if (reportFailures === 0) {
  6529. matchFailed("[0-4]");
  6530. }
  6531. }
  6532. if (result1 !== null) {
  6533. result2 = parse_DIGIT();
  6534. if (result2 !== null) {
  6535. result0 = [result0, result1, result2];
  6536. } else {
  6537. result0 = null;
  6538. pos = pos0;
  6539. }
  6540. } else {
  6541. result0 = null;
  6542. pos = pos0;
  6543. }
  6544. } else {
  6545. result0 = null;
  6546. pos = pos0;
  6547. }
  6548. if (result0 === null) {
  6549. pos0 = pos;
  6550. if (input.charCodeAt(pos) === 49) {
  6551. result0 = "1";
  6552. pos++;
  6553. } else {
  6554. result0 = null;
  6555. if (reportFailures === 0) {
  6556. matchFailed("\"1\"");
  6557. }
  6558. }
  6559. if (result0 !== null) {
  6560. result1 = parse_DIGIT();
  6561. if (result1 !== null) {
  6562. result2 = parse_DIGIT();
  6563. if (result2 !== null) {
  6564. result0 = [result0, result1, result2];
  6565. } else {
  6566. result0 = null;
  6567. pos = pos0;
  6568. }
  6569. } else {
  6570. result0 = null;
  6571. pos = pos0;
  6572. }
  6573. } else {
  6574. result0 = null;
  6575. pos = pos0;
  6576. }
  6577. if (result0 === null) {
  6578. pos0 = pos;
  6579. if (/^[1-9]/.test(input.charAt(pos))) {
  6580. result0 = input.charAt(pos);
  6581. pos++;
  6582. } else {
  6583. result0 = null;
  6584. if (reportFailures === 0) {
  6585. matchFailed("[1-9]");
  6586. }
  6587. }
  6588. if (result0 !== null) {
  6589. result1 = parse_DIGIT();
  6590. if (result1 !== null) {
  6591. result0 = [result0, result1];
  6592. } else {
  6593. result0 = null;
  6594. pos = pos0;
  6595. }
  6596. } else {
  6597. result0 = null;
  6598. pos = pos0;
  6599. }
  6600. if (result0 === null) {
  6601. result0 = parse_DIGIT();
  6602. }
  6603. }
  6604. }
  6605. }
  6606. return result0;
  6607. }
  6608. function parse_port() {
  6609. var result0, result1, result2, result3, result4;
  6610. var pos0, pos1;
  6611. pos0 = pos;
  6612. pos1 = pos;
  6613. result0 = parse_DIGIT();
  6614. result0 = result0 !== null ? result0 : "";
  6615. if (result0 !== null) {
  6616. result1 = parse_DIGIT();
  6617. result1 = result1 !== null ? result1 : "";
  6618. if (result1 !== null) {
  6619. result2 = parse_DIGIT();
  6620. result2 = result2 !== null ? result2 : "";
  6621. if (result2 !== null) {
  6622. result3 = parse_DIGIT();
  6623. result3 = result3 !== null ? result3 : "";
  6624. if (result3 !== null) {
  6625. result4 = parse_DIGIT();
  6626. result4 = result4 !== null ? result4 : "";
  6627. if (result4 !== null) {
  6628. result0 = [result0, result1, result2, result3, result4];
  6629. } else {
  6630. result0 = null;
  6631. pos = pos1;
  6632. }
  6633. } else {
  6634. result0 = null;
  6635. pos = pos1;
  6636. }
  6637. } else {
  6638. result0 = null;
  6639. pos = pos1;
  6640. }
  6641. } else {
  6642. result0 = null;
  6643. pos = pos1;
  6644. }
  6645. } else {
  6646. result0 = null;
  6647. pos = pos1;
  6648. }
  6649. if (result0 !== null) {
  6650. result0 = function (offset, port) {
  6651. port = parseInt(port.join(''));
  6652. data.port = port;
  6653. return port;
  6654. }(pos0, result0);
  6655. }
  6656. if (result0 === null) {
  6657. pos = pos0;
  6658. }
  6659. return result0;
  6660. }
  6661. function parse_uri_parameters() {
  6662. var result0, result1, result2;
  6663. var pos0;
  6664. result0 = [];
  6665. pos0 = pos;
  6666. if (input.charCodeAt(pos) === 59) {
  6667. result1 = ";";
  6668. pos++;
  6669. } else {
  6670. result1 = null;
  6671. if (reportFailures === 0) {
  6672. matchFailed("\";\"");
  6673. }
  6674. }
  6675. if (result1 !== null) {
  6676. result2 = parse_uri_parameter();
  6677. if (result2 !== null) {
  6678. result1 = [result1, result2];
  6679. } else {
  6680. result1 = null;
  6681. pos = pos0;
  6682. }
  6683. } else {
  6684. result1 = null;
  6685. pos = pos0;
  6686. }
  6687. while (result1 !== null) {
  6688. result0.push(result1);
  6689. pos0 = pos;
  6690. if (input.charCodeAt(pos) === 59) {
  6691. result1 = ";";
  6692. pos++;
  6693. } else {
  6694. result1 = null;
  6695. if (reportFailures === 0) {
  6696. matchFailed("\";\"");
  6697. }
  6698. }
  6699. if (result1 !== null) {
  6700. result2 = parse_uri_parameter();
  6701. if (result2 !== null) {
  6702. result1 = [result1, result2];
  6703. } else {
  6704. result1 = null;
  6705. pos = pos0;
  6706. }
  6707. } else {
  6708. result1 = null;
  6709. pos = pos0;
  6710. }
  6711. }
  6712. return result0;
  6713. }
  6714. function parse_uri_parameter() {
  6715. var result0;
  6716. result0 = parse_transport_param();
  6717. if (result0 === null) {
  6718. result0 = parse_user_param();
  6719. if (result0 === null) {
  6720. result0 = parse_method_param();
  6721. if (result0 === null) {
  6722. result0 = parse_ttl_param();
  6723. if (result0 === null) {
  6724. result0 = parse_maddr_param();
  6725. if (result0 === null) {
  6726. result0 = parse_lr_param();
  6727. if (result0 === null) {
  6728. result0 = parse_other_param();
  6729. }
  6730. }
  6731. }
  6732. }
  6733. }
  6734. }
  6735. return result0;
  6736. }
  6737. function parse_transport_param() {
  6738. var result0, result1;
  6739. var pos0, pos1;
  6740. pos0 = pos;
  6741. pos1 = pos;
  6742. if (input.substr(pos, 10).toLowerCase() === "transport=") {
  6743. result0 = input.substr(pos, 10);
  6744. pos += 10;
  6745. } else {
  6746. result0 = null;
  6747. if (reportFailures === 0) {
  6748. matchFailed("\"transport=\"");
  6749. }
  6750. }
  6751. if (result0 !== null) {
  6752. if (input.substr(pos, 3).toLowerCase() === "udp") {
  6753. result1 = input.substr(pos, 3);
  6754. pos += 3;
  6755. } else {
  6756. result1 = null;
  6757. if (reportFailures === 0) {
  6758. matchFailed("\"udp\"");
  6759. }
  6760. }
  6761. if (result1 === null) {
  6762. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  6763. result1 = input.substr(pos, 3);
  6764. pos += 3;
  6765. } else {
  6766. result1 = null;
  6767. if (reportFailures === 0) {
  6768. matchFailed("\"tcp\"");
  6769. }
  6770. }
  6771. if (result1 === null) {
  6772. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  6773. result1 = input.substr(pos, 4);
  6774. pos += 4;
  6775. } else {
  6776. result1 = null;
  6777. if (reportFailures === 0) {
  6778. matchFailed("\"sctp\"");
  6779. }
  6780. }
  6781. if (result1 === null) {
  6782. if (input.substr(pos, 3).toLowerCase() === "tls") {
  6783. result1 = input.substr(pos, 3);
  6784. pos += 3;
  6785. } else {
  6786. result1 = null;
  6787. if (reportFailures === 0) {
  6788. matchFailed("\"tls\"");
  6789. }
  6790. }
  6791. if (result1 === null) {
  6792. result1 = parse_token();
  6793. }
  6794. }
  6795. }
  6796. }
  6797. if (result1 !== null) {
  6798. result0 = [result0, result1];
  6799. } else {
  6800. result0 = null;
  6801. pos = pos1;
  6802. }
  6803. } else {
  6804. result0 = null;
  6805. pos = pos1;
  6806. }
  6807. if (result0 !== null) {
  6808. result0 = function (offset, transport) {
  6809. if (!data.uri_params) data.uri_params = {};
  6810. data.uri_params['transport'] = transport.toLowerCase();
  6811. }(pos0, result0[1]);
  6812. }
  6813. if (result0 === null) {
  6814. pos = pos0;
  6815. }
  6816. return result0;
  6817. }
  6818. function parse_user_param() {
  6819. var result0, result1;
  6820. var pos0, pos1;
  6821. pos0 = pos;
  6822. pos1 = pos;
  6823. if (input.substr(pos, 5).toLowerCase() === "user=") {
  6824. result0 = input.substr(pos, 5);
  6825. pos += 5;
  6826. } else {
  6827. result0 = null;
  6828. if (reportFailures === 0) {
  6829. matchFailed("\"user=\"");
  6830. }
  6831. }
  6832. if (result0 !== null) {
  6833. if (input.substr(pos, 5).toLowerCase() === "phone") {
  6834. result1 = input.substr(pos, 5);
  6835. pos += 5;
  6836. } else {
  6837. result1 = null;
  6838. if (reportFailures === 0) {
  6839. matchFailed("\"phone\"");
  6840. }
  6841. }
  6842. if (result1 === null) {
  6843. if (input.substr(pos, 2).toLowerCase() === "ip") {
  6844. result1 = input.substr(pos, 2);
  6845. pos += 2;
  6846. } else {
  6847. result1 = null;
  6848. if (reportFailures === 0) {
  6849. matchFailed("\"ip\"");
  6850. }
  6851. }
  6852. if (result1 === null) {
  6853. result1 = parse_token();
  6854. }
  6855. }
  6856. if (result1 !== null) {
  6857. result0 = [result0, result1];
  6858. } else {
  6859. result0 = null;
  6860. pos = pos1;
  6861. }
  6862. } else {
  6863. result0 = null;
  6864. pos = pos1;
  6865. }
  6866. if (result0 !== null) {
  6867. result0 = function (offset, user) {
  6868. if (!data.uri_params) data.uri_params = {};
  6869. data.uri_params['user'] = user.toLowerCase();
  6870. }(pos0, result0[1]);
  6871. }
  6872. if (result0 === null) {
  6873. pos = pos0;
  6874. }
  6875. return result0;
  6876. }
  6877. function parse_method_param() {
  6878. var result0, result1;
  6879. var pos0, pos1;
  6880. pos0 = pos;
  6881. pos1 = pos;
  6882. if (input.substr(pos, 7).toLowerCase() === "method=") {
  6883. result0 = input.substr(pos, 7);
  6884. pos += 7;
  6885. } else {
  6886. result0 = null;
  6887. if (reportFailures === 0) {
  6888. matchFailed("\"method=\"");
  6889. }
  6890. }
  6891. if (result0 !== null) {
  6892. result1 = parse_Method();
  6893. if (result1 !== null) {
  6894. result0 = [result0, result1];
  6895. } else {
  6896. result0 = null;
  6897. pos = pos1;
  6898. }
  6899. } else {
  6900. result0 = null;
  6901. pos = pos1;
  6902. }
  6903. if (result0 !== null) {
  6904. result0 = function (offset, method) {
  6905. if (!data.uri_params) data.uri_params = {};
  6906. data.uri_params['method'] = method;
  6907. }(pos0, result0[1]);
  6908. }
  6909. if (result0 === null) {
  6910. pos = pos0;
  6911. }
  6912. return result0;
  6913. }
  6914. function parse_ttl_param() {
  6915. var result0, result1;
  6916. var pos0, pos1;
  6917. pos0 = pos;
  6918. pos1 = pos;
  6919. if (input.substr(pos, 4).toLowerCase() === "ttl=") {
  6920. result0 = input.substr(pos, 4);
  6921. pos += 4;
  6922. } else {
  6923. result0 = null;
  6924. if (reportFailures === 0) {
  6925. matchFailed("\"ttl=\"");
  6926. }
  6927. }
  6928. if (result0 !== null) {
  6929. result1 = parse_ttl();
  6930. if (result1 !== null) {
  6931. result0 = [result0, result1];
  6932. } else {
  6933. result0 = null;
  6934. pos = pos1;
  6935. }
  6936. } else {
  6937. result0 = null;
  6938. pos = pos1;
  6939. }
  6940. if (result0 !== null) {
  6941. result0 = function (offset, ttl) {
  6942. if (!data.params) data.params = {};
  6943. data.params['ttl'] = ttl;
  6944. }(pos0, result0[1]);
  6945. }
  6946. if (result0 === null) {
  6947. pos = pos0;
  6948. }
  6949. return result0;
  6950. }
  6951. function parse_maddr_param() {
  6952. var result0, result1;
  6953. var pos0, pos1;
  6954. pos0 = pos;
  6955. pos1 = pos;
  6956. if (input.substr(pos, 6).toLowerCase() === "maddr=") {
  6957. result0 = input.substr(pos, 6);
  6958. pos += 6;
  6959. } else {
  6960. result0 = null;
  6961. if (reportFailures === 0) {
  6962. matchFailed("\"maddr=\"");
  6963. }
  6964. }
  6965. if (result0 !== null) {
  6966. result1 = parse_host();
  6967. if (result1 !== null) {
  6968. result0 = [result0, result1];
  6969. } else {
  6970. result0 = null;
  6971. pos = pos1;
  6972. }
  6973. } else {
  6974. result0 = null;
  6975. pos = pos1;
  6976. }
  6977. if (result0 !== null) {
  6978. result0 = function (offset, maddr) {
  6979. if (!data.uri_params) data.uri_params = {};
  6980. data.uri_params['maddr'] = maddr;
  6981. }(pos0, result0[1]);
  6982. }
  6983. if (result0 === null) {
  6984. pos = pos0;
  6985. }
  6986. return result0;
  6987. }
  6988. function parse_lr_param() {
  6989. var result0, result1, result2;
  6990. var pos0, pos1, pos2;
  6991. pos0 = pos;
  6992. pos1 = pos;
  6993. if (input.substr(pos, 2).toLowerCase() === "lr") {
  6994. result0 = input.substr(pos, 2);
  6995. pos += 2;
  6996. } else {
  6997. result0 = null;
  6998. if (reportFailures === 0) {
  6999. matchFailed("\"lr\"");
  7000. }
  7001. }
  7002. if (result0 !== null) {
  7003. pos2 = pos;
  7004. if (input.charCodeAt(pos) === 61) {
  7005. result1 = "=";
  7006. pos++;
  7007. } else {
  7008. result1 = null;
  7009. if (reportFailures === 0) {
  7010. matchFailed("\"=\"");
  7011. }
  7012. }
  7013. if (result1 !== null) {
  7014. result2 = parse_token();
  7015. if (result2 !== null) {
  7016. result1 = [result1, result2];
  7017. } else {
  7018. result1 = null;
  7019. pos = pos2;
  7020. }
  7021. } else {
  7022. result1 = null;
  7023. pos = pos2;
  7024. }
  7025. result1 = result1 !== null ? result1 : "";
  7026. if (result1 !== null) {
  7027. result0 = [result0, result1];
  7028. } else {
  7029. result0 = null;
  7030. pos = pos1;
  7031. }
  7032. } else {
  7033. result0 = null;
  7034. pos = pos1;
  7035. }
  7036. if (result0 !== null) {
  7037. result0 = function (offset) {
  7038. if (!data.uri_params) data.uri_params = {};
  7039. data.uri_params['lr'] = undefined;
  7040. }(pos0);
  7041. }
  7042. if (result0 === null) {
  7043. pos = pos0;
  7044. }
  7045. return result0;
  7046. }
  7047. function parse_other_param() {
  7048. var result0, result1, result2;
  7049. var pos0, pos1, pos2;
  7050. pos0 = pos;
  7051. pos1 = pos;
  7052. result0 = parse_pname();
  7053. if (result0 !== null) {
  7054. pos2 = pos;
  7055. if (input.charCodeAt(pos) === 61) {
  7056. result1 = "=";
  7057. pos++;
  7058. } else {
  7059. result1 = null;
  7060. if (reportFailures === 0) {
  7061. matchFailed("\"=\"");
  7062. }
  7063. }
  7064. if (result1 !== null) {
  7065. result2 = parse_pvalue();
  7066. if (result2 !== null) {
  7067. result1 = [result1, result2];
  7068. } else {
  7069. result1 = null;
  7070. pos = pos2;
  7071. }
  7072. } else {
  7073. result1 = null;
  7074. pos = pos2;
  7075. }
  7076. result1 = result1 !== null ? result1 : "";
  7077. if (result1 !== null) {
  7078. result0 = [result0, result1];
  7079. } else {
  7080. result0 = null;
  7081. pos = pos1;
  7082. }
  7083. } else {
  7084. result0 = null;
  7085. pos = pos1;
  7086. }
  7087. if (result0 !== null) {
  7088. result0 = function (offset, param, value) {
  7089. if (!data.uri_params) data.uri_params = {};
  7090. if (typeof value === 'undefined') {
  7091. value = undefined;
  7092. } else {
  7093. value = value[1];
  7094. }
  7095. data.uri_params[param.toLowerCase()] = value;
  7096. }(pos0, result0[0], result0[1]);
  7097. }
  7098. if (result0 === null) {
  7099. pos = pos0;
  7100. }
  7101. return result0;
  7102. }
  7103. function parse_pname() {
  7104. var result0, result1;
  7105. var pos0;
  7106. pos0 = pos;
  7107. result1 = parse_paramchar();
  7108. if (result1 !== null) {
  7109. result0 = [];
  7110. while (result1 !== null) {
  7111. result0.push(result1);
  7112. result1 = parse_paramchar();
  7113. }
  7114. } else {
  7115. result0 = null;
  7116. }
  7117. if (result0 !== null) {
  7118. result0 = function (offset, pname) {
  7119. return pname.join('');
  7120. }(pos0, result0);
  7121. }
  7122. if (result0 === null) {
  7123. pos = pos0;
  7124. }
  7125. return result0;
  7126. }
  7127. function parse_pvalue() {
  7128. var result0, result1;
  7129. var pos0;
  7130. pos0 = pos;
  7131. result1 = parse_paramchar();
  7132. if (result1 !== null) {
  7133. result0 = [];
  7134. while (result1 !== null) {
  7135. result0.push(result1);
  7136. result1 = parse_paramchar();
  7137. }
  7138. } else {
  7139. result0 = null;
  7140. }
  7141. if (result0 !== null) {
  7142. result0 = function (offset, pvalue) {
  7143. return pvalue.join('');
  7144. }(pos0, result0);
  7145. }
  7146. if (result0 === null) {
  7147. pos = pos0;
  7148. }
  7149. return result0;
  7150. }
  7151. function parse_paramchar() {
  7152. var result0;
  7153. result0 = parse_param_unreserved();
  7154. if (result0 === null) {
  7155. result0 = parse_unreserved();
  7156. if (result0 === null) {
  7157. result0 = parse_escaped();
  7158. }
  7159. }
  7160. return result0;
  7161. }
  7162. function parse_param_unreserved() {
  7163. var result0;
  7164. if (input.charCodeAt(pos) === 91) {
  7165. result0 = "[";
  7166. pos++;
  7167. } else {
  7168. result0 = null;
  7169. if (reportFailures === 0) {
  7170. matchFailed("\"[\"");
  7171. }
  7172. }
  7173. if (result0 === null) {
  7174. if (input.charCodeAt(pos) === 93) {
  7175. result0 = "]";
  7176. pos++;
  7177. } else {
  7178. result0 = null;
  7179. if (reportFailures === 0) {
  7180. matchFailed("\"]\"");
  7181. }
  7182. }
  7183. if (result0 === null) {
  7184. if (input.charCodeAt(pos) === 47) {
  7185. result0 = "/";
  7186. pos++;
  7187. } else {
  7188. result0 = null;
  7189. if (reportFailures === 0) {
  7190. matchFailed("\"/\"");
  7191. }
  7192. }
  7193. if (result0 === null) {
  7194. if (input.charCodeAt(pos) === 58) {
  7195. result0 = ":";
  7196. pos++;
  7197. } else {
  7198. result0 = null;
  7199. if (reportFailures === 0) {
  7200. matchFailed("\":\"");
  7201. }
  7202. }
  7203. if (result0 === null) {
  7204. if (input.charCodeAt(pos) === 38) {
  7205. result0 = "&";
  7206. pos++;
  7207. } else {
  7208. result0 = null;
  7209. if (reportFailures === 0) {
  7210. matchFailed("\"&\"");
  7211. }
  7212. }
  7213. if (result0 === null) {
  7214. if (input.charCodeAt(pos) === 43) {
  7215. result0 = "+";
  7216. pos++;
  7217. } else {
  7218. result0 = null;
  7219. if (reportFailures === 0) {
  7220. matchFailed("\"+\"");
  7221. }
  7222. }
  7223. if (result0 === null) {
  7224. if (input.charCodeAt(pos) === 36) {
  7225. result0 = "$";
  7226. pos++;
  7227. } else {
  7228. result0 = null;
  7229. if (reportFailures === 0) {
  7230. matchFailed("\"$\"");
  7231. }
  7232. }
  7233. }
  7234. }
  7235. }
  7236. }
  7237. }
  7238. }
  7239. return result0;
  7240. }
  7241. function parse_headers() {
  7242. var result0, result1, result2, result3, result4;
  7243. var pos0, pos1;
  7244. pos0 = pos;
  7245. if (input.charCodeAt(pos) === 63) {
  7246. result0 = "?";
  7247. pos++;
  7248. } else {
  7249. result0 = null;
  7250. if (reportFailures === 0) {
  7251. matchFailed("\"?\"");
  7252. }
  7253. }
  7254. if (result0 !== null) {
  7255. result1 = parse_header();
  7256. if (result1 !== null) {
  7257. result2 = [];
  7258. pos1 = pos;
  7259. if (input.charCodeAt(pos) === 38) {
  7260. result3 = "&";
  7261. pos++;
  7262. } else {
  7263. result3 = null;
  7264. if (reportFailures === 0) {
  7265. matchFailed("\"&\"");
  7266. }
  7267. }
  7268. if (result3 !== null) {
  7269. result4 = parse_header();
  7270. if (result4 !== null) {
  7271. result3 = [result3, result4];
  7272. } else {
  7273. result3 = null;
  7274. pos = pos1;
  7275. }
  7276. } else {
  7277. result3 = null;
  7278. pos = pos1;
  7279. }
  7280. while (result3 !== null) {
  7281. result2.push(result3);
  7282. pos1 = pos;
  7283. if (input.charCodeAt(pos) === 38) {
  7284. result3 = "&";
  7285. pos++;
  7286. } else {
  7287. result3 = null;
  7288. if (reportFailures === 0) {
  7289. matchFailed("\"&\"");
  7290. }
  7291. }
  7292. if (result3 !== null) {
  7293. result4 = parse_header();
  7294. if (result4 !== null) {
  7295. result3 = [result3, result4];
  7296. } else {
  7297. result3 = null;
  7298. pos = pos1;
  7299. }
  7300. } else {
  7301. result3 = null;
  7302. pos = pos1;
  7303. }
  7304. }
  7305. if (result2 !== null) {
  7306. result0 = [result0, result1, result2];
  7307. } else {
  7308. result0 = null;
  7309. pos = pos0;
  7310. }
  7311. } else {
  7312. result0 = null;
  7313. pos = pos0;
  7314. }
  7315. } else {
  7316. result0 = null;
  7317. pos = pos0;
  7318. }
  7319. return result0;
  7320. }
  7321. function parse_header() {
  7322. var result0, result1, result2;
  7323. var pos0, pos1;
  7324. pos0 = pos;
  7325. pos1 = pos;
  7326. result0 = parse_hname();
  7327. if (result0 !== null) {
  7328. if (input.charCodeAt(pos) === 61) {
  7329. result1 = "=";
  7330. pos++;
  7331. } else {
  7332. result1 = null;
  7333. if (reportFailures === 0) {
  7334. matchFailed("\"=\"");
  7335. }
  7336. }
  7337. if (result1 !== null) {
  7338. result2 = parse_hvalue();
  7339. if (result2 !== null) {
  7340. result0 = [result0, result1, result2];
  7341. } else {
  7342. result0 = null;
  7343. pos = pos1;
  7344. }
  7345. } else {
  7346. result0 = null;
  7347. pos = pos1;
  7348. }
  7349. } else {
  7350. result0 = null;
  7351. pos = pos1;
  7352. }
  7353. if (result0 !== null) {
  7354. result0 = function (offset, hname, hvalue) {
  7355. hname = hname.join('').toLowerCase();
  7356. hvalue = hvalue.join('');
  7357. if (!data.uri_headers) data.uri_headers = {};
  7358. if (!data.uri_headers[hname]) {
  7359. data.uri_headers[hname] = [hvalue];
  7360. } else {
  7361. data.uri_headers[hname].push(hvalue);
  7362. }
  7363. }(pos0, result0[0], result0[2]);
  7364. }
  7365. if (result0 === null) {
  7366. pos = pos0;
  7367. }
  7368. return result0;
  7369. }
  7370. function parse_hname() {
  7371. var result0, result1;
  7372. result1 = parse_hnv_unreserved();
  7373. if (result1 === null) {
  7374. result1 = parse_unreserved();
  7375. if (result1 === null) {
  7376. result1 = parse_escaped();
  7377. }
  7378. }
  7379. if (result1 !== null) {
  7380. result0 = [];
  7381. while (result1 !== null) {
  7382. result0.push(result1);
  7383. result1 = parse_hnv_unreserved();
  7384. if (result1 === null) {
  7385. result1 = parse_unreserved();
  7386. if (result1 === null) {
  7387. result1 = parse_escaped();
  7388. }
  7389. }
  7390. }
  7391. } else {
  7392. result0 = null;
  7393. }
  7394. return result0;
  7395. }
  7396. function parse_hvalue() {
  7397. var result0, result1;
  7398. result0 = [];
  7399. result1 = parse_hnv_unreserved();
  7400. if (result1 === null) {
  7401. result1 = parse_unreserved();
  7402. if (result1 === null) {
  7403. result1 = parse_escaped();
  7404. }
  7405. }
  7406. while (result1 !== null) {
  7407. result0.push(result1);
  7408. result1 = parse_hnv_unreserved();
  7409. if (result1 === null) {
  7410. result1 = parse_unreserved();
  7411. if (result1 === null) {
  7412. result1 = parse_escaped();
  7413. }
  7414. }
  7415. }
  7416. return result0;
  7417. }
  7418. function parse_hnv_unreserved() {
  7419. var result0;
  7420. if (input.charCodeAt(pos) === 91) {
  7421. result0 = "[";
  7422. pos++;
  7423. } else {
  7424. result0 = null;
  7425. if (reportFailures === 0) {
  7426. matchFailed("\"[\"");
  7427. }
  7428. }
  7429. if (result0 === null) {
  7430. if (input.charCodeAt(pos) === 93) {
  7431. result0 = "]";
  7432. pos++;
  7433. } else {
  7434. result0 = null;
  7435. if (reportFailures === 0) {
  7436. matchFailed("\"]\"");
  7437. }
  7438. }
  7439. if (result0 === null) {
  7440. if (input.charCodeAt(pos) === 47) {
  7441. result0 = "/";
  7442. pos++;
  7443. } else {
  7444. result0 = null;
  7445. if (reportFailures === 0) {
  7446. matchFailed("\"/\"");
  7447. }
  7448. }
  7449. if (result0 === null) {
  7450. if (input.charCodeAt(pos) === 63) {
  7451. result0 = "?";
  7452. pos++;
  7453. } else {
  7454. result0 = null;
  7455. if (reportFailures === 0) {
  7456. matchFailed("\"?\"");
  7457. }
  7458. }
  7459. if (result0 === null) {
  7460. if (input.charCodeAt(pos) === 58) {
  7461. result0 = ":";
  7462. pos++;
  7463. } else {
  7464. result0 = null;
  7465. if (reportFailures === 0) {
  7466. matchFailed("\":\"");
  7467. }
  7468. }
  7469. if (result0 === null) {
  7470. if (input.charCodeAt(pos) === 43) {
  7471. result0 = "+";
  7472. pos++;
  7473. } else {
  7474. result0 = null;
  7475. if (reportFailures === 0) {
  7476. matchFailed("\"+\"");
  7477. }
  7478. }
  7479. if (result0 === null) {
  7480. if (input.charCodeAt(pos) === 36) {
  7481. result0 = "$";
  7482. pos++;
  7483. } else {
  7484. result0 = null;
  7485. if (reportFailures === 0) {
  7486. matchFailed("\"$\"");
  7487. }
  7488. }
  7489. }
  7490. }
  7491. }
  7492. }
  7493. }
  7494. }
  7495. return result0;
  7496. }
  7497. function parse_Request_Response() {
  7498. var result0;
  7499. result0 = parse_Status_Line();
  7500. if (result0 === null) {
  7501. result0 = parse_Request_Line();
  7502. }
  7503. return result0;
  7504. }
  7505. function parse_Request_Line() {
  7506. var result0, result1, result2, result3, result4;
  7507. var pos0;
  7508. pos0 = pos;
  7509. result0 = parse_Method();
  7510. if (result0 !== null) {
  7511. result1 = parse_SP();
  7512. if (result1 !== null) {
  7513. result2 = parse_Request_URI();
  7514. if (result2 !== null) {
  7515. result3 = parse_SP();
  7516. if (result3 !== null) {
  7517. result4 = parse_SIP_Version();
  7518. if (result4 !== null) {
  7519. result0 = [result0, result1, result2, result3, result4];
  7520. } else {
  7521. result0 = null;
  7522. pos = pos0;
  7523. }
  7524. } else {
  7525. result0 = null;
  7526. pos = pos0;
  7527. }
  7528. } else {
  7529. result0 = null;
  7530. pos = pos0;
  7531. }
  7532. } else {
  7533. result0 = null;
  7534. pos = pos0;
  7535. }
  7536. } else {
  7537. result0 = null;
  7538. pos = pos0;
  7539. }
  7540. return result0;
  7541. }
  7542. function parse_Request_URI() {
  7543. var result0;
  7544. result0 = parse_SIP_URI();
  7545. if (result0 === null) {
  7546. result0 = parse_absoluteURI();
  7547. }
  7548. return result0;
  7549. }
  7550. function parse_absoluteURI() {
  7551. var result0, result1, result2;
  7552. var pos0;
  7553. pos0 = pos;
  7554. result0 = parse_scheme();
  7555. if (result0 !== null) {
  7556. if (input.charCodeAt(pos) === 58) {
  7557. result1 = ":";
  7558. pos++;
  7559. } else {
  7560. result1 = null;
  7561. if (reportFailures === 0) {
  7562. matchFailed("\":\"");
  7563. }
  7564. }
  7565. if (result1 !== null) {
  7566. result2 = parse_hier_part();
  7567. if (result2 === null) {
  7568. result2 = parse_opaque_part();
  7569. }
  7570. if (result2 !== null) {
  7571. result0 = [result0, result1, result2];
  7572. } else {
  7573. result0 = null;
  7574. pos = pos0;
  7575. }
  7576. } else {
  7577. result0 = null;
  7578. pos = pos0;
  7579. }
  7580. } else {
  7581. result0 = null;
  7582. pos = pos0;
  7583. }
  7584. return result0;
  7585. }
  7586. function parse_hier_part() {
  7587. var result0, result1, result2;
  7588. var pos0, pos1;
  7589. pos0 = pos;
  7590. result0 = parse_net_path();
  7591. if (result0 === null) {
  7592. result0 = parse_abs_path();
  7593. }
  7594. if (result0 !== null) {
  7595. pos1 = pos;
  7596. if (input.charCodeAt(pos) === 63) {
  7597. result1 = "?";
  7598. pos++;
  7599. } else {
  7600. result1 = null;
  7601. if (reportFailures === 0) {
  7602. matchFailed("\"?\"");
  7603. }
  7604. }
  7605. if (result1 !== null) {
  7606. result2 = parse_query();
  7607. if (result2 !== null) {
  7608. result1 = [result1, result2];
  7609. } else {
  7610. result1 = null;
  7611. pos = pos1;
  7612. }
  7613. } else {
  7614. result1 = null;
  7615. pos = pos1;
  7616. }
  7617. result1 = result1 !== null ? result1 : "";
  7618. if (result1 !== null) {
  7619. result0 = [result0, result1];
  7620. } else {
  7621. result0 = null;
  7622. pos = pos0;
  7623. }
  7624. } else {
  7625. result0 = null;
  7626. pos = pos0;
  7627. }
  7628. return result0;
  7629. }
  7630. function parse_net_path() {
  7631. var result0, result1, result2;
  7632. var pos0;
  7633. pos0 = pos;
  7634. if (input.substr(pos, 2) === "//") {
  7635. result0 = "//";
  7636. pos += 2;
  7637. } else {
  7638. result0 = null;
  7639. if (reportFailures === 0) {
  7640. matchFailed("\"//\"");
  7641. }
  7642. }
  7643. if (result0 !== null) {
  7644. result1 = parse_authority();
  7645. if (result1 !== null) {
  7646. result2 = parse_abs_path();
  7647. result2 = result2 !== null ? result2 : "";
  7648. if (result2 !== null) {
  7649. result0 = [result0, result1, result2];
  7650. } else {
  7651. result0 = null;
  7652. pos = pos0;
  7653. }
  7654. } else {
  7655. result0 = null;
  7656. pos = pos0;
  7657. }
  7658. } else {
  7659. result0 = null;
  7660. pos = pos0;
  7661. }
  7662. return result0;
  7663. }
  7664. function parse_abs_path() {
  7665. var result0, result1;
  7666. var pos0;
  7667. pos0 = pos;
  7668. if (input.charCodeAt(pos) === 47) {
  7669. result0 = "/";
  7670. pos++;
  7671. } else {
  7672. result0 = null;
  7673. if (reportFailures === 0) {
  7674. matchFailed("\"/\"");
  7675. }
  7676. }
  7677. if (result0 !== null) {
  7678. result1 = parse_path_segments();
  7679. if (result1 !== null) {
  7680. result0 = [result0, result1];
  7681. } else {
  7682. result0 = null;
  7683. pos = pos0;
  7684. }
  7685. } else {
  7686. result0 = null;
  7687. pos = pos0;
  7688. }
  7689. return result0;
  7690. }
  7691. function parse_opaque_part() {
  7692. var result0, result1, result2;
  7693. var pos0;
  7694. pos0 = pos;
  7695. result0 = parse_uric_no_slash();
  7696. if (result0 !== null) {
  7697. result1 = [];
  7698. result2 = parse_uric();
  7699. while (result2 !== null) {
  7700. result1.push(result2);
  7701. result2 = parse_uric();
  7702. }
  7703. if (result1 !== null) {
  7704. result0 = [result0, result1];
  7705. } else {
  7706. result0 = null;
  7707. pos = pos0;
  7708. }
  7709. } else {
  7710. result0 = null;
  7711. pos = pos0;
  7712. }
  7713. return result0;
  7714. }
  7715. function parse_uric() {
  7716. var result0;
  7717. result0 = parse_reserved();
  7718. if (result0 === null) {
  7719. result0 = parse_unreserved();
  7720. if (result0 === null) {
  7721. result0 = parse_escaped();
  7722. }
  7723. }
  7724. return result0;
  7725. }
  7726. function parse_uric_no_slash() {
  7727. var result0;
  7728. result0 = parse_unreserved();
  7729. if (result0 === null) {
  7730. result0 = parse_escaped();
  7731. if (result0 === null) {
  7732. if (input.charCodeAt(pos) === 59) {
  7733. result0 = ";";
  7734. pos++;
  7735. } else {
  7736. result0 = null;
  7737. if (reportFailures === 0) {
  7738. matchFailed("\";\"");
  7739. }
  7740. }
  7741. if (result0 === null) {
  7742. if (input.charCodeAt(pos) === 63) {
  7743. result0 = "?";
  7744. pos++;
  7745. } else {
  7746. result0 = null;
  7747. if (reportFailures === 0) {
  7748. matchFailed("\"?\"");
  7749. }
  7750. }
  7751. if (result0 === null) {
  7752. if (input.charCodeAt(pos) === 58) {
  7753. result0 = ":";
  7754. pos++;
  7755. } else {
  7756. result0 = null;
  7757. if (reportFailures === 0) {
  7758. matchFailed("\":\"");
  7759. }
  7760. }
  7761. if (result0 === null) {
  7762. if (input.charCodeAt(pos) === 64) {
  7763. result0 = "@";
  7764. pos++;
  7765. } else {
  7766. result0 = null;
  7767. if (reportFailures === 0) {
  7768. matchFailed("\"@\"");
  7769. }
  7770. }
  7771. if (result0 === null) {
  7772. if (input.charCodeAt(pos) === 38) {
  7773. result0 = "&";
  7774. pos++;
  7775. } else {
  7776. result0 = null;
  7777. if (reportFailures === 0) {
  7778. matchFailed("\"&\"");
  7779. }
  7780. }
  7781. if (result0 === null) {
  7782. if (input.charCodeAt(pos) === 61) {
  7783. result0 = "=";
  7784. pos++;
  7785. } else {
  7786. result0 = null;
  7787. if (reportFailures === 0) {
  7788. matchFailed("\"=\"");
  7789. }
  7790. }
  7791. if (result0 === null) {
  7792. if (input.charCodeAt(pos) === 43) {
  7793. result0 = "+";
  7794. pos++;
  7795. } else {
  7796. result0 = null;
  7797. if (reportFailures === 0) {
  7798. matchFailed("\"+\"");
  7799. }
  7800. }
  7801. if (result0 === null) {
  7802. if (input.charCodeAt(pos) === 36) {
  7803. result0 = "$";
  7804. pos++;
  7805. } else {
  7806. result0 = null;
  7807. if (reportFailures === 0) {
  7808. matchFailed("\"$\"");
  7809. }
  7810. }
  7811. if (result0 === null) {
  7812. if (input.charCodeAt(pos) === 44) {
  7813. result0 = ",";
  7814. pos++;
  7815. } else {
  7816. result0 = null;
  7817. if (reportFailures === 0) {
  7818. matchFailed("\",\"");
  7819. }
  7820. }
  7821. }
  7822. }
  7823. }
  7824. }
  7825. }
  7826. }
  7827. }
  7828. }
  7829. }
  7830. }
  7831. return result0;
  7832. }
  7833. function parse_path_segments() {
  7834. var result0, result1, result2, result3;
  7835. var pos0, pos1;
  7836. pos0 = pos;
  7837. result0 = parse_segment();
  7838. if (result0 !== null) {
  7839. result1 = [];
  7840. pos1 = pos;
  7841. if (input.charCodeAt(pos) === 47) {
  7842. result2 = "/";
  7843. pos++;
  7844. } else {
  7845. result2 = null;
  7846. if (reportFailures === 0) {
  7847. matchFailed("\"/\"");
  7848. }
  7849. }
  7850. if (result2 !== null) {
  7851. result3 = parse_segment();
  7852. if (result3 !== null) {
  7853. result2 = [result2, result3];
  7854. } else {
  7855. result2 = null;
  7856. pos = pos1;
  7857. }
  7858. } else {
  7859. result2 = null;
  7860. pos = pos1;
  7861. }
  7862. while (result2 !== null) {
  7863. result1.push(result2);
  7864. pos1 = pos;
  7865. if (input.charCodeAt(pos) === 47) {
  7866. result2 = "/";
  7867. pos++;
  7868. } else {
  7869. result2 = null;
  7870. if (reportFailures === 0) {
  7871. matchFailed("\"/\"");
  7872. }
  7873. }
  7874. if (result2 !== null) {
  7875. result3 = parse_segment();
  7876. if (result3 !== null) {
  7877. result2 = [result2, result3];
  7878. } else {
  7879. result2 = null;
  7880. pos = pos1;
  7881. }
  7882. } else {
  7883. result2 = null;
  7884. pos = pos1;
  7885. }
  7886. }
  7887. if (result1 !== null) {
  7888. result0 = [result0, result1];
  7889. } else {
  7890. result0 = null;
  7891. pos = pos0;
  7892. }
  7893. } else {
  7894. result0 = null;
  7895. pos = pos0;
  7896. }
  7897. return result0;
  7898. }
  7899. function parse_segment() {
  7900. var result0, result1, result2, result3;
  7901. var pos0, pos1;
  7902. pos0 = pos;
  7903. result0 = [];
  7904. result1 = parse_pchar();
  7905. while (result1 !== null) {
  7906. result0.push(result1);
  7907. result1 = parse_pchar();
  7908. }
  7909. if (result0 !== null) {
  7910. result1 = [];
  7911. pos1 = pos;
  7912. if (input.charCodeAt(pos) === 59) {
  7913. result2 = ";";
  7914. pos++;
  7915. } else {
  7916. result2 = null;
  7917. if (reportFailures === 0) {
  7918. matchFailed("\";\"");
  7919. }
  7920. }
  7921. if (result2 !== null) {
  7922. result3 = parse_param();
  7923. if (result3 !== null) {
  7924. result2 = [result2, result3];
  7925. } else {
  7926. result2 = null;
  7927. pos = pos1;
  7928. }
  7929. } else {
  7930. result2 = null;
  7931. pos = pos1;
  7932. }
  7933. while (result2 !== null) {
  7934. result1.push(result2);
  7935. pos1 = pos;
  7936. if (input.charCodeAt(pos) === 59) {
  7937. result2 = ";";
  7938. pos++;
  7939. } else {
  7940. result2 = null;
  7941. if (reportFailures === 0) {
  7942. matchFailed("\";\"");
  7943. }
  7944. }
  7945. if (result2 !== null) {
  7946. result3 = parse_param();
  7947. if (result3 !== null) {
  7948. result2 = [result2, result3];
  7949. } else {
  7950. result2 = null;
  7951. pos = pos1;
  7952. }
  7953. } else {
  7954. result2 = null;
  7955. pos = pos1;
  7956. }
  7957. }
  7958. if (result1 !== null) {
  7959. result0 = [result0, result1];
  7960. } else {
  7961. result0 = null;
  7962. pos = pos0;
  7963. }
  7964. } else {
  7965. result0 = null;
  7966. pos = pos0;
  7967. }
  7968. return result0;
  7969. }
  7970. function parse_param() {
  7971. var result0, result1;
  7972. result0 = [];
  7973. result1 = parse_pchar();
  7974. while (result1 !== null) {
  7975. result0.push(result1);
  7976. result1 = parse_pchar();
  7977. }
  7978. return result0;
  7979. }
  7980. function parse_pchar() {
  7981. var result0;
  7982. result0 = parse_unreserved();
  7983. if (result0 === null) {
  7984. result0 = parse_escaped();
  7985. if (result0 === null) {
  7986. if (input.charCodeAt(pos) === 58) {
  7987. result0 = ":";
  7988. pos++;
  7989. } else {
  7990. result0 = null;
  7991. if (reportFailures === 0) {
  7992. matchFailed("\":\"");
  7993. }
  7994. }
  7995. if (result0 === null) {
  7996. if (input.charCodeAt(pos) === 64) {
  7997. result0 = "@";
  7998. pos++;
  7999. } else {
  8000. result0 = null;
  8001. if (reportFailures === 0) {
  8002. matchFailed("\"@\"");
  8003. }
  8004. }
  8005. if (result0 === null) {
  8006. if (input.charCodeAt(pos) === 38) {
  8007. result0 = "&";
  8008. pos++;
  8009. } else {
  8010. result0 = null;
  8011. if (reportFailures === 0) {
  8012. matchFailed("\"&\"");
  8013. }
  8014. }
  8015. if (result0 === null) {
  8016. if (input.charCodeAt(pos) === 61) {
  8017. result0 = "=";
  8018. pos++;
  8019. } else {
  8020. result0 = null;
  8021. if (reportFailures === 0) {
  8022. matchFailed("\"=\"");
  8023. }
  8024. }
  8025. if (result0 === null) {
  8026. if (input.charCodeAt(pos) === 43) {
  8027. result0 = "+";
  8028. pos++;
  8029. } else {
  8030. result0 = null;
  8031. if (reportFailures === 0) {
  8032. matchFailed("\"+\"");
  8033. }
  8034. }
  8035. if (result0 === null) {
  8036. if (input.charCodeAt(pos) === 36) {
  8037. result0 = "$";
  8038. pos++;
  8039. } else {
  8040. result0 = null;
  8041. if (reportFailures === 0) {
  8042. matchFailed("\"$\"");
  8043. }
  8044. }
  8045. if (result0 === null) {
  8046. if (input.charCodeAt(pos) === 44) {
  8047. result0 = ",";
  8048. pos++;
  8049. } else {
  8050. result0 = null;
  8051. if (reportFailures === 0) {
  8052. matchFailed("\",\"");
  8053. }
  8054. }
  8055. }
  8056. }
  8057. }
  8058. }
  8059. }
  8060. }
  8061. }
  8062. }
  8063. return result0;
  8064. }
  8065. function parse_scheme() {
  8066. var result0, result1, result2;
  8067. var pos0, pos1;
  8068. pos0 = pos;
  8069. pos1 = pos;
  8070. result0 = parse_ALPHA();
  8071. if (result0 !== null) {
  8072. result1 = [];
  8073. result2 = parse_ALPHA();
  8074. if (result2 === null) {
  8075. result2 = parse_DIGIT();
  8076. if (result2 === null) {
  8077. if (input.charCodeAt(pos) === 43) {
  8078. result2 = "+";
  8079. pos++;
  8080. } else {
  8081. result2 = null;
  8082. if (reportFailures === 0) {
  8083. matchFailed("\"+\"");
  8084. }
  8085. }
  8086. if (result2 === null) {
  8087. if (input.charCodeAt(pos) === 45) {
  8088. result2 = "-";
  8089. pos++;
  8090. } else {
  8091. result2 = null;
  8092. if (reportFailures === 0) {
  8093. matchFailed("\"-\"");
  8094. }
  8095. }
  8096. if (result2 === null) {
  8097. if (input.charCodeAt(pos) === 46) {
  8098. result2 = ".";
  8099. pos++;
  8100. } else {
  8101. result2 = null;
  8102. if (reportFailures === 0) {
  8103. matchFailed("\".\"");
  8104. }
  8105. }
  8106. }
  8107. }
  8108. }
  8109. }
  8110. while (result2 !== null) {
  8111. result1.push(result2);
  8112. result2 = parse_ALPHA();
  8113. if (result2 === null) {
  8114. result2 = parse_DIGIT();
  8115. if (result2 === null) {
  8116. if (input.charCodeAt(pos) === 43) {
  8117. result2 = "+";
  8118. pos++;
  8119. } else {
  8120. result2 = null;
  8121. if (reportFailures === 0) {
  8122. matchFailed("\"+\"");
  8123. }
  8124. }
  8125. if (result2 === null) {
  8126. if (input.charCodeAt(pos) === 45) {
  8127. result2 = "-";
  8128. pos++;
  8129. } else {
  8130. result2 = null;
  8131. if (reportFailures === 0) {
  8132. matchFailed("\"-\"");
  8133. }
  8134. }
  8135. if (result2 === null) {
  8136. if (input.charCodeAt(pos) === 46) {
  8137. result2 = ".";
  8138. pos++;
  8139. } else {
  8140. result2 = null;
  8141. if (reportFailures === 0) {
  8142. matchFailed("\".\"");
  8143. }
  8144. }
  8145. }
  8146. }
  8147. }
  8148. }
  8149. }
  8150. if (result1 !== null) {
  8151. result0 = [result0, result1];
  8152. } else {
  8153. result0 = null;
  8154. pos = pos1;
  8155. }
  8156. } else {
  8157. result0 = null;
  8158. pos = pos1;
  8159. }
  8160. if (result0 !== null) {
  8161. result0 = function (offset) {
  8162. data.scheme = input.substring(pos, offset);
  8163. }(pos0);
  8164. }
  8165. if (result0 === null) {
  8166. pos = pos0;
  8167. }
  8168. return result0;
  8169. }
  8170. function parse_authority() {
  8171. var result0;
  8172. result0 = parse_srvr();
  8173. if (result0 === null) {
  8174. result0 = parse_reg_name();
  8175. }
  8176. return result0;
  8177. }
  8178. function parse_srvr() {
  8179. var result0, result1;
  8180. var pos0, pos1;
  8181. pos0 = pos;
  8182. pos1 = pos;
  8183. result0 = parse_userinfo();
  8184. if (result0 !== null) {
  8185. if (input.charCodeAt(pos) === 64) {
  8186. result1 = "@";
  8187. pos++;
  8188. } else {
  8189. result1 = null;
  8190. if (reportFailures === 0) {
  8191. matchFailed("\"@\"");
  8192. }
  8193. }
  8194. if (result1 !== null) {
  8195. result0 = [result0, result1];
  8196. } else {
  8197. result0 = null;
  8198. pos = pos1;
  8199. }
  8200. } else {
  8201. result0 = null;
  8202. pos = pos1;
  8203. }
  8204. result0 = result0 !== null ? result0 : "";
  8205. if (result0 !== null) {
  8206. result1 = parse_hostport();
  8207. if (result1 !== null) {
  8208. result0 = [result0, result1];
  8209. } else {
  8210. result0 = null;
  8211. pos = pos0;
  8212. }
  8213. } else {
  8214. result0 = null;
  8215. pos = pos0;
  8216. }
  8217. result0 = result0 !== null ? result0 : "";
  8218. return result0;
  8219. }
  8220. function parse_reg_name() {
  8221. var result0, result1;
  8222. result1 = parse_unreserved();
  8223. if (result1 === null) {
  8224. result1 = parse_escaped();
  8225. if (result1 === null) {
  8226. if (input.charCodeAt(pos) === 36) {
  8227. result1 = "$";
  8228. pos++;
  8229. } else {
  8230. result1 = null;
  8231. if (reportFailures === 0) {
  8232. matchFailed("\"$\"");
  8233. }
  8234. }
  8235. if (result1 === null) {
  8236. if (input.charCodeAt(pos) === 44) {
  8237. result1 = ",";
  8238. pos++;
  8239. } else {
  8240. result1 = null;
  8241. if (reportFailures === 0) {
  8242. matchFailed("\",\"");
  8243. }
  8244. }
  8245. if (result1 === null) {
  8246. if (input.charCodeAt(pos) === 59) {
  8247. result1 = ";";
  8248. pos++;
  8249. } else {
  8250. result1 = null;
  8251. if (reportFailures === 0) {
  8252. matchFailed("\";\"");
  8253. }
  8254. }
  8255. if (result1 === null) {
  8256. if (input.charCodeAt(pos) === 58) {
  8257. result1 = ":";
  8258. pos++;
  8259. } else {
  8260. result1 = null;
  8261. if (reportFailures === 0) {
  8262. matchFailed("\":\"");
  8263. }
  8264. }
  8265. if (result1 === null) {
  8266. if (input.charCodeAt(pos) === 64) {
  8267. result1 = "@";
  8268. pos++;
  8269. } else {
  8270. result1 = null;
  8271. if (reportFailures === 0) {
  8272. matchFailed("\"@\"");
  8273. }
  8274. }
  8275. if (result1 === null) {
  8276. if (input.charCodeAt(pos) === 38) {
  8277. result1 = "&";
  8278. pos++;
  8279. } else {
  8280. result1 = null;
  8281. if (reportFailures === 0) {
  8282. matchFailed("\"&\"");
  8283. }
  8284. }
  8285. if (result1 === null) {
  8286. if (input.charCodeAt(pos) === 61) {
  8287. result1 = "=";
  8288. pos++;
  8289. } else {
  8290. result1 = null;
  8291. if (reportFailures === 0) {
  8292. matchFailed("\"=\"");
  8293. }
  8294. }
  8295. if (result1 === null) {
  8296. if (input.charCodeAt(pos) === 43) {
  8297. result1 = "+";
  8298. pos++;
  8299. } else {
  8300. result1 = null;
  8301. if (reportFailures === 0) {
  8302. matchFailed("\"+\"");
  8303. }
  8304. }
  8305. }
  8306. }
  8307. }
  8308. }
  8309. }
  8310. }
  8311. }
  8312. }
  8313. }
  8314. if (result1 !== null) {
  8315. result0 = [];
  8316. while (result1 !== null) {
  8317. result0.push(result1);
  8318. result1 = parse_unreserved();
  8319. if (result1 === null) {
  8320. result1 = parse_escaped();
  8321. if (result1 === null) {
  8322. if (input.charCodeAt(pos) === 36) {
  8323. result1 = "$";
  8324. pos++;
  8325. } else {
  8326. result1 = null;
  8327. if (reportFailures === 0) {
  8328. matchFailed("\"$\"");
  8329. }
  8330. }
  8331. if (result1 === null) {
  8332. if (input.charCodeAt(pos) === 44) {
  8333. result1 = ",";
  8334. pos++;
  8335. } else {
  8336. result1 = null;
  8337. if (reportFailures === 0) {
  8338. matchFailed("\",\"");
  8339. }
  8340. }
  8341. if (result1 === null) {
  8342. if (input.charCodeAt(pos) === 59) {
  8343. result1 = ";";
  8344. pos++;
  8345. } else {
  8346. result1 = null;
  8347. if (reportFailures === 0) {
  8348. matchFailed("\";\"");
  8349. }
  8350. }
  8351. if (result1 === null) {
  8352. if (input.charCodeAt(pos) === 58) {
  8353. result1 = ":";
  8354. pos++;
  8355. } else {
  8356. result1 = null;
  8357. if (reportFailures === 0) {
  8358. matchFailed("\":\"");
  8359. }
  8360. }
  8361. if (result1 === null) {
  8362. if (input.charCodeAt(pos) === 64) {
  8363. result1 = "@";
  8364. pos++;
  8365. } else {
  8366. result1 = null;
  8367. if (reportFailures === 0) {
  8368. matchFailed("\"@\"");
  8369. }
  8370. }
  8371. if (result1 === null) {
  8372. if (input.charCodeAt(pos) === 38) {
  8373. result1 = "&";
  8374. pos++;
  8375. } else {
  8376. result1 = null;
  8377. if (reportFailures === 0) {
  8378. matchFailed("\"&\"");
  8379. }
  8380. }
  8381. if (result1 === null) {
  8382. if (input.charCodeAt(pos) === 61) {
  8383. result1 = "=";
  8384. pos++;
  8385. } else {
  8386. result1 = null;
  8387. if (reportFailures === 0) {
  8388. matchFailed("\"=\"");
  8389. }
  8390. }
  8391. if (result1 === null) {
  8392. if (input.charCodeAt(pos) === 43) {
  8393. result1 = "+";
  8394. pos++;
  8395. } else {
  8396. result1 = null;
  8397. if (reportFailures === 0) {
  8398. matchFailed("\"+\"");
  8399. }
  8400. }
  8401. }
  8402. }
  8403. }
  8404. }
  8405. }
  8406. }
  8407. }
  8408. }
  8409. }
  8410. }
  8411. } else {
  8412. result0 = null;
  8413. }
  8414. return result0;
  8415. }
  8416. function parse_query() {
  8417. var result0, result1;
  8418. result0 = [];
  8419. result1 = parse_uric();
  8420. while (result1 !== null) {
  8421. result0.push(result1);
  8422. result1 = parse_uric();
  8423. }
  8424. return result0;
  8425. }
  8426. function parse_SIP_Version() {
  8427. var result0, result1, result2, result3, result4, result5;
  8428. var pos0, pos1;
  8429. pos0 = pos;
  8430. pos1 = pos;
  8431. if (input.substr(pos, 3).toLowerCase() === "sip") {
  8432. result0 = input.substr(pos, 3);
  8433. pos += 3;
  8434. } else {
  8435. result0 = null;
  8436. if (reportFailures === 0) {
  8437. matchFailed("\"SIP\"");
  8438. }
  8439. }
  8440. if (result0 !== null) {
  8441. if (input.charCodeAt(pos) === 47) {
  8442. result1 = "/";
  8443. pos++;
  8444. } else {
  8445. result1 = null;
  8446. if (reportFailures === 0) {
  8447. matchFailed("\"/\"");
  8448. }
  8449. }
  8450. if (result1 !== null) {
  8451. result3 = parse_DIGIT();
  8452. if (result3 !== null) {
  8453. result2 = [];
  8454. while (result3 !== null) {
  8455. result2.push(result3);
  8456. result3 = parse_DIGIT();
  8457. }
  8458. } else {
  8459. result2 = null;
  8460. }
  8461. if (result2 !== null) {
  8462. if (input.charCodeAt(pos) === 46) {
  8463. result3 = ".";
  8464. pos++;
  8465. } else {
  8466. result3 = null;
  8467. if (reportFailures === 0) {
  8468. matchFailed("\".\"");
  8469. }
  8470. }
  8471. if (result3 !== null) {
  8472. result5 = parse_DIGIT();
  8473. if (result5 !== null) {
  8474. result4 = [];
  8475. while (result5 !== null) {
  8476. result4.push(result5);
  8477. result5 = parse_DIGIT();
  8478. }
  8479. } else {
  8480. result4 = null;
  8481. }
  8482. if (result4 !== null) {
  8483. result0 = [result0, result1, result2, result3, result4];
  8484. } else {
  8485. result0 = null;
  8486. pos = pos1;
  8487. }
  8488. } else {
  8489. result0 = null;
  8490. pos = pos1;
  8491. }
  8492. } else {
  8493. result0 = null;
  8494. pos = pos1;
  8495. }
  8496. } else {
  8497. result0 = null;
  8498. pos = pos1;
  8499. }
  8500. } else {
  8501. result0 = null;
  8502. pos = pos1;
  8503. }
  8504. if (result0 !== null) {
  8505. result0 = function (offset) {
  8506. data.sip_version = input.substring(pos, offset);
  8507. }(pos0);
  8508. }
  8509. if (result0 === null) {
  8510. pos = pos0;
  8511. }
  8512. return result0;
  8513. }
  8514. function parse_INVITEm() {
  8515. var result0;
  8516. if (input.substr(pos, 6) === "INVITE") {
  8517. result0 = "INVITE";
  8518. pos += 6;
  8519. } else {
  8520. result0 = null;
  8521. if (reportFailures === 0) {
  8522. matchFailed("\"INVITE\"");
  8523. }
  8524. }
  8525. return result0;
  8526. }
  8527. function parse_ACKm() {
  8528. var result0;
  8529. if (input.substr(pos, 3) === "ACK") {
  8530. result0 = "ACK";
  8531. pos += 3;
  8532. } else {
  8533. result0 = null;
  8534. if (reportFailures === 0) {
  8535. matchFailed("\"ACK\"");
  8536. }
  8537. }
  8538. return result0;
  8539. }
  8540. function parse_OPTIONSm() {
  8541. var result0;
  8542. if (input.substr(pos, 7) === "OPTIONS") {
  8543. result0 = "OPTIONS";
  8544. pos += 7;
  8545. } else {
  8546. result0 = null;
  8547. if (reportFailures === 0) {
  8548. matchFailed("\"OPTIONS\"");
  8549. }
  8550. }
  8551. return result0;
  8552. }
  8553. function parse_BYEm() {
  8554. var result0;
  8555. if (input.substr(pos, 3) === "BYE") {
  8556. result0 = "BYE";
  8557. pos += 3;
  8558. } else {
  8559. result0 = null;
  8560. if (reportFailures === 0) {
  8561. matchFailed("\"BYE\"");
  8562. }
  8563. }
  8564. return result0;
  8565. }
  8566. function parse_CANCELm() {
  8567. var result0;
  8568. if (input.substr(pos, 6) === "CANCEL") {
  8569. result0 = "CANCEL";
  8570. pos += 6;
  8571. } else {
  8572. result0 = null;
  8573. if (reportFailures === 0) {
  8574. matchFailed("\"CANCEL\"");
  8575. }
  8576. }
  8577. return result0;
  8578. }
  8579. function parse_REGISTERm() {
  8580. var result0;
  8581. if (input.substr(pos, 8) === "REGISTER") {
  8582. result0 = "REGISTER";
  8583. pos += 8;
  8584. } else {
  8585. result0 = null;
  8586. if (reportFailures === 0) {
  8587. matchFailed("\"REGISTER\"");
  8588. }
  8589. }
  8590. return result0;
  8591. }
  8592. function parse_SUBSCRIBEm() {
  8593. var result0;
  8594. if (input.substr(pos, 9) === "SUBSCRIBE") {
  8595. result0 = "SUBSCRIBE";
  8596. pos += 9;
  8597. } else {
  8598. result0 = null;
  8599. if (reportFailures === 0) {
  8600. matchFailed("\"SUBSCRIBE\"");
  8601. }
  8602. }
  8603. return result0;
  8604. }
  8605. function parse_NOTIFYm() {
  8606. var result0;
  8607. if (input.substr(pos, 6) === "NOTIFY") {
  8608. result0 = "NOTIFY";
  8609. pos += 6;
  8610. } else {
  8611. result0 = null;
  8612. if (reportFailures === 0) {
  8613. matchFailed("\"NOTIFY\"");
  8614. }
  8615. }
  8616. return result0;
  8617. }
  8618. function parse_REFERm() {
  8619. var result0;
  8620. if (input.substr(pos, 5) === "REFER") {
  8621. result0 = "REFER";
  8622. pos += 5;
  8623. } else {
  8624. result0 = null;
  8625. if (reportFailures === 0) {
  8626. matchFailed("\"REFER\"");
  8627. }
  8628. }
  8629. return result0;
  8630. }
  8631. function parse_Method() {
  8632. var result0;
  8633. var pos0;
  8634. pos0 = pos;
  8635. result0 = parse_INVITEm();
  8636. if (result0 === null) {
  8637. result0 = parse_ACKm();
  8638. if (result0 === null) {
  8639. result0 = parse_OPTIONSm();
  8640. if (result0 === null) {
  8641. result0 = parse_BYEm();
  8642. if (result0 === null) {
  8643. result0 = parse_CANCELm();
  8644. if (result0 === null) {
  8645. result0 = parse_REGISTERm();
  8646. if (result0 === null) {
  8647. result0 = parse_SUBSCRIBEm();
  8648. if (result0 === null) {
  8649. result0 = parse_NOTIFYm();
  8650. if (result0 === null) {
  8651. result0 = parse_REFERm();
  8652. if (result0 === null) {
  8653. result0 = parse_token();
  8654. }
  8655. }
  8656. }
  8657. }
  8658. }
  8659. }
  8660. }
  8661. }
  8662. }
  8663. if (result0 !== null) {
  8664. result0 = function (offset) {
  8665. data.method = input.substring(pos, offset);
  8666. return data.method;
  8667. }(pos0);
  8668. }
  8669. if (result0 === null) {
  8670. pos = pos0;
  8671. }
  8672. return result0;
  8673. }
  8674. function parse_Status_Line() {
  8675. var result0, result1, result2, result3, result4;
  8676. var pos0;
  8677. pos0 = pos;
  8678. result0 = parse_SIP_Version();
  8679. if (result0 !== null) {
  8680. result1 = parse_SP();
  8681. if (result1 !== null) {
  8682. result2 = parse_Status_Code();
  8683. if (result2 !== null) {
  8684. result3 = parse_SP();
  8685. if (result3 !== null) {
  8686. result4 = parse_Reason_Phrase();
  8687. if (result4 !== null) {
  8688. result0 = [result0, result1, result2, result3, result4];
  8689. } else {
  8690. result0 = null;
  8691. pos = pos0;
  8692. }
  8693. } else {
  8694. result0 = null;
  8695. pos = pos0;
  8696. }
  8697. } else {
  8698. result0 = null;
  8699. pos = pos0;
  8700. }
  8701. } else {
  8702. result0 = null;
  8703. pos = pos0;
  8704. }
  8705. } else {
  8706. result0 = null;
  8707. pos = pos0;
  8708. }
  8709. return result0;
  8710. }
  8711. function parse_Status_Code() {
  8712. var result0;
  8713. var pos0;
  8714. pos0 = pos;
  8715. result0 = parse_extension_code();
  8716. if (result0 !== null) {
  8717. result0 = function (offset, status_code) {
  8718. data.status_code = parseInt(status_code.join(''));
  8719. }(pos0, result0);
  8720. }
  8721. if (result0 === null) {
  8722. pos = pos0;
  8723. }
  8724. return result0;
  8725. }
  8726. function parse_extension_code() {
  8727. var result0, result1, result2;
  8728. var pos0;
  8729. pos0 = pos;
  8730. result0 = parse_DIGIT();
  8731. if (result0 !== null) {
  8732. result1 = parse_DIGIT();
  8733. if (result1 !== null) {
  8734. result2 = parse_DIGIT();
  8735. if (result2 !== null) {
  8736. result0 = [result0, result1, result2];
  8737. } else {
  8738. result0 = null;
  8739. pos = pos0;
  8740. }
  8741. } else {
  8742. result0 = null;
  8743. pos = pos0;
  8744. }
  8745. } else {
  8746. result0 = null;
  8747. pos = pos0;
  8748. }
  8749. return result0;
  8750. }
  8751. function parse_Reason_Phrase() {
  8752. var result0, result1;
  8753. var pos0;
  8754. pos0 = pos;
  8755. result0 = [];
  8756. result1 = parse_reserved();
  8757. if (result1 === null) {
  8758. result1 = parse_unreserved();
  8759. if (result1 === null) {
  8760. result1 = parse_escaped();
  8761. if (result1 === null) {
  8762. result1 = parse_UTF8_NONASCII();
  8763. if (result1 === null) {
  8764. result1 = parse_UTF8_CONT();
  8765. if (result1 === null) {
  8766. result1 = parse_SP();
  8767. if (result1 === null) {
  8768. result1 = parse_HTAB();
  8769. }
  8770. }
  8771. }
  8772. }
  8773. }
  8774. }
  8775. while (result1 !== null) {
  8776. result0.push(result1);
  8777. result1 = parse_reserved();
  8778. if (result1 === null) {
  8779. result1 = parse_unreserved();
  8780. if (result1 === null) {
  8781. result1 = parse_escaped();
  8782. if (result1 === null) {
  8783. result1 = parse_UTF8_NONASCII();
  8784. if (result1 === null) {
  8785. result1 = parse_UTF8_CONT();
  8786. if (result1 === null) {
  8787. result1 = parse_SP();
  8788. if (result1 === null) {
  8789. result1 = parse_HTAB();
  8790. }
  8791. }
  8792. }
  8793. }
  8794. }
  8795. }
  8796. }
  8797. if (result0 !== null) {
  8798. result0 = function (offset) {
  8799. data.reason_phrase = input.substring(pos, offset);
  8800. }(pos0);
  8801. }
  8802. if (result0 === null) {
  8803. pos = pos0;
  8804. }
  8805. return result0;
  8806. }
  8807. function parse_Allow_Events() {
  8808. var result0, result1, result2, result3;
  8809. var pos0, pos1;
  8810. pos0 = pos;
  8811. result0 = parse_event_type();
  8812. if (result0 !== null) {
  8813. result1 = [];
  8814. pos1 = pos;
  8815. result2 = parse_COMMA();
  8816. if (result2 !== null) {
  8817. result3 = parse_event_type();
  8818. if (result3 !== null) {
  8819. result2 = [result2, result3];
  8820. } else {
  8821. result2 = null;
  8822. pos = pos1;
  8823. }
  8824. } else {
  8825. result2 = null;
  8826. pos = pos1;
  8827. }
  8828. while (result2 !== null) {
  8829. result1.push(result2);
  8830. pos1 = pos;
  8831. result2 = parse_COMMA();
  8832. if (result2 !== null) {
  8833. result3 = parse_event_type();
  8834. if (result3 !== null) {
  8835. result2 = [result2, result3];
  8836. } else {
  8837. result2 = null;
  8838. pos = pos1;
  8839. }
  8840. } else {
  8841. result2 = null;
  8842. pos = pos1;
  8843. }
  8844. }
  8845. if (result1 !== null) {
  8846. result0 = [result0, result1];
  8847. } else {
  8848. result0 = null;
  8849. pos = pos0;
  8850. }
  8851. } else {
  8852. result0 = null;
  8853. pos = pos0;
  8854. }
  8855. return result0;
  8856. }
  8857. function parse_Call_ID() {
  8858. var result0, result1, result2;
  8859. var pos0, pos1, pos2;
  8860. pos0 = pos;
  8861. pos1 = pos;
  8862. result0 = parse_word();
  8863. if (result0 !== null) {
  8864. pos2 = pos;
  8865. if (input.charCodeAt(pos) === 64) {
  8866. result1 = "@";
  8867. pos++;
  8868. } else {
  8869. result1 = null;
  8870. if (reportFailures === 0) {
  8871. matchFailed("\"@\"");
  8872. }
  8873. }
  8874. if (result1 !== null) {
  8875. result2 = parse_word();
  8876. if (result2 !== null) {
  8877. result1 = [result1, result2];
  8878. } else {
  8879. result1 = null;
  8880. pos = pos2;
  8881. }
  8882. } else {
  8883. result1 = null;
  8884. pos = pos2;
  8885. }
  8886. result1 = result1 !== null ? result1 : "";
  8887. if (result1 !== null) {
  8888. result0 = [result0, result1];
  8889. } else {
  8890. result0 = null;
  8891. pos = pos1;
  8892. }
  8893. } else {
  8894. result0 = null;
  8895. pos = pos1;
  8896. }
  8897. if (result0 !== null) {
  8898. result0 = function (offset) {
  8899. data = input.substring(pos, offset);
  8900. }(pos0);
  8901. }
  8902. if (result0 === null) {
  8903. pos = pos0;
  8904. }
  8905. return result0;
  8906. }
  8907. function parse_Contact() {
  8908. var result0, result1, result2, result3;
  8909. var pos0, pos1, pos2;
  8910. pos0 = pos;
  8911. result0 = parse_STAR();
  8912. if (result0 === null) {
  8913. pos1 = pos;
  8914. result0 = parse_contact_param();
  8915. if (result0 !== null) {
  8916. result1 = [];
  8917. pos2 = pos;
  8918. result2 = parse_COMMA();
  8919. if (result2 !== null) {
  8920. result3 = parse_contact_param();
  8921. if (result3 !== null) {
  8922. result2 = [result2, result3];
  8923. } else {
  8924. result2 = null;
  8925. pos = pos2;
  8926. }
  8927. } else {
  8928. result2 = null;
  8929. pos = pos2;
  8930. }
  8931. while (result2 !== null) {
  8932. result1.push(result2);
  8933. pos2 = pos;
  8934. result2 = parse_COMMA();
  8935. if (result2 !== null) {
  8936. result3 = parse_contact_param();
  8937. if (result3 !== null) {
  8938. result2 = [result2, result3];
  8939. } else {
  8940. result2 = null;
  8941. pos = pos2;
  8942. }
  8943. } else {
  8944. result2 = null;
  8945. pos = pos2;
  8946. }
  8947. }
  8948. if (result1 !== null) {
  8949. result0 = [result0, result1];
  8950. } else {
  8951. result0 = null;
  8952. pos = pos1;
  8953. }
  8954. } else {
  8955. result0 = null;
  8956. pos = pos1;
  8957. }
  8958. }
  8959. if (result0 !== null) {
  8960. result0 = function (offset) {
  8961. var idx, length;
  8962. length = data.multi_header.length;
  8963. for (idx = 0; idx < length; idx++) {
  8964. if (data.multi_header[idx].parsed === null) {
  8965. data = null;
  8966. break;
  8967. }
  8968. }
  8969. if (data !== null) {
  8970. data = data.multi_header;
  8971. } else {
  8972. data = -1;
  8973. }
  8974. }(pos0);
  8975. }
  8976. if (result0 === null) {
  8977. pos = pos0;
  8978. }
  8979. return result0;
  8980. }
  8981. function parse_contact_param() {
  8982. var result0, result1, result2, result3;
  8983. var pos0, pos1, pos2;
  8984. pos0 = pos;
  8985. pos1 = pos;
  8986. result0 = parse_SIP_URI_noparams();
  8987. if (result0 === null) {
  8988. result0 = parse_name_addr();
  8989. }
  8990. if (result0 !== null) {
  8991. result1 = [];
  8992. pos2 = pos;
  8993. result2 = parse_SEMI();
  8994. if (result2 !== null) {
  8995. result3 = parse_contact_params();
  8996. if (result3 !== null) {
  8997. result2 = [result2, result3];
  8998. } else {
  8999. result2 = null;
  9000. pos = pos2;
  9001. }
  9002. } else {
  9003. result2 = null;
  9004. pos = pos2;
  9005. }
  9006. while (result2 !== null) {
  9007. result1.push(result2);
  9008. pos2 = pos;
  9009. result2 = parse_SEMI();
  9010. if (result2 !== null) {
  9011. result3 = parse_contact_params();
  9012. if (result3 !== null) {
  9013. result2 = [result2, result3];
  9014. } else {
  9015. result2 = null;
  9016. pos = pos2;
  9017. }
  9018. } else {
  9019. result2 = null;
  9020. pos = pos2;
  9021. }
  9022. }
  9023. if (result1 !== null) {
  9024. result0 = [result0, result1];
  9025. } else {
  9026. result0 = null;
  9027. pos = pos1;
  9028. }
  9029. } else {
  9030. result0 = null;
  9031. pos = pos1;
  9032. }
  9033. if (result0 !== null) {
  9034. result0 = function (offset) {
  9035. var header;
  9036. if (!data.multi_header) data.multi_header = [];
  9037. try {
  9038. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  9039. delete data.uri;
  9040. delete data.display_name;
  9041. delete data.params;
  9042. } catch (e) {
  9043. header = null;
  9044. }
  9045. data.multi_header.push({
  9046. 'possition': pos,
  9047. 'offset': offset,
  9048. 'parsed': header
  9049. });
  9050. }(pos0);
  9051. }
  9052. if (result0 === null) {
  9053. pos = pos0;
  9054. }
  9055. return result0;
  9056. }
  9057. function parse_name_addr() {
  9058. var result0, result1, result2, result3;
  9059. var pos0;
  9060. pos0 = pos;
  9061. result0 = parse_display_name();
  9062. result0 = result0 !== null ? result0 : "";
  9063. if (result0 !== null) {
  9064. result1 = parse_LAQUOT();
  9065. if (result1 !== null) {
  9066. result2 = parse_SIP_URI();
  9067. if (result2 !== null) {
  9068. result3 = parse_RAQUOT();
  9069. if (result3 !== null) {
  9070. result0 = [result0, result1, result2, result3];
  9071. } else {
  9072. result0 = null;
  9073. pos = pos0;
  9074. }
  9075. } else {
  9076. result0 = null;
  9077. pos = pos0;
  9078. }
  9079. } else {
  9080. result0 = null;
  9081. pos = pos0;
  9082. }
  9083. } else {
  9084. result0 = null;
  9085. pos = pos0;
  9086. }
  9087. return result0;
  9088. }
  9089. function parse_display_name() {
  9090. var result0, result1, result2, result3;
  9091. var pos0, pos1, pos2;
  9092. pos0 = pos;
  9093. pos1 = pos;
  9094. result0 = parse_token();
  9095. if (result0 !== null) {
  9096. result1 = [];
  9097. pos2 = pos;
  9098. result2 = parse_LWS();
  9099. if (result2 !== null) {
  9100. result3 = parse_token();
  9101. if (result3 !== null) {
  9102. result2 = [result2, result3];
  9103. } else {
  9104. result2 = null;
  9105. pos = pos2;
  9106. }
  9107. } else {
  9108. result2 = null;
  9109. pos = pos2;
  9110. }
  9111. while (result2 !== null) {
  9112. result1.push(result2);
  9113. pos2 = pos;
  9114. result2 = parse_LWS();
  9115. if (result2 !== null) {
  9116. result3 = parse_token();
  9117. if (result3 !== null) {
  9118. result2 = [result2, result3];
  9119. } else {
  9120. result2 = null;
  9121. pos = pos2;
  9122. }
  9123. } else {
  9124. result2 = null;
  9125. pos = pos2;
  9126. }
  9127. }
  9128. if (result1 !== null) {
  9129. result0 = [result0, result1];
  9130. } else {
  9131. result0 = null;
  9132. pos = pos1;
  9133. }
  9134. } else {
  9135. result0 = null;
  9136. pos = pos1;
  9137. }
  9138. if (result0 === null) {
  9139. result0 = parse_quoted_string_clean();
  9140. }
  9141. if (result0 !== null) {
  9142. result0 = function (offset, display_name) {
  9143. if (typeof display_name === 'string') {
  9144. // quoted_string_clean
  9145. data.display_name = display_name;
  9146. } else {
  9147. // token ( LWS token )*
  9148. data.display_name = display_name[1].reduce(function (acc, cur) {
  9149. return acc + cur[0] + cur[1];
  9150. }, display_name[0]);
  9151. }
  9152. }(pos0, result0);
  9153. }
  9154. if (result0 === null) {
  9155. pos = pos0;
  9156. }
  9157. return result0;
  9158. }
  9159. function parse_contact_params() {
  9160. var result0;
  9161. result0 = parse_c_p_q();
  9162. if (result0 === null) {
  9163. result0 = parse_c_p_expires();
  9164. if (result0 === null) {
  9165. result0 = parse_generic_param();
  9166. }
  9167. }
  9168. return result0;
  9169. }
  9170. function parse_c_p_q() {
  9171. var result0, result1, result2;
  9172. var pos0, pos1;
  9173. pos0 = pos;
  9174. pos1 = pos;
  9175. if (input.substr(pos, 1).toLowerCase() === "q") {
  9176. result0 = input.substr(pos, 1);
  9177. pos++;
  9178. } else {
  9179. result0 = null;
  9180. if (reportFailures === 0) {
  9181. matchFailed("\"q\"");
  9182. }
  9183. }
  9184. if (result0 !== null) {
  9185. result1 = parse_EQUAL();
  9186. if (result1 !== null) {
  9187. result2 = parse_qvalue();
  9188. if (result2 !== null) {
  9189. result0 = [result0, result1, result2];
  9190. } else {
  9191. result0 = null;
  9192. pos = pos1;
  9193. }
  9194. } else {
  9195. result0 = null;
  9196. pos = pos1;
  9197. }
  9198. } else {
  9199. result0 = null;
  9200. pos = pos1;
  9201. }
  9202. if (result0 !== null) {
  9203. result0 = function (offset, q) {
  9204. if (!data.params) data.params = {};
  9205. data.params['q'] = q;
  9206. }(pos0, result0[2]);
  9207. }
  9208. if (result0 === null) {
  9209. pos = pos0;
  9210. }
  9211. return result0;
  9212. }
  9213. function parse_c_p_expires() {
  9214. var result0, result1, result2;
  9215. var pos0, pos1;
  9216. pos0 = pos;
  9217. pos1 = pos;
  9218. if (input.substr(pos, 7).toLowerCase() === "expires") {
  9219. result0 = input.substr(pos, 7);
  9220. pos += 7;
  9221. } else {
  9222. result0 = null;
  9223. if (reportFailures === 0) {
  9224. matchFailed("\"expires\"");
  9225. }
  9226. }
  9227. if (result0 !== null) {
  9228. result1 = parse_EQUAL();
  9229. if (result1 !== null) {
  9230. result2 = parse_delta_seconds();
  9231. if (result2 !== null) {
  9232. result0 = [result0, result1, result2];
  9233. } else {
  9234. result0 = null;
  9235. pos = pos1;
  9236. }
  9237. } else {
  9238. result0 = null;
  9239. pos = pos1;
  9240. }
  9241. } else {
  9242. result0 = null;
  9243. pos = pos1;
  9244. }
  9245. if (result0 !== null) {
  9246. result0 = function (offset, expires) {
  9247. if (!data.params) data.params = {};
  9248. data.params['expires'] = expires;
  9249. }(pos0, result0[2]);
  9250. }
  9251. if (result0 === null) {
  9252. pos = pos0;
  9253. }
  9254. return result0;
  9255. }
  9256. function parse_delta_seconds() {
  9257. var result0, result1;
  9258. var pos0;
  9259. pos0 = pos;
  9260. result1 = parse_DIGIT();
  9261. if (result1 !== null) {
  9262. result0 = [];
  9263. while (result1 !== null) {
  9264. result0.push(result1);
  9265. result1 = parse_DIGIT();
  9266. }
  9267. } else {
  9268. result0 = null;
  9269. }
  9270. if (result0 !== null) {
  9271. result0 = function (offset, delta_seconds) {
  9272. return parseInt(delta_seconds.join(''));
  9273. }(pos0, result0);
  9274. }
  9275. if (result0 === null) {
  9276. pos = pos0;
  9277. }
  9278. return result0;
  9279. }
  9280. function parse_qvalue() {
  9281. var result0, result1, result2, result3, result4;
  9282. var pos0, pos1, pos2;
  9283. pos0 = pos;
  9284. pos1 = pos;
  9285. if (input.charCodeAt(pos) === 48) {
  9286. result0 = "0";
  9287. pos++;
  9288. } else {
  9289. result0 = null;
  9290. if (reportFailures === 0) {
  9291. matchFailed("\"0\"");
  9292. }
  9293. }
  9294. if (result0 !== null) {
  9295. pos2 = pos;
  9296. if (input.charCodeAt(pos) === 46) {
  9297. result1 = ".";
  9298. pos++;
  9299. } else {
  9300. result1 = null;
  9301. if (reportFailures === 0) {
  9302. matchFailed("\".\"");
  9303. }
  9304. }
  9305. if (result1 !== null) {
  9306. result2 = parse_DIGIT();
  9307. result2 = result2 !== null ? result2 : "";
  9308. if (result2 !== null) {
  9309. result3 = parse_DIGIT();
  9310. result3 = result3 !== null ? result3 : "";
  9311. if (result3 !== null) {
  9312. result4 = parse_DIGIT();
  9313. result4 = result4 !== null ? result4 : "";
  9314. if (result4 !== null) {
  9315. result1 = [result1, result2, result3, result4];
  9316. } else {
  9317. result1 = null;
  9318. pos = pos2;
  9319. }
  9320. } else {
  9321. result1 = null;
  9322. pos = pos2;
  9323. }
  9324. } else {
  9325. result1 = null;
  9326. pos = pos2;
  9327. }
  9328. } else {
  9329. result1 = null;
  9330. pos = pos2;
  9331. }
  9332. result1 = result1 !== null ? result1 : "";
  9333. if (result1 !== null) {
  9334. result0 = [result0, result1];
  9335. } else {
  9336. result0 = null;
  9337. pos = pos1;
  9338. }
  9339. } else {
  9340. result0 = null;
  9341. pos = pos1;
  9342. }
  9343. if (result0 !== null) {
  9344. result0 = function (offset) {
  9345. return parseFloat(input.substring(pos, offset));
  9346. }(pos0);
  9347. }
  9348. if (result0 === null) {
  9349. pos = pos0;
  9350. }
  9351. return result0;
  9352. }
  9353. function parse_generic_param() {
  9354. var result0, result1, result2;
  9355. var pos0, pos1, pos2;
  9356. pos0 = pos;
  9357. pos1 = pos;
  9358. result0 = parse_token();
  9359. if (result0 !== null) {
  9360. pos2 = pos;
  9361. result1 = parse_EQUAL();
  9362. if (result1 !== null) {
  9363. result2 = parse_gen_value();
  9364. if (result2 !== null) {
  9365. result1 = [result1, result2];
  9366. } else {
  9367. result1 = null;
  9368. pos = pos2;
  9369. }
  9370. } else {
  9371. result1 = null;
  9372. pos = pos2;
  9373. }
  9374. result1 = result1 !== null ? result1 : "";
  9375. if (result1 !== null) {
  9376. result0 = [result0, result1];
  9377. } else {
  9378. result0 = null;
  9379. pos = pos1;
  9380. }
  9381. } else {
  9382. result0 = null;
  9383. pos = pos1;
  9384. }
  9385. if (result0 !== null) {
  9386. result0 = function (offset, param, value) {
  9387. if (!data.params) data.params = {};
  9388. if (typeof value === 'undefined') {
  9389. value = undefined;
  9390. } else {
  9391. value = value[1];
  9392. }
  9393. data.params[param.toLowerCase()] = value;
  9394. }(pos0, result0[0], result0[1]);
  9395. }
  9396. if (result0 === null) {
  9397. pos = pos0;
  9398. }
  9399. return result0;
  9400. }
  9401. function parse_gen_value() {
  9402. var result0;
  9403. result0 = parse_token();
  9404. if (result0 === null) {
  9405. result0 = parse_host();
  9406. if (result0 === null) {
  9407. result0 = parse_quoted_string();
  9408. }
  9409. }
  9410. return result0;
  9411. }
  9412. function parse_Content_Disposition() {
  9413. var result0, result1, result2, result3;
  9414. var pos0, pos1;
  9415. pos0 = pos;
  9416. result0 = parse_disp_type();
  9417. if (result0 !== null) {
  9418. result1 = [];
  9419. pos1 = pos;
  9420. result2 = parse_SEMI();
  9421. if (result2 !== null) {
  9422. result3 = parse_disp_param();
  9423. if (result3 !== null) {
  9424. result2 = [result2, result3];
  9425. } else {
  9426. result2 = null;
  9427. pos = pos1;
  9428. }
  9429. } else {
  9430. result2 = null;
  9431. pos = pos1;
  9432. }
  9433. while (result2 !== null) {
  9434. result1.push(result2);
  9435. pos1 = pos;
  9436. result2 = parse_SEMI();
  9437. if (result2 !== null) {
  9438. result3 = parse_disp_param();
  9439. if (result3 !== null) {
  9440. result2 = [result2, result3];
  9441. } else {
  9442. result2 = null;
  9443. pos = pos1;
  9444. }
  9445. } else {
  9446. result2 = null;
  9447. pos = pos1;
  9448. }
  9449. }
  9450. if (result1 !== null) {
  9451. result0 = [result0, result1];
  9452. } else {
  9453. result0 = null;
  9454. pos = pos0;
  9455. }
  9456. } else {
  9457. result0 = null;
  9458. pos = pos0;
  9459. }
  9460. return result0;
  9461. }
  9462. function parse_disp_type() {
  9463. var result0;
  9464. if (input.substr(pos, 6).toLowerCase() === "render") {
  9465. result0 = input.substr(pos, 6);
  9466. pos += 6;
  9467. } else {
  9468. result0 = null;
  9469. if (reportFailures === 0) {
  9470. matchFailed("\"render\"");
  9471. }
  9472. }
  9473. if (result0 === null) {
  9474. if (input.substr(pos, 7).toLowerCase() === "session") {
  9475. result0 = input.substr(pos, 7);
  9476. pos += 7;
  9477. } else {
  9478. result0 = null;
  9479. if (reportFailures === 0) {
  9480. matchFailed("\"session\"");
  9481. }
  9482. }
  9483. if (result0 === null) {
  9484. if (input.substr(pos, 4).toLowerCase() === "icon") {
  9485. result0 = input.substr(pos, 4);
  9486. pos += 4;
  9487. } else {
  9488. result0 = null;
  9489. if (reportFailures === 0) {
  9490. matchFailed("\"icon\"");
  9491. }
  9492. }
  9493. if (result0 === null) {
  9494. if (input.substr(pos, 5).toLowerCase() === "alert") {
  9495. result0 = input.substr(pos, 5);
  9496. pos += 5;
  9497. } else {
  9498. result0 = null;
  9499. if (reportFailures === 0) {
  9500. matchFailed("\"alert\"");
  9501. }
  9502. }
  9503. if (result0 === null) {
  9504. result0 = parse_token();
  9505. }
  9506. }
  9507. }
  9508. }
  9509. return result0;
  9510. }
  9511. function parse_disp_param() {
  9512. var result0;
  9513. result0 = parse_handling_param();
  9514. if (result0 === null) {
  9515. result0 = parse_generic_param();
  9516. }
  9517. return result0;
  9518. }
  9519. function parse_handling_param() {
  9520. var result0, result1, result2;
  9521. var pos0;
  9522. pos0 = pos;
  9523. if (input.substr(pos, 8).toLowerCase() === "handling") {
  9524. result0 = input.substr(pos, 8);
  9525. pos += 8;
  9526. } else {
  9527. result0 = null;
  9528. if (reportFailures === 0) {
  9529. matchFailed("\"handling\"");
  9530. }
  9531. }
  9532. if (result0 !== null) {
  9533. result1 = parse_EQUAL();
  9534. if (result1 !== null) {
  9535. if (input.substr(pos, 8).toLowerCase() === "optional") {
  9536. result2 = input.substr(pos, 8);
  9537. pos += 8;
  9538. } else {
  9539. result2 = null;
  9540. if (reportFailures === 0) {
  9541. matchFailed("\"optional\"");
  9542. }
  9543. }
  9544. if (result2 === null) {
  9545. if (input.substr(pos, 8).toLowerCase() === "required") {
  9546. result2 = input.substr(pos, 8);
  9547. pos += 8;
  9548. } else {
  9549. result2 = null;
  9550. if (reportFailures === 0) {
  9551. matchFailed("\"required\"");
  9552. }
  9553. }
  9554. if (result2 === null) {
  9555. result2 = parse_token();
  9556. }
  9557. }
  9558. if (result2 !== null) {
  9559. result0 = [result0, result1, result2];
  9560. } else {
  9561. result0 = null;
  9562. pos = pos0;
  9563. }
  9564. } else {
  9565. result0 = null;
  9566. pos = pos0;
  9567. }
  9568. } else {
  9569. result0 = null;
  9570. pos = pos0;
  9571. }
  9572. return result0;
  9573. }
  9574. function parse_Content_Encoding() {
  9575. var result0, result1, result2, result3;
  9576. var pos0, pos1;
  9577. pos0 = pos;
  9578. result0 = parse_token();
  9579. if (result0 !== null) {
  9580. result1 = [];
  9581. pos1 = pos;
  9582. result2 = parse_COMMA();
  9583. if (result2 !== null) {
  9584. result3 = parse_token();
  9585. if (result3 !== null) {
  9586. result2 = [result2, result3];
  9587. } else {
  9588. result2 = null;
  9589. pos = pos1;
  9590. }
  9591. } else {
  9592. result2 = null;
  9593. pos = pos1;
  9594. }
  9595. while (result2 !== null) {
  9596. result1.push(result2);
  9597. pos1 = pos;
  9598. result2 = parse_COMMA();
  9599. if (result2 !== null) {
  9600. result3 = parse_token();
  9601. if (result3 !== null) {
  9602. result2 = [result2, result3];
  9603. } else {
  9604. result2 = null;
  9605. pos = pos1;
  9606. }
  9607. } else {
  9608. result2 = null;
  9609. pos = pos1;
  9610. }
  9611. }
  9612. if (result1 !== null) {
  9613. result0 = [result0, result1];
  9614. } else {
  9615. result0 = null;
  9616. pos = pos0;
  9617. }
  9618. } else {
  9619. result0 = null;
  9620. pos = pos0;
  9621. }
  9622. return result0;
  9623. }
  9624. function parse_Content_Length() {
  9625. var result0, result1;
  9626. var pos0;
  9627. pos0 = pos;
  9628. result1 = parse_DIGIT();
  9629. if (result1 !== null) {
  9630. result0 = [];
  9631. while (result1 !== null) {
  9632. result0.push(result1);
  9633. result1 = parse_DIGIT();
  9634. }
  9635. } else {
  9636. result0 = null;
  9637. }
  9638. if (result0 !== null) {
  9639. result0 = function (offset, length) {
  9640. data = parseInt(length.join(''));
  9641. }(pos0, result0);
  9642. }
  9643. if (result0 === null) {
  9644. pos = pos0;
  9645. }
  9646. return result0;
  9647. }
  9648. function parse_Content_Type() {
  9649. var result0;
  9650. var pos0;
  9651. pos0 = pos;
  9652. result0 = parse_media_type();
  9653. if (result0 !== null) {
  9654. result0 = function (offset) {
  9655. data = input.substring(pos, offset);
  9656. }(pos0);
  9657. }
  9658. if (result0 === null) {
  9659. pos = pos0;
  9660. }
  9661. return result0;
  9662. }
  9663. function parse_media_type() {
  9664. var result0, result1, result2, result3, result4, result5;
  9665. var pos0, pos1;
  9666. pos0 = pos;
  9667. result0 = parse_m_type();
  9668. if (result0 !== null) {
  9669. result1 = parse_SLASH();
  9670. if (result1 !== null) {
  9671. result2 = parse_m_subtype();
  9672. if (result2 !== null) {
  9673. result3 = [];
  9674. pos1 = pos;
  9675. result4 = parse_SEMI();
  9676. if (result4 !== null) {
  9677. result5 = parse_m_parameter();
  9678. if (result5 !== null) {
  9679. result4 = [result4, result5];
  9680. } else {
  9681. result4 = null;
  9682. pos = pos1;
  9683. }
  9684. } else {
  9685. result4 = null;
  9686. pos = pos1;
  9687. }
  9688. while (result4 !== null) {
  9689. result3.push(result4);
  9690. pos1 = pos;
  9691. result4 = parse_SEMI();
  9692. if (result4 !== null) {
  9693. result5 = parse_m_parameter();
  9694. if (result5 !== null) {
  9695. result4 = [result4, result5];
  9696. } else {
  9697. result4 = null;
  9698. pos = pos1;
  9699. }
  9700. } else {
  9701. result4 = null;
  9702. pos = pos1;
  9703. }
  9704. }
  9705. if (result3 !== null) {
  9706. result0 = [result0, result1, result2, result3];
  9707. } else {
  9708. result0 = null;
  9709. pos = pos0;
  9710. }
  9711. } else {
  9712. result0 = null;
  9713. pos = pos0;
  9714. }
  9715. } else {
  9716. result0 = null;
  9717. pos = pos0;
  9718. }
  9719. } else {
  9720. result0 = null;
  9721. pos = pos0;
  9722. }
  9723. return result0;
  9724. }
  9725. function parse_m_type() {
  9726. var result0;
  9727. result0 = parse_discrete_type();
  9728. if (result0 === null) {
  9729. result0 = parse_composite_type();
  9730. }
  9731. return result0;
  9732. }
  9733. function parse_discrete_type() {
  9734. var result0;
  9735. if (input.substr(pos, 4).toLowerCase() === "text") {
  9736. result0 = input.substr(pos, 4);
  9737. pos += 4;
  9738. } else {
  9739. result0 = null;
  9740. if (reportFailures === 0) {
  9741. matchFailed("\"text\"");
  9742. }
  9743. }
  9744. if (result0 === null) {
  9745. if (input.substr(pos, 5).toLowerCase() === "image") {
  9746. result0 = input.substr(pos, 5);
  9747. pos += 5;
  9748. } else {
  9749. result0 = null;
  9750. if (reportFailures === 0) {
  9751. matchFailed("\"image\"");
  9752. }
  9753. }
  9754. if (result0 === null) {
  9755. if (input.substr(pos, 5).toLowerCase() === "audio") {
  9756. result0 = input.substr(pos, 5);
  9757. pos += 5;
  9758. } else {
  9759. result0 = null;
  9760. if (reportFailures === 0) {
  9761. matchFailed("\"audio\"");
  9762. }
  9763. }
  9764. if (result0 === null) {
  9765. if (input.substr(pos, 5).toLowerCase() === "video") {
  9766. result0 = input.substr(pos, 5);
  9767. pos += 5;
  9768. } else {
  9769. result0 = null;
  9770. if (reportFailures === 0) {
  9771. matchFailed("\"video\"");
  9772. }
  9773. }
  9774. if (result0 === null) {
  9775. if (input.substr(pos, 11).toLowerCase() === "application") {
  9776. result0 = input.substr(pos, 11);
  9777. pos += 11;
  9778. } else {
  9779. result0 = null;
  9780. if (reportFailures === 0) {
  9781. matchFailed("\"application\"");
  9782. }
  9783. }
  9784. if (result0 === null) {
  9785. result0 = parse_extension_token();
  9786. }
  9787. }
  9788. }
  9789. }
  9790. }
  9791. return result0;
  9792. }
  9793. function parse_composite_type() {
  9794. var result0;
  9795. if (input.substr(pos, 7).toLowerCase() === "message") {
  9796. result0 = input.substr(pos, 7);
  9797. pos += 7;
  9798. } else {
  9799. result0 = null;
  9800. if (reportFailures === 0) {
  9801. matchFailed("\"message\"");
  9802. }
  9803. }
  9804. if (result0 === null) {
  9805. if (input.substr(pos, 9).toLowerCase() === "multipart") {
  9806. result0 = input.substr(pos, 9);
  9807. pos += 9;
  9808. } else {
  9809. result0 = null;
  9810. if (reportFailures === 0) {
  9811. matchFailed("\"multipart\"");
  9812. }
  9813. }
  9814. if (result0 === null) {
  9815. result0 = parse_extension_token();
  9816. }
  9817. }
  9818. return result0;
  9819. }
  9820. function parse_extension_token() {
  9821. var result0;
  9822. result0 = parse_token();
  9823. if (result0 === null) {
  9824. result0 = parse_x_token();
  9825. }
  9826. return result0;
  9827. }
  9828. function parse_x_token() {
  9829. var result0, result1;
  9830. var pos0;
  9831. pos0 = pos;
  9832. if (input.substr(pos, 2).toLowerCase() === "x-") {
  9833. result0 = input.substr(pos, 2);
  9834. pos += 2;
  9835. } else {
  9836. result0 = null;
  9837. if (reportFailures === 0) {
  9838. matchFailed("\"x-\"");
  9839. }
  9840. }
  9841. if (result0 !== null) {
  9842. result1 = parse_token();
  9843. if (result1 !== null) {
  9844. result0 = [result0, result1];
  9845. } else {
  9846. result0 = null;
  9847. pos = pos0;
  9848. }
  9849. } else {
  9850. result0 = null;
  9851. pos = pos0;
  9852. }
  9853. return result0;
  9854. }
  9855. function parse_m_subtype() {
  9856. var result0;
  9857. result0 = parse_extension_token();
  9858. if (result0 === null) {
  9859. result0 = parse_token();
  9860. }
  9861. return result0;
  9862. }
  9863. function parse_m_parameter() {
  9864. var result0, result1, result2;
  9865. var pos0;
  9866. pos0 = pos;
  9867. result0 = parse_token();
  9868. if (result0 !== null) {
  9869. result1 = parse_EQUAL();
  9870. if (result1 !== null) {
  9871. result2 = parse_m_value();
  9872. if (result2 !== null) {
  9873. result0 = [result0, result1, result2];
  9874. } else {
  9875. result0 = null;
  9876. pos = pos0;
  9877. }
  9878. } else {
  9879. result0 = null;
  9880. pos = pos0;
  9881. }
  9882. } else {
  9883. result0 = null;
  9884. pos = pos0;
  9885. }
  9886. return result0;
  9887. }
  9888. function parse_m_value() {
  9889. var result0;
  9890. result0 = parse_token();
  9891. if (result0 === null) {
  9892. result0 = parse_quoted_string();
  9893. }
  9894. return result0;
  9895. }
  9896. function parse_CSeq() {
  9897. var result0, result1, result2;
  9898. var pos0;
  9899. pos0 = pos;
  9900. result0 = parse_CSeq_value();
  9901. if (result0 !== null) {
  9902. result1 = parse_LWS();
  9903. if (result1 !== null) {
  9904. result2 = parse_Method();
  9905. if (result2 !== null) {
  9906. result0 = [result0, result1, result2];
  9907. } else {
  9908. result0 = null;
  9909. pos = pos0;
  9910. }
  9911. } else {
  9912. result0 = null;
  9913. pos = pos0;
  9914. }
  9915. } else {
  9916. result0 = null;
  9917. pos = pos0;
  9918. }
  9919. return result0;
  9920. }
  9921. function parse_CSeq_value() {
  9922. var result0, result1;
  9923. var pos0;
  9924. pos0 = pos;
  9925. result1 = parse_DIGIT();
  9926. if (result1 !== null) {
  9927. result0 = [];
  9928. while (result1 !== null) {
  9929. result0.push(result1);
  9930. result1 = parse_DIGIT();
  9931. }
  9932. } else {
  9933. result0 = null;
  9934. }
  9935. if (result0 !== null) {
  9936. result0 = function (offset, cseq_value) {
  9937. data.value = parseInt(cseq_value.join(''));
  9938. }(pos0, result0);
  9939. }
  9940. if (result0 === null) {
  9941. pos = pos0;
  9942. }
  9943. return result0;
  9944. }
  9945. function parse_Expires() {
  9946. var result0;
  9947. var pos0;
  9948. pos0 = pos;
  9949. result0 = parse_delta_seconds();
  9950. if (result0 !== null) {
  9951. result0 = function (offset, expires) {
  9952. data = expires;
  9953. }(pos0, result0);
  9954. }
  9955. if (result0 === null) {
  9956. pos = pos0;
  9957. }
  9958. return result0;
  9959. }
  9960. function parse_Event() {
  9961. var result0, result1, result2, result3;
  9962. var pos0, pos1, pos2;
  9963. pos0 = pos;
  9964. pos1 = pos;
  9965. result0 = parse_event_type();
  9966. if (result0 !== null) {
  9967. result1 = [];
  9968. pos2 = pos;
  9969. result2 = parse_SEMI();
  9970. if (result2 !== null) {
  9971. result3 = parse_generic_param();
  9972. if (result3 !== null) {
  9973. result2 = [result2, result3];
  9974. } else {
  9975. result2 = null;
  9976. pos = pos2;
  9977. }
  9978. } else {
  9979. result2 = null;
  9980. pos = pos2;
  9981. }
  9982. while (result2 !== null) {
  9983. result1.push(result2);
  9984. pos2 = pos;
  9985. result2 = parse_SEMI();
  9986. if (result2 !== null) {
  9987. result3 = parse_generic_param();
  9988. if (result3 !== null) {
  9989. result2 = [result2, result3];
  9990. } else {
  9991. result2 = null;
  9992. pos = pos2;
  9993. }
  9994. } else {
  9995. result2 = null;
  9996. pos = pos2;
  9997. }
  9998. }
  9999. if (result1 !== null) {
  10000. result0 = [result0, result1];
  10001. } else {
  10002. result0 = null;
  10003. pos = pos1;
  10004. }
  10005. } else {
  10006. result0 = null;
  10007. pos = pos1;
  10008. }
  10009. if (result0 !== null) {
  10010. result0 = function (offset, event_type) {
  10011. data.event = event_type.join('').toLowerCase();
  10012. }(pos0, result0[0]);
  10013. }
  10014. if (result0 === null) {
  10015. pos = pos0;
  10016. }
  10017. return result0;
  10018. }
  10019. function parse_event_type() {
  10020. var result0, result1, result2, result3;
  10021. var pos0, pos1;
  10022. pos0 = pos;
  10023. result0 = parse_token_nodot();
  10024. if (result0 !== null) {
  10025. result1 = [];
  10026. pos1 = pos;
  10027. if (input.charCodeAt(pos) === 46) {
  10028. result2 = ".";
  10029. pos++;
  10030. } else {
  10031. result2 = null;
  10032. if (reportFailures === 0) {
  10033. matchFailed("\".\"");
  10034. }
  10035. }
  10036. if (result2 !== null) {
  10037. result3 = parse_token_nodot();
  10038. if (result3 !== null) {
  10039. result2 = [result2, result3];
  10040. } else {
  10041. result2 = null;
  10042. pos = pos1;
  10043. }
  10044. } else {
  10045. result2 = null;
  10046. pos = pos1;
  10047. }
  10048. while (result2 !== null) {
  10049. result1.push(result2);
  10050. pos1 = pos;
  10051. if (input.charCodeAt(pos) === 46) {
  10052. result2 = ".";
  10053. pos++;
  10054. } else {
  10055. result2 = null;
  10056. if (reportFailures === 0) {
  10057. matchFailed("\".\"");
  10058. }
  10059. }
  10060. if (result2 !== null) {
  10061. result3 = parse_token_nodot();
  10062. if (result3 !== null) {
  10063. result2 = [result2, result3];
  10064. } else {
  10065. result2 = null;
  10066. pos = pos1;
  10067. }
  10068. } else {
  10069. result2 = null;
  10070. pos = pos1;
  10071. }
  10072. }
  10073. if (result1 !== null) {
  10074. result0 = [result0, result1];
  10075. } else {
  10076. result0 = null;
  10077. pos = pos0;
  10078. }
  10079. } else {
  10080. result0 = null;
  10081. pos = pos0;
  10082. }
  10083. return result0;
  10084. }
  10085. function parse_From() {
  10086. var result0, result1, result2, result3;
  10087. var pos0, pos1, pos2;
  10088. pos0 = pos;
  10089. pos1 = pos;
  10090. result0 = parse_SIP_URI_noparams();
  10091. if (result0 === null) {
  10092. result0 = parse_name_addr();
  10093. }
  10094. if (result0 !== null) {
  10095. result1 = [];
  10096. pos2 = pos;
  10097. result2 = parse_SEMI();
  10098. if (result2 !== null) {
  10099. result3 = parse_from_param();
  10100. if (result3 !== null) {
  10101. result2 = [result2, result3];
  10102. } else {
  10103. result2 = null;
  10104. pos = pos2;
  10105. }
  10106. } else {
  10107. result2 = null;
  10108. pos = pos2;
  10109. }
  10110. while (result2 !== null) {
  10111. result1.push(result2);
  10112. pos2 = pos;
  10113. result2 = parse_SEMI();
  10114. if (result2 !== null) {
  10115. result3 = parse_from_param();
  10116. if (result3 !== null) {
  10117. result2 = [result2, result3];
  10118. } else {
  10119. result2 = null;
  10120. pos = pos2;
  10121. }
  10122. } else {
  10123. result2 = null;
  10124. pos = pos2;
  10125. }
  10126. }
  10127. if (result1 !== null) {
  10128. result0 = [result0, result1];
  10129. } else {
  10130. result0 = null;
  10131. pos = pos1;
  10132. }
  10133. } else {
  10134. result0 = null;
  10135. pos = pos1;
  10136. }
  10137. if (result0 !== null) {
  10138. result0 = function (offset) {
  10139. var tag = data.tag;
  10140. try {
  10141. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  10142. if (tag) {
  10143. data.setParam('tag', tag);
  10144. }
  10145. } catch (e) {
  10146. data = -1;
  10147. }
  10148. }(pos0);
  10149. }
  10150. if (result0 === null) {
  10151. pos = pos0;
  10152. }
  10153. return result0;
  10154. }
  10155. function parse_from_param() {
  10156. var result0;
  10157. result0 = parse_tag_param();
  10158. if (result0 === null) {
  10159. result0 = parse_generic_param();
  10160. }
  10161. return result0;
  10162. }
  10163. function parse_tag_param() {
  10164. var result0, result1, result2;
  10165. var pos0, pos1;
  10166. pos0 = pos;
  10167. pos1 = pos;
  10168. if (input.substr(pos, 3).toLowerCase() === "tag") {
  10169. result0 = input.substr(pos, 3);
  10170. pos += 3;
  10171. } else {
  10172. result0 = null;
  10173. if (reportFailures === 0) {
  10174. matchFailed("\"tag\"");
  10175. }
  10176. }
  10177. if (result0 !== null) {
  10178. result1 = parse_EQUAL();
  10179. if (result1 !== null) {
  10180. result2 = parse_token();
  10181. if (result2 !== null) {
  10182. result0 = [result0, result1, result2];
  10183. } else {
  10184. result0 = null;
  10185. pos = pos1;
  10186. }
  10187. } else {
  10188. result0 = null;
  10189. pos = pos1;
  10190. }
  10191. } else {
  10192. result0 = null;
  10193. pos = pos1;
  10194. }
  10195. if (result0 !== null) {
  10196. result0 = function (offset, tag) {
  10197. data.tag = tag;
  10198. }(pos0, result0[2]);
  10199. }
  10200. if (result0 === null) {
  10201. pos = pos0;
  10202. }
  10203. return result0;
  10204. }
  10205. function parse_Max_Forwards() {
  10206. var result0, result1;
  10207. var pos0;
  10208. pos0 = pos;
  10209. result1 = parse_DIGIT();
  10210. if (result1 !== null) {
  10211. result0 = [];
  10212. while (result1 !== null) {
  10213. result0.push(result1);
  10214. result1 = parse_DIGIT();
  10215. }
  10216. } else {
  10217. result0 = null;
  10218. }
  10219. if (result0 !== null) {
  10220. result0 = function (offset, forwards) {
  10221. data = parseInt(forwards.join(''));
  10222. }(pos0, result0);
  10223. }
  10224. if (result0 === null) {
  10225. pos = pos0;
  10226. }
  10227. return result0;
  10228. }
  10229. function parse_Min_Expires() {
  10230. var result0;
  10231. var pos0;
  10232. pos0 = pos;
  10233. result0 = parse_delta_seconds();
  10234. if (result0 !== null) {
  10235. result0 = function (offset, min_expires) {
  10236. data = min_expires;
  10237. }(pos0, result0);
  10238. }
  10239. if (result0 === null) {
  10240. pos = pos0;
  10241. }
  10242. return result0;
  10243. }
  10244. function parse_Name_Addr_Header() {
  10245. var result0, result1, result2, result3, result4, result5, result6;
  10246. var pos0, pos1, pos2;
  10247. pos0 = pos;
  10248. pos1 = pos;
  10249. result0 = [];
  10250. result1 = parse_display_name();
  10251. while (result1 !== null) {
  10252. result0.push(result1);
  10253. result1 = parse_display_name();
  10254. }
  10255. if (result0 !== null) {
  10256. result1 = parse_LAQUOT();
  10257. if (result1 !== null) {
  10258. result2 = parse_SIP_URI();
  10259. if (result2 !== null) {
  10260. result3 = parse_RAQUOT();
  10261. if (result3 !== null) {
  10262. result4 = [];
  10263. pos2 = pos;
  10264. result5 = parse_SEMI();
  10265. if (result5 !== null) {
  10266. result6 = parse_generic_param();
  10267. if (result6 !== null) {
  10268. result5 = [result5, result6];
  10269. } else {
  10270. result5 = null;
  10271. pos = pos2;
  10272. }
  10273. } else {
  10274. result5 = null;
  10275. pos = pos2;
  10276. }
  10277. while (result5 !== null) {
  10278. result4.push(result5);
  10279. pos2 = pos;
  10280. result5 = parse_SEMI();
  10281. if (result5 !== null) {
  10282. result6 = parse_generic_param();
  10283. if (result6 !== null) {
  10284. result5 = [result5, result6];
  10285. } else {
  10286. result5 = null;
  10287. pos = pos2;
  10288. }
  10289. } else {
  10290. result5 = null;
  10291. pos = pos2;
  10292. }
  10293. }
  10294. if (result4 !== null) {
  10295. result0 = [result0, result1, result2, result3, result4];
  10296. } else {
  10297. result0 = null;
  10298. pos = pos1;
  10299. }
  10300. } else {
  10301. result0 = null;
  10302. pos = pos1;
  10303. }
  10304. } else {
  10305. result0 = null;
  10306. pos = pos1;
  10307. }
  10308. } else {
  10309. result0 = null;
  10310. pos = pos1;
  10311. }
  10312. } else {
  10313. result0 = null;
  10314. pos = pos1;
  10315. }
  10316. if (result0 !== null) {
  10317. result0 = function (offset) {
  10318. try {
  10319. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  10320. } catch (e) {
  10321. data = -1;
  10322. }
  10323. }(pos0);
  10324. }
  10325. if (result0 === null) {
  10326. pos = pos0;
  10327. }
  10328. return result0;
  10329. }
  10330. function parse_Proxy_Authenticate() {
  10331. var result0;
  10332. result0 = parse_challenge();
  10333. return result0;
  10334. }
  10335. function parse_challenge() {
  10336. var result0, result1, result2, result3, result4, result5;
  10337. var pos0, pos1;
  10338. pos0 = pos;
  10339. if (input.substr(pos, 6).toLowerCase() === "digest") {
  10340. result0 = input.substr(pos, 6);
  10341. pos += 6;
  10342. } else {
  10343. result0 = null;
  10344. if (reportFailures === 0) {
  10345. matchFailed("\"Digest\"");
  10346. }
  10347. }
  10348. if (result0 !== null) {
  10349. result1 = parse_LWS();
  10350. if (result1 !== null) {
  10351. result2 = parse_digest_cln();
  10352. if (result2 !== null) {
  10353. result3 = [];
  10354. pos1 = pos;
  10355. result4 = parse_COMMA();
  10356. if (result4 !== null) {
  10357. result5 = parse_digest_cln();
  10358. if (result5 !== null) {
  10359. result4 = [result4, result5];
  10360. } else {
  10361. result4 = null;
  10362. pos = pos1;
  10363. }
  10364. } else {
  10365. result4 = null;
  10366. pos = pos1;
  10367. }
  10368. while (result4 !== null) {
  10369. result3.push(result4);
  10370. pos1 = pos;
  10371. result4 = parse_COMMA();
  10372. if (result4 !== null) {
  10373. result5 = parse_digest_cln();
  10374. if (result5 !== null) {
  10375. result4 = [result4, result5];
  10376. } else {
  10377. result4 = null;
  10378. pos = pos1;
  10379. }
  10380. } else {
  10381. result4 = null;
  10382. pos = pos1;
  10383. }
  10384. }
  10385. if (result3 !== null) {
  10386. result0 = [result0, result1, result2, result3];
  10387. } else {
  10388. result0 = null;
  10389. pos = pos0;
  10390. }
  10391. } else {
  10392. result0 = null;
  10393. pos = pos0;
  10394. }
  10395. } else {
  10396. result0 = null;
  10397. pos = pos0;
  10398. }
  10399. } else {
  10400. result0 = null;
  10401. pos = pos0;
  10402. }
  10403. if (result0 === null) {
  10404. result0 = parse_other_challenge();
  10405. }
  10406. return result0;
  10407. }
  10408. function parse_other_challenge() {
  10409. var result0, result1, result2, result3, result4, result5;
  10410. var pos0, pos1;
  10411. pos0 = pos;
  10412. result0 = parse_token();
  10413. if (result0 !== null) {
  10414. result1 = parse_LWS();
  10415. if (result1 !== null) {
  10416. result2 = parse_auth_param();
  10417. if (result2 !== null) {
  10418. result3 = [];
  10419. pos1 = pos;
  10420. result4 = parse_COMMA();
  10421. if (result4 !== null) {
  10422. result5 = parse_auth_param();
  10423. if (result5 !== null) {
  10424. result4 = [result4, result5];
  10425. } else {
  10426. result4 = null;
  10427. pos = pos1;
  10428. }
  10429. } else {
  10430. result4 = null;
  10431. pos = pos1;
  10432. }
  10433. while (result4 !== null) {
  10434. result3.push(result4);
  10435. pos1 = pos;
  10436. result4 = parse_COMMA();
  10437. if (result4 !== null) {
  10438. result5 = parse_auth_param();
  10439. if (result5 !== null) {
  10440. result4 = [result4, result5];
  10441. } else {
  10442. result4 = null;
  10443. pos = pos1;
  10444. }
  10445. } else {
  10446. result4 = null;
  10447. pos = pos1;
  10448. }
  10449. }
  10450. if (result3 !== null) {
  10451. result0 = [result0, result1, result2, result3];
  10452. } else {
  10453. result0 = null;
  10454. pos = pos0;
  10455. }
  10456. } else {
  10457. result0 = null;
  10458. pos = pos0;
  10459. }
  10460. } else {
  10461. result0 = null;
  10462. pos = pos0;
  10463. }
  10464. } else {
  10465. result0 = null;
  10466. pos = pos0;
  10467. }
  10468. return result0;
  10469. }
  10470. function parse_auth_param() {
  10471. var result0, result1, result2;
  10472. var pos0;
  10473. pos0 = pos;
  10474. result0 = parse_token();
  10475. if (result0 !== null) {
  10476. result1 = parse_EQUAL();
  10477. if (result1 !== null) {
  10478. result2 = parse_token();
  10479. if (result2 === null) {
  10480. result2 = parse_quoted_string();
  10481. }
  10482. if (result2 !== null) {
  10483. result0 = [result0, result1, result2];
  10484. } else {
  10485. result0 = null;
  10486. pos = pos0;
  10487. }
  10488. } else {
  10489. result0 = null;
  10490. pos = pos0;
  10491. }
  10492. } else {
  10493. result0 = null;
  10494. pos = pos0;
  10495. }
  10496. return result0;
  10497. }
  10498. function parse_digest_cln() {
  10499. var result0;
  10500. result0 = parse_realm();
  10501. if (result0 === null) {
  10502. result0 = parse_domain();
  10503. if (result0 === null) {
  10504. result0 = parse_nonce();
  10505. if (result0 === null) {
  10506. result0 = parse_opaque();
  10507. if (result0 === null) {
  10508. result0 = parse_stale();
  10509. if (result0 === null) {
  10510. result0 = parse_algorithm();
  10511. if (result0 === null) {
  10512. result0 = parse_qop_options();
  10513. if (result0 === null) {
  10514. result0 = parse_auth_param();
  10515. }
  10516. }
  10517. }
  10518. }
  10519. }
  10520. }
  10521. }
  10522. return result0;
  10523. }
  10524. function parse_realm() {
  10525. var result0, result1, result2;
  10526. var pos0;
  10527. pos0 = pos;
  10528. if (input.substr(pos, 5).toLowerCase() === "realm") {
  10529. result0 = input.substr(pos, 5);
  10530. pos += 5;
  10531. } else {
  10532. result0 = null;
  10533. if (reportFailures === 0) {
  10534. matchFailed("\"realm\"");
  10535. }
  10536. }
  10537. if (result0 !== null) {
  10538. result1 = parse_EQUAL();
  10539. if (result1 !== null) {
  10540. result2 = parse_realm_value();
  10541. if (result2 !== null) {
  10542. result0 = [result0, result1, result2];
  10543. } else {
  10544. result0 = null;
  10545. pos = pos0;
  10546. }
  10547. } else {
  10548. result0 = null;
  10549. pos = pos0;
  10550. }
  10551. } else {
  10552. result0 = null;
  10553. pos = pos0;
  10554. }
  10555. return result0;
  10556. }
  10557. function parse_realm_value() {
  10558. var result0;
  10559. var pos0;
  10560. pos0 = pos;
  10561. result0 = parse_quoted_string_clean();
  10562. if (result0 !== null) {
  10563. result0 = function (offset, realm) {
  10564. data.realm = realm;
  10565. }(pos0, result0);
  10566. }
  10567. if (result0 === null) {
  10568. pos = pos0;
  10569. }
  10570. return result0;
  10571. }
  10572. function parse_domain() {
  10573. var result0, result1, result2, result3, result4, result5, result6;
  10574. var pos0, pos1;
  10575. pos0 = pos;
  10576. if (input.substr(pos, 6).toLowerCase() === "domain") {
  10577. result0 = input.substr(pos, 6);
  10578. pos += 6;
  10579. } else {
  10580. result0 = null;
  10581. if (reportFailures === 0) {
  10582. matchFailed("\"domain\"");
  10583. }
  10584. }
  10585. if (result0 !== null) {
  10586. result1 = parse_EQUAL();
  10587. if (result1 !== null) {
  10588. result2 = parse_LDQUOT();
  10589. if (result2 !== null) {
  10590. result3 = parse_URI();
  10591. if (result3 !== null) {
  10592. result4 = [];
  10593. pos1 = pos;
  10594. result6 = parse_SP();
  10595. if (result6 !== null) {
  10596. result5 = [];
  10597. while (result6 !== null) {
  10598. result5.push(result6);
  10599. result6 = parse_SP();
  10600. }
  10601. } else {
  10602. result5 = null;
  10603. }
  10604. if (result5 !== null) {
  10605. result6 = parse_URI();
  10606. if (result6 !== null) {
  10607. result5 = [result5, result6];
  10608. } else {
  10609. result5 = null;
  10610. pos = pos1;
  10611. }
  10612. } else {
  10613. result5 = null;
  10614. pos = pos1;
  10615. }
  10616. while (result5 !== null) {
  10617. result4.push(result5);
  10618. pos1 = pos;
  10619. result6 = parse_SP();
  10620. if (result6 !== null) {
  10621. result5 = [];
  10622. while (result6 !== null) {
  10623. result5.push(result6);
  10624. result6 = parse_SP();
  10625. }
  10626. } else {
  10627. result5 = null;
  10628. }
  10629. if (result5 !== null) {
  10630. result6 = parse_URI();
  10631. if (result6 !== null) {
  10632. result5 = [result5, result6];
  10633. } else {
  10634. result5 = null;
  10635. pos = pos1;
  10636. }
  10637. } else {
  10638. result5 = null;
  10639. pos = pos1;
  10640. }
  10641. }
  10642. if (result4 !== null) {
  10643. result5 = parse_RDQUOT();
  10644. if (result5 !== null) {
  10645. result0 = [result0, result1, result2, result3, result4, result5];
  10646. } else {
  10647. result0 = null;
  10648. pos = pos0;
  10649. }
  10650. } else {
  10651. result0 = null;
  10652. pos = pos0;
  10653. }
  10654. } else {
  10655. result0 = null;
  10656. pos = pos0;
  10657. }
  10658. } else {
  10659. result0 = null;
  10660. pos = pos0;
  10661. }
  10662. } else {
  10663. result0 = null;
  10664. pos = pos0;
  10665. }
  10666. } else {
  10667. result0 = null;
  10668. pos = pos0;
  10669. }
  10670. return result0;
  10671. }
  10672. function parse_URI() {
  10673. var result0;
  10674. result0 = parse_absoluteURI();
  10675. if (result0 === null) {
  10676. result0 = parse_abs_path();
  10677. }
  10678. return result0;
  10679. }
  10680. function parse_nonce() {
  10681. var result0, result1, result2;
  10682. var pos0;
  10683. pos0 = pos;
  10684. if (input.substr(pos, 5).toLowerCase() === "nonce") {
  10685. result0 = input.substr(pos, 5);
  10686. pos += 5;
  10687. } else {
  10688. result0 = null;
  10689. if (reportFailures === 0) {
  10690. matchFailed("\"nonce\"");
  10691. }
  10692. }
  10693. if (result0 !== null) {
  10694. result1 = parse_EQUAL();
  10695. if (result1 !== null) {
  10696. result2 = parse_nonce_value();
  10697. if (result2 !== null) {
  10698. result0 = [result0, result1, result2];
  10699. } else {
  10700. result0 = null;
  10701. pos = pos0;
  10702. }
  10703. } else {
  10704. result0 = null;
  10705. pos = pos0;
  10706. }
  10707. } else {
  10708. result0 = null;
  10709. pos = pos0;
  10710. }
  10711. return result0;
  10712. }
  10713. function parse_nonce_value() {
  10714. var result0;
  10715. var pos0;
  10716. pos0 = pos;
  10717. result0 = parse_quoted_string_clean();
  10718. if (result0 !== null) {
  10719. result0 = function (offset, nonce) {
  10720. data.nonce = nonce;
  10721. }(pos0, result0);
  10722. }
  10723. if (result0 === null) {
  10724. pos = pos0;
  10725. }
  10726. return result0;
  10727. }
  10728. function parse_opaque() {
  10729. var result0, result1, result2;
  10730. var pos0, pos1;
  10731. pos0 = pos;
  10732. pos1 = pos;
  10733. if (input.substr(pos, 6).toLowerCase() === "opaque") {
  10734. result0 = input.substr(pos, 6);
  10735. pos += 6;
  10736. } else {
  10737. result0 = null;
  10738. if (reportFailures === 0) {
  10739. matchFailed("\"opaque\"");
  10740. }
  10741. }
  10742. if (result0 !== null) {
  10743. result1 = parse_EQUAL();
  10744. if (result1 !== null) {
  10745. result2 = parse_quoted_string_clean();
  10746. if (result2 !== null) {
  10747. result0 = [result0, result1, result2];
  10748. } else {
  10749. result0 = null;
  10750. pos = pos1;
  10751. }
  10752. } else {
  10753. result0 = null;
  10754. pos = pos1;
  10755. }
  10756. } else {
  10757. result0 = null;
  10758. pos = pos1;
  10759. }
  10760. if (result0 !== null) {
  10761. result0 = function (offset, opaque) {
  10762. data.opaque = opaque;
  10763. }(pos0, result0[2]);
  10764. }
  10765. if (result0 === null) {
  10766. pos = pos0;
  10767. }
  10768. return result0;
  10769. }
  10770. function parse_stale() {
  10771. var result0, result1, result2;
  10772. var pos0, pos1;
  10773. pos0 = pos;
  10774. if (input.substr(pos, 5).toLowerCase() === "stale") {
  10775. result0 = input.substr(pos, 5);
  10776. pos += 5;
  10777. } else {
  10778. result0 = null;
  10779. if (reportFailures === 0) {
  10780. matchFailed("\"stale\"");
  10781. }
  10782. }
  10783. if (result0 !== null) {
  10784. result1 = parse_EQUAL();
  10785. if (result1 !== null) {
  10786. pos1 = pos;
  10787. if (input.substr(pos, 4).toLowerCase() === "true") {
  10788. result2 = input.substr(pos, 4);
  10789. pos += 4;
  10790. } else {
  10791. result2 = null;
  10792. if (reportFailures === 0) {
  10793. matchFailed("\"true\"");
  10794. }
  10795. }
  10796. if (result2 !== null) {
  10797. result2 = function (offset) {
  10798. data.stale = true;
  10799. }(pos1);
  10800. }
  10801. if (result2 === null) {
  10802. pos = pos1;
  10803. }
  10804. if (result2 === null) {
  10805. pos1 = pos;
  10806. if (input.substr(pos, 5).toLowerCase() === "false") {
  10807. result2 = input.substr(pos, 5);
  10808. pos += 5;
  10809. } else {
  10810. result2 = null;
  10811. if (reportFailures === 0) {
  10812. matchFailed("\"false\"");
  10813. }
  10814. }
  10815. if (result2 !== null) {
  10816. result2 = function (offset) {
  10817. data.stale = false;
  10818. }(pos1);
  10819. }
  10820. if (result2 === null) {
  10821. pos = pos1;
  10822. }
  10823. }
  10824. if (result2 !== null) {
  10825. result0 = [result0, result1, result2];
  10826. } else {
  10827. result0 = null;
  10828. pos = pos0;
  10829. }
  10830. } else {
  10831. result0 = null;
  10832. pos = pos0;
  10833. }
  10834. } else {
  10835. result0 = null;
  10836. pos = pos0;
  10837. }
  10838. return result0;
  10839. }
  10840. function parse_algorithm() {
  10841. var result0, result1, result2;
  10842. var pos0, pos1;
  10843. pos0 = pos;
  10844. pos1 = pos;
  10845. if (input.substr(pos, 9).toLowerCase() === "algorithm") {
  10846. result0 = input.substr(pos, 9);
  10847. pos += 9;
  10848. } else {
  10849. result0 = null;
  10850. if (reportFailures === 0) {
  10851. matchFailed("\"algorithm\"");
  10852. }
  10853. }
  10854. if (result0 !== null) {
  10855. result1 = parse_EQUAL();
  10856. if (result1 !== null) {
  10857. if (input.substr(pos, 3).toLowerCase() === "md5") {
  10858. result2 = input.substr(pos, 3);
  10859. pos += 3;
  10860. } else {
  10861. result2 = null;
  10862. if (reportFailures === 0) {
  10863. matchFailed("\"MD5\"");
  10864. }
  10865. }
  10866. if (result2 === null) {
  10867. if (input.substr(pos, 8).toLowerCase() === "md5-sess") {
  10868. result2 = input.substr(pos, 8);
  10869. pos += 8;
  10870. } else {
  10871. result2 = null;
  10872. if (reportFailures === 0) {
  10873. matchFailed("\"MD5-sess\"");
  10874. }
  10875. }
  10876. if (result2 === null) {
  10877. result2 = parse_token();
  10878. }
  10879. }
  10880. if (result2 !== null) {
  10881. result0 = [result0, result1, result2];
  10882. } else {
  10883. result0 = null;
  10884. pos = pos1;
  10885. }
  10886. } else {
  10887. result0 = null;
  10888. pos = pos1;
  10889. }
  10890. } else {
  10891. result0 = null;
  10892. pos = pos1;
  10893. }
  10894. if (result0 !== null) {
  10895. result0 = function (offset, algorithm) {
  10896. data.algorithm = algorithm.toUpperCase();
  10897. }(pos0, result0[2]);
  10898. }
  10899. if (result0 === null) {
  10900. pos = pos0;
  10901. }
  10902. return result0;
  10903. }
  10904. function parse_qop_options() {
  10905. var result0, result1, result2, result3, result4, result5, result6;
  10906. var pos0, pos1, pos2;
  10907. pos0 = pos;
  10908. if (input.substr(pos, 3).toLowerCase() === "qop") {
  10909. result0 = input.substr(pos, 3);
  10910. pos += 3;
  10911. } else {
  10912. result0 = null;
  10913. if (reportFailures === 0) {
  10914. matchFailed("\"qop\"");
  10915. }
  10916. }
  10917. if (result0 !== null) {
  10918. result1 = parse_EQUAL();
  10919. if (result1 !== null) {
  10920. result2 = parse_LDQUOT();
  10921. if (result2 !== null) {
  10922. pos1 = pos;
  10923. result3 = parse_qop_value();
  10924. if (result3 !== null) {
  10925. result4 = [];
  10926. pos2 = pos;
  10927. if (input.charCodeAt(pos) === 44) {
  10928. result5 = ",";
  10929. pos++;
  10930. } else {
  10931. result5 = null;
  10932. if (reportFailures === 0) {
  10933. matchFailed("\",\"");
  10934. }
  10935. }
  10936. if (result5 !== null) {
  10937. result6 = parse_qop_value();
  10938. if (result6 !== null) {
  10939. result5 = [result5, result6];
  10940. } else {
  10941. result5 = null;
  10942. pos = pos2;
  10943. }
  10944. } else {
  10945. result5 = null;
  10946. pos = pos2;
  10947. }
  10948. while (result5 !== null) {
  10949. result4.push(result5);
  10950. pos2 = pos;
  10951. if (input.charCodeAt(pos) === 44) {
  10952. result5 = ",";
  10953. pos++;
  10954. } else {
  10955. result5 = null;
  10956. if (reportFailures === 0) {
  10957. matchFailed("\",\"");
  10958. }
  10959. }
  10960. if (result5 !== null) {
  10961. result6 = parse_qop_value();
  10962. if (result6 !== null) {
  10963. result5 = [result5, result6];
  10964. } else {
  10965. result5 = null;
  10966. pos = pos2;
  10967. }
  10968. } else {
  10969. result5 = null;
  10970. pos = pos2;
  10971. }
  10972. }
  10973. if (result4 !== null) {
  10974. result3 = [result3, result4];
  10975. } else {
  10976. result3 = null;
  10977. pos = pos1;
  10978. }
  10979. } else {
  10980. result3 = null;
  10981. pos = pos1;
  10982. }
  10983. if (result3 !== null) {
  10984. result4 = parse_RDQUOT();
  10985. if (result4 !== null) {
  10986. result0 = [result0, result1, result2, result3, result4];
  10987. } else {
  10988. result0 = null;
  10989. pos = pos0;
  10990. }
  10991. } else {
  10992. result0 = null;
  10993. pos = pos0;
  10994. }
  10995. } else {
  10996. result0 = null;
  10997. pos = pos0;
  10998. }
  10999. } else {
  11000. result0 = null;
  11001. pos = pos0;
  11002. }
  11003. } else {
  11004. result0 = null;
  11005. pos = pos0;
  11006. }
  11007. return result0;
  11008. }
  11009. function parse_qop_value() {
  11010. var result0;
  11011. var pos0;
  11012. pos0 = pos;
  11013. if (input.substr(pos, 8).toLowerCase() === "auth-int") {
  11014. result0 = input.substr(pos, 8);
  11015. pos += 8;
  11016. } else {
  11017. result0 = null;
  11018. if (reportFailures === 0) {
  11019. matchFailed("\"auth-int\"");
  11020. }
  11021. }
  11022. if (result0 === null) {
  11023. if (input.substr(pos, 4).toLowerCase() === "auth") {
  11024. result0 = input.substr(pos, 4);
  11025. pos += 4;
  11026. } else {
  11027. result0 = null;
  11028. if (reportFailures === 0) {
  11029. matchFailed("\"auth\"");
  11030. }
  11031. }
  11032. if (result0 === null) {
  11033. result0 = parse_token();
  11034. }
  11035. }
  11036. if (result0 !== null) {
  11037. result0 = function (offset, qop_value) {
  11038. data.qop || (data.qop = []);
  11039. data.qop.push(qop_value.toLowerCase());
  11040. }(pos0, result0);
  11041. }
  11042. if (result0 === null) {
  11043. pos = pos0;
  11044. }
  11045. return result0;
  11046. }
  11047. function parse_Proxy_Require() {
  11048. var result0, result1, result2, result3;
  11049. var pos0, pos1;
  11050. pos0 = pos;
  11051. result0 = parse_token();
  11052. if (result0 !== null) {
  11053. result1 = [];
  11054. pos1 = pos;
  11055. result2 = parse_COMMA();
  11056. if (result2 !== null) {
  11057. result3 = parse_token();
  11058. if (result3 !== null) {
  11059. result2 = [result2, result3];
  11060. } else {
  11061. result2 = null;
  11062. pos = pos1;
  11063. }
  11064. } else {
  11065. result2 = null;
  11066. pos = pos1;
  11067. }
  11068. while (result2 !== null) {
  11069. result1.push(result2);
  11070. pos1 = pos;
  11071. result2 = parse_COMMA();
  11072. if (result2 !== null) {
  11073. result3 = parse_token();
  11074. if (result3 !== null) {
  11075. result2 = [result2, result3];
  11076. } else {
  11077. result2 = null;
  11078. pos = pos1;
  11079. }
  11080. } else {
  11081. result2 = null;
  11082. pos = pos1;
  11083. }
  11084. }
  11085. if (result1 !== null) {
  11086. result0 = [result0, result1];
  11087. } else {
  11088. result0 = null;
  11089. pos = pos0;
  11090. }
  11091. } else {
  11092. result0 = null;
  11093. pos = pos0;
  11094. }
  11095. return result0;
  11096. }
  11097. function parse_Record_Route() {
  11098. var result0, result1, result2, result3;
  11099. var pos0, pos1, pos2;
  11100. pos0 = pos;
  11101. pos1 = pos;
  11102. result0 = parse_rec_route();
  11103. if (result0 !== null) {
  11104. result1 = [];
  11105. pos2 = pos;
  11106. result2 = parse_COMMA();
  11107. if (result2 !== null) {
  11108. result3 = parse_rec_route();
  11109. if (result3 !== null) {
  11110. result2 = [result2, result3];
  11111. } else {
  11112. result2 = null;
  11113. pos = pos2;
  11114. }
  11115. } else {
  11116. result2 = null;
  11117. pos = pos2;
  11118. }
  11119. while (result2 !== null) {
  11120. result1.push(result2);
  11121. pos2 = pos;
  11122. result2 = parse_COMMA();
  11123. if (result2 !== null) {
  11124. result3 = parse_rec_route();
  11125. if (result3 !== null) {
  11126. result2 = [result2, result3];
  11127. } else {
  11128. result2 = null;
  11129. pos = pos2;
  11130. }
  11131. } else {
  11132. result2 = null;
  11133. pos = pos2;
  11134. }
  11135. }
  11136. if (result1 !== null) {
  11137. result0 = [result0, result1];
  11138. } else {
  11139. result0 = null;
  11140. pos = pos1;
  11141. }
  11142. } else {
  11143. result0 = null;
  11144. pos = pos1;
  11145. }
  11146. if (result0 !== null) {
  11147. result0 = function (offset) {
  11148. var idx, length;
  11149. length = data.multi_header.length;
  11150. for (idx = 0; idx < length; idx++) {
  11151. if (data.multi_header[idx].parsed === null) {
  11152. data = null;
  11153. break;
  11154. }
  11155. }
  11156. if (data !== null) {
  11157. data = data.multi_header;
  11158. } else {
  11159. data = -1;
  11160. }
  11161. }(pos0);
  11162. }
  11163. if (result0 === null) {
  11164. pos = pos0;
  11165. }
  11166. return result0;
  11167. }
  11168. function parse_rec_route() {
  11169. var result0, result1, result2, result3;
  11170. var pos0, pos1, pos2;
  11171. pos0 = pos;
  11172. pos1 = pos;
  11173. result0 = parse_name_addr();
  11174. if (result0 !== null) {
  11175. result1 = [];
  11176. pos2 = pos;
  11177. result2 = parse_SEMI();
  11178. if (result2 !== null) {
  11179. result3 = parse_generic_param();
  11180. if (result3 !== null) {
  11181. result2 = [result2, result3];
  11182. } else {
  11183. result2 = null;
  11184. pos = pos2;
  11185. }
  11186. } else {
  11187. result2 = null;
  11188. pos = pos2;
  11189. }
  11190. while (result2 !== null) {
  11191. result1.push(result2);
  11192. pos2 = pos;
  11193. result2 = parse_SEMI();
  11194. if (result2 !== null) {
  11195. result3 = parse_generic_param();
  11196. if (result3 !== null) {
  11197. result2 = [result2, result3];
  11198. } else {
  11199. result2 = null;
  11200. pos = pos2;
  11201. }
  11202. } else {
  11203. result2 = null;
  11204. pos = pos2;
  11205. }
  11206. }
  11207. if (result1 !== null) {
  11208. result0 = [result0, result1];
  11209. } else {
  11210. result0 = null;
  11211. pos = pos1;
  11212. }
  11213. } else {
  11214. result0 = null;
  11215. pos = pos1;
  11216. }
  11217. if (result0 !== null) {
  11218. result0 = function (offset) {
  11219. var header;
  11220. if (!data.multi_header) data.multi_header = [];
  11221. try {
  11222. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  11223. delete data.uri;
  11224. delete data.display_name;
  11225. delete data.params;
  11226. } catch (e) {
  11227. header = null;
  11228. }
  11229. data.multi_header.push({
  11230. 'possition': pos,
  11231. 'offset': offset,
  11232. 'parsed': header
  11233. });
  11234. }(pos0);
  11235. }
  11236. if (result0 === null) {
  11237. pos = pos0;
  11238. }
  11239. return result0;
  11240. }
  11241. function parse_Reason() {
  11242. var result0, result1, result2, result3;
  11243. var pos0, pos1, pos2;
  11244. pos0 = pos;
  11245. pos1 = pos;
  11246. if (input.substr(pos, 3).toLowerCase() === "sip") {
  11247. result0 = input.substr(pos, 3);
  11248. pos += 3;
  11249. } else {
  11250. result0 = null;
  11251. if (reportFailures === 0) {
  11252. matchFailed("\"SIP\"");
  11253. }
  11254. }
  11255. if (result0 === null) {
  11256. result0 = parse_token();
  11257. }
  11258. if (result0 !== null) {
  11259. result1 = [];
  11260. pos2 = pos;
  11261. result2 = parse_SEMI();
  11262. if (result2 !== null) {
  11263. result3 = parse_reason_param();
  11264. if (result3 !== null) {
  11265. result2 = [result2, result3];
  11266. } else {
  11267. result2 = null;
  11268. pos = pos2;
  11269. }
  11270. } else {
  11271. result2 = null;
  11272. pos = pos2;
  11273. }
  11274. while (result2 !== null) {
  11275. result1.push(result2);
  11276. pos2 = pos;
  11277. result2 = parse_SEMI();
  11278. if (result2 !== null) {
  11279. result3 = parse_reason_param();
  11280. if (result3 !== null) {
  11281. result2 = [result2, result3];
  11282. } else {
  11283. result2 = null;
  11284. pos = pos2;
  11285. }
  11286. } else {
  11287. result2 = null;
  11288. pos = pos2;
  11289. }
  11290. }
  11291. if (result1 !== null) {
  11292. result0 = [result0, result1];
  11293. } else {
  11294. result0 = null;
  11295. pos = pos1;
  11296. }
  11297. } else {
  11298. result0 = null;
  11299. pos = pos1;
  11300. }
  11301. if (result0 !== null) {
  11302. result0 = function (offset, protocol) {
  11303. data.protocol = protocol.toLowerCase();
  11304. if (!data.params) data.params = {};
  11305. if (data.params.text && data.params.text[0] === '"') {
  11306. var text = data.params.text;
  11307. data.text = text.substring(1, text.length - 1);
  11308. delete data.params.text;
  11309. }
  11310. }(pos0, result0[0]);
  11311. }
  11312. if (result0 === null) {
  11313. pos = pos0;
  11314. }
  11315. return result0;
  11316. }
  11317. function parse_reason_param() {
  11318. var result0;
  11319. result0 = parse_reason_cause();
  11320. if (result0 === null) {
  11321. result0 = parse_generic_param();
  11322. }
  11323. return result0;
  11324. }
  11325. function parse_reason_cause() {
  11326. var result0, result1, result2, result3;
  11327. var pos0, pos1;
  11328. pos0 = pos;
  11329. pos1 = pos;
  11330. if (input.substr(pos, 5).toLowerCase() === "cause") {
  11331. result0 = input.substr(pos, 5);
  11332. pos += 5;
  11333. } else {
  11334. result0 = null;
  11335. if (reportFailures === 0) {
  11336. matchFailed("\"cause\"");
  11337. }
  11338. }
  11339. if (result0 !== null) {
  11340. result1 = parse_EQUAL();
  11341. if (result1 !== null) {
  11342. result3 = parse_DIGIT();
  11343. if (result3 !== null) {
  11344. result2 = [];
  11345. while (result3 !== null) {
  11346. result2.push(result3);
  11347. result3 = parse_DIGIT();
  11348. }
  11349. } else {
  11350. result2 = null;
  11351. }
  11352. if (result2 !== null) {
  11353. result0 = [result0, result1, result2];
  11354. } else {
  11355. result0 = null;
  11356. pos = pos1;
  11357. }
  11358. } else {
  11359. result0 = null;
  11360. pos = pos1;
  11361. }
  11362. } else {
  11363. result0 = null;
  11364. pos = pos1;
  11365. }
  11366. if (result0 !== null) {
  11367. result0 = function (offset, cause) {
  11368. data.cause = parseInt(cause.join(''));
  11369. }(pos0, result0[2]);
  11370. }
  11371. if (result0 === null) {
  11372. pos = pos0;
  11373. }
  11374. return result0;
  11375. }
  11376. function parse_Require() {
  11377. var result0, result1, result2, result3;
  11378. var pos0, pos1;
  11379. pos0 = pos;
  11380. result0 = parse_token();
  11381. if (result0 !== null) {
  11382. result1 = [];
  11383. pos1 = pos;
  11384. result2 = parse_COMMA();
  11385. if (result2 !== null) {
  11386. result3 = parse_token();
  11387. if (result3 !== null) {
  11388. result2 = [result2, result3];
  11389. } else {
  11390. result2 = null;
  11391. pos = pos1;
  11392. }
  11393. } else {
  11394. result2 = null;
  11395. pos = pos1;
  11396. }
  11397. while (result2 !== null) {
  11398. result1.push(result2);
  11399. pos1 = pos;
  11400. result2 = parse_COMMA();
  11401. if (result2 !== null) {
  11402. result3 = parse_token();
  11403. if (result3 !== null) {
  11404. result2 = [result2, result3];
  11405. } else {
  11406. result2 = null;
  11407. pos = pos1;
  11408. }
  11409. } else {
  11410. result2 = null;
  11411. pos = pos1;
  11412. }
  11413. }
  11414. if (result1 !== null) {
  11415. result0 = [result0, result1];
  11416. } else {
  11417. result0 = null;
  11418. pos = pos0;
  11419. }
  11420. } else {
  11421. result0 = null;
  11422. pos = pos0;
  11423. }
  11424. return result0;
  11425. }
  11426. function parse_Route() {
  11427. var result0, result1, result2, result3;
  11428. var pos0, pos1;
  11429. pos0 = pos;
  11430. result0 = parse_route_param();
  11431. if (result0 !== null) {
  11432. result1 = [];
  11433. pos1 = pos;
  11434. result2 = parse_COMMA();
  11435. if (result2 !== null) {
  11436. result3 = parse_route_param();
  11437. if (result3 !== null) {
  11438. result2 = [result2, result3];
  11439. } else {
  11440. result2 = null;
  11441. pos = pos1;
  11442. }
  11443. } else {
  11444. result2 = null;
  11445. pos = pos1;
  11446. }
  11447. while (result2 !== null) {
  11448. result1.push(result2);
  11449. pos1 = pos;
  11450. result2 = parse_COMMA();
  11451. if (result2 !== null) {
  11452. result3 = parse_route_param();
  11453. if (result3 !== null) {
  11454. result2 = [result2, result3];
  11455. } else {
  11456. result2 = null;
  11457. pos = pos1;
  11458. }
  11459. } else {
  11460. result2 = null;
  11461. pos = pos1;
  11462. }
  11463. }
  11464. if (result1 !== null) {
  11465. result0 = [result0, result1];
  11466. } else {
  11467. result0 = null;
  11468. pos = pos0;
  11469. }
  11470. } else {
  11471. result0 = null;
  11472. pos = pos0;
  11473. }
  11474. return result0;
  11475. }
  11476. function parse_route_param() {
  11477. var result0, result1, result2, result3;
  11478. var pos0, pos1;
  11479. pos0 = pos;
  11480. result0 = parse_name_addr();
  11481. if (result0 !== null) {
  11482. result1 = [];
  11483. pos1 = pos;
  11484. result2 = parse_SEMI();
  11485. if (result2 !== null) {
  11486. result3 = parse_generic_param();
  11487. if (result3 !== null) {
  11488. result2 = [result2, result3];
  11489. } else {
  11490. result2 = null;
  11491. pos = pos1;
  11492. }
  11493. } else {
  11494. result2 = null;
  11495. pos = pos1;
  11496. }
  11497. while (result2 !== null) {
  11498. result1.push(result2);
  11499. pos1 = pos;
  11500. result2 = parse_SEMI();
  11501. if (result2 !== null) {
  11502. result3 = parse_generic_param();
  11503. if (result3 !== null) {
  11504. result2 = [result2, result3];
  11505. } else {
  11506. result2 = null;
  11507. pos = pos1;
  11508. }
  11509. } else {
  11510. result2 = null;
  11511. pos = pos1;
  11512. }
  11513. }
  11514. if (result1 !== null) {
  11515. result0 = [result0, result1];
  11516. } else {
  11517. result0 = null;
  11518. pos = pos0;
  11519. }
  11520. } else {
  11521. result0 = null;
  11522. pos = pos0;
  11523. }
  11524. return result0;
  11525. }
  11526. function parse_Subscription_State() {
  11527. var result0, result1, result2, result3;
  11528. var pos0, pos1;
  11529. pos0 = pos;
  11530. result0 = parse_substate_value();
  11531. if (result0 !== null) {
  11532. result1 = [];
  11533. pos1 = pos;
  11534. result2 = parse_SEMI();
  11535. if (result2 !== null) {
  11536. result3 = parse_subexp_params();
  11537. if (result3 !== null) {
  11538. result2 = [result2, result3];
  11539. } else {
  11540. result2 = null;
  11541. pos = pos1;
  11542. }
  11543. } else {
  11544. result2 = null;
  11545. pos = pos1;
  11546. }
  11547. while (result2 !== null) {
  11548. result1.push(result2);
  11549. pos1 = pos;
  11550. result2 = parse_SEMI();
  11551. if (result2 !== null) {
  11552. result3 = parse_subexp_params();
  11553. if (result3 !== null) {
  11554. result2 = [result2, result3];
  11555. } else {
  11556. result2 = null;
  11557. pos = pos1;
  11558. }
  11559. } else {
  11560. result2 = null;
  11561. pos = pos1;
  11562. }
  11563. }
  11564. if (result1 !== null) {
  11565. result0 = [result0, result1];
  11566. } else {
  11567. result0 = null;
  11568. pos = pos0;
  11569. }
  11570. } else {
  11571. result0 = null;
  11572. pos = pos0;
  11573. }
  11574. return result0;
  11575. }
  11576. function parse_substate_value() {
  11577. var result0;
  11578. var pos0;
  11579. pos0 = pos;
  11580. if (input.substr(pos, 6).toLowerCase() === "active") {
  11581. result0 = input.substr(pos, 6);
  11582. pos += 6;
  11583. } else {
  11584. result0 = null;
  11585. if (reportFailures === 0) {
  11586. matchFailed("\"active\"");
  11587. }
  11588. }
  11589. if (result0 === null) {
  11590. if (input.substr(pos, 7).toLowerCase() === "pending") {
  11591. result0 = input.substr(pos, 7);
  11592. pos += 7;
  11593. } else {
  11594. result0 = null;
  11595. if (reportFailures === 0) {
  11596. matchFailed("\"pending\"");
  11597. }
  11598. }
  11599. if (result0 === null) {
  11600. if (input.substr(pos, 10).toLowerCase() === "terminated") {
  11601. result0 = input.substr(pos, 10);
  11602. pos += 10;
  11603. } else {
  11604. result0 = null;
  11605. if (reportFailures === 0) {
  11606. matchFailed("\"terminated\"");
  11607. }
  11608. }
  11609. if (result0 === null) {
  11610. result0 = parse_token();
  11611. }
  11612. }
  11613. }
  11614. if (result0 !== null) {
  11615. result0 = function (offset) {
  11616. data.state = input.substring(pos, offset);
  11617. }(pos0);
  11618. }
  11619. if (result0 === null) {
  11620. pos = pos0;
  11621. }
  11622. return result0;
  11623. }
  11624. function parse_subexp_params() {
  11625. var result0, result1, result2;
  11626. var pos0, pos1;
  11627. pos0 = pos;
  11628. pos1 = pos;
  11629. if (input.substr(pos, 6).toLowerCase() === "reason") {
  11630. result0 = input.substr(pos, 6);
  11631. pos += 6;
  11632. } else {
  11633. result0 = null;
  11634. if (reportFailures === 0) {
  11635. matchFailed("\"reason\"");
  11636. }
  11637. }
  11638. if (result0 !== null) {
  11639. result1 = parse_EQUAL();
  11640. if (result1 !== null) {
  11641. result2 = parse_event_reason_value();
  11642. if (result2 !== null) {
  11643. result0 = [result0, result1, result2];
  11644. } else {
  11645. result0 = null;
  11646. pos = pos1;
  11647. }
  11648. } else {
  11649. result0 = null;
  11650. pos = pos1;
  11651. }
  11652. } else {
  11653. result0 = null;
  11654. pos = pos1;
  11655. }
  11656. if (result0 !== null) {
  11657. result0 = function (offset, reason) {
  11658. if (typeof reason !== 'undefined') data.reason = reason;
  11659. }(pos0, result0[2]);
  11660. }
  11661. if (result0 === null) {
  11662. pos = pos0;
  11663. }
  11664. if (result0 === null) {
  11665. pos0 = pos;
  11666. pos1 = pos;
  11667. if (input.substr(pos, 7).toLowerCase() === "expires") {
  11668. result0 = input.substr(pos, 7);
  11669. pos += 7;
  11670. } else {
  11671. result0 = null;
  11672. if (reportFailures === 0) {
  11673. matchFailed("\"expires\"");
  11674. }
  11675. }
  11676. if (result0 !== null) {
  11677. result1 = parse_EQUAL();
  11678. if (result1 !== null) {
  11679. result2 = parse_delta_seconds();
  11680. if (result2 !== null) {
  11681. result0 = [result0, result1, result2];
  11682. } else {
  11683. result0 = null;
  11684. pos = pos1;
  11685. }
  11686. } else {
  11687. result0 = null;
  11688. pos = pos1;
  11689. }
  11690. } else {
  11691. result0 = null;
  11692. pos = pos1;
  11693. }
  11694. if (result0 !== null) {
  11695. result0 = function (offset, expires) {
  11696. if (typeof expires !== 'undefined') data.expires = expires;
  11697. }(pos0, result0[2]);
  11698. }
  11699. if (result0 === null) {
  11700. pos = pos0;
  11701. }
  11702. if (result0 === null) {
  11703. pos0 = pos;
  11704. pos1 = pos;
  11705. if (input.substr(pos, 11).toLowerCase() === "retry_after") {
  11706. result0 = input.substr(pos, 11);
  11707. pos += 11;
  11708. } else {
  11709. result0 = null;
  11710. if (reportFailures === 0) {
  11711. matchFailed("\"retry_after\"");
  11712. }
  11713. }
  11714. if (result0 !== null) {
  11715. result1 = parse_EQUAL();
  11716. if (result1 !== null) {
  11717. result2 = parse_delta_seconds();
  11718. if (result2 !== null) {
  11719. result0 = [result0, result1, result2];
  11720. } else {
  11721. result0 = null;
  11722. pos = pos1;
  11723. }
  11724. } else {
  11725. result0 = null;
  11726. pos = pos1;
  11727. }
  11728. } else {
  11729. result0 = null;
  11730. pos = pos1;
  11731. }
  11732. if (result0 !== null) {
  11733. result0 = function (offset, retry_after) {
  11734. if (typeof retry_after !== 'undefined') data.retry_after = retry_after;
  11735. }(pos0, result0[2]);
  11736. }
  11737. if (result0 === null) {
  11738. pos = pos0;
  11739. }
  11740. if (result0 === null) {
  11741. result0 = parse_generic_param();
  11742. }
  11743. }
  11744. }
  11745. return result0;
  11746. }
  11747. function parse_event_reason_value() {
  11748. var result0;
  11749. if (input.substr(pos, 11).toLowerCase() === "deactivated") {
  11750. result0 = input.substr(pos, 11);
  11751. pos += 11;
  11752. } else {
  11753. result0 = null;
  11754. if (reportFailures === 0) {
  11755. matchFailed("\"deactivated\"");
  11756. }
  11757. }
  11758. if (result0 === null) {
  11759. if (input.substr(pos, 9).toLowerCase() === "probation") {
  11760. result0 = input.substr(pos, 9);
  11761. pos += 9;
  11762. } else {
  11763. result0 = null;
  11764. if (reportFailures === 0) {
  11765. matchFailed("\"probation\"");
  11766. }
  11767. }
  11768. if (result0 === null) {
  11769. if (input.substr(pos, 8).toLowerCase() === "rejected") {
  11770. result0 = input.substr(pos, 8);
  11771. pos += 8;
  11772. } else {
  11773. result0 = null;
  11774. if (reportFailures === 0) {
  11775. matchFailed("\"rejected\"");
  11776. }
  11777. }
  11778. if (result0 === null) {
  11779. if (input.substr(pos, 7).toLowerCase() === "timeout") {
  11780. result0 = input.substr(pos, 7);
  11781. pos += 7;
  11782. } else {
  11783. result0 = null;
  11784. if (reportFailures === 0) {
  11785. matchFailed("\"timeout\"");
  11786. }
  11787. }
  11788. if (result0 === null) {
  11789. if (input.substr(pos, 6).toLowerCase() === "giveup") {
  11790. result0 = input.substr(pos, 6);
  11791. pos += 6;
  11792. } else {
  11793. result0 = null;
  11794. if (reportFailures === 0) {
  11795. matchFailed("\"giveup\"");
  11796. }
  11797. }
  11798. if (result0 === null) {
  11799. if (input.substr(pos, 10).toLowerCase() === "noresource") {
  11800. result0 = input.substr(pos, 10);
  11801. pos += 10;
  11802. } else {
  11803. result0 = null;
  11804. if (reportFailures === 0) {
  11805. matchFailed("\"noresource\"");
  11806. }
  11807. }
  11808. if (result0 === null) {
  11809. if (input.substr(pos, 9).toLowerCase() === "invariant") {
  11810. result0 = input.substr(pos, 9);
  11811. pos += 9;
  11812. } else {
  11813. result0 = null;
  11814. if (reportFailures === 0) {
  11815. matchFailed("\"invariant\"");
  11816. }
  11817. }
  11818. if (result0 === null) {
  11819. result0 = parse_token();
  11820. }
  11821. }
  11822. }
  11823. }
  11824. }
  11825. }
  11826. }
  11827. return result0;
  11828. }
  11829. function parse_Subject() {
  11830. var result0;
  11831. result0 = parse_TEXT_UTF8_TRIM();
  11832. result0 = result0 !== null ? result0 : "";
  11833. return result0;
  11834. }
  11835. function parse_Supported() {
  11836. var result0, result1, result2, result3;
  11837. var pos0, pos1;
  11838. pos0 = pos;
  11839. result0 = parse_token();
  11840. if (result0 !== null) {
  11841. result1 = [];
  11842. pos1 = pos;
  11843. result2 = parse_COMMA();
  11844. if (result2 !== null) {
  11845. result3 = parse_token();
  11846. if (result3 !== null) {
  11847. result2 = [result2, result3];
  11848. } else {
  11849. result2 = null;
  11850. pos = pos1;
  11851. }
  11852. } else {
  11853. result2 = null;
  11854. pos = pos1;
  11855. }
  11856. while (result2 !== null) {
  11857. result1.push(result2);
  11858. pos1 = pos;
  11859. result2 = parse_COMMA();
  11860. if (result2 !== null) {
  11861. result3 = parse_token();
  11862. if (result3 !== null) {
  11863. result2 = [result2, result3];
  11864. } else {
  11865. result2 = null;
  11866. pos = pos1;
  11867. }
  11868. } else {
  11869. result2 = null;
  11870. pos = pos1;
  11871. }
  11872. }
  11873. if (result1 !== null) {
  11874. result0 = [result0, result1];
  11875. } else {
  11876. result0 = null;
  11877. pos = pos0;
  11878. }
  11879. } else {
  11880. result0 = null;
  11881. pos = pos0;
  11882. }
  11883. result0 = result0 !== null ? result0 : "";
  11884. return result0;
  11885. }
  11886. function parse_To() {
  11887. var result0, result1, result2, result3;
  11888. var pos0, pos1, pos2;
  11889. pos0 = pos;
  11890. pos1 = pos;
  11891. result0 = parse_SIP_URI_noparams();
  11892. if (result0 === null) {
  11893. result0 = parse_name_addr();
  11894. }
  11895. if (result0 !== null) {
  11896. result1 = [];
  11897. pos2 = pos;
  11898. result2 = parse_SEMI();
  11899. if (result2 !== null) {
  11900. result3 = parse_to_param();
  11901. if (result3 !== null) {
  11902. result2 = [result2, result3];
  11903. } else {
  11904. result2 = null;
  11905. pos = pos2;
  11906. }
  11907. } else {
  11908. result2 = null;
  11909. pos = pos2;
  11910. }
  11911. while (result2 !== null) {
  11912. result1.push(result2);
  11913. pos2 = pos;
  11914. result2 = parse_SEMI();
  11915. if (result2 !== null) {
  11916. result3 = parse_to_param();
  11917. if (result3 !== null) {
  11918. result2 = [result2, result3];
  11919. } else {
  11920. result2 = null;
  11921. pos = pos2;
  11922. }
  11923. } else {
  11924. result2 = null;
  11925. pos = pos2;
  11926. }
  11927. }
  11928. if (result1 !== null) {
  11929. result0 = [result0, result1];
  11930. } else {
  11931. result0 = null;
  11932. pos = pos1;
  11933. }
  11934. } else {
  11935. result0 = null;
  11936. pos = pos1;
  11937. }
  11938. if (result0 !== null) {
  11939. result0 = function (offset) {
  11940. var tag = data.tag;
  11941. try {
  11942. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  11943. if (tag) {
  11944. data.setParam('tag', tag);
  11945. }
  11946. } catch (e) {
  11947. data = -1;
  11948. }
  11949. }(pos0);
  11950. }
  11951. if (result0 === null) {
  11952. pos = pos0;
  11953. }
  11954. return result0;
  11955. }
  11956. function parse_to_param() {
  11957. var result0;
  11958. result0 = parse_tag_param();
  11959. if (result0 === null) {
  11960. result0 = parse_generic_param();
  11961. }
  11962. return result0;
  11963. }
  11964. function parse_Via() {
  11965. var result0, result1, result2, result3;
  11966. var pos0, pos1;
  11967. pos0 = pos;
  11968. result0 = parse_via_param();
  11969. if (result0 !== null) {
  11970. result1 = [];
  11971. pos1 = pos;
  11972. result2 = parse_COMMA();
  11973. if (result2 !== null) {
  11974. result3 = parse_via_param();
  11975. if (result3 !== null) {
  11976. result2 = [result2, result3];
  11977. } else {
  11978. result2 = null;
  11979. pos = pos1;
  11980. }
  11981. } else {
  11982. result2 = null;
  11983. pos = pos1;
  11984. }
  11985. while (result2 !== null) {
  11986. result1.push(result2);
  11987. pos1 = pos;
  11988. result2 = parse_COMMA();
  11989. if (result2 !== null) {
  11990. result3 = parse_via_param();
  11991. if (result3 !== null) {
  11992. result2 = [result2, result3];
  11993. } else {
  11994. result2 = null;
  11995. pos = pos1;
  11996. }
  11997. } else {
  11998. result2 = null;
  11999. pos = pos1;
  12000. }
  12001. }
  12002. if (result1 !== null) {
  12003. result0 = [result0, result1];
  12004. } else {
  12005. result0 = null;
  12006. pos = pos0;
  12007. }
  12008. } else {
  12009. result0 = null;
  12010. pos = pos0;
  12011. }
  12012. return result0;
  12013. }
  12014. function parse_via_param() {
  12015. var result0, result1, result2, result3, result4, result5;
  12016. var pos0, pos1;
  12017. pos0 = pos;
  12018. result0 = parse_sent_protocol();
  12019. if (result0 !== null) {
  12020. result1 = parse_LWS();
  12021. if (result1 !== null) {
  12022. result2 = parse_sent_by();
  12023. if (result2 !== null) {
  12024. result3 = [];
  12025. pos1 = pos;
  12026. result4 = parse_SEMI();
  12027. if (result4 !== null) {
  12028. result5 = parse_via_params();
  12029. if (result5 !== null) {
  12030. result4 = [result4, result5];
  12031. } else {
  12032. result4 = null;
  12033. pos = pos1;
  12034. }
  12035. } else {
  12036. result4 = null;
  12037. pos = pos1;
  12038. }
  12039. while (result4 !== null) {
  12040. result3.push(result4);
  12041. pos1 = pos;
  12042. result4 = parse_SEMI();
  12043. if (result4 !== null) {
  12044. result5 = parse_via_params();
  12045. if (result5 !== null) {
  12046. result4 = [result4, result5];
  12047. } else {
  12048. result4 = null;
  12049. pos = pos1;
  12050. }
  12051. } else {
  12052. result4 = null;
  12053. pos = pos1;
  12054. }
  12055. }
  12056. if (result3 !== null) {
  12057. result0 = [result0, result1, result2, result3];
  12058. } else {
  12059. result0 = null;
  12060. pos = pos0;
  12061. }
  12062. } else {
  12063. result0 = null;
  12064. pos = pos0;
  12065. }
  12066. } else {
  12067. result0 = null;
  12068. pos = pos0;
  12069. }
  12070. } else {
  12071. result0 = null;
  12072. pos = pos0;
  12073. }
  12074. return result0;
  12075. }
  12076. function parse_via_params() {
  12077. var result0;
  12078. result0 = parse_via_ttl();
  12079. if (result0 === null) {
  12080. result0 = parse_via_maddr();
  12081. if (result0 === null) {
  12082. result0 = parse_via_received();
  12083. if (result0 === null) {
  12084. result0 = parse_via_branch();
  12085. if (result0 === null) {
  12086. result0 = parse_response_port();
  12087. if (result0 === null) {
  12088. result0 = parse_generic_param();
  12089. }
  12090. }
  12091. }
  12092. }
  12093. }
  12094. return result0;
  12095. }
  12096. function parse_via_ttl() {
  12097. var result0, result1, result2;
  12098. var pos0, pos1;
  12099. pos0 = pos;
  12100. pos1 = pos;
  12101. if (input.substr(pos, 3).toLowerCase() === "ttl") {
  12102. result0 = input.substr(pos, 3);
  12103. pos += 3;
  12104. } else {
  12105. result0 = null;
  12106. if (reportFailures === 0) {
  12107. matchFailed("\"ttl\"");
  12108. }
  12109. }
  12110. if (result0 !== null) {
  12111. result1 = parse_EQUAL();
  12112. if (result1 !== null) {
  12113. result2 = parse_ttl();
  12114. if (result2 !== null) {
  12115. result0 = [result0, result1, result2];
  12116. } else {
  12117. result0 = null;
  12118. pos = pos1;
  12119. }
  12120. } else {
  12121. result0 = null;
  12122. pos = pos1;
  12123. }
  12124. } else {
  12125. result0 = null;
  12126. pos = pos1;
  12127. }
  12128. if (result0 !== null) {
  12129. result0 = function (offset, via_ttl_value) {
  12130. data.ttl = via_ttl_value;
  12131. }(pos0, result0[2]);
  12132. }
  12133. if (result0 === null) {
  12134. pos = pos0;
  12135. }
  12136. return result0;
  12137. }
  12138. function parse_via_maddr() {
  12139. var result0, result1, result2;
  12140. var pos0, pos1;
  12141. pos0 = pos;
  12142. pos1 = pos;
  12143. if (input.substr(pos, 5).toLowerCase() === "maddr") {
  12144. result0 = input.substr(pos, 5);
  12145. pos += 5;
  12146. } else {
  12147. result0 = null;
  12148. if (reportFailures === 0) {
  12149. matchFailed("\"maddr\"");
  12150. }
  12151. }
  12152. if (result0 !== null) {
  12153. result1 = parse_EQUAL();
  12154. if (result1 !== null) {
  12155. result2 = parse_host();
  12156. if (result2 !== null) {
  12157. result0 = [result0, result1, result2];
  12158. } else {
  12159. result0 = null;
  12160. pos = pos1;
  12161. }
  12162. } else {
  12163. result0 = null;
  12164. pos = pos1;
  12165. }
  12166. } else {
  12167. result0 = null;
  12168. pos = pos1;
  12169. }
  12170. if (result0 !== null) {
  12171. result0 = function (offset, via_maddr) {
  12172. data.maddr = via_maddr;
  12173. }(pos0, result0[2]);
  12174. }
  12175. if (result0 === null) {
  12176. pos = pos0;
  12177. }
  12178. return result0;
  12179. }
  12180. function parse_via_received() {
  12181. var result0, result1, result2;
  12182. var pos0, pos1;
  12183. pos0 = pos;
  12184. pos1 = pos;
  12185. if (input.substr(pos, 8).toLowerCase() === "received") {
  12186. result0 = input.substr(pos, 8);
  12187. pos += 8;
  12188. } else {
  12189. result0 = null;
  12190. if (reportFailures === 0) {
  12191. matchFailed("\"received\"");
  12192. }
  12193. }
  12194. if (result0 !== null) {
  12195. result1 = parse_EQUAL();
  12196. if (result1 !== null) {
  12197. result2 = parse_IPv4address();
  12198. if (result2 === null) {
  12199. result2 = parse_IPv6address();
  12200. }
  12201. if (result2 !== null) {
  12202. result0 = [result0, result1, result2];
  12203. } else {
  12204. result0 = null;
  12205. pos = pos1;
  12206. }
  12207. } else {
  12208. result0 = null;
  12209. pos = pos1;
  12210. }
  12211. } else {
  12212. result0 = null;
  12213. pos = pos1;
  12214. }
  12215. if (result0 !== null) {
  12216. result0 = function (offset, via_received) {
  12217. data.received = via_received;
  12218. }(pos0, result0[2]);
  12219. }
  12220. if (result0 === null) {
  12221. pos = pos0;
  12222. }
  12223. return result0;
  12224. }
  12225. function parse_via_branch() {
  12226. var result0, result1, result2;
  12227. var pos0, pos1;
  12228. pos0 = pos;
  12229. pos1 = pos;
  12230. if (input.substr(pos, 6).toLowerCase() === "branch") {
  12231. result0 = input.substr(pos, 6);
  12232. pos += 6;
  12233. } else {
  12234. result0 = null;
  12235. if (reportFailures === 0) {
  12236. matchFailed("\"branch\"");
  12237. }
  12238. }
  12239. if (result0 !== null) {
  12240. result1 = parse_EQUAL();
  12241. if (result1 !== null) {
  12242. result2 = parse_token();
  12243. if (result2 !== null) {
  12244. result0 = [result0, result1, result2];
  12245. } else {
  12246. result0 = null;
  12247. pos = pos1;
  12248. }
  12249. } else {
  12250. result0 = null;
  12251. pos = pos1;
  12252. }
  12253. } else {
  12254. result0 = null;
  12255. pos = pos1;
  12256. }
  12257. if (result0 !== null) {
  12258. result0 = function (offset, via_branch) {
  12259. data.branch = via_branch;
  12260. }(pos0, result0[2]);
  12261. }
  12262. if (result0 === null) {
  12263. pos = pos0;
  12264. }
  12265. return result0;
  12266. }
  12267. function parse_response_port() {
  12268. var result0, result1, result2, result3;
  12269. var pos0, pos1, pos2;
  12270. pos0 = pos;
  12271. pos1 = pos;
  12272. if (input.substr(pos, 5).toLowerCase() === "rport") {
  12273. result0 = input.substr(pos, 5);
  12274. pos += 5;
  12275. } else {
  12276. result0 = null;
  12277. if (reportFailures === 0) {
  12278. matchFailed("\"rport\"");
  12279. }
  12280. }
  12281. if (result0 !== null) {
  12282. pos2 = pos;
  12283. result1 = parse_EQUAL();
  12284. if (result1 !== null) {
  12285. result2 = [];
  12286. result3 = parse_DIGIT();
  12287. while (result3 !== null) {
  12288. result2.push(result3);
  12289. result3 = parse_DIGIT();
  12290. }
  12291. if (result2 !== null) {
  12292. result1 = [result1, result2];
  12293. } else {
  12294. result1 = null;
  12295. pos = pos2;
  12296. }
  12297. } else {
  12298. result1 = null;
  12299. pos = pos2;
  12300. }
  12301. result1 = result1 !== null ? result1 : "";
  12302. if (result1 !== null) {
  12303. result0 = [result0, result1];
  12304. } else {
  12305. result0 = null;
  12306. pos = pos1;
  12307. }
  12308. } else {
  12309. result0 = null;
  12310. pos = pos1;
  12311. }
  12312. if (result0 !== null) {
  12313. result0 = function (offset) {
  12314. if (typeof response_port !== 'undefined') data.rport = response_port.join('');
  12315. }(pos0);
  12316. }
  12317. if (result0 === null) {
  12318. pos = pos0;
  12319. }
  12320. return result0;
  12321. }
  12322. function parse_sent_protocol() {
  12323. var result0, result1, result2, result3, result4;
  12324. var pos0;
  12325. pos0 = pos;
  12326. result0 = parse_protocol_name();
  12327. if (result0 !== null) {
  12328. result1 = parse_SLASH();
  12329. if (result1 !== null) {
  12330. result2 = parse_token();
  12331. if (result2 !== null) {
  12332. result3 = parse_SLASH();
  12333. if (result3 !== null) {
  12334. result4 = parse_transport();
  12335. if (result4 !== null) {
  12336. result0 = [result0, result1, result2, result3, result4];
  12337. } else {
  12338. result0 = null;
  12339. pos = pos0;
  12340. }
  12341. } else {
  12342. result0 = null;
  12343. pos = pos0;
  12344. }
  12345. } else {
  12346. result0 = null;
  12347. pos = pos0;
  12348. }
  12349. } else {
  12350. result0 = null;
  12351. pos = pos0;
  12352. }
  12353. } else {
  12354. result0 = null;
  12355. pos = pos0;
  12356. }
  12357. return result0;
  12358. }
  12359. function parse_protocol_name() {
  12360. var result0;
  12361. var pos0;
  12362. pos0 = pos;
  12363. if (input.substr(pos, 3).toLowerCase() === "sip") {
  12364. result0 = input.substr(pos, 3);
  12365. pos += 3;
  12366. } else {
  12367. result0 = null;
  12368. if (reportFailures === 0) {
  12369. matchFailed("\"SIP\"");
  12370. }
  12371. }
  12372. if (result0 === null) {
  12373. result0 = parse_token();
  12374. }
  12375. if (result0 !== null) {
  12376. result0 = function (offset, via_protocol) {
  12377. data.protocol = via_protocol;
  12378. }(pos0, result0);
  12379. }
  12380. if (result0 === null) {
  12381. pos = pos0;
  12382. }
  12383. return result0;
  12384. }
  12385. function parse_transport() {
  12386. var result0;
  12387. var pos0;
  12388. pos0 = pos;
  12389. if (input.substr(pos, 3).toLowerCase() === "udp") {
  12390. result0 = input.substr(pos, 3);
  12391. pos += 3;
  12392. } else {
  12393. result0 = null;
  12394. if (reportFailures === 0) {
  12395. matchFailed("\"UDP\"");
  12396. }
  12397. }
  12398. if (result0 === null) {
  12399. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  12400. result0 = input.substr(pos, 3);
  12401. pos += 3;
  12402. } else {
  12403. result0 = null;
  12404. if (reportFailures === 0) {
  12405. matchFailed("\"TCP\"");
  12406. }
  12407. }
  12408. if (result0 === null) {
  12409. if (input.substr(pos, 3).toLowerCase() === "tls") {
  12410. result0 = input.substr(pos, 3);
  12411. pos += 3;
  12412. } else {
  12413. result0 = null;
  12414. if (reportFailures === 0) {
  12415. matchFailed("\"TLS\"");
  12416. }
  12417. }
  12418. if (result0 === null) {
  12419. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  12420. result0 = input.substr(pos, 4);
  12421. pos += 4;
  12422. } else {
  12423. result0 = null;
  12424. if (reportFailures === 0) {
  12425. matchFailed("\"SCTP\"");
  12426. }
  12427. }
  12428. if (result0 === null) {
  12429. result0 = parse_token();
  12430. }
  12431. }
  12432. }
  12433. }
  12434. if (result0 !== null) {
  12435. result0 = function (offset, via_transport) {
  12436. data.transport = via_transport;
  12437. }(pos0, result0);
  12438. }
  12439. if (result0 === null) {
  12440. pos = pos0;
  12441. }
  12442. return result0;
  12443. }
  12444. function parse_sent_by() {
  12445. var result0, result1, result2;
  12446. var pos0, pos1;
  12447. pos0 = pos;
  12448. result0 = parse_via_host();
  12449. if (result0 !== null) {
  12450. pos1 = pos;
  12451. result1 = parse_COLON();
  12452. if (result1 !== null) {
  12453. result2 = parse_via_port();
  12454. if (result2 !== null) {
  12455. result1 = [result1, result2];
  12456. } else {
  12457. result1 = null;
  12458. pos = pos1;
  12459. }
  12460. } else {
  12461. result1 = null;
  12462. pos = pos1;
  12463. }
  12464. result1 = result1 !== null ? result1 : "";
  12465. if (result1 !== null) {
  12466. result0 = [result0, result1];
  12467. } else {
  12468. result0 = null;
  12469. pos = pos0;
  12470. }
  12471. } else {
  12472. result0 = null;
  12473. pos = pos0;
  12474. }
  12475. return result0;
  12476. }
  12477. function parse_via_host() {
  12478. var result0;
  12479. var pos0;
  12480. pos0 = pos;
  12481. result0 = parse_IPv4address();
  12482. if (result0 === null) {
  12483. result0 = parse_IPv6reference();
  12484. if (result0 === null) {
  12485. result0 = parse_hostname();
  12486. }
  12487. }
  12488. if (result0 !== null) {
  12489. result0 = function (offset) {
  12490. data.host = input.substring(pos, offset);
  12491. }(pos0);
  12492. }
  12493. if (result0 === null) {
  12494. pos = pos0;
  12495. }
  12496. return result0;
  12497. }
  12498. function parse_via_port() {
  12499. var result0, result1, result2, result3, result4;
  12500. var pos0, pos1;
  12501. pos0 = pos;
  12502. pos1 = pos;
  12503. result0 = parse_DIGIT();
  12504. result0 = result0 !== null ? result0 : "";
  12505. if (result0 !== null) {
  12506. result1 = parse_DIGIT();
  12507. result1 = result1 !== null ? result1 : "";
  12508. if (result1 !== null) {
  12509. result2 = parse_DIGIT();
  12510. result2 = result2 !== null ? result2 : "";
  12511. if (result2 !== null) {
  12512. result3 = parse_DIGIT();
  12513. result3 = result3 !== null ? result3 : "";
  12514. if (result3 !== null) {
  12515. result4 = parse_DIGIT();
  12516. result4 = result4 !== null ? result4 : "";
  12517. if (result4 !== null) {
  12518. result0 = [result0, result1, result2, result3, result4];
  12519. } else {
  12520. result0 = null;
  12521. pos = pos1;
  12522. }
  12523. } else {
  12524. result0 = null;
  12525. pos = pos1;
  12526. }
  12527. } else {
  12528. result0 = null;
  12529. pos = pos1;
  12530. }
  12531. } else {
  12532. result0 = null;
  12533. pos = pos1;
  12534. }
  12535. } else {
  12536. result0 = null;
  12537. pos = pos1;
  12538. }
  12539. if (result0 !== null) {
  12540. result0 = function (offset, via_sent_by_port) {
  12541. data.port = parseInt(via_sent_by_port.join(''));
  12542. }(pos0, result0);
  12543. }
  12544. if (result0 === null) {
  12545. pos = pos0;
  12546. }
  12547. return result0;
  12548. }
  12549. function parse_ttl() {
  12550. var result0, result1, result2;
  12551. var pos0, pos1;
  12552. pos0 = pos;
  12553. pos1 = pos;
  12554. result0 = parse_DIGIT();
  12555. if (result0 !== null) {
  12556. result1 = parse_DIGIT();
  12557. result1 = result1 !== null ? result1 : "";
  12558. if (result1 !== null) {
  12559. result2 = parse_DIGIT();
  12560. result2 = result2 !== null ? result2 : "";
  12561. if (result2 !== null) {
  12562. result0 = [result0, result1, result2];
  12563. } else {
  12564. result0 = null;
  12565. pos = pos1;
  12566. }
  12567. } else {
  12568. result0 = null;
  12569. pos = pos1;
  12570. }
  12571. } else {
  12572. result0 = null;
  12573. pos = pos1;
  12574. }
  12575. if (result0 !== null) {
  12576. result0 = function (offset, ttl) {
  12577. return parseInt(ttl.join(''));
  12578. }(pos0, result0);
  12579. }
  12580. if (result0 === null) {
  12581. pos = pos0;
  12582. }
  12583. return result0;
  12584. }
  12585. function parse_WWW_Authenticate() {
  12586. var result0;
  12587. result0 = parse_challenge();
  12588. return result0;
  12589. }
  12590. function parse_Session_Expires() {
  12591. var result0, result1, result2, result3;
  12592. var pos0, pos1;
  12593. pos0 = pos;
  12594. result0 = parse_s_e_expires();
  12595. if (result0 !== null) {
  12596. result1 = [];
  12597. pos1 = pos;
  12598. result2 = parse_SEMI();
  12599. if (result2 !== null) {
  12600. result3 = parse_s_e_params();
  12601. if (result3 !== null) {
  12602. result2 = [result2, result3];
  12603. } else {
  12604. result2 = null;
  12605. pos = pos1;
  12606. }
  12607. } else {
  12608. result2 = null;
  12609. pos = pos1;
  12610. }
  12611. while (result2 !== null) {
  12612. result1.push(result2);
  12613. pos1 = pos;
  12614. result2 = parse_SEMI();
  12615. if (result2 !== null) {
  12616. result3 = parse_s_e_params();
  12617. if (result3 !== null) {
  12618. result2 = [result2, result3];
  12619. } else {
  12620. result2 = null;
  12621. pos = pos1;
  12622. }
  12623. } else {
  12624. result2 = null;
  12625. pos = pos1;
  12626. }
  12627. }
  12628. if (result1 !== null) {
  12629. result0 = [result0, result1];
  12630. } else {
  12631. result0 = null;
  12632. pos = pos0;
  12633. }
  12634. } else {
  12635. result0 = null;
  12636. pos = pos0;
  12637. }
  12638. return result0;
  12639. }
  12640. function parse_s_e_expires() {
  12641. var result0;
  12642. var pos0;
  12643. pos0 = pos;
  12644. result0 = parse_delta_seconds();
  12645. if (result0 !== null) {
  12646. result0 = function (offset, expires) {
  12647. data.expires = expires;
  12648. }(pos0, result0);
  12649. }
  12650. if (result0 === null) {
  12651. pos = pos0;
  12652. }
  12653. return result0;
  12654. }
  12655. function parse_s_e_params() {
  12656. var result0;
  12657. result0 = parse_s_e_refresher();
  12658. if (result0 === null) {
  12659. result0 = parse_generic_param();
  12660. }
  12661. return result0;
  12662. }
  12663. function parse_s_e_refresher() {
  12664. var result0, result1, result2;
  12665. var pos0, pos1;
  12666. pos0 = pos;
  12667. pos1 = pos;
  12668. if (input.substr(pos, 9).toLowerCase() === "refresher") {
  12669. result0 = input.substr(pos, 9);
  12670. pos += 9;
  12671. } else {
  12672. result0 = null;
  12673. if (reportFailures === 0) {
  12674. matchFailed("\"refresher\"");
  12675. }
  12676. }
  12677. if (result0 !== null) {
  12678. result1 = parse_EQUAL();
  12679. if (result1 !== null) {
  12680. if (input.substr(pos, 3).toLowerCase() === "uac") {
  12681. result2 = input.substr(pos, 3);
  12682. pos += 3;
  12683. } else {
  12684. result2 = null;
  12685. if (reportFailures === 0) {
  12686. matchFailed("\"uac\"");
  12687. }
  12688. }
  12689. if (result2 === null) {
  12690. if (input.substr(pos, 3).toLowerCase() === "uas") {
  12691. result2 = input.substr(pos, 3);
  12692. pos += 3;
  12693. } else {
  12694. result2 = null;
  12695. if (reportFailures === 0) {
  12696. matchFailed("\"uas\"");
  12697. }
  12698. }
  12699. }
  12700. if (result2 !== null) {
  12701. result0 = [result0, result1, result2];
  12702. } else {
  12703. result0 = null;
  12704. pos = pos1;
  12705. }
  12706. } else {
  12707. result0 = null;
  12708. pos = pos1;
  12709. }
  12710. } else {
  12711. result0 = null;
  12712. pos = pos1;
  12713. }
  12714. if (result0 !== null) {
  12715. result0 = function (offset, s_e_refresher_value) {
  12716. data.refresher = s_e_refresher_value.toLowerCase();
  12717. }(pos0, result0[2]);
  12718. }
  12719. if (result0 === null) {
  12720. pos = pos0;
  12721. }
  12722. return result0;
  12723. }
  12724. function parse_extension_header() {
  12725. var result0, result1, result2;
  12726. var pos0;
  12727. pos0 = pos;
  12728. result0 = parse_token();
  12729. if (result0 !== null) {
  12730. result1 = parse_HCOLON();
  12731. if (result1 !== null) {
  12732. result2 = parse_header_value();
  12733. if (result2 !== null) {
  12734. result0 = [result0, result1, result2];
  12735. } else {
  12736. result0 = null;
  12737. pos = pos0;
  12738. }
  12739. } else {
  12740. result0 = null;
  12741. pos = pos0;
  12742. }
  12743. } else {
  12744. result0 = null;
  12745. pos = pos0;
  12746. }
  12747. return result0;
  12748. }
  12749. function parse_header_value() {
  12750. var result0, result1;
  12751. result0 = [];
  12752. result1 = parse_TEXT_UTF8char();
  12753. if (result1 === null) {
  12754. result1 = parse_UTF8_CONT();
  12755. if (result1 === null) {
  12756. result1 = parse_LWS();
  12757. }
  12758. }
  12759. while (result1 !== null) {
  12760. result0.push(result1);
  12761. result1 = parse_TEXT_UTF8char();
  12762. if (result1 === null) {
  12763. result1 = parse_UTF8_CONT();
  12764. if (result1 === null) {
  12765. result1 = parse_LWS();
  12766. }
  12767. }
  12768. }
  12769. return result0;
  12770. }
  12771. function parse_message_body() {
  12772. var result0, result1;
  12773. result0 = [];
  12774. result1 = parse_OCTET();
  12775. while (result1 !== null) {
  12776. result0.push(result1);
  12777. result1 = parse_OCTET();
  12778. }
  12779. return result0;
  12780. }
  12781. function parse_uuid_URI() {
  12782. var result0, result1;
  12783. var pos0;
  12784. pos0 = pos;
  12785. if (input.substr(pos, 5) === "uuid:") {
  12786. result0 = "uuid:";
  12787. pos += 5;
  12788. } else {
  12789. result0 = null;
  12790. if (reportFailures === 0) {
  12791. matchFailed("\"uuid:\"");
  12792. }
  12793. }
  12794. if (result0 !== null) {
  12795. result1 = parse_uuid();
  12796. if (result1 !== null) {
  12797. result0 = [result0, result1];
  12798. } else {
  12799. result0 = null;
  12800. pos = pos0;
  12801. }
  12802. } else {
  12803. result0 = null;
  12804. pos = pos0;
  12805. }
  12806. return result0;
  12807. }
  12808. function parse_uuid() {
  12809. var result0, result1, result2, result3, result4, result5, result6, result7, result8;
  12810. var pos0, pos1;
  12811. pos0 = pos;
  12812. pos1 = pos;
  12813. result0 = parse_hex8();
  12814. if (result0 !== null) {
  12815. if (input.charCodeAt(pos) === 45) {
  12816. result1 = "-";
  12817. pos++;
  12818. } else {
  12819. result1 = null;
  12820. if (reportFailures === 0) {
  12821. matchFailed("\"-\"");
  12822. }
  12823. }
  12824. if (result1 !== null) {
  12825. result2 = parse_hex4();
  12826. if (result2 !== null) {
  12827. if (input.charCodeAt(pos) === 45) {
  12828. result3 = "-";
  12829. pos++;
  12830. } else {
  12831. result3 = null;
  12832. if (reportFailures === 0) {
  12833. matchFailed("\"-\"");
  12834. }
  12835. }
  12836. if (result3 !== null) {
  12837. result4 = parse_hex4();
  12838. if (result4 !== null) {
  12839. if (input.charCodeAt(pos) === 45) {
  12840. result5 = "-";
  12841. pos++;
  12842. } else {
  12843. result5 = null;
  12844. if (reportFailures === 0) {
  12845. matchFailed("\"-\"");
  12846. }
  12847. }
  12848. if (result5 !== null) {
  12849. result6 = parse_hex4();
  12850. if (result6 !== null) {
  12851. if (input.charCodeAt(pos) === 45) {
  12852. result7 = "-";
  12853. pos++;
  12854. } else {
  12855. result7 = null;
  12856. if (reportFailures === 0) {
  12857. matchFailed("\"-\"");
  12858. }
  12859. }
  12860. if (result7 !== null) {
  12861. result8 = parse_hex12();
  12862. if (result8 !== null) {
  12863. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  12864. } else {
  12865. result0 = null;
  12866. pos = pos1;
  12867. }
  12868. } else {
  12869. result0 = null;
  12870. pos = pos1;
  12871. }
  12872. } else {
  12873. result0 = null;
  12874. pos = pos1;
  12875. }
  12876. } else {
  12877. result0 = null;
  12878. pos = pos1;
  12879. }
  12880. } else {
  12881. result0 = null;
  12882. pos = pos1;
  12883. }
  12884. } else {
  12885. result0 = null;
  12886. pos = pos1;
  12887. }
  12888. } else {
  12889. result0 = null;
  12890. pos = pos1;
  12891. }
  12892. } else {
  12893. result0 = null;
  12894. pos = pos1;
  12895. }
  12896. } else {
  12897. result0 = null;
  12898. pos = pos1;
  12899. }
  12900. if (result0 !== null) {
  12901. result0 = function (offset, uuid) {
  12902. data = input.substring(pos + 5, offset);
  12903. }(pos0, result0[0]);
  12904. }
  12905. if (result0 === null) {
  12906. pos = pos0;
  12907. }
  12908. return result0;
  12909. }
  12910. function parse_hex4() {
  12911. var result0, result1, result2, result3;
  12912. var pos0;
  12913. pos0 = pos;
  12914. result0 = parse_HEXDIG();
  12915. if (result0 !== null) {
  12916. result1 = parse_HEXDIG();
  12917. if (result1 !== null) {
  12918. result2 = parse_HEXDIG();
  12919. if (result2 !== null) {
  12920. result3 = parse_HEXDIG();
  12921. if (result3 !== null) {
  12922. result0 = [result0, result1, result2, result3];
  12923. } else {
  12924. result0 = null;
  12925. pos = pos0;
  12926. }
  12927. } else {
  12928. result0 = null;
  12929. pos = pos0;
  12930. }
  12931. } else {
  12932. result0 = null;
  12933. pos = pos0;
  12934. }
  12935. } else {
  12936. result0 = null;
  12937. pos = pos0;
  12938. }
  12939. return result0;
  12940. }
  12941. function parse_hex8() {
  12942. var result0, result1;
  12943. var pos0;
  12944. pos0 = pos;
  12945. result0 = parse_hex4();
  12946. if (result0 !== null) {
  12947. result1 = parse_hex4();
  12948. if (result1 !== null) {
  12949. result0 = [result0, result1];
  12950. } else {
  12951. result0 = null;
  12952. pos = pos0;
  12953. }
  12954. } else {
  12955. result0 = null;
  12956. pos = pos0;
  12957. }
  12958. return result0;
  12959. }
  12960. function parse_hex12() {
  12961. var result0, result1, result2;
  12962. var pos0;
  12963. pos0 = pos;
  12964. result0 = parse_hex4();
  12965. if (result0 !== null) {
  12966. result1 = parse_hex4();
  12967. if (result1 !== null) {
  12968. result2 = parse_hex4();
  12969. if (result2 !== null) {
  12970. result0 = [result0, result1, result2];
  12971. } else {
  12972. result0 = null;
  12973. pos = pos0;
  12974. }
  12975. } else {
  12976. result0 = null;
  12977. pos = pos0;
  12978. }
  12979. } else {
  12980. result0 = null;
  12981. pos = pos0;
  12982. }
  12983. return result0;
  12984. }
  12985. function parse_Refer_To() {
  12986. var result0, result1, result2, result3;
  12987. var pos0, pos1, pos2;
  12988. pos0 = pos;
  12989. pos1 = pos;
  12990. result0 = parse_SIP_URI_noparams();
  12991. if (result0 === null) {
  12992. result0 = parse_name_addr();
  12993. }
  12994. if (result0 !== null) {
  12995. result1 = [];
  12996. pos2 = pos;
  12997. result2 = parse_SEMI();
  12998. if (result2 !== null) {
  12999. result3 = parse_generic_param();
  13000. if (result3 !== null) {
  13001. result2 = [result2, result3];
  13002. } else {
  13003. result2 = null;
  13004. pos = pos2;
  13005. }
  13006. } else {
  13007. result2 = null;
  13008. pos = pos2;
  13009. }
  13010. while (result2 !== null) {
  13011. result1.push(result2);
  13012. pos2 = pos;
  13013. result2 = parse_SEMI();
  13014. if (result2 !== null) {
  13015. result3 = parse_generic_param();
  13016. if (result3 !== null) {
  13017. result2 = [result2, result3];
  13018. } else {
  13019. result2 = null;
  13020. pos = pos2;
  13021. }
  13022. } else {
  13023. result2 = null;
  13024. pos = pos2;
  13025. }
  13026. }
  13027. if (result1 !== null) {
  13028. result0 = [result0, result1];
  13029. } else {
  13030. result0 = null;
  13031. pos = pos1;
  13032. }
  13033. } else {
  13034. result0 = null;
  13035. pos = pos1;
  13036. }
  13037. if (result0 !== null) {
  13038. result0 = function (offset) {
  13039. try {
  13040. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  13041. } catch (e) {
  13042. data = -1;
  13043. }
  13044. }(pos0);
  13045. }
  13046. if (result0 === null) {
  13047. pos = pos0;
  13048. }
  13049. return result0;
  13050. }
  13051. function parse_Replaces() {
  13052. var result0, result1, result2, result3;
  13053. var pos0, pos1;
  13054. pos0 = pos;
  13055. result0 = parse_call_id();
  13056. if (result0 !== null) {
  13057. result1 = [];
  13058. pos1 = pos;
  13059. result2 = parse_SEMI();
  13060. if (result2 !== null) {
  13061. result3 = parse_replaces_param();
  13062. if (result3 !== null) {
  13063. result2 = [result2, result3];
  13064. } else {
  13065. result2 = null;
  13066. pos = pos1;
  13067. }
  13068. } else {
  13069. result2 = null;
  13070. pos = pos1;
  13071. }
  13072. while (result2 !== null) {
  13073. result1.push(result2);
  13074. pos1 = pos;
  13075. result2 = parse_SEMI();
  13076. if (result2 !== null) {
  13077. result3 = parse_replaces_param();
  13078. if (result3 !== null) {
  13079. result2 = [result2, result3];
  13080. } else {
  13081. result2 = null;
  13082. pos = pos1;
  13083. }
  13084. } else {
  13085. result2 = null;
  13086. pos = pos1;
  13087. }
  13088. }
  13089. if (result1 !== null) {
  13090. result0 = [result0, result1];
  13091. } else {
  13092. result0 = null;
  13093. pos = pos0;
  13094. }
  13095. } else {
  13096. result0 = null;
  13097. pos = pos0;
  13098. }
  13099. return result0;
  13100. }
  13101. function parse_call_id() {
  13102. var result0, result1, result2;
  13103. var pos0, pos1, pos2;
  13104. pos0 = pos;
  13105. pos1 = pos;
  13106. result0 = parse_word();
  13107. if (result0 !== null) {
  13108. pos2 = pos;
  13109. if (input.charCodeAt(pos) === 64) {
  13110. result1 = "@";
  13111. pos++;
  13112. } else {
  13113. result1 = null;
  13114. if (reportFailures === 0) {
  13115. matchFailed("\"@\"");
  13116. }
  13117. }
  13118. if (result1 !== null) {
  13119. result2 = parse_word();
  13120. if (result2 !== null) {
  13121. result1 = [result1, result2];
  13122. } else {
  13123. result1 = null;
  13124. pos = pos2;
  13125. }
  13126. } else {
  13127. result1 = null;
  13128. pos = pos2;
  13129. }
  13130. result1 = result1 !== null ? result1 : "";
  13131. if (result1 !== null) {
  13132. result0 = [result0, result1];
  13133. } else {
  13134. result0 = null;
  13135. pos = pos1;
  13136. }
  13137. } else {
  13138. result0 = null;
  13139. pos = pos1;
  13140. }
  13141. if (result0 !== null) {
  13142. result0 = function (offset) {
  13143. data.call_id = input.substring(pos, offset);
  13144. }(pos0);
  13145. }
  13146. if (result0 === null) {
  13147. pos = pos0;
  13148. }
  13149. return result0;
  13150. }
  13151. function parse_replaces_param() {
  13152. var result0;
  13153. result0 = parse_to_tag();
  13154. if (result0 === null) {
  13155. result0 = parse_from_tag();
  13156. if (result0 === null) {
  13157. result0 = parse_early_flag();
  13158. if (result0 === null) {
  13159. result0 = parse_generic_param();
  13160. }
  13161. }
  13162. }
  13163. return result0;
  13164. }
  13165. function parse_to_tag() {
  13166. var result0, result1, result2;
  13167. var pos0, pos1;
  13168. pos0 = pos;
  13169. pos1 = pos;
  13170. if (input.substr(pos, 6) === "to-tag") {
  13171. result0 = "to-tag";
  13172. pos += 6;
  13173. } else {
  13174. result0 = null;
  13175. if (reportFailures === 0) {
  13176. matchFailed("\"to-tag\"");
  13177. }
  13178. }
  13179. if (result0 !== null) {
  13180. result1 = parse_EQUAL();
  13181. if (result1 !== null) {
  13182. result2 = parse_token();
  13183. if (result2 !== null) {
  13184. result0 = [result0, result1, result2];
  13185. } else {
  13186. result0 = null;
  13187. pos = pos1;
  13188. }
  13189. } else {
  13190. result0 = null;
  13191. pos = pos1;
  13192. }
  13193. } else {
  13194. result0 = null;
  13195. pos = pos1;
  13196. }
  13197. if (result0 !== null) {
  13198. result0 = function (offset, to_tag) {
  13199. data.to_tag = to_tag;
  13200. }(pos0, result0[2]);
  13201. }
  13202. if (result0 === null) {
  13203. pos = pos0;
  13204. }
  13205. return result0;
  13206. }
  13207. function parse_from_tag() {
  13208. var result0, result1, result2;
  13209. var pos0, pos1;
  13210. pos0 = pos;
  13211. pos1 = pos;
  13212. if (input.substr(pos, 8) === "from-tag") {
  13213. result0 = "from-tag";
  13214. pos += 8;
  13215. } else {
  13216. result0 = null;
  13217. if (reportFailures === 0) {
  13218. matchFailed("\"from-tag\"");
  13219. }
  13220. }
  13221. if (result0 !== null) {
  13222. result1 = parse_EQUAL();
  13223. if (result1 !== null) {
  13224. result2 = parse_token();
  13225. if (result2 !== null) {
  13226. result0 = [result0, result1, result2];
  13227. } else {
  13228. result0 = null;
  13229. pos = pos1;
  13230. }
  13231. } else {
  13232. result0 = null;
  13233. pos = pos1;
  13234. }
  13235. } else {
  13236. result0 = null;
  13237. pos = pos1;
  13238. }
  13239. if (result0 !== null) {
  13240. result0 = function (offset, from_tag) {
  13241. data.from_tag = from_tag;
  13242. }(pos0, result0[2]);
  13243. }
  13244. if (result0 === null) {
  13245. pos = pos0;
  13246. }
  13247. return result0;
  13248. }
  13249. function parse_early_flag() {
  13250. var result0;
  13251. var pos0;
  13252. pos0 = pos;
  13253. if (input.substr(pos, 10) === "early-only") {
  13254. result0 = "early-only";
  13255. pos += 10;
  13256. } else {
  13257. result0 = null;
  13258. if (reportFailures === 0) {
  13259. matchFailed("\"early-only\"");
  13260. }
  13261. }
  13262. if (result0 !== null) {
  13263. result0 = function (offset) {
  13264. data.early_only = true;
  13265. }(pos0);
  13266. }
  13267. if (result0 === null) {
  13268. pos = pos0;
  13269. }
  13270. return result0;
  13271. }
  13272. function cleanupExpected(expected) {
  13273. expected.sort();
  13274. var lastExpected = null;
  13275. var cleanExpected = [];
  13276. for (var i = 0; i < expected.length; i++) {
  13277. if (expected[i] !== lastExpected) {
  13278. cleanExpected.push(expected[i]);
  13279. lastExpected = expected[i];
  13280. }
  13281. }
  13282. return cleanExpected;
  13283. }
  13284. function computeErrorPosition() {
  13285. /*
  13286. * The first idea was to use |String.split| to break the input up to the
  13287. * error position along newlines and derive the line and column from
  13288. * there. However IE's |split| implementation is so broken that it was
  13289. * enough to prevent it.
  13290. */
  13291. var line = 1;
  13292. var column = 1;
  13293. var seenCR = false;
  13294. for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
  13295. var ch = input.charAt(i);
  13296. if (ch === "\n") {
  13297. if (!seenCR) {
  13298. line++;
  13299. }
  13300. column = 1;
  13301. seenCR = false;
  13302. } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
  13303. line++;
  13304. column = 1;
  13305. seenCR = true;
  13306. } else {
  13307. column++;
  13308. seenCR = false;
  13309. }
  13310. }
  13311. return {
  13312. line: line,
  13313. column: column
  13314. };
  13315. }
  13316. var URI = require('./URI');
  13317. var NameAddrHeader = require('./NameAddrHeader');
  13318. var data = {};
  13319. var result = parseFunctions[startRule]();
  13320. /*
  13321. * The parser is now in one of the following three states:
  13322. *
  13323. * 1. The parser successfully parsed the whole input.
  13324. *
  13325. * - |result !== null|
  13326. * - |pos === input.length|
  13327. * - |rightmostFailuresExpected| may or may not contain something
  13328. *
  13329. * 2. The parser successfully parsed only a part of the input.
  13330. *
  13331. * - |result !== null|
  13332. * - |pos < input.length|
  13333. * - |rightmostFailuresExpected| may or may not contain something
  13334. *
  13335. * 3. The parser did not successfully parse any part of the input.
  13336. *
  13337. * - |result === null|
  13338. * - |pos === 0|
  13339. * - |rightmostFailuresExpected| contains at least one failure
  13340. *
  13341. * All code following this comment (including called functions) must
  13342. * handle these states.
  13343. */
  13344. if (result === null || pos !== input.length) {
  13345. var offset = Math.max(pos, rightmostFailuresPos);
  13346. var found = offset < input.length ? input.charAt(offset) : null;
  13347. var errorPosition = computeErrorPosition();
  13348. new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
  13349. return -1;
  13350. }
  13351. return data;
  13352. },
  13353. /* Returns the parser source code. */
  13354. toSource: function toSource() {
  13355. return this._source;
  13356. }
  13357. };
  13358. /* Thrown when a parser encounters a syntax error. */
  13359. result.SyntaxError = function (expected, found, offset, line, column) {
  13360. function buildMessage(expected, found) {
  13361. var expectedHumanized, foundHumanized;
  13362. switch (expected.length) {
  13363. case 0:
  13364. expectedHumanized = "end of input";
  13365. break;
  13366. case 1:
  13367. expectedHumanized = expected[0];
  13368. break;
  13369. default:
  13370. expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
  13371. }
  13372. foundHumanized = found ? quote(found) : "end of input";
  13373. return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
  13374. }
  13375. this.name = "SyntaxError";
  13376. this.expected = expected;
  13377. this.found = found;
  13378. this.message = buildMessage(expected, found);
  13379. this.offset = offset;
  13380. this.line = line;
  13381. this.column = column;
  13382. };
  13383. result.SyntaxError.prototype = Error.prototype;
  13384. return result;
  13385. }();
  13386. },{"./NameAddrHeader":10,"./URI":25}],8:[function(require,module,exports){
  13387. "use strict";
  13388. var pkg = require('../package.json');
  13389. var C = require('./Constants');
  13390. var Exceptions = require('./Exceptions');
  13391. var Utils = require('./Utils');
  13392. var UA = require('./UA');
  13393. var URI = require('./URI');
  13394. var NameAddrHeader = require('./NameAddrHeader');
  13395. var Grammar = require('./Grammar');
  13396. var WebSocketInterface = require('./WebSocketInterface');
  13397. var debug = require('debug')('JsSIP');
  13398. debug('version %s', pkg.version);
  13399. /**
  13400. * Expose the JsSIP module.
  13401. */
  13402. module.exports = {
  13403. C: C,
  13404. Exceptions: Exceptions,
  13405. Utils: Utils,
  13406. UA: UA,
  13407. URI: URI,
  13408. NameAddrHeader: NameAddrHeader,
  13409. WebSocketInterface: WebSocketInterface,
  13410. Grammar: Grammar,
  13411. // Expose the debug module.
  13412. debug: require('debug'),
  13413. get name() {
  13414. return pkg.title;
  13415. },
  13416. get version() {
  13417. return pkg.version;
  13418. }
  13419. };
  13420. },{"../package.json":38,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":24,"./URI":25,"./Utils":26,"./WebSocketInterface":27,"debug":30}],9:[function(require,module,exports){
  13421. "use strict";
  13422. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  13423. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13424. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13425. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13426. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13427. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13428. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13429. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  13430. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13431. var EventEmitter = require('events').EventEmitter;
  13432. var JsSIP_C = require('./Constants');
  13433. var SIPMessage = require('./SIPMessage');
  13434. var Utils = require('./Utils');
  13435. var RequestSender = require('./RequestSender');
  13436. var Exceptions = require('./Exceptions');
  13437. var debug = require('debug')('JsSIP:Message');
  13438. module.exports =
  13439. /*#__PURE__*/
  13440. function (_EventEmitter) {
  13441. _inherits(Message, _EventEmitter);
  13442. function Message(ua) {
  13443. var _this;
  13444. _classCallCheck(this, Message);
  13445. _this = _possibleConstructorReturn(this, _getPrototypeOf(Message).call(this));
  13446. _this._ua = ua;
  13447. _this._request = null;
  13448. _this._closed = false;
  13449. _this._direction = null;
  13450. _this._local_identity = null;
  13451. _this._remote_identity = null; // Whether an incoming message has been replied.
  13452. _this._is_replied = false; // Custom message empty object for high level use.
  13453. _this._data = {};
  13454. return _this;
  13455. }
  13456. _createClass(Message, [{
  13457. key: "send",
  13458. value: function send(target, body) {
  13459. var _this2 = this;
  13460. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  13461. var originalTarget = target;
  13462. if (target === undefined || body === undefined) {
  13463. throw new TypeError('Not enough arguments');
  13464. } // Check target validity.
  13465. target = this._ua.normalizeTarget(target);
  13466. if (!target) {
  13467. throw new TypeError("Invalid target: ".concat(originalTarget));
  13468. } // Get call options.
  13469. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13470. var eventHandlers = options.eventHandlers || {};
  13471. var contentType = options.contentType || 'text/plain'; // Set event handlers.
  13472. for (var event in eventHandlers) {
  13473. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  13474. this.on(event, eventHandlers[event]);
  13475. }
  13476. }
  13477. extraHeaders.push("Content-Type: ".concat(contentType));
  13478. this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, null, extraHeaders);
  13479. if (body) {
  13480. this._request.body = body;
  13481. }
  13482. var request_sender = new RequestSender(this._ua, this._request, {
  13483. onRequestTimeout: function onRequestTimeout() {
  13484. _this2._onRequestTimeout();
  13485. },
  13486. onTransportError: function onTransportError() {
  13487. _this2._onTransportError();
  13488. },
  13489. onReceiveResponse: function onReceiveResponse(response) {
  13490. _this2._receiveResponse(response);
  13491. }
  13492. });
  13493. this._newMessage('local', this._request);
  13494. request_sender.send();
  13495. }
  13496. }, {
  13497. key: "init_incoming",
  13498. value: function init_incoming(request) {
  13499. this._request = request;
  13500. this._newMessage('remote', request); // Reply with a 200 OK if the user didn't reply.
  13501. if (!this._is_replied) {
  13502. this._is_replied = true;
  13503. request.reply(200);
  13504. }
  13505. this._close();
  13506. }
  13507. /**
  13508. * Accept the incoming Message
  13509. * Only valid for incoming Messages
  13510. */
  13511. }, {
  13512. key: "accept",
  13513. value: function accept() {
  13514. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13515. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13516. var body = options.body;
  13517. if (this._direction !== 'incoming') {
  13518. throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message');
  13519. }
  13520. if (this._is_replied) {
  13521. throw new Error('incoming Message already replied');
  13522. }
  13523. this._is_replied = true;
  13524. this._request.reply(200, null, extraHeaders, body);
  13525. }
  13526. /**
  13527. * Reject the incoming Message
  13528. * Only valid for incoming Messages
  13529. */
  13530. }, {
  13531. key: "reject",
  13532. value: function reject() {
  13533. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13534. var status_code = options.status_code || 480;
  13535. var reason_phrase = options.reason_phrase;
  13536. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13537. var body = options.body;
  13538. if (this._direction !== 'incoming') {
  13539. throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message');
  13540. }
  13541. if (this._is_replied) {
  13542. throw new Error('incoming Message already replied');
  13543. }
  13544. if (status_code < 300 || status_code >= 700) {
  13545. throw new TypeError("Invalid status_code: ".concat(status_code));
  13546. }
  13547. this._is_replied = true;
  13548. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  13549. }
  13550. }, {
  13551. key: "_receiveResponse",
  13552. value: function _receiveResponse(response) {
  13553. if (this._closed) {
  13554. return;
  13555. }
  13556. switch (true) {
  13557. case /^1[0-9]{2}$/.test(response.status_code):
  13558. // Ignore provisional responses.
  13559. break;
  13560. case /^2[0-9]{2}$/.test(response.status_code):
  13561. this._succeeded('remote', response);
  13562. break;
  13563. default:
  13564. {
  13565. var cause = Utils.sipErrorCause(response.status_code);
  13566. this._failed('remote', response, cause);
  13567. break;
  13568. }
  13569. }
  13570. }
  13571. }, {
  13572. key: "_onRequestTimeout",
  13573. value: function _onRequestTimeout() {
  13574. if (this._closed) {
  13575. return;
  13576. }
  13577. this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT);
  13578. }
  13579. }, {
  13580. key: "_onTransportError",
  13581. value: function _onTransportError() {
  13582. if (this._closed) {
  13583. return;
  13584. }
  13585. this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  13586. }
  13587. }, {
  13588. key: "_close",
  13589. value: function _close() {
  13590. this._closed = true;
  13591. this._ua.destroyMessage(this);
  13592. }
  13593. /**
  13594. * Internal Callbacks
  13595. */
  13596. }, {
  13597. key: "_newMessage",
  13598. value: function _newMessage(originator, request) {
  13599. if (originator === 'remote') {
  13600. this._direction = 'incoming';
  13601. this._local_identity = request.to;
  13602. this._remote_identity = request.from;
  13603. } else if (originator === 'local') {
  13604. this._direction = 'outgoing';
  13605. this._local_identity = request.from;
  13606. this._remote_identity = request.to;
  13607. }
  13608. this._ua.newMessage(this, {
  13609. originator: originator,
  13610. message: this,
  13611. request: request
  13612. });
  13613. }
  13614. }, {
  13615. key: "_failed",
  13616. value: function _failed(originator, response, cause) {
  13617. debug('MESSAGE failed');
  13618. this._close();
  13619. debug('emit "failed"');
  13620. this.emit('failed', {
  13621. originator: originator,
  13622. response: response || null,
  13623. cause: cause
  13624. });
  13625. }
  13626. }, {
  13627. key: "_succeeded",
  13628. value: function _succeeded(originator, response) {
  13629. debug('MESSAGE succeeded');
  13630. this._close();
  13631. debug('emit "succeeded"');
  13632. this.emit('succeeded', {
  13633. originator: originator,
  13634. response: response
  13635. });
  13636. }
  13637. }, {
  13638. key: "direction",
  13639. get: function get() {
  13640. return this._direction;
  13641. }
  13642. }, {
  13643. key: "local_identity",
  13644. get: function get() {
  13645. return this._local_identity;
  13646. }
  13647. }, {
  13648. key: "remote_identity",
  13649. get: function get() {
  13650. return this._remote_identity;
  13651. }
  13652. }]);
  13653. return Message;
  13654. }(EventEmitter);
  13655. },{"./Constants":2,"./Exceptions":6,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30,"events":29}],10:[function(require,module,exports){
  13656. "use strict";
  13657. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13658. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  13659. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13660. var URI = require('./URI');
  13661. var Grammar = require('./Grammar');
  13662. module.exports =
  13663. /*#__PURE__*/
  13664. function () {
  13665. _createClass(NameAddrHeader, null, [{
  13666. key: "parse",
  13667. /**
  13668. * Parse the given string and returns a NameAddrHeader instance or undefined if
  13669. * it is an invalid NameAddrHeader.
  13670. */
  13671. value: function parse(name_addr_header) {
  13672. name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header');
  13673. if (name_addr_header !== -1) {
  13674. return name_addr_header;
  13675. } else {
  13676. return undefined;
  13677. }
  13678. }
  13679. }]);
  13680. function NameAddrHeader(uri, display_name, parameters) {
  13681. _classCallCheck(this, NameAddrHeader);
  13682. // Checks.
  13683. if (!uri || !(uri instanceof URI)) {
  13684. throw new TypeError('missing or invalid "uri" parameter');
  13685. } // Initialize parameters.
  13686. this._uri = uri;
  13687. this._parameters = {};
  13688. this.display_name = display_name;
  13689. for (var param in parameters) {
  13690. if (Object.prototype.hasOwnProperty.call(parameters, param)) {
  13691. this.setParam(param, parameters[param]);
  13692. }
  13693. }
  13694. }
  13695. _createClass(NameAddrHeader, [{
  13696. key: "setParam",
  13697. value: function setParam(key, value) {
  13698. if (key) {
  13699. this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
  13700. }
  13701. }
  13702. }, {
  13703. key: "getParam",
  13704. value: function getParam(key) {
  13705. if (key) {
  13706. return this._parameters[key.toLowerCase()];
  13707. }
  13708. }
  13709. }, {
  13710. key: "hasParam",
  13711. value: function hasParam(key) {
  13712. if (key) {
  13713. return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
  13714. }
  13715. }
  13716. }, {
  13717. key: "deleteParam",
  13718. value: function deleteParam(parameter) {
  13719. parameter = parameter.toLowerCase();
  13720. if (this._parameters.hasOwnProperty(parameter)) {
  13721. var value = this._parameters[parameter];
  13722. delete this._parameters[parameter];
  13723. return value;
  13724. }
  13725. }
  13726. }, {
  13727. key: "clearParams",
  13728. value: function clearParams() {
  13729. this._parameters = {};
  13730. }
  13731. }, {
  13732. key: "clone",
  13733. value: function clone() {
  13734. return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters)));
  13735. }
  13736. }, {
  13737. key: "_quote",
  13738. value: function _quote(str) {
  13739. return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
  13740. }
  13741. }, {
  13742. key: "toString",
  13743. value: function toString() {
  13744. var body = this._display_name ? "\"".concat(this._quote(this._display_name), "\" ") : '';
  13745. body += "<".concat(this._uri.toString(), ">");
  13746. for (var parameter in this._parameters) {
  13747. if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
  13748. body += ";".concat(parameter);
  13749. if (this._parameters[parameter] !== null) {
  13750. body += "=".concat(this._parameters[parameter]);
  13751. }
  13752. }
  13753. }
  13754. return body;
  13755. }
  13756. }, {
  13757. key: "uri",
  13758. get: function get() {
  13759. return this._uri;
  13760. }
  13761. }, {
  13762. key: "display_name",
  13763. get: function get() {
  13764. return this._display_name;
  13765. },
  13766. set: function set(value) {
  13767. this._display_name = value === 0 ? '0' : value;
  13768. }
  13769. }]);
  13770. return NameAddrHeader;
  13771. }();
  13772. },{"./Grammar":7,"./URI":25}],11:[function(require,module,exports){
  13773. "use strict";
  13774. var Grammar = require('./Grammar');
  13775. var SIPMessage = require('./SIPMessage');
  13776. var debugerror = require('debug')('JsSIP:ERROR:Parser');
  13777. debugerror.log = console.warn.bind(console);
  13778. /**
  13779. * Parse SIP Message
  13780. */
  13781. exports.parseMessage = function (data, ua) {
  13782. var message;
  13783. var bodyStart;
  13784. var headerEnd = data.indexOf('\r\n');
  13785. if (headerEnd === -1) {
  13786. debugerror('parseMessage() | no CRLF found, not a SIP message');
  13787. return;
  13788. } // Parse first line. Check if it is a Request or a Reply.
  13789. var firstLine = data.substring(0, headerEnd);
  13790. var parsed = Grammar.parse(firstLine, 'Request_Response');
  13791. if (parsed === -1) {
  13792. debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\""));
  13793. return;
  13794. } else if (!parsed.status_code) {
  13795. message = new SIPMessage.IncomingRequest(ua);
  13796. message.method = parsed.method;
  13797. message.ruri = parsed.uri;
  13798. } else {
  13799. message = new SIPMessage.IncomingResponse();
  13800. message.status_code = parsed.status_code;
  13801. message.reason_phrase = parsed.reason_phrase;
  13802. }
  13803. message.data = data;
  13804. var headerStart = headerEnd + 2;
  13805. /* Loop over every line in data. Detect the end of each header and parse
  13806. * it or simply add to the headers collection.
  13807. */
  13808. while (true) {
  13809. headerEnd = getHeader(data, headerStart); // The SIP message has normally finished.
  13810. if (headerEnd === -2) {
  13811. bodyStart = headerStart + 2;
  13812. break;
  13813. } // Data.indexOf returned -1 due to a malformed message.
  13814. else if (headerEnd === -1) {
  13815. debugerror('parseMessage() | malformed message');
  13816. return;
  13817. }
  13818. parsed = parseHeader(message, data, headerStart, headerEnd);
  13819. if (parsed !== true) {
  13820. debugerror('parseMessage() |', parsed.error);
  13821. return;
  13822. }
  13823. headerStart = headerEnd + 2;
  13824. }
  13825. /* RFC3261 18.3.
  13826. * If there are additional bytes in the transport packet
  13827. * beyond the end of the body, they MUST be discarded.
  13828. */
  13829. if (message.hasHeader('content-length')) {
  13830. var contentLength = message.getHeader('content-length');
  13831. message.body = data.substr(bodyStart, contentLength);
  13832. } else {
  13833. message.body = data.substring(bodyStart);
  13834. }
  13835. return message;
  13836. };
  13837. /**
  13838. * Extract and parse every header of a SIP message.
  13839. */
  13840. function getHeader(data, headerStart) {
  13841. // 'start' position of the header.
  13842. var start = headerStart; // 'end' position of the header.
  13843. var end = 0; // 'partial end' position of the header.
  13844. var partialEnd = 0; // End of message.
  13845. if (data.substring(start, start + 2).match(/(^\r\n)/)) {
  13846. return -2;
  13847. }
  13848. while (end === 0) {
  13849. // Partial End of Header.
  13850. partialEnd = data.indexOf('\r\n', start); // 'indexOf' returns -1 if the value to be found never occurs.
  13851. if (partialEnd === -1) {
  13852. return partialEnd;
  13853. }
  13854. if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) {
  13855. // Not the end of the message. Continue from the next position.
  13856. start = partialEnd + 2;
  13857. } else {
  13858. end = partialEnd;
  13859. }
  13860. }
  13861. return end;
  13862. }
  13863. function parseHeader(message, data, headerStart, headerEnd) {
  13864. var parsed;
  13865. var hcolonIndex = data.indexOf(':', headerStart);
  13866. var headerName = data.substring(headerStart, hcolonIndex).trim();
  13867. var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim(); // If header-field is well-known, parse it.
  13868. switch (headerName.toLowerCase()) {
  13869. case 'via':
  13870. case 'v':
  13871. message.addHeader('via', headerValue);
  13872. if (message.getHeaders('via').length === 1) {
  13873. parsed = message.parseHeader('Via');
  13874. if (parsed) {
  13875. message.via = parsed;
  13876. message.via_branch = parsed.branch;
  13877. }
  13878. } else {
  13879. parsed = 0;
  13880. }
  13881. break;
  13882. case 'from':
  13883. case 'f':
  13884. message.setHeader('from', headerValue);
  13885. parsed = message.parseHeader('from');
  13886. if (parsed) {
  13887. message.from = parsed;
  13888. message.from_tag = parsed.getParam('tag');
  13889. }
  13890. break;
  13891. case 'to':
  13892. case 't':
  13893. message.setHeader('to', headerValue);
  13894. parsed = message.parseHeader('to');
  13895. if (parsed) {
  13896. message.to = parsed;
  13897. message.to_tag = parsed.getParam('tag');
  13898. }
  13899. break;
  13900. case 'record-route':
  13901. parsed = Grammar.parse(headerValue, 'Record_Route');
  13902. if (parsed === -1) {
  13903. parsed = undefined;
  13904. } else {
  13905. var _iteratorNormalCompletion = true;
  13906. var _didIteratorError = false;
  13907. var _iteratorError = undefined;
  13908. try {
  13909. for (var _iterator = parsed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  13910. var header = _step.value;
  13911. message.addHeader('record-route', headerValue.substring(header.possition, header.offset));
  13912. message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed;
  13913. }
  13914. } catch (err) {
  13915. _didIteratorError = true;
  13916. _iteratorError = err;
  13917. } finally {
  13918. try {
  13919. if (!_iteratorNormalCompletion && _iterator.return != null) {
  13920. _iterator.return();
  13921. }
  13922. } finally {
  13923. if (_didIteratorError) {
  13924. throw _iteratorError;
  13925. }
  13926. }
  13927. }
  13928. }
  13929. break;
  13930. case 'call-id':
  13931. case 'i':
  13932. message.setHeader('call-id', headerValue);
  13933. parsed = message.parseHeader('call-id');
  13934. if (parsed) {
  13935. message.call_id = headerValue;
  13936. }
  13937. break;
  13938. case 'contact':
  13939. case 'm':
  13940. parsed = Grammar.parse(headerValue, 'Contact');
  13941. if (parsed === -1) {
  13942. parsed = undefined;
  13943. } else {
  13944. var _iteratorNormalCompletion2 = true;
  13945. var _didIteratorError2 = false;
  13946. var _iteratorError2 = undefined;
  13947. try {
  13948. for (var _iterator2 = parsed[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  13949. var _header = _step2.value;
  13950. message.addHeader('contact', headerValue.substring(_header.possition, _header.offset));
  13951. message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed;
  13952. }
  13953. } catch (err) {
  13954. _didIteratorError2 = true;
  13955. _iteratorError2 = err;
  13956. } finally {
  13957. try {
  13958. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  13959. _iterator2.return();
  13960. }
  13961. } finally {
  13962. if (_didIteratorError2) {
  13963. throw _iteratorError2;
  13964. }
  13965. }
  13966. }
  13967. }
  13968. break;
  13969. case 'content-length':
  13970. case 'l':
  13971. message.setHeader('content-length', headerValue);
  13972. parsed = message.parseHeader('content-length');
  13973. break;
  13974. case 'content-type':
  13975. case 'c':
  13976. message.setHeader('content-type', headerValue);
  13977. parsed = message.parseHeader('content-type');
  13978. break;
  13979. case 'cseq':
  13980. message.setHeader('cseq', headerValue);
  13981. parsed = message.parseHeader('cseq');
  13982. if (parsed) {
  13983. message.cseq = parsed.value;
  13984. }
  13985. if (message instanceof SIPMessage.IncomingResponse) {
  13986. message.method = parsed.method;
  13987. }
  13988. break;
  13989. case 'max-forwards':
  13990. message.setHeader('max-forwards', headerValue);
  13991. parsed = message.parseHeader('max-forwards');
  13992. break;
  13993. case 'www-authenticate':
  13994. message.setHeader('www-authenticate', headerValue);
  13995. parsed = message.parseHeader('www-authenticate');
  13996. break;
  13997. case 'proxy-authenticate':
  13998. message.setHeader('proxy-authenticate', headerValue);
  13999. parsed = message.parseHeader('proxy-authenticate');
  14000. break;
  14001. case 'session-expires':
  14002. case 'x':
  14003. message.setHeader('session-expires', headerValue);
  14004. parsed = message.parseHeader('session-expires');
  14005. if (parsed) {
  14006. message.session_expires = parsed.expires;
  14007. message.session_expires_refresher = parsed.refresher;
  14008. }
  14009. break;
  14010. case 'refer-to':
  14011. case 'r':
  14012. message.setHeader('refer-to', headerValue);
  14013. parsed = message.parseHeader('refer-to');
  14014. if (parsed) {
  14015. message.refer_to = parsed;
  14016. }
  14017. break;
  14018. case 'replaces':
  14019. message.setHeader('replaces', headerValue);
  14020. parsed = message.parseHeader('replaces');
  14021. if (parsed) {
  14022. message.replaces = parsed;
  14023. }
  14024. break;
  14025. case 'event':
  14026. case 'o':
  14027. message.setHeader('event', headerValue);
  14028. parsed = message.parseHeader('event');
  14029. if (parsed) {
  14030. message.event = parsed;
  14031. }
  14032. break;
  14033. default:
  14034. // Do not parse this header.
  14035. message.addHeader(headerName, headerValue);
  14036. parsed = 0;
  14037. }
  14038. if (parsed === undefined) {
  14039. return {
  14040. error: "error parsing header \"".concat(headerName, "\"")
  14041. };
  14042. } else {
  14043. return true;
  14044. }
  14045. }
  14046. },{"./Grammar":7,"./SIPMessage":19,"debug":30}],12:[function(require,module,exports){
  14047. "use strict";
  14048. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  14049. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14050. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14051. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14052. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14053. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14054. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14055. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14056. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14057. /* globals RTCPeerConnection: false, RTCSessionDescription: false */
  14058. var EventEmitter = require('events').EventEmitter;
  14059. var sdp_transform = require('sdp-transform');
  14060. var JsSIP_C = require('./Constants');
  14061. var Exceptions = require('./Exceptions');
  14062. var Transactions = require('./Transactions');
  14063. var Utils = require('./Utils');
  14064. var Timers = require('./Timers');
  14065. var SIPMessage = require('./SIPMessage');
  14066. var Dialog = require('./Dialog');
  14067. var RequestSender = require('./RequestSender');
  14068. var RTCSession_DTMF = require('./RTCSession/DTMF');
  14069. var RTCSession_Info = require('./RTCSession/Info');
  14070. var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier');
  14071. var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber');
  14072. var URI = require('./URI');
  14073. var debug = require('debug')('JsSIP:RTCSession');
  14074. var debugerror = require('debug')('JsSIP:ERROR:RTCSession');
  14075. debugerror.log = console.warn.bind(console);
  14076. var C = {
  14077. // RTCSession states.
  14078. STATUS_NULL: 0,
  14079. STATUS_INVITE_SENT: 1,
  14080. STATUS_1XX_RECEIVED: 2,
  14081. STATUS_INVITE_RECEIVED: 3,
  14082. STATUS_WAITING_FOR_ANSWER: 4,
  14083. STATUS_ANSWERED: 5,
  14084. STATUS_WAITING_FOR_ACK: 6,
  14085. STATUS_CANCELED: 7,
  14086. STATUS_TERMINATED: 8,
  14087. STATUS_CONFIRMED: 9
  14088. };
  14089. /**
  14090. * Local variables.
  14091. */
  14092. var holdMediaTypes = ['audio', 'video'];
  14093. module.exports =
  14094. /*#__PURE__*/
  14095. function (_EventEmitter) {
  14096. _inherits(RTCSession, _EventEmitter);
  14097. _createClass(RTCSession, null, [{
  14098. key: "C",
  14099. /**
  14100. * Expose C object.
  14101. */
  14102. get: function get() {
  14103. return C;
  14104. }
  14105. }]);
  14106. function RTCSession(ua) {
  14107. var _this;
  14108. _classCallCheck(this, RTCSession);
  14109. debug('new');
  14110. _this = _possibleConstructorReturn(this, _getPrototypeOf(RTCSession).call(this));
  14111. _this._id = null;
  14112. _this._ua = ua;
  14113. _this._status = C.STATUS_NULL;
  14114. _this._dialog = null;
  14115. _this._earlyDialogs = {};
  14116. _this._contact = null;
  14117. _this._from_tag = null;
  14118. _this._to_tag = null; // The RTCPeerConnection instance (public attribute).
  14119. _this._connection = null; // Prevent races on serial PeerConnction operations.
  14120. _this._connectionPromiseQueue = Promise.resolve(); // Incoming/Outgoing request being currently processed.
  14121. _this._request = null; // Cancel state for initial outgoing request.
  14122. _this._is_canceled = false;
  14123. _this._cancel_reason = ''; // RTCSession confirmation flag.
  14124. _this._is_confirmed = false; // Is late SDP being negotiated.
  14125. _this._late_sdp = false; // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()).
  14126. _this._rtcOfferConstraints = null;
  14127. _this._rtcAnswerConstraints = null; // Local MediaStream.
  14128. _this._localMediaStream = null;
  14129. _this._localMediaStreamLocallyGenerated = false; // Flag to indicate PeerConnection ready for new actions.
  14130. _this._rtcReady = true; // SIP Timers.
  14131. _this._timers = {
  14132. ackTimer: null,
  14133. expiresTimer: null,
  14134. invite2xxTimer: null,
  14135. userNoAnswerTimer: null
  14136. }; // Session info.
  14137. _this._direction = null;
  14138. _this._local_identity = null;
  14139. _this._remote_identity = null;
  14140. _this._start_time = null;
  14141. _this._end_time = null;
  14142. _this._tones = null; // Mute/Hold state.
  14143. _this._audioMuted = false;
  14144. _this._videoMuted = false;
  14145. _this._localHold = false;
  14146. _this._remoteHold = false; // Session Timers (RFC 4028).
  14147. _this._sessionTimers = {
  14148. enabled: _this._ua.configuration.session_timers,
  14149. refreshMethod: _this._ua.configuration.session_timers_refresh_method,
  14150. defaultExpires: JsSIP_C.SESSION_EXPIRES,
  14151. currentExpires: null,
  14152. running: false,
  14153. refresher: false,
  14154. timer: null // A setTimeout.
  14155. }; // Map of ReferSubscriber instances indexed by the REFER's CSeq number.
  14156. _this._referSubscribers = {}; // Custom session empty object for high level use.
  14157. _this._data = {};
  14158. return _this;
  14159. }
  14160. /**
  14161. * User API
  14162. */
  14163. // Expose RTCSession constants as a property of the RTCSession instance.
  14164. _createClass(RTCSession, [{
  14165. key: "isInProgress",
  14166. value: function isInProgress() {
  14167. switch (this._status) {
  14168. case C.STATUS_NULL:
  14169. case C.STATUS_INVITE_SENT:
  14170. case C.STATUS_1XX_RECEIVED:
  14171. case C.STATUS_INVITE_RECEIVED:
  14172. case C.STATUS_WAITING_FOR_ANSWER:
  14173. return true;
  14174. default:
  14175. return false;
  14176. }
  14177. }
  14178. }, {
  14179. key: "isEstablished",
  14180. value: function isEstablished() {
  14181. switch (this._status) {
  14182. case C.STATUS_ANSWERED:
  14183. case C.STATUS_WAITING_FOR_ACK:
  14184. case C.STATUS_CONFIRMED:
  14185. return true;
  14186. default:
  14187. return false;
  14188. }
  14189. }
  14190. }, {
  14191. key: "isEnded",
  14192. value: function isEnded() {
  14193. switch (this._status) {
  14194. case C.STATUS_CANCELED:
  14195. case C.STATUS_TERMINATED:
  14196. return true;
  14197. default:
  14198. return false;
  14199. }
  14200. }
  14201. }, {
  14202. key: "isMuted",
  14203. value: function isMuted() {
  14204. return {
  14205. audio: this._audioMuted,
  14206. video: this._videoMuted
  14207. };
  14208. }
  14209. }, {
  14210. key: "isOnHold",
  14211. value: function isOnHold() {
  14212. return {
  14213. local: this._localHold,
  14214. remote: this._remoteHold
  14215. };
  14216. }
  14217. }, {
  14218. key: "connect",
  14219. value: function connect(target) {
  14220. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  14221. var initCallback = arguments.length > 2 ? arguments[2] : undefined;
  14222. debug('connect()');
  14223. var originalTarget = target;
  14224. var eventHandlers = options.eventHandlers || {};
  14225. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14226. var mediaConstraints = options.mediaConstraints || {
  14227. audio: true,
  14228. video: true
  14229. };
  14230. var mediaStream = options.mediaStream || null;
  14231. var pcConfig = options.pcConfig || {
  14232. iceServers: []
  14233. };
  14234. var rtcConstraints = options.rtcConstraints || null;
  14235. var rtcOfferConstraints = options.rtcOfferConstraints || null;
  14236. this._rtcOfferConstraints = rtcOfferConstraints;
  14237. this._rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  14238. this._data = options.data || this._data; // Check target.
  14239. if (target === undefined) {
  14240. throw new TypeError('Not enough arguments');
  14241. } // Check Session Status.
  14242. if (this._status !== C.STATUS_NULL) {
  14243. throw new Exceptions.InvalidStateError(this._status);
  14244. } // Check WebRTC support.
  14245. if (!window.RTCPeerConnection) {
  14246. throw new Exceptions.NotSupportedError('WebRTC not supported');
  14247. } // Check target validity.
  14248. target = this._ua.normalizeTarget(target);
  14249. if (!target) {
  14250. throw new TypeError("Invalid target: ".concat(originalTarget));
  14251. } // Session Timers.
  14252. if (this._sessionTimers.enabled) {
  14253. if (Utils.isDecimal(options.sessionTimersExpires)) {
  14254. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  14255. this._sessionTimers.defaultExpires = options.sessionTimersExpires;
  14256. } else {
  14257. this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  14258. }
  14259. }
  14260. } // Set event handlers.
  14261. for (var event in eventHandlers) {
  14262. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  14263. this.on(event, eventHandlers[event]);
  14264. }
  14265. } // Session parameter initialization.
  14266. this._from_tag = Utils.newTag(); // Set anonymous property.
  14267. var anonymous = options.anonymous || false;
  14268. var requestParams = {
  14269. from_tag: this._from_tag
  14270. };
  14271. this._contact = this._ua.contact.toString({
  14272. anonymous: anonymous,
  14273. outbound: true
  14274. });
  14275. if (anonymous) {
  14276. requestParams.from_display_name = 'Anonymous';
  14277. requestParams.from_uri = new URI('sip', 'anonymous', 'anonymous.invalid');
  14278. extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()));
  14279. extraHeaders.push('Privacy: id');
  14280. }
  14281. extraHeaders.push("Contact: ".concat(this._contact));
  14282. extraHeaders.push('Content-Type: application/sdp');
  14283. if (this._sessionTimers.enabled) {
  14284. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires));
  14285. }
  14286. this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders);
  14287. this._id = this._request.call_id + this._from_tag; // Create a new RTCPeerConnection instance.
  14288. this._createRTCConnection(pcConfig, rtcConstraints); // Set internal properties.
  14289. this._direction = 'outgoing';
  14290. this._local_identity = this._request.from;
  14291. this._remote_identity = this._request.to; // User explicitly provided a newRTCSession callback for this session.
  14292. if (initCallback) {
  14293. initCallback(this);
  14294. }
  14295. this._newRTCSession('local', this._request);
  14296. this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream);
  14297. }
  14298. }, {
  14299. key: "init_incoming",
  14300. value: function init_incoming(request, initCallback) {
  14301. var _this2 = this;
  14302. debug('init_incoming()');
  14303. var expires;
  14304. var contentType = request.getHeader('Content-Type'); // Check body and content type.
  14305. if (request.body && contentType !== 'application/sdp') {
  14306. request.reply(415);
  14307. return;
  14308. } // Session parameter initialization.
  14309. this._status = C.STATUS_INVITE_RECEIVED;
  14310. this._from_tag = request.from_tag;
  14311. this._id = request.call_id + this._from_tag;
  14312. this._request = request;
  14313. this._contact = this._ua.contact.toString(); // Get the Expires header value if exists.
  14314. if (request.hasHeader('expires')) {
  14315. expires = request.getHeader('expires') * 1000;
  14316. }
  14317. /* Set the to_tag before
  14318. * replying a response code that will create a dialog.
  14319. */
  14320. request.to_tag = Utils.newTag(); // An error on dialog creation will fire 'failed' event.
  14321. if (!this._createDialog(request, 'UAS', true)) {
  14322. request.reply(500, 'Missing Contact header field');
  14323. return;
  14324. }
  14325. if (request.body) {
  14326. this._late_sdp = false;
  14327. } else {
  14328. this._late_sdp = true;
  14329. }
  14330. this._status = C.STATUS_WAITING_FOR_ANSWER; // Set userNoAnswerTimer.
  14331. this._timers.userNoAnswerTimer = setTimeout(function () {
  14332. request.reply(408);
  14333. _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER);
  14334. }, this._ua.configuration.no_answer_timeout);
  14335. /* Set expiresTimer
  14336. * RFC3261 13.3.1
  14337. */
  14338. if (expires) {
  14339. this._timers.expiresTimer = setTimeout(function () {
  14340. if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) {
  14341. request.reply(487);
  14342. _this2._failed('system', null, JsSIP_C.causes.EXPIRES);
  14343. }
  14344. }, expires);
  14345. } // Set internal properties.
  14346. this._direction = 'incoming';
  14347. this._local_identity = request.to;
  14348. this._remote_identity = request.from; // A init callback was specifically defined.
  14349. if (initCallback) {
  14350. initCallback(this);
  14351. } // Fire 'newRTCSession' event.
  14352. this._newRTCSession('remote', request); // The user may have rejected the call in the 'newRTCSession' event.
  14353. if (this._status === C.STATUS_TERMINATED) {
  14354. return;
  14355. } // Reply 180.
  14356. request.reply(180, null, ["Contact: ".concat(this._contact)]); // Fire 'progress' event.
  14357. // TODO: Document that 'response' field in 'progress' event is null for incoming calls.
  14358. this._progress('local', null);
  14359. }
  14360. /**
  14361. * Answer the call.
  14362. */
  14363. }, {
  14364. key: "answer",
  14365. value: function answer() {
  14366. var _this3 = this;
  14367. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14368. debug('answer()');
  14369. var request = this._request;
  14370. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14371. var mediaConstraints = options.mediaConstraints || {};
  14372. var mediaStream = options.mediaStream || null;
  14373. var pcConfig = options.pcConfig || {
  14374. iceServers: []
  14375. };
  14376. var rtcConstraints = options.rtcConstraints || null;
  14377. var rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  14378. var tracks;
  14379. var peerHasAudioLine = false;
  14380. var peerHasVideoLine = false;
  14381. var peerOffersFullAudio = false;
  14382. var peerOffersFullVideo = false;
  14383. this._rtcAnswerConstraints = rtcAnswerConstraints;
  14384. this._rtcOfferConstraints = options.rtcOfferConstraints || null;
  14385. this._data = options.data || this._data; // Check Session Direction and Status.
  14386. if (this._direction !== 'incoming') {
  14387. throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession');
  14388. } // Check Session status.
  14389. if (this._status !== C.STATUS_WAITING_FOR_ANSWER) {
  14390. throw new Exceptions.InvalidStateError(this._status);
  14391. } // Session Timers.
  14392. if (this._sessionTimers.enabled) {
  14393. if (Utils.isDecimal(options.sessionTimersExpires)) {
  14394. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  14395. this._sessionTimers.defaultExpires = options.sessionTimersExpires;
  14396. } else {
  14397. this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  14398. }
  14399. }
  14400. }
  14401. this._status = C.STATUS_ANSWERED; // An error on dialog creation will fire 'failed' event.
  14402. if (!this._createDialog(request, 'UAS')) {
  14403. request.reply(500, 'Error creating dialog');
  14404. return;
  14405. }
  14406. clearTimeout(this._timers.userNoAnswerTimer);
  14407. extraHeaders.unshift("Contact: ".concat(this._contact)); // Determine incoming media from incoming SDP offer (if any).
  14408. var sdp = request.parseSDP(); // Make sure sdp.media is an array, not the case if there is only one media.
  14409. if (!Array.isArray(sdp.media)) {
  14410. sdp.media = [sdp.media];
  14411. } // Go through all medias in SDP to find offered capabilities to answer with.
  14412. var _iteratorNormalCompletion = true;
  14413. var _didIteratorError = false;
  14414. var _iteratorError = undefined;
  14415. try {
  14416. for (var _iterator = sdp.media[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  14417. var m = _step.value;
  14418. if (m.type === 'audio') {
  14419. peerHasAudioLine = true;
  14420. if (!m.direction || m.direction === 'sendrecv') {
  14421. peerOffersFullAudio = true;
  14422. }
  14423. }
  14424. if (m.type === 'video') {
  14425. peerHasVideoLine = true;
  14426. if (!m.direction || m.direction === 'sendrecv') {
  14427. peerOffersFullVideo = true;
  14428. }
  14429. }
  14430. } // Remove audio from mediaStream if suggested by mediaConstraints.
  14431. } catch (err) {
  14432. _didIteratorError = true;
  14433. _iteratorError = err;
  14434. } finally {
  14435. try {
  14436. if (!_iteratorNormalCompletion && _iterator.return != null) {
  14437. _iterator.return();
  14438. }
  14439. } finally {
  14440. if (_didIteratorError) {
  14441. throw _iteratorError;
  14442. }
  14443. }
  14444. }
  14445. if (mediaStream && mediaConstraints.audio === false) {
  14446. tracks = mediaStream.getAudioTracks();
  14447. var _iteratorNormalCompletion2 = true;
  14448. var _didIteratorError2 = false;
  14449. var _iteratorError2 = undefined;
  14450. try {
  14451. for (var _iterator2 = tracks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  14452. var track = _step2.value;
  14453. mediaStream.removeTrack(track);
  14454. }
  14455. } catch (err) {
  14456. _didIteratorError2 = true;
  14457. _iteratorError2 = err;
  14458. } finally {
  14459. try {
  14460. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  14461. _iterator2.return();
  14462. }
  14463. } finally {
  14464. if (_didIteratorError2) {
  14465. throw _iteratorError2;
  14466. }
  14467. }
  14468. }
  14469. } // Remove video from mediaStream if suggested by mediaConstraints.
  14470. if (mediaStream && mediaConstraints.video === false) {
  14471. tracks = mediaStream.getVideoTracks();
  14472. var _iteratorNormalCompletion3 = true;
  14473. var _didIteratorError3 = false;
  14474. var _iteratorError3 = undefined;
  14475. try {
  14476. for (var _iterator3 = tracks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  14477. var _track = _step3.value;
  14478. mediaStream.removeTrack(_track);
  14479. }
  14480. } catch (err) {
  14481. _didIteratorError3 = true;
  14482. _iteratorError3 = err;
  14483. } finally {
  14484. try {
  14485. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  14486. _iterator3.return();
  14487. }
  14488. } finally {
  14489. if (_didIteratorError3) {
  14490. throw _iteratorError3;
  14491. }
  14492. }
  14493. }
  14494. } // Set audio constraints based on incoming stream if not supplied.
  14495. if (!mediaStream && mediaConstraints.audio === undefined) {
  14496. mediaConstraints.audio = peerOffersFullAudio;
  14497. } // Set video constraints based on incoming stream if not supplied.
  14498. if (!mediaStream && mediaConstraints.video === undefined) {
  14499. mediaConstraints.video = peerOffersFullVideo;
  14500. } // Don't ask for audio if the incoming offer has no audio section.
  14501. if (!mediaStream && !peerHasAudioLine) {
  14502. mediaConstraints.audio = false;
  14503. } // Don't ask for video if the incoming offer has no video section.
  14504. if (!mediaStream && !peerHasVideoLine) {
  14505. mediaConstraints.video = false;
  14506. } // Create a new RTCPeerConnection instance.
  14507. // TODO: This may throw an error, should react.
  14508. this._createRTCConnection(pcConfig, rtcConstraints);
  14509. Promise.resolve() // Handle local MediaStream.
  14510. .then(function () {
  14511. // A local MediaStream is given, use it.
  14512. if (mediaStream) {
  14513. return mediaStream;
  14514. } // Audio and/or video requested, prompt getUserMedia.
  14515. else if (mediaConstraints.audio || mediaConstraints.video) {
  14516. _this3._localMediaStreamLocallyGenerated = true;
  14517. return navigator.mediaDevices.getUserMedia(mediaConstraints).catch(function (error) {
  14518. if (_this3._status === C.STATUS_TERMINATED) {
  14519. throw new Error('terminated');
  14520. }
  14521. request.reply(480);
  14522. _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  14523. debugerror('emit "getusermediafailed" [error:%o]', error);
  14524. _this3.emit('getusermediafailed', error);
  14525. throw new Error('getUserMedia() failed');
  14526. });
  14527. }
  14528. }) // Attach MediaStream to RTCPeerconnection.
  14529. .then(function (stream) {
  14530. if (_this3._status === C.STATUS_TERMINATED) {
  14531. throw new Error('terminated');
  14532. }
  14533. _this3._localMediaStream = stream;
  14534. if (stream) {
  14535. stream.getTracks().forEach(function (track) {
  14536. _this3._connection.addTrack(track, stream);
  14537. });
  14538. }
  14539. }) // Set remote description.
  14540. .then(function () {
  14541. if (_this3._late_sdp) {
  14542. return;
  14543. }
  14544. var e = {
  14545. originator: 'remote',
  14546. type: 'offer',
  14547. sdp: request.body
  14548. };
  14549. debug('emit "sdp"');
  14550. _this3.emit('sdp', e);
  14551. var offer = new RTCSessionDescription({
  14552. type: 'offer',
  14553. sdp: e.sdp
  14554. });
  14555. _this3._connectionPromiseQueue = _this3._connectionPromiseQueue.then(function () {
  14556. return _this3._connection.setRemoteDescription(offer);
  14557. }).catch(function (error) {
  14558. request.reply(488);
  14559. _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR);
  14560. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  14561. _this3.emit('peerconnection:setremotedescriptionfailed', error);
  14562. throw new Error('peerconnection.setRemoteDescription() failed');
  14563. });
  14564. return _this3._connectionPromiseQueue;
  14565. }) // Create local description.
  14566. .then(function () {
  14567. if (_this3._status === C.STATUS_TERMINATED) {
  14568. throw new Error('terminated');
  14569. } // TODO: Is this event already useful?
  14570. _this3._connecting(request);
  14571. if (!_this3._late_sdp) {
  14572. return _this3._createLocalDescription('answer', rtcAnswerConstraints).catch(function () {
  14573. request.reply(500);
  14574. throw new Error('_createLocalDescription() failed');
  14575. });
  14576. } else {
  14577. return _this3._createLocalDescription('offer', _this3._rtcOfferConstraints).catch(function () {
  14578. request.reply(500);
  14579. throw new Error('_createLocalDescription() failed');
  14580. });
  14581. }
  14582. }) // Send reply.
  14583. .then(function (desc) {
  14584. if (_this3._status === C.STATUS_TERMINATED) {
  14585. throw new Error('terminated');
  14586. }
  14587. _this3._handleSessionTimersInIncomingRequest(request, extraHeaders);
  14588. request.reply(200, null, extraHeaders, desc, function () {
  14589. _this3._status = C.STATUS_WAITING_FOR_ACK;
  14590. _this3._setInvite2xxTimer(request, desc);
  14591. _this3._setACKTimer();
  14592. _this3._accepted('local');
  14593. }, function () {
  14594. _this3._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  14595. });
  14596. }).catch(function (error) {
  14597. if (_this3._status === C.STATUS_TERMINATED) {
  14598. return;
  14599. }
  14600. debugerror(error);
  14601. });
  14602. }
  14603. /**
  14604. * Terminate the call.
  14605. */
  14606. }, {
  14607. key: "terminate",
  14608. value: function terminate() {
  14609. var _this4 = this;
  14610. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14611. debug('terminate()');
  14612. var cause = options.cause || JsSIP_C.causes.BYE;
  14613. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14614. var body = options.body;
  14615. var cancel_reason;
  14616. var status_code = options.status_code;
  14617. var reason_phrase = options.reason_phrase; // Check Session Status.
  14618. if (this._status === C.STATUS_TERMINATED) {
  14619. throw new Exceptions.InvalidStateError(this._status);
  14620. }
  14621. switch (this._status) {
  14622. // - UAC -
  14623. case C.STATUS_NULL:
  14624. case C.STATUS_INVITE_SENT:
  14625. case C.STATUS_1XX_RECEIVED:
  14626. debug('canceling session');
  14627. if (status_code && (status_code < 200 || status_code >= 700)) {
  14628. throw new TypeError("Invalid status_code: ".concat(status_code));
  14629. } else if (status_code) {
  14630. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  14631. cancel_reason = "SIP ;cause=".concat(status_code, " ;text=\"").concat(reason_phrase, "\"");
  14632. } // Check Session Status.
  14633. if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) {
  14634. this._is_canceled = true;
  14635. this._cancel_reason = cancel_reason;
  14636. } else if (this._status === C.STATUS_1XX_RECEIVED) {
  14637. this._request.cancel(cancel_reason);
  14638. }
  14639. this._status = C.STATUS_CANCELED;
  14640. this._failed('local', null, JsSIP_C.causes.CANCELED);
  14641. break;
  14642. // - UAS -
  14643. case C.STATUS_WAITING_FOR_ANSWER:
  14644. case C.STATUS_ANSWERED:
  14645. debug('rejecting session');
  14646. status_code = status_code || 480;
  14647. if (status_code < 300 || status_code >= 700) {
  14648. throw new TypeError("Invalid status_code: ".concat(status_code));
  14649. }
  14650. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  14651. this._failed('local', null, JsSIP_C.causes.REJECTED);
  14652. break;
  14653. case C.STATUS_WAITING_FOR_ACK:
  14654. case C.STATUS_CONFIRMED:
  14655. debug('terminating session');
  14656. reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  14657. if (status_code && (status_code < 200 || status_code >= 700)) {
  14658. throw new TypeError("Invalid status_code: ".concat(status_code));
  14659. } else if (status_code) {
  14660. extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\""));
  14661. }
  14662. /* RFC 3261 section 15 (Terminating a session):
  14663. *
  14664. * "...the callee's UA MUST NOT send a BYE on a confirmed dialog
  14665. * until it has received an ACK for its 2xx response or until the server
  14666. * transaction times out."
  14667. */
  14668. if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) {
  14669. // Save the dialog for later restoration.
  14670. var dialog = this._dialog; // Send the BYE as soon as the ACK is received...
  14671. this.receiveRequest = function (_ref) {
  14672. var method = _ref.method;
  14673. if (method === JsSIP_C.ACK) {
  14674. _this4.sendRequest(JsSIP_C.BYE, {
  14675. extraHeaders: extraHeaders,
  14676. body: body
  14677. });
  14678. dialog.terminate();
  14679. }
  14680. }; // .., or when the INVITE transaction times out
  14681. this._request.server_transaction.on('stateChanged', function () {
  14682. if (_this4._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) {
  14683. _this4.sendRequest(JsSIP_C.BYE, {
  14684. extraHeaders: extraHeaders,
  14685. body: body
  14686. });
  14687. dialog.terminate();
  14688. }
  14689. });
  14690. this._ended('local', null, cause); // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-).
  14691. this._dialog = dialog; // Restore the dialog into 'ua' so the ACK can reach 'this' session.
  14692. this._ua.newDialog(dialog);
  14693. } else {
  14694. this.sendRequest(JsSIP_C.BYE, {
  14695. extraHeaders: extraHeaders,
  14696. body: body
  14697. });
  14698. this._ended('local', null, cause);
  14699. }
  14700. }
  14701. }
  14702. }, {
  14703. key: "sendDTMF",
  14704. value: function sendDTMF(tones) {
  14705. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  14706. debug('sendDTMF() | tones: %s', tones);
  14707. var position = 0;
  14708. var duration = options.duration || null;
  14709. var interToneGap = options.interToneGap || null;
  14710. if (tones === undefined) {
  14711. throw new TypeError('Not enough arguments');
  14712. } // Check Session Status.
  14713. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) {
  14714. throw new Exceptions.InvalidStateError(this._status);
  14715. } // Convert to string.
  14716. if (typeof tones === 'number') {
  14717. tones = tones.toString();
  14718. } // Check tones.
  14719. if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) {
  14720. throw new TypeError("Invalid tones: ".concat(tones));
  14721. } // Check duration.
  14722. if (duration && !Utils.isDecimal(duration)) {
  14723. throw new TypeError("Invalid tone duration: ".concat(duration));
  14724. } else if (!duration) {
  14725. duration = RTCSession_DTMF.C.DEFAULT_DURATION;
  14726. } else if (duration < RTCSession_DTMF.C.MIN_DURATION) {
  14727. debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds"));
  14728. duration = RTCSession_DTMF.C.MIN_DURATION;
  14729. } else if (duration > RTCSession_DTMF.C.MAX_DURATION) {
  14730. debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds"));
  14731. duration = RTCSession_DTMF.C.MAX_DURATION;
  14732. } else {
  14733. duration = Math.abs(duration);
  14734. }
  14735. options.duration = duration; // Check interToneGap.
  14736. if (interToneGap && !Utils.isDecimal(interToneGap)) {
  14737. throw new TypeError("Invalid interToneGap: ".concat(interToneGap));
  14738. } else if (!interToneGap) {
  14739. interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP;
  14740. } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) {
  14741. debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds"));
  14742. interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP;
  14743. } else {
  14744. interToneGap = Math.abs(interToneGap);
  14745. }
  14746. if (this._tones) {
  14747. // Tones are already queued, just add to the queue.
  14748. this._tones += tones;
  14749. return;
  14750. }
  14751. this._tones = tones; // Send the first tone.
  14752. _sendDTMF.call(this);
  14753. function _sendDTMF() {
  14754. var _this5 = this;
  14755. var timeout;
  14756. if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) {
  14757. // Stop sending DTMF.
  14758. this._tones = null;
  14759. return;
  14760. }
  14761. var tone = this._tones[position];
  14762. position += 1;
  14763. if (tone === ',') {
  14764. timeout = 2000;
  14765. } else {
  14766. var dtmf = new RTCSession_DTMF(this);
  14767. options.eventHandlers = {
  14768. onFailed: function onFailed() {
  14769. _this5._tones = null;
  14770. }
  14771. };
  14772. dtmf.send(tone, options);
  14773. timeout = duration + interToneGap;
  14774. } // Set timeout for the next tone.
  14775. setTimeout(_sendDTMF.bind(this), timeout);
  14776. }
  14777. }
  14778. }, {
  14779. key: "sendInfo",
  14780. value: function sendInfo(contentType, body) {
  14781. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  14782. debug('sendInfo()'); // Check Session Status.
  14783. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) {
  14784. throw new Exceptions.InvalidStateError(this._status);
  14785. }
  14786. var info = new RTCSession_Info(this);
  14787. info.send(contentType, body, options);
  14788. }
  14789. /**
  14790. * Mute
  14791. */
  14792. }, {
  14793. key: "mute",
  14794. value: function mute() {
  14795. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  14796. audio: true,
  14797. video: false
  14798. };
  14799. debug('mute()');
  14800. var audioMuted = false,
  14801. videoMuted = false;
  14802. if (this._audioMuted === false && options.audio) {
  14803. audioMuted = true;
  14804. this._audioMuted = true;
  14805. this._toggleMuteAudio(true);
  14806. }
  14807. if (this._videoMuted === false && options.video) {
  14808. videoMuted = true;
  14809. this._videoMuted = true;
  14810. this._toggleMuteVideo(true);
  14811. }
  14812. if (audioMuted === true || videoMuted === true) {
  14813. this._onmute({
  14814. audio: audioMuted,
  14815. video: videoMuted
  14816. });
  14817. }
  14818. }
  14819. /**
  14820. * Unmute
  14821. */
  14822. }, {
  14823. key: "unmute",
  14824. value: function unmute() {
  14825. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  14826. audio: true,
  14827. video: true
  14828. };
  14829. debug('unmute()');
  14830. var audioUnMuted = false,
  14831. videoUnMuted = false;
  14832. if (this._audioMuted === true && options.audio) {
  14833. audioUnMuted = true;
  14834. this._audioMuted = false;
  14835. if (this._localHold === false) {
  14836. this._toggleMuteAudio(false);
  14837. }
  14838. }
  14839. if (this._videoMuted === true && options.video) {
  14840. videoUnMuted = true;
  14841. this._videoMuted = false;
  14842. if (this._localHold === false) {
  14843. this._toggleMuteVideo(false);
  14844. }
  14845. }
  14846. if (audioUnMuted === true || videoUnMuted === true) {
  14847. this._onunmute({
  14848. audio: audioUnMuted,
  14849. video: videoUnMuted
  14850. });
  14851. }
  14852. }
  14853. /**
  14854. * Hold
  14855. */
  14856. }, {
  14857. key: "hold",
  14858. value: function hold() {
  14859. var _this6 = this;
  14860. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14861. var done = arguments.length > 1 ? arguments[1] : undefined;
  14862. debug('hold()');
  14863. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  14864. return false;
  14865. }
  14866. if (this._localHold === true) {
  14867. return false;
  14868. }
  14869. if (!this._isReadyToReOffer()) {
  14870. return false;
  14871. }
  14872. this._localHold = true;
  14873. this._onhold('local');
  14874. var eventHandlers = {
  14875. succeeded: function succeeded() {
  14876. if (done) {
  14877. done();
  14878. }
  14879. },
  14880. failed: function failed() {
  14881. _this6.terminate({
  14882. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14883. status_code: 500,
  14884. reason_phrase: 'Hold Failed'
  14885. });
  14886. }
  14887. };
  14888. if (options.useUpdate) {
  14889. this._sendUpdate({
  14890. sdpOffer: true,
  14891. eventHandlers: eventHandlers,
  14892. extraHeaders: options.extraHeaders
  14893. });
  14894. } else {
  14895. this._sendReinvite({
  14896. eventHandlers: eventHandlers,
  14897. extraHeaders: options.extraHeaders
  14898. });
  14899. }
  14900. return true;
  14901. }
  14902. }, {
  14903. key: "unhold",
  14904. value: function unhold() {
  14905. var _this7 = this;
  14906. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14907. var done = arguments.length > 1 ? arguments[1] : undefined;
  14908. debug('unhold()');
  14909. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  14910. return false;
  14911. }
  14912. if (this._localHold === false) {
  14913. return false;
  14914. }
  14915. if (!this._isReadyToReOffer()) {
  14916. return false;
  14917. }
  14918. this._localHold = false;
  14919. this._onunhold('local');
  14920. var eventHandlers = {
  14921. succeeded: function succeeded() {
  14922. if (done) {
  14923. done();
  14924. }
  14925. },
  14926. failed: function failed() {
  14927. _this7.terminate({
  14928. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14929. status_code: 500,
  14930. reason_phrase: 'Unhold Failed'
  14931. });
  14932. }
  14933. };
  14934. if (options.useUpdate) {
  14935. this._sendUpdate({
  14936. sdpOffer: true,
  14937. eventHandlers: eventHandlers,
  14938. extraHeaders: options.extraHeaders
  14939. });
  14940. } else {
  14941. this._sendReinvite({
  14942. eventHandlers: eventHandlers,
  14943. extraHeaders: options.extraHeaders
  14944. });
  14945. }
  14946. return true;
  14947. }
  14948. }, {
  14949. key: "renegotiate",
  14950. value: function renegotiate() {
  14951. var _this8 = this;
  14952. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14953. var done = arguments.length > 1 ? arguments[1] : undefined;
  14954. debug('renegotiate()');
  14955. var rtcOfferConstraints = options.rtcOfferConstraints || null;
  14956. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  14957. return false;
  14958. }
  14959. if (!this._isReadyToReOffer()) {
  14960. return false;
  14961. }
  14962. var eventHandlers = {
  14963. succeeded: function succeeded() {
  14964. if (done) {
  14965. done();
  14966. }
  14967. },
  14968. failed: function failed() {
  14969. _this8.terminate({
  14970. cause: JsSIP_C.causes.WEBRTC_ERROR,
  14971. status_code: 500,
  14972. reason_phrase: 'Media Renegotiation Failed'
  14973. });
  14974. }
  14975. };
  14976. this._setLocalMediaStatus();
  14977. if (options.useUpdate) {
  14978. this._sendUpdate({
  14979. sdpOffer: true,
  14980. eventHandlers: eventHandlers,
  14981. rtcOfferConstraints: rtcOfferConstraints,
  14982. extraHeaders: options.extraHeaders
  14983. });
  14984. } else {
  14985. this._sendReinvite({
  14986. eventHandlers: eventHandlers,
  14987. rtcOfferConstraints: rtcOfferConstraints,
  14988. extraHeaders: options.extraHeaders
  14989. });
  14990. }
  14991. return true;
  14992. }
  14993. /**
  14994. * Refer
  14995. */
  14996. }, {
  14997. key: "refer",
  14998. value: function refer(target, options) {
  14999. var _this9 = this;
  15000. debug('refer()');
  15001. var originalTarget = target;
  15002. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15003. return false;
  15004. } // Check target validity.
  15005. target = this._ua.normalizeTarget(target);
  15006. if (!target) {
  15007. throw new TypeError("Invalid target: ".concat(originalTarget));
  15008. }
  15009. var referSubscriber = new RTCSession_ReferSubscriber(this);
  15010. referSubscriber.sendRefer(target, options); // Store in the map.
  15011. var id = referSubscriber.id;
  15012. this._referSubscribers[id] = referSubscriber; // Listen for ending events so we can remove it from the map.
  15013. referSubscriber.on('requestFailed', function () {
  15014. delete _this9._referSubscribers[id];
  15015. });
  15016. referSubscriber.on('accepted', function () {
  15017. delete _this9._referSubscribers[id];
  15018. });
  15019. referSubscriber.on('failed', function () {
  15020. delete _this9._referSubscribers[id];
  15021. });
  15022. return referSubscriber;
  15023. }
  15024. /**
  15025. * Send a generic in-dialog Request
  15026. */
  15027. }, {
  15028. key: "sendRequest",
  15029. value: function sendRequest(method, options) {
  15030. debug('sendRequest()');
  15031. return this._dialog.sendRequest(method, options);
  15032. }
  15033. /**
  15034. * In dialog Request Reception
  15035. */
  15036. }, {
  15037. key: "receiveRequest",
  15038. value: function receiveRequest(request) {
  15039. var _this10 = this;
  15040. debug('receiveRequest()');
  15041. if (request.method === JsSIP_C.CANCEL) {
  15042. /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL
  15043. * was in progress and that the UAC MAY continue with the session established by
  15044. * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the
  15045. * established session. So the CANCEL is processed only if the session is not yet
  15046. * established.
  15047. */
  15048. /*
  15049. * Terminate the whole session in case the user didn't accept (or yet send the answer)
  15050. * nor reject the request opening the session.
  15051. */
  15052. if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) {
  15053. this._status = C.STATUS_CANCELED;
  15054. this._request.reply(487);
  15055. this._failed('remote', request, JsSIP_C.causes.CANCELED);
  15056. }
  15057. } else {
  15058. // Requests arriving here are in-dialog requests.
  15059. switch (request.method) {
  15060. case JsSIP_C.ACK:
  15061. if (this._status !== C.STATUS_WAITING_FOR_ACK) {
  15062. return;
  15063. } // Update signaling status.
  15064. this._status = C.STATUS_CONFIRMED;
  15065. clearTimeout(this._timers.ackTimer);
  15066. clearTimeout(this._timers.invite2xxTimer);
  15067. if (this._late_sdp) {
  15068. if (!request.body) {
  15069. this.terminate({
  15070. cause: JsSIP_C.causes.MISSING_SDP,
  15071. status_code: 400
  15072. });
  15073. break;
  15074. }
  15075. var e = {
  15076. originator: 'remote',
  15077. type: 'answer',
  15078. sdp: request.body
  15079. };
  15080. debug('emit "sdp"');
  15081. this.emit('sdp', e);
  15082. var answer = new RTCSessionDescription({
  15083. type: 'answer',
  15084. sdp: e.sdp
  15085. });
  15086. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15087. return _this10._connection.setRemoteDescription(answer);
  15088. }).then(function () {
  15089. if (!_this10._is_confirmed) {
  15090. _this10._confirmed('remote', request);
  15091. }
  15092. }).catch(function (error) {
  15093. _this10.terminate({
  15094. cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION,
  15095. status_code: 488
  15096. });
  15097. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15098. _this10.emit('peerconnection:setremotedescriptionfailed', error);
  15099. });
  15100. } else if (!this._is_confirmed) {
  15101. this._confirmed('remote', request);
  15102. }
  15103. break;
  15104. case JsSIP_C.BYE:
  15105. if (this._status === C.STATUS_CONFIRMED || this._status === C.STATUS_WAITING_FOR_ACK) {
  15106. request.reply(200);
  15107. this._ended('remote', request, JsSIP_C.causes.BYE);
  15108. } else if (this._status === C.STATUS_INVITE_RECEIVED) {
  15109. request.reply(200);
  15110. this._request.reply(487, 'BYE Received');
  15111. this._ended('remote', request, JsSIP_C.causes.BYE);
  15112. } else {
  15113. request.reply(403, 'Wrong Status');
  15114. }
  15115. break;
  15116. case JsSIP_C.INVITE:
  15117. if (this._status === C.STATUS_CONFIRMED) {
  15118. if (request.hasHeader('replaces')) {
  15119. this._receiveReplaces(request);
  15120. } else {
  15121. this._receiveReinvite(request);
  15122. }
  15123. } else {
  15124. request.reply(403, 'Wrong Status');
  15125. }
  15126. break;
  15127. case JsSIP_C.INFO:
  15128. if (this._status === C.STATUS_1XX_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED || this._status === C.STATUS_WAITING_FOR_ACK || this._status === C.STATUS_CONFIRMED) {
  15129. var contentType = request.getHeader('content-type');
  15130. if (contentType && contentType.match(/^application\/dtmf-relay/i)) {
  15131. new RTCSession_DTMF(this).init_incoming(request);
  15132. } else if (contentType !== undefined) {
  15133. new RTCSession_Info(this).init_incoming(request);
  15134. } else {
  15135. request.reply(415);
  15136. }
  15137. } else {
  15138. request.reply(403, 'Wrong Status');
  15139. }
  15140. break;
  15141. case JsSIP_C.UPDATE:
  15142. if (this._status === C.STATUS_CONFIRMED) {
  15143. this._receiveUpdate(request);
  15144. } else {
  15145. request.reply(403, 'Wrong Status');
  15146. }
  15147. break;
  15148. case JsSIP_C.REFER:
  15149. if (this._status === C.STATUS_CONFIRMED) {
  15150. this._receiveRefer(request);
  15151. } else {
  15152. request.reply(403, 'Wrong Status');
  15153. }
  15154. break;
  15155. case JsSIP_C.NOTIFY:
  15156. if (this._status === C.STATUS_CONFIRMED) {
  15157. this._receiveNotify(request);
  15158. } else {
  15159. request.reply(403, 'Wrong Status');
  15160. }
  15161. break;
  15162. default:
  15163. request.reply(501);
  15164. }
  15165. }
  15166. }
  15167. /**
  15168. * Session Callbacks
  15169. */
  15170. }, {
  15171. key: "onTransportError",
  15172. value: function onTransportError() {
  15173. debugerror('onTransportError()');
  15174. if (this._status !== C.STATUS_TERMINATED) {
  15175. this.terminate({
  15176. status_code: 500,
  15177. reason_phrase: JsSIP_C.causes.CONNECTION_ERROR,
  15178. cause: JsSIP_C.causes.CONNECTION_ERROR
  15179. });
  15180. }
  15181. }
  15182. }, {
  15183. key: "onRequestTimeout",
  15184. value: function onRequestTimeout() {
  15185. debugerror('onRequestTimeout()');
  15186. if (this._status !== C.STATUS_TERMINATED) {
  15187. this.terminate({
  15188. status_code: 408,
  15189. reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT,
  15190. cause: JsSIP_C.causes.REQUEST_TIMEOUT
  15191. });
  15192. }
  15193. }
  15194. }, {
  15195. key: "onDialogError",
  15196. value: function onDialogError() {
  15197. debugerror('onDialogError()');
  15198. if (this._status !== C.STATUS_TERMINATED) {
  15199. this.terminate({
  15200. status_code: 500,
  15201. reason_phrase: JsSIP_C.causes.DIALOG_ERROR,
  15202. cause: JsSIP_C.causes.DIALOG_ERROR
  15203. });
  15204. }
  15205. } // Called from DTMF handler.
  15206. }, {
  15207. key: "newDTMF",
  15208. value: function newDTMF(data) {
  15209. debug('newDTMF()');
  15210. this.emit('newDTMF', data);
  15211. } // Called from Info handler.
  15212. }, {
  15213. key: "newInfo",
  15214. value: function newInfo(data) {
  15215. debug('newInfo()');
  15216. this.emit('newInfo', data);
  15217. }
  15218. /**
  15219. * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP.
  15220. */
  15221. }, {
  15222. key: "_isReadyToReOffer",
  15223. value: function _isReadyToReOffer() {
  15224. if (!this._rtcReady) {
  15225. debug('_isReadyToReOffer() | internal WebRTC status not ready');
  15226. return false;
  15227. } // No established yet.
  15228. if (!this._dialog) {
  15229. debug('_isReadyToReOffer() | session not established yet');
  15230. return false;
  15231. } // Another INVITE transaction is in progress.
  15232. if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) {
  15233. debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress');
  15234. return false;
  15235. }
  15236. return true;
  15237. }
  15238. }, {
  15239. key: "_close",
  15240. value: function _close() {
  15241. debug('close()');
  15242. if (this._status === C.STATUS_TERMINATED) {
  15243. return;
  15244. }
  15245. this._status = C.STATUS_TERMINATED; // Terminate RTC.
  15246. if (this._connection) {
  15247. try {
  15248. this._connection.close();
  15249. } catch (error) {
  15250. debugerror('close() | error closing the RTCPeerConnection: %o', error);
  15251. }
  15252. } // Close local MediaStream if it was not given by the user.
  15253. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) {
  15254. debug('close() | closing local MediaStream');
  15255. Utils.closeMediaStream(this._localMediaStream);
  15256. } // Terminate signaling.
  15257. // Clear SIP timers.
  15258. for (var timer in this._timers) {
  15259. if (Object.prototype.hasOwnProperty.call(this._timers, timer)) {
  15260. clearTimeout(this._timers[timer]);
  15261. }
  15262. } // Clear Session Timers.
  15263. clearTimeout(this._sessionTimers.timer); // Terminate confirmed dialog.
  15264. if (this._dialog) {
  15265. this._dialog.terminate();
  15266. delete this._dialog;
  15267. } // Terminate early dialogs.
  15268. for (var dialog in this._earlyDialogs) {
  15269. if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) {
  15270. this._earlyDialogs[dialog].terminate();
  15271. delete this._earlyDialogs[dialog];
  15272. }
  15273. } // Terminate REFER subscribers.
  15274. for (var subscriber in this._referSubscribers) {
  15275. if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) {
  15276. delete this._referSubscribers[subscriber];
  15277. }
  15278. }
  15279. this._ua.destroyRTCSession(this);
  15280. }
  15281. /**
  15282. * Private API.
  15283. */
  15284. /**
  15285. * RFC3261 13.3.1.4
  15286. * Response retransmissions cannot be accomplished by transaction layer
  15287. * since it is destroyed when receiving the first 2xx answer
  15288. */
  15289. }, {
  15290. key: "_setInvite2xxTimer",
  15291. value: function _setInvite2xxTimer(request, body) {
  15292. var timeout = Timers.T1;
  15293. function invite2xxRetransmission() {
  15294. if (this._status !== C.STATUS_WAITING_FOR_ACK) {
  15295. return;
  15296. }
  15297. request.reply(200, null, ["Contact: ".concat(this._contact)], body);
  15298. if (timeout < Timers.T2) {
  15299. timeout = timeout * 2;
  15300. if (timeout > Timers.T2) {
  15301. timeout = Timers.T2;
  15302. }
  15303. }
  15304. this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
  15305. }
  15306. this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
  15307. }
  15308. /**
  15309. * RFC3261 14.2
  15310. * If a UAS generates a 2xx response and never receives an ACK,
  15311. * it SHOULD generate a BYE to terminate the dialog.
  15312. */
  15313. }, {
  15314. key: "_setACKTimer",
  15315. value: function _setACKTimer() {
  15316. var _this11 = this;
  15317. this._timers.ackTimer = setTimeout(function () {
  15318. if (_this11._status === C.STATUS_WAITING_FOR_ACK) {
  15319. debug('no ACK received, terminating the session');
  15320. clearTimeout(_this11._timers.invite2xxTimer);
  15321. _this11.sendRequest(JsSIP_C.BYE);
  15322. _this11._ended('remote', null, JsSIP_C.causes.NO_ACK);
  15323. }
  15324. }, Timers.TIMER_H);
  15325. }
  15326. }, {
  15327. key: "_createRTCConnection",
  15328. value: function _createRTCConnection(pcConfig, rtcConstraints) {
  15329. var _this12 = this;
  15330. this._connection = new RTCPeerConnection(pcConfig, rtcConstraints);
  15331. this._connection.addEventListener('iceconnectionstatechange', function () {
  15332. var state = _this12._connection.iceConnectionState; // TODO: Do more with different states.
  15333. if (state === 'failed') {
  15334. _this12.terminate({
  15335. cause: JsSIP_C.causes.RTP_TIMEOUT,
  15336. status_code: 408,
  15337. reason_phrase: JsSIP_C.causes.RTP_TIMEOUT
  15338. });
  15339. }
  15340. });
  15341. debug('emit "peerconnection"');
  15342. this.emit('peerconnection', {
  15343. peerconnection: this._connection
  15344. });
  15345. }
  15346. }, {
  15347. key: "_createLocalDescription",
  15348. value: function _createLocalDescription(type, constraints) {
  15349. var _this13 = this;
  15350. debug('createLocalDescription()');
  15351. if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\""));
  15352. var connection = this._connection;
  15353. this._rtcReady = false;
  15354. return Promise.resolve() // Create Offer or Answer.
  15355. .then(function () {
  15356. if (type === 'offer') {
  15357. return connection.createOffer(constraints).catch(function (error) {
  15358. debugerror('emit "peerconnection:createofferfailed" [error:%o]', error);
  15359. _this13.emit('peerconnection:createofferfailed', error);
  15360. return Promise.reject(error);
  15361. });
  15362. } else {
  15363. return connection.createAnswer(constraints).catch(function (error) {
  15364. debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error);
  15365. _this13.emit('peerconnection:createanswerfailed', error);
  15366. return Promise.reject(error);
  15367. });
  15368. }
  15369. }) // Set local description.
  15370. .then(function (desc) {
  15371. return connection.setLocalDescription(desc).catch(function (error) {
  15372. _this13._rtcReady = true;
  15373. debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error);
  15374. _this13.emit('peerconnection:setlocaldescriptionfailed', error);
  15375. return Promise.reject(error);
  15376. });
  15377. }).then(function () {
  15378. // Resolve right away if 'pc.iceGatheringState' is 'complete'.
  15379. if (connection.iceGatheringState === 'complete') {
  15380. _this13._rtcReady = true;
  15381. var e = {
  15382. originator: 'local',
  15383. type: type,
  15384. sdp: connection.localDescription.sdp
  15385. };
  15386. debug('emit "sdp"');
  15387. _this13.emit('sdp', e);
  15388. return Promise.resolve(e.sdp);
  15389. } // Add 'pc.onicencandidate' event handler to resolve on last candidate.
  15390. return new Promise(function (resolve) {
  15391. var finished = false;
  15392. var iceCandidateListener;
  15393. var iceGatheringStateListener;
  15394. var ready = function ready() {
  15395. connection.removeEventListener('icecandidate', iceCandidateListener);
  15396. connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener);
  15397. finished = true;
  15398. _this13._rtcReady = true;
  15399. var e = {
  15400. originator: 'local',
  15401. type: type,
  15402. sdp: connection.localDescription.sdp
  15403. };
  15404. debug('emit "sdp"');
  15405. _this13.emit('sdp', e);
  15406. resolve(e.sdp);
  15407. };
  15408. connection.addEventListener('icecandidate', iceCandidateListener = function iceCandidateListener(event) {
  15409. var candidate = event.candidate;
  15410. if (candidate) {
  15411. _this13.emit('icecandidate', {
  15412. candidate: candidate,
  15413. ready: ready
  15414. });
  15415. } else if (!finished) {
  15416. ready();
  15417. }
  15418. });
  15419. connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = function iceGatheringStateListener() {
  15420. if (connection.iceGatheringState === 'complete' && !finished) {
  15421. ready();
  15422. }
  15423. });
  15424. });
  15425. });
  15426. }
  15427. /**
  15428. * Dialog Management
  15429. */
  15430. }, {
  15431. key: "_createDialog",
  15432. value: function _createDialog(message, type, early) {
  15433. var local_tag = type === 'UAS' ? message.to_tag : message.from_tag;
  15434. var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag;
  15435. var id = message.call_id + local_tag + remote_tag;
  15436. var early_dialog = this._earlyDialogs[id]; // Early Dialog.
  15437. if (early) {
  15438. if (early_dialog) {
  15439. return true;
  15440. } else {
  15441. early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created.
  15442. if (early_dialog.error) {
  15443. debug(early_dialog.error);
  15444. this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  15445. return false;
  15446. } else {
  15447. this._earlyDialogs[id] = early_dialog;
  15448. return true;
  15449. }
  15450. }
  15451. } // Confirmed Dialog.
  15452. else {
  15453. this._from_tag = message.from_tag;
  15454. this._to_tag = message.to_tag; // In case the dialog is in _early_ state, update it.
  15455. if (early_dialog) {
  15456. early_dialog.update(message, type);
  15457. this._dialog = early_dialog;
  15458. delete this._earlyDialogs[id];
  15459. return true;
  15460. } // Otherwise, create a _confirmed_ dialog.
  15461. var dialog = new Dialog(this, message, type);
  15462. if (dialog.error) {
  15463. debug(dialog.error);
  15464. this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  15465. return false;
  15466. } else {
  15467. this._dialog = dialog;
  15468. return true;
  15469. }
  15470. }
  15471. }
  15472. /**
  15473. * In dialog INVITE Reception
  15474. */
  15475. }, {
  15476. key: "_receiveReinvite",
  15477. value: function _receiveReinvite(request) {
  15478. var _this14 = this;
  15479. debug('receiveReinvite()');
  15480. var contentType = request.getHeader('Content-Type');
  15481. var data = {
  15482. request: request,
  15483. callback: undefined,
  15484. reject: reject.bind(this)
  15485. };
  15486. var rejected = false;
  15487. function reject() {
  15488. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15489. rejected = true;
  15490. var status_code = options.status_code || 403;
  15491. var reason_phrase = options.reason_phrase || '';
  15492. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  15493. if (this._status !== C.STATUS_CONFIRMED) {
  15494. return false;
  15495. }
  15496. if (status_code < 300 || status_code >= 700) {
  15497. throw new TypeError("Invalid status_code: ".concat(status_code));
  15498. }
  15499. request.reply(status_code, reason_phrase, extraHeaders);
  15500. } // Emit 'reinvite'.
  15501. this.emit('reinvite', data);
  15502. if (rejected) {
  15503. return;
  15504. }
  15505. this._late_sdp = false; // Request without SDP.
  15506. if (!request.body) {
  15507. this._late_sdp = true;
  15508. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15509. return _this14._createLocalDescription('offer', _this14._rtcOfferConstraints);
  15510. }).then(function (sdp) {
  15511. sendAnswer.call(_this14, sdp);
  15512. }).catch(function () {
  15513. request.reply(500);
  15514. });
  15515. return;
  15516. } // Request with SDP.
  15517. if (contentType !== 'application/sdp') {
  15518. debug('invalid Content-Type');
  15519. request.reply(415);
  15520. return;
  15521. }
  15522. this._processInDialogSdpOffer(request) // Send answer.
  15523. .then(function (desc) {
  15524. if (_this14._status === C.STATUS_TERMINATED) {
  15525. return;
  15526. }
  15527. sendAnswer.call(_this14, desc);
  15528. }).catch(function (error) {
  15529. debugerror(error);
  15530. });
  15531. function sendAnswer(desc) {
  15532. var _this15 = this;
  15533. var extraHeaders = ["Contact: ".concat(this._contact)];
  15534. this._handleSessionTimersInIncomingRequest(request, extraHeaders);
  15535. if (this._late_sdp) {
  15536. desc = this._mangleOffer(desc);
  15537. }
  15538. request.reply(200, null, extraHeaders, desc, function () {
  15539. _this15._status = C.STATUS_WAITING_FOR_ACK;
  15540. _this15._setInvite2xxTimer(request, desc);
  15541. _this15._setACKTimer();
  15542. }); // If callback is given execute it.
  15543. if (typeof data.callback === 'function') {
  15544. data.callback();
  15545. }
  15546. }
  15547. }
  15548. /**
  15549. * In dialog UPDATE Reception
  15550. */
  15551. }, {
  15552. key: "_receiveUpdate",
  15553. value: function _receiveUpdate(request) {
  15554. var _this16 = this;
  15555. debug('receiveUpdate()');
  15556. var contentType = request.getHeader('Content-Type');
  15557. var data = {
  15558. request: request,
  15559. callback: undefined,
  15560. reject: reject.bind(this)
  15561. };
  15562. var rejected = false;
  15563. function reject() {
  15564. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15565. rejected = true;
  15566. var status_code = options.status_code || 403;
  15567. var reason_phrase = options.reason_phrase || '';
  15568. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  15569. if (this._status !== C.STATUS_CONFIRMED) {
  15570. return false;
  15571. }
  15572. if (status_code < 300 || status_code >= 700) {
  15573. throw new TypeError("Invalid status_code: ".concat(status_code));
  15574. }
  15575. request.reply(status_code, reason_phrase, extraHeaders);
  15576. } // Emit 'update'.
  15577. this.emit('update', data);
  15578. if (rejected) {
  15579. return;
  15580. }
  15581. if (!request.body) {
  15582. sendAnswer.call(this, null);
  15583. return;
  15584. }
  15585. if (contentType !== 'application/sdp') {
  15586. debug('invalid Content-Type');
  15587. request.reply(415);
  15588. return;
  15589. }
  15590. this._processInDialogSdpOffer(request) // Send answer.
  15591. .then(function (desc) {
  15592. if (_this16._status === C.STATUS_TERMINATED) {
  15593. return;
  15594. }
  15595. sendAnswer.call(_this16, desc);
  15596. }).catch(function (error) {
  15597. debugerror(error);
  15598. });
  15599. function sendAnswer(desc) {
  15600. var extraHeaders = ["Contact: ".concat(this._contact)];
  15601. this._handleSessionTimersInIncomingRequest(request, extraHeaders);
  15602. request.reply(200, null, extraHeaders, desc); // If callback is given execute it.
  15603. if (typeof data.callback === 'function') {
  15604. data.callback();
  15605. }
  15606. }
  15607. }
  15608. }, {
  15609. key: "_processInDialogSdpOffer",
  15610. value: function _processInDialogSdpOffer(request) {
  15611. var _this17 = this;
  15612. debug('_processInDialogSdpOffer()');
  15613. var sdp = request.parseSDP();
  15614. var hold = false;
  15615. var _iteratorNormalCompletion4 = true;
  15616. var _didIteratorError4 = false;
  15617. var _iteratorError4 = undefined;
  15618. try {
  15619. for (var _iterator4 = sdp.media[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  15620. var m = _step4.value;
  15621. if (holdMediaTypes.indexOf(m.type) === -1) {
  15622. continue;
  15623. }
  15624. var direction = m.direction || sdp.direction || 'sendrecv';
  15625. if (direction === 'sendonly' || direction === 'inactive') {
  15626. hold = true;
  15627. } // If at least one of the streams is active don't emit 'hold'.
  15628. else {
  15629. hold = false;
  15630. break;
  15631. }
  15632. }
  15633. } catch (err) {
  15634. _didIteratorError4 = true;
  15635. _iteratorError4 = err;
  15636. } finally {
  15637. try {
  15638. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  15639. _iterator4.return();
  15640. }
  15641. } finally {
  15642. if (_didIteratorError4) {
  15643. throw _iteratorError4;
  15644. }
  15645. }
  15646. }
  15647. var e = {
  15648. originator: 'remote',
  15649. type: 'offer',
  15650. sdp: request.body
  15651. };
  15652. debug('emit "sdp"');
  15653. this.emit('sdp', e);
  15654. var offer = new RTCSessionDescription({
  15655. type: 'offer',
  15656. sdp: e.sdp
  15657. });
  15658. this._connectionPromiseQueue = this._connectionPromiseQueue // Set remote description.
  15659. .then(function () {
  15660. if (_this17._status === C.STATUS_TERMINATED) {
  15661. throw new Error('terminated');
  15662. }
  15663. return _this17._connection.setRemoteDescription(offer).catch(function (error) {
  15664. request.reply(488);
  15665. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15666. _this17.emit('peerconnection:setremotedescriptionfailed', error);
  15667. throw new Error('peerconnection.setRemoteDescription() failed');
  15668. });
  15669. }).then(function () {
  15670. if (_this17._status === C.STATUS_TERMINATED) {
  15671. throw new Error('terminated');
  15672. }
  15673. if (_this17._remoteHold === true && hold === false) {
  15674. _this17._remoteHold = false;
  15675. _this17._onunhold('remote');
  15676. } else if (_this17._remoteHold === false && hold === true) {
  15677. _this17._remoteHold = true;
  15678. _this17._onhold('remote');
  15679. }
  15680. }) // Create local description.
  15681. .then(function () {
  15682. if (_this17._status === C.STATUS_TERMINATED) {
  15683. throw new Error('terminated');
  15684. }
  15685. return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints).catch(function () {
  15686. request.reply(500);
  15687. throw new Error('_createLocalDescription() failed');
  15688. });
  15689. });
  15690. return this._connectionPromiseQueue;
  15691. }
  15692. /**
  15693. * In dialog Refer Reception
  15694. */
  15695. }, {
  15696. key: "_receiveRefer",
  15697. value: function _receiveRefer(request) {
  15698. var _this18 = this;
  15699. debug('receiveRefer()');
  15700. if (!request.refer_to) {
  15701. debug('no Refer-To header field present in REFER');
  15702. request.reply(400);
  15703. return;
  15704. }
  15705. if (request.refer_to.uri.scheme !== JsSIP_C.SIP) {
  15706. debug('Refer-To header field points to a non-SIP URI scheme');
  15707. request.reply(416);
  15708. return;
  15709. } // Reply before the transaction timer expires.
  15710. request.reply(202);
  15711. var notifier = new RTCSession_ReferNotifier(this, request.cseq);
  15712. debug('emit "refer"'); // Emit 'refer'.
  15713. this.emit('refer', {
  15714. request: request,
  15715. accept: function accept(initCallback, options) {
  15716. _accept.call(_this18, initCallback, options);
  15717. },
  15718. reject: function reject() {
  15719. _reject.call(_this18);
  15720. }
  15721. });
  15722. function _accept(initCallback) {
  15723. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  15724. initCallback = typeof initCallback === 'function' ? initCallback : null;
  15725. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15726. return false;
  15727. }
  15728. var session = new RTCSession(this._ua);
  15729. session.on('progress', function (_ref2) {
  15730. var response = _ref2.response;
  15731. notifier.notify(response.status_code, response.reason_phrase);
  15732. });
  15733. session.on('accepted', function (_ref3) {
  15734. var response = _ref3.response;
  15735. notifier.notify(response.status_code, response.reason_phrase);
  15736. });
  15737. session.on('_failed', function (_ref4) {
  15738. var message = _ref4.message,
  15739. cause = _ref4.cause;
  15740. if (message) {
  15741. notifier.notify(message.status_code, message.reason_phrase);
  15742. } else {
  15743. notifier.notify(487, cause);
  15744. }
  15745. }); // Consider the Replaces header present in the Refer-To URI.
  15746. if (request.refer_to.uri.hasHeader('replaces')) {
  15747. var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces'));
  15748. options.extraHeaders = Utils.cloneArray(options.extraHeaders);
  15749. options.extraHeaders.push("Replaces: ".concat(replaces));
  15750. }
  15751. session.connect(request.refer_to.uri.toAor(), options, initCallback);
  15752. }
  15753. function _reject() {
  15754. notifier.notify(603);
  15755. }
  15756. }
  15757. /**
  15758. * In dialog Notify Reception
  15759. */
  15760. }, {
  15761. key: "_receiveNotify",
  15762. value: function _receiveNotify(request) {
  15763. debug('receiveNotify()');
  15764. if (!request.event) {
  15765. request.reply(400);
  15766. }
  15767. switch (request.event.event) {
  15768. case 'refer':
  15769. {
  15770. var id;
  15771. var referSubscriber;
  15772. if (request.event.params && request.event.params.id) {
  15773. id = request.event.params.id;
  15774. referSubscriber = this._referSubscribers[id];
  15775. } else if (Object.keys(this._referSubscribers).length === 1) {
  15776. referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]];
  15777. } else {
  15778. request.reply(400, 'Missing event id parameter');
  15779. return;
  15780. }
  15781. if (!referSubscriber) {
  15782. request.reply(481, 'Subscription does not exist');
  15783. return;
  15784. }
  15785. referSubscriber.receiveNotify(request);
  15786. request.reply(200);
  15787. break;
  15788. }
  15789. default:
  15790. {
  15791. request.reply(489);
  15792. }
  15793. }
  15794. }
  15795. /**
  15796. * INVITE with Replaces Reception
  15797. */
  15798. }, {
  15799. key: "_receiveReplaces",
  15800. value: function _receiveReplaces(request) {
  15801. var _this20 = this;
  15802. debug('receiveReplaces()');
  15803. function _accept2(initCallback) {
  15804. var _this19 = this;
  15805. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15806. return false;
  15807. }
  15808. var session = new RTCSession(this._ua); // Terminate the current session when the new one is confirmed.
  15809. session.on('confirmed', function () {
  15810. _this19.terminate();
  15811. });
  15812. session.init_incoming(request, initCallback);
  15813. }
  15814. function _reject2() {
  15815. debug('Replaced INVITE rejected by the user');
  15816. request.reply(486);
  15817. } // Emit 'replace'.
  15818. this.emit('replaces', {
  15819. request: request,
  15820. accept: function accept(initCallback) {
  15821. _accept2.call(_this20, initCallback);
  15822. },
  15823. reject: function reject() {
  15824. _reject2.call(_this20);
  15825. }
  15826. });
  15827. }
  15828. /**
  15829. * Initial Request Sender
  15830. */
  15831. }, {
  15832. key: "_sendInitialRequest",
  15833. value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) {
  15834. var _this21 = this;
  15835. var request_sender = new RequestSender(this._ua, this._request, {
  15836. onRequestTimeout: function onRequestTimeout() {
  15837. _this21.onRequestTimeout();
  15838. },
  15839. onTransportError: function onTransportError() {
  15840. _this21.onTransportError();
  15841. },
  15842. // Update the request on authentication.
  15843. onAuthenticated: function onAuthenticated(request) {
  15844. _this21._request = request;
  15845. },
  15846. onReceiveResponse: function onReceiveResponse(response) {
  15847. _this21._receiveInviteResponse(response);
  15848. }
  15849. }); // This Promise is resolved within the next iteration, so the app has now
  15850. // a chance to set events such as 'peerconnection' and 'connecting'.
  15851. Promise.resolve() // Get a stream if required.
  15852. .then(function () {
  15853. // A stream is given, let the app set events such as 'peerconnection' and 'connecting'.
  15854. if (mediaStream) {
  15855. return mediaStream;
  15856. } // Request for user media access.
  15857. else if (mediaConstraints.audio || mediaConstraints.video) {
  15858. _this21._localMediaStreamLocallyGenerated = true;
  15859. return navigator.mediaDevices.getUserMedia(mediaConstraints).catch(function (error) {
  15860. if (_this21._status === C.STATUS_TERMINATED) {
  15861. throw new Error('terminated');
  15862. }
  15863. _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  15864. debugerror('emit "getusermediafailed" [error:%o]', error);
  15865. _this21.emit('getusermediafailed', error);
  15866. throw error;
  15867. });
  15868. }
  15869. }).then(function (stream) {
  15870. if (_this21._status === C.STATUS_TERMINATED) {
  15871. throw new Error('terminated');
  15872. }
  15873. _this21._localMediaStream = stream;
  15874. if (stream) {
  15875. stream.getTracks().forEach(function (track) {
  15876. _this21._connection.addTrack(track, stream);
  15877. });
  15878. } // TODO: should this be triggered here?
  15879. _this21._connecting(_this21._request);
  15880. return _this21._createLocalDescription('offer', rtcOfferConstraints).catch(function (error) {
  15881. _this21._failed('local', null, JsSIP_C.causes.WEBRTC_ERROR);
  15882. throw error;
  15883. });
  15884. }).then(function (desc) {
  15885. if (_this21._is_canceled || _this21._status === C.STATUS_TERMINATED) {
  15886. throw new Error('terminated');
  15887. }
  15888. _this21._request.body = desc;
  15889. _this21._status = C.STATUS_INVITE_SENT;
  15890. debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent.
  15891. _this21.emit('sending', {
  15892. request: _this21._request
  15893. });
  15894. request_sender.send();
  15895. }).catch(function (error) {
  15896. if (_this21._status === C.STATUS_TERMINATED) {
  15897. return;
  15898. }
  15899. debugerror(error);
  15900. });
  15901. }
  15902. /**
  15903. * Reception of Response for Initial INVITE
  15904. */
  15905. }, {
  15906. key: "_receiveInviteResponse",
  15907. value: function _receiveInviteResponse(response) {
  15908. var _this22 = this;
  15909. debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests.
  15910. if (this._dialog && response.status_code >= 200 && response.status_code <= 299) {
  15911. /*
  15912. * If it is a retransmission from the endpoint that established
  15913. * the dialog, send an ACK
  15914. */
  15915. if (this._dialog.id.call_id === response.call_id && this._dialog.id.local_tag === response.from_tag && this._dialog.id.remote_tag === response.to_tag) {
  15916. this.sendRequest(JsSIP_C.ACK);
  15917. return;
  15918. } // If not, send an ACK and terminate.
  15919. else {
  15920. var dialog = new Dialog(this, response, 'UAC');
  15921. if (dialog.error !== undefined) {
  15922. debug(dialog.error);
  15923. return;
  15924. }
  15925. this.sendRequest(JsSIP_C.ACK);
  15926. this.sendRequest(JsSIP_C.BYE);
  15927. return;
  15928. }
  15929. } // Proceed to cancellation if the user requested.
  15930. if (this._is_canceled) {
  15931. if (response.status_code >= 100 && response.status_code < 200) {
  15932. this._request.cancel(this._cancel_reason);
  15933. } else if (response.status_code >= 200 && response.status_code < 299) {
  15934. this._acceptAndTerminate(response);
  15935. }
  15936. return;
  15937. }
  15938. if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) {
  15939. return;
  15940. }
  15941. switch (true) {
  15942. case /^100$/.test(response.status_code):
  15943. this._status = C.STATUS_1XX_RECEIVED;
  15944. break;
  15945. case /^1[0-9]{2}$/.test(response.status_code):
  15946. {
  15947. // Do nothing with 1xx responses without To tag.
  15948. if (!response.to_tag) {
  15949. debug('1xx response received without to tag');
  15950. break;
  15951. } // Create Early Dialog if 1XX comes with contact.
  15952. if (response.hasHeader('contact')) {
  15953. // An error on dialog creation will fire 'failed' event.
  15954. if (!this._createDialog(response, 'UAC', true)) {
  15955. break;
  15956. }
  15957. }
  15958. this._status = C.STATUS_1XX_RECEIVED;
  15959. this._progress('remote', response);
  15960. if (!response.body) {
  15961. break;
  15962. }
  15963. var e = {
  15964. originator: 'remote',
  15965. type: 'answer',
  15966. sdp: response.body
  15967. };
  15968. debug('emit "sdp"');
  15969. this.emit('sdp', e);
  15970. var answer = new RTCSessionDescription({
  15971. type: 'answer',
  15972. sdp: e.sdp
  15973. });
  15974. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15975. return _this22._connection.setRemoteDescription(answer);
  15976. }).catch(function (error) {
  15977. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15978. _this22.emit('peerconnection:setremotedescriptionfailed', error);
  15979. });
  15980. break;
  15981. }
  15982. case /^2[0-9]{2}$/.test(response.status_code):
  15983. {
  15984. this._status = C.STATUS_CONFIRMED;
  15985. if (!response.body) {
  15986. this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP);
  15987. this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  15988. break;
  15989. } // An error on dialog creation will fire 'failed' event.
  15990. if (!this._createDialog(response, 'UAC')) {
  15991. break;
  15992. }
  15993. var _e = {
  15994. originator: 'remote',
  15995. type: 'answer',
  15996. sdp: response.body
  15997. };
  15998. debug('emit "sdp"');
  15999. this.emit('sdp', _e);
  16000. var _answer = new RTCSessionDescription({
  16001. type: 'answer',
  16002. sdp: _e.sdp
  16003. });
  16004. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16005. // Be ready for 200 with SDP after a 180/183 with SDP.
  16006. // We created a SDP 'answer' for it, so check the current signaling state.
  16007. if (_this22._connection.signalingState === 'stable') {
  16008. return _this22._connection.createOffer(_this22._rtcOfferConstraints).then(function (offer) {
  16009. return _this22._connection.setLocalDescription(offer);
  16010. }).catch(function (error) {
  16011. _this22._acceptAndTerminate(response, 500, error.toString());
  16012. _this22._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR);
  16013. });
  16014. }
  16015. }).then(function () {
  16016. _this22._connection.setRemoteDescription(_answer).then(function () {
  16017. // Handle Session Timers.
  16018. _this22._handleSessionTimersInIncomingResponse(response);
  16019. _this22._accepted('remote', response);
  16020. _this22.sendRequest(JsSIP_C.ACK);
  16021. _this22._confirmed('local', null);
  16022. }).catch(function (error) {
  16023. _this22._acceptAndTerminate(response, 488, 'Not Acceptable Here');
  16024. _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  16025. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16026. _this22.emit('peerconnection:setremotedescriptionfailed', error);
  16027. });
  16028. });
  16029. break;
  16030. }
  16031. default:
  16032. {
  16033. var cause = Utils.sipErrorCause(response.status_code);
  16034. this._failed('remote', response, cause);
  16035. }
  16036. }
  16037. }
  16038. /**
  16039. * Send Re-INVITE
  16040. */
  16041. }, {
  16042. key: "_sendReinvite",
  16043. value: function _sendReinvite() {
  16044. var _this23 = this;
  16045. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16046. debug('sendReinvite()');
  16047. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16048. var eventHandlers = options.eventHandlers || {};
  16049. var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
  16050. var succeeded = false;
  16051. extraHeaders.push("Contact: ".concat(this._contact));
  16052. extraHeaders.push('Content-Type: application/sdp'); // Session Timers.
  16053. if (this._sessionTimers.running) {
  16054. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas'));
  16055. }
  16056. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16057. return _this23._createLocalDescription('offer', rtcOfferConstraints);
  16058. }).then(function (sdp) {
  16059. sdp = _this23._mangleOffer(sdp);
  16060. var e = {
  16061. originator: 'local',
  16062. type: 'offer',
  16063. sdp: sdp
  16064. };
  16065. debug('emit "sdp"');
  16066. _this23.emit('sdp', e);
  16067. _this23.sendRequest(JsSIP_C.INVITE, {
  16068. extraHeaders: extraHeaders,
  16069. body: sdp,
  16070. eventHandlers: {
  16071. onSuccessResponse: function onSuccessResponse(response) {
  16072. onSucceeded.call(_this23, response);
  16073. succeeded = true;
  16074. },
  16075. onErrorResponse: function onErrorResponse(response) {
  16076. onFailed.call(_this23, response);
  16077. },
  16078. onTransportError: function onTransportError() {
  16079. _this23.onTransportError(); // Do nothing because session ends.
  16080. },
  16081. onRequestTimeout: function onRequestTimeout() {
  16082. _this23.onRequestTimeout(); // Do nothing because session ends.
  16083. },
  16084. onDialogError: function onDialogError() {
  16085. _this23.onDialogError(); // Do nothing because session ends.
  16086. }
  16087. }
  16088. });
  16089. }).catch(function () {
  16090. onFailed();
  16091. });
  16092. function onSucceeded(response) {
  16093. var _this24 = this;
  16094. if (this._status === C.STATUS_TERMINATED) {
  16095. return;
  16096. }
  16097. this.sendRequest(JsSIP_C.ACK); // If it is a 2XX retransmission exit now.
  16098. if (succeeded) {
  16099. return;
  16100. } // Handle Session Timers.
  16101. this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer.
  16102. if (!response.body) {
  16103. onFailed.call(this);
  16104. return;
  16105. } else if (response.getHeader('Content-Type') !== 'application/sdp') {
  16106. onFailed.call(this);
  16107. return;
  16108. }
  16109. var e = {
  16110. originator: 'remote',
  16111. type: 'answer',
  16112. sdp: response.body
  16113. };
  16114. debug('emit "sdp"');
  16115. this.emit('sdp', e);
  16116. var answer = new RTCSessionDescription({
  16117. type: 'answer',
  16118. sdp: e.sdp
  16119. });
  16120. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16121. return _this24._connection.setRemoteDescription(answer);
  16122. }).then(function () {
  16123. if (eventHandlers.succeeded) {
  16124. eventHandlers.succeeded(response);
  16125. }
  16126. }).catch(function (error) {
  16127. onFailed.call(_this24);
  16128. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16129. _this24.emit('peerconnection:setremotedescriptionfailed', error);
  16130. });
  16131. }
  16132. function onFailed(response) {
  16133. if (eventHandlers.failed) {
  16134. eventHandlers.failed(response);
  16135. }
  16136. }
  16137. }
  16138. /**
  16139. * Send UPDATE
  16140. */
  16141. }, {
  16142. key: "_sendUpdate",
  16143. value: function _sendUpdate() {
  16144. var _this25 = this;
  16145. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16146. debug('sendUpdate()');
  16147. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16148. var eventHandlers = options.eventHandlers || {};
  16149. var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
  16150. var sdpOffer = options.sdpOffer || false;
  16151. var succeeded = false;
  16152. extraHeaders.push("Contact: ".concat(this._contact)); // Session Timers.
  16153. if (this._sessionTimers.running) {
  16154. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas'));
  16155. }
  16156. if (sdpOffer) {
  16157. extraHeaders.push('Content-Type: application/sdp');
  16158. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16159. return _this25._createLocalDescription('offer', rtcOfferConstraints);
  16160. }).then(function (sdp) {
  16161. sdp = _this25._mangleOffer(sdp);
  16162. var e = {
  16163. originator: 'local',
  16164. type: 'offer',
  16165. sdp: sdp
  16166. };
  16167. debug('emit "sdp"');
  16168. _this25.emit('sdp', e);
  16169. _this25.sendRequest(JsSIP_C.UPDATE, {
  16170. extraHeaders: extraHeaders,
  16171. body: sdp,
  16172. eventHandlers: {
  16173. onSuccessResponse: function onSuccessResponse(response) {
  16174. onSucceeded.call(_this25, response);
  16175. succeeded = true;
  16176. },
  16177. onErrorResponse: function onErrorResponse(response) {
  16178. onFailed.call(_this25, response);
  16179. },
  16180. onTransportError: function onTransportError() {
  16181. _this25.onTransportError(); // Do nothing because session ends.
  16182. },
  16183. onRequestTimeout: function onRequestTimeout() {
  16184. _this25.onRequestTimeout(); // Do nothing because session ends.
  16185. },
  16186. onDialogError: function onDialogError() {
  16187. _this25.onDialogError(); // Do nothing because session ends.
  16188. }
  16189. }
  16190. });
  16191. }).catch(function () {
  16192. onFailed.call(_this25);
  16193. });
  16194. } // No SDP.
  16195. else {
  16196. this.sendRequest(JsSIP_C.UPDATE, {
  16197. extraHeaders: extraHeaders,
  16198. eventHandlers: {
  16199. onSuccessResponse: function onSuccessResponse(response) {
  16200. onSucceeded.call(_this25, response);
  16201. },
  16202. onErrorResponse: function onErrorResponse(response) {
  16203. onFailed.call(_this25, response);
  16204. },
  16205. onTransportError: function onTransportError() {
  16206. _this25.onTransportError(); // Do nothing because session ends.
  16207. },
  16208. onRequestTimeout: function onRequestTimeout() {
  16209. _this25.onRequestTimeout(); // Do nothing because session ends.
  16210. },
  16211. onDialogError: function onDialogError() {
  16212. _this25.onDialogError(); // Do nothing because session ends.
  16213. }
  16214. }
  16215. });
  16216. }
  16217. function onSucceeded(response) {
  16218. var _this26 = this;
  16219. if (this._status === C.STATUS_TERMINATED) {
  16220. return;
  16221. } // If it is a 2XX retransmission exit now.
  16222. if (succeeded) {
  16223. return;
  16224. } // Handle Session Timers.
  16225. this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer.
  16226. if (sdpOffer) {
  16227. if (!response.body) {
  16228. onFailed.call(this);
  16229. return;
  16230. } else if (response.getHeader('Content-Type') !== 'application/sdp') {
  16231. onFailed.call(this);
  16232. return;
  16233. }
  16234. var e = {
  16235. originator: 'remote',
  16236. type: 'answer',
  16237. sdp: response.body
  16238. };
  16239. debug('emit "sdp"');
  16240. this.emit('sdp', e);
  16241. var answer = new RTCSessionDescription({
  16242. type: 'answer',
  16243. sdp: e.sdp
  16244. });
  16245. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16246. return _this26._connection.setRemoteDescription(answer);
  16247. }).then(function () {
  16248. if (eventHandlers.succeeded) {
  16249. eventHandlers.succeeded(response);
  16250. }
  16251. }).catch(function (error) {
  16252. onFailed.call(_this26);
  16253. debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16254. _this26.emit('peerconnection:setremotedescriptionfailed', error);
  16255. });
  16256. } // No SDP answer.
  16257. else if (eventHandlers.succeeded) {
  16258. eventHandlers.succeeded(response);
  16259. }
  16260. }
  16261. function onFailed(response) {
  16262. if (eventHandlers.failed) {
  16263. eventHandlers.failed(response);
  16264. }
  16265. }
  16266. }
  16267. }, {
  16268. key: "_acceptAndTerminate",
  16269. value: function _acceptAndTerminate(response, status_code, reason_phrase) {
  16270. debug('acceptAndTerminate()');
  16271. var extraHeaders = [];
  16272. if (status_code) {
  16273. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  16274. extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\""));
  16275. } // An error on dialog creation will fire 'failed' event.
  16276. if (this._dialog || this._createDialog(response, 'UAC')) {
  16277. this.sendRequest(JsSIP_C.ACK);
  16278. this.sendRequest(JsSIP_C.BYE, {
  16279. extraHeaders: extraHeaders
  16280. });
  16281. } // Update session status.
  16282. this._status = C.STATUS_TERMINATED;
  16283. }
  16284. /**
  16285. * Correctly set the SDP direction attributes if the call is on local hold
  16286. */
  16287. }, {
  16288. key: "_mangleOffer",
  16289. value: function _mangleOffer(sdp) {
  16290. if (!this._localHold && !this._remoteHold) {
  16291. return sdp;
  16292. }
  16293. sdp = sdp_transform.parse(sdp); // Local hold.
  16294. if (this._localHold && !this._remoteHold) {
  16295. debug('mangleOffer() | me on hold, mangling offer');
  16296. var _iteratorNormalCompletion5 = true;
  16297. var _didIteratorError5 = false;
  16298. var _iteratorError5 = undefined;
  16299. try {
  16300. for (var _iterator5 = sdp.media[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  16301. var m = _step5.value;
  16302. if (holdMediaTypes.indexOf(m.type) === -1) {
  16303. continue;
  16304. }
  16305. if (!m.direction) {
  16306. m.direction = 'sendonly';
  16307. } else if (m.direction === 'sendrecv') {
  16308. m.direction = 'sendonly';
  16309. } else if (m.direction === 'recvonly') {
  16310. m.direction = 'inactive';
  16311. }
  16312. }
  16313. } catch (err) {
  16314. _didIteratorError5 = true;
  16315. _iteratorError5 = err;
  16316. } finally {
  16317. try {
  16318. if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
  16319. _iterator5.return();
  16320. }
  16321. } finally {
  16322. if (_didIteratorError5) {
  16323. throw _iteratorError5;
  16324. }
  16325. }
  16326. }
  16327. } // Local and remote hold.
  16328. else if (this._localHold && this._remoteHold) {
  16329. debug('mangleOffer() | both on hold, mangling offer');
  16330. var _iteratorNormalCompletion6 = true;
  16331. var _didIteratorError6 = false;
  16332. var _iteratorError6 = undefined;
  16333. try {
  16334. for (var _iterator6 = sdp.media[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
  16335. var _m = _step6.value;
  16336. if (holdMediaTypes.indexOf(_m.type) === -1) {
  16337. continue;
  16338. }
  16339. _m.direction = 'inactive';
  16340. }
  16341. } catch (err) {
  16342. _didIteratorError6 = true;
  16343. _iteratorError6 = err;
  16344. } finally {
  16345. try {
  16346. if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
  16347. _iterator6.return();
  16348. }
  16349. } finally {
  16350. if (_didIteratorError6) {
  16351. throw _iteratorError6;
  16352. }
  16353. }
  16354. }
  16355. } // Remote hold.
  16356. else if (this._remoteHold) {
  16357. debug('mangleOffer() | remote on hold, mangling offer');
  16358. var _iteratorNormalCompletion7 = true;
  16359. var _didIteratorError7 = false;
  16360. var _iteratorError7 = undefined;
  16361. try {
  16362. for (var _iterator7 = sdp.media[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
  16363. var _m2 = _step7.value;
  16364. if (holdMediaTypes.indexOf(_m2.type) === -1) {
  16365. continue;
  16366. }
  16367. if (!_m2.direction) {
  16368. _m2.direction = 'recvonly';
  16369. } else if (_m2.direction === 'sendrecv') {
  16370. _m2.direction = 'recvonly';
  16371. } else if (_m2.direction === 'recvonly') {
  16372. _m2.direction = 'inactive';
  16373. }
  16374. }
  16375. } catch (err) {
  16376. _didIteratorError7 = true;
  16377. _iteratorError7 = err;
  16378. } finally {
  16379. try {
  16380. if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
  16381. _iterator7.return();
  16382. }
  16383. } finally {
  16384. if (_didIteratorError7) {
  16385. throw _iteratorError7;
  16386. }
  16387. }
  16388. }
  16389. }
  16390. return sdp_transform.write(sdp);
  16391. }
  16392. }, {
  16393. key: "_setLocalMediaStatus",
  16394. value: function _setLocalMediaStatus() {
  16395. var enableAudio = true,
  16396. enableVideo = true;
  16397. if (this._localHold || this._remoteHold) {
  16398. enableAudio = false;
  16399. enableVideo = false;
  16400. }
  16401. if (this._audioMuted) {
  16402. enableAudio = false;
  16403. }
  16404. if (this._videoMuted) {
  16405. enableVideo = false;
  16406. }
  16407. this._toggleMuteAudio(!enableAudio);
  16408. this._toggleMuteVideo(!enableVideo);
  16409. }
  16410. /**
  16411. * Handle SessionTimers for an incoming INVITE or UPDATE.
  16412. * @param {IncomingRequest} request
  16413. * @param {Array} responseExtraHeaders Extra headers for the 200 response.
  16414. */
  16415. }, {
  16416. key: "_handleSessionTimersInIncomingRequest",
  16417. value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) {
  16418. if (!this._sessionTimers.enabled) {
  16419. return;
  16420. }
  16421. var session_expires_refresher;
  16422. if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  16423. this._sessionTimers.currentExpires = request.session_expires;
  16424. session_expires_refresher = request.session_expires_refresher || 'uas';
  16425. } else {
  16426. this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
  16427. session_expires_refresher = 'uas';
  16428. }
  16429. responseExtraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(session_expires_refresher));
  16430. this._sessionTimers.refresher = session_expires_refresher === 'uas';
  16431. this._runSessionTimer();
  16432. }
  16433. /**
  16434. * Handle SessionTimers for an incoming response to INVITE or UPDATE.
  16435. * @param {IncomingResponse} response
  16436. */
  16437. }, {
  16438. key: "_handleSessionTimersInIncomingResponse",
  16439. value: function _handleSessionTimersInIncomingResponse(response) {
  16440. if (!this._sessionTimers.enabled) {
  16441. return;
  16442. }
  16443. var session_expires_refresher;
  16444. if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  16445. this._sessionTimers.currentExpires = response.session_expires;
  16446. session_expires_refresher = response.session_expires_refresher || 'uac';
  16447. } else {
  16448. this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
  16449. session_expires_refresher = 'uac';
  16450. }
  16451. this._sessionTimers.refresher = session_expires_refresher === 'uac';
  16452. this._runSessionTimer();
  16453. }
  16454. }, {
  16455. key: "_runSessionTimer",
  16456. value: function _runSessionTimer() {
  16457. var _this27 = this;
  16458. var expires = this._sessionTimers.currentExpires;
  16459. this._sessionTimers.running = true;
  16460. clearTimeout(this._sessionTimers.timer); // I'm the refresher.
  16461. if (this._sessionTimers.refresher) {
  16462. this._sessionTimers.timer = setTimeout(function () {
  16463. if (_this27._status === C.STATUS_TERMINATED) {
  16464. return;
  16465. }
  16466. debug('runSessionTimer() | sending session refresh request');
  16467. if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) {
  16468. _this27._sendUpdate();
  16469. } else {
  16470. _this27._sendReinvite();
  16471. }
  16472. }, expires * 500); // Half the given interval (as the RFC states).
  16473. } // I'm not the refresher.
  16474. else {
  16475. this._sessionTimers.timer = setTimeout(function () {
  16476. if (_this27._status === C.STATUS_TERMINATED) {
  16477. return;
  16478. }
  16479. debugerror('runSessionTimer() | timer expired, terminating the session');
  16480. _this27.terminate({
  16481. cause: JsSIP_C.causes.REQUEST_TIMEOUT,
  16482. status_code: 408,
  16483. reason_phrase: 'Session Timer Expired'
  16484. });
  16485. }, expires * 1100);
  16486. }
  16487. }
  16488. }, {
  16489. key: "_toggleMuteAudio",
  16490. value: function _toggleMuteAudio(mute) {
  16491. var senders = this._connection.getSenders().filter(function (sender) {
  16492. return sender.track && sender.track.kind === 'audio';
  16493. });
  16494. var _iteratorNormalCompletion8 = true;
  16495. var _didIteratorError8 = false;
  16496. var _iteratorError8 = undefined;
  16497. try {
  16498. for (var _iterator8 = senders[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
  16499. var sender = _step8.value;
  16500. sender.track.enabled = !mute;
  16501. }
  16502. } catch (err) {
  16503. _didIteratorError8 = true;
  16504. _iteratorError8 = err;
  16505. } finally {
  16506. try {
  16507. if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
  16508. _iterator8.return();
  16509. }
  16510. } finally {
  16511. if (_didIteratorError8) {
  16512. throw _iteratorError8;
  16513. }
  16514. }
  16515. }
  16516. }
  16517. }, {
  16518. key: "_toggleMuteVideo",
  16519. value: function _toggleMuteVideo(mute) {
  16520. var senders = this._connection.getSenders().filter(function (sender) {
  16521. return sender.track && sender.track.kind === 'video';
  16522. });
  16523. var _iteratorNormalCompletion9 = true;
  16524. var _didIteratorError9 = false;
  16525. var _iteratorError9 = undefined;
  16526. try {
  16527. for (var _iterator9 = senders[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
  16528. var sender = _step9.value;
  16529. sender.track.enabled = !mute;
  16530. }
  16531. } catch (err) {
  16532. _didIteratorError9 = true;
  16533. _iteratorError9 = err;
  16534. } finally {
  16535. try {
  16536. if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
  16537. _iterator9.return();
  16538. }
  16539. } finally {
  16540. if (_didIteratorError9) {
  16541. throw _iteratorError9;
  16542. }
  16543. }
  16544. }
  16545. }
  16546. }, {
  16547. key: "_newRTCSession",
  16548. value: function _newRTCSession(originator, request) {
  16549. debug('newRTCSession()');
  16550. this._ua.newRTCSession(this, {
  16551. originator: originator,
  16552. session: this,
  16553. request: request
  16554. });
  16555. }
  16556. }, {
  16557. key: "_connecting",
  16558. value: function _connecting(request) {
  16559. debug('session connecting');
  16560. debug('emit "connecting"');
  16561. this.emit('connecting', {
  16562. request: request
  16563. });
  16564. }
  16565. }, {
  16566. key: "_progress",
  16567. value: function _progress(originator, response) {
  16568. debug('session progress');
  16569. debug('emit "progress"');
  16570. this.emit('progress', {
  16571. originator: originator,
  16572. response: response || null
  16573. });
  16574. }
  16575. }, {
  16576. key: "_accepted",
  16577. value: function _accepted(originator, message) {
  16578. debug('session accepted');
  16579. this._start_time = new Date();
  16580. debug('emit "accepted"');
  16581. this.emit('accepted', {
  16582. originator: originator,
  16583. response: message || null
  16584. });
  16585. }
  16586. }, {
  16587. key: "_confirmed",
  16588. value: function _confirmed(originator, ack) {
  16589. debug('session confirmed');
  16590. this._is_confirmed = true;
  16591. debug('emit "confirmed"');
  16592. this.emit('confirmed', {
  16593. originator: originator,
  16594. ack: ack || null
  16595. });
  16596. }
  16597. }, {
  16598. key: "_ended",
  16599. value: function _ended(originator, message, cause) {
  16600. debug('session ended');
  16601. this._end_time = new Date();
  16602. this._close();
  16603. debug('emit "ended"');
  16604. this.emit('ended', {
  16605. originator: originator,
  16606. message: message || null,
  16607. cause: cause
  16608. });
  16609. }
  16610. }, {
  16611. key: "_failed",
  16612. value: function _failed(originator, message, cause) {
  16613. debug('session failed'); // Emit private '_failed' event first.
  16614. debug('emit "_failed"');
  16615. this.emit('_failed', {
  16616. originator: originator,
  16617. message: message || null,
  16618. cause: cause
  16619. });
  16620. this._close();
  16621. debug('emit "failed"');
  16622. this.emit('failed', {
  16623. originator: originator,
  16624. message: message || null,
  16625. cause: cause
  16626. });
  16627. }
  16628. }, {
  16629. key: "_onhold",
  16630. value: function _onhold(originator) {
  16631. debug('session onhold');
  16632. this._setLocalMediaStatus();
  16633. debug('emit "hold"');
  16634. this.emit('hold', {
  16635. originator: originator
  16636. });
  16637. }
  16638. }, {
  16639. key: "_onunhold",
  16640. value: function _onunhold(originator) {
  16641. debug('session onunhold');
  16642. this._setLocalMediaStatus();
  16643. debug('emit "unhold"');
  16644. this.emit('unhold', {
  16645. originator: originator
  16646. });
  16647. }
  16648. }, {
  16649. key: "_onmute",
  16650. value: function _onmute(_ref5) {
  16651. var audio = _ref5.audio,
  16652. video = _ref5.video;
  16653. debug('session onmute');
  16654. this._setLocalMediaStatus();
  16655. debug('emit "muted"');
  16656. this.emit('muted', {
  16657. audio: audio,
  16658. video: video
  16659. });
  16660. }
  16661. }, {
  16662. key: "_onunmute",
  16663. value: function _onunmute(_ref6) {
  16664. var audio = _ref6.audio,
  16665. video = _ref6.video;
  16666. debug('session onunmute');
  16667. this._setLocalMediaStatus();
  16668. debug('emit "unmuted"');
  16669. this.emit('unmuted', {
  16670. audio: audio,
  16671. video: video
  16672. });
  16673. }
  16674. }, {
  16675. key: "C",
  16676. get: function get() {
  16677. return C;
  16678. } // Expose session failed/ended causes as a property of the RTCSession instance.
  16679. }, {
  16680. key: "causes",
  16681. get: function get() {
  16682. return JsSIP_C.causes;
  16683. }
  16684. }, {
  16685. key: "id",
  16686. get: function get() {
  16687. return this._id;
  16688. }
  16689. }, {
  16690. key: "connection",
  16691. get: function get() {
  16692. return this._connection;
  16693. }
  16694. }, {
  16695. key: "contact",
  16696. get: function get() {
  16697. return this._contact;
  16698. }
  16699. }, {
  16700. key: "direction",
  16701. get: function get() {
  16702. return this._direction;
  16703. }
  16704. }, {
  16705. key: "local_identity",
  16706. get: function get() {
  16707. return this._local_identity;
  16708. }
  16709. }, {
  16710. key: "remote_identity",
  16711. get: function get() {
  16712. return this._remote_identity;
  16713. }
  16714. }, {
  16715. key: "start_time",
  16716. get: function get() {
  16717. return this._start_time;
  16718. }
  16719. }, {
  16720. key: "end_time",
  16721. get: function get() {
  16722. return this._end_time;
  16723. }
  16724. }, {
  16725. key: "data",
  16726. get: function get() {
  16727. return this._data;
  16728. },
  16729. set: function set(_data) {
  16730. this._data = _data;
  16731. }
  16732. }, {
  16733. key: "status",
  16734. get: function get() {
  16735. return this._status;
  16736. }
  16737. }]);
  16738. return RTCSession;
  16739. }(EventEmitter);
  16740. },{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":13,"./RTCSession/Info":14,"./RTCSession/ReferNotifier":15,"./RTCSession/ReferSubscriber":16,"./RequestSender":18,"./SIPMessage":19,"./Timers":21,"./Transactions":22,"./URI":25,"./Utils":26,"debug":30,"events":29,"sdp-transform":35}],13:[function(require,module,exports){
  16741. "use strict";
  16742. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16743. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16744. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16745. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16746. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16747. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16748. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16749. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16750. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16751. var EventEmitter = require('events').EventEmitter;
  16752. var JsSIP_C = require('../Constants');
  16753. var Exceptions = require('../Exceptions');
  16754. var Utils = require('../Utils');
  16755. var debug = require('debug')('JsSIP:RTCSession:DTMF');
  16756. var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF');
  16757. debugerror.log = console.warn.bind(console);
  16758. var C = {
  16759. MIN_DURATION: 70,
  16760. MAX_DURATION: 6000,
  16761. DEFAULT_DURATION: 100,
  16762. MIN_INTER_TONE_GAP: 50,
  16763. DEFAULT_INTER_TONE_GAP: 500
  16764. };
  16765. module.exports =
  16766. /*#__PURE__*/
  16767. function (_EventEmitter) {
  16768. _inherits(DTMF, _EventEmitter);
  16769. function DTMF(session) {
  16770. var _this;
  16771. _classCallCheck(this, DTMF);
  16772. _this = _possibleConstructorReturn(this, _getPrototypeOf(DTMF).call(this));
  16773. _this._session = session;
  16774. _this._direction = null;
  16775. _this._tone = null;
  16776. _this._duration = null;
  16777. _this._request = null;
  16778. return _this;
  16779. }
  16780. _createClass(DTMF, [{
  16781. key: "send",
  16782. value: function send(tone) {
  16783. var _this2 = this;
  16784. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  16785. if (tone === undefined) {
  16786. throw new TypeError('Not enough arguments');
  16787. }
  16788. this._direction = 'outgoing'; // Check RTCSession Status.
  16789. if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
  16790. throw new Exceptions.InvalidStateError(this._session.status);
  16791. }
  16792. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16793. this.eventHandlers = options.eventHandlers || {}; // Check tone type.
  16794. if (typeof tone === 'string') {
  16795. tone = tone.toUpperCase();
  16796. } else if (typeof tone === 'number') {
  16797. tone = tone.toString();
  16798. } else {
  16799. throw new TypeError("Invalid tone: ".concat(tone));
  16800. } // Check tone value.
  16801. if (!tone.match(/^[0-9A-DR#*]$/)) {
  16802. throw new TypeError("Invalid tone: ".concat(tone));
  16803. } else {
  16804. this._tone = tone;
  16805. } // Duration is checked/corrected in RTCSession.
  16806. this._duration = options.duration;
  16807. extraHeaders.push('Content-Type: application/dtmf-relay');
  16808. var body = "Signal=".concat(this._tone, "\r\n");
  16809. body += "Duration=".concat(this._duration);
  16810. this._session.newDTMF({
  16811. originator: 'local',
  16812. dtmf: this,
  16813. request: this._request
  16814. });
  16815. this._session.sendRequest(JsSIP_C.INFO, {
  16816. extraHeaders: extraHeaders,
  16817. eventHandlers: {
  16818. onSuccessResponse: function onSuccessResponse(response) {
  16819. _this2.emit('succeeded', {
  16820. originator: 'remote',
  16821. response: response
  16822. });
  16823. },
  16824. onErrorResponse: function onErrorResponse(response) {
  16825. if (_this2.eventHandlers.onFailed) {
  16826. _this2.eventHandlers.onFailed();
  16827. }
  16828. _this2.emit('failed', {
  16829. originator: 'remote',
  16830. response: response
  16831. });
  16832. },
  16833. onRequestTimeout: function onRequestTimeout() {
  16834. _this2._session.onRequestTimeout();
  16835. },
  16836. onTransportError: function onTransportError() {
  16837. _this2._session.onTransportError();
  16838. },
  16839. onDialogError: function onDialogError() {
  16840. _this2._session.onDialogError();
  16841. }
  16842. },
  16843. body: body
  16844. });
  16845. }
  16846. }, {
  16847. key: "init_incoming",
  16848. value: function init_incoming(request) {
  16849. var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;
  16850. var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;
  16851. this._direction = 'incoming';
  16852. this._request = request;
  16853. request.reply(200);
  16854. if (request.body) {
  16855. var body = request.body.split('\n');
  16856. if (body.length >= 1) {
  16857. if (reg_tone.test(body[0])) {
  16858. this._tone = body[0].replace(reg_tone, '$2');
  16859. }
  16860. }
  16861. if (body.length >= 2) {
  16862. if (reg_duration.test(body[1])) {
  16863. this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10);
  16864. }
  16865. }
  16866. }
  16867. if (!this._duration) {
  16868. this._duration = C.DEFAULT_DURATION;
  16869. }
  16870. if (!this._tone) {
  16871. debug('invalid INFO DTMF received, discarded');
  16872. } else {
  16873. this._session.newDTMF({
  16874. originator: 'remote',
  16875. dtmf: this,
  16876. request: request
  16877. });
  16878. }
  16879. }
  16880. }, {
  16881. key: "tone",
  16882. get: function get() {
  16883. return this._tone;
  16884. }
  16885. }, {
  16886. key: "duration",
  16887. get: function get() {
  16888. return this._duration;
  16889. }
  16890. }]);
  16891. return DTMF;
  16892. }(EventEmitter);
  16893. /**
  16894. * Expose C object.
  16895. */
  16896. module.exports.C = C;
  16897. },{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],14:[function(require,module,exports){
  16898. "use strict";
  16899. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  16900. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16901. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  16902. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  16903. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  16904. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16905. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  16906. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16907. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  16908. var EventEmitter = require('events').EventEmitter;
  16909. var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info');
  16910. debugerror.log = console.warn.bind(console);
  16911. var JsSIP_C = require('../Constants');
  16912. var Exceptions = require('../Exceptions');
  16913. var Utils = require('../Utils');
  16914. module.exports =
  16915. /*#__PURE__*/
  16916. function (_EventEmitter) {
  16917. _inherits(Info, _EventEmitter);
  16918. function Info(session) {
  16919. var _this;
  16920. _classCallCheck(this, Info);
  16921. _this = _possibleConstructorReturn(this, _getPrototypeOf(Info).call(this));
  16922. _this._session = session;
  16923. _this._direction = null;
  16924. _this._contentType = null;
  16925. _this._body = null;
  16926. return _this;
  16927. }
  16928. _createClass(Info, [{
  16929. key: "send",
  16930. value: function send(contentType, body) {
  16931. var _this2 = this;
  16932. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  16933. this._direction = 'outgoing';
  16934. if (contentType === undefined) {
  16935. throw new TypeError('Not enough arguments');
  16936. } // Check RTCSession Status.
  16937. if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
  16938. throw new Exceptions.InvalidStateError(this._session.status);
  16939. }
  16940. this._contentType = contentType;
  16941. this._body = body;
  16942. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16943. extraHeaders.push("Content-Type: ".concat(contentType));
  16944. this._session.newInfo({
  16945. originator: 'local',
  16946. info: this,
  16947. request: this.request
  16948. });
  16949. this._session.sendRequest(JsSIP_C.INFO, {
  16950. extraHeaders: extraHeaders,
  16951. eventHandlers: {
  16952. onSuccessResponse: function onSuccessResponse(response) {
  16953. _this2.emit('succeeded', {
  16954. originator: 'remote',
  16955. response: response
  16956. });
  16957. },
  16958. onErrorResponse: function onErrorResponse(response) {
  16959. _this2.emit('failed', {
  16960. originator: 'remote',
  16961. response: response
  16962. });
  16963. },
  16964. onTransportError: function onTransportError() {
  16965. _this2._session.onTransportError();
  16966. },
  16967. onRequestTimeout: function onRequestTimeout() {
  16968. _this2._session.onRequestTimeout();
  16969. },
  16970. onDialogError: function onDialogError() {
  16971. _this2._session.onDialogError();
  16972. }
  16973. },
  16974. body: body
  16975. });
  16976. }
  16977. }, {
  16978. key: "init_incoming",
  16979. value: function init_incoming(request) {
  16980. this._direction = 'incoming';
  16981. this.request = request;
  16982. request.reply(200);
  16983. this._contentType = request.getHeader('content-type');
  16984. this._body = request.body;
  16985. this._session.newInfo({
  16986. originator: 'remote',
  16987. info: this,
  16988. request: request
  16989. });
  16990. }
  16991. }, {
  16992. key: "contentType",
  16993. get: function get() {
  16994. return this._contentType;
  16995. }
  16996. }, {
  16997. key: "body",
  16998. get: function get() {
  16999. return this._body;
  17000. }
  17001. }]);
  17002. return Info;
  17003. }(EventEmitter);
  17004. },{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],15:[function(require,module,exports){
  17005. "use strict";
  17006. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17007. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17008. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17009. var JsSIP_C = require('../Constants');
  17010. var debug = require('debug')('JsSIP:RTCSession:ReferNotifier');
  17011. var C = {
  17012. event_type: 'refer',
  17013. body_type: 'message/sipfrag;version=2.0',
  17014. expires: 300
  17015. };
  17016. module.exports =
  17017. /*#__PURE__*/
  17018. function () {
  17019. function ReferNotifier(session, id, expires) {
  17020. _classCallCheck(this, ReferNotifier);
  17021. this._session = session;
  17022. this._id = id;
  17023. this._expires = expires || C.expires;
  17024. this._active = true; // The creation of a Notifier results in an immediate NOTIFY.
  17025. this.notify(100);
  17026. }
  17027. _createClass(ReferNotifier, [{
  17028. key: "notify",
  17029. value: function notify(code, reason) {
  17030. debug('notify()');
  17031. if (this._active === false) {
  17032. return;
  17033. }
  17034. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  17035. var state;
  17036. if (code >= 200) {
  17037. state = 'terminated;reason=noresource';
  17038. } else {
  17039. state = "active;expires=".concat(this._expires);
  17040. } // Put this in a try/catch block.
  17041. this._session.sendRequest(JsSIP_C.NOTIFY, {
  17042. extraHeaders: ["Event: ".concat(C.event_type, ";id=").concat(this._id), "Subscription-State: ".concat(state), "Content-Type: ".concat(C.body_type)],
  17043. body: "SIP/2.0 ".concat(code, " ").concat(reason),
  17044. eventHandlers: {
  17045. // If a negative response is received, subscription is canceled.
  17046. onErrorResponse: function onErrorResponse() {
  17047. this._active = false;
  17048. }
  17049. }
  17050. });
  17051. }
  17052. }]);
  17053. return ReferNotifier;
  17054. }();
  17055. },{"../Constants":2,"debug":30}],16:[function(require,module,exports){
  17056. "use strict";
  17057. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  17058. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17059. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17060. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17061. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17062. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17063. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17064. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  17065. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17066. var EventEmitter = require('events').EventEmitter;
  17067. var JsSIP_C = require('../Constants');
  17068. var Grammar = require('../Grammar');
  17069. var Utils = require('../Utils');
  17070. var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber');
  17071. module.exports =
  17072. /*#__PURE__*/
  17073. function (_EventEmitter) {
  17074. _inherits(ReferSubscriber, _EventEmitter);
  17075. function ReferSubscriber(session) {
  17076. var _this;
  17077. _classCallCheck(this, ReferSubscriber);
  17078. _this = _possibleConstructorReturn(this, _getPrototypeOf(ReferSubscriber).call(this));
  17079. _this._id = null;
  17080. _this._session = session;
  17081. return _this;
  17082. }
  17083. _createClass(ReferSubscriber, [{
  17084. key: "sendRefer",
  17085. value: function sendRefer(target) {
  17086. var _this2 = this;
  17087. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  17088. debug('sendRefer()');
  17089. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  17090. var eventHandlers = options.eventHandlers || {}; // Set event handlers.
  17091. for (var event in eventHandlers) {
  17092. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  17093. this.on(event, eventHandlers[event]);
  17094. }
  17095. } // Replaces URI header field.
  17096. var replaces = null;
  17097. if (options.replaces) {
  17098. replaces = options.replaces._request.call_id;
  17099. replaces += ";to-tag=".concat(options.replaces._to_tag);
  17100. replaces += ";from-tag=".concat(options.replaces._from_tag);
  17101. replaces = encodeURIComponent(replaces);
  17102. } // Refer-To header field.
  17103. var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">");
  17104. extraHeaders.push(referTo); // Referred-By header field.
  17105. var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">");
  17106. extraHeaders.push(referredBy);
  17107. extraHeaders.push("Contact: ".concat(this._session.contact));
  17108. var request = this._session.sendRequest(JsSIP_C.REFER, {
  17109. extraHeaders: extraHeaders,
  17110. eventHandlers: {
  17111. onSuccessResponse: function onSuccessResponse(response) {
  17112. _this2._requestSucceeded(response);
  17113. },
  17114. onErrorResponse: function onErrorResponse(response) {
  17115. _this2._requestFailed(response, JsSIP_C.causes.REJECTED);
  17116. },
  17117. onTransportError: function onTransportError() {
  17118. _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR);
  17119. },
  17120. onRequestTimeout: function onRequestTimeout() {
  17121. _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17122. },
  17123. onDialogError: function onDialogError() {
  17124. _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR);
  17125. }
  17126. }
  17127. });
  17128. this._id = request.cseq;
  17129. }
  17130. }, {
  17131. key: "receiveNotify",
  17132. value: function receiveNotify(request) {
  17133. debug('receiveNotify()');
  17134. if (!request.body) {
  17135. return;
  17136. }
  17137. var status_line = Grammar.parse(request.body.trim(), 'Status_Line');
  17138. if (status_line === -1) {
  17139. debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\""));
  17140. return;
  17141. }
  17142. switch (true) {
  17143. case /^100$/.test(status_line.status_code):
  17144. this.emit('trying', {
  17145. request: request,
  17146. status_line: status_line
  17147. });
  17148. break;
  17149. case /^1[0-9]{2}$/.test(status_line.status_code):
  17150. this.emit('progress', {
  17151. request: request,
  17152. status_line: status_line
  17153. });
  17154. break;
  17155. case /^2[0-9]{2}$/.test(status_line.status_code):
  17156. this.emit('accepted', {
  17157. request: request,
  17158. status_line: status_line
  17159. });
  17160. break;
  17161. default:
  17162. this.emit('failed', {
  17163. request: request,
  17164. status_line: status_line
  17165. });
  17166. break;
  17167. }
  17168. }
  17169. }, {
  17170. key: "_requestSucceeded",
  17171. value: function _requestSucceeded(response) {
  17172. debug('REFER succeeded');
  17173. debug('emit "requestSucceeded"');
  17174. this.emit('requestSucceeded', {
  17175. response: response
  17176. });
  17177. }
  17178. }, {
  17179. key: "_requestFailed",
  17180. value: function _requestFailed(response, cause) {
  17181. debug('REFER failed');
  17182. debug('emit "requestFailed"');
  17183. this.emit('requestFailed', {
  17184. response: response || null,
  17185. cause: cause
  17186. });
  17187. }
  17188. }, {
  17189. key: "id",
  17190. get: function get() {
  17191. return this._id;
  17192. }
  17193. }]);
  17194. return ReferSubscriber;
  17195. }(EventEmitter);
  17196. },{"../Constants":2,"../Grammar":7,"../Utils":26,"debug":30,"events":29}],17:[function(require,module,exports){
  17197. "use strict";
  17198. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17199. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17200. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17201. var Utils = require('./Utils');
  17202. var JsSIP_C = require('./Constants');
  17203. var SIPMessage = require('./SIPMessage');
  17204. var RequestSender = require('./RequestSender');
  17205. var debug = require('debug')('JsSIP:Registrator');
  17206. var MIN_REGISTER_EXPIRES = 10; // In seconds.
  17207. module.exports =
  17208. /*#__PURE__*/
  17209. function () {
  17210. function Registrator(ua, transport) {
  17211. _classCallCheck(this, Registrator);
  17212. var reg_id = 1; // Force reg_id to 1.
  17213. this._ua = ua;
  17214. this._transport = transport;
  17215. this._registrar = ua.configuration.registrar_server;
  17216. this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2.
  17217. this._call_id = Utils.createRandomToken(22);
  17218. this._cseq = 0;
  17219. this._to_uri = ua.configuration.uri;
  17220. this._registrationTimer = null; // Ongoing Register request.
  17221. this._registering = false; // Set status.
  17222. this._registered = false; // Contact header.
  17223. this._contact = this._ua.contact.toString(); // Sip.ice media feature tag (RFC 5768).
  17224. this._contact += ';+sip.ice'; // Custom headers for REGISTER and un-REGISTER.
  17225. this._extraHeaders = []; // Custom Contact header params for REGISTER and un-REGISTER.
  17226. this._extraContactParams = '';
  17227. if (reg_id) {
  17228. this._contact += ";reg-id=".concat(reg_id);
  17229. this._contact += ";+sip.instance=\"<urn:uuid:".concat(this._ua.configuration.instance_id, ">\"");
  17230. }
  17231. }
  17232. _createClass(Registrator, [{
  17233. key: "setExtraHeaders",
  17234. value: function setExtraHeaders(extraHeaders) {
  17235. if (!Array.isArray(extraHeaders)) {
  17236. extraHeaders = [];
  17237. }
  17238. this._extraHeaders = extraHeaders.slice();
  17239. }
  17240. }, {
  17241. key: "setExtraContactParams",
  17242. value: function setExtraContactParams(extraContactParams) {
  17243. if (!(extraContactParams instanceof Object)) {
  17244. extraContactParams = {};
  17245. } // Reset it.
  17246. this._extraContactParams = '';
  17247. for (var param_key in extraContactParams) {
  17248. if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) {
  17249. var param_value = extraContactParams[param_key];
  17250. this._extraContactParams += ";".concat(param_key);
  17251. if (param_value) {
  17252. this._extraContactParams += "=".concat(param_value);
  17253. }
  17254. }
  17255. }
  17256. }
  17257. }, {
  17258. key: "register",
  17259. value: function register() {
  17260. var _this = this;
  17261. if (this._registering) {
  17262. debug('Register request in progress...');
  17263. return;
  17264. }
  17265. var extraHeaders = this._extraHeaders.slice();
  17266. extraHeaders.push("Contact: ".concat(this._contact, ";expires=").concat(this._expires).concat(this._extraContactParams));
  17267. extraHeaders.push("Expires: ".concat(this._expires));
  17268. var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
  17269. 'to_uri': this._to_uri,
  17270. 'call_id': this._call_id,
  17271. 'cseq': this._cseq += 1
  17272. }, extraHeaders);
  17273. var request_sender = new RequestSender(this._ua, request, {
  17274. onRequestTimeout: function onRequestTimeout() {
  17275. _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17276. },
  17277. onTransportError: function onTransportError() {
  17278. _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR);
  17279. },
  17280. // Increase the CSeq on authentication.
  17281. onAuthenticated: function onAuthenticated() {
  17282. _this._cseq += 1;
  17283. },
  17284. onReceiveResponse: function onReceiveResponse(response) {
  17285. // Discard responses to older REGISTER/un-REGISTER requests.
  17286. if (response.cseq !== _this._cseq) {
  17287. return;
  17288. } // Clear registration timer.
  17289. if (_this._registrationTimer !== null) {
  17290. clearTimeout(_this._registrationTimer);
  17291. _this._registrationTimer = null;
  17292. }
  17293. switch (true) {
  17294. case /^1[0-9]{2}$/.test(response.status_code):
  17295. {
  17296. // Ignore provisional responses.
  17297. break;
  17298. }
  17299. case /^2[0-9]{2}$/.test(response.status_code):
  17300. {
  17301. _this._registering = false;
  17302. if (!response.hasHeader('Contact')) {
  17303. debug('no Contact header in response to REGISTER, response ignored');
  17304. break;
  17305. }
  17306. var contacts = response.headers['Contact'].reduce(function (a, b) {
  17307. return a.concat(b.parsed);
  17308. }, []); // Get the Contact pointing to us and update the expires value accordingly.
  17309. var contact = contacts.find(function (element) {
  17310. return element.uri.user === _this._ua.contact.uri.user;
  17311. });
  17312. if (!contact) {
  17313. debug('no Contact header pointing to us, response ignored');
  17314. break;
  17315. }
  17316. var expires = contact.getParam('expires');
  17317. if (!expires && response.hasHeader('expires')) {
  17318. expires = response.getHeader('expires');
  17319. }
  17320. if (!expires) {
  17321. expires = _this._expires;
  17322. }
  17323. expires = Number(expires);
  17324. if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES; // Re-Register or emit an event before the expiration interval has elapsed.
  17325. // For that, decrease the expires value. ie: 3 seconds.
  17326. _this._registrationTimer = setTimeout(function () {
  17327. _this._registrationTimer = null; // If there are no listeners for registrationExpiring, renew registration.
  17328. // If there are listeners, let the function listening do the register call.
  17329. if (_this._ua.listeners('registrationExpiring').length === 0) {
  17330. _this.register();
  17331. } else {
  17332. _this._ua.emit('registrationExpiring');
  17333. }
  17334. }, expires * 1000 - 5000); // Save gruu values.
  17335. if (contact.hasParam('temp-gruu')) {
  17336. _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, '');
  17337. }
  17338. if (contact.hasParam('pub-gruu')) {
  17339. _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, '');
  17340. }
  17341. if (!_this._registered) {
  17342. _this._registered = true;
  17343. _this._ua.registered({
  17344. response: response
  17345. });
  17346. }
  17347. break;
  17348. }
  17349. // Interval too brief RFC3261 10.2.8.
  17350. case /^423$/.test(response.status_code):
  17351. {
  17352. if (response.hasHeader('min-expires')) {
  17353. // Increase our registration interval to the suggested minimum.
  17354. _this._expires = Number(response.getHeader('min-expires'));
  17355. if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES; // Attempt the registration again immediately.
  17356. _this.register();
  17357. } else {
  17358. // This response MUST contain a Min-Expires header field.
  17359. debug('423 response received for REGISTER without Min-Expires');
  17360. _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE);
  17361. }
  17362. break;
  17363. }
  17364. default:
  17365. {
  17366. var cause = Utils.sipErrorCause(response.status_code);
  17367. _this._registrationFailure(response, cause);
  17368. }
  17369. }
  17370. }
  17371. });
  17372. this._registering = true;
  17373. request_sender.send();
  17374. }
  17375. }, {
  17376. key: "unregister",
  17377. value: function unregister() {
  17378. var _this2 = this;
  17379. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17380. if (!this._registered) {
  17381. debug('already unregistered');
  17382. return;
  17383. }
  17384. this._registered = false; // Clear the registration timer.
  17385. if (this._registrationTimer !== null) {
  17386. clearTimeout(this._registrationTimer);
  17387. this._registrationTimer = null;
  17388. }
  17389. var extraHeaders = this._extraHeaders.slice();
  17390. if (options.all) {
  17391. extraHeaders.push("Contact: *".concat(this._extraContactParams));
  17392. } else {
  17393. extraHeaders.push("Contact: ".concat(this._contact, ";expires=0").concat(this._extraContactParams));
  17394. }
  17395. extraHeaders.push('Expires: 0');
  17396. var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
  17397. 'to_uri': this._to_uri,
  17398. 'call_id': this._call_id,
  17399. 'cseq': this._cseq += 1
  17400. }, extraHeaders);
  17401. var request_sender = new RequestSender(this._ua, request, {
  17402. onRequestTimeout: function onRequestTimeout() {
  17403. _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17404. },
  17405. onTransportError: function onTransportError() {
  17406. _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR);
  17407. },
  17408. // Increase the CSeq on authentication.
  17409. onAuthenticated: function onAuthenticated() {
  17410. _this2._cseq += 1;
  17411. },
  17412. onReceiveResponse: function onReceiveResponse(response) {
  17413. switch (true) {
  17414. case /^1[0-9]{2}$/.test(response.status_code):
  17415. // Ignore provisional responses.
  17416. break;
  17417. case /^2[0-9]{2}$/.test(response.status_code):
  17418. _this2._unregistered(response);
  17419. break;
  17420. default:
  17421. {
  17422. var cause = Utils.sipErrorCause(response.status_code);
  17423. _this2._unregistered(response, cause);
  17424. }
  17425. }
  17426. }
  17427. });
  17428. request_sender.send();
  17429. }
  17430. }, {
  17431. key: "close",
  17432. value: function close() {
  17433. if (this._registered) {
  17434. this.unregister();
  17435. }
  17436. }
  17437. }, {
  17438. key: "onTransportClosed",
  17439. value: function onTransportClosed() {
  17440. this._registering = false;
  17441. if (this._registrationTimer !== null) {
  17442. clearTimeout(this._registrationTimer);
  17443. this._registrationTimer = null;
  17444. }
  17445. if (this._registered) {
  17446. this._registered = false;
  17447. this._ua.unregistered({});
  17448. }
  17449. }
  17450. }, {
  17451. key: "_registrationFailure",
  17452. value: function _registrationFailure(response, cause) {
  17453. this._registering = false;
  17454. this._ua.registrationFailed({
  17455. response: response || null,
  17456. cause: cause
  17457. });
  17458. if (this._registered) {
  17459. this._registered = false;
  17460. this._ua.unregistered({
  17461. response: response || null,
  17462. cause: cause
  17463. });
  17464. }
  17465. }
  17466. }, {
  17467. key: "_unregistered",
  17468. value: function _unregistered(response, cause) {
  17469. this._registering = false;
  17470. this._registered = false;
  17471. this._ua.unregistered({
  17472. response: response || null,
  17473. cause: cause || null
  17474. });
  17475. }
  17476. }, {
  17477. key: "registered",
  17478. get: function get() {
  17479. return this._registered;
  17480. }
  17481. }]);
  17482. return Registrator;
  17483. }();
  17484. },{"./Constants":2,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30}],18:[function(require,module,exports){
  17485. "use strict";
  17486. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17487. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17488. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17489. var JsSIP_C = require('./Constants');
  17490. var DigestAuthentication = require('./DigestAuthentication');
  17491. var Transactions = require('./Transactions');
  17492. var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers.
  17493. var EventHandlers = {
  17494. onRequestTimeout: function onRequestTimeout() {},
  17495. onTransportError: function onTransportError() {},
  17496. onReceiveResponse: function onReceiveResponse() {},
  17497. onAuthenticated: function onAuthenticated() {}
  17498. };
  17499. module.exports =
  17500. /*#__PURE__*/
  17501. function () {
  17502. function RequestSender(ua, request, eventHandlers) {
  17503. _classCallCheck(this, RequestSender);
  17504. this._ua = ua;
  17505. this._eventHandlers = eventHandlers;
  17506. this._method = request.method;
  17507. this._request = request;
  17508. this._auth = null;
  17509. this._challenged = false;
  17510. this._staled = false; // Define the undefined handlers.
  17511. for (var handler in EventHandlers) {
  17512. if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
  17513. if (!this._eventHandlers[handler]) {
  17514. this._eventHandlers[handler] = EventHandlers[handler];
  17515. }
  17516. }
  17517. } // If ua is in closing process or even closed just allow sending Bye and ACK.
  17518. if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) {
  17519. this._eventHandlers.onTransportError();
  17520. }
  17521. }
  17522. /**
  17523. * Create the client transaction and send the message.
  17524. */
  17525. _createClass(RequestSender, [{
  17526. key: "send",
  17527. value: function send() {
  17528. var _this = this;
  17529. var eventHandlers = {
  17530. onRequestTimeout: function onRequestTimeout() {
  17531. _this._eventHandlers.onRequestTimeout();
  17532. },
  17533. onTransportError: function onTransportError() {
  17534. _this._eventHandlers.onTransportError();
  17535. },
  17536. onReceiveResponse: function onReceiveResponse(response) {
  17537. _this._receiveResponse(response);
  17538. }
  17539. };
  17540. switch (this._method) {
  17541. case 'INVITE':
  17542. this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17543. break;
  17544. case 'ACK':
  17545. this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17546. break;
  17547. default:
  17548. this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17549. }
  17550. this.clientTransaction.send();
  17551. }
  17552. /**
  17553. * Called from client transaction when receiving a correct response to the request.
  17554. * Authenticate request if needed or pass the response back to the applicant.
  17555. */
  17556. }, {
  17557. key: "_receiveResponse",
  17558. value: function _receiveResponse(response) {
  17559. var challenge;
  17560. var authorization_header_name;
  17561. var status_code = response.status_code;
  17562. /*
  17563. * Authentication
  17564. * Authenticate once. _challenged_ flag used to avoid infinite authentications.
  17565. */
  17566. if ((status_code === 401 || status_code === 407) && (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) {
  17567. // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header.
  17568. if (response.status_code === 401) {
  17569. challenge = response.parseHeader('www-authenticate');
  17570. authorization_header_name = 'authorization';
  17571. } else {
  17572. challenge = response.parseHeader('proxy-authenticate');
  17573. authorization_header_name = 'proxy-authorization';
  17574. } // Verify it seems a valid challenge.
  17575. if (!challenge) {
  17576. debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate"));
  17577. this._eventHandlers.onReceiveResponse(response);
  17578. return;
  17579. }
  17580. if (!this._challenged || !this._staled && challenge.stale === true) {
  17581. if (!this._auth) {
  17582. this._auth = new DigestAuthentication({
  17583. username: this._ua.configuration.authorization_user,
  17584. password: this._ua.configuration.password,
  17585. realm: this._ua.configuration.realm,
  17586. ha1: this._ua.configuration.ha1
  17587. });
  17588. } // Verify that the challenge is really valid.
  17589. if (!this._auth.authenticate(this._request, challenge)) {
  17590. this._eventHandlers.onReceiveResponse(response);
  17591. return;
  17592. }
  17593. this._challenged = true; // Update ha1 and realm in the UA.
  17594. this._ua.set('realm', this._auth.get('realm'));
  17595. this._ua.set('ha1', this._auth.get('ha1'));
  17596. if (challenge.stale) {
  17597. this._staled = true;
  17598. }
  17599. this._request = this._request.clone();
  17600. this._request.cseq += 1;
  17601. this._request.setHeader('cseq', "".concat(this._request.cseq, " ").concat(this._method));
  17602. this._request.setHeader(authorization_header_name, this._auth.toString());
  17603. this._eventHandlers.onAuthenticated(this._request);
  17604. this.send();
  17605. } else {
  17606. this._eventHandlers.onReceiveResponse(response);
  17607. }
  17608. } else {
  17609. this._eventHandlers.onReceiveResponse(response);
  17610. }
  17611. }
  17612. }]);
  17613. return RequestSender;
  17614. }();
  17615. },{"./Constants":2,"./DigestAuthentication":5,"./Transactions":22,"debug":30}],19:[function(require,module,exports){
  17616. "use strict";
  17617. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  17618. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17619. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17620. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17621. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  17622. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17623. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17624. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  17625. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17626. var sdp_transform = require('sdp-transform');
  17627. var JsSIP_C = require('./Constants');
  17628. var Utils = require('./Utils');
  17629. var NameAddrHeader = require('./NameAddrHeader');
  17630. var Grammar = require('./Grammar');
  17631. var debug = require('debug')('JsSIP:SIPMessage');
  17632. /**
  17633. * -param {String} method request method
  17634. * -param {String} ruri request uri
  17635. * -param {UA} ua
  17636. * -param {Object} params parameters that will have priority over ua.configuration parameters:
  17637. * <br>
  17638. * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set
  17639. * -param {Object} [headers] extra headers
  17640. * -param {String} [body]
  17641. */
  17642. var OutgoingRequest =
  17643. /*#__PURE__*/
  17644. function () {
  17645. function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) {
  17646. _classCallCheck(this, OutgoingRequest);
  17647. // Mandatory parameters check.
  17648. if (!method || !ruri || !ua) {
  17649. return null;
  17650. }
  17651. params = params || {};
  17652. this.ua = ua;
  17653. this.headers = {};
  17654. this.method = method;
  17655. this.ruri = ruri;
  17656. this.body = body;
  17657. this.extraHeaders = Utils.cloneArray(extraHeaders); // Fill the Common SIP Request Headers.
  17658. // Route.
  17659. if (params.route_set) {
  17660. this.setHeader('route', params.route_set);
  17661. } else if (ua.configuration.use_preloaded_route) {
  17662. this.setHeader('route', "<".concat(ua.transport.sip_uri, ";lr>"));
  17663. } // Via.
  17664. // Empty Via header. Will be filled by the client transaction.
  17665. this.setHeader('via', ''); // Max-Forwards.
  17666. this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS); // To
  17667. var to_uri = params.to_uri || ruri;
  17668. var to_params = params.to_tag ? {
  17669. tag: params.to_tag
  17670. } : null;
  17671. var to_display_name = typeof params.to_display_name !== 'undefined' ? params.to_display_name : null;
  17672. this.to = new NameAddrHeader(to_uri, to_display_name, to_params);
  17673. this.setHeader('to', this.to.toString()); // From.
  17674. var from_uri = params.from_uri || ua.configuration.uri;
  17675. var from_params = {
  17676. tag: params.from_tag || Utils.newTag()
  17677. };
  17678. var display_name;
  17679. if (typeof params.from_display_name !== 'undefined') {
  17680. display_name = params.from_display_name;
  17681. } else if (ua.configuration.display_name) {
  17682. display_name = ua.configuration.display_name;
  17683. } else {
  17684. display_name = null;
  17685. }
  17686. this.from = new NameAddrHeader(from_uri, display_name, from_params);
  17687. this.setHeader('from', this.from.toString()); // Call-ID.
  17688. var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15);
  17689. this.call_id = call_id;
  17690. this.setHeader('call-id', call_id); // CSeq.
  17691. var cseq = params.cseq || Math.floor(Math.random() * 10000);
  17692. this.cseq = cseq;
  17693. this.setHeader('cseq', "".concat(cseq, " ").concat(method));
  17694. }
  17695. /**
  17696. * Replace the the given header by the given value.
  17697. * -param {String} name header name
  17698. * -param {String | Array} value header value
  17699. */
  17700. _createClass(OutgoingRequest, [{
  17701. key: "setHeader",
  17702. value: function setHeader(name, value) {
  17703. // Remove the header from extraHeaders if present.
  17704. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  17705. for (var idx = 0; idx < this.extraHeaders.length; idx++) {
  17706. if (regexp.test(this.extraHeaders[idx])) {
  17707. this.extraHeaders.splice(idx, 1);
  17708. }
  17709. }
  17710. this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
  17711. }
  17712. /**
  17713. * Get the value of the given header name at the given position.
  17714. * -param {String} name header name
  17715. * -returns {String|undefined} Returns the specified header, null if header doesn't exist.
  17716. */
  17717. }, {
  17718. key: "getHeader",
  17719. value: function getHeader(name) {
  17720. var headers = this.headers[Utils.headerize(name)];
  17721. if (headers) {
  17722. if (headers[0]) {
  17723. return headers[0];
  17724. }
  17725. } else {
  17726. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  17727. var _iteratorNormalCompletion = true;
  17728. var _didIteratorError = false;
  17729. var _iteratorError = undefined;
  17730. try {
  17731. for (var _iterator = this.extraHeaders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  17732. var header = _step.value;
  17733. if (regexp.test(header)) {
  17734. return header.substring(header.indexOf(':') + 1).trim();
  17735. }
  17736. }
  17737. } catch (err) {
  17738. _didIteratorError = true;
  17739. _iteratorError = err;
  17740. } finally {
  17741. try {
  17742. if (!_iteratorNormalCompletion && _iterator.return != null) {
  17743. _iterator.return();
  17744. }
  17745. } finally {
  17746. if (_didIteratorError) {
  17747. throw _iteratorError;
  17748. }
  17749. }
  17750. }
  17751. }
  17752. return;
  17753. }
  17754. /**
  17755. * Get the header/s of the given name.
  17756. * -param {String} name header name
  17757. * -returns {Array} Array with all the headers of the specified name.
  17758. */
  17759. }, {
  17760. key: "getHeaders",
  17761. value: function getHeaders(name) {
  17762. var headers = this.headers[Utils.headerize(name)];
  17763. var result = [];
  17764. if (headers) {
  17765. var _iteratorNormalCompletion2 = true;
  17766. var _didIteratorError2 = false;
  17767. var _iteratorError2 = undefined;
  17768. try {
  17769. for (var _iterator2 = headers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  17770. var header = _step2.value;
  17771. result.push(header);
  17772. }
  17773. } catch (err) {
  17774. _didIteratorError2 = true;
  17775. _iteratorError2 = err;
  17776. } finally {
  17777. try {
  17778. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  17779. _iterator2.return();
  17780. }
  17781. } finally {
  17782. if (_didIteratorError2) {
  17783. throw _iteratorError2;
  17784. }
  17785. }
  17786. }
  17787. return result;
  17788. } else {
  17789. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  17790. var _iteratorNormalCompletion3 = true;
  17791. var _didIteratorError3 = false;
  17792. var _iteratorError3 = undefined;
  17793. try {
  17794. for (var _iterator3 = this.extraHeaders[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  17795. var _header = _step3.value;
  17796. if (regexp.test(_header)) {
  17797. result.push(_header.substring(_header.indexOf(':') + 1).trim());
  17798. }
  17799. }
  17800. } catch (err) {
  17801. _didIteratorError3 = true;
  17802. _iteratorError3 = err;
  17803. } finally {
  17804. try {
  17805. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  17806. _iterator3.return();
  17807. }
  17808. } finally {
  17809. if (_didIteratorError3) {
  17810. throw _iteratorError3;
  17811. }
  17812. }
  17813. }
  17814. return result;
  17815. }
  17816. }
  17817. /**
  17818. * Verify the existence of the given header.
  17819. * -param {String} name header name
  17820. * -returns {boolean} true if header with given name exists, false otherwise
  17821. */
  17822. }, {
  17823. key: "hasHeader",
  17824. value: function hasHeader(name) {
  17825. if (this.headers[Utils.headerize(name)]) {
  17826. return true;
  17827. } else {
  17828. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  17829. var _iteratorNormalCompletion4 = true;
  17830. var _didIteratorError4 = false;
  17831. var _iteratorError4 = undefined;
  17832. try {
  17833. for (var _iterator4 = this.extraHeaders[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  17834. var header = _step4.value;
  17835. if (regexp.test(header)) {
  17836. return true;
  17837. }
  17838. }
  17839. } catch (err) {
  17840. _didIteratorError4 = true;
  17841. _iteratorError4 = err;
  17842. } finally {
  17843. try {
  17844. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  17845. _iterator4.return();
  17846. }
  17847. } finally {
  17848. if (_didIteratorError4) {
  17849. throw _iteratorError4;
  17850. }
  17851. }
  17852. }
  17853. }
  17854. return false;
  17855. }
  17856. /**
  17857. * Parse the current body as a SDP and store the resulting object
  17858. * into this.sdp.
  17859. * -param {Boolean} force: Parse even if this.sdp already exists.
  17860. *
  17861. * Returns this.sdp.
  17862. */
  17863. }, {
  17864. key: "parseSDP",
  17865. value: function parseSDP(force) {
  17866. if (!force && this.sdp) {
  17867. return this.sdp;
  17868. } else {
  17869. this.sdp = sdp_transform.parse(this.body || '');
  17870. return this.sdp;
  17871. }
  17872. }
  17873. }, {
  17874. key: "toString",
  17875. value: function toString() {
  17876. var msg = "".concat(this.method, " ").concat(this.ruri, " SIP/2.0\r\n");
  17877. for (var headerName in this.headers) {
  17878. if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) {
  17879. var _iteratorNormalCompletion5 = true;
  17880. var _didIteratorError5 = false;
  17881. var _iteratorError5 = undefined;
  17882. try {
  17883. for (var _iterator5 = this.headers[headerName][Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  17884. var headerValue = _step5.value;
  17885. msg += "".concat(headerName, ": ").concat(headerValue, "\r\n");
  17886. }
  17887. } catch (err) {
  17888. _didIteratorError5 = true;
  17889. _iteratorError5 = err;
  17890. } finally {
  17891. try {
  17892. if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
  17893. _iterator5.return();
  17894. }
  17895. } finally {
  17896. if (_didIteratorError5) {
  17897. throw _iteratorError5;
  17898. }
  17899. }
  17900. }
  17901. }
  17902. }
  17903. var _iteratorNormalCompletion6 = true;
  17904. var _didIteratorError6 = false;
  17905. var _iteratorError6 = undefined;
  17906. try {
  17907. for (var _iterator6 = this.extraHeaders[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
  17908. var header = _step6.value;
  17909. msg += "".concat(header.trim(), "\r\n");
  17910. } // Supported.
  17911. } catch (err) {
  17912. _didIteratorError6 = true;
  17913. _iteratorError6 = err;
  17914. } finally {
  17915. try {
  17916. if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
  17917. _iterator6.return();
  17918. }
  17919. } finally {
  17920. if (_didIteratorError6) {
  17921. throw _iteratorError6;
  17922. }
  17923. }
  17924. }
  17925. var supported = [];
  17926. switch (this.method) {
  17927. case JsSIP_C.REGISTER:
  17928. supported.push('path', 'gruu');
  17929. break;
  17930. case JsSIP_C.INVITE:
  17931. if (this.ua.configuration.session_timers) {
  17932. supported.push('timer');
  17933. }
  17934. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  17935. supported.push('gruu');
  17936. }
  17937. supported.push('ice', 'replaces');
  17938. break;
  17939. case JsSIP_C.UPDATE:
  17940. if (this.ua.configuration.session_timers) {
  17941. supported.push('timer');
  17942. }
  17943. supported.push('ice');
  17944. break;
  17945. }
  17946. supported.push('outbound');
  17947. var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT; // Allow.
  17948. msg += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  17949. msg += "Supported: ".concat(supported, "\r\n");
  17950. msg += "User-Agent: ".concat(userAgent, "\r\n");
  17951. if (this.body) {
  17952. var length = Utils.str_utf8_length(this.body);
  17953. msg += "Content-Length: ".concat(length, "\r\n\r\n");
  17954. msg += this.body;
  17955. } else {
  17956. msg += 'Content-Length: 0\r\n\r\n';
  17957. }
  17958. return msg;
  17959. }
  17960. }, {
  17961. key: "clone",
  17962. value: function clone() {
  17963. var request = new OutgoingRequest(this.method, this.ruri, this.ua);
  17964. Object.keys(this.headers).forEach(function (name) {
  17965. request.headers[name] = this.headers[name].slice();
  17966. }, this);
  17967. request.body = this.body;
  17968. request.extraHeaders = Utils.cloneArray(this.extraHeaders);
  17969. request.to = this.to;
  17970. request.from = this.from;
  17971. request.call_id = this.call_id;
  17972. request.cseq = this.cseq;
  17973. return request;
  17974. }
  17975. }]);
  17976. return OutgoingRequest;
  17977. }();
  17978. var InitialOutgoingInviteRequest =
  17979. /*#__PURE__*/
  17980. function (_OutgoingRequest) {
  17981. _inherits(InitialOutgoingInviteRequest, _OutgoingRequest);
  17982. function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) {
  17983. var _this;
  17984. _classCallCheck(this, InitialOutgoingInviteRequest);
  17985. _this = _possibleConstructorReturn(this, _getPrototypeOf(InitialOutgoingInviteRequest).call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body));
  17986. _this.transaction = null;
  17987. return _this;
  17988. }
  17989. _createClass(InitialOutgoingInviteRequest, [{
  17990. key: "cancel",
  17991. value: function cancel(reason) {
  17992. this.transaction.cancel(reason);
  17993. }
  17994. }, {
  17995. key: "clone",
  17996. value: function clone() {
  17997. var request = new InitialOutgoingInviteRequest(this.ruri, this.ua);
  17998. Object.keys(this.headers).forEach(function (name) {
  17999. request.headers[name] = this.headers[name].slice();
  18000. }, this);
  18001. request.body = this.body;
  18002. request.extraHeaders = Utils.cloneArray(this.extraHeaders);
  18003. request.to = this.to;
  18004. request.from = this.from;
  18005. request.call_id = this.call_id;
  18006. request.cseq = this.cseq;
  18007. request.transaction = this.transaction;
  18008. return request;
  18009. }
  18010. }]);
  18011. return InitialOutgoingInviteRequest;
  18012. }(OutgoingRequest);
  18013. var IncomingMessage =
  18014. /*#__PURE__*/
  18015. function () {
  18016. function IncomingMessage() {
  18017. _classCallCheck(this, IncomingMessage);
  18018. this.data = null;
  18019. this.headers = null;
  18020. this.method = null;
  18021. this.via = null;
  18022. this.via_branch = null;
  18023. this.call_id = null;
  18024. this.cseq = null;
  18025. this.from = null;
  18026. this.from_tag = null;
  18027. this.to = null;
  18028. this.to_tag = null;
  18029. this.body = null;
  18030. this.sdp = null;
  18031. }
  18032. /**
  18033. * Insert a header of the given name and value into the last position of the
  18034. * header array.
  18035. */
  18036. _createClass(IncomingMessage, [{
  18037. key: "addHeader",
  18038. value: function addHeader(name, value) {
  18039. var header = {
  18040. raw: value
  18041. };
  18042. name = Utils.headerize(name);
  18043. if (this.headers[name]) {
  18044. this.headers[name].push(header);
  18045. } else {
  18046. this.headers[name] = [header];
  18047. }
  18048. }
  18049. /**
  18050. * Get the value of the given header name at the given position.
  18051. */
  18052. }, {
  18053. key: "getHeader",
  18054. value: function getHeader(name) {
  18055. var header = this.headers[Utils.headerize(name)];
  18056. if (header) {
  18057. if (header[0]) {
  18058. return header[0].raw;
  18059. }
  18060. } else {
  18061. return;
  18062. }
  18063. }
  18064. /**
  18065. * Get the header/s of the given name.
  18066. */
  18067. }, {
  18068. key: "getHeaders",
  18069. value: function getHeaders(name) {
  18070. var headers = this.headers[Utils.headerize(name)];
  18071. var result = [];
  18072. if (!headers) {
  18073. return [];
  18074. }
  18075. var _iteratorNormalCompletion7 = true;
  18076. var _didIteratorError7 = false;
  18077. var _iteratorError7 = undefined;
  18078. try {
  18079. for (var _iterator7 = headers[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
  18080. var header = _step7.value;
  18081. result.push(header.raw);
  18082. }
  18083. } catch (err) {
  18084. _didIteratorError7 = true;
  18085. _iteratorError7 = err;
  18086. } finally {
  18087. try {
  18088. if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
  18089. _iterator7.return();
  18090. }
  18091. } finally {
  18092. if (_didIteratorError7) {
  18093. throw _iteratorError7;
  18094. }
  18095. }
  18096. }
  18097. return result;
  18098. }
  18099. /**
  18100. * Verify the existence of the given header.
  18101. */
  18102. }, {
  18103. key: "hasHeader",
  18104. value: function hasHeader(name) {
  18105. return this.headers[Utils.headerize(name)] ? true : false;
  18106. }
  18107. /**
  18108. * Parse the given header on the given index.
  18109. * -param {String} name header name
  18110. * -param {Number} [idx=0] header index
  18111. * -returns {Object|undefined} Parsed header object, undefined if the header
  18112. * is not present or in case of a parsing error.
  18113. */
  18114. }, {
  18115. key: "parseHeader",
  18116. value: function parseHeader(name) {
  18117. var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  18118. name = Utils.headerize(name);
  18119. if (!this.headers[name]) {
  18120. debug("header \"".concat(name, "\" not present"));
  18121. return;
  18122. } else if (idx >= this.headers[name].length) {
  18123. debug("not so many \"".concat(name, "\" headers present"));
  18124. return;
  18125. }
  18126. var header = this.headers[name][idx];
  18127. var value = header.raw;
  18128. if (header.parsed) {
  18129. return header.parsed;
  18130. } // Substitute '-' by '_' for grammar rule matching.
  18131. var parsed = Grammar.parse(value, name.replace(/-/g, '_'));
  18132. if (parsed === -1) {
  18133. this.headers[name].splice(idx, 1); // delete from headers
  18134. debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\""));
  18135. return;
  18136. } else {
  18137. header.parsed = parsed;
  18138. return parsed;
  18139. }
  18140. }
  18141. /**
  18142. * Message Header attribute selector. Alias of parseHeader.
  18143. * -param {String} name header name
  18144. * -param {Number} [idx=0] header index
  18145. * -returns {Object|undefined} Parsed header object, undefined if the header
  18146. * is not present or in case of a parsing error.
  18147. *
  18148. * -example
  18149. * message.s('via',3).port
  18150. */
  18151. }, {
  18152. key: "s",
  18153. value: function s(name, idx) {
  18154. return this.parseHeader(name, idx);
  18155. }
  18156. /**
  18157. * Replace the value of the given header by the value.
  18158. * -param {String} name header name
  18159. * -param {String} value header value
  18160. */
  18161. }, {
  18162. key: "setHeader",
  18163. value: function setHeader(name, value) {
  18164. var header = {
  18165. raw: value
  18166. };
  18167. this.headers[Utils.headerize(name)] = [header];
  18168. }
  18169. /**
  18170. * Parse the current body as a SDP and store the resulting object
  18171. * into this.sdp.
  18172. * -param {Boolean} force: Parse even if this.sdp already exists.
  18173. *
  18174. * Returns this.sdp.
  18175. */
  18176. }, {
  18177. key: "parseSDP",
  18178. value: function parseSDP(force) {
  18179. if (!force && this.sdp) {
  18180. return this.sdp;
  18181. } else {
  18182. this.sdp = sdp_transform.parse(this.body || '');
  18183. return this.sdp;
  18184. }
  18185. }
  18186. }, {
  18187. key: "toString",
  18188. value: function toString() {
  18189. return this.data;
  18190. }
  18191. }]);
  18192. return IncomingMessage;
  18193. }();
  18194. var IncomingRequest =
  18195. /*#__PURE__*/
  18196. function (_IncomingMessage) {
  18197. _inherits(IncomingRequest, _IncomingMessage);
  18198. function IncomingRequest(ua) {
  18199. var _this2;
  18200. _classCallCheck(this, IncomingRequest);
  18201. _this2 = _possibleConstructorReturn(this, _getPrototypeOf(IncomingRequest).call(this));
  18202. _this2.ua = ua;
  18203. _this2.headers = {};
  18204. _this2.ruri = null;
  18205. _this2.transport = null;
  18206. _this2.server_transaction = null;
  18207. return _this2;
  18208. }
  18209. /**
  18210. * Stateful reply.
  18211. * -param {Number} code status code
  18212. * -param {String} reason reason phrase
  18213. * -param {Object} headers extra headers
  18214. * -param {String} body body
  18215. * -param {Function} [onSuccess] onSuccess callback
  18216. * -param {Function} [onFailure] onFailure callback
  18217. */
  18218. _createClass(IncomingRequest, [{
  18219. key: "reply",
  18220. value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) {
  18221. var supported = [];
  18222. var to = this.getHeader('To');
  18223. code = code || null;
  18224. reason = reason || null; // Validate code and reason values.
  18225. if (!code || code < 100 || code > 699) {
  18226. throw new TypeError("Invalid status_code: ".concat(code));
  18227. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  18228. throw new TypeError("Invalid reason_phrase: ".concat(reason));
  18229. }
  18230. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  18231. extraHeaders = Utils.cloneArray(extraHeaders);
  18232. var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n");
  18233. if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) {
  18234. var headers = this.getHeaders('record-route');
  18235. var _iteratorNormalCompletion8 = true;
  18236. var _didIteratorError8 = false;
  18237. var _iteratorError8 = undefined;
  18238. try {
  18239. for (var _iterator8 = headers[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
  18240. var header = _step8.value;
  18241. response += "Record-Route: ".concat(header, "\r\n");
  18242. }
  18243. } catch (err) {
  18244. _didIteratorError8 = true;
  18245. _iteratorError8 = err;
  18246. } finally {
  18247. try {
  18248. if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
  18249. _iterator8.return();
  18250. }
  18251. } finally {
  18252. if (_didIteratorError8) {
  18253. throw _iteratorError8;
  18254. }
  18255. }
  18256. }
  18257. }
  18258. var vias = this.getHeaders('via');
  18259. var _iteratorNormalCompletion9 = true;
  18260. var _didIteratorError9 = false;
  18261. var _iteratorError9 = undefined;
  18262. try {
  18263. for (var _iterator9 = vias[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
  18264. var via = _step9.value;
  18265. response += "Via: ".concat(via, "\r\n");
  18266. }
  18267. } catch (err) {
  18268. _didIteratorError9 = true;
  18269. _iteratorError9 = err;
  18270. } finally {
  18271. try {
  18272. if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
  18273. _iterator9.return();
  18274. }
  18275. } finally {
  18276. if (_didIteratorError9) {
  18277. throw _iteratorError9;
  18278. }
  18279. }
  18280. }
  18281. if (!this.to_tag && code > 100) {
  18282. to += ";tag=".concat(Utils.newTag());
  18283. } else if (this.to_tag && !this.s('to').hasParam('tag')) {
  18284. to += ";tag=".concat(this.to_tag);
  18285. }
  18286. response += "To: ".concat(to, "\r\n");
  18287. response += "From: ".concat(this.getHeader('From'), "\r\n");
  18288. response += "Call-ID: ".concat(this.call_id, "\r\n");
  18289. response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n");
  18290. var _iteratorNormalCompletion10 = true;
  18291. var _didIteratorError10 = false;
  18292. var _iteratorError10 = undefined;
  18293. try {
  18294. for (var _iterator10 = extraHeaders[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
  18295. var _header2 = _step10.value;
  18296. response += "".concat(_header2.trim(), "\r\n");
  18297. } // Supported.
  18298. } catch (err) {
  18299. _didIteratorError10 = true;
  18300. _iteratorError10 = err;
  18301. } finally {
  18302. try {
  18303. if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
  18304. _iterator10.return();
  18305. }
  18306. } finally {
  18307. if (_didIteratorError10) {
  18308. throw _iteratorError10;
  18309. }
  18310. }
  18311. }
  18312. switch (this.method) {
  18313. case JsSIP_C.INVITE:
  18314. if (this.ua.configuration.session_timers) {
  18315. supported.push('timer');
  18316. }
  18317. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  18318. supported.push('gruu');
  18319. }
  18320. supported.push('ice', 'replaces');
  18321. break;
  18322. case JsSIP_C.UPDATE:
  18323. if (this.ua.configuration.session_timers) {
  18324. supported.push('timer');
  18325. }
  18326. if (body) {
  18327. supported.push('ice');
  18328. }
  18329. supported.push('replaces');
  18330. }
  18331. supported.push('outbound'); // Allow and Accept.
  18332. if (this.method === JsSIP_C.OPTIONS) {
  18333. response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  18334. response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n");
  18335. } else if (code === 405) {
  18336. response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  18337. } else if (code === 415) {
  18338. response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n");
  18339. }
  18340. response += "Supported: ".concat(supported, "\r\n");
  18341. if (body) {
  18342. var length = Utils.str_utf8_length(body);
  18343. response += 'Content-Type: application/sdp\r\n';
  18344. response += "Content-Length: ".concat(length, "\r\n\r\n");
  18345. response += body;
  18346. } else {
  18347. response += "Content-Length: ".concat(0, "\r\n\r\n");
  18348. }
  18349. this.server_transaction.receiveResponse(code, response, onSuccess, onFailure);
  18350. }
  18351. /**
  18352. * Stateless reply.
  18353. * -param {Number} code status code
  18354. * -param {String} reason reason phrase
  18355. */
  18356. }, {
  18357. key: "reply_sl",
  18358. value: function reply_sl() {
  18359. var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  18360. var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  18361. var vias = this.getHeaders('via'); // Validate code and reason values.
  18362. if (!code || code < 100 || code > 699) {
  18363. throw new TypeError("Invalid status_code: ".concat(code));
  18364. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  18365. throw new TypeError("Invalid reason_phrase: ".concat(reason));
  18366. }
  18367. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  18368. var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n");
  18369. var _iteratorNormalCompletion11 = true;
  18370. var _didIteratorError11 = false;
  18371. var _iteratorError11 = undefined;
  18372. try {
  18373. for (var _iterator11 = vias[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
  18374. var via = _step11.value;
  18375. response += "Via: ".concat(via, "\r\n");
  18376. }
  18377. } catch (err) {
  18378. _didIteratorError11 = true;
  18379. _iteratorError11 = err;
  18380. } finally {
  18381. try {
  18382. if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
  18383. _iterator11.return();
  18384. }
  18385. } finally {
  18386. if (_didIteratorError11) {
  18387. throw _iteratorError11;
  18388. }
  18389. }
  18390. }
  18391. var to = this.getHeader('To');
  18392. if (!this.to_tag && code > 100) {
  18393. to += ";tag=".concat(Utils.newTag());
  18394. } else if (this.to_tag && !this.s('to').hasParam('tag')) {
  18395. to += ";tag=".concat(this.to_tag);
  18396. }
  18397. response += "To: ".concat(to, "\r\n");
  18398. response += "From: ".concat(this.getHeader('From'), "\r\n");
  18399. response += "Call-ID: ".concat(this.call_id, "\r\n");
  18400. response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n");
  18401. response += "Content-Length: ".concat(0, "\r\n\r\n");
  18402. this.transport.send(response);
  18403. }
  18404. }]);
  18405. return IncomingRequest;
  18406. }(IncomingMessage);
  18407. var IncomingResponse =
  18408. /*#__PURE__*/
  18409. function (_IncomingMessage2) {
  18410. _inherits(IncomingResponse, _IncomingMessage2);
  18411. function IncomingResponse() {
  18412. var _this3;
  18413. _classCallCheck(this, IncomingResponse);
  18414. _this3 = _possibleConstructorReturn(this, _getPrototypeOf(IncomingResponse).call(this));
  18415. _this3.headers = {};
  18416. _this3.status_code = null;
  18417. _this3.reason_phrase = null;
  18418. return _this3;
  18419. }
  18420. return IncomingResponse;
  18421. }(IncomingMessage);
  18422. module.exports = {
  18423. OutgoingRequest: OutgoingRequest,
  18424. InitialOutgoingInviteRequest: InitialOutgoingInviteRequest,
  18425. IncomingRequest: IncomingRequest,
  18426. IncomingResponse: IncomingResponse
  18427. };
  18428. },{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":26,"debug":30,"sdp-transform":35}],20:[function(require,module,exports){
  18429. "use strict";
  18430. var Utils = require('./Utils');
  18431. var Grammar = require('./Grammar');
  18432. var debugerror = require('debug')('JsSIP:ERROR:Socket');
  18433. debugerror.log = console.warn.bind(console);
  18434. /**
  18435. * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/
  18436. *
  18437. * interface Socket {
  18438. * attribute String via_transport
  18439. * attribute String url
  18440. * attribute String sip_uri
  18441. *
  18442. * method connect();
  18443. * method disconnect();
  18444. * method send(data);
  18445. *
  18446. * attribute EventHandler onconnect
  18447. * attribute EventHandler ondisconnect
  18448. * attribute EventHandler ondata
  18449. * }
  18450. *
  18451. */
  18452. exports.isSocket = function (socket) {
  18453. // Ignore if an array is given.
  18454. if (Array.isArray(socket)) {
  18455. return false;
  18456. }
  18457. if (typeof socket === 'undefined') {
  18458. debugerror('undefined JsSIP.Socket instance');
  18459. return false;
  18460. } // Check Properties.
  18461. try {
  18462. if (!Utils.isString(socket.url)) {
  18463. debugerror('missing or invalid JsSIP.Socket url property');
  18464. throw new Error();
  18465. }
  18466. if (!Utils.isString(socket.via_transport)) {
  18467. debugerror('missing or invalid JsSIP.Socket via_transport property');
  18468. throw new Error();
  18469. }
  18470. if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) {
  18471. debugerror('missing or invalid JsSIP.Socket sip_uri property');
  18472. throw new Error();
  18473. }
  18474. } catch (e) {
  18475. return false;
  18476. } // Check Methods.
  18477. try {
  18478. ['connect', 'disconnect', 'send'].forEach(function (method) {
  18479. if (!Utils.isFunction(socket[method])) {
  18480. debugerror("missing or invalid JsSIP.Socket method: ".concat(method));
  18481. throw new Error();
  18482. }
  18483. });
  18484. } catch (e) {
  18485. return false;
  18486. }
  18487. return true;
  18488. };
  18489. },{"./Grammar":7,"./Utils":26,"debug":30}],21:[function(require,module,exports){
  18490. "use strict";
  18491. var T1 = 500,
  18492. T2 = 4000,
  18493. T4 = 5000;
  18494. module.exports = {
  18495. T1: T1,
  18496. T2: T2,
  18497. T4: T4,
  18498. TIMER_B: 64 * T1,
  18499. TIMER_D: 0 * T1,
  18500. TIMER_F: 64 * T1,
  18501. TIMER_H: 64 * T1,
  18502. TIMER_I: 0 * T1,
  18503. TIMER_J: 0 * T1,
  18504. TIMER_K: 0 * T4,
  18505. TIMER_L: 64 * T1,
  18506. TIMER_M: 64 * T1,
  18507. PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1
  18508. };
  18509. },{}],22:[function(require,module,exports){
  18510. "use strict";
  18511. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  18512. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18513. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  18514. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18515. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18516. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18517. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  18518. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18519. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18520. var EventEmitter = require('events').EventEmitter;
  18521. var JsSIP_C = require('./Constants');
  18522. var SIPMessage = require('./SIPMessage');
  18523. var Timers = require('./Timers');
  18524. var debugnict = require('debug')('JsSIP:NonInviteClientTransaction');
  18525. var debugict = require('debug')('JsSIP:InviteClientTransaction');
  18526. var debugact = require('debug')('JsSIP:AckClientTransaction');
  18527. var debugnist = require('debug')('JsSIP:NonInviteServerTransaction');
  18528. var debugist = require('debug')('JsSIP:InviteServerTransaction');
  18529. var C = {
  18530. // Transaction states.
  18531. STATUS_TRYING: 1,
  18532. STATUS_PROCEEDING: 2,
  18533. STATUS_CALLING: 3,
  18534. STATUS_ACCEPTED: 4,
  18535. STATUS_COMPLETED: 5,
  18536. STATUS_TERMINATED: 6,
  18537. STATUS_CONFIRMED: 7,
  18538. // Transaction types.
  18539. NON_INVITE_CLIENT: 'nict',
  18540. NON_INVITE_SERVER: 'nist',
  18541. INVITE_CLIENT: 'ict',
  18542. INVITE_SERVER: 'ist'
  18543. };
  18544. var NonInviteClientTransaction =
  18545. /*#__PURE__*/
  18546. function (_EventEmitter) {
  18547. _inherits(NonInviteClientTransaction, _EventEmitter);
  18548. function NonInviteClientTransaction(ua, transport, request, eventHandlers) {
  18549. var _this;
  18550. _classCallCheck(this, NonInviteClientTransaction);
  18551. _this = _possibleConstructorReturn(this, _getPrototypeOf(NonInviteClientTransaction).call(this));
  18552. _this.type = C.NON_INVITE_CLIENT;
  18553. _this.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  18554. _this.ua = ua;
  18555. _this.transport = transport;
  18556. _this.request = request;
  18557. _this.eventHandlers = eventHandlers;
  18558. var via = "SIP/2.0/".concat(transport.via_transport);
  18559. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this.id);
  18560. _this.request.setHeader('via', via);
  18561. _this.ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this)));
  18562. return _this;
  18563. }
  18564. _createClass(NonInviteClientTransaction, [{
  18565. key: "stateChanged",
  18566. value: function stateChanged(state) {
  18567. this.state = state;
  18568. this.emit('stateChanged');
  18569. }
  18570. }, {
  18571. key: "send",
  18572. value: function send() {
  18573. var _this2 = this;
  18574. this.stateChanged(C.STATUS_TRYING);
  18575. this.F = setTimeout(function () {
  18576. _this2.timer_F();
  18577. }, Timers.TIMER_F);
  18578. if (!this.transport.send(this.request)) {
  18579. this.onTransportError();
  18580. }
  18581. }
  18582. }, {
  18583. key: "onTransportError",
  18584. value: function onTransportError() {
  18585. debugnict("transport error occurred, deleting transaction ".concat(this.id));
  18586. clearTimeout(this.F);
  18587. clearTimeout(this.K);
  18588. this.stateChanged(C.STATUS_TERMINATED);
  18589. this.ua.destroyTransaction(this);
  18590. this.eventHandlers.onTransportError();
  18591. }
  18592. }, {
  18593. key: "timer_F",
  18594. value: function timer_F() {
  18595. debugnict("Timer F expired for transaction ".concat(this.id));
  18596. this.stateChanged(C.STATUS_TERMINATED);
  18597. this.ua.destroyTransaction(this);
  18598. this.eventHandlers.onRequestTimeout();
  18599. }
  18600. }, {
  18601. key: "timer_K",
  18602. value: function timer_K() {
  18603. this.stateChanged(C.STATUS_TERMINATED);
  18604. this.ua.destroyTransaction(this);
  18605. }
  18606. }, {
  18607. key: "receiveResponse",
  18608. value: function receiveResponse(response) {
  18609. var _this3 = this;
  18610. var status_code = response.status_code;
  18611. if (status_code < 200) {
  18612. switch (this.state) {
  18613. case C.STATUS_TRYING:
  18614. case C.STATUS_PROCEEDING:
  18615. this.stateChanged(C.STATUS_PROCEEDING);
  18616. this.eventHandlers.onReceiveResponse(response);
  18617. break;
  18618. }
  18619. } else {
  18620. switch (this.state) {
  18621. case C.STATUS_TRYING:
  18622. case C.STATUS_PROCEEDING:
  18623. this.stateChanged(C.STATUS_COMPLETED);
  18624. clearTimeout(this.F);
  18625. if (status_code === 408) {
  18626. this.eventHandlers.onRequestTimeout();
  18627. } else {
  18628. this.eventHandlers.onReceiveResponse(response);
  18629. }
  18630. this.K = setTimeout(function () {
  18631. _this3.timer_K();
  18632. }, Timers.TIMER_K);
  18633. break;
  18634. case C.STATUS_COMPLETED:
  18635. break;
  18636. }
  18637. }
  18638. }
  18639. }, {
  18640. key: "C",
  18641. get: function get() {
  18642. return C;
  18643. }
  18644. }]);
  18645. return NonInviteClientTransaction;
  18646. }(EventEmitter);
  18647. var InviteClientTransaction =
  18648. /*#__PURE__*/
  18649. function (_EventEmitter2) {
  18650. _inherits(InviteClientTransaction, _EventEmitter2);
  18651. function InviteClientTransaction(ua, transport, request, eventHandlers) {
  18652. var _this4;
  18653. _classCallCheck(this, InviteClientTransaction);
  18654. _this4 = _possibleConstructorReturn(this, _getPrototypeOf(InviteClientTransaction).call(this));
  18655. _this4.type = C.INVITE_CLIENT;
  18656. _this4.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  18657. _this4.ua = ua;
  18658. _this4.transport = transport;
  18659. _this4.request = request;
  18660. _this4.eventHandlers = eventHandlers;
  18661. request.transaction = _assertThisInitialized(_assertThisInitialized(_this4));
  18662. var via = "SIP/2.0/".concat(transport.via_transport);
  18663. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this4.id);
  18664. _this4.request.setHeader('via', via);
  18665. _this4.ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this4)));
  18666. return _this4;
  18667. }
  18668. _createClass(InviteClientTransaction, [{
  18669. key: "stateChanged",
  18670. value: function stateChanged(state) {
  18671. this.state = state;
  18672. this.emit('stateChanged');
  18673. }
  18674. }, {
  18675. key: "send",
  18676. value: function send() {
  18677. var _this5 = this;
  18678. this.stateChanged(C.STATUS_CALLING);
  18679. this.B = setTimeout(function () {
  18680. _this5.timer_B();
  18681. }, Timers.TIMER_B);
  18682. if (!this.transport.send(this.request)) {
  18683. this.onTransportError();
  18684. }
  18685. }
  18686. }, {
  18687. key: "onTransportError",
  18688. value: function onTransportError() {
  18689. clearTimeout(this.B);
  18690. clearTimeout(this.D);
  18691. clearTimeout(this.M);
  18692. if (this.state !== C.STATUS_ACCEPTED) {
  18693. debugict("transport error occurred, deleting transaction ".concat(this.id));
  18694. this.eventHandlers.onTransportError();
  18695. }
  18696. this.stateChanged(C.STATUS_TERMINATED);
  18697. this.ua.destroyTransaction(this);
  18698. } // RFC 6026 7.2.
  18699. }, {
  18700. key: "timer_M",
  18701. value: function timer_M() {
  18702. debugict("Timer M expired for transaction ".concat(this.id));
  18703. if (this.state === C.STATUS_ACCEPTED) {
  18704. clearTimeout(this.B);
  18705. this.stateChanged(C.STATUS_TERMINATED);
  18706. this.ua.destroyTransaction(this);
  18707. }
  18708. } // RFC 3261 17.1.1.
  18709. }, {
  18710. key: "timer_B",
  18711. value: function timer_B() {
  18712. debugict("Timer B expired for transaction ".concat(this.id));
  18713. if (this.state === C.STATUS_CALLING) {
  18714. this.stateChanged(C.STATUS_TERMINATED);
  18715. this.ua.destroyTransaction(this);
  18716. this.eventHandlers.onRequestTimeout();
  18717. }
  18718. }
  18719. }, {
  18720. key: "timer_D",
  18721. value: function timer_D() {
  18722. debugict("Timer D expired for transaction ".concat(this.id));
  18723. clearTimeout(this.B);
  18724. this.stateChanged(C.STATUS_TERMINATED);
  18725. this.ua.destroyTransaction(this);
  18726. }
  18727. }, {
  18728. key: "sendACK",
  18729. value: function sendACK(response) {
  18730. var _this6 = this;
  18731. var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, {
  18732. 'route_set': this.request.getHeaders('route'),
  18733. 'call_id': this.request.getHeader('call-id'),
  18734. 'cseq': this.request.cseq
  18735. });
  18736. ack.setHeader('from', this.request.getHeader('from'));
  18737. ack.setHeader('via', this.request.getHeader('via'));
  18738. ack.setHeader('to', response.getHeader('to'));
  18739. this.D = setTimeout(function () {
  18740. _this6.timer_D();
  18741. }, Timers.TIMER_D);
  18742. this.transport.send(ack);
  18743. }
  18744. }, {
  18745. key: "cancel",
  18746. value: function cancel(reason) {
  18747. // Send only if a provisional response (>100) has been received.
  18748. if (this.state !== C.STATUS_PROCEEDING) {
  18749. return;
  18750. }
  18751. var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, {
  18752. 'route_set': this.request.getHeaders('route'),
  18753. 'call_id': this.request.getHeader('call-id'),
  18754. 'cseq': this.request.cseq
  18755. });
  18756. cancel.setHeader('from', this.request.getHeader('from'));
  18757. cancel.setHeader('via', this.request.getHeader('via'));
  18758. cancel.setHeader('to', this.request.getHeader('to'));
  18759. if (reason) {
  18760. cancel.setHeader('reason', reason);
  18761. }
  18762. this.transport.send(cancel);
  18763. }
  18764. }, {
  18765. key: "receiveResponse",
  18766. value: function receiveResponse(response) {
  18767. var _this7 = this;
  18768. var status_code = response.status_code;
  18769. if (status_code >= 100 && status_code <= 199) {
  18770. switch (this.state) {
  18771. case C.STATUS_CALLING:
  18772. this.stateChanged(C.STATUS_PROCEEDING);
  18773. this.eventHandlers.onReceiveResponse(response);
  18774. break;
  18775. case C.STATUS_PROCEEDING:
  18776. this.eventHandlers.onReceiveResponse(response);
  18777. break;
  18778. }
  18779. } else if (status_code >= 200 && status_code <= 299) {
  18780. switch (this.state) {
  18781. case C.STATUS_CALLING:
  18782. case C.STATUS_PROCEEDING:
  18783. this.stateChanged(C.STATUS_ACCEPTED);
  18784. this.M = setTimeout(function () {
  18785. _this7.timer_M();
  18786. }, Timers.TIMER_M);
  18787. this.eventHandlers.onReceiveResponse(response);
  18788. break;
  18789. case C.STATUS_ACCEPTED:
  18790. this.eventHandlers.onReceiveResponse(response);
  18791. break;
  18792. }
  18793. } else if (status_code >= 300 && status_code <= 699) {
  18794. switch (this.state) {
  18795. case C.STATUS_CALLING:
  18796. case C.STATUS_PROCEEDING:
  18797. this.stateChanged(C.STATUS_COMPLETED);
  18798. this.sendACK(response);
  18799. this.eventHandlers.onReceiveResponse(response);
  18800. break;
  18801. case C.STATUS_COMPLETED:
  18802. this.sendACK(response);
  18803. break;
  18804. }
  18805. }
  18806. }
  18807. }, {
  18808. key: "C",
  18809. get: function get() {
  18810. return C;
  18811. }
  18812. }]);
  18813. return InviteClientTransaction;
  18814. }(EventEmitter);
  18815. var AckClientTransaction =
  18816. /*#__PURE__*/
  18817. function (_EventEmitter3) {
  18818. _inherits(AckClientTransaction, _EventEmitter3);
  18819. function AckClientTransaction(ua, transport, request, eventHandlers) {
  18820. var _this8;
  18821. _classCallCheck(this, AckClientTransaction);
  18822. _this8 = _possibleConstructorReturn(this, _getPrototypeOf(AckClientTransaction).call(this));
  18823. _this8.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  18824. _this8.transport = transport;
  18825. _this8.request = request;
  18826. _this8.eventHandlers = eventHandlers;
  18827. var via = "SIP/2.0/".concat(transport.via_transport);
  18828. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this8.id);
  18829. _this8.request.setHeader('via', via);
  18830. return _this8;
  18831. }
  18832. _createClass(AckClientTransaction, [{
  18833. key: "send",
  18834. value: function send() {
  18835. if (!this.transport.send(this.request)) {
  18836. this.onTransportError();
  18837. }
  18838. }
  18839. }, {
  18840. key: "onTransportError",
  18841. value: function onTransportError() {
  18842. debugact("transport error occurred for transaction ".concat(this.id));
  18843. this.eventHandlers.onTransportError();
  18844. }
  18845. }, {
  18846. key: "C",
  18847. get: function get() {
  18848. return C;
  18849. }
  18850. }]);
  18851. return AckClientTransaction;
  18852. }(EventEmitter);
  18853. var NonInviteServerTransaction =
  18854. /*#__PURE__*/
  18855. function (_EventEmitter4) {
  18856. _inherits(NonInviteServerTransaction, _EventEmitter4);
  18857. function NonInviteServerTransaction(ua, transport, request) {
  18858. var _this9;
  18859. _classCallCheck(this, NonInviteServerTransaction);
  18860. _this9 = _possibleConstructorReturn(this, _getPrototypeOf(NonInviteServerTransaction).call(this));
  18861. _this9.type = C.NON_INVITE_SERVER;
  18862. _this9.id = request.via_branch;
  18863. _this9.ua = ua;
  18864. _this9.transport = transport;
  18865. _this9.request = request;
  18866. _this9.last_response = '';
  18867. request.server_transaction = _assertThisInitialized(_assertThisInitialized(_this9));
  18868. _this9.state = C.STATUS_TRYING;
  18869. ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this9)));
  18870. return _this9;
  18871. }
  18872. _createClass(NonInviteServerTransaction, [{
  18873. key: "stateChanged",
  18874. value: function stateChanged(state) {
  18875. this.state = state;
  18876. this.emit('stateChanged');
  18877. }
  18878. }, {
  18879. key: "timer_J",
  18880. value: function timer_J() {
  18881. debugnist("Timer J expired for transaction ".concat(this.id));
  18882. this.stateChanged(C.STATUS_TERMINATED);
  18883. this.ua.destroyTransaction(this);
  18884. }
  18885. }, {
  18886. key: "onTransportError",
  18887. value: function onTransportError() {
  18888. if (!this.transportError) {
  18889. this.transportError = true;
  18890. debugnist("transport error occurred, deleting transaction ".concat(this.id));
  18891. clearTimeout(this.J);
  18892. this.stateChanged(C.STATUS_TERMINATED);
  18893. this.ua.destroyTransaction(this);
  18894. }
  18895. }
  18896. }, {
  18897. key: "receiveResponse",
  18898. value: function receiveResponse(status_code, response, onSuccess, onFailure) {
  18899. var _this10 = this;
  18900. if (status_code === 100) {
  18901. /* RFC 4320 4.1
  18902. * 'A SIP element MUST NOT
  18903. * send any provisional response with a
  18904. * Status-Code other than 100 to a non-INVITE request.'
  18905. */
  18906. switch (this.state) {
  18907. case C.STATUS_TRYING:
  18908. this.stateChanged(C.STATUS_PROCEEDING);
  18909. if (!this.transport.send(response)) {
  18910. this.onTransportError();
  18911. }
  18912. break;
  18913. case C.STATUS_PROCEEDING:
  18914. this.last_response = response;
  18915. if (!this.transport.send(response)) {
  18916. this.onTransportError();
  18917. if (onFailure) {
  18918. onFailure();
  18919. }
  18920. } else if (onSuccess) {
  18921. onSuccess();
  18922. }
  18923. break;
  18924. }
  18925. } else if (status_code >= 200 && status_code <= 699) {
  18926. switch (this.state) {
  18927. case C.STATUS_TRYING:
  18928. case C.STATUS_PROCEEDING:
  18929. this.stateChanged(C.STATUS_COMPLETED);
  18930. this.last_response = response;
  18931. this.J = setTimeout(function () {
  18932. _this10.timer_J();
  18933. }, Timers.TIMER_J);
  18934. if (!this.transport.send(response)) {
  18935. this.onTransportError();
  18936. if (onFailure) {
  18937. onFailure();
  18938. }
  18939. } else if (onSuccess) {
  18940. onSuccess();
  18941. }
  18942. break;
  18943. case C.STATUS_COMPLETED:
  18944. break;
  18945. }
  18946. }
  18947. }
  18948. }, {
  18949. key: "C",
  18950. get: function get() {
  18951. return C;
  18952. }
  18953. }]);
  18954. return NonInviteServerTransaction;
  18955. }(EventEmitter);
  18956. var InviteServerTransaction =
  18957. /*#__PURE__*/
  18958. function (_EventEmitter5) {
  18959. _inherits(InviteServerTransaction, _EventEmitter5);
  18960. function InviteServerTransaction(ua, transport, request) {
  18961. var _this11;
  18962. _classCallCheck(this, InviteServerTransaction);
  18963. _this11 = _possibleConstructorReturn(this, _getPrototypeOf(InviteServerTransaction).call(this));
  18964. _this11.type = C.INVITE_SERVER;
  18965. _this11.id = request.via_branch;
  18966. _this11.ua = ua;
  18967. _this11.transport = transport;
  18968. _this11.request = request;
  18969. _this11.last_response = '';
  18970. request.server_transaction = _assertThisInitialized(_assertThisInitialized(_this11));
  18971. _this11.state = C.STATUS_PROCEEDING;
  18972. ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this11)));
  18973. _this11.resendProvisionalTimer = null;
  18974. request.reply(100);
  18975. return _this11;
  18976. }
  18977. _createClass(InviteServerTransaction, [{
  18978. key: "stateChanged",
  18979. value: function stateChanged(state) {
  18980. this.state = state;
  18981. this.emit('stateChanged');
  18982. }
  18983. }, {
  18984. key: "timer_H",
  18985. value: function timer_H() {
  18986. debugist("Timer H expired for transaction ".concat(this.id));
  18987. if (this.state === C.STATUS_COMPLETED) {
  18988. debugist('ACK not received, dialog will be terminated');
  18989. }
  18990. this.stateChanged(C.STATUS_TERMINATED);
  18991. this.ua.destroyTransaction(this);
  18992. }
  18993. }, {
  18994. key: "timer_I",
  18995. value: function timer_I() {
  18996. this.stateChanged(C.STATUS_TERMINATED);
  18997. } // RFC 6026 7.1.
  18998. }, {
  18999. key: "timer_L",
  19000. value: function timer_L() {
  19001. debugist("Timer L expired for transaction ".concat(this.id));
  19002. if (this.state === C.STATUS_ACCEPTED) {
  19003. this.stateChanged(C.STATUS_TERMINATED);
  19004. this.ua.destroyTransaction(this);
  19005. }
  19006. }
  19007. }, {
  19008. key: "onTransportError",
  19009. value: function onTransportError() {
  19010. if (!this.transportError) {
  19011. this.transportError = true;
  19012. debugist("transport error occurred, deleting transaction ".concat(this.id));
  19013. if (this.resendProvisionalTimer !== null) {
  19014. clearInterval(this.resendProvisionalTimer);
  19015. this.resendProvisionalTimer = null;
  19016. }
  19017. clearTimeout(this.L);
  19018. clearTimeout(this.H);
  19019. clearTimeout(this.I);
  19020. this.stateChanged(C.STATUS_TERMINATED);
  19021. this.ua.destroyTransaction(this);
  19022. }
  19023. }
  19024. }, {
  19025. key: "resend_provisional",
  19026. value: function resend_provisional() {
  19027. if (!this.transport.send(this.last_response)) {
  19028. this.onTransportError();
  19029. }
  19030. } // INVITE Server Transaction RFC 3261 17.2.1.
  19031. }, {
  19032. key: "receiveResponse",
  19033. value: function receiveResponse(status_code, response, onSuccess, onFailure) {
  19034. var _this12 = this;
  19035. if (status_code >= 100 && status_code <= 199) {
  19036. switch (this.state) {
  19037. case C.STATUS_PROCEEDING:
  19038. if (!this.transport.send(response)) {
  19039. this.onTransportError();
  19040. }
  19041. this.last_response = response;
  19042. break;
  19043. }
  19044. }
  19045. if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) {
  19046. // Trigger the resendProvisionalTimer only for the first non 100 provisional response.
  19047. if (this.resendProvisionalTimer === null) {
  19048. this.resendProvisionalTimer = setInterval(function () {
  19049. _this12.resend_provisional();
  19050. }, Timers.PROVISIONAL_RESPONSE_INTERVAL);
  19051. }
  19052. } else if (status_code >= 200 && status_code <= 299) {
  19053. switch (this.state) {
  19054. case C.STATUS_PROCEEDING:
  19055. this.stateChanged(C.STATUS_ACCEPTED);
  19056. this.last_response = response;
  19057. this.L = setTimeout(function () {
  19058. _this12.timer_L();
  19059. }, Timers.TIMER_L);
  19060. if (this.resendProvisionalTimer !== null) {
  19061. clearInterval(this.resendProvisionalTimer);
  19062. this.resendProvisionalTimer = null;
  19063. }
  19064. /* falls through */
  19065. case C.STATUS_ACCEPTED:
  19066. // Note that this point will be reached for proceeding this.state also.
  19067. if (!this.transport.send(response)) {
  19068. this.onTransportError();
  19069. if (onFailure) {
  19070. onFailure();
  19071. }
  19072. } else if (onSuccess) {
  19073. onSuccess();
  19074. }
  19075. break;
  19076. }
  19077. } else if (status_code >= 300 && status_code <= 699) {
  19078. switch (this.state) {
  19079. case C.STATUS_PROCEEDING:
  19080. if (this.resendProvisionalTimer !== null) {
  19081. clearInterval(this.resendProvisionalTimer);
  19082. this.resendProvisionalTimer = null;
  19083. }
  19084. if (!this.transport.send(response)) {
  19085. this.onTransportError();
  19086. if (onFailure) {
  19087. onFailure();
  19088. }
  19089. } else {
  19090. this.stateChanged(C.STATUS_COMPLETED);
  19091. this.H = setTimeout(function () {
  19092. _this12.timer_H();
  19093. }, Timers.TIMER_H);
  19094. if (onSuccess) {
  19095. onSuccess();
  19096. }
  19097. }
  19098. break;
  19099. }
  19100. }
  19101. }
  19102. }, {
  19103. key: "C",
  19104. get: function get() {
  19105. return C;
  19106. }
  19107. }]);
  19108. return InviteServerTransaction;
  19109. }(EventEmitter);
  19110. /**
  19111. * INVITE:
  19112. * _true_ if retransmission
  19113. * _false_ new request
  19114. *
  19115. * ACK:
  19116. * _true_ ACK to non2xx response
  19117. * _false_ ACK must be passed to TU (accepted state)
  19118. * ACK to 2xx response
  19119. *
  19120. * CANCEL:
  19121. * _true_ no matching invite transaction
  19122. * _false_ matching invite transaction and no final response sent
  19123. *
  19124. * OTHER:
  19125. * _true_ retransmission
  19126. * _false_ new request
  19127. */
  19128. function checkTransaction(_ref, request) {
  19129. var _transactions = _ref._transactions;
  19130. var tr;
  19131. switch (request.method) {
  19132. case JsSIP_C.INVITE:
  19133. tr = _transactions.ist[request.via_branch];
  19134. if (tr) {
  19135. switch (tr.state) {
  19136. case C.STATUS_PROCEEDING:
  19137. tr.transport.send(tr.last_response);
  19138. break;
  19139. // RFC 6026 7.1 Invite retransmission.
  19140. // Received while in C.STATUS_ACCEPTED state. Absorb it.
  19141. case C.STATUS_ACCEPTED:
  19142. break;
  19143. }
  19144. return true;
  19145. }
  19146. break;
  19147. case JsSIP_C.ACK:
  19148. tr = _transactions.ist[request.via_branch]; // RFC 6026 7.1.
  19149. if (tr) {
  19150. if (tr.state === C.STATUS_ACCEPTED) {
  19151. return false;
  19152. } else if (tr.state === C.STATUS_COMPLETED) {
  19153. tr.state = C.STATUS_CONFIRMED;
  19154. tr.I = setTimeout(function () {
  19155. tr.timer_I();
  19156. }, Timers.TIMER_I);
  19157. return true;
  19158. }
  19159. } // ACK to 2XX Response.
  19160. else {
  19161. return false;
  19162. }
  19163. break;
  19164. case JsSIP_C.CANCEL:
  19165. tr = _transactions.ist[request.via_branch];
  19166. if (tr) {
  19167. request.reply_sl(200);
  19168. if (tr.state === C.STATUS_PROCEEDING) {
  19169. return false;
  19170. } else {
  19171. return true;
  19172. }
  19173. } else {
  19174. request.reply_sl(481);
  19175. return true;
  19176. }
  19177. default:
  19178. // Non-INVITE Server Transaction RFC 3261 17.2.2.
  19179. tr = _transactions.nist[request.via_branch];
  19180. if (tr) {
  19181. switch (tr.state) {
  19182. case C.STATUS_TRYING:
  19183. break;
  19184. case C.STATUS_PROCEEDING:
  19185. case C.STATUS_COMPLETED:
  19186. tr.transport.send(tr.last_response);
  19187. break;
  19188. }
  19189. return true;
  19190. }
  19191. break;
  19192. }
  19193. }
  19194. module.exports = {
  19195. C: C,
  19196. NonInviteClientTransaction: NonInviteClientTransaction,
  19197. InviteClientTransaction: InviteClientTransaction,
  19198. AckClientTransaction: AckClientTransaction,
  19199. NonInviteServerTransaction: NonInviteServerTransaction,
  19200. InviteServerTransaction: InviteServerTransaction,
  19201. checkTransaction: checkTransaction
  19202. };
  19203. },{"./Constants":2,"./SIPMessage":19,"./Timers":21,"debug":30,"events":29}],23:[function(require,module,exports){
  19204. "use strict";
  19205. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19206. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  19207. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19208. var Socket = require('./Socket');
  19209. var debug = require('debug')('JsSIP:Transport');
  19210. var debugerror = require('debug')('JsSIP:ERROR:Transport');
  19211. var JsSIP_C = require('./Constants');
  19212. debugerror.log = console.warn.bind(console);
  19213. /**
  19214. * Constants
  19215. */
  19216. var C = {
  19217. // Transport status.
  19218. STATUS_CONNECTED: 0,
  19219. STATUS_CONNECTING: 1,
  19220. STATUS_DISCONNECTED: 2,
  19221. // Socket status.
  19222. SOCKET_STATUS_READY: 0,
  19223. SOCKET_STATUS_ERROR: 1,
  19224. // Recovery options.
  19225. recovery_options: {
  19226. // minimum interval in seconds between recover attempts.
  19227. min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL,
  19228. // maximum interval in seconds between recover attempts.
  19229. max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL
  19230. }
  19231. };
  19232. /*
  19233. * Manages one or multiple JsSIP.Socket instances.
  19234. * Is reponsible for transport recovery logic among all socket instances.
  19235. *
  19236. * @socket JsSIP::Socket instance
  19237. */
  19238. module.exports =
  19239. /*#__PURE__*/
  19240. function () {
  19241. function Transport(sockets) {
  19242. var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options;
  19243. _classCallCheck(this, Transport);
  19244. debug('new()');
  19245. this.status = C.STATUS_DISCONNECTED; // Current socket.
  19246. this.socket = null; // Socket collection.
  19247. this.sockets = [];
  19248. this.recovery_options = recovery_options;
  19249. this.recover_attempts = 0;
  19250. this.recovery_timer = null;
  19251. this.close_requested = false;
  19252. if (typeof sockets === 'undefined') {
  19253. throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument');
  19254. }
  19255. if (!(sockets instanceof Array)) {
  19256. sockets = [sockets];
  19257. }
  19258. sockets.forEach(function (socket) {
  19259. if (!Socket.isSocket(socket.socket)) {
  19260. throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance');
  19261. }
  19262. if (socket.weight && !Number(socket.weight)) {
  19263. throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number');
  19264. }
  19265. this.sockets.push({
  19266. socket: socket.socket,
  19267. weight: socket.weight || 0,
  19268. status: C.SOCKET_STATUS_READY
  19269. });
  19270. }, this); // Get the socket with higher weight.
  19271. this._getSocket();
  19272. }
  19273. /**
  19274. * Instance Methods
  19275. */
  19276. _createClass(Transport, [{
  19277. key: "connect",
  19278. value: function connect() {
  19279. debug('connect()');
  19280. if (this.isConnected()) {
  19281. debug('Transport is already connected');
  19282. return;
  19283. } else if (this.isConnecting()) {
  19284. debug('Transport is connecting');
  19285. return;
  19286. }
  19287. this.close_requested = false;
  19288. this.status = C.STATUS_CONNECTING;
  19289. this.onconnecting({
  19290. socket: this.socket,
  19291. attempts: this.recover_attempts
  19292. });
  19293. if (!this.close_requested) {
  19294. // Bind socket event callbacks.
  19295. this.socket.onconnect = this._onConnect.bind(this);
  19296. this.socket.ondisconnect = this._onDisconnect.bind(this);
  19297. this.socket.ondata = this._onData.bind(this);
  19298. this.socket.connect();
  19299. }
  19300. return;
  19301. }
  19302. }, {
  19303. key: "disconnect",
  19304. value: function disconnect() {
  19305. debug('close()');
  19306. this.close_requested = true;
  19307. this.recover_attempts = 0;
  19308. this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer.
  19309. if (this.recovery_timer !== null) {
  19310. clearTimeout(this.recovery_timer);
  19311. this.recovery_timer = null;
  19312. } // Unbind socket event callbacks.
  19313. this.socket.onconnect = function () {};
  19314. this.socket.ondisconnect = function () {};
  19315. this.socket.ondata = function () {};
  19316. this.socket.disconnect();
  19317. this.ondisconnect({
  19318. socket: this.socket,
  19319. error: false
  19320. });
  19321. }
  19322. }, {
  19323. key: "send",
  19324. value: function send(data) {
  19325. debug('send()');
  19326. if (!this.isConnected()) {
  19327. debugerror('unable to send message, transport is not connected');
  19328. return false;
  19329. }
  19330. var message = data.toString();
  19331. debug("sending message:\n\n".concat(message, "\n"));
  19332. return this.socket.send(message);
  19333. }
  19334. }, {
  19335. key: "isConnected",
  19336. value: function isConnected() {
  19337. return this.status === C.STATUS_CONNECTED;
  19338. }
  19339. }, {
  19340. key: "isConnecting",
  19341. value: function isConnecting() {
  19342. return this.status === C.STATUS_CONNECTING;
  19343. }
  19344. /**
  19345. * Private API.
  19346. */
  19347. }, {
  19348. key: "_reconnect",
  19349. value: function _reconnect() {
  19350. var _this = this;
  19351. this.recover_attempts += 1;
  19352. var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1);
  19353. if (k < this.recovery_options.min_interval) {
  19354. k = this.recovery_options.min_interval;
  19355. } else if (k > this.recovery_options.max_interval) {
  19356. k = this.recovery_options.max_interval;
  19357. }
  19358. debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds"));
  19359. this.recovery_timer = setTimeout(function () {
  19360. if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) {
  19361. // Get the next available socket with higher weight.
  19362. _this._getSocket(); // Connect the socket.
  19363. _this.connect();
  19364. }
  19365. }, k * 1000);
  19366. }
  19367. /**
  19368. * get the next available socket with higher weight
  19369. */
  19370. }, {
  19371. key: "_getSocket",
  19372. value: function _getSocket() {
  19373. var candidates = [];
  19374. this.sockets.forEach(function (socket) {
  19375. if (socket.status === C.SOCKET_STATUS_ERROR) {
  19376. return; // continue the array iteration
  19377. } else if (candidates.length === 0) {
  19378. candidates.push(socket);
  19379. } else if (socket.weight > candidates[0].weight) {
  19380. candidates = [socket];
  19381. } else if (socket.weight === candidates[0].weight) {
  19382. candidates.push(socket);
  19383. }
  19384. });
  19385. if (candidates.length === 0) {
  19386. // All sockets have failed. reset sockets status.
  19387. this.sockets.forEach(function (socket) {
  19388. socket.status = C.SOCKET_STATUS_READY;
  19389. }); // Get next available socket.
  19390. this._getSocket();
  19391. return;
  19392. }
  19393. var idx = Math.floor(Math.random() * candidates.length);
  19394. this.socket = candidates[idx].socket;
  19395. }
  19396. /**
  19397. * Socket Event Handlers
  19398. */
  19399. }, {
  19400. key: "_onConnect",
  19401. value: function _onConnect() {
  19402. this.recover_attempts = 0;
  19403. this.status = C.STATUS_CONNECTED; // Clear recovery_timer.
  19404. if (this.recovery_timer !== null) {
  19405. clearTimeout(this.recovery_timer);
  19406. this.recovery_timer = null;
  19407. }
  19408. this.onconnect({
  19409. socket: this
  19410. });
  19411. }
  19412. }, {
  19413. key: "_onDisconnect",
  19414. value: function _onDisconnect(error, code, reason) {
  19415. this.status = C.STATUS_DISCONNECTED;
  19416. this.ondisconnect({
  19417. socket: this.socket,
  19418. error: error,
  19419. code: code,
  19420. reason: reason
  19421. });
  19422. if (this.close_requested) {
  19423. return;
  19424. } // Update socket status.
  19425. else {
  19426. this.sockets.forEach(function (socket) {
  19427. if (this.socket === socket.socket) {
  19428. socket.status = C.SOCKET_STATUS_ERROR;
  19429. }
  19430. }, this);
  19431. }
  19432. this._reconnect(error);
  19433. }
  19434. }, {
  19435. key: "_onData",
  19436. value: function _onData(data) {
  19437. // CRLF Keep Alive response from server. Ignore it.
  19438. if (data === '\r\n') {
  19439. debug('received message with CRLF Keep Alive response');
  19440. return;
  19441. } // Binary message.
  19442. else if (typeof data !== 'string') {
  19443. try {
  19444. data = String.fromCharCode.apply(null, new Uint8Array(data));
  19445. } catch (evt) {
  19446. debug('received binary message failed to be converted into string,' + ' message discarded');
  19447. return;
  19448. }
  19449. debug("received binary message:\n\n".concat(data, "\n"));
  19450. } // Text message.
  19451. else {
  19452. debug("received text message:\n\n".concat(data, "\n"));
  19453. }
  19454. this.ondata({
  19455. transport: this,
  19456. message: data
  19457. });
  19458. }
  19459. }, {
  19460. key: "via_transport",
  19461. get: function get() {
  19462. return this.socket.via_transport;
  19463. }
  19464. }, {
  19465. key: "url",
  19466. get: function get() {
  19467. return this.socket.url;
  19468. }
  19469. }, {
  19470. key: "sip_uri",
  19471. get: function get() {
  19472. return this.socket.sip_uri;
  19473. }
  19474. }]);
  19475. return Transport;
  19476. }();
  19477. },{"./Constants":2,"./Socket":20,"debug":30}],24:[function(require,module,exports){
  19478. "use strict";
  19479. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  19480. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19481. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  19482. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  19483. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  19484. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19485. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  19486. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  19487. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  19488. var EventEmitter = require('events').EventEmitter;
  19489. var JsSIP_C = require('./Constants');
  19490. var Registrator = require('./Registrator');
  19491. var RTCSession = require('./RTCSession');
  19492. var Message = require('./Message');
  19493. var Transactions = require('./Transactions');
  19494. var Transport = require('./Transport');
  19495. var Utils = require('./Utils');
  19496. var Exceptions = require('./Exceptions');
  19497. var URI = require('./URI');
  19498. var Parser = require('./Parser');
  19499. var SIPMessage = require('./SIPMessage');
  19500. var sanityCheck = require('./sanityCheck');
  19501. var config = require('./Config');
  19502. var debug = require('debug')('JsSIP:UA');
  19503. var debugerror = require('debug')('JsSIP:ERROR:UA');
  19504. debugerror.log = console.warn.bind(console);
  19505. var C = {
  19506. // UA status codes.
  19507. STATUS_INIT: 0,
  19508. STATUS_READY: 1,
  19509. STATUS_USER_CLOSED: 2,
  19510. STATUS_NOT_READY: 3,
  19511. // UA error codes.
  19512. CONFIGURATION_ERROR: 1,
  19513. NETWORK_ERROR: 2
  19514. };
  19515. /**
  19516. * The User-Agent class.
  19517. * @class JsSIP.UA
  19518. * @param {Object} configuration Configuration parameters.
  19519. * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid.
  19520. * @throws {TypeError} If no configuration is given.
  19521. */
  19522. module.exports =
  19523. /*#__PURE__*/
  19524. function (_EventEmitter) {
  19525. _inherits(UA, _EventEmitter);
  19526. _createClass(UA, null, [{
  19527. key: "C",
  19528. // Expose C object.
  19529. get: function get() {
  19530. return C;
  19531. }
  19532. }]);
  19533. function UA(configuration) {
  19534. var _this;
  19535. _classCallCheck(this, UA);
  19536. debug('new() [configuration:%o]', configuration);
  19537. _this = _possibleConstructorReturn(this, _getPrototypeOf(UA).call(this));
  19538. _this._cache = {
  19539. credentials: {}
  19540. };
  19541. _this._configuration = Object.assign({}, config.settings);
  19542. _this._dynConfiguration = {};
  19543. _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE).
  19544. _this._applicants = {};
  19545. _this._sessions = {};
  19546. _this._transport = null;
  19547. _this._contact = null;
  19548. _this._status = C.STATUS_INIT;
  19549. _this._error = null;
  19550. _this._transactions = {
  19551. nist: {},
  19552. nict: {},
  19553. ist: {},
  19554. ict: {}
  19555. }; // Custom UA empty object for high level use.
  19556. _this._data = {};
  19557. _this._closeTimer = null; // Check configuration argument.
  19558. if (configuration === undefined) {
  19559. throw new TypeError('Not enough arguments');
  19560. } // Load configuration.
  19561. try {
  19562. _this._loadConfig(configuration);
  19563. } catch (e) {
  19564. _this._status = C.STATUS_NOT_READY;
  19565. _this._error = C.CONFIGURATION_ERROR;
  19566. throw e;
  19567. } // Initialize registrator.
  19568. _this._registrator = new Registrator(_assertThisInitialized(_assertThisInitialized(_this)));
  19569. return _this;
  19570. }
  19571. _createClass(UA, [{
  19572. key: "start",
  19573. // =================
  19574. // High Level API
  19575. // =================
  19576. /**
  19577. * Connect to the server if status = STATUS_INIT.
  19578. * Resume UA after being closed.
  19579. */
  19580. value: function start() {
  19581. debug('start()');
  19582. if (this._status === C.STATUS_INIT) {
  19583. this._transport.connect();
  19584. } else if (this._status === C.STATUS_USER_CLOSED) {
  19585. debug('restarting UA'); // Disconnect.
  19586. if (this._closeTimer !== null) {
  19587. clearTimeout(this._closeTimer);
  19588. this._closeTimer = null;
  19589. this._transport.disconnect();
  19590. } // Reconnect.
  19591. this._status = C.STATUS_INIT;
  19592. this._transport.connect();
  19593. } else if (this._status === C.STATUS_READY) {
  19594. debug('UA is in READY status, not restarted');
  19595. } else {
  19596. debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect');
  19597. } // Set dynamic configuration.
  19598. this._dynConfiguration.register = this._configuration.register;
  19599. }
  19600. /**
  19601. * Register.
  19602. */
  19603. }, {
  19604. key: "register",
  19605. value: function register() {
  19606. debug('register()');
  19607. this._dynConfiguration.register = true;
  19608. this._registrator.register();
  19609. }
  19610. /**
  19611. * Unregister.
  19612. */
  19613. }, {
  19614. key: "unregister",
  19615. value: function unregister(options) {
  19616. debug('unregister()');
  19617. this._dynConfiguration.register = false;
  19618. this._registrator.unregister(options);
  19619. }
  19620. /**
  19621. * Get the Registrator instance.
  19622. */
  19623. }, {
  19624. key: "registrator",
  19625. value: function registrator() {
  19626. return this._registrator;
  19627. }
  19628. /**
  19629. * Registration state.
  19630. */
  19631. }, {
  19632. key: "isRegistered",
  19633. value: function isRegistered() {
  19634. return this._registrator.registered;
  19635. }
  19636. /**
  19637. * Connection state.
  19638. */
  19639. }, {
  19640. key: "isConnected",
  19641. value: function isConnected() {
  19642. return this._transport.isConnected();
  19643. }
  19644. /**
  19645. * Make an outgoing call.
  19646. *
  19647. * -param {String} target
  19648. * -param {Object} [options]
  19649. *
  19650. * -throws {TypeError}
  19651. *
  19652. */
  19653. }, {
  19654. key: "call",
  19655. value: function call(target, options) {
  19656. debug('call()');
  19657. var session = new RTCSession(this);
  19658. session.connect(target, options);
  19659. return session;
  19660. }
  19661. /**
  19662. * Send a message.
  19663. *
  19664. * -param {String} target
  19665. * -param {String} body
  19666. * -param {Object} [options]
  19667. *
  19668. * -throws {TypeError}
  19669. *
  19670. */
  19671. }, {
  19672. key: "sendMessage",
  19673. value: function sendMessage(target, body, options) {
  19674. debug('sendMessage()');
  19675. var message = new Message(this);
  19676. message.send(target, body, options);
  19677. return message;
  19678. }
  19679. /**
  19680. * Terminate ongoing sessions.
  19681. */
  19682. }, {
  19683. key: "terminateSessions",
  19684. value: function terminateSessions(options) {
  19685. debug('terminateSessions()');
  19686. for (var idx in this._sessions) {
  19687. if (!this._sessions[idx].isEnded()) {
  19688. this._sessions[idx].terminate(options);
  19689. }
  19690. }
  19691. }
  19692. /**
  19693. * Gracefully close.
  19694. *
  19695. */
  19696. }, {
  19697. key: "stop",
  19698. value: function stop() {
  19699. var _this2 = this;
  19700. debug('stop()'); // Remove dynamic settings.
  19701. this._dynConfiguration = {};
  19702. if (this._status === C.STATUS_USER_CLOSED) {
  19703. debug('UA already closed');
  19704. return;
  19705. } // Close registrator.
  19706. this._registrator.close(); // If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
  19707. var num_sessions = Object.keys(this._sessions).length; // Run _terminate_ on every Session.
  19708. for (var session in this._sessions) {
  19709. if (Object.prototype.hasOwnProperty.call(this._sessions, session)) {
  19710. debug("closing session ".concat(session));
  19711. try {
  19712. this._sessions[session].terminate();
  19713. } catch (error) {}
  19714. }
  19715. } // Run _close_ on every applicant.
  19716. for (var applicant in this._applicants) {
  19717. if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try {
  19718. this._applicants[applicant].close();
  19719. } catch (error) {}
  19720. }
  19721. this._status = C.STATUS_USER_CLOSED;
  19722. var num_transactions = Object.keys(this._transactions.nict).length + Object.keys(this._transactions.nist).length + Object.keys(this._transactions.ict).length + Object.keys(this._transactions.ist).length;
  19723. if (num_transactions === 0 && num_sessions === 0) {
  19724. this._transport.disconnect();
  19725. } else {
  19726. this._closeTimer = setTimeout(function () {
  19727. _this2._closeTimer = null;
  19728. _this2._transport.disconnect();
  19729. }, 2000);
  19730. }
  19731. }
  19732. /**
  19733. * Normalice a string into a valid SIP request URI
  19734. * -param {String} target
  19735. * -returns {JsSIP.URI|undefined}
  19736. */
  19737. }, {
  19738. key: "normalizeTarget",
  19739. value: function normalizeTarget(target) {
  19740. return Utils.normalizeTarget(target, this._configuration.hostport_params);
  19741. }
  19742. /**
  19743. * Allow retrieving configuration and autogenerated fields in runtime.
  19744. */
  19745. }, {
  19746. key: "get",
  19747. value: function get(parameter) {
  19748. switch (parameter) {
  19749. case 'realm':
  19750. return this._configuration.realm;
  19751. case 'ha1':
  19752. return this._configuration.ha1;
  19753. default:
  19754. debugerror('get() | cannot get "%s" parameter in runtime', parameter);
  19755. return undefined;
  19756. }
  19757. }
  19758. /**
  19759. * Allow configuration changes in runtime.
  19760. * Returns true if the parameter could be set.
  19761. */
  19762. }, {
  19763. key: "set",
  19764. value: function set(parameter, value) {
  19765. switch (parameter) {
  19766. case 'password':
  19767. {
  19768. this._configuration.password = String(value);
  19769. break;
  19770. }
  19771. case 'realm':
  19772. {
  19773. this._configuration.realm = String(value);
  19774. break;
  19775. }
  19776. case 'ha1':
  19777. {
  19778. this._configuration.ha1 = String(value); // Delete the plain SIP password.
  19779. this._configuration.password = null;
  19780. break;
  19781. }
  19782. case 'display_name':
  19783. {
  19784. this._configuration.display_name = value;
  19785. break;
  19786. }
  19787. default:
  19788. debugerror('set() | cannot set "%s" parameter in runtime', parameter);
  19789. return false;
  19790. }
  19791. return true;
  19792. } // ==========================
  19793. // Event Handlers.
  19794. // ==========================
  19795. /**
  19796. * new Transaction
  19797. */
  19798. }, {
  19799. key: "newTransaction",
  19800. value: function newTransaction(transaction) {
  19801. this._transactions[transaction.type][transaction.id] = transaction;
  19802. this.emit('newTransaction', {
  19803. transaction: transaction
  19804. });
  19805. }
  19806. /**
  19807. * Transaction destroyed.
  19808. */
  19809. }, {
  19810. key: "destroyTransaction",
  19811. value: function destroyTransaction(transaction) {
  19812. delete this._transactions[transaction.type][transaction.id];
  19813. this.emit('transactionDestroyed', {
  19814. transaction: transaction
  19815. });
  19816. }
  19817. /**
  19818. * new Dialog
  19819. */
  19820. }, {
  19821. key: "newDialog",
  19822. value: function newDialog(dialog) {
  19823. this._dialogs[dialog.id] = dialog;
  19824. }
  19825. /**
  19826. * Dialog destroyed.
  19827. */
  19828. }, {
  19829. key: "destroyDialog",
  19830. value: function destroyDialog(dialog) {
  19831. delete this._dialogs[dialog.id];
  19832. }
  19833. /**
  19834. * new Message
  19835. */
  19836. }, {
  19837. key: "newMessage",
  19838. value: function newMessage(message, data) {
  19839. this._applicants[message] = message;
  19840. this.emit('newMessage', data);
  19841. }
  19842. /**
  19843. * Message destroyed.
  19844. */
  19845. }, {
  19846. key: "destroyMessage",
  19847. value: function destroyMessage(message) {
  19848. delete this._applicants[message];
  19849. }
  19850. /**
  19851. * new RTCSession
  19852. */
  19853. }, {
  19854. key: "newRTCSession",
  19855. value: function newRTCSession(session, data) {
  19856. this._sessions[session.id] = session;
  19857. this.emit('newRTCSession', data);
  19858. }
  19859. /**
  19860. * RTCSession destroyed.
  19861. */
  19862. }, {
  19863. key: "destroyRTCSession",
  19864. value: function destroyRTCSession(session) {
  19865. delete this._sessions[session.id];
  19866. }
  19867. /**
  19868. * Registered
  19869. */
  19870. }, {
  19871. key: "registered",
  19872. value: function registered(data) {
  19873. this.emit('registered', data);
  19874. }
  19875. /**
  19876. * Unregistered
  19877. */
  19878. }, {
  19879. key: "unregistered",
  19880. value: function unregistered(data) {
  19881. this.emit('unregistered', data);
  19882. }
  19883. /**
  19884. * Registration Failed
  19885. */
  19886. }, {
  19887. key: "registrationFailed",
  19888. value: function registrationFailed(data) {
  19889. this.emit('registrationFailed', data);
  19890. } // =========================
  19891. // ReceiveRequest.
  19892. // =========================
  19893. /**
  19894. * Request reception
  19895. */
  19896. }, {
  19897. key: "receiveRequest",
  19898. value: function receiveRequest(request) {
  19899. var method = request.method; // Check that request URI points to us.
  19900. if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) {
  19901. debug('Request-URI does not point to us');
  19902. if (request.method !== JsSIP_C.ACK) {
  19903. request.reply_sl(404);
  19904. }
  19905. return;
  19906. } // Check request URI scheme.
  19907. if (request.ruri.scheme === JsSIP_C.SIPS) {
  19908. request.reply_sl(416);
  19909. return;
  19910. } // Check transaction.
  19911. if (Transactions.checkTransaction(this, request)) {
  19912. return;
  19913. } // Create the server transaction.
  19914. if (method === JsSIP_C.INVITE) {
  19915. /* eslint-disable no-new */
  19916. new Transactions.InviteServerTransaction(this, this._transport, request);
  19917. /* eslint-enable no-new */
  19918. } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) {
  19919. /* eslint-disable no-new */
  19920. new Transactions.NonInviteServerTransaction(this, this._transport, request);
  19921. /* eslint-enable no-new */
  19922. }
  19923. /* RFC3261 12.2.2
  19924. * Requests that do not change in any way the state of a dialog may be
  19925. * received within a dialog (for example, an OPTIONS request).
  19926. * They are processed as if they had been received outside the dialog.
  19927. */
  19928. if (method === JsSIP_C.OPTIONS) {
  19929. request.reply(200);
  19930. } else if (method === JsSIP_C.MESSAGE) {
  19931. if (this.listeners('newMessage').length === 0) {
  19932. request.reply(405);
  19933. return;
  19934. }
  19935. var message = new Message(this);
  19936. message.init_incoming(request);
  19937. } else if (method === JsSIP_C.INVITE) {
  19938. // Initial INVITE.
  19939. if (!request.to_tag && this.listeners('newRTCSession').length === 0) {
  19940. request.reply(405);
  19941. return;
  19942. }
  19943. }
  19944. var dialog;
  19945. var session; // Initial Request.
  19946. if (!request.to_tag) {
  19947. switch (method) {
  19948. case JsSIP_C.INVITE:
  19949. if (window.RTCPeerConnection) {
  19950. // TODO
  19951. if (request.hasHeader('replaces')) {
  19952. var replaces = request.replaces;
  19953. dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag);
  19954. if (dialog) {
  19955. session = dialog.owner;
  19956. if (!session.isEnded()) {
  19957. session.receiveRequest(request);
  19958. } else {
  19959. request.reply(603);
  19960. }
  19961. } else {
  19962. request.reply(481);
  19963. }
  19964. } else {
  19965. session = new RTCSession(this);
  19966. session.init_incoming(request);
  19967. }
  19968. } else {
  19969. debugerror('INVITE received but WebRTC is not supported');
  19970. request.reply(488);
  19971. }
  19972. break;
  19973. case JsSIP_C.BYE:
  19974. // Out of dialog BYE received.
  19975. request.reply(481);
  19976. break;
  19977. case JsSIP_C.CANCEL:
  19978. session = this._findSession(request);
  19979. if (session) {
  19980. session.receiveRequest(request);
  19981. } else {
  19982. debug('received CANCEL request for a non existent session');
  19983. }
  19984. break;
  19985. case JsSIP_C.ACK:
  19986. /* Absorb it.
  19987. * ACK request without a corresponding Invite Transaction
  19988. * and without To tag.
  19989. */
  19990. break;
  19991. case JsSIP_C.NOTIFY:
  19992. // Receive new sip event.
  19993. this.emit('sipEvent', {
  19994. event: request.event,
  19995. request: request
  19996. });
  19997. request.reply(200);
  19998. break;
  19999. default:
  20000. request.reply(405);
  20001. break;
  20002. }
  20003. } // In-dialog request.
  20004. else {
  20005. dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag);
  20006. if (dialog) {
  20007. dialog.receiveRequest(request);
  20008. } else if (method === JsSIP_C.NOTIFY) {
  20009. session = this._findSession(request);
  20010. if (session) {
  20011. session.receiveRequest(request);
  20012. } else {
  20013. debug('received NOTIFY request for a non existent subscription');
  20014. request.reply(481, 'Subscription does not exist');
  20015. }
  20016. }
  20017. /* RFC3261 12.2.2
  20018. * Request with to tag, but no matching dialog found.
  20019. * Exception: ACK for an Invite request for which a dialog has not
  20020. * been created.
  20021. */
  20022. else if (method !== JsSIP_C.ACK) {
  20023. request.reply(481);
  20024. }
  20025. }
  20026. } // =================
  20027. // Utils.
  20028. // =================
  20029. /**
  20030. * Get the session to which the request belongs to, if any.
  20031. */
  20032. }, {
  20033. key: "_findSession",
  20034. value: function _findSession(_ref) {
  20035. var call_id = _ref.call_id,
  20036. from_tag = _ref.from_tag,
  20037. to_tag = _ref.to_tag;
  20038. var sessionIDa = call_id + from_tag;
  20039. var sessionA = this._sessions[sessionIDa];
  20040. var sessionIDb = call_id + to_tag;
  20041. var sessionB = this._sessions[sessionIDb];
  20042. if (sessionA) {
  20043. return sessionA;
  20044. } else if (sessionB) {
  20045. return sessionB;
  20046. } else {
  20047. return null;
  20048. }
  20049. }
  20050. /**
  20051. * Get the dialog to which the request belongs to, if any.
  20052. */
  20053. }, {
  20054. key: "_findDialog",
  20055. value: function _findDialog(call_id, from_tag, to_tag) {
  20056. var id = call_id + from_tag + to_tag;
  20057. var dialog = this._dialogs[id];
  20058. if (dialog) {
  20059. return dialog;
  20060. } else {
  20061. id = call_id + to_tag + from_tag;
  20062. dialog = this._dialogs[id];
  20063. if (dialog) {
  20064. return dialog;
  20065. } else {
  20066. return null;
  20067. }
  20068. }
  20069. }
  20070. }, {
  20071. key: "_loadConfig",
  20072. value: function _loadConfig(configuration) {
  20073. // Check and load the given configuration.
  20074. try {
  20075. config.load(this._configuration, configuration);
  20076. } catch (e) {
  20077. throw e;
  20078. } // Post Configuration Process.
  20079. // Allow passing 0 number as display_name.
  20080. if (this._configuration.display_name === 0) {
  20081. this._configuration.display_name = '0';
  20082. } // Instance-id for GRUU.
  20083. if (!this._configuration.instance_id) {
  20084. this._configuration.instance_id = Utils.newUUID();
  20085. } // Jssip_id instance parameter. Static random tag of length 5.
  20086. this._configuration.jssip_id = Utils.createRandomToken(5); // String containing this._configuration.uri without scheme and user.
  20087. var hostport_params = this._configuration.uri.clone();
  20088. hostport_params.user = null;
  20089. this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, ''); // Transport.
  20090. try {
  20091. this._transport = new Transport(this._configuration.sockets, {
  20092. // Recovery options.
  20093. max_interval: this._configuration.connection_recovery_max_interval,
  20094. min_interval: this._configuration.connection_recovery_min_interval
  20095. }); // Transport event callbacks.
  20096. this._transport.onconnecting = onTransportConnecting.bind(this);
  20097. this._transport.onconnect = onTransportConnect.bind(this);
  20098. this._transport.ondisconnect = onTransportDisconnect.bind(this);
  20099. this._transport.ondata = onTransportData.bind(this);
  20100. } catch (e) {
  20101. debugerror(e);
  20102. throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets);
  20103. } // Remove sockets instance from configuration object.
  20104. delete this._configuration.sockets; // Check whether authorization_user is explicitly defined.
  20105. // Take 'this._configuration.uri.user' value if not.
  20106. if (!this._configuration.authorization_user) {
  20107. this._configuration.authorization_user = this._configuration.uri.user;
  20108. } // If no 'registrar_server' is set use the 'uri' value without user portion and
  20109. // without URI params/headers.
  20110. if (!this._configuration.registrar_server) {
  20111. var registrar_server = this._configuration.uri.clone();
  20112. registrar_server.user = null;
  20113. registrar_server.clearParams();
  20114. registrar_server.clearHeaders();
  20115. this._configuration.registrar_server = registrar_server;
  20116. } // User no_answer_timeout.
  20117. this._configuration.no_answer_timeout *= 1000; // Via Host.
  20118. if (this._configuration.contact_uri) {
  20119. this._configuration.via_host = this._configuration.contact_uri.host;
  20120. } // Contact URI.
  20121. else {
  20122. this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, {
  20123. transport: 'ws'
  20124. });
  20125. }
  20126. this._contact = {
  20127. pub_gruu: null,
  20128. temp_gruu: null,
  20129. uri: this._configuration.contact_uri,
  20130. toString: function toString() {
  20131. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20132. var anonymous = options.anonymous || null;
  20133. var outbound = options.outbound || null;
  20134. var contact = '<';
  20135. if (anonymous) {
  20136. contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
  20137. } else {
  20138. contact += this.pub_gruu || this.uri.toString();
  20139. }
  20140. if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) {
  20141. contact += ';ob';
  20142. }
  20143. contact += '>';
  20144. return contact;
  20145. }
  20146. }; // Seal the configuration.
  20147. var writable_parameters = ['password', 'realm', 'ha1', 'display_name', 'register'];
  20148. for (var parameter in this._configuration) {
  20149. if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) {
  20150. if (writable_parameters.indexOf(parameter) !== -1) {
  20151. Object.defineProperty(this._configuration, parameter, {
  20152. writable: true,
  20153. configurable: false
  20154. });
  20155. } else {
  20156. Object.defineProperty(this._configuration, parameter, {
  20157. writable: false,
  20158. configurable: false
  20159. });
  20160. }
  20161. }
  20162. }
  20163. debug('configuration parameters after validation:');
  20164. for (var _parameter in this._configuration) {
  20165. // Only show the user user configurable parameters.
  20166. if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) {
  20167. switch (_parameter) {
  20168. case 'uri':
  20169. case 'registrar_server':
  20170. debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter]));
  20171. break;
  20172. case 'password':
  20173. case 'ha1':
  20174. debug("- ".concat(_parameter, ": NOT SHOWN"));
  20175. break;
  20176. default:
  20177. debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter])));
  20178. }
  20179. }
  20180. }
  20181. return;
  20182. }
  20183. }, {
  20184. key: "C",
  20185. get: function get() {
  20186. return C;
  20187. }
  20188. }, {
  20189. key: "status",
  20190. get: function get() {
  20191. return this._status;
  20192. }
  20193. }, {
  20194. key: "contact",
  20195. get: function get() {
  20196. return this._contact;
  20197. }
  20198. }, {
  20199. key: "configuration",
  20200. get: function get() {
  20201. return this._configuration;
  20202. }
  20203. }, {
  20204. key: "transport",
  20205. get: function get() {
  20206. return this._transport;
  20207. }
  20208. }]);
  20209. return UA;
  20210. }(EventEmitter);
  20211. /**
  20212. * Transport event handlers
  20213. */
  20214. // Transport connecting event.
  20215. function onTransportConnecting(data) {
  20216. this.emit('connecting', data);
  20217. } // Transport connected event.
  20218. function onTransportConnect(data) {
  20219. if (this._status === C.STATUS_USER_CLOSED) {
  20220. return;
  20221. }
  20222. this._status = C.STATUS_READY;
  20223. this._error = null;
  20224. this.emit('connected', data);
  20225. if (this._dynConfiguration.register) {
  20226. this._registrator.register();
  20227. }
  20228. } // Transport disconnected event.
  20229. function onTransportDisconnect(data) {
  20230. // Run _onTransportError_ callback on every client transaction using _transport_.
  20231. var client_transactions = ['nict', 'ict', 'nist', 'ist'];
  20232. for (var _i = 0; _i < client_transactions.length; _i++) {
  20233. var type = client_transactions[_i];
  20234. for (var id in this._transactions[type]) {
  20235. if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) {
  20236. this._transactions[type][id].onTransportError();
  20237. }
  20238. }
  20239. }
  20240. this.emit('disconnected', data); // Call registrator _onTransportClosed_.
  20241. this._registrator.onTransportClosed();
  20242. if (this._status !== C.STATUS_USER_CLOSED) {
  20243. this._status = C.STATUS_NOT_READY;
  20244. this._error = C.NETWORK_ERROR;
  20245. }
  20246. } // Transport data event.
  20247. function onTransportData(data) {
  20248. var transport = data.transport;
  20249. var message = data.message;
  20250. message = Parser.parseMessage(message, this);
  20251. if (!message) {
  20252. return;
  20253. }
  20254. if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) {
  20255. return;
  20256. } // Do some sanity check.
  20257. if (!sanityCheck(message, this, transport)) {
  20258. return;
  20259. }
  20260. if (message instanceof SIPMessage.IncomingRequest) {
  20261. message.transport = transport;
  20262. this.receiveRequest(message);
  20263. } else if (message instanceof SIPMessage.IncomingResponse) {
  20264. /* Unike stated in 18.1.2, if a response does not match
  20265. * any transaction, it is discarded here and no passed to the core
  20266. * in order to be discarded there.
  20267. */
  20268. var transaction;
  20269. switch (message.method) {
  20270. case JsSIP_C.INVITE:
  20271. transaction = this._transactions.ict[message.via_branch];
  20272. if (transaction) {
  20273. transaction.receiveResponse(message);
  20274. }
  20275. break;
  20276. case JsSIP_C.ACK:
  20277. // Just in case ;-).
  20278. break;
  20279. default:
  20280. transaction = this._transactions.nict[message.via_branch];
  20281. if (transaction) {
  20282. transaction.receiveResponse(message);
  20283. }
  20284. break;
  20285. }
  20286. }
  20287. }
  20288. },{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":30,"events":29}],25:[function(require,module,exports){
  20289. "use strict";
  20290. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20291. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  20292. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20293. var JsSIP_C = require('./Constants');
  20294. var Utils = require('./Utils');
  20295. var Grammar = require('./Grammar');
  20296. /**
  20297. * -param {String} [scheme]
  20298. * -param {String} [user]
  20299. * -param {String} host
  20300. * -param {String} [port]
  20301. * -param {Object} [parameters]
  20302. * -param {Object} [headers]
  20303. *
  20304. */
  20305. module.exports =
  20306. /*#__PURE__*/
  20307. function () {
  20308. _createClass(URI, null, [{
  20309. key: "parse",
  20310. /**
  20311. * Parse the given string and returns a JsSIP.URI instance or undefined if
  20312. * it is an invalid URI.
  20313. */
  20314. value: function parse(uri) {
  20315. uri = Grammar.parse(uri, 'SIP_URI');
  20316. if (uri !== -1) {
  20317. return uri;
  20318. } else {
  20319. return undefined;
  20320. }
  20321. }
  20322. }]);
  20323. function URI(scheme, user, host, port) {
  20324. var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  20325. var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
  20326. _classCallCheck(this, URI);
  20327. // Checks.
  20328. if (!host) {
  20329. throw new TypeError('missing or invalid "host" parameter');
  20330. } // Initialize parameters.
  20331. this._parameters = {};
  20332. this._headers = {};
  20333. this._scheme = scheme || JsSIP_C.SIP;
  20334. this._user = user;
  20335. this._host = host;
  20336. this._port = port;
  20337. for (var param in parameters) {
  20338. if (Object.prototype.hasOwnProperty.call(parameters, param)) {
  20339. this.setParam(param, parameters[param]);
  20340. }
  20341. }
  20342. for (var header in headers) {
  20343. if (Object.prototype.hasOwnProperty.call(headers, header)) {
  20344. this.setHeader(header, headers[header]);
  20345. }
  20346. }
  20347. }
  20348. _createClass(URI, [{
  20349. key: "setParam",
  20350. value: function setParam(key, value) {
  20351. if (key) {
  20352. this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
  20353. }
  20354. }
  20355. }, {
  20356. key: "getParam",
  20357. value: function getParam(key) {
  20358. if (key) {
  20359. return this._parameters[key.toLowerCase()];
  20360. }
  20361. }
  20362. }, {
  20363. key: "hasParam",
  20364. value: function hasParam(key) {
  20365. if (key) {
  20366. return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
  20367. }
  20368. }
  20369. }, {
  20370. key: "deleteParam",
  20371. value: function deleteParam(parameter) {
  20372. parameter = parameter.toLowerCase();
  20373. if (this._parameters.hasOwnProperty(parameter)) {
  20374. var value = this._parameters[parameter];
  20375. delete this._parameters[parameter];
  20376. return value;
  20377. }
  20378. }
  20379. }, {
  20380. key: "clearParams",
  20381. value: function clearParams() {
  20382. this._parameters = {};
  20383. }
  20384. }, {
  20385. key: "setHeader",
  20386. value: function setHeader(name, value) {
  20387. this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
  20388. }
  20389. }, {
  20390. key: "getHeader",
  20391. value: function getHeader(name) {
  20392. if (name) {
  20393. return this._headers[Utils.headerize(name)];
  20394. }
  20395. }
  20396. }, {
  20397. key: "hasHeader",
  20398. value: function hasHeader(name) {
  20399. if (name) {
  20400. return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false;
  20401. }
  20402. }
  20403. }, {
  20404. key: "deleteHeader",
  20405. value: function deleteHeader(header) {
  20406. header = Utils.headerize(header);
  20407. if (this._headers.hasOwnProperty(header)) {
  20408. var value = this._headers[header];
  20409. delete this._headers[header];
  20410. return value;
  20411. }
  20412. }
  20413. }, {
  20414. key: "clearHeaders",
  20415. value: function clearHeaders() {
  20416. this._headers = {};
  20417. }
  20418. }, {
  20419. key: "clone",
  20420. value: function clone() {
  20421. return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers)));
  20422. }
  20423. }, {
  20424. key: "toString",
  20425. value: function toString() {
  20426. var headers = [];
  20427. var uri = "".concat(this._scheme, ":");
  20428. if (this._user) {
  20429. uri += "".concat(Utils.escapeUser(this._user), "@");
  20430. }
  20431. uri += this._host;
  20432. if (this._port || this._port === 0) {
  20433. uri += ":".concat(this._port);
  20434. }
  20435. for (var parameter in this._parameters) {
  20436. if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
  20437. uri += ";".concat(parameter);
  20438. if (this._parameters[parameter] !== null) {
  20439. uri += "=".concat(this._parameters[parameter]);
  20440. }
  20441. }
  20442. }
  20443. for (var header in this._headers) {
  20444. if (Object.prototype.hasOwnProperty.call(this._headers, header)) {
  20445. var _iteratorNormalCompletion = true;
  20446. var _didIteratorError = false;
  20447. var _iteratorError = undefined;
  20448. try {
  20449. for (var _iterator = this._headers[header][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  20450. var item = _step.value;
  20451. headers.push("".concat(header, "=").concat(item));
  20452. }
  20453. } catch (err) {
  20454. _didIteratorError = true;
  20455. _iteratorError = err;
  20456. } finally {
  20457. try {
  20458. if (!_iteratorNormalCompletion && _iterator.return != null) {
  20459. _iterator.return();
  20460. }
  20461. } finally {
  20462. if (_didIteratorError) {
  20463. throw _iteratorError;
  20464. }
  20465. }
  20466. }
  20467. }
  20468. }
  20469. if (headers.length > 0) {
  20470. uri += "?".concat(headers.join('&'));
  20471. }
  20472. return uri;
  20473. }
  20474. }, {
  20475. key: "toAor",
  20476. value: function toAor(show_port) {
  20477. var aor = "".concat(this._scheme, ":");
  20478. if (this._user) {
  20479. aor += "".concat(Utils.escapeUser(this._user), "@");
  20480. }
  20481. aor += this._host;
  20482. if (show_port && (this._port || this._port === 0)) {
  20483. aor += ":".concat(this._port);
  20484. }
  20485. return aor;
  20486. }
  20487. }, {
  20488. key: "scheme",
  20489. get: function get() {
  20490. return this._scheme;
  20491. },
  20492. set: function set(value) {
  20493. this._scheme = value.toLowerCase();
  20494. }
  20495. }, {
  20496. key: "user",
  20497. get: function get() {
  20498. return this._user;
  20499. },
  20500. set: function set(value) {
  20501. this._user = value;
  20502. }
  20503. }, {
  20504. key: "host",
  20505. get: function get() {
  20506. return this._host;
  20507. },
  20508. set: function set(value) {
  20509. this._host = value.toLowerCase();
  20510. }
  20511. }, {
  20512. key: "port",
  20513. get: function get() {
  20514. return this._port;
  20515. },
  20516. set: function set(value) {
  20517. this._port = value === 0 ? value : parseInt(value, 10) || null;
  20518. }
  20519. }]);
  20520. return URI;
  20521. }();
  20522. },{"./Constants":2,"./Grammar":7,"./Utils":26}],26:[function(require,module,exports){
  20523. "use strict";
  20524. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  20525. var JsSIP_C = require('./Constants');
  20526. var URI = require('./URI');
  20527. var Grammar = require('./Grammar');
  20528. exports.str_utf8_length = function (string) {
  20529. return unescape(encodeURIComponent(string)).length;
  20530. }; // Used by 'hasMethods'.
  20531. var isFunction = exports.isFunction = function (fn) {
  20532. if (fn !== undefined) {
  20533. return Object.prototype.toString.call(fn) === '[object Function]' ? true : false;
  20534. } else {
  20535. return false;
  20536. }
  20537. };
  20538. exports.isString = function (str) {
  20539. if (str !== undefined) {
  20540. return Object.prototype.toString.call(str) === '[object String]' ? true : false;
  20541. } else {
  20542. return false;
  20543. }
  20544. };
  20545. exports.isDecimal = function (num) {
  20546. return !isNaN(num) && parseFloat(num) === parseInt(num, 10);
  20547. };
  20548. exports.isEmpty = function (value) {
  20549. return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value);
  20550. };
  20551. exports.hasMethods = function (obj) {
  20552. for (var _len = arguments.length, methodNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  20553. methodNames[_key - 1] = arguments[_key];
  20554. }
  20555. for (var _i = 0; _i < methodNames.length; _i++) {
  20556. var methodName = methodNames[_i];
  20557. if (isFunction(obj[methodName])) {
  20558. return false;
  20559. }
  20560. }
  20561. return true;
  20562. }; // Used by 'newTag'.
  20563. var createRandomToken = exports.createRandomToken = function (size) {
  20564. var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32;
  20565. var i,
  20566. r,
  20567. token = '';
  20568. for (i = 0; i < size; i++) {
  20569. r = Math.random() * base | 0;
  20570. token += r.toString(base);
  20571. }
  20572. return token;
  20573. };
  20574. exports.newTag = function () {
  20575. return createRandomToken(10);
  20576. }; // https://stackoverflow.com/users/109538/broofa.
  20577. exports.newUUID = function () {
  20578. var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  20579. var r = Math.random() * 16 | 0,
  20580. v = c === 'x' ? r : r & 0x3 | 0x8;
  20581. return v.toString(16);
  20582. });
  20583. return UUID;
  20584. };
  20585. exports.hostType = function (host) {
  20586. if (!host) {
  20587. return;
  20588. } else {
  20589. host = Grammar.parse(host, 'host');
  20590. if (host !== -1) {
  20591. return host.host_type;
  20592. }
  20593. }
  20594. };
  20595. /**
  20596. * Hex-escape a SIP URI user.
  20597. * Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F).
  20598. *
  20599. * Used by 'normalizeTarget'.
  20600. */
  20601. var escapeUser = exports.escapeUser = function (user) {
  20602. return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/');
  20603. };
  20604. /**
  20605. * Normalize SIP URI.
  20606. * NOTE: It does not allow a SIP URI without username.
  20607. * Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'.
  20608. * Detects the domain part (if given) and properly hex-escapes the user portion.
  20609. * If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators.
  20610. */
  20611. exports.normalizeTarget = function (target, domain) {
  20612. // If no target is given then raise an error.
  20613. if (!target) {
  20614. return; // If a URI instance is given then return it.
  20615. } else if (target instanceof URI) {
  20616. return target; // If a string is given split it by '@':
  20617. // - Last fragment is the desired domain.
  20618. // - Otherwise append the given domain argument.
  20619. } else if (typeof target === 'string') {
  20620. var target_array = target.split('@');
  20621. var target_user;
  20622. var target_domain;
  20623. switch (target_array.length) {
  20624. case 1:
  20625. if (!domain) {
  20626. return;
  20627. }
  20628. target_user = target;
  20629. target_domain = domain;
  20630. break;
  20631. case 2:
  20632. target_user = target_array[0];
  20633. target_domain = target_array[1];
  20634. break;
  20635. default:
  20636. target_user = target_array.slice(0, target_array.length - 1).join('@');
  20637. target_domain = target_array[target_array.length - 1];
  20638. } // Remove the URI scheme (if present).
  20639. target_user = target_user.replace(/^(sips?|tel):/i, ''); // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols.
  20640. if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) {
  20641. target_user = target_user.replace(/[-.()]/g, '');
  20642. } // Build the complete SIP URI.
  20643. target = "".concat(JsSIP_C.SIP, ":").concat(escapeUser(target_user), "@").concat(target_domain); // Finally parse the resulting URI.
  20644. var uri;
  20645. if (uri = URI.parse(target)) {
  20646. return uri;
  20647. } else {
  20648. return;
  20649. }
  20650. } else {
  20651. return;
  20652. }
  20653. };
  20654. exports.headerize = function (string) {
  20655. var exceptions = {
  20656. 'Call-Id': 'Call-ID',
  20657. 'Cseq': 'CSeq',
  20658. 'Www-Authenticate': 'WWW-Authenticate'
  20659. };
  20660. var name = string.toLowerCase().replace(/_/g, '-').split('-');
  20661. var hname = '';
  20662. var parts = name.length;
  20663. var part;
  20664. for (part = 0; part < parts; part++) {
  20665. if (part !== 0) {
  20666. hname += '-';
  20667. }
  20668. hname += name[part].charAt(0).toUpperCase() + name[part].substring(1);
  20669. }
  20670. if (exceptions[hname]) {
  20671. hname = exceptions[hname];
  20672. }
  20673. return hname;
  20674. };
  20675. exports.sipErrorCause = function (status_code) {
  20676. for (var cause in JsSIP_C.SIP_ERROR_CAUSES) {
  20677. if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) {
  20678. return JsSIP_C.causes[cause];
  20679. }
  20680. }
  20681. return JsSIP_C.causes.SIP_FAILURE_CODE;
  20682. };
  20683. /**
  20684. * Generate a random Test-Net IP (https://tools.ietf.org/html/rfc5735)
  20685. */
  20686. exports.getRandomTestNetIP = function () {
  20687. function getOctet(from, to) {
  20688. return Math.floor(Math.random() * (to - from + 1) + from);
  20689. }
  20690. return "192.0.2.".concat(getOctet(1, 254));
  20691. }; // MD5 (Message-Digest Algorithm) https://www.webtoolkit.info.
  20692. exports.calculateMD5 = function (string) {
  20693. function rotateLeft(lValue, iShiftBits) {
  20694. return lValue << iShiftBits | lValue >>> 32 - iShiftBits;
  20695. }
  20696. function addUnsigned(lX, lY) {
  20697. var lX8 = lX & 0x80000000;
  20698. var lY8 = lY & 0x80000000;
  20699. var lX4 = lX & 0x40000000;
  20700. var lY4 = lY & 0x40000000;
  20701. var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
  20702. if (lX4 & lY4) {
  20703. return lResult ^ 0x80000000 ^ lX8 ^ lY8;
  20704. }
  20705. if (lX4 | lY4) {
  20706. if (lResult & 0x40000000) {
  20707. return lResult ^ 0xC0000000 ^ lX8 ^ lY8;
  20708. } else {
  20709. return lResult ^ 0x40000000 ^ lX8 ^ lY8;
  20710. }
  20711. } else {
  20712. return lResult ^ lX8 ^ lY8;
  20713. }
  20714. }
  20715. function doF(x, y, z) {
  20716. return x & y | ~x & z;
  20717. }
  20718. function doG(x, y, z) {
  20719. return x & z | y & ~z;
  20720. }
  20721. function doH(x, y, z) {
  20722. return x ^ y ^ z;
  20723. }
  20724. function doI(x, y, z) {
  20725. return y ^ (x | ~z);
  20726. }
  20727. function doFF(a, b, c, d, x, s, ac) {
  20728. a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac));
  20729. return addUnsigned(rotateLeft(a, s), b);
  20730. }
  20731. function doGG(a, b, c, d, x, s, ac) {
  20732. a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac));
  20733. return addUnsigned(rotateLeft(a, s), b);
  20734. }
  20735. function doHH(a, b, c, d, x, s, ac) {
  20736. a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac));
  20737. return addUnsigned(rotateLeft(a, s), b);
  20738. }
  20739. function doII(a, b, c, d, x, s, ac) {
  20740. a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac));
  20741. return addUnsigned(rotateLeft(a, s), b);
  20742. }
  20743. function convertToWordArray(str) {
  20744. var lWordCount;
  20745. var lMessageLength = str.length;
  20746. var lNumberOfWords_temp1 = lMessageLength + 8;
  20747. var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64;
  20748. var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
  20749. var lWordArray = new Array(lNumberOfWords - 1);
  20750. var lBytePosition = 0;
  20751. var lByteCount = 0;
  20752. while (lByteCount < lMessageLength) {
  20753. lWordCount = (lByteCount - lByteCount % 4) / 4;
  20754. lBytePosition = lByteCount % 4 * 8;
  20755. lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition;
  20756. lByteCount++;
  20757. }
  20758. lWordCount = (lByteCount - lByteCount % 4) / 4;
  20759. lBytePosition = lByteCount % 4 * 8;
  20760. lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition;
  20761. lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
  20762. lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
  20763. return lWordArray;
  20764. }
  20765. function wordToHex(lValue) {
  20766. var wordToHexValue = '',
  20767. wordToHexValue_temp = '',
  20768. lByte,
  20769. lCount;
  20770. for (lCount = 0; lCount <= 3; lCount++) {
  20771. lByte = lValue >>> lCount * 8 & 255;
  20772. wordToHexValue_temp = "0".concat(lByte.toString(16));
  20773. wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2);
  20774. }
  20775. return wordToHexValue;
  20776. }
  20777. function utf8Encode(str) {
  20778. str = str.replace(/\r\n/g, '\n');
  20779. var utftext = '';
  20780. for (var n = 0; n < str.length; n++) {
  20781. var _c = str.charCodeAt(n);
  20782. if (_c < 128) {
  20783. utftext += String.fromCharCode(_c);
  20784. } else if (_c > 127 && _c < 2048) {
  20785. utftext += String.fromCharCode(_c >> 6 | 192);
  20786. utftext += String.fromCharCode(_c & 63 | 128);
  20787. } else {
  20788. utftext += String.fromCharCode(_c >> 12 | 224);
  20789. utftext += String.fromCharCode(_c >> 6 & 63 | 128);
  20790. utftext += String.fromCharCode(_c & 63 | 128);
  20791. }
  20792. }
  20793. return utftext;
  20794. }
  20795. var x = [];
  20796. var k, AA, BB, CC, DD, a, b, c, d;
  20797. var S11 = 7,
  20798. S12 = 12,
  20799. S13 = 17,
  20800. S14 = 22;
  20801. var S21 = 5,
  20802. S22 = 9,
  20803. S23 = 14,
  20804. S24 = 20;
  20805. var S31 = 4,
  20806. S32 = 11,
  20807. S33 = 16,
  20808. S34 = 23;
  20809. var S41 = 6,
  20810. S42 = 10,
  20811. S43 = 15,
  20812. S44 = 21;
  20813. string = utf8Encode(string);
  20814. x = convertToWordArray(string);
  20815. a = 0x67452301;
  20816. b = 0xEFCDAB89;
  20817. c = 0x98BADCFE;
  20818. d = 0x10325476;
  20819. for (k = 0; k < x.length; k += 16) {
  20820. AA = a;
  20821. BB = b;
  20822. CC = c;
  20823. DD = d;
  20824. a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
  20825. d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
  20826. c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB);
  20827. b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
  20828. a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
  20829. d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
  20830. c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613);
  20831. b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501);
  20832. a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8);
  20833. d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
  20834. c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
  20835. b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
  20836. a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122);
  20837. d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193);
  20838. c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E);
  20839. b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821);
  20840. a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
  20841. d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340);
  20842. c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
  20843. b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
  20844. a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
  20845. d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453);
  20846. c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
  20847. b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
  20848. a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
  20849. d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
  20850. c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
  20851. b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
  20852. a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
  20853. d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
  20854. c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
  20855. b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
  20856. a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
  20857. d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681);
  20858. c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
  20859. b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
  20860. a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
  20861. d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
  20862. c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
  20863. b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
  20864. a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
  20865. d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
  20866. c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
  20867. b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05);
  20868. a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
  20869. d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
  20870. c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
  20871. b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
  20872. a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244);
  20873. d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97);
  20874. c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
  20875. b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039);
  20876. a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3);
  20877. d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
  20878. c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
  20879. b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1);
  20880. a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
  20881. d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
  20882. c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314);
  20883. b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
  20884. a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82);
  20885. d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
  20886. c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
  20887. b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391);
  20888. a = addUnsigned(a, AA);
  20889. b = addUnsigned(b, BB);
  20890. c = addUnsigned(c, CC);
  20891. d = addUnsigned(d, DD);
  20892. }
  20893. var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
  20894. return temp.toLowerCase();
  20895. };
  20896. exports.closeMediaStream = function (stream) {
  20897. if (!stream) {
  20898. return;
  20899. } // Latest spec states that MediaStream has no stop() method and instead must
  20900. // call stop() on every MediaStreamTrack.
  20901. try {
  20902. var tracks;
  20903. if (stream.getTracks) {
  20904. tracks = stream.getTracks();
  20905. var _iteratorNormalCompletion = true;
  20906. var _didIteratorError = false;
  20907. var _iteratorError = undefined;
  20908. try {
  20909. for (var _iterator = tracks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  20910. var track = _step.value;
  20911. track.stop();
  20912. }
  20913. } catch (err) {
  20914. _didIteratorError = true;
  20915. _iteratorError = err;
  20916. } finally {
  20917. try {
  20918. if (!_iteratorNormalCompletion && _iterator.return != null) {
  20919. _iterator.return();
  20920. }
  20921. } finally {
  20922. if (_didIteratorError) {
  20923. throw _iteratorError;
  20924. }
  20925. }
  20926. }
  20927. } else {
  20928. tracks = stream.getAudioTracks();
  20929. var _iteratorNormalCompletion2 = true;
  20930. var _didIteratorError2 = false;
  20931. var _iteratorError2 = undefined;
  20932. try {
  20933. for (var _iterator2 = tracks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  20934. var _track = _step2.value;
  20935. _track.stop();
  20936. }
  20937. } catch (err) {
  20938. _didIteratorError2 = true;
  20939. _iteratorError2 = err;
  20940. } finally {
  20941. try {
  20942. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  20943. _iterator2.return();
  20944. }
  20945. } finally {
  20946. if (_didIteratorError2) {
  20947. throw _iteratorError2;
  20948. }
  20949. }
  20950. }
  20951. tracks = stream.getVideoTracks();
  20952. var _iteratorNormalCompletion3 = true;
  20953. var _didIteratorError3 = false;
  20954. var _iteratorError3 = undefined;
  20955. try {
  20956. for (var _iterator3 = tracks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  20957. var _track2 = _step3.value;
  20958. _track2.stop();
  20959. }
  20960. } catch (err) {
  20961. _didIteratorError3 = true;
  20962. _iteratorError3 = err;
  20963. } finally {
  20964. try {
  20965. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  20966. _iterator3.return();
  20967. }
  20968. } finally {
  20969. if (_didIteratorError3) {
  20970. throw _iteratorError3;
  20971. }
  20972. }
  20973. }
  20974. }
  20975. } catch (error) {
  20976. // Deprecated by the spec, but still in use.
  20977. // NOTE: In Temasys IE plugin stream.stop is a callable 'object'.
  20978. if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') {
  20979. stream.stop();
  20980. }
  20981. }
  20982. };
  20983. exports.cloneArray = function (array) {
  20984. return array && array.slice() || [];
  20985. };
  20986. },{"./Constants":2,"./Grammar":7,"./URI":25}],27:[function(require,module,exports){
  20987. "use strict";
  20988. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20989. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  20990. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20991. var Grammar = require('./Grammar');
  20992. var debug = require('debug')('JsSIP:WebSocketInterface');
  20993. var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface');
  20994. debugerror.log = console.warn.bind(console);
  20995. module.exports =
  20996. /*#__PURE__*/
  20997. function () {
  20998. function WebSocketInterface(url) {
  20999. _classCallCheck(this, WebSocketInterface);
  21000. debug('new() [url:"%s"]', url);
  21001. this._url = url;
  21002. this._sip_uri = null;
  21003. this._via_transport = null;
  21004. this._ws = null;
  21005. var parsed_url = Grammar.parse(url, 'absoluteURI');
  21006. if (parsed_url === -1) {
  21007. debugerror("invalid WebSocket URI: ".concat(url));
  21008. throw new TypeError("Invalid argument: ".concat(url));
  21009. } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') {
  21010. debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme));
  21011. throw new TypeError("Invalid argument: ".concat(url));
  21012. } else {
  21013. this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws");
  21014. this._via_transport = parsed_url.scheme.toUpperCase();
  21015. }
  21016. }
  21017. _createClass(WebSocketInterface, [{
  21018. key: "connect",
  21019. value: function connect() {
  21020. debug('connect()');
  21021. if (this.isConnected()) {
  21022. debug("WebSocket ".concat(this._url, " is already connected"));
  21023. return;
  21024. } else if (this.isConnecting()) {
  21025. debug("WebSocket ".concat(this._url, " is connecting"));
  21026. return;
  21027. }
  21028. if (this._ws) {
  21029. this.disconnect();
  21030. }
  21031. debug("connecting to WebSocket ".concat(this._url));
  21032. try {
  21033. this._ws = new WebSocket(this._url, 'sip');
  21034. this._ws.binaryType = 'arraybuffer';
  21035. this._ws.onopen = this._onOpen.bind(this);
  21036. this._ws.onclose = this._onClose.bind(this);
  21037. this._ws.onmessage = this._onMessage.bind(this);
  21038. this._ws.onerror = this._onError.bind(this);
  21039. } catch (e) {
  21040. this._onError(e);
  21041. }
  21042. }
  21043. }, {
  21044. key: "disconnect",
  21045. value: function disconnect() {
  21046. debug('disconnect()');
  21047. if (this._ws) {
  21048. // Unbind websocket event callbacks.
  21049. this._ws.onopen = function () {};
  21050. this._ws.onclose = function () {};
  21051. this._ws.onmessage = function () {};
  21052. this._ws.onerror = function () {};
  21053. this._ws.close();
  21054. this._ws = null;
  21055. }
  21056. }
  21057. }, {
  21058. key: "send",
  21059. value: function send(message) {
  21060. debug('send()');
  21061. if (this.isConnected()) {
  21062. this._ws.send(message);
  21063. return true;
  21064. } else {
  21065. debugerror('unable to send message, WebSocket is not open');
  21066. return false;
  21067. }
  21068. }
  21069. }, {
  21070. key: "isConnected",
  21071. value: function isConnected() {
  21072. return this._ws && this._ws.readyState === this._ws.OPEN;
  21073. }
  21074. }, {
  21075. key: "isConnecting",
  21076. value: function isConnecting() {
  21077. return this._ws && this._ws.readyState === this._ws.CONNECTING;
  21078. }
  21079. /**
  21080. * WebSocket Event Handlers
  21081. */
  21082. }, {
  21083. key: "_onOpen",
  21084. value: function _onOpen() {
  21085. debug("WebSocket ".concat(this._url, " connected"));
  21086. this.onconnect();
  21087. }
  21088. }, {
  21089. key: "_onClose",
  21090. value: function _onClose(_ref) {
  21091. var wasClean = _ref.wasClean,
  21092. code = _ref.code,
  21093. reason = _ref.reason;
  21094. debug("WebSocket ".concat(this._url, " closed"));
  21095. if (wasClean === false) {
  21096. debug('WebSocket abrupt disconnection');
  21097. }
  21098. var data = {
  21099. socket: this,
  21100. error: !wasClean,
  21101. code: code,
  21102. reason: reason
  21103. };
  21104. this.ondisconnect(data);
  21105. }
  21106. }, {
  21107. key: "_onMessage",
  21108. value: function _onMessage(_ref2) {
  21109. var data = _ref2.data;
  21110. debug('received WebSocket message');
  21111. this.ondata(data);
  21112. }
  21113. }, {
  21114. key: "_onError",
  21115. value: function _onError(e) {
  21116. debugerror("WebSocket ".concat(this._url, " error: ").concat(e));
  21117. }
  21118. }, {
  21119. key: "via_transport",
  21120. get: function get() {
  21121. return this._via_transport;
  21122. },
  21123. set: function set(value) {
  21124. this._via_transport = value.toUpperCase();
  21125. }
  21126. }, {
  21127. key: "sip_uri",
  21128. get: function get() {
  21129. return this._sip_uri;
  21130. }
  21131. }, {
  21132. key: "url",
  21133. get: function get() {
  21134. return this._url;
  21135. }
  21136. }]);
  21137. return WebSocketInterface;
  21138. }();
  21139. },{"./Grammar":7,"debug":30}],28:[function(require,module,exports){
  21140. "use strict";
  21141. var JsSIP_C = require('./Constants');
  21142. var SIPMessage = require('./SIPMessage');
  21143. var Utils = require('./Utils');
  21144. var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses.
  21145. var all = [minimumHeaders]; // Checks for requests.
  21146. var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2]; // Checks for responses.
  21147. var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response]; // local variables.
  21148. var message;
  21149. var ua;
  21150. var transport;
  21151. module.exports = function (m, u, t) {
  21152. message = m;
  21153. ua = u;
  21154. transport = t;
  21155. for (var _i = 0; _i < all.length; _i++) {
  21156. var _check2 = all[_i];
  21157. if (_check2() === false) {
  21158. return false;
  21159. }
  21160. }
  21161. if (message instanceof SIPMessage.IncomingRequest) {
  21162. for (var _i2 = 0; _i2 < requests.length; _i2++) {
  21163. var check = requests[_i2];
  21164. if (check() === false) {
  21165. return false;
  21166. }
  21167. }
  21168. } else if (message instanceof SIPMessage.IncomingResponse) {
  21169. for (var _i3 = 0; _i3 < responses.length; _i3++) {
  21170. var _check = responses[_i3];
  21171. if (_check() === false) {
  21172. return false;
  21173. }
  21174. }
  21175. } // Everything is OK.
  21176. return true;
  21177. };
  21178. /*
  21179. * Sanity Check for incoming Messages
  21180. *
  21181. * Requests:
  21182. * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme
  21183. * - _rfc3261_16_3_4_ Receive a Request already sent by us
  21184. * Does not look at via sent-by but at jssip_id, which is inserted as
  21185. * a prefix in all initial requests generated by the ua
  21186. * - _rfc3261_18_3_request_ Body Content-Length
  21187. * - _rfc3261_8_2_2_2_ Merged Requests
  21188. *
  21189. * Responses:
  21190. * - _rfc3261_8_1_3_3_ Multiple Via headers
  21191. * - _rfc3261_18_3_response_ Body Content-Length
  21192. *
  21193. * All:
  21194. * - Minimum headers in a SIP message
  21195. */
  21196. // Sanity Check functions for requests.
  21197. function rfc3261_8_2_2_1() {
  21198. if (message.s('to').uri.scheme !== 'sip') {
  21199. reply(416);
  21200. return false;
  21201. }
  21202. }
  21203. function rfc3261_16_3_4() {
  21204. if (!message.to_tag) {
  21205. if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) {
  21206. reply(482);
  21207. return false;
  21208. }
  21209. }
  21210. }
  21211. function rfc3261_18_3_request() {
  21212. var len = Utils.str_utf8_length(message.body);
  21213. var contentLength = message.getHeader('content-length');
  21214. if (len < contentLength) {
  21215. reply(400);
  21216. return false;
  21217. }
  21218. }
  21219. function rfc3261_8_2_2_2() {
  21220. var fromTag = message.from_tag;
  21221. var call_id = message.call_id;
  21222. var cseq = message.cseq;
  21223. var tr; // Accept any in-dialog request.
  21224. if (message.to_tag) {
  21225. return;
  21226. } // INVITE request.
  21227. if (message.method === JsSIP_C.INVITE) {
  21228. // If the branch matches the key of any IST then assume it is a retransmission
  21229. // and ignore the INVITE.
  21230. // TODO: we should reply the last response.
  21231. if (ua._transactions.ist[message.via_branch]) {
  21232. return false;
  21233. } // Otherwise check whether it is a merged request.
  21234. else {
  21235. for (var transaction in ua._transactions.ist) {
  21236. if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) {
  21237. tr = ua._transactions.ist[transaction];
  21238. if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  21239. reply(482);
  21240. return false;
  21241. }
  21242. }
  21243. }
  21244. }
  21245. } // Non INVITE request.
  21246. // If the branch matches the key of any NIST then assume it is a retransmission
  21247. // and ignore the request.
  21248. // TODO: we should reply the last response.
  21249. else if (ua._transactions.nist[message.via_branch]) {
  21250. return false;
  21251. } // Otherwise check whether it is a merged request.
  21252. else {
  21253. for (var _transaction in ua._transactions.nist) {
  21254. if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) {
  21255. tr = ua._transactions.nist[_transaction];
  21256. if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  21257. reply(482);
  21258. return false;
  21259. }
  21260. }
  21261. }
  21262. }
  21263. } // Sanity Check functions for responses.
  21264. function rfc3261_8_1_3_3() {
  21265. if (message.getHeaders('via').length > 1) {
  21266. debug('more than one Via header field present in the response, dropping the response');
  21267. return false;
  21268. }
  21269. }
  21270. function rfc3261_18_3_response() {
  21271. var len = Utils.str_utf8_length(message.body),
  21272. contentLength = message.getHeader('content-length');
  21273. if (len < contentLength) {
  21274. debug('message body length is lower than the value in Content-Length header field, dropping the response');
  21275. return false;
  21276. }
  21277. } // Sanity Check functions for requests and responses.
  21278. function minimumHeaders() {
  21279. var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via'];
  21280. for (var _i4 = 0; _i4 < mandatoryHeaders.length; _i4++) {
  21281. var header = mandatoryHeaders[_i4];
  21282. if (!message.hasHeader(header)) {
  21283. debug("missing mandatory header field : ".concat(header, ", dropping the response"));
  21284. return false;
  21285. }
  21286. }
  21287. } // Reply.
  21288. function reply(status_code) {
  21289. var vias = message.getHeaders('via');
  21290. var to;
  21291. var response = "SIP/2.0 ".concat(status_code, " ").concat(JsSIP_C.REASON_PHRASE[status_code], "\r\n");
  21292. var _iteratorNormalCompletion = true;
  21293. var _didIteratorError = false;
  21294. var _iteratorError = undefined;
  21295. try {
  21296. for (var _iterator = vias[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  21297. var via = _step.value;
  21298. response += "Via: ".concat(via, "\r\n");
  21299. }
  21300. } catch (err) {
  21301. _didIteratorError = true;
  21302. _iteratorError = err;
  21303. } finally {
  21304. try {
  21305. if (!_iteratorNormalCompletion && _iterator.return != null) {
  21306. _iterator.return();
  21307. }
  21308. } finally {
  21309. if (_didIteratorError) {
  21310. throw _iteratorError;
  21311. }
  21312. }
  21313. }
  21314. to = message.getHeader('To');
  21315. if (!message.to_tag) {
  21316. to += ";tag=".concat(Utils.newTag());
  21317. }
  21318. response += "To: ".concat(to, "\r\n");
  21319. response += "From: ".concat(message.getHeader('From'), "\r\n");
  21320. response += "Call-ID: ".concat(message.call_id, "\r\n");
  21321. response += "CSeq: ".concat(message.cseq, " ").concat(message.method, "\r\n");
  21322. response += '\r\n';
  21323. transport.send(response);
  21324. }
  21325. },{"./Constants":2,"./SIPMessage":19,"./Utils":26,"debug":30}],29:[function(require,module,exports){
  21326. // Copyright Joyent, Inc. and other Node contributors.
  21327. //
  21328. // Permission is hereby granted, free of charge, to any person obtaining a
  21329. // copy of this software and associated documentation files (the
  21330. // "Software"), to deal in the Software without restriction, including
  21331. // without limitation the rights to use, copy, modify, merge, publish,
  21332. // distribute, sublicense, and/or sell copies of the Software, and to permit
  21333. // persons to whom the Software is furnished to do so, subject to the
  21334. // following conditions:
  21335. //
  21336. // The above copyright notice and this permission notice shall be included
  21337. // in all copies or substantial portions of the Software.
  21338. //
  21339. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21340. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21341. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  21342. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  21343. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21344. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21345. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  21346. var objectCreate = Object.create || objectCreatePolyfill
  21347. var objectKeys = Object.keys || objectKeysPolyfill
  21348. var bind = Function.prototype.bind || functionBindPolyfill
  21349. function EventEmitter() {
  21350. if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
  21351. this._events = objectCreate(null);
  21352. this._eventsCount = 0;
  21353. }
  21354. this._maxListeners = this._maxListeners || undefined;
  21355. }
  21356. module.exports = EventEmitter;
  21357. // Backwards-compat with node 0.10.x
  21358. EventEmitter.EventEmitter = EventEmitter;
  21359. EventEmitter.prototype._events = undefined;
  21360. EventEmitter.prototype._maxListeners = undefined;
  21361. // By default EventEmitters will print a warning if more than 10 listeners are
  21362. // added to it. This is a useful default which helps finding memory leaks.
  21363. var defaultMaxListeners = 10;
  21364. var hasDefineProperty;
  21365. try {
  21366. var o = {};
  21367. if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
  21368. hasDefineProperty = o.x === 0;
  21369. } catch (err) { hasDefineProperty = false }
  21370. if (hasDefineProperty) {
  21371. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  21372. enumerable: true,
  21373. get: function() {
  21374. return defaultMaxListeners;
  21375. },
  21376. set: function(arg) {
  21377. // check whether the input is a positive number (whose value is zero or
  21378. // greater and not a NaN).
  21379. if (typeof arg !== 'number' || arg < 0 || arg !== arg)
  21380. throw new TypeError('"defaultMaxListeners" must be a positive number');
  21381. defaultMaxListeners = arg;
  21382. }
  21383. });
  21384. } else {
  21385. EventEmitter.defaultMaxListeners = defaultMaxListeners;
  21386. }
  21387. // Obviously not all Emitters should be limited to 10. This function allows
  21388. // that to be increased. Set to zero for unlimited.
  21389. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  21390. if (typeof n !== 'number' || n < 0 || isNaN(n))
  21391. throw new TypeError('"n" argument must be a positive number');
  21392. this._maxListeners = n;
  21393. return this;
  21394. };
  21395. function $getMaxListeners(that) {
  21396. if (that._maxListeners === undefined)
  21397. return EventEmitter.defaultMaxListeners;
  21398. return that._maxListeners;
  21399. }
  21400. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  21401. return $getMaxListeners(this);
  21402. };
  21403. // These standalone emit* functions are used to optimize calling of event
  21404. // handlers for fast cases because emit() itself often has a variable number of
  21405. // arguments and can be deoptimized because of that. These functions always have
  21406. // the same number of arguments and thus do not get deoptimized, so the code
  21407. // inside them can execute faster.
  21408. function emitNone(handler, isFn, self) {
  21409. if (isFn)
  21410. handler.call(self);
  21411. else {
  21412. var len = handler.length;
  21413. var listeners = arrayClone(handler, len);
  21414. for (var i = 0; i < len; ++i)
  21415. listeners[i].call(self);
  21416. }
  21417. }
  21418. function emitOne(handler, isFn, self, arg1) {
  21419. if (isFn)
  21420. handler.call(self, arg1);
  21421. else {
  21422. var len = handler.length;
  21423. var listeners = arrayClone(handler, len);
  21424. for (var i = 0; i < len; ++i)
  21425. listeners[i].call(self, arg1);
  21426. }
  21427. }
  21428. function emitTwo(handler, isFn, self, arg1, arg2) {
  21429. if (isFn)
  21430. handler.call(self, arg1, arg2);
  21431. else {
  21432. var len = handler.length;
  21433. var listeners = arrayClone(handler, len);
  21434. for (var i = 0; i < len; ++i)
  21435. listeners[i].call(self, arg1, arg2);
  21436. }
  21437. }
  21438. function emitThree(handler, isFn, self, arg1, arg2, arg3) {
  21439. if (isFn)
  21440. handler.call(self, arg1, arg2, arg3);
  21441. else {
  21442. var len = handler.length;
  21443. var listeners = arrayClone(handler, len);
  21444. for (var i = 0; i < len; ++i)
  21445. listeners[i].call(self, arg1, arg2, arg3);
  21446. }
  21447. }
  21448. function emitMany(handler, isFn, self, args) {
  21449. if (isFn)
  21450. handler.apply(self, args);
  21451. else {
  21452. var len = handler.length;
  21453. var listeners = arrayClone(handler, len);
  21454. for (var i = 0; i < len; ++i)
  21455. listeners[i].apply(self, args);
  21456. }
  21457. }
  21458. EventEmitter.prototype.emit = function emit(type) {
  21459. var er, handler, len, args, i, events;
  21460. var doError = (type === 'error');
  21461. events = this._events;
  21462. if (events)
  21463. doError = (doError && events.error == null);
  21464. else if (!doError)
  21465. return false;
  21466. // If there is no 'error' event listener then throw.
  21467. if (doError) {
  21468. if (arguments.length > 1)
  21469. er = arguments[1];
  21470. if (er instanceof Error) {
  21471. throw er; // Unhandled 'error' event
  21472. } else {
  21473. // At least give some kind of context to the user
  21474. var err = new Error('Unhandled "error" event. (' + er + ')');
  21475. err.context = er;
  21476. throw err;
  21477. }
  21478. return false;
  21479. }
  21480. handler = events[type];
  21481. if (!handler)
  21482. return false;
  21483. var isFn = typeof handler === 'function';
  21484. len = arguments.length;
  21485. switch (len) {
  21486. // fast cases
  21487. case 1:
  21488. emitNone(handler, isFn, this);
  21489. break;
  21490. case 2:
  21491. emitOne(handler, isFn, this, arguments[1]);
  21492. break;
  21493. case 3:
  21494. emitTwo(handler, isFn, this, arguments[1], arguments[2]);
  21495. break;
  21496. case 4:
  21497. emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
  21498. break;
  21499. // slower
  21500. default:
  21501. args = new Array(len - 1);
  21502. for (i = 1; i < len; i++)
  21503. args[i - 1] = arguments[i];
  21504. emitMany(handler, isFn, this, args);
  21505. }
  21506. return true;
  21507. };
  21508. function _addListener(target, type, listener, prepend) {
  21509. var m;
  21510. var events;
  21511. var existing;
  21512. if (typeof listener !== 'function')
  21513. throw new TypeError('"listener" argument must be a function');
  21514. events = target._events;
  21515. if (!events) {
  21516. events = target._events = objectCreate(null);
  21517. target._eventsCount = 0;
  21518. } else {
  21519. // To avoid recursion in the case that type === "newListener"! Before
  21520. // adding it to the listeners, first emit "newListener".
  21521. if (events.newListener) {
  21522. target.emit('newListener', type,
  21523. listener.listener ? listener.listener : listener);
  21524. // Re-assign `events` because a newListener handler could have caused the
  21525. // this._events to be assigned to a new object
  21526. events = target._events;
  21527. }
  21528. existing = events[type];
  21529. }
  21530. if (!existing) {
  21531. // Optimize the case of one listener. Don't need the extra array object.
  21532. existing = events[type] = listener;
  21533. ++target._eventsCount;
  21534. } else {
  21535. if (typeof existing === 'function') {
  21536. // Adding the second element, need to change to array.
  21537. existing = events[type] =
  21538. prepend ? [listener, existing] : [existing, listener];
  21539. } else {
  21540. // If we've already got an array, just append.
  21541. if (prepend) {
  21542. existing.unshift(listener);
  21543. } else {
  21544. existing.push(listener);
  21545. }
  21546. }
  21547. // Check for listener leak
  21548. if (!existing.warned) {
  21549. m = $getMaxListeners(target);
  21550. if (m && m > 0 && existing.length > m) {
  21551. existing.warned = true;
  21552. var w = new Error('Possible EventEmitter memory leak detected. ' +
  21553. existing.length + ' "' + String(type) + '" listeners ' +
  21554. 'added. Use emitter.setMaxListeners() to ' +
  21555. 'increase limit.');
  21556. w.name = 'MaxListenersExceededWarning';
  21557. w.emitter = target;
  21558. w.type = type;
  21559. w.count = existing.length;
  21560. if (typeof console === 'object' && console.warn) {
  21561. console.warn('%s: %s', w.name, w.message);
  21562. }
  21563. }
  21564. }
  21565. }
  21566. return target;
  21567. }
  21568. EventEmitter.prototype.addListener = function addListener(type, listener) {
  21569. return _addListener(this, type, listener, false);
  21570. };
  21571. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  21572. EventEmitter.prototype.prependListener =
  21573. function prependListener(type, listener) {
  21574. return _addListener(this, type, listener, true);
  21575. };
  21576. function onceWrapper() {
  21577. if (!this.fired) {
  21578. this.target.removeListener(this.type, this.wrapFn);
  21579. this.fired = true;
  21580. switch (arguments.length) {
  21581. case 0:
  21582. return this.listener.call(this.target);
  21583. case 1:
  21584. return this.listener.call(this.target, arguments[0]);
  21585. case 2:
  21586. return this.listener.call(this.target, arguments[0], arguments[1]);
  21587. case 3:
  21588. return this.listener.call(this.target, arguments[0], arguments[1],
  21589. arguments[2]);
  21590. default:
  21591. var args = new Array(arguments.length);
  21592. for (var i = 0; i < args.length; ++i)
  21593. args[i] = arguments[i];
  21594. this.listener.apply(this.target, args);
  21595. }
  21596. }
  21597. }
  21598. function _onceWrap(target, type, listener) {
  21599. var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  21600. var wrapped = bind.call(onceWrapper, state);
  21601. wrapped.listener = listener;
  21602. state.wrapFn = wrapped;
  21603. return wrapped;
  21604. }
  21605. EventEmitter.prototype.once = function once(type, listener) {
  21606. if (typeof listener !== 'function')
  21607. throw new TypeError('"listener" argument must be a function');
  21608. this.on(type, _onceWrap(this, type, listener));
  21609. return this;
  21610. };
  21611. EventEmitter.prototype.prependOnceListener =
  21612. function prependOnceListener(type, listener) {
  21613. if (typeof listener !== 'function')
  21614. throw new TypeError('"listener" argument must be a function');
  21615. this.prependListener(type, _onceWrap(this, type, listener));
  21616. return this;
  21617. };
  21618. // Emits a 'removeListener' event if and only if the listener was removed.
  21619. EventEmitter.prototype.removeListener =
  21620. function removeListener(type, listener) {
  21621. var list, events, position, i, originalListener;
  21622. if (typeof listener !== 'function')
  21623. throw new TypeError('"listener" argument must be a function');
  21624. events = this._events;
  21625. if (!events)
  21626. return this;
  21627. list = events[type];
  21628. if (!list)
  21629. return this;
  21630. if (list === listener || list.listener === listener) {
  21631. if (--this._eventsCount === 0)
  21632. this._events = objectCreate(null);
  21633. else {
  21634. delete events[type];
  21635. if (events.removeListener)
  21636. this.emit('removeListener', type, list.listener || listener);
  21637. }
  21638. } else if (typeof list !== 'function') {
  21639. position = -1;
  21640. for (i = list.length - 1; i >= 0; i--) {
  21641. if (list[i] === listener || list[i].listener === listener) {
  21642. originalListener = list[i].listener;
  21643. position = i;
  21644. break;
  21645. }
  21646. }
  21647. if (position < 0)
  21648. return this;
  21649. if (position === 0)
  21650. list.shift();
  21651. else
  21652. spliceOne(list, position);
  21653. if (list.length === 1)
  21654. events[type] = list[0];
  21655. if (events.removeListener)
  21656. this.emit('removeListener', type, originalListener || listener);
  21657. }
  21658. return this;
  21659. };
  21660. EventEmitter.prototype.removeAllListeners =
  21661. function removeAllListeners(type) {
  21662. var listeners, events, i;
  21663. events = this._events;
  21664. if (!events)
  21665. return this;
  21666. // not listening for removeListener, no need to emit
  21667. if (!events.removeListener) {
  21668. if (arguments.length === 0) {
  21669. this._events = objectCreate(null);
  21670. this._eventsCount = 0;
  21671. } else if (events[type]) {
  21672. if (--this._eventsCount === 0)
  21673. this._events = objectCreate(null);
  21674. else
  21675. delete events[type];
  21676. }
  21677. return this;
  21678. }
  21679. // emit removeListener for all listeners on all events
  21680. if (arguments.length === 0) {
  21681. var keys = objectKeys(events);
  21682. var key;
  21683. for (i = 0; i < keys.length; ++i) {
  21684. key = keys[i];
  21685. if (key === 'removeListener') continue;
  21686. this.removeAllListeners(key);
  21687. }
  21688. this.removeAllListeners('removeListener');
  21689. this._events = objectCreate(null);
  21690. this._eventsCount = 0;
  21691. return this;
  21692. }
  21693. listeners = events[type];
  21694. if (typeof listeners === 'function') {
  21695. this.removeListener(type, listeners);
  21696. } else if (listeners) {
  21697. // LIFO order
  21698. for (i = listeners.length - 1; i >= 0; i--) {
  21699. this.removeListener(type, listeners[i]);
  21700. }
  21701. }
  21702. return this;
  21703. };
  21704. function _listeners(target, type, unwrap) {
  21705. var events = target._events;
  21706. if (!events)
  21707. return [];
  21708. var evlistener = events[type];
  21709. if (!evlistener)
  21710. return [];
  21711. if (typeof evlistener === 'function')
  21712. return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  21713. return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  21714. }
  21715. EventEmitter.prototype.listeners = function listeners(type) {
  21716. return _listeners(this, type, true);
  21717. };
  21718. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  21719. return _listeners(this, type, false);
  21720. };
  21721. EventEmitter.listenerCount = function(emitter, type) {
  21722. if (typeof emitter.listenerCount === 'function') {
  21723. return emitter.listenerCount(type);
  21724. } else {
  21725. return listenerCount.call(emitter, type);
  21726. }
  21727. };
  21728. EventEmitter.prototype.listenerCount = listenerCount;
  21729. function listenerCount(type) {
  21730. var events = this._events;
  21731. if (events) {
  21732. var evlistener = events[type];
  21733. if (typeof evlistener === 'function') {
  21734. return 1;
  21735. } else if (evlistener) {
  21736. return evlistener.length;
  21737. }
  21738. }
  21739. return 0;
  21740. }
  21741. EventEmitter.prototype.eventNames = function eventNames() {
  21742. return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
  21743. };
  21744. // About 1.5x faster than the two-arg version of Array#splice().
  21745. function spliceOne(list, index) {
  21746. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
  21747. list[i] = list[k];
  21748. list.pop();
  21749. }
  21750. function arrayClone(arr, n) {
  21751. var copy = new Array(n);
  21752. for (var i = 0; i < n; ++i)
  21753. copy[i] = arr[i];
  21754. return copy;
  21755. }
  21756. function unwrapListeners(arr) {
  21757. var ret = new Array(arr.length);
  21758. for (var i = 0; i < ret.length; ++i) {
  21759. ret[i] = arr[i].listener || arr[i];
  21760. }
  21761. return ret;
  21762. }
  21763. function objectCreatePolyfill(proto) {
  21764. var F = function() {};
  21765. F.prototype = proto;
  21766. return new F;
  21767. }
  21768. function objectKeysPolyfill(obj) {
  21769. var keys = [];
  21770. for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
  21771. keys.push(k);
  21772. }
  21773. return k;
  21774. }
  21775. function functionBindPolyfill(context) {
  21776. var fn = this;
  21777. return function () {
  21778. return fn.apply(context, arguments);
  21779. };
  21780. }
  21781. },{}],30:[function(require,module,exports){
  21782. (function (process){
  21783. /* eslint-env browser */
  21784. /**
  21785. * This is the web browser implementation of `debug()`.
  21786. */
  21787. exports.log = log;
  21788. exports.formatArgs = formatArgs;
  21789. exports.save = save;
  21790. exports.load = load;
  21791. exports.useColors = useColors;
  21792. exports.storage = localstorage();
  21793. /**
  21794. * Colors.
  21795. */
  21796. exports.colors = [
  21797. '#0000CC',
  21798. '#0000FF',
  21799. '#0033CC',
  21800. '#0033FF',
  21801. '#0066CC',
  21802. '#0066FF',
  21803. '#0099CC',
  21804. '#0099FF',
  21805. '#00CC00',
  21806. '#00CC33',
  21807. '#00CC66',
  21808. '#00CC99',
  21809. '#00CCCC',
  21810. '#00CCFF',
  21811. '#3300CC',
  21812. '#3300FF',
  21813. '#3333CC',
  21814. '#3333FF',
  21815. '#3366CC',
  21816. '#3366FF',
  21817. '#3399CC',
  21818. '#3399FF',
  21819. '#33CC00',
  21820. '#33CC33',
  21821. '#33CC66',
  21822. '#33CC99',
  21823. '#33CCCC',
  21824. '#33CCFF',
  21825. '#6600CC',
  21826. '#6600FF',
  21827. '#6633CC',
  21828. '#6633FF',
  21829. '#66CC00',
  21830. '#66CC33',
  21831. '#9900CC',
  21832. '#9900FF',
  21833. '#9933CC',
  21834. '#9933FF',
  21835. '#99CC00',
  21836. '#99CC33',
  21837. '#CC0000',
  21838. '#CC0033',
  21839. '#CC0066',
  21840. '#CC0099',
  21841. '#CC00CC',
  21842. '#CC00FF',
  21843. '#CC3300',
  21844. '#CC3333',
  21845. '#CC3366',
  21846. '#CC3399',
  21847. '#CC33CC',
  21848. '#CC33FF',
  21849. '#CC6600',
  21850. '#CC6633',
  21851. '#CC9900',
  21852. '#CC9933',
  21853. '#CCCC00',
  21854. '#CCCC33',
  21855. '#FF0000',
  21856. '#FF0033',
  21857. '#FF0066',
  21858. '#FF0099',
  21859. '#FF00CC',
  21860. '#FF00FF',
  21861. '#FF3300',
  21862. '#FF3333',
  21863. '#FF3366',
  21864. '#FF3399',
  21865. '#FF33CC',
  21866. '#FF33FF',
  21867. '#FF6600',
  21868. '#FF6633',
  21869. '#FF9900',
  21870. '#FF9933',
  21871. '#FFCC00',
  21872. '#FFCC33'
  21873. ];
  21874. /**
  21875. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  21876. * and the Firebug extension (any Firefox version) are known
  21877. * to support "%c" CSS customizations.
  21878. *
  21879. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  21880. */
  21881. // eslint-disable-next-line complexity
  21882. function useColors() {
  21883. // NB: In an Electron preload script, document will be defined but not fully
  21884. // initialized. Since we know we're in Chrome, we'll just detect this case
  21885. // explicitly
  21886. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  21887. return true;
  21888. }
  21889. // Internet Explorer and Edge do not support colors.
  21890. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  21891. return false;
  21892. }
  21893. // Is webkit? http://stackoverflow.com/a/16459606/376773
  21894. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  21895. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  21896. // Is firebug? http://stackoverflow.com/a/398120/376773
  21897. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  21898. // Is firefox >= v31?
  21899. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  21900. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  21901. // Double check webkit in userAgent just in case we are in a worker
  21902. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  21903. }
  21904. /**
  21905. * Colorize log arguments if enabled.
  21906. *
  21907. * @api public
  21908. */
  21909. function formatArgs(args) {
  21910. args[0] = (this.useColors ? '%c' : '') +
  21911. this.namespace +
  21912. (this.useColors ? ' %c' : ' ') +
  21913. args[0] +
  21914. (this.useColors ? '%c ' : ' ') +
  21915. '+' + module.exports.humanize(this.diff);
  21916. if (!this.useColors) {
  21917. return;
  21918. }
  21919. const c = 'color: ' + this.color;
  21920. args.splice(1, 0, c, 'color: inherit');
  21921. // The final "%c" is somewhat tricky, because there could be other
  21922. // arguments passed either before or after the %c, so we need to
  21923. // figure out the correct index to insert the CSS into
  21924. let index = 0;
  21925. let lastC = 0;
  21926. args[0].replace(/%[a-zA-Z%]/g, match => {
  21927. if (match === '%%') {
  21928. return;
  21929. }
  21930. index++;
  21931. if (match === '%c') {
  21932. // We only are interested in the *last* %c
  21933. // (the user may have provided their own)
  21934. lastC = index;
  21935. }
  21936. });
  21937. args.splice(lastC, 0, c);
  21938. }
  21939. /**
  21940. * Invokes `console.log()` when available.
  21941. * No-op when `console.log` is not a "function".
  21942. *
  21943. * @api public
  21944. */
  21945. function log(...args) {
  21946. // This hackery is required for IE8/9, where
  21947. // the `console.log` function doesn't have 'apply'
  21948. return typeof console === 'object' &&
  21949. console.log &&
  21950. console.log(...args);
  21951. }
  21952. /**
  21953. * Save `namespaces`.
  21954. *
  21955. * @param {String} namespaces
  21956. * @api private
  21957. */
  21958. function save(namespaces) {
  21959. try {
  21960. if (namespaces) {
  21961. exports.storage.setItem('debug', namespaces);
  21962. } else {
  21963. exports.storage.removeItem('debug');
  21964. }
  21965. } catch (error) {
  21966. // Swallow
  21967. // XXX (@Qix-) should we be logging these?
  21968. }
  21969. }
  21970. /**
  21971. * Load `namespaces`.
  21972. *
  21973. * @return {String} returns the previously persisted debug modes
  21974. * @api private
  21975. */
  21976. function load() {
  21977. let r;
  21978. try {
  21979. r = exports.storage.getItem('debug');
  21980. } catch (error) {
  21981. // Swallow
  21982. // XXX (@Qix-) should we be logging these?
  21983. }
  21984. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  21985. if (!r && typeof process !== 'undefined' && 'env' in process) {
  21986. r = process.env.DEBUG;
  21987. }
  21988. return r;
  21989. }
  21990. /**
  21991. * Localstorage attempts to return the localstorage.
  21992. *
  21993. * This is necessary because safari throws
  21994. * when a user disables cookies/localstorage
  21995. * and you attempt to access it.
  21996. *
  21997. * @return {LocalStorage}
  21998. * @api private
  21999. */
  22000. function localstorage() {
  22001. try {
  22002. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  22003. // The Browser also has localStorage in the global context.
  22004. return localStorage;
  22005. } catch (error) {
  22006. // Swallow
  22007. // XXX (@Qix-) should we be logging these?
  22008. }
  22009. }
  22010. module.exports = require('./common')(exports);
  22011. const {formatters} = module.exports;
  22012. /**
  22013. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  22014. */
  22015. formatters.j = function (v) {
  22016. try {
  22017. return JSON.stringify(v);
  22018. } catch (error) {
  22019. return '[UnexpectedJSONParseError]: ' + error.message;
  22020. }
  22021. };
  22022. }).call(this,require('_process'))
  22023. },{"./common":31,"_process":33}],31:[function(require,module,exports){
  22024. /**
  22025. * This is the common logic for both the Node.js and web browser
  22026. * implementations of `debug()`.
  22027. */
  22028. function setup(env) {
  22029. createDebug.debug = createDebug;
  22030. createDebug.default = createDebug;
  22031. createDebug.coerce = coerce;
  22032. createDebug.disable = disable;
  22033. createDebug.enable = enable;
  22034. createDebug.enabled = enabled;
  22035. createDebug.humanize = require('ms');
  22036. Object.keys(env).forEach(key => {
  22037. createDebug[key] = env[key];
  22038. });
  22039. /**
  22040. * Active `debug` instances.
  22041. */
  22042. createDebug.instances = [];
  22043. /**
  22044. * The currently active debug mode names, and names to skip.
  22045. */
  22046. createDebug.names = [];
  22047. createDebug.skips = [];
  22048. /**
  22049. * Map of special "%n" handling functions, for the debug "format" argument.
  22050. *
  22051. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  22052. */
  22053. createDebug.formatters = {};
  22054. /**
  22055. * Selects a color for a debug namespace
  22056. * @param {String} namespace The namespace string for the for the debug instance to be colored
  22057. * @return {Number|String} An ANSI color code for the given namespace
  22058. * @api private
  22059. */
  22060. function selectColor(namespace) {
  22061. let hash = 0;
  22062. for (let i = 0; i < namespace.length; i++) {
  22063. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  22064. hash |= 0; // Convert to 32bit integer
  22065. }
  22066. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  22067. }
  22068. createDebug.selectColor = selectColor;
  22069. /**
  22070. * Create a debugger with the given `namespace`.
  22071. *
  22072. * @param {String} namespace
  22073. * @return {Function}
  22074. * @api public
  22075. */
  22076. function createDebug(namespace) {
  22077. let prevTime;
  22078. function debug(...args) {
  22079. // Disabled?
  22080. if (!debug.enabled) {
  22081. return;
  22082. }
  22083. const self = debug;
  22084. // Set `diff` timestamp
  22085. const curr = Number(new Date());
  22086. const ms = curr - (prevTime || curr);
  22087. self.diff = ms;
  22088. self.prev = prevTime;
  22089. self.curr = curr;
  22090. prevTime = curr;
  22091. args[0] = createDebug.coerce(args[0]);
  22092. if (typeof args[0] !== 'string') {
  22093. // Anything else let's inspect with %O
  22094. args.unshift('%O');
  22095. }
  22096. // Apply any `formatters` transformations
  22097. let index = 0;
  22098. args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
  22099. // If we encounter an escaped % then don't increase the array index
  22100. if (match === '%%') {
  22101. return match;
  22102. }
  22103. index++;
  22104. const formatter = createDebug.formatters[format];
  22105. if (typeof formatter === 'function') {
  22106. const val = args[index];
  22107. match = formatter.call(self, val);
  22108. // Now we need to remove `args[index]` since it's inlined in the `format`
  22109. args.splice(index, 1);
  22110. index--;
  22111. }
  22112. return match;
  22113. });
  22114. // Apply env-specific formatting (colors, etc.)
  22115. createDebug.formatArgs.call(self, args);
  22116. const logFn = self.log || createDebug.log;
  22117. logFn.apply(self, args);
  22118. }
  22119. debug.namespace = namespace;
  22120. debug.enabled = createDebug.enabled(namespace);
  22121. debug.useColors = createDebug.useColors();
  22122. debug.color = selectColor(namespace);
  22123. debug.destroy = destroy;
  22124. debug.extend = extend;
  22125. // Debug.formatArgs = formatArgs;
  22126. // debug.rawLog = rawLog;
  22127. // env-specific initialization logic for debug instances
  22128. if (typeof createDebug.init === 'function') {
  22129. createDebug.init(debug);
  22130. }
  22131. createDebug.instances.push(debug);
  22132. return debug;
  22133. }
  22134. function destroy() {
  22135. const index = createDebug.instances.indexOf(this);
  22136. if (index !== -1) {
  22137. createDebug.instances.splice(index, 1);
  22138. return true;
  22139. }
  22140. return false;
  22141. }
  22142. function extend(namespace, delimiter) {
  22143. return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  22144. }
  22145. /**
  22146. * Enables a debug mode by namespaces. This can include modes
  22147. * separated by a colon and wildcards.
  22148. *
  22149. * @param {String} namespaces
  22150. * @api public
  22151. */
  22152. function enable(namespaces) {
  22153. createDebug.save(namespaces);
  22154. createDebug.names = [];
  22155. createDebug.skips = [];
  22156. let i;
  22157. const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  22158. const len = split.length;
  22159. for (i = 0; i < len; i++) {
  22160. if (!split[i]) {
  22161. // ignore empty strings
  22162. continue;
  22163. }
  22164. namespaces = split[i].replace(/\*/g, '.*?');
  22165. if (namespaces[0] === '-') {
  22166. createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  22167. } else {
  22168. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  22169. }
  22170. }
  22171. for (i = 0; i < createDebug.instances.length; i++) {
  22172. const instance = createDebug.instances[i];
  22173. instance.enabled = createDebug.enabled(instance.namespace);
  22174. }
  22175. }
  22176. /**
  22177. * Disable debug output.
  22178. *
  22179. * @return {String} namespaces
  22180. * @api public
  22181. */
  22182. function disable() {
  22183. const namespaces = [
  22184. ...createDebug.names.map(toNamespace),
  22185. ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
  22186. ].join(',');
  22187. createDebug.enable('');
  22188. return namespaces;
  22189. }
  22190. /**
  22191. * Returns true if the given mode name is enabled, false otherwise.
  22192. *
  22193. * @param {String} name
  22194. * @return {Boolean}
  22195. * @api public
  22196. */
  22197. function enabled(name) {
  22198. if (name[name.length - 1] === '*') {
  22199. return true;
  22200. }
  22201. let i;
  22202. let len;
  22203. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  22204. if (createDebug.skips[i].test(name)) {
  22205. return false;
  22206. }
  22207. }
  22208. for (i = 0, len = createDebug.names.length; i < len; i++) {
  22209. if (createDebug.names[i].test(name)) {
  22210. return true;
  22211. }
  22212. }
  22213. return false;
  22214. }
  22215. /**
  22216. * Convert regexp to namespace
  22217. *
  22218. * @param {RegExp} regxep
  22219. * @return {String} namespace
  22220. * @api private
  22221. */
  22222. function toNamespace(regexp) {
  22223. return regexp.toString()
  22224. .substring(2, regexp.toString().length - 2)
  22225. .replace(/\.\*\?$/, '*');
  22226. }
  22227. /**
  22228. * Coerce `val`.
  22229. *
  22230. * @param {Mixed} val
  22231. * @return {Mixed}
  22232. * @api private
  22233. */
  22234. function coerce(val) {
  22235. if (val instanceof Error) {
  22236. return val.stack || val.message;
  22237. }
  22238. return val;
  22239. }
  22240. createDebug.enable(createDebug.load());
  22241. return createDebug;
  22242. }
  22243. module.exports = setup;
  22244. },{"ms":32}],32:[function(require,module,exports){
  22245. /**
  22246. * Helpers.
  22247. */
  22248. var s = 1000;
  22249. var m = s * 60;
  22250. var h = m * 60;
  22251. var d = h * 24;
  22252. var w = d * 7;
  22253. var y = d * 365.25;
  22254. /**
  22255. * Parse or format the given `val`.
  22256. *
  22257. * Options:
  22258. *
  22259. * - `long` verbose formatting [false]
  22260. *
  22261. * @param {String|Number} val
  22262. * @param {Object} [options]
  22263. * @throws {Error} throw an error if val is not a non-empty string or a number
  22264. * @return {String|Number}
  22265. * @api public
  22266. */
  22267. module.exports = function(val, options) {
  22268. options = options || {};
  22269. var type = typeof val;
  22270. if (type === 'string' && val.length > 0) {
  22271. return parse(val);
  22272. } else if (type === 'number' && isNaN(val) === false) {
  22273. return options.long ? fmtLong(val) : fmtShort(val);
  22274. }
  22275. throw new Error(
  22276. 'val is not a non-empty string or a valid number. val=' +
  22277. JSON.stringify(val)
  22278. );
  22279. };
  22280. /**
  22281. * Parse the given `str` and return milliseconds.
  22282. *
  22283. * @param {String} str
  22284. * @return {Number}
  22285. * @api private
  22286. */
  22287. function parse(str) {
  22288. str = String(str);
  22289. if (str.length > 100) {
  22290. return;
  22291. }
  22292. var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
  22293. str
  22294. );
  22295. if (!match) {
  22296. return;
  22297. }
  22298. var n = parseFloat(match[1]);
  22299. var type = (match[2] || 'ms').toLowerCase();
  22300. switch (type) {
  22301. case 'years':
  22302. case 'year':
  22303. case 'yrs':
  22304. case 'yr':
  22305. case 'y':
  22306. return n * y;
  22307. case 'weeks':
  22308. case 'week':
  22309. case 'w':
  22310. return n * w;
  22311. case 'days':
  22312. case 'day':
  22313. case 'd':
  22314. return n * d;
  22315. case 'hours':
  22316. case 'hour':
  22317. case 'hrs':
  22318. case 'hr':
  22319. case 'h':
  22320. return n * h;
  22321. case 'minutes':
  22322. case 'minute':
  22323. case 'mins':
  22324. case 'min':
  22325. case 'm':
  22326. return n * m;
  22327. case 'seconds':
  22328. case 'second':
  22329. case 'secs':
  22330. case 'sec':
  22331. case 's':
  22332. return n * s;
  22333. case 'milliseconds':
  22334. case 'millisecond':
  22335. case 'msecs':
  22336. case 'msec':
  22337. case 'ms':
  22338. return n;
  22339. default:
  22340. return undefined;
  22341. }
  22342. }
  22343. /**
  22344. * Short format for `ms`.
  22345. *
  22346. * @param {Number} ms
  22347. * @return {String}
  22348. * @api private
  22349. */
  22350. function fmtShort(ms) {
  22351. var msAbs = Math.abs(ms);
  22352. if (msAbs >= d) {
  22353. return Math.round(ms / d) + 'd';
  22354. }
  22355. if (msAbs >= h) {
  22356. return Math.round(ms / h) + 'h';
  22357. }
  22358. if (msAbs >= m) {
  22359. return Math.round(ms / m) + 'm';
  22360. }
  22361. if (msAbs >= s) {
  22362. return Math.round(ms / s) + 's';
  22363. }
  22364. return ms + 'ms';
  22365. }
  22366. /**
  22367. * Long format for `ms`.
  22368. *
  22369. * @param {Number} ms
  22370. * @return {String}
  22371. * @api private
  22372. */
  22373. function fmtLong(ms) {
  22374. var msAbs = Math.abs(ms);
  22375. if (msAbs >= d) {
  22376. return plural(ms, msAbs, d, 'day');
  22377. }
  22378. if (msAbs >= h) {
  22379. return plural(ms, msAbs, h, 'hour');
  22380. }
  22381. if (msAbs >= m) {
  22382. return plural(ms, msAbs, m, 'minute');
  22383. }
  22384. if (msAbs >= s) {
  22385. return plural(ms, msAbs, s, 'second');
  22386. }
  22387. return ms + ' ms';
  22388. }
  22389. /**
  22390. * Pluralization helper.
  22391. */
  22392. function plural(ms, msAbs, n, name) {
  22393. var isPlural = msAbs >= n * 1.5;
  22394. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  22395. }
  22396. },{}],33:[function(require,module,exports){
  22397. // shim for using process in browser
  22398. var process = module.exports = {};
  22399. // cached from whatever global is present so that test runners that stub it
  22400. // don't break things. But we need to wrap it in a try catch in case it is
  22401. // wrapped in strict mode code which doesn't define any globals. It's inside a
  22402. // function because try/catches deoptimize in certain engines.
  22403. var cachedSetTimeout;
  22404. var cachedClearTimeout;
  22405. function defaultSetTimout() {
  22406. throw new Error('setTimeout has not been defined');
  22407. }
  22408. function defaultClearTimeout () {
  22409. throw new Error('clearTimeout has not been defined');
  22410. }
  22411. (function () {
  22412. try {
  22413. if (typeof setTimeout === 'function') {
  22414. cachedSetTimeout = setTimeout;
  22415. } else {
  22416. cachedSetTimeout = defaultSetTimout;
  22417. }
  22418. } catch (e) {
  22419. cachedSetTimeout = defaultSetTimout;
  22420. }
  22421. try {
  22422. if (typeof clearTimeout === 'function') {
  22423. cachedClearTimeout = clearTimeout;
  22424. } else {
  22425. cachedClearTimeout = defaultClearTimeout;
  22426. }
  22427. } catch (e) {
  22428. cachedClearTimeout = defaultClearTimeout;
  22429. }
  22430. } ())
  22431. function runTimeout(fun) {
  22432. if (cachedSetTimeout === setTimeout) {
  22433. //normal enviroments in sane situations
  22434. return setTimeout(fun, 0);
  22435. }
  22436. // if setTimeout wasn't available but was latter defined
  22437. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  22438. cachedSetTimeout = setTimeout;
  22439. return setTimeout(fun, 0);
  22440. }
  22441. try {
  22442. // when when somebody has screwed with setTimeout but no I.E. maddness
  22443. return cachedSetTimeout(fun, 0);
  22444. } catch(e){
  22445. try {
  22446. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  22447. return cachedSetTimeout.call(null, fun, 0);
  22448. } catch(e){
  22449. // 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
  22450. return cachedSetTimeout.call(this, fun, 0);
  22451. }
  22452. }
  22453. }
  22454. function runClearTimeout(marker) {
  22455. if (cachedClearTimeout === clearTimeout) {
  22456. //normal enviroments in sane situations
  22457. return clearTimeout(marker);
  22458. }
  22459. // if clearTimeout wasn't available but was latter defined
  22460. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  22461. cachedClearTimeout = clearTimeout;
  22462. return clearTimeout(marker);
  22463. }
  22464. try {
  22465. // when when somebody has screwed with setTimeout but no I.E. maddness
  22466. return cachedClearTimeout(marker);
  22467. } catch (e){
  22468. try {
  22469. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  22470. return cachedClearTimeout.call(null, marker);
  22471. } catch (e){
  22472. // 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.
  22473. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  22474. return cachedClearTimeout.call(this, marker);
  22475. }
  22476. }
  22477. }
  22478. var queue = [];
  22479. var draining = false;
  22480. var currentQueue;
  22481. var queueIndex = -1;
  22482. function cleanUpNextTick() {
  22483. if (!draining || !currentQueue) {
  22484. return;
  22485. }
  22486. draining = false;
  22487. if (currentQueue.length) {
  22488. queue = currentQueue.concat(queue);
  22489. } else {
  22490. queueIndex = -1;
  22491. }
  22492. if (queue.length) {
  22493. drainQueue();
  22494. }
  22495. }
  22496. function drainQueue() {
  22497. if (draining) {
  22498. return;
  22499. }
  22500. var timeout = runTimeout(cleanUpNextTick);
  22501. draining = true;
  22502. var len = queue.length;
  22503. while(len) {
  22504. currentQueue = queue;
  22505. queue = [];
  22506. while (++queueIndex < len) {
  22507. if (currentQueue) {
  22508. currentQueue[queueIndex].run();
  22509. }
  22510. }
  22511. queueIndex = -1;
  22512. len = queue.length;
  22513. }
  22514. currentQueue = null;
  22515. draining = false;
  22516. runClearTimeout(timeout);
  22517. }
  22518. process.nextTick = function (fun) {
  22519. var args = new Array(arguments.length - 1);
  22520. if (arguments.length > 1) {
  22521. for (var i = 1; i < arguments.length; i++) {
  22522. args[i - 1] = arguments[i];
  22523. }
  22524. }
  22525. queue.push(new Item(fun, args));
  22526. if (queue.length === 1 && !draining) {
  22527. runTimeout(drainQueue);
  22528. }
  22529. };
  22530. // v8 likes predictible objects
  22531. function Item(fun, array) {
  22532. this.fun = fun;
  22533. this.array = array;
  22534. }
  22535. Item.prototype.run = function () {
  22536. this.fun.apply(null, this.array);
  22537. };
  22538. process.title = 'browser';
  22539. process.browser = true;
  22540. process.env = {};
  22541. process.argv = [];
  22542. process.version = ''; // empty string to avoid regexp issues
  22543. process.versions = {};
  22544. function noop() {}
  22545. process.on = noop;
  22546. process.addListener = noop;
  22547. process.once = noop;
  22548. process.off = noop;
  22549. process.removeListener = noop;
  22550. process.removeAllListeners = noop;
  22551. process.emit = noop;
  22552. process.prependListener = noop;
  22553. process.prependOnceListener = noop;
  22554. process.listeners = function (name) { return [] }
  22555. process.binding = function (name) {
  22556. throw new Error('process.binding is not supported');
  22557. };
  22558. process.cwd = function () { return '/' };
  22559. process.chdir = function (dir) {
  22560. throw new Error('process.chdir is not supported');
  22561. };
  22562. process.umask = function() { return 0; };
  22563. },{}],34:[function(require,module,exports){
  22564. var grammar = module.exports = {
  22565. v: [{
  22566. name: 'version',
  22567. reg: /^(\d*)$/
  22568. }],
  22569. o: [{ //o=- 20518 0 IN IP4 203.0.113.1
  22570. // NB: sessionId will be a String in most cases because it is huge
  22571. name: 'origin',
  22572. reg: /^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,
  22573. names: ['username', 'sessionId', 'sessionVersion', 'netType', 'ipVer', 'address'],
  22574. format: '%s %s %d %s IP%d %s'
  22575. }],
  22576. // default parsing of these only (though some of these feel outdated)
  22577. s: [{ name: 'name' }],
  22578. i: [{ name: 'description' }],
  22579. u: [{ name: 'uri' }],
  22580. e: [{ name: 'email' }],
  22581. p: [{ name: 'phone' }],
  22582. z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly..
  22583. r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly
  22584. //k: [{}], // outdated thing ignored
  22585. t: [{ //t=0 0
  22586. name: 'timing',
  22587. reg: /^(\d*) (\d*)/,
  22588. names: ['start', 'stop'],
  22589. format: '%d %d'
  22590. }],
  22591. c: [{ //c=IN IP4 10.47.197.26
  22592. name: 'connection',
  22593. reg: /^IN IP(\d) (\S*)/,
  22594. names: ['version', 'ip'],
  22595. format: 'IN IP%d %s'
  22596. }],
  22597. b: [{ //b=AS:4000
  22598. push: 'bandwidth',
  22599. reg: /^(TIAS|AS|CT|RR|RS):(\d*)/,
  22600. names: ['type', 'limit'],
  22601. format: '%s:%s'
  22602. }],
  22603. m: [{ //m=video 51744 RTP/AVP 126 97 98 34 31
  22604. // NB: special - pushes to session
  22605. // TODO: rtp/fmtp should be filtered by the payloads found here?
  22606. reg: /^(\w*) (\d*) ([\w\/]*)(?: (.*))?/,
  22607. names: ['type', 'port', 'protocol', 'payloads'],
  22608. format: '%s %d %s %s'
  22609. }],
  22610. a: [
  22611. { //a=rtpmap:110 opus/48000/2
  22612. push: 'rtp',
  22613. reg: /^rtpmap:(\d*) ([\w\-\.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,
  22614. names: ['payload', 'codec', 'rate', 'encoding'],
  22615. format: function (o) {
  22616. return (o.encoding) ?
  22617. 'rtpmap:%d %s/%s/%s':
  22618. o.rate ?
  22619. 'rtpmap:%d %s/%s':
  22620. 'rtpmap:%d %s';
  22621. }
  22622. },
  22623. { //a=fmtp:108 profile-level-id=24;object=23;bitrate=64000
  22624. //a=fmtp:111 minptime=10; useinbandfec=1
  22625. push: 'fmtp',
  22626. reg: /^fmtp:(\d*) ([\S| ]*)/,
  22627. names: ['payload', 'config'],
  22628. format: 'fmtp:%d %s'
  22629. },
  22630. { //a=control:streamid=0
  22631. name: 'control',
  22632. reg: /^control:(.*)/,
  22633. format: 'control:%s'
  22634. },
  22635. { //a=rtcp:65179 IN IP4 193.84.77.194
  22636. name: 'rtcp',
  22637. reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,
  22638. names: ['port', 'netType', 'ipVer', 'address'],
  22639. format: function (o) {
  22640. return (o.address != null) ?
  22641. 'rtcp:%d %s IP%d %s':
  22642. 'rtcp:%d';
  22643. }
  22644. },
  22645. { //a=rtcp-fb:98 trr-int 100
  22646. push: 'rtcpFbTrrInt',
  22647. reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/,
  22648. names: ['payload', 'value'],
  22649. format: 'rtcp-fb:%d trr-int %d'
  22650. },
  22651. { //a=rtcp-fb:98 nack rpsi
  22652. push: 'rtcpFb',
  22653. reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,
  22654. names: ['payload', 'type', 'subtype'],
  22655. format: function (o) {
  22656. return (o.subtype != null) ?
  22657. 'rtcp-fb:%s %s %s':
  22658. 'rtcp-fb:%s %s';
  22659. }
  22660. },
  22661. { //a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  22662. //a=extmap:1/recvonly URI-gps-string
  22663. push: 'ext',
  22664. reg: /^extmap:(\d+)(?:\/(\w+))? (\S*)(?: (\S*))?/,
  22665. names: ['value', 'direction', 'uri', 'config'],
  22666. format: function (o) {
  22667. return 'extmap:%d' + (o.direction ? '/%s' : '%v') + ' %s' + (o.config ? ' %s' : '');
  22668. }
  22669. },
  22670. { //a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32
  22671. push: 'crypto',
  22672. reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,
  22673. names: ['id', 'suite', 'config', 'sessionConfig'],
  22674. format: function (o) {
  22675. return (o.sessionConfig != null) ?
  22676. 'crypto:%d %s %s %s':
  22677. 'crypto:%d %s %s';
  22678. }
  22679. },
  22680. { //a=setup:actpass
  22681. name: 'setup',
  22682. reg: /^setup:(\w*)/,
  22683. format: 'setup:%s'
  22684. },
  22685. { //a=mid:1
  22686. name: 'mid',
  22687. reg: /^mid:([^\s]*)/,
  22688. format: 'mid:%s'
  22689. },
  22690. { //a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a
  22691. name: 'msid',
  22692. reg: /^msid:(.*)/,
  22693. format: 'msid:%s'
  22694. },
  22695. { //a=ptime:20
  22696. name: 'ptime',
  22697. reg: /^ptime:(\d*)/,
  22698. format: 'ptime:%d'
  22699. },
  22700. { //a=maxptime:60
  22701. name: 'maxptime',
  22702. reg: /^maxptime:(\d*)/,
  22703. format: 'maxptime:%d'
  22704. },
  22705. { //a=sendrecv
  22706. name: 'direction',
  22707. reg: /^(sendrecv|recvonly|sendonly|inactive)/
  22708. },
  22709. { //a=ice-lite
  22710. name: 'icelite',
  22711. reg: /^(ice-lite)/
  22712. },
  22713. { //a=ice-ufrag:F7gI
  22714. name: 'iceUfrag',
  22715. reg: /^ice-ufrag:(\S*)/,
  22716. format: 'ice-ufrag:%s'
  22717. },
  22718. { //a=ice-pwd:x9cml/YzichV2+XlhiMu8g
  22719. name: 'icePwd',
  22720. reg: /^ice-pwd:(\S*)/,
  22721. format: 'ice-pwd:%s'
  22722. },
  22723. { //a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
  22724. name: 'fingerprint',
  22725. reg: /^fingerprint:(\S*) (\S*)/,
  22726. names: ['type', 'hash'],
  22727. format: 'fingerprint:%s %s'
  22728. },
  22729. { //a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
  22730. //a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10
  22731. //a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0 network-id 3 network-cost 10
  22732. //a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10
  22733. //a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0 network-id 3 network-cost 10
  22734. push:'candidates',
  22735. reg: /^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,
  22736. names: ['foundation', 'component', 'transport', 'priority', 'ip', 'port', 'type', 'raddr', 'rport', 'tcptype', 'generation', 'network-id', 'network-cost'],
  22737. format: function (o) {
  22738. var str = 'candidate:%s %d %s %d %s %d typ %s';
  22739. str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v';
  22740. // NB: candidate has three optional chunks, so %void middles one if it's missing
  22741. str += (o.tcptype != null) ? ' tcptype %s' : '%v';
  22742. if (o.generation != null) {
  22743. str += ' generation %d';
  22744. }
  22745. str += (o['network-id'] != null) ? ' network-id %d' : '%v';
  22746. str += (o['network-cost'] != null) ? ' network-cost %d' : '%v';
  22747. return str;
  22748. }
  22749. },
  22750. { //a=end-of-candidates (keep after the candidates line for readability)
  22751. name: 'endOfCandidates',
  22752. reg: /^(end-of-candidates)/
  22753. },
  22754. { //a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ...
  22755. name: 'remoteCandidates',
  22756. reg: /^remote-candidates:(.*)/,
  22757. format: 'remote-candidates:%s'
  22758. },
  22759. { //a=ice-options:google-ice
  22760. name: 'iceOptions',
  22761. reg: /^ice-options:(\S*)/,
  22762. format: 'ice-options:%s'
  22763. },
  22764. { //a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1
  22765. push: 'ssrcs',
  22766. reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,
  22767. names: ['id', 'attribute', 'value'],
  22768. format: function (o) {
  22769. var str = 'ssrc:%d';
  22770. if (o.attribute != null) {
  22771. str += ' %s';
  22772. if (o.value != null) {
  22773. str += ':%s';
  22774. }
  22775. }
  22776. return str;
  22777. }
  22778. },
  22779. { //a=ssrc-group:FEC 1 2
  22780. //a=ssrc-group:FEC-FR 3004364195 1080772241
  22781. push: 'ssrcGroups',
  22782. // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E
  22783. reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,
  22784. names: ['semantics', 'ssrcs'],
  22785. format: 'ssrc-group:%s %s'
  22786. },
  22787. { //a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV
  22788. name: 'msidSemantic',
  22789. reg: /^msid-semantic:\s?(\w*) (\S*)/,
  22790. names: ['semantic', 'token'],
  22791. format: 'msid-semantic: %s %s' // space after ':' is not accidental
  22792. },
  22793. { //a=group:BUNDLE audio video
  22794. push: 'groups',
  22795. reg: /^group:(\w*) (.*)/,
  22796. names: ['type', 'mids'],
  22797. format: 'group:%s %s'
  22798. },
  22799. { //a=rtcp-mux
  22800. name: 'rtcpMux',
  22801. reg: /^(rtcp-mux)/
  22802. },
  22803. { //a=rtcp-rsize
  22804. name: 'rtcpRsize',
  22805. reg: /^(rtcp-rsize)/
  22806. },
  22807. { //a=sctpmap:5000 webrtc-datachannel 1024
  22808. name: 'sctpmap',
  22809. reg: /^sctpmap:([\w_\/]*) (\S*)(?: (\S*))?/,
  22810. names: ['sctpmapNumber', 'app', 'maxMessageSize'],
  22811. format: function (o) {
  22812. return (o.maxMessageSize != null) ?
  22813. 'sctpmap:%s %s %s' :
  22814. 'sctpmap:%s %s';
  22815. }
  22816. },
  22817. { //a=x-google-flag:conference
  22818. name: 'xGoogleFlag',
  22819. reg: /^x-google-flag:([^\s]*)/,
  22820. format: 'x-google-flag:%s'
  22821. },
  22822. { //a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0
  22823. push: 'rids',
  22824. reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,
  22825. names: ['id', 'direction', 'params'],
  22826. format: function (o) {
  22827. return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s';
  22828. }
  22829. },
  22830. { //a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250]
  22831. //a=imageattr:* send [x=800,y=640] recv *
  22832. //a=imageattr:100 recv [x=320,y=240]
  22833. push: 'imageattrs',
  22834. reg: new RegExp(
  22835. //a=imageattr:97
  22836. '^imageattr:(\\d+|\\*)' +
  22837. //send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320]
  22838. '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' +
  22839. //recv [x=330,y=250]
  22840. '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?'
  22841. ),
  22842. names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'],
  22843. format: function (o) {
  22844. return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : '');
  22845. }
  22846. },
  22847. { //a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8
  22848. //a=simulcast:recv 1;4,5 send 6;7
  22849. name: 'simulcast',
  22850. reg: new RegExp(
  22851. //a=simulcast:
  22852. '^simulcast:' +
  22853. //send 1,2,3;~4,~5
  22854. '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' +
  22855. //space + recv 6;~7,~8
  22856. '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' +
  22857. //end
  22858. '$'
  22859. ),
  22860. names: ['dir1', 'list1', 'dir2', 'list2'],
  22861. format: function (o) {
  22862. return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : '');
  22863. }
  22864. },
  22865. { //Old simulcast draft 03 (implemented by Firefox)
  22866. // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03
  22867. //a=simulcast: recv pt=97;98 send pt=97
  22868. //a=simulcast: send rid=5;6;7 paused=6,7
  22869. name: 'simulcast_03',
  22870. reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/,
  22871. names: ['value'],
  22872. format: 'simulcast: %s'
  22873. },
  22874. {
  22875. //a=framerate:25
  22876. //a=framerate:29.97
  22877. name: 'framerate',
  22878. reg: /^framerate:(\d+(?:$|\.\d+))/,
  22879. format: 'framerate:%s'
  22880. },
  22881. { // RFC4570
  22882. //a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5
  22883. name: 'sourceFilter',
  22884. reg: /^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,
  22885. names: ['filterMode', 'netType', 'addressTypes', 'destAddress', 'srcList'],
  22886. format: 'source-filter: %s %s %s %s %s'
  22887. },
  22888. { //a=bundle-only
  22889. name: 'bundleOnly',
  22890. reg: /^(bundle-only)/
  22891. },
  22892. { //a=label:1
  22893. name: 'label',
  22894. reg: /^label:(.+)/,
  22895. format: 'label:%s'
  22896. },
  22897. {
  22898. // RFC version 26 for SCTP over DTLS
  22899. // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5
  22900. name:'sctpPort',
  22901. reg: /^sctp-port:(\d+)$/,
  22902. format: 'sctp-port:%s'
  22903. },
  22904. {
  22905. // RFC version 26 for SCTP over DTLS
  22906. // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
  22907. name:'maxMessageSize',
  22908. reg: /^max-message-size:(\d+)$/,
  22909. format: 'max-message-size:%s'
  22910. },
  22911. { // any a= that we don't understand is kepts verbatim on media.invalid
  22912. push: 'invalid',
  22913. names: ['value']
  22914. }
  22915. ]
  22916. };
  22917. // set sensible defaults to avoid polluting the grammar with boring details
  22918. Object.keys(grammar).forEach(function (key) {
  22919. var objs = grammar[key];
  22920. objs.forEach(function (obj) {
  22921. if (!obj.reg) {
  22922. obj.reg = /(.*)/;
  22923. }
  22924. if (!obj.format) {
  22925. obj.format = '%s';
  22926. }
  22927. });
  22928. });
  22929. },{}],35:[function(require,module,exports){
  22930. var parser = require('./parser');
  22931. var writer = require('./writer');
  22932. exports.write = writer;
  22933. exports.parse = parser.parse;
  22934. exports.parseFmtpConfig = parser.parseFmtpConfig;
  22935. exports.parseParams = parser.parseParams;
  22936. exports.parsePayloads = parser.parsePayloads;
  22937. exports.parseRemoteCandidates = parser.parseRemoteCandidates;
  22938. exports.parseImageAttributes = parser.parseImageAttributes;
  22939. exports.parseSimulcastStreamList = parser.parseSimulcastStreamList;
  22940. },{"./parser":36,"./writer":37}],36:[function(require,module,exports){
  22941. var toIntIfInt = function (v) {
  22942. return String(Number(v)) === v ? Number(v) : v;
  22943. };
  22944. var attachProperties = function (match, location, names, rawName) {
  22945. if (rawName && !names) {
  22946. location[rawName] = toIntIfInt(match[1]);
  22947. }
  22948. else {
  22949. for (var i = 0; i < names.length; i += 1) {
  22950. if (match[i+1] != null) {
  22951. location[names[i]] = toIntIfInt(match[i+1]);
  22952. }
  22953. }
  22954. }
  22955. };
  22956. var parseReg = function (obj, location, content) {
  22957. var needsBlank = obj.name && obj.names;
  22958. if (obj.push && !location[obj.push]) {
  22959. location[obj.push] = [];
  22960. }
  22961. else if (needsBlank && !location[obj.name]) {
  22962. location[obj.name] = {};
  22963. }
  22964. var keyLocation = obj.push ?
  22965. {} : // blank object that will be pushed
  22966. needsBlank ? location[obj.name] : location; // otherwise, named location or root
  22967. attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name);
  22968. if (obj.push) {
  22969. location[obj.push].push(keyLocation);
  22970. }
  22971. };
  22972. var grammar = require('./grammar');
  22973. var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/);
  22974. exports.parse = function (sdp) {
  22975. var session = {}
  22976. , media = []
  22977. , location = session; // points at where properties go under (one of the above)
  22978. // parse lines we understand
  22979. sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) {
  22980. var type = l[0];
  22981. var content = l.slice(2);
  22982. if (type === 'm') {
  22983. media.push({rtp: [], fmtp: []});
  22984. location = media[media.length-1]; // point at latest media line
  22985. }
  22986. for (var j = 0; j < (grammar[type] || []).length; j += 1) {
  22987. var obj = grammar[type][j];
  22988. if (obj.reg.test(content)) {
  22989. return parseReg(obj, location, content);
  22990. }
  22991. }
  22992. });
  22993. session.media = media; // link it up
  22994. return session;
  22995. };
  22996. var paramReducer = function (acc, expr) {
  22997. var s = expr.split(/=(.+)/, 2);
  22998. if (s.length === 2) {
  22999. acc[s[0]] = toIntIfInt(s[1]);
  23000. } else if (s.length === 1 && expr.length > 1) {
  23001. acc[s[0]] = undefined;
  23002. }
  23003. return acc;
  23004. };
  23005. exports.parseParams = function (str) {
  23006. return str.split(/\;\s?/).reduce(paramReducer, {});
  23007. };
  23008. // For backward compatibility - alias will be removed in 3.0.0
  23009. exports.parseFmtpConfig = exports.parseParams;
  23010. exports.parsePayloads = function (str) {
  23011. return str.split(' ').map(Number);
  23012. };
  23013. exports.parseRemoteCandidates = function (str) {
  23014. var candidates = [];
  23015. var parts = str.split(' ').map(toIntIfInt);
  23016. for (var i = 0; i < parts.length; i += 3) {
  23017. candidates.push({
  23018. component: parts[i],
  23019. ip: parts[i + 1],
  23020. port: parts[i + 2]
  23021. });
  23022. }
  23023. return candidates;
  23024. };
  23025. exports.parseImageAttributes = function (str) {
  23026. return str.split(' ').map(function (item) {
  23027. return item.substring(1, item.length-1).split(',').reduce(paramReducer, {});
  23028. });
  23029. };
  23030. exports.parseSimulcastStreamList = function (str) {
  23031. return str.split(';').map(function (stream) {
  23032. return stream.split(',').map(function (format) {
  23033. var scid, paused = false;
  23034. if (format[0] !== '~') {
  23035. scid = toIntIfInt(format);
  23036. } else {
  23037. scid = toIntIfInt(format.substring(1, format.length));
  23038. paused = true;
  23039. }
  23040. return {
  23041. scid: scid,
  23042. paused: paused
  23043. };
  23044. });
  23045. });
  23046. };
  23047. },{"./grammar":34}],37:[function(require,module,exports){
  23048. var grammar = require('./grammar');
  23049. // customized util.format - discards excess arguments and can void middle ones
  23050. var formatRegExp = /%[sdv%]/g;
  23051. var format = function (formatStr) {
  23052. var i = 1;
  23053. var args = arguments;
  23054. var len = args.length;
  23055. return formatStr.replace(formatRegExp, function (x) {
  23056. if (i >= len) {
  23057. return x; // missing argument
  23058. }
  23059. var arg = args[i];
  23060. i += 1;
  23061. switch (x) {
  23062. case '%%':
  23063. return '%';
  23064. case '%s':
  23065. return String(arg);
  23066. case '%d':
  23067. return Number(arg);
  23068. case '%v':
  23069. return '';
  23070. }
  23071. });
  23072. // NB: we discard excess arguments - they are typically undefined from makeLine
  23073. };
  23074. var makeLine = function (type, obj, location) {
  23075. var str = obj.format instanceof Function ?
  23076. (obj.format(obj.push ? location : location[obj.name])) :
  23077. obj.format;
  23078. var args = [type + '=' + str];
  23079. if (obj.names) {
  23080. for (var i = 0; i < obj.names.length; i += 1) {
  23081. var n = obj.names[i];
  23082. if (obj.name) {
  23083. args.push(location[obj.name][n]);
  23084. }
  23085. else { // for mLine and push attributes
  23086. args.push(location[obj.names[i]]);
  23087. }
  23088. }
  23089. }
  23090. else {
  23091. args.push(location[obj.name]);
  23092. }
  23093. return format.apply(null, args);
  23094. };
  23095. // RFC specified order
  23096. // TODO: extend this with all the rest
  23097. var defaultOuterOrder = [
  23098. 'v', 'o', 's', 'i',
  23099. 'u', 'e', 'p', 'c',
  23100. 'b', 't', 'r', 'z', 'a'
  23101. ];
  23102. var defaultInnerOrder = ['i', 'c', 'b', 'a'];
  23103. module.exports = function (session, opts) {
  23104. opts = opts || {};
  23105. // ensure certain properties exist
  23106. if (session.version == null) {
  23107. session.version = 0; // 'v=0' must be there (only defined version atm)
  23108. }
  23109. if (session.name == null) {
  23110. session.name = ' '; // 's= ' must be there if no meaningful name set
  23111. }
  23112. session.media.forEach(function (mLine) {
  23113. if (mLine.payloads == null) {
  23114. mLine.payloads = '';
  23115. }
  23116. });
  23117. var outerOrder = opts.outerOrder || defaultOuterOrder;
  23118. var innerOrder = opts.innerOrder || defaultInnerOrder;
  23119. var sdp = [];
  23120. // loop through outerOrder for matching properties on session
  23121. outerOrder.forEach(function (type) {
  23122. grammar[type].forEach(function (obj) {
  23123. if (obj.name in session && session[obj.name] != null) {
  23124. sdp.push(makeLine(type, obj, session));
  23125. }
  23126. else if (obj.push in session && session[obj.push] != null) {
  23127. session[obj.push].forEach(function (el) {
  23128. sdp.push(makeLine(type, obj, el));
  23129. });
  23130. }
  23131. });
  23132. });
  23133. // then for each media line, follow the innerOrder
  23134. session.media.forEach(function (mLine) {
  23135. sdp.push(makeLine('m', grammar.m[0], mLine));
  23136. innerOrder.forEach(function (type) {
  23137. grammar[type].forEach(function (obj) {
  23138. if (obj.name in mLine && mLine[obj.name] != null) {
  23139. sdp.push(makeLine(type, obj, mLine));
  23140. }
  23141. else if (obj.push in mLine && mLine[obj.push] != null) {
  23142. mLine[obj.push].forEach(function (el) {
  23143. sdp.push(makeLine(type, obj, el));
  23144. });
  23145. }
  23146. });
  23147. });
  23148. });
  23149. return sdp.join('\r\n') + '\r\n';
  23150. };
  23151. },{"./grammar":34}],38:[function(require,module,exports){
  23152. module.exports={
  23153. "name": "jssip",
  23154. "title": "JsSIP",
  23155. "description": "the Javascript SIP library",
  23156. "version": "3.3.11",
  23157. "homepage": "https://jssip.net",
  23158. "author": "JosĂŠ Luis MillĂĄn <jmillan@aliax.net> (https://github.com/jmillan)",
  23159. "contributors": [
  23160. "IĂąaki Baz Castillo <ibc@aliax.net> (https://github.com/ibc)"
  23161. ],
  23162. "main": "lib-es5/JsSIP.js",
  23163. "keywords": [
  23164. "sip",
  23165. "websocket",
  23166. "webrtc",
  23167. "node",
  23168. "browser",
  23169. "library"
  23170. ],
  23171. "license": "MIT",
  23172. "repository": {
  23173. "type": "git",
  23174. "url": "https://github.com/versatica/JsSIP.git"
  23175. },
  23176. "bugs": {
  23177. "url": "https://github.com/versatica/JsSIP/issues"
  23178. },
  23179. "dependencies": {
  23180. "debug": "^4.1.1",
  23181. "events": "^3.0.0",
  23182. "sdp-transform": "^2.7.0"
  23183. },
  23184. "devDependencies": {
  23185. "@babel/core": "^7.4.3",
  23186. "@babel/preset-env": "^7.4.3",
  23187. "ansi-colors": "^3.2.4",
  23188. "browserify": "^16.2.3",
  23189. "eslint": "^5.16.0",
  23190. "fancy-log": "^1.3.3",
  23191. "gulp": "^4.0.0",
  23192. "gulp-babel": "^8.0.0",
  23193. "gulp-eslint": "^5.0.0",
  23194. "gulp-expect-file": "^1.0.1",
  23195. "gulp-header": "^2.0.7",
  23196. "gulp-nodeunit-runner": "^0.2.2",
  23197. "gulp-plumber": "^1.2.1",
  23198. "gulp-rename": "^1.4.0",
  23199. "gulp-uglify-es": "^1.0.4",
  23200. "pegjs": "^0.7.0",
  23201. "vinyl-buffer": "^1.0.1",
  23202. "vinyl-source-stream": "^2.0.0"
  23203. },
  23204. "scripts": {
  23205. "lint": "gulp lint",
  23206. "test": "gulp test",
  23207. "prepublishOnly": "gulp babel"
  23208. }
  23209. }
  23210. },{}]},{},[8])(8)
  23211. });