Нет описания

jssip.js 810KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345
  1. /*
  2. * JsSIP v3.9.1
  3. * the Javascript SIP library
  4. * Copyright: 2012-2022
  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. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  11. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  12. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  13. var Utils = require('./Utils');
  14. var JsSIP_C = require('./Constants');
  15. var Grammar = require('./Grammar');
  16. var URI = require('./URI');
  17. var Socket = require('./Socket');
  18. var Exceptions = require('./Exceptions'); // Default settings.
  19. exports.settings = {
  20. // SIP authentication.
  21. authorization_user: null,
  22. password: null,
  23. realm: null,
  24. ha1: null,
  25. authorization_jwt: null,
  26. // SIP account.
  27. display_name: null,
  28. uri: null,
  29. contact_uri: null,
  30. // SIP instance id (GRUU).
  31. instance_id: null,
  32. // Preloaded SIP Route header field.
  33. use_preloaded_route: false,
  34. // Session parameters.
  35. session_timers: true,
  36. session_timers_refresh_method: JsSIP_C.UPDATE,
  37. session_timers_force_refresher: false,
  38. no_answer_timeout: 60,
  39. // Registration parameters.
  40. register: true,
  41. register_expires: 600,
  42. registrar_server: null,
  43. // Connection options.
  44. sockets: null,
  45. connection_recovery_max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL,
  46. connection_recovery_min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL,
  47. /*
  48. * Host address.
  49. * Value to be set in Via sent_by and host part of Contact FQDN.
  50. */
  51. via_host: "".concat(Utils.createRandomToken(12), ".invalid")
  52. }; // Configuration checks.
  53. var checks = {
  54. mandatory: {
  55. sockets: function sockets(_sockets2) {
  56. /* Allow defining sockets parameter as:
  57. * Socket: socket
  58. * Array of Socket: [socket1, socket2]
  59. * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}]
  60. * Array of Objects and Socket: [{socket: socket1}, socket2]
  61. */
  62. var _sockets = [];
  63. if (Socket.isSocket(_sockets2)) {
  64. _sockets.push({
  65. socket: _sockets2
  66. });
  67. } else if (Array.isArray(_sockets2) && _sockets2.length) {
  68. var _iterator = _createForOfIteratorHelper(_sockets2),
  69. _step;
  70. try {
  71. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  72. var socket = _step.value;
  73. if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) {
  74. _sockets.push(socket);
  75. } else if (Socket.isSocket(socket)) {
  76. _sockets.push({
  77. socket: socket
  78. });
  79. }
  80. }
  81. } catch (err) {
  82. _iterator.e(err);
  83. } finally {
  84. _iterator.f();
  85. }
  86. } else {
  87. return;
  88. }
  89. return _sockets;
  90. },
  91. uri: function uri(_uri) {
  92. if (!/^sip:/i.test(_uri)) {
  93. _uri = "".concat(JsSIP_C.SIP, ":").concat(_uri);
  94. }
  95. var parsed = URI.parse(_uri);
  96. if (!parsed) {
  97. return;
  98. } else if (!parsed.user) {
  99. return;
  100. } else {
  101. return parsed;
  102. }
  103. }
  104. },
  105. optional: {
  106. authorization_user: function authorization_user(_authorization_user) {
  107. if (Grammar.parse("\"".concat(_authorization_user, "\""), 'quoted_string') === -1) {
  108. return;
  109. } else {
  110. return _authorization_user;
  111. }
  112. },
  113. authorization_jwt: function authorization_jwt(_authorization_jwt) {
  114. if (typeof _authorization_jwt === 'string') {
  115. return _authorization_jwt;
  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. session_timers_force_refresher: function session_timers_force_refresher(_session_timers_force_refresher) {
  182. if (typeof _session_timers_force_refresher === 'boolean') {
  183. return _session_timers_force_refresher;
  184. }
  185. },
  186. password: function password(_password) {
  187. return String(_password);
  188. },
  189. realm: function realm(_realm) {
  190. return String(_realm);
  191. },
  192. ha1: function ha1(_ha) {
  193. return String(_ha);
  194. },
  195. register: function register(_register) {
  196. if (typeof _register === 'boolean') {
  197. return _register;
  198. }
  199. },
  200. register_expires: function register_expires(_register_expires) {
  201. if (Utils.isDecimal(_register_expires)) {
  202. var value = Number(_register_expires);
  203. if (value > 0) {
  204. return value;
  205. }
  206. }
  207. },
  208. registrar_server: function registrar_server(_registrar_server) {
  209. if (!/^sip:/i.test(_registrar_server)) {
  210. _registrar_server = "".concat(JsSIP_C.SIP, ":").concat(_registrar_server);
  211. }
  212. var parsed = URI.parse(_registrar_server);
  213. if (!parsed) {
  214. return;
  215. } else if (parsed.user) {
  216. return;
  217. } else {
  218. return parsed;
  219. }
  220. },
  221. use_preloaded_route: function use_preloaded_route(_use_preloaded_route) {
  222. if (typeof _use_preloaded_route === 'boolean') {
  223. return _use_preloaded_route;
  224. }
  225. }
  226. }
  227. };
  228. exports.load = function (dst, src) {
  229. // Check Mandatory parameters.
  230. for (var parameter in checks.mandatory) {
  231. if (!src.hasOwnProperty(parameter)) {
  232. throw new Exceptions.ConfigurationError(parameter);
  233. } else {
  234. var value = src[parameter];
  235. var checked_value = checks.mandatory[parameter](value);
  236. if (checked_value !== undefined) {
  237. dst[parameter] = checked_value;
  238. } else {
  239. throw new Exceptions.ConfigurationError(parameter, value);
  240. }
  241. }
  242. } // Check Optional parameters.
  243. for (var _parameter in checks.optional) {
  244. if (src.hasOwnProperty(_parameter)) {
  245. var _value = src[_parameter];
  246. /* If the parameter value is null, empty string, undefined, empty array
  247. * or it's a number with NaN value, then apply its default value.
  248. */
  249. if (Utils.isEmpty(_value)) {
  250. continue;
  251. }
  252. var _checked_value = checks.optional[_parameter](_value);
  253. if (_checked_value !== undefined) {
  254. dst[_parameter] = _checked_value;
  255. } else {
  256. throw new Exceptions.ConfigurationError(_parameter, _value);
  257. }
  258. }
  259. }
  260. };
  261. },{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":22,"./URI":27,"./Utils":28}],2:[function(require,module,exports){
  262. "use strict";
  263. var pkg = require('../package.json');
  264. module.exports = {
  265. USER_AGENT: "".concat(pkg.title, " ").concat(pkg.version),
  266. // SIP scheme.
  267. SIP: 'sip',
  268. SIPS: 'sips',
  269. // End and Failure causes.
  270. causes: {
  271. // Generic error causes.
  272. CONNECTION_ERROR: 'Connection Error',
  273. REQUEST_TIMEOUT: 'Request Timeout',
  274. SIP_FAILURE_CODE: 'SIP Failure Code',
  275. INTERNAL_ERROR: 'Internal Error',
  276. // SIP error causes.
  277. BUSY: 'Busy',
  278. REJECTED: 'Rejected',
  279. REDIRECTED: 'Redirected',
  280. UNAVAILABLE: 'Unavailable',
  281. NOT_FOUND: 'Not Found',
  282. ADDRESS_INCOMPLETE: 'Address Incomplete',
  283. INCOMPATIBLE_SDP: 'Incompatible SDP',
  284. MISSING_SDP: 'Missing SDP',
  285. AUTHENTICATION_ERROR: 'Authentication Error',
  286. // Session error causes.
  287. BYE: 'Terminated',
  288. WEBRTC_ERROR: 'WebRTC Error',
  289. CANCELED: 'Canceled',
  290. NO_ANSWER: 'No Answer',
  291. EXPIRES: 'Expires',
  292. NO_ACK: 'No ACK',
  293. DIALOG_ERROR: 'Dialog Error',
  294. USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access',
  295. BAD_MEDIA_DESCRIPTION: 'Bad Media Description',
  296. RTP_TIMEOUT: 'RTP Timeout'
  297. },
  298. SIP_ERROR_CAUSES: {
  299. REDIRECTED: [300, 301, 302, 305, 380],
  300. BUSY: [486, 600],
  301. REJECTED: [403, 603],
  302. NOT_FOUND: [404, 604],
  303. UNAVAILABLE: [480, 410, 408, 430],
  304. ADDRESS_INCOMPLETE: [484, 424],
  305. INCOMPATIBLE_SDP: [488, 606],
  306. AUTHENTICATION_ERROR: [401, 407]
  307. },
  308. // SIP Methods.
  309. ACK: 'ACK',
  310. BYE: 'BYE',
  311. CANCEL: 'CANCEL',
  312. INFO: 'INFO',
  313. INVITE: 'INVITE',
  314. MESSAGE: 'MESSAGE',
  315. NOTIFY: 'NOTIFY',
  316. OPTIONS: 'OPTIONS',
  317. REGISTER: 'REGISTER',
  318. REFER: 'REFER',
  319. UPDATE: 'UPDATE',
  320. SUBSCRIBE: 'SUBSCRIBE',
  321. // DTMF transport methods.
  322. DTMF_TRANSPORT: {
  323. INFO: 'INFO',
  324. RFC2833: 'RFC2833'
  325. },
  326. /* SIP Response Reasons
  327. * DOC: https://www.iana.org/assignments/sip-parameters
  328. * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7
  329. */
  330. REASON_PHRASE: {
  331. 100: 'Trying',
  332. 180: 'Ringing',
  333. 181: 'Call Is Being Forwarded',
  334. 182: 'Queued',
  335. 183: 'Session Progress',
  336. 199: 'Early Dialog Terminated',
  337. // draft-ietf-sipcore-199
  338. 200: 'OK',
  339. 202: 'Accepted',
  340. // RFC 3265
  341. 204: 'No Notification',
  342. // RFC 5839
  343. 300: 'Multiple Choices',
  344. 301: 'Moved Permanently',
  345. 302: 'Moved Temporarily',
  346. 305: 'Use Proxy',
  347. 380: 'Alternative Service',
  348. 400: 'Bad Request',
  349. 401: 'Unauthorized',
  350. 402: 'Payment Required',
  351. 403: 'Forbidden',
  352. 404: 'Not Found',
  353. 405: 'Method Not Allowed',
  354. 406: 'Not Acceptable',
  355. 407: 'Proxy Authentication Required',
  356. 408: 'Request Timeout',
  357. 410: 'Gone',
  358. 412: 'Conditional Request Failed',
  359. // RFC 3903
  360. 413: 'Request Entity Too Large',
  361. 414: 'Request-URI Too Long',
  362. 415: 'Unsupported Media Type',
  363. 416: 'Unsupported URI Scheme',
  364. 417: 'Unknown Resource-Priority',
  365. // RFC 4412
  366. 420: 'Bad Extension',
  367. 421: 'Extension Required',
  368. 422: 'Session Interval Too Small',
  369. // RFC 4028
  370. 423: 'Interval Too Brief',
  371. 424: 'Bad Location Information',
  372. // RFC 6442
  373. 428: 'Use Identity Header',
  374. // RFC 4474
  375. 429: 'Provide Referrer Identity',
  376. // RFC 3892
  377. 430: 'Flow Failed',
  378. // RFC 5626
  379. 433: 'Anonymity Disallowed',
  380. // RFC 5079
  381. 436: 'Bad Identity-Info',
  382. // RFC 4474
  383. 437: 'Unsupported Certificate',
  384. // RFC 4744
  385. 438: 'Invalid Identity Header',
  386. // RFC 4744
  387. 439: 'First Hop Lacks Outbound Support',
  388. // RFC 5626
  389. 440: 'Max-Breadth Exceeded',
  390. // RFC 5393
  391. 469: 'Bad Info Package',
  392. // draft-ietf-sipcore-info-events
  393. 470: 'Consent Needed',
  394. // RFC 5360
  395. 478: 'Unresolvable Destination',
  396. // Custom code copied from Kamailio.
  397. 480: 'Temporarily Unavailable',
  398. 481: 'Call/Transaction Does Not Exist',
  399. 482: 'Loop Detected',
  400. 483: 'Too Many Hops',
  401. 484: 'Address Incomplete',
  402. 485: 'Ambiguous',
  403. 486: 'Busy Here',
  404. 487: 'Request Terminated',
  405. 488: 'Not Acceptable Here',
  406. 489: 'Bad Event',
  407. // RFC 3265
  408. 491: 'Request Pending',
  409. 493: 'Undecipherable',
  410. 494: 'Security Agreement Required',
  411. // RFC 3329
  412. 500: 'JsSIP Internal Error',
  413. 501: 'Not Implemented',
  414. 502: 'Bad Gateway',
  415. 503: 'Service Unavailable',
  416. 504: 'Server Time-out',
  417. 505: 'Version Not Supported',
  418. 513: 'Message Too Large',
  419. 580: 'Precondition Failure',
  420. // RFC 3312
  421. 600: 'Busy Everywhere',
  422. 603: 'Decline',
  423. 604: 'Does Not Exist Anywhere',
  424. 606: 'Not Acceptable'
  425. },
  426. ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY',
  427. ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay',
  428. MAX_FORWARDS: 69,
  429. SESSION_EXPIRES: 90,
  430. MIN_SESSION_EXPIRES: 60,
  431. CONNECTION_RECOVERY_MAX_INTERVAL: 30,
  432. CONNECTION_RECOVERY_MIN_INTERVAL: 2
  433. };
  434. },{"../package.json":40}],3:[function(require,module,exports){
  435. "use strict";
  436. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  437. 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); } }
  438. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  439. var Logger = require('./Logger');
  440. var SIPMessage = require('./SIPMessage');
  441. var JsSIP_C = require('./Constants');
  442. var Transactions = require('./Transactions');
  443. var Dialog_RequestSender = require('./Dialog/RequestSender');
  444. var Utils = require('./Utils');
  445. var logger = new Logger('Dialog');
  446. var C = {
  447. // Dialog states.
  448. STATUS_EARLY: 1,
  449. STATUS_CONFIRMED: 2
  450. }; // RFC 3261 12.1.
  451. module.exports = /*#__PURE__*/function () {
  452. _createClass(Dialog, null, [{
  453. key: "C",
  454. // Expose C object.
  455. get: function get() {
  456. return C;
  457. }
  458. }]);
  459. function Dialog(owner, message, type) {
  460. var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED;
  461. _classCallCheck(this, Dialog);
  462. this._owner = owner;
  463. this._ua = owner._ua;
  464. this._uac_pending_reply = false;
  465. this._uas_pending_reply = false;
  466. if (!message.hasHeader('contact')) {
  467. return {
  468. error: 'unable to create a Dialog without Contact header field'
  469. };
  470. }
  471. if (message instanceof SIPMessage.IncomingResponse) {
  472. state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED;
  473. }
  474. var contact = message.parseHeader('contact'); // RFC 3261 12.1.1.
  475. if (type === 'UAS') {
  476. this._id = {
  477. call_id: message.call_id,
  478. local_tag: message.to_tag,
  479. remote_tag: message.from_tag,
  480. toString: function toString() {
  481. return this.call_id + this.local_tag + this.remote_tag;
  482. }
  483. };
  484. this._state = state;
  485. this._remote_seqnum = message.cseq;
  486. this._local_uri = message.parseHeader('to').uri;
  487. this._remote_uri = message.parseHeader('from').uri;
  488. this._remote_target = contact.uri;
  489. this._route_set = message.getHeaders('record-route');
  490. this._ack_seqnum = this._remote_seqnum;
  491. } // RFC 3261 12.1.2.
  492. else if (type === 'UAC') {
  493. this._id = {
  494. call_id: message.call_id,
  495. local_tag: message.from_tag,
  496. remote_tag: message.to_tag,
  497. toString: function toString() {
  498. return this.call_id + this.local_tag + this.remote_tag;
  499. }
  500. };
  501. this._state = state;
  502. this._local_seqnum = message.cseq;
  503. this._local_uri = message.parseHeader('from').uri;
  504. this._remote_uri = message.parseHeader('to').uri;
  505. this._remote_target = contact.uri;
  506. this._route_set = message.getHeaders('record-route').reverse();
  507. this._ack_seqnum = null;
  508. }
  509. this._ua.newDialog(this);
  510. logger.debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED'));
  511. }
  512. _createClass(Dialog, [{
  513. key: "update",
  514. value: function update(message, type) {
  515. this._state = C.STATUS_CONFIRMED;
  516. logger.debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state"));
  517. if (type === 'UAC') {
  518. // RFC 3261 13.2.2.4.
  519. this._route_set = message.getHeaders('record-route').reverse();
  520. }
  521. }
  522. }, {
  523. key: "terminate",
  524. value: function terminate() {
  525. logger.debug("dialog ".concat(this._id.toString(), " deleted"));
  526. this._ua.destroyDialog(this);
  527. }
  528. }, {
  529. key: "sendRequest",
  530. value: function sendRequest(method) {
  531. var _this = this;
  532. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  533. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  534. var eventHandlers = Utils.cloneObject(options.eventHandlers);
  535. var body = options.body || null;
  536. var request = this._createRequest(method, extraHeaders, body); // Increase the local CSeq on authentication.
  537. eventHandlers.onAuthenticated = function () {
  538. _this._local_seqnum += 1;
  539. };
  540. var request_sender = new Dialog_RequestSender(this, request, eventHandlers);
  541. request_sender.send(); // Return the instance of OutgoingRequest.
  542. return request;
  543. }
  544. }, {
  545. key: "receiveRequest",
  546. value: function receiveRequest(request) {
  547. // Check in-dialog request.
  548. if (!this._checkInDialogRequest(request)) {
  549. return;
  550. } // ACK received. Cleanup this._ack_seqnum.
  551. if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) {
  552. this._ack_seqnum = null;
  553. } // INVITE received. Set this._ack_seqnum.
  554. else if (request.method === JsSIP_C.INVITE) {
  555. this._ack_seqnum = request.cseq;
  556. }
  557. this._owner.receiveRequest(request);
  558. } // RFC 3261 12.2.1.1.
  559. }, {
  560. key: "_createRequest",
  561. value: function _createRequest(method, extraHeaders, body) {
  562. extraHeaders = Utils.cloneArray(extraHeaders);
  563. if (!this._local_seqnum) {
  564. this._local_seqnum = Math.floor(Math.random() * 10000);
  565. }
  566. var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1;
  567. var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, {
  568. 'cseq': cseq,
  569. 'call_id': this._id.call_id,
  570. 'from_uri': this._local_uri,
  571. 'from_tag': this._id.local_tag,
  572. 'to_uri': this._remote_uri,
  573. 'to_tag': this._id.remote_tag,
  574. 'route_set': this._route_set
  575. }, extraHeaders, body);
  576. return request;
  577. } // RFC 3261 12.2.2.
  578. }, {
  579. key: "_checkInDialogRequest",
  580. value: function _checkInDialogRequest(request) {
  581. var _this2 = this;
  582. if (!this._remote_seqnum) {
  583. this._remote_seqnum = request.cseq;
  584. } else if (request.cseq < this._remote_seqnum) {
  585. if (request.method === JsSIP_C.ACK) {
  586. // We are not expecting any ACK with lower seqnum than the current one.
  587. // Or this is not the ACK we are waiting for.
  588. if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) {
  589. return false;
  590. }
  591. } else {
  592. request.reply(500);
  593. return false;
  594. }
  595. } else if (request.cseq > this._remote_seqnum) {
  596. this._remote_seqnum = request.cseq;
  597. } // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-.
  598. if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) {
  599. if (this._uac_pending_reply === true) {
  600. request.reply(491);
  601. } else if (this._uas_pending_reply === true) {
  602. var retryAfter = (Math.random() * 10 | 0) + 1;
  603. request.reply(500, null, ["Retry-After:".concat(retryAfter)]);
  604. return false;
  605. } else {
  606. this._uas_pending_reply = true;
  607. var stateChanged = function stateChanged() {
  608. 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) {
  609. request.server_transaction.removeListener('stateChanged', stateChanged);
  610. _this2._uas_pending_reply = false;
  611. }
  612. };
  613. request.server_transaction.on('stateChanged', stateChanged);
  614. } // RFC3261 12.2.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_ACCEPTED) {
  618. _this2._remote_target = request.parseHeader('contact').uri;
  619. }
  620. });
  621. }
  622. } else if (request.method === JsSIP_C.NOTIFY) {
  623. // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted.
  624. if (request.hasHeader('contact')) {
  625. request.server_transaction.on('stateChanged', function () {
  626. if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) {
  627. _this2._remote_target = request.parseHeader('contact').uri;
  628. }
  629. });
  630. }
  631. }
  632. return true;
  633. }
  634. }, {
  635. key: "id",
  636. get: function get() {
  637. return this._id;
  638. }
  639. }, {
  640. key: "local_seqnum",
  641. get: function get() {
  642. return this._local_seqnum;
  643. },
  644. set: function set(num) {
  645. this._local_seqnum = num;
  646. }
  647. }, {
  648. key: "owner",
  649. get: function get() {
  650. return this._owner;
  651. }
  652. }, {
  653. key: "uac_pending_reply",
  654. get: function get() {
  655. return this._uac_pending_reply;
  656. },
  657. set: function set(pending) {
  658. this._uac_pending_reply = pending;
  659. }
  660. }, {
  661. key: "uas_pending_reply",
  662. get: function get() {
  663. return this._uas_pending_reply;
  664. }
  665. }]);
  666. return Dialog;
  667. }();
  668. },{"./Constants":2,"./Dialog/RequestSender":4,"./Logger":9,"./SIPMessage":21,"./Transactions":24,"./Utils":28}],4:[function(require,module,exports){
  669. "use strict";
  670. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  671. 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); } }
  672. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  673. var JsSIP_C = require('../Constants');
  674. var Transactions = require('../Transactions');
  675. var RTCSession = require('../RTCSession');
  676. var RequestSender = require('../RequestSender'); // Default event handlers.
  677. var EventHandlers = {
  678. onRequestTimeout: function onRequestTimeout() {},
  679. onTransportError: function onTransportError() {},
  680. onSuccessResponse: function onSuccessResponse() {},
  681. onErrorResponse: function onErrorResponse() {},
  682. onAuthenticated: function onAuthenticated() {},
  683. onDialogError: function onDialogError() {}
  684. };
  685. module.exports = /*#__PURE__*/function () {
  686. function DialogRequestSender(dialog, request, eventHandlers) {
  687. _classCallCheck(this, DialogRequestSender);
  688. this._dialog = dialog;
  689. this._ua = dialog._ua;
  690. this._request = request;
  691. this._eventHandlers = eventHandlers; // RFC3261 14.1 Modifying an Existing Session. UAC Behavior.
  692. this._reattempt = false;
  693. this._reattemptTimer = null; // Define the undefined handlers.
  694. for (var handler in EventHandlers) {
  695. if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
  696. if (!this._eventHandlers[handler]) {
  697. this._eventHandlers[handler] = EventHandlers[handler];
  698. }
  699. }
  700. }
  701. }
  702. _createClass(DialogRequestSender, [{
  703. key: "send",
  704. value: function send() {
  705. var _this = this;
  706. var request_sender = new RequestSender(this._ua, this._request, {
  707. onRequestTimeout: function onRequestTimeout() {
  708. _this._eventHandlers.onRequestTimeout();
  709. },
  710. onTransportError: function onTransportError() {
  711. _this._eventHandlers.onTransportError();
  712. },
  713. onAuthenticated: function onAuthenticated(request) {
  714. _this._eventHandlers.onAuthenticated(request);
  715. },
  716. onReceiveResponse: function onReceiveResponse(response) {
  717. _this._receiveResponse(response);
  718. }
  719. });
  720. request_sender.send(); // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-.
  721. if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) {
  722. this._dialog.uac_pending_reply = true;
  723. var stateChanged = function stateChanged() {
  724. 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) {
  725. request_sender.clientTransaction.removeListener('stateChanged', stateChanged);
  726. _this._dialog.uac_pending_reply = false;
  727. }
  728. };
  729. request_sender.clientTransaction.on('stateChanged', stateChanged);
  730. }
  731. }
  732. }, {
  733. key: "_receiveResponse",
  734. value: function _receiveResponse(response) {
  735. var _this2 = this;
  736. // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog.
  737. if (response.status_code === 408 || response.status_code === 481) {
  738. this._eventHandlers.onDialogError(response);
  739. } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) {
  740. if (this._reattempt) {
  741. if (response.status_code >= 200 && response.status_code < 300) {
  742. this._eventHandlers.onSuccessResponse(response);
  743. } else if (response.status_code >= 300) {
  744. this._eventHandlers.onErrorResponse(response);
  745. }
  746. } else {
  747. this._request.cseq = this._dialog.local_seqnum += 1;
  748. this._reattemptTimer = setTimeout(function () {
  749. // TODO: look at dialog state instead.
  750. if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) {
  751. _this2._reattempt = true;
  752. _this2._request_sender.send();
  753. }
  754. }, 1000);
  755. }
  756. } else if (response.status_code >= 200 && response.status_code < 300) {
  757. this._eventHandlers.onSuccessResponse(response);
  758. } else if (response.status_code >= 300) {
  759. this._eventHandlers.onErrorResponse(response);
  760. }
  761. }
  762. }, {
  763. key: "request",
  764. get: function get() {
  765. return this._request;
  766. }
  767. }]);
  768. return DialogRequestSender;
  769. }();
  770. },{"../Constants":2,"../RTCSession":14,"../RequestSender":20,"../Transactions":24}],5:[function(require,module,exports){
  771. "use strict";
  772. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  773. 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); } }
  774. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  775. var Logger = require('./Logger');
  776. var Utils = require('./Utils');
  777. var logger = new Logger('DigestAuthentication');
  778. module.exports = /*#__PURE__*/function () {
  779. function DigestAuthentication(credentials) {
  780. _classCallCheck(this, DigestAuthentication);
  781. this._credentials = credentials;
  782. this._cnonce = null;
  783. this._nc = 0;
  784. this._ncHex = '00000000';
  785. this._algorithm = null;
  786. this._realm = null;
  787. this._nonce = null;
  788. this._opaque = null;
  789. this._stale = null;
  790. this._qop = null;
  791. this._method = null;
  792. this._uri = null;
  793. this._ha1 = null;
  794. this._response = null;
  795. }
  796. _createClass(DigestAuthentication, [{
  797. key: "get",
  798. value: function get(parameter) {
  799. switch (parameter) {
  800. case 'realm':
  801. return this._realm;
  802. case 'ha1':
  803. return this._ha1;
  804. default:
  805. logger.warn('get() | cannot get "%s" parameter', parameter);
  806. return undefined;
  807. }
  808. }
  809. /**
  810. * Performs Digest authentication given a SIP request and the challenge
  811. * received in a response to that request.
  812. * Returns true if auth was successfully generated, false otherwise.
  813. */
  814. }, {
  815. key: "authenticate",
  816. value: function authenticate(_ref, challenge)
  817. /* test interface */
  818. {
  819. var method = _ref.method,
  820. ruri = _ref.ruri,
  821. body = _ref.body;
  822. var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  823. this._algorithm = challenge.algorithm;
  824. this._realm = challenge.realm;
  825. this._nonce = challenge.nonce;
  826. this._opaque = challenge.opaque;
  827. this._stale = challenge.stale;
  828. if (this._algorithm) {
  829. if (this._algorithm !== 'MD5') {
  830. logger.warn('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');
  831. return false;
  832. }
  833. } else {
  834. this._algorithm = 'MD5';
  835. }
  836. if (!this._nonce) {
  837. logger.warn('authenticate() | challenge without Digest nonce, authentication aborted');
  838. return false;
  839. }
  840. if (!this._realm) {
  841. logger.warn('authenticate() | challenge without Digest realm, authentication aborted');
  842. return false;
  843. } // If no plain SIP password is provided.
  844. if (!this._credentials.password) {
  845. // If ha1 is not provided we cannot authenticate.
  846. if (!this._credentials.ha1) {
  847. logger.warn('authenticate() | no plain SIP password nor ha1 provided, authentication aborted');
  848. return false;
  849. } // If the realm does not match the stored realm we cannot authenticate.
  850. if (this._credentials.realm !== this._realm) {
  851. logger.warn('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);
  852. return false;
  853. }
  854. } // 'qop' can contain a list of values (Array). Let's choose just one.
  855. if (challenge.qop) {
  856. if (challenge.qop.indexOf('auth-int') > -1) {
  857. this._qop = 'auth-int';
  858. } else if (challenge.qop.indexOf('auth') > -1) {
  859. this._qop = 'auth';
  860. } else {
  861. // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here.
  862. logger.warn('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');
  863. return false;
  864. }
  865. } else {
  866. this._qop = null;
  867. } // Fill other attributes.
  868. this._method = method;
  869. this._uri = ruri;
  870. this._cnonce = cnonce || Utils.createRandomToken(12);
  871. this._nc += 1;
  872. var hex = Number(this._nc).toString(16);
  873. this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex; // Nc-value = 8LHEX. Max value = 'FFFFFFFF'.
  874. if (this._nc === 4294967296) {
  875. this._nc = 1;
  876. this._ncHex = '00000001';
  877. } // Calculate the Digest "response" value.
  878. // If we have plain SIP password then regenerate ha1.
  879. if (this._credentials.password) {
  880. // HA1 = MD5(A1) = MD5(username:realm:password).
  881. this._ha1 = Utils.calculateMD5("".concat(this._credentials.username, ":").concat(this._realm, ":").concat(this._credentials.password));
  882. } // Otherwise reuse the stored ha1.
  883. else {
  884. this._ha1 = this._credentials.ha1;
  885. }
  886. var a2;
  887. var ha2;
  888. if (this._qop === 'auth') {
  889. // HA2 = MD5(A2) = MD5(method:digestURI).
  890. a2 = "".concat(this._method, ":").concat(this._uri);
  891. ha2 = Utils.calculateMD5(a2);
  892. logger.debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
  893. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2));
  894. } else if (this._qop === 'auth-int') {
  895. // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)).
  896. a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : ''));
  897. ha2 = Utils.calculateMD5(a2);
  898. logger.debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
  899. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2));
  900. } else if (this._qop === null) {
  901. // HA2 = MD5(A2) = MD5(method:digestURI).
  902. a2 = "".concat(this._method, ":").concat(this._uri);
  903. ha2 = Utils.calculateMD5(a2);
  904. logger.debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2).
  905. this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2));
  906. }
  907. logger.debug('authenticate() | response generated');
  908. return true;
  909. }
  910. /**
  911. * Return the Proxy-Authorization or WWW-Authorization header value.
  912. */
  913. }, {
  914. key: "toString",
  915. value: function toString() {
  916. var auth_params = [];
  917. if (!this._response) {
  918. throw new Error('response field does not exist, cannot generate Authorization header');
  919. }
  920. auth_params.push("algorithm=".concat(this._algorithm));
  921. auth_params.push("username=\"".concat(this._credentials.username, "\""));
  922. auth_params.push("realm=\"".concat(this._realm, "\""));
  923. auth_params.push("nonce=\"".concat(this._nonce, "\""));
  924. auth_params.push("uri=\"".concat(this._uri, "\""));
  925. auth_params.push("response=\"".concat(this._response, "\""));
  926. if (this._opaque) {
  927. auth_params.push("opaque=\"".concat(this._opaque, "\""));
  928. }
  929. if (this._qop) {
  930. auth_params.push("qop=".concat(this._qop));
  931. auth_params.push("cnonce=\"".concat(this._cnonce, "\""));
  932. auth_params.push("nc=".concat(this._ncHex));
  933. }
  934. return "Digest ".concat(auth_params.join(', '));
  935. }
  936. }]);
  937. return DigestAuthentication;
  938. }();
  939. },{"./Logger":9,"./Utils":28}],6:[function(require,module,exports){
  940. "use strict";
  941. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  942. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  943. 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); }
  944. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  945. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  946. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  947. 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); }
  948. 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); }
  949. 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; } }
  950. function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
  951. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  952. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  953. var ConfigurationError = /*#__PURE__*/function (_Error) {
  954. _inherits(ConfigurationError, _Error);
  955. var _super = _createSuper(ConfigurationError);
  956. function ConfigurationError(parameter, value) {
  957. var _this;
  958. _classCallCheck(this, ConfigurationError);
  959. _this = _super.call(this);
  960. _this.code = 1;
  961. _this.name = 'CONFIGURATION_ERROR';
  962. _this.parameter = parameter;
  963. _this.value = value;
  964. _this.message = !_this.value ? "Missing parameter: ".concat(_this.parameter) : "Invalid value ".concat(JSON.stringify(_this.value), " for parameter \"").concat(_this.parameter, "\"");
  965. return _this;
  966. }
  967. return ConfigurationError;
  968. }( /*#__PURE__*/_wrapNativeSuper(Error));
  969. var InvalidStateError = /*#__PURE__*/function (_Error2) {
  970. _inherits(InvalidStateError, _Error2);
  971. var _super2 = _createSuper(InvalidStateError);
  972. function InvalidStateError(status) {
  973. var _this2;
  974. _classCallCheck(this, InvalidStateError);
  975. _this2 = _super2.call(this);
  976. _this2.code = 2;
  977. _this2.name = 'INVALID_STATE_ERROR';
  978. _this2.status = status;
  979. _this2.message = "Invalid status: ".concat(status);
  980. return _this2;
  981. }
  982. return InvalidStateError;
  983. }( /*#__PURE__*/_wrapNativeSuper(Error));
  984. var NotSupportedError = /*#__PURE__*/function (_Error3) {
  985. _inherits(NotSupportedError, _Error3);
  986. var _super3 = _createSuper(NotSupportedError);
  987. function NotSupportedError(message) {
  988. var _this3;
  989. _classCallCheck(this, NotSupportedError);
  990. _this3 = _super3.call(this);
  991. _this3.code = 3;
  992. _this3.name = 'NOT_SUPPORTED_ERROR';
  993. _this3.message = message;
  994. return _this3;
  995. }
  996. return NotSupportedError;
  997. }( /*#__PURE__*/_wrapNativeSuper(Error));
  998. var NotReadyError = /*#__PURE__*/function (_Error4) {
  999. _inherits(NotReadyError, _Error4);
  1000. var _super4 = _createSuper(NotReadyError);
  1001. function NotReadyError(message) {
  1002. var _this4;
  1003. _classCallCheck(this, NotReadyError);
  1004. _this4 = _super4.call(this);
  1005. _this4.code = 4;
  1006. _this4.name = 'NOT_READY_ERROR';
  1007. _this4.message = message;
  1008. return _this4;
  1009. }
  1010. return NotReadyError;
  1011. }( /*#__PURE__*/_wrapNativeSuper(Error));
  1012. module.exports = {
  1013. ConfigurationError: ConfigurationError,
  1014. InvalidStateError: InvalidStateError,
  1015. NotSupportedError: NotSupportedError,
  1016. NotReadyError: NotReadyError
  1017. };
  1018. },{}],7:[function(require,module,exports){
  1019. "use strict";
  1020. module.exports = function () {
  1021. /*
  1022. * Generated by PEG.js 0.7.0.
  1023. *
  1024. * http://pegjs.majda.cz/
  1025. */
  1026. function quote(s) {
  1027. /*
  1028. * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
  1029. * string literal except for the closing quote character, backslash,
  1030. * carriage return, line separator, paragraph separator, and line feed.
  1031. * Any character may appear in the form of an escape sequence.
  1032. *
  1033. * For portability, we also escape escape all control and non-ASCII
  1034. * characters. Note that "\0" and "\v" escape sequences are not used
  1035. * because JSHint does not like the first and IE the second.
  1036. */
  1037. return '"' + s.replace(/\\/g, '\\\\') // backslash
  1038. .replace(/"/g, '\\"') // closing quote character
  1039. .replace(/\x08/g, '\\b') // backspace
  1040. .replace(/\t/g, '\\t') // horizontal tab
  1041. .replace(/\n/g, '\\n') // line feed
  1042. .replace(/\f/g, '\\f') // form feed
  1043. .replace(/\r/g, '\\r') // carriage return
  1044. .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"';
  1045. }
  1046. var result = {
  1047. /*
  1048. * Parses the input with a generated parser. If the parsing is successfull,
  1049. * returns a value explicitly or implicitly specified by the grammar from
  1050. * which the parser was generated (see |PEG.buildParser|). If the parsing is
  1051. * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
  1052. */
  1053. parse: function parse(input, startRule) {
  1054. var parseFunctions = {
  1055. "CRLF": parse_CRLF,
  1056. "DIGIT": parse_DIGIT,
  1057. "ALPHA": parse_ALPHA,
  1058. "HEXDIG": parse_HEXDIG,
  1059. "WSP": parse_WSP,
  1060. "OCTET": parse_OCTET,
  1061. "DQUOTE": parse_DQUOTE,
  1062. "SP": parse_SP,
  1063. "HTAB": parse_HTAB,
  1064. "alphanum": parse_alphanum,
  1065. "reserved": parse_reserved,
  1066. "unreserved": parse_unreserved,
  1067. "mark": parse_mark,
  1068. "escaped": parse_escaped,
  1069. "LWS": parse_LWS,
  1070. "SWS": parse_SWS,
  1071. "HCOLON": parse_HCOLON,
  1072. "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM,
  1073. "TEXT_UTF8char": parse_TEXT_UTF8char,
  1074. "UTF8_NONASCII": parse_UTF8_NONASCII,
  1075. "UTF8_CONT": parse_UTF8_CONT,
  1076. "LHEX": parse_LHEX,
  1077. "token": parse_token,
  1078. "token_nodot": parse_token_nodot,
  1079. "separators": parse_separators,
  1080. "word": parse_word,
  1081. "STAR": parse_STAR,
  1082. "SLASH": parse_SLASH,
  1083. "EQUAL": parse_EQUAL,
  1084. "LPAREN": parse_LPAREN,
  1085. "RPAREN": parse_RPAREN,
  1086. "RAQUOT": parse_RAQUOT,
  1087. "LAQUOT": parse_LAQUOT,
  1088. "COMMA": parse_COMMA,
  1089. "SEMI": parse_SEMI,
  1090. "COLON": parse_COLON,
  1091. "LDQUOT": parse_LDQUOT,
  1092. "RDQUOT": parse_RDQUOT,
  1093. "comment": parse_comment,
  1094. "ctext": parse_ctext,
  1095. "quoted_string": parse_quoted_string,
  1096. "quoted_string_clean": parse_quoted_string_clean,
  1097. "qdtext": parse_qdtext,
  1098. "quoted_pair": parse_quoted_pair,
  1099. "SIP_URI_noparams": parse_SIP_URI_noparams,
  1100. "SIP_URI": parse_SIP_URI,
  1101. "uri_scheme": parse_uri_scheme,
  1102. "uri_scheme_sips": parse_uri_scheme_sips,
  1103. "uri_scheme_sip": parse_uri_scheme_sip,
  1104. "userinfo": parse_userinfo,
  1105. "user": parse_user,
  1106. "user_unreserved": parse_user_unreserved,
  1107. "password": parse_password,
  1108. "hostport": parse_hostport,
  1109. "host": parse_host,
  1110. "hostname": parse_hostname,
  1111. "domainlabel": parse_domainlabel,
  1112. "toplabel": parse_toplabel,
  1113. "IPv6reference": parse_IPv6reference,
  1114. "IPv6address": parse_IPv6address,
  1115. "h16": parse_h16,
  1116. "ls32": parse_ls32,
  1117. "IPv4address": parse_IPv4address,
  1118. "dec_octet": parse_dec_octet,
  1119. "port": parse_port,
  1120. "uri_parameters": parse_uri_parameters,
  1121. "uri_parameter": parse_uri_parameter,
  1122. "transport_param": parse_transport_param,
  1123. "user_param": parse_user_param,
  1124. "method_param": parse_method_param,
  1125. "ttl_param": parse_ttl_param,
  1126. "maddr_param": parse_maddr_param,
  1127. "lr_param": parse_lr_param,
  1128. "other_param": parse_other_param,
  1129. "pname": parse_pname,
  1130. "pvalue": parse_pvalue,
  1131. "paramchar": parse_paramchar,
  1132. "param_unreserved": parse_param_unreserved,
  1133. "headers": parse_headers,
  1134. "header": parse_header,
  1135. "hname": parse_hname,
  1136. "hvalue": parse_hvalue,
  1137. "hnv_unreserved": parse_hnv_unreserved,
  1138. "Request_Response": parse_Request_Response,
  1139. "Request_Line": parse_Request_Line,
  1140. "Request_URI": parse_Request_URI,
  1141. "absoluteURI": parse_absoluteURI,
  1142. "hier_part": parse_hier_part,
  1143. "net_path": parse_net_path,
  1144. "abs_path": parse_abs_path,
  1145. "opaque_part": parse_opaque_part,
  1146. "uric": parse_uric,
  1147. "uric_no_slash": parse_uric_no_slash,
  1148. "path_segments": parse_path_segments,
  1149. "segment": parse_segment,
  1150. "param": parse_param,
  1151. "pchar": parse_pchar,
  1152. "scheme": parse_scheme,
  1153. "authority": parse_authority,
  1154. "srvr": parse_srvr,
  1155. "reg_name": parse_reg_name,
  1156. "query": parse_query,
  1157. "SIP_Version": parse_SIP_Version,
  1158. "INVITEm": parse_INVITEm,
  1159. "ACKm": parse_ACKm,
  1160. "OPTIONSm": parse_OPTIONSm,
  1161. "BYEm": parse_BYEm,
  1162. "CANCELm": parse_CANCELm,
  1163. "REGISTERm": parse_REGISTERm,
  1164. "SUBSCRIBEm": parse_SUBSCRIBEm,
  1165. "NOTIFYm": parse_NOTIFYm,
  1166. "REFERm": parse_REFERm,
  1167. "Method": parse_Method,
  1168. "Status_Line": parse_Status_Line,
  1169. "Status_Code": parse_Status_Code,
  1170. "extension_code": parse_extension_code,
  1171. "Reason_Phrase": parse_Reason_Phrase,
  1172. "Allow_Events": parse_Allow_Events,
  1173. "Call_ID": parse_Call_ID,
  1174. "Contact": parse_Contact,
  1175. "contact_param": parse_contact_param,
  1176. "name_addr": parse_name_addr,
  1177. "display_name": parse_display_name,
  1178. "contact_params": parse_contact_params,
  1179. "c_p_q": parse_c_p_q,
  1180. "c_p_expires": parse_c_p_expires,
  1181. "delta_seconds": parse_delta_seconds,
  1182. "qvalue": parse_qvalue,
  1183. "generic_param": parse_generic_param,
  1184. "gen_value": parse_gen_value,
  1185. "Content_Disposition": parse_Content_Disposition,
  1186. "disp_type": parse_disp_type,
  1187. "disp_param": parse_disp_param,
  1188. "handling_param": parse_handling_param,
  1189. "Content_Encoding": parse_Content_Encoding,
  1190. "Content_Length": parse_Content_Length,
  1191. "Content_Type": parse_Content_Type,
  1192. "media_type": parse_media_type,
  1193. "m_type": parse_m_type,
  1194. "discrete_type": parse_discrete_type,
  1195. "composite_type": parse_composite_type,
  1196. "extension_token": parse_extension_token,
  1197. "x_token": parse_x_token,
  1198. "m_subtype": parse_m_subtype,
  1199. "m_parameter": parse_m_parameter,
  1200. "m_value": parse_m_value,
  1201. "CSeq": parse_CSeq,
  1202. "CSeq_value": parse_CSeq_value,
  1203. "Expires": parse_Expires,
  1204. "Event": parse_Event,
  1205. "event_type": parse_event_type,
  1206. "From": parse_From,
  1207. "from_param": parse_from_param,
  1208. "tag_param": parse_tag_param,
  1209. "Max_Forwards": parse_Max_Forwards,
  1210. "Min_Expires": parse_Min_Expires,
  1211. "Name_Addr_Header": parse_Name_Addr_Header,
  1212. "Proxy_Authenticate": parse_Proxy_Authenticate,
  1213. "challenge": parse_challenge,
  1214. "other_challenge": parse_other_challenge,
  1215. "auth_param": parse_auth_param,
  1216. "digest_cln": parse_digest_cln,
  1217. "realm": parse_realm,
  1218. "realm_value": parse_realm_value,
  1219. "domain": parse_domain,
  1220. "URI": parse_URI,
  1221. "nonce": parse_nonce,
  1222. "nonce_value": parse_nonce_value,
  1223. "opaque": parse_opaque,
  1224. "stale": parse_stale,
  1225. "algorithm": parse_algorithm,
  1226. "qop_options": parse_qop_options,
  1227. "qop_value": parse_qop_value,
  1228. "Proxy_Require": parse_Proxy_Require,
  1229. "Record_Route": parse_Record_Route,
  1230. "rec_route": parse_rec_route,
  1231. "Reason": parse_Reason,
  1232. "reason_param": parse_reason_param,
  1233. "reason_cause": parse_reason_cause,
  1234. "Require": parse_Require,
  1235. "Route": parse_Route,
  1236. "route_param": parse_route_param,
  1237. "Subscription_State": parse_Subscription_State,
  1238. "substate_value": parse_substate_value,
  1239. "subexp_params": parse_subexp_params,
  1240. "event_reason_value": parse_event_reason_value,
  1241. "Subject": parse_Subject,
  1242. "Supported": parse_Supported,
  1243. "To": parse_To,
  1244. "to_param": parse_to_param,
  1245. "Via": parse_Via,
  1246. "via_param": parse_via_param,
  1247. "via_params": parse_via_params,
  1248. "via_ttl": parse_via_ttl,
  1249. "via_maddr": parse_via_maddr,
  1250. "via_received": parse_via_received,
  1251. "via_branch": parse_via_branch,
  1252. "response_port": parse_response_port,
  1253. "rport": parse_rport,
  1254. "sent_protocol": parse_sent_protocol,
  1255. "protocol_name": parse_protocol_name,
  1256. "transport": parse_transport,
  1257. "sent_by": parse_sent_by,
  1258. "via_host": parse_via_host,
  1259. "via_port": parse_via_port,
  1260. "ttl": parse_ttl,
  1261. "WWW_Authenticate": parse_WWW_Authenticate,
  1262. "Session_Expires": parse_Session_Expires,
  1263. "s_e_expires": parse_s_e_expires,
  1264. "s_e_params": parse_s_e_params,
  1265. "s_e_refresher": parse_s_e_refresher,
  1266. "extension_header": parse_extension_header,
  1267. "header_value": parse_header_value,
  1268. "message_body": parse_message_body,
  1269. "uuid_URI": parse_uuid_URI,
  1270. "uuid": parse_uuid,
  1271. "hex4": parse_hex4,
  1272. "hex8": parse_hex8,
  1273. "hex12": parse_hex12,
  1274. "Refer_To": parse_Refer_To,
  1275. "Replaces": parse_Replaces,
  1276. "call_id": parse_call_id,
  1277. "replaces_param": parse_replaces_param,
  1278. "to_tag": parse_to_tag,
  1279. "from_tag": parse_from_tag,
  1280. "early_flag": parse_early_flag
  1281. };
  1282. if (startRule !== undefined) {
  1283. if (parseFunctions[startRule] === undefined) {
  1284. throw new Error("Invalid rule name: " + quote(startRule) + ".");
  1285. }
  1286. } else {
  1287. startRule = "CRLF";
  1288. }
  1289. var pos = 0;
  1290. var reportFailures = 0;
  1291. var rightmostFailuresPos = 0;
  1292. var rightmostFailuresExpected = [];
  1293. function padLeft(input, padding, length) {
  1294. var result = input;
  1295. var padLength = length - input.length;
  1296. for (var i = 0; i < padLength; i++) {
  1297. result = padding + result;
  1298. }
  1299. return result;
  1300. }
  1301. function escape(ch) {
  1302. var charCode = ch.charCodeAt(0);
  1303. var escapeChar;
  1304. var length;
  1305. if (charCode <= 0xFF) {
  1306. escapeChar = 'x';
  1307. length = 2;
  1308. } else {
  1309. escapeChar = 'u';
  1310. length = 4;
  1311. }
  1312. return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
  1313. }
  1314. function matchFailed(failure) {
  1315. if (pos < rightmostFailuresPos) {
  1316. return;
  1317. }
  1318. if (pos > rightmostFailuresPos) {
  1319. rightmostFailuresPos = pos;
  1320. rightmostFailuresExpected = [];
  1321. }
  1322. rightmostFailuresExpected.push(failure);
  1323. }
  1324. function parse_CRLF() {
  1325. var result0;
  1326. if (input.substr(pos, 2) === "\r\n") {
  1327. result0 = "\r\n";
  1328. pos += 2;
  1329. } else {
  1330. result0 = null;
  1331. if (reportFailures === 0) {
  1332. matchFailed("\"\\r\\n\"");
  1333. }
  1334. }
  1335. return result0;
  1336. }
  1337. function parse_DIGIT() {
  1338. var result0;
  1339. if (/^[0-9]/.test(input.charAt(pos))) {
  1340. result0 = input.charAt(pos);
  1341. pos++;
  1342. } else {
  1343. result0 = null;
  1344. if (reportFailures === 0) {
  1345. matchFailed("[0-9]");
  1346. }
  1347. }
  1348. return result0;
  1349. }
  1350. function parse_ALPHA() {
  1351. var result0;
  1352. if (/^[a-zA-Z]/.test(input.charAt(pos))) {
  1353. result0 = input.charAt(pos);
  1354. pos++;
  1355. } else {
  1356. result0 = null;
  1357. if (reportFailures === 0) {
  1358. matchFailed("[a-zA-Z]");
  1359. }
  1360. }
  1361. return result0;
  1362. }
  1363. function parse_HEXDIG() {
  1364. var result0;
  1365. if (/^[0-9a-fA-F]/.test(input.charAt(pos))) {
  1366. result0 = input.charAt(pos);
  1367. pos++;
  1368. } else {
  1369. result0 = null;
  1370. if (reportFailures === 0) {
  1371. matchFailed("[0-9a-fA-F]");
  1372. }
  1373. }
  1374. return result0;
  1375. }
  1376. function parse_WSP() {
  1377. var result0;
  1378. result0 = parse_SP();
  1379. if (result0 === null) {
  1380. result0 = parse_HTAB();
  1381. }
  1382. return result0;
  1383. }
  1384. function parse_OCTET() {
  1385. var result0;
  1386. if (/^[\0-\xFF]/.test(input.charAt(pos))) {
  1387. result0 = input.charAt(pos);
  1388. pos++;
  1389. } else {
  1390. result0 = null;
  1391. if (reportFailures === 0) {
  1392. matchFailed("[\\0-\\xFF]");
  1393. }
  1394. }
  1395. return result0;
  1396. }
  1397. function parse_DQUOTE() {
  1398. var result0;
  1399. if (/^["]/.test(input.charAt(pos))) {
  1400. result0 = input.charAt(pos);
  1401. pos++;
  1402. } else {
  1403. result0 = null;
  1404. if (reportFailures === 0) {
  1405. matchFailed("[\"]");
  1406. }
  1407. }
  1408. return result0;
  1409. }
  1410. function parse_SP() {
  1411. var result0;
  1412. if (input.charCodeAt(pos) === 32) {
  1413. result0 = " ";
  1414. pos++;
  1415. } else {
  1416. result0 = null;
  1417. if (reportFailures === 0) {
  1418. matchFailed("\" \"");
  1419. }
  1420. }
  1421. return result0;
  1422. }
  1423. function parse_HTAB() {
  1424. var result0;
  1425. if (input.charCodeAt(pos) === 9) {
  1426. result0 = "\t";
  1427. pos++;
  1428. } else {
  1429. result0 = null;
  1430. if (reportFailures === 0) {
  1431. matchFailed("\"\\t\"");
  1432. }
  1433. }
  1434. return result0;
  1435. }
  1436. function parse_alphanum() {
  1437. var result0;
  1438. if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) {
  1439. result0 = input.charAt(pos);
  1440. pos++;
  1441. } else {
  1442. result0 = null;
  1443. if (reportFailures === 0) {
  1444. matchFailed("[a-zA-Z0-9]");
  1445. }
  1446. }
  1447. return result0;
  1448. }
  1449. function parse_reserved() {
  1450. var result0;
  1451. if (input.charCodeAt(pos) === 59) {
  1452. result0 = ";";
  1453. pos++;
  1454. } else {
  1455. result0 = null;
  1456. if (reportFailures === 0) {
  1457. matchFailed("\";\"");
  1458. }
  1459. }
  1460. if (result0 === null) {
  1461. if (input.charCodeAt(pos) === 47) {
  1462. result0 = "/";
  1463. pos++;
  1464. } else {
  1465. result0 = null;
  1466. if (reportFailures === 0) {
  1467. matchFailed("\"/\"");
  1468. }
  1469. }
  1470. if (result0 === null) {
  1471. if (input.charCodeAt(pos) === 63) {
  1472. result0 = "?";
  1473. pos++;
  1474. } else {
  1475. result0 = null;
  1476. if (reportFailures === 0) {
  1477. matchFailed("\"?\"");
  1478. }
  1479. }
  1480. if (result0 === null) {
  1481. if (input.charCodeAt(pos) === 58) {
  1482. result0 = ":";
  1483. pos++;
  1484. } else {
  1485. result0 = null;
  1486. if (reportFailures === 0) {
  1487. matchFailed("\":\"");
  1488. }
  1489. }
  1490. if (result0 === null) {
  1491. if (input.charCodeAt(pos) === 64) {
  1492. result0 = "@";
  1493. pos++;
  1494. } else {
  1495. result0 = null;
  1496. if (reportFailures === 0) {
  1497. matchFailed("\"@\"");
  1498. }
  1499. }
  1500. if (result0 === null) {
  1501. if (input.charCodeAt(pos) === 38) {
  1502. result0 = "&";
  1503. pos++;
  1504. } else {
  1505. result0 = null;
  1506. if (reportFailures === 0) {
  1507. matchFailed("\"&\"");
  1508. }
  1509. }
  1510. if (result0 === null) {
  1511. if (input.charCodeAt(pos) === 61) {
  1512. result0 = "=";
  1513. pos++;
  1514. } else {
  1515. result0 = null;
  1516. if (reportFailures === 0) {
  1517. matchFailed("\"=\"");
  1518. }
  1519. }
  1520. if (result0 === null) {
  1521. if (input.charCodeAt(pos) === 43) {
  1522. result0 = "+";
  1523. pos++;
  1524. } else {
  1525. result0 = null;
  1526. if (reportFailures === 0) {
  1527. matchFailed("\"+\"");
  1528. }
  1529. }
  1530. if (result0 === null) {
  1531. if (input.charCodeAt(pos) === 36) {
  1532. result0 = "$";
  1533. pos++;
  1534. } else {
  1535. result0 = null;
  1536. if (reportFailures === 0) {
  1537. matchFailed("\"$\"");
  1538. }
  1539. }
  1540. if (result0 === null) {
  1541. if (input.charCodeAt(pos) === 44) {
  1542. result0 = ",";
  1543. pos++;
  1544. } else {
  1545. result0 = null;
  1546. if (reportFailures === 0) {
  1547. matchFailed("\",\"");
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. }
  1558. }
  1559. return result0;
  1560. }
  1561. function parse_unreserved() {
  1562. var result0;
  1563. result0 = parse_alphanum();
  1564. if (result0 === null) {
  1565. result0 = parse_mark();
  1566. }
  1567. return result0;
  1568. }
  1569. function parse_mark() {
  1570. var result0;
  1571. if (input.charCodeAt(pos) === 45) {
  1572. result0 = "-";
  1573. pos++;
  1574. } else {
  1575. result0 = null;
  1576. if (reportFailures === 0) {
  1577. matchFailed("\"-\"");
  1578. }
  1579. }
  1580. if (result0 === null) {
  1581. if (input.charCodeAt(pos) === 95) {
  1582. result0 = "_";
  1583. pos++;
  1584. } else {
  1585. result0 = null;
  1586. if (reportFailures === 0) {
  1587. matchFailed("\"_\"");
  1588. }
  1589. }
  1590. if (result0 === null) {
  1591. if (input.charCodeAt(pos) === 46) {
  1592. result0 = ".";
  1593. pos++;
  1594. } else {
  1595. result0 = null;
  1596. if (reportFailures === 0) {
  1597. matchFailed("\".\"");
  1598. }
  1599. }
  1600. if (result0 === null) {
  1601. if (input.charCodeAt(pos) === 33) {
  1602. result0 = "!";
  1603. pos++;
  1604. } else {
  1605. result0 = null;
  1606. if (reportFailures === 0) {
  1607. matchFailed("\"!\"");
  1608. }
  1609. }
  1610. if (result0 === null) {
  1611. if (input.charCodeAt(pos) === 126) {
  1612. result0 = "~";
  1613. pos++;
  1614. } else {
  1615. result0 = null;
  1616. if (reportFailures === 0) {
  1617. matchFailed("\"~\"");
  1618. }
  1619. }
  1620. if (result0 === null) {
  1621. if (input.charCodeAt(pos) === 42) {
  1622. result0 = "*";
  1623. pos++;
  1624. } else {
  1625. result0 = null;
  1626. if (reportFailures === 0) {
  1627. matchFailed("\"*\"");
  1628. }
  1629. }
  1630. if (result0 === null) {
  1631. if (input.charCodeAt(pos) === 39) {
  1632. result0 = "'";
  1633. pos++;
  1634. } else {
  1635. result0 = null;
  1636. if (reportFailures === 0) {
  1637. matchFailed("\"'\"");
  1638. }
  1639. }
  1640. if (result0 === null) {
  1641. if (input.charCodeAt(pos) === 40) {
  1642. result0 = "(";
  1643. pos++;
  1644. } else {
  1645. result0 = null;
  1646. if (reportFailures === 0) {
  1647. matchFailed("\"(\"");
  1648. }
  1649. }
  1650. if (result0 === null) {
  1651. if (input.charCodeAt(pos) === 41) {
  1652. result0 = ")";
  1653. pos++;
  1654. } else {
  1655. result0 = null;
  1656. if (reportFailures === 0) {
  1657. matchFailed("\")\"");
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. }
  1667. }
  1668. return result0;
  1669. }
  1670. function parse_escaped() {
  1671. var result0, result1, result2;
  1672. var pos0, pos1;
  1673. pos0 = pos;
  1674. pos1 = pos;
  1675. if (input.charCodeAt(pos) === 37) {
  1676. result0 = "%";
  1677. pos++;
  1678. } else {
  1679. result0 = null;
  1680. if (reportFailures === 0) {
  1681. matchFailed("\"%\"");
  1682. }
  1683. }
  1684. if (result0 !== null) {
  1685. result1 = parse_HEXDIG();
  1686. if (result1 !== null) {
  1687. result2 = parse_HEXDIG();
  1688. if (result2 !== null) {
  1689. result0 = [result0, result1, result2];
  1690. } else {
  1691. result0 = null;
  1692. pos = pos1;
  1693. }
  1694. } else {
  1695. result0 = null;
  1696. pos = pos1;
  1697. }
  1698. } else {
  1699. result0 = null;
  1700. pos = pos1;
  1701. }
  1702. if (result0 !== null) {
  1703. result0 = function (offset, escaped) {
  1704. return escaped.join('');
  1705. }(pos0, result0);
  1706. }
  1707. if (result0 === null) {
  1708. pos = pos0;
  1709. }
  1710. return result0;
  1711. }
  1712. function parse_LWS() {
  1713. var result0, result1, result2;
  1714. var pos0, pos1, pos2;
  1715. pos0 = pos;
  1716. pos1 = pos;
  1717. pos2 = pos;
  1718. result0 = [];
  1719. result1 = parse_WSP();
  1720. while (result1 !== null) {
  1721. result0.push(result1);
  1722. result1 = parse_WSP();
  1723. }
  1724. if (result0 !== null) {
  1725. result1 = parse_CRLF();
  1726. if (result1 !== null) {
  1727. result0 = [result0, result1];
  1728. } else {
  1729. result0 = null;
  1730. pos = pos2;
  1731. }
  1732. } else {
  1733. result0 = null;
  1734. pos = pos2;
  1735. }
  1736. result0 = result0 !== null ? result0 : "";
  1737. if (result0 !== null) {
  1738. result2 = parse_WSP();
  1739. if (result2 !== null) {
  1740. result1 = [];
  1741. while (result2 !== null) {
  1742. result1.push(result2);
  1743. result2 = parse_WSP();
  1744. }
  1745. } else {
  1746. result1 = null;
  1747. }
  1748. if (result1 !== null) {
  1749. result0 = [result0, result1];
  1750. } else {
  1751. result0 = null;
  1752. pos = pos1;
  1753. }
  1754. } else {
  1755. result0 = null;
  1756. pos = pos1;
  1757. }
  1758. if (result0 !== null) {
  1759. result0 = function (offset) {
  1760. return " ";
  1761. }(pos0);
  1762. }
  1763. if (result0 === null) {
  1764. pos = pos0;
  1765. }
  1766. return result0;
  1767. }
  1768. function parse_SWS() {
  1769. var result0;
  1770. result0 = parse_LWS();
  1771. result0 = result0 !== null ? result0 : "";
  1772. return result0;
  1773. }
  1774. function parse_HCOLON() {
  1775. var result0, result1, result2;
  1776. var pos0, pos1;
  1777. pos0 = pos;
  1778. pos1 = pos;
  1779. result0 = [];
  1780. result1 = parse_SP();
  1781. if (result1 === null) {
  1782. result1 = parse_HTAB();
  1783. }
  1784. while (result1 !== null) {
  1785. result0.push(result1);
  1786. result1 = parse_SP();
  1787. if (result1 === null) {
  1788. result1 = parse_HTAB();
  1789. }
  1790. }
  1791. if (result0 !== null) {
  1792. if (input.charCodeAt(pos) === 58) {
  1793. result1 = ":";
  1794. pos++;
  1795. } else {
  1796. result1 = null;
  1797. if (reportFailures === 0) {
  1798. matchFailed("\":\"");
  1799. }
  1800. }
  1801. if (result1 !== null) {
  1802. result2 = parse_SWS();
  1803. if (result2 !== null) {
  1804. result0 = [result0, result1, result2];
  1805. } else {
  1806. result0 = null;
  1807. pos = pos1;
  1808. }
  1809. } else {
  1810. result0 = null;
  1811. pos = pos1;
  1812. }
  1813. } else {
  1814. result0 = null;
  1815. pos = pos1;
  1816. }
  1817. if (result0 !== null) {
  1818. result0 = function (offset) {
  1819. return ':';
  1820. }(pos0);
  1821. }
  1822. if (result0 === null) {
  1823. pos = pos0;
  1824. }
  1825. return result0;
  1826. }
  1827. function parse_TEXT_UTF8_TRIM() {
  1828. var result0, result1, result2, result3;
  1829. var pos0, pos1, pos2;
  1830. pos0 = pos;
  1831. pos1 = pos;
  1832. result1 = parse_TEXT_UTF8char();
  1833. if (result1 !== null) {
  1834. result0 = [];
  1835. while (result1 !== null) {
  1836. result0.push(result1);
  1837. result1 = parse_TEXT_UTF8char();
  1838. }
  1839. } else {
  1840. result0 = null;
  1841. }
  1842. if (result0 !== null) {
  1843. result1 = [];
  1844. pos2 = pos;
  1845. result2 = [];
  1846. result3 = parse_LWS();
  1847. while (result3 !== null) {
  1848. result2.push(result3);
  1849. result3 = parse_LWS();
  1850. }
  1851. if (result2 !== null) {
  1852. result3 = parse_TEXT_UTF8char();
  1853. if (result3 !== null) {
  1854. result2 = [result2, result3];
  1855. } else {
  1856. result2 = null;
  1857. pos = pos2;
  1858. }
  1859. } else {
  1860. result2 = null;
  1861. pos = pos2;
  1862. }
  1863. while (result2 !== null) {
  1864. result1.push(result2);
  1865. pos2 = pos;
  1866. result2 = [];
  1867. result3 = parse_LWS();
  1868. while (result3 !== null) {
  1869. result2.push(result3);
  1870. result3 = parse_LWS();
  1871. }
  1872. if (result2 !== null) {
  1873. result3 = parse_TEXT_UTF8char();
  1874. if (result3 !== null) {
  1875. result2 = [result2, result3];
  1876. } else {
  1877. result2 = null;
  1878. pos = pos2;
  1879. }
  1880. } else {
  1881. result2 = null;
  1882. pos = pos2;
  1883. }
  1884. }
  1885. if (result1 !== null) {
  1886. result0 = [result0, result1];
  1887. } else {
  1888. result0 = null;
  1889. pos = pos1;
  1890. }
  1891. } else {
  1892. result0 = null;
  1893. pos = pos1;
  1894. }
  1895. if (result0 !== null) {
  1896. result0 = function (offset) {
  1897. return input.substring(pos, offset);
  1898. }(pos0);
  1899. }
  1900. if (result0 === null) {
  1901. pos = pos0;
  1902. }
  1903. return result0;
  1904. }
  1905. function parse_TEXT_UTF8char() {
  1906. var result0;
  1907. if (/^[!-~]/.test(input.charAt(pos))) {
  1908. result0 = input.charAt(pos);
  1909. pos++;
  1910. } else {
  1911. result0 = null;
  1912. if (reportFailures === 0) {
  1913. matchFailed("[!-~]");
  1914. }
  1915. }
  1916. if (result0 === null) {
  1917. result0 = parse_UTF8_NONASCII();
  1918. }
  1919. return result0;
  1920. }
  1921. function parse_UTF8_NONASCII() {
  1922. var result0;
  1923. if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) {
  1924. result0 = input.charAt(pos);
  1925. pos++;
  1926. } else {
  1927. result0 = null;
  1928. if (reportFailures === 0) {
  1929. matchFailed("[\\x80-\\uFFFF]");
  1930. }
  1931. }
  1932. return result0;
  1933. }
  1934. function parse_UTF8_CONT() {
  1935. var result0;
  1936. if (/^[\x80-\xBF]/.test(input.charAt(pos))) {
  1937. result0 = input.charAt(pos);
  1938. pos++;
  1939. } else {
  1940. result0 = null;
  1941. if (reportFailures === 0) {
  1942. matchFailed("[\\x80-\\xBF]");
  1943. }
  1944. }
  1945. return result0;
  1946. }
  1947. function parse_LHEX() {
  1948. var result0;
  1949. result0 = parse_DIGIT();
  1950. if (result0 === null) {
  1951. if (/^[a-f]/.test(input.charAt(pos))) {
  1952. result0 = input.charAt(pos);
  1953. pos++;
  1954. } else {
  1955. result0 = null;
  1956. if (reportFailures === 0) {
  1957. matchFailed("[a-f]");
  1958. }
  1959. }
  1960. }
  1961. return result0;
  1962. }
  1963. function parse_token() {
  1964. var result0, result1;
  1965. var pos0;
  1966. pos0 = pos;
  1967. result1 = parse_alphanum();
  1968. if (result1 === null) {
  1969. if (input.charCodeAt(pos) === 45) {
  1970. result1 = "-";
  1971. pos++;
  1972. } else {
  1973. result1 = null;
  1974. if (reportFailures === 0) {
  1975. matchFailed("\"-\"");
  1976. }
  1977. }
  1978. if (result1 === null) {
  1979. if (input.charCodeAt(pos) === 46) {
  1980. result1 = ".";
  1981. pos++;
  1982. } else {
  1983. result1 = null;
  1984. if (reportFailures === 0) {
  1985. matchFailed("\".\"");
  1986. }
  1987. }
  1988. if (result1 === null) {
  1989. if (input.charCodeAt(pos) === 33) {
  1990. result1 = "!";
  1991. pos++;
  1992. } else {
  1993. result1 = null;
  1994. if (reportFailures === 0) {
  1995. matchFailed("\"!\"");
  1996. }
  1997. }
  1998. if (result1 === null) {
  1999. if (input.charCodeAt(pos) === 37) {
  2000. result1 = "%";
  2001. pos++;
  2002. } else {
  2003. result1 = null;
  2004. if (reportFailures === 0) {
  2005. matchFailed("\"%\"");
  2006. }
  2007. }
  2008. if (result1 === null) {
  2009. if (input.charCodeAt(pos) === 42) {
  2010. result1 = "*";
  2011. pos++;
  2012. } else {
  2013. result1 = null;
  2014. if (reportFailures === 0) {
  2015. matchFailed("\"*\"");
  2016. }
  2017. }
  2018. if (result1 === null) {
  2019. if (input.charCodeAt(pos) === 95) {
  2020. result1 = "_";
  2021. pos++;
  2022. } else {
  2023. result1 = null;
  2024. if (reportFailures === 0) {
  2025. matchFailed("\"_\"");
  2026. }
  2027. }
  2028. if (result1 === null) {
  2029. if (input.charCodeAt(pos) === 43) {
  2030. result1 = "+";
  2031. pos++;
  2032. } else {
  2033. result1 = null;
  2034. if (reportFailures === 0) {
  2035. matchFailed("\"+\"");
  2036. }
  2037. }
  2038. if (result1 === null) {
  2039. if (input.charCodeAt(pos) === 96) {
  2040. result1 = "`";
  2041. pos++;
  2042. } else {
  2043. result1 = null;
  2044. if (reportFailures === 0) {
  2045. matchFailed("\"`\"");
  2046. }
  2047. }
  2048. if (result1 === null) {
  2049. if (input.charCodeAt(pos) === 39) {
  2050. result1 = "'";
  2051. pos++;
  2052. } else {
  2053. result1 = null;
  2054. if (reportFailures === 0) {
  2055. matchFailed("\"'\"");
  2056. }
  2057. }
  2058. if (result1 === null) {
  2059. if (input.charCodeAt(pos) === 126) {
  2060. result1 = "~";
  2061. pos++;
  2062. } else {
  2063. result1 = null;
  2064. if (reportFailures === 0) {
  2065. matchFailed("\"~\"");
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. }
  2073. }
  2074. }
  2075. }
  2076. }
  2077. }
  2078. if (result1 !== null) {
  2079. result0 = [];
  2080. while (result1 !== null) {
  2081. result0.push(result1);
  2082. result1 = parse_alphanum();
  2083. if (result1 === null) {
  2084. if (input.charCodeAt(pos) === 45) {
  2085. result1 = "-";
  2086. pos++;
  2087. } else {
  2088. result1 = null;
  2089. if (reportFailures === 0) {
  2090. matchFailed("\"-\"");
  2091. }
  2092. }
  2093. if (result1 === null) {
  2094. if (input.charCodeAt(pos) === 46) {
  2095. result1 = ".";
  2096. pos++;
  2097. } else {
  2098. result1 = null;
  2099. if (reportFailures === 0) {
  2100. matchFailed("\".\"");
  2101. }
  2102. }
  2103. if (result1 === null) {
  2104. if (input.charCodeAt(pos) === 33) {
  2105. result1 = "!";
  2106. pos++;
  2107. } else {
  2108. result1 = null;
  2109. if (reportFailures === 0) {
  2110. matchFailed("\"!\"");
  2111. }
  2112. }
  2113. if (result1 === null) {
  2114. if (input.charCodeAt(pos) === 37) {
  2115. result1 = "%";
  2116. pos++;
  2117. } else {
  2118. result1 = null;
  2119. if (reportFailures === 0) {
  2120. matchFailed("\"%\"");
  2121. }
  2122. }
  2123. if (result1 === null) {
  2124. if (input.charCodeAt(pos) === 42) {
  2125. result1 = "*";
  2126. pos++;
  2127. } else {
  2128. result1 = null;
  2129. if (reportFailures === 0) {
  2130. matchFailed("\"*\"");
  2131. }
  2132. }
  2133. if (result1 === null) {
  2134. if (input.charCodeAt(pos) === 95) {
  2135. result1 = "_";
  2136. pos++;
  2137. } else {
  2138. result1 = null;
  2139. if (reportFailures === 0) {
  2140. matchFailed("\"_\"");
  2141. }
  2142. }
  2143. if (result1 === null) {
  2144. if (input.charCodeAt(pos) === 43) {
  2145. result1 = "+";
  2146. pos++;
  2147. } else {
  2148. result1 = null;
  2149. if (reportFailures === 0) {
  2150. matchFailed("\"+\"");
  2151. }
  2152. }
  2153. if (result1 === null) {
  2154. if (input.charCodeAt(pos) === 96) {
  2155. result1 = "`";
  2156. pos++;
  2157. } else {
  2158. result1 = null;
  2159. if (reportFailures === 0) {
  2160. matchFailed("\"`\"");
  2161. }
  2162. }
  2163. if (result1 === null) {
  2164. if (input.charCodeAt(pos) === 39) {
  2165. result1 = "'";
  2166. pos++;
  2167. } else {
  2168. result1 = null;
  2169. if (reportFailures === 0) {
  2170. matchFailed("\"'\"");
  2171. }
  2172. }
  2173. if (result1 === null) {
  2174. if (input.charCodeAt(pos) === 126) {
  2175. result1 = "~";
  2176. pos++;
  2177. } else {
  2178. result1 = null;
  2179. if (reportFailures === 0) {
  2180. matchFailed("\"~\"");
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. }
  2192. }
  2193. }
  2194. } else {
  2195. result0 = null;
  2196. }
  2197. if (result0 !== null) {
  2198. result0 = function (offset) {
  2199. return input.substring(pos, offset);
  2200. }(pos0);
  2201. }
  2202. if (result0 === null) {
  2203. pos = pos0;
  2204. }
  2205. return result0;
  2206. }
  2207. function parse_token_nodot() {
  2208. var result0, result1;
  2209. var pos0;
  2210. pos0 = pos;
  2211. result1 = parse_alphanum();
  2212. if (result1 === null) {
  2213. if (input.charCodeAt(pos) === 45) {
  2214. result1 = "-";
  2215. pos++;
  2216. } else {
  2217. result1 = null;
  2218. if (reportFailures === 0) {
  2219. matchFailed("\"-\"");
  2220. }
  2221. }
  2222. if (result1 === null) {
  2223. if (input.charCodeAt(pos) === 33) {
  2224. result1 = "!";
  2225. pos++;
  2226. } else {
  2227. result1 = null;
  2228. if (reportFailures === 0) {
  2229. matchFailed("\"!\"");
  2230. }
  2231. }
  2232. if (result1 === null) {
  2233. if (input.charCodeAt(pos) === 37) {
  2234. result1 = "%";
  2235. pos++;
  2236. } else {
  2237. result1 = null;
  2238. if (reportFailures === 0) {
  2239. matchFailed("\"%\"");
  2240. }
  2241. }
  2242. if (result1 === null) {
  2243. if (input.charCodeAt(pos) === 42) {
  2244. result1 = "*";
  2245. pos++;
  2246. } else {
  2247. result1 = null;
  2248. if (reportFailures === 0) {
  2249. matchFailed("\"*\"");
  2250. }
  2251. }
  2252. if (result1 === null) {
  2253. if (input.charCodeAt(pos) === 95) {
  2254. result1 = "_";
  2255. pos++;
  2256. } else {
  2257. result1 = null;
  2258. if (reportFailures === 0) {
  2259. matchFailed("\"_\"");
  2260. }
  2261. }
  2262. if (result1 === null) {
  2263. if (input.charCodeAt(pos) === 43) {
  2264. result1 = "+";
  2265. pos++;
  2266. } else {
  2267. result1 = null;
  2268. if (reportFailures === 0) {
  2269. matchFailed("\"+\"");
  2270. }
  2271. }
  2272. if (result1 === null) {
  2273. if (input.charCodeAt(pos) === 96) {
  2274. result1 = "`";
  2275. pos++;
  2276. } else {
  2277. result1 = null;
  2278. if (reportFailures === 0) {
  2279. matchFailed("\"`\"");
  2280. }
  2281. }
  2282. if (result1 === null) {
  2283. if (input.charCodeAt(pos) === 39) {
  2284. result1 = "'";
  2285. pos++;
  2286. } else {
  2287. result1 = null;
  2288. if (reportFailures === 0) {
  2289. matchFailed("\"'\"");
  2290. }
  2291. }
  2292. if (result1 === null) {
  2293. if (input.charCodeAt(pos) === 126) {
  2294. result1 = "~";
  2295. pos++;
  2296. } else {
  2297. result1 = null;
  2298. if (reportFailures === 0) {
  2299. matchFailed("\"~\"");
  2300. }
  2301. }
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. if (result1 !== null) {
  2312. result0 = [];
  2313. while (result1 !== null) {
  2314. result0.push(result1);
  2315. result1 = parse_alphanum();
  2316. if (result1 === null) {
  2317. if (input.charCodeAt(pos) === 45) {
  2318. result1 = "-";
  2319. pos++;
  2320. } else {
  2321. result1 = null;
  2322. if (reportFailures === 0) {
  2323. matchFailed("\"-\"");
  2324. }
  2325. }
  2326. if (result1 === null) {
  2327. if (input.charCodeAt(pos) === 33) {
  2328. result1 = "!";
  2329. pos++;
  2330. } else {
  2331. result1 = null;
  2332. if (reportFailures === 0) {
  2333. matchFailed("\"!\"");
  2334. }
  2335. }
  2336. if (result1 === null) {
  2337. if (input.charCodeAt(pos) === 37) {
  2338. result1 = "%";
  2339. pos++;
  2340. } else {
  2341. result1 = null;
  2342. if (reportFailures === 0) {
  2343. matchFailed("\"%\"");
  2344. }
  2345. }
  2346. if (result1 === null) {
  2347. if (input.charCodeAt(pos) === 42) {
  2348. result1 = "*";
  2349. pos++;
  2350. } else {
  2351. result1 = null;
  2352. if (reportFailures === 0) {
  2353. matchFailed("\"*\"");
  2354. }
  2355. }
  2356. if (result1 === null) {
  2357. if (input.charCodeAt(pos) === 95) {
  2358. result1 = "_";
  2359. pos++;
  2360. } else {
  2361. result1 = null;
  2362. if (reportFailures === 0) {
  2363. matchFailed("\"_\"");
  2364. }
  2365. }
  2366. if (result1 === null) {
  2367. if (input.charCodeAt(pos) === 43) {
  2368. result1 = "+";
  2369. pos++;
  2370. } else {
  2371. result1 = null;
  2372. if (reportFailures === 0) {
  2373. matchFailed("\"+\"");
  2374. }
  2375. }
  2376. if (result1 === null) {
  2377. if (input.charCodeAt(pos) === 96) {
  2378. result1 = "`";
  2379. pos++;
  2380. } else {
  2381. result1 = null;
  2382. if (reportFailures === 0) {
  2383. matchFailed("\"`\"");
  2384. }
  2385. }
  2386. if (result1 === null) {
  2387. if (input.charCodeAt(pos) === 39) {
  2388. result1 = "'";
  2389. pos++;
  2390. } else {
  2391. result1 = null;
  2392. if (reportFailures === 0) {
  2393. matchFailed("\"'\"");
  2394. }
  2395. }
  2396. if (result1 === null) {
  2397. if (input.charCodeAt(pos) === 126) {
  2398. result1 = "~";
  2399. pos++;
  2400. } else {
  2401. result1 = null;
  2402. if (reportFailures === 0) {
  2403. matchFailed("\"~\"");
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. }
  2416. } else {
  2417. result0 = null;
  2418. }
  2419. if (result0 !== null) {
  2420. result0 = function (offset) {
  2421. return input.substring(pos, offset);
  2422. }(pos0);
  2423. }
  2424. if (result0 === null) {
  2425. pos = pos0;
  2426. }
  2427. return result0;
  2428. }
  2429. function parse_separators() {
  2430. var result0;
  2431. if (input.charCodeAt(pos) === 40) {
  2432. result0 = "(";
  2433. pos++;
  2434. } else {
  2435. result0 = null;
  2436. if (reportFailures === 0) {
  2437. matchFailed("\"(\"");
  2438. }
  2439. }
  2440. if (result0 === null) {
  2441. if (input.charCodeAt(pos) === 41) {
  2442. result0 = ")";
  2443. pos++;
  2444. } else {
  2445. result0 = null;
  2446. if (reportFailures === 0) {
  2447. matchFailed("\")\"");
  2448. }
  2449. }
  2450. if (result0 === null) {
  2451. if (input.charCodeAt(pos) === 60) {
  2452. result0 = "<";
  2453. pos++;
  2454. } else {
  2455. result0 = null;
  2456. if (reportFailures === 0) {
  2457. matchFailed("\"<\"");
  2458. }
  2459. }
  2460. if (result0 === null) {
  2461. if (input.charCodeAt(pos) === 62) {
  2462. result0 = ">";
  2463. pos++;
  2464. } else {
  2465. result0 = null;
  2466. if (reportFailures === 0) {
  2467. matchFailed("\">\"");
  2468. }
  2469. }
  2470. if (result0 === null) {
  2471. if (input.charCodeAt(pos) === 64) {
  2472. result0 = "@";
  2473. pos++;
  2474. } else {
  2475. result0 = null;
  2476. if (reportFailures === 0) {
  2477. matchFailed("\"@\"");
  2478. }
  2479. }
  2480. if (result0 === null) {
  2481. if (input.charCodeAt(pos) === 44) {
  2482. result0 = ",";
  2483. pos++;
  2484. } else {
  2485. result0 = null;
  2486. if (reportFailures === 0) {
  2487. matchFailed("\",\"");
  2488. }
  2489. }
  2490. if (result0 === null) {
  2491. if (input.charCodeAt(pos) === 59) {
  2492. result0 = ";";
  2493. pos++;
  2494. } else {
  2495. result0 = null;
  2496. if (reportFailures === 0) {
  2497. matchFailed("\";\"");
  2498. }
  2499. }
  2500. if (result0 === null) {
  2501. if (input.charCodeAt(pos) === 58) {
  2502. result0 = ":";
  2503. pos++;
  2504. } else {
  2505. result0 = null;
  2506. if (reportFailures === 0) {
  2507. matchFailed("\":\"");
  2508. }
  2509. }
  2510. if (result0 === null) {
  2511. if (input.charCodeAt(pos) === 92) {
  2512. result0 = "\\";
  2513. pos++;
  2514. } else {
  2515. result0 = null;
  2516. if (reportFailures === 0) {
  2517. matchFailed("\"\\\\\"");
  2518. }
  2519. }
  2520. if (result0 === null) {
  2521. result0 = parse_DQUOTE();
  2522. if (result0 === null) {
  2523. if (input.charCodeAt(pos) === 47) {
  2524. result0 = "/";
  2525. pos++;
  2526. } else {
  2527. result0 = null;
  2528. if (reportFailures === 0) {
  2529. matchFailed("\"/\"");
  2530. }
  2531. }
  2532. if (result0 === null) {
  2533. if (input.charCodeAt(pos) === 91) {
  2534. result0 = "[";
  2535. pos++;
  2536. } else {
  2537. result0 = null;
  2538. if (reportFailures === 0) {
  2539. matchFailed("\"[\"");
  2540. }
  2541. }
  2542. if (result0 === null) {
  2543. if (input.charCodeAt(pos) === 93) {
  2544. result0 = "]";
  2545. pos++;
  2546. } else {
  2547. result0 = null;
  2548. if (reportFailures === 0) {
  2549. matchFailed("\"]\"");
  2550. }
  2551. }
  2552. if (result0 === null) {
  2553. if (input.charCodeAt(pos) === 63) {
  2554. result0 = "?";
  2555. pos++;
  2556. } else {
  2557. result0 = null;
  2558. if (reportFailures === 0) {
  2559. matchFailed("\"?\"");
  2560. }
  2561. }
  2562. if (result0 === null) {
  2563. if (input.charCodeAt(pos) === 61) {
  2564. result0 = "=";
  2565. pos++;
  2566. } else {
  2567. result0 = null;
  2568. if (reportFailures === 0) {
  2569. matchFailed("\"=\"");
  2570. }
  2571. }
  2572. if (result0 === null) {
  2573. if (input.charCodeAt(pos) === 123) {
  2574. result0 = "{";
  2575. pos++;
  2576. } else {
  2577. result0 = null;
  2578. if (reportFailures === 0) {
  2579. matchFailed("\"{\"");
  2580. }
  2581. }
  2582. if (result0 === null) {
  2583. if (input.charCodeAt(pos) === 125) {
  2584. result0 = "}";
  2585. pos++;
  2586. } else {
  2587. result0 = null;
  2588. if (reportFailures === 0) {
  2589. matchFailed("\"}\"");
  2590. }
  2591. }
  2592. if (result0 === null) {
  2593. result0 = parse_SP();
  2594. if (result0 === null) {
  2595. result0 = parse_HTAB();
  2596. }
  2597. }
  2598. }
  2599. }
  2600. }
  2601. }
  2602. }
  2603. }
  2604. }
  2605. }
  2606. }
  2607. }
  2608. }
  2609. }
  2610. }
  2611. }
  2612. }
  2613. }
  2614. return result0;
  2615. }
  2616. function parse_word() {
  2617. var result0, result1;
  2618. var pos0;
  2619. pos0 = pos;
  2620. result1 = parse_alphanum();
  2621. if (result1 === null) {
  2622. if (input.charCodeAt(pos) === 45) {
  2623. result1 = "-";
  2624. pos++;
  2625. } else {
  2626. result1 = null;
  2627. if (reportFailures === 0) {
  2628. matchFailed("\"-\"");
  2629. }
  2630. }
  2631. if (result1 === null) {
  2632. if (input.charCodeAt(pos) === 46) {
  2633. result1 = ".";
  2634. pos++;
  2635. } else {
  2636. result1 = null;
  2637. if (reportFailures === 0) {
  2638. matchFailed("\".\"");
  2639. }
  2640. }
  2641. if (result1 === null) {
  2642. if (input.charCodeAt(pos) === 33) {
  2643. result1 = "!";
  2644. pos++;
  2645. } else {
  2646. result1 = null;
  2647. if (reportFailures === 0) {
  2648. matchFailed("\"!\"");
  2649. }
  2650. }
  2651. if (result1 === null) {
  2652. if (input.charCodeAt(pos) === 37) {
  2653. result1 = "%";
  2654. pos++;
  2655. } else {
  2656. result1 = null;
  2657. if (reportFailures === 0) {
  2658. matchFailed("\"%\"");
  2659. }
  2660. }
  2661. if (result1 === null) {
  2662. if (input.charCodeAt(pos) === 42) {
  2663. result1 = "*";
  2664. pos++;
  2665. } else {
  2666. result1 = null;
  2667. if (reportFailures === 0) {
  2668. matchFailed("\"*\"");
  2669. }
  2670. }
  2671. if (result1 === null) {
  2672. if (input.charCodeAt(pos) === 95) {
  2673. result1 = "_";
  2674. pos++;
  2675. } else {
  2676. result1 = null;
  2677. if (reportFailures === 0) {
  2678. matchFailed("\"_\"");
  2679. }
  2680. }
  2681. if (result1 === null) {
  2682. if (input.charCodeAt(pos) === 43) {
  2683. result1 = "+";
  2684. pos++;
  2685. } else {
  2686. result1 = null;
  2687. if (reportFailures === 0) {
  2688. matchFailed("\"+\"");
  2689. }
  2690. }
  2691. if (result1 === null) {
  2692. if (input.charCodeAt(pos) === 96) {
  2693. result1 = "`";
  2694. pos++;
  2695. } else {
  2696. result1 = null;
  2697. if (reportFailures === 0) {
  2698. matchFailed("\"`\"");
  2699. }
  2700. }
  2701. if (result1 === null) {
  2702. if (input.charCodeAt(pos) === 39) {
  2703. result1 = "'";
  2704. pos++;
  2705. } else {
  2706. result1 = null;
  2707. if (reportFailures === 0) {
  2708. matchFailed("\"'\"");
  2709. }
  2710. }
  2711. if (result1 === null) {
  2712. if (input.charCodeAt(pos) === 126) {
  2713. result1 = "~";
  2714. pos++;
  2715. } else {
  2716. result1 = null;
  2717. if (reportFailures === 0) {
  2718. matchFailed("\"~\"");
  2719. }
  2720. }
  2721. if (result1 === null) {
  2722. if (input.charCodeAt(pos) === 40) {
  2723. result1 = "(";
  2724. pos++;
  2725. } else {
  2726. result1 = null;
  2727. if (reportFailures === 0) {
  2728. matchFailed("\"(\"");
  2729. }
  2730. }
  2731. if (result1 === null) {
  2732. if (input.charCodeAt(pos) === 41) {
  2733. result1 = ")";
  2734. pos++;
  2735. } else {
  2736. result1 = null;
  2737. if (reportFailures === 0) {
  2738. matchFailed("\")\"");
  2739. }
  2740. }
  2741. if (result1 === null) {
  2742. if (input.charCodeAt(pos) === 60) {
  2743. result1 = "<";
  2744. pos++;
  2745. } else {
  2746. result1 = null;
  2747. if (reportFailures === 0) {
  2748. matchFailed("\"<\"");
  2749. }
  2750. }
  2751. if (result1 === null) {
  2752. if (input.charCodeAt(pos) === 62) {
  2753. result1 = ">";
  2754. pos++;
  2755. } else {
  2756. result1 = null;
  2757. if (reportFailures === 0) {
  2758. matchFailed("\">\"");
  2759. }
  2760. }
  2761. if (result1 === null) {
  2762. if (input.charCodeAt(pos) === 58) {
  2763. result1 = ":";
  2764. pos++;
  2765. } else {
  2766. result1 = null;
  2767. if (reportFailures === 0) {
  2768. matchFailed("\":\"");
  2769. }
  2770. }
  2771. if (result1 === null) {
  2772. if (input.charCodeAt(pos) === 92) {
  2773. result1 = "\\";
  2774. pos++;
  2775. } else {
  2776. result1 = null;
  2777. if (reportFailures === 0) {
  2778. matchFailed("\"\\\\\"");
  2779. }
  2780. }
  2781. if (result1 === null) {
  2782. result1 = parse_DQUOTE();
  2783. if (result1 === null) {
  2784. if (input.charCodeAt(pos) === 47) {
  2785. result1 = "/";
  2786. pos++;
  2787. } else {
  2788. result1 = null;
  2789. if (reportFailures === 0) {
  2790. matchFailed("\"/\"");
  2791. }
  2792. }
  2793. if (result1 === null) {
  2794. if (input.charCodeAt(pos) === 91) {
  2795. result1 = "[";
  2796. pos++;
  2797. } else {
  2798. result1 = null;
  2799. if (reportFailures === 0) {
  2800. matchFailed("\"[\"");
  2801. }
  2802. }
  2803. if (result1 === null) {
  2804. if (input.charCodeAt(pos) === 93) {
  2805. result1 = "]";
  2806. pos++;
  2807. } else {
  2808. result1 = null;
  2809. if (reportFailures === 0) {
  2810. matchFailed("\"]\"");
  2811. }
  2812. }
  2813. if (result1 === null) {
  2814. if (input.charCodeAt(pos) === 63) {
  2815. result1 = "?";
  2816. pos++;
  2817. } else {
  2818. result1 = null;
  2819. if (reportFailures === 0) {
  2820. matchFailed("\"?\"");
  2821. }
  2822. }
  2823. if (result1 === null) {
  2824. if (input.charCodeAt(pos) === 123) {
  2825. result1 = "{";
  2826. pos++;
  2827. } else {
  2828. result1 = null;
  2829. if (reportFailures === 0) {
  2830. matchFailed("\"{\"");
  2831. }
  2832. }
  2833. if (result1 === null) {
  2834. if (input.charCodeAt(pos) === 125) {
  2835. result1 = "}";
  2836. pos++;
  2837. } else {
  2838. result1 = null;
  2839. if (reportFailures === 0) {
  2840. matchFailed("\"}\"");
  2841. }
  2842. }
  2843. }
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. }
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. }
  2866. if (result1 !== null) {
  2867. result0 = [];
  2868. while (result1 !== null) {
  2869. result0.push(result1);
  2870. result1 = parse_alphanum();
  2871. if (result1 === null) {
  2872. if (input.charCodeAt(pos) === 45) {
  2873. result1 = "-";
  2874. pos++;
  2875. } else {
  2876. result1 = null;
  2877. if (reportFailures === 0) {
  2878. matchFailed("\"-\"");
  2879. }
  2880. }
  2881. if (result1 === null) {
  2882. if (input.charCodeAt(pos) === 46) {
  2883. result1 = ".";
  2884. pos++;
  2885. } else {
  2886. result1 = null;
  2887. if (reportFailures === 0) {
  2888. matchFailed("\".\"");
  2889. }
  2890. }
  2891. if (result1 === null) {
  2892. if (input.charCodeAt(pos) === 33) {
  2893. result1 = "!";
  2894. pos++;
  2895. } else {
  2896. result1 = null;
  2897. if (reportFailures === 0) {
  2898. matchFailed("\"!\"");
  2899. }
  2900. }
  2901. if (result1 === null) {
  2902. if (input.charCodeAt(pos) === 37) {
  2903. result1 = "%";
  2904. pos++;
  2905. } else {
  2906. result1 = null;
  2907. if (reportFailures === 0) {
  2908. matchFailed("\"%\"");
  2909. }
  2910. }
  2911. if (result1 === null) {
  2912. if (input.charCodeAt(pos) === 42) {
  2913. result1 = "*";
  2914. pos++;
  2915. } else {
  2916. result1 = null;
  2917. if (reportFailures === 0) {
  2918. matchFailed("\"*\"");
  2919. }
  2920. }
  2921. if (result1 === null) {
  2922. if (input.charCodeAt(pos) === 95) {
  2923. result1 = "_";
  2924. pos++;
  2925. } else {
  2926. result1 = null;
  2927. if (reportFailures === 0) {
  2928. matchFailed("\"_\"");
  2929. }
  2930. }
  2931. if (result1 === null) {
  2932. if (input.charCodeAt(pos) === 43) {
  2933. result1 = "+";
  2934. pos++;
  2935. } else {
  2936. result1 = null;
  2937. if (reportFailures === 0) {
  2938. matchFailed("\"+\"");
  2939. }
  2940. }
  2941. if (result1 === null) {
  2942. if (input.charCodeAt(pos) === 96) {
  2943. result1 = "`";
  2944. pos++;
  2945. } else {
  2946. result1 = null;
  2947. if (reportFailures === 0) {
  2948. matchFailed("\"`\"");
  2949. }
  2950. }
  2951. if (result1 === null) {
  2952. if (input.charCodeAt(pos) === 39) {
  2953. result1 = "'";
  2954. pos++;
  2955. } else {
  2956. result1 = null;
  2957. if (reportFailures === 0) {
  2958. matchFailed("\"'\"");
  2959. }
  2960. }
  2961. if (result1 === null) {
  2962. if (input.charCodeAt(pos) === 126) {
  2963. result1 = "~";
  2964. pos++;
  2965. } else {
  2966. result1 = null;
  2967. if (reportFailures === 0) {
  2968. matchFailed("\"~\"");
  2969. }
  2970. }
  2971. if (result1 === null) {
  2972. if (input.charCodeAt(pos) === 40) {
  2973. result1 = "(";
  2974. pos++;
  2975. } else {
  2976. result1 = null;
  2977. if (reportFailures === 0) {
  2978. matchFailed("\"(\"");
  2979. }
  2980. }
  2981. if (result1 === null) {
  2982. if (input.charCodeAt(pos) === 41) {
  2983. result1 = ")";
  2984. pos++;
  2985. } else {
  2986. result1 = null;
  2987. if (reportFailures === 0) {
  2988. matchFailed("\")\"");
  2989. }
  2990. }
  2991. if (result1 === null) {
  2992. if (input.charCodeAt(pos) === 60) {
  2993. result1 = "<";
  2994. pos++;
  2995. } else {
  2996. result1 = null;
  2997. if (reportFailures === 0) {
  2998. matchFailed("\"<\"");
  2999. }
  3000. }
  3001. if (result1 === null) {
  3002. if (input.charCodeAt(pos) === 62) {
  3003. result1 = ">";
  3004. pos++;
  3005. } else {
  3006. result1 = null;
  3007. if (reportFailures === 0) {
  3008. matchFailed("\">\"");
  3009. }
  3010. }
  3011. if (result1 === null) {
  3012. if (input.charCodeAt(pos) === 58) {
  3013. result1 = ":";
  3014. pos++;
  3015. } else {
  3016. result1 = null;
  3017. if (reportFailures === 0) {
  3018. matchFailed("\":\"");
  3019. }
  3020. }
  3021. if (result1 === null) {
  3022. if (input.charCodeAt(pos) === 92) {
  3023. result1 = "\\";
  3024. pos++;
  3025. } else {
  3026. result1 = null;
  3027. if (reportFailures === 0) {
  3028. matchFailed("\"\\\\\"");
  3029. }
  3030. }
  3031. if (result1 === null) {
  3032. result1 = parse_DQUOTE();
  3033. if (result1 === null) {
  3034. if (input.charCodeAt(pos) === 47) {
  3035. result1 = "/";
  3036. pos++;
  3037. } else {
  3038. result1 = null;
  3039. if (reportFailures === 0) {
  3040. matchFailed("\"/\"");
  3041. }
  3042. }
  3043. if (result1 === null) {
  3044. if (input.charCodeAt(pos) === 91) {
  3045. result1 = "[";
  3046. pos++;
  3047. } else {
  3048. result1 = null;
  3049. if (reportFailures === 0) {
  3050. matchFailed("\"[\"");
  3051. }
  3052. }
  3053. if (result1 === null) {
  3054. if (input.charCodeAt(pos) === 93) {
  3055. result1 = "]";
  3056. pos++;
  3057. } else {
  3058. result1 = null;
  3059. if (reportFailures === 0) {
  3060. matchFailed("\"]\"");
  3061. }
  3062. }
  3063. if (result1 === null) {
  3064. if (input.charCodeAt(pos) === 63) {
  3065. result1 = "?";
  3066. pos++;
  3067. } else {
  3068. result1 = null;
  3069. if (reportFailures === 0) {
  3070. matchFailed("\"?\"");
  3071. }
  3072. }
  3073. if (result1 === null) {
  3074. if (input.charCodeAt(pos) === 123) {
  3075. result1 = "{";
  3076. pos++;
  3077. } else {
  3078. result1 = null;
  3079. if (reportFailures === 0) {
  3080. matchFailed("\"{\"");
  3081. }
  3082. }
  3083. if (result1 === null) {
  3084. if (input.charCodeAt(pos) === 125) {
  3085. result1 = "}";
  3086. pos++;
  3087. } else {
  3088. result1 = null;
  3089. if (reportFailures === 0) {
  3090. matchFailed("\"}\"");
  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. }
  3116. }
  3117. } else {
  3118. result0 = null;
  3119. }
  3120. if (result0 !== null) {
  3121. result0 = function (offset) {
  3122. return input.substring(pos, offset);
  3123. }(pos0);
  3124. }
  3125. if (result0 === null) {
  3126. pos = pos0;
  3127. }
  3128. return result0;
  3129. }
  3130. function parse_STAR() {
  3131. var result0, result1, result2;
  3132. var pos0, pos1;
  3133. pos0 = pos;
  3134. pos1 = pos;
  3135. result0 = parse_SWS();
  3136. if (result0 !== null) {
  3137. if (input.charCodeAt(pos) === 42) {
  3138. result1 = "*";
  3139. pos++;
  3140. } else {
  3141. result1 = null;
  3142. if (reportFailures === 0) {
  3143. matchFailed("\"*\"");
  3144. }
  3145. }
  3146. if (result1 !== null) {
  3147. result2 = parse_SWS();
  3148. if (result2 !== null) {
  3149. result0 = [result0, result1, result2];
  3150. } else {
  3151. result0 = null;
  3152. pos = pos1;
  3153. }
  3154. } else {
  3155. result0 = null;
  3156. pos = pos1;
  3157. }
  3158. } else {
  3159. result0 = null;
  3160. pos = pos1;
  3161. }
  3162. if (result0 !== null) {
  3163. result0 = function (offset) {
  3164. return "*";
  3165. }(pos0);
  3166. }
  3167. if (result0 === null) {
  3168. pos = pos0;
  3169. }
  3170. return result0;
  3171. }
  3172. function parse_SLASH() {
  3173. var result0, result1, result2;
  3174. var pos0, pos1;
  3175. pos0 = pos;
  3176. pos1 = pos;
  3177. result0 = parse_SWS();
  3178. if (result0 !== null) {
  3179. if (input.charCodeAt(pos) === 47) {
  3180. result1 = "/";
  3181. pos++;
  3182. } else {
  3183. result1 = null;
  3184. if (reportFailures === 0) {
  3185. matchFailed("\"/\"");
  3186. }
  3187. }
  3188. if (result1 !== null) {
  3189. result2 = parse_SWS();
  3190. if (result2 !== null) {
  3191. result0 = [result0, result1, result2];
  3192. } else {
  3193. result0 = null;
  3194. pos = pos1;
  3195. }
  3196. } else {
  3197. result0 = null;
  3198. pos = pos1;
  3199. }
  3200. } else {
  3201. result0 = null;
  3202. pos = pos1;
  3203. }
  3204. if (result0 !== null) {
  3205. result0 = function (offset) {
  3206. return "/";
  3207. }(pos0);
  3208. }
  3209. if (result0 === null) {
  3210. pos = pos0;
  3211. }
  3212. return result0;
  3213. }
  3214. function parse_EQUAL() {
  3215. var result0, result1, result2;
  3216. var pos0, pos1;
  3217. pos0 = pos;
  3218. pos1 = pos;
  3219. result0 = parse_SWS();
  3220. if (result0 !== null) {
  3221. if (input.charCodeAt(pos) === 61) {
  3222. result1 = "=";
  3223. pos++;
  3224. } else {
  3225. result1 = null;
  3226. if (reportFailures === 0) {
  3227. matchFailed("\"=\"");
  3228. }
  3229. }
  3230. if (result1 !== null) {
  3231. result2 = parse_SWS();
  3232. if (result2 !== null) {
  3233. result0 = [result0, result1, result2];
  3234. } else {
  3235. result0 = null;
  3236. pos = pos1;
  3237. }
  3238. } else {
  3239. result0 = null;
  3240. pos = pos1;
  3241. }
  3242. } else {
  3243. result0 = null;
  3244. pos = pos1;
  3245. }
  3246. if (result0 !== null) {
  3247. result0 = function (offset) {
  3248. return "=";
  3249. }(pos0);
  3250. }
  3251. if (result0 === null) {
  3252. pos = pos0;
  3253. }
  3254. return result0;
  3255. }
  3256. function parse_LPAREN() {
  3257. var result0, result1, result2;
  3258. var pos0, pos1;
  3259. pos0 = pos;
  3260. pos1 = pos;
  3261. result0 = parse_SWS();
  3262. if (result0 !== null) {
  3263. if (input.charCodeAt(pos) === 40) {
  3264. result1 = "(";
  3265. pos++;
  3266. } else {
  3267. result1 = null;
  3268. if (reportFailures === 0) {
  3269. matchFailed("\"(\"");
  3270. }
  3271. }
  3272. if (result1 !== null) {
  3273. result2 = parse_SWS();
  3274. if (result2 !== null) {
  3275. result0 = [result0, result1, result2];
  3276. } else {
  3277. result0 = null;
  3278. pos = pos1;
  3279. }
  3280. } else {
  3281. result0 = null;
  3282. pos = pos1;
  3283. }
  3284. } else {
  3285. result0 = null;
  3286. pos = pos1;
  3287. }
  3288. if (result0 !== null) {
  3289. result0 = function (offset) {
  3290. return "(";
  3291. }(pos0);
  3292. }
  3293. if (result0 === null) {
  3294. pos = pos0;
  3295. }
  3296. return result0;
  3297. }
  3298. function parse_RPAREN() {
  3299. var result0, result1, result2;
  3300. var pos0, pos1;
  3301. pos0 = pos;
  3302. pos1 = pos;
  3303. result0 = parse_SWS();
  3304. if (result0 !== null) {
  3305. if (input.charCodeAt(pos) === 41) {
  3306. result1 = ")";
  3307. pos++;
  3308. } else {
  3309. result1 = null;
  3310. if (reportFailures === 0) {
  3311. matchFailed("\")\"");
  3312. }
  3313. }
  3314. if (result1 !== null) {
  3315. result2 = parse_SWS();
  3316. if (result2 !== null) {
  3317. result0 = [result0, result1, result2];
  3318. } else {
  3319. result0 = null;
  3320. pos = pos1;
  3321. }
  3322. } else {
  3323. result0 = null;
  3324. pos = pos1;
  3325. }
  3326. } else {
  3327. result0 = null;
  3328. pos = pos1;
  3329. }
  3330. if (result0 !== null) {
  3331. result0 = function (offset) {
  3332. return ")";
  3333. }(pos0);
  3334. }
  3335. if (result0 === null) {
  3336. pos = pos0;
  3337. }
  3338. return result0;
  3339. }
  3340. function parse_RAQUOT() {
  3341. var result0, result1;
  3342. var pos0, pos1;
  3343. pos0 = pos;
  3344. pos1 = pos;
  3345. if (input.charCodeAt(pos) === 62) {
  3346. result0 = ">";
  3347. pos++;
  3348. } else {
  3349. result0 = null;
  3350. if (reportFailures === 0) {
  3351. matchFailed("\">\"");
  3352. }
  3353. }
  3354. if (result0 !== null) {
  3355. result1 = parse_SWS();
  3356. if (result1 !== null) {
  3357. result0 = [result0, result1];
  3358. } else {
  3359. result0 = null;
  3360. pos = pos1;
  3361. }
  3362. } else {
  3363. result0 = null;
  3364. pos = pos1;
  3365. }
  3366. if (result0 !== null) {
  3367. result0 = function (offset) {
  3368. return ">";
  3369. }(pos0);
  3370. }
  3371. if (result0 === null) {
  3372. pos = pos0;
  3373. }
  3374. return result0;
  3375. }
  3376. function parse_LAQUOT() {
  3377. var result0, result1;
  3378. var pos0, pos1;
  3379. pos0 = pos;
  3380. pos1 = pos;
  3381. result0 = parse_SWS();
  3382. if (result0 !== null) {
  3383. if (input.charCodeAt(pos) === 60) {
  3384. result1 = "<";
  3385. pos++;
  3386. } else {
  3387. result1 = null;
  3388. if (reportFailures === 0) {
  3389. matchFailed("\"<\"");
  3390. }
  3391. }
  3392. if (result1 !== null) {
  3393. result0 = [result0, result1];
  3394. } else {
  3395. result0 = null;
  3396. pos = pos1;
  3397. }
  3398. } else {
  3399. result0 = null;
  3400. pos = pos1;
  3401. }
  3402. if (result0 !== null) {
  3403. result0 = function (offset) {
  3404. return "<";
  3405. }(pos0);
  3406. }
  3407. if (result0 === null) {
  3408. pos = pos0;
  3409. }
  3410. return result0;
  3411. }
  3412. function parse_COMMA() {
  3413. var result0, result1, result2;
  3414. var pos0, pos1;
  3415. pos0 = pos;
  3416. pos1 = pos;
  3417. result0 = parse_SWS();
  3418. if (result0 !== null) {
  3419. if (input.charCodeAt(pos) === 44) {
  3420. result1 = ",";
  3421. pos++;
  3422. } else {
  3423. result1 = null;
  3424. if (reportFailures === 0) {
  3425. matchFailed("\",\"");
  3426. }
  3427. }
  3428. if (result1 !== null) {
  3429. result2 = parse_SWS();
  3430. if (result2 !== null) {
  3431. result0 = [result0, result1, result2];
  3432. } else {
  3433. result0 = null;
  3434. pos = pos1;
  3435. }
  3436. } else {
  3437. result0 = null;
  3438. pos = pos1;
  3439. }
  3440. } else {
  3441. result0 = null;
  3442. pos = pos1;
  3443. }
  3444. if (result0 !== null) {
  3445. result0 = function (offset) {
  3446. return ",";
  3447. }(pos0);
  3448. }
  3449. if (result0 === null) {
  3450. pos = pos0;
  3451. }
  3452. return result0;
  3453. }
  3454. function parse_SEMI() {
  3455. var result0, result1, result2;
  3456. var pos0, pos1;
  3457. pos0 = pos;
  3458. pos1 = pos;
  3459. result0 = parse_SWS();
  3460. if (result0 !== null) {
  3461. if (input.charCodeAt(pos) === 59) {
  3462. result1 = ";";
  3463. pos++;
  3464. } else {
  3465. result1 = null;
  3466. if (reportFailures === 0) {
  3467. matchFailed("\";\"");
  3468. }
  3469. }
  3470. if (result1 !== null) {
  3471. result2 = parse_SWS();
  3472. if (result2 !== null) {
  3473. result0 = [result0, result1, result2];
  3474. } else {
  3475. result0 = null;
  3476. pos = pos1;
  3477. }
  3478. } else {
  3479. result0 = null;
  3480. pos = pos1;
  3481. }
  3482. } else {
  3483. result0 = null;
  3484. pos = pos1;
  3485. }
  3486. if (result0 !== null) {
  3487. result0 = function (offset) {
  3488. return ";";
  3489. }(pos0);
  3490. }
  3491. if (result0 === null) {
  3492. pos = pos0;
  3493. }
  3494. return result0;
  3495. }
  3496. function parse_COLON() {
  3497. var result0, result1, result2;
  3498. var pos0, pos1;
  3499. pos0 = pos;
  3500. pos1 = pos;
  3501. result0 = parse_SWS();
  3502. if (result0 !== null) {
  3503. if (input.charCodeAt(pos) === 58) {
  3504. result1 = ":";
  3505. pos++;
  3506. } else {
  3507. result1 = null;
  3508. if (reportFailures === 0) {
  3509. matchFailed("\":\"");
  3510. }
  3511. }
  3512. if (result1 !== null) {
  3513. result2 = parse_SWS();
  3514. if (result2 !== null) {
  3515. result0 = [result0, result1, result2];
  3516. } else {
  3517. result0 = null;
  3518. pos = pos1;
  3519. }
  3520. } else {
  3521. result0 = null;
  3522. pos = pos1;
  3523. }
  3524. } else {
  3525. result0 = null;
  3526. pos = pos1;
  3527. }
  3528. if (result0 !== null) {
  3529. result0 = function (offset) {
  3530. return ":";
  3531. }(pos0);
  3532. }
  3533. if (result0 === null) {
  3534. pos = pos0;
  3535. }
  3536. return result0;
  3537. }
  3538. function parse_LDQUOT() {
  3539. var result0, result1;
  3540. var pos0, pos1;
  3541. pos0 = pos;
  3542. pos1 = pos;
  3543. result0 = parse_SWS();
  3544. if (result0 !== null) {
  3545. result1 = parse_DQUOTE();
  3546. if (result1 !== null) {
  3547. result0 = [result0, result1];
  3548. } else {
  3549. result0 = null;
  3550. pos = pos1;
  3551. }
  3552. } else {
  3553. result0 = null;
  3554. pos = pos1;
  3555. }
  3556. if (result0 !== null) {
  3557. result0 = function (offset) {
  3558. return "\"";
  3559. }(pos0);
  3560. }
  3561. if (result0 === null) {
  3562. pos = pos0;
  3563. }
  3564. return result0;
  3565. }
  3566. function parse_RDQUOT() {
  3567. var result0, result1;
  3568. var pos0, pos1;
  3569. pos0 = pos;
  3570. pos1 = pos;
  3571. result0 = parse_DQUOTE();
  3572. if (result0 !== null) {
  3573. result1 = parse_SWS();
  3574. if (result1 !== null) {
  3575. result0 = [result0, result1];
  3576. } else {
  3577. result0 = null;
  3578. pos = pos1;
  3579. }
  3580. } else {
  3581. result0 = null;
  3582. pos = pos1;
  3583. }
  3584. if (result0 !== null) {
  3585. result0 = function (offset) {
  3586. return "\"";
  3587. }(pos0);
  3588. }
  3589. if (result0 === null) {
  3590. pos = pos0;
  3591. }
  3592. return result0;
  3593. }
  3594. function parse_comment() {
  3595. var result0, result1, result2;
  3596. var pos0;
  3597. pos0 = pos;
  3598. result0 = parse_LPAREN();
  3599. if (result0 !== null) {
  3600. result1 = [];
  3601. result2 = parse_ctext();
  3602. if (result2 === null) {
  3603. result2 = parse_quoted_pair();
  3604. if (result2 === null) {
  3605. result2 = parse_comment();
  3606. }
  3607. }
  3608. while (result2 !== null) {
  3609. result1.push(result2);
  3610. result2 = parse_ctext();
  3611. if (result2 === null) {
  3612. result2 = parse_quoted_pair();
  3613. if (result2 === null) {
  3614. result2 = parse_comment();
  3615. }
  3616. }
  3617. }
  3618. if (result1 !== null) {
  3619. result2 = parse_RPAREN();
  3620. if (result2 !== null) {
  3621. result0 = [result0, result1, result2];
  3622. } else {
  3623. result0 = null;
  3624. pos = pos0;
  3625. }
  3626. } else {
  3627. result0 = null;
  3628. pos = pos0;
  3629. }
  3630. } else {
  3631. result0 = null;
  3632. pos = pos0;
  3633. }
  3634. return result0;
  3635. }
  3636. function parse_ctext() {
  3637. var result0;
  3638. if (/^[!-']/.test(input.charAt(pos))) {
  3639. result0 = input.charAt(pos);
  3640. pos++;
  3641. } else {
  3642. result0 = null;
  3643. if (reportFailures === 0) {
  3644. matchFailed("[!-']");
  3645. }
  3646. }
  3647. if (result0 === null) {
  3648. if (/^[*-[]/.test(input.charAt(pos))) {
  3649. result0 = input.charAt(pos);
  3650. pos++;
  3651. } else {
  3652. result0 = null;
  3653. if (reportFailures === 0) {
  3654. matchFailed("[*-[]");
  3655. }
  3656. }
  3657. if (result0 === null) {
  3658. if (/^[\]-~]/.test(input.charAt(pos))) {
  3659. result0 = input.charAt(pos);
  3660. pos++;
  3661. } else {
  3662. result0 = null;
  3663. if (reportFailures === 0) {
  3664. matchFailed("[\\]-~]");
  3665. }
  3666. }
  3667. if (result0 === null) {
  3668. result0 = parse_UTF8_NONASCII();
  3669. if (result0 === null) {
  3670. result0 = parse_LWS();
  3671. }
  3672. }
  3673. }
  3674. }
  3675. return result0;
  3676. }
  3677. function parse_quoted_string() {
  3678. var result0, result1, result2, result3;
  3679. var pos0, pos1;
  3680. pos0 = pos;
  3681. pos1 = pos;
  3682. result0 = parse_SWS();
  3683. if (result0 !== null) {
  3684. result1 = parse_DQUOTE();
  3685. if (result1 !== null) {
  3686. result2 = [];
  3687. result3 = parse_qdtext();
  3688. if (result3 === null) {
  3689. result3 = parse_quoted_pair();
  3690. }
  3691. while (result3 !== null) {
  3692. result2.push(result3);
  3693. result3 = parse_qdtext();
  3694. if (result3 === null) {
  3695. result3 = parse_quoted_pair();
  3696. }
  3697. }
  3698. if (result2 !== null) {
  3699. result3 = parse_DQUOTE();
  3700. if (result3 !== null) {
  3701. result0 = [result0, result1, result2, result3];
  3702. } else {
  3703. result0 = null;
  3704. pos = pos1;
  3705. }
  3706. } else {
  3707. result0 = null;
  3708. pos = pos1;
  3709. }
  3710. } else {
  3711. result0 = null;
  3712. pos = pos1;
  3713. }
  3714. } else {
  3715. result0 = null;
  3716. pos = pos1;
  3717. }
  3718. if (result0 !== null) {
  3719. result0 = function (offset) {
  3720. return input.substring(pos, offset);
  3721. }(pos0);
  3722. }
  3723. if (result0 === null) {
  3724. pos = pos0;
  3725. }
  3726. return result0;
  3727. }
  3728. function parse_quoted_string_clean() {
  3729. var result0, result1, result2, result3;
  3730. var pos0, pos1;
  3731. pos0 = pos;
  3732. pos1 = pos;
  3733. result0 = parse_SWS();
  3734. if (result0 !== null) {
  3735. result1 = parse_DQUOTE();
  3736. if (result1 !== null) {
  3737. result2 = [];
  3738. result3 = parse_qdtext();
  3739. if (result3 === null) {
  3740. result3 = parse_quoted_pair();
  3741. }
  3742. while (result3 !== null) {
  3743. result2.push(result3);
  3744. result3 = parse_qdtext();
  3745. if (result3 === null) {
  3746. result3 = parse_quoted_pair();
  3747. }
  3748. }
  3749. if (result2 !== null) {
  3750. result3 = parse_DQUOTE();
  3751. if (result3 !== null) {
  3752. result0 = [result0, result1, result2, result3];
  3753. } else {
  3754. result0 = null;
  3755. pos = pos1;
  3756. }
  3757. } else {
  3758. result0 = null;
  3759. pos = pos1;
  3760. }
  3761. } else {
  3762. result0 = null;
  3763. pos = pos1;
  3764. }
  3765. } else {
  3766. result0 = null;
  3767. pos = pos1;
  3768. }
  3769. if (result0 !== null) {
  3770. result0 = function (offset) {
  3771. var trimmed = input.substring(pos, offset).trim();
  3772. return trimmed.substring(1, trimmed.length - 1) // remove outer quotes
  3773. .replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g, '$1');
  3774. }(pos0);
  3775. }
  3776. if (result0 === null) {
  3777. pos = pos0;
  3778. }
  3779. return result0;
  3780. }
  3781. function parse_qdtext() {
  3782. var result0;
  3783. result0 = parse_LWS();
  3784. if (result0 === null) {
  3785. if (input.charCodeAt(pos) === 33) {
  3786. result0 = "!";
  3787. pos++;
  3788. } else {
  3789. result0 = null;
  3790. if (reportFailures === 0) {
  3791. matchFailed("\"!\"");
  3792. }
  3793. }
  3794. if (result0 === null) {
  3795. if (/^[#-[]/.test(input.charAt(pos))) {
  3796. result0 = input.charAt(pos);
  3797. pos++;
  3798. } else {
  3799. result0 = null;
  3800. if (reportFailures === 0) {
  3801. matchFailed("[#-[]");
  3802. }
  3803. }
  3804. if (result0 === null) {
  3805. if (/^[\]-~]/.test(input.charAt(pos))) {
  3806. result0 = input.charAt(pos);
  3807. pos++;
  3808. } else {
  3809. result0 = null;
  3810. if (reportFailures === 0) {
  3811. matchFailed("[\\]-~]");
  3812. }
  3813. }
  3814. if (result0 === null) {
  3815. result0 = parse_UTF8_NONASCII();
  3816. }
  3817. }
  3818. }
  3819. }
  3820. return result0;
  3821. }
  3822. function parse_quoted_pair() {
  3823. var result0, result1;
  3824. var pos0;
  3825. pos0 = pos;
  3826. if (input.charCodeAt(pos) === 92) {
  3827. result0 = "\\";
  3828. pos++;
  3829. } else {
  3830. result0 = null;
  3831. if (reportFailures === 0) {
  3832. matchFailed("\"\\\\\"");
  3833. }
  3834. }
  3835. if (result0 !== null) {
  3836. if (/^[\0-\t]/.test(input.charAt(pos))) {
  3837. result1 = input.charAt(pos);
  3838. pos++;
  3839. } else {
  3840. result1 = null;
  3841. if (reportFailures === 0) {
  3842. matchFailed("[\\0-\\t]");
  3843. }
  3844. }
  3845. if (result1 === null) {
  3846. if (/^[\x0B-\f]/.test(input.charAt(pos))) {
  3847. result1 = input.charAt(pos);
  3848. pos++;
  3849. } else {
  3850. result1 = null;
  3851. if (reportFailures === 0) {
  3852. matchFailed("[\\x0B-\\f]");
  3853. }
  3854. }
  3855. if (result1 === null) {
  3856. if (/^[\x0E-]/.test(input.charAt(pos))) {
  3857. result1 = input.charAt(pos);
  3858. pos++;
  3859. } else {
  3860. result1 = null;
  3861. if (reportFailures === 0) {
  3862. matchFailed("[\\x0E-]");
  3863. }
  3864. }
  3865. }
  3866. }
  3867. if (result1 !== null) {
  3868. result0 = [result0, result1];
  3869. } else {
  3870. result0 = null;
  3871. pos = pos0;
  3872. }
  3873. } else {
  3874. result0 = null;
  3875. pos = pos0;
  3876. }
  3877. return result0;
  3878. }
  3879. function parse_SIP_URI_noparams() {
  3880. var result0, result1, result2, result3;
  3881. var pos0, pos1;
  3882. pos0 = pos;
  3883. pos1 = pos;
  3884. result0 = parse_uri_scheme();
  3885. if (result0 !== null) {
  3886. if (input.charCodeAt(pos) === 58) {
  3887. result1 = ":";
  3888. pos++;
  3889. } else {
  3890. result1 = null;
  3891. if (reportFailures === 0) {
  3892. matchFailed("\":\"");
  3893. }
  3894. }
  3895. if (result1 !== null) {
  3896. result2 = parse_userinfo();
  3897. result2 = result2 !== null ? result2 : "";
  3898. if (result2 !== null) {
  3899. result3 = parse_hostport();
  3900. if (result3 !== null) {
  3901. result0 = [result0, result1, result2, result3];
  3902. } else {
  3903. result0 = null;
  3904. pos = pos1;
  3905. }
  3906. } else {
  3907. result0 = null;
  3908. pos = pos1;
  3909. }
  3910. } else {
  3911. result0 = null;
  3912. pos = pos1;
  3913. }
  3914. } else {
  3915. result0 = null;
  3916. pos = pos1;
  3917. }
  3918. if (result0 !== null) {
  3919. result0 = function (offset) {
  3920. try {
  3921. data.uri = new URI(data.scheme, data.user, data.host, data.port);
  3922. delete data.scheme;
  3923. delete data.user;
  3924. delete data.host;
  3925. delete data.host_type;
  3926. delete data.port;
  3927. } catch (e) {
  3928. data = -1;
  3929. }
  3930. }(pos0);
  3931. }
  3932. if (result0 === null) {
  3933. pos = pos0;
  3934. }
  3935. return result0;
  3936. }
  3937. function parse_SIP_URI() {
  3938. var result0, result1, result2, result3, result4, result5;
  3939. var pos0, pos1;
  3940. pos0 = pos;
  3941. pos1 = pos;
  3942. result0 = parse_uri_scheme();
  3943. if (result0 !== null) {
  3944. if (input.charCodeAt(pos) === 58) {
  3945. result1 = ":";
  3946. pos++;
  3947. } else {
  3948. result1 = null;
  3949. if (reportFailures === 0) {
  3950. matchFailed("\":\"");
  3951. }
  3952. }
  3953. if (result1 !== null) {
  3954. result2 = parse_userinfo();
  3955. result2 = result2 !== null ? result2 : "";
  3956. if (result2 !== null) {
  3957. result3 = parse_hostport();
  3958. if (result3 !== null) {
  3959. result4 = parse_uri_parameters();
  3960. if (result4 !== null) {
  3961. result5 = parse_headers();
  3962. result5 = result5 !== null ? result5 : "";
  3963. if (result5 !== null) {
  3964. result0 = [result0, result1, result2, result3, result4, result5];
  3965. } else {
  3966. result0 = null;
  3967. pos = pos1;
  3968. }
  3969. } else {
  3970. result0 = null;
  3971. pos = pos1;
  3972. }
  3973. } else {
  3974. result0 = null;
  3975. pos = pos1;
  3976. }
  3977. } else {
  3978. result0 = null;
  3979. pos = pos1;
  3980. }
  3981. } else {
  3982. result0 = null;
  3983. pos = pos1;
  3984. }
  3985. } else {
  3986. result0 = null;
  3987. pos = pos1;
  3988. }
  3989. if (result0 !== null) {
  3990. result0 = function (offset) {
  3991. var header;
  3992. try {
  3993. data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers);
  3994. delete data.scheme;
  3995. delete data.user;
  3996. delete data.host;
  3997. delete data.host_type;
  3998. delete data.port;
  3999. delete data.uri_params;
  4000. if (startRule === 'SIP_URI') {
  4001. data = data.uri;
  4002. }
  4003. } catch (e) {
  4004. data = -1;
  4005. }
  4006. }(pos0);
  4007. }
  4008. if (result0 === null) {
  4009. pos = pos0;
  4010. }
  4011. return result0;
  4012. }
  4013. function parse_uri_scheme() {
  4014. var result0;
  4015. result0 = parse_uri_scheme_sips();
  4016. if (result0 === null) {
  4017. result0 = parse_uri_scheme_sip();
  4018. }
  4019. return result0;
  4020. }
  4021. function parse_uri_scheme_sips() {
  4022. var result0;
  4023. var pos0;
  4024. pos0 = pos;
  4025. if (input.substr(pos, 4).toLowerCase() === "sips") {
  4026. result0 = input.substr(pos, 4);
  4027. pos += 4;
  4028. } else {
  4029. result0 = null;
  4030. if (reportFailures === 0) {
  4031. matchFailed("\"sips\"");
  4032. }
  4033. }
  4034. if (result0 !== null) {
  4035. result0 = function (offset, scheme) {
  4036. data.scheme = scheme.toLowerCase();
  4037. }(pos0, result0);
  4038. }
  4039. if (result0 === null) {
  4040. pos = pos0;
  4041. }
  4042. return result0;
  4043. }
  4044. function parse_uri_scheme_sip() {
  4045. var result0;
  4046. var pos0;
  4047. pos0 = pos;
  4048. if (input.substr(pos, 3).toLowerCase() === "sip") {
  4049. result0 = input.substr(pos, 3);
  4050. pos += 3;
  4051. } else {
  4052. result0 = null;
  4053. if (reportFailures === 0) {
  4054. matchFailed("\"sip\"");
  4055. }
  4056. }
  4057. if (result0 !== null) {
  4058. result0 = function (offset, scheme) {
  4059. data.scheme = scheme.toLowerCase();
  4060. }(pos0, result0);
  4061. }
  4062. if (result0 === null) {
  4063. pos = pos0;
  4064. }
  4065. return result0;
  4066. }
  4067. function parse_userinfo() {
  4068. var result0, result1, result2;
  4069. var pos0, pos1, pos2;
  4070. pos0 = pos;
  4071. pos1 = pos;
  4072. result0 = parse_user();
  4073. if (result0 !== null) {
  4074. pos2 = pos;
  4075. if (input.charCodeAt(pos) === 58) {
  4076. result1 = ":";
  4077. pos++;
  4078. } else {
  4079. result1 = null;
  4080. if (reportFailures === 0) {
  4081. matchFailed("\":\"");
  4082. }
  4083. }
  4084. if (result1 !== null) {
  4085. result2 = parse_password();
  4086. if (result2 !== null) {
  4087. result1 = [result1, result2];
  4088. } else {
  4089. result1 = null;
  4090. pos = pos2;
  4091. }
  4092. } else {
  4093. result1 = null;
  4094. pos = pos2;
  4095. }
  4096. result1 = result1 !== null ? result1 : "";
  4097. if (result1 !== null) {
  4098. if (input.charCodeAt(pos) === 64) {
  4099. result2 = "@";
  4100. pos++;
  4101. } else {
  4102. result2 = null;
  4103. if (reportFailures === 0) {
  4104. matchFailed("\"@\"");
  4105. }
  4106. }
  4107. if (result2 !== null) {
  4108. result0 = [result0, result1, result2];
  4109. } else {
  4110. result0 = null;
  4111. pos = pos1;
  4112. }
  4113. } else {
  4114. result0 = null;
  4115. pos = pos1;
  4116. }
  4117. } else {
  4118. result0 = null;
  4119. pos = pos1;
  4120. }
  4121. if (result0 !== null) {
  4122. result0 = function (offset) {
  4123. data.user = decodeURIComponent(input.substring(pos - 1, offset));
  4124. }(pos0);
  4125. }
  4126. if (result0 === null) {
  4127. pos = pos0;
  4128. }
  4129. return result0;
  4130. }
  4131. function parse_user() {
  4132. var result0, result1;
  4133. result1 = parse_unreserved();
  4134. if (result1 === null) {
  4135. result1 = parse_escaped();
  4136. if (result1 === null) {
  4137. result1 = parse_user_unreserved();
  4138. }
  4139. }
  4140. if (result1 !== null) {
  4141. result0 = [];
  4142. while (result1 !== null) {
  4143. result0.push(result1);
  4144. result1 = parse_unreserved();
  4145. if (result1 === null) {
  4146. result1 = parse_escaped();
  4147. if (result1 === null) {
  4148. result1 = parse_user_unreserved();
  4149. }
  4150. }
  4151. }
  4152. } else {
  4153. result0 = null;
  4154. }
  4155. return result0;
  4156. }
  4157. function parse_user_unreserved() {
  4158. var result0;
  4159. if (input.charCodeAt(pos) === 38) {
  4160. result0 = "&";
  4161. pos++;
  4162. } else {
  4163. result0 = null;
  4164. if (reportFailures === 0) {
  4165. matchFailed("\"&\"");
  4166. }
  4167. }
  4168. if (result0 === null) {
  4169. if (input.charCodeAt(pos) === 61) {
  4170. result0 = "=";
  4171. pos++;
  4172. } else {
  4173. result0 = null;
  4174. if (reportFailures === 0) {
  4175. matchFailed("\"=\"");
  4176. }
  4177. }
  4178. if (result0 === null) {
  4179. if (input.charCodeAt(pos) === 43) {
  4180. result0 = "+";
  4181. pos++;
  4182. } else {
  4183. result0 = null;
  4184. if (reportFailures === 0) {
  4185. matchFailed("\"+\"");
  4186. }
  4187. }
  4188. if (result0 === null) {
  4189. if (input.charCodeAt(pos) === 36) {
  4190. result0 = "$";
  4191. pos++;
  4192. } else {
  4193. result0 = null;
  4194. if (reportFailures === 0) {
  4195. matchFailed("\"$\"");
  4196. }
  4197. }
  4198. if (result0 === null) {
  4199. if (input.charCodeAt(pos) === 44) {
  4200. result0 = ",";
  4201. pos++;
  4202. } else {
  4203. result0 = null;
  4204. if (reportFailures === 0) {
  4205. matchFailed("\",\"");
  4206. }
  4207. }
  4208. if (result0 === null) {
  4209. if (input.charCodeAt(pos) === 59) {
  4210. result0 = ";";
  4211. pos++;
  4212. } else {
  4213. result0 = null;
  4214. if (reportFailures === 0) {
  4215. matchFailed("\";\"");
  4216. }
  4217. }
  4218. if (result0 === null) {
  4219. if (input.charCodeAt(pos) === 63) {
  4220. result0 = "?";
  4221. pos++;
  4222. } else {
  4223. result0 = null;
  4224. if (reportFailures === 0) {
  4225. matchFailed("\"?\"");
  4226. }
  4227. }
  4228. if (result0 === null) {
  4229. if (input.charCodeAt(pos) === 47) {
  4230. result0 = "/";
  4231. pos++;
  4232. } else {
  4233. result0 = null;
  4234. if (reportFailures === 0) {
  4235. matchFailed("\"/\"");
  4236. }
  4237. }
  4238. }
  4239. }
  4240. }
  4241. }
  4242. }
  4243. }
  4244. }
  4245. return result0;
  4246. }
  4247. function parse_password() {
  4248. var result0, result1;
  4249. var pos0;
  4250. pos0 = pos;
  4251. result0 = [];
  4252. result1 = parse_unreserved();
  4253. if (result1 === null) {
  4254. result1 = parse_escaped();
  4255. if (result1 === null) {
  4256. if (input.charCodeAt(pos) === 38) {
  4257. result1 = "&";
  4258. pos++;
  4259. } else {
  4260. result1 = null;
  4261. if (reportFailures === 0) {
  4262. matchFailed("\"&\"");
  4263. }
  4264. }
  4265. if (result1 === null) {
  4266. if (input.charCodeAt(pos) === 61) {
  4267. result1 = "=";
  4268. pos++;
  4269. } else {
  4270. result1 = null;
  4271. if (reportFailures === 0) {
  4272. matchFailed("\"=\"");
  4273. }
  4274. }
  4275. if (result1 === null) {
  4276. if (input.charCodeAt(pos) === 43) {
  4277. result1 = "+";
  4278. pos++;
  4279. } else {
  4280. result1 = null;
  4281. if (reportFailures === 0) {
  4282. matchFailed("\"+\"");
  4283. }
  4284. }
  4285. if (result1 === null) {
  4286. if (input.charCodeAt(pos) === 36) {
  4287. result1 = "$";
  4288. pos++;
  4289. } else {
  4290. result1 = null;
  4291. if (reportFailures === 0) {
  4292. matchFailed("\"$\"");
  4293. }
  4294. }
  4295. if (result1 === null) {
  4296. if (input.charCodeAt(pos) === 44) {
  4297. result1 = ",";
  4298. pos++;
  4299. } else {
  4300. result1 = null;
  4301. if (reportFailures === 0) {
  4302. matchFailed("\",\"");
  4303. }
  4304. }
  4305. }
  4306. }
  4307. }
  4308. }
  4309. }
  4310. }
  4311. while (result1 !== null) {
  4312. result0.push(result1);
  4313. result1 = parse_unreserved();
  4314. if (result1 === null) {
  4315. result1 = parse_escaped();
  4316. if (result1 === null) {
  4317. if (input.charCodeAt(pos) === 38) {
  4318. result1 = "&";
  4319. pos++;
  4320. } else {
  4321. result1 = null;
  4322. if (reportFailures === 0) {
  4323. matchFailed("\"&\"");
  4324. }
  4325. }
  4326. if (result1 === null) {
  4327. if (input.charCodeAt(pos) === 61) {
  4328. result1 = "=";
  4329. pos++;
  4330. } else {
  4331. result1 = null;
  4332. if (reportFailures === 0) {
  4333. matchFailed("\"=\"");
  4334. }
  4335. }
  4336. if (result1 === null) {
  4337. if (input.charCodeAt(pos) === 43) {
  4338. result1 = "+";
  4339. pos++;
  4340. } else {
  4341. result1 = null;
  4342. if (reportFailures === 0) {
  4343. matchFailed("\"+\"");
  4344. }
  4345. }
  4346. if (result1 === null) {
  4347. if (input.charCodeAt(pos) === 36) {
  4348. result1 = "$";
  4349. pos++;
  4350. } else {
  4351. result1 = null;
  4352. if (reportFailures === 0) {
  4353. matchFailed("\"$\"");
  4354. }
  4355. }
  4356. if (result1 === null) {
  4357. if (input.charCodeAt(pos) === 44) {
  4358. result1 = ",";
  4359. pos++;
  4360. } else {
  4361. result1 = null;
  4362. if (reportFailures === 0) {
  4363. matchFailed("\",\"");
  4364. }
  4365. }
  4366. }
  4367. }
  4368. }
  4369. }
  4370. }
  4371. }
  4372. }
  4373. if (result0 !== null) {
  4374. result0 = function (offset) {
  4375. data.password = input.substring(pos, offset);
  4376. }(pos0);
  4377. }
  4378. if (result0 === null) {
  4379. pos = pos0;
  4380. }
  4381. return result0;
  4382. }
  4383. function parse_hostport() {
  4384. var result0, result1, result2;
  4385. var pos0, pos1;
  4386. pos0 = pos;
  4387. result0 = parse_host();
  4388. if (result0 !== null) {
  4389. pos1 = pos;
  4390. if (input.charCodeAt(pos) === 58) {
  4391. result1 = ":";
  4392. pos++;
  4393. } else {
  4394. result1 = null;
  4395. if (reportFailures === 0) {
  4396. matchFailed("\":\"");
  4397. }
  4398. }
  4399. if (result1 !== null) {
  4400. result2 = parse_port();
  4401. if (result2 !== null) {
  4402. result1 = [result1, result2];
  4403. } else {
  4404. result1 = null;
  4405. pos = pos1;
  4406. }
  4407. } else {
  4408. result1 = null;
  4409. pos = pos1;
  4410. }
  4411. result1 = result1 !== null ? result1 : "";
  4412. if (result1 !== null) {
  4413. result0 = [result0, result1];
  4414. } else {
  4415. result0 = null;
  4416. pos = pos0;
  4417. }
  4418. } else {
  4419. result0 = null;
  4420. pos = pos0;
  4421. }
  4422. return result0;
  4423. }
  4424. function parse_host() {
  4425. var result0;
  4426. var pos0;
  4427. pos0 = pos;
  4428. result0 = parse_hostname();
  4429. if (result0 === null) {
  4430. result0 = parse_IPv4address();
  4431. if (result0 === null) {
  4432. result0 = parse_IPv6reference();
  4433. }
  4434. }
  4435. if (result0 !== null) {
  4436. result0 = function (offset) {
  4437. data.host = input.substring(pos, offset).toLowerCase();
  4438. return data.host;
  4439. }(pos0);
  4440. }
  4441. if (result0 === null) {
  4442. pos = pos0;
  4443. }
  4444. return result0;
  4445. }
  4446. function parse_hostname() {
  4447. var result0, result1, result2;
  4448. var pos0, pos1, pos2;
  4449. pos0 = pos;
  4450. pos1 = pos;
  4451. result0 = [];
  4452. pos2 = pos;
  4453. result1 = parse_domainlabel();
  4454. if (result1 !== null) {
  4455. if (input.charCodeAt(pos) === 46) {
  4456. result2 = ".";
  4457. pos++;
  4458. } else {
  4459. result2 = null;
  4460. if (reportFailures === 0) {
  4461. matchFailed("\".\"");
  4462. }
  4463. }
  4464. if (result2 !== null) {
  4465. result1 = [result1, result2];
  4466. } else {
  4467. result1 = null;
  4468. pos = pos2;
  4469. }
  4470. } else {
  4471. result1 = null;
  4472. pos = pos2;
  4473. }
  4474. while (result1 !== null) {
  4475. result0.push(result1);
  4476. pos2 = pos;
  4477. result1 = parse_domainlabel();
  4478. if (result1 !== null) {
  4479. if (input.charCodeAt(pos) === 46) {
  4480. result2 = ".";
  4481. pos++;
  4482. } else {
  4483. result2 = null;
  4484. if (reportFailures === 0) {
  4485. matchFailed("\".\"");
  4486. }
  4487. }
  4488. if (result2 !== null) {
  4489. result1 = [result1, result2];
  4490. } else {
  4491. result1 = null;
  4492. pos = pos2;
  4493. }
  4494. } else {
  4495. result1 = null;
  4496. pos = pos2;
  4497. }
  4498. }
  4499. if (result0 !== null) {
  4500. result1 = parse_toplabel();
  4501. if (result1 !== null) {
  4502. if (input.charCodeAt(pos) === 46) {
  4503. result2 = ".";
  4504. pos++;
  4505. } else {
  4506. result2 = null;
  4507. if (reportFailures === 0) {
  4508. matchFailed("\".\"");
  4509. }
  4510. }
  4511. result2 = result2 !== null ? result2 : "";
  4512. if (result2 !== null) {
  4513. result0 = [result0, result1, result2];
  4514. } else {
  4515. result0 = null;
  4516. pos = pos1;
  4517. }
  4518. } else {
  4519. result0 = null;
  4520. pos = pos1;
  4521. }
  4522. } else {
  4523. result0 = null;
  4524. pos = pos1;
  4525. }
  4526. if (result0 !== null) {
  4527. result0 = function (offset) {
  4528. data.host_type = 'domain';
  4529. return input.substring(pos, offset);
  4530. }(pos0);
  4531. }
  4532. if (result0 === null) {
  4533. pos = pos0;
  4534. }
  4535. return result0;
  4536. }
  4537. function parse_domainlabel() {
  4538. var result0, result1, result2;
  4539. var pos0;
  4540. pos0 = pos;
  4541. result0 = parse_alphanum();
  4542. if (result0 !== null) {
  4543. result1 = [];
  4544. result2 = parse_alphanum();
  4545. if (result2 === null) {
  4546. if (input.charCodeAt(pos) === 45) {
  4547. result2 = "-";
  4548. pos++;
  4549. } else {
  4550. result2 = null;
  4551. if (reportFailures === 0) {
  4552. matchFailed("\"-\"");
  4553. }
  4554. }
  4555. if (result2 === null) {
  4556. if (input.charCodeAt(pos) === 95) {
  4557. result2 = "_";
  4558. pos++;
  4559. } else {
  4560. result2 = null;
  4561. if (reportFailures === 0) {
  4562. matchFailed("\"_\"");
  4563. }
  4564. }
  4565. }
  4566. }
  4567. while (result2 !== null) {
  4568. result1.push(result2);
  4569. result2 = parse_alphanum();
  4570. if (result2 === null) {
  4571. if (input.charCodeAt(pos) === 45) {
  4572. result2 = "-";
  4573. pos++;
  4574. } else {
  4575. result2 = null;
  4576. if (reportFailures === 0) {
  4577. matchFailed("\"-\"");
  4578. }
  4579. }
  4580. if (result2 === null) {
  4581. if (input.charCodeAt(pos) === 95) {
  4582. result2 = "_";
  4583. pos++;
  4584. } else {
  4585. result2 = null;
  4586. if (reportFailures === 0) {
  4587. matchFailed("\"_\"");
  4588. }
  4589. }
  4590. }
  4591. }
  4592. }
  4593. if (result1 !== null) {
  4594. result0 = [result0, result1];
  4595. } else {
  4596. result0 = null;
  4597. pos = pos0;
  4598. }
  4599. } else {
  4600. result0 = null;
  4601. pos = pos0;
  4602. }
  4603. return result0;
  4604. }
  4605. function parse_toplabel() {
  4606. var result0, result1, result2;
  4607. var pos0;
  4608. pos0 = pos;
  4609. result0 = parse_ALPHA();
  4610. if (result0 !== null) {
  4611. result1 = [];
  4612. result2 = parse_alphanum();
  4613. if (result2 === null) {
  4614. if (input.charCodeAt(pos) === 45) {
  4615. result2 = "-";
  4616. pos++;
  4617. } else {
  4618. result2 = null;
  4619. if (reportFailures === 0) {
  4620. matchFailed("\"-\"");
  4621. }
  4622. }
  4623. if (result2 === null) {
  4624. if (input.charCodeAt(pos) === 95) {
  4625. result2 = "_";
  4626. pos++;
  4627. } else {
  4628. result2 = null;
  4629. if (reportFailures === 0) {
  4630. matchFailed("\"_\"");
  4631. }
  4632. }
  4633. }
  4634. }
  4635. while (result2 !== null) {
  4636. result1.push(result2);
  4637. result2 = parse_alphanum();
  4638. if (result2 === null) {
  4639. if (input.charCodeAt(pos) === 45) {
  4640. result2 = "-";
  4641. pos++;
  4642. } else {
  4643. result2 = null;
  4644. if (reportFailures === 0) {
  4645. matchFailed("\"-\"");
  4646. }
  4647. }
  4648. if (result2 === null) {
  4649. if (input.charCodeAt(pos) === 95) {
  4650. result2 = "_";
  4651. pos++;
  4652. } else {
  4653. result2 = null;
  4654. if (reportFailures === 0) {
  4655. matchFailed("\"_\"");
  4656. }
  4657. }
  4658. }
  4659. }
  4660. }
  4661. if (result1 !== null) {
  4662. result0 = [result0, result1];
  4663. } else {
  4664. result0 = null;
  4665. pos = pos0;
  4666. }
  4667. } else {
  4668. result0 = null;
  4669. pos = pos0;
  4670. }
  4671. return result0;
  4672. }
  4673. function parse_IPv6reference() {
  4674. var result0, result1, result2;
  4675. var pos0, pos1;
  4676. pos0 = pos;
  4677. pos1 = pos;
  4678. if (input.charCodeAt(pos) === 91) {
  4679. result0 = "[";
  4680. pos++;
  4681. } else {
  4682. result0 = null;
  4683. if (reportFailures === 0) {
  4684. matchFailed("\"[\"");
  4685. }
  4686. }
  4687. if (result0 !== null) {
  4688. result1 = parse_IPv6address();
  4689. if (result1 !== null) {
  4690. if (input.charCodeAt(pos) === 93) {
  4691. result2 = "]";
  4692. pos++;
  4693. } else {
  4694. result2 = null;
  4695. if (reportFailures === 0) {
  4696. matchFailed("\"]\"");
  4697. }
  4698. }
  4699. if (result2 !== null) {
  4700. result0 = [result0, result1, result2];
  4701. } else {
  4702. result0 = null;
  4703. pos = pos1;
  4704. }
  4705. } else {
  4706. result0 = null;
  4707. pos = pos1;
  4708. }
  4709. } else {
  4710. result0 = null;
  4711. pos = pos1;
  4712. }
  4713. if (result0 !== null) {
  4714. result0 = function (offset) {
  4715. data.host_type = 'IPv6';
  4716. return input.substring(pos, offset);
  4717. }(pos0);
  4718. }
  4719. if (result0 === null) {
  4720. pos = pos0;
  4721. }
  4722. return result0;
  4723. }
  4724. function parse_IPv6address() {
  4725. var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12;
  4726. var pos0, pos1, pos2;
  4727. pos0 = pos;
  4728. pos1 = pos;
  4729. result0 = parse_h16();
  4730. if (result0 !== null) {
  4731. if (input.charCodeAt(pos) === 58) {
  4732. result1 = ":";
  4733. pos++;
  4734. } else {
  4735. result1 = null;
  4736. if (reportFailures === 0) {
  4737. matchFailed("\":\"");
  4738. }
  4739. }
  4740. if (result1 !== null) {
  4741. result2 = parse_h16();
  4742. if (result2 !== null) {
  4743. if (input.charCodeAt(pos) === 58) {
  4744. result3 = ":";
  4745. pos++;
  4746. } else {
  4747. result3 = null;
  4748. if (reportFailures === 0) {
  4749. matchFailed("\":\"");
  4750. }
  4751. }
  4752. if (result3 !== null) {
  4753. result4 = parse_h16();
  4754. if (result4 !== null) {
  4755. if (input.charCodeAt(pos) === 58) {
  4756. result5 = ":";
  4757. pos++;
  4758. } else {
  4759. result5 = null;
  4760. if (reportFailures === 0) {
  4761. matchFailed("\":\"");
  4762. }
  4763. }
  4764. if (result5 !== null) {
  4765. result6 = parse_h16();
  4766. if (result6 !== null) {
  4767. if (input.charCodeAt(pos) === 58) {
  4768. result7 = ":";
  4769. pos++;
  4770. } else {
  4771. result7 = null;
  4772. if (reportFailures === 0) {
  4773. matchFailed("\":\"");
  4774. }
  4775. }
  4776. if (result7 !== null) {
  4777. result8 = parse_h16();
  4778. if (result8 !== null) {
  4779. if (input.charCodeAt(pos) === 58) {
  4780. result9 = ":";
  4781. pos++;
  4782. } else {
  4783. result9 = null;
  4784. if (reportFailures === 0) {
  4785. matchFailed("\":\"");
  4786. }
  4787. }
  4788. if (result9 !== null) {
  4789. result10 = parse_h16();
  4790. if (result10 !== null) {
  4791. if (input.charCodeAt(pos) === 58) {
  4792. result11 = ":";
  4793. pos++;
  4794. } else {
  4795. result11 = null;
  4796. if (reportFailures === 0) {
  4797. matchFailed("\":\"");
  4798. }
  4799. }
  4800. if (result11 !== null) {
  4801. result12 = parse_ls32();
  4802. if (result12 !== null) {
  4803. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
  4804. } else {
  4805. result0 = null;
  4806. pos = pos1;
  4807. }
  4808. } else {
  4809. result0 = null;
  4810. pos = pos1;
  4811. }
  4812. } else {
  4813. result0 = null;
  4814. pos = pos1;
  4815. }
  4816. } else {
  4817. result0 = null;
  4818. pos = pos1;
  4819. }
  4820. } else {
  4821. result0 = null;
  4822. pos = pos1;
  4823. }
  4824. } else {
  4825. result0 = null;
  4826. pos = pos1;
  4827. }
  4828. } else {
  4829. result0 = null;
  4830. pos = pos1;
  4831. }
  4832. } else {
  4833. result0 = null;
  4834. pos = pos1;
  4835. }
  4836. } else {
  4837. result0 = null;
  4838. pos = pos1;
  4839. }
  4840. } else {
  4841. result0 = null;
  4842. pos = pos1;
  4843. }
  4844. } else {
  4845. result0 = null;
  4846. pos = pos1;
  4847. }
  4848. } else {
  4849. result0 = null;
  4850. pos = pos1;
  4851. }
  4852. } else {
  4853. result0 = null;
  4854. pos = pos1;
  4855. }
  4856. if (result0 === null) {
  4857. pos1 = pos;
  4858. if (input.substr(pos, 2) === "::") {
  4859. result0 = "::";
  4860. pos += 2;
  4861. } else {
  4862. result0 = null;
  4863. if (reportFailures === 0) {
  4864. matchFailed("\"::\"");
  4865. }
  4866. }
  4867. if (result0 !== null) {
  4868. result1 = parse_h16();
  4869. if (result1 !== null) {
  4870. if (input.charCodeAt(pos) === 58) {
  4871. result2 = ":";
  4872. pos++;
  4873. } else {
  4874. result2 = null;
  4875. if (reportFailures === 0) {
  4876. matchFailed("\":\"");
  4877. }
  4878. }
  4879. if (result2 !== null) {
  4880. result3 = parse_h16();
  4881. if (result3 !== null) {
  4882. if (input.charCodeAt(pos) === 58) {
  4883. result4 = ":";
  4884. pos++;
  4885. } else {
  4886. result4 = null;
  4887. if (reportFailures === 0) {
  4888. matchFailed("\":\"");
  4889. }
  4890. }
  4891. if (result4 !== null) {
  4892. result5 = parse_h16();
  4893. if (result5 !== null) {
  4894. if (input.charCodeAt(pos) === 58) {
  4895. result6 = ":";
  4896. pos++;
  4897. } else {
  4898. result6 = null;
  4899. if (reportFailures === 0) {
  4900. matchFailed("\":\"");
  4901. }
  4902. }
  4903. if (result6 !== null) {
  4904. result7 = parse_h16();
  4905. if (result7 !== null) {
  4906. if (input.charCodeAt(pos) === 58) {
  4907. result8 = ":";
  4908. pos++;
  4909. } else {
  4910. result8 = null;
  4911. if (reportFailures === 0) {
  4912. matchFailed("\":\"");
  4913. }
  4914. }
  4915. if (result8 !== null) {
  4916. result9 = parse_h16();
  4917. if (result9 !== null) {
  4918. if (input.charCodeAt(pos) === 58) {
  4919. result10 = ":";
  4920. pos++;
  4921. } else {
  4922. result10 = null;
  4923. if (reportFailures === 0) {
  4924. matchFailed("\":\"");
  4925. }
  4926. }
  4927. if (result10 !== null) {
  4928. result11 = parse_ls32();
  4929. if (result11 !== null) {
  4930. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11];
  4931. } else {
  4932. result0 = null;
  4933. pos = pos1;
  4934. }
  4935. } else {
  4936. result0 = null;
  4937. pos = pos1;
  4938. }
  4939. } else {
  4940. result0 = null;
  4941. pos = pos1;
  4942. }
  4943. } else {
  4944. result0 = null;
  4945. pos = pos1;
  4946. }
  4947. } else {
  4948. result0 = null;
  4949. pos = pos1;
  4950. }
  4951. } else {
  4952. result0 = null;
  4953. pos = pos1;
  4954. }
  4955. } else {
  4956. result0 = null;
  4957. pos = pos1;
  4958. }
  4959. } else {
  4960. result0 = null;
  4961. pos = pos1;
  4962. }
  4963. } else {
  4964. result0 = null;
  4965. pos = pos1;
  4966. }
  4967. } else {
  4968. result0 = null;
  4969. pos = pos1;
  4970. }
  4971. } else {
  4972. result0 = null;
  4973. pos = pos1;
  4974. }
  4975. } else {
  4976. result0 = null;
  4977. pos = pos1;
  4978. }
  4979. if (result0 === null) {
  4980. pos1 = pos;
  4981. if (input.substr(pos, 2) === "::") {
  4982. result0 = "::";
  4983. pos += 2;
  4984. } else {
  4985. result0 = null;
  4986. if (reportFailures === 0) {
  4987. matchFailed("\"::\"");
  4988. }
  4989. }
  4990. if (result0 !== null) {
  4991. result1 = parse_h16();
  4992. if (result1 !== null) {
  4993. if (input.charCodeAt(pos) === 58) {
  4994. result2 = ":";
  4995. pos++;
  4996. } else {
  4997. result2 = null;
  4998. if (reportFailures === 0) {
  4999. matchFailed("\":\"");
  5000. }
  5001. }
  5002. if (result2 !== null) {
  5003. result3 = parse_h16();
  5004. if (result3 !== null) {
  5005. if (input.charCodeAt(pos) === 58) {
  5006. result4 = ":";
  5007. pos++;
  5008. } else {
  5009. result4 = null;
  5010. if (reportFailures === 0) {
  5011. matchFailed("\":\"");
  5012. }
  5013. }
  5014. if (result4 !== null) {
  5015. result5 = parse_h16();
  5016. if (result5 !== null) {
  5017. if (input.charCodeAt(pos) === 58) {
  5018. result6 = ":";
  5019. pos++;
  5020. } else {
  5021. result6 = null;
  5022. if (reportFailures === 0) {
  5023. matchFailed("\":\"");
  5024. }
  5025. }
  5026. if (result6 !== null) {
  5027. result7 = parse_h16();
  5028. if (result7 !== null) {
  5029. if (input.charCodeAt(pos) === 58) {
  5030. result8 = ":";
  5031. pos++;
  5032. } else {
  5033. result8 = null;
  5034. if (reportFailures === 0) {
  5035. matchFailed("\":\"");
  5036. }
  5037. }
  5038. if (result8 !== null) {
  5039. result9 = parse_ls32();
  5040. if (result9 !== null) {
  5041. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  5042. } else {
  5043. result0 = null;
  5044. pos = pos1;
  5045. }
  5046. } else {
  5047. result0 = null;
  5048. pos = pos1;
  5049. }
  5050. } else {
  5051. result0 = null;
  5052. pos = pos1;
  5053. }
  5054. } else {
  5055. result0 = null;
  5056. pos = pos1;
  5057. }
  5058. } else {
  5059. result0 = null;
  5060. pos = pos1;
  5061. }
  5062. } else {
  5063. result0 = null;
  5064. pos = pos1;
  5065. }
  5066. } else {
  5067. result0 = null;
  5068. pos = pos1;
  5069. }
  5070. } else {
  5071. result0 = null;
  5072. pos = pos1;
  5073. }
  5074. } else {
  5075. result0 = null;
  5076. pos = pos1;
  5077. }
  5078. } else {
  5079. result0 = null;
  5080. pos = pos1;
  5081. }
  5082. if (result0 === null) {
  5083. pos1 = pos;
  5084. if (input.substr(pos, 2) === "::") {
  5085. result0 = "::";
  5086. pos += 2;
  5087. } else {
  5088. result0 = null;
  5089. if (reportFailures === 0) {
  5090. matchFailed("\"::\"");
  5091. }
  5092. }
  5093. if (result0 !== null) {
  5094. result1 = parse_h16();
  5095. if (result1 !== null) {
  5096. if (input.charCodeAt(pos) === 58) {
  5097. result2 = ":";
  5098. pos++;
  5099. } else {
  5100. result2 = null;
  5101. if (reportFailures === 0) {
  5102. matchFailed("\":\"");
  5103. }
  5104. }
  5105. if (result2 !== null) {
  5106. result3 = parse_h16();
  5107. if (result3 !== null) {
  5108. if (input.charCodeAt(pos) === 58) {
  5109. result4 = ":";
  5110. pos++;
  5111. } else {
  5112. result4 = null;
  5113. if (reportFailures === 0) {
  5114. matchFailed("\":\"");
  5115. }
  5116. }
  5117. if (result4 !== null) {
  5118. result5 = parse_h16();
  5119. if (result5 !== null) {
  5120. if (input.charCodeAt(pos) === 58) {
  5121. result6 = ":";
  5122. pos++;
  5123. } else {
  5124. result6 = null;
  5125. if (reportFailures === 0) {
  5126. matchFailed("\":\"");
  5127. }
  5128. }
  5129. if (result6 !== null) {
  5130. result7 = parse_ls32();
  5131. if (result7 !== null) {
  5132. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5133. } else {
  5134. result0 = null;
  5135. pos = pos1;
  5136. }
  5137. } else {
  5138. result0 = null;
  5139. pos = pos1;
  5140. }
  5141. } else {
  5142. result0 = null;
  5143. pos = pos1;
  5144. }
  5145. } else {
  5146. result0 = null;
  5147. pos = pos1;
  5148. }
  5149. } else {
  5150. result0 = null;
  5151. pos = pos1;
  5152. }
  5153. } else {
  5154. result0 = null;
  5155. pos = pos1;
  5156. }
  5157. } else {
  5158. result0 = null;
  5159. pos = pos1;
  5160. }
  5161. } else {
  5162. result0 = null;
  5163. pos = pos1;
  5164. }
  5165. if (result0 === null) {
  5166. pos1 = pos;
  5167. if (input.substr(pos, 2) === "::") {
  5168. result0 = "::";
  5169. pos += 2;
  5170. } else {
  5171. result0 = null;
  5172. if (reportFailures === 0) {
  5173. matchFailed("\"::\"");
  5174. }
  5175. }
  5176. if (result0 !== null) {
  5177. result1 = parse_h16();
  5178. if (result1 !== null) {
  5179. if (input.charCodeAt(pos) === 58) {
  5180. result2 = ":";
  5181. pos++;
  5182. } else {
  5183. result2 = null;
  5184. if (reportFailures === 0) {
  5185. matchFailed("\":\"");
  5186. }
  5187. }
  5188. if (result2 !== null) {
  5189. result3 = parse_h16();
  5190. if (result3 !== null) {
  5191. if (input.charCodeAt(pos) === 58) {
  5192. result4 = ":";
  5193. pos++;
  5194. } else {
  5195. result4 = null;
  5196. if (reportFailures === 0) {
  5197. matchFailed("\":\"");
  5198. }
  5199. }
  5200. if (result4 !== null) {
  5201. result5 = parse_ls32();
  5202. if (result5 !== null) {
  5203. result0 = [result0, result1, result2, result3, result4, result5];
  5204. } else {
  5205. result0 = null;
  5206. pos = pos1;
  5207. }
  5208. } else {
  5209. result0 = null;
  5210. pos = pos1;
  5211. }
  5212. } else {
  5213. result0 = null;
  5214. pos = pos1;
  5215. }
  5216. } else {
  5217. result0 = null;
  5218. pos = pos1;
  5219. }
  5220. } else {
  5221. result0 = null;
  5222. pos = pos1;
  5223. }
  5224. } else {
  5225. result0 = null;
  5226. pos = pos1;
  5227. }
  5228. if (result0 === null) {
  5229. pos1 = pos;
  5230. if (input.substr(pos, 2) === "::") {
  5231. result0 = "::";
  5232. pos += 2;
  5233. } else {
  5234. result0 = null;
  5235. if (reportFailures === 0) {
  5236. matchFailed("\"::\"");
  5237. }
  5238. }
  5239. if (result0 !== null) {
  5240. result1 = parse_h16();
  5241. if (result1 !== null) {
  5242. if (input.charCodeAt(pos) === 58) {
  5243. result2 = ":";
  5244. pos++;
  5245. } else {
  5246. result2 = null;
  5247. if (reportFailures === 0) {
  5248. matchFailed("\":\"");
  5249. }
  5250. }
  5251. if (result2 !== null) {
  5252. result3 = parse_ls32();
  5253. if (result3 !== null) {
  5254. result0 = [result0, result1, result2, result3];
  5255. } else {
  5256. result0 = null;
  5257. pos = pos1;
  5258. }
  5259. } else {
  5260. result0 = null;
  5261. pos = pos1;
  5262. }
  5263. } else {
  5264. result0 = null;
  5265. pos = pos1;
  5266. }
  5267. } else {
  5268. result0 = null;
  5269. pos = pos1;
  5270. }
  5271. if (result0 === null) {
  5272. pos1 = pos;
  5273. if (input.substr(pos, 2) === "::") {
  5274. result0 = "::";
  5275. pos += 2;
  5276. } else {
  5277. result0 = null;
  5278. if (reportFailures === 0) {
  5279. matchFailed("\"::\"");
  5280. }
  5281. }
  5282. if (result0 !== null) {
  5283. result1 = parse_ls32();
  5284. if (result1 !== null) {
  5285. result0 = [result0, result1];
  5286. } else {
  5287. result0 = null;
  5288. pos = pos1;
  5289. }
  5290. } else {
  5291. result0 = null;
  5292. pos = pos1;
  5293. }
  5294. if (result0 === null) {
  5295. pos1 = pos;
  5296. if (input.substr(pos, 2) === "::") {
  5297. result0 = "::";
  5298. pos += 2;
  5299. } else {
  5300. result0 = null;
  5301. if (reportFailures === 0) {
  5302. matchFailed("\"::\"");
  5303. }
  5304. }
  5305. if (result0 !== null) {
  5306. result1 = parse_h16();
  5307. if (result1 !== null) {
  5308. result0 = [result0, result1];
  5309. } else {
  5310. result0 = null;
  5311. pos = pos1;
  5312. }
  5313. } else {
  5314. result0 = null;
  5315. pos = pos1;
  5316. }
  5317. if (result0 === null) {
  5318. pos1 = pos;
  5319. result0 = parse_h16();
  5320. if (result0 !== null) {
  5321. if (input.substr(pos, 2) === "::") {
  5322. result1 = "::";
  5323. pos += 2;
  5324. } else {
  5325. result1 = null;
  5326. if (reportFailures === 0) {
  5327. matchFailed("\"::\"");
  5328. }
  5329. }
  5330. if (result1 !== null) {
  5331. result2 = parse_h16();
  5332. if (result2 !== null) {
  5333. if (input.charCodeAt(pos) === 58) {
  5334. result3 = ":";
  5335. pos++;
  5336. } else {
  5337. result3 = null;
  5338. if (reportFailures === 0) {
  5339. matchFailed("\":\"");
  5340. }
  5341. }
  5342. if (result3 !== null) {
  5343. result4 = parse_h16();
  5344. if (result4 !== null) {
  5345. if (input.charCodeAt(pos) === 58) {
  5346. result5 = ":";
  5347. pos++;
  5348. } else {
  5349. result5 = null;
  5350. if (reportFailures === 0) {
  5351. matchFailed("\":\"");
  5352. }
  5353. }
  5354. if (result5 !== null) {
  5355. result6 = parse_h16();
  5356. if (result6 !== null) {
  5357. if (input.charCodeAt(pos) === 58) {
  5358. result7 = ":";
  5359. pos++;
  5360. } else {
  5361. result7 = null;
  5362. if (reportFailures === 0) {
  5363. matchFailed("\":\"");
  5364. }
  5365. }
  5366. if (result7 !== null) {
  5367. result8 = parse_h16();
  5368. if (result8 !== null) {
  5369. if (input.charCodeAt(pos) === 58) {
  5370. result9 = ":";
  5371. pos++;
  5372. } else {
  5373. result9 = null;
  5374. if (reportFailures === 0) {
  5375. matchFailed("\":\"");
  5376. }
  5377. }
  5378. if (result9 !== null) {
  5379. result10 = parse_ls32();
  5380. if (result10 !== null) {
  5381. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10];
  5382. } else {
  5383. result0 = null;
  5384. pos = pos1;
  5385. }
  5386. } else {
  5387. result0 = null;
  5388. pos = pos1;
  5389. }
  5390. } else {
  5391. result0 = null;
  5392. pos = pos1;
  5393. }
  5394. } else {
  5395. result0 = null;
  5396. pos = pos1;
  5397. }
  5398. } else {
  5399. result0 = null;
  5400. pos = pos1;
  5401. }
  5402. } else {
  5403. result0 = null;
  5404. pos = pos1;
  5405. }
  5406. } else {
  5407. result0 = null;
  5408. pos = pos1;
  5409. }
  5410. } else {
  5411. result0 = null;
  5412. pos = pos1;
  5413. }
  5414. } else {
  5415. result0 = null;
  5416. pos = pos1;
  5417. }
  5418. } else {
  5419. result0 = null;
  5420. pos = pos1;
  5421. }
  5422. } else {
  5423. result0 = null;
  5424. pos = pos1;
  5425. }
  5426. if (result0 === null) {
  5427. pos1 = pos;
  5428. result0 = parse_h16();
  5429. if (result0 !== null) {
  5430. pos2 = pos;
  5431. if (input.charCodeAt(pos) === 58) {
  5432. result1 = ":";
  5433. pos++;
  5434. } else {
  5435. result1 = null;
  5436. if (reportFailures === 0) {
  5437. matchFailed("\":\"");
  5438. }
  5439. }
  5440. if (result1 !== null) {
  5441. result2 = parse_h16();
  5442. if (result2 !== null) {
  5443. result1 = [result1, result2];
  5444. } else {
  5445. result1 = null;
  5446. pos = pos2;
  5447. }
  5448. } else {
  5449. result1 = null;
  5450. pos = pos2;
  5451. }
  5452. result1 = result1 !== null ? result1 : "";
  5453. if (result1 !== null) {
  5454. if (input.substr(pos, 2) === "::") {
  5455. result2 = "::";
  5456. pos += 2;
  5457. } else {
  5458. result2 = null;
  5459. if (reportFailures === 0) {
  5460. matchFailed("\"::\"");
  5461. }
  5462. }
  5463. if (result2 !== null) {
  5464. result3 = parse_h16();
  5465. if (result3 !== null) {
  5466. if (input.charCodeAt(pos) === 58) {
  5467. result4 = ":";
  5468. pos++;
  5469. } else {
  5470. result4 = null;
  5471. if (reportFailures === 0) {
  5472. matchFailed("\":\"");
  5473. }
  5474. }
  5475. if (result4 !== null) {
  5476. result5 = parse_h16();
  5477. if (result5 !== null) {
  5478. if (input.charCodeAt(pos) === 58) {
  5479. result6 = ":";
  5480. pos++;
  5481. } else {
  5482. result6 = null;
  5483. if (reportFailures === 0) {
  5484. matchFailed("\":\"");
  5485. }
  5486. }
  5487. if (result6 !== null) {
  5488. result7 = parse_h16();
  5489. if (result7 !== null) {
  5490. if (input.charCodeAt(pos) === 58) {
  5491. result8 = ":";
  5492. pos++;
  5493. } else {
  5494. result8 = null;
  5495. if (reportFailures === 0) {
  5496. matchFailed("\":\"");
  5497. }
  5498. }
  5499. if (result8 !== null) {
  5500. result9 = parse_ls32();
  5501. if (result9 !== null) {
  5502. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
  5503. } else {
  5504. result0 = null;
  5505. pos = pos1;
  5506. }
  5507. } else {
  5508. result0 = null;
  5509. pos = pos1;
  5510. }
  5511. } else {
  5512. result0 = null;
  5513. pos = pos1;
  5514. }
  5515. } else {
  5516. result0 = null;
  5517. pos = pos1;
  5518. }
  5519. } else {
  5520. result0 = null;
  5521. pos = pos1;
  5522. }
  5523. } else {
  5524. result0 = null;
  5525. pos = pos1;
  5526. }
  5527. } else {
  5528. result0 = null;
  5529. pos = pos1;
  5530. }
  5531. } else {
  5532. result0 = null;
  5533. pos = pos1;
  5534. }
  5535. } else {
  5536. result0 = null;
  5537. pos = pos1;
  5538. }
  5539. } else {
  5540. result0 = null;
  5541. pos = pos1;
  5542. }
  5543. if (result0 === null) {
  5544. pos1 = pos;
  5545. result0 = parse_h16();
  5546. if (result0 !== null) {
  5547. pos2 = pos;
  5548. if (input.charCodeAt(pos) === 58) {
  5549. result1 = ":";
  5550. pos++;
  5551. } else {
  5552. result1 = null;
  5553. if (reportFailures === 0) {
  5554. matchFailed("\":\"");
  5555. }
  5556. }
  5557. if (result1 !== null) {
  5558. result2 = parse_h16();
  5559. if (result2 !== null) {
  5560. result1 = [result1, result2];
  5561. } else {
  5562. result1 = null;
  5563. pos = pos2;
  5564. }
  5565. } else {
  5566. result1 = null;
  5567. pos = pos2;
  5568. }
  5569. result1 = result1 !== null ? result1 : "";
  5570. if (result1 !== null) {
  5571. pos2 = pos;
  5572. if (input.charCodeAt(pos) === 58) {
  5573. result2 = ":";
  5574. pos++;
  5575. } else {
  5576. result2 = null;
  5577. if (reportFailures === 0) {
  5578. matchFailed("\":\"");
  5579. }
  5580. }
  5581. if (result2 !== null) {
  5582. result3 = parse_h16();
  5583. if (result3 !== null) {
  5584. result2 = [result2, result3];
  5585. } else {
  5586. result2 = null;
  5587. pos = pos2;
  5588. }
  5589. } else {
  5590. result2 = null;
  5591. pos = pos2;
  5592. }
  5593. result2 = result2 !== null ? result2 : "";
  5594. if (result2 !== null) {
  5595. if (input.substr(pos, 2) === "::") {
  5596. result3 = "::";
  5597. pos += 2;
  5598. } else {
  5599. result3 = null;
  5600. if (reportFailures === 0) {
  5601. matchFailed("\"::\"");
  5602. }
  5603. }
  5604. if (result3 !== null) {
  5605. result4 = parse_h16();
  5606. if (result4 !== null) {
  5607. if (input.charCodeAt(pos) === 58) {
  5608. result5 = ":";
  5609. pos++;
  5610. } else {
  5611. result5 = null;
  5612. if (reportFailures === 0) {
  5613. matchFailed("\":\"");
  5614. }
  5615. }
  5616. if (result5 !== null) {
  5617. result6 = parse_h16();
  5618. if (result6 !== null) {
  5619. if (input.charCodeAt(pos) === 58) {
  5620. result7 = ":";
  5621. pos++;
  5622. } else {
  5623. result7 = null;
  5624. if (reportFailures === 0) {
  5625. matchFailed("\":\"");
  5626. }
  5627. }
  5628. if (result7 !== null) {
  5629. result8 = parse_ls32();
  5630. if (result8 !== null) {
  5631. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  5632. } else {
  5633. result0 = null;
  5634. pos = pos1;
  5635. }
  5636. } else {
  5637. result0 = null;
  5638. pos = pos1;
  5639. }
  5640. } else {
  5641. result0 = null;
  5642. pos = pos1;
  5643. }
  5644. } else {
  5645. result0 = null;
  5646. pos = pos1;
  5647. }
  5648. } else {
  5649. result0 = null;
  5650. pos = pos1;
  5651. }
  5652. } else {
  5653. result0 = null;
  5654. pos = pos1;
  5655. }
  5656. } else {
  5657. result0 = null;
  5658. pos = pos1;
  5659. }
  5660. } else {
  5661. result0 = null;
  5662. pos = pos1;
  5663. }
  5664. } else {
  5665. result0 = null;
  5666. pos = pos1;
  5667. }
  5668. if (result0 === null) {
  5669. pos1 = pos;
  5670. result0 = parse_h16();
  5671. if (result0 !== null) {
  5672. pos2 = pos;
  5673. if (input.charCodeAt(pos) === 58) {
  5674. result1 = ":";
  5675. pos++;
  5676. } else {
  5677. result1 = null;
  5678. if (reportFailures === 0) {
  5679. matchFailed("\":\"");
  5680. }
  5681. }
  5682. if (result1 !== null) {
  5683. result2 = parse_h16();
  5684. if (result2 !== null) {
  5685. result1 = [result1, result2];
  5686. } else {
  5687. result1 = null;
  5688. pos = pos2;
  5689. }
  5690. } else {
  5691. result1 = null;
  5692. pos = pos2;
  5693. }
  5694. result1 = result1 !== null ? result1 : "";
  5695. if (result1 !== null) {
  5696. pos2 = pos;
  5697. if (input.charCodeAt(pos) === 58) {
  5698. result2 = ":";
  5699. pos++;
  5700. } else {
  5701. result2 = null;
  5702. if (reportFailures === 0) {
  5703. matchFailed("\":\"");
  5704. }
  5705. }
  5706. if (result2 !== null) {
  5707. result3 = parse_h16();
  5708. if (result3 !== null) {
  5709. result2 = [result2, result3];
  5710. } else {
  5711. result2 = null;
  5712. pos = pos2;
  5713. }
  5714. } else {
  5715. result2 = null;
  5716. pos = pos2;
  5717. }
  5718. result2 = result2 !== null ? result2 : "";
  5719. if (result2 !== null) {
  5720. pos2 = pos;
  5721. if (input.charCodeAt(pos) === 58) {
  5722. result3 = ":";
  5723. pos++;
  5724. } else {
  5725. result3 = null;
  5726. if (reportFailures === 0) {
  5727. matchFailed("\":\"");
  5728. }
  5729. }
  5730. if (result3 !== null) {
  5731. result4 = parse_h16();
  5732. if (result4 !== null) {
  5733. result3 = [result3, result4];
  5734. } else {
  5735. result3 = null;
  5736. pos = pos2;
  5737. }
  5738. } else {
  5739. result3 = null;
  5740. pos = pos2;
  5741. }
  5742. result3 = result3 !== null ? result3 : "";
  5743. if (result3 !== null) {
  5744. if (input.substr(pos, 2) === "::") {
  5745. result4 = "::";
  5746. pos += 2;
  5747. } else {
  5748. result4 = null;
  5749. if (reportFailures === 0) {
  5750. matchFailed("\"::\"");
  5751. }
  5752. }
  5753. if (result4 !== null) {
  5754. result5 = parse_h16();
  5755. if (result5 !== null) {
  5756. if (input.charCodeAt(pos) === 58) {
  5757. result6 = ":";
  5758. pos++;
  5759. } else {
  5760. result6 = null;
  5761. if (reportFailures === 0) {
  5762. matchFailed("\":\"");
  5763. }
  5764. }
  5765. if (result6 !== null) {
  5766. result7 = parse_ls32();
  5767. if (result7 !== null) {
  5768. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  5769. } else {
  5770. result0 = null;
  5771. pos = pos1;
  5772. }
  5773. } else {
  5774. result0 = null;
  5775. pos = pos1;
  5776. }
  5777. } else {
  5778. result0 = null;
  5779. pos = pos1;
  5780. }
  5781. } else {
  5782. result0 = null;
  5783. pos = pos1;
  5784. }
  5785. } else {
  5786. result0 = null;
  5787. pos = pos1;
  5788. }
  5789. } else {
  5790. result0 = null;
  5791. pos = pos1;
  5792. }
  5793. } else {
  5794. result0 = null;
  5795. pos = pos1;
  5796. }
  5797. } else {
  5798. result0 = null;
  5799. pos = pos1;
  5800. }
  5801. if (result0 === null) {
  5802. pos1 = pos;
  5803. result0 = parse_h16();
  5804. if (result0 !== null) {
  5805. pos2 = pos;
  5806. if (input.charCodeAt(pos) === 58) {
  5807. result1 = ":";
  5808. pos++;
  5809. } else {
  5810. result1 = null;
  5811. if (reportFailures === 0) {
  5812. matchFailed("\":\"");
  5813. }
  5814. }
  5815. if (result1 !== null) {
  5816. result2 = parse_h16();
  5817. if (result2 !== null) {
  5818. result1 = [result1, result2];
  5819. } else {
  5820. result1 = null;
  5821. pos = pos2;
  5822. }
  5823. } else {
  5824. result1 = null;
  5825. pos = pos2;
  5826. }
  5827. result1 = result1 !== null ? result1 : "";
  5828. if (result1 !== null) {
  5829. pos2 = pos;
  5830. if (input.charCodeAt(pos) === 58) {
  5831. result2 = ":";
  5832. pos++;
  5833. } else {
  5834. result2 = null;
  5835. if (reportFailures === 0) {
  5836. matchFailed("\":\"");
  5837. }
  5838. }
  5839. if (result2 !== null) {
  5840. result3 = parse_h16();
  5841. if (result3 !== null) {
  5842. result2 = [result2, result3];
  5843. } else {
  5844. result2 = null;
  5845. pos = pos2;
  5846. }
  5847. } else {
  5848. result2 = null;
  5849. pos = pos2;
  5850. }
  5851. result2 = result2 !== null ? result2 : "";
  5852. if (result2 !== null) {
  5853. pos2 = pos;
  5854. if (input.charCodeAt(pos) === 58) {
  5855. result3 = ":";
  5856. pos++;
  5857. } else {
  5858. result3 = null;
  5859. if (reportFailures === 0) {
  5860. matchFailed("\":\"");
  5861. }
  5862. }
  5863. if (result3 !== null) {
  5864. result4 = parse_h16();
  5865. if (result4 !== null) {
  5866. result3 = [result3, result4];
  5867. } else {
  5868. result3 = null;
  5869. pos = pos2;
  5870. }
  5871. } else {
  5872. result3 = null;
  5873. pos = pos2;
  5874. }
  5875. result3 = result3 !== null ? result3 : "";
  5876. if (result3 !== null) {
  5877. pos2 = pos;
  5878. if (input.charCodeAt(pos) === 58) {
  5879. result4 = ":";
  5880. pos++;
  5881. } else {
  5882. result4 = null;
  5883. if (reportFailures === 0) {
  5884. matchFailed("\":\"");
  5885. }
  5886. }
  5887. if (result4 !== null) {
  5888. result5 = parse_h16();
  5889. if (result5 !== null) {
  5890. result4 = [result4, result5];
  5891. } else {
  5892. result4 = null;
  5893. pos = pos2;
  5894. }
  5895. } else {
  5896. result4 = null;
  5897. pos = pos2;
  5898. }
  5899. result4 = result4 !== null ? result4 : "";
  5900. if (result4 !== null) {
  5901. if (input.substr(pos, 2) === "::") {
  5902. result5 = "::";
  5903. pos += 2;
  5904. } else {
  5905. result5 = null;
  5906. if (reportFailures === 0) {
  5907. matchFailed("\"::\"");
  5908. }
  5909. }
  5910. if (result5 !== null) {
  5911. result6 = parse_ls32();
  5912. if (result6 !== null) {
  5913. result0 = [result0, result1, result2, result3, result4, result5, result6];
  5914. } else {
  5915. result0 = null;
  5916. pos = pos1;
  5917. }
  5918. } else {
  5919. result0 = null;
  5920. pos = pos1;
  5921. }
  5922. } else {
  5923. result0 = null;
  5924. pos = pos1;
  5925. }
  5926. } else {
  5927. result0 = null;
  5928. pos = pos1;
  5929. }
  5930. } else {
  5931. result0 = null;
  5932. pos = pos1;
  5933. }
  5934. } else {
  5935. result0 = null;
  5936. pos = pos1;
  5937. }
  5938. } else {
  5939. result0 = null;
  5940. pos = pos1;
  5941. }
  5942. if (result0 === null) {
  5943. pos1 = pos;
  5944. result0 = parse_h16();
  5945. if (result0 !== null) {
  5946. pos2 = pos;
  5947. if (input.charCodeAt(pos) === 58) {
  5948. result1 = ":";
  5949. pos++;
  5950. } else {
  5951. result1 = null;
  5952. if (reportFailures === 0) {
  5953. matchFailed("\":\"");
  5954. }
  5955. }
  5956. if (result1 !== null) {
  5957. result2 = parse_h16();
  5958. if (result2 !== null) {
  5959. result1 = [result1, result2];
  5960. } else {
  5961. result1 = null;
  5962. pos = pos2;
  5963. }
  5964. } else {
  5965. result1 = null;
  5966. pos = pos2;
  5967. }
  5968. result1 = result1 !== null ? result1 : "";
  5969. if (result1 !== null) {
  5970. pos2 = pos;
  5971. if (input.charCodeAt(pos) === 58) {
  5972. result2 = ":";
  5973. pos++;
  5974. } else {
  5975. result2 = null;
  5976. if (reportFailures === 0) {
  5977. matchFailed("\":\"");
  5978. }
  5979. }
  5980. if (result2 !== null) {
  5981. result3 = parse_h16();
  5982. if (result3 !== null) {
  5983. result2 = [result2, result3];
  5984. } else {
  5985. result2 = null;
  5986. pos = pos2;
  5987. }
  5988. } else {
  5989. result2 = null;
  5990. pos = pos2;
  5991. }
  5992. result2 = result2 !== null ? result2 : "";
  5993. if (result2 !== null) {
  5994. pos2 = pos;
  5995. if (input.charCodeAt(pos) === 58) {
  5996. result3 = ":";
  5997. pos++;
  5998. } else {
  5999. result3 = null;
  6000. if (reportFailures === 0) {
  6001. matchFailed("\":\"");
  6002. }
  6003. }
  6004. if (result3 !== null) {
  6005. result4 = parse_h16();
  6006. if (result4 !== null) {
  6007. result3 = [result3, result4];
  6008. } else {
  6009. result3 = null;
  6010. pos = pos2;
  6011. }
  6012. } else {
  6013. result3 = null;
  6014. pos = pos2;
  6015. }
  6016. result3 = result3 !== null ? result3 : "";
  6017. if (result3 !== null) {
  6018. pos2 = pos;
  6019. if (input.charCodeAt(pos) === 58) {
  6020. result4 = ":";
  6021. pos++;
  6022. } else {
  6023. result4 = null;
  6024. if (reportFailures === 0) {
  6025. matchFailed("\":\"");
  6026. }
  6027. }
  6028. if (result4 !== null) {
  6029. result5 = parse_h16();
  6030. if (result5 !== null) {
  6031. result4 = [result4, result5];
  6032. } else {
  6033. result4 = null;
  6034. pos = pos2;
  6035. }
  6036. } else {
  6037. result4 = null;
  6038. pos = pos2;
  6039. }
  6040. result4 = result4 !== null ? result4 : "";
  6041. if (result4 !== null) {
  6042. pos2 = pos;
  6043. if (input.charCodeAt(pos) === 58) {
  6044. result5 = ":";
  6045. pos++;
  6046. } else {
  6047. result5 = null;
  6048. if (reportFailures === 0) {
  6049. matchFailed("\":\"");
  6050. }
  6051. }
  6052. if (result5 !== null) {
  6053. result6 = parse_h16();
  6054. if (result6 !== null) {
  6055. result5 = [result5, result6];
  6056. } else {
  6057. result5 = null;
  6058. pos = pos2;
  6059. }
  6060. } else {
  6061. result5 = null;
  6062. pos = pos2;
  6063. }
  6064. result5 = result5 !== null ? result5 : "";
  6065. if (result5 !== null) {
  6066. if (input.substr(pos, 2) === "::") {
  6067. result6 = "::";
  6068. pos += 2;
  6069. } else {
  6070. result6 = null;
  6071. if (reportFailures === 0) {
  6072. matchFailed("\"::\"");
  6073. }
  6074. }
  6075. if (result6 !== null) {
  6076. result7 = parse_h16();
  6077. if (result7 !== null) {
  6078. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  6079. } else {
  6080. result0 = null;
  6081. pos = pos1;
  6082. }
  6083. } else {
  6084. result0 = null;
  6085. pos = pos1;
  6086. }
  6087. } else {
  6088. result0 = null;
  6089. pos = pos1;
  6090. }
  6091. } else {
  6092. result0 = null;
  6093. pos = pos1;
  6094. }
  6095. } else {
  6096. result0 = null;
  6097. pos = pos1;
  6098. }
  6099. } else {
  6100. result0 = null;
  6101. pos = pos1;
  6102. }
  6103. } else {
  6104. result0 = null;
  6105. pos = pos1;
  6106. }
  6107. } else {
  6108. result0 = null;
  6109. pos = pos1;
  6110. }
  6111. if (result0 === null) {
  6112. pos1 = pos;
  6113. result0 = parse_h16();
  6114. if (result0 !== null) {
  6115. pos2 = pos;
  6116. if (input.charCodeAt(pos) === 58) {
  6117. result1 = ":";
  6118. pos++;
  6119. } else {
  6120. result1 = null;
  6121. if (reportFailures === 0) {
  6122. matchFailed("\":\"");
  6123. }
  6124. }
  6125. if (result1 !== null) {
  6126. result2 = parse_h16();
  6127. if (result2 !== null) {
  6128. result1 = [result1, result2];
  6129. } else {
  6130. result1 = null;
  6131. pos = pos2;
  6132. }
  6133. } else {
  6134. result1 = null;
  6135. pos = pos2;
  6136. }
  6137. result1 = result1 !== null ? result1 : "";
  6138. if (result1 !== null) {
  6139. pos2 = pos;
  6140. if (input.charCodeAt(pos) === 58) {
  6141. result2 = ":";
  6142. pos++;
  6143. } else {
  6144. result2 = null;
  6145. if (reportFailures === 0) {
  6146. matchFailed("\":\"");
  6147. }
  6148. }
  6149. if (result2 !== null) {
  6150. result3 = parse_h16();
  6151. if (result3 !== null) {
  6152. result2 = [result2, result3];
  6153. } else {
  6154. result2 = null;
  6155. pos = pos2;
  6156. }
  6157. } else {
  6158. result2 = null;
  6159. pos = pos2;
  6160. }
  6161. result2 = result2 !== null ? result2 : "";
  6162. if (result2 !== null) {
  6163. pos2 = pos;
  6164. if (input.charCodeAt(pos) === 58) {
  6165. result3 = ":";
  6166. pos++;
  6167. } else {
  6168. result3 = null;
  6169. if (reportFailures === 0) {
  6170. matchFailed("\":\"");
  6171. }
  6172. }
  6173. if (result3 !== null) {
  6174. result4 = parse_h16();
  6175. if (result4 !== null) {
  6176. result3 = [result3, result4];
  6177. } else {
  6178. result3 = null;
  6179. pos = pos2;
  6180. }
  6181. } else {
  6182. result3 = null;
  6183. pos = pos2;
  6184. }
  6185. result3 = result3 !== null ? result3 : "";
  6186. if (result3 !== null) {
  6187. pos2 = pos;
  6188. if (input.charCodeAt(pos) === 58) {
  6189. result4 = ":";
  6190. pos++;
  6191. } else {
  6192. result4 = null;
  6193. if (reportFailures === 0) {
  6194. matchFailed("\":\"");
  6195. }
  6196. }
  6197. if (result4 !== null) {
  6198. result5 = parse_h16();
  6199. if (result5 !== null) {
  6200. result4 = [result4, result5];
  6201. } else {
  6202. result4 = null;
  6203. pos = pos2;
  6204. }
  6205. } else {
  6206. result4 = null;
  6207. pos = pos2;
  6208. }
  6209. result4 = result4 !== null ? result4 : "";
  6210. if (result4 !== null) {
  6211. pos2 = pos;
  6212. if (input.charCodeAt(pos) === 58) {
  6213. result5 = ":";
  6214. pos++;
  6215. } else {
  6216. result5 = null;
  6217. if (reportFailures === 0) {
  6218. matchFailed("\":\"");
  6219. }
  6220. }
  6221. if (result5 !== null) {
  6222. result6 = parse_h16();
  6223. if (result6 !== null) {
  6224. result5 = [result5, result6];
  6225. } else {
  6226. result5 = null;
  6227. pos = pos2;
  6228. }
  6229. } else {
  6230. result5 = null;
  6231. pos = pos2;
  6232. }
  6233. result5 = result5 !== null ? result5 : "";
  6234. if (result5 !== null) {
  6235. pos2 = pos;
  6236. if (input.charCodeAt(pos) === 58) {
  6237. result6 = ":";
  6238. pos++;
  6239. } else {
  6240. result6 = null;
  6241. if (reportFailures === 0) {
  6242. matchFailed("\":\"");
  6243. }
  6244. }
  6245. if (result6 !== null) {
  6246. result7 = parse_h16();
  6247. if (result7 !== null) {
  6248. result6 = [result6, result7];
  6249. } else {
  6250. result6 = null;
  6251. pos = pos2;
  6252. }
  6253. } else {
  6254. result6 = null;
  6255. pos = pos2;
  6256. }
  6257. result6 = result6 !== null ? result6 : "";
  6258. if (result6 !== null) {
  6259. if (input.substr(pos, 2) === "::") {
  6260. result7 = "::";
  6261. pos += 2;
  6262. } else {
  6263. result7 = null;
  6264. if (reportFailures === 0) {
  6265. matchFailed("\"::\"");
  6266. }
  6267. }
  6268. if (result7 !== null) {
  6269. result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
  6270. } else {
  6271. result0 = null;
  6272. pos = pos1;
  6273. }
  6274. } else {
  6275. result0 = null;
  6276. pos = pos1;
  6277. }
  6278. } else {
  6279. result0 = null;
  6280. pos = pos1;
  6281. }
  6282. } else {
  6283. result0 = null;
  6284. pos = pos1;
  6285. }
  6286. } else {
  6287. result0 = null;
  6288. pos = pos1;
  6289. }
  6290. } else {
  6291. result0 = null;
  6292. pos = pos1;
  6293. }
  6294. } else {
  6295. result0 = null;
  6296. pos = pos1;
  6297. }
  6298. } else {
  6299. result0 = null;
  6300. pos = pos1;
  6301. }
  6302. }
  6303. }
  6304. }
  6305. }
  6306. }
  6307. }
  6308. }
  6309. }
  6310. }
  6311. }
  6312. }
  6313. }
  6314. }
  6315. }
  6316. if (result0 !== null) {
  6317. result0 = function (offset) {
  6318. data.host_type = 'IPv6';
  6319. return input.substring(pos, offset);
  6320. }(pos0);
  6321. }
  6322. if (result0 === null) {
  6323. pos = pos0;
  6324. }
  6325. return result0;
  6326. }
  6327. function parse_h16() {
  6328. var result0, result1, result2, result3;
  6329. var pos0;
  6330. pos0 = pos;
  6331. result0 = parse_HEXDIG();
  6332. if (result0 !== null) {
  6333. result1 = parse_HEXDIG();
  6334. result1 = result1 !== null ? result1 : "";
  6335. if (result1 !== null) {
  6336. result2 = parse_HEXDIG();
  6337. result2 = result2 !== null ? result2 : "";
  6338. if (result2 !== null) {
  6339. result3 = parse_HEXDIG();
  6340. result3 = result3 !== null ? result3 : "";
  6341. if (result3 !== null) {
  6342. result0 = [result0, result1, result2, result3];
  6343. } else {
  6344. result0 = null;
  6345. pos = pos0;
  6346. }
  6347. } else {
  6348. result0 = null;
  6349. pos = pos0;
  6350. }
  6351. } else {
  6352. result0 = null;
  6353. pos = pos0;
  6354. }
  6355. } else {
  6356. result0 = null;
  6357. pos = pos0;
  6358. }
  6359. return result0;
  6360. }
  6361. function parse_ls32() {
  6362. var result0, result1, result2;
  6363. var pos0;
  6364. pos0 = pos;
  6365. result0 = parse_h16();
  6366. if (result0 !== null) {
  6367. if (input.charCodeAt(pos) === 58) {
  6368. result1 = ":";
  6369. pos++;
  6370. } else {
  6371. result1 = null;
  6372. if (reportFailures === 0) {
  6373. matchFailed("\":\"");
  6374. }
  6375. }
  6376. if (result1 !== null) {
  6377. result2 = parse_h16();
  6378. if (result2 !== null) {
  6379. result0 = [result0, result1, result2];
  6380. } else {
  6381. result0 = null;
  6382. pos = pos0;
  6383. }
  6384. } else {
  6385. result0 = null;
  6386. pos = pos0;
  6387. }
  6388. } else {
  6389. result0 = null;
  6390. pos = pos0;
  6391. }
  6392. if (result0 === null) {
  6393. result0 = parse_IPv4address();
  6394. }
  6395. return result0;
  6396. }
  6397. function parse_IPv4address() {
  6398. var result0, result1, result2, result3, result4, result5, result6;
  6399. var pos0, pos1;
  6400. pos0 = pos;
  6401. pos1 = pos;
  6402. result0 = parse_dec_octet();
  6403. if (result0 !== null) {
  6404. if (input.charCodeAt(pos) === 46) {
  6405. result1 = ".";
  6406. pos++;
  6407. } else {
  6408. result1 = null;
  6409. if (reportFailures === 0) {
  6410. matchFailed("\".\"");
  6411. }
  6412. }
  6413. if (result1 !== null) {
  6414. result2 = parse_dec_octet();
  6415. if (result2 !== null) {
  6416. if (input.charCodeAt(pos) === 46) {
  6417. result3 = ".";
  6418. pos++;
  6419. } else {
  6420. result3 = null;
  6421. if (reportFailures === 0) {
  6422. matchFailed("\".\"");
  6423. }
  6424. }
  6425. if (result3 !== null) {
  6426. result4 = parse_dec_octet();
  6427. if (result4 !== null) {
  6428. if (input.charCodeAt(pos) === 46) {
  6429. result5 = ".";
  6430. pos++;
  6431. } else {
  6432. result5 = null;
  6433. if (reportFailures === 0) {
  6434. matchFailed("\".\"");
  6435. }
  6436. }
  6437. if (result5 !== null) {
  6438. result6 = parse_dec_octet();
  6439. if (result6 !== null) {
  6440. result0 = [result0, result1, result2, result3, result4, result5, result6];
  6441. } else {
  6442. result0 = null;
  6443. pos = pos1;
  6444. }
  6445. } else {
  6446. result0 = null;
  6447. pos = pos1;
  6448. }
  6449. } else {
  6450. result0 = null;
  6451. pos = pos1;
  6452. }
  6453. } else {
  6454. result0 = null;
  6455. pos = pos1;
  6456. }
  6457. } else {
  6458. result0 = null;
  6459. pos = pos1;
  6460. }
  6461. } else {
  6462. result0 = null;
  6463. pos = pos1;
  6464. }
  6465. } else {
  6466. result0 = null;
  6467. pos = pos1;
  6468. }
  6469. if (result0 !== null) {
  6470. result0 = function (offset) {
  6471. data.host_type = 'IPv4';
  6472. return input.substring(pos, offset);
  6473. }(pos0);
  6474. }
  6475. if (result0 === null) {
  6476. pos = pos0;
  6477. }
  6478. return result0;
  6479. }
  6480. function parse_dec_octet() {
  6481. var result0, result1, result2;
  6482. var pos0;
  6483. pos0 = pos;
  6484. if (input.substr(pos, 2) === "25") {
  6485. result0 = "25";
  6486. pos += 2;
  6487. } else {
  6488. result0 = null;
  6489. if (reportFailures === 0) {
  6490. matchFailed("\"25\"");
  6491. }
  6492. }
  6493. if (result0 !== null) {
  6494. if (/^[0-5]/.test(input.charAt(pos))) {
  6495. result1 = input.charAt(pos);
  6496. pos++;
  6497. } else {
  6498. result1 = null;
  6499. if (reportFailures === 0) {
  6500. matchFailed("[0-5]");
  6501. }
  6502. }
  6503. if (result1 !== null) {
  6504. result0 = [result0, result1];
  6505. } else {
  6506. result0 = null;
  6507. pos = pos0;
  6508. }
  6509. } else {
  6510. result0 = null;
  6511. pos = pos0;
  6512. }
  6513. if (result0 === null) {
  6514. pos0 = pos;
  6515. if (input.charCodeAt(pos) === 50) {
  6516. result0 = "2";
  6517. pos++;
  6518. } else {
  6519. result0 = null;
  6520. if (reportFailures === 0) {
  6521. matchFailed("\"2\"");
  6522. }
  6523. }
  6524. if (result0 !== null) {
  6525. if (/^[0-4]/.test(input.charAt(pos))) {
  6526. result1 = input.charAt(pos);
  6527. pos++;
  6528. } else {
  6529. result1 = null;
  6530. if (reportFailures === 0) {
  6531. matchFailed("[0-4]");
  6532. }
  6533. }
  6534. if (result1 !== null) {
  6535. result2 = parse_DIGIT();
  6536. if (result2 !== null) {
  6537. result0 = [result0, result1, result2];
  6538. } else {
  6539. result0 = null;
  6540. pos = pos0;
  6541. }
  6542. } else {
  6543. result0 = null;
  6544. pos = pos0;
  6545. }
  6546. } else {
  6547. result0 = null;
  6548. pos = pos0;
  6549. }
  6550. if (result0 === null) {
  6551. pos0 = pos;
  6552. if (input.charCodeAt(pos) === 49) {
  6553. result0 = "1";
  6554. pos++;
  6555. } else {
  6556. result0 = null;
  6557. if (reportFailures === 0) {
  6558. matchFailed("\"1\"");
  6559. }
  6560. }
  6561. if (result0 !== null) {
  6562. result1 = parse_DIGIT();
  6563. if (result1 !== null) {
  6564. result2 = parse_DIGIT();
  6565. if (result2 !== null) {
  6566. result0 = [result0, result1, result2];
  6567. } else {
  6568. result0 = null;
  6569. pos = pos0;
  6570. }
  6571. } else {
  6572. result0 = null;
  6573. pos = pos0;
  6574. }
  6575. } else {
  6576. result0 = null;
  6577. pos = pos0;
  6578. }
  6579. if (result0 === null) {
  6580. pos0 = pos;
  6581. if (/^[1-9]/.test(input.charAt(pos))) {
  6582. result0 = input.charAt(pos);
  6583. pos++;
  6584. } else {
  6585. result0 = null;
  6586. if (reportFailures === 0) {
  6587. matchFailed("[1-9]");
  6588. }
  6589. }
  6590. if (result0 !== null) {
  6591. result1 = parse_DIGIT();
  6592. if (result1 !== null) {
  6593. result0 = [result0, result1];
  6594. } else {
  6595. result0 = null;
  6596. pos = pos0;
  6597. }
  6598. } else {
  6599. result0 = null;
  6600. pos = pos0;
  6601. }
  6602. if (result0 === null) {
  6603. result0 = parse_DIGIT();
  6604. }
  6605. }
  6606. }
  6607. }
  6608. return result0;
  6609. }
  6610. function parse_port() {
  6611. var result0, result1, result2, result3, result4;
  6612. var pos0, pos1;
  6613. pos0 = pos;
  6614. pos1 = pos;
  6615. result0 = parse_DIGIT();
  6616. result0 = result0 !== null ? result0 : "";
  6617. if (result0 !== null) {
  6618. result1 = parse_DIGIT();
  6619. result1 = result1 !== null ? result1 : "";
  6620. if (result1 !== null) {
  6621. result2 = parse_DIGIT();
  6622. result2 = result2 !== null ? result2 : "";
  6623. if (result2 !== null) {
  6624. result3 = parse_DIGIT();
  6625. result3 = result3 !== null ? result3 : "";
  6626. if (result3 !== null) {
  6627. result4 = parse_DIGIT();
  6628. result4 = result4 !== null ? result4 : "";
  6629. if (result4 !== null) {
  6630. result0 = [result0, result1, result2, result3, result4];
  6631. } else {
  6632. result0 = null;
  6633. pos = pos1;
  6634. }
  6635. } else {
  6636. result0 = null;
  6637. pos = pos1;
  6638. }
  6639. } else {
  6640. result0 = null;
  6641. pos = pos1;
  6642. }
  6643. } else {
  6644. result0 = null;
  6645. pos = pos1;
  6646. }
  6647. } else {
  6648. result0 = null;
  6649. pos = pos1;
  6650. }
  6651. if (result0 !== null) {
  6652. result0 = function (offset, port) {
  6653. port = parseInt(port.join(''));
  6654. data.port = port;
  6655. return port;
  6656. }(pos0, result0);
  6657. }
  6658. if (result0 === null) {
  6659. pos = pos0;
  6660. }
  6661. return result0;
  6662. }
  6663. function parse_uri_parameters() {
  6664. var result0, result1, result2;
  6665. var pos0;
  6666. result0 = [];
  6667. pos0 = pos;
  6668. if (input.charCodeAt(pos) === 59) {
  6669. result1 = ";";
  6670. pos++;
  6671. } else {
  6672. result1 = null;
  6673. if (reportFailures === 0) {
  6674. matchFailed("\";\"");
  6675. }
  6676. }
  6677. if (result1 !== null) {
  6678. result2 = parse_uri_parameter();
  6679. if (result2 !== null) {
  6680. result1 = [result1, result2];
  6681. } else {
  6682. result1 = null;
  6683. pos = pos0;
  6684. }
  6685. } else {
  6686. result1 = null;
  6687. pos = pos0;
  6688. }
  6689. while (result1 !== null) {
  6690. result0.push(result1);
  6691. pos0 = pos;
  6692. if (input.charCodeAt(pos) === 59) {
  6693. result1 = ";";
  6694. pos++;
  6695. } else {
  6696. result1 = null;
  6697. if (reportFailures === 0) {
  6698. matchFailed("\";\"");
  6699. }
  6700. }
  6701. if (result1 !== null) {
  6702. result2 = parse_uri_parameter();
  6703. if (result2 !== null) {
  6704. result1 = [result1, result2];
  6705. } else {
  6706. result1 = null;
  6707. pos = pos0;
  6708. }
  6709. } else {
  6710. result1 = null;
  6711. pos = pos0;
  6712. }
  6713. }
  6714. return result0;
  6715. }
  6716. function parse_uri_parameter() {
  6717. var result0;
  6718. result0 = parse_transport_param();
  6719. if (result0 === null) {
  6720. result0 = parse_user_param();
  6721. if (result0 === null) {
  6722. result0 = parse_method_param();
  6723. if (result0 === null) {
  6724. result0 = parse_ttl_param();
  6725. if (result0 === null) {
  6726. result0 = parse_maddr_param();
  6727. if (result0 === null) {
  6728. result0 = parse_lr_param();
  6729. if (result0 === null) {
  6730. result0 = parse_other_param();
  6731. }
  6732. }
  6733. }
  6734. }
  6735. }
  6736. }
  6737. return result0;
  6738. }
  6739. function parse_transport_param() {
  6740. var result0, result1;
  6741. var pos0, pos1;
  6742. pos0 = pos;
  6743. pos1 = pos;
  6744. if (input.substr(pos, 10).toLowerCase() === "transport=") {
  6745. result0 = input.substr(pos, 10);
  6746. pos += 10;
  6747. } else {
  6748. result0 = null;
  6749. if (reportFailures === 0) {
  6750. matchFailed("\"transport=\"");
  6751. }
  6752. }
  6753. if (result0 !== null) {
  6754. if (input.substr(pos, 3).toLowerCase() === "udp") {
  6755. result1 = input.substr(pos, 3);
  6756. pos += 3;
  6757. } else {
  6758. result1 = null;
  6759. if (reportFailures === 0) {
  6760. matchFailed("\"udp\"");
  6761. }
  6762. }
  6763. if (result1 === null) {
  6764. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  6765. result1 = input.substr(pos, 3);
  6766. pos += 3;
  6767. } else {
  6768. result1 = null;
  6769. if (reportFailures === 0) {
  6770. matchFailed("\"tcp\"");
  6771. }
  6772. }
  6773. if (result1 === null) {
  6774. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  6775. result1 = input.substr(pos, 4);
  6776. pos += 4;
  6777. } else {
  6778. result1 = null;
  6779. if (reportFailures === 0) {
  6780. matchFailed("\"sctp\"");
  6781. }
  6782. }
  6783. if (result1 === null) {
  6784. if (input.substr(pos, 3).toLowerCase() === "tls") {
  6785. result1 = input.substr(pos, 3);
  6786. pos += 3;
  6787. } else {
  6788. result1 = null;
  6789. if (reportFailures === 0) {
  6790. matchFailed("\"tls\"");
  6791. }
  6792. }
  6793. if (result1 === null) {
  6794. result1 = parse_token();
  6795. }
  6796. }
  6797. }
  6798. }
  6799. if (result1 !== null) {
  6800. result0 = [result0, result1];
  6801. } else {
  6802. result0 = null;
  6803. pos = pos1;
  6804. }
  6805. } else {
  6806. result0 = null;
  6807. pos = pos1;
  6808. }
  6809. if (result0 !== null) {
  6810. result0 = function (offset, transport) {
  6811. if (!data.uri_params) data.uri_params = {};
  6812. data.uri_params['transport'] = transport.toLowerCase();
  6813. }(pos0, result0[1]);
  6814. }
  6815. if (result0 === null) {
  6816. pos = pos0;
  6817. }
  6818. return result0;
  6819. }
  6820. function parse_user_param() {
  6821. var result0, result1;
  6822. var pos0, pos1;
  6823. pos0 = pos;
  6824. pos1 = pos;
  6825. if (input.substr(pos, 5).toLowerCase() === "user=") {
  6826. result0 = input.substr(pos, 5);
  6827. pos += 5;
  6828. } else {
  6829. result0 = null;
  6830. if (reportFailures === 0) {
  6831. matchFailed("\"user=\"");
  6832. }
  6833. }
  6834. if (result0 !== null) {
  6835. if (input.substr(pos, 5).toLowerCase() === "phone") {
  6836. result1 = input.substr(pos, 5);
  6837. pos += 5;
  6838. } else {
  6839. result1 = null;
  6840. if (reportFailures === 0) {
  6841. matchFailed("\"phone\"");
  6842. }
  6843. }
  6844. if (result1 === null) {
  6845. if (input.substr(pos, 2).toLowerCase() === "ip") {
  6846. result1 = input.substr(pos, 2);
  6847. pos += 2;
  6848. } else {
  6849. result1 = null;
  6850. if (reportFailures === 0) {
  6851. matchFailed("\"ip\"");
  6852. }
  6853. }
  6854. if (result1 === null) {
  6855. result1 = parse_token();
  6856. }
  6857. }
  6858. if (result1 !== null) {
  6859. result0 = [result0, result1];
  6860. } else {
  6861. result0 = null;
  6862. pos = pos1;
  6863. }
  6864. } else {
  6865. result0 = null;
  6866. pos = pos1;
  6867. }
  6868. if (result0 !== null) {
  6869. result0 = function (offset, user) {
  6870. if (!data.uri_params) data.uri_params = {};
  6871. data.uri_params['user'] = user.toLowerCase();
  6872. }(pos0, result0[1]);
  6873. }
  6874. if (result0 === null) {
  6875. pos = pos0;
  6876. }
  6877. return result0;
  6878. }
  6879. function parse_method_param() {
  6880. var result0, result1;
  6881. var pos0, pos1;
  6882. pos0 = pos;
  6883. pos1 = pos;
  6884. if (input.substr(pos, 7).toLowerCase() === "method=") {
  6885. result0 = input.substr(pos, 7);
  6886. pos += 7;
  6887. } else {
  6888. result0 = null;
  6889. if (reportFailures === 0) {
  6890. matchFailed("\"method=\"");
  6891. }
  6892. }
  6893. if (result0 !== null) {
  6894. result1 = parse_Method();
  6895. if (result1 !== null) {
  6896. result0 = [result0, result1];
  6897. } else {
  6898. result0 = null;
  6899. pos = pos1;
  6900. }
  6901. } else {
  6902. result0 = null;
  6903. pos = pos1;
  6904. }
  6905. if (result0 !== null) {
  6906. result0 = function (offset, method) {
  6907. if (!data.uri_params) data.uri_params = {};
  6908. data.uri_params['method'] = method;
  6909. }(pos0, result0[1]);
  6910. }
  6911. if (result0 === null) {
  6912. pos = pos0;
  6913. }
  6914. return result0;
  6915. }
  6916. function parse_ttl_param() {
  6917. var result0, result1;
  6918. var pos0, pos1;
  6919. pos0 = pos;
  6920. pos1 = pos;
  6921. if (input.substr(pos, 4).toLowerCase() === "ttl=") {
  6922. result0 = input.substr(pos, 4);
  6923. pos += 4;
  6924. } else {
  6925. result0 = null;
  6926. if (reportFailures === 0) {
  6927. matchFailed("\"ttl=\"");
  6928. }
  6929. }
  6930. if (result0 !== null) {
  6931. result1 = parse_ttl();
  6932. if (result1 !== null) {
  6933. result0 = [result0, result1];
  6934. } else {
  6935. result0 = null;
  6936. pos = pos1;
  6937. }
  6938. } else {
  6939. result0 = null;
  6940. pos = pos1;
  6941. }
  6942. if (result0 !== null) {
  6943. result0 = function (offset, ttl) {
  6944. if (!data.params) data.params = {};
  6945. data.params['ttl'] = ttl;
  6946. }(pos0, result0[1]);
  6947. }
  6948. if (result0 === null) {
  6949. pos = pos0;
  6950. }
  6951. return result0;
  6952. }
  6953. function parse_maddr_param() {
  6954. var result0, result1;
  6955. var pos0, pos1;
  6956. pos0 = pos;
  6957. pos1 = pos;
  6958. if (input.substr(pos, 6).toLowerCase() === "maddr=") {
  6959. result0 = input.substr(pos, 6);
  6960. pos += 6;
  6961. } else {
  6962. result0 = null;
  6963. if (reportFailures === 0) {
  6964. matchFailed("\"maddr=\"");
  6965. }
  6966. }
  6967. if (result0 !== null) {
  6968. result1 = parse_host();
  6969. if (result1 !== null) {
  6970. result0 = [result0, result1];
  6971. } else {
  6972. result0 = null;
  6973. pos = pos1;
  6974. }
  6975. } else {
  6976. result0 = null;
  6977. pos = pos1;
  6978. }
  6979. if (result0 !== null) {
  6980. result0 = function (offset, maddr) {
  6981. if (!data.uri_params) data.uri_params = {};
  6982. data.uri_params['maddr'] = maddr;
  6983. }(pos0, result0[1]);
  6984. }
  6985. if (result0 === null) {
  6986. pos = pos0;
  6987. }
  6988. return result0;
  6989. }
  6990. function parse_lr_param() {
  6991. var result0, result1, result2;
  6992. var pos0, pos1, pos2;
  6993. pos0 = pos;
  6994. pos1 = pos;
  6995. if (input.substr(pos, 2).toLowerCase() === "lr") {
  6996. result0 = input.substr(pos, 2);
  6997. pos += 2;
  6998. } else {
  6999. result0 = null;
  7000. if (reportFailures === 0) {
  7001. matchFailed("\"lr\"");
  7002. }
  7003. }
  7004. if (result0 !== null) {
  7005. pos2 = pos;
  7006. if (input.charCodeAt(pos) === 61) {
  7007. result1 = "=";
  7008. pos++;
  7009. } else {
  7010. result1 = null;
  7011. if (reportFailures === 0) {
  7012. matchFailed("\"=\"");
  7013. }
  7014. }
  7015. if (result1 !== null) {
  7016. result2 = parse_token();
  7017. if (result2 !== null) {
  7018. result1 = [result1, result2];
  7019. } else {
  7020. result1 = null;
  7021. pos = pos2;
  7022. }
  7023. } else {
  7024. result1 = null;
  7025. pos = pos2;
  7026. }
  7027. result1 = result1 !== null ? result1 : "";
  7028. if (result1 !== null) {
  7029. result0 = [result0, result1];
  7030. } else {
  7031. result0 = null;
  7032. pos = pos1;
  7033. }
  7034. } else {
  7035. result0 = null;
  7036. pos = pos1;
  7037. }
  7038. if (result0 !== null) {
  7039. result0 = function (offset) {
  7040. if (!data.uri_params) data.uri_params = {};
  7041. data.uri_params['lr'] = undefined;
  7042. }(pos0);
  7043. }
  7044. if (result0 === null) {
  7045. pos = pos0;
  7046. }
  7047. return result0;
  7048. }
  7049. function parse_other_param() {
  7050. var result0, result1, result2;
  7051. var pos0, pos1, pos2;
  7052. pos0 = pos;
  7053. pos1 = pos;
  7054. result0 = parse_pname();
  7055. if (result0 !== null) {
  7056. pos2 = pos;
  7057. if (input.charCodeAt(pos) === 61) {
  7058. result1 = "=";
  7059. pos++;
  7060. } else {
  7061. result1 = null;
  7062. if (reportFailures === 0) {
  7063. matchFailed("\"=\"");
  7064. }
  7065. }
  7066. if (result1 !== null) {
  7067. result2 = parse_pvalue();
  7068. if (result2 !== null) {
  7069. result1 = [result1, result2];
  7070. } else {
  7071. result1 = null;
  7072. pos = pos2;
  7073. }
  7074. } else {
  7075. result1 = null;
  7076. pos = pos2;
  7077. }
  7078. result1 = result1 !== null ? result1 : "";
  7079. if (result1 !== null) {
  7080. result0 = [result0, result1];
  7081. } else {
  7082. result0 = null;
  7083. pos = pos1;
  7084. }
  7085. } else {
  7086. result0 = null;
  7087. pos = pos1;
  7088. }
  7089. if (result0 !== null) {
  7090. result0 = function (offset, param, value) {
  7091. if (!data.uri_params) data.uri_params = {};
  7092. if (typeof value === 'undefined') {
  7093. value = undefined;
  7094. } else {
  7095. value = value[1];
  7096. }
  7097. data.uri_params[param.toLowerCase()] = value;
  7098. }(pos0, result0[0], result0[1]);
  7099. }
  7100. if (result0 === null) {
  7101. pos = pos0;
  7102. }
  7103. return result0;
  7104. }
  7105. function parse_pname() {
  7106. var result0, result1;
  7107. var pos0;
  7108. pos0 = pos;
  7109. result1 = parse_paramchar();
  7110. if (result1 !== null) {
  7111. result0 = [];
  7112. while (result1 !== null) {
  7113. result0.push(result1);
  7114. result1 = parse_paramchar();
  7115. }
  7116. } else {
  7117. result0 = null;
  7118. }
  7119. if (result0 !== null) {
  7120. result0 = function (offset, pname) {
  7121. return pname.join('');
  7122. }(pos0, result0);
  7123. }
  7124. if (result0 === null) {
  7125. pos = pos0;
  7126. }
  7127. return result0;
  7128. }
  7129. function parse_pvalue() {
  7130. var result0, result1;
  7131. var pos0;
  7132. pos0 = pos;
  7133. result1 = parse_paramchar();
  7134. if (result1 !== null) {
  7135. result0 = [];
  7136. while (result1 !== null) {
  7137. result0.push(result1);
  7138. result1 = parse_paramchar();
  7139. }
  7140. } else {
  7141. result0 = null;
  7142. }
  7143. if (result0 !== null) {
  7144. result0 = function (offset, pvalue) {
  7145. return pvalue.join('');
  7146. }(pos0, result0);
  7147. }
  7148. if (result0 === null) {
  7149. pos = pos0;
  7150. }
  7151. return result0;
  7152. }
  7153. function parse_paramchar() {
  7154. var result0;
  7155. result0 = parse_param_unreserved();
  7156. if (result0 === null) {
  7157. result0 = parse_unreserved();
  7158. if (result0 === null) {
  7159. result0 = parse_escaped();
  7160. }
  7161. }
  7162. return result0;
  7163. }
  7164. function parse_param_unreserved() {
  7165. var result0;
  7166. if (input.charCodeAt(pos) === 91) {
  7167. result0 = "[";
  7168. pos++;
  7169. } else {
  7170. result0 = null;
  7171. if (reportFailures === 0) {
  7172. matchFailed("\"[\"");
  7173. }
  7174. }
  7175. if (result0 === null) {
  7176. if (input.charCodeAt(pos) === 93) {
  7177. result0 = "]";
  7178. pos++;
  7179. } else {
  7180. result0 = null;
  7181. if (reportFailures === 0) {
  7182. matchFailed("\"]\"");
  7183. }
  7184. }
  7185. if (result0 === null) {
  7186. if (input.charCodeAt(pos) === 47) {
  7187. result0 = "/";
  7188. pos++;
  7189. } else {
  7190. result0 = null;
  7191. if (reportFailures === 0) {
  7192. matchFailed("\"/\"");
  7193. }
  7194. }
  7195. if (result0 === null) {
  7196. if (input.charCodeAt(pos) === 58) {
  7197. result0 = ":";
  7198. pos++;
  7199. } else {
  7200. result0 = null;
  7201. if (reportFailures === 0) {
  7202. matchFailed("\":\"");
  7203. }
  7204. }
  7205. if (result0 === null) {
  7206. if (input.charCodeAt(pos) === 38) {
  7207. result0 = "&";
  7208. pos++;
  7209. } else {
  7210. result0 = null;
  7211. if (reportFailures === 0) {
  7212. matchFailed("\"&\"");
  7213. }
  7214. }
  7215. if (result0 === null) {
  7216. if (input.charCodeAt(pos) === 43) {
  7217. result0 = "+";
  7218. pos++;
  7219. } else {
  7220. result0 = null;
  7221. if (reportFailures === 0) {
  7222. matchFailed("\"+\"");
  7223. }
  7224. }
  7225. if (result0 === null) {
  7226. if (input.charCodeAt(pos) === 36) {
  7227. result0 = "$";
  7228. pos++;
  7229. } else {
  7230. result0 = null;
  7231. if (reportFailures === 0) {
  7232. matchFailed("\"$\"");
  7233. }
  7234. }
  7235. }
  7236. }
  7237. }
  7238. }
  7239. }
  7240. }
  7241. return result0;
  7242. }
  7243. function parse_headers() {
  7244. var result0, result1, result2, result3, result4;
  7245. var pos0, pos1;
  7246. pos0 = pos;
  7247. if (input.charCodeAt(pos) === 63) {
  7248. result0 = "?";
  7249. pos++;
  7250. } else {
  7251. result0 = null;
  7252. if (reportFailures === 0) {
  7253. matchFailed("\"?\"");
  7254. }
  7255. }
  7256. if (result0 !== null) {
  7257. result1 = parse_header();
  7258. if (result1 !== null) {
  7259. result2 = [];
  7260. pos1 = pos;
  7261. if (input.charCodeAt(pos) === 38) {
  7262. result3 = "&";
  7263. pos++;
  7264. } else {
  7265. result3 = null;
  7266. if (reportFailures === 0) {
  7267. matchFailed("\"&\"");
  7268. }
  7269. }
  7270. if (result3 !== null) {
  7271. result4 = parse_header();
  7272. if (result4 !== null) {
  7273. result3 = [result3, result4];
  7274. } else {
  7275. result3 = null;
  7276. pos = pos1;
  7277. }
  7278. } else {
  7279. result3 = null;
  7280. pos = pos1;
  7281. }
  7282. while (result3 !== null) {
  7283. result2.push(result3);
  7284. pos1 = pos;
  7285. if (input.charCodeAt(pos) === 38) {
  7286. result3 = "&";
  7287. pos++;
  7288. } else {
  7289. result3 = null;
  7290. if (reportFailures === 0) {
  7291. matchFailed("\"&\"");
  7292. }
  7293. }
  7294. if (result3 !== null) {
  7295. result4 = parse_header();
  7296. if (result4 !== null) {
  7297. result3 = [result3, result4];
  7298. } else {
  7299. result3 = null;
  7300. pos = pos1;
  7301. }
  7302. } else {
  7303. result3 = null;
  7304. pos = pos1;
  7305. }
  7306. }
  7307. if (result2 !== null) {
  7308. result0 = [result0, result1, result2];
  7309. } else {
  7310. result0 = null;
  7311. pos = pos0;
  7312. }
  7313. } else {
  7314. result0 = null;
  7315. pos = pos0;
  7316. }
  7317. } else {
  7318. result0 = null;
  7319. pos = pos0;
  7320. }
  7321. return result0;
  7322. }
  7323. function parse_header() {
  7324. var result0, result1, result2;
  7325. var pos0, pos1;
  7326. pos0 = pos;
  7327. pos1 = pos;
  7328. result0 = parse_hname();
  7329. if (result0 !== null) {
  7330. if (input.charCodeAt(pos) === 61) {
  7331. result1 = "=";
  7332. pos++;
  7333. } else {
  7334. result1 = null;
  7335. if (reportFailures === 0) {
  7336. matchFailed("\"=\"");
  7337. }
  7338. }
  7339. if (result1 !== null) {
  7340. result2 = parse_hvalue();
  7341. if (result2 !== null) {
  7342. result0 = [result0, result1, result2];
  7343. } else {
  7344. result0 = null;
  7345. pos = pos1;
  7346. }
  7347. } else {
  7348. result0 = null;
  7349. pos = pos1;
  7350. }
  7351. } else {
  7352. result0 = null;
  7353. pos = pos1;
  7354. }
  7355. if (result0 !== null) {
  7356. result0 = function (offset, hname, hvalue) {
  7357. hname = hname.join('').toLowerCase();
  7358. hvalue = hvalue.join('');
  7359. if (!data.uri_headers) data.uri_headers = {};
  7360. if (!data.uri_headers[hname]) {
  7361. data.uri_headers[hname] = [hvalue];
  7362. } else {
  7363. data.uri_headers[hname].push(hvalue);
  7364. }
  7365. }(pos0, result0[0], result0[2]);
  7366. }
  7367. if (result0 === null) {
  7368. pos = pos0;
  7369. }
  7370. return result0;
  7371. }
  7372. function parse_hname() {
  7373. var result0, result1;
  7374. result1 = parse_hnv_unreserved();
  7375. if (result1 === null) {
  7376. result1 = parse_unreserved();
  7377. if (result1 === null) {
  7378. result1 = parse_escaped();
  7379. }
  7380. }
  7381. if (result1 !== null) {
  7382. result0 = [];
  7383. while (result1 !== null) {
  7384. result0.push(result1);
  7385. result1 = parse_hnv_unreserved();
  7386. if (result1 === null) {
  7387. result1 = parse_unreserved();
  7388. if (result1 === null) {
  7389. result1 = parse_escaped();
  7390. }
  7391. }
  7392. }
  7393. } else {
  7394. result0 = null;
  7395. }
  7396. return result0;
  7397. }
  7398. function parse_hvalue() {
  7399. var result0, result1;
  7400. result0 = [];
  7401. result1 = parse_hnv_unreserved();
  7402. if (result1 === null) {
  7403. result1 = parse_unreserved();
  7404. if (result1 === null) {
  7405. result1 = parse_escaped();
  7406. }
  7407. }
  7408. while (result1 !== null) {
  7409. result0.push(result1);
  7410. result1 = parse_hnv_unreserved();
  7411. if (result1 === null) {
  7412. result1 = parse_unreserved();
  7413. if (result1 === null) {
  7414. result1 = parse_escaped();
  7415. }
  7416. }
  7417. }
  7418. return result0;
  7419. }
  7420. function parse_hnv_unreserved() {
  7421. var result0;
  7422. if (input.charCodeAt(pos) === 91) {
  7423. result0 = "[";
  7424. pos++;
  7425. } else {
  7426. result0 = null;
  7427. if (reportFailures === 0) {
  7428. matchFailed("\"[\"");
  7429. }
  7430. }
  7431. if (result0 === null) {
  7432. if (input.charCodeAt(pos) === 93) {
  7433. result0 = "]";
  7434. pos++;
  7435. } else {
  7436. result0 = null;
  7437. if (reportFailures === 0) {
  7438. matchFailed("\"]\"");
  7439. }
  7440. }
  7441. if (result0 === null) {
  7442. if (input.charCodeAt(pos) === 47) {
  7443. result0 = "/";
  7444. pos++;
  7445. } else {
  7446. result0 = null;
  7447. if (reportFailures === 0) {
  7448. matchFailed("\"/\"");
  7449. }
  7450. }
  7451. if (result0 === null) {
  7452. if (input.charCodeAt(pos) === 63) {
  7453. result0 = "?";
  7454. pos++;
  7455. } else {
  7456. result0 = null;
  7457. if (reportFailures === 0) {
  7458. matchFailed("\"?\"");
  7459. }
  7460. }
  7461. if (result0 === null) {
  7462. if (input.charCodeAt(pos) === 58) {
  7463. result0 = ":";
  7464. pos++;
  7465. } else {
  7466. result0 = null;
  7467. if (reportFailures === 0) {
  7468. matchFailed("\":\"");
  7469. }
  7470. }
  7471. if (result0 === null) {
  7472. if (input.charCodeAt(pos) === 43) {
  7473. result0 = "+";
  7474. pos++;
  7475. } else {
  7476. result0 = null;
  7477. if (reportFailures === 0) {
  7478. matchFailed("\"+\"");
  7479. }
  7480. }
  7481. if (result0 === null) {
  7482. if (input.charCodeAt(pos) === 36) {
  7483. result0 = "$";
  7484. pos++;
  7485. } else {
  7486. result0 = null;
  7487. if (reportFailures === 0) {
  7488. matchFailed("\"$\"");
  7489. }
  7490. }
  7491. }
  7492. }
  7493. }
  7494. }
  7495. }
  7496. }
  7497. return result0;
  7498. }
  7499. function parse_Request_Response() {
  7500. var result0;
  7501. result0 = parse_Status_Line();
  7502. if (result0 === null) {
  7503. result0 = parse_Request_Line();
  7504. }
  7505. return result0;
  7506. }
  7507. function parse_Request_Line() {
  7508. var result0, result1, result2, result3, result4;
  7509. var pos0;
  7510. pos0 = pos;
  7511. result0 = parse_Method();
  7512. if (result0 !== null) {
  7513. result1 = parse_SP();
  7514. if (result1 !== null) {
  7515. result2 = parse_Request_URI();
  7516. if (result2 !== null) {
  7517. result3 = parse_SP();
  7518. if (result3 !== null) {
  7519. result4 = parse_SIP_Version();
  7520. if (result4 !== null) {
  7521. result0 = [result0, result1, result2, result3, result4];
  7522. } else {
  7523. result0 = null;
  7524. pos = pos0;
  7525. }
  7526. } else {
  7527. result0 = null;
  7528. pos = pos0;
  7529. }
  7530. } else {
  7531. result0 = null;
  7532. pos = pos0;
  7533. }
  7534. } else {
  7535. result0 = null;
  7536. pos = pos0;
  7537. }
  7538. } else {
  7539. result0 = null;
  7540. pos = pos0;
  7541. }
  7542. return result0;
  7543. }
  7544. function parse_Request_URI() {
  7545. var result0;
  7546. result0 = parse_SIP_URI();
  7547. if (result0 === null) {
  7548. result0 = parse_absoluteURI();
  7549. }
  7550. return result0;
  7551. }
  7552. function parse_absoluteURI() {
  7553. var result0, result1, result2;
  7554. var pos0;
  7555. pos0 = pos;
  7556. result0 = parse_scheme();
  7557. if (result0 !== null) {
  7558. if (input.charCodeAt(pos) === 58) {
  7559. result1 = ":";
  7560. pos++;
  7561. } else {
  7562. result1 = null;
  7563. if (reportFailures === 0) {
  7564. matchFailed("\":\"");
  7565. }
  7566. }
  7567. if (result1 !== null) {
  7568. result2 = parse_hier_part();
  7569. if (result2 === null) {
  7570. result2 = parse_opaque_part();
  7571. }
  7572. if (result2 !== null) {
  7573. result0 = [result0, result1, result2];
  7574. } else {
  7575. result0 = null;
  7576. pos = pos0;
  7577. }
  7578. } else {
  7579. result0 = null;
  7580. pos = pos0;
  7581. }
  7582. } else {
  7583. result0 = null;
  7584. pos = pos0;
  7585. }
  7586. return result0;
  7587. }
  7588. function parse_hier_part() {
  7589. var result0, result1, result2;
  7590. var pos0, pos1;
  7591. pos0 = pos;
  7592. result0 = parse_net_path();
  7593. if (result0 === null) {
  7594. result0 = parse_abs_path();
  7595. }
  7596. if (result0 !== null) {
  7597. pos1 = pos;
  7598. if (input.charCodeAt(pos) === 63) {
  7599. result1 = "?";
  7600. pos++;
  7601. } else {
  7602. result1 = null;
  7603. if (reportFailures === 0) {
  7604. matchFailed("\"?\"");
  7605. }
  7606. }
  7607. if (result1 !== null) {
  7608. result2 = parse_query();
  7609. if (result2 !== null) {
  7610. result1 = [result1, result2];
  7611. } else {
  7612. result1 = null;
  7613. pos = pos1;
  7614. }
  7615. } else {
  7616. result1 = null;
  7617. pos = pos1;
  7618. }
  7619. result1 = result1 !== null ? result1 : "";
  7620. if (result1 !== null) {
  7621. result0 = [result0, result1];
  7622. } else {
  7623. result0 = null;
  7624. pos = pos0;
  7625. }
  7626. } else {
  7627. result0 = null;
  7628. pos = pos0;
  7629. }
  7630. return result0;
  7631. }
  7632. function parse_net_path() {
  7633. var result0, result1, result2;
  7634. var pos0;
  7635. pos0 = pos;
  7636. if (input.substr(pos, 2) === "//") {
  7637. result0 = "//";
  7638. pos += 2;
  7639. } else {
  7640. result0 = null;
  7641. if (reportFailures === 0) {
  7642. matchFailed("\"//\"");
  7643. }
  7644. }
  7645. if (result0 !== null) {
  7646. result1 = parse_authority();
  7647. if (result1 !== null) {
  7648. result2 = parse_abs_path();
  7649. result2 = result2 !== null ? result2 : "";
  7650. if (result2 !== null) {
  7651. result0 = [result0, result1, result2];
  7652. } else {
  7653. result0 = null;
  7654. pos = pos0;
  7655. }
  7656. } else {
  7657. result0 = null;
  7658. pos = pos0;
  7659. }
  7660. } else {
  7661. result0 = null;
  7662. pos = pos0;
  7663. }
  7664. return result0;
  7665. }
  7666. function parse_abs_path() {
  7667. var result0, result1;
  7668. var pos0;
  7669. pos0 = pos;
  7670. if (input.charCodeAt(pos) === 47) {
  7671. result0 = "/";
  7672. pos++;
  7673. } else {
  7674. result0 = null;
  7675. if (reportFailures === 0) {
  7676. matchFailed("\"/\"");
  7677. }
  7678. }
  7679. if (result0 !== null) {
  7680. result1 = parse_path_segments();
  7681. if (result1 !== null) {
  7682. result0 = [result0, result1];
  7683. } else {
  7684. result0 = null;
  7685. pos = pos0;
  7686. }
  7687. } else {
  7688. result0 = null;
  7689. pos = pos0;
  7690. }
  7691. return result0;
  7692. }
  7693. function parse_opaque_part() {
  7694. var result0, result1, result2;
  7695. var pos0;
  7696. pos0 = pos;
  7697. result0 = parse_uric_no_slash();
  7698. if (result0 !== null) {
  7699. result1 = [];
  7700. result2 = parse_uric();
  7701. while (result2 !== null) {
  7702. result1.push(result2);
  7703. result2 = parse_uric();
  7704. }
  7705. if (result1 !== null) {
  7706. result0 = [result0, result1];
  7707. } else {
  7708. result0 = null;
  7709. pos = pos0;
  7710. }
  7711. } else {
  7712. result0 = null;
  7713. pos = pos0;
  7714. }
  7715. return result0;
  7716. }
  7717. function parse_uric() {
  7718. var result0;
  7719. result0 = parse_reserved();
  7720. if (result0 === null) {
  7721. result0 = parse_unreserved();
  7722. if (result0 === null) {
  7723. result0 = parse_escaped();
  7724. }
  7725. }
  7726. return result0;
  7727. }
  7728. function parse_uric_no_slash() {
  7729. var result0;
  7730. result0 = parse_unreserved();
  7731. if (result0 === null) {
  7732. result0 = parse_escaped();
  7733. if (result0 === null) {
  7734. if (input.charCodeAt(pos) === 59) {
  7735. result0 = ";";
  7736. pos++;
  7737. } else {
  7738. result0 = null;
  7739. if (reportFailures === 0) {
  7740. matchFailed("\";\"");
  7741. }
  7742. }
  7743. if (result0 === null) {
  7744. if (input.charCodeAt(pos) === 63) {
  7745. result0 = "?";
  7746. pos++;
  7747. } else {
  7748. result0 = null;
  7749. if (reportFailures === 0) {
  7750. matchFailed("\"?\"");
  7751. }
  7752. }
  7753. if (result0 === null) {
  7754. if (input.charCodeAt(pos) === 58) {
  7755. result0 = ":";
  7756. pos++;
  7757. } else {
  7758. result0 = null;
  7759. if (reportFailures === 0) {
  7760. matchFailed("\":\"");
  7761. }
  7762. }
  7763. if (result0 === null) {
  7764. if (input.charCodeAt(pos) === 64) {
  7765. result0 = "@";
  7766. pos++;
  7767. } else {
  7768. result0 = null;
  7769. if (reportFailures === 0) {
  7770. matchFailed("\"@\"");
  7771. }
  7772. }
  7773. if (result0 === null) {
  7774. if (input.charCodeAt(pos) === 38) {
  7775. result0 = "&";
  7776. pos++;
  7777. } else {
  7778. result0 = null;
  7779. if (reportFailures === 0) {
  7780. matchFailed("\"&\"");
  7781. }
  7782. }
  7783. if (result0 === null) {
  7784. if (input.charCodeAt(pos) === 61) {
  7785. result0 = "=";
  7786. pos++;
  7787. } else {
  7788. result0 = null;
  7789. if (reportFailures === 0) {
  7790. matchFailed("\"=\"");
  7791. }
  7792. }
  7793. if (result0 === null) {
  7794. if (input.charCodeAt(pos) === 43) {
  7795. result0 = "+";
  7796. pos++;
  7797. } else {
  7798. result0 = null;
  7799. if (reportFailures === 0) {
  7800. matchFailed("\"+\"");
  7801. }
  7802. }
  7803. if (result0 === null) {
  7804. if (input.charCodeAt(pos) === 36) {
  7805. result0 = "$";
  7806. pos++;
  7807. } else {
  7808. result0 = null;
  7809. if (reportFailures === 0) {
  7810. matchFailed("\"$\"");
  7811. }
  7812. }
  7813. if (result0 === null) {
  7814. if (input.charCodeAt(pos) === 44) {
  7815. result0 = ",";
  7816. pos++;
  7817. } else {
  7818. result0 = null;
  7819. if (reportFailures === 0) {
  7820. matchFailed("\",\"");
  7821. }
  7822. }
  7823. }
  7824. }
  7825. }
  7826. }
  7827. }
  7828. }
  7829. }
  7830. }
  7831. }
  7832. }
  7833. return result0;
  7834. }
  7835. function parse_path_segments() {
  7836. var result0, result1, result2, result3;
  7837. var pos0, pos1;
  7838. pos0 = pos;
  7839. result0 = parse_segment();
  7840. if (result0 !== null) {
  7841. result1 = [];
  7842. pos1 = pos;
  7843. if (input.charCodeAt(pos) === 47) {
  7844. result2 = "/";
  7845. pos++;
  7846. } else {
  7847. result2 = null;
  7848. if (reportFailures === 0) {
  7849. matchFailed("\"/\"");
  7850. }
  7851. }
  7852. if (result2 !== null) {
  7853. result3 = parse_segment();
  7854. if (result3 !== null) {
  7855. result2 = [result2, result3];
  7856. } else {
  7857. result2 = null;
  7858. pos = pos1;
  7859. }
  7860. } else {
  7861. result2 = null;
  7862. pos = pos1;
  7863. }
  7864. while (result2 !== null) {
  7865. result1.push(result2);
  7866. pos1 = pos;
  7867. if (input.charCodeAt(pos) === 47) {
  7868. result2 = "/";
  7869. pos++;
  7870. } else {
  7871. result2 = null;
  7872. if (reportFailures === 0) {
  7873. matchFailed("\"/\"");
  7874. }
  7875. }
  7876. if (result2 !== null) {
  7877. result3 = parse_segment();
  7878. if (result3 !== null) {
  7879. result2 = [result2, result3];
  7880. } else {
  7881. result2 = null;
  7882. pos = pos1;
  7883. }
  7884. } else {
  7885. result2 = null;
  7886. pos = pos1;
  7887. }
  7888. }
  7889. if (result1 !== null) {
  7890. result0 = [result0, result1];
  7891. } else {
  7892. result0 = null;
  7893. pos = pos0;
  7894. }
  7895. } else {
  7896. result0 = null;
  7897. pos = pos0;
  7898. }
  7899. return result0;
  7900. }
  7901. function parse_segment() {
  7902. var result0, result1, result2, result3;
  7903. var pos0, pos1;
  7904. pos0 = pos;
  7905. result0 = [];
  7906. result1 = parse_pchar();
  7907. while (result1 !== null) {
  7908. result0.push(result1);
  7909. result1 = parse_pchar();
  7910. }
  7911. if (result0 !== null) {
  7912. result1 = [];
  7913. pos1 = pos;
  7914. if (input.charCodeAt(pos) === 59) {
  7915. result2 = ";";
  7916. pos++;
  7917. } else {
  7918. result2 = null;
  7919. if (reportFailures === 0) {
  7920. matchFailed("\";\"");
  7921. }
  7922. }
  7923. if (result2 !== null) {
  7924. result3 = parse_param();
  7925. if (result3 !== null) {
  7926. result2 = [result2, result3];
  7927. } else {
  7928. result2 = null;
  7929. pos = pos1;
  7930. }
  7931. } else {
  7932. result2 = null;
  7933. pos = pos1;
  7934. }
  7935. while (result2 !== null) {
  7936. result1.push(result2);
  7937. pos1 = pos;
  7938. if (input.charCodeAt(pos) === 59) {
  7939. result2 = ";";
  7940. pos++;
  7941. } else {
  7942. result2 = null;
  7943. if (reportFailures === 0) {
  7944. matchFailed("\";\"");
  7945. }
  7946. }
  7947. if (result2 !== null) {
  7948. result3 = parse_param();
  7949. if (result3 !== null) {
  7950. result2 = [result2, result3];
  7951. } else {
  7952. result2 = null;
  7953. pos = pos1;
  7954. }
  7955. } else {
  7956. result2 = null;
  7957. pos = pos1;
  7958. }
  7959. }
  7960. if (result1 !== null) {
  7961. result0 = [result0, result1];
  7962. } else {
  7963. result0 = null;
  7964. pos = pos0;
  7965. }
  7966. } else {
  7967. result0 = null;
  7968. pos = pos0;
  7969. }
  7970. return result0;
  7971. }
  7972. function parse_param() {
  7973. var result0, result1;
  7974. result0 = [];
  7975. result1 = parse_pchar();
  7976. while (result1 !== null) {
  7977. result0.push(result1);
  7978. result1 = parse_pchar();
  7979. }
  7980. return result0;
  7981. }
  7982. function parse_pchar() {
  7983. var result0;
  7984. result0 = parse_unreserved();
  7985. if (result0 === null) {
  7986. result0 = parse_escaped();
  7987. if (result0 === null) {
  7988. if (input.charCodeAt(pos) === 58) {
  7989. result0 = ":";
  7990. pos++;
  7991. } else {
  7992. result0 = null;
  7993. if (reportFailures === 0) {
  7994. matchFailed("\":\"");
  7995. }
  7996. }
  7997. if (result0 === null) {
  7998. if (input.charCodeAt(pos) === 64) {
  7999. result0 = "@";
  8000. pos++;
  8001. } else {
  8002. result0 = null;
  8003. if (reportFailures === 0) {
  8004. matchFailed("\"@\"");
  8005. }
  8006. }
  8007. if (result0 === null) {
  8008. if (input.charCodeAt(pos) === 38) {
  8009. result0 = "&";
  8010. pos++;
  8011. } else {
  8012. result0 = null;
  8013. if (reportFailures === 0) {
  8014. matchFailed("\"&\"");
  8015. }
  8016. }
  8017. if (result0 === null) {
  8018. if (input.charCodeAt(pos) === 61) {
  8019. result0 = "=";
  8020. pos++;
  8021. } else {
  8022. result0 = null;
  8023. if (reportFailures === 0) {
  8024. matchFailed("\"=\"");
  8025. }
  8026. }
  8027. if (result0 === null) {
  8028. if (input.charCodeAt(pos) === 43) {
  8029. result0 = "+";
  8030. pos++;
  8031. } else {
  8032. result0 = null;
  8033. if (reportFailures === 0) {
  8034. matchFailed("\"+\"");
  8035. }
  8036. }
  8037. if (result0 === null) {
  8038. if (input.charCodeAt(pos) === 36) {
  8039. result0 = "$";
  8040. pos++;
  8041. } else {
  8042. result0 = null;
  8043. if (reportFailures === 0) {
  8044. matchFailed("\"$\"");
  8045. }
  8046. }
  8047. if (result0 === null) {
  8048. if (input.charCodeAt(pos) === 44) {
  8049. result0 = ",";
  8050. pos++;
  8051. } else {
  8052. result0 = null;
  8053. if (reportFailures === 0) {
  8054. matchFailed("\",\"");
  8055. }
  8056. }
  8057. }
  8058. }
  8059. }
  8060. }
  8061. }
  8062. }
  8063. }
  8064. }
  8065. return result0;
  8066. }
  8067. function parse_scheme() {
  8068. var result0, result1, result2;
  8069. var pos0, pos1;
  8070. pos0 = pos;
  8071. pos1 = pos;
  8072. result0 = parse_ALPHA();
  8073. if (result0 !== null) {
  8074. result1 = [];
  8075. result2 = parse_ALPHA();
  8076. if (result2 === null) {
  8077. result2 = parse_DIGIT();
  8078. if (result2 === null) {
  8079. if (input.charCodeAt(pos) === 43) {
  8080. result2 = "+";
  8081. pos++;
  8082. } else {
  8083. result2 = null;
  8084. if (reportFailures === 0) {
  8085. matchFailed("\"+\"");
  8086. }
  8087. }
  8088. if (result2 === null) {
  8089. if (input.charCodeAt(pos) === 45) {
  8090. result2 = "-";
  8091. pos++;
  8092. } else {
  8093. result2 = null;
  8094. if (reportFailures === 0) {
  8095. matchFailed("\"-\"");
  8096. }
  8097. }
  8098. if (result2 === null) {
  8099. if (input.charCodeAt(pos) === 46) {
  8100. result2 = ".";
  8101. pos++;
  8102. } else {
  8103. result2 = null;
  8104. if (reportFailures === 0) {
  8105. matchFailed("\".\"");
  8106. }
  8107. }
  8108. }
  8109. }
  8110. }
  8111. }
  8112. while (result2 !== null) {
  8113. result1.push(result2);
  8114. result2 = parse_ALPHA();
  8115. if (result2 === null) {
  8116. result2 = parse_DIGIT();
  8117. if (result2 === null) {
  8118. if (input.charCodeAt(pos) === 43) {
  8119. result2 = "+";
  8120. pos++;
  8121. } else {
  8122. result2 = null;
  8123. if (reportFailures === 0) {
  8124. matchFailed("\"+\"");
  8125. }
  8126. }
  8127. if (result2 === null) {
  8128. if (input.charCodeAt(pos) === 45) {
  8129. result2 = "-";
  8130. pos++;
  8131. } else {
  8132. result2 = null;
  8133. if (reportFailures === 0) {
  8134. matchFailed("\"-\"");
  8135. }
  8136. }
  8137. if (result2 === null) {
  8138. if (input.charCodeAt(pos) === 46) {
  8139. result2 = ".";
  8140. pos++;
  8141. } else {
  8142. result2 = null;
  8143. if (reportFailures === 0) {
  8144. matchFailed("\".\"");
  8145. }
  8146. }
  8147. }
  8148. }
  8149. }
  8150. }
  8151. }
  8152. if (result1 !== null) {
  8153. result0 = [result0, result1];
  8154. } else {
  8155. result0 = null;
  8156. pos = pos1;
  8157. }
  8158. } else {
  8159. result0 = null;
  8160. pos = pos1;
  8161. }
  8162. if (result0 !== null) {
  8163. result0 = function (offset) {
  8164. data.scheme = input.substring(pos, offset);
  8165. }(pos0);
  8166. }
  8167. if (result0 === null) {
  8168. pos = pos0;
  8169. }
  8170. return result0;
  8171. }
  8172. function parse_authority() {
  8173. var result0;
  8174. result0 = parse_srvr();
  8175. if (result0 === null) {
  8176. result0 = parse_reg_name();
  8177. }
  8178. return result0;
  8179. }
  8180. function parse_srvr() {
  8181. var result0, result1;
  8182. var pos0, pos1;
  8183. pos0 = pos;
  8184. pos1 = pos;
  8185. result0 = parse_userinfo();
  8186. if (result0 !== null) {
  8187. if (input.charCodeAt(pos) === 64) {
  8188. result1 = "@";
  8189. pos++;
  8190. } else {
  8191. result1 = null;
  8192. if (reportFailures === 0) {
  8193. matchFailed("\"@\"");
  8194. }
  8195. }
  8196. if (result1 !== null) {
  8197. result0 = [result0, result1];
  8198. } else {
  8199. result0 = null;
  8200. pos = pos1;
  8201. }
  8202. } else {
  8203. result0 = null;
  8204. pos = pos1;
  8205. }
  8206. result0 = result0 !== null ? result0 : "";
  8207. if (result0 !== null) {
  8208. result1 = parse_hostport();
  8209. if (result1 !== null) {
  8210. result0 = [result0, result1];
  8211. } else {
  8212. result0 = null;
  8213. pos = pos0;
  8214. }
  8215. } else {
  8216. result0 = null;
  8217. pos = pos0;
  8218. }
  8219. result0 = result0 !== null ? result0 : "";
  8220. return result0;
  8221. }
  8222. function parse_reg_name() {
  8223. var result0, result1;
  8224. result1 = parse_unreserved();
  8225. if (result1 === null) {
  8226. result1 = parse_escaped();
  8227. if (result1 === null) {
  8228. if (input.charCodeAt(pos) === 36) {
  8229. result1 = "$";
  8230. pos++;
  8231. } else {
  8232. result1 = null;
  8233. if (reportFailures === 0) {
  8234. matchFailed("\"$\"");
  8235. }
  8236. }
  8237. if (result1 === null) {
  8238. if (input.charCodeAt(pos) === 44) {
  8239. result1 = ",";
  8240. pos++;
  8241. } else {
  8242. result1 = null;
  8243. if (reportFailures === 0) {
  8244. matchFailed("\",\"");
  8245. }
  8246. }
  8247. if (result1 === null) {
  8248. if (input.charCodeAt(pos) === 59) {
  8249. result1 = ";";
  8250. pos++;
  8251. } else {
  8252. result1 = null;
  8253. if (reportFailures === 0) {
  8254. matchFailed("\";\"");
  8255. }
  8256. }
  8257. if (result1 === null) {
  8258. if (input.charCodeAt(pos) === 58) {
  8259. result1 = ":";
  8260. pos++;
  8261. } else {
  8262. result1 = null;
  8263. if (reportFailures === 0) {
  8264. matchFailed("\":\"");
  8265. }
  8266. }
  8267. if (result1 === null) {
  8268. if (input.charCodeAt(pos) === 64) {
  8269. result1 = "@";
  8270. pos++;
  8271. } else {
  8272. result1 = null;
  8273. if (reportFailures === 0) {
  8274. matchFailed("\"@\"");
  8275. }
  8276. }
  8277. if (result1 === null) {
  8278. if (input.charCodeAt(pos) === 38) {
  8279. result1 = "&";
  8280. pos++;
  8281. } else {
  8282. result1 = null;
  8283. if (reportFailures === 0) {
  8284. matchFailed("\"&\"");
  8285. }
  8286. }
  8287. if (result1 === null) {
  8288. if (input.charCodeAt(pos) === 61) {
  8289. result1 = "=";
  8290. pos++;
  8291. } else {
  8292. result1 = null;
  8293. if (reportFailures === 0) {
  8294. matchFailed("\"=\"");
  8295. }
  8296. }
  8297. if (result1 === null) {
  8298. if (input.charCodeAt(pos) === 43) {
  8299. result1 = "+";
  8300. pos++;
  8301. } else {
  8302. result1 = null;
  8303. if (reportFailures === 0) {
  8304. matchFailed("\"+\"");
  8305. }
  8306. }
  8307. }
  8308. }
  8309. }
  8310. }
  8311. }
  8312. }
  8313. }
  8314. }
  8315. }
  8316. if (result1 !== null) {
  8317. result0 = [];
  8318. while (result1 !== null) {
  8319. result0.push(result1);
  8320. result1 = parse_unreserved();
  8321. if (result1 === null) {
  8322. result1 = parse_escaped();
  8323. if (result1 === null) {
  8324. if (input.charCodeAt(pos) === 36) {
  8325. result1 = "$";
  8326. pos++;
  8327. } else {
  8328. result1 = null;
  8329. if (reportFailures === 0) {
  8330. matchFailed("\"$\"");
  8331. }
  8332. }
  8333. if (result1 === null) {
  8334. if (input.charCodeAt(pos) === 44) {
  8335. result1 = ",";
  8336. pos++;
  8337. } else {
  8338. result1 = null;
  8339. if (reportFailures === 0) {
  8340. matchFailed("\",\"");
  8341. }
  8342. }
  8343. if (result1 === null) {
  8344. if (input.charCodeAt(pos) === 59) {
  8345. result1 = ";";
  8346. pos++;
  8347. } else {
  8348. result1 = null;
  8349. if (reportFailures === 0) {
  8350. matchFailed("\";\"");
  8351. }
  8352. }
  8353. if (result1 === null) {
  8354. if (input.charCodeAt(pos) === 58) {
  8355. result1 = ":";
  8356. pos++;
  8357. } else {
  8358. result1 = null;
  8359. if (reportFailures === 0) {
  8360. matchFailed("\":\"");
  8361. }
  8362. }
  8363. if (result1 === null) {
  8364. if (input.charCodeAt(pos) === 64) {
  8365. result1 = "@";
  8366. pos++;
  8367. } else {
  8368. result1 = null;
  8369. if (reportFailures === 0) {
  8370. matchFailed("\"@\"");
  8371. }
  8372. }
  8373. if (result1 === null) {
  8374. if (input.charCodeAt(pos) === 38) {
  8375. result1 = "&";
  8376. pos++;
  8377. } else {
  8378. result1 = null;
  8379. if (reportFailures === 0) {
  8380. matchFailed("\"&\"");
  8381. }
  8382. }
  8383. if (result1 === null) {
  8384. if (input.charCodeAt(pos) === 61) {
  8385. result1 = "=";
  8386. pos++;
  8387. } else {
  8388. result1 = null;
  8389. if (reportFailures === 0) {
  8390. matchFailed("\"=\"");
  8391. }
  8392. }
  8393. if (result1 === null) {
  8394. if (input.charCodeAt(pos) === 43) {
  8395. result1 = "+";
  8396. pos++;
  8397. } else {
  8398. result1 = null;
  8399. if (reportFailures === 0) {
  8400. matchFailed("\"+\"");
  8401. }
  8402. }
  8403. }
  8404. }
  8405. }
  8406. }
  8407. }
  8408. }
  8409. }
  8410. }
  8411. }
  8412. }
  8413. } else {
  8414. result0 = null;
  8415. }
  8416. return result0;
  8417. }
  8418. function parse_query() {
  8419. var result0, result1;
  8420. result0 = [];
  8421. result1 = parse_uric();
  8422. while (result1 !== null) {
  8423. result0.push(result1);
  8424. result1 = parse_uric();
  8425. }
  8426. return result0;
  8427. }
  8428. function parse_SIP_Version() {
  8429. var result0, result1, result2, result3, result4, result5;
  8430. var pos0, pos1;
  8431. pos0 = pos;
  8432. pos1 = pos;
  8433. if (input.substr(pos, 3).toLowerCase() === "sip") {
  8434. result0 = input.substr(pos, 3);
  8435. pos += 3;
  8436. } else {
  8437. result0 = null;
  8438. if (reportFailures === 0) {
  8439. matchFailed("\"SIP\"");
  8440. }
  8441. }
  8442. if (result0 !== null) {
  8443. if (input.charCodeAt(pos) === 47) {
  8444. result1 = "/";
  8445. pos++;
  8446. } else {
  8447. result1 = null;
  8448. if (reportFailures === 0) {
  8449. matchFailed("\"/\"");
  8450. }
  8451. }
  8452. if (result1 !== null) {
  8453. result3 = parse_DIGIT();
  8454. if (result3 !== null) {
  8455. result2 = [];
  8456. while (result3 !== null) {
  8457. result2.push(result3);
  8458. result3 = parse_DIGIT();
  8459. }
  8460. } else {
  8461. result2 = null;
  8462. }
  8463. if (result2 !== null) {
  8464. if (input.charCodeAt(pos) === 46) {
  8465. result3 = ".";
  8466. pos++;
  8467. } else {
  8468. result3 = null;
  8469. if (reportFailures === 0) {
  8470. matchFailed("\".\"");
  8471. }
  8472. }
  8473. if (result3 !== null) {
  8474. result5 = parse_DIGIT();
  8475. if (result5 !== null) {
  8476. result4 = [];
  8477. while (result5 !== null) {
  8478. result4.push(result5);
  8479. result5 = parse_DIGIT();
  8480. }
  8481. } else {
  8482. result4 = null;
  8483. }
  8484. if (result4 !== null) {
  8485. result0 = [result0, result1, result2, result3, result4];
  8486. } else {
  8487. result0 = null;
  8488. pos = pos1;
  8489. }
  8490. } else {
  8491. result0 = null;
  8492. pos = pos1;
  8493. }
  8494. } else {
  8495. result0 = null;
  8496. pos = pos1;
  8497. }
  8498. } else {
  8499. result0 = null;
  8500. pos = pos1;
  8501. }
  8502. } else {
  8503. result0 = null;
  8504. pos = pos1;
  8505. }
  8506. if (result0 !== null) {
  8507. result0 = function (offset) {
  8508. data.sip_version = input.substring(pos, offset);
  8509. }(pos0);
  8510. }
  8511. if (result0 === null) {
  8512. pos = pos0;
  8513. }
  8514. return result0;
  8515. }
  8516. function parse_INVITEm() {
  8517. var result0;
  8518. if (input.substr(pos, 6) === "INVITE") {
  8519. result0 = "INVITE";
  8520. pos += 6;
  8521. } else {
  8522. result0 = null;
  8523. if (reportFailures === 0) {
  8524. matchFailed("\"INVITE\"");
  8525. }
  8526. }
  8527. return result0;
  8528. }
  8529. function parse_ACKm() {
  8530. var result0;
  8531. if (input.substr(pos, 3) === "ACK") {
  8532. result0 = "ACK";
  8533. pos += 3;
  8534. } else {
  8535. result0 = null;
  8536. if (reportFailures === 0) {
  8537. matchFailed("\"ACK\"");
  8538. }
  8539. }
  8540. return result0;
  8541. }
  8542. function parse_OPTIONSm() {
  8543. var result0;
  8544. if (input.substr(pos, 7) === "OPTIONS") {
  8545. result0 = "OPTIONS";
  8546. pos += 7;
  8547. } else {
  8548. result0 = null;
  8549. if (reportFailures === 0) {
  8550. matchFailed("\"OPTIONS\"");
  8551. }
  8552. }
  8553. return result0;
  8554. }
  8555. function parse_BYEm() {
  8556. var result0;
  8557. if (input.substr(pos, 3) === "BYE") {
  8558. result0 = "BYE";
  8559. pos += 3;
  8560. } else {
  8561. result0 = null;
  8562. if (reportFailures === 0) {
  8563. matchFailed("\"BYE\"");
  8564. }
  8565. }
  8566. return result0;
  8567. }
  8568. function parse_CANCELm() {
  8569. var result0;
  8570. if (input.substr(pos, 6) === "CANCEL") {
  8571. result0 = "CANCEL";
  8572. pos += 6;
  8573. } else {
  8574. result0 = null;
  8575. if (reportFailures === 0) {
  8576. matchFailed("\"CANCEL\"");
  8577. }
  8578. }
  8579. return result0;
  8580. }
  8581. function parse_REGISTERm() {
  8582. var result0;
  8583. if (input.substr(pos, 8) === "REGISTER") {
  8584. result0 = "REGISTER";
  8585. pos += 8;
  8586. } else {
  8587. result0 = null;
  8588. if (reportFailures === 0) {
  8589. matchFailed("\"REGISTER\"");
  8590. }
  8591. }
  8592. return result0;
  8593. }
  8594. function parse_SUBSCRIBEm() {
  8595. var result0;
  8596. if (input.substr(pos, 9) === "SUBSCRIBE") {
  8597. result0 = "SUBSCRIBE";
  8598. pos += 9;
  8599. } else {
  8600. result0 = null;
  8601. if (reportFailures === 0) {
  8602. matchFailed("\"SUBSCRIBE\"");
  8603. }
  8604. }
  8605. return result0;
  8606. }
  8607. function parse_NOTIFYm() {
  8608. var result0;
  8609. if (input.substr(pos, 6) === "NOTIFY") {
  8610. result0 = "NOTIFY";
  8611. pos += 6;
  8612. } else {
  8613. result0 = null;
  8614. if (reportFailures === 0) {
  8615. matchFailed("\"NOTIFY\"");
  8616. }
  8617. }
  8618. return result0;
  8619. }
  8620. function parse_REFERm() {
  8621. var result0;
  8622. if (input.substr(pos, 5) === "REFER") {
  8623. result0 = "REFER";
  8624. pos += 5;
  8625. } else {
  8626. result0 = null;
  8627. if (reportFailures === 0) {
  8628. matchFailed("\"REFER\"");
  8629. }
  8630. }
  8631. return result0;
  8632. }
  8633. function parse_Method() {
  8634. var result0;
  8635. var pos0;
  8636. pos0 = pos;
  8637. result0 = parse_INVITEm();
  8638. if (result0 === null) {
  8639. result0 = parse_ACKm();
  8640. if (result0 === null) {
  8641. result0 = parse_OPTIONSm();
  8642. if (result0 === null) {
  8643. result0 = parse_BYEm();
  8644. if (result0 === null) {
  8645. result0 = parse_CANCELm();
  8646. if (result0 === null) {
  8647. result0 = parse_REGISTERm();
  8648. if (result0 === null) {
  8649. result0 = parse_SUBSCRIBEm();
  8650. if (result0 === null) {
  8651. result0 = parse_NOTIFYm();
  8652. if (result0 === null) {
  8653. result0 = parse_REFERm();
  8654. if (result0 === null) {
  8655. result0 = parse_token();
  8656. }
  8657. }
  8658. }
  8659. }
  8660. }
  8661. }
  8662. }
  8663. }
  8664. }
  8665. if (result0 !== null) {
  8666. result0 = function (offset) {
  8667. data.method = input.substring(pos, offset);
  8668. return data.method;
  8669. }(pos0);
  8670. }
  8671. if (result0 === null) {
  8672. pos = pos0;
  8673. }
  8674. return result0;
  8675. }
  8676. function parse_Status_Line() {
  8677. var result0, result1, result2, result3, result4;
  8678. var pos0;
  8679. pos0 = pos;
  8680. result0 = parse_SIP_Version();
  8681. if (result0 !== null) {
  8682. result1 = parse_SP();
  8683. if (result1 !== null) {
  8684. result2 = parse_Status_Code();
  8685. if (result2 !== null) {
  8686. result3 = parse_SP();
  8687. if (result3 !== null) {
  8688. result4 = parse_Reason_Phrase();
  8689. if (result4 !== null) {
  8690. result0 = [result0, result1, result2, result3, result4];
  8691. } else {
  8692. result0 = null;
  8693. pos = pos0;
  8694. }
  8695. } else {
  8696. result0 = null;
  8697. pos = pos0;
  8698. }
  8699. } else {
  8700. result0 = null;
  8701. pos = pos0;
  8702. }
  8703. } else {
  8704. result0 = null;
  8705. pos = pos0;
  8706. }
  8707. } else {
  8708. result0 = null;
  8709. pos = pos0;
  8710. }
  8711. return result0;
  8712. }
  8713. function parse_Status_Code() {
  8714. var result0;
  8715. var pos0;
  8716. pos0 = pos;
  8717. result0 = parse_extension_code();
  8718. if (result0 !== null) {
  8719. result0 = function (offset, status_code) {
  8720. data.status_code = parseInt(status_code.join(''));
  8721. }(pos0, result0);
  8722. }
  8723. if (result0 === null) {
  8724. pos = pos0;
  8725. }
  8726. return result0;
  8727. }
  8728. function parse_extension_code() {
  8729. var result0, result1, result2;
  8730. var pos0;
  8731. pos0 = pos;
  8732. result0 = parse_DIGIT();
  8733. if (result0 !== null) {
  8734. result1 = parse_DIGIT();
  8735. if (result1 !== null) {
  8736. result2 = parse_DIGIT();
  8737. if (result2 !== null) {
  8738. result0 = [result0, result1, result2];
  8739. } else {
  8740. result0 = null;
  8741. pos = pos0;
  8742. }
  8743. } else {
  8744. result0 = null;
  8745. pos = pos0;
  8746. }
  8747. } else {
  8748. result0 = null;
  8749. pos = pos0;
  8750. }
  8751. return result0;
  8752. }
  8753. function parse_Reason_Phrase() {
  8754. var result0, result1;
  8755. var pos0;
  8756. pos0 = pos;
  8757. result0 = [];
  8758. result1 = parse_reserved();
  8759. if (result1 === null) {
  8760. result1 = parse_unreserved();
  8761. if (result1 === null) {
  8762. result1 = parse_escaped();
  8763. if (result1 === null) {
  8764. result1 = parse_UTF8_NONASCII();
  8765. if (result1 === null) {
  8766. result1 = parse_UTF8_CONT();
  8767. if (result1 === null) {
  8768. result1 = parse_SP();
  8769. if (result1 === null) {
  8770. result1 = parse_HTAB();
  8771. }
  8772. }
  8773. }
  8774. }
  8775. }
  8776. }
  8777. while (result1 !== null) {
  8778. result0.push(result1);
  8779. result1 = parse_reserved();
  8780. if (result1 === null) {
  8781. result1 = parse_unreserved();
  8782. if (result1 === null) {
  8783. result1 = parse_escaped();
  8784. if (result1 === null) {
  8785. result1 = parse_UTF8_NONASCII();
  8786. if (result1 === null) {
  8787. result1 = parse_UTF8_CONT();
  8788. if (result1 === null) {
  8789. result1 = parse_SP();
  8790. if (result1 === null) {
  8791. result1 = parse_HTAB();
  8792. }
  8793. }
  8794. }
  8795. }
  8796. }
  8797. }
  8798. }
  8799. if (result0 !== null) {
  8800. result0 = function (offset) {
  8801. data.reason_phrase = input.substring(pos, offset);
  8802. }(pos0);
  8803. }
  8804. if (result0 === null) {
  8805. pos = pos0;
  8806. }
  8807. return result0;
  8808. }
  8809. function parse_Allow_Events() {
  8810. var result0, result1, result2, result3;
  8811. var pos0, pos1;
  8812. pos0 = pos;
  8813. result0 = parse_event_type();
  8814. if (result0 !== null) {
  8815. result1 = [];
  8816. pos1 = pos;
  8817. result2 = parse_COMMA();
  8818. if (result2 !== null) {
  8819. result3 = parse_event_type();
  8820. if (result3 !== null) {
  8821. result2 = [result2, result3];
  8822. } else {
  8823. result2 = null;
  8824. pos = pos1;
  8825. }
  8826. } else {
  8827. result2 = null;
  8828. pos = pos1;
  8829. }
  8830. while (result2 !== null) {
  8831. result1.push(result2);
  8832. pos1 = pos;
  8833. result2 = parse_COMMA();
  8834. if (result2 !== null) {
  8835. result3 = parse_event_type();
  8836. if (result3 !== null) {
  8837. result2 = [result2, result3];
  8838. } else {
  8839. result2 = null;
  8840. pos = pos1;
  8841. }
  8842. } else {
  8843. result2 = null;
  8844. pos = pos1;
  8845. }
  8846. }
  8847. if (result1 !== null) {
  8848. result0 = [result0, result1];
  8849. } else {
  8850. result0 = null;
  8851. pos = pos0;
  8852. }
  8853. } else {
  8854. result0 = null;
  8855. pos = pos0;
  8856. }
  8857. return result0;
  8858. }
  8859. function parse_Call_ID() {
  8860. var result0, result1, result2;
  8861. var pos0, pos1, pos2;
  8862. pos0 = pos;
  8863. pos1 = pos;
  8864. result0 = parse_word();
  8865. if (result0 !== null) {
  8866. pos2 = pos;
  8867. if (input.charCodeAt(pos) === 64) {
  8868. result1 = "@";
  8869. pos++;
  8870. } else {
  8871. result1 = null;
  8872. if (reportFailures === 0) {
  8873. matchFailed("\"@\"");
  8874. }
  8875. }
  8876. if (result1 !== null) {
  8877. result2 = parse_word();
  8878. if (result2 !== null) {
  8879. result1 = [result1, result2];
  8880. } else {
  8881. result1 = null;
  8882. pos = pos2;
  8883. }
  8884. } else {
  8885. result1 = null;
  8886. pos = pos2;
  8887. }
  8888. result1 = result1 !== null ? result1 : "";
  8889. if (result1 !== null) {
  8890. result0 = [result0, result1];
  8891. } else {
  8892. result0 = null;
  8893. pos = pos1;
  8894. }
  8895. } else {
  8896. result0 = null;
  8897. pos = pos1;
  8898. }
  8899. if (result0 !== null) {
  8900. result0 = function (offset) {
  8901. data = input.substring(pos, offset);
  8902. }(pos0);
  8903. }
  8904. if (result0 === null) {
  8905. pos = pos0;
  8906. }
  8907. return result0;
  8908. }
  8909. function parse_Contact() {
  8910. var result0, result1, result2, result3;
  8911. var pos0, pos1, pos2;
  8912. pos0 = pos;
  8913. result0 = parse_STAR();
  8914. if (result0 === null) {
  8915. pos1 = pos;
  8916. result0 = parse_contact_param();
  8917. if (result0 !== null) {
  8918. result1 = [];
  8919. pos2 = pos;
  8920. result2 = parse_COMMA();
  8921. if (result2 !== null) {
  8922. result3 = parse_contact_param();
  8923. if (result3 !== null) {
  8924. result2 = [result2, result3];
  8925. } else {
  8926. result2 = null;
  8927. pos = pos2;
  8928. }
  8929. } else {
  8930. result2 = null;
  8931. pos = pos2;
  8932. }
  8933. while (result2 !== null) {
  8934. result1.push(result2);
  8935. pos2 = pos;
  8936. result2 = parse_COMMA();
  8937. if (result2 !== null) {
  8938. result3 = parse_contact_param();
  8939. if (result3 !== null) {
  8940. result2 = [result2, result3];
  8941. } else {
  8942. result2 = null;
  8943. pos = pos2;
  8944. }
  8945. } else {
  8946. result2 = null;
  8947. pos = pos2;
  8948. }
  8949. }
  8950. if (result1 !== null) {
  8951. result0 = [result0, result1];
  8952. } else {
  8953. result0 = null;
  8954. pos = pos1;
  8955. }
  8956. } else {
  8957. result0 = null;
  8958. pos = pos1;
  8959. }
  8960. }
  8961. if (result0 !== null) {
  8962. result0 = function (offset) {
  8963. var idx, length;
  8964. length = data.multi_header.length;
  8965. for (idx = 0; idx < length; idx++) {
  8966. if (data.multi_header[idx].parsed === null) {
  8967. data = null;
  8968. break;
  8969. }
  8970. }
  8971. if (data !== null) {
  8972. data = data.multi_header;
  8973. } else {
  8974. data = -1;
  8975. }
  8976. }(pos0);
  8977. }
  8978. if (result0 === null) {
  8979. pos = pos0;
  8980. }
  8981. return result0;
  8982. }
  8983. function parse_contact_param() {
  8984. var result0, result1, result2, result3;
  8985. var pos0, pos1, pos2;
  8986. pos0 = pos;
  8987. pos1 = pos;
  8988. result0 = parse_SIP_URI_noparams();
  8989. if (result0 === null) {
  8990. result0 = parse_name_addr();
  8991. }
  8992. if (result0 !== null) {
  8993. result1 = [];
  8994. pos2 = pos;
  8995. result2 = parse_SEMI();
  8996. if (result2 !== null) {
  8997. result3 = parse_contact_params();
  8998. if (result3 !== null) {
  8999. result2 = [result2, result3];
  9000. } else {
  9001. result2 = null;
  9002. pos = pos2;
  9003. }
  9004. } else {
  9005. result2 = null;
  9006. pos = pos2;
  9007. }
  9008. while (result2 !== null) {
  9009. result1.push(result2);
  9010. pos2 = pos;
  9011. result2 = parse_SEMI();
  9012. if (result2 !== null) {
  9013. result3 = parse_contact_params();
  9014. if (result3 !== null) {
  9015. result2 = [result2, result3];
  9016. } else {
  9017. result2 = null;
  9018. pos = pos2;
  9019. }
  9020. } else {
  9021. result2 = null;
  9022. pos = pos2;
  9023. }
  9024. }
  9025. if (result1 !== null) {
  9026. result0 = [result0, result1];
  9027. } else {
  9028. result0 = null;
  9029. pos = pos1;
  9030. }
  9031. } else {
  9032. result0 = null;
  9033. pos = pos1;
  9034. }
  9035. if (result0 !== null) {
  9036. result0 = function (offset) {
  9037. var header;
  9038. if (!data.multi_header) data.multi_header = [];
  9039. try {
  9040. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  9041. delete data.uri;
  9042. delete data.display_name;
  9043. delete data.params;
  9044. } catch (e) {
  9045. header = null;
  9046. }
  9047. data.multi_header.push({
  9048. 'possition': pos,
  9049. 'offset': offset,
  9050. 'parsed': header
  9051. });
  9052. }(pos0);
  9053. }
  9054. if (result0 === null) {
  9055. pos = pos0;
  9056. }
  9057. return result0;
  9058. }
  9059. function parse_name_addr() {
  9060. var result0, result1, result2, result3;
  9061. var pos0;
  9062. pos0 = pos;
  9063. result0 = parse_display_name();
  9064. result0 = result0 !== null ? result0 : "";
  9065. if (result0 !== null) {
  9066. result1 = parse_LAQUOT();
  9067. if (result1 !== null) {
  9068. result2 = parse_SIP_URI();
  9069. if (result2 !== null) {
  9070. result3 = parse_RAQUOT();
  9071. if (result3 !== null) {
  9072. result0 = [result0, result1, result2, result3];
  9073. } else {
  9074. result0 = null;
  9075. pos = pos0;
  9076. }
  9077. } else {
  9078. result0 = null;
  9079. pos = pos0;
  9080. }
  9081. } else {
  9082. result0 = null;
  9083. pos = pos0;
  9084. }
  9085. } else {
  9086. result0 = null;
  9087. pos = pos0;
  9088. }
  9089. return result0;
  9090. }
  9091. function parse_display_name() {
  9092. var result0, result1, result2, result3;
  9093. var pos0, pos1, pos2;
  9094. pos0 = pos;
  9095. pos1 = pos;
  9096. result0 = parse_token();
  9097. if (result0 !== null) {
  9098. result1 = [];
  9099. pos2 = pos;
  9100. result2 = parse_LWS();
  9101. if (result2 !== null) {
  9102. result3 = parse_token();
  9103. if (result3 !== null) {
  9104. result2 = [result2, result3];
  9105. } else {
  9106. result2 = null;
  9107. pos = pos2;
  9108. }
  9109. } else {
  9110. result2 = null;
  9111. pos = pos2;
  9112. }
  9113. while (result2 !== null) {
  9114. result1.push(result2);
  9115. pos2 = pos;
  9116. result2 = parse_LWS();
  9117. if (result2 !== null) {
  9118. result3 = parse_token();
  9119. if (result3 !== null) {
  9120. result2 = [result2, result3];
  9121. } else {
  9122. result2 = null;
  9123. pos = pos2;
  9124. }
  9125. } else {
  9126. result2 = null;
  9127. pos = pos2;
  9128. }
  9129. }
  9130. if (result1 !== null) {
  9131. result0 = [result0, result1];
  9132. } else {
  9133. result0 = null;
  9134. pos = pos1;
  9135. }
  9136. } else {
  9137. result0 = null;
  9138. pos = pos1;
  9139. }
  9140. if (result0 === null) {
  9141. result0 = parse_quoted_string_clean();
  9142. }
  9143. if (result0 !== null) {
  9144. result0 = function (offset, display_name) {
  9145. if (typeof display_name === 'string') {
  9146. // quoted_string_clean
  9147. data.display_name = display_name;
  9148. } else {
  9149. // token ( LWS token )*
  9150. data.display_name = display_name[1].reduce(function (acc, cur) {
  9151. return acc + cur[0] + cur[1];
  9152. }, display_name[0]);
  9153. }
  9154. }(pos0, result0);
  9155. }
  9156. if (result0 === null) {
  9157. pos = pos0;
  9158. }
  9159. return result0;
  9160. }
  9161. function parse_contact_params() {
  9162. var result0;
  9163. result0 = parse_c_p_q();
  9164. if (result0 === null) {
  9165. result0 = parse_c_p_expires();
  9166. if (result0 === null) {
  9167. result0 = parse_generic_param();
  9168. }
  9169. }
  9170. return result0;
  9171. }
  9172. function parse_c_p_q() {
  9173. var result0, result1, result2;
  9174. var pos0, pos1;
  9175. pos0 = pos;
  9176. pos1 = pos;
  9177. if (input.substr(pos, 1).toLowerCase() === "q") {
  9178. result0 = input.substr(pos, 1);
  9179. pos++;
  9180. } else {
  9181. result0 = null;
  9182. if (reportFailures === 0) {
  9183. matchFailed("\"q\"");
  9184. }
  9185. }
  9186. if (result0 !== null) {
  9187. result1 = parse_EQUAL();
  9188. if (result1 !== null) {
  9189. result2 = parse_qvalue();
  9190. if (result2 !== null) {
  9191. result0 = [result0, result1, result2];
  9192. } else {
  9193. result0 = null;
  9194. pos = pos1;
  9195. }
  9196. } else {
  9197. result0 = null;
  9198. pos = pos1;
  9199. }
  9200. } else {
  9201. result0 = null;
  9202. pos = pos1;
  9203. }
  9204. if (result0 !== null) {
  9205. result0 = function (offset, q) {
  9206. if (!data.params) data.params = {};
  9207. data.params['q'] = q;
  9208. }(pos0, result0[2]);
  9209. }
  9210. if (result0 === null) {
  9211. pos = pos0;
  9212. }
  9213. return result0;
  9214. }
  9215. function parse_c_p_expires() {
  9216. var result0, result1, result2;
  9217. var pos0, pos1;
  9218. pos0 = pos;
  9219. pos1 = pos;
  9220. if (input.substr(pos, 7).toLowerCase() === "expires") {
  9221. result0 = input.substr(pos, 7);
  9222. pos += 7;
  9223. } else {
  9224. result0 = null;
  9225. if (reportFailures === 0) {
  9226. matchFailed("\"expires\"");
  9227. }
  9228. }
  9229. if (result0 !== null) {
  9230. result1 = parse_EQUAL();
  9231. if (result1 !== null) {
  9232. result2 = parse_delta_seconds();
  9233. if (result2 !== null) {
  9234. result0 = [result0, result1, result2];
  9235. } else {
  9236. result0 = null;
  9237. pos = pos1;
  9238. }
  9239. } else {
  9240. result0 = null;
  9241. pos = pos1;
  9242. }
  9243. } else {
  9244. result0 = null;
  9245. pos = pos1;
  9246. }
  9247. if (result0 !== null) {
  9248. result0 = function (offset, expires) {
  9249. if (!data.params) data.params = {};
  9250. data.params['expires'] = expires;
  9251. }(pos0, result0[2]);
  9252. }
  9253. if (result0 === null) {
  9254. pos = pos0;
  9255. }
  9256. return result0;
  9257. }
  9258. function parse_delta_seconds() {
  9259. var result0, result1;
  9260. var pos0;
  9261. pos0 = pos;
  9262. result1 = parse_DIGIT();
  9263. if (result1 !== null) {
  9264. result0 = [];
  9265. while (result1 !== null) {
  9266. result0.push(result1);
  9267. result1 = parse_DIGIT();
  9268. }
  9269. } else {
  9270. result0 = null;
  9271. }
  9272. if (result0 !== null) {
  9273. result0 = function (offset, delta_seconds) {
  9274. return parseInt(delta_seconds.join(''));
  9275. }(pos0, result0);
  9276. }
  9277. if (result0 === null) {
  9278. pos = pos0;
  9279. }
  9280. return result0;
  9281. }
  9282. function parse_qvalue() {
  9283. var result0, result1, result2, result3, result4;
  9284. var pos0, pos1, pos2;
  9285. pos0 = pos;
  9286. pos1 = pos;
  9287. if (input.charCodeAt(pos) === 48) {
  9288. result0 = "0";
  9289. pos++;
  9290. } else {
  9291. result0 = null;
  9292. if (reportFailures === 0) {
  9293. matchFailed("\"0\"");
  9294. }
  9295. }
  9296. if (result0 !== null) {
  9297. pos2 = pos;
  9298. if (input.charCodeAt(pos) === 46) {
  9299. result1 = ".";
  9300. pos++;
  9301. } else {
  9302. result1 = null;
  9303. if (reportFailures === 0) {
  9304. matchFailed("\".\"");
  9305. }
  9306. }
  9307. if (result1 !== null) {
  9308. result2 = parse_DIGIT();
  9309. result2 = result2 !== null ? result2 : "";
  9310. if (result2 !== null) {
  9311. result3 = parse_DIGIT();
  9312. result3 = result3 !== null ? result3 : "";
  9313. if (result3 !== null) {
  9314. result4 = parse_DIGIT();
  9315. result4 = result4 !== null ? result4 : "";
  9316. if (result4 !== null) {
  9317. result1 = [result1, result2, result3, result4];
  9318. } else {
  9319. result1 = null;
  9320. pos = pos2;
  9321. }
  9322. } else {
  9323. result1 = null;
  9324. pos = pos2;
  9325. }
  9326. } else {
  9327. result1 = null;
  9328. pos = pos2;
  9329. }
  9330. } else {
  9331. result1 = null;
  9332. pos = pos2;
  9333. }
  9334. result1 = result1 !== null ? result1 : "";
  9335. if (result1 !== null) {
  9336. result0 = [result0, result1];
  9337. } else {
  9338. result0 = null;
  9339. pos = pos1;
  9340. }
  9341. } else {
  9342. result0 = null;
  9343. pos = pos1;
  9344. }
  9345. if (result0 !== null) {
  9346. result0 = function (offset) {
  9347. return parseFloat(input.substring(pos, offset));
  9348. }(pos0);
  9349. }
  9350. if (result0 === null) {
  9351. pos = pos0;
  9352. }
  9353. return result0;
  9354. }
  9355. function parse_generic_param() {
  9356. var result0, result1, result2;
  9357. var pos0, pos1, pos2;
  9358. pos0 = pos;
  9359. pos1 = pos;
  9360. result0 = parse_token();
  9361. if (result0 !== null) {
  9362. pos2 = pos;
  9363. result1 = parse_EQUAL();
  9364. if (result1 !== null) {
  9365. result2 = parse_gen_value();
  9366. if (result2 !== null) {
  9367. result1 = [result1, result2];
  9368. } else {
  9369. result1 = null;
  9370. pos = pos2;
  9371. }
  9372. } else {
  9373. result1 = null;
  9374. pos = pos2;
  9375. }
  9376. result1 = result1 !== null ? result1 : "";
  9377. if (result1 !== null) {
  9378. result0 = [result0, result1];
  9379. } else {
  9380. result0 = null;
  9381. pos = pos1;
  9382. }
  9383. } else {
  9384. result0 = null;
  9385. pos = pos1;
  9386. }
  9387. if (result0 !== null) {
  9388. result0 = function (offset, param, value) {
  9389. if (!data.params) data.params = {};
  9390. if (typeof value === 'undefined') {
  9391. value = undefined;
  9392. } else {
  9393. value = value[1];
  9394. }
  9395. data.params[param.toLowerCase()] = value;
  9396. }(pos0, result0[0], result0[1]);
  9397. }
  9398. if (result0 === null) {
  9399. pos = pos0;
  9400. }
  9401. return result0;
  9402. }
  9403. function parse_gen_value() {
  9404. var result0;
  9405. result0 = parse_token();
  9406. if (result0 === null) {
  9407. result0 = parse_host();
  9408. if (result0 === null) {
  9409. result0 = parse_quoted_string();
  9410. }
  9411. }
  9412. return result0;
  9413. }
  9414. function parse_Content_Disposition() {
  9415. var result0, result1, result2, result3;
  9416. var pos0, pos1;
  9417. pos0 = pos;
  9418. result0 = parse_disp_type();
  9419. if (result0 !== null) {
  9420. result1 = [];
  9421. pos1 = pos;
  9422. result2 = parse_SEMI();
  9423. if (result2 !== null) {
  9424. result3 = parse_disp_param();
  9425. if (result3 !== null) {
  9426. result2 = [result2, result3];
  9427. } else {
  9428. result2 = null;
  9429. pos = pos1;
  9430. }
  9431. } else {
  9432. result2 = null;
  9433. pos = pos1;
  9434. }
  9435. while (result2 !== null) {
  9436. result1.push(result2);
  9437. pos1 = pos;
  9438. result2 = parse_SEMI();
  9439. if (result2 !== null) {
  9440. result3 = parse_disp_param();
  9441. if (result3 !== null) {
  9442. result2 = [result2, result3];
  9443. } else {
  9444. result2 = null;
  9445. pos = pos1;
  9446. }
  9447. } else {
  9448. result2 = null;
  9449. pos = pos1;
  9450. }
  9451. }
  9452. if (result1 !== null) {
  9453. result0 = [result0, result1];
  9454. } else {
  9455. result0 = null;
  9456. pos = pos0;
  9457. }
  9458. } else {
  9459. result0 = null;
  9460. pos = pos0;
  9461. }
  9462. return result0;
  9463. }
  9464. function parse_disp_type() {
  9465. var result0;
  9466. if (input.substr(pos, 6).toLowerCase() === "render") {
  9467. result0 = input.substr(pos, 6);
  9468. pos += 6;
  9469. } else {
  9470. result0 = null;
  9471. if (reportFailures === 0) {
  9472. matchFailed("\"render\"");
  9473. }
  9474. }
  9475. if (result0 === null) {
  9476. if (input.substr(pos, 7).toLowerCase() === "session") {
  9477. result0 = input.substr(pos, 7);
  9478. pos += 7;
  9479. } else {
  9480. result0 = null;
  9481. if (reportFailures === 0) {
  9482. matchFailed("\"session\"");
  9483. }
  9484. }
  9485. if (result0 === null) {
  9486. if (input.substr(pos, 4).toLowerCase() === "icon") {
  9487. result0 = input.substr(pos, 4);
  9488. pos += 4;
  9489. } else {
  9490. result0 = null;
  9491. if (reportFailures === 0) {
  9492. matchFailed("\"icon\"");
  9493. }
  9494. }
  9495. if (result0 === null) {
  9496. if (input.substr(pos, 5).toLowerCase() === "alert") {
  9497. result0 = input.substr(pos, 5);
  9498. pos += 5;
  9499. } else {
  9500. result0 = null;
  9501. if (reportFailures === 0) {
  9502. matchFailed("\"alert\"");
  9503. }
  9504. }
  9505. if (result0 === null) {
  9506. result0 = parse_token();
  9507. }
  9508. }
  9509. }
  9510. }
  9511. return result0;
  9512. }
  9513. function parse_disp_param() {
  9514. var result0;
  9515. result0 = parse_handling_param();
  9516. if (result0 === null) {
  9517. result0 = parse_generic_param();
  9518. }
  9519. return result0;
  9520. }
  9521. function parse_handling_param() {
  9522. var result0, result1, result2;
  9523. var pos0;
  9524. pos0 = pos;
  9525. if (input.substr(pos, 8).toLowerCase() === "handling") {
  9526. result0 = input.substr(pos, 8);
  9527. pos += 8;
  9528. } else {
  9529. result0 = null;
  9530. if (reportFailures === 0) {
  9531. matchFailed("\"handling\"");
  9532. }
  9533. }
  9534. if (result0 !== null) {
  9535. result1 = parse_EQUAL();
  9536. if (result1 !== null) {
  9537. if (input.substr(pos, 8).toLowerCase() === "optional") {
  9538. result2 = input.substr(pos, 8);
  9539. pos += 8;
  9540. } else {
  9541. result2 = null;
  9542. if (reportFailures === 0) {
  9543. matchFailed("\"optional\"");
  9544. }
  9545. }
  9546. if (result2 === null) {
  9547. if (input.substr(pos, 8).toLowerCase() === "required") {
  9548. result2 = input.substr(pos, 8);
  9549. pos += 8;
  9550. } else {
  9551. result2 = null;
  9552. if (reportFailures === 0) {
  9553. matchFailed("\"required\"");
  9554. }
  9555. }
  9556. if (result2 === null) {
  9557. result2 = parse_token();
  9558. }
  9559. }
  9560. if (result2 !== null) {
  9561. result0 = [result0, result1, result2];
  9562. } else {
  9563. result0 = null;
  9564. pos = pos0;
  9565. }
  9566. } else {
  9567. result0 = null;
  9568. pos = pos0;
  9569. }
  9570. } else {
  9571. result0 = null;
  9572. pos = pos0;
  9573. }
  9574. return result0;
  9575. }
  9576. function parse_Content_Encoding() {
  9577. var result0, result1, result2, result3;
  9578. var pos0, pos1;
  9579. pos0 = pos;
  9580. result0 = parse_token();
  9581. if (result0 !== null) {
  9582. result1 = [];
  9583. pos1 = pos;
  9584. result2 = parse_COMMA();
  9585. if (result2 !== null) {
  9586. result3 = parse_token();
  9587. if (result3 !== null) {
  9588. result2 = [result2, result3];
  9589. } else {
  9590. result2 = null;
  9591. pos = pos1;
  9592. }
  9593. } else {
  9594. result2 = null;
  9595. pos = pos1;
  9596. }
  9597. while (result2 !== null) {
  9598. result1.push(result2);
  9599. pos1 = pos;
  9600. result2 = parse_COMMA();
  9601. if (result2 !== null) {
  9602. result3 = parse_token();
  9603. if (result3 !== null) {
  9604. result2 = [result2, result3];
  9605. } else {
  9606. result2 = null;
  9607. pos = pos1;
  9608. }
  9609. } else {
  9610. result2 = null;
  9611. pos = pos1;
  9612. }
  9613. }
  9614. if (result1 !== null) {
  9615. result0 = [result0, result1];
  9616. } else {
  9617. result0 = null;
  9618. pos = pos0;
  9619. }
  9620. } else {
  9621. result0 = null;
  9622. pos = pos0;
  9623. }
  9624. return result0;
  9625. }
  9626. function parse_Content_Length() {
  9627. var result0, result1;
  9628. var pos0;
  9629. pos0 = pos;
  9630. result1 = parse_DIGIT();
  9631. if (result1 !== null) {
  9632. result0 = [];
  9633. while (result1 !== null) {
  9634. result0.push(result1);
  9635. result1 = parse_DIGIT();
  9636. }
  9637. } else {
  9638. result0 = null;
  9639. }
  9640. if (result0 !== null) {
  9641. result0 = function (offset, length) {
  9642. data = parseInt(length.join(''));
  9643. }(pos0, result0);
  9644. }
  9645. if (result0 === null) {
  9646. pos = pos0;
  9647. }
  9648. return result0;
  9649. }
  9650. function parse_Content_Type() {
  9651. var result0;
  9652. var pos0;
  9653. pos0 = pos;
  9654. result0 = parse_media_type();
  9655. if (result0 !== null) {
  9656. result0 = function (offset) {
  9657. data = input.substring(pos, offset);
  9658. }(pos0);
  9659. }
  9660. if (result0 === null) {
  9661. pos = pos0;
  9662. }
  9663. return result0;
  9664. }
  9665. function parse_media_type() {
  9666. var result0, result1, result2, result3, result4, result5;
  9667. var pos0, pos1;
  9668. pos0 = pos;
  9669. result0 = parse_m_type();
  9670. if (result0 !== null) {
  9671. result1 = parse_SLASH();
  9672. if (result1 !== null) {
  9673. result2 = parse_m_subtype();
  9674. if (result2 !== null) {
  9675. result3 = [];
  9676. pos1 = pos;
  9677. result4 = parse_SEMI();
  9678. if (result4 !== null) {
  9679. result5 = parse_m_parameter();
  9680. if (result5 !== null) {
  9681. result4 = [result4, result5];
  9682. } else {
  9683. result4 = null;
  9684. pos = pos1;
  9685. }
  9686. } else {
  9687. result4 = null;
  9688. pos = pos1;
  9689. }
  9690. while (result4 !== null) {
  9691. result3.push(result4);
  9692. pos1 = pos;
  9693. result4 = parse_SEMI();
  9694. if (result4 !== null) {
  9695. result5 = parse_m_parameter();
  9696. if (result5 !== null) {
  9697. result4 = [result4, result5];
  9698. } else {
  9699. result4 = null;
  9700. pos = pos1;
  9701. }
  9702. } else {
  9703. result4 = null;
  9704. pos = pos1;
  9705. }
  9706. }
  9707. if (result3 !== null) {
  9708. result0 = [result0, result1, result2, result3];
  9709. } else {
  9710. result0 = null;
  9711. pos = pos0;
  9712. }
  9713. } else {
  9714. result0 = null;
  9715. pos = pos0;
  9716. }
  9717. } else {
  9718. result0 = null;
  9719. pos = pos0;
  9720. }
  9721. } else {
  9722. result0 = null;
  9723. pos = pos0;
  9724. }
  9725. return result0;
  9726. }
  9727. function parse_m_type() {
  9728. var result0;
  9729. result0 = parse_discrete_type();
  9730. if (result0 === null) {
  9731. result0 = parse_composite_type();
  9732. }
  9733. return result0;
  9734. }
  9735. function parse_discrete_type() {
  9736. var result0;
  9737. if (input.substr(pos, 4).toLowerCase() === "text") {
  9738. result0 = input.substr(pos, 4);
  9739. pos += 4;
  9740. } else {
  9741. result0 = null;
  9742. if (reportFailures === 0) {
  9743. matchFailed("\"text\"");
  9744. }
  9745. }
  9746. if (result0 === null) {
  9747. if (input.substr(pos, 5).toLowerCase() === "image") {
  9748. result0 = input.substr(pos, 5);
  9749. pos += 5;
  9750. } else {
  9751. result0 = null;
  9752. if (reportFailures === 0) {
  9753. matchFailed("\"image\"");
  9754. }
  9755. }
  9756. if (result0 === null) {
  9757. if (input.substr(pos, 5).toLowerCase() === "audio") {
  9758. result0 = input.substr(pos, 5);
  9759. pos += 5;
  9760. } else {
  9761. result0 = null;
  9762. if (reportFailures === 0) {
  9763. matchFailed("\"audio\"");
  9764. }
  9765. }
  9766. if (result0 === null) {
  9767. if (input.substr(pos, 5).toLowerCase() === "video") {
  9768. result0 = input.substr(pos, 5);
  9769. pos += 5;
  9770. } else {
  9771. result0 = null;
  9772. if (reportFailures === 0) {
  9773. matchFailed("\"video\"");
  9774. }
  9775. }
  9776. if (result0 === null) {
  9777. if (input.substr(pos, 11).toLowerCase() === "application") {
  9778. result0 = input.substr(pos, 11);
  9779. pos += 11;
  9780. } else {
  9781. result0 = null;
  9782. if (reportFailures === 0) {
  9783. matchFailed("\"application\"");
  9784. }
  9785. }
  9786. if (result0 === null) {
  9787. result0 = parse_extension_token();
  9788. }
  9789. }
  9790. }
  9791. }
  9792. }
  9793. return result0;
  9794. }
  9795. function parse_composite_type() {
  9796. var result0;
  9797. if (input.substr(pos, 7).toLowerCase() === "message") {
  9798. result0 = input.substr(pos, 7);
  9799. pos += 7;
  9800. } else {
  9801. result0 = null;
  9802. if (reportFailures === 0) {
  9803. matchFailed("\"message\"");
  9804. }
  9805. }
  9806. if (result0 === null) {
  9807. if (input.substr(pos, 9).toLowerCase() === "multipart") {
  9808. result0 = input.substr(pos, 9);
  9809. pos += 9;
  9810. } else {
  9811. result0 = null;
  9812. if (reportFailures === 0) {
  9813. matchFailed("\"multipart\"");
  9814. }
  9815. }
  9816. if (result0 === null) {
  9817. result0 = parse_extension_token();
  9818. }
  9819. }
  9820. return result0;
  9821. }
  9822. function parse_extension_token() {
  9823. var result0;
  9824. result0 = parse_token();
  9825. if (result0 === null) {
  9826. result0 = parse_x_token();
  9827. }
  9828. return result0;
  9829. }
  9830. function parse_x_token() {
  9831. var result0, result1;
  9832. var pos0;
  9833. pos0 = pos;
  9834. if (input.substr(pos, 2).toLowerCase() === "x-") {
  9835. result0 = input.substr(pos, 2);
  9836. pos += 2;
  9837. } else {
  9838. result0 = null;
  9839. if (reportFailures === 0) {
  9840. matchFailed("\"x-\"");
  9841. }
  9842. }
  9843. if (result0 !== null) {
  9844. result1 = parse_token();
  9845. if (result1 !== null) {
  9846. result0 = [result0, result1];
  9847. } else {
  9848. result0 = null;
  9849. pos = pos0;
  9850. }
  9851. } else {
  9852. result0 = null;
  9853. pos = pos0;
  9854. }
  9855. return result0;
  9856. }
  9857. function parse_m_subtype() {
  9858. var result0;
  9859. result0 = parse_extension_token();
  9860. if (result0 === null) {
  9861. result0 = parse_token();
  9862. }
  9863. return result0;
  9864. }
  9865. function parse_m_parameter() {
  9866. var result0, result1, result2;
  9867. var pos0;
  9868. pos0 = pos;
  9869. result0 = parse_token();
  9870. if (result0 !== null) {
  9871. result1 = parse_EQUAL();
  9872. if (result1 !== null) {
  9873. result2 = parse_m_value();
  9874. if (result2 !== null) {
  9875. result0 = [result0, result1, result2];
  9876. } else {
  9877. result0 = null;
  9878. pos = pos0;
  9879. }
  9880. } else {
  9881. result0 = null;
  9882. pos = pos0;
  9883. }
  9884. } else {
  9885. result0 = null;
  9886. pos = pos0;
  9887. }
  9888. return result0;
  9889. }
  9890. function parse_m_value() {
  9891. var result0;
  9892. result0 = parse_token();
  9893. if (result0 === null) {
  9894. result0 = parse_quoted_string();
  9895. }
  9896. return result0;
  9897. }
  9898. function parse_CSeq() {
  9899. var result0, result1, result2;
  9900. var pos0;
  9901. pos0 = pos;
  9902. result0 = parse_CSeq_value();
  9903. if (result0 !== null) {
  9904. result1 = parse_LWS();
  9905. if (result1 !== null) {
  9906. result2 = parse_Method();
  9907. if (result2 !== null) {
  9908. result0 = [result0, result1, result2];
  9909. } else {
  9910. result0 = null;
  9911. pos = pos0;
  9912. }
  9913. } else {
  9914. result0 = null;
  9915. pos = pos0;
  9916. }
  9917. } else {
  9918. result0 = null;
  9919. pos = pos0;
  9920. }
  9921. return result0;
  9922. }
  9923. function parse_CSeq_value() {
  9924. var result0, result1;
  9925. var pos0;
  9926. pos0 = pos;
  9927. result1 = parse_DIGIT();
  9928. if (result1 !== null) {
  9929. result0 = [];
  9930. while (result1 !== null) {
  9931. result0.push(result1);
  9932. result1 = parse_DIGIT();
  9933. }
  9934. } else {
  9935. result0 = null;
  9936. }
  9937. if (result0 !== null) {
  9938. result0 = function (offset, cseq_value) {
  9939. data.value = parseInt(cseq_value.join(''));
  9940. }(pos0, result0);
  9941. }
  9942. if (result0 === null) {
  9943. pos = pos0;
  9944. }
  9945. return result0;
  9946. }
  9947. function parse_Expires() {
  9948. var result0;
  9949. var pos0;
  9950. pos0 = pos;
  9951. result0 = parse_delta_seconds();
  9952. if (result0 !== null) {
  9953. result0 = function (offset, expires) {
  9954. data = expires;
  9955. }(pos0, result0);
  9956. }
  9957. if (result0 === null) {
  9958. pos = pos0;
  9959. }
  9960. return result0;
  9961. }
  9962. function parse_Event() {
  9963. var result0, result1, result2, result3;
  9964. var pos0, pos1, pos2;
  9965. pos0 = pos;
  9966. pos1 = pos;
  9967. result0 = parse_event_type();
  9968. if (result0 !== null) {
  9969. result1 = [];
  9970. pos2 = pos;
  9971. result2 = parse_SEMI();
  9972. if (result2 !== null) {
  9973. result3 = parse_generic_param();
  9974. if (result3 !== null) {
  9975. result2 = [result2, result3];
  9976. } else {
  9977. result2 = null;
  9978. pos = pos2;
  9979. }
  9980. } else {
  9981. result2 = null;
  9982. pos = pos2;
  9983. }
  9984. while (result2 !== null) {
  9985. result1.push(result2);
  9986. pos2 = pos;
  9987. result2 = parse_SEMI();
  9988. if (result2 !== null) {
  9989. result3 = parse_generic_param();
  9990. if (result3 !== null) {
  9991. result2 = [result2, result3];
  9992. } else {
  9993. result2 = null;
  9994. pos = pos2;
  9995. }
  9996. } else {
  9997. result2 = null;
  9998. pos = pos2;
  9999. }
  10000. }
  10001. if (result1 !== null) {
  10002. result0 = [result0, result1];
  10003. } else {
  10004. result0 = null;
  10005. pos = pos1;
  10006. }
  10007. } else {
  10008. result0 = null;
  10009. pos = pos1;
  10010. }
  10011. if (result0 !== null) {
  10012. result0 = function (offset, event_type) {
  10013. data.event = event_type.join('').toLowerCase();
  10014. }(pos0, result0[0]);
  10015. }
  10016. if (result0 === null) {
  10017. pos = pos0;
  10018. }
  10019. return result0;
  10020. }
  10021. function parse_event_type() {
  10022. var result0, result1, result2, result3;
  10023. var pos0, pos1;
  10024. pos0 = pos;
  10025. result0 = parse_token_nodot();
  10026. if (result0 !== null) {
  10027. result1 = [];
  10028. pos1 = pos;
  10029. if (input.charCodeAt(pos) === 46) {
  10030. result2 = ".";
  10031. pos++;
  10032. } else {
  10033. result2 = null;
  10034. if (reportFailures === 0) {
  10035. matchFailed("\".\"");
  10036. }
  10037. }
  10038. if (result2 !== null) {
  10039. result3 = parse_token_nodot();
  10040. if (result3 !== null) {
  10041. result2 = [result2, result3];
  10042. } else {
  10043. result2 = null;
  10044. pos = pos1;
  10045. }
  10046. } else {
  10047. result2 = null;
  10048. pos = pos1;
  10049. }
  10050. while (result2 !== null) {
  10051. result1.push(result2);
  10052. pos1 = pos;
  10053. if (input.charCodeAt(pos) === 46) {
  10054. result2 = ".";
  10055. pos++;
  10056. } else {
  10057. result2 = null;
  10058. if (reportFailures === 0) {
  10059. matchFailed("\".\"");
  10060. }
  10061. }
  10062. if (result2 !== null) {
  10063. result3 = parse_token_nodot();
  10064. if (result3 !== null) {
  10065. result2 = [result2, result3];
  10066. } else {
  10067. result2 = null;
  10068. pos = pos1;
  10069. }
  10070. } else {
  10071. result2 = null;
  10072. pos = pos1;
  10073. }
  10074. }
  10075. if (result1 !== null) {
  10076. result0 = [result0, result1];
  10077. } else {
  10078. result0 = null;
  10079. pos = pos0;
  10080. }
  10081. } else {
  10082. result0 = null;
  10083. pos = pos0;
  10084. }
  10085. return result0;
  10086. }
  10087. function parse_From() {
  10088. var result0, result1, result2, result3;
  10089. var pos0, pos1, pos2;
  10090. pos0 = pos;
  10091. pos1 = pos;
  10092. result0 = parse_SIP_URI_noparams();
  10093. if (result0 === null) {
  10094. result0 = parse_name_addr();
  10095. }
  10096. if (result0 !== null) {
  10097. result1 = [];
  10098. pos2 = pos;
  10099. result2 = parse_SEMI();
  10100. if (result2 !== null) {
  10101. result3 = parse_from_param();
  10102. if (result3 !== null) {
  10103. result2 = [result2, result3];
  10104. } else {
  10105. result2 = null;
  10106. pos = pos2;
  10107. }
  10108. } else {
  10109. result2 = null;
  10110. pos = pos2;
  10111. }
  10112. while (result2 !== null) {
  10113. result1.push(result2);
  10114. pos2 = pos;
  10115. result2 = parse_SEMI();
  10116. if (result2 !== null) {
  10117. result3 = parse_from_param();
  10118. if (result3 !== null) {
  10119. result2 = [result2, result3];
  10120. } else {
  10121. result2 = null;
  10122. pos = pos2;
  10123. }
  10124. } else {
  10125. result2 = null;
  10126. pos = pos2;
  10127. }
  10128. }
  10129. if (result1 !== null) {
  10130. result0 = [result0, result1];
  10131. } else {
  10132. result0 = null;
  10133. pos = pos1;
  10134. }
  10135. } else {
  10136. result0 = null;
  10137. pos = pos1;
  10138. }
  10139. if (result0 !== null) {
  10140. result0 = function (offset) {
  10141. var tag = data.tag;
  10142. try {
  10143. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  10144. if (tag) {
  10145. data.setParam('tag', tag);
  10146. }
  10147. } catch (e) {
  10148. data = -1;
  10149. }
  10150. }(pos0);
  10151. }
  10152. if (result0 === null) {
  10153. pos = pos0;
  10154. }
  10155. return result0;
  10156. }
  10157. function parse_from_param() {
  10158. var result0;
  10159. result0 = parse_tag_param();
  10160. if (result0 === null) {
  10161. result0 = parse_generic_param();
  10162. }
  10163. return result0;
  10164. }
  10165. function parse_tag_param() {
  10166. var result0, result1, result2;
  10167. var pos0, pos1;
  10168. pos0 = pos;
  10169. pos1 = pos;
  10170. if (input.substr(pos, 3).toLowerCase() === "tag") {
  10171. result0 = input.substr(pos, 3);
  10172. pos += 3;
  10173. } else {
  10174. result0 = null;
  10175. if (reportFailures === 0) {
  10176. matchFailed("\"tag\"");
  10177. }
  10178. }
  10179. if (result0 !== null) {
  10180. result1 = parse_EQUAL();
  10181. if (result1 !== null) {
  10182. result2 = parse_token();
  10183. if (result2 !== null) {
  10184. result0 = [result0, result1, result2];
  10185. } else {
  10186. result0 = null;
  10187. pos = pos1;
  10188. }
  10189. } else {
  10190. result0 = null;
  10191. pos = pos1;
  10192. }
  10193. } else {
  10194. result0 = null;
  10195. pos = pos1;
  10196. }
  10197. if (result0 !== null) {
  10198. result0 = function (offset, tag) {
  10199. data.tag = tag;
  10200. }(pos0, result0[2]);
  10201. }
  10202. if (result0 === null) {
  10203. pos = pos0;
  10204. }
  10205. return result0;
  10206. }
  10207. function parse_Max_Forwards() {
  10208. var result0, result1;
  10209. var pos0;
  10210. pos0 = pos;
  10211. result1 = parse_DIGIT();
  10212. if (result1 !== null) {
  10213. result0 = [];
  10214. while (result1 !== null) {
  10215. result0.push(result1);
  10216. result1 = parse_DIGIT();
  10217. }
  10218. } else {
  10219. result0 = null;
  10220. }
  10221. if (result0 !== null) {
  10222. result0 = function (offset, forwards) {
  10223. data = parseInt(forwards.join(''));
  10224. }(pos0, result0);
  10225. }
  10226. if (result0 === null) {
  10227. pos = pos0;
  10228. }
  10229. return result0;
  10230. }
  10231. function parse_Min_Expires() {
  10232. var result0;
  10233. var pos0;
  10234. pos0 = pos;
  10235. result0 = parse_delta_seconds();
  10236. if (result0 !== null) {
  10237. result0 = function (offset, min_expires) {
  10238. data = min_expires;
  10239. }(pos0, result0);
  10240. }
  10241. if (result0 === null) {
  10242. pos = pos0;
  10243. }
  10244. return result0;
  10245. }
  10246. function parse_Name_Addr_Header() {
  10247. var result0, result1, result2, result3, result4, result5, result6;
  10248. var pos0, pos1, pos2;
  10249. pos0 = pos;
  10250. pos1 = pos;
  10251. result0 = [];
  10252. result1 = parse_display_name();
  10253. while (result1 !== null) {
  10254. result0.push(result1);
  10255. result1 = parse_display_name();
  10256. }
  10257. if (result0 !== null) {
  10258. result1 = parse_LAQUOT();
  10259. if (result1 !== null) {
  10260. result2 = parse_SIP_URI();
  10261. if (result2 !== null) {
  10262. result3 = parse_RAQUOT();
  10263. if (result3 !== null) {
  10264. result4 = [];
  10265. pos2 = pos;
  10266. result5 = parse_SEMI();
  10267. if (result5 !== null) {
  10268. result6 = parse_generic_param();
  10269. if (result6 !== null) {
  10270. result5 = [result5, result6];
  10271. } else {
  10272. result5 = null;
  10273. pos = pos2;
  10274. }
  10275. } else {
  10276. result5 = null;
  10277. pos = pos2;
  10278. }
  10279. while (result5 !== null) {
  10280. result4.push(result5);
  10281. pos2 = pos;
  10282. result5 = parse_SEMI();
  10283. if (result5 !== null) {
  10284. result6 = parse_generic_param();
  10285. if (result6 !== null) {
  10286. result5 = [result5, result6];
  10287. } else {
  10288. result5 = null;
  10289. pos = pos2;
  10290. }
  10291. } else {
  10292. result5 = null;
  10293. pos = pos2;
  10294. }
  10295. }
  10296. if (result4 !== null) {
  10297. result0 = [result0, result1, result2, result3, result4];
  10298. } else {
  10299. result0 = null;
  10300. pos = pos1;
  10301. }
  10302. } else {
  10303. result0 = null;
  10304. pos = pos1;
  10305. }
  10306. } else {
  10307. result0 = null;
  10308. pos = pos1;
  10309. }
  10310. } else {
  10311. result0 = null;
  10312. pos = pos1;
  10313. }
  10314. } else {
  10315. result0 = null;
  10316. pos = pos1;
  10317. }
  10318. if (result0 !== null) {
  10319. result0 = function (offset) {
  10320. try {
  10321. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  10322. } catch (e) {
  10323. data = -1;
  10324. }
  10325. }(pos0);
  10326. }
  10327. if (result0 === null) {
  10328. pos = pos0;
  10329. }
  10330. return result0;
  10331. }
  10332. function parse_Proxy_Authenticate() {
  10333. var result0;
  10334. result0 = parse_challenge();
  10335. return result0;
  10336. }
  10337. function parse_challenge() {
  10338. var result0, result1, result2, result3, result4, result5;
  10339. var pos0, pos1;
  10340. pos0 = pos;
  10341. if (input.substr(pos, 6).toLowerCase() === "digest") {
  10342. result0 = input.substr(pos, 6);
  10343. pos += 6;
  10344. } else {
  10345. result0 = null;
  10346. if (reportFailures === 0) {
  10347. matchFailed("\"Digest\"");
  10348. }
  10349. }
  10350. if (result0 !== null) {
  10351. result1 = parse_LWS();
  10352. if (result1 !== null) {
  10353. result2 = parse_digest_cln();
  10354. if (result2 !== null) {
  10355. result3 = [];
  10356. pos1 = pos;
  10357. result4 = parse_COMMA();
  10358. if (result4 !== null) {
  10359. result5 = parse_digest_cln();
  10360. if (result5 !== null) {
  10361. result4 = [result4, result5];
  10362. } else {
  10363. result4 = null;
  10364. pos = pos1;
  10365. }
  10366. } else {
  10367. result4 = null;
  10368. pos = pos1;
  10369. }
  10370. while (result4 !== null) {
  10371. result3.push(result4);
  10372. pos1 = pos;
  10373. result4 = parse_COMMA();
  10374. if (result4 !== null) {
  10375. result5 = parse_digest_cln();
  10376. if (result5 !== null) {
  10377. result4 = [result4, result5];
  10378. } else {
  10379. result4 = null;
  10380. pos = pos1;
  10381. }
  10382. } else {
  10383. result4 = null;
  10384. pos = pos1;
  10385. }
  10386. }
  10387. if (result3 !== null) {
  10388. result0 = [result0, result1, result2, result3];
  10389. } else {
  10390. result0 = null;
  10391. pos = pos0;
  10392. }
  10393. } else {
  10394. result0 = null;
  10395. pos = pos0;
  10396. }
  10397. } else {
  10398. result0 = null;
  10399. pos = pos0;
  10400. }
  10401. } else {
  10402. result0 = null;
  10403. pos = pos0;
  10404. }
  10405. if (result0 === null) {
  10406. result0 = parse_other_challenge();
  10407. }
  10408. return result0;
  10409. }
  10410. function parse_other_challenge() {
  10411. var result0, result1, result2, result3, result4, result5;
  10412. var pos0, pos1;
  10413. pos0 = pos;
  10414. result0 = parse_token();
  10415. if (result0 !== null) {
  10416. result1 = parse_LWS();
  10417. if (result1 !== null) {
  10418. result2 = parse_auth_param();
  10419. if (result2 !== null) {
  10420. result3 = [];
  10421. pos1 = pos;
  10422. result4 = parse_COMMA();
  10423. if (result4 !== null) {
  10424. result5 = parse_auth_param();
  10425. if (result5 !== null) {
  10426. result4 = [result4, result5];
  10427. } else {
  10428. result4 = null;
  10429. pos = pos1;
  10430. }
  10431. } else {
  10432. result4 = null;
  10433. pos = pos1;
  10434. }
  10435. while (result4 !== null) {
  10436. result3.push(result4);
  10437. pos1 = pos;
  10438. result4 = parse_COMMA();
  10439. if (result4 !== null) {
  10440. result5 = parse_auth_param();
  10441. if (result5 !== null) {
  10442. result4 = [result4, result5];
  10443. } else {
  10444. result4 = null;
  10445. pos = pos1;
  10446. }
  10447. } else {
  10448. result4 = null;
  10449. pos = pos1;
  10450. }
  10451. }
  10452. if (result3 !== null) {
  10453. result0 = [result0, result1, result2, result3];
  10454. } else {
  10455. result0 = null;
  10456. pos = pos0;
  10457. }
  10458. } else {
  10459. result0 = null;
  10460. pos = pos0;
  10461. }
  10462. } else {
  10463. result0 = null;
  10464. pos = pos0;
  10465. }
  10466. } else {
  10467. result0 = null;
  10468. pos = pos0;
  10469. }
  10470. return result0;
  10471. }
  10472. function parse_auth_param() {
  10473. var result0, result1, result2;
  10474. var pos0;
  10475. pos0 = pos;
  10476. result0 = parse_token();
  10477. if (result0 !== null) {
  10478. result1 = parse_EQUAL();
  10479. if (result1 !== null) {
  10480. result2 = parse_token();
  10481. if (result2 === null) {
  10482. result2 = parse_quoted_string();
  10483. }
  10484. if (result2 !== null) {
  10485. result0 = [result0, result1, result2];
  10486. } else {
  10487. result0 = null;
  10488. pos = pos0;
  10489. }
  10490. } else {
  10491. result0 = null;
  10492. pos = pos0;
  10493. }
  10494. } else {
  10495. result0 = null;
  10496. pos = pos0;
  10497. }
  10498. return result0;
  10499. }
  10500. function parse_digest_cln() {
  10501. var result0;
  10502. result0 = parse_realm();
  10503. if (result0 === null) {
  10504. result0 = parse_domain();
  10505. if (result0 === null) {
  10506. result0 = parse_nonce();
  10507. if (result0 === null) {
  10508. result0 = parse_opaque();
  10509. if (result0 === null) {
  10510. result0 = parse_stale();
  10511. if (result0 === null) {
  10512. result0 = parse_algorithm();
  10513. if (result0 === null) {
  10514. result0 = parse_qop_options();
  10515. if (result0 === null) {
  10516. result0 = parse_auth_param();
  10517. }
  10518. }
  10519. }
  10520. }
  10521. }
  10522. }
  10523. }
  10524. return result0;
  10525. }
  10526. function parse_realm() {
  10527. var result0, result1, result2;
  10528. var pos0;
  10529. pos0 = pos;
  10530. if (input.substr(pos, 5).toLowerCase() === "realm") {
  10531. result0 = input.substr(pos, 5);
  10532. pos += 5;
  10533. } else {
  10534. result0 = null;
  10535. if (reportFailures === 0) {
  10536. matchFailed("\"realm\"");
  10537. }
  10538. }
  10539. if (result0 !== null) {
  10540. result1 = parse_EQUAL();
  10541. if (result1 !== null) {
  10542. result2 = parse_realm_value();
  10543. if (result2 !== null) {
  10544. result0 = [result0, result1, result2];
  10545. } else {
  10546. result0 = null;
  10547. pos = pos0;
  10548. }
  10549. } else {
  10550. result0 = null;
  10551. pos = pos0;
  10552. }
  10553. } else {
  10554. result0 = null;
  10555. pos = pos0;
  10556. }
  10557. return result0;
  10558. }
  10559. function parse_realm_value() {
  10560. var result0;
  10561. var pos0;
  10562. pos0 = pos;
  10563. result0 = parse_quoted_string_clean();
  10564. if (result0 !== null) {
  10565. result0 = function (offset, realm) {
  10566. data.realm = realm;
  10567. }(pos0, result0);
  10568. }
  10569. if (result0 === null) {
  10570. pos = pos0;
  10571. }
  10572. return result0;
  10573. }
  10574. function parse_domain() {
  10575. var result0, result1, result2, result3, result4, result5, result6;
  10576. var pos0, pos1;
  10577. pos0 = pos;
  10578. if (input.substr(pos, 6).toLowerCase() === "domain") {
  10579. result0 = input.substr(pos, 6);
  10580. pos += 6;
  10581. } else {
  10582. result0 = null;
  10583. if (reportFailures === 0) {
  10584. matchFailed("\"domain\"");
  10585. }
  10586. }
  10587. if (result0 !== null) {
  10588. result1 = parse_EQUAL();
  10589. if (result1 !== null) {
  10590. result2 = parse_LDQUOT();
  10591. if (result2 !== null) {
  10592. result3 = parse_URI();
  10593. if (result3 !== null) {
  10594. result4 = [];
  10595. pos1 = pos;
  10596. result6 = parse_SP();
  10597. if (result6 !== null) {
  10598. result5 = [];
  10599. while (result6 !== null) {
  10600. result5.push(result6);
  10601. result6 = parse_SP();
  10602. }
  10603. } else {
  10604. result5 = null;
  10605. }
  10606. if (result5 !== null) {
  10607. result6 = parse_URI();
  10608. if (result6 !== null) {
  10609. result5 = [result5, result6];
  10610. } else {
  10611. result5 = null;
  10612. pos = pos1;
  10613. }
  10614. } else {
  10615. result5 = null;
  10616. pos = pos1;
  10617. }
  10618. while (result5 !== null) {
  10619. result4.push(result5);
  10620. pos1 = pos;
  10621. result6 = parse_SP();
  10622. if (result6 !== null) {
  10623. result5 = [];
  10624. while (result6 !== null) {
  10625. result5.push(result6);
  10626. result6 = parse_SP();
  10627. }
  10628. } else {
  10629. result5 = null;
  10630. }
  10631. if (result5 !== null) {
  10632. result6 = parse_URI();
  10633. if (result6 !== null) {
  10634. result5 = [result5, result6];
  10635. } else {
  10636. result5 = null;
  10637. pos = pos1;
  10638. }
  10639. } else {
  10640. result5 = null;
  10641. pos = pos1;
  10642. }
  10643. }
  10644. if (result4 !== null) {
  10645. result5 = parse_RDQUOT();
  10646. if (result5 !== null) {
  10647. result0 = [result0, result1, result2, result3, result4, result5];
  10648. } else {
  10649. result0 = null;
  10650. pos = pos0;
  10651. }
  10652. } else {
  10653. result0 = null;
  10654. pos = pos0;
  10655. }
  10656. } else {
  10657. result0 = null;
  10658. pos = pos0;
  10659. }
  10660. } else {
  10661. result0 = null;
  10662. pos = pos0;
  10663. }
  10664. } else {
  10665. result0 = null;
  10666. pos = pos0;
  10667. }
  10668. } else {
  10669. result0 = null;
  10670. pos = pos0;
  10671. }
  10672. return result0;
  10673. }
  10674. function parse_URI() {
  10675. var result0;
  10676. result0 = parse_absoluteURI();
  10677. if (result0 === null) {
  10678. result0 = parse_abs_path();
  10679. }
  10680. return result0;
  10681. }
  10682. function parse_nonce() {
  10683. var result0, result1, result2;
  10684. var pos0;
  10685. pos0 = pos;
  10686. if (input.substr(pos, 5).toLowerCase() === "nonce") {
  10687. result0 = input.substr(pos, 5);
  10688. pos += 5;
  10689. } else {
  10690. result0 = null;
  10691. if (reportFailures === 0) {
  10692. matchFailed("\"nonce\"");
  10693. }
  10694. }
  10695. if (result0 !== null) {
  10696. result1 = parse_EQUAL();
  10697. if (result1 !== null) {
  10698. result2 = parse_nonce_value();
  10699. if (result2 !== null) {
  10700. result0 = [result0, result1, result2];
  10701. } else {
  10702. result0 = null;
  10703. pos = pos0;
  10704. }
  10705. } else {
  10706. result0 = null;
  10707. pos = pos0;
  10708. }
  10709. } else {
  10710. result0 = null;
  10711. pos = pos0;
  10712. }
  10713. return result0;
  10714. }
  10715. function parse_nonce_value() {
  10716. var result0;
  10717. var pos0;
  10718. pos0 = pos;
  10719. result0 = parse_quoted_string_clean();
  10720. if (result0 !== null) {
  10721. result0 = function (offset, nonce) {
  10722. data.nonce = nonce;
  10723. }(pos0, result0);
  10724. }
  10725. if (result0 === null) {
  10726. pos = pos0;
  10727. }
  10728. return result0;
  10729. }
  10730. function parse_opaque() {
  10731. var result0, result1, result2;
  10732. var pos0, pos1;
  10733. pos0 = pos;
  10734. pos1 = pos;
  10735. if (input.substr(pos, 6).toLowerCase() === "opaque") {
  10736. result0 = input.substr(pos, 6);
  10737. pos += 6;
  10738. } else {
  10739. result0 = null;
  10740. if (reportFailures === 0) {
  10741. matchFailed("\"opaque\"");
  10742. }
  10743. }
  10744. if (result0 !== null) {
  10745. result1 = parse_EQUAL();
  10746. if (result1 !== null) {
  10747. result2 = parse_quoted_string_clean();
  10748. if (result2 !== null) {
  10749. result0 = [result0, result1, result2];
  10750. } else {
  10751. result0 = null;
  10752. pos = pos1;
  10753. }
  10754. } else {
  10755. result0 = null;
  10756. pos = pos1;
  10757. }
  10758. } else {
  10759. result0 = null;
  10760. pos = pos1;
  10761. }
  10762. if (result0 !== null) {
  10763. result0 = function (offset, opaque) {
  10764. data.opaque = opaque;
  10765. }(pos0, result0[2]);
  10766. }
  10767. if (result0 === null) {
  10768. pos = pos0;
  10769. }
  10770. return result0;
  10771. }
  10772. function parse_stale() {
  10773. var result0, result1, result2;
  10774. var pos0, pos1;
  10775. pos0 = pos;
  10776. if (input.substr(pos, 5).toLowerCase() === "stale") {
  10777. result0 = input.substr(pos, 5);
  10778. pos += 5;
  10779. } else {
  10780. result0 = null;
  10781. if (reportFailures === 0) {
  10782. matchFailed("\"stale\"");
  10783. }
  10784. }
  10785. if (result0 !== null) {
  10786. result1 = parse_EQUAL();
  10787. if (result1 !== null) {
  10788. pos1 = pos;
  10789. if (input.substr(pos, 4).toLowerCase() === "true") {
  10790. result2 = input.substr(pos, 4);
  10791. pos += 4;
  10792. } else {
  10793. result2 = null;
  10794. if (reportFailures === 0) {
  10795. matchFailed("\"true\"");
  10796. }
  10797. }
  10798. if (result2 !== null) {
  10799. result2 = function (offset) {
  10800. data.stale = true;
  10801. }(pos1);
  10802. }
  10803. if (result2 === null) {
  10804. pos = pos1;
  10805. }
  10806. if (result2 === null) {
  10807. pos1 = pos;
  10808. if (input.substr(pos, 5).toLowerCase() === "false") {
  10809. result2 = input.substr(pos, 5);
  10810. pos += 5;
  10811. } else {
  10812. result2 = null;
  10813. if (reportFailures === 0) {
  10814. matchFailed("\"false\"");
  10815. }
  10816. }
  10817. if (result2 !== null) {
  10818. result2 = function (offset) {
  10819. data.stale = false;
  10820. }(pos1);
  10821. }
  10822. if (result2 === null) {
  10823. pos = pos1;
  10824. }
  10825. }
  10826. if (result2 !== null) {
  10827. result0 = [result0, result1, result2];
  10828. } else {
  10829. result0 = null;
  10830. pos = pos0;
  10831. }
  10832. } else {
  10833. result0 = null;
  10834. pos = pos0;
  10835. }
  10836. } else {
  10837. result0 = null;
  10838. pos = pos0;
  10839. }
  10840. return result0;
  10841. }
  10842. function parse_algorithm() {
  10843. var result0, result1, result2;
  10844. var pos0, pos1;
  10845. pos0 = pos;
  10846. pos1 = pos;
  10847. if (input.substr(pos, 9).toLowerCase() === "algorithm") {
  10848. result0 = input.substr(pos, 9);
  10849. pos += 9;
  10850. } else {
  10851. result0 = null;
  10852. if (reportFailures === 0) {
  10853. matchFailed("\"algorithm\"");
  10854. }
  10855. }
  10856. if (result0 !== null) {
  10857. result1 = parse_EQUAL();
  10858. if (result1 !== null) {
  10859. if (input.substr(pos, 3).toLowerCase() === "md5") {
  10860. result2 = input.substr(pos, 3);
  10861. pos += 3;
  10862. } else {
  10863. result2 = null;
  10864. if (reportFailures === 0) {
  10865. matchFailed("\"MD5\"");
  10866. }
  10867. }
  10868. if (result2 === null) {
  10869. if (input.substr(pos, 8).toLowerCase() === "md5-sess") {
  10870. result2 = input.substr(pos, 8);
  10871. pos += 8;
  10872. } else {
  10873. result2 = null;
  10874. if (reportFailures === 0) {
  10875. matchFailed("\"MD5-sess\"");
  10876. }
  10877. }
  10878. if (result2 === null) {
  10879. result2 = parse_token();
  10880. }
  10881. }
  10882. if (result2 !== null) {
  10883. result0 = [result0, result1, result2];
  10884. } else {
  10885. result0 = null;
  10886. pos = pos1;
  10887. }
  10888. } else {
  10889. result0 = null;
  10890. pos = pos1;
  10891. }
  10892. } else {
  10893. result0 = null;
  10894. pos = pos1;
  10895. }
  10896. if (result0 !== null) {
  10897. result0 = function (offset, algorithm) {
  10898. data.algorithm = algorithm.toUpperCase();
  10899. }(pos0, result0[2]);
  10900. }
  10901. if (result0 === null) {
  10902. pos = pos0;
  10903. }
  10904. return result0;
  10905. }
  10906. function parse_qop_options() {
  10907. var result0, result1, result2, result3, result4, result5, result6;
  10908. var pos0, pos1, pos2;
  10909. pos0 = pos;
  10910. if (input.substr(pos, 3).toLowerCase() === "qop") {
  10911. result0 = input.substr(pos, 3);
  10912. pos += 3;
  10913. } else {
  10914. result0 = null;
  10915. if (reportFailures === 0) {
  10916. matchFailed("\"qop\"");
  10917. }
  10918. }
  10919. if (result0 !== null) {
  10920. result1 = parse_EQUAL();
  10921. if (result1 !== null) {
  10922. result2 = parse_LDQUOT();
  10923. if (result2 !== null) {
  10924. pos1 = pos;
  10925. result3 = parse_qop_value();
  10926. if (result3 !== null) {
  10927. result4 = [];
  10928. pos2 = pos;
  10929. if (input.charCodeAt(pos) === 44) {
  10930. result5 = ",";
  10931. pos++;
  10932. } else {
  10933. result5 = null;
  10934. if (reportFailures === 0) {
  10935. matchFailed("\",\"");
  10936. }
  10937. }
  10938. if (result5 !== null) {
  10939. result6 = parse_qop_value();
  10940. if (result6 !== null) {
  10941. result5 = [result5, result6];
  10942. } else {
  10943. result5 = null;
  10944. pos = pos2;
  10945. }
  10946. } else {
  10947. result5 = null;
  10948. pos = pos2;
  10949. }
  10950. while (result5 !== null) {
  10951. result4.push(result5);
  10952. pos2 = pos;
  10953. if (input.charCodeAt(pos) === 44) {
  10954. result5 = ",";
  10955. pos++;
  10956. } else {
  10957. result5 = null;
  10958. if (reportFailures === 0) {
  10959. matchFailed("\",\"");
  10960. }
  10961. }
  10962. if (result5 !== null) {
  10963. result6 = parse_qop_value();
  10964. if (result6 !== null) {
  10965. result5 = [result5, result6];
  10966. } else {
  10967. result5 = null;
  10968. pos = pos2;
  10969. }
  10970. } else {
  10971. result5 = null;
  10972. pos = pos2;
  10973. }
  10974. }
  10975. if (result4 !== null) {
  10976. result3 = [result3, result4];
  10977. } else {
  10978. result3 = null;
  10979. pos = pos1;
  10980. }
  10981. } else {
  10982. result3 = null;
  10983. pos = pos1;
  10984. }
  10985. if (result3 !== null) {
  10986. result4 = parse_RDQUOT();
  10987. if (result4 !== null) {
  10988. result0 = [result0, result1, result2, result3, result4];
  10989. } else {
  10990. result0 = null;
  10991. pos = pos0;
  10992. }
  10993. } else {
  10994. result0 = null;
  10995. pos = pos0;
  10996. }
  10997. } else {
  10998. result0 = null;
  10999. pos = pos0;
  11000. }
  11001. } else {
  11002. result0 = null;
  11003. pos = pos0;
  11004. }
  11005. } else {
  11006. result0 = null;
  11007. pos = pos0;
  11008. }
  11009. return result0;
  11010. }
  11011. function parse_qop_value() {
  11012. var result0;
  11013. var pos0;
  11014. pos0 = pos;
  11015. if (input.substr(pos, 8).toLowerCase() === "auth-int") {
  11016. result0 = input.substr(pos, 8);
  11017. pos += 8;
  11018. } else {
  11019. result0 = null;
  11020. if (reportFailures === 0) {
  11021. matchFailed("\"auth-int\"");
  11022. }
  11023. }
  11024. if (result0 === null) {
  11025. if (input.substr(pos, 4).toLowerCase() === "auth") {
  11026. result0 = input.substr(pos, 4);
  11027. pos += 4;
  11028. } else {
  11029. result0 = null;
  11030. if (reportFailures === 0) {
  11031. matchFailed("\"auth\"");
  11032. }
  11033. }
  11034. if (result0 === null) {
  11035. result0 = parse_token();
  11036. }
  11037. }
  11038. if (result0 !== null) {
  11039. result0 = function (offset, qop_value) {
  11040. data.qop || (data.qop = []);
  11041. data.qop.push(qop_value.toLowerCase());
  11042. }(pos0, result0);
  11043. }
  11044. if (result0 === null) {
  11045. pos = pos0;
  11046. }
  11047. return result0;
  11048. }
  11049. function parse_Proxy_Require() {
  11050. var result0, result1, result2, result3;
  11051. var pos0, pos1;
  11052. pos0 = pos;
  11053. result0 = parse_token();
  11054. if (result0 !== null) {
  11055. result1 = [];
  11056. pos1 = pos;
  11057. result2 = parse_COMMA();
  11058. if (result2 !== null) {
  11059. result3 = parse_token();
  11060. if (result3 !== null) {
  11061. result2 = [result2, result3];
  11062. } else {
  11063. result2 = null;
  11064. pos = pos1;
  11065. }
  11066. } else {
  11067. result2 = null;
  11068. pos = pos1;
  11069. }
  11070. while (result2 !== null) {
  11071. result1.push(result2);
  11072. pos1 = pos;
  11073. result2 = parse_COMMA();
  11074. if (result2 !== null) {
  11075. result3 = parse_token();
  11076. if (result3 !== null) {
  11077. result2 = [result2, result3];
  11078. } else {
  11079. result2 = null;
  11080. pos = pos1;
  11081. }
  11082. } else {
  11083. result2 = null;
  11084. pos = pos1;
  11085. }
  11086. }
  11087. if (result1 !== null) {
  11088. result0 = [result0, result1];
  11089. } else {
  11090. result0 = null;
  11091. pos = pos0;
  11092. }
  11093. } else {
  11094. result0 = null;
  11095. pos = pos0;
  11096. }
  11097. return result0;
  11098. }
  11099. function parse_Record_Route() {
  11100. var result0, result1, result2, result3;
  11101. var pos0, pos1, pos2;
  11102. pos0 = pos;
  11103. pos1 = pos;
  11104. result0 = parse_rec_route();
  11105. if (result0 !== null) {
  11106. result1 = [];
  11107. pos2 = pos;
  11108. result2 = parse_COMMA();
  11109. if (result2 !== null) {
  11110. result3 = parse_rec_route();
  11111. if (result3 !== null) {
  11112. result2 = [result2, result3];
  11113. } else {
  11114. result2 = null;
  11115. pos = pos2;
  11116. }
  11117. } else {
  11118. result2 = null;
  11119. pos = pos2;
  11120. }
  11121. while (result2 !== null) {
  11122. result1.push(result2);
  11123. pos2 = pos;
  11124. result2 = parse_COMMA();
  11125. if (result2 !== null) {
  11126. result3 = parse_rec_route();
  11127. if (result3 !== null) {
  11128. result2 = [result2, result3];
  11129. } else {
  11130. result2 = null;
  11131. pos = pos2;
  11132. }
  11133. } else {
  11134. result2 = null;
  11135. pos = pos2;
  11136. }
  11137. }
  11138. if (result1 !== null) {
  11139. result0 = [result0, result1];
  11140. } else {
  11141. result0 = null;
  11142. pos = pos1;
  11143. }
  11144. } else {
  11145. result0 = null;
  11146. pos = pos1;
  11147. }
  11148. if (result0 !== null) {
  11149. result0 = function (offset) {
  11150. var idx, length;
  11151. length = data.multi_header.length;
  11152. for (idx = 0; idx < length; idx++) {
  11153. if (data.multi_header[idx].parsed === null) {
  11154. data = null;
  11155. break;
  11156. }
  11157. }
  11158. if (data !== null) {
  11159. data = data.multi_header;
  11160. } else {
  11161. data = -1;
  11162. }
  11163. }(pos0);
  11164. }
  11165. if (result0 === null) {
  11166. pos = pos0;
  11167. }
  11168. return result0;
  11169. }
  11170. function parse_rec_route() {
  11171. var result0, result1, result2, result3;
  11172. var pos0, pos1, pos2;
  11173. pos0 = pos;
  11174. pos1 = pos;
  11175. result0 = parse_name_addr();
  11176. if (result0 !== null) {
  11177. result1 = [];
  11178. pos2 = pos;
  11179. result2 = parse_SEMI();
  11180. if (result2 !== null) {
  11181. result3 = parse_generic_param();
  11182. if (result3 !== null) {
  11183. result2 = [result2, result3];
  11184. } else {
  11185. result2 = null;
  11186. pos = pos2;
  11187. }
  11188. } else {
  11189. result2 = null;
  11190. pos = pos2;
  11191. }
  11192. while (result2 !== null) {
  11193. result1.push(result2);
  11194. pos2 = pos;
  11195. result2 = parse_SEMI();
  11196. if (result2 !== null) {
  11197. result3 = parse_generic_param();
  11198. if (result3 !== null) {
  11199. result2 = [result2, result3];
  11200. } else {
  11201. result2 = null;
  11202. pos = pos2;
  11203. }
  11204. } else {
  11205. result2 = null;
  11206. pos = pos2;
  11207. }
  11208. }
  11209. if (result1 !== null) {
  11210. result0 = [result0, result1];
  11211. } else {
  11212. result0 = null;
  11213. pos = pos1;
  11214. }
  11215. } else {
  11216. result0 = null;
  11217. pos = pos1;
  11218. }
  11219. if (result0 !== null) {
  11220. result0 = function (offset) {
  11221. var header;
  11222. if (!data.multi_header) data.multi_header = [];
  11223. try {
  11224. header = new NameAddrHeader(data.uri, data.display_name, data.params);
  11225. delete data.uri;
  11226. delete data.display_name;
  11227. delete data.params;
  11228. } catch (e) {
  11229. header = null;
  11230. }
  11231. data.multi_header.push({
  11232. 'possition': pos,
  11233. 'offset': offset,
  11234. 'parsed': header
  11235. });
  11236. }(pos0);
  11237. }
  11238. if (result0 === null) {
  11239. pos = pos0;
  11240. }
  11241. return result0;
  11242. }
  11243. function parse_Reason() {
  11244. var result0, result1, result2, result3;
  11245. var pos0, pos1, pos2;
  11246. pos0 = pos;
  11247. pos1 = pos;
  11248. if (input.substr(pos, 3).toLowerCase() === "sip") {
  11249. result0 = input.substr(pos, 3);
  11250. pos += 3;
  11251. } else {
  11252. result0 = null;
  11253. if (reportFailures === 0) {
  11254. matchFailed("\"SIP\"");
  11255. }
  11256. }
  11257. if (result0 === null) {
  11258. result0 = parse_token();
  11259. }
  11260. if (result0 !== null) {
  11261. result1 = [];
  11262. pos2 = pos;
  11263. result2 = parse_SEMI();
  11264. if (result2 !== null) {
  11265. result3 = parse_reason_param();
  11266. if (result3 !== null) {
  11267. result2 = [result2, result3];
  11268. } else {
  11269. result2 = null;
  11270. pos = pos2;
  11271. }
  11272. } else {
  11273. result2 = null;
  11274. pos = pos2;
  11275. }
  11276. while (result2 !== null) {
  11277. result1.push(result2);
  11278. pos2 = pos;
  11279. result2 = parse_SEMI();
  11280. if (result2 !== null) {
  11281. result3 = parse_reason_param();
  11282. if (result3 !== null) {
  11283. result2 = [result2, result3];
  11284. } else {
  11285. result2 = null;
  11286. pos = pos2;
  11287. }
  11288. } else {
  11289. result2 = null;
  11290. pos = pos2;
  11291. }
  11292. }
  11293. if (result1 !== null) {
  11294. result0 = [result0, result1];
  11295. } else {
  11296. result0 = null;
  11297. pos = pos1;
  11298. }
  11299. } else {
  11300. result0 = null;
  11301. pos = pos1;
  11302. }
  11303. if (result0 !== null) {
  11304. result0 = function (offset, protocol) {
  11305. data.protocol = protocol.toLowerCase();
  11306. if (!data.params) data.params = {};
  11307. if (data.params.text && data.params.text[0] === '"') {
  11308. var text = data.params.text;
  11309. data.text = text.substring(1, text.length - 1);
  11310. delete data.params.text;
  11311. }
  11312. }(pos0, result0[0]);
  11313. }
  11314. if (result0 === null) {
  11315. pos = pos0;
  11316. }
  11317. return result0;
  11318. }
  11319. function parse_reason_param() {
  11320. var result0;
  11321. result0 = parse_reason_cause();
  11322. if (result0 === null) {
  11323. result0 = parse_generic_param();
  11324. }
  11325. return result0;
  11326. }
  11327. function parse_reason_cause() {
  11328. var result0, result1, result2, result3;
  11329. var pos0, pos1;
  11330. pos0 = pos;
  11331. pos1 = pos;
  11332. if (input.substr(pos, 5).toLowerCase() === "cause") {
  11333. result0 = input.substr(pos, 5);
  11334. pos += 5;
  11335. } else {
  11336. result0 = null;
  11337. if (reportFailures === 0) {
  11338. matchFailed("\"cause\"");
  11339. }
  11340. }
  11341. if (result0 !== null) {
  11342. result1 = parse_EQUAL();
  11343. if (result1 !== null) {
  11344. result3 = parse_DIGIT();
  11345. if (result3 !== null) {
  11346. result2 = [];
  11347. while (result3 !== null) {
  11348. result2.push(result3);
  11349. result3 = parse_DIGIT();
  11350. }
  11351. } else {
  11352. result2 = null;
  11353. }
  11354. if (result2 !== null) {
  11355. result0 = [result0, result1, result2];
  11356. } else {
  11357. result0 = null;
  11358. pos = pos1;
  11359. }
  11360. } else {
  11361. result0 = null;
  11362. pos = pos1;
  11363. }
  11364. } else {
  11365. result0 = null;
  11366. pos = pos1;
  11367. }
  11368. if (result0 !== null) {
  11369. result0 = function (offset, cause) {
  11370. data.cause = parseInt(cause.join(''));
  11371. }(pos0, result0[2]);
  11372. }
  11373. if (result0 === null) {
  11374. pos = pos0;
  11375. }
  11376. return result0;
  11377. }
  11378. function parse_Require() {
  11379. var result0, result1, result2, result3;
  11380. var pos0, pos1;
  11381. pos0 = pos;
  11382. result0 = parse_token();
  11383. if (result0 !== null) {
  11384. result1 = [];
  11385. pos1 = pos;
  11386. result2 = parse_COMMA();
  11387. if (result2 !== null) {
  11388. result3 = parse_token();
  11389. if (result3 !== null) {
  11390. result2 = [result2, result3];
  11391. } else {
  11392. result2 = null;
  11393. pos = pos1;
  11394. }
  11395. } else {
  11396. result2 = null;
  11397. pos = pos1;
  11398. }
  11399. while (result2 !== null) {
  11400. result1.push(result2);
  11401. pos1 = pos;
  11402. result2 = parse_COMMA();
  11403. if (result2 !== null) {
  11404. result3 = parse_token();
  11405. if (result3 !== null) {
  11406. result2 = [result2, result3];
  11407. } else {
  11408. result2 = null;
  11409. pos = pos1;
  11410. }
  11411. } else {
  11412. result2 = null;
  11413. pos = pos1;
  11414. }
  11415. }
  11416. if (result1 !== null) {
  11417. result0 = [result0, result1];
  11418. } else {
  11419. result0 = null;
  11420. pos = pos0;
  11421. }
  11422. } else {
  11423. result0 = null;
  11424. pos = pos0;
  11425. }
  11426. return result0;
  11427. }
  11428. function parse_Route() {
  11429. var result0, result1, result2, result3;
  11430. var pos0, pos1;
  11431. pos0 = pos;
  11432. result0 = parse_route_param();
  11433. if (result0 !== null) {
  11434. result1 = [];
  11435. pos1 = pos;
  11436. result2 = parse_COMMA();
  11437. if (result2 !== null) {
  11438. result3 = parse_route_param();
  11439. if (result3 !== null) {
  11440. result2 = [result2, result3];
  11441. } else {
  11442. result2 = null;
  11443. pos = pos1;
  11444. }
  11445. } else {
  11446. result2 = null;
  11447. pos = pos1;
  11448. }
  11449. while (result2 !== null) {
  11450. result1.push(result2);
  11451. pos1 = pos;
  11452. result2 = parse_COMMA();
  11453. if (result2 !== null) {
  11454. result3 = parse_route_param();
  11455. if (result3 !== null) {
  11456. result2 = [result2, result3];
  11457. } else {
  11458. result2 = null;
  11459. pos = pos1;
  11460. }
  11461. } else {
  11462. result2 = null;
  11463. pos = pos1;
  11464. }
  11465. }
  11466. if (result1 !== null) {
  11467. result0 = [result0, result1];
  11468. } else {
  11469. result0 = null;
  11470. pos = pos0;
  11471. }
  11472. } else {
  11473. result0 = null;
  11474. pos = pos0;
  11475. }
  11476. return result0;
  11477. }
  11478. function parse_route_param() {
  11479. var result0, result1, result2, result3;
  11480. var pos0, pos1;
  11481. pos0 = pos;
  11482. result0 = parse_name_addr();
  11483. if (result0 !== null) {
  11484. result1 = [];
  11485. pos1 = pos;
  11486. result2 = parse_SEMI();
  11487. if (result2 !== null) {
  11488. result3 = parse_generic_param();
  11489. if (result3 !== null) {
  11490. result2 = [result2, result3];
  11491. } else {
  11492. result2 = null;
  11493. pos = pos1;
  11494. }
  11495. } else {
  11496. result2 = null;
  11497. pos = pos1;
  11498. }
  11499. while (result2 !== null) {
  11500. result1.push(result2);
  11501. pos1 = pos;
  11502. result2 = parse_SEMI();
  11503. if (result2 !== null) {
  11504. result3 = parse_generic_param();
  11505. if (result3 !== null) {
  11506. result2 = [result2, result3];
  11507. } else {
  11508. result2 = null;
  11509. pos = pos1;
  11510. }
  11511. } else {
  11512. result2 = null;
  11513. pos = pos1;
  11514. }
  11515. }
  11516. if (result1 !== null) {
  11517. result0 = [result0, result1];
  11518. } else {
  11519. result0 = null;
  11520. pos = pos0;
  11521. }
  11522. } else {
  11523. result0 = null;
  11524. pos = pos0;
  11525. }
  11526. return result0;
  11527. }
  11528. function parse_Subscription_State() {
  11529. var result0, result1, result2, result3;
  11530. var pos0, pos1;
  11531. pos0 = pos;
  11532. result0 = parse_substate_value();
  11533. if (result0 !== null) {
  11534. result1 = [];
  11535. pos1 = pos;
  11536. result2 = parse_SEMI();
  11537. if (result2 !== null) {
  11538. result3 = parse_subexp_params();
  11539. if (result3 !== null) {
  11540. result2 = [result2, result3];
  11541. } else {
  11542. result2 = null;
  11543. pos = pos1;
  11544. }
  11545. } else {
  11546. result2 = null;
  11547. pos = pos1;
  11548. }
  11549. while (result2 !== null) {
  11550. result1.push(result2);
  11551. pos1 = pos;
  11552. result2 = parse_SEMI();
  11553. if (result2 !== null) {
  11554. result3 = parse_subexp_params();
  11555. if (result3 !== null) {
  11556. result2 = [result2, result3];
  11557. } else {
  11558. result2 = null;
  11559. pos = pos1;
  11560. }
  11561. } else {
  11562. result2 = null;
  11563. pos = pos1;
  11564. }
  11565. }
  11566. if (result1 !== null) {
  11567. result0 = [result0, result1];
  11568. } else {
  11569. result0 = null;
  11570. pos = pos0;
  11571. }
  11572. } else {
  11573. result0 = null;
  11574. pos = pos0;
  11575. }
  11576. return result0;
  11577. }
  11578. function parse_substate_value() {
  11579. var result0;
  11580. var pos0;
  11581. pos0 = pos;
  11582. if (input.substr(pos, 6).toLowerCase() === "active") {
  11583. result0 = input.substr(pos, 6);
  11584. pos += 6;
  11585. } else {
  11586. result0 = null;
  11587. if (reportFailures === 0) {
  11588. matchFailed("\"active\"");
  11589. }
  11590. }
  11591. if (result0 === null) {
  11592. if (input.substr(pos, 7).toLowerCase() === "pending") {
  11593. result0 = input.substr(pos, 7);
  11594. pos += 7;
  11595. } else {
  11596. result0 = null;
  11597. if (reportFailures === 0) {
  11598. matchFailed("\"pending\"");
  11599. }
  11600. }
  11601. if (result0 === null) {
  11602. if (input.substr(pos, 10).toLowerCase() === "terminated") {
  11603. result0 = input.substr(pos, 10);
  11604. pos += 10;
  11605. } else {
  11606. result0 = null;
  11607. if (reportFailures === 0) {
  11608. matchFailed("\"terminated\"");
  11609. }
  11610. }
  11611. if (result0 === null) {
  11612. result0 = parse_token();
  11613. }
  11614. }
  11615. }
  11616. if (result0 !== null) {
  11617. result0 = function (offset) {
  11618. data.state = input.substring(pos, offset);
  11619. }(pos0);
  11620. }
  11621. if (result0 === null) {
  11622. pos = pos0;
  11623. }
  11624. return result0;
  11625. }
  11626. function parse_subexp_params() {
  11627. var result0, result1, result2;
  11628. var pos0, pos1;
  11629. pos0 = pos;
  11630. pos1 = pos;
  11631. if (input.substr(pos, 6).toLowerCase() === "reason") {
  11632. result0 = input.substr(pos, 6);
  11633. pos += 6;
  11634. } else {
  11635. result0 = null;
  11636. if (reportFailures === 0) {
  11637. matchFailed("\"reason\"");
  11638. }
  11639. }
  11640. if (result0 !== null) {
  11641. result1 = parse_EQUAL();
  11642. if (result1 !== null) {
  11643. result2 = parse_event_reason_value();
  11644. if (result2 !== null) {
  11645. result0 = [result0, result1, result2];
  11646. } else {
  11647. result0 = null;
  11648. pos = pos1;
  11649. }
  11650. } else {
  11651. result0 = null;
  11652. pos = pos1;
  11653. }
  11654. } else {
  11655. result0 = null;
  11656. pos = pos1;
  11657. }
  11658. if (result0 !== null) {
  11659. result0 = function (offset, reason) {
  11660. if (typeof reason !== 'undefined') data.reason = reason;
  11661. }(pos0, result0[2]);
  11662. }
  11663. if (result0 === null) {
  11664. pos = pos0;
  11665. }
  11666. if (result0 === null) {
  11667. pos0 = pos;
  11668. pos1 = pos;
  11669. if (input.substr(pos, 7).toLowerCase() === "expires") {
  11670. result0 = input.substr(pos, 7);
  11671. pos += 7;
  11672. } else {
  11673. result0 = null;
  11674. if (reportFailures === 0) {
  11675. matchFailed("\"expires\"");
  11676. }
  11677. }
  11678. if (result0 !== null) {
  11679. result1 = parse_EQUAL();
  11680. if (result1 !== null) {
  11681. result2 = parse_delta_seconds();
  11682. if (result2 !== null) {
  11683. result0 = [result0, result1, result2];
  11684. } else {
  11685. result0 = null;
  11686. pos = pos1;
  11687. }
  11688. } else {
  11689. result0 = null;
  11690. pos = pos1;
  11691. }
  11692. } else {
  11693. result0 = null;
  11694. pos = pos1;
  11695. }
  11696. if (result0 !== null) {
  11697. result0 = function (offset, expires) {
  11698. if (typeof expires !== 'undefined') data.expires = expires;
  11699. }(pos0, result0[2]);
  11700. }
  11701. if (result0 === null) {
  11702. pos = pos0;
  11703. }
  11704. if (result0 === null) {
  11705. pos0 = pos;
  11706. pos1 = pos;
  11707. if (input.substr(pos, 11).toLowerCase() === "retry_after") {
  11708. result0 = input.substr(pos, 11);
  11709. pos += 11;
  11710. } else {
  11711. result0 = null;
  11712. if (reportFailures === 0) {
  11713. matchFailed("\"retry_after\"");
  11714. }
  11715. }
  11716. if (result0 !== null) {
  11717. result1 = parse_EQUAL();
  11718. if (result1 !== null) {
  11719. result2 = parse_delta_seconds();
  11720. if (result2 !== null) {
  11721. result0 = [result0, result1, result2];
  11722. } else {
  11723. result0 = null;
  11724. pos = pos1;
  11725. }
  11726. } else {
  11727. result0 = null;
  11728. pos = pos1;
  11729. }
  11730. } else {
  11731. result0 = null;
  11732. pos = pos1;
  11733. }
  11734. if (result0 !== null) {
  11735. result0 = function (offset, retry_after) {
  11736. if (typeof retry_after !== 'undefined') data.retry_after = retry_after;
  11737. }(pos0, result0[2]);
  11738. }
  11739. if (result0 === null) {
  11740. pos = pos0;
  11741. }
  11742. if (result0 === null) {
  11743. result0 = parse_generic_param();
  11744. }
  11745. }
  11746. }
  11747. return result0;
  11748. }
  11749. function parse_event_reason_value() {
  11750. var result0;
  11751. if (input.substr(pos, 11).toLowerCase() === "deactivated") {
  11752. result0 = input.substr(pos, 11);
  11753. pos += 11;
  11754. } else {
  11755. result0 = null;
  11756. if (reportFailures === 0) {
  11757. matchFailed("\"deactivated\"");
  11758. }
  11759. }
  11760. if (result0 === null) {
  11761. if (input.substr(pos, 9).toLowerCase() === "probation") {
  11762. result0 = input.substr(pos, 9);
  11763. pos += 9;
  11764. } else {
  11765. result0 = null;
  11766. if (reportFailures === 0) {
  11767. matchFailed("\"probation\"");
  11768. }
  11769. }
  11770. if (result0 === null) {
  11771. if (input.substr(pos, 8).toLowerCase() === "rejected") {
  11772. result0 = input.substr(pos, 8);
  11773. pos += 8;
  11774. } else {
  11775. result0 = null;
  11776. if (reportFailures === 0) {
  11777. matchFailed("\"rejected\"");
  11778. }
  11779. }
  11780. if (result0 === null) {
  11781. if (input.substr(pos, 7).toLowerCase() === "timeout") {
  11782. result0 = input.substr(pos, 7);
  11783. pos += 7;
  11784. } else {
  11785. result0 = null;
  11786. if (reportFailures === 0) {
  11787. matchFailed("\"timeout\"");
  11788. }
  11789. }
  11790. if (result0 === null) {
  11791. if (input.substr(pos, 6).toLowerCase() === "giveup") {
  11792. result0 = input.substr(pos, 6);
  11793. pos += 6;
  11794. } else {
  11795. result0 = null;
  11796. if (reportFailures === 0) {
  11797. matchFailed("\"giveup\"");
  11798. }
  11799. }
  11800. if (result0 === null) {
  11801. if (input.substr(pos, 10).toLowerCase() === "noresource") {
  11802. result0 = input.substr(pos, 10);
  11803. pos += 10;
  11804. } else {
  11805. result0 = null;
  11806. if (reportFailures === 0) {
  11807. matchFailed("\"noresource\"");
  11808. }
  11809. }
  11810. if (result0 === null) {
  11811. if (input.substr(pos, 9).toLowerCase() === "invariant") {
  11812. result0 = input.substr(pos, 9);
  11813. pos += 9;
  11814. } else {
  11815. result0 = null;
  11816. if (reportFailures === 0) {
  11817. matchFailed("\"invariant\"");
  11818. }
  11819. }
  11820. if (result0 === null) {
  11821. result0 = parse_token();
  11822. }
  11823. }
  11824. }
  11825. }
  11826. }
  11827. }
  11828. }
  11829. return result0;
  11830. }
  11831. function parse_Subject() {
  11832. var result0;
  11833. result0 = parse_TEXT_UTF8_TRIM();
  11834. result0 = result0 !== null ? result0 : "";
  11835. return result0;
  11836. }
  11837. function parse_Supported() {
  11838. var result0, result1, result2, result3;
  11839. var pos0, pos1;
  11840. pos0 = pos;
  11841. result0 = parse_token();
  11842. if (result0 !== null) {
  11843. result1 = [];
  11844. pos1 = pos;
  11845. result2 = parse_COMMA();
  11846. if (result2 !== null) {
  11847. result3 = parse_token();
  11848. if (result3 !== null) {
  11849. result2 = [result2, result3];
  11850. } else {
  11851. result2 = null;
  11852. pos = pos1;
  11853. }
  11854. } else {
  11855. result2 = null;
  11856. pos = pos1;
  11857. }
  11858. while (result2 !== null) {
  11859. result1.push(result2);
  11860. pos1 = pos;
  11861. result2 = parse_COMMA();
  11862. if (result2 !== null) {
  11863. result3 = parse_token();
  11864. if (result3 !== null) {
  11865. result2 = [result2, result3];
  11866. } else {
  11867. result2 = null;
  11868. pos = pos1;
  11869. }
  11870. } else {
  11871. result2 = null;
  11872. pos = pos1;
  11873. }
  11874. }
  11875. if (result1 !== null) {
  11876. result0 = [result0, result1];
  11877. } else {
  11878. result0 = null;
  11879. pos = pos0;
  11880. }
  11881. } else {
  11882. result0 = null;
  11883. pos = pos0;
  11884. }
  11885. result0 = result0 !== null ? result0 : "";
  11886. return result0;
  11887. }
  11888. function parse_To() {
  11889. var result0, result1, result2, result3;
  11890. var pos0, pos1, pos2;
  11891. pos0 = pos;
  11892. pos1 = pos;
  11893. result0 = parse_SIP_URI_noparams();
  11894. if (result0 === null) {
  11895. result0 = parse_name_addr();
  11896. }
  11897. if (result0 !== null) {
  11898. result1 = [];
  11899. pos2 = pos;
  11900. result2 = parse_SEMI();
  11901. if (result2 !== null) {
  11902. result3 = parse_to_param();
  11903. if (result3 !== null) {
  11904. result2 = [result2, result3];
  11905. } else {
  11906. result2 = null;
  11907. pos = pos2;
  11908. }
  11909. } else {
  11910. result2 = null;
  11911. pos = pos2;
  11912. }
  11913. while (result2 !== null) {
  11914. result1.push(result2);
  11915. pos2 = pos;
  11916. result2 = parse_SEMI();
  11917. if (result2 !== null) {
  11918. result3 = parse_to_param();
  11919. if (result3 !== null) {
  11920. result2 = [result2, result3];
  11921. } else {
  11922. result2 = null;
  11923. pos = pos2;
  11924. }
  11925. } else {
  11926. result2 = null;
  11927. pos = pos2;
  11928. }
  11929. }
  11930. if (result1 !== null) {
  11931. result0 = [result0, result1];
  11932. } else {
  11933. result0 = null;
  11934. pos = pos1;
  11935. }
  11936. } else {
  11937. result0 = null;
  11938. pos = pos1;
  11939. }
  11940. if (result0 !== null) {
  11941. result0 = function (offset) {
  11942. var tag = data.tag;
  11943. try {
  11944. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  11945. if (tag) {
  11946. data.setParam('tag', tag);
  11947. }
  11948. } catch (e) {
  11949. data = -1;
  11950. }
  11951. }(pos0);
  11952. }
  11953. if (result0 === null) {
  11954. pos = pos0;
  11955. }
  11956. return result0;
  11957. }
  11958. function parse_to_param() {
  11959. var result0;
  11960. result0 = parse_tag_param();
  11961. if (result0 === null) {
  11962. result0 = parse_generic_param();
  11963. }
  11964. return result0;
  11965. }
  11966. function parse_Via() {
  11967. var result0, result1, result2, result3;
  11968. var pos0, pos1;
  11969. pos0 = pos;
  11970. result0 = parse_via_param();
  11971. if (result0 !== null) {
  11972. result1 = [];
  11973. pos1 = pos;
  11974. result2 = parse_COMMA();
  11975. if (result2 !== null) {
  11976. result3 = parse_via_param();
  11977. if (result3 !== null) {
  11978. result2 = [result2, result3];
  11979. } else {
  11980. result2 = null;
  11981. pos = pos1;
  11982. }
  11983. } else {
  11984. result2 = null;
  11985. pos = pos1;
  11986. }
  11987. while (result2 !== null) {
  11988. result1.push(result2);
  11989. pos1 = pos;
  11990. result2 = parse_COMMA();
  11991. if (result2 !== null) {
  11992. result3 = parse_via_param();
  11993. if (result3 !== null) {
  11994. result2 = [result2, result3];
  11995. } else {
  11996. result2 = null;
  11997. pos = pos1;
  11998. }
  11999. } else {
  12000. result2 = null;
  12001. pos = pos1;
  12002. }
  12003. }
  12004. if (result1 !== null) {
  12005. result0 = [result0, result1];
  12006. } else {
  12007. result0 = null;
  12008. pos = pos0;
  12009. }
  12010. } else {
  12011. result0 = null;
  12012. pos = pos0;
  12013. }
  12014. return result0;
  12015. }
  12016. function parse_via_param() {
  12017. var result0, result1, result2, result3, result4, result5;
  12018. var pos0, pos1;
  12019. pos0 = pos;
  12020. result0 = parse_sent_protocol();
  12021. if (result0 !== null) {
  12022. result1 = parse_LWS();
  12023. if (result1 !== null) {
  12024. result2 = parse_sent_by();
  12025. if (result2 !== null) {
  12026. result3 = [];
  12027. pos1 = pos;
  12028. result4 = parse_SEMI();
  12029. if (result4 !== null) {
  12030. result5 = parse_via_params();
  12031. if (result5 !== null) {
  12032. result4 = [result4, result5];
  12033. } else {
  12034. result4 = null;
  12035. pos = pos1;
  12036. }
  12037. } else {
  12038. result4 = null;
  12039. pos = pos1;
  12040. }
  12041. while (result4 !== null) {
  12042. result3.push(result4);
  12043. pos1 = pos;
  12044. result4 = parse_SEMI();
  12045. if (result4 !== null) {
  12046. result5 = parse_via_params();
  12047. if (result5 !== null) {
  12048. result4 = [result4, result5];
  12049. } else {
  12050. result4 = null;
  12051. pos = pos1;
  12052. }
  12053. } else {
  12054. result4 = null;
  12055. pos = pos1;
  12056. }
  12057. }
  12058. if (result3 !== null) {
  12059. result0 = [result0, result1, result2, result3];
  12060. } else {
  12061. result0 = null;
  12062. pos = pos0;
  12063. }
  12064. } else {
  12065. result0 = null;
  12066. pos = pos0;
  12067. }
  12068. } else {
  12069. result0 = null;
  12070. pos = pos0;
  12071. }
  12072. } else {
  12073. result0 = null;
  12074. pos = pos0;
  12075. }
  12076. return result0;
  12077. }
  12078. function parse_via_params() {
  12079. var result0;
  12080. result0 = parse_via_ttl();
  12081. if (result0 === null) {
  12082. result0 = parse_via_maddr();
  12083. if (result0 === null) {
  12084. result0 = parse_via_received();
  12085. if (result0 === null) {
  12086. result0 = parse_via_branch();
  12087. if (result0 === null) {
  12088. result0 = parse_response_port();
  12089. if (result0 === null) {
  12090. result0 = parse_generic_param();
  12091. }
  12092. }
  12093. }
  12094. }
  12095. }
  12096. return result0;
  12097. }
  12098. function parse_via_ttl() {
  12099. var result0, result1, result2;
  12100. var pos0, pos1;
  12101. pos0 = pos;
  12102. pos1 = pos;
  12103. if (input.substr(pos, 3).toLowerCase() === "ttl") {
  12104. result0 = input.substr(pos, 3);
  12105. pos += 3;
  12106. } else {
  12107. result0 = null;
  12108. if (reportFailures === 0) {
  12109. matchFailed("\"ttl\"");
  12110. }
  12111. }
  12112. if (result0 !== null) {
  12113. result1 = parse_EQUAL();
  12114. if (result1 !== null) {
  12115. result2 = parse_ttl();
  12116. if (result2 !== null) {
  12117. result0 = [result0, result1, result2];
  12118. } else {
  12119. result0 = null;
  12120. pos = pos1;
  12121. }
  12122. } else {
  12123. result0 = null;
  12124. pos = pos1;
  12125. }
  12126. } else {
  12127. result0 = null;
  12128. pos = pos1;
  12129. }
  12130. if (result0 !== null) {
  12131. result0 = function (offset, via_ttl_value) {
  12132. data.ttl = via_ttl_value;
  12133. }(pos0, result0[2]);
  12134. }
  12135. if (result0 === null) {
  12136. pos = pos0;
  12137. }
  12138. return result0;
  12139. }
  12140. function parse_via_maddr() {
  12141. var result0, result1, result2;
  12142. var pos0, pos1;
  12143. pos0 = pos;
  12144. pos1 = pos;
  12145. if (input.substr(pos, 5).toLowerCase() === "maddr") {
  12146. result0 = input.substr(pos, 5);
  12147. pos += 5;
  12148. } else {
  12149. result0 = null;
  12150. if (reportFailures === 0) {
  12151. matchFailed("\"maddr\"");
  12152. }
  12153. }
  12154. if (result0 !== null) {
  12155. result1 = parse_EQUAL();
  12156. if (result1 !== null) {
  12157. result2 = parse_host();
  12158. if (result2 !== null) {
  12159. result0 = [result0, result1, result2];
  12160. } else {
  12161. result0 = null;
  12162. pos = pos1;
  12163. }
  12164. } else {
  12165. result0 = null;
  12166. pos = pos1;
  12167. }
  12168. } else {
  12169. result0 = null;
  12170. pos = pos1;
  12171. }
  12172. if (result0 !== null) {
  12173. result0 = function (offset, via_maddr) {
  12174. data.maddr = via_maddr;
  12175. }(pos0, result0[2]);
  12176. }
  12177. if (result0 === null) {
  12178. pos = pos0;
  12179. }
  12180. return result0;
  12181. }
  12182. function parse_via_received() {
  12183. var result0, result1, result2;
  12184. var pos0, pos1;
  12185. pos0 = pos;
  12186. pos1 = pos;
  12187. if (input.substr(pos, 8).toLowerCase() === "received") {
  12188. result0 = input.substr(pos, 8);
  12189. pos += 8;
  12190. } else {
  12191. result0 = null;
  12192. if (reportFailures === 0) {
  12193. matchFailed("\"received\"");
  12194. }
  12195. }
  12196. if (result0 !== null) {
  12197. result1 = parse_EQUAL();
  12198. if (result1 !== null) {
  12199. result2 = parse_IPv4address();
  12200. if (result2 === null) {
  12201. result2 = parse_IPv6address();
  12202. }
  12203. if (result2 !== null) {
  12204. result0 = [result0, result1, result2];
  12205. } else {
  12206. result0 = null;
  12207. pos = pos1;
  12208. }
  12209. } else {
  12210. result0 = null;
  12211. pos = pos1;
  12212. }
  12213. } else {
  12214. result0 = null;
  12215. pos = pos1;
  12216. }
  12217. if (result0 !== null) {
  12218. result0 = function (offset, via_received) {
  12219. data.received = via_received;
  12220. }(pos0, result0[2]);
  12221. }
  12222. if (result0 === null) {
  12223. pos = pos0;
  12224. }
  12225. return result0;
  12226. }
  12227. function parse_via_branch() {
  12228. var result0, result1, result2;
  12229. var pos0, pos1;
  12230. pos0 = pos;
  12231. pos1 = pos;
  12232. if (input.substr(pos, 6).toLowerCase() === "branch") {
  12233. result0 = input.substr(pos, 6);
  12234. pos += 6;
  12235. } else {
  12236. result0 = null;
  12237. if (reportFailures === 0) {
  12238. matchFailed("\"branch\"");
  12239. }
  12240. }
  12241. if (result0 !== null) {
  12242. result1 = parse_EQUAL();
  12243. if (result1 !== null) {
  12244. result2 = parse_token();
  12245. if (result2 !== null) {
  12246. result0 = [result0, result1, result2];
  12247. } else {
  12248. result0 = null;
  12249. pos = pos1;
  12250. }
  12251. } else {
  12252. result0 = null;
  12253. pos = pos1;
  12254. }
  12255. } else {
  12256. result0 = null;
  12257. pos = pos1;
  12258. }
  12259. if (result0 !== null) {
  12260. result0 = function (offset, via_branch) {
  12261. data.branch = via_branch;
  12262. }(pos0, result0[2]);
  12263. }
  12264. if (result0 === null) {
  12265. pos = pos0;
  12266. }
  12267. return result0;
  12268. }
  12269. function parse_response_port() {
  12270. var result0, result1, result2;
  12271. var pos0, pos1;
  12272. pos0 = pos;
  12273. if (input.substr(pos, 5).toLowerCase() === "rport") {
  12274. result0 = input.substr(pos, 5);
  12275. pos += 5;
  12276. } else {
  12277. result0 = null;
  12278. if (reportFailures === 0) {
  12279. matchFailed("\"rport\"");
  12280. }
  12281. }
  12282. if (result0 !== null) {
  12283. pos1 = pos;
  12284. result1 = parse_EQUAL();
  12285. if (result1 !== null) {
  12286. result2 = parse_rport();
  12287. if (result2 !== null) {
  12288. result1 = [result1, result2];
  12289. } else {
  12290. result1 = null;
  12291. pos = pos1;
  12292. }
  12293. } else {
  12294. result1 = null;
  12295. pos = pos1;
  12296. }
  12297. result1 = result1 !== null ? result1 : "";
  12298. if (result1 !== null) {
  12299. result0 = [result0, result1];
  12300. } else {
  12301. result0 = null;
  12302. pos = pos0;
  12303. }
  12304. } else {
  12305. result0 = null;
  12306. pos = pos0;
  12307. }
  12308. return result0;
  12309. }
  12310. function parse_rport() {
  12311. var result0, result1, result2, result3, result4;
  12312. var pos0, pos1;
  12313. pos0 = pos;
  12314. pos1 = pos;
  12315. result0 = parse_DIGIT();
  12316. result0 = result0 !== null ? result0 : "";
  12317. if (result0 !== null) {
  12318. result1 = parse_DIGIT();
  12319. result1 = result1 !== null ? result1 : "";
  12320. if (result1 !== null) {
  12321. result2 = parse_DIGIT();
  12322. result2 = result2 !== null ? result2 : "";
  12323. if (result2 !== null) {
  12324. result3 = parse_DIGIT();
  12325. result3 = result3 !== null ? result3 : "";
  12326. if (result3 !== null) {
  12327. result4 = parse_DIGIT();
  12328. result4 = result4 !== null ? result4 : "";
  12329. if (result4 !== null) {
  12330. result0 = [result0, result1, result2, result3, result4];
  12331. } else {
  12332. result0 = null;
  12333. pos = pos1;
  12334. }
  12335. } else {
  12336. result0 = null;
  12337. pos = pos1;
  12338. }
  12339. } else {
  12340. result0 = null;
  12341. pos = pos1;
  12342. }
  12343. } else {
  12344. result0 = null;
  12345. pos = pos1;
  12346. }
  12347. } else {
  12348. result0 = null;
  12349. pos = pos1;
  12350. }
  12351. if (result0 !== null) {
  12352. result0 = function (offset, rport) {
  12353. data.rport = parseInt(rport.join(''));
  12354. }(pos0, result0);
  12355. }
  12356. if (result0 === null) {
  12357. pos = pos0;
  12358. }
  12359. return result0;
  12360. }
  12361. function parse_sent_protocol() {
  12362. var result0, result1, result2, result3, result4;
  12363. var pos0;
  12364. pos0 = pos;
  12365. result0 = parse_protocol_name();
  12366. if (result0 !== null) {
  12367. result1 = parse_SLASH();
  12368. if (result1 !== null) {
  12369. result2 = parse_token();
  12370. if (result2 !== null) {
  12371. result3 = parse_SLASH();
  12372. if (result3 !== null) {
  12373. result4 = parse_transport();
  12374. if (result4 !== null) {
  12375. result0 = [result0, result1, result2, result3, result4];
  12376. } else {
  12377. result0 = null;
  12378. pos = pos0;
  12379. }
  12380. } else {
  12381. result0 = null;
  12382. pos = pos0;
  12383. }
  12384. } else {
  12385. result0 = null;
  12386. pos = pos0;
  12387. }
  12388. } else {
  12389. result0 = null;
  12390. pos = pos0;
  12391. }
  12392. } else {
  12393. result0 = null;
  12394. pos = pos0;
  12395. }
  12396. return result0;
  12397. }
  12398. function parse_protocol_name() {
  12399. var result0;
  12400. var pos0;
  12401. pos0 = pos;
  12402. if (input.substr(pos, 3).toLowerCase() === "sip") {
  12403. result0 = input.substr(pos, 3);
  12404. pos += 3;
  12405. } else {
  12406. result0 = null;
  12407. if (reportFailures === 0) {
  12408. matchFailed("\"SIP\"");
  12409. }
  12410. }
  12411. if (result0 === null) {
  12412. result0 = parse_token();
  12413. }
  12414. if (result0 !== null) {
  12415. result0 = function (offset, via_protocol) {
  12416. data.protocol = via_protocol;
  12417. }(pos0, result0);
  12418. }
  12419. if (result0 === null) {
  12420. pos = pos0;
  12421. }
  12422. return result0;
  12423. }
  12424. function parse_transport() {
  12425. var result0;
  12426. var pos0;
  12427. pos0 = pos;
  12428. if (input.substr(pos, 3).toLowerCase() === "udp") {
  12429. result0 = input.substr(pos, 3);
  12430. pos += 3;
  12431. } else {
  12432. result0 = null;
  12433. if (reportFailures === 0) {
  12434. matchFailed("\"UDP\"");
  12435. }
  12436. }
  12437. if (result0 === null) {
  12438. if (input.substr(pos, 3).toLowerCase() === "tcp") {
  12439. result0 = input.substr(pos, 3);
  12440. pos += 3;
  12441. } else {
  12442. result0 = null;
  12443. if (reportFailures === 0) {
  12444. matchFailed("\"TCP\"");
  12445. }
  12446. }
  12447. if (result0 === null) {
  12448. if (input.substr(pos, 3).toLowerCase() === "tls") {
  12449. result0 = input.substr(pos, 3);
  12450. pos += 3;
  12451. } else {
  12452. result0 = null;
  12453. if (reportFailures === 0) {
  12454. matchFailed("\"TLS\"");
  12455. }
  12456. }
  12457. if (result0 === null) {
  12458. if (input.substr(pos, 4).toLowerCase() === "sctp") {
  12459. result0 = input.substr(pos, 4);
  12460. pos += 4;
  12461. } else {
  12462. result0 = null;
  12463. if (reportFailures === 0) {
  12464. matchFailed("\"SCTP\"");
  12465. }
  12466. }
  12467. if (result0 === null) {
  12468. result0 = parse_token();
  12469. }
  12470. }
  12471. }
  12472. }
  12473. if (result0 !== null) {
  12474. result0 = function (offset, via_transport) {
  12475. data.transport = via_transport;
  12476. }(pos0, result0);
  12477. }
  12478. if (result0 === null) {
  12479. pos = pos0;
  12480. }
  12481. return result0;
  12482. }
  12483. function parse_sent_by() {
  12484. var result0, result1, result2;
  12485. var pos0, pos1;
  12486. pos0 = pos;
  12487. result0 = parse_via_host();
  12488. if (result0 !== null) {
  12489. pos1 = pos;
  12490. result1 = parse_COLON();
  12491. if (result1 !== null) {
  12492. result2 = parse_via_port();
  12493. if (result2 !== null) {
  12494. result1 = [result1, result2];
  12495. } else {
  12496. result1 = null;
  12497. pos = pos1;
  12498. }
  12499. } else {
  12500. result1 = null;
  12501. pos = pos1;
  12502. }
  12503. result1 = result1 !== null ? result1 : "";
  12504. if (result1 !== null) {
  12505. result0 = [result0, result1];
  12506. } else {
  12507. result0 = null;
  12508. pos = pos0;
  12509. }
  12510. } else {
  12511. result0 = null;
  12512. pos = pos0;
  12513. }
  12514. return result0;
  12515. }
  12516. function parse_via_host() {
  12517. var result0;
  12518. var pos0;
  12519. pos0 = pos;
  12520. result0 = parse_IPv4address();
  12521. if (result0 === null) {
  12522. result0 = parse_IPv6reference();
  12523. if (result0 === null) {
  12524. result0 = parse_hostname();
  12525. }
  12526. }
  12527. if (result0 !== null) {
  12528. result0 = function (offset) {
  12529. data.host = input.substring(pos, offset);
  12530. }(pos0);
  12531. }
  12532. if (result0 === null) {
  12533. pos = pos0;
  12534. }
  12535. return result0;
  12536. }
  12537. function parse_via_port() {
  12538. var result0, result1, result2, result3, result4;
  12539. var pos0, pos1;
  12540. pos0 = pos;
  12541. pos1 = pos;
  12542. result0 = parse_DIGIT();
  12543. result0 = result0 !== null ? result0 : "";
  12544. if (result0 !== null) {
  12545. result1 = parse_DIGIT();
  12546. result1 = result1 !== null ? result1 : "";
  12547. if (result1 !== null) {
  12548. result2 = parse_DIGIT();
  12549. result2 = result2 !== null ? result2 : "";
  12550. if (result2 !== null) {
  12551. result3 = parse_DIGIT();
  12552. result3 = result3 !== null ? result3 : "";
  12553. if (result3 !== null) {
  12554. result4 = parse_DIGIT();
  12555. result4 = result4 !== null ? result4 : "";
  12556. if (result4 !== null) {
  12557. result0 = [result0, result1, result2, result3, result4];
  12558. } else {
  12559. result0 = null;
  12560. pos = pos1;
  12561. }
  12562. } else {
  12563. result0 = null;
  12564. pos = pos1;
  12565. }
  12566. } else {
  12567. result0 = null;
  12568. pos = pos1;
  12569. }
  12570. } else {
  12571. result0 = null;
  12572. pos = pos1;
  12573. }
  12574. } else {
  12575. result0 = null;
  12576. pos = pos1;
  12577. }
  12578. if (result0 !== null) {
  12579. result0 = function (offset, via_sent_by_port) {
  12580. data.port = parseInt(via_sent_by_port.join(''));
  12581. }(pos0, result0);
  12582. }
  12583. if (result0 === null) {
  12584. pos = pos0;
  12585. }
  12586. return result0;
  12587. }
  12588. function parse_ttl() {
  12589. var result0, result1, result2;
  12590. var pos0, pos1;
  12591. pos0 = pos;
  12592. pos1 = pos;
  12593. result0 = parse_DIGIT();
  12594. if (result0 !== null) {
  12595. result1 = parse_DIGIT();
  12596. result1 = result1 !== null ? result1 : "";
  12597. if (result1 !== null) {
  12598. result2 = parse_DIGIT();
  12599. result2 = result2 !== null ? result2 : "";
  12600. if (result2 !== null) {
  12601. result0 = [result0, result1, result2];
  12602. } else {
  12603. result0 = null;
  12604. pos = pos1;
  12605. }
  12606. } else {
  12607. result0 = null;
  12608. pos = pos1;
  12609. }
  12610. } else {
  12611. result0 = null;
  12612. pos = pos1;
  12613. }
  12614. if (result0 !== null) {
  12615. result0 = function (offset, ttl) {
  12616. return parseInt(ttl.join(''));
  12617. }(pos0, result0);
  12618. }
  12619. if (result0 === null) {
  12620. pos = pos0;
  12621. }
  12622. return result0;
  12623. }
  12624. function parse_WWW_Authenticate() {
  12625. var result0;
  12626. result0 = parse_challenge();
  12627. return result0;
  12628. }
  12629. function parse_Session_Expires() {
  12630. var result0, result1, result2, result3;
  12631. var pos0, pos1;
  12632. pos0 = pos;
  12633. result0 = parse_s_e_expires();
  12634. if (result0 !== null) {
  12635. result1 = [];
  12636. pos1 = pos;
  12637. result2 = parse_SEMI();
  12638. if (result2 !== null) {
  12639. result3 = parse_s_e_params();
  12640. if (result3 !== null) {
  12641. result2 = [result2, result3];
  12642. } else {
  12643. result2 = null;
  12644. pos = pos1;
  12645. }
  12646. } else {
  12647. result2 = null;
  12648. pos = pos1;
  12649. }
  12650. while (result2 !== null) {
  12651. result1.push(result2);
  12652. pos1 = pos;
  12653. result2 = parse_SEMI();
  12654. if (result2 !== null) {
  12655. result3 = parse_s_e_params();
  12656. if (result3 !== null) {
  12657. result2 = [result2, result3];
  12658. } else {
  12659. result2 = null;
  12660. pos = pos1;
  12661. }
  12662. } else {
  12663. result2 = null;
  12664. pos = pos1;
  12665. }
  12666. }
  12667. if (result1 !== null) {
  12668. result0 = [result0, result1];
  12669. } else {
  12670. result0 = null;
  12671. pos = pos0;
  12672. }
  12673. } else {
  12674. result0 = null;
  12675. pos = pos0;
  12676. }
  12677. return result0;
  12678. }
  12679. function parse_s_e_expires() {
  12680. var result0;
  12681. var pos0;
  12682. pos0 = pos;
  12683. result0 = parse_delta_seconds();
  12684. if (result0 !== null) {
  12685. result0 = function (offset, expires) {
  12686. data.expires = expires;
  12687. }(pos0, result0);
  12688. }
  12689. if (result0 === null) {
  12690. pos = pos0;
  12691. }
  12692. return result0;
  12693. }
  12694. function parse_s_e_params() {
  12695. var result0;
  12696. result0 = parse_s_e_refresher();
  12697. if (result0 === null) {
  12698. result0 = parse_generic_param();
  12699. }
  12700. return result0;
  12701. }
  12702. function parse_s_e_refresher() {
  12703. var result0, result1, result2;
  12704. var pos0, pos1;
  12705. pos0 = pos;
  12706. pos1 = pos;
  12707. if (input.substr(pos, 9).toLowerCase() === "refresher") {
  12708. result0 = input.substr(pos, 9);
  12709. pos += 9;
  12710. } else {
  12711. result0 = null;
  12712. if (reportFailures === 0) {
  12713. matchFailed("\"refresher\"");
  12714. }
  12715. }
  12716. if (result0 !== null) {
  12717. result1 = parse_EQUAL();
  12718. if (result1 !== null) {
  12719. if (input.substr(pos, 3).toLowerCase() === "uac") {
  12720. result2 = input.substr(pos, 3);
  12721. pos += 3;
  12722. } else {
  12723. result2 = null;
  12724. if (reportFailures === 0) {
  12725. matchFailed("\"uac\"");
  12726. }
  12727. }
  12728. if (result2 === null) {
  12729. if (input.substr(pos, 3).toLowerCase() === "uas") {
  12730. result2 = input.substr(pos, 3);
  12731. pos += 3;
  12732. } else {
  12733. result2 = null;
  12734. if (reportFailures === 0) {
  12735. matchFailed("\"uas\"");
  12736. }
  12737. }
  12738. }
  12739. if (result2 !== null) {
  12740. result0 = [result0, result1, result2];
  12741. } else {
  12742. result0 = null;
  12743. pos = pos1;
  12744. }
  12745. } else {
  12746. result0 = null;
  12747. pos = pos1;
  12748. }
  12749. } else {
  12750. result0 = null;
  12751. pos = pos1;
  12752. }
  12753. if (result0 !== null) {
  12754. result0 = function (offset, s_e_refresher_value) {
  12755. data.refresher = s_e_refresher_value.toLowerCase();
  12756. }(pos0, result0[2]);
  12757. }
  12758. if (result0 === null) {
  12759. pos = pos0;
  12760. }
  12761. return result0;
  12762. }
  12763. function parse_extension_header() {
  12764. var result0, result1, result2;
  12765. var pos0;
  12766. pos0 = pos;
  12767. result0 = parse_token();
  12768. if (result0 !== null) {
  12769. result1 = parse_HCOLON();
  12770. if (result1 !== null) {
  12771. result2 = parse_header_value();
  12772. if (result2 !== null) {
  12773. result0 = [result0, result1, result2];
  12774. } else {
  12775. result0 = null;
  12776. pos = pos0;
  12777. }
  12778. } else {
  12779. result0 = null;
  12780. pos = pos0;
  12781. }
  12782. } else {
  12783. result0 = null;
  12784. pos = pos0;
  12785. }
  12786. return result0;
  12787. }
  12788. function parse_header_value() {
  12789. var result0, result1;
  12790. result0 = [];
  12791. result1 = parse_TEXT_UTF8char();
  12792. if (result1 === null) {
  12793. result1 = parse_UTF8_CONT();
  12794. if (result1 === null) {
  12795. result1 = parse_LWS();
  12796. }
  12797. }
  12798. while (result1 !== null) {
  12799. result0.push(result1);
  12800. result1 = parse_TEXT_UTF8char();
  12801. if (result1 === null) {
  12802. result1 = parse_UTF8_CONT();
  12803. if (result1 === null) {
  12804. result1 = parse_LWS();
  12805. }
  12806. }
  12807. }
  12808. return result0;
  12809. }
  12810. function parse_message_body() {
  12811. var result0, result1;
  12812. result0 = [];
  12813. result1 = parse_OCTET();
  12814. while (result1 !== null) {
  12815. result0.push(result1);
  12816. result1 = parse_OCTET();
  12817. }
  12818. return result0;
  12819. }
  12820. function parse_uuid_URI() {
  12821. var result0, result1;
  12822. var pos0;
  12823. pos0 = pos;
  12824. if (input.substr(pos, 5) === "uuid:") {
  12825. result0 = "uuid:";
  12826. pos += 5;
  12827. } else {
  12828. result0 = null;
  12829. if (reportFailures === 0) {
  12830. matchFailed("\"uuid:\"");
  12831. }
  12832. }
  12833. if (result0 !== null) {
  12834. result1 = parse_uuid();
  12835. if (result1 !== null) {
  12836. result0 = [result0, result1];
  12837. } else {
  12838. result0 = null;
  12839. pos = pos0;
  12840. }
  12841. } else {
  12842. result0 = null;
  12843. pos = pos0;
  12844. }
  12845. return result0;
  12846. }
  12847. function parse_uuid() {
  12848. var result0, result1, result2, result3, result4, result5, result6, result7, result8;
  12849. var pos0, pos1;
  12850. pos0 = pos;
  12851. pos1 = pos;
  12852. result0 = parse_hex8();
  12853. if (result0 !== null) {
  12854. if (input.charCodeAt(pos) === 45) {
  12855. result1 = "-";
  12856. pos++;
  12857. } else {
  12858. result1 = null;
  12859. if (reportFailures === 0) {
  12860. matchFailed("\"-\"");
  12861. }
  12862. }
  12863. if (result1 !== null) {
  12864. result2 = parse_hex4();
  12865. if (result2 !== null) {
  12866. if (input.charCodeAt(pos) === 45) {
  12867. result3 = "-";
  12868. pos++;
  12869. } else {
  12870. result3 = null;
  12871. if (reportFailures === 0) {
  12872. matchFailed("\"-\"");
  12873. }
  12874. }
  12875. if (result3 !== null) {
  12876. result4 = parse_hex4();
  12877. if (result4 !== null) {
  12878. if (input.charCodeAt(pos) === 45) {
  12879. result5 = "-";
  12880. pos++;
  12881. } else {
  12882. result5 = null;
  12883. if (reportFailures === 0) {
  12884. matchFailed("\"-\"");
  12885. }
  12886. }
  12887. if (result5 !== null) {
  12888. result6 = parse_hex4();
  12889. if (result6 !== null) {
  12890. if (input.charCodeAt(pos) === 45) {
  12891. result7 = "-";
  12892. pos++;
  12893. } else {
  12894. result7 = null;
  12895. if (reportFailures === 0) {
  12896. matchFailed("\"-\"");
  12897. }
  12898. }
  12899. if (result7 !== null) {
  12900. result8 = parse_hex12();
  12901. if (result8 !== null) {
  12902. result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
  12903. } else {
  12904. result0 = null;
  12905. pos = pos1;
  12906. }
  12907. } else {
  12908. result0 = null;
  12909. pos = pos1;
  12910. }
  12911. } else {
  12912. result0 = null;
  12913. pos = pos1;
  12914. }
  12915. } else {
  12916. result0 = null;
  12917. pos = pos1;
  12918. }
  12919. } else {
  12920. result0 = null;
  12921. pos = pos1;
  12922. }
  12923. } else {
  12924. result0 = null;
  12925. pos = pos1;
  12926. }
  12927. } else {
  12928. result0 = null;
  12929. pos = pos1;
  12930. }
  12931. } else {
  12932. result0 = null;
  12933. pos = pos1;
  12934. }
  12935. } else {
  12936. result0 = null;
  12937. pos = pos1;
  12938. }
  12939. if (result0 !== null) {
  12940. result0 = function (offset, uuid) {
  12941. data = input.substring(pos + 5, offset);
  12942. }(pos0, result0[0]);
  12943. }
  12944. if (result0 === null) {
  12945. pos = pos0;
  12946. }
  12947. return result0;
  12948. }
  12949. function parse_hex4() {
  12950. var result0, result1, result2, result3;
  12951. var pos0;
  12952. pos0 = pos;
  12953. result0 = parse_HEXDIG();
  12954. if (result0 !== null) {
  12955. result1 = parse_HEXDIG();
  12956. if (result1 !== null) {
  12957. result2 = parse_HEXDIG();
  12958. if (result2 !== null) {
  12959. result3 = parse_HEXDIG();
  12960. if (result3 !== null) {
  12961. result0 = [result0, result1, result2, result3];
  12962. } else {
  12963. result0 = null;
  12964. pos = pos0;
  12965. }
  12966. } else {
  12967. result0 = null;
  12968. pos = pos0;
  12969. }
  12970. } else {
  12971. result0 = null;
  12972. pos = pos0;
  12973. }
  12974. } else {
  12975. result0 = null;
  12976. pos = pos0;
  12977. }
  12978. return result0;
  12979. }
  12980. function parse_hex8() {
  12981. var result0, result1;
  12982. var pos0;
  12983. pos0 = pos;
  12984. result0 = parse_hex4();
  12985. if (result0 !== null) {
  12986. result1 = parse_hex4();
  12987. if (result1 !== null) {
  12988. result0 = [result0, result1];
  12989. } else {
  12990. result0 = null;
  12991. pos = pos0;
  12992. }
  12993. } else {
  12994. result0 = null;
  12995. pos = pos0;
  12996. }
  12997. return result0;
  12998. }
  12999. function parse_hex12() {
  13000. var result0, result1, result2;
  13001. var pos0;
  13002. pos0 = pos;
  13003. result0 = parse_hex4();
  13004. if (result0 !== null) {
  13005. result1 = parse_hex4();
  13006. if (result1 !== null) {
  13007. result2 = parse_hex4();
  13008. if (result2 !== null) {
  13009. result0 = [result0, result1, result2];
  13010. } else {
  13011. result0 = null;
  13012. pos = pos0;
  13013. }
  13014. } else {
  13015. result0 = null;
  13016. pos = pos0;
  13017. }
  13018. } else {
  13019. result0 = null;
  13020. pos = pos0;
  13021. }
  13022. return result0;
  13023. }
  13024. function parse_Refer_To() {
  13025. var result0, result1, result2, result3;
  13026. var pos0, pos1, pos2;
  13027. pos0 = pos;
  13028. pos1 = pos;
  13029. result0 = parse_SIP_URI_noparams();
  13030. if (result0 === null) {
  13031. result0 = parse_name_addr();
  13032. }
  13033. if (result0 !== null) {
  13034. result1 = [];
  13035. pos2 = pos;
  13036. result2 = parse_SEMI();
  13037. if (result2 !== null) {
  13038. result3 = parse_generic_param();
  13039. if (result3 !== null) {
  13040. result2 = [result2, result3];
  13041. } else {
  13042. result2 = null;
  13043. pos = pos2;
  13044. }
  13045. } else {
  13046. result2 = null;
  13047. pos = pos2;
  13048. }
  13049. while (result2 !== null) {
  13050. result1.push(result2);
  13051. pos2 = pos;
  13052. result2 = parse_SEMI();
  13053. if (result2 !== null) {
  13054. result3 = parse_generic_param();
  13055. if (result3 !== null) {
  13056. result2 = [result2, result3];
  13057. } else {
  13058. result2 = null;
  13059. pos = pos2;
  13060. }
  13061. } else {
  13062. result2 = null;
  13063. pos = pos2;
  13064. }
  13065. }
  13066. if (result1 !== null) {
  13067. result0 = [result0, result1];
  13068. } else {
  13069. result0 = null;
  13070. pos = pos1;
  13071. }
  13072. } else {
  13073. result0 = null;
  13074. pos = pos1;
  13075. }
  13076. if (result0 !== null) {
  13077. result0 = function (offset) {
  13078. try {
  13079. data = new NameAddrHeader(data.uri, data.display_name, data.params);
  13080. } catch (e) {
  13081. data = -1;
  13082. }
  13083. }(pos0);
  13084. }
  13085. if (result0 === null) {
  13086. pos = pos0;
  13087. }
  13088. return result0;
  13089. }
  13090. function parse_Replaces() {
  13091. var result0, result1, result2, result3;
  13092. var pos0, pos1;
  13093. pos0 = pos;
  13094. result0 = parse_call_id();
  13095. if (result0 !== null) {
  13096. result1 = [];
  13097. pos1 = pos;
  13098. result2 = parse_SEMI();
  13099. if (result2 !== null) {
  13100. result3 = parse_replaces_param();
  13101. if (result3 !== null) {
  13102. result2 = [result2, result3];
  13103. } else {
  13104. result2 = null;
  13105. pos = pos1;
  13106. }
  13107. } else {
  13108. result2 = null;
  13109. pos = pos1;
  13110. }
  13111. while (result2 !== null) {
  13112. result1.push(result2);
  13113. pos1 = pos;
  13114. result2 = parse_SEMI();
  13115. if (result2 !== null) {
  13116. result3 = parse_replaces_param();
  13117. if (result3 !== null) {
  13118. result2 = [result2, result3];
  13119. } else {
  13120. result2 = null;
  13121. pos = pos1;
  13122. }
  13123. } else {
  13124. result2 = null;
  13125. pos = pos1;
  13126. }
  13127. }
  13128. if (result1 !== null) {
  13129. result0 = [result0, result1];
  13130. } else {
  13131. result0 = null;
  13132. pos = pos0;
  13133. }
  13134. } else {
  13135. result0 = null;
  13136. pos = pos0;
  13137. }
  13138. return result0;
  13139. }
  13140. function parse_call_id() {
  13141. var result0, result1, result2;
  13142. var pos0, pos1, pos2;
  13143. pos0 = pos;
  13144. pos1 = pos;
  13145. result0 = parse_word();
  13146. if (result0 !== null) {
  13147. pos2 = pos;
  13148. if (input.charCodeAt(pos) === 64) {
  13149. result1 = "@";
  13150. pos++;
  13151. } else {
  13152. result1 = null;
  13153. if (reportFailures === 0) {
  13154. matchFailed("\"@\"");
  13155. }
  13156. }
  13157. if (result1 !== null) {
  13158. result2 = parse_word();
  13159. if (result2 !== null) {
  13160. result1 = [result1, result2];
  13161. } else {
  13162. result1 = null;
  13163. pos = pos2;
  13164. }
  13165. } else {
  13166. result1 = null;
  13167. pos = pos2;
  13168. }
  13169. result1 = result1 !== null ? result1 : "";
  13170. if (result1 !== null) {
  13171. result0 = [result0, result1];
  13172. } else {
  13173. result0 = null;
  13174. pos = pos1;
  13175. }
  13176. } else {
  13177. result0 = null;
  13178. pos = pos1;
  13179. }
  13180. if (result0 !== null) {
  13181. result0 = function (offset) {
  13182. data.call_id = input.substring(pos, offset);
  13183. }(pos0);
  13184. }
  13185. if (result0 === null) {
  13186. pos = pos0;
  13187. }
  13188. return result0;
  13189. }
  13190. function parse_replaces_param() {
  13191. var result0;
  13192. result0 = parse_to_tag();
  13193. if (result0 === null) {
  13194. result0 = parse_from_tag();
  13195. if (result0 === null) {
  13196. result0 = parse_early_flag();
  13197. if (result0 === null) {
  13198. result0 = parse_generic_param();
  13199. }
  13200. }
  13201. }
  13202. return result0;
  13203. }
  13204. function parse_to_tag() {
  13205. var result0, result1, result2;
  13206. var pos0, pos1;
  13207. pos0 = pos;
  13208. pos1 = pos;
  13209. if (input.substr(pos, 6) === "to-tag") {
  13210. result0 = "to-tag";
  13211. pos += 6;
  13212. } else {
  13213. result0 = null;
  13214. if (reportFailures === 0) {
  13215. matchFailed("\"to-tag\"");
  13216. }
  13217. }
  13218. if (result0 !== null) {
  13219. result1 = parse_EQUAL();
  13220. if (result1 !== null) {
  13221. result2 = parse_token();
  13222. if (result2 !== null) {
  13223. result0 = [result0, result1, result2];
  13224. } else {
  13225. result0 = null;
  13226. pos = pos1;
  13227. }
  13228. } else {
  13229. result0 = null;
  13230. pos = pos1;
  13231. }
  13232. } else {
  13233. result0 = null;
  13234. pos = pos1;
  13235. }
  13236. if (result0 !== null) {
  13237. result0 = function (offset, to_tag) {
  13238. data.to_tag = to_tag;
  13239. }(pos0, result0[2]);
  13240. }
  13241. if (result0 === null) {
  13242. pos = pos0;
  13243. }
  13244. return result0;
  13245. }
  13246. function parse_from_tag() {
  13247. var result0, result1, result2;
  13248. var pos0, pos1;
  13249. pos0 = pos;
  13250. pos1 = pos;
  13251. if (input.substr(pos, 8) === "from-tag") {
  13252. result0 = "from-tag";
  13253. pos += 8;
  13254. } else {
  13255. result0 = null;
  13256. if (reportFailures === 0) {
  13257. matchFailed("\"from-tag\"");
  13258. }
  13259. }
  13260. if (result0 !== null) {
  13261. result1 = parse_EQUAL();
  13262. if (result1 !== null) {
  13263. result2 = parse_token();
  13264. if (result2 !== null) {
  13265. result0 = [result0, result1, result2];
  13266. } else {
  13267. result0 = null;
  13268. pos = pos1;
  13269. }
  13270. } else {
  13271. result0 = null;
  13272. pos = pos1;
  13273. }
  13274. } else {
  13275. result0 = null;
  13276. pos = pos1;
  13277. }
  13278. if (result0 !== null) {
  13279. result0 = function (offset, from_tag) {
  13280. data.from_tag = from_tag;
  13281. }(pos0, result0[2]);
  13282. }
  13283. if (result0 === null) {
  13284. pos = pos0;
  13285. }
  13286. return result0;
  13287. }
  13288. function parse_early_flag() {
  13289. var result0;
  13290. var pos0;
  13291. pos0 = pos;
  13292. if (input.substr(pos, 10) === "early-only") {
  13293. result0 = "early-only";
  13294. pos += 10;
  13295. } else {
  13296. result0 = null;
  13297. if (reportFailures === 0) {
  13298. matchFailed("\"early-only\"");
  13299. }
  13300. }
  13301. if (result0 !== null) {
  13302. result0 = function (offset) {
  13303. data.early_only = true;
  13304. }(pos0);
  13305. }
  13306. if (result0 === null) {
  13307. pos = pos0;
  13308. }
  13309. return result0;
  13310. }
  13311. function cleanupExpected(expected) {
  13312. expected.sort();
  13313. var lastExpected = null;
  13314. var cleanExpected = [];
  13315. for (var i = 0; i < expected.length; i++) {
  13316. if (expected[i] !== lastExpected) {
  13317. cleanExpected.push(expected[i]);
  13318. lastExpected = expected[i];
  13319. }
  13320. }
  13321. return cleanExpected;
  13322. }
  13323. function computeErrorPosition() {
  13324. /*
  13325. * The first idea was to use |String.split| to break the input up to the
  13326. * error position along newlines and derive the line and column from
  13327. * there. However IE's |split| implementation is so broken that it was
  13328. * enough to prevent it.
  13329. */
  13330. var line = 1;
  13331. var column = 1;
  13332. var seenCR = false;
  13333. for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
  13334. var ch = input.charAt(i);
  13335. if (ch === "\n") {
  13336. if (!seenCR) {
  13337. line++;
  13338. }
  13339. column = 1;
  13340. seenCR = false;
  13341. } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
  13342. line++;
  13343. column = 1;
  13344. seenCR = true;
  13345. } else {
  13346. column++;
  13347. seenCR = false;
  13348. }
  13349. }
  13350. return {
  13351. line: line,
  13352. column: column
  13353. };
  13354. }
  13355. var URI = require('./URI');
  13356. var NameAddrHeader = require('./NameAddrHeader');
  13357. var data = {};
  13358. var result = parseFunctions[startRule]();
  13359. /*
  13360. * The parser is now in one of the following three states:
  13361. *
  13362. * 1. The parser successfully parsed the whole input.
  13363. *
  13364. * - |result !== null|
  13365. * - |pos === input.length|
  13366. * - |rightmostFailuresExpected| may or may not contain something
  13367. *
  13368. * 2. The parser successfully parsed only a part of the input.
  13369. *
  13370. * - |result !== null|
  13371. * - |pos < input.length|
  13372. * - |rightmostFailuresExpected| may or may not contain something
  13373. *
  13374. * 3. The parser did not successfully parse any part of the input.
  13375. *
  13376. * - |result === null|
  13377. * - |pos === 0|
  13378. * - |rightmostFailuresExpected| contains at least one failure
  13379. *
  13380. * All code following this comment (including called functions) must
  13381. * handle these states.
  13382. */
  13383. if (result === null || pos !== input.length) {
  13384. var offset = Math.max(pos, rightmostFailuresPos);
  13385. var found = offset < input.length ? input.charAt(offset) : null;
  13386. var errorPosition = computeErrorPosition();
  13387. new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
  13388. return -1;
  13389. }
  13390. return data;
  13391. },
  13392. /* Returns the parser source code. */
  13393. toSource: function toSource() {
  13394. return this._source;
  13395. }
  13396. };
  13397. /* Thrown when a parser encounters a syntax error. */
  13398. result.SyntaxError = function (expected, found, offset, line, column) {
  13399. function buildMessage(expected, found) {
  13400. var expectedHumanized, foundHumanized;
  13401. switch (expected.length) {
  13402. case 0:
  13403. expectedHumanized = "end of input";
  13404. break;
  13405. case 1:
  13406. expectedHumanized = expected[0];
  13407. break;
  13408. default:
  13409. expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
  13410. }
  13411. foundHumanized = found ? quote(found) : "end of input";
  13412. return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
  13413. }
  13414. this.name = "SyntaxError";
  13415. this.expected = expected;
  13416. this.found = found;
  13417. this.message = buildMessage(expected, found);
  13418. this.offset = offset;
  13419. this.line = line;
  13420. this.column = column;
  13421. };
  13422. result.SyntaxError.prototype = Error.prototype;
  13423. return result;
  13424. }();
  13425. },{"./NameAddrHeader":11,"./URI":27}],8:[function(require,module,exports){
  13426. "use strict";
  13427. var pkg = require('../package.json');
  13428. var C = require('./Constants');
  13429. var Exceptions = require('./Exceptions');
  13430. var Utils = require('./Utils');
  13431. var UA = require('./UA');
  13432. var URI = require('./URI');
  13433. var NameAddrHeader = require('./NameAddrHeader');
  13434. var Grammar = require('./Grammar');
  13435. var WebSocketInterface = require('./WebSocketInterface');
  13436. var debug = require('debug')('JsSIP');
  13437. debug('version %s', pkg.version);
  13438. /**
  13439. * Expose the JsSIP module.
  13440. */
  13441. module.exports = {
  13442. C: C,
  13443. Exceptions: Exceptions,
  13444. Utils: Utils,
  13445. UA: UA,
  13446. URI: URI,
  13447. NameAddrHeader: NameAddrHeader,
  13448. WebSocketInterface: WebSocketInterface,
  13449. Grammar: Grammar,
  13450. // Expose the debug module.
  13451. debug: require('debug'),
  13452. get name() {
  13453. return pkg.title;
  13454. },
  13455. get version() {
  13456. return pkg.version;
  13457. }
  13458. };
  13459. },{"../package.json":40,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":11,"./UA":26,"./URI":27,"./Utils":28,"./WebSocketInterface":29,"debug":32}],9:[function(require,module,exports){
  13460. "use strict";
  13461. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13462. 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); } }
  13463. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13464. var debug = require('debug');
  13465. var APP_NAME = 'JsSIP';
  13466. module.exports = /*#__PURE__*/function () {
  13467. function Logger(prefix) {
  13468. _classCallCheck(this, Logger);
  13469. if (prefix) {
  13470. this._debug = debug["default"]("".concat(APP_NAME, ":").concat(prefix));
  13471. this._warn = debug["default"]("".concat(APP_NAME, ":WARN:").concat(prefix));
  13472. this._error = debug["default"]("".concat(APP_NAME, ":ERROR:").concat(prefix));
  13473. } else {
  13474. this._debug = debug["default"](APP_NAME);
  13475. this._warn = debug["default"]("".concat(APP_NAME, ":WARN"));
  13476. this._error = debug["default"]("".concat(APP_NAME, ":ERROR"));
  13477. }
  13478. /* eslint-disable no-console */
  13479. this._debug.log = console.info.bind(console);
  13480. this._warn.log = console.warn.bind(console);
  13481. this._error.log = console.error.bind(console);
  13482. /* eslint-enable no-console */
  13483. }
  13484. _createClass(Logger, [{
  13485. key: "debug",
  13486. get: function get() {
  13487. return this._debug;
  13488. }
  13489. }, {
  13490. key: "warn",
  13491. get: function get() {
  13492. return this._warn;
  13493. }
  13494. }, {
  13495. key: "error",
  13496. get: function get() {
  13497. return this._error;
  13498. }
  13499. }]);
  13500. return Logger;
  13501. }();
  13502. },{"debug":32}],10:[function(require,module,exports){
  13503. "use strict";
  13504. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  13505. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13506. 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); } }
  13507. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13508. 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); }
  13509. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13510. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13511. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13512. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13513. 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; } }
  13514. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13515. var EventEmitter = require('events').EventEmitter;
  13516. var Logger = require('./Logger');
  13517. var JsSIP_C = require('./Constants');
  13518. var SIPMessage = require('./SIPMessage');
  13519. var Utils = require('./Utils');
  13520. var RequestSender = require('./RequestSender');
  13521. var Exceptions = require('./Exceptions');
  13522. var URI = require('./URI');
  13523. var logger = new Logger('Message');
  13524. module.exports = /*#__PURE__*/function (_EventEmitter) {
  13525. _inherits(Message, _EventEmitter);
  13526. var _super = _createSuper(Message);
  13527. function Message(ua) {
  13528. var _this;
  13529. _classCallCheck(this, Message);
  13530. _this = _super.call(this);
  13531. _this._ua = ua;
  13532. _this._request = null;
  13533. _this._closed = false;
  13534. _this._direction = null;
  13535. _this._local_identity = null;
  13536. _this._remote_identity = null; // Whether an incoming message has been replied.
  13537. _this._is_replied = false; // Custom message empty object for high level use.
  13538. _this._data = {};
  13539. return _this;
  13540. }
  13541. _createClass(Message, [{
  13542. key: "send",
  13543. value: function send(target, body) {
  13544. var _this2 = this;
  13545. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  13546. var originalTarget = target;
  13547. if (target === undefined || body === undefined) {
  13548. throw new TypeError('Not enough arguments');
  13549. } // Check target validity.
  13550. target = this._ua.normalizeTarget(target);
  13551. if (!target) {
  13552. throw new TypeError("Invalid target: ".concat(originalTarget));
  13553. } // Get call options.
  13554. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13555. var eventHandlers = Utils.cloneObject(options.eventHandlers);
  13556. var contentType = options.contentType || 'text/plain';
  13557. var requestParams = {};
  13558. if (options.fromUserName) {
  13559. requestParams.from_uri = new URI('sip', options.fromUserName, this._ua.configuration.uri.host);
  13560. extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()));
  13561. }
  13562. if (options.fromDisplayName) {
  13563. requestParams.from_display_name = options.fromDisplayName;
  13564. } // Set event handlers.
  13565. for (var event in eventHandlers) {
  13566. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  13567. this.on(event, eventHandlers[event]);
  13568. }
  13569. }
  13570. extraHeaders.push("Content-Type: ".concat(contentType));
  13571. this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, requestParams, extraHeaders);
  13572. if (body) {
  13573. this._request.body = body;
  13574. }
  13575. var request_sender = new RequestSender(this._ua, this._request, {
  13576. onRequestTimeout: function onRequestTimeout() {
  13577. _this2._onRequestTimeout();
  13578. },
  13579. onTransportError: function onTransportError() {
  13580. _this2._onTransportError();
  13581. },
  13582. onReceiveResponse: function onReceiveResponse(response) {
  13583. _this2._receiveResponse(response);
  13584. }
  13585. });
  13586. this._newMessage('local', this._request);
  13587. request_sender.send();
  13588. }
  13589. }, {
  13590. key: "init_incoming",
  13591. value: function init_incoming(request) {
  13592. this._request = request;
  13593. this._newMessage('remote', request); // Reply with a 200 OK if the user didn't reply.
  13594. if (!this._is_replied) {
  13595. this._is_replied = true;
  13596. request.reply(200);
  13597. }
  13598. this._close();
  13599. }
  13600. /**
  13601. * Accept the incoming Message
  13602. * Only valid for incoming Messages
  13603. */
  13604. }, {
  13605. key: "accept",
  13606. value: function accept() {
  13607. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13608. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13609. var body = options.body;
  13610. if (this._direction !== 'incoming') {
  13611. throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message');
  13612. }
  13613. if (this._is_replied) {
  13614. throw new Error('incoming Message already replied');
  13615. }
  13616. this._is_replied = true;
  13617. this._request.reply(200, null, extraHeaders, body);
  13618. }
  13619. /**
  13620. * Reject the incoming Message
  13621. * Only valid for incoming Messages
  13622. */
  13623. }, {
  13624. key: "reject",
  13625. value: function reject() {
  13626. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13627. var status_code = options.status_code || 480;
  13628. var reason_phrase = options.reason_phrase;
  13629. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13630. var body = options.body;
  13631. if (this._direction !== 'incoming') {
  13632. throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message');
  13633. }
  13634. if (this._is_replied) {
  13635. throw new Error('incoming Message already replied');
  13636. }
  13637. if (status_code < 300 || status_code >= 700) {
  13638. throw new TypeError("Invalid status_code: ".concat(status_code));
  13639. }
  13640. this._is_replied = true;
  13641. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  13642. }
  13643. }, {
  13644. key: "_receiveResponse",
  13645. value: function _receiveResponse(response) {
  13646. if (this._closed) {
  13647. return;
  13648. }
  13649. switch (true) {
  13650. case /^1[0-9]{2}$/.test(response.status_code):
  13651. // Ignore provisional responses.
  13652. break;
  13653. case /^2[0-9]{2}$/.test(response.status_code):
  13654. this._succeeded('remote', response);
  13655. break;
  13656. default:
  13657. {
  13658. var cause = Utils.sipErrorCause(response.status_code);
  13659. this._failed('remote', response, cause);
  13660. break;
  13661. }
  13662. }
  13663. }
  13664. }, {
  13665. key: "_onRequestTimeout",
  13666. value: function _onRequestTimeout() {
  13667. if (this._closed) {
  13668. return;
  13669. }
  13670. this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT);
  13671. }
  13672. }, {
  13673. key: "_onTransportError",
  13674. value: function _onTransportError() {
  13675. if (this._closed) {
  13676. return;
  13677. }
  13678. this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  13679. }
  13680. }, {
  13681. key: "_close",
  13682. value: function _close() {
  13683. this._closed = true;
  13684. this._ua.destroyMessage(this);
  13685. }
  13686. /**
  13687. * Internal Callbacks
  13688. */
  13689. }, {
  13690. key: "_newMessage",
  13691. value: function _newMessage(originator, request) {
  13692. if (originator === 'remote') {
  13693. this._direction = 'incoming';
  13694. this._local_identity = request.to;
  13695. this._remote_identity = request.from;
  13696. } else if (originator === 'local') {
  13697. this._direction = 'outgoing';
  13698. this._local_identity = request.from;
  13699. this._remote_identity = request.to;
  13700. }
  13701. this._ua.newMessage(this, {
  13702. originator: originator,
  13703. message: this,
  13704. request: request
  13705. });
  13706. }
  13707. }, {
  13708. key: "_failed",
  13709. value: function _failed(originator, response, cause) {
  13710. logger.debug('MESSAGE failed');
  13711. this._close();
  13712. logger.debug('emit "failed"');
  13713. this.emit('failed', {
  13714. originator: originator,
  13715. response: response || null,
  13716. cause: cause
  13717. });
  13718. }
  13719. }, {
  13720. key: "_succeeded",
  13721. value: function _succeeded(originator, response) {
  13722. logger.debug('MESSAGE succeeded');
  13723. this._close();
  13724. logger.debug('emit "succeeded"');
  13725. this.emit('succeeded', {
  13726. originator: originator,
  13727. response: response
  13728. });
  13729. }
  13730. }, {
  13731. key: "direction",
  13732. get: function get() {
  13733. return this._direction;
  13734. }
  13735. }, {
  13736. key: "local_identity",
  13737. get: function get() {
  13738. return this._local_identity;
  13739. }
  13740. }, {
  13741. key: "remote_identity",
  13742. get: function get() {
  13743. return this._remote_identity;
  13744. }
  13745. }]);
  13746. return Message;
  13747. }(EventEmitter);
  13748. },{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./URI":27,"./Utils":28,"events":31}],11:[function(require,module,exports){
  13749. "use strict";
  13750. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13751. 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); } }
  13752. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13753. var URI = require('./URI');
  13754. var Grammar = require('./Grammar');
  13755. module.exports = /*#__PURE__*/function () {
  13756. _createClass(NameAddrHeader, null, [{
  13757. key: "parse",
  13758. /**
  13759. * Parse the given string and returns a NameAddrHeader instance or undefined if
  13760. * it is an invalid NameAddrHeader.
  13761. */
  13762. value: function parse(name_addr_header) {
  13763. name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header');
  13764. if (name_addr_header !== -1) {
  13765. return name_addr_header;
  13766. } else {
  13767. return undefined;
  13768. }
  13769. }
  13770. }]);
  13771. function NameAddrHeader(uri, display_name, parameters) {
  13772. _classCallCheck(this, NameAddrHeader);
  13773. // Checks.
  13774. if (!uri || !(uri instanceof URI)) {
  13775. throw new TypeError('missing or invalid "uri" parameter');
  13776. } // Initialize parameters.
  13777. this._uri = uri;
  13778. this._parameters = {};
  13779. this.display_name = display_name;
  13780. for (var param in parameters) {
  13781. if (Object.prototype.hasOwnProperty.call(parameters, param)) {
  13782. this.setParam(param, parameters[param]);
  13783. }
  13784. }
  13785. }
  13786. _createClass(NameAddrHeader, [{
  13787. key: "setParam",
  13788. value: function setParam(key, value) {
  13789. if (key) {
  13790. this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
  13791. }
  13792. }
  13793. }, {
  13794. key: "getParam",
  13795. value: function getParam(key) {
  13796. if (key) {
  13797. return this._parameters[key.toLowerCase()];
  13798. }
  13799. }
  13800. }, {
  13801. key: "hasParam",
  13802. value: function hasParam(key) {
  13803. if (key) {
  13804. return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
  13805. }
  13806. }
  13807. }, {
  13808. key: "deleteParam",
  13809. value: function deleteParam(parameter) {
  13810. parameter = parameter.toLowerCase();
  13811. if (this._parameters.hasOwnProperty(parameter)) {
  13812. var value = this._parameters[parameter];
  13813. delete this._parameters[parameter];
  13814. return value;
  13815. }
  13816. }
  13817. }, {
  13818. key: "clearParams",
  13819. value: function clearParams() {
  13820. this._parameters = {};
  13821. }
  13822. }, {
  13823. key: "clone",
  13824. value: function clone() {
  13825. return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters)));
  13826. }
  13827. }, {
  13828. key: "_quote",
  13829. value: function _quote(str) {
  13830. return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
  13831. }
  13832. }, {
  13833. key: "toString",
  13834. value: function toString() {
  13835. var body = this._display_name ? "\"".concat(this._quote(this._display_name), "\" ") : '';
  13836. body += "<".concat(this._uri.toString(), ">");
  13837. for (var parameter in this._parameters) {
  13838. if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
  13839. body += ";".concat(parameter);
  13840. if (this._parameters[parameter] !== null) {
  13841. body += "=".concat(this._parameters[parameter]);
  13842. }
  13843. }
  13844. }
  13845. return body;
  13846. }
  13847. }, {
  13848. key: "uri",
  13849. get: function get() {
  13850. return this._uri;
  13851. }
  13852. }, {
  13853. key: "display_name",
  13854. get: function get() {
  13855. return this._display_name;
  13856. },
  13857. set: function set(value) {
  13858. this._display_name = value === 0 ? '0' : value;
  13859. }
  13860. }]);
  13861. return NameAddrHeader;
  13862. }();
  13863. },{"./Grammar":7,"./URI":27}],12:[function(require,module,exports){
  13864. "use strict";
  13865. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  13866. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13867. 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); } }
  13868. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13869. 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); }
  13870. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13871. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  13872. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  13873. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  13874. 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; } }
  13875. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13876. var EventEmitter = require('events').EventEmitter;
  13877. var Logger = require('./Logger');
  13878. var JsSIP_C = require('./Constants');
  13879. var SIPMessage = require('./SIPMessage');
  13880. var Utils = require('./Utils');
  13881. var RequestSender = require('./RequestSender');
  13882. var Exceptions = require('./Exceptions');
  13883. var logger = new Logger('Options');
  13884. module.exports = /*#__PURE__*/function (_EventEmitter) {
  13885. _inherits(Options, _EventEmitter);
  13886. var _super = _createSuper(Options);
  13887. function Options(ua) {
  13888. var _this;
  13889. _classCallCheck(this, Options);
  13890. _this = _super.call(this);
  13891. _this._ua = ua;
  13892. _this._request = null;
  13893. _this._closed = false;
  13894. _this._direction = null;
  13895. _this._local_identity = null;
  13896. _this._remote_identity = null; // Whether an incoming message has been replied.
  13897. _this._is_replied = false; // Custom message empty object for high level use.
  13898. _this._data = {};
  13899. return _this;
  13900. }
  13901. _createClass(Options, [{
  13902. key: "send",
  13903. value: function send(target, body) {
  13904. var _this2 = this;
  13905. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  13906. var originalTarget = target;
  13907. if (target === undefined) {
  13908. throw new TypeError('A target is required for OPTIONS');
  13909. } // Check target validity.
  13910. target = this._ua.normalizeTarget(target);
  13911. if (!target) {
  13912. throw new TypeError("Invalid target: ".concat(originalTarget));
  13913. } // Get call options.
  13914. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13915. var eventHandlers = Utils.cloneObject(options.eventHandlers);
  13916. var contentType = options.contentType || 'application/sdp'; // Set event handlers.
  13917. for (var event in eventHandlers) {
  13918. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  13919. this.on(event, eventHandlers[event]);
  13920. }
  13921. }
  13922. extraHeaders.push("Content-Type: ".concat(contentType));
  13923. this._request = new SIPMessage.OutgoingRequest(JsSIP_C.OPTIONS, target, this._ua, null, extraHeaders);
  13924. if (body) {
  13925. this._request.body = body;
  13926. }
  13927. var request_sender = new RequestSender(this._ua, this._request, {
  13928. onRequestTimeout: function onRequestTimeout() {
  13929. _this2._onRequestTimeout();
  13930. },
  13931. onTransportError: function onTransportError() {
  13932. _this2._onTransportError();
  13933. },
  13934. onReceiveResponse: function onReceiveResponse(response) {
  13935. _this2._receiveResponse(response);
  13936. }
  13937. });
  13938. this._newOptions('local', this._request);
  13939. request_sender.send();
  13940. }
  13941. }, {
  13942. key: "init_incoming",
  13943. value: function init_incoming(request) {
  13944. this._request = request;
  13945. this._newOptions('remote', request); // Reply with a 200 OK if the user didn't reply.
  13946. if (!this._is_replied) {
  13947. this._is_replied = true;
  13948. request.reply(200);
  13949. }
  13950. this._close();
  13951. }
  13952. /**
  13953. * Accept the incoming Options
  13954. * Only valid for incoming Options
  13955. */
  13956. }, {
  13957. key: "accept",
  13958. value: function accept() {
  13959. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13960. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13961. var body = options.body;
  13962. if (this._direction !== 'incoming') {
  13963. throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Options');
  13964. }
  13965. if (this._is_replied) {
  13966. throw new Error('incoming Options already replied');
  13967. }
  13968. this._is_replied = true;
  13969. this._request.reply(200, null, extraHeaders, body);
  13970. }
  13971. /**
  13972. * Reject the incoming Options
  13973. * Only valid for incoming Options
  13974. */
  13975. }, {
  13976. key: "reject",
  13977. value: function reject() {
  13978. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13979. var status_code = options.status_code || 480;
  13980. var reason_phrase = options.reason_phrase;
  13981. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  13982. var body = options.body;
  13983. if (this._direction !== 'incoming') {
  13984. throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Options');
  13985. }
  13986. if (this._is_replied) {
  13987. throw new Error('incoming Options already replied');
  13988. }
  13989. if (status_code < 300 || status_code >= 700) {
  13990. throw new TypeError("Invalid status_code: ".concat(status_code));
  13991. }
  13992. this._is_replied = true;
  13993. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  13994. }
  13995. }, {
  13996. key: "_receiveResponse",
  13997. value: function _receiveResponse(response) {
  13998. if (this._closed) {
  13999. return;
  14000. }
  14001. switch (true) {
  14002. case /^1[0-9]{2}$/.test(response.status_code):
  14003. // Ignore provisional responses.
  14004. break;
  14005. case /^2[0-9]{2}$/.test(response.status_code):
  14006. this._succeeded('remote', response);
  14007. break;
  14008. default:
  14009. {
  14010. var cause = Utils.sipErrorCause(response.status_code);
  14011. this._failed('remote', response, cause);
  14012. break;
  14013. }
  14014. }
  14015. }
  14016. }, {
  14017. key: "_onRequestTimeout",
  14018. value: function _onRequestTimeout() {
  14019. if (this._closed) {
  14020. return;
  14021. }
  14022. this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT);
  14023. }
  14024. }, {
  14025. key: "_onTransportError",
  14026. value: function _onTransportError() {
  14027. if (this._closed) {
  14028. return;
  14029. }
  14030. this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  14031. }
  14032. }, {
  14033. key: "_close",
  14034. value: function _close() {
  14035. this._closed = true;
  14036. this._ua.destroyMessage(this);
  14037. }
  14038. /**
  14039. * Internal Callbacks
  14040. */
  14041. }, {
  14042. key: "_newOptions",
  14043. value: function _newOptions(originator, request) {
  14044. if (originator === 'remote') {
  14045. this._direction = 'incoming';
  14046. this._local_identity = request.to;
  14047. this._remote_identity = request.from;
  14048. } else if (originator === 'local') {
  14049. this._direction = 'outgoing';
  14050. this._local_identity = request.from;
  14051. this._remote_identity = request.to;
  14052. }
  14053. this._ua.newOptions(this, {
  14054. originator: originator,
  14055. message: this,
  14056. request: request
  14057. });
  14058. }
  14059. }, {
  14060. key: "_failed",
  14061. value: function _failed(originator, response, cause) {
  14062. logger.debug('OPTIONS failed');
  14063. this._close();
  14064. logger.debug('emit "failed"');
  14065. this.emit('failed', {
  14066. originator: originator,
  14067. response: response || null,
  14068. cause: cause
  14069. });
  14070. }
  14071. }, {
  14072. key: "_succeeded",
  14073. value: function _succeeded(originator, response) {
  14074. logger.debug('OPTIONS succeeded');
  14075. this._close();
  14076. logger.debug('emit "succeeded"');
  14077. this.emit('succeeded', {
  14078. originator: originator,
  14079. response: response
  14080. });
  14081. }
  14082. }, {
  14083. key: "direction",
  14084. get: function get() {
  14085. return this._direction;
  14086. }
  14087. }, {
  14088. key: "local_identity",
  14089. get: function get() {
  14090. return this._local_identity;
  14091. }
  14092. }, {
  14093. key: "remote_identity",
  14094. get: function get() {
  14095. return this._remote_identity;
  14096. }
  14097. }]);
  14098. return Options;
  14099. }(EventEmitter);
  14100. },{"./Constants":2,"./Exceptions":6,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28,"events":31}],13:[function(require,module,exports){
  14101. "use strict";
  14102. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  14103. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  14104. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  14105. var Logger = require('./Logger');
  14106. var Grammar = require('./Grammar');
  14107. var SIPMessage = require('./SIPMessage');
  14108. var logger = new Logger('Parser');
  14109. /**
  14110. * Parse SIP Message
  14111. */
  14112. exports.parseMessage = function (data, ua) {
  14113. var message;
  14114. var bodyStart;
  14115. var headerEnd = data.indexOf('\r\n');
  14116. if (headerEnd === -1) {
  14117. logger.warn('parseMessage() | no CRLF found, not a SIP message');
  14118. return;
  14119. } // Parse first line. Check if it is a Request or a Reply.
  14120. var firstLine = data.substring(0, headerEnd);
  14121. var parsed = Grammar.parse(firstLine, 'Request_Response');
  14122. if (parsed === -1) {
  14123. logger.warn("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\""));
  14124. return;
  14125. } else if (!parsed.status_code) {
  14126. message = new SIPMessage.IncomingRequest(ua);
  14127. message.method = parsed.method;
  14128. message.ruri = parsed.uri;
  14129. } else {
  14130. message = new SIPMessage.IncomingResponse();
  14131. message.status_code = parsed.status_code;
  14132. message.reason_phrase = parsed.reason_phrase;
  14133. }
  14134. message.data = data;
  14135. var headerStart = headerEnd + 2;
  14136. /* Loop over every line in data. Detect the end of each header and parse
  14137. * it or simply add to the headers collection.
  14138. */
  14139. while (true) {
  14140. headerEnd = getHeader(data, headerStart); // The SIP message has normally finished.
  14141. if (headerEnd === -2) {
  14142. bodyStart = headerStart + 2;
  14143. break;
  14144. } // Data.indexOf returned -1 due to a malformed message.
  14145. else if (headerEnd === -1) {
  14146. logger.warn('parseMessage() | malformed message');
  14147. return;
  14148. }
  14149. parsed = parseHeader(message, data, headerStart, headerEnd);
  14150. if (parsed !== true) {
  14151. logger.warn('parseMessage() |', parsed.error);
  14152. return;
  14153. }
  14154. headerStart = headerEnd + 2;
  14155. }
  14156. /* RFC3261 18.3.
  14157. * If there are additional bytes in the transport packet
  14158. * beyond the end of the body, they MUST be discarded.
  14159. */
  14160. if (message.hasHeader('content-length')) {
  14161. var contentLength = message.getHeader('content-length');
  14162. message.body = data.substr(bodyStart, contentLength);
  14163. } else {
  14164. message.body = data.substring(bodyStart);
  14165. }
  14166. return message;
  14167. };
  14168. /**
  14169. * Extract and parse every header of a SIP message.
  14170. */
  14171. function getHeader(data, headerStart) {
  14172. // 'start' position of the header.
  14173. var start = headerStart; // 'end' position of the header.
  14174. var end = 0; // 'partial end' position of the header.
  14175. var partialEnd = 0; // End of message.
  14176. if (data.substring(start, start + 2).match(/(^\r\n)/)) {
  14177. return -2;
  14178. }
  14179. while (end === 0) {
  14180. // Partial End of Header.
  14181. partialEnd = data.indexOf('\r\n', start); // 'indexOf' returns -1 if the value to be found never occurs.
  14182. if (partialEnd === -1) {
  14183. return partialEnd;
  14184. }
  14185. if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) {
  14186. // Not the end of the message. Continue from the next position.
  14187. start = partialEnd + 2;
  14188. } else {
  14189. end = partialEnd;
  14190. }
  14191. }
  14192. return end;
  14193. }
  14194. function parseHeader(message, data, headerStart, headerEnd) {
  14195. var parsed;
  14196. var hcolonIndex = data.indexOf(':', headerStart);
  14197. var headerName = data.substring(headerStart, hcolonIndex).trim();
  14198. var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim(); // If header-field is well-known, parse it.
  14199. switch (headerName.toLowerCase()) {
  14200. case 'via':
  14201. case 'v':
  14202. message.addHeader('via', headerValue);
  14203. if (message.getHeaders('via').length === 1) {
  14204. parsed = message.parseHeader('Via');
  14205. if (parsed) {
  14206. message.via = parsed;
  14207. message.via_branch = parsed.branch;
  14208. }
  14209. } else {
  14210. parsed = 0;
  14211. }
  14212. break;
  14213. case 'from':
  14214. case 'f':
  14215. message.setHeader('from', headerValue);
  14216. parsed = message.parseHeader('from');
  14217. if (parsed) {
  14218. message.from = parsed;
  14219. message.from_tag = parsed.getParam('tag');
  14220. }
  14221. break;
  14222. case 'to':
  14223. case 't':
  14224. message.setHeader('to', headerValue);
  14225. parsed = message.parseHeader('to');
  14226. if (parsed) {
  14227. message.to = parsed;
  14228. message.to_tag = parsed.getParam('tag');
  14229. }
  14230. break;
  14231. case 'record-route':
  14232. parsed = Grammar.parse(headerValue, 'Record_Route');
  14233. if (parsed === -1) {
  14234. parsed = undefined;
  14235. } else {
  14236. var _iterator = _createForOfIteratorHelper(parsed),
  14237. _step;
  14238. try {
  14239. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  14240. var header = _step.value;
  14241. message.addHeader('record-route', headerValue.substring(header.possition, header.offset));
  14242. message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed;
  14243. }
  14244. } catch (err) {
  14245. _iterator.e(err);
  14246. } finally {
  14247. _iterator.f();
  14248. }
  14249. }
  14250. break;
  14251. case 'call-id':
  14252. case 'i':
  14253. message.setHeader('call-id', headerValue);
  14254. parsed = message.parseHeader('call-id');
  14255. if (parsed) {
  14256. message.call_id = headerValue;
  14257. }
  14258. break;
  14259. case 'contact':
  14260. case 'm':
  14261. parsed = Grammar.parse(headerValue, 'Contact');
  14262. if (parsed === -1) {
  14263. parsed = undefined;
  14264. } else {
  14265. var _iterator2 = _createForOfIteratorHelper(parsed),
  14266. _step2;
  14267. try {
  14268. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  14269. var _header = _step2.value;
  14270. message.addHeader('contact', headerValue.substring(_header.possition, _header.offset));
  14271. message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed;
  14272. }
  14273. } catch (err) {
  14274. _iterator2.e(err);
  14275. } finally {
  14276. _iterator2.f();
  14277. }
  14278. }
  14279. break;
  14280. case 'content-length':
  14281. case 'l':
  14282. message.setHeader('content-length', headerValue);
  14283. parsed = message.parseHeader('content-length');
  14284. break;
  14285. case 'content-type':
  14286. case 'c':
  14287. message.setHeader('content-type', headerValue);
  14288. parsed = message.parseHeader('content-type');
  14289. break;
  14290. case 'cseq':
  14291. message.setHeader('cseq', headerValue);
  14292. parsed = message.parseHeader('cseq');
  14293. if (parsed) {
  14294. message.cseq = parsed.value;
  14295. }
  14296. if (message instanceof SIPMessage.IncomingResponse) {
  14297. message.method = parsed.method;
  14298. }
  14299. break;
  14300. case 'max-forwards':
  14301. message.setHeader('max-forwards', headerValue);
  14302. parsed = message.parseHeader('max-forwards');
  14303. break;
  14304. case 'www-authenticate':
  14305. message.setHeader('www-authenticate', headerValue);
  14306. parsed = message.parseHeader('www-authenticate');
  14307. break;
  14308. case 'proxy-authenticate':
  14309. message.setHeader('proxy-authenticate', headerValue);
  14310. parsed = message.parseHeader('proxy-authenticate');
  14311. break;
  14312. case 'session-expires':
  14313. case 'x':
  14314. message.setHeader('session-expires', headerValue);
  14315. parsed = message.parseHeader('session-expires');
  14316. if (parsed) {
  14317. message.session_expires = parsed.expires;
  14318. message.session_expires_refresher = parsed.refresher;
  14319. }
  14320. break;
  14321. case 'refer-to':
  14322. case 'r':
  14323. message.setHeader('refer-to', headerValue);
  14324. parsed = message.parseHeader('refer-to');
  14325. if (parsed) {
  14326. message.refer_to = parsed;
  14327. }
  14328. break;
  14329. case 'replaces':
  14330. message.setHeader('replaces', headerValue);
  14331. parsed = message.parseHeader('replaces');
  14332. if (parsed) {
  14333. message.replaces = parsed;
  14334. }
  14335. break;
  14336. case 'event':
  14337. case 'o':
  14338. message.setHeader('event', headerValue);
  14339. parsed = message.parseHeader('event');
  14340. if (parsed) {
  14341. message.event = parsed;
  14342. }
  14343. break;
  14344. default:
  14345. // Do not parse this header.
  14346. message.addHeader(headerName, headerValue);
  14347. parsed = 0;
  14348. }
  14349. if (parsed === undefined) {
  14350. return {
  14351. error: "error parsing header \"".concat(headerName, "\"")
  14352. };
  14353. } else {
  14354. return true;
  14355. }
  14356. }
  14357. },{"./Grammar":7,"./Logger":9,"./SIPMessage":21}],14:[function(require,module,exports){
  14358. "use strict";
  14359. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  14360. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  14361. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  14362. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  14363. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14364. 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); } }
  14365. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14366. 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); }
  14367. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14368. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14369. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14370. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14371. 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; } }
  14372. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14373. /* globals RTCPeerConnection: false, RTCSessionDescription: false */
  14374. var EventEmitter = require('events').EventEmitter;
  14375. var sdp_transform = require('sdp-transform');
  14376. var Logger = require('./Logger');
  14377. var JsSIP_C = require('./Constants');
  14378. var Exceptions = require('./Exceptions');
  14379. var Transactions = require('./Transactions');
  14380. var Utils = require('./Utils');
  14381. var Timers = require('./Timers');
  14382. var SIPMessage = require('./SIPMessage');
  14383. var Dialog = require('./Dialog');
  14384. var RequestSender = require('./RequestSender');
  14385. var RTCSession_DTMF = require('./RTCSession/DTMF');
  14386. var RTCSession_Info = require('./RTCSession/Info');
  14387. var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier');
  14388. var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber');
  14389. var URI = require('./URI');
  14390. var logger = new Logger('RTCSession');
  14391. var C = {
  14392. // RTCSession states.
  14393. STATUS_NULL: 0,
  14394. STATUS_INVITE_SENT: 1,
  14395. STATUS_1XX_RECEIVED: 2,
  14396. STATUS_INVITE_RECEIVED: 3,
  14397. STATUS_WAITING_FOR_ANSWER: 4,
  14398. STATUS_ANSWERED: 5,
  14399. STATUS_WAITING_FOR_ACK: 6,
  14400. STATUS_CANCELED: 7,
  14401. STATUS_TERMINATED: 8,
  14402. STATUS_CONFIRMED: 9
  14403. };
  14404. /**
  14405. * Local variables.
  14406. */
  14407. var holdMediaTypes = ['audio', 'video'];
  14408. module.exports = /*#__PURE__*/function (_EventEmitter) {
  14409. _inherits(RTCSession, _EventEmitter);
  14410. var _super = _createSuper(RTCSession);
  14411. _createClass(RTCSession, null, [{
  14412. key: "C",
  14413. /**
  14414. * Expose C object.
  14415. */
  14416. get: function get() {
  14417. return C;
  14418. }
  14419. }]);
  14420. function RTCSession(ua) {
  14421. var _this;
  14422. _classCallCheck(this, RTCSession);
  14423. logger.debug('new');
  14424. _this = _super.call(this);
  14425. _this._id = null;
  14426. _this._ua = ua;
  14427. _this._status = C.STATUS_NULL;
  14428. _this._dialog = null;
  14429. _this._earlyDialogs = {};
  14430. _this._contact = null;
  14431. _this._from_tag = null;
  14432. _this._to_tag = null; // The RTCPeerConnection instance (public attribute).
  14433. _this._connection = null; // Prevent races on serial PeerConnction operations.
  14434. _this._connectionPromiseQueue = Promise.resolve(); // Incoming/Outgoing request being currently processed.
  14435. _this._request = null; // Cancel state for initial outgoing request.
  14436. _this._is_canceled = false;
  14437. _this._cancel_reason = ''; // RTCSession confirmation flag.
  14438. _this._is_confirmed = false; // Is late SDP being negotiated.
  14439. _this._late_sdp = false; // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()).
  14440. _this._rtcOfferConstraints = null;
  14441. _this._rtcAnswerConstraints = null; // Local MediaStream.
  14442. _this._localMediaStream = null;
  14443. _this._localMediaStreamLocallyGenerated = false; // Flag to indicate PeerConnection ready for new actions.
  14444. _this._rtcReady = true; // Flag to indicate ICE candidate gathering is finished even if iceGatheringState is not yet 'complete'.
  14445. _this._iceReady = false; // SIP Timers.
  14446. _this._timers = {
  14447. ackTimer: null,
  14448. expiresTimer: null,
  14449. invite2xxTimer: null,
  14450. userNoAnswerTimer: null
  14451. }; // Session info.
  14452. _this._direction = null;
  14453. _this._local_identity = null;
  14454. _this._remote_identity = null;
  14455. _this._start_time = null;
  14456. _this._end_time = null;
  14457. _this._tones = null; // Mute/Hold state.
  14458. _this._audioMuted = false;
  14459. _this._videoMuted = false;
  14460. _this._localHold = false;
  14461. _this._remoteHold = false; // Session Timers (RFC 4028).
  14462. _this._sessionTimers = {
  14463. enabled: _this._ua.configuration.session_timers,
  14464. refreshMethod: _this._ua.configuration.session_timers_refresh_method,
  14465. defaultExpires: JsSIP_C.SESSION_EXPIRES,
  14466. currentExpires: null,
  14467. running: false,
  14468. refresher: false,
  14469. timer: null // A setTimeout.
  14470. }; // Map of ReferSubscriber instances indexed by the REFER's CSeq number.
  14471. _this._referSubscribers = {}; // Custom session empty object for high level use.
  14472. _this._data = {};
  14473. return _this;
  14474. }
  14475. /**
  14476. * User API
  14477. */
  14478. // Expose RTCSession constants as a property of the RTCSession instance.
  14479. _createClass(RTCSession, [{
  14480. key: "isInProgress",
  14481. value: function isInProgress() {
  14482. switch (this._status) {
  14483. case C.STATUS_NULL:
  14484. case C.STATUS_INVITE_SENT:
  14485. case C.STATUS_1XX_RECEIVED:
  14486. case C.STATUS_INVITE_RECEIVED:
  14487. case C.STATUS_WAITING_FOR_ANSWER:
  14488. return true;
  14489. default:
  14490. return false;
  14491. }
  14492. }
  14493. }, {
  14494. key: "isEstablished",
  14495. value: function isEstablished() {
  14496. switch (this._status) {
  14497. case C.STATUS_ANSWERED:
  14498. case C.STATUS_WAITING_FOR_ACK:
  14499. case C.STATUS_CONFIRMED:
  14500. return true;
  14501. default:
  14502. return false;
  14503. }
  14504. }
  14505. }, {
  14506. key: "isEnded",
  14507. value: function isEnded() {
  14508. switch (this._status) {
  14509. case C.STATUS_CANCELED:
  14510. case C.STATUS_TERMINATED:
  14511. return true;
  14512. default:
  14513. return false;
  14514. }
  14515. }
  14516. }, {
  14517. key: "isMuted",
  14518. value: function isMuted() {
  14519. return {
  14520. audio: this._audioMuted,
  14521. video: this._videoMuted
  14522. };
  14523. }
  14524. }, {
  14525. key: "isOnHold",
  14526. value: function isOnHold() {
  14527. return {
  14528. local: this._localHold,
  14529. remote: this._remoteHold
  14530. };
  14531. }
  14532. }, {
  14533. key: "connect",
  14534. value: function connect(target) {
  14535. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  14536. var initCallback = arguments.length > 2 ? arguments[2] : undefined;
  14537. logger.debug('connect()');
  14538. var originalTarget = target;
  14539. var eventHandlers = Utils.cloneObject(options.eventHandlers);
  14540. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14541. var mediaConstraints = Utils.cloneObject(options.mediaConstraints, {
  14542. audio: true,
  14543. video: true
  14544. });
  14545. var mediaStream = options.mediaStream || null;
  14546. var pcConfig = Utils.cloneObject(options.pcConfig, {
  14547. iceServers: []
  14548. });
  14549. var rtcConstraints = options.rtcConstraints || null;
  14550. var rtcOfferConstraints = options.rtcOfferConstraints || null;
  14551. this._rtcOfferConstraints = rtcOfferConstraints;
  14552. this._rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  14553. this._data = options.data || this._data; // Check target.
  14554. if (target === undefined) {
  14555. throw new TypeError('Not enough arguments');
  14556. } // Check Session Status.
  14557. if (this._status !== C.STATUS_NULL) {
  14558. throw new Exceptions.InvalidStateError(this._status);
  14559. } // Check WebRTC support.
  14560. if (!window.RTCPeerConnection) {
  14561. throw new Exceptions.NotSupportedError('WebRTC not supported');
  14562. } // Check target validity.
  14563. target = this._ua.normalizeTarget(target);
  14564. if (!target) {
  14565. throw new TypeError("Invalid target: ".concat(originalTarget));
  14566. } // Session Timers.
  14567. if (this._sessionTimers.enabled) {
  14568. if (Utils.isDecimal(options.sessionTimersExpires)) {
  14569. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  14570. this._sessionTimers.defaultExpires = options.sessionTimersExpires;
  14571. } else {
  14572. this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  14573. }
  14574. }
  14575. } // Set event handlers.
  14576. for (var event in eventHandlers) {
  14577. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  14578. this.on(event, eventHandlers[event]);
  14579. }
  14580. } // Session parameter initialization.
  14581. this._from_tag = Utils.newTag(); // Set anonymous property.
  14582. var anonymous = options.anonymous || false;
  14583. var requestParams = {
  14584. from_tag: this._from_tag
  14585. };
  14586. this._contact = this._ua.contact.toString({
  14587. anonymous: anonymous,
  14588. outbound: true
  14589. });
  14590. if (anonymous) {
  14591. requestParams.from_display_name = 'Anonymous';
  14592. requestParams.from_uri = new URI('sip', 'anonymous', 'anonymous.invalid');
  14593. extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()));
  14594. extraHeaders.push('Privacy: id');
  14595. } else if (options.fromUserName) {
  14596. requestParams.from_uri = new URI('sip', options.fromUserName, this._ua.configuration.uri.host);
  14597. extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()));
  14598. }
  14599. if (options.fromDisplayName) {
  14600. requestParams.from_display_name = options.fromDisplayName;
  14601. }
  14602. extraHeaders.push("Contact: ".concat(this._contact));
  14603. extraHeaders.push('Content-Type: application/sdp');
  14604. if (this._sessionTimers.enabled) {
  14605. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires).concat(this._ua.configuration.session_timers_force_refresher ? ';refresher=uac' : ''));
  14606. }
  14607. this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders);
  14608. this._id = this._request.call_id + this._from_tag; // Create a new RTCPeerConnection instance.
  14609. this._createRTCConnection(pcConfig, rtcConstraints); // Set internal properties.
  14610. this._direction = 'outgoing';
  14611. this._local_identity = this._request.from;
  14612. this._remote_identity = this._request.to; // User explicitly provided a newRTCSession callback for this session.
  14613. if (initCallback) {
  14614. initCallback(this);
  14615. }
  14616. this._newRTCSession('local', this._request);
  14617. this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream);
  14618. }
  14619. }, {
  14620. key: "init_incoming",
  14621. value: function init_incoming(request, initCallback) {
  14622. var _this2 = this;
  14623. logger.debug('init_incoming()');
  14624. var expires;
  14625. var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined; // Check body and content type.
  14626. if (request.body && contentType !== 'application/sdp') {
  14627. request.reply(415);
  14628. return;
  14629. } // Session parameter initialization.
  14630. this._status = C.STATUS_INVITE_RECEIVED;
  14631. this._from_tag = request.from_tag;
  14632. this._id = request.call_id + this._from_tag;
  14633. this._request = request;
  14634. this._contact = this._ua.contact.toString(); // Get the Expires header value if exists.
  14635. if (request.hasHeader('expires')) {
  14636. expires = request.getHeader('expires') * 1000;
  14637. }
  14638. /* Set the to_tag before
  14639. * replying a response code that will create a dialog.
  14640. */
  14641. request.to_tag = Utils.newTag(); // An error on dialog creation will fire 'failed' event.
  14642. if (!this._createDialog(request, 'UAS', true)) {
  14643. request.reply(500, 'Missing Contact header field');
  14644. return;
  14645. }
  14646. if (request.body) {
  14647. this._late_sdp = false;
  14648. } else {
  14649. this._late_sdp = true;
  14650. }
  14651. this._status = C.STATUS_WAITING_FOR_ANSWER; // Set userNoAnswerTimer.
  14652. this._timers.userNoAnswerTimer = setTimeout(function () {
  14653. request.reply(408);
  14654. _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER);
  14655. }, this._ua.configuration.no_answer_timeout);
  14656. /* Set expiresTimer
  14657. * RFC3261 13.3.1
  14658. */
  14659. if (expires) {
  14660. this._timers.expiresTimer = setTimeout(function () {
  14661. if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) {
  14662. request.reply(487);
  14663. _this2._failed('system', null, JsSIP_C.causes.EXPIRES);
  14664. }
  14665. }, expires);
  14666. } // Set internal properties.
  14667. this._direction = 'incoming';
  14668. this._local_identity = request.to;
  14669. this._remote_identity = request.from; // A init callback was specifically defined.
  14670. if (initCallback) {
  14671. initCallback(this);
  14672. } // Fire 'newRTCSession' event.
  14673. this._newRTCSession('remote', request); // The user may have rejected the call in the 'newRTCSession' event.
  14674. if (this._status === C.STATUS_TERMINATED) {
  14675. return;
  14676. } // Reply 180.
  14677. request.reply(180, null, ["Contact: ".concat(this._contact)]); // Fire 'progress' event.
  14678. // TODO: Document that 'response' field in 'progress' event is null for incoming calls.
  14679. this._progress('local', null);
  14680. }
  14681. /**
  14682. * Answer the call.
  14683. */
  14684. }, {
  14685. key: "answer",
  14686. value: function answer() {
  14687. var _this3 = this;
  14688. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14689. logger.debug('answer()');
  14690. var request = this._request;
  14691. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14692. var mediaConstraints = Utils.cloneObject(options.mediaConstraints);
  14693. var mediaStream = options.mediaStream || null;
  14694. var pcConfig = Utils.cloneObject(options.pcConfig, {
  14695. iceServers: []
  14696. });
  14697. var rtcConstraints = options.rtcConstraints || null;
  14698. var rtcAnswerConstraints = options.rtcAnswerConstraints || null;
  14699. var rtcOfferConstraints = Utils.cloneObject(options.rtcOfferConstraints);
  14700. var tracks;
  14701. var peerHasAudioLine = false;
  14702. var peerHasVideoLine = false;
  14703. var peerOffersFullAudio = false;
  14704. var peerOffersFullVideo = false;
  14705. this._rtcAnswerConstraints = rtcAnswerConstraints;
  14706. this._rtcOfferConstraints = options.rtcOfferConstraints || null;
  14707. this._data = options.data || this._data; // Check Session Direction and Status.
  14708. if (this._direction !== 'incoming') {
  14709. throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession');
  14710. } // Check Session status.
  14711. if (this._status !== C.STATUS_WAITING_FOR_ANSWER) {
  14712. throw new Exceptions.InvalidStateError(this._status);
  14713. } // Session Timers.
  14714. if (this._sessionTimers.enabled) {
  14715. if (Utils.isDecimal(options.sessionTimersExpires)) {
  14716. if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  14717. this._sessionTimers.defaultExpires = options.sessionTimersExpires;
  14718. } else {
  14719. this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
  14720. }
  14721. }
  14722. }
  14723. this._status = C.STATUS_ANSWERED; // An error on dialog creation will fire 'failed' event.
  14724. if (!this._createDialog(request, 'UAS')) {
  14725. request.reply(500, 'Error creating dialog');
  14726. return;
  14727. }
  14728. clearTimeout(this._timers.userNoAnswerTimer);
  14729. extraHeaders.unshift("Contact: ".concat(this._contact)); // Determine incoming media from incoming SDP offer (if any).
  14730. var sdp = request.parseSDP(); // Make sure sdp.media is an array, not the case if there is only one media.
  14731. if (!Array.isArray(sdp.media)) {
  14732. sdp.media = [sdp.media];
  14733. } // Go through all medias in SDP to find offered capabilities to answer with.
  14734. var _iterator = _createForOfIteratorHelper(sdp.media),
  14735. _step;
  14736. try {
  14737. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  14738. var m = _step.value;
  14739. if (m.type === 'audio') {
  14740. peerHasAudioLine = true;
  14741. if (!m.direction || m.direction === 'sendrecv') {
  14742. peerOffersFullAudio = true;
  14743. }
  14744. }
  14745. if (m.type === 'video') {
  14746. peerHasVideoLine = true;
  14747. if (!m.direction || m.direction === 'sendrecv') {
  14748. peerOffersFullVideo = true;
  14749. }
  14750. }
  14751. } // Remove audio from mediaStream if suggested by mediaConstraints.
  14752. } catch (err) {
  14753. _iterator.e(err);
  14754. } finally {
  14755. _iterator.f();
  14756. }
  14757. if (mediaStream && mediaConstraints.audio === false) {
  14758. tracks = mediaStream.getAudioTracks();
  14759. var _iterator2 = _createForOfIteratorHelper(tracks),
  14760. _step2;
  14761. try {
  14762. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  14763. var track = _step2.value;
  14764. mediaStream.removeTrack(track);
  14765. }
  14766. } catch (err) {
  14767. _iterator2.e(err);
  14768. } finally {
  14769. _iterator2.f();
  14770. }
  14771. } // Remove video from mediaStream if suggested by mediaConstraints.
  14772. if (mediaStream && mediaConstraints.video === false) {
  14773. tracks = mediaStream.getVideoTracks();
  14774. var _iterator3 = _createForOfIteratorHelper(tracks),
  14775. _step3;
  14776. try {
  14777. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  14778. var _track = _step3.value;
  14779. mediaStream.removeTrack(_track);
  14780. }
  14781. } catch (err) {
  14782. _iterator3.e(err);
  14783. } finally {
  14784. _iterator3.f();
  14785. }
  14786. } // Set audio constraints based on incoming stream if not supplied.
  14787. if (!mediaStream && mediaConstraints.audio === undefined) {
  14788. mediaConstraints.audio = peerOffersFullAudio;
  14789. } // Set video constraints based on incoming stream if not supplied.
  14790. if (!mediaStream && mediaConstraints.video === undefined) {
  14791. mediaConstraints.video = peerOffersFullVideo;
  14792. } // Don't ask for audio if the incoming offer has no audio section.
  14793. if (!mediaStream && !peerHasAudioLine && !rtcOfferConstraints.offerToReceiveAudio) {
  14794. mediaConstraints.audio = false;
  14795. } // Don't ask for video if the incoming offer has no video section.
  14796. if (!mediaStream && !peerHasVideoLine && !rtcOfferConstraints.offerToReceiveVideo) {
  14797. mediaConstraints.video = false;
  14798. } // Create a new RTCPeerConnection instance.
  14799. // TODO: This may throw an error, should react.
  14800. this._createRTCConnection(pcConfig, rtcConstraints);
  14801. Promise.resolve() // Handle local MediaStream.
  14802. .then(function () {
  14803. // A local MediaStream is given, use it.
  14804. if (mediaStream) {
  14805. return mediaStream;
  14806. } // Audio and/or video requested, prompt getUserMedia.
  14807. else if (mediaConstraints.audio || mediaConstraints.video) {
  14808. _this3._localMediaStreamLocallyGenerated = true;
  14809. return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) {
  14810. if (_this3._status === C.STATUS_TERMINATED) {
  14811. throw new Error('terminated');
  14812. }
  14813. request.reply(480);
  14814. _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  14815. logger.warn('emit "getusermediafailed" [error:%o]', error);
  14816. _this3.emit('getusermediafailed', error);
  14817. throw new Error('getUserMedia() failed');
  14818. });
  14819. }
  14820. }) // Attach MediaStream to RTCPeerconnection.
  14821. .then(function (stream) {
  14822. if (_this3._status === C.STATUS_TERMINATED) {
  14823. throw new Error('terminated');
  14824. }
  14825. _this3._localMediaStream = stream;
  14826. if (stream) {
  14827. stream.getTracks().forEach(function (track) {
  14828. _this3._connection.addTrack(track, stream);
  14829. });
  14830. }
  14831. }) // Set remote description.
  14832. .then(function () {
  14833. if (_this3._late_sdp) {
  14834. return;
  14835. }
  14836. var e = {
  14837. originator: 'remote',
  14838. type: 'offer',
  14839. sdp: request.body
  14840. };
  14841. logger.debug('emit "sdp"');
  14842. _this3.emit('sdp', e);
  14843. var offer = new RTCSessionDescription({
  14844. type: 'offer',
  14845. sdp: e.sdp
  14846. });
  14847. _this3._connectionPromiseQueue = _this3._connectionPromiseQueue.then(function () {
  14848. return _this3._connection.setRemoteDescription(offer);
  14849. })["catch"](function (error) {
  14850. request.reply(488);
  14851. _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR);
  14852. logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  14853. _this3.emit('peerconnection:setremotedescriptionfailed', error);
  14854. throw new Error('peerconnection.setRemoteDescription() failed');
  14855. });
  14856. return _this3._connectionPromiseQueue;
  14857. }) // Create local description.
  14858. .then(function () {
  14859. if (_this3._status === C.STATUS_TERMINATED) {
  14860. throw new Error('terminated');
  14861. } // TODO: Is this event already useful?
  14862. _this3._connecting(request);
  14863. if (!_this3._late_sdp) {
  14864. return _this3._createLocalDescription('answer', rtcAnswerConstraints)["catch"](function () {
  14865. request.reply(500);
  14866. throw new Error('_createLocalDescription() failed');
  14867. });
  14868. } else {
  14869. return _this3._createLocalDescription('offer', _this3._rtcOfferConstraints)["catch"](function () {
  14870. request.reply(500);
  14871. throw new Error('_createLocalDescription() failed');
  14872. });
  14873. }
  14874. }) // Send reply.
  14875. .then(function (desc) {
  14876. if (_this3._status === C.STATUS_TERMINATED) {
  14877. throw new Error('terminated');
  14878. }
  14879. _this3._handleSessionTimersInIncomingRequest(request, extraHeaders);
  14880. request.reply(200, null, extraHeaders, desc, function () {
  14881. _this3._status = C.STATUS_WAITING_FOR_ACK;
  14882. _this3._setInvite2xxTimer(request, desc);
  14883. _this3._setACKTimer();
  14884. _this3._accepted('local');
  14885. }, function () {
  14886. _this3._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
  14887. });
  14888. })["catch"](function (error) {
  14889. if (_this3._status === C.STATUS_TERMINATED) {
  14890. return;
  14891. }
  14892. logger.warn(error);
  14893. });
  14894. }
  14895. /**
  14896. * Terminate the call.
  14897. */
  14898. }, {
  14899. key: "terminate",
  14900. value: function terminate() {
  14901. var _this4 = this;
  14902. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14903. logger.debug('terminate()');
  14904. var cause = options.cause || JsSIP_C.causes.BYE;
  14905. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  14906. var body = options.body;
  14907. var cancel_reason;
  14908. var status_code = options.status_code;
  14909. var reason_phrase = options.reason_phrase; // Check Session Status.
  14910. if (this._status === C.STATUS_TERMINATED) {
  14911. throw new Exceptions.InvalidStateError(this._status);
  14912. }
  14913. switch (this._status) {
  14914. // - UAC -
  14915. case C.STATUS_NULL:
  14916. case C.STATUS_INVITE_SENT:
  14917. case C.STATUS_1XX_RECEIVED:
  14918. logger.debug('canceling session');
  14919. if (status_code && (status_code < 200 || status_code >= 700)) {
  14920. throw new TypeError("Invalid status_code: ".concat(status_code));
  14921. } else if (status_code) {
  14922. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  14923. cancel_reason = "SIP ;cause=".concat(status_code, " ;text=\"").concat(reason_phrase, "\"");
  14924. } // Check Session Status.
  14925. if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) {
  14926. this._is_canceled = true;
  14927. this._cancel_reason = cancel_reason;
  14928. } else if (this._status === C.STATUS_1XX_RECEIVED) {
  14929. this._request.cancel(cancel_reason);
  14930. }
  14931. this._status = C.STATUS_CANCELED;
  14932. this._failed('local', null, JsSIP_C.causes.CANCELED);
  14933. break;
  14934. // - UAS -
  14935. case C.STATUS_WAITING_FOR_ANSWER:
  14936. case C.STATUS_ANSWERED:
  14937. logger.debug('rejecting session');
  14938. status_code = status_code || 480;
  14939. if (status_code < 300 || status_code >= 700) {
  14940. throw new TypeError("Invalid status_code: ".concat(status_code));
  14941. }
  14942. this._request.reply(status_code, reason_phrase, extraHeaders, body);
  14943. this._failed('local', null, JsSIP_C.causes.REJECTED);
  14944. break;
  14945. case C.STATUS_WAITING_FOR_ACK:
  14946. case C.STATUS_CONFIRMED:
  14947. logger.debug('terminating session');
  14948. reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  14949. if (status_code && (status_code < 200 || status_code >= 700)) {
  14950. throw new TypeError("Invalid status_code: ".concat(status_code));
  14951. } else if (status_code) {
  14952. extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\""));
  14953. }
  14954. /* RFC 3261 section 15 (Terminating a session):
  14955. *
  14956. * "...the callee's UA MUST NOT send a BYE on a confirmed dialog
  14957. * until it has received an ACK for its 2xx response or until the server
  14958. * transaction times out."
  14959. */
  14960. if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) {
  14961. // Save the dialog for later restoration.
  14962. var dialog = this._dialog; // Send the BYE as soon as the ACK is received...
  14963. this.receiveRequest = function (_ref) {
  14964. var method = _ref.method;
  14965. if (method === JsSIP_C.ACK) {
  14966. _this4.sendRequest(JsSIP_C.BYE, {
  14967. extraHeaders: extraHeaders,
  14968. body: body
  14969. });
  14970. dialog.terminate();
  14971. }
  14972. }; // .., or when the INVITE transaction times out
  14973. this._request.server_transaction.on('stateChanged', function () {
  14974. if (_this4._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) {
  14975. _this4.sendRequest(JsSIP_C.BYE, {
  14976. extraHeaders: extraHeaders,
  14977. body: body
  14978. });
  14979. dialog.terminate();
  14980. }
  14981. });
  14982. this._ended('local', null, cause); // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-).
  14983. this._dialog = dialog; // Restore the dialog into 'ua' so the ACK can reach 'this' session.
  14984. this._ua.newDialog(dialog);
  14985. } else {
  14986. this.sendRequest(JsSIP_C.BYE, {
  14987. extraHeaders: extraHeaders,
  14988. body: body
  14989. });
  14990. this._ended('local', null, cause);
  14991. }
  14992. }
  14993. }
  14994. }, {
  14995. key: "sendDTMF",
  14996. value: function sendDTMF(tones) {
  14997. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  14998. logger.debug('sendDTMF() | tones: %s', tones);
  14999. var position = 0;
  15000. var duration = options.duration || null;
  15001. var interToneGap = options.interToneGap || null;
  15002. var transportType = options.transportType || JsSIP_C.DTMF_TRANSPORT.INFO;
  15003. if (tones === undefined) {
  15004. throw new TypeError('Not enough arguments');
  15005. } // Check Session Status.
  15006. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_1XX_RECEIVED) {
  15007. throw new Exceptions.InvalidStateError(this._status);
  15008. } // Check Transport type.
  15009. if (transportType !== JsSIP_C.DTMF_TRANSPORT.INFO && transportType !== JsSIP_C.DTMF_TRANSPORT.RFC2833) {
  15010. throw new TypeError("invalid transportType: ".concat(transportType));
  15011. } // Convert to string.
  15012. if (typeof tones === 'number') {
  15013. tones = tones.toString();
  15014. } // Check tones.
  15015. if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) {
  15016. throw new TypeError("Invalid tones: ".concat(tones));
  15017. } // Check duration.
  15018. if (duration && !Utils.isDecimal(duration)) {
  15019. throw new TypeError("Invalid tone duration: ".concat(duration));
  15020. } else if (!duration) {
  15021. duration = RTCSession_DTMF.C.DEFAULT_DURATION;
  15022. } else if (duration < RTCSession_DTMF.C.MIN_DURATION) {
  15023. logger.debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds"));
  15024. duration = RTCSession_DTMF.C.MIN_DURATION;
  15025. } else if (duration > RTCSession_DTMF.C.MAX_DURATION) {
  15026. logger.debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds"));
  15027. duration = RTCSession_DTMF.C.MAX_DURATION;
  15028. } else {
  15029. duration = Math.abs(duration);
  15030. }
  15031. options.duration = duration; // Check interToneGap.
  15032. if (interToneGap && !Utils.isDecimal(interToneGap)) {
  15033. throw new TypeError("Invalid interToneGap: ".concat(interToneGap));
  15034. } else if (!interToneGap) {
  15035. interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP;
  15036. } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) {
  15037. logger.debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds"));
  15038. interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP;
  15039. } else {
  15040. interToneGap = Math.abs(interToneGap);
  15041. } // RFC2833. Let RTCDTMFSender enqueue the DTMFs.
  15042. if (transportType === JsSIP_C.DTMF_TRANSPORT.RFC2833) {
  15043. // Send DTMF in current audio RTP stream.
  15044. var sender = this._getDTMFRTPSender();
  15045. if (sender) {
  15046. // Add remaining buffered tones.
  15047. tones = sender.toneBuffer + tones; // Insert tones.
  15048. sender.insertDTMF(tones, duration, interToneGap);
  15049. }
  15050. return;
  15051. }
  15052. if (this._tones) {
  15053. // Tones are already queued, just add to the queue.
  15054. this._tones += tones;
  15055. return;
  15056. }
  15057. this._tones = tones; // Send the first tone.
  15058. _sendDTMF.call(this);
  15059. function _sendDTMF() {
  15060. var _this5 = this;
  15061. var timeout;
  15062. if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) {
  15063. // Stop sending DTMF.
  15064. this._tones = null;
  15065. return;
  15066. }
  15067. var tone = this._tones[position];
  15068. position += 1;
  15069. if (tone === ',') {
  15070. timeout = 2000;
  15071. } else {
  15072. // Send DTMF via SIP INFO messages.
  15073. var dtmf = new RTCSession_DTMF(this);
  15074. options.eventHandlers = {
  15075. onFailed: function onFailed() {
  15076. _this5._tones = null;
  15077. }
  15078. };
  15079. dtmf.send(tone, options);
  15080. timeout = duration + interToneGap;
  15081. } // Set timeout for the next tone.
  15082. setTimeout(_sendDTMF.bind(this), timeout);
  15083. }
  15084. }
  15085. }, {
  15086. key: "sendInfo",
  15087. value: function sendInfo(contentType, body) {
  15088. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  15089. logger.debug('sendInfo()'); // Check Session Status.
  15090. if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_1XX_RECEIVED) {
  15091. throw new Exceptions.InvalidStateError(this._status);
  15092. }
  15093. var info = new RTCSession_Info(this);
  15094. info.send(contentType, body, options);
  15095. }
  15096. /**
  15097. * Mute
  15098. */
  15099. }, {
  15100. key: "mute",
  15101. value: function mute() {
  15102. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  15103. audio: true,
  15104. video: false
  15105. };
  15106. logger.debug('mute()');
  15107. var audioMuted = false,
  15108. videoMuted = false;
  15109. if (this._audioMuted === false && options.audio) {
  15110. audioMuted = true;
  15111. this._audioMuted = true;
  15112. this._toggleMuteAudio(true);
  15113. }
  15114. if (this._videoMuted === false && options.video) {
  15115. videoMuted = true;
  15116. this._videoMuted = true;
  15117. this._toggleMuteVideo(true);
  15118. }
  15119. if (audioMuted === true || videoMuted === true) {
  15120. this._onmute({
  15121. audio: audioMuted,
  15122. video: videoMuted
  15123. });
  15124. }
  15125. }
  15126. /**
  15127. * Unmute
  15128. */
  15129. }, {
  15130. key: "unmute",
  15131. value: function unmute() {
  15132. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  15133. audio: true,
  15134. video: true
  15135. };
  15136. logger.debug('unmute()');
  15137. var audioUnMuted = false,
  15138. videoUnMuted = false;
  15139. if (this._audioMuted === true && options.audio) {
  15140. audioUnMuted = true;
  15141. this._audioMuted = false;
  15142. if (this._localHold === false) {
  15143. this._toggleMuteAudio(false);
  15144. }
  15145. }
  15146. if (this._videoMuted === true && options.video) {
  15147. videoUnMuted = true;
  15148. this._videoMuted = false;
  15149. if (this._localHold === false) {
  15150. this._toggleMuteVideo(false);
  15151. }
  15152. }
  15153. if (audioUnMuted === true || videoUnMuted === true) {
  15154. this._onunmute({
  15155. audio: audioUnMuted,
  15156. video: videoUnMuted
  15157. });
  15158. }
  15159. }
  15160. /**
  15161. * Hold
  15162. */
  15163. }, {
  15164. key: "hold",
  15165. value: function hold() {
  15166. var _this6 = this;
  15167. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15168. var done = arguments.length > 1 ? arguments[1] : undefined;
  15169. logger.debug('hold()');
  15170. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15171. return false;
  15172. }
  15173. if (this._localHold === true) {
  15174. return false;
  15175. }
  15176. if (!this._isReadyToReOffer()) {
  15177. return false;
  15178. }
  15179. this._localHold = true;
  15180. this._onhold('local');
  15181. var eventHandlers = {
  15182. succeeded: function succeeded() {
  15183. if (done) {
  15184. done();
  15185. }
  15186. },
  15187. failed: function failed() {
  15188. _this6.terminate({
  15189. cause: JsSIP_C.causes.WEBRTC_ERROR,
  15190. status_code: 500,
  15191. reason_phrase: 'Hold Failed'
  15192. });
  15193. }
  15194. };
  15195. if (options.useUpdate) {
  15196. this._sendUpdate({
  15197. sdpOffer: true,
  15198. eventHandlers: eventHandlers,
  15199. extraHeaders: options.extraHeaders
  15200. });
  15201. } else {
  15202. this._sendReinvite({
  15203. eventHandlers: eventHandlers,
  15204. extraHeaders: options.extraHeaders
  15205. });
  15206. }
  15207. return true;
  15208. }
  15209. }, {
  15210. key: "unhold",
  15211. value: function unhold() {
  15212. var _this7 = this;
  15213. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15214. var done = arguments.length > 1 ? arguments[1] : undefined;
  15215. logger.debug('unhold()');
  15216. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15217. return false;
  15218. }
  15219. if (this._localHold === false) {
  15220. return false;
  15221. }
  15222. if (!this._isReadyToReOffer()) {
  15223. return false;
  15224. }
  15225. this._localHold = false;
  15226. this._onunhold('local');
  15227. var eventHandlers = {
  15228. succeeded: function succeeded() {
  15229. if (done) {
  15230. done();
  15231. }
  15232. },
  15233. failed: function failed() {
  15234. _this7.terminate({
  15235. cause: JsSIP_C.causes.WEBRTC_ERROR,
  15236. status_code: 500,
  15237. reason_phrase: 'Unhold Failed'
  15238. });
  15239. }
  15240. };
  15241. if (options.useUpdate) {
  15242. this._sendUpdate({
  15243. sdpOffer: true,
  15244. eventHandlers: eventHandlers,
  15245. extraHeaders: options.extraHeaders
  15246. });
  15247. } else {
  15248. this._sendReinvite({
  15249. eventHandlers: eventHandlers,
  15250. extraHeaders: options.extraHeaders
  15251. });
  15252. }
  15253. return true;
  15254. }
  15255. }, {
  15256. key: "renegotiate",
  15257. value: function renegotiate() {
  15258. var _this8 = this;
  15259. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15260. var done = arguments.length > 1 ? arguments[1] : undefined;
  15261. logger.debug('renegotiate()');
  15262. var rtcOfferConstraints = options.rtcOfferConstraints || null;
  15263. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15264. return false;
  15265. }
  15266. if (!this._isReadyToReOffer()) {
  15267. return false;
  15268. }
  15269. var eventHandlers = {
  15270. succeeded: function succeeded() {
  15271. if (done) {
  15272. done();
  15273. }
  15274. },
  15275. failed: function failed() {
  15276. _this8.terminate({
  15277. cause: JsSIP_C.causes.WEBRTC_ERROR,
  15278. status_code: 500,
  15279. reason_phrase: 'Media Renegotiation Failed'
  15280. });
  15281. }
  15282. };
  15283. this._setLocalMediaStatus();
  15284. if (options.useUpdate) {
  15285. this._sendUpdate({
  15286. sdpOffer: true,
  15287. eventHandlers: eventHandlers,
  15288. rtcOfferConstraints: rtcOfferConstraints,
  15289. extraHeaders: options.extraHeaders
  15290. });
  15291. } else {
  15292. this._sendReinvite({
  15293. eventHandlers: eventHandlers,
  15294. rtcOfferConstraints: rtcOfferConstraints,
  15295. extraHeaders: options.extraHeaders
  15296. });
  15297. }
  15298. return true;
  15299. }
  15300. /**
  15301. * Refer
  15302. */
  15303. }, {
  15304. key: "refer",
  15305. value: function refer(target, options) {
  15306. var _this9 = this;
  15307. logger.debug('refer()');
  15308. var originalTarget = target;
  15309. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  15310. return false;
  15311. } // Check target validity.
  15312. target = this._ua.normalizeTarget(target);
  15313. if (!target) {
  15314. throw new TypeError("Invalid target: ".concat(originalTarget));
  15315. }
  15316. var referSubscriber = new RTCSession_ReferSubscriber(this);
  15317. referSubscriber.sendRefer(target, options); // Store in the map.
  15318. var id = referSubscriber.id;
  15319. this._referSubscribers[id] = referSubscriber; // Listen for ending events so we can remove it from the map.
  15320. referSubscriber.on('requestFailed', function () {
  15321. delete _this9._referSubscribers[id];
  15322. });
  15323. referSubscriber.on('accepted', function () {
  15324. delete _this9._referSubscribers[id];
  15325. });
  15326. referSubscriber.on('failed', function () {
  15327. delete _this9._referSubscribers[id];
  15328. });
  15329. return referSubscriber;
  15330. }
  15331. /**
  15332. * Send a generic in-dialog Request
  15333. */
  15334. }, {
  15335. key: "sendRequest",
  15336. value: function sendRequest(method, options) {
  15337. logger.debug('sendRequest()');
  15338. return this._dialog.sendRequest(method, options);
  15339. }
  15340. /**
  15341. * In dialog Request Reception
  15342. */
  15343. }, {
  15344. key: "receiveRequest",
  15345. value: function receiveRequest(request) {
  15346. var _this10 = this;
  15347. logger.debug('receiveRequest()');
  15348. if (request.method === JsSIP_C.CANCEL) {
  15349. /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL
  15350. * was in progress and that the UAC MAY continue with the session established by
  15351. * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the
  15352. * established session. So the CANCEL is processed only if the session is not yet
  15353. * established.
  15354. */
  15355. /*
  15356. * Terminate the whole session in case the user didn't accept (or yet send the answer)
  15357. * nor reject the request opening the session.
  15358. */
  15359. if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) {
  15360. this._status = C.STATUS_CANCELED;
  15361. this._request.reply(487);
  15362. this._failed('remote', request, JsSIP_C.causes.CANCELED);
  15363. }
  15364. } else {
  15365. // Requests arriving here are in-dialog requests.
  15366. switch (request.method) {
  15367. case JsSIP_C.ACK:
  15368. if (this._status !== C.STATUS_WAITING_FOR_ACK) {
  15369. return;
  15370. } // Update signaling status.
  15371. this._status = C.STATUS_CONFIRMED;
  15372. clearTimeout(this._timers.ackTimer);
  15373. clearTimeout(this._timers.invite2xxTimer);
  15374. if (this._late_sdp) {
  15375. if (!request.body) {
  15376. this.terminate({
  15377. cause: JsSIP_C.causes.MISSING_SDP,
  15378. status_code: 400
  15379. });
  15380. break;
  15381. }
  15382. var e = {
  15383. originator: 'remote',
  15384. type: 'answer',
  15385. sdp: request.body
  15386. };
  15387. logger.debug('emit "sdp"');
  15388. this.emit('sdp', e);
  15389. var answer = new RTCSessionDescription({
  15390. type: 'answer',
  15391. sdp: e.sdp
  15392. });
  15393. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15394. return _this10._connection.setRemoteDescription(answer);
  15395. }).then(function () {
  15396. if (!_this10._is_confirmed) {
  15397. _this10._confirmed('remote', request);
  15398. }
  15399. })["catch"](function (error) {
  15400. _this10.terminate({
  15401. cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION,
  15402. status_code: 488
  15403. });
  15404. logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15405. _this10.emit('peerconnection:setremotedescriptionfailed', error);
  15406. });
  15407. } else if (!this._is_confirmed) {
  15408. this._confirmed('remote', request);
  15409. }
  15410. break;
  15411. case JsSIP_C.BYE:
  15412. if (this._status === C.STATUS_CONFIRMED || this._status === C.STATUS_WAITING_FOR_ACK) {
  15413. request.reply(200);
  15414. this._ended('remote', request, JsSIP_C.causes.BYE);
  15415. } else if (this._status === C.STATUS_INVITE_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER) {
  15416. request.reply(200);
  15417. this._request.reply(487, 'BYE Received');
  15418. this._ended('remote', request, JsSIP_C.causes.BYE);
  15419. } else {
  15420. request.reply(403, 'Wrong Status');
  15421. }
  15422. break;
  15423. case JsSIP_C.INVITE:
  15424. if (this._status === C.STATUS_CONFIRMED) {
  15425. if (request.hasHeader('replaces')) {
  15426. this._receiveReplaces(request);
  15427. } else {
  15428. this._receiveReinvite(request);
  15429. }
  15430. } else {
  15431. request.reply(403, 'Wrong Status');
  15432. }
  15433. break;
  15434. case JsSIP_C.INFO:
  15435. 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) {
  15436. var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined;
  15437. if (contentType && contentType.match(/^application\/dtmf-relay/i)) {
  15438. new RTCSession_DTMF(this).init_incoming(request);
  15439. } else if (contentType !== undefined) {
  15440. new RTCSession_Info(this).init_incoming(request);
  15441. } else {
  15442. request.reply(415);
  15443. }
  15444. } else {
  15445. request.reply(403, 'Wrong Status');
  15446. }
  15447. break;
  15448. case JsSIP_C.UPDATE:
  15449. if (this._status === C.STATUS_CONFIRMED) {
  15450. this._receiveUpdate(request);
  15451. } else {
  15452. request.reply(403, 'Wrong Status');
  15453. }
  15454. break;
  15455. case JsSIP_C.REFER:
  15456. if (this._status === C.STATUS_CONFIRMED) {
  15457. this._receiveRefer(request);
  15458. } else {
  15459. request.reply(403, 'Wrong Status');
  15460. }
  15461. break;
  15462. case JsSIP_C.NOTIFY:
  15463. if (this._status === C.STATUS_CONFIRMED) {
  15464. this._receiveNotify(request);
  15465. } else {
  15466. request.reply(403, 'Wrong Status');
  15467. }
  15468. break;
  15469. default:
  15470. request.reply(501);
  15471. }
  15472. }
  15473. }
  15474. /**
  15475. * Session Callbacks
  15476. */
  15477. }, {
  15478. key: "onTransportError",
  15479. value: function onTransportError() {
  15480. logger.warn('onTransportError()');
  15481. if (this._status !== C.STATUS_TERMINATED) {
  15482. this.terminate({
  15483. status_code: 500,
  15484. reason_phrase: JsSIP_C.causes.CONNECTION_ERROR,
  15485. cause: JsSIP_C.causes.CONNECTION_ERROR
  15486. });
  15487. }
  15488. }
  15489. }, {
  15490. key: "onRequestTimeout",
  15491. value: function onRequestTimeout() {
  15492. logger.warn('onRequestTimeout()');
  15493. if (this._status !== C.STATUS_TERMINATED) {
  15494. this.terminate({
  15495. status_code: 408,
  15496. reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT,
  15497. cause: JsSIP_C.causes.REQUEST_TIMEOUT
  15498. });
  15499. }
  15500. }
  15501. }, {
  15502. key: "onDialogError",
  15503. value: function onDialogError() {
  15504. logger.warn('onDialogError()');
  15505. if (this._status !== C.STATUS_TERMINATED) {
  15506. this.terminate({
  15507. status_code: 500,
  15508. reason_phrase: JsSIP_C.causes.DIALOG_ERROR,
  15509. cause: JsSIP_C.causes.DIALOG_ERROR
  15510. });
  15511. }
  15512. } // Called from DTMF handler.
  15513. }, {
  15514. key: "newDTMF",
  15515. value: function newDTMF(data) {
  15516. logger.debug('newDTMF()');
  15517. this.emit('newDTMF', data);
  15518. } // Called from Info handler.
  15519. }, {
  15520. key: "newInfo",
  15521. value: function newInfo(data) {
  15522. logger.debug('newInfo()');
  15523. this.emit('newInfo', data);
  15524. }
  15525. /**
  15526. * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP.
  15527. */
  15528. }, {
  15529. key: "_isReadyToReOffer",
  15530. value: function _isReadyToReOffer() {
  15531. if (!this._rtcReady) {
  15532. logger.debug('_isReadyToReOffer() | internal WebRTC status not ready');
  15533. return false;
  15534. } // No established yet.
  15535. if (!this._dialog) {
  15536. logger.debug('_isReadyToReOffer() | session not established yet');
  15537. return false;
  15538. } // Another INVITE transaction is in progress.
  15539. if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) {
  15540. logger.debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress');
  15541. return false;
  15542. }
  15543. return true;
  15544. }
  15545. }, {
  15546. key: "_close",
  15547. value: function _close() {
  15548. logger.debug('close()'); // Close local MediaStream if it was not given by the user.
  15549. if (this._localMediaStream && this._localMediaStreamLocallyGenerated) {
  15550. logger.debug('close() | closing local MediaStream');
  15551. Utils.closeMediaStream(this._localMediaStream);
  15552. }
  15553. if (this._status === C.STATUS_TERMINATED) {
  15554. return;
  15555. }
  15556. this._status = C.STATUS_TERMINATED; // Terminate RTC.
  15557. if (this._connection) {
  15558. try {
  15559. this._connection.close();
  15560. } catch (error) {
  15561. logger.warn('close() | error closing the RTCPeerConnection: %o', error);
  15562. }
  15563. } // Terminate signaling.
  15564. // Clear SIP timers.
  15565. for (var timer in this._timers) {
  15566. if (Object.prototype.hasOwnProperty.call(this._timers, timer)) {
  15567. clearTimeout(this._timers[timer]);
  15568. }
  15569. } // Clear Session Timers.
  15570. clearTimeout(this._sessionTimers.timer); // Terminate confirmed dialog.
  15571. if (this._dialog) {
  15572. this._dialog.terminate();
  15573. delete this._dialog;
  15574. } // Terminate early dialogs.
  15575. for (var dialog in this._earlyDialogs) {
  15576. if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) {
  15577. this._earlyDialogs[dialog].terminate();
  15578. delete this._earlyDialogs[dialog];
  15579. }
  15580. } // Terminate REFER subscribers.
  15581. for (var subscriber in this._referSubscribers) {
  15582. if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) {
  15583. delete this._referSubscribers[subscriber];
  15584. }
  15585. }
  15586. this._ua.destroyRTCSession(this);
  15587. }
  15588. /**
  15589. * Private API.
  15590. */
  15591. /**
  15592. * RFC3261 13.3.1.4
  15593. * Response retransmissions cannot be accomplished by transaction layer
  15594. * since it is destroyed when receiving the first 2xx answer
  15595. */
  15596. }, {
  15597. key: "_setInvite2xxTimer",
  15598. value: function _setInvite2xxTimer(request, body) {
  15599. var timeout = Timers.T1;
  15600. function invite2xxRetransmission() {
  15601. if (this._status !== C.STATUS_WAITING_FOR_ACK) {
  15602. return;
  15603. }
  15604. request.reply(200, null, ["Contact: ".concat(this._contact)], body);
  15605. if (timeout < Timers.T2) {
  15606. timeout = timeout * 2;
  15607. if (timeout > Timers.T2) {
  15608. timeout = Timers.T2;
  15609. }
  15610. }
  15611. this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
  15612. }
  15613. this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
  15614. }
  15615. /**
  15616. * RFC3261 14.2
  15617. * If a UAS generates a 2xx response and never receives an ACK,
  15618. * it SHOULD generate a BYE to terminate the dialog.
  15619. */
  15620. }, {
  15621. key: "_setACKTimer",
  15622. value: function _setACKTimer() {
  15623. var _this11 = this;
  15624. this._timers.ackTimer = setTimeout(function () {
  15625. if (_this11._status === C.STATUS_WAITING_FOR_ACK) {
  15626. logger.debug('no ACK received, terminating the session');
  15627. clearTimeout(_this11._timers.invite2xxTimer);
  15628. _this11.sendRequest(JsSIP_C.BYE);
  15629. _this11._ended('remote', null, JsSIP_C.causes.NO_ACK);
  15630. }
  15631. }, Timers.TIMER_H);
  15632. }
  15633. }, {
  15634. key: "_createRTCConnection",
  15635. value: function _createRTCConnection(pcConfig, rtcConstraints) {
  15636. var _this12 = this;
  15637. this._connection = new RTCPeerConnection(pcConfig, rtcConstraints);
  15638. this._connection.addEventListener('iceconnectionstatechange', function () {
  15639. var state = _this12._connection.iceConnectionState; // TODO: Do more with different states.
  15640. if (state === 'failed') {
  15641. _this12.terminate({
  15642. cause: JsSIP_C.causes.RTP_TIMEOUT,
  15643. status_code: 408,
  15644. reason_phrase: JsSIP_C.causes.RTP_TIMEOUT
  15645. });
  15646. }
  15647. });
  15648. logger.debug('emit "peerconnection"');
  15649. this.emit('peerconnection', {
  15650. peerconnection: this._connection
  15651. });
  15652. }
  15653. }, {
  15654. key: "_createLocalDescription",
  15655. value: function _createLocalDescription(type, constraints) {
  15656. var _this13 = this;
  15657. logger.debug('createLocalDescription()');
  15658. if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\""));
  15659. var connection = this._connection;
  15660. this._rtcReady = false;
  15661. return Promise.resolve() // Create Offer or Answer.
  15662. .then(function () {
  15663. if (type === 'offer') {
  15664. return connection.createOffer(constraints)["catch"](function (error) {
  15665. logger.warn('emit "peerconnection:createofferfailed" [error:%o]', error);
  15666. _this13.emit('peerconnection:createofferfailed', error);
  15667. return Promise.reject(error);
  15668. });
  15669. } else {
  15670. return connection.createAnswer(constraints)["catch"](function (error) {
  15671. logger.warn('emit "peerconnection:createanswerfailed" [error:%o]', error);
  15672. _this13.emit('peerconnection:createanswerfailed', error);
  15673. return Promise.reject(error);
  15674. });
  15675. }
  15676. }) // Set local description.
  15677. .then(function (desc) {
  15678. return connection.setLocalDescription(desc)["catch"](function (error) {
  15679. _this13._rtcReady = true;
  15680. logger.warn('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error);
  15681. _this13.emit('peerconnection:setlocaldescriptionfailed', error);
  15682. return Promise.reject(error);
  15683. });
  15684. }).then(function () {
  15685. // Resolve right away if 'pc.iceGatheringState' is 'complete'.
  15686. /**
  15687. * Resolve right away if:
  15688. * - 'connection.iceGatheringState' is 'complete' and no 'iceRestart' constraint is set.
  15689. * - 'connection.iceGatheringState' is 'gathering' and 'iceReady' is true.
  15690. */
  15691. var iceRestart = constraints && constraints.iceRestart;
  15692. if (connection.iceGatheringState === 'complete' && !iceRestart || connection.iceGatheringState === 'gathering' && _this13._iceReady) {
  15693. _this13._rtcReady = true;
  15694. var e = {
  15695. originator: 'local',
  15696. type: type,
  15697. sdp: connection.localDescription.sdp
  15698. };
  15699. logger.debug('emit "sdp"');
  15700. _this13.emit('sdp', e);
  15701. return Promise.resolve(e.sdp);
  15702. } // Add 'pc.onicencandidate' event handler to resolve on last candidate.
  15703. return new Promise(function (resolve) {
  15704. var finished = false;
  15705. var iceCandidateListener;
  15706. var iceGatheringStateListener;
  15707. _this13._iceReady = false;
  15708. var ready = function ready() {
  15709. connection.removeEventListener('icecandidate', iceCandidateListener);
  15710. connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener);
  15711. finished = true;
  15712. _this13._rtcReady = true; // connection.iceGatheringState will still indicate 'gathering' and thus be blocking.
  15713. _this13._iceReady = true;
  15714. var e = {
  15715. originator: 'local',
  15716. type: type,
  15717. sdp: connection.localDescription.sdp
  15718. };
  15719. logger.debug('emit "sdp"');
  15720. _this13.emit('sdp', e);
  15721. resolve(e.sdp);
  15722. };
  15723. connection.addEventListener('icecandidate', iceCandidateListener = function iceCandidateListener(event) {
  15724. var candidate = event.candidate;
  15725. if (candidate) {
  15726. _this13.emit('icecandidate', {
  15727. candidate: candidate,
  15728. ready: ready
  15729. });
  15730. } else if (!finished) {
  15731. ready();
  15732. }
  15733. });
  15734. connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = function iceGatheringStateListener() {
  15735. if (connection.iceGatheringState === 'complete' && !finished) {
  15736. ready();
  15737. }
  15738. });
  15739. });
  15740. });
  15741. }
  15742. /**
  15743. * Dialog Management
  15744. */
  15745. }, {
  15746. key: "_createDialog",
  15747. value: function _createDialog(message, type, early) {
  15748. var local_tag = type === 'UAS' ? message.to_tag : message.from_tag;
  15749. var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag;
  15750. var id = message.call_id + local_tag + remote_tag;
  15751. var early_dialog = this._earlyDialogs[id]; // Early Dialog.
  15752. if (early) {
  15753. if (early_dialog) {
  15754. return true;
  15755. } else {
  15756. early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created.
  15757. if (early_dialog.error) {
  15758. logger.debug(early_dialog.error);
  15759. this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  15760. return false;
  15761. } else {
  15762. this._earlyDialogs[id] = early_dialog;
  15763. return true;
  15764. }
  15765. }
  15766. } // Confirmed Dialog.
  15767. else {
  15768. this._from_tag = message.from_tag;
  15769. this._to_tag = message.to_tag; // In case the dialog is in _early_ state, update it.
  15770. if (early_dialog) {
  15771. early_dialog.update(message, type);
  15772. this._dialog = early_dialog;
  15773. delete this._earlyDialogs[id];
  15774. return true;
  15775. } // Otherwise, create a _confirmed_ dialog.
  15776. var dialog = new Dialog(this, message, type);
  15777. if (dialog.error) {
  15778. logger.debug(dialog.error);
  15779. this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
  15780. return false;
  15781. } else {
  15782. this._dialog = dialog;
  15783. return true;
  15784. }
  15785. }
  15786. }
  15787. /**
  15788. * In dialog INVITE Reception
  15789. */
  15790. }, {
  15791. key: "_receiveReinvite",
  15792. value: function _receiveReinvite(request) {
  15793. var _this14 = this;
  15794. logger.debug('receiveReinvite()');
  15795. var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined;
  15796. var data = {
  15797. request: request,
  15798. callback: undefined,
  15799. reject: reject.bind(this)
  15800. };
  15801. var rejected = false;
  15802. function reject() {
  15803. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15804. rejected = true;
  15805. var status_code = options.status_code || 403;
  15806. var reason_phrase = options.reason_phrase || '';
  15807. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  15808. if (this._status !== C.STATUS_CONFIRMED) {
  15809. return false;
  15810. }
  15811. if (status_code < 300 || status_code >= 700) {
  15812. throw new TypeError("Invalid status_code: ".concat(status_code));
  15813. }
  15814. request.reply(status_code, reason_phrase, extraHeaders);
  15815. } // Emit 'reinvite'.
  15816. this.emit('reinvite', data);
  15817. if (rejected) {
  15818. return;
  15819. }
  15820. this._late_sdp = false; // Request without SDP.
  15821. if (!request.body) {
  15822. this._late_sdp = true;
  15823. if (this._remoteHold) {
  15824. this._remoteHold = false;
  15825. this._onunhold('remote');
  15826. }
  15827. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  15828. return _this14._createLocalDescription('offer', _this14._rtcOfferConstraints);
  15829. }).then(function (sdp) {
  15830. sendAnswer.call(_this14, sdp);
  15831. })["catch"](function () {
  15832. request.reply(500);
  15833. });
  15834. return;
  15835. } // Request with SDP.
  15836. if (contentType !== 'application/sdp') {
  15837. logger.debug('invalid Content-Type');
  15838. request.reply(415);
  15839. return;
  15840. }
  15841. this._processInDialogSdpOffer(request) // Send answer.
  15842. .then(function (desc) {
  15843. if (_this14._status === C.STATUS_TERMINATED) {
  15844. return;
  15845. }
  15846. sendAnswer.call(_this14, desc);
  15847. })["catch"](function (error) {
  15848. logger.warn(error);
  15849. });
  15850. function sendAnswer(desc) {
  15851. var _this15 = this;
  15852. var extraHeaders = ["Contact: ".concat(this._contact)];
  15853. this._handleSessionTimersInIncomingRequest(request, extraHeaders);
  15854. if (this._late_sdp) {
  15855. desc = this._mangleOffer(desc);
  15856. }
  15857. request.reply(200, null, extraHeaders, desc, function () {
  15858. _this15._status = C.STATUS_WAITING_FOR_ACK;
  15859. _this15._setInvite2xxTimer(request, desc);
  15860. _this15._setACKTimer();
  15861. }); // If callback is given execute it.
  15862. if (typeof data.callback === 'function') {
  15863. data.callback();
  15864. }
  15865. }
  15866. }
  15867. /**
  15868. * In dialog UPDATE Reception
  15869. */
  15870. }, {
  15871. key: "_receiveUpdate",
  15872. value: function _receiveUpdate(request) {
  15873. var _this16 = this;
  15874. logger.debug('receiveUpdate()');
  15875. var contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined;
  15876. var data = {
  15877. request: request,
  15878. callback: undefined,
  15879. reject: reject.bind(this)
  15880. };
  15881. var rejected = false;
  15882. function reject() {
  15883. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  15884. rejected = true;
  15885. var status_code = options.status_code || 403;
  15886. var reason_phrase = options.reason_phrase || '';
  15887. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  15888. if (this._status !== C.STATUS_CONFIRMED) {
  15889. return false;
  15890. }
  15891. if (status_code < 300 || status_code >= 700) {
  15892. throw new TypeError("Invalid status_code: ".concat(status_code));
  15893. }
  15894. request.reply(status_code, reason_phrase, extraHeaders);
  15895. } // Emit 'update'.
  15896. this.emit('update', data);
  15897. if (rejected) {
  15898. return;
  15899. }
  15900. if (!request.body) {
  15901. sendAnswer.call(this, null);
  15902. return;
  15903. }
  15904. if (contentType !== 'application/sdp') {
  15905. logger.debug('invalid Content-Type');
  15906. request.reply(415);
  15907. return;
  15908. }
  15909. this._processInDialogSdpOffer(request) // Send answer.
  15910. .then(function (desc) {
  15911. if (_this16._status === C.STATUS_TERMINATED) {
  15912. return;
  15913. }
  15914. sendAnswer.call(_this16, desc);
  15915. })["catch"](function (error) {
  15916. logger.warn(error);
  15917. });
  15918. function sendAnswer(desc) {
  15919. var extraHeaders = ["Contact: ".concat(this._contact)];
  15920. this._handleSessionTimersInIncomingRequest(request, extraHeaders);
  15921. request.reply(200, null, extraHeaders, desc); // If callback is given execute it.
  15922. if (typeof data.callback === 'function') {
  15923. data.callback();
  15924. }
  15925. }
  15926. }
  15927. }, {
  15928. key: "_processInDialogSdpOffer",
  15929. value: function _processInDialogSdpOffer(request) {
  15930. var _this17 = this;
  15931. logger.debug('_processInDialogSdpOffer()');
  15932. var sdp = request.parseSDP();
  15933. var hold = false;
  15934. var _iterator4 = _createForOfIteratorHelper(sdp.media),
  15935. _step4;
  15936. try {
  15937. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  15938. var m = _step4.value;
  15939. if (holdMediaTypes.indexOf(m.type) === -1) {
  15940. continue;
  15941. }
  15942. var direction = m.direction || sdp.direction || 'sendrecv';
  15943. if (direction === 'sendonly' || direction === 'inactive') {
  15944. hold = true;
  15945. } // If at least one of the streams is active don't emit 'hold'.
  15946. else {
  15947. hold = false;
  15948. break;
  15949. }
  15950. }
  15951. } catch (err) {
  15952. _iterator4.e(err);
  15953. } finally {
  15954. _iterator4.f();
  15955. }
  15956. var e = {
  15957. originator: 'remote',
  15958. type: 'offer',
  15959. sdp: request.body
  15960. };
  15961. logger.debug('emit "sdp"');
  15962. this.emit('sdp', e);
  15963. var offer = new RTCSessionDescription({
  15964. type: 'offer',
  15965. sdp: e.sdp
  15966. });
  15967. this._connectionPromiseQueue = this._connectionPromiseQueue // Set remote description.
  15968. .then(function () {
  15969. if (_this17._status === C.STATUS_TERMINATED) {
  15970. throw new Error('terminated');
  15971. }
  15972. return _this17._connection.setRemoteDescription(offer)["catch"](function (error) {
  15973. request.reply(488);
  15974. logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  15975. _this17.emit('peerconnection:setremotedescriptionfailed', error);
  15976. throw error;
  15977. });
  15978. }).then(function () {
  15979. if (_this17._status === C.STATUS_TERMINATED) {
  15980. throw new Error('terminated');
  15981. }
  15982. if (_this17._remoteHold === true && hold === false) {
  15983. _this17._remoteHold = false;
  15984. _this17._onunhold('remote');
  15985. } else if (_this17._remoteHold === false && hold === true) {
  15986. _this17._remoteHold = true;
  15987. _this17._onhold('remote');
  15988. }
  15989. }) // Create local description.
  15990. .then(function () {
  15991. if (_this17._status === C.STATUS_TERMINATED) {
  15992. throw new Error('terminated');
  15993. }
  15994. return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints)["catch"](function (error) {
  15995. request.reply(500);
  15996. logger.warn('emit "peerconnection:createtelocaldescriptionfailed" [error:%o]', error);
  15997. throw error;
  15998. });
  15999. })["catch"](function (error) {
  16000. logger.warn('_processInDialogSdpOffer() failed [error: %o]', error);
  16001. });
  16002. return this._connectionPromiseQueue;
  16003. }
  16004. /**
  16005. * In dialog Refer Reception
  16006. */
  16007. }, {
  16008. key: "_receiveRefer",
  16009. value: function _receiveRefer(request) {
  16010. var _this18 = this;
  16011. logger.debug('receiveRefer()');
  16012. if (!request.refer_to) {
  16013. logger.debug('no Refer-To header field present in REFER');
  16014. request.reply(400);
  16015. return;
  16016. }
  16017. if (request.refer_to.uri.scheme !== JsSIP_C.SIP) {
  16018. logger.debug('Refer-To header field points to a non-SIP URI scheme');
  16019. request.reply(416);
  16020. return;
  16021. } // Reply before the transaction timer expires.
  16022. request.reply(202);
  16023. var notifier = new RTCSession_ReferNotifier(this, request.cseq);
  16024. logger.debug('emit "refer"'); // Emit 'refer'.
  16025. this.emit('refer', {
  16026. request: request,
  16027. accept: function accept(initCallback, options) {
  16028. _accept.call(_this18, initCallback, options);
  16029. },
  16030. reject: function reject() {
  16031. _reject.call(_this18);
  16032. }
  16033. });
  16034. function _accept(initCallback) {
  16035. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  16036. initCallback = typeof initCallback === 'function' ? initCallback : null;
  16037. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  16038. return false;
  16039. }
  16040. var session = new RTCSession(this._ua);
  16041. session.on('progress', function (_ref2) {
  16042. var response = _ref2.response;
  16043. notifier.notify(response.status_code, response.reason_phrase);
  16044. });
  16045. session.on('accepted', function (_ref3) {
  16046. var response = _ref3.response;
  16047. notifier.notify(response.status_code, response.reason_phrase);
  16048. });
  16049. session.on('_failed', function (_ref4) {
  16050. var message = _ref4.message,
  16051. cause = _ref4.cause;
  16052. if (message) {
  16053. notifier.notify(message.status_code, message.reason_phrase);
  16054. } else {
  16055. notifier.notify(487, cause);
  16056. }
  16057. }); // Consider the Replaces header present in the Refer-To URI.
  16058. if (request.refer_to.uri.hasHeader('replaces')) {
  16059. var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces'));
  16060. options.extraHeaders = Utils.cloneArray(options.extraHeaders);
  16061. options.extraHeaders.push("Replaces: ".concat(replaces));
  16062. }
  16063. session.connect(request.refer_to.uri.toAor(), options, initCallback);
  16064. }
  16065. function _reject() {
  16066. notifier.notify(603);
  16067. }
  16068. }
  16069. /**
  16070. * In dialog Notify Reception
  16071. */
  16072. }, {
  16073. key: "_receiveNotify",
  16074. value: function _receiveNotify(request) {
  16075. logger.debug('receiveNotify()');
  16076. if (!request.event) {
  16077. request.reply(400);
  16078. }
  16079. switch (request.event.event) {
  16080. case 'refer':
  16081. {
  16082. var id;
  16083. var referSubscriber;
  16084. if (request.event.params && request.event.params.id) {
  16085. id = request.event.params.id;
  16086. referSubscriber = this._referSubscribers[id];
  16087. } else if (Object.keys(this._referSubscribers).length === 1) {
  16088. referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]];
  16089. } else {
  16090. request.reply(400, 'Missing event id parameter');
  16091. return;
  16092. }
  16093. if (!referSubscriber) {
  16094. request.reply(481, 'Subscription does not exist');
  16095. return;
  16096. }
  16097. referSubscriber.receiveNotify(request);
  16098. request.reply(200);
  16099. break;
  16100. }
  16101. default:
  16102. {
  16103. request.reply(489);
  16104. }
  16105. }
  16106. }
  16107. /**
  16108. * INVITE with Replaces Reception
  16109. */
  16110. }, {
  16111. key: "_receiveReplaces",
  16112. value: function _receiveReplaces(request) {
  16113. var _this20 = this;
  16114. logger.debug('receiveReplaces()');
  16115. function _accept2(initCallback) {
  16116. var _this19 = this;
  16117. if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
  16118. return false;
  16119. }
  16120. var session = new RTCSession(this._ua); // Terminate the current session when the new one is confirmed.
  16121. session.on('confirmed', function () {
  16122. _this19.terminate();
  16123. });
  16124. session.init_incoming(request, initCallback);
  16125. }
  16126. function _reject2() {
  16127. logger.debug('Replaced INVITE rejected by the user');
  16128. request.reply(486);
  16129. } // Emit 'replace'.
  16130. this.emit('replaces', {
  16131. request: request,
  16132. accept: function accept(initCallback) {
  16133. _accept2.call(_this20, initCallback);
  16134. },
  16135. reject: function reject() {
  16136. _reject2.call(_this20);
  16137. }
  16138. });
  16139. }
  16140. /**
  16141. * Initial Request Sender
  16142. */
  16143. }, {
  16144. key: "_sendInitialRequest",
  16145. value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) {
  16146. var _this21 = this;
  16147. var request_sender = new RequestSender(this._ua, this._request, {
  16148. onRequestTimeout: function onRequestTimeout() {
  16149. _this21.onRequestTimeout();
  16150. },
  16151. onTransportError: function onTransportError() {
  16152. _this21.onTransportError();
  16153. },
  16154. // Update the request on authentication.
  16155. onAuthenticated: function onAuthenticated(request) {
  16156. _this21._request = request;
  16157. },
  16158. onReceiveResponse: function onReceiveResponse(response) {
  16159. _this21._receiveInviteResponse(response);
  16160. }
  16161. }); // This Promise is resolved within the next iteration, so the app has now
  16162. // a chance to set events such as 'peerconnection' and 'connecting'.
  16163. Promise.resolve() // Get a stream if required.
  16164. .then(function () {
  16165. // A stream is given, let the app set events such as 'peerconnection' and 'connecting'.
  16166. if (mediaStream) {
  16167. return mediaStream;
  16168. } // Request for user media access.
  16169. else if (mediaConstraints.audio || mediaConstraints.video) {
  16170. _this21._localMediaStreamLocallyGenerated = true;
  16171. return navigator.mediaDevices.getUserMedia(mediaConstraints)["catch"](function (error) {
  16172. if (_this21._status === C.STATUS_TERMINATED) {
  16173. throw new Error('terminated');
  16174. }
  16175. _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
  16176. logger.warn('emit "getusermediafailed" [error:%o]', error);
  16177. _this21.emit('getusermediafailed', error);
  16178. throw error;
  16179. });
  16180. }
  16181. }).then(function (stream) {
  16182. if (_this21._status === C.STATUS_TERMINATED) {
  16183. throw new Error('terminated');
  16184. }
  16185. _this21._localMediaStream = stream;
  16186. if (stream) {
  16187. stream.getTracks().forEach(function (track) {
  16188. _this21._connection.addTrack(track, stream);
  16189. });
  16190. } // TODO: should this be triggered here?
  16191. _this21._connecting(_this21._request);
  16192. return _this21._createLocalDescription('offer', rtcOfferConstraints)["catch"](function (error) {
  16193. _this21._failed('local', null, JsSIP_C.causes.WEBRTC_ERROR);
  16194. throw error;
  16195. });
  16196. }).then(function (desc) {
  16197. if (_this21._is_canceled || _this21._status === C.STATUS_TERMINATED) {
  16198. throw new Error('terminated');
  16199. }
  16200. _this21._request.body = desc;
  16201. _this21._status = C.STATUS_INVITE_SENT;
  16202. logger.debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent.
  16203. _this21.emit('sending', {
  16204. request: _this21._request
  16205. });
  16206. request_sender.send();
  16207. })["catch"](function (error) {
  16208. if (_this21._status === C.STATUS_TERMINATED) {
  16209. return;
  16210. }
  16211. logger.warn(error);
  16212. });
  16213. }
  16214. /**
  16215. * Get DTMF RTCRtpSender.
  16216. */
  16217. }, {
  16218. key: "_getDTMFRTPSender",
  16219. value: function _getDTMFRTPSender() {
  16220. var sender = this._connection.getSenders().find(function (rtpSender) {
  16221. return rtpSender.track && rtpSender.track.kind === 'audio';
  16222. });
  16223. if (!(sender && sender.dtmf)) {
  16224. logger.warn('sendDTMF() | no local audio track to send DTMF with');
  16225. return;
  16226. }
  16227. return sender.dtmf;
  16228. }
  16229. /**
  16230. * Reception of Response for Initial INVITE
  16231. */
  16232. }, {
  16233. key: "_receiveInviteResponse",
  16234. value: function _receiveInviteResponse(response) {
  16235. var _this22 = this;
  16236. logger.debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests.
  16237. if (this._dialog && response.status_code >= 200 && response.status_code <= 299) {
  16238. /*
  16239. * If it is a retransmission from the endpoint that established
  16240. * the dialog, send an ACK
  16241. */
  16242. 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) {
  16243. this.sendRequest(JsSIP_C.ACK);
  16244. return;
  16245. } // If not, send an ACK and terminate.
  16246. else {
  16247. var dialog = new Dialog(this, response, 'UAC');
  16248. if (dialog.error !== undefined) {
  16249. logger.debug(dialog.error);
  16250. return;
  16251. }
  16252. this.sendRequest(JsSIP_C.ACK);
  16253. this.sendRequest(JsSIP_C.BYE);
  16254. return;
  16255. }
  16256. } // Proceed to cancellation if the user requested.
  16257. if (this._is_canceled) {
  16258. if (response.status_code >= 100 && response.status_code < 200) {
  16259. this._request.cancel(this._cancel_reason);
  16260. } else if (response.status_code >= 200 && response.status_code < 299) {
  16261. this._acceptAndTerminate(response);
  16262. }
  16263. return;
  16264. }
  16265. if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) {
  16266. return;
  16267. }
  16268. switch (true) {
  16269. case /^100$/.test(response.status_code):
  16270. this._status = C.STATUS_1XX_RECEIVED;
  16271. break;
  16272. case /^1[0-9]{2}$/.test(response.status_code):
  16273. {
  16274. // Do nothing with 1xx responses without To tag.
  16275. if (!response.to_tag) {
  16276. logger.debug('1xx response received without to tag');
  16277. break;
  16278. } // Create Early Dialog if 1XX comes with contact.
  16279. if (response.hasHeader('contact')) {
  16280. // An error on dialog creation will fire 'failed' event.
  16281. if (!this._createDialog(response, 'UAC', true)) {
  16282. break;
  16283. }
  16284. }
  16285. this._status = C.STATUS_1XX_RECEIVED;
  16286. if (!response.body) {
  16287. this._progress('remote', response);
  16288. break;
  16289. }
  16290. var e = {
  16291. originator: 'remote',
  16292. type: 'answer',
  16293. sdp: response.body
  16294. };
  16295. logger.debug('emit "sdp"');
  16296. this.emit('sdp', e);
  16297. var answer = new RTCSessionDescription({
  16298. type: 'answer',
  16299. sdp: e.sdp
  16300. });
  16301. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16302. return _this22._connection.setRemoteDescription(answer);
  16303. }).then(function () {
  16304. return _this22._progress('remote', response);
  16305. })["catch"](function (error) {
  16306. logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16307. _this22.emit('peerconnection:setremotedescriptionfailed', error);
  16308. });
  16309. break;
  16310. }
  16311. case /^2[0-9]{2}$/.test(response.status_code):
  16312. {
  16313. this._status = C.STATUS_CONFIRMED;
  16314. if (!response.body) {
  16315. this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP);
  16316. this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  16317. break;
  16318. } // An error on dialog creation will fire 'failed' event.
  16319. if (!this._createDialog(response, 'UAC')) {
  16320. break;
  16321. }
  16322. var _e = {
  16323. originator: 'remote',
  16324. type: 'answer',
  16325. sdp: response.body
  16326. };
  16327. logger.debug('emit "sdp"');
  16328. this.emit('sdp', _e);
  16329. var _answer = new RTCSessionDescription({
  16330. type: 'answer',
  16331. sdp: _e.sdp
  16332. });
  16333. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16334. // Be ready for 200 with SDP after a 180/183 with SDP.
  16335. // We created a SDP 'answer' for it, so check the current signaling state.
  16336. if (_this22._connection.signalingState === 'stable') {
  16337. return _this22._connection.createOffer(_this22._rtcOfferConstraints).then(function (offer) {
  16338. return _this22._connection.setLocalDescription(offer);
  16339. })["catch"](function (error) {
  16340. _this22._acceptAndTerminate(response, 500, error.toString());
  16341. _this22._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR);
  16342. });
  16343. }
  16344. }).then(function () {
  16345. _this22._connection.setRemoteDescription(_answer).then(function () {
  16346. // Handle Session Timers.
  16347. _this22._handleSessionTimersInIncomingResponse(response);
  16348. _this22._accepted('remote', response);
  16349. _this22.sendRequest(JsSIP_C.ACK);
  16350. _this22._confirmed('local', null);
  16351. })["catch"](function (error) {
  16352. _this22._acceptAndTerminate(response, 488, 'Not Acceptable Here');
  16353. _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
  16354. logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16355. _this22.emit('peerconnection:setremotedescriptionfailed', error);
  16356. });
  16357. });
  16358. break;
  16359. }
  16360. default:
  16361. {
  16362. var cause = Utils.sipErrorCause(response.status_code);
  16363. this._failed('remote', response, cause);
  16364. }
  16365. }
  16366. }
  16367. /**
  16368. * Send Re-INVITE
  16369. */
  16370. }, {
  16371. key: "_sendReinvite",
  16372. value: function _sendReinvite() {
  16373. var _this23 = this;
  16374. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16375. logger.debug('sendReinvite()');
  16376. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16377. var eventHandlers = Utils.cloneObject(options.eventHandlers);
  16378. var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
  16379. var succeeded = false;
  16380. extraHeaders.push("Contact: ".concat(this._contact));
  16381. extraHeaders.push('Content-Type: application/sdp'); // Session Timers.
  16382. if (this._sessionTimers.running) {
  16383. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas'));
  16384. }
  16385. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16386. return _this23._createLocalDescription('offer', rtcOfferConstraints);
  16387. }).then(function (sdp) {
  16388. sdp = _this23._mangleOffer(sdp);
  16389. var e = {
  16390. originator: 'local',
  16391. type: 'offer',
  16392. sdp: sdp
  16393. };
  16394. logger.debug('emit "sdp"');
  16395. _this23.emit('sdp', e);
  16396. _this23.sendRequest(JsSIP_C.INVITE, {
  16397. extraHeaders: extraHeaders,
  16398. body: sdp,
  16399. eventHandlers: {
  16400. onSuccessResponse: function onSuccessResponse(response) {
  16401. onSucceeded.call(_this23, response);
  16402. succeeded = true;
  16403. },
  16404. onErrorResponse: function onErrorResponse(response) {
  16405. onFailed.call(_this23, response);
  16406. },
  16407. onTransportError: function onTransportError() {
  16408. _this23.onTransportError(); // Do nothing because session ends.
  16409. },
  16410. onRequestTimeout: function onRequestTimeout() {
  16411. _this23.onRequestTimeout(); // Do nothing because session ends.
  16412. },
  16413. onDialogError: function onDialogError() {
  16414. _this23.onDialogError(); // Do nothing because session ends.
  16415. }
  16416. }
  16417. });
  16418. })["catch"](function () {
  16419. onFailed();
  16420. });
  16421. function onSucceeded(response) {
  16422. var _this24 = this;
  16423. if (this._status === C.STATUS_TERMINATED) {
  16424. return;
  16425. }
  16426. this.sendRequest(JsSIP_C.ACK); // If it is a 2XX retransmission exit now.
  16427. if (succeeded) {
  16428. return;
  16429. } // Handle Session Timers.
  16430. this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer.
  16431. if (!response.body) {
  16432. onFailed.call(this);
  16433. return;
  16434. } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') {
  16435. onFailed.call(this);
  16436. return;
  16437. }
  16438. var e = {
  16439. originator: 'remote',
  16440. type: 'answer',
  16441. sdp: response.body
  16442. };
  16443. logger.debug('emit "sdp"');
  16444. this.emit('sdp', e);
  16445. var answer = new RTCSessionDescription({
  16446. type: 'answer',
  16447. sdp: e.sdp
  16448. });
  16449. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16450. return _this24._connection.setRemoteDescription(answer);
  16451. }).then(function () {
  16452. if (eventHandlers.succeeded) {
  16453. eventHandlers.succeeded(response);
  16454. }
  16455. })["catch"](function (error) {
  16456. onFailed.call(_this24);
  16457. logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16458. _this24.emit('peerconnection:setremotedescriptionfailed', error);
  16459. });
  16460. }
  16461. function onFailed(response) {
  16462. if (eventHandlers.failed) {
  16463. eventHandlers.failed(response);
  16464. }
  16465. }
  16466. }
  16467. /**
  16468. * Send UPDATE
  16469. */
  16470. }, {
  16471. key: "_sendUpdate",
  16472. value: function _sendUpdate() {
  16473. var _this25 = this;
  16474. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  16475. logger.debug('sendUpdate()');
  16476. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  16477. var eventHandlers = Utils.cloneObject(options.eventHandlers);
  16478. var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
  16479. var sdpOffer = options.sdpOffer || false;
  16480. var succeeded = false;
  16481. extraHeaders.push("Contact: ".concat(this._contact)); // Session Timers.
  16482. if (this._sessionTimers.running) {
  16483. extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas'));
  16484. }
  16485. if (sdpOffer) {
  16486. extraHeaders.push('Content-Type: application/sdp');
  16487. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16488. return _this25._createLocalDescription('offer', rtcOfferConstraints);
  16489. }).then(function (sdp) {
  16490. sdp = _this25._mangleOffer(sdp);
  16491. var e = {
  16492. originator: 'local',
  16493. type: 'offer',
  16494. sdp: sdp
  16495. };
  16496. logger.debug('emit "sdp"');
  16497. _this25.emit('sdp', e);
  16498. _this25.sendRequest(JsSIP_C.UPDATE, {
  16499. extraHeaders: extraHeaders,
  16500. body: sdp,
  16501. eventHandlers: {
  16502. onSuccessResponse: function onSuccessResponse(response) {
  16503. onSucceeded.call(_this25, response);
  16504. succeeded = true;
  16505. },
  16506. onErrorResponse: function onErrorResponse(response) {
  16507. onFailed.call(_this25, response);
  16508. },
  16509. onTransportError: function onTransportError() {
  16510. _this25.onTransportError(); // Do nothing because session ends.
  16511. },
  16512. onRequestTimeout: function onRequestTimeout() {
  16513. _this25.onRequestTimeout(); // Do nothing because session ends.
  16514. },
  16515. onDialogError: function onDialogError() {
  16516. _this25.onDialogError(); // Do nothing because session ends.
  16517. }
  16518. }
  16519. });
  16520. })["catch"](function () {
  16521. onFailed.call(_this25);
  16522. });
  16523. } // No SDP.
  16524. else {
  16525. this.sendRequest(JsSIP_C.UPDATE, {
  16526. extraHeaders: extraHeaders,
  16527. eventHandlers: {
  16528. onSuccessResponse: function onSuccessResponse(response) {
  16529. onSucceeded.call(_this25, response);
  16530. },
  16531. onErrorResponse: function onErrorResponse(response) {
  16532. onFailed.call(_this25, response);
  16533. },
  16534. onTransportError: function onTransportError() {
  16535. _this25.onTransportError(); // Do nothing because session ends.
  16536. },
  16537. onRequestTimeout: function onRequestTimeout() {
  16538. _this25.onRequestTimeout(); // Do nothing because session ends.
  16539. },
  16540. onDialogError: function onDialogError() {
  16541. _this25.onDialogError(); // Do nothing because session ends.
  16542. }
  16543. }
  16544. });
  16545. }
  16546. function onSucceeded(response) {
  16547. var _this26 = this;
  16548. if (this._status === C.STATUS_TERMINATED) {
  16549. return;
  16550. } // If it is a 2XX retransmission exit now.
  16551. if (succeeded) {
  16552. return;
  16553. } // Handle Session Timers.
  16554. this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer.
  16555. if (sdpOffer) {
  16556. if (!response.body) {
  16557. onFailed.call(this);
  16558. return;
  16559. } else if (!response.hasHeader('Content-Type') || response.getHeader('Content-Type').toLowerCase() !== 'application/sdp') {
  16560. onFailed.call(this);
  16561. return;
  16562. }
  16563. var e = {
  16564. originator: 'remote',
  16565. type: 'answer',
  16566. sdp: response.body
  16567. };
  16568. logger.debug('emit "sdp"');
  16569. this.emit('sdp', e);
  16570. var answer = new RTCSessionDescription({
  16571. type: 'answer',
  16572. sdp: e.sdp
  16573. });
  16574. this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
  16575. return _this26._connection.setRemoteDescription(answer);
  16576. }).then(function () {
  16577. if (eventHandlers.succeeded) {
  16578. eventHandlers.succeeded(response);
  16579. }
  16580. })["catch"](function (error) {
  16581. onFailed.call(_this26);
  16582. logger.warn('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
  16583. _this26.emit('peerconnection:setremotedescriptionfailed', error);
  16584. });
  16585. } // No SDP answer.
  16586. else if (eventHandlers.succeeded) {
  16587. eventHandlers.succeeded(response);
  16588. }
  16589. }
  16590. function onFailed(response) {
  16591. if (eventHandlers.failed) {
  16592. eventHandlers.failed(response);
  16593. }
  16594. }
  16595. }
  16596. }, {
  16597. key: "_acceptAndTerminate",
  16598. value: function _acceptAndTerminate(response, status_code, reason_phrase) {
  16599. logger.debug('acceptAndTerminate()');
  16600. var extraHeaders = [];
  16601. if (status_code) {
  16602. reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
  16603. extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\""));
  16604. } // An error on dialog creation will fire 'failed' event.
  16605. if (this._dialog || this._createDialog(response, 'UAC')) {
  16606. this.sendRequest(JsSIP_C.ACK);
  16607. this.sendRequest(JsSIP_C.BYE, {
  16608. extraHeaders: extraHeaders
  16609. });
  16610. } // Update session status.
  16611. this._status = C.STATUS_TERMINATED;
  16612. }
  16613. /**
  16614. * Correctly set the SDP direction attributes if the call is on local hold
  16615. */
  16616. }, {
  16617. key: "_mangleOffer",
  16618. value: function _mangleOffer(sdp) {
  16619. if (!this._localHold && !this._remoteHold) {
  16620. return sdp;
  16621. }
  16622. sdp = sdp_transform.parse(sdp); // Local hold.
  16623. if (this._localHold && !this._remoteHold) {
  16624. logger.debug('mangleOffer() | me on hold, mangling offer');
  16625. var _iterator5 = _createForOfIteratorHelper(sdp.media),
  16626. _step5;
  16627. try {
  16628. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  16629. var m = _step5.value;
  16630. if (holdMediaTypes.indexOf(m.type) === -1) {
  16631. continue;
  16632. }
  16633. if (!m.direction) {
  16634. m.direction = 'sendonly';
  16635. } else if (m.direction === 'sendrecv') {
  16636. m.direction = 'sendonly';
  16637. } else if (m.direction === 'recvonly') {
  16638. m.direction = 'inactive';
  16639. }
  16640. }
  16641. } catch (err) {
  16642. _iterator5.e(err);
  16643. } finally {
  16644. _iterator5.f();
  16645. }
  16646. } // Local and remote hold.
  16647. else if (this._localHold && this._remoteHold) {
  16648. logger.debug('mangleOffer() | both on hold, mangling offer');
  16649. var _iterator6 = _createForOfIteratorHelper(sdp.media),
  16650. _step6;
  16651. try {
  16652. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  16653. var _m = _step6.value;
  16654. if (holdMediaTypes.indexOf(_m.type) === -1) {
  16655. continue;
  16656. }
  16657. _m.direction = 'inactive';
  16658. }
  16659. } catch (err) {
  16660. _iterator6.e(err);
  16661. } finally {
  16662. _iterator6.f();
  16663. }
  16664. } // Remote hold.
  16665. else if (this._remoteHold) {
  16666. logger.debug('mangleOffer() | remote on hold, mangling offer');
  16667. var _iterator7 = _createForOfIteratorHelper(sdp.media),
  16668. _step7;
  16669. try {
  16670. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  16671. var _m2 = _step7.value;
  16672. if (holdMediaTypes.indexOf(_m2.type) === -1) {
  16673. continue;
  16674. }
  16675. if (!_m2.direction) {
  16676. _m2.direction = 'recvonly';
  16677. } else if (_m2.direction === 'sendrecv') {
  16678. _m2.direction = 'recvonly';
  16679. } else if (_m2.direction === 'recvonly') {
  16680. _m2.direction = 'inactive';
  16681. }
  16682. }
  16683. } catch (err) {
  16684. _iterator7.e(err);
  16685. } finally {
  16686. _iterator7.f();
  16687. }
  16688. }
  16689. return sdp_transform.write(sdp);
  16690. }
  16691. }, {
  16692. key: "_setLocalMediaStatus",
  16693. value: function _setLocalMediaStatus() {
  16694. var enableAudio = true,
  16695. enableVideo = true;
  16696. if (this._localHold || this._remoteHold) {
  16697. enableAudio = false;
  16698. enableVideo = false;
  16699. }
  16700. if (this._audioMuted) {
  16701. enableAudio = false;
  16702. }
  16703. if (this._videoMuted) {
  16704. enableVideo = false;
  16705. }
  16706. this._toggleMuteAudio(!enableAudio);
  16707. this._toggleMuteVideo(!enableVideo);
  16708. }
  16709. /**
  16710. * Handle SessionTimers for an incoming INVITE or UPDATE.
  16711. * @param {IncomingRequest} request
  16712. * @param {Array} responseExtraHeaders Extra headers for the 200 response.
  16713. */
  16714. }, {
  16715. key: "_handleSessionTimersInIncomingRequest",
  16716. value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) {
  16717. if (!this._sessionTimers.enabled) {
  16718. return;
  16719. }
  16720. var session_expires_refresher;
  16721. if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  16722. this._sessionTimers.currentExpires = request.session_expires;
  16723. session_expires_refresher = request.session_expires_refresher || 'uas';
  16724. } else {
  16725. this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
  16726. session_expires_refresher = 'uas';
  16727. }
  16728. responseExtraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(session_expires_refresher));
  16729. this._sessionTimers.refresher = session_expires_refresher === 'uas';
  16730. this._runSessionTimer();
  16731. }
  16732. /**
  16733. * Handle SessionTimers for an incoming response to INVITE or UPDATE.
  16734. * @param {IncomingResponse} response
  16735. */
  16736. }, {
  16737. key: "_handleSessionTimersInIncomingResponse",
  16738. value: function _handleSessionTimersInIncomingResponse(response) {
  16739. if (!this._sessionTimers.enabled) {
  16740. return;
  16741. }
  16742. var session_expires_refresher;
  16743. if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
  16744. this._sessionTimers.currentExpires = response.session_expires;
  16745. session_expires_refresher = response.session_expires_refresher || 'uac';
  16746. } else {
  16747. this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
  16748. session_expires_refresher = 'uac';
  16749. }
  16750. this._sessionTimers.refresher = session_expires_refresher === 'uac';
  16751. this._runSessionTimer();
  16752. }
  16753. }, {
  16754. key: "_runSessionTimer",
  16755. value: function _runSessionTimer() {
  16756. var _this27 = this;
  16757. var expires = this._sessionTimers.currentExpires;
  16758. this._sessionTimers.running = true;
  16759. clearTimeout(this._sessionTimers.timer); // I'm the refresher.
  16760. if (this._sessionTimers.refresher) {
  16761. this._sessionTimers.timer = setTimeout(function () {
  16762. if (_this27._status === C.STATUS_TERMINATED) {
  16763. return;
  16764. }
  16765. if (!_this27._isReadyToReOffer()) {
  16766. return;
  16767. }
  16768. logger.debug('runSessionTimer() | sending session refresh request');
  16769. if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) {
  16770. _this27._sendUpdate();
  16771. } else {
  16772. _this27._sendReinvite();
  16773. }
  16774. }, expires * 500); // Half the given interval (as the RFC states).
  16775. } // I'm not the refresher.
  16776. else {
  16777. this._sessionTimers.timer = setTimeout(function () {
  16778. if (_this27._status === C.STATUS_TERMINATED) {
  16779. return;
  16780. }
  16781. logger.warn('runSessionTimer() | timer expired, terminating the session');
  16782. _this27.terminate({
  16783. cause: JsSIP_C.causes.REQUEST_TIMEOUT,
  16784. status_code: 408,
  16785. reason_phrase: 'Session Timer Expired'
  16786. });
  16787. }, expires * 1100);
  16788. }
  16789. }
  16790. }, {
  16791. key: "_toggleMuteAudio",
  16792. value: function _toggleMuteAudio(mute) {
  16793. var senders = this._connection.getSenders().filter(function (sender) {
  16794. return sender.track && sender.track.kind === 'audio';
  16795. });
  16796. var _iterator8 = _createForOfIteratorHelper(senders),
  16797. _step8;
  16798. try {
  16799. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  16800. var sender = _step8.value;
  16801. sender.track.enabled = !mute;
  16802. }
  16803. } catch (err) {
  16804. _iterator8.e(err);
  16805. } finally {
  16806. _iterator8.f();
  16807. }
  16808. }
  16809. }, {
  16810. key: "_toggleMuteVideo",
  16811. value: function _toggleMuteVideo(mute) {
  16812. var senders = this._connection.getSenders().filter(function (sender) {
  16813. return sender.track && sender.track.kind === 'video';
  16814. });
  16815. var _iterator9 = _createForOfIteratorHelper(senders),
  16816. _step9;
  16817. try {
  16818. for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
  16819. var sender = _step9.value;
  16820. sender.track.enabled = !mute;
  16821. }
  16822. } catch (err) {
  16823. _iterator9.e(err);
  16824. } finally {
  16825. _iterator9.f();
  16826. }
  16827. }
  16828. }, {
  16829. key: "_newRTCSession",
  16830. value: function _newRTCSession(originator, request) {
  16831. logger.debug('newRTCSession()');
  16832. this._ua.newRTCSession(this, {
  16833. originator: originator,
  16834. session: this,
  16835. request: request
  16836. });
  16837. }
  16838. }, {
  16839. key: "_connecting",
  16840. value: function _connecting(request) {
  16841. logger.debug('session connecting');
  16842. logger.debug('emit "connecting"');
  16843. this.emit('connecting', {
  16844. request: request
  16845. });
  16846. }
  16847. }, {
  16848. key: "_progress",
  16849. value: function _progress(originator, response) {
  16850. logger.debug('session progress');
  16851. logger.debug('emit "progress"');
  16852. this.emit('progress', {
  16853. originator: originator,
  16854. response: response || null
  16855. });
  16856. }
  16857. }, {
  16858. key: "_accepted",
  16859. value: function _accepted(originator, message) {
  16860. logger.debug('session accepted');
  16861. this._start_time = new Date();
  16862. logger.debug('emit "accepted"');
  16863. this.emit('accepted', {
  16864. originator: originator,
  16865. response: message || null
  16866. });
  16867. }
  16868. }, {
  16869. key: "_confirmed",
  16870. value: function _confirmed(originator, ack) {
  16871. logger.debug('session confirmed');
  16872. this._is_confirmed = true;
  16873. logger.debug('emit "confirmed"');
  16874. this.emit('confirmed', {
  16875. originator: originator,
  16876. ack: ack || null
  16877. });
  16878. }
  16879. }, {
  16880. key: "_ended",
  16881. value: function _ended(originator, message, cause) {
  16882. logger.debug('session ended');
  16883. this._end_time = new Date();
  16884. this._close();
  16885. logger.debug('emit "ended"');
  16886. this.emit('ended', {
  16887. originator: originator,
  16888. message: message || null,
  16889. cause: cause
  16890. });
  16891. }
  16892. }, {
  16893. key: "_failed",
  16894. value: function _failed(originator, message, cause) {
  16895. logger.debug('session failed'); // Emit private '_failed' event first.
  16896. logger.debug('emit "_failed"');
  16897. this.emit('_failed', {
  16898. originator: originator,
  16899. message: message || null,
  16900. cause: cause
  16901. });
  16902. this._close();
  16903. logger.debug('emit "failed"');
  16904. this.emit('failed', {
  16905. originator: originator,
  16906. message: message || null,
  16907. cause: cause
  16908. });
  16909. }
  16910. }, {
  16911. key: "_onhold",
  16912. value: function _onhold(originator) {
  16913. logger.debug('session onhold');
  16914. this._setLocalMediaStatus();
  16915. logger.debug('emit "hold"');
  16916. this.emit('hold', {
  16917. originator: originator
  16918. });
  16919. }
  16920. }, {
  16921. key: "_onunhold",
  16922. value: function _onunhold(originator) {
  16923. logger.debug('session onunhold');
  16924. this._setLocalMediaStatus();
  16925. logger.debug('emit "unhold"');
  16926. this.emit('unhold', {
  16927. originator: originator
  16928. });
  16929. }
  16930. }, {
  16931. key: "_onmute",
  16932. value: function _onmute(_ref5) {
  16933. var audio = _ref5.audio,
  16934. video = _ref5.video;
  16935. logger.debug('session onmute');
  16936. this._setLocalMediaStatus();
  16937. logger.debug('emit "muted"');
  16938. this.emit('muted', {
  16939. audio: audio,
  16940. video: video
  16941. });
  16942. }
  16943. }, {
  16944. key: "_onunmute",
  16945. value: function _onunmute(_ref6) {
  16946. var audio = _ref6.audio,
  16947. video = _ref6.video;
  16948. logger.debug('session onunmute');
  16949. this._setLocalMediaStatus();
  16950. logger.debug('emit "unmuted"');
  16951. this.emit('unmuted', {
  16952. audio: audio,
  16953. video: video
  16954. });
  16955. }
  16956. }, {
  16957. key: "C",
  16958. get: function get() {
  16959. return C;
  16960. } // Expose session failed/ended causes as a property of the RTCSession instance.
  16961. }, {
  16962. key: "causes",
  16963. get: function get() {
  16964. return JsSIP_C.causes;
  16965. }
  16966. }, {
  16967. key: "id",
  16968. get: function get() {
  16969. return this._id;
  16970. }
  16971. }, {
  16972. key: "connection",
  16973. get: function get() {
  16974. return this._connection;
  16975. }
  16976. }, {
  16977. key: "contact",
  16978. get: function get() {
  16979. return this._contact;
  16980. }
  16981. }, {
  16982. key: "direction",
  16983. get: function get() {
  16984. return this._direction;
  16985. }
  16986. }, {
  16987. key: "local_identity",
  16988. get: function get() {
  16989. return this._local_identity;
  16990. }
  16991. }, {
  16992. key: "remote_identity",
  16993. get: function get() {
  16994. return this._remote_identity;
  16995. }
  16996. }, {
  16997. key: "start_time",
  16998. get: function get() {
  16999. return this._start_time;
  17000. }
  17001. }, {
  17002. key: "end_time",
  17003. get: function get() {
  17004. return this._end_time;
  17005. }
  17006. }, {
  17007. key: "data",
  17008. get: function get() {
  17009. return this._data;
  17010. },
  17011. set: function set(_data) {
  17012. this._data = _data;
  17013. }
  17014. }, {
  17015. key: "status",
  17016. get: function get() {
  17017. return this._status;
  17018. }
  17019. }]);
  17020. return RTCSession;
  17021. }(EventEmitter);
  17022. },{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./Logger":9,"./RTCSession/DTMF":15,"./RTCSession/Info":16,"./RTCSession/ReferNotifier":17,"./RTCSession/ReferSubscriber":18,"./RequestSender":20,"./SIPMessage":21,"./Timers":23,"./Transactions":24,"./URI":27,"./Utils":28,"events":31,"sdp-transform":37}],15:[function(require,module,exports){
  17023. "use strict";
  17024. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  17025. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17026. 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); } }
  17027. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17028. 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); }
  17029. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17030. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17031. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17032. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17033. 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; } }
  17034. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17035. var EventEmitter = require('events').EventEmitter;
  17036. var Logger = require('../Logger');
  17037. var JsSIP_C = require('../Constants');
  17038. var Exceptions = require('../Exceptions');
  17039. var Utils = require('../Utils');
  17040. var logger = new Logger('RTCSession:DTMF');
  17041. var C = {
  17042. MIN_DURATION: 70,
  17043. MAX_DURATION: 6000,
  17044. DEFAULT_DURATION: 100,
  17045. MIN_INTER_TONE_GAP: 50,
  17046. DEFAULT_INTER_TONE_GAP: 500
  17047. };
  17048. module.exports = /*#__PURE__*/function (_EventEmitter) {
  17049. _inherits(DTMF, _EventEmitter);
  17050. var _super = _createSuper(DTMF);
  17051. function DTMF(session) {
  17052. var _this;
  17053. _classCallCheck(this, DTMF);
  17054. _this = _super.call(this);
  17055. _this._session = session;
  17056. _this._direction = null;
  17057. _this._tone = null;
  17058. _this._duration = null;
  17059. _this._request = null;
  17060. return _this;
  17061. }
  17062. _createClass(DTMF, [{
  17063. key: "send",
  17064. value: function send(tone) {
  17065. var _this2 = this;
  17066. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  17067. if (tone === undefined) {
  17068. throw new TypeError('Not enough arguments');
  17069. }
  17070. this._direction = 'outgoing'; // Check RTCSession Status.
  17071. if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
  17072. throw new Exceptions.InvalidStateError(this._session.status);
  17073. }
  17074. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  17075. this.eventHandlers = Utils.cloneObject(options.eventHandlers); // Check tone type.
  17076. if (typeof tone === 'string') {
  17077. tone = tone.toUpperCase();
  17078. } else if (typeof tone === 'number') {
  17079. tone = tone.toString();
  17080. } else {
  17081. throw new TypeError("Invalid tone: ".concat(tone));
  17082. } // Check tone value.
  17083. if (!tone.match(/^[0-9A-DR#*]$/)) {
  17084. throw new TypeError("Invalid tone: ".concat(tone));
  17085. } else {
  17086. this._tone = tone;
  17087. } // Duration is checked/corrected in RTCSession.
  17088. this._duration = options.duration;
  17089. extraHeaders.push('Content-Type: application/dtmf-relay');
  17090. var body = "Signal=".concat(this._tone, "\r\n");
  17091. body += "Duration=".concat(this._duration);
  17092. this._session.newDTMF({
  17093. originator: 'local',
  17094. dtmf: this,
  17095. request: this._request
  17096. });
  17097. this._session.sendRequest(JsSIP_C.INFO, {
  17098. extraHeaders: extraHeaders,
  17099. eventHandlers: {
  17100. onSuccessResponse: function onSuccessResponse(response) {
  17101. _this2.emit('succeeded', {
  17102. originator: 'remote',
  17103. response: response
  17104. });
  17105. },
  17106. onErrorResponse: function onErrorResponse(response) {
  17107. if (_this2.eventHandlers.onFailed) {
  17108. _this2.eventHandlers.onFailed();
  17109. }
  17110. _this2.emit('failed', {
  17111. originator: 'remote',
  17112. response: response
  17113. });
  17114. },
  17115. onRequestTimeout: function onRequestTimeout() {
  17116. _this2._session.onRequestTimeout();
  17117. },
  17118. onTransportError: function onTransportError() {
  17119. _this2._session.onTransportError();
  17120. },
  17121. onDialogError: function onDialogError() {
  17122. _this2._session.onDialogError();
  17123. }
  17124. },
  17125. body: body
  17126. });
  17127. }
  17128. }, {
  17129. key: "init_incoming",
  17130. value: function init_incoming(request) {
  17131. var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;
  17132. var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;
  17133. this._direction = 'incoming';
  17134. this._request = request;
  17135. request.reply(200);
  17136. if (request.body) {
  17137. var body = request.body.split('\n');
  17138. if (body.length >= 1) {
  17139. if (reg_tone.test(body[0])) {
  17140. this._tone = body[0].replace(reg_tone, '$2');
  17141. }
  17142. }
  17143. if (body.length >= 2) {
  17144. if (reg_duration.test(body[1])) {
  17145. this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10);
  17146. }
  17147. }
  17148. }
  17149. if (!this._duration) {
  17150. this._duration = C.DEFAULT_DURATION;
  17151. }
  17152. if (!this._tone) {
  17153. logger.debug('invalid INFO DTMF received, discarded');
  17154. } else {
  17155. this._session.newDTMF({
  17156. originator: 'remote',
  17157. dtmf: this,
  17158. request: request
  17159. });
  17160. }
  17161. }
  17162. }, {
  17163. key: "tone",
  17164. get: function get() {
  17165. return this._tone;
  17166. }
  17167. }, {
  17168. key: "duration",
  17169. get: function get() {
  17170. return this._duration;
  17171. }
  17172. }]);
  17173. return DTMF;
  17174. }(EventEmitter);
  17175. /**
  17176. * Expose C object.
  17177. */
  17178. module.exports.C = C;
  17179. },{"../Constants":2,"../Exceptions":6,"../Logger":9,"../Utils":28,"events":31}],16:[function(require,module,exports){
  17180. "use strict";
  17181. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  17182. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17183. 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); } }
  17184. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17185. 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); }
  17186. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17187. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17188. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17189. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17190. 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; } }
  17191. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17192. var EventEmitter = require('events').EventEmitter;
  17193. var JsSIP_C = require('../Constants');
  17194. var Exceptions = require('../Exceptions');
  17195. var Utils = require('../Utils');
  17196. module.exports = /*#__PURE__*/function (_EventEmitter) {
  17197. _inherits(Info, _EventEmitter);
  17198. var _super = _createSuper(Info);
  17199. function Info(session) {
  17200. var _this;
  17201. _classCallCheck(this, Info);
  17202. _this = _super.call(this);
  17203. _this._session = session;
  17204. _this._direction = null;
  17205. _this._contentType = null;
  17206. _this._body = null;
  17207. return _this;
  17208. }
  17209. _createClass(Info, [{
  17210. key: "send",
  17211. value: function send(contentType, body) {
  17212. var _this2 = this;
  17213. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  17214. this._direction = 'outgoing';
  17215. if (contentType === undefined) {
  17216. throw new TypeError('Not enough arguments');
  17217. } // Check RTCSession Status.
  17218. if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
  17219. throw new Exceptions.InvalidStateError(this._session.status);
  17220. }
  17221. this._contentType = contentType;
  17222. this._body = body;
  17223. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  17224. extraHeaders.push("Content-Type: ".concat(contentType));
  17225. this._session.newInfo({
  17226. originator: 'local',
  17227. info: this,
  17228. request: this.request
  17229. });
  17230. this._session.sendRequest(JsSIP_C.INFO, {
  17231. extraHeaders: extraHeaders,
  17232. eventHandlers: {
  17233. onSuccessResponse: function onSuccessResponse(response) {
  17234. _this2.emit('succeeded', {
  17235. originator: 'remote',
  17236. response: response
  17237. });
  17238. },
  17239. onErrorResponse: function onErrorResponse(response) {
  17240. _this2.emit('failed', {
  17241. originator: 'remote',
  17242. response: response
  17243. });
  17244. },
  17245. onTransportError: function onTransportError() {
  17246. _this2._session.onTransportError();
  17247. },
  17248. onRequestTimeout: function onRequestTimeout() {
  17249. _this2._session.onRequestTimeout();
  17250. },
  17251. onDialogError: function onDialogError() {
  17252. _this2._session.onDialogError();
  17253. }
  17254. },
  17255. body: body
  17256. });
  17257. }
  17258. }, {
  17259. key: "init_incoming",
  17260. value: function init_incoming(request) {
  17261. this._direction = 'incoming';
  17262. this.request = request;
  17263. request.reply(200);
  17264. this._contentType = request.hasHeader('Content-Type') ? request.getHeader('Content-Type').toLowerCase() : undefined;
  17265. this._body = request.body;
  17266. this._session.newInfo({
  17267. originator: 'remote',
  17268. info: this,
  17269. request: request
  17270. });
  17271. }
  17272. }, {
  17273. key: "contentType",
  17274. get: function get() {
  17275. return this._contentType;
  17276. }
  17277. }, {
  17278. key: "body",
  17279. get: function get() {
  17280. return this._body;
  17281. }
  17282. }]);
  17283. return Info;
  17284. }(EventEmitter);
  17285. },{"../Constants":2,"../Exceptions":6,"../Utils":28,"events":31}],17:[function(require,module,exports){
  17286. "use strict";
  17287. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17288. 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); } }
  17289. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17290. var Logger = require('../Logger');
  17291. var JsSIP_C = require('../Constants');
  17292. var logger = new Logger('RTCSession:ReferNotifier');
  17293. var C = {
  17294. event_type: 'refer',
  17295. body_type: 'message/sipfrag;version=2.0',
  17296. expires: 300
  17297. };
  17298. module.exports = /*#__PURE__*/function () {
  17299. function ReferNotifier(session, id, expires) {
  17300. _classCallCheck(this, ReferNotifier);
  17301. this._session = session;
  17302. this._id = id;
  17303. this._expires = expires || C.expires;
  17304. this._active = true; // The creation of a Notifier results in an immediate NOTIFY.
  17305. this.notify(100);
  17306. }
  17307. _createClass(ReferNotifier, [{
  17308. key: "notify",
  17309. value: function notify(code, reason) {
  17310. logger.debug('notify()');
  17311. if (this._active === false) {
  17312. return;
  17313. }
  17314. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  17315. var state;
  17316. if (code >= 200) {
  17317. state = 'terminated;reason=noresource';
  17318. } else {
  17319. state = "active;expires=".concat(this._expires);
  17320. } // Put this in a try/catch block.
  17321. this._session.sendRequest(JsSIP_C.NOTIFY, {
  17322. extraHeaders: ["Event: ".concat(C.event_type, ";id=").concat(this._id), "Subscription-State: ".concat(state), "Content-Type: ".concat(C.body_type)],
  17323. body: "SIP/2.0 ".concat(code, " ").concat(reason),
  17324. eventHandlers: {
  17325. // If a negative response is received, subscription is canceled.
  17326. onErrorResponse: function onErrorResponse() {
  17327. this._active = false;
  17328. }
  17329. }
  17330. });
  17331. }
  17332. }]);
  17333. return ReferNotifier;
  17334. }();
  17335. },{"../Constants":2,"../Logger":9}],18:[function(require,module,exports){
  17336. "use strict";
  17337. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  17338. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17339. 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); } }
  17340. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17341. 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); }
  17342. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17343. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17344. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17345. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17346. 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; } }
  17347. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17348. var EventEmitter = require('events').EventEmitter;
  17349. var Logger = require('../Logger');
  17350. var JsSIP_C = require('../Constants');
  17351. var Grammar = require('../Grammar');
  17352. var Utils = require('../Utils');
  17353. var logger = new Logger('RTCSession:ReferSubscriber');
  17354. module.exports = /*#__PURE__*/function (_EventEmitter) {
  17355. _inherits(ReferSubscriber, _EventEmitter);
  17356. var _super = _createSuper(ReferSubscriber);
  17357. function ReferSubscriber(session) {
  17358. var _this;
  17359. _classCallCheck(this, ReferSubscriber);
  17360. _this = _super.call(this);
  17361. _this._id = null;
  17362. _this._session = session;
  17363. return _this;
  17364. }
  17365. _createClass(ReferSubscriber, [{
  17366. key: "sendRefer",
  17367. value: function sendRefer(target) {
  17368. var _this2 = this;
  17369. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  17370. logger.debug('sendRefer()');
  17371. var extraHeaders = Utils.cloneArray(options.extraHeaders);
  17372. var eventHandlers = Utils.cloneObject(options.eventHandlers); // Set event handlers.
  17373. for (var event in eventHandlers) {
  17374. if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
  17375. this.on(event, eventHandlers[event]);
  17376. }
  17377. } // Replaces URI header field.
  17378. var replaces = null;
  17379. if (options.replaces) {
  17380. replaces = options.replaces._request.call_id;
  17381. replaces += ";to-tag=".concat(options.replaces._to_tag);
  17382. replaces += ";from-tag=".concat(options.replaces._from_tag);
  17383. replaces = encodeURIComponent(replaces);
  17384. } // Refer-To header field.
  17385. var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">");
  17386. extraHeaders.push(referTo); // Referred-By header field (if not already present).
  17387. if (!extraHeaders.some(function (header) {
  17388. return header.toLowerCase().startsWith('referred-by:');
  17389. })) {
  17390. 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, ">");
  17391. extraHeaders.push(referredBy);
  17392. }
  17393. extraHeaders.push("Contact: ".concat(this._session.contact));
  17394. var request = this._session.sendRequest(JsSIP_C.REFER, {
  17395. extraHeaders: extraHeaders,
  17396. eventHandlers: {
  17397. onSuccessResponse: function onSuccessResponse(response) {
  17398. _this2._requestSucceeded(response);
  17399. },
  17400. onErrorResponse: function onErrorResponse(response) {
  17401. _this2._requestFailed(response, JsSIP_C.causes.REJECTED);
  17402. },
  17403. onTransportError: function onTransportError() {
  17404. _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR);
  17405. },
  17406. onRequestTimeout: function onRequestTimeout() {
  17407. _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17408. },
  17409. onDialogError: function onDialogError() {
  17410. _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR);
  17411. }
  17412. }
  17413. });
  17414. this._id = request.cseq;
  17415. }
  17416. }, {
  17417. key: "receiveNotify",
  17418. value: function receiveNotify(request) {
  17419. logger.debug('receiveNotify()');
  17420. if (!request.body) {
  17421. return;
  17422. }
  17423. var status_line = Grammar.parse(request.body.trim(), 'Status_Line');
  17424. if (status_line === -1) {
  17425. logger.debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\""));
  17426. return;
  17427. }
  17428. switch (true) {
  17429. case /^100$/.test(status_line.status_code):
  17430. this.emit('trying', {
  17431. request: request,
  17432. status_line: status_line
  17433. });
  17434. break;
  17435. case /^1[0-9]{2}$/.test(status_line.status_code):
  17436. this.emit('progress', {
  17437. request: request,
  17438. status_line: status_line
  17439. });
  17440. break;
  17441. case /^2[0-9]{2}$/.test(status_line.status_code):
  17442. this.emit('accepted', {
  17443. request: request,
  17444. status_line: status_line
  17445. });
  17446. break;
  17447. default:
  17448. this.emit('failed', {
  17449. request: request,
  17450. status_line: status_line
  17451. });
  17452. break;
  17453. }
  17454. }
  17455. }, {
  17456. key: "_requestSucceeded",
  17457. value: function _requestSucceeded(response) {
  17458. logger.debug('REFER succeeded');
  17459. logger.debug('emit "requestSucceeded"');
  17460. this.emit('requestSucceeded', {
  17461. response: response
  17462. });
  17463. }
  17464. }, {
  17465. key: "_requestFailed",
  17466. value: function _requestFailed(response, cause) {
  17467. logger.debug('REFER failed');
  17468. logger.debug('emit "requestFailed"');
  17469. this.emit('requestFailed', {
  17470. response: response || null,
  17471. cause: cause
  17472. });
  17473. }
  17474. }, {
  17475. key: "id",
  17476. get: function get() {
  17477. return this._id;
  17478. }
  17479. }]);
  17480. return ReferSubscriber;
  17481. }(EventEmitter);
  17482. },{"../Constants":2,"../Grammar":7,"../Logger":9,"../Utils":28,"events":31}],19:[function(require,module,exports){
  17483. "use strict";
  17484. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17485. 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); } }
  17486. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17487. var Logger = require('./Logger');
  17488. var Utils = require('./Utils');
  17489. var JsSIP_C = require('./Constants');
  17490. var SIPMessage = require('./SIPMessage');
  17491. var RequestSender = require('./RequestSender');
  17492. var logger = new Logger('Registrator');
  17493. var MIN_REGISTER_EXPIRES = 10; // In seconds.
  17494. module.exports = /*#__PURE__*/function () {
  17495. function Registrator(ua, transport) {
  17496. _classCallCheck(this, Registrator);
  17497. // Force reg_id to 1.
  17498. this._reg_id = 1;
  17499. this._ua = ua;
  17500. this._transport = transport;
  17501. this._registrar = ua.configuration.registrar_server;
  17502. this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2.
  17503. this._call_id = Utils.createRandomToken(22);
  17504. this._cseq = 0;
  17505. this._to_uri = ua.configuration.uri;
  17506. this._registrationTimer = null; // Ongoing Register request.
  17507. this._registering = false; // Set status.
  17508. this._registered = false; // Contact header.
  17509. this._contact = this._ua.contact.toString(); // Sip.ice media feature tag (RFC 5768).
  17510. this._contact += ';+sip.ice'; // Custom headers for REGISTER and un-REGISTER.
  17511. this._extraHeaders = []; // Custom Contact header params for REGISTER and un-REGISTER.
  17512. this._extraContactParams = ''; // Contents of the sip.instance Contact header parameter.
  17513. this._sipInstance = "\"<urn:uuid:".concat(this._ua.configuration.instance_id, ">\"");
  17514. this._contact += ";reg-id=".concat(this._reg_id);
  17515. this._contact += ";+sip.instance=".concat(this._sipInstance);
  17516. }
  17517. _createClass(Registrator, [{
  17518. key: "setExtraHeaders",
  17519. value: function setExtraHeaders(extraHeaders) {
  17520. if (!Array.isArray(extraHeaders)) {
  17521. extraHeaders = [];
  17522. }
  17523. this._extraHeaders = extraHeaders.slice();
  17524. }
  17525. }, {
  17526. key: "setExtraContactParams",
  17527. value: function setExtraContactParams(extraContactParams) {
  17528. if (!(extraContactParams instanceof Object)) {
  17529. extraContactParams = {};
  17530. } // Reset it.
  17531. this._extraContactParams = '';
  17532. for (var param_key in extraContactParams) {
  17533. if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) {
  17534. var param_value = extraContactParams[param_key];
  17535. this._extraContactParams += ";".concat(param_key);
  17536. if (param_value) {
  17537. this._extraContactParams += "=".concat(param_value);
  17538. }
  17539. }
  17540. }
  17541. }
  17542. }, {
  17543. key: "register",
  17544. value: function register() {
  17545. var _this = this;
  17546. if (this._registering) {
  17547. logger.debug('Register request in progress...');
  17548. return;
  17549. }
  17550. var extraHeaders = this._extraHeaders.slice();
  17551. extraHeaders.push("Contact: ".concat(this._contact, ";expires=").concat(this._expires).concat(this._extraContactParams));
  17552. extraHeaders.push("Expires: ".concat(this._expires));
  17553. var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
  17554. 'to_uri': this._to_uri,
  17555. 'call_id': this._call_id,
  17556. 'cseq': this._cseq += 1
  17557. }, extraHeaders);
  17558. var request_sender = new RequestSender(this._ua, request, {
  17559. onRequestTimeout: function onRequestTimeout() {
  17560. _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17561. },
  17562. onTransportError: function onTransportError() {
  17563. _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR);
  17564. },
  17565. // Increase the CSeq on authentication.
  17566. onAuthenticated: function onAuthenticated() {
  17567. _this._cseq += 1;
  17568. },
  17569. onReceiveResponse: function onReceiveResponse(response) {
  17570. // Discard responses to older REGISTER/un-REGISTER requests.
  17571. if (response.cseq !== _this._cseq) {
  17572. return;
  17573. } // Clear registration timer.
  17574. if (_this._registrationTimer !== null) {
  17575. clearTimeout(_this._registrationTimer);
  17576. _this._registrationTimer = null;
  17577. }
  17578. switch (true) {
  17579. case /^1[0-9]{2}$/.test(response.status_code):
  17580. {
  17581. // Ignore provisional responses.
  17582. break;
  17583. }
  17584. case /^2[0-9]{2}$/.test(response.status_code):
  17585. {
  17586. _this._registering = false;
  17587. if (!response.hasHeader('Contact')) {
  17588. logger.debug('no Contact header in response to REGISTER, response ignored');
  17589. break;
  17590. }
  17591. var contacts = response.headers['Contact'].reduce(function (a, b) {
  17592. return a.concat(b.parsed);
  17593. }, []); // Get the Contact pointing to us and update the expires value accordingly.
  17594. // Try to find a matching Contact using sip.instance and reg-id.
  17595. var contact = contacts.find(function (element) {
  17596. return _this._sipInstance === element.getParam('+sip.instance') && _this._reg_id === parseInt(element.getParam('reg-id'));
  17597. }); // If no match was found using the sip.instance try comparing the URIs.
  17598. if (!contact) {
  17599. contact = contacts.find(function (element) {
  17600. return element.uri.user === _this._ua.contact.uri.user;
  17601. });
  17602. }
  17603. if (!contact) {
  17604. logger.debug('no Contact header pointing to us, response ignored');
  17605. break;
  17606. }
  17607. var expires = contact.getParam('expires');
  17608. if (!expires && response.hasHeader('expires')) {
  17609. expires = response.getHeader('expires');
  17610. }
  17611. if (!expires) {
  17612. expires = _this._expires;
  17613. }
  17614. expires = Number(expires);
  17615. if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES;
  17616. var timeout = expires > 64 ? expires * 1000 / 2 + Math.floor((expires / 2 - 32) * 1000 * Math.random()) : expires * 1000 - 5000; // Re-Register or emit an event before the expiration interval has elapsed.
  17617. // For that, decrease the expires value. ie: 3 seconds.
  17618. _this._registrationTimer = setTimeout(function () {
  17619. _this._registrationTimer = null; // If there are no listeners for registrationExpiring, renew registration.
  17620. // If there are listeners, let the function listening do the register call.
  17621. if (_this._ua.listeners('registrationExpiring').length === 0) {
  17622. _this.register();
  17623. } else {
  17624. _this._ua.emit('registrationExpiring');
  17625. }
  17626. }, timeout); // Save gruu values.
  17627. if (contact.hasParam('temp-gruu')) {
  17628. _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, '');
  17629. }
  17630. if (contact.hasParam('pub-gruu')) {
  17631. _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, '');
  17632. }
  17633. if (!_this._registered) {
  17634. _this._registered = true;
  17635. _this._ua.registered({
  17636. response: response
  17637. });
  17638. }
  17639. break;
  17640. }
  17641. // Interval too brief RFC3261 10.2.8.
  17642. case /^423$/.test(response.status_code):
  17643. {
  17644. if (response.hasHeader('min-expires')) {
  17645. // Increase our registration interval to the suggested minimum.
  17646. _this._expires = Number(response.getHeader('min-expires'));
  17647. if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES; // Attempt the registration again immediately.
  17648. _this.register();
  17649. } else {
  17650. // This response MUST contain a Min-Expires header field.
  17651. logger.debug('423 response received for REGISTER without Min-Expires');
  17652. _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE);
  17653. }
  17654. break;
  17655. }
  17656. default:
  17657. {
  17658. var cause = Utils.sipErrorCause(response.status_code);
  17659. _this._registrationFailure(response, cause);
  17660. }
  17661. }
  17662. }
  17663. });
  17664. this._registering = true;
  17665. request_sender.send();
  17666. }
  17667. }, {
  17668. key: "unregister",
  17669. value: function unregister() {
  17670. var _this2 = this;
  17671. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17672. if (!this._registered) {
  17673. logger.debug('already unregistered');
  17674. return;
  17675. }
  17676. this._registered = false; // Clear the registration timer.
  17677. if (this._registrationTimer !== null) {
  17678. clearTimeout(this._registrationTimer);
  17679. this._registrationTimer = null;
  17680. }
  17681. var extraHeaders = this._extraHeaders.slice();
  17682. if (options.all) {
  17683. extraHeaders.push("Contact: *".concat(this._extraContactParams));
  17684. } else {
  17685. extraHeaders.push("Contact: ".concat(this._contact, ";expires=0").concat(this._extraContactParams));
  17686. }
  17687. extraHeaders.push('Expires: 0');
  17688. var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
  17689. 'to_uri': this._to_uri,
  17690. 'call_id': this._call_id,
  17691. 'cseq': this._cseq += 1
  17692. }, extraHeaders);
  17693. var request_sender = new RequestSender(this._ua, request, {
  17694. onRequestTimeout: function onRequestTimeout() {
  17695. _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT);
  17696. },
  17697. onTransportError: function onTransportError() {
  17698. _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR);
  17699. },
  17700. // Increase the CSeq on authentication.
  17701. onAuthenticated: function onAuthenticated() {
  17702. _this2._cseq += 1;
  17703. },
  17704. onReceiveResponse: function onReceiveResponse(response) {
  17705. switch (true) {
  17706. case /^1[0-9]{2}$/.test(response.status_code):
  17707. // Ignore provisional responses.
  17708. break;
  17709. case /^2[0-9]{2}$/.test(response.status_code):
  17710. _this2._unregistered(response);
  17711. break;
  17712. default:
  17713. {
  17714. var cause = Utils.sipErrorCause(response.status_code);
  17715. _this2._unregistered(response, cause);
  17716. }
  17717. }
  17718. }
  17719. });
  17720. request_sender.send();
  17721. }
  17722. }, {
  17723. key: "close",
  17724. value: function close() {
  17725. if (this._registered) {
  17726. this.unregister();
  17727. }
  17728. }
  17729. }, {
  17730. key: "onTransportClosed",
  17731. value: function onTransportClosed() {
  17732. this._registering = false;
  17733. if (this._registrationTimer !== null) {
  17734. clearTimeout(this._registrationTimer);
  17735. this._registrationTimer = null;
  17736. }
  17737. if (this._registered) {
  17738. this._registered = false;
  17739. this._ua.unregistered({});
  17740. }
  17741. }
  17742. }, {
  17743. key: "_registrationFailure",
  17744. value: function _registrationFailure(response, cause) {
  17745. this._registering = false;
  17746. this._ua.registrationFailed({
  17747. response: response || null,
  17748. cause: cause
  17749. });
  17750. if (this._registered) {
  17751. this._registered = false;
  17752. this._ua.unregistered({
  17753. response: response || null,
  17754. cause: cause
  17755. });
  17756. }
  17757. }
  17758. }, {
  17759. key: "_unregistered",
  17760. value: function _unregistered(response, cause) {
  17761. this._registering = false;
  17762. this._registered = false;
  17763. this._ua.unregistered({
  17764. response: response || null,
  17765. cause: cause || null
  17766. });
  17767. }
  17768. }, {
  17769. key: "registered",
  17770. get: function get() {
  17771. return this._registered;
  17772. }
  17773. }]);
  17774. return Registrator;
  17775. }();
  17776. },{"./Constants":2,"./Logger":9,"./RequestSender":20,"./SIPMessage":21,"./Utils":28}],20:[function(require,module,exports){
  17777. "use strict";
  17778. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17779. 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); } }
  17780. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17781. var Logger = require('./Logger');
  17782. var JsSIP_C = require('./Constants');
  17783. var DigestAuthentication = require('./DigestAuthentication');
  17784. var Transactions = require('./Transactions');
  17785. var logger = new Logger('RequestSender'); // Default event handlers.
  17786. var EventHandlers = {
  17787. onRequestTimeout: function onRequestTimeout() {},
  17788. onTransportError: function onTransportError() {},
  17789. onReceiveResponse: function onReceiveResponse() {},
  17790. onAuthenticated: function onAuthenticated() {}
  17791. };
  17792. module.exports = /*#__PURE__*/function () {
  17793. function RequestSender(ua, request, eventHandlers) {
  17794. _classCallCheck(this, RequestSender);
  17795. this._ua = ua;
  17796. this._eventHandlers = eventHandlers;
  17797. this._method = request.method;
  17798. this._request = request;
  17799. this._auth = null;
  17800. this._challenged = false;
  17801. this._staled = false; // Define the undefined handlers.
  17802. for (var handler in EventHandlers) {
  17803. if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
  17804. if (!this._eventHandlers[handler]) {
  17805. this._eventHandlers[handler] = EventHandlers[handler];
  17806. }
  17807. }
  17808. } // If ua is in closing process or even closed just allow sending Bye and ACK.
  17809. if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) {
  17810. this._eventHandlers.onTransportError();
  17811. }
  17812. }
  17813. /**
  17814. * Create the client transaction and send the message.
  17815. */
  17816. _createClass(RequestSender, [{
  17817. key: "send",
  17818. value: function send() {
  17819. var _this = this;
  17820. var eventHandlers = {
  17821. onRequestTimeout: function onRequestTimeout() {
  17822. _this._eventHandlers.onRequestTimeout();
  17823. },
  17824. onTransportError: function onTransportError() {
  17825. _this._eventHandlers.onTransportError();
  17826. },
  17827. onReceiveResponse: function onReceiveResponse(response) {
  17828. _this._receiveResponse(response);
  17829. }
  17830. };
  17831. switch (this._method) {
  17832. case 'INVITE':
  17833. this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17834. break;
  17835. case 'ACK':
  17836. this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17837. break;
  17838. default:
  17839. this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
  17840. } // If authorization JWT is present, use it.
  17841. if (this._ua._configuration.authorization_jwt) {
  17842. this._request.setHeader('Authorization', this._ua._configuration.authorization_jwt);
  17843. }
  17844. this.clientTransaction.send();
  17845. }
  17846. /**
  17847. * Called from client transaction when receiving a correct response to the request.
  17848. * Authenticate request if needed or pass the response back to the applicant.
  17849. */
  17850. }, {
  17851. key: "_receiveResponse",
  17852. value: function _receiveResponse(response) {
  17853. var challenge;
  17854. var authorization_header_name;
  17855. var status_code = response.status_code;
  17856. /*
  17857. * Authentication
  17858. * Authenticate once. _challenged_ flag used to avoid infinite authentications.
  17859. */
  17860. if ((status_code === 401 || status_code === 407) && (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) {
  17861. // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header.
  17862. if (response.status_code === 401) {
  17863. challenge = response.parseHeader('www-authenticate');
  17864. authorization_header_name = 'authorization';
  17865. } else {
  17866. challenge = response.parseHeader('proxy-authenticate');
  17867. authorization_header_name = 'proxy-authorization';
  17868. } // Verify it seems a valid challenge.
  17869. if (!challenge) {
  17870. logger.debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate"));
  17871. this._eventHandlers.onReceiveResponse(response);
  17872. return;
  17873. }
  17874. if (!this._challenged || !this._staled && challenge.stale === true) {
  17875. if (!this._auth) {
  17876. this._auth = new DigestAuthentication({
  17877. username: this._ua.configuration.authorization_user,
  17878. password: this._ua.configuration.password,
  17879. realm: this._ua.configuration.realm,
  17880. ha1: this._ua.configuration.ha1
  17881. });
  17882. } // Verify that the challenge is really valid.
  17883. if (!this._auth.authenticate(this._request, challenge)) {
  17884. this._eventHandlers.onReceiveResponse(response);
  17885. return;
  17886. }
  17887. this._challenged = true; // Update ha1 and realm in the UA.
  17888. this._ua.set('realm', this._auth.get('realm'));
  17889. this._ua.set('ha1', this._auth.get('ha1'));
  17890. if (challenge.stale) {
  17891. this._staled = true;
  17892. }
  17893. this._request = this._request.clone();
  17894. this._request.cseq += 1;
  17895. this._request.setHeader('cseq', "".concat(this._request.cseq, " ").concat(this._method));
  17896. this._request.setHeader(authorization_header_name, this._auth.toString());
  17897. this._eventHandlers.onAuthenticated(this._request);
  17898. this.send();
  17899. } else {
  17900. this._eventHandlers.onReceiveResponse(response);
  17901. }
  17902. } else {
  17903. this._eventHandlers.onReceiveResponse(response);
  17904. }
  17905. }
  17906. }]);
  17907. return RequestSender;
  17908. }();
  17909. },{"./Constants":2,"./DigestAuthentication":5,"./Logger":9,"./Transactions":24}],21:[function(require,module,exports){
  17910. "use strict";
  17911. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  17912. 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); }
  17913. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  17914. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  17915. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  17916. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  17917. 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; } }
  17918. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  17919. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  17920. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  17921. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  17922. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17923. 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); } }
  17924. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  17925. var sdp_transform = require('sdp-transform');
  17926. var Logger = require('./Logger');
  17927. var JsSIP_C = require('./Constants');
  17928. var Utils = require('./Utils');
  17929. var NameAddrHeader = require('./NameAddrHeader');
  17930. var Grammar = require('./Grammar');
  17931. var logger = new Logger('SIPMessage');
  17932. /**
  17933. * -param {String} method request method
  17934. * -param {String} ruri request uri
  17935. * -param {UA} ua
  17936. * -param {Object} params parameters that will have priority over ua.configuration parameters:
  17937. * <br>
  17938. * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set
  17939. * -param {Object} [headers] extra headers
  17940. * -param {String} [body]
  17941. */
  17942. var OutgoingRequest = /*#__PURE__*/function () {
  17943. function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) {
  17944. _classCallCheck(this, OutgoingRequest);
  17945. // Mandatory parameters check.
  17946. if (!method || !ruri || !ua) {
  17947. return null;
  17948. }
  17949. params = params || {};
  17950. this.ua = ua;
  17951. this.headers = {};
  17952. this.method = method;
  17953. this.ruri = ruri;
  17954. this.body = body;
  17955. this.extraHeaders = Utils.cloneArray(extraHeaders); // Fill the Common SIP Request Headers.
  17956. // Route.
  17957. if (params.route_set) {
  17958. this.setHeader('route', params.route_set);
  17959. } else if (ua.configuration.use_preloaded_route) {
  17960. this.setHeader('route', "<".concat(ua.transport.sip_uri, ";lr>"));
  17961. } // Via.
  17962. // Empty Via header. Will be filled by the client transaction.
  17963. this.setHeader('via', ''); // Max-Forwards.
  17964. this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS); // To
  17965. var to_uri = params.to_uri || ruri;
  17966. var to_params = params.to_tag ? {
  17967. tag: params.to_tag
  17968. } : null;
  17969. var to_display_name = typeof params.to_display_name !== 'undefined' ? params.to_display_name : null;
  17970. this.to = new NameAddrHeader(to_uri, to_display_name, to_params);
  17971. this.setHeader('to', this.to.toString()); // From.
  17972. var from_uri = params.from_uri || ua.configuration.uri;
  17973. var from_params = {
  17974. tag: params.from_tag || Utils.newTag()
  17975. };
  17976. var display_name;
  17977. if (typeof params.from_display_name !== 'undefined') {
  17978. display_name = params.from_display_name;
  17979. } else if (ua.configuration.display_name) {
  17980. display_name = ua.configuration.display_name;
  17981. } else {
  17982. display_name = null;
  17983. }
  17984. this.from = new NameAddrHeader(from_uri, display_name, from_params);
  17985. this.setHeader('from', this.from.toString()); // Call-ID.
  17986. var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15);
  17987. this.call_id = call_id;
  17988. this.setHeader('call-id', call_id); // CSeq.
  17989. var cseq = params.cseq || Math.floor(Math.random() * 10000);
  17990. this.cseq = cseq;
  17991. this.setHeader('cseq', "".concat(cseq, " ").concat(method));
  17992. }
  17993. /**
  17994. * Replace the the given header by the given value.
  17995. * -param {String} name header name
  17996. * -param {String | Array} value header value
  17997. */
  17998. _createClass(OutgoingRequest, [{
  17999. key: "setHeader",
  18000. value: function setHeader(name, value) {
  18001. // Remove the header from extraHeaders if present.
  18002. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  18003. for (var idx = 0; idx < this.extraHeaders.length; idx++) {
  18004. if (regexp.test(this.extraHeaders[idx])) {
  18005. this.extraHeaders.splice(idx, 1);
  18006. }
  18007. }
  18008. this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
  18009. }
  18010. /**
  18011. * Get the value of the given header name at the given position.
  18012. * -param {String} name header name
  18013. * -returns {String|undefined} Returns the specified header, null if header doesn't exist.
  18014. */
  18015. }, {
  18016. key: "getHeader",
  18017. value: function getHeader(name) {
  18018. var headers = this.headers[Utils.headerize(name)];
  18019. if (headers) {
  18020. if (headers[0]) {
  18021. return headers[0];
  18022. }
  18023. } else {
  18024. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  18025. var _iterator = _createForOfIteratorHelper(this.extraHeaders),
  18026. _step;
  18027. try {
  18028. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  18029. var header = _step.value;
  18030. if (regexp.test(header)) {
  18031. return header.substring(header.indexOf(':') + 1).trim();
  18032. }
  18033. }
  18034. } catch (err) {
  18035. _iterator.e(err);
  18036. } finally {
  18037. _iterator.f();
  18038. }
  18039. }
  18040. return;
  18041. }
  18042. /**
  18043. * Get the header/s of the given name.
  18044. * -param {String} name header name
  18045. * -returns {Array} Array with all the headers of the specified name.
  18046. */
  18047. }, {
  18048. key: "getHeaders",
  18049. value: function getHeaders(name) {
  18050. var headers = this.headers[Utils.headerize(name)];
  18051. var result = [];
  18052. if (headers) {
  18053. var _iterator2 = _createForOfIteratorHelper(headers),
  18054. _step2;
  18055. try {
  18056. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  18057. var header = _step2.value;
  18058. result.push(header);
  18059. }
  18060. } catch (err) {
  18061. _iterator2.e(err);
  18062. } finally {
  18063. _iterator2.f();
  18064. }
  18065. return result;
  18066. } else {
  18067. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  18068. var _iterator3 = _createForOfIteratorHelper(this.extraHeaders),
  18069. _step3;
  18070. try {
  18071. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  18072. var _header = _step3.value;
  18073. if (regexp.test(_header)) {
  18074. result.push(_header.substring(_header.indexOf(':') + 1).trim());
  18075. }
  18076. }
  18077. } catch (err) {
  18078. _iterator3.e(err);
  18079. } finally {
  18080. _iterator3.f();
  18081. }
  18082. return result;
  18083. }
  18084. }
  18085. /**
  18086. * Verify the existence of the given header.
  18087. * -param {String} name header name
  18088. * -returns {boolean} true if header with given name exists, false otherwise
  18089. */
  18090. }, {
  18091. key: "hasHeader",
  18092. value: function hasHeader(name) {
  18093. if (this.headers[Utils.headerize(name)]) {
  18094. return true;
  18095. } else {
  18096. var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
  18097. var _iterator4 = _createForOfIteratorHelper(this.extraHeaders),
  18098. _step4;
  18099. try {
  18100. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  18101. var header = _step4.value;
  18102. if (regexp.test(header)) {
  18103. return true;
  18104. }
  18105. }
  18106. } catch (err) {
  18107. _iterator4.e(err);
  18108. } finally {
  18109. _iterator4.f();
  18110. }
  18111. }
  18112. return false;
  18113. }
  18114. /**
  18115. * Parse the current body as a SDP and store the resulting object
  18116. * into this.sdp.
  18117. * -param {Boolean} force: Parse even if this.sdp already exists.
  18118. *
  18119. * Returns this.sdp.
  18120. */
  18121. }, {
  18122. key: "parseSDP",
  18123. value: function parseSDP(force) {
  18124. if (!force && this.sdp) {
  18125. return this.sdp;
  18126. } else {
  18127. this.sdp = sdp_transform.parse(this.body || '');
  18128. return this.sdp;
  18129. }
  18130. }
  18131. }, {
  18132. key: "toString",
  18133. value: function toString() {
  18134. var msg = "".concat(this.method, " ").concat(this.ruri, " SIP/2.0\r\n");
  18135. for (var headerName in this.headers) {
  18136. if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) {
  18137. var _iterator5 = _createForOfIteratorHelper(this.headers[headerName]),
  18138. _step5;
  18139. try {
  18140. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  18141. var headerValue = _step5.value;
  18142. msg += "".concat(headerName, ": ").concat(headerValue, "\r\n");
  18143. }
  18144. } catch (err) {
  18145. _iterator5.e(err);
  18146. } finally {
  18147. _iterator5.f();
  18148. }
  18149. }
  18150. }
  18151. var _iterator6 = _createForOfIteratorHelper(this.extraHeaders),
  18152. _step6;
  18153. try {
  18154. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  18155. var header = _step6.value;
  18156. msg += "".concat(header.trim(), "\r\n");
  18157. } // Supported.
  18158. } catch (err) {
  18159. _iterator6.e(err);
  18160. } finally {
  18161. _iterator6.f();
  18162. }
  18163. var supported = [];
  18164. switch (this.method) {
  18165. case JsSIP_C.REGISTER:
  18166. supported.push('path', 'gruu');
  18167. break;
  18168. case JsSIP_C.INVITE:
  18169. if (this.ua.configuration.session_timers) {
  18170. supported.push('timer');
  18171. }
  18172. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  18173. supported.push('gruu');
  18174. }
  18175. supported.push('ice', 'replaces');
  18176. break;
  18177. case JsSIP_C.UPDATE:
  18178. if (this.ua.configuration.session_timers) {
  18179. supported.push('timer');
  18180. }
  18181. supported.push('ice');
  18182. break;
  18183. }
  18184. supported.push('outbound');
  18185. var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT; // Allow.
  18186. msg += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  18187. msg += "Supported: ".concat(supported, "\r\n");
  18188. msg += "User-Agent: ".concat(userAgent, "\r\n");
  18189. if (this.body) {
  18190. var length = Utils.str_utf8_length(this.body);
  18191. msg += "Content-Length: ".concat(length, "\r\n\r\n");
  18192. msg += this.body;
  18193. } else {
  18194. msg += 'Content-Length: 0\r\n\r\n';
  18195. }
  18196. return msg;
  18197. }
  18198. }, {
  18199. key: "clone",
  18200. value: function clone() {
  18201. var request = new OutgoingRequest(this.method, this.ruri, this.ua);
  18202. Object.keys(this.headers).forEach(function (name) {
  18203. request.headers[name] = this.headers[name].slice();
  18204. }, this);
  18205. request.body = this.body;
  18206. request.extraHeaders = Utils.cloneArray(this.extraHeaders);
  18207. request.to = this.to;
  18208. request.from = this.from;
  18209. request.call_id = this.call_id;
  18210. request.cseq = this.cseq;
  18211. return request;
  18212. }
  18213. }]);
  18214. return OutgoingRequest;
  18215. }();
  18216. var InitialOutgoingInviteRequest = /*#__PURE__*/function (_OutgoingRequest) {
  18217. _inherits(InitialOutgoingInviteRequest, _OutgoingRequest);
  18218. var _super = _createSuper(InitialOutgoingInviteRequest);
  18219. function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) {
  18220. var _this;
  18221. _classCallCheck(this, InitialOutgoingInviteRequest);
  18222. _this = _super.call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body);
  18223. _this.transaction = null;
  18224. return _this;
  18225. }
  18226. _createClass(InitialOutgoingInviteRequest, [{
  18227. key: "cancel",
  18228. value: function cancel(reason) {
  18229. this.transaction.cancel(reason);
  18230. }
  18231. }, {
  18232. key: "clone",
  18233. value: function clone() {
  18234. var request = new InitialOutgoingInviteRequest(this.ruri, this.ua);
  18235. Object.keys(this.headers).forEach(function (name) {
  18236. request.headers[name] = this.headers[name].slice();
  18237. }, this);
  18238. request.body = this.body;
  18239. request.extraHeaders = Utils.cloneArray(this.extraHeaders);
  18240. request.to = this.to;
  18241. request.from = this.from;
  18242. request.call_id = this.call_id;
  18243. request.cseq = this.cseq;
  18244. request.transaction = this.transaction;
  18245. return request;
  18246. }
  18247. }]);
  18248. return InitialOutgoingInviteRequest;
  18249. }(OutgoingRequest);
  18250. var IncomingMessage = /*#__PURE__*/function () {
  18251. function IncomingMessage() {
  18252. _classCallCheck(this, IncomingMessage);
  18253. this.data = null;
  18254. this.headers = null;
  18255. this.method = null;
  18256. this.via = null;
  18257. this.via_branch = null;
  18258. this.call_id = null;
  18259. this.cseq = null;
  18260. this.from = null;
  18261. this.from_tag = null;
  18262. this.to = null;
  18263. this.to_tag = null;
  18264. this.body = null;
  18265. this.sdp = null;
  18266. }
  18267. /**
  18268. * Insert a header of the given name and value into the last position of the
  18269. * header array.
  18270. */
  18271. _createClass(IncomingMessage, [{
  18272. key: "addHeader",
  18273. value: function addHeader(name, value) {
  18274. var header = {
  18275. raw: value
  18276. };
  18277. name = Utils.headerize(name);
  18278. if (this.headers[name]) {
  18279. this.headers[name].push(header);
  18280. } else {
  18281. this.headers[name] = [header];
  18282. }
  18283. }
  18284. /**
  18285. * Get the value of the given header name at the given position.
  18286. */
  18287. }, {
  18288. key: "getHeader",
  18289. value: function getHeader(name) {
  18290. var header = this.headers[Utils.headerize(name)];
  18291. if (header) {
  18292. if (header[0]) {
  18293. return header[0].raw;
  18294. }
  18295. } else {
  18296. return;
  18297. }
  18298. }
  18299. /**
  18300. * Get the header/s of the given name.
  18301. */
  18302. }, {
  18303. key: "getHeaders",
  18304. value: function getHeaders(name) {
  18305. var headers = this.headers[Utils.headerize(name)];
  18306. var result = [];
  18307. if (!headers) {
  18308. return [];
  18309. }
  18310. var _iterator7 = _createForOfIteratorHelper(headers),
  18311. _step7;
  18312. try {
  18313. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  18314. var header = _step7.value;
  18315. result.push(header.raw);
  18316. }
  18317. } catch (err) {
  18318. _iterator7.e(err);
  18319. } finally {
  18320. _iterator7.f();
  18321. }
  18322. return result;
  18323. }
  18324. /**
  18325. * Verify the existence of the given header.
  18326. */
  18327. }, {
  18328. key: "hasHeader",
  18329. value: function hasHeader(name) {
  18330. return this.headers[Utils.headerize(name)] ? true : false;
  18331. }
  18332. /**
  18333. * Parse the given header on the given index.
  18334. * -param {String} name header name
  18335. * -param {Number} [idx=0] header index
  18336. * -returns {Object|undefined} Parsed header object, undefined if the header
  18337. * is not present or in case of a parsing error.
  18338. */
  18339. }, {
  18340. key: "parseHeader",
  18341. value: function parseHeader(name) {
  18342. var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  18343. name = Utils.headerize(name);
  18344. if (!this.headers[name]) {
  18345. logger.debug("header \"".concat(name, "\" not present"));
  18346. return;
  18347. } else if (idx >= this.headers[name].length) {
  18348. logger.debug("not so many \"".concat(name, "\" headers present"));
  18349. return;
  18350. }
  18351. var header = this.headers[name][idx];
  18352. var value = header.raw;
  18353. if (header.parsed) {
  18354. return header.parsed;
  18355. } // Substitute '-' by '_' for grammar rule matching.
  18356. var parsed = Grammar.parse(value, name.replace(/-/g, '_'));
  18357. if (parsed === -1) {
  18358. this.headers[name].splice(idx, 1); // delete from headers
  18359. logger.debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\""));
  18360. return;
  18361. } else {
  18362. header.parsed = parsed;
  18363. return parsed;
  18364. }
  18365. }
  18366. /**
  18367. * Message Header attribute selector. Alias of parseHeader.
  18368. * -param {String} name header name
  18369. * -param {Number} [idx=0] header index
  18370. * -returns {Object|undefined} Parsed header object, undefined if the header
  18371. * is not present or in case of a parsing error.
  18372. *
  18373. * -example
  18374. * message.s('via',3).port
  18375. */
  18376. }, {
  18377. key: "s",
  18378. value: function s(name, idx) {
  18379. return this.parseHeader(name, idx);
  18380. }
  18381. /**
  18382. * Replace the value of the given header by the value.
  18383. * -param {String} name header name
  18384. * -param {String} value header value
  18385. */
  18386. }, {
  18387. key: "setHeader",
  18388. value: function setHeader(name, value) {
  18389. var header = {
  18390. raw: value
  18391. };
  18392. this.headers[Utils.headerize(name)] = [header];
  18393. }
  18394. /**
  18395. * Parse the current body as a SDP and store the resulting object
  18396. * into this.sdp.
  18397. * -param {Boolean} force: Parse even if this.sdp already exists.
  18398. *
  18399. * Returns this.sdp.
  18400. */
  18401. }, {
  18402. key: "parseSDP",
  18403. value: function parseSDP(force) {
  18404. if (!force && this.sdp) {
  18405. return this.sdp;
  18406. } else {
  18407. this.sdp = sdp_transform.parse(this.body || '');
  18408. return this.sdp;
  18409. }
  18410. }
  18411. }, {
  18412. key: "toString",
  18413. value: function toString() {
  18414. return this.data;
  18415. }
  18416. }]);
  18417. return IncomingMessage;
  18418. }();
  18419. var IncomingRequest = /*#__PURE__*/function (_IncomingMessage) {
  18420. _inherits(IncomingRequest, _IncomingMessage);
  18421. var _super2 = _createSuper(IncomingRequest);
  18422. function IncomingRequest(ua) {
  18423. var _this2;
  18424. _classCallCheck(this, IncomingRequest);
  18425. _this2 = _super2.call(this);
  18426. _this2.ua = ua;
  18427. _this2.headers = {};
  18428. _this2.ruri = null;
  18429. _this2.transport = null;
  18430. _this2.server_transaction = null;
  18431. return _this2;
  18432. }
  18433. /**
  18434. * Stateful reply.
  18435. * -param {Number} code status code
  18436. * -param {String} reason reason phrase
  18437. * -param {Object} headers extra headers
  18438. * -param {String} body body
  18439. * -param {Function} [onSuccess] onSuccess callback
  18440. * -param {Function} [onFailure] onFailure callback
  18441. */
  18442. _createClass(IncomingRequest, [{
  18443. key: "reply",
  18444. value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) {
  18445. var supported = [];
  18446. var to = this.getHeader('To');
  18447. code = code || null;
  18448. reason = reason || null; // Validate code and reason values.
  18449. if (!code || code < 100 || code > 699) {
  18450. throw new TypeError("Invalid status_code: ".concat(code));
  18451. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  18452. throw new TypeError("Invalid reason_phrase: ".concat(reason));
  18453. }
  18454. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  18455. extraHeaders = Utils.cloneArray(extraHeaders);
  18456. var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n");
  18457. if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) {
  18458. var headers = this.getHeaders('record-route');
  18459. var _iterator8 = _createForOfIteratorHelper(headers),
  18460. _step8;
  18461. try {
  18462. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  18463. var header = _step8.value;
  18464. response += "Record-Route: ".concat(header, "\r\n");
  18465. }
  18466. } catch (err) {
  18467. _iterator8.e(err);
  18468. } finally {
  18469. _iterator8.f();
  18470. }
  18471. }
  18472. var vias = this.getHeaders('via');
  18473. var _iterator9 = _createForOfIteratorHelper(vias),
  18474. _step9;
  18475. try {
  18476. for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
  18477. var via = _step9.value;
  18478. response += "Via: ".concat(via, "\r\n");
  18479. }
  18480. } catch (err) {
  18481. _iterator9.e(err);
  18482. } finally {
  18483. _iterator9.f();
  18484. }
  18485. if (!this.to_tag && code > 100) {
  18486. to += ";tag=".concat(Utils.newTag());
  18487. } else if (this.to_tag && !this.s('to').hasParam('tag')) {
  18488. to += ";tag=".concat(this.to_tag);
  18489. }
  18490. response += "To: ".concat(to, "\r\n");
  18491. response += "From: ".concat(this.getHeader('From'), "\r\n");
  18492. response += "Call-ID: ".concat(this.call_id, "\r\n");
  18493. response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n");
  18494. var _iterator10 = _createForOfIteratorHelper(extraHeaders),
  18495. _step10;
  18496. try {
  18497. for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
  18498. var _header2 = _step10.value;
  18499. response += "".concat(_header2.trim(), "\r\n");
  18500. } // Supported.
  18501. } catch (err) {
  18502. _iterator10.e(err);
  18503. } finally {
  18504. _iterator10.f();
  18505. }
  18506. switch (this.method) {
  18507. case JsSIP_C.INVITE:
  18508. if (this.ua.configuration.session_timers) {
  18509. supported.push('timer');
  18510. }
  18511. if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
  18512. supported.push('gruu');
  18513. }
  18514. supported.push('ice', 'replaces');
  18515. break;
  18516. case JsSIP_C.UPDATE:
  18517. if (this.ua.configuration.session_timers) {
  18518. supported.push('timer');
  18519. }
  18520. if (body) {
  18521. supported.push('ice');
  18522. }
  18523. supported.push('replaces');
  18524. }
  18525. supported.push('outbound'); // Allow and Accept.
  18526. if (this.method === JsSIP_C.OPTIONS) {
  18527. response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  18528. response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n");
  18529. } else if (code === 405) {
  18530. response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
  18531. } else if (code === 415) {
  18532. response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n");
  18533. }
  18534. response += "Supported: ".concat(supported, "\r\n");
  18535. if (body) {
  18536. var length = Utils.str_utf8_length(body);
  18537. response += 'Content-Type: application/sdp\r\n';
  18538. response += "Content-Length: ".concat(length, "\r\n\r\n");
  18539. response += body;
  18540. } else {
  18541. response += "Content-Length: ".concat(0, "\r\n\r\n");
  18542. }
  18543. this.server_transaction.receiveResponse(code, response, onSuccess, onFailure);
  18544. }
  18545. /**
  18546. * Stateless reply.
  18547. * -param {Number} code status code
  18548. * -param {String} reason reason phrase
  18549. */
  18550. }, {
  18551. key: "reply_sl",
  18552. value: function reply_sl() {
  18553. var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  18554. var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  18555. var vias = this.getHeaders('via'); // Validate code and reason values.
  18556. if (!code || code < 100 || code > 699) {
  18557. throw new TypeError("Invalid status_code: ".concat(code));
  18558. } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
  18559. throw new TypeError("Invalid reason_phrase: ".concat(reason));
  18560. }
  18561. reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
  18562. var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n");
  18563. var _iterator11 = _createForOfIteratorHelper(vias),
  18564. _step11;
  18565. try {
  18566. for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
  18567. var via = _step11.value;
  18568. response += "Via: ".concat(via, "\r\n");
  18569. }
  18570. } catch (err) {
  18571. _iterator11.e(err);
  18572. } finally {
  18573. _iterator11.f();
  18574. }
  18575. var to = this.getHeader('To');
  18576. if (!this.to_tag && code > 100) {
  18577. to += ";tag=".concat(Utils.newTag());
  18578. } else if (this.to_tag && !this.s('to').hasParam('tag')) {
  18579. to += ";tag=".concat(this.to_tag);
  18580. }
  18581. response += "To: ".concat(to, "\r\n");
  18582. response += "From: ".concat(this.getHeader('From'), "\r\n");
  18583. response += "Call-ID: ".concat(this.call_id, "\r\n");
  18584. response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n");
  18585. response += "Content-Length: ".concat(0, "\r\n\r\n");
  18586. this.transport.send(response);
  18587. }
  18588. }]);
  18589. return IncomingRequest;
  18590. }(IncomingMessage);
  18591. var IncomingResponse = /*#__PURE__*/function (_IncomingMessage2) {
  18592. _inherits(IncomingResponse, _IncomingMessage2);
  18593. var _super3 = _createSuper(IncomingResponse);
  18594. function IncomingResponse() {
  18595. var _this3;
  18596. _classCallCheck(this, IncomingResponse);
  18597. _this3 = _super3.call(this);
  18598. _this3.headers = {};
  18599. _this3.status_code = null;
  18600. _this3.reason_phrase = null;
  18601. return _this3;
  18602. }
  18603. return IncomingResponse;
  18604. }(IncomingMessage);
  18605. module.exports = {
  18606. OutgoingRequest: OutgoingRequest,
  18607. InitialOutgoingInviteRequest: InitialOutgoingInviteRequest,
  18608. IncomingRequest: IncomingRequest,
  18609. IncomingResponse: IncomingResponse
  18610. };
  18611. },{"./Constants":2,"./Grammar":7,"./Logger":9,"./NameAddrHeader":11,"./Utils":28,"sdp-transform":37}],22:[function(require,module,exports){
  18612. "use strict";
  18613. var Logger = require('./Logger');
  18614. var Utils = require('./Utils');
  18615. var Grammar = require('./Grammar');
  18616. var logger = new Logger('Socket');
  18617. /**
  18618. * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/
  18619. *
  18620. * interface Socket {
  18621. * attribute String via_transport
  18622. * attribute String url
  18623. * attribute String sip_uri
  18624. *
  18625. * method connect();
  18626. * method disconnect();
  18627. * method send(data);
  18628. *
  18629. * attribute EventHandler onconnect
  18630. * attribute EventHandler ondisconnect
  18631. * attribute EventHandler ondata
  18632. * }
  18633. *
  18634. */
  18635. exports.isSocket = function (socket) {
  18636. // Ignore if an array is given.
  18637. if (Array.isArray(socket)) {
  18638. return false;
  18639. }
  18640. if (typeof socket === 'undefined') {
  18641. logger.warn('undefined JsSIP.Socket instance');
  18642. return false;
  18643. } // Check Properties.
  18644. try {
  18645. if (!Utils.isString(socket.url)) {
  18646. logger.warn('missing or invalid JsSIP.Socket url property');
  18647. throw new Error('Missing or invalid JsSIP.Socket url property');
  18648. }
  18649. if (!Utils.isString(socket.via_transport)) {
  18650. logger.warn('missing or invalid JsSIP.Socket via_transport property');
  18651. throw new Error('Missing or invalid JsSIP.Socket via_transport property');
  18652. }
  18653. if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) {
  18654. logger.warn('missing or invalid JsSIP.Socket sip_uri property');
  18655. throw new Error('missing or invalid JsSIP.Socket sip_uri property');
  18656. }
  18657. } catch (e) {
  18658. return false;
  18659. } // Check Methods.
  18660. try {
  18661. ['connect', 'disconnect', 'send'].forEach(function (method) {
  18662. if (!Utils.isFunction(socket[method])) {
  18663. logger.warn("missing or invalid JsSIP.Socket method: ".concat(method));
  18664. throw new Error("Missing or invalid JsSIP.Socket method: ".concat(method));
  18665. }
  18666. });
  18667. } catch (e) {
  18668. return false;
  18669. }
  18670. return true;
  18671. };
  18672. },{"./Grammar":7,"./Logger":9,"./Utils":28}],23:[function(require,module,exports){
  18673. "use strict";
  18674. var T1 = 500,
  18675. T2 = 4000,
  18676. T4 = 5000;
  18677. module.exports = {
  18678. T1: T1,
  18679. T2: T2,
  18680. T4: T4,
  18681. TIMER_B: 64 * T1,
  18682. TIMER_D: 0 * T1,
  18683. TIMER_F: 64 * T1,
  18684. TIMER_H: 64 * T1,
  18685. TIMER_I: 0 * T1,
  18686. TIMER_J: 0 * T1,
  18687. TIMER_K: 0 * T4,
  18688. TIMER_L: 64 * T1,
  18689. TIMER_M: 64 * T1,
  18690. PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1
  18691. };
  18692. },{}],24:[function(require,module,exports){
  18693. "use strict";
  18694. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  18695. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18696. 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); } }
  18697. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18698. 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); }
  18699. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  18700. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  18701. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  18702. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  18703. 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; } }
  18704. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18705. var EventEmitter = require('events').EventEmitter;
  18706. var Logger = require('./Logger');
  18707. var JsSIP_C = require('./Constants');
  18708. var SIPMessage = require('./SIPMessage');
  18709. var Timers = require('./Timers');
  18710. var loggernict = new Logger('NonInviteClientTransaction');
  18711. var loggerict = new Logger('InviteClientTransaction');
  18712. var loggeract = new Logger('AckClientTransaction');
  18713. var loggernist = new Logger('NonInviteServerTransaction');
  18714. var loggerist = new Logger('InviteServerTransaction');
  18715. var C = {
  18716. // Transaction states.
  18717. STATUS_TRYING: 1,
  18718. STATUS_PROCEEDING: 2,
  18719. STATUS_CALLING: 3,
  18720. STATUS_ACCEPTED: 4,
  18721. STATUS_COMPLETED: 5,
  18722. STATUS_TERMINATED: 6,
  18723. STATUS_CONFIRMED: 7,
  18724. // Transaction types.
  18725. NON_INVITE_CLIENT: 'nict',
  18726. NON_INVITE_SERVER: 'nist',
  18727. INVITE_CLIENT: 'ict',
  18728. INVITE_SERVER: 'ist'
  18729. };
  18730. var NonInviteClientTransaction = /*#__PURE__*/function (_EventEmitter) {
  18731. _inherits(NonInviteClientTransaction, _EventEmitter);
  18732. var _super = _createSuper(NonInviteClientTransaction);
  18733. function NonInviteClientTransaction(ua, transport, request, eventHandlers) {
  18734. var _this;
  18735. _classCallCheck(this, NonInviteClientTransaction);
  18736. _this = _super.call(this);
  18737. _this.type = C.NON_INVITE_CLIENT;
  18738. _this.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  18739. _this.ua = ua;
  18740. _this.transport = transport;
  18741. _this.request = request;
  18742. _this.eventHandlers = eventHandlers;
  18743. var via = "SIP/2.0/".concat(transport.via_transport);
  18744. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this.id);
  18745. _this.request.setHeader('via', via);
  18746. _this.ua.newTransaction(_assertThisInitialized(_this));
  18747. return _this;
  18748. }
  18749. _createClass(NonInviteClientTransaction, [{
  18750. key: "stateChanged",
  18751. value: function stateChanged(state) {
  18752. this.state = state;
  18753. this.emit('stateChanged');
  18754. }
  18755. }, {
  18756. key: "send",
  18757. value: function send() {
  18758. var _this2 = this;
  18759. this.stateChanged(C.STATUS_TRYING);
  18760. this.F = setTimeout(function () {
  18761. _this2.timer_F();
  18762. }, Timers.TIMER_F);
  18763. if (!this.transport.send(this.request)) {
  18764. this.onTransportError();
  18765. }
  18766. }
  18767. }, {
  18768. key: "onTransportError",
  18769. value: function onTransportError() {
  18770. loggernict.debug("transport error occurred, deleting transaction ".concat(this.id));
  18771. clearTimeout(this.F);
  18772. clearTimeout(this.K);
  18773. this.stateChanged(C.STATUS_TERMINATED);
  18774. this.ua.destroyTransaction(this);
  18775. this.eventHandlers.onTransportError();
  18776. }
  18777. }, {
  18778. key: "timer_F",
  18779. value: function timer_F() {
  18780. loggernict.debug("Timer F expired for transaction ".concat(this.id));
  18781. this.stateChanged(C.STATUS_TERMINATED);
  18782. this.ua.destroyTransaction(this);
  18783. this.eventHandlers.onRequestTimeout();
  18784. }
  18785. }, {
  18786. key: "timer_K",
  18787. value: function timer_K() {
  18788. this.stateChanged(C.STATUS_TERMINATED);
  18789. this.ua.destroyTransaction(this);
  18790. }
  18791. }, {
  18792. key: "receiveResponse",
  18793. value: function receiveResponse(response) {
  18794. var _this3 = this;
  18795. var status_code = response.status_code;
  18796. if (status_code < 200) {
  18797. switch (this.state) {
  18798. case C.STATUS_TRYING:
  18799. case C.STATUS_PROCEEDING:
  18800. this.stateChanged(C.STATUS_PROCEEDING);
  18801. this.eventHandlers.onReceiveResponse(response);
  18802. break;
  18803. }
  18804. } else {
  18805. switch (this.state) {
  18806. case C.STATUS_TRYING:
  18807. case C.STATUS_PROCEEDING:
  18808. this.stateChanged(C.STATUS_COMPLETED);
  18809. clearTimeout(this.F);
  18810. if (status_code === 408) {
  18811. this.eventHandlers.onRequestTimeout();
  18812. } else {
  18813. this.eventHandlers.onReceiveResponse(response);
  18814. }
  18815. this.K = setTimeout(function () {
  18816. _this3.timer_K();
  18817. }, Timers.TIMER_K);
  18818. break;
  18819. case C.STATUS_COMPLETED:
  18820. break;
  18821. }
  18822. }
  18823. }
  18824. }, {
  18825. key: "C",
  18826. get: function get() {
  18827. return C;
  18828. }
  18829. }]);
  18830. return NonInviteClientTransaction;
  18831. }(EventEmitter);
  18832. var InviteClientTransaction = /*#__PURE__*/function (_EventEmitter2) {
  18833. _inherits(InviteClientTransaction, _EventEmitter2);
  18834. var _super2 = _createSuper(InviteClientTransaction);
  18835. function InviteClientTransaction(ua, transport, request, eventHandlers) {
  18836. var _this4;
  18837. _classCallCheck(this, InviteClientTransaction);
  18838. _this4 = _super2.call(this);
  18839. _this4.type = C.INVITE_CLIENT;
  18840. _this4.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  18841. _this4.ua = ua;
  18842. _this4.transport = transport;
  18843. _this4.request = request;
  18844. _this4.eventHandlers = eventHandlers;
  18845. request.transaction = _assertThisInitialized(_this4);
  18846. var via = "SIP/2.0/".concat(transport.via_transport);
  18847. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this4.id);
  18848. _this4.request.setHeader('via', via);
  18849. _this4.ua.newTransaction(_assertThisInitialized(_this4));
  18850. return _this4;
  18851. }
  18852. _createClass(InviteClientTransaction, [{
  18853. key: "stateChanged",
  18854. value: function stateChanged(state) {
  18855. this.state = state;
  18856. this.emit('stateChanged');
  18857. }
  18858. }, {
  18859. key: "send",
  18860. value: function send() {
  18861. var _this5 = this;
  18862. this.stateChanged(C.STATUS_CALLING);
  18863. this.B = setTimeout(function () {
  18864. _this5.timer_B();
  18865. }, Timers.TIMER_B);
  18866. if (!this.transport.send(this.request)) {
  18867. this.onTransportError();
  18868. }
  18869. }
  18870. }, {
  18871. key: "onTransportError",
  18872. value: function onTransportError() {
  18873. clearTimeout(this.B);
  18874. clearTimeout(this.D);
  18875. clearTimeout(this.M);
  18876. if (this.state !== C.STATUS_ACCEPTED) {
  18877. loggerict.debug("transport error occurred, deleting transaction ".concat(this.id));
  18878. this.eventHandlers.onTransportError();
  18879. }
  18880. this.stateChanged(C.STATUS_TERMINATED);
  18881. this.ua.destroyTransaction(this);
  18882. } // RFC 6026 7.2.
  18883. }, {
  18884. key: "timer_M",
  18885. value: function timer_M() {
  18886. loggerict.debug("Timer M expired for transaction ".concat(this.id));
  18887. if (this.state === C.STATUS_ACCEPTED) {
  18888. clearTimeout(this.B);
  18889. this.stateChanged(C.STATUS_TERMINATED);
  18890. this.ua.destroyTransaction(this);
  18891. }
  18892. } // RFC 3261 17.1.1.
  18893. }, {
  18894. key: "timer_B",
  18895. value: function timer_B() {
  18896. loggerict.debug("Timer B expired for transaction ".concat(this.id));
  18897. if (this.state === C.STATUS_CALLING) {
  18898. this.stateChanged(C.STATUS_TERMINATED);
  18899. this.ua.destroyTransaction(this);
  18900. this.eventHandlers.onRequestTimeout();
  18901. }
  18902. }
  18903. }, {
  18904. key: "timer_D",
  18905. value: function timer_D() {
  18906. loggerict.debug("Timer D expired for transaction ".concat(this.id));
  18907. clearTimeout(this.B);
  18908. this.stateChanged(C.STATUS_TERMINATED);
  18909. this.ua.destroyTransaction(this);
  18910. }
  18911. }, {
  18912. key: "sendACK",
  18913. value: function sendACK(response) {
  18914. var _this6 = this;
  18915. var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, {
  18916. 'route_set': this.request.getHeaders('route'),
  18917. 'call_id': this.request.getHeader('call-id'),
  18918. 'cseq': this.request.cseq
  18919. });
  18920. ack.setHeader('from', this.request.getHeader('from'));
  18921. ack.setHeader('via', this.request.getHeader('via'));
  18922. ack.setHeader('to', response.getHeader('to'));
  18923. this.D = setTimeout(function () {
  18924. _this6.timer_D();
  18925. }, Timers.TIMER_D);
  18926. this.transport.send(ack);
  18927. }
  18928. }, {
  18929. key: "cancel",
  18930. value: function cancel(reason) {
  18931. // Send only if a provisional response (>100) has been received.
  18932. if (this.state !== C.STATUS_PROCEEDING) {
  18933. return;
  18934. }
  18935. var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, {
  18936. 'route_set': this.request.getHeaders('route'),
  18937. 'call_id': this.request.getHeader('call-id'),
  18938. 'cseq': this.request.cseq
  18939. });
  18940. cancel.setHeader('from', this.request.getHeader('from'));
  18941. cancel.setHeader('via', this.request.getHeader('via'));
  18942. cancel.setHeader('to', this.request.getHeader('to'));
  18943. if (reason) {
  18944. cancel.setHeader('reason', reason);
  18945. }
  18946. this.transport.send(cancel);
  18947. }
  18948. }, {
  18949. key: "receiveResponse",
  18950. value: function receiveResponse(response) {
  18951. var _this7 = this;
  18952. var status_code = response.status_code;
  18953. if (status_code >= 100 && status_code <= 199) {
  18954. switch (this.state) {
  18955. case C.STATUS_CALLING:
  18956. this.stateChanged(C.STATUS_PROCEEDING);
  18957. this.eventHandlers.onReceiveResponse(response);
  18958. break;
  18959. case C.STATUS_PROCEEDING:
  18960. this.eventHandlers.onReceiveResponse(response);
  18961. break;
  18962. }
  18963. } else if (status_code >= 200 && status_code <= 299) {
  18964. switch (this.state) {
  18965. case C.STATUS_CALLING:
  18966. case C.STATUS_PROCEEDING:
  18967. this.stateChanged(C.STATUS_ACCEPTED);
  18968. this.M = setTimeout(function () {
  18969. _this7.timer_M();
  18970. }, Timers.TIMER_M);
  18971. this.eventHandlers.onReceiveResponse(response);
  18972. break;
  18973. case C.STATUS_ACCEPTED:
  18974. this.eventHandlers.onReceiveResponse(response);
  18975. break;
  18976. }
  18977. } else if (status_code >= 300 && status_code <= 699) {
  18978. switch (this.state) {
  18979. case C.STATUS_CALLING:
  18980. case C.STATUS_PROCEEDING:
  18981. this.stateChanged(C.STATUS_COMPLETED);
  18982. this.sendACK(response);
  18983. this.eventHandlers.onReceiveResponse(response);
  18984. break;
  18985. case C.STATUS_COMPLETED:
  18986. this.sendACK(response);
  18987. break;
  18988. }
  18989. }
  18990. }
  18991. }, {
  18992. key: "C",
  18993. get: function get() {
  18994. return C;
  18995. }
  18996. }]);
  18997. return InviteClientTransaction;
  18998. }(EventEmitter);
  18999. var AckClientTransaction = /*#__PURE__*/function (_EventEmitter3) {
  19000. _inherits(AckClientTransaction, _EventEmitter3);
  19001. var _super3 = _createSuper(AckClientTransaction);
  19002. function AckClientTransaction(ua, transport, request, eventHandlers) {
  19003. var _this8;
  19004. _classCallCheck(this, AckClientTransaction);
  19005. _this8 = _super3.call(this);
  19006. _this8.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
  19007. _this8.transport = transport;
  19008. _this8.request = request;
  19009. _this8.eventHandlers = eventHandlers;
  19010. var via = "SIP/2.0/".concat(transport.via_transport);
  19011. via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this8.id);
  19012. _this8.request.setHeader('via', via);
  19013. return _this8;
  19014. }
  19015. _createClass(AckClientTransaction, [{
  19016. key: "send",
  19017. value: function send() {
  19018. if (!this.transport.send(this.request)) {
  19019. this.onTransportError();
  19020. }
  19021. }
  19022. }, {
  19023. key: "onTransportError",
  19024. value: function onTransportError() {
  19025. loggeract.debug("transport error occurred for transaction ".concat(this.id));
  19026. this.eventHandlers.onTransportError();
  19027. }
  19028. }, {
  19029. key: "C",
  19030. get: function get() {
  19031. return C;
  19032. }
  19033. }]);
  19034. return AckClientTransaction;
  19035. }(EventEmitter);
  19036. var NonInviteServerTransaction = /*#__PURE__*/function (_EventEmitter4) {
  19037. _inherits(NonInviteServerTransaction, _EventEmitter4);
  19038. var _super4 = _createSuper(NonInviteServerTransaction);
  19039. function NonInviteServerTransaction(ua, transport, request) {
  19040. var _this9;
  19041. _classCallCheck(this, NonInviteServerTransaction);
  19042. _this9 = _super4.call(this);
  19043. _this9.type = C.NON_INVITE_SERVER;
  19044. _this9.id = request.via_branch;
  19045. _this9.ua = ua;
  19046. _this9.transport = transport;
  19047. _this9.request = request;
  19048. _this9.last_response = '';
  19049. request.server_transaction = _assertThisInitialized(_this9);
  19050. _this9.state = C.STATUS_TRYING;
  19051. ua.newTransaction(_assertThisInitialized(_this9));
  19052. return _this9;
  19053. }
  19054. _createClass(NonInviteServerTransaction, [{
  19055. key: "stateChanged",
  19056. value: function stateChanged(state) {
  19057. this.state = state;
  19058. this.emit('stateChanged');
  19059. }
  19060. }, {
  19061. key: "timer_J",
  19062. value: function timer_J() {
  19063. loggernist.debug("Timer J expired for transaction ".concat(this.id));
  19064. this.stateChanged(C.STATUS_TERMINATED);
  19065. this.ua.destroyTransaction(this);
  19066. }
  19067. }, {
  19068. key: "onTransportError",
  19069. value: function onTransportError() {
  19070. if (!this.transportError) {
  19071. this.transportError = true;
  19072. loggernist.debug("transport error occurred, deleting transaction ".concat(this.id));
  19073. clearTimeout(this.J);
  19074. this.stateChanged(C.STATUS_TERMINATED);
  19075. this.ua.destroyTransaction(this);
  19076. }
  19077. }
  19078. }, {
  19079. key: "receiveResponse",
  19080. value: function receiveResponse(status_code, response, onSuccess, onFailure) {
  19081. var _this10 = this;
  19082. if (status_code === 100) {
  19083. /* RFC 4320 4.1
  19084. * 'A SIP element MUST NOT
  19085. * send any provisional response with a
  19086. * Status-Code other than 100 to a non-INVITE request.'
  19087. */
  19088. switch (this.state) {
  19089. case C.STATUS_TRYING:
  19090. this.stateChanged(C.STATUS_PROCEEDING);
  19091. if (!this.transport.send(response)) {
  19092. this.onTransportError();
  19093. }
  19094. break;
  19095. case C.STATUS_PROCEEDING:
  19096. this.last_response = response;
  19097. if (!this.transport.send(response)) {
  19098. this.onTransportError();
  19099. if (onFailure) {
  19100. onFailure();
  19101. }
  19102. } else if (onSuccess) {
  19103. onSuccess();
  19104. }
  19105. break;
  19106. }
  19107. } else if (status_code >= 200 && status_code <= 699) {
  19108. switch (this.state) {
  19109. case C.STATUS_TRYING:
  19110. case C.STATUS_PROCEEDING:
  19111. this.stateChanged(C.STATUS_COMPLETED);
  19112. this.last_response = response;
  19113. this.J = setTimeout(function () {
  19114. _this10.timer_J();
  19115. }, Timers.TIMER_J);
  19116. if (!this.transport.send(response)) {
  19117. this.onTransportError();
  19118. if (onFailure) {
  19119. onFailure();
  19120. }
  19121. } else if (onSuccess) {
  19122. onSuccess();
  19123. }
  19124. break;
  19125. case C.STATUS_COMPLETED:
  19126. break;
  19127. }
  19128. }
  19129. }
  19130. }, {
  19131. key: "C",
  19132. get: function get() {
  19133. return C;
  19134. }
  19135. }]);
  19136. return NonInviteServerTransaction;
  19137. }(EventEmitter);
  19138. var InviteServerTransaction = /*#__PURE__*/function (_EventEmitter5) {
  19139. _inherits(InviteServerTransaction, _EventEmitter5);
  19140. var _super5 = _createSuper(InviteServerTransaction);
  19141. function InviteServerTransaction(ua, transport, request) {
  19142. var _this11;
  19143. _classCallCheck(this, InviteServerTransaction);
  19144. _this11 = _super5.call(this);
  19145. _this11.type = C.INVITE_SERVER;
  19146. _this11.id = request.via_branch;
  19147. _this11.ua = ua;
  19148. _this11.transport = transport;
  19149. _this11.request = request;
  19150. _this11.last_response = '';
  19151. request.server_transaction = _assertThisInitialized(_this11);
  19152. _this11.state = C.STATUS_PROCEEDING;
  19153. ua.newTransaction(_assertThisInitialized(_this11));
  19154. _this11.resendProvisionalTimer = null;
  19155. request.reply(100);
  19156. return _this11;
  19157. }
  19158. _createClass(InviteServerTransaction, [{
  19159. key: "stateChanged",
  19160. value: function stateChanged(state) {
  19161. this.state = state;
  19162. this.emit('stateChanged');
  19163. }
  19164. }, {
  19165. key: "timer_H",
  19166. value: function timer_H() {
  19167. loggerist.debug("Timer H expired for transaction ".concat(this.id));
  19168. if (this.state === C.STATUS_COMPLETED) {
  19169. loggerist.debug('ACK not received, dialog will be terminated');
  19170. }
  19171. this.stateChanged(C.STATUS_TERMINATED);
  19172. this.ua.destroyTransaction(this);
  19173. }
  19174. }, {
  19175. key: "timer_I",
  19176. value: function timer_I() {
  19177. this.stateChanged(C.STATUS_TERMINATED);
  19178. this.ua.destroyTransaction(this);
  19179. } // RFC 6026 7.1.
  19180. }, {
  19181. key: "timer_L",
  19182. value: function timer_L() {
  19183. loggerist.debug("Timer L expired for transaction ".concat(this.id));
  19184. if (this.state === C.STATUS_ACCEPTED) {
  19185. this.stateChanged(C.STATUS_TERMINATED);
  19186. this.ua.destroyTransaction(this);
  19187. }
  19188. }
  19189. }, {
  19190. key: "onTransportError",
  19191. value: function onTransportError() {
  19192. if (!this.transportError) {
  19193. this.transportError = true;
  19194. loggerist.debug("transport error occurred, deleting transaction ".concat(this.id));
  19195. if (this.resendProvisionalTimer !== null) {
  19196. clearInterval(this.resendProvisionalTimer);
  19197. this.resendProvisionalTimer = null;
  19198. }
  19199. clearTimeout(this.L);
  19200. clearTimeout(this.H);
  19201. clearTimeout(this.I);
  19202. this.stateChanged(C.STATUS_TERMINATED);
  19203. this.ua.destroyTransaction(this);
  19204. }
  19205. }
  19206. }, {
  19207. key: "resend_provisional",
  19208. value: function resend_provisional() {
  19209. if (!this.transport.send(this.last_response)) {
  19210. this.onTransportError();
  19211. }
  19212. } // INVITE Server Transaction RFC 3261 17.2.1.
  19213. }, {
  19214. key: "receiveResponse",
  19215. value: function receiveResponse(status_code, response, onSuccess, onFailure) {
  19216. var _this12 = this;
  19217. if (status_code >= 100 && status_code <= 199) {
  19218. switch (this.state) {
  19219. case C.STATUS_PROCEEDING:
  19220. if (!this.transport.send(response)) {
  19221. this.onTransportError();
  19222. }
  19223. this.last_response = response;
  19224. break;
  19225. }
  19226. }
  19227. if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) {
  19228. // Trigger the resendProvisionalTimer only for the first non 100 provisional response.
  19229. if (this.resendProvisionalTimer === null) {
  19230. this.resendProvisionalTimer = setInterval(function () {
  19231. _this12.resend_provisional();
  19232. }, Timers.PROVISIONAL_RESPONSE_INTERVAL);
  19233. }
  19234. } else if (status_code >= 200 && status_code <= 299) {
  19235. switch (this.state) {
  19236. case C.STATUS_PROCEEDING:
  19237. this.stateChanged(C.STATUS_ACCEPTED);
  19238. this.last_response = response;
  19239. this.L = setTimeout(function () {
  19240. _this12.timer_L();
  19241. }, Timers.TIMER_L);
  19242. if (this.resendProvisionalTimer !== null) {
  19243. clearInterval(this.resendProvisionalTimer);
  19244. this.resendProvisionalTimer = null;
  19245. }
  19246. /* falls through */
  19247. case C.STATUS_ACCEPTED:
  19248. // Note that this point will be reached for proceeding this.state also.
  19249. if (!this.transport.send(response)) {
  19250. this.onTransportError();
  19251. if (onFailure) {
  19252. onFailure();
  19253. }
  19254. } else if (onSuccess) {
  19255. onSuccess();
  19256. }
  19257. break;
  19258. }
  19259. } else if (status_code >= 300 && status_code <= 699) {
  19260. switch (this.state) {
  19261. case C.STATUS_PROCEEDING:
  19262. if (this.resendProvisionalTimer !== null) {
  19263. clearInterval(this.resendProvisionalTimer);
  19264. this.resendProvisionalTimer = null;
  19265. }
  19266. if (!this.transport.send(response)) {
  19267. this.onTransportError();
  19268. if (onFailure) {
  19269. onFailure();
  19270. }
  19271. } else {
  19272. this.stateChanged(C.STATUS_COMPLETED);
  19273. this.H = setTimeout(function () {
  19274. _this12.timer_H();
  19275. }, Timers.TIMER_H);
  19276. if (onSuccess) {
  19277. onSuccess();
  19278. }
  19279. }
  19280. break;
  19281. }
  19282. }
  19283. }
  19284. }, {
  19285. key: "C",
  19286. get: function get() {
  19287. return C;
  19288. }
  19289. }]);
  19290. return InviteServerTransaction;
  19291. }(EventEmitter);
  19292. /**
  19293. * INVITE:
  19294. * _true_ if retransmission
  19295. * _false_ new request
  19296. *
  19297. * ACK:
  19298. * _true_ ACK to non2xx response
  19299. * _false_ ACK must be passed to TU (accepted state)
  19300. * ACK to 2xx response
  19301. *
  19302. * CANCEL:
  19303. * _true_ no matching invite transaction
  19304. * _false_ matching invite transaction and no final response sent
  19305. *
  19306. * OTHER:
  19307. * _true_ retransmission
  19308. * _false_ new request
  19309. */
  19310. function checkTransaction(_ref, request) {
  19311. var _transactions = _ref._transactions;
  19312. var tr;
  19313. switch (request.method) {
  19314. case JsSIP_C.INVITE:
  19315. tr = _transactions.ist[request.via_branch];
  19316. if (tr) {
  19317. switch (tr.state) {
  19318. case C.STATUS_PROCEEDING:
  19319. tr.transport.send(tr.last_response);
  19320. break;
  19321. // RFC 6026 7.1 Invite retransmission.
  19322. // Received while in C.STATUS_ACCEPTED state. Absorb it.
  19323. case C.STATUS_ACCEPTED:
  19324. break;
  19325. }
  19326. return true;
  19327. }
  19328. break;
  19329. case JsSIP_C.ACK:
  19330. tr = _transactions.ist[request.via_branch]; // RFC 6026 7.1.
  19331. if (tr) {
  19332. if (tr.state === C.STATUS_ACCEPTED) {
  19333. return false;
  19334. } else if (tr.state === C.STATUS_COMPLETED) {
  19335. tr.state = C.STATUS_CONFIRMED;
  19336. tr.I = setTimeout(function () {
  19337. tr.timer_I();
  19338. }, Timers.TIMER_I);
  19339. return true;
  19340. }
  19341. } // ACK to 2XX Response.
  19342. else {
  19343. return false;
  19344. }
  19345. break;
  19346. case JsSIP_C.CANCEL:
  19347. tr = _transactions.ist[request.via_branch];
  19348. if (tr) {
  19349. request.reply_sl(200);
  19350. if (tr.state === C.STATUS_PROCEEDING) {
  19351. return false;
  19352. } else {
  19353. return true;
  19354. }
  19355. } else {
  19356. request.reply_sl(481);
  19357. return true;
  19358. }
  19359. default:
  19360. // Non-INVITE Server Transaction RFC 3261 17.2.2.
  19361. tr = _transactions.nist[request.via_branch];
  19362. if (tr) {
  19363. switch (tr.state) {
  19364. case C.STATUS_TRYING:
  19365. break;
  19366. case C.STATUS_PROCEEDING:
  19367. case C.STATUS_COMPLETED:
  19368. tr.transport.send(tr.last_response);
  19369. break;
  19370. }
  19371. return true;
  19372. }
  19373. break;
  19374. }
  19375. }
  19376. module.exports = {
  19377. C: C,
  19378. NonInviteClientTransaction: NonInviteClientTransaction,
  19379. InviteClientTransaction: InviteClientTransaction,
  19380. AckClientTransaction: AckClientTransaction,
  19381. NonInviteServerTransaction: NonInviteServerTransaction,
  19382. InviteServerTransaction: InviteServerTransaction,
  19383. checkTransaction: checkTransaction
  19384. };
  19385. },{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Timers":23,"events":31}],25:[function(require,module,exports){
  19386. "use strict";
  19387. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19388. 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); } }
  19389. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19390. var Logger = require('./Logger');
  19391. var Socket = require('./Socket');
  19392. var JsSIP_C = require('./Constants');
  19393. var logger = new Logger('Transport');
  19394. /**
  19395. * Constants
  19396. */
  19397. var C = {
  19398. // Transport status.
  19399. STATUS_CONNECTED: 0,
  19400. STATUS_CONNECTING: 1,
  19401. STATUS_DISCONNECTED: 2,
  19402. // Socket status.
  19403. SOCKET_STATUS_READY: 0,
  19404. SOCKET_STATUS_ERROR: 1,
  19405. // Recovery options.
  19406. recovery_options: {
  19407. // minimum interval in seconds between recover attempts.
  19408. min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL,
  19409. // maximum interval in seconds between recover attempts.
  19410. max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL
  19411. }
  19412. };
  19413. /*
  19414. * Manages one or multiple JsSIP.Socket instances.
  19415. * Is reponsible for transport recovery logic among all socket instances.
  19416. *
  19417. * @socket JsSIP::Socket instance
  19418. */
  19419. module.exports = /*#__PURE__*/function () {
  19420. function Transport(sockets) {
  19421. var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options;
  19422. _classCallCheck(this, Transport);
  19423. logger.debug('new()');
  19424. this.status = C.STATUS_DISCONNECTED; // Current socket.
  19425. this.socket = null; // Socket collection.
  19426. this.sockets = [];
  19427. this.recovery_options = recovery_options;
  19428. this.recover_attempts = 0;
  19429. this.recovery_timer = null;
  19430. this.close_requested = false; // It seems that TextDecoder is not available in some versions of React-Native.
  19431. // See https://github.com/versatica/JsSIP/issues/695
  19432. try {
  19433. this.textDecoder = new TextDecoder('utf8');
  19434. } catch (error) {
  19435. logger.warn("cannot use TextDecoder: ".concat(error));
  19436. }
  19437. if (typeof sockets === 'undefined') {
  19438. throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument');
  19439. }
  19440. if (!(sockets instanceof Array)) {
  19441. sockets = [sockets];
  19442. }
  19443. sockets.forEach(function (socket) {
  19444. if (!Socket.isSocket(socket.socket)) {
  19445. throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance');
  19446. }
  19447. if (socket.weight && !Number(socket.weight)) {
  19448. throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number');
  19449. }
  19450. this.sockets.push({
  19451. socket: socket.socket,
  19452. weight: socket.weight || 0,
  19453. status: C.SOCKET_STATUS_READY
  19454. });
  19455. }, this); // Get the socket with higher weight.
  19456. this._getSocket();
  19457. }
  19458. /**
  19459. * Instance Methods
  19460. */
  19461. _createClass(Transport, [{
  19462. key: "connect",
  19463. value: function connect() {
  19464. logger.debug('connect()');
  19465. if (this.isConnected()) {
  19466. logger.debug('Transport is already connected');
  19467. return;
  19468. } else if (this.isConnecting()) {
  19469. logger.debug('Transport is connecting');
  19470. return;
  19471. }
  19472. this.close_requested = false;
  19473. this.status = C.STATUS_CONNECTING;
  19474. this.onconnecting({
  19475. socket: this.socket,
  19476. attempts: this.recover_attempts
  19477. });
  19478. if (!this.close_requested) {
  19479. // Bind socket event callbacks.
  19480. this.socket.onconnect = this._onConnect.bind(this);
  19481. this.socket.ondisconnect = this._onDisconnect.bind(this);
  19482. this.socket.ondata = this._onData.bind(this);
  19483. this.socket.connect();
  19484. }
  19485. return;
  19486. }
  19487. }, {
  19488. key: "disconnect",
  19489. value: function disconnect() {
  19490. logger.debug('close()');
  19491. this.close_requested = true;
  19492. this.recover_attempts = 0;
  19493. this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer.
  19494. if (this.recovery_timer !== null) {
  19495. clearTimeout(this.recovery_timer);
  19496. this.recovery_timer = null;
  19497. } // Unbind socket event callbacks.
  19498. this.socket.onconnect = function () {};
  19499. this.socket.ondisconnect = function () {};
  19500. this.socket.ondata = function () {};
  19501. this.socket.disconnect();
  19502. this.ondisconnect({
  19503. socket: this.socket,
  19504. error: false
  19505. });
  19506. }
  19507. }, {
  19508. key: "send",
  19509. value: function send(data) {
  19510. logger.debug('send()');
  19511. if (!this.isConnected()) {
  19512. logger.warn('unable to send message, transport is not connected');
  19513. return false;
  19514. }
  19515. var message = data.toString();
  19516. logger.debug("sending message:\n\n".concat(message, "\n"));
  19517. return this.socket.send(message);
  19518. }
  19519. }, {
  19520. key: "isConnected",
  19521. value: function isConnected() {
  19522. return this.status === C.STATUS_CONNECTED;
  19523. }
  19524. }, {
  19525. key: "isConnecting",
  19526. value: function isConnecting() {
  19527. return this.status === C.STATUS_CONNECTING;
  19528. }
  19529. /**
  19530. * Private API.
  19531. */
  19532. }, {
  19533. key: "_reconnect",
  19534. value: function _reconnect() {
  19535. var _this = this;
  19536. this.recover_attempts += 1;
  19537. var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1);
  19538. if (k < this.recovery_options.min_interval) {
  19539. k = this.recovery_options.min_interval;
  19540. } else if (k > this.recovery_options.max_interval) {
  19541. k = this.recovery_options.max_interval;
  19542. }
  19543. logger.debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds"));
  19544. this.recovery_timer = setTimeout(function () {
  19545. if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) {
  19546. // Get the next available socket with higher weight.
  19547. _this._getSocket(); // Connect the socket.
  19548. _this.connect();
  19549. }
  19550. }, k * 1000);
  19551. }
  19552. /**
  19553. * get the next available socket with higher weight
  19554. */
  19555. }, {
  19556. key: "_getSocket",
  19557. value: function _getSocket() {
  19558. var candidates = [];
  19559. this.sockets.forEach(function (socket) {
  19560. if (socket.status === C.SOCKET_STATUS_ERROR) {
  19561. return; // continue the array iteration
  19562. } else if (candidates.length === 0) {
  19563. candidates.push(socket);
  19564. } else if (socket.weight > candidates[0].weight) {
  19565. candidates = [socket];
  19566. } else if (socket.weight === candidates[0].weight) {
  19567. candidates.push(socket);
  19568. }
  19569. });
  19570. if (candidates.length === 0) {
  19571. // All sockets have failed. reset sockets status.
  19572. this.sockets.forEach(function (socket) {
  19573. socket.status = C.SOCKET_STATUS_READY;
  19574. }); // Get next available socket.
  19575. this._getSocket();
  19576. return;
  19577. }
  19578. var idx = Math.floor(Math.random() * candidates.length);
  19579. this.socket = candidates[idx].socket;
  19580. }
  19581. /**
  19582. * Socket Event Handlers
  19583. */
  19584. }, {
  19585. key: "_onConnect",
  19586. value: function _onConnect() {
  19587. this.recover_attempts = 0;
  19588. this.status = C.STATUS_CONNECTED; // Clear recovery_timer.
  19589. if (this.recovery_timer !== null) {
  19590. clearTimeout(this.recovery_timer);
  19591. this.recovery_timer = null;
  19592. }
  19593. this.onconnect({
  19594. socket: this
  19595. });
  19596. }
  19597. }, {
  19598. key: "_onDisconnect",
  19599. value: function _onDisconnect(error, code, reason) {
  19600. this.status = C.STATUS_DISCONNECTED;
  19601. this.ondisconnect({
  19602. socket: this.socket,
  19603. error: error,
  19604. code: code,
  19605. reason: reason
  19606. });
  19607. if (this.close_requested) {
  19608. return;
  19609. } // Update socket status.
  19610. else {
  19611. this.sockets.forEach(function (socket) {
  19612. if (this.socket === socket.socket) {
  19613. socket.status = C.SOCKET_STATUS_ERROR;
  19614. }
  19615. }, this);
  19616. }
  19617. this._reconnect(error);
  19618. }
  19619. }, {
  19620. key: "_onData",
  19621. value: function _onData(data) {
  19622. // CRLF Keep Alive response from server. Ignore it.
  19623. if (data === '\r\n') {
  19624. logger.debug('received message with CRLF Keep Alive response');
  19625. return;
  19626. } // Binary message.
  19627. else if (typeof data !== 'string') {
  19628. try {
  19629. if (this.textDecoder) data = this.textDecoder.decode(data);else data = String.fromCharCode.apply(null, new Uint8Array(data));
  19630. } catch (evt) {
  19631. logger.debug('received binary message failed to be converted into string,' + ' message discarded');
  19632. return;
  19633. }
  19634. logger.debug("received binary message:\n\n".concat(data, "\n"));
  19635. } // Text message.
  19636. else {
  19637. logger.debug("received text message:\n\n".concat(data, "\n"));
  19638. }
  19639. this.ondata({
  19640. transport: this,
  19641. message: data
  19642. });
  19643. }
  19644. }, {
  19645. key: "via_transport",
  19646. get: function get() {
  19647. return this.socket.via_transport;
  19648. }
  19649. }, {
  19650. key: "url",
  19651. get: function get() {
  19652. return this.socket.url;
  19653. }
  19654. }, {
  19655. key: "sip_uri",
  19656. get: function get() {
  19657. return this.socket.sip_uri;
  19658. }
  19659. }]);
  19660. return Transport;
  19661. }();
  19662. },{"./Constants":2,"./Logger":9,"./Socket":22}],26:[function(require,module,exports){
  19663. "use strict";
  19664. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  19665. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  19666. 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); } }
  19667. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  19668. 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); }
  19669. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  19670. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  19671. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  19672. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  19673. 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; } }
  19674. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  19675. var EventEmitter = require('events').EventEmitter;
  19676. var Logger = require('./Logger');
  19677. var JsSIP_C = require('./Constants');
  19678. var Registrator = require('./Registrator');
  19679. var RTCSession = require('./RTCSession');
  19680. var Message = require('./Message');
  19681. var Options = require('./Options');
  19682. var Transactions = require('./Transactions');
  19683. var Transport = require('./Transport');
  19684. var Utils = require('./Utils');
  19685. var Exceptions = require('./Exceptions');
  19686. var URI = require('./URI');
  19687. var Parser = require('./Parser');
  19688. var SIPMessage = require('./SIPMessage');
  19689. var sanityCheck = require('./sanityCheck');
  19690. var config = require('./Config');
  19691. var logger = new Logger('UA');
  19692. var C = {
  19693. // UA status codes.
  19694. STATUS_INIT: 0,
  19695. STATUS_READY: 1,
  19696. STATUS_USER_CLOSED: 2,
  19697. STATUS_NOT_READY: 3,
  19698. // UA error codes.
  19699. CONFIGURATION_ERROR: 1,
  19700. NETWORK_ERROR: 2
  19701. };
  19702. /**
  19703. * The User-Agent class.
  19704. * @class JsSIP.UA
  19705. * @param {Object} configuration Configuration parameters.
  19706. * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid.
  19707. * @throws {TypeError} If no configuration is given.
  19708. */
  19709. module.exports = /*#__PURE__*/function (_EventEmitter) {
  19710. _inherits(UA, _EventEmitter);
  19711. var _super = _createSuper(UA);
  19712. _createClass(UA, null, [{
  19713. key: "C",
  19714. // Expose C object.
  19715. get: function get() {
  19716. return C;
  19717. }
  19718. }]);
  19719. function UA(configuration) {
  19720. var _this;
  19721. _classCallCheck(this, UA);
  19722. logger.debug('new() [configuration:%o]', configuration);
  19723. _this = _super.call(this);
  19724. _this._cache = {
  19725. credentials: {}
  19726. };
  19727. _this._configuration = Object.assign({}, config.settings);
  19728. _this._dynConfiguration = {};
  19729. _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE/OPTIONS).
  19730. _this._applicants = {};
  19731. _this._sessions = {};
  19732. _this._transport = null;
  19733. _this._contact = null;
  19734. _this._status = C.STATUS_INIT;
  19735. _this._error = null;
  19736. _this._transactions = {
  19737. nist: {},
  19738. nict: {},
  19739. ist: {},
  19740. ict: {}
  19741. }; // Custom UA empty object for high level use.
  19742. _this._data = {};
  19743. _this._closeTimer = null; // Check configuration argument.
  19744. if (configuration === undefined) {
  19745. throw new TypeError('Not enough arguments');
  19746. } // Load configuration.
  19747. try {
  19748. _this._loadConfig(configuration);
  19749. } catch (e) {
  19750. _this._status = C.STATUS_NOT_READY;
  19751. _this._error = C.CONFIGURATION_ERROR;
  19752. throw e;
  19753. } // Initialize registrator.
  19754. _this._registrator = new Registrator(_assertThisInitialized(_this));
  19755. return _this;
  19756. }
  19757. _createClass(UA, [{
  19758. key: "start",
  19759. // =================
  19760. // High Level API
  19761. // =================
  19762. /**
  19763. * Connect to the server if status = STATUS_INIT.
  19764. * Resume UA after being closed.
  19765. */
  19766. value: function start() {
  19767. logger.debug('start()');
  19768. if (this._status === C.STATUS_INIT) {
  19769. this._transport.connect();
  19770. } else if (this._status === C.STATUS_USER_CLOSED) {
  19771. logger.debug('restarting UA'); // Disconnect.
  19772. if (this._closeTimer !== null) {
  19773. clearTimeout(this._closeTimer);
  19774. this._closeTimer = null;
  19775. this._transport.disconnect();
  19776. } // Reconnect.
  19777. this._status = C.STATUS_INIT;
  19778. this._transport.connect();
  19779. } else if (this._status === C.STATUS_READY) {
  19780. logger.debug('UA is in READY status, not restarted');
  19781. } else {
  19782. logger.debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect');
  19783. } // Set dynamic configuration.
  19784. this._dynConfiguration.register = this._configuration.register;
  19785. }
  19786. /**
  19787. * Register.
  19788. */
  19789. }, {
  19790. key: "register",
  19791. value: function register() {
  19792. logger.debug('register()');
  19793. this._dynConfiguration.register = true;
  19794. this._registrator.register();
  19795. }
  19796. /**
  19797. * Unregister.
  19798. */
  19799. }, {
  19800. key: "unregister",
  19801. value: function unregister(options) {
  19802. logger.debug('unregister()');
  19803. this._dynConfiguration.register = false;
  19804. this._registrator.unregister(options);
  19805. }
  19806. /**
  19807. * Get the Registrator instance.
  19808. */
  19809. }, {
  19810. key: "registrator",
  19811. value: function registrator() {
  19812. return this._registrator;
  19813. }
  19814. /**
  19815. * Registration state.
  19816. */
  19817. }, {
  19818. key: "isRegistered",
  19819. value: function isRegistered() {
  19820. return this._registrator.registered;
  19821. }
  19822. /**
  19823. * Connection state.
  19824. */
  19825. }, {
  19826. key: "isConnected",
  19827. value: function isConnected() {
  19828. return this._transport.isConnected();
  19829. }
  19830. /**
  19831. * Make an outgoing call.
  19832. *
  19833. * -param {String} target
  19834. * -param {Object} [options]
  19835. *
  19836. * -throws {TypeError}
  19837. *
  19838. */
  19839. }, {
  19840. key: "call",
  19841. value: function call(target, options) {
  19842. logger.debug('call()');
  19843. var session = new RTCSession(this);
  19844. session.connect(target, options);
  19845. return session;
  19846. }
  19847. /**
  19848. * Send a message.
  19849. *
  19850. * -param {String} target
  19851. * -param {String} body
  19852. * -param {Object} [options]
  19853. *
  19854. * -throws {TypeError}
  19855. *
  19856. */
  19857. }, {
  19858. key: "sendMessage",
  19859. value: function sendMessage(target, body, options) {
  19860. logger.debug('sendMessage()');
  19861. var message = new Message(this);
  19862. message.send(target, body, options);
  19863. return message;
  19864. }
  19865. /**
  19866. * Send a SIP OPTIONS.
  19867. *
  19868. * -param {String} target
  19869. * -param {String} [body]
  19870. * -param {Object} [options]
  19871. *
  19872. * -throws {TypeError}
  19873. *
  19874. */
  19875. }, {
  19876. key: "sendOptions",
  19877. value: function sendOptions(target, body, options) {
  19878. logger.debug('sendOptions()');
  19879. var message = new Options(this);
  19880. message.send(target, body, options);
  19881. return message;
  19882. }
  19883. /**
  19884. * Terminate ongoing sessions.
  19885. */
  19886. }, {
  19887. key: "terminateSessions",
  19888. value: function terminateSessions(options) {
  19889. logger.debug('terminateSessions()');
  19890. for (var idx in this._sessions) {
  19891. if (!this._sessions[idx].isEnded()) {
  19892. this._sessions[idx].terminate(options);
  19893. }
  19894. }
  19895. }
  19896. /**
  19897. * Gracefully close.
  19898. *
  19899. */
  19900. }, {
  19901. key: "stop",
  19902. value: function stop() {
  19903. var _this2 = this;
  19904. logger.debug('stop()'); // Remove dynamic settings.
  19905. this._dynConfiguration = {};
  19906. if (this._status === C.STATUS_USER_CLOSED) {
  19907. logger.debug('UA already closed');
  19908. return;
  19909. } // Close registrator.
  19910. this._registrator.close(); // If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
  19911. var num_sessions = Object.keys(this._sessions).length; // Run _terminate_ on every Session.
  19912. for (var session in this._sessions) {
  19913. if (Object.prototype.hasOwnProperty.call(this._sessions, session)) {
  19914. logger.debug("closing session ".concat(session));
  19915. try {
  19916. this._sessions[session].terminate();
  19917. } catch (error) {}
  19918. }
  19919. } // Run _close_ on every applicant.
  19920. for (var applicant in this._applicants) {
  19921. if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try {
  19922. this._applicants[applicant].close();
  19923. } catch (error) {}
  19924. }
  19925. this._status = C.STATUS_USER_CLOSED;
  19926. 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;
  19927. if (num_transactions === 0 && num_sessions === 0) {
  19928. this._transport.disconnect();
  19929. } else {
  19930. this._closeTimer = setTimeout(function () {
  19931. _this2._closeTimer = null;
  19932. _this2._transport.disconnect();
  19933. }, 2000);
  19934. }
  19935. }
  19936. /**
  19937. * Normalice a string into a valid SIP request URI
  19938. * -param {String} target
  19939. * -returns {JsSIP.URI|undefined}
  19940. */
  19941. }, {
  19942. key: "normalizeTarget",
  19943. value: function normalizeTarget(target) {
  19944. return Utils.normalizeTarget(target, this._configuration.hostport_params);
  19945. }
  19946. /**
  19947. * Allow retrieving configuration and autogenerated fields in runtime.
  19948. */
  19949. }, {
  19950. key: "get",
  19951. value: function get(parameter) {
  19952. switch (parameter) {
  19953. case 'authorization_user':
  19954. return this._configuration.authorization_user;
  19955. case 'realm':
  19956. return this._configuration.realm;
  19957. case 'ha1':
  19958. return this._configuration.ha1;
  19959. case 'authorization_jwt':
  19960. return this._configuration.authorization_jwt;
  19961. default:
  19962. logger.warn('get() | cannot get "%s" parameter in runtime', parameter);
  19963. return undefined;
  19964. }
  19965. }
  19966. /**
  19967. * Allow configuration changes in runtime.
  19968. * Returns true if the parameter could be set.
  19969. */
  19970. }, {
  19971. key: "set",
  19972. value: function set(parameter, value) {
  19973. switch (parameter) {
  19974. case 'authorization_user':
  19975. {
  19976. this._configuration.authorization_user = String(value);
  19977. break;
  19978. }
  19979. case 'password':
  19980. {
  19981. this._configuration.password = String(value);
  19982. break;
  19983. }
  19984. case 'realm':
  19985. {
  19986. this._configuration.realm = String(value);
  19987. break;
  19988. }
  19989. case 'ha1':
  19990. {
  19991. this._configuration.ha1 = String(value); // Delete the plain SIP password.
  19992. this._configuration.password = null;
  19993. break;
  19994. }
  19995. case 'authorization_jwt':
  19996. {
  19997. this._configuration.authorization_jwt = String(value);
  19998. break;
  19999. }
  20000. case 'display_name':
  20001. {
  20002. this._configuration.display_name = value;
  20003. break;
  20004. }
  20005. default:
  20006. logger.warn('set() | cannot set "%s" parameter in runtime', parameter);
  20007. return false;
  20008. }
  20009. return true;
  20010. } // ==========================
  20011. // Event Handlers.
  20012. // ==========================
  20013. /**
  20014. * new Transaction
  20015. */
  20016. }, {
  20017. key: "newTransaction",
  20018. value: function newTransaction(transaction) {
  20019. this._transactions[transaction.type][transaction.id] = transaction;
  20020. this.emit('newTransaction', {
  20021. transaction: transaction
  20022. });
  20023. }
  20024. /**
  20025. * Transaction destroyed.
  20026. */
  20027. }, {
  20028. key: "destroyTransaction",
  20029. value: function destroyTransaction(transaction) {
  20030. delete this._transactions[transaction.type][transaction.id];
  20031. this.emit('transactionDestroyed', {
  20032. transaction: transaction
  20033. });
  20034. }
  20035. /**
  20036. * new Dialog
  20037. */
  20038. }, {
  20039. key: "newDialog",
  20040. value: function newDialog(dialog) {
  20041. this._dialogs[dialog.id] = dialog;
  20042. }
  20043. /**
  20044. * Dialog destroyed.
  20045. */
  20046. }, {
  20047. key: "destroyDialog",
  20048. value: function destroyDialog(dialog) {
  20049. delete this._dialogs[dialog.id];
  20050. }
  20051. /**
  20052. * new Message
  20053. */
  20054. }, {
  20055. key: "newMessage",
  20056. value: function newMessage(message, data) {
  20057. this._applicants[message] = message;
  20058. this.emit('newMessage', data);
  20059. }
  20060. /**
  20061. * new Options
  20062. */
  20063. }, {
  20064. key: "newOptions",
  20065. value: function newOptions(message, data) {
  20066. this._applicants[message] = message;
  20067. this.emit('newOptions', data);
  20068. }
  20069. /**
  20070. * Message destroyed.
  20071. */
  20072. }, {
  20073. key: "destroyMessage",
  20074. value: function destroyMessage(message) {
  20075. delete this._applicants[message];
  20076. }
  20077. /**
  20078. * new RTCSession
  20079. */
  20080. }, {
  20081. key: "newRTCSession",
  20082. value: function newRTCSession(session, data) {
  20083. this._sessions[session.id] = session;
  20084. this.emit('newRTCSession', data);
  20085. }
  20086. /**
  20087. * RTCSession destroyed.
  20088. */
  20089. }, {
  20090. key: "destroyRTCSession",
  20091. value: function destroyRTCSession(session) {
  20092. delete this._sessions[session.id];
  20093. }
  20094. /**
  20095. * Registered
  20096. */
  20097. }, {
  20098. key: "registered",
  20099. value: function registered(data) {
  20100. this.emit('registered', data);
  20101. }
  20102. /**
  20103. * Unregistered
  20104. */
  20105. }, {
  20106. key: "unregistered",
  20107. value: function unregistered(data) {
  20108. this.emit('unregistered', data);
  20109. }
  20110. /**
  20111. * Registration Failed
  20112. */
  20113. }, {
  20114. key: "registrationFailed",
  20115. value: function registrationFailed(data) {
  20116. this.emit('registrationFailed', data);
  20117. } // =========================
  20118. // ReceiveRequest.
  20119. // =========================
  20120. /**
  20121. * Request reception
  20122. */
  20123. }, {
  20124. key: "receiveRequest",
  20125. value: function receiveRequest(request) {
  20126. var method = request.method; // Check that request URI points to us.
  20127. if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) {
  20128. logger.debug('Request-URI does not point to us');
  20129. if (request.method !== JsSIP_C.ACK) {
  20130. request.reply_sl(404);
  20131. }
  20132. return;
  20133. } // Check request URI scheme.
  20134. if (request.ruri.scheme === JsSIP_C.SIPS) {
  20135. request.reply_sl(416);
  20136. return;
  20137. } // Check transaction.
  20138. if (Transactions.checkTransaction(this, request)) {
  20139. return;
  20140. } // Create the server transaction.
  20141. if (method === JsSIP_C.INVITE) {
  20142. /* eslint-disable no-new */
  20143. new Transactions.InviteServerTransaction(this, this._transport, request);
  20144. /* eslint-enable no-new */
  20145. } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) {
  20146. /* eslint-disable no-new */
  20147. new Transactions.NonInviteServerTransaction(this, this._transport, request);
  20148. /* eslint-enable no-new */
  20149. }
  20150. /* RFC3261 12.2.2
  20151. * Requests that do not change in any way the state of a dialog may be
  20152. * received within a dialog (for example, an OPTIONS request).
  20153. * They are processed as if they had been received outside the dialog.
  20154. */
  20155. if (method === JsSIP_C.OPTIONS) {
  20156. if (this.listeners('newOptions').length === 0) {
  20157. request.reply(200);
  20158. return;
  20159. }
  20160. var message = new Options(this);
  20161. message.init_incoming(request);
  20162. } else if (method === JsSIP_C.MESSAGE) {
  20163. if (this.listeners('newMessage').length === 0) {
  20164. request.reply(405);
  20165. return;
  20166. }
  20167. var _message = new Message(this);
  20168. _message.init_incoming(request);
  20169. } else if (method === JsSIP_C.INVITE) {
  20170. // Initial INVITE.
  20171. if (!request.to_tag && this.listeners('newRTCSession').length === 0) {
  20172. request.reply(405);
  20173. return;
  20174. }
  20175. }
  20176. var dialog;
  20177. var session; // Initial Request.
  20178. if (!request.to_tag) {
  20179. switch (method) {
  20180. case JsSIP_C.INVITE:
  20181. if (window.RTCPeerConnection) {
  20182. // TODO
  20183. if (request.hasHeader('replaces')) {
  20184. var replaces = request.replaces;
  20185. dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag);
  20186. if (dialog) {
  20187. session = dialog.owner;
  20188. if (!session.isEnded()) {
  20189. session.receiveRequest(request);
  20190. } else {
  20191. request.reply(603);
  20192. }
  20193. } else {
  20194. request.reply(481);
  20195. }
  20196. } else {
  20197. session = new RTCSession(this);
  20198. session.init_incoming(request);
  20199. }
  20200. } else {
  20201. logger.warn('INVITE received but WebRTC is not supported');
  20202. request.reply(488);
  20203. }
  20204. break;
  20205. case JsSIP_C.BYE:
  20206. // Out of dialog BYE received.
  20207. request.reply(481);
  20208. break;
  20209. case JsSIP_C.CANCEL:
  20210. session = this._findSession(request);
  20211. if (session) {
  20212. session.receiveRequest(request);
  20213. } else {
  20214. logger.debug('received CANCEL request for a non existent session');
  20215. }
  20216. break;
  20217. case JsSIP_C.ACK:
  20218. /* Absorb it.
  20219. * ACK request without a corresponding Invite Transaction
  20220. * and without To tag.
  20221. */
  20222. break;
  20223. case JsSIP_C.NOTIFY:
  20224. // Receive new sip event.
  20225. this.emit('sipEvent', {
  20226. event: request.event,
  20227. request: request
  20228. });
  20229. request.reply(200);
  20230. break;
  20231. default:
  20232. request.reply(405);
  20233. break;
  20234. }
  20235. } // In-dialog request.
  20236. else {
  20237. dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag);
  20238. if (dialog) {
  20239. dialog.receiveRequest(request);
  20240. } else if (method === JsSIP_C.NOTIFY) {
  20241. session = this._findSession(request);
  20242. if (session) {
  20243. session.receiveRequest(request);
  20244. } else {
  20245. logger.debug('received NOTIFY request for a non existent subscription');
  20246. request.reply(481, 'Subscription does not exist');
  20247. }
  20248. }
  20249. /* RFC3261 12.2.2
  20250. * Request with to tag, but no matching dialog found.
  20251. * Exception: ACK for an Invite request for which a dialog has not
  20252. * been created.
  20253. */
  20254. else if (method !== JsSIP_C.ACK) {
  20255. request.reply(481);
  20256. }
  20257. }
  20258. } // =================
  20259. // Utils.
  20260. // =================
  20261. /**
  20262. * Get the session to which the request belongs to, if any.
  20263. */
  20264. }, {
  20265. key: "_findSession",
  20266. value: function _findSession(_ref) {
  20267. var call_id = _ref.call_id,
  20268. from_tag = _ref.from_tag,
  20269. to_tag = _ref.to_tag;
  20270. var sessionIDa = call_id + from_tag;
  20271. var sessionA = this._sessions[sessionIDa];
  20272. var sessionIDb = call_id + to_tag;
  20273. var sessionB = this._sessions[sessionIDb];
  20274. if (sessionA) {
  20275. return sessionA;
  20276. } else if (sessionB) {
  20277. return sessionB;
  20278. } else {
  20279. return null;
  20280. }
  20281. }
  20282. /**
  20283. * Get the dialog to which the request belongs to, if any.
  20284. */
  20285. }, {
  20286. key: "_findDialog",
  20287. value: function _findDialog(call_id, from_tag, to_tag) {
  20288. var id = call_id + from_tag + to_tag;
  20289. var dialog = this._dialogs[id];
  20290. if (dialog) {
  20291. return dialog;
  20292. } else {
  20293. id = call_id + to_tag + from_tag;
  20294. dialog = this._dialogs[id];
  20295. if (dialog) {
  20296. return dialog;
  20297. } else {
  20298. return null;
  20299. }
  20300. }
  20301. }
  20302. }, {
  20303. key: "_loadConfig",
  20304. value: function _loadConfig(configuration) {
  20305. // Check and load the given configuration.
  20306. try {
  20307. config.load(this._configuration, configuration);
  20308. } catch (e) {
  20309. throw e;
  20310. } // Post Configuration Process.
  20311. // Allow passing 0 number as display_name.
  20312. if (this._configuration.display_name === 0) {
  20313. this._configuration.display_name = '0';
  20314. } // Instance-id for GRUU.
  20315. if (!this._configuration.instance_id) {
  20316. this._configuration.instance_id = Utils.newUUID();
  20317. } // Jssip_id instance parameter. Static random tag of length 5.
  20318. this._configuration.jssip_id = Utils.createRandomToken(5); // String containing this._configuration.uri without scheme and user.
  20319. var hostport_params = this._configuration.uri.clone();
  20320. hostport_params.user = null;
  20321. this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, ''); // Transport.
  20322. try {
  20323. this._transport = new Transport(this._configuration.sockets, {
  20324. // Recovery options.
  20325. max_interval: this._configuration.connection_recovery_max_interval,
  20326. min_interval: this._configuration.connection_recovery_min_interval
  20327. }); // Transport event callbacks.
  20328. this._transport.onconnecting = onTransportConnecting.bind(this);
  20329. this._transport.onconnect = onTransportConnect.bind(this);
  20330. this._transport.ondisconnect = onTransportDisconnect.bind(this);
  20331. this._transport.ondata = onTransportData.bind(this);
  20332. } catch (e) {
  20333. logger.warn(e);
  20334. throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets);
  20335. } // Remove sockets instance from configuration object.
  20336. delete this._configuration.sockets; // Check whether authorization_user is explicitly defined.
  20337. // Take 'this._configuration.uri.user' value if not.
  20338. if (!this._configuration.authorization_user) {
  20339. this._configuration.authorization_user = this._configuration.uri.user;
  20340. } // If no 'registrar_server' is set use the 'uri' value without user portion and
  20341. // without URI params/headers.
  20342. if (!this._configuration.registrar_server) {
  20343. var registrar_server = this._configuration.uri.clone();
  20344. registrar_server.user = null;
  20345. registrar_server.clearParams();
  20346. registrar_server.clearHeaders();
  20347. this._configuration.registrar_server = registrar_server;
  20348. } // User no_answer_timeout.
  20349. this._configuration.no_answer_timeout *= 1000; // Via Host.
  20350. if (this._configuration.contact_uri) {
  20351. this._configuration.via_host = this._configuration.contact_uri.host;
  20352. } // Contact URI.
  20353. else {
  20354. this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, {
  20355. transport: 'ws'
  20356. });
  20357. }
  20358. this._contact = {
  20359. pub_gruu: null,
  20360. temp_gruu: null,
  20361. uri: this._configuration.contact_uri,
  20362. toString: function toString() {
  20363. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20364. var anonymous = options.anonymous || null;
  20365. var outbound = options.outbound || null;
  20366. var contact = '<';
  20367. if (anonymous) {
  20368. contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
  20369. } else {
  20370. contact += this.pub_gruu || this.uri.toString();
  20371. }
  20372. if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) {
  20373. contact += ';ob';
  20374. }
  20375. contact += '>';
  20376. return contact;
  20377. }
  20378. }; // Seal the configuration.
  20379. var writable_parameters = ['authorization_user', 'password', 'realm', 'ha1', 'authorization_jwt', 'display_name', 'register'];
  20380. for (var parameter in this._configuration) {
  20381. if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) {
  20382. if (writable_parameters.indexOf(parameter) !== -1) {
  20383. Object.defineProperty(this._configuration, parameter, {
  20384. writable: true,
  20385. configurable: false
  20386. });
  20387. } else {
  20388. Object.defineProperty(this._configuration, parameter, {
  20389. writable: false,
  20390. configurable: false
  20391. });
  20392. }
  20393. }
  20394. }
  20395. logger.debug('configuration parameters after validation:');
  20396. for (var _parameter in this._configuration) {
  20397. // Only show the user user configurable parameters.
  20398. if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) {
  20399. switch (_parameter) {
  20400. case 'uri':
  20401. case 'registrar_server':
  20402. logger.debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter]));
  20403. break;
  20404. case 'password':
  20405. case 'ha1':
  20406. case 'authorization_jwt':
  20407. logger.debug("- ".concat(_parameter, ": NOT SHOWN"));
  20408. break;
  20409. default:
  20410. logger.debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter])));
  20411. }
  20412. }
  20413. }
  20414. return;
  20415. }
  20416. }, {
  20417. key: "C",
  20418. get: function get() {
  20419. return C;
  20420. }
  20421. }, {
  20422. key: "status",
  20423. get: function get() {
  20424. return this._status;
  20425. }
  20426. }, {
  20427. key: "contact",
  20428. get: function get() {
  20429. return this._contact;
  20430. }
  20431. }, {
  20432. key: "configuration",
  20433. get: function get() {
  20434. return this._configuration;
  20435. }
  20436. }, {
  20437. key: "transport",
  20438. get: function get() {
  20439. return this._transport;
  20440. }
  20441. }]);
  20442. return UA;
  20443. }(EventEmitter);
  20444. /**
  20445. * Transport event handlers
  20446. */
  20447. // Transport connecting event.
  20448. function onTransportConnecting(data) {
  20449. this.emit('connecting', data);
  20450. } // Transport connected event.
  20451. function onTransportConnect(data) {
  20452. if (this._status === C.STATUS_USER_CLOSED) {
  20453. return;
  20454. }
  20455. this._status = C.STATUS_READY;
  20456. this._error = null;
  20457. this.emit('connected', data);
  20458. if (this._dynConfiguration.register) {
  20459. this._registrator.register();
  20460. }
  20461. } // Transport disconnected event.
  20462. function onTransportDisconnect(data) {
  20463. // Run _onTransportError_ callback on every client transaction using _transport_.
  20464. var client_transactions = ['nict', 'ict', 'nist', 'ist'];
  20465. for (var _i = 0, _client_transactions = client_transactions; _i < _client_transactions.length; _i++) {
  20466. var type = _client_transactions[_i];
  20467. for (var id in this._transactions[type]) {
  20468. if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) {
  20469. this._transactions[type][id].onTransportError();
  20470. }
  20471. }
  20472. }
  20473. this.emit('disconnected', data); // Call registrator _onTransportClosed_.
  20474. this._registrator.onTransportClosed();
  20475. if (this._status !== C.STATUS_USER_CLOSED) {
  20476. this._status = C.STATUS_NOT_READY;
  20477. this._error = C.NETWORK_ERROR;
  20478. }
  20479. } // Transport data event.
  20480. function onTransportData(data) {
  20481. var transport = data.transport;
  20482. var message = data.message;
  20483. message = Parser.parseMessage(message, this);
  20484. if (!message) {
  20485. return;
  20486. }
  20487. if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) {
  20488. return;
  20489. } // Do some sanity check.
  20490. if (!sanityCheck(message, this, transport)) {
  20491. return;
  20492. }
  20493. if (message instanceof SIPMessage.IncomingRequest) {
  20494. message.transport = transport;
  20495. this.receiveRequest(message);
  20496. } else if (message instanceof SIPMessage.IncomingResponse) {
  20497. /* Unike stated in 18.1.2, if a response does not match
  20498. * any transaction, it is discarded here and no passed to the core
  20499. * in order to be discarded there.
  20500. */
  20501. var transaction;
  20502. switch (message.method) {
  20503. case JsSIP_C.INVITE:
  20504. transaction = this._transactions.ict[message.via_branch];
  20505. if (transaction) {
  20506. transaction.receiveResponse(message);
  20507. }
  20508. break;
  20509. case JsSIP_C.ACK:
  20510. // Just in case ;-).
  20511. break;
  20512. default:
  20513. transaction = this._transactions.nict[message.via_branch];
  20514. if (transaction) {
  20515. transaction.receiveResponse(message);
  20516. }
  20517. break;
  20518. }
  20519. }
  20520. }
  20521. },{"./Config":1,"./Constants":2,"./Exceptions":6,"./Logger":9,"./Message":10,"./Options":12,"./Parser":13,"./RTCSession":14,"./Registrator":19,"./SIPMessage":21,"./Transactions":24,"./Transport":25,"./URI":27,"./Utils":28,"./sanityCheck":30,"events":31}],27:[function(require,module,exports){
  20522. "use strict";
  20523. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  20524. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  20525. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  20526. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20527. 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); } }
  20528. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  20529. var JsSIP_C = require('./Constants');
  20530. var Utils = require('./Utils');
  20531. var Grammar = require('./Grammar');
  20532. /**
  20533. * -param {String} [scheme]
  20534. * -param {String} [user]
  20535. * -param {String} host
  20536. * -param {String} [port]
  20537. * -param {Object} [parameters]
  20538. * -param {Object} [headers]
  20539. *
  20540. */
  20541. module.exports = /*#__PURE__*/function () {
  20542. _createClass(URI, null, [{
  20543. key: "parse",
  20544. /**
  20545. * Parse the given string and returns a JsSIP.URI instance or undefined if
  20546. * it is an invalid URI.
  20547. */
  20548. value: function parse(uri) {
  20549. uri = Grammar.parse(uri, 'SIP_URI');
  20550. if (uri !== -1) {
  20551. return uri;
  20552. } else {
  20553. return undefined;
  20554. }
  20555. }
  20556. }]);
  20557. function URI(scheme, user, host, port) {
  20558. var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  20559. var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
  20560. _classCallCheck(this, URI);
  20561. // Checks.
  20562. if (!host) {
  20563. throw new TypeError('missing or invalid "host" parameter');
  20564. } // Initialize parameters.
  20565. this._parameters = {};
  20566. this._headers = {};
  20567. this._scheme = scheme || JsSIP_C.SIP;
  20568. this._user = user;
  20569. this._host = host;
  20570. this._port = port;
  20571. for (var param in parameters) {
  20572. if (Object.prototype.hasOwnProperty.call(parameters, param)) {
  20573. this.setParam(param, parameters[param]);
  20574. }
  20575. }
  20576. for (var header in headers) {
  20577. if (Object.prototype.hasOwnProperty.call(headers, header)) {
  20578. this.setHeader(header, headers[header]);
  20579. }
  20580. }
  20581. }
  20582. _createClass(URI, [{
  20583. key: "setParam",
  20584. value: function setParam(key, value) {
  20585. if (key) {
  20586. this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
  20587. }
  20588. }
  20589. }, {
  20590. key: "getParam",
  20591. value: function getParam(key) {
  20592. if (key) {
  20593. return this._parameters[key.toLowerCase()];
  20594. }
  20595. }
  20596. }, {
  20597. key: "hasParam",
  20598. value: function hasParam(key) {
  20599. if (key) {
  20600. return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
  20601. }
  20602. }
  20603. }, {
  20604. key: "deleteParam",
  20605. value: function deleteParam(parameter) {
  20606. parameter = parameter.toLowerCase();
  20607. if (this._parameters.hasOwnProperty(parameter)) {
  20608. var value = this._parameters[parameter];
  20609. delete this._parameters[parameter];
  20610. return value;
  20611. }
  20612. }
  20613. }, {
  20614. key: "clearParams",
  20615. value: function clearParams() {
  20616. this._parameters = {};
  20617. }
  20618. }, {
  20619. key: "setHeader",
  20620. value: function setHeader(name, value) {
  20621. this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
  20622. }
  20623. }, {
  20624. key: "getHeader",
  20625. value: function getHeader(name) {
  20626. if (name) {
  20627. return this._headers[Utils.headerize(name)];
  20628. }
  20629. }
  20630. }, {
  20631. key: "hasHeader",
  20632. value: function hasHeader(name) {
  20633. if (name) {
  20634. return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false;
  20635. }
  20636. }
  20637. }, {
  20638. key: "deleteHeader",
  20639. value: function deleteHeader(header) {
  20640. header = Utils.headerize(header);
  20641. if (this._headers.hasOwnProperty(header)) {
  20642. var value = this._headers[header];
  20643. delete this._headers[header];
  20644. return value;
  20645. }
  20646. }
  20647. }, {
  20648. key: "clearHeaders",
  20649. value: function clearHeaders() {
  20650. this._headers = {};
  20651. }
  20652. }, {
  20653. key: "clone",
  20654. value: function clone() {
  20655. return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers)));
  20656. }
  20657. }, {
  20658. key: "toString",
  20659. value: function toString() {
  20660. var headers = [];
  20661. var uri = "".concat(this._scheme, ":");
  20662. if (this._user) {
  20663. uri += "".concat(Utils.escapeUser(this._user), "@");
  20664. }
  20665. uri += this._host;
  20666. if (this._port || this._port === 0) {
  20667. uri += ":".concat(this._port);
  20668. }
  20669. for (var parameter in this._parameters) {
  20670. if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
  20671. uri += ";".concat(parameter);
  20672. if (this._parameters[parameter] !== null) {
  20673. uri += "=".concat(this._parameters[parameter]);
  20674. }
  20675. }
  20676. }
  20677. for (var header in this._headers) {
  20678. if (Object.prototype.hasOwnProperty.call(this._headers, header)) {
  20679. var _iterator = _createForOfIteratorHelper(this._headers[header]),
  20680. _step;
  20681. try {
  20682. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  20683. var item = _step.value;
  20684. headers.push("".concat(header, "=").concat(item));
  20685. }
  20686. } catch (err) {
  20687. _iterator.e(err);
  20688. } finally {
  20689. _iterator.f();
  20690. }
  20691. }
  20692. }
  20693. if (headers.length > 0) {
  20694. uri += "?".concat(headers.join('&'));
  20695. }
  20696. return uri;
  20697. }
  20698. }, {
  20699. key: "toAor",
  20700. value: function toAor(show_port) {
  20701. var aor = "".concat(this._scheme, ":");
  20702. if (this._user) {
  20703. aor += "".concat(Utils.escapeUser(this._user), "@");
  20704. }
  20705. aor += this._host;
  20706. if (show_port && (this._port || this._port === 0)) {
  20707. aor += ":".concat(this._port);
  20708. }
  20709. return aor;
  20710. }
  20711. }, {
  20712. key: "scheme",
  20713. get: function get() {
  20714. return this._scheme;
  20715. },
  20716. set: function set(value) {
  20717. this._scheme = value.toLowerCase();
  20718. }
  20719. }, {
  20720. key: "user",
  20721. get: function get() {
  20722. return this._user;
  20723. },
  20724. set: function set(value) {
  20725. this._user = value;
  20726. }
  20727. }, {
  20728. key: "host",
  20729. get: function get() {
  20730. return this._host;
  20731. },
  20732. set: function set(value) {
  20733. this._host = value.toLowerCase();
  20734. }
  20735. }, {
  20736. key: "port",
  20737. get: function get() {
  20738. return this._port;
  20739. },
  20740. set: function set(value) {
  20741. this._port = value === 0 ? value : parseInt(value, 10) || null;
  20742. }
  20743. }]);
  20744. return URI;
  20745. }();
  20746. },{"./Constants":2,"./Grammar":7,"./Utils":28}],28:[function(require,module,exports){
  20747. "use strict";
  20748. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  20749. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  20750. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  20751. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  20752. var JsSIP_C = require('./Constants');
  20753. var URI = require('./URI');
  20754. var Grammar = require('./Grammar');
  20755. exports.str_utf8_length = function (string) {
  20756. return unescape(encodeURIComponent(string)).length;
  20757. }; // Used by 'hasMethods'.
  20758. var isFunction = exports.isFunction = function (fn) {
  20759. if (fn !== undefined) {
  20760. return Object.prototype.toString.call(fn) === '[object Function]' ? true : false;
  20761. } else {
  20762. return false;
  20763. }
  20764. };
  20765. exports.isString = function (str) {
  20766. if (str !== undefined) {
  20767. return Object.prototype.toString.call(str) === '[object String]' ? true : false;
  20768. } else {
  20769. return false;
  20770. }
  20771. };
  20772. exports.isDecimal = function (num) {
  20773. return !isNaN(num) && parseFloat(num) === parseInt(num, 10);
  20774. };
  20775. exports.isEmpty = function (value) {
  20776. return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value);
  20777. };
  20778. exports.hasMethods = function (obj) {
  20779. for (var _len = arguments.length, methodNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  20780. methodNames[_key - 1] = arguments[_key];
  20781. }
  20782. for (var _i = 0, _methodNames = methodNames; _i < _methodNames.length; _i++) {
  20783. var methodName = _methodNames[_i];
  20784. if (isFunction(obj[methodName])) {
  20785. return false;
  20786. }
  20787. }
  20788. return true;
  20789. }; // Used by 'newTag'.
  20790. var createRandomToken = exports.createRandomToken = function (size) {
  20791. var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32;
  20792. var i,
  20793. r,
  20794. token = '';
  20795. for (i = 0; i < size; i++) {
  20796. r = Math.random() * base | 0;
  20797. token += r.toString(base);
  20798. }
  20799. return token;
  20800. };
  20801. exports.newTag = function () {
  20802. return createRandomToken(10);
  20803. }; // https://stackoverflow.com/users/109538/broofa.
  20804. exports.newUUID = function () {
  20805. var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  20806. var r = Math.random() * 16 | 0,
  20807. v = c === 'x' ? r : r & 0x3 | 0x8;
  20808. return v.toString(16);
  20809. });
  20810. return UUID;
  20811. };
  20812. exports.hostType = function (host) {
  20813. if (!host) {
  20814. return;
  20815. } else {
  20816. host = Grammar.parse(host, 'host');
  20817. if (host !== -1) {
  20818. return host.host_type;
  20819. }
  20820. }
  20821. };
  20822. /**
  20823. * Hex-escape a SIP URI user.
  20824. * Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F).
  20825. *
  20826. * Used by 'normalizeTarget'.
  20827. */
  20828. var escapeUser = exports.escapeUser = function (user) {
  20829. return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/');
  20830. };
  20831. /**
  20832. * Normalize SIP URI.
  20833. * NOTE: It does not allow a SIP URI without username.
  20834. * Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'.
  20835. * Detects the domain part (if given) and properly hex-escapes the user portion.
  20836. * If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators.
  20837. */
  20838. exports.normalizeTarget = function (target, domain) {
  20839. // If no target is given then raise an error.
  20840. if (!target) {
  20841. return; // If a URI instance is given then return it.
  20842. } else if (target instanceof URI) {
  20843. return target; // If a string is given split it by '@':
  20844. // - Last fragment is the desired domain.
  20845. // - Otherwise append the given domain argument.
  20846. } else if (typeof target === 'string') {
  20847. var target_array = target.split('@');
  20848. var target_user;
  20849. var target_domain;
  20850. switch (target_array.length) {
  20851. case 1:
  20852. if (!domain) {
  20853. return;
  20854. }
  20855. target_user = target;
  20856. target_domain = domain;
  20857. break;
  20858. case 2:
  20859. target_user = target_array[0];
  20860. target_domain = target_array[1];
  20861. break;
  20862. default:
  20863. target_user = target_array.slice(0, target_array.length - 1).join('@');
  20864. target_domain = target_array[target_array.length - 1];
  20865. } // Remove the URI scheme (if present).
  20866. target_user = target_user.replace(/^(sips?|tel):/i, ''); // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols.
  20867. if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) {
  20868. target_user = target_user.replace(/[-.()]/g, '');
  20869. } // Build the complete SIP URI.
  20870. target = "".concat(JsSIP_C.SIP, ":").concat(escapeUser(target_user), "@").concat(target_domain); // Finally parse the resulting URI.
  20871. var uri;
  20872. if (uri = URI.parse(target)) {
  20873. return uri;
  20874. } else {
  20875. return;
  20876. }
  20877. } else {
  20878. return;
  20879. }
  20880. };
  20881. exports.headerize = function (string) {
  20882. var exceptions = {
  20883. 'Call-Id': 'Call-ID',
  20884. 'Cseq': 'CSeq',
  20885. 'Www-Authenticate': 'WWW-Authenticate'
  20886. };
  20887. var name = string.toLowerCase().replace(/_/g, '-').split('-');
  20888. var hname = '';
  20889. var parts = name.length;
  20890. var part;
  20891. for (part = 0; part < parts; part++) {
  20892. if (part !== 0) {
  20893. hname += '-';
  20894. }
  20895. hname += name[part].charAt(0).toUpperCase() + name[part].substring(1);
  20896. }
  20897. if (exceptions[hname]) {
  20898. hname = exceptions[hname];
  20899. }
  20900. return hname;
  20901. };
  20902. exports.sipErrorCause = function (status_code) {
  20903. for (var cause in JsSIP_C.SIP_ERROR_CAUSES) {
  20904. if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) {
  20905. return JsSIP_C.causes[cause];
  20906. }
  20907. }
  20908. return JsSIP_C.causes.SIP_FAILURE_CODE;
  20909. };
  20910. /**
  20911. * Generate a random Test-Net IP (https://tools.ietf.org/html/rfc5735)
  20912. */
  20913. exports.getRandomTestNetIP = function () {
  20914. function getOctet(from, to) {
  20915. return Math.floor(Math.random() * (to - from + 1) + from);
  20916. }
  20917. return "192.0.2.".concat(getOctet(1, 254));
  20918. }; // MD5 (Message-Digest Algorithm) https://www.webtoolkit.info.
  20919. exports.calculateMD5 = function (string) {
  20920. function rotateLeft(lValue, iShiftBits) {
  20921. return lValue << iShiftBits | lValue >>> 32 - iShiftBits;
  20922. }
  20923. function addUnsigned(lX, lY) {
  20924. var lX8 = lX & 0x80000000;
  20925. var lY8 = lY & 0x80000000;
  20926. var lX4 = lX & 0x40000000;
  20927. var lY4 = lY & 0x40000000;
  20928. var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
  20929. if (lX4 & lY4) {
  20930. return lResult ^ 0x80000000 ^ lX8 ^ lY8;
  20931. }
  20932. if (lX4 | lY4) {
  20933. if (lResult & 0x40000000) {
  20934. return lResult ^ 0xC0000000 ^ lX8 ^ lY8;
  20935. } else {
  20936. return lResult ^ 0x40000000 ^ lX8 ^ lY8;
  20937. }
  20938. } else {
  20939. return lResult ^ lX8 ^ lY8;
  20940. }
  20941. }
  20942. function doF(x, y, z) {
  20943. return x & y | ~x & z;
  20944. }
  20945. function doG(x, y, z) {
  20946. return x & z | y & ~z;
  20947. }
  20948. function doH(x, y, z) {
  20949. return x ^ y ^ z;
  20950. }
  20951. function doI(x, y, z) {
  20952. return y ^ (x | ~z);
  20953. }
  20954. function doFF(a, b, c, d, x, s, ac) {
  20955. a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac));
  20956. return addUnsigned(rotateLeft(a, s), b);
  20957. }
  20958. function doGG(a, b, c, d, x, s, ac) {
  20959. a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac));
  20960. return addUnsigned(rotateLeft(a, s), b);
  20961. }
  20962. function doHH(a, b, c, d, x, s, ac) {
  20963. a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac));
  20964. return addUnsigned(rotateLeft(a, s), b);
  20965. }
  20966. function doII(a, b, c, d, x, s, ac) {
  20967. a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac));
  20968. return addUnsigned(rotateLeft(a, s), b);
  20969. }
  20970. function convertToWordArray(str) {
  20971. var lWordCount;
  20972. var lMessageLength = str.length;
  20973. var lNumberOfWords_temp1 = lMessageLength + 8;
  20974. var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64;
  20975. var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
  20976. var lWordArray = new Array(lNumberOfWords - 1);
  20977. var lBytePosition = 0;
  20978. var lByteCount = 0;
  20979. while (lByteCount < lMessageLength) {
  20980. lWordCount = (lByteCount - lByteCount % 4) / 4;
  20981. lBytePosition = lByteCount % 4 * 8;
  20982. lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition;
  20983. lByteCount++;
  20984. }
  20985. lWordCount = (lByteCount - lByteCount % 4) / 4;
  20986. lBytePosition = lByteCount % 4 * 8;
  20987. lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition;
  20988. lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
  20989. lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
  20990. return lWordArray;
  20991. }
  20992. function wordToHex(lValue) {
  20993. var wordToHexValue = '',
  20994. wordToHexValue_temp = '',
  20995. lByte,
  20996. lCount;
  20997. for (lCount = 0; lCount <= 3; lCount++) {
  20998. lByte = lValue >>> lCount * 8 & 255;
  20999. wordToHexValue_temp = "0".concat(lByte.toString(16));
  21000. wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2);
  21001. }
  21002. return wordToHexValue;
  21003. }
  21004. function utf8Encode(str) {
  21005. str = str.replace(/\r\n/g, '\n');
  21006. var utftext = '';
  21007. for (var n = 0; n < str.length; n++) {
  21008. var _c = str.charCodeAt(n);
  21009. if (_c < 128) {
  21010. utftext += String.fromCharCode(_c);
  21011. } else if (_c > 127 && _c < 2048) {
  21012. utftext += String.fromCharCode(_c >> 6 | 192);
  21013. utftext += String.fromCharCode(_c & 63 | 128);
  21014. } else {
  21015. utftext += String.fromCharCode(_c >> 12 | 224);
  21016. utftext += String.fromCharCode(_c >> 6 & 63 | 128);
  21017. utftext += String.fromCharCode(_c & 63 | 128);
  21018. }
  21019. }
  21020. return utftext;
  21021. }
  21022. var x = [];
  21023. var k, AA, BB, CC, DD, a, b, c, d;
  21024. var S11 = 7,
  21025. S12 = 12,
  21026. S13 = 17,
  21027. S14 = 22;
  21028. var S21 = 5,
  21029. S22 = 9,
  21030. S23 = 14,
  21031. S24 = 20;
  21032. var S31 = 4,
  21033. S32 = 11,
  21034. S33 = 16,
  21035. S34 = 23;
  21036. var S41 = 6,
  21037. S42 = 10,
  21038. S43 = 15,
  21039. S44 = 21;
  21040. string = utf8Encode(string);
  21041. x = convertToWordArray(string);
  21042. a = 0x67452301;
  21043. b = 0xEFCDAB89;
  21044. c = 0x98BADCFE;
  21045. d = 0x10325476;
  21046. for (k = 0; k < x.length; k += 16) {
  21047. AA = a;
  21048. BB = b;
  21049. CC = c;
  21050. DD = d;
  21051. a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
  21052. d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
  21053. c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB);
  21054. b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
  21055. a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
  21056. d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
  21057. c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613);
  21058. b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501);
  21059. a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8);
  21060. d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
  21061. c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
  21062. b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
  21063. a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122);
  21064. d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193);
  21065. c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E);
  21066. b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821);
  21067. a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
  21068. d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340);
  21069. c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
  21070. b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
  21071. a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
  21072. d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453);
  21073. c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
  21074. b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
  21075. a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
  21076. d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
  21077. c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
  21078. b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
  21079. a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
  21080. d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
  21081. c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
  21082. b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
  21083. a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
  21084. d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681);
  21085. c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
  21086. b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
  21087. a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
  21088. d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
  21089. c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
  21090. b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
  21091. a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
  21092. d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
  21093. c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
  21094. b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05);
  21095. a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
  21096. d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
  21097. c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
  21098. b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
  21099. a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244);
  21100. d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97);
  21101. c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
  21102. b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039);
  21103. a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3);
  21104. d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
  21105. c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
  21106. b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1);
  21107. a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
  21108. d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
  21109. c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314);
  21110. b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
  21111. a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82);
  21112. d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
  21113. c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
  21114. b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391);
  21115. a = addUnsigned(a, AA);
  21116. b = addUnsigned(b, BB);
  21117. c = addUnsigned(c, CC);
  21118. d = addUnsigned(d, DD);
  21119. }
  21120. var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
  21121. return temp.toLowerCase();
  21122. };
  21123. exports.closeMediaStream = function (stream) {
  21124. if (!stream) {
  21125. return;
  21126. } // Latest spec states that MediaStream has no stop() method and instead must
  21127. // call stop() on every MediaStreamTrack.
  21128. try {
  21129. var tracks;
  21130. if (stream.getTracks) {
  21131. tracks = stream.getTracks();
  21132. var _iterator = _createForOfIteratorHelper(tracks),
  21133. _step;
  21134. try {
  21135. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  21136. var track = _step.value;
  21137. track.stop();
  21138. }
  21139. } catch (err) {
  21140. _iterator.e(err);
  21141. } finally {
  21142. _iterator.f();
  21143. }
  21144. } else {
  21145. tracks = stream.getAudioTracks();
  21146. var _iterator2 = _createForOfIteratorHelper(tracks),
  21147. _step2;
  21148. try {
  21149. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  21150. var _track = _step2.value;
  21151. _track.stop();
  21152. }
  21153. } catch (err) {
  21154. _iterator2.e(err);
  21155. } finally {
  21156. _iterator2.f();
  21157. }
  21158. tracks = stream.getVideoTracks();
  21159. var _iterator3 = _createForOfIteratorHelper(tracks),
  21160. _step3;
  21161. try {
  21162. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  21163. var _track2 = _step3.value;
  21164. _track2.stop();
  21165. }
  21166. } catch (err) {
  21167. _iterator3.e(err);
  21168. } finally {
  21169. _iterator3.f();
  21170. }
  21171. }
  21172. } catch (error) {
  21173. // Deprecated by the spec, but still in use.
  21174. // NOTE: In Temasys IE plugin stream.stop is a callable 'object'.
  21175. if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') {
  21176. stream.stop();
  21177. }
  21178. }
  21179. };
  21180. exports.cloneArray = function (array) {
  21181. return array && array.slice() || [];
  21182. };
  21183. exports.cloneObject = function (obj) {
  21184. var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21185. return obj && Object.assign({}, obj) || fallback;
  21186. };
  21187. },{"./Constants":2,"./Grammar":7,"./URI":27}],29:[function(require,module,exports){
  21188. "use strict";
  21189. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  21190. 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); } }
  21191. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  21192. var Logger = require('./Logger');
  21193. var Grammar = require('./Grammar');
  21194. var logger = new Logger('WebSocketInterface');
  21195. module.exports = /*#__PURE__*/function () {
  21196. function WebSocketInterface(url) {
  21197. _classCallCheck(this, WebSocketInterface);
  21198. logger.debug('new() [url:"%s"]', url);
  21199. this._url = url;
  21200. this._sip_uri = null;
  21201. this._via_transport = null;
  21202. this._ws = null;
  21203. var parsed_url = Grammar.parse(url, 'absoluteURI');
  21204. if (parsed_url === -1) {
  21205. logger.warn("invalid WebSocket URI: ".concat(url));
  21206. throw new TypeError("Invalid argument: ".concat(url));
  21207. } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') {
  21208. logger.warn("invalid WebSocket URI scheme: ".concat(parsed_url.scheme));
  21209. throw new TypeError("Invalid argument: ".concat(url));
  21210. } else {
  21211. this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws");
  21212. this._via_transport = parsed_url.scheme.toUpperCase();
  21213. }
  21214. }
  21215. _createClass(WebSocketInterface, [{
  21216. key: "connect",
  21217. value: function connect() {
  21218. logger.debug('connect()');
  21219. if (this.isConnected()) {
  21220. logger.debug("WebSocket ".concat(this._url, " is already connected"));
  21221. return;
  21222. } else if (this.isConnecting()) {
  21223. logger.debug("WebSocket ".concat(this._url, " is connecting"));
  21224. return;
  21225. }
  21226. if (this._ws) {
  21227. this.disconnect();
  21228. }
  21229. logger.debug("connecting to WebSocket ".concat(this._url));
  21230. try {
  21231. this._ws = new WebSocket(this._url, 'sip');
  21232. this._ws.binaryType = 'arraybuffer';
  21233. this._ws.onopen = this._onOpen.bind(this);
  21234. this._ws.onclose = this._onClose.bind(this);
  21235. this._ws.onmessage = this._onMessage.bind(this);
  21236. this._ws.onerror = this._onError.bind(this);
  21237. } catch (e) {
  21238. this._onError(e);
  21239. }
  21240. }
  21241. }, {
  21242. key: "disconnect",
  21243. value: function disconnect() {
  21244. logger.debug('disconnect()');
  21245. if (this._ws) {
  21246. // Unbind websocket event callbacks.
  21247. this._ws.onopen = function () {};
  21248. this._ws.onclose = function () {};
  21249. this._ws.onmessage = function () {};
  21250. this._ws.onerror = function () {};
  21251. this._ws.close();
  21252. this._ws = null;
  21253. }
  21254. }
  21255. }, {
  21256. key: "send",
  21257. value: function send(message) {
  21258. logger.debug('send()');
  21259. if (this.isConnected()) {
  21260. this._ws.send(message);
  21261. return true;
  21262. } else {
  21263. logger.warn('unable to send message, WebSocket is not open');
  21264. return false;
  21265. }
  21266. }
  21267. }, {
  21268. key: "isConnected",
  21269. value: function isConnected() {
  21270. return this._ws && this._ws.readyState === this._ws.OPEN;
  21271. }
  21272. }, {
  21273. key: "isConnecting",
  21274. value: function isConnecting() {
  21275. return this._ws && this._ws.readyState === this._ws.CONNECTING;
  21276. }
  21277. /**
  21278. * WebSocket Event Handlers
  21279. */
  21280. }, {
  21281. key: "_onOpen",
  21282. value: function _onOpen() {
  21283. logger.debug("WebSocket ".concat(this._url, " connected"));
  21284. this.onconnect();
  21285. }
  21286. }, {
  21287. key: "_onClose",
  21288. value: function _onClose(_ref) {
  21289. var wasClean = _ref.wasClean,
  21290. code = _ref.code,
  21291. reason = _ref.reason;
  21292. logger.debug("WebSocket ".concat(this._url, " closed"));
  21293. if (wasClean === false) {
  21294. logger.debug('WebSocket abrupt disconnection');
  21295. }
  21296. this.ondisconnect(!wasClean, code, reason);
  21297. }
  21298. }, {
  21299. key: "_onMessage",
  21300. value: function _onMessage(_ref2) {
  21301. var data = _ref2.data;
  21302. logger.debug('received WebSocket message');
  21303. this.ondata(data);
  21304. }
  21305. }, {
  21306. key: "_onError",
  21307. value: function _onError(e) {
  21308. logger.warn("WebSocket ".concat(this._url, " error: "), e);
  21309. }
  21310. }, {
  21311. key: "via_transport",
  21312. get: function get() {
  21313. return this._via_transport;
  21314. },
  21315. set: function set(value) {
  21316. this._via_transport = value.toUpperCase();
  21317. }
  21318. }, {
  21319. key: "sip_uri",
  21320. get: function get() {
  21321. return this._sip_uri;
  21322. }
  21323. }, {
  21324. key: "url",
  21325. get: function get() {
  21326. return this._url;
  21327. }
  21328. }]);
  21329. return WebSocketInterface;
  21330. }();
  21331. },{"./Grammar":7,"./Logger":9}],30:[function(require,module,exports){
  21332. "use strict";
  21333. function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  21334. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  21335. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  21336. var Logger = require('./Logger');
  21337. var JsSIP_C = require('./Constants');
  21338. var SIPMessage = require('./SIPMessage');
  21339. var Utils = require('./Utils');
  21340. var logger = new Logger('sanityCheck'); // Checks for requests and responses.
  21341. var all = [minimumHeaders]; // Checks for requests.
  21342. var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2]; // Checks for responses.
  21343. var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response]; // local variables.
  21344. var message;
  21345. var ua;
  21346. var transport;
  21347. module.exports = function (m, u, t) {
  21348. message = m;
  21349. ua = u;
  21350. transport = t;
  21351. var _iterator = _createForOfIteratorHelper(all),
  21352. _step;
  21353. try {
  21354. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  21355. var _check2 = _step.value;
  21356. if (_check2() === false) {
  21357. return false;
  21358. }
  21359. }
  21360. } catch (err) {
  21361. _iterator.e(err);
  21362. } finally {
  21363. _iterator.f();
  21364. }
  21365. if (message instanceof SIPMessage.IncomingRequest) {
  21366. var _iterator2 = _createForOfIteratorHelper(requests),
  21367. _step2;
  21368. try {
  21369. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  21370. var check = _step2.value;
  21371. if (check() === false) {
  21372. return false;
  21373. }
  21374. }
  21375. } catch (err) {
  21376. _iterator2.e(err);
  21377. } finally {
  21378. _iterator2.f();
  21379. }
  21380. } else if (message instanceof SIPMessage.IncomingResponse) {
  21381. var _iterator3 = _createForOfIteratorHelper(responses),
  21382. _step3;
  21383. try {
  21384. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  21385. var _check = _step3.value;
  21386. if (_check() === false) {
  21387. return false;
  21388. }
  21389. }
  21390. } catch (err) {
  21391. _iterator3.e(err);
  21392. } finally {
  21393. _iterator3.f();
  21394. }
  21395. } // Everything is OK.
  21396. return true;
  21397. };
  21398. /*
  21399. * Sanity Check for incoming Messages
  21400. *
  21401. * Requests:
  21402. * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme
  21403. * - _rfc3261_16_3_4_ Receive a Request already sent by us
  21404. * Does not look at via sent-by but at jssip_id, which is inserted as
  21405. * a prefix in all initial requests generated by the ua
  21406. * - _rfc3261_18_3_request_ Body Content-Length
  21407. * - _rfc3261_8_2_2_2_ Merged Requests
  21408. *
  21409. * Responses:
  21410. * - _rfc3261_8_1_3_3_ Multiple Via headers
  21411. * - _rfc3261_18_3_response_ Body Content-Length
  21412. *
  21413. * All:
  21414. * - Minimum headers in a SIP message
  21415. */
  21416. // Sanity Check functions for requests.
  21417. function rfc3261_8_2_2_1() {
  21418. if (message.s('to').uri.scheme !== 'sip') {
  21419. reply(416);
  21420. return false;
  21421. }
  21422. }
  21423. function rfc3261_16_3_4() {
  21424. if (!message.to_tag) {
  21425. if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) {
  21426. reply(482);
  21427. return false;
  21428. }
  21429. }
  21430. }
  21431. function rfc3261_18_3_request() {
  21432. var len = Utils.str_utf8_length(message.body);
  21433. var contentLength = message.getHeader('content-length');
  21434. if (len < contentLength) {
  21435. reply(400);
  21436. return false;
  21437. }
  21438. }
  21439. function rfc3261_8_2_2_2() {
  21440. var fromTag = message.from_tag;
  21441. var call_id = message.call_id;
  21442. var cseq = message.cseq;
  21443. var tr; // Accept any in-dialog request.
  21444. if (message.to_tag) {
  21445. return;
  21446. } // INVITE request.
  21447. if (message.method === JsSIP_C.INVITE) {
  21448. // If the branch matches the key of any IST then assume it is a retransmission
  21449. // and ignore the INVITE.
  21450. // TODO: we should reply the last response.
  21451. if (ua._transactions.ist[message.via_branch]) {
  21452. return false;
  21453. } // Otherwise check whether it is a merged request.
  21454. else {
  21455. for (var transaction in ua._transactions.ist) {
  21456. if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) {
  21457. tr = ua._transactions.ist[transaction];
  21458. if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  21459. reply(482);
  21460. return false;
  21461. }
  21462. }
  21463. }
  21464. }
  21465. } // Non INVITE request.
  21466. // If the branch matches the key of any NIST then assume it is a retransmission
  21467. // and ignore the request.
  21468. // TODO: we should reply the last response.
  21469. else if (ua._transactions.nist[message.via_branch]) {
  21470. return false;
  21471. } // Otherwise check whether it is a merged request.
  21472. else {
  21473. for (var _transaction in ua._transactions.nist) {
  21474. if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) {
  21475. tr = ua._transactions.nist[_transaction];
  21476. if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
  21477. reply(482);
  21478. return false;
  21479. }
  21480. }
  21481. }
  21482. }
  21483. } // Sanity Check functions for responses.
  21484. function rfc3261_8_1_3_3() {
  21485. if (message.getHeaders('via').length > 1) {
  21486. logger.debug('more than one Via header field present in the response, dropping the response');
  21487. return false;
  21488. }
  21489. }
  21490. function rfc3261_18_3_response() {
  21491. var len = Utils.str_utf8_length(message.body),
  21492. contentLength = message.getHeader('content-length');
  21493. if (len < contentLength) {
  21494. logger.debug('message body length is lower than the value in Content-Length header field, dropping the response');
  21495. return false;
  21496. }
  21497. } // Sanity Check functions for requests and responses.
  21498. function minimumHeaders() {
  21499. var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via'];
  21500. for (var _i = 0, _mandatoryHeaders = mandatoryHeaders; _i < _mandatoryHeaders.length; _i++) {
  21501. var header = _mandatoryHeaders[_i];
  21502. if (!message.hasHeader(header)) {
  21503. logger.debug("missing mandatory header field : ".concat(header, ", dropping the response"));
  21504. return false;
  21505. }
  21506. }
  21507. } // Reply.
  21508. function reply(status_code) {
  21509. var vias = message.getHeaders('via');
  21510. var to;
  21511. var response = "SIP/2.0 ".concat(status_code, " ").concat(JsSIP_C.REASON_PHRASE[status_code], "\r\n");
  21512. var _iterator4 = _createForOfIteratorHelper(vias),
  21513. _step4;
  21514. try {
  21515. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  21516. var via = _step4.value;
  21517. response += "Via: ".concat(via, "\r\n");
  21518. }
  21519. } catch (err) {
  21520. _iterator4.e(err);
  21521. } finally {
  21522. _iterator4.f();
  21523. }
  21524. to = message.getHeader('To');
  21525. if (!message.to_tag) {
  21526. to += ";tag=".concat(Utils.newTag());
  21527. }
  21528. response += "To: ".concat(to, "\r\n");
  21529. response += "From: ".concat(message.getHeader('From'), "\r\n");
  21530. response += "Call-ID: ".concat(message.call_id, "\r\n");
  21531. response += "CSeq: ".concat(message.cseq, " ").concat(message.method, "\r\n");
  21532. response += '\r\n';
  21533. transport.send(response);
  21534. }
  21535. },{"./Constants":2,"./Logger":9,"./SIPMessage":21,"./Utils":28}],31:[function(require,module,exports){
  21536. // Copyright Joyent, Inc. and other Node contributors.
  21537. //
  21538. // Permission is hereby granted, free of charge, to any person obtaining a
  21539. // copy of this software and associated documentation files (the
  21540. // "Software"), to deal in the Software without restriction, including
  21541. // without limitation the rights to use, copy, modify, merge, publish,
  21542. // distribute, sublicense, and/or sell copies of the Software, and to permit
  21543. // persons to whom the Software is furnished to do so, subject to the
  21544. // following conditions:
  21545. //
  21546. // The above copyright notice and this permission notice shall be included
  21547. // in all copies or substantial portions of the Software.
  21548. //
  21549. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21550. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21551. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  21552. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  21553. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21554. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21555. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  21556. var objectCreate = Object.create || objectCreatePolyfill
  21557. var objectKeys = Object.keys || objectKeysPolyfill
  21558. var bind = Function.prototype.bind || functionBindPolyfill
  21559. function EventEmitter() {
  21560. if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
  21561. this._events = objectCreate(null);
  21562. this._eventsCount = 0;
  21563. }
  21564. this._maxListeners = this._maxListeners || undefined;
  21565. }
  21566. module.exports = EventEmitter;
  21567. // Backwards-compat with node 0.10.x
  21568. EventEmitter.EventEmitter = EventEmitter;
  21569. EventEmitter.prototype._events = undefined;
  21570. EventEmitter.prototype._maxListeners = undefined;
  21571. // By default EventEmitters will print a warning if more than 10 listeners are
  21572. // added to it. This is a useful default which helps finding memory leaks.
  21573. var defaultMaxListeners = 10;
  21574. var hasDefineProperty;
  21575. try {
  21576. var o = {};
  21577. if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
  21578. hasDefineProperty = o.x === 0;
  21579. } catch (err) { hasDefineProperty = false }
  21580. if (hasDefineProperty) {
  21581. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  21582. enumerable: true,
  21583. get: function() {
  21584. return defaultMaxListeners;
  21585. },
  21586. set: function(arg) {
  21587. // check whether the input is a positive number (whose value is zero or
  21588. // greater and not a NaN).
  21589. if (typeof arg !== 'number' || arg < 0 || arg !== arg)
  21590. throw new TypeError('"defaultMaxListeners" must be a positive number');
  21591. defaultMaxListeners = arg;
  21592. }
  21593. });
  21594. } else {
  21595. EventEmitter.defaultMaxListeners = defaultMaxListeners;
  21596. }
  21597. // Obviously not all Emitters should be limited to 10. This function allows
  21598. // that to be increased. Set to zero for unlimited.
  21599. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  21600. if (typeof n !== 'number' || n < 0 || isNaN(n))
  21601. throw new TypeError('"n" argument must be a positive number');
  21602. this._maxListeners = n;
  21603. return this;
  21604. };
  21605. function $getMaxListeners(that) {
  21606. if (that._maxListeners === undefined)
  21607. return EventEmitter.defaultMaxListeners;
  21608. return that._maxListeners;
  21609. }
  21610. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  21611. return $getMaxListeners(this);
  21612. };
  21613. // These standalone emit* functions are used to optimize calling of event
  21614. // handlers for fast cases because emit() itself often has a variable number of
  21615. // arguments and can be deoptimized because of that. These functions always have
  21616. // the same number of arguments and thus do not get deoptimized, so the code
  21617. // inside them can execute faster.
  21618. function emitNone(handler, isFn, self) {
  21619. if (isFn)
  21620. handler.call(self);
  21621. else {
  21622. var len = handler.length;
  21623. var listeners = arrayClone(handler, len);
  21624. for (var i = 0; i < len; ++i)
  21625. listeners[i].call(self);
  21626. }
  21627. }
  21628. function emitOne(handler, isFn, self, arg1) {
  21629. if (isFn)
  21630. handler.call(self, arg1);
  21631. else {
  21632. var len = handler.length;
  21633. var listeners = arrayClone(handler, len);
  21634. for (var i = 0; i < len; ++i)
  21635. listeners[i].call(self, arg1);
  21636. }
  21637. }
  21638. function emitTwo(handler, isFn, self, arg1, arg2) {
  21639. if (isFn)
  21640. handler.call(self, arg1, arg2);
  21641. else {
  21642. var len = handler.length;
  21643. var listeners = arrayClone(handler, len);
  21644. for (var i = 0; i < len; ++i)
  21645. listeners[i].call(self, arg1, arg2);
  21646. }
  21647. }
  21648. function emitThree(handler, isFn, self, arg1, arg2, arg3) {
  21649. if (isFn)
  21650. handler.call(self, arg1, arg2, arg3);
  21651. else {
  21652. var len = handler.length;
  21653. var listeners = arrayClone(handler, len);
  21654. for (var i = 0; i < len; ++i)
  21655. listeners[i].call(self, arg1, arg2, arg3);
  21656. }
  21657. }
  21658. function emitMany(handler, isFn, self, args) {
  21659. if (isFn)
  21660. handler.apply(self, args);
  21661. else {
  21662. var len = handler.length;
  21663. var listeners = arrayClone(handler, len);
  21664. for (var i = 0; i < len; ++i)
  21665. listeners[i].apply(self, args);
  21666. }
  21667. }
  21668. EventEmitter.prototype.emit = function emit(type) {
  21669. var er, handler, len, args, i, events;
  21670. var doError = (type === 'error');
  21671. events = this._events;
  21672. if (events)
  21673. doError = (doError && events.error == null);
  21674. else if (!doError)
  21675. return false;
  21676. // If there is no 'error' event listener then throw.
  21677. if (doError) {
  21678. if (arguments.length > 1)
  21679. er = arguments[1];
  21680. if (er instanceof Error) {
  21681. throw er; // Unhandled 'error' event
  21682. } else {
  21683. // At least give some kind of context to the user
  21684. var err = new Error('Unhandled "error" event. (' + er + ')');
  21685. err.context = er;
  21686. throw err;
  21687. }
  21688. return false;
  21689. }
  21690. handler = events[type];
  21691. if (!handler)
  21692. return false;
  21693. var isFn = typeof handler === 'function';
  21694. len = arguments.length;
  21695. switch (len) {
  21696. // fast cases
  21697. case 1:
  21698. emitNone(handler, isFn, this);
  21699. break;
  21700. case 2:
  21701. emitOne(handler, isFn, this, arguments[1]);
  21702. break;
  21703. case 3:
  21704. emitTwo(handler, isFn, this, arguments[1], arguments[2]);
  21705. break;
  21706. case 4:
  21707. emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
  21708. break;
  21709. // slower
  21710. default:
  21711. args = new Array(len - 1);
  21712. for (i = 1; i < len; i++)
  21713. args[i - 1] = arguments[i];
  21714. emitMany(handler, isFn, this, args);
  21715. }
  21716. return true;
  21717. };
  21718. function _addListener(target, type, listener, prepend) {
  21719. var m;
  21720. var events;
  21721. var existing;
  21722. if (typeof listener !== 'function')
  21723. throw new TypeError('"listener" argument must be a function');
  21724. events = target._events;
  21725. if (!events) {
  21726. events = target._events = objectCreate(null);
  21727. target._eventsCount = 0;
  21728. } else {
  21729. // To avoid recursion in the case that type === "newListener"! Before
  21730. // adding it to the listeners, first emit "newListener".
  21731. if (events.newListener) {
  21732. target.emit('newListener', type,
  21733. listener.listener ? listener.listener : listener);
  21734. // Re-assign `events` because a newListener handler could have caused the
  21735. // this._events to be assigned to a new object
  21736. events = target._events;
  21737. }
  21738. existing = events[type];
  21739. }
  21740. if (!existing) {
  21741. // Optimize the case of one listener. Don't need the extra array object.
  21742. existing = events[type] = listener;
  21743. ++target._eventsCount;
  21744. } else {
  21745. if (typeof existing === 'function') {
  21746. // Adding the second element, need to change to array.
  21747. existing = events[type] =
  21748. prepend ? [listener, existing] : [existing, listener];
  21749. } else {
  21750. // If we've already got an array, just append.
  21751. if (prepend) {
  21752. existing.unshift(listener);
  21753. } else {
  21754. existing.push(listener);
  21755. }
  21756. }
  21757. // Check for listener leak
  21758. if (!existing.warned) {
  21759. m = $getMaxListeners(target);
  21760. if (m && m > 0 && existing.length > m) {
  21761. existing.warned = true;
  21762. var w = new Error('Possible EventEmitter memory leak detected. ' +
  21763. existing.length + ' "' + String(type) + '" listeners ' +
  21764. 'added. Use emitter.setMaxListeners() to ' +
  21765. 'increase limit.');
  21766. w.name = 'MaxListenersExceededWarning';
  21767. w.emitter = target;
  21768. w.type = type;
  21769. w.count = existing.length;
  21770. if (typeof console === 'object' && console.warn) {
  21771. console.warn('%s: %s', w.name, w.message);
  21772. }
  21773. }
  21774. }
  21775. }
  21776. return target;
  21777. }
  21778. EventEmitter.prototype.addListener = function addListener(type, listener) {
  21779. return _addListener(this, type, listener, false);
  21780. };
  21781. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  21782. EventEmitter.prototype.prependListener =
  21783. function prependListener(type, listener) {
  21784. return _addListener(this, type, listener, true);
  21785. };
  21786. function onceWrapper() {
  21787. if (!this.fired) {
  21788. this.target.removeListener(this.type, this.wrapFn);
  21789. this.fired = true;
  21790. switch (arguments.length) {
  21791. case 0:
  21792. return this.listener.call(this.target);
  21793. case 1:
  21794. return this.listener.call(this.target, arguments[0]);
  21795. case 2:
  21796. return this.listener.call(this.target, arguments[0], arguments[1]);
  21797. case 3:
  21798. return this.listener.call(this.target, arguments[0], arguments[1],
  21799. arguments[2]);
  21800. default:
  21801. var args = new Array(arguments.length);
  21802. for (var i = 0; i < args.length; ++i)
  21803. args[i] = arguments[i];
  21804. this.listener.apply(this.target, args);
  21805. }
  21806. }
  21807. }
  21808. function _onceWrap(target, type, listener) {
  21809. var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  21810. var wrapped = bind.call(onceWrapper, state);
  21811. wrapped.listener = listener;
  21812. state.wrapFn = wrapped;
  21813. return wrapped;
  21814. }
  21815. EventEmitter.prototype.once = function once(type, listener) {
  21816. if (typeof listener !== 'function')
  21817. throw new TypeError('"listener" argument must be a function');
  21818. this.on(type, _onceWrap(this, type, listener));
  21819. return this;
  21820. };
  21821. EventEmitter.prototype.prependOnceListener =
  21822. function prependOnceListener(type, listener) {
  21823. if (typeof listener !== 'function')
  21824. throw new TypeError('"listener" argument must be a function');
  21825. this.prependListener(type, _onceWrap(this, type, listener));
  21826. return this;
  21827. };
  21828. // Emits a 'removeListener' event if and only if the listener was removed.
  21829. EventEmitter.prototype.removeListener =
  21830. function removeListener(type, listener) {
  21831. var list, events, position, i, originalListener;
  21832. if (typeof listener !== 'function')
  21833. throw new TypeError('"listener" argument must be a function');
  21834. events = this._events;
  21835. if (!events)
  21836. return this;
  21837. list = events[type];
  21838. if (!list)
  21839. return this;
  21840. if (list === listener || list.listener === listener) {
  21841. if (--this._eventsCount === 0)
  21842. this._events = objectCreate(null);
  21843. else {
  21844. delete events[type];
  21845. if (events.removeListener)
  21846. this.emit('removeListener', type, list.listener || listener);
  21847. }
  21848. } else if (typeof list !== 'function') {
  21849. position = -1;
  21850. for (i = list.length - 1; i >= 0; i--) {
  21851. if (list[i] === listener || list[i].listener === listener) {
  21852. originalListener = list[i].listener;
  21853. position = i;
  21854. break;
  21855. }
  21856. }
  21857. if (position < 0)
  21858. return this;
  21859. if (position === 0)
  21860. list.shift();
  21861. else
  21862. spliceOne(list, position);
  21863. if (list.length === 1)
  21864. events[type] = list[0];
  21865. if (events.removeListener)
  21866. this.emit('removeListener', type, originalListener || listener);
  21867. }
  21868. return this;
  21869. };
  21870. EventEmitter.prototype.removeAllListeners =
  21871. function removeAllListeners(type) {
  21872. var listeners, events, i;
  21873. events = this._events;
  21874. if (!events)
  21875. return this;
  21876. // not listening for removeListener, no need to emit
  21877. if (!events.removeListener) {
  21878. if (arguments.length === 0) {
  21879. this._events = objectCreate(null);
  21880. this._eventsCount = 0;
  21881. } else if (events[type]) {
  21882. if (--this._eventsCount === 0)
  21883. this._events = objectCreate(null);
  21884. else
  21885. delete events[type];
  21886. }
  21887. return this;
  21888. }
  21889. // emit removeListener for all listeners on all events
  21890. if (arguments.length === 0) {
  21891. var keys = objectKeys(events);
  21892. var key;
  21893. for (i = 0; i < keys.length; ++i) {
  21894. key = keys[i];
  21895. if (key === 'removeListener') continue;
  21896. this.removeAllListeners(key);
  21897. }
  21898. this.removeAllListeners('removeListener');
  21899. this._events = objectCreate(null);
  21900. this._eventsCount = 0;
  21901. return this;
  21902. }
  21903. listeners = events[type];
  21904. if (typeof listeners === 'function') {
  21905. this.removeListener(type, listeners);
  21906. } else if (listeners) {
  21907. // LIFO order
  21908. for (i = listeners.length - 1; i >= 0; i--) {
  21909. this.removeListener(type, listeners[i]);
  21910. }
  21911. }
  21912. return this;
  21913. };
  21914. function _listeners(target, type, unwrap) {
  21915. var events = target._events;
  21916. if (!events)
  21917. return [];
  21918. var evlistener = events[type];
  21919. if (!evlistener)
  21920. return [];
  21921. if (typeof evlistener === 'function')
  21922. return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  21923. return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  21924. }
  21925. EventEmitter.prototype.listeners = function listeners(type) {
  21926. return _listeners(this, type, true);
  21927. };
  21928. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  21929. return _listeners(this, type, false);
  21930. };
  21931. EventEmitter.listenerCount = function(emitter, type) {
  21932. if (typeof emitter.listenerCount === 'function') {
  21933. return emitter.listenerCount(type);
  21934. } else {
  21935. return listenerCount.call(emitter, type);
  21936. }
  21937. };
  21938. EventEmitter.prototype.listenerCount = listenerCount;
  21939. function listenerCount(type) {
  21940. var events = this._events;
  21941. if (events) {
  21942. var evlistener = events[type];
  21943. if (typeof evlistener === 'function') {
  21944. return 1;
  21945. } else if (evlistener) {
  21946. return evlistener.length;
  21947. }
  21948. }
  21949. return 0;
  21950. }
  21951. EventEmitter.prototype.eventNames = function eventNames() {
  21952. return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
  21953. };
  21954. // About 1.5x faster than the two-arg version of Array#splice().
  21955. function spliceOne(list, index) {
  21956. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
  21957. list[i] = list[k];
  21958. list.pop();
  21959. }
  21960. function arrayClone(arr, n) {
  21961. var copy = new Array(n);
  21962. for (var i = 0; i < n; ++i)
  21963. copy[i] = arr[i];
  21964. return copy;
  21965. }
  21966. function unwrapListeners(arr) {
  21967. var ret = new Array(arr.length);
  21968. for (var i = 0; i < ret.length; ++i) {
  21969. ret[i] = arr[i].listener || arr[i];
  21970. }
  21971. return ret;
  21972. }
  21973. function objectCreatePolyfill(proto) {
  21974. var F = function() {};
  21975. F.prototype = proto;
  21976. return new F;
  21977. }
  21978. function objectKeysPolyfill(obj) {
  21979. var keys = [];
  21980. for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
  21981. keys.push(k);
  21982. }
  21983. return k;
  21984. }
  21985. function functionBindPolyfill(context) {
  21986. var fn = this;
  21987. return function () {
  21988. return fn.apply(context, arguments);
  21989. };
  21990. }
  21991. },{}],32:[function(require,module,exports){
  21992. (function (process){
  21993. /* eslint-env browser */
  21994. /**
  21995. * This is the web browser implementation of `debug()`.
  21996. */
  21997. exports.log = log;
  21998. exports.formatArgs = formatArgs;
  21999. exports.save = save;
  22000. exports.load = load;
  22001. exports.useColors = useColors;
  22002. exports.storage = localstorage();
  22003. /**
  22004. * Colors.
  22005. */
  22006. exports.colors = [
  22007. '#0000CC',
  22008. '#0000FF',
  22009. '#0033CC',
  22010. '#0033FF',
  22011. '#0066CC',
  22012. '#0066FF',
  22013. '#0099CC',
  22014. '#0099FF',
  22015. '#00CC00',
  22016. '#00CC33',
  22017. '#00CC66',
  22018. '#00CC99',
  22019. '#00CCCC',
  22020. '#00CCFF',
  22021. '#3300CC',
  22022. '#3300FF',
  22023. '#3333CC',
  22024. '#3333FF',
  22025. '#3366CC',
  22026. '#3366FF',
  22027. '#3399CC',
  22028. '#3399FF',
  22029. '#33CC00',
  22030. '#33CC33',
  22031. '#33CC66',
  22032. '#33CC99',
  22033. '#33CCCC',
  22034. '#33CCFF',
  22035. '#6600CC',
  22036. '#6600FF',
  22037. '#6633CC',
  22038. '#6633FF',
  22039. '#66CC00',
  22040. '#66CC33',
  22041. '#9900CC',
  22042. '#9900FF',
  22043. '#9933CC',
  22044. '#9933FF',
  22045. '#99CC00',
  22046. '#99CC33',
  22047. '#CC0000',
  22048. '#CC0033',
  22049. '#CC0066',
  22050. '#CC0099',
  22051. '#CC00CC',
  22052. '#CC00FF',
  22053. '#CC3300',
  22054. '#CC3333',
  22055. '#CC3366',
  22056. '#CC3399',
  22057. '#CC33CC',
  22058. '#CC33FF',
  22059. '#CC6600',
  22060. '#CC6633',
  22061. '#CC9900',
  22062. '#CC9933',
  22063. '#CCCC00',
  22064. '#CCCC33',
  22065. '#FF0000',
  22066. '#FF0033',
  22067. '#FF0066',
  22068. '#FF0099',
  22069. '#FF00CC',
  22070. '#FF00FF',
  22071. '#FF3300',
  22072. '#FF3333',
  22073. '#FF3366',
  22074. '#FF3399',
  22075. '#FF33CC',
  22076. '#FF33FF',
  22077. '#FF6600',
  22078. '#FF6633',
  22079. '#FF9900',
  22080. '#FF9933',
  22081. '#FFCC00',
  22082. '#FFCC33'
  22083. ];
  22084. /**
  22085. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  22086. * and the Firebug extension (any Firefox version) are known
  22087. * to support "%c" CSS customizations.
  22088. *
  22089. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  22090. */
  22091. // eslint-disable-next-line complexity
  22092. function useColors() {
  22093. // NB: In an Electron preload script, document will be defined but not fully
  22094. // initialized. Since we know we're in Chrome, we'll just detect this case
  22095. // explicitly
  22096. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  22097. return true;
  22098. }
  22099. // Internet Explorer and Edge do not support colors.
  22100. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  22101. return false;
  22102. }
  22103. // Is webkit? http://stackoverflow.com/a/16459606/376773
  22104. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  22105. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  22106. // Is firebug? http://stackoverflow.com/a/398120/376773
  22107. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  22108. // Is firefox >= v31?
  22109. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  22110. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  22111. // Double check webkit in userAgent just in case we are in a worker
  22112. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  22113. }
  22114. /**
  22115. * Colorize log arguments if enabled.
  22116. *
  22117. * @api public
  22118. */
  22119. function formatArgs(args) {
  22120. args[0] = (this.useColors ? '%c' : '') +
  22121. this.namespace +
  22122. (this.useColors ? ' %c' : ' ') +
  22123. args[0] +
  22124. (this.useColors ? '%c ' : ' ') +
  22125. '+' + module.exports.humanize(this.diff);
  22126. if (!this.useColors) {
  22127. return;
  22128. }
  22129. const c = 'color: ' + this.color;
  22130. args.splice(1, 0, c, 'color: inherit');
  22131. // The final "%c" is somewhat tricky, because there could be other
  22132. // arguments passed either before or after the %c, so we need to
  22133. // figure out the correct index to insert the CSS into
  22134. let index = 0;
  22135. let lastC = 0;
  22136. args[0].replace(/%[a-zA-Z%]/g, match => {
  22137. if (match === '%%') {
  22138. return;
  22139. }
  22140. index++;
  22141. if (match === '%c') {
  22142. // We only are interested in the *last* %c
  22143. // (the user may have provided their own)
  22144. lastC = index;
  22145. }
  22146. });
  22147. args.splice(lastC, 0, c);
  22148. }
  22149. /**
  22150. * Invokes `console.log()` when available.
  22151. * No-op when `console.log` is not a "function".
  22152. *
  22153. * @api public
  22154. */
  22155. function log(...args) {
  22156. // This hackery is required for IE8/9, where
  22157. // the `console.log` function doesn't have 'apply'
  22158. return typeof console === 'object' &&
  22159. console.log &&
  22160. console.log(...args);
  22161. }
  22162. /**
  22163. * Save `namespaces`.
  22164. *
  22165. * @param {String} namespaces
  22166. * @api private
  22167. */
  22168. function save(namespaces) {
  22169. try {
  22170. if (namespaces) {
  22171. exports.storage.setItem('debug', namespaces);
  22172. } else {
  22173. exports.storage.removeItem('debug');
  22174. }
  22175. } catch (error) {
  22176. // Swallow
  22177. // XXX (@Qix-) should we be logging these?
  22178. }
  22179. }
  22180. /**
  22181. * Load `namespaces`.
  22182. *
  22183. * @return {String} returns the previously persisted debug modes
  22184. * @api private
  22185. */
  22186. function load() {
  22187. let r;
  22188. try {
  22189. r = exports.storage.getItem('debug');
  22190. } catch (error) {
  22191. // Swallow
  22192. // XXX (@Qix-) should we be logging these?
  22193. }
  22194. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  22195. if (!r && typeof process !== 'undefined' && 'env' in process) {
  22196. r = process.env.DEBUG;
  22197. }
  22198. return r;
  22199. }
  22200. /**
  22201. * Localstorage attempts to return the localstorage.
  22202. *
  22203. * This is necessary because safari throws
  22204. * when a user disables cookies/localstorage
  22205. * and you attempt to access it.
  22206. *
  22207. * @return {LocalStorage}
  22208. * @api private
  22209. */
  22210. function localstorage() {
  22211. try {
  22212. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  22213. // The Browser also has localStorage in the global context.
  22214. return localStorage;
  22215. } catch (error) {
  22216. // Swallow
  22217. // XXX (@Qix-) should we be logging these?
  22218. }
  22219. }
  22220. module.exports = require('./common')(exports);
  22221. const {formatters} = module.exports;
  22222. /**
  22223. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  22224. */
  22225. formatters.j = function (v) {
  22226. try {
  22227. return JSON.stringify(v);
  22228. } catch (error) {
  22229. return '[UnexpectedJSONParseError]: ' + error.message;
  22230. }
  22231. };
  22232. }).call(this,require('_process'))
  22233. },{"./common":33,"_process":35}],33:[function(require,module,exports){
  22234. /**
  22235. * This is the common logic for both the Node.js and web browser
  22236. * implementations of `debug()`.
  22237. */
  22238. function setup(env) {
  22239. createDebug.debug = createDebug;
  22240. createDebug.default = createDebug;
  22241. createDebug.coerce = coerce;
  22242. createDebug.disable = disable;
  22243. createDebug.enable = enable;
  22244. createDebug.enabled = enabled;
  22245. createDebug.humanize = require('ms');
  22246. Object.keys(env).forEach(key => {
  22247. createDebug[key] = env[key];
  22248. });
  22249. /**
  22250. * Active `debug` instances.
  22251. */
  22252. createDebug.instances = [];
  22253. /**
  22254. * The currently active debug mode names, and names to skip.
  22255. */
  22256. createDebug.names = [];
  22257. createDebug.skips = [];
  22258. /**
  22259. * Map of special "%n" handling functions, for the debug "format" argument.
  22260. *
  22261. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  22262. */
  22263. createDebug.formatters = {};
  22264. /**
  22265. * Selects a color for a debug namespace
  22266. * @param {String} namespace The namespace string for the for the debug instance to be colored
  22267. * @return {Number|String} An ANSI color code for the given namespace
  22268. * @api private
  22269. */
  22270. function selectColor(namespace) {
  22271. let hash = 0;
  22272. for (let i = 0; i < namespace.length; i++) {
  22273. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  22274. hash |= 0; // Convert to 32bit integer
  22275. }
  22276. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  22277. }
  22278. createDebug.selectColor = selectColor;
  22279. /**
  22280. * Create a debugger with the given `namespace`.
  22281. *
  22282. * @param {String} namespace
  22283. * @return {Function}
  22284. * @api public
  22285. */
  22286. function createDebug(namespace) {
  22287. let prevTime;
  22288. function debug(...args) {
  22289. // Disabled?
  22290. if (!debug.enabled) {
  22291. return;
  22292. }
  22293. const self = debug;
  22294. // Set `diff` timestamp
  22295. const curr = Number(new Date());
  22296. const ms = curr - (prevTime || curr);
  22297. self.diff = ms;
  22298. self.prev = prevTime;
  22299. self.curr = curr;
  22300. prevTime = curr;
  22301. args[0] = createDebug.coerce(args[0]);
  22302. if (typeof args[0] !== 'string') {
  22303. // Anything else let's inspect with %O
  22304. args.unshift('%O');
  22305. }
  22306. // Apply any `formatters` transformations
  22307. let index = 0;
  22308. args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
  22309. // If we encounter an escaped % then don't increase the array index
  22310. if (match === '%%') {
  22311. return match;
  22312. }
  22313. index++;
  22314. const formatter = createDebug.formatters[format];
  22315. if (typeof formatter === 'function') {
  22316. const val = args[index];
  22317. match = formatter.call(self, val);
  22318. // Now we need to remove `args[index]` since it's inlined in the `format`
  22319. args.splice(index, 1);
  22320. index--;
  22321. }
  22322. return match;
  22323. });
  22324. // Apply env-specific formatting (colors, etc.)
  22325. createDebug.formatArgs.call(self, args);
  22326. const logFn = self.log || createDebug.log;
  22327. logFn.apply(self, args);
  22328. }
  22329. debug.namespace = namespace;
  22330. debug.enabled = createDebug.enabled(namespace);
  22331. debug.useColors = createDebug.useColors();
  22332. debug.color = selectColor(namespace);
  22333. debug.destroy = destroy;
  22334. debug.extend = extend;
  22335. // Debug.formatArgs = formatArgs;
  22336. // debug.rawLog = rawLog;
  22337. // env-specific initialization logic for debug instances
  22338. if (typeof createDebug.init === 'function') {
  22339. createDebug.init(debug);
  22340. }
  22341. createDebug.instances.push(debug);
  22342. return debug;
  22343. }
  22344. function destroy() {
  22345. const index = createDebug.instances.indexOf(this);
  22346. if (index !== -1) {
  22347. createDebug.instances.splice(index, 1);
  22348. return true;
  22349. }
  22350. return false;
  22351. }
  22352. function extend(namespace, delimiter) {
  22353. const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  22354. newDebug.log = this.log;
  22355. return newDebug;
  22356. }
  22357. /**
  22358. * Enables a debug mode by namespaces. This can include modes
  22359. * separated by a colon and wildcards.
  22360. *
  22361. * @param {String} namespaces
  22362. * @api public
  22363. */
  22364. function enable(namespaces) {
  22365. createDebug.save(namespaces);
  22366. createDebug.names = [];
  22367. createDebug.skips = [];
  22368. let i;
  22369. const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  22370. const len = split.length;
  22371. for (i = 0; i < len; i++) {
  22372. if (!split[i]) {
  22373. // ignore empty strings
  22374. continue;
  22375. }
  22376. namespaces = split[i].replace(/\*/g, '.*?');
  22377. if (namespaces[0] === '-') {
  22378. createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  22379. } else {
  22380. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  22381. }
  22382. }
  22383. for (i = 0; i < createDebug.instances.length; i++) {
  22384. const instance = createDebug.instances[i];
  22385. instance.enabled = createDebug.enabled(instance.namespace);
  22386. }
  22387. }
  22388. /**
  22389. * Disable debug output.
  22390. *
  22391. * @return {String} namespaces
  22392. * @api public
  22393. */
  22394. function disable() {
  22395. const namespaces = [
  22396. ...createDebug.names.map(toNamespace),
  22397. ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
  22398. ].join(',');
  22399. createDebug.enable('');
  22400. return namespaces;
  22401. }
  22402. /**
  22403. * Returns true if the given mode name is enabled, false otherwise.
  22404. *
  22405. * @param {String} name
  22406. * @return {Boolean}
  22407. * @api public
  22408. */
  22409. function enabled(name) {
  22410. if (name[name.length - 1] === '*') {
  22411. return true;
  22412. }
  22413. let i;
  22414. let len;
  22415. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  22416. if (createDebug.skips[i].test(name)) {
  22417. return false;
  22418. }
  22419. }
  22420. for (i = 0, len = createDebug.names.length; i < len; i++) {
  22421. if (createDebug.names[i].test(name)) {
  22422. return true;
  22423. }
  22424. }
  22425. return false;
  22426. }
  22427. /**
  22428. * Convert regexp to namespace
  22429. *
  22430. * @param {RegExp} regxep
  22431. * @return {String} namespace
  22432. * @api private
  22433. */
  22434. function toNamespace(regexp) {
  22435. return regexp.toString()
  22436. .substring(2, regexp.toString().length - 2)
  22437. .replace(/\.\*\?$/, '*');
  22438. }
  22439. /**
  22440. * Coerce `val`.
  22441. *
  22442. * @param {Mixed} val
  22443. * @return {Mixed}
  22444. * @api private
  22445. */
  22446. function coerce(val) {
  22447. if (val instanceof Error) {
  22448. return val.stack || val.message;
  22449. }
  22450. return val;
  22451. }
  22452. createDebug.enable(createDebug.load());
  22453. return createDebug;
  22454. }
  22455. module.exports = setup;
  22456. },{"ms":34}],34:[function(require,module,exports){
  22457. /**
  22458. * Helpers.
  22459. */
  22460. var s = 1000;
  22461. var m = s * 60;
  22462. var h = m * 60;
  22463. var d = h * 24;
  22464. var w = d * 7;
  22465. var y = d * 365.25;
  22466. /**
  22467. * Parse or format the given `val`.
  22468. *
  22469. * Options:
  22470. *
  22471. * - `long` verbose formatting [false]
  22472. *
  22473. * @param {String|Number} val
  22474. * @param {Object} [options]
  22475. * @throws {Error} throw an error if val is not a non-empty string or a number
  22476. * @return {String|Number}
  22477. * @api public
  22478. */
  22479. module.exports = function(val, options) {
  22480. options = options || {};
  22481. var type = typeof val;
  22482. if (type === 'string' && val.length > 0) {
  22483. return parse(val);
  22484. } else if (type === 'number' && isFinite(val)) {
  22485. return options.long ? fmtLong(val) : fmtShort(val);
  22486. }
  22487. throw new Error(
  22488. 'val is not a non-empty string or a valid number. val=' +
  22489. JSON.stringify(val)
  22490. );
  22491. };
  22492. /**
  22493. * Parse the given `str` and return milliseconds.
  22494. *
  22495. * @param {String} str
  22496. * @return {Number}
  22497. * @api private
  22498. */
  22499. function parse(str) {
  22500. str = String(str);
  22501. if (str.length > 100) {
  22502. return;
  22503. }
  22504. var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
  22505. str
  22506. );
  22507. if (!match) {
  22508. return;
  22509. }
  22510. var n = parseFloat(match[1]);
  22511. var type = (match[2] || 'ms').toLowerCase();
  22512. switch (type) {
  22513. case 'years':
  22514. case 'year':
  22515. case 'yrs':
  22516. case 'yr':
  22517. case 'y':
  22518. return n * y;
  22519. case 'weeks':
  22520. case 'week':
  22521. case 'w':
  22522. return n * w;
  22523. case 'days':
  22524. case 'day':
  22525. case 'd':
  22526. return n * d;
  22527. case 'hours':
  22528. case 'hour':
  22529. case 'hrs':
  22530. case 'hr':
  22531. case 'h':
  22532. return n * h;
  22533. case 'minutes':
  22534. case 'minute':
  22535. case 'mins':
  22536. case 'min':
  22537. case 'm':
  22538. return n * m;
  22539. case 'seconds':
  22540. case 'second':
  22541. case 'secs':
  22542. case 'sec':
  22543. case 's':
  22544. return n * s;
  22545. case 'milliseconds':
  22546. case 'millisecond':
  22547. case 'msecs':
  22548. case 'msec':
  22549. case 'ms':
  22550. return n;
  22551. default:
  22552. return undefined;
  22553. }
  22554. }
  22555. /**
  22556. * Short format for `ms`.
  22557. *
  22558. * @param {Number} ms
  22559. * @return {String}
  22560. * @api private
  22561. */
  22562. function fmtShort(ms) {
  22563. var msAbs = Math.abs(ms);
  22564. if (msAbs >= d) {
  22565. return Math.round(ms / d) + 'd';
  22566. }
  22567. if (msAbs >= h) {
  22568. return Math.round(ms / h) + 'h';
  22569. }
  22570. if (msAbs >= m) {
  22571. return Math.round(ms / m) + 'm';
  22572. }
  22573. if (msAbs >= s) {
  22574. return Math.round(ms / s) + 's';
  22575. }
  22576. return ms + 'ms';
  22577. }
  22578. /**
  22579. * Long format for `ms`.
  22580. *
  22581. * @param {Number} ms
  22582. * @return {String}
  22583. * @api private
  22584. */
  22585. function fmtLong(ms) {
  22586. var msAbs = Math.abs(ms);
  22587. if (msAbs >= d) {
  22588. return plural(ms, msAbs, d, 'day');
  22589. }
  22590. if (msAbs >= h) {
  22591. return plural(ms, msAbs, h, 'hour');
  22592. }
  22593. if (msAbs >= m) {
  22594. return plural(ms, msAbs, m, 'minute');
  22595. }
  22596. if (msAbs >= s) {
  22597. return plural(ms, msAbs, s, 'second');
  22598. }
  22599. return ms + ' ms';
  22600. }
  22601. /**
  22602. * Pluralization helper.
  22603. */
  22604. function plural(ms, msAbs, n, name) {
  22605. var isPlural = msAbs >= n * 1.5;
  22606. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  22607. }
  22608. },{}],35:[function(require,module,exports){
  22609. // shim for using process in browser
  22610. var process = module.exports = {};
  22611. // cached from whatever global is present so that test runners that stub it
  22612. // don't break things. But we need to wrap it in a try catch in case it is
  22613. // wrapped in strict mode code which doesn't define any globals. It's inside a
  22614. // function because try/catches deoptimize in certain engines.
  22615. var cachedSetTimeout;
  22616. var cachedClearTimeout;
  22617. function defaultSetTimout() {
  22618. throw new Error('setTimeout has not been defined');
  22619. }
  22620. function defaultClearTimeout () {
  22621. throw new Error('clearTimeout has not been defined');
  22622. }
  22623. (function () {
  22624. try {
  22625. if (typeof setTimeout === 'function') {
  22626. cachedSetTimeout = setTimeout;
  22627. } else {
  22628. cachedSetTimeout = defaultSetTimout;
  22629. }
  22630. } catch (e) {
  22631. cachedSetTimeout = defaultSetTimout;
  22632. }
  22633. try {
  22634. if (typeof clearTimeout === 'function') {
  22635. cachedClearTimeout = clearTimeout;
  22636. } else {
  22637. cachedClearTimeout = defaultClearTimeout;
  22638. }
  22639. } catch (e) {
  22640. cachedClearTimeout = defaultClearTimeout;
  22641. }
  22642. } ())
  22643. function runTimeout(fun) {
  22644. if (cachedSetTimeout === setTimeout) {
  22645. //normal enviroments in sane situations
  22646. return setTimeout(fun, 0);
  22647. }
  22648. // if setTimeout wasn't available but was latter defined
  22649. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  22650. cachedSetTimeout = setTimeout;
  22651. return setTimeout(fun, 0);
  22652. }
  22653. try {
  22654. // when when somebody has screwed with setTimeout but no I.E. maddness
  22655. return cachedSetTimeout(fun, 0);
  22656. } catch(e){
  22657. try {
  22658. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  22659. return cachedSetTimeout.call(null, fun, 0);
  22660. } catch(e){
  22661. // 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
  22662. return cachedSetTimeout.call(this, fun, 0);
  22663. }
  22664. }
  22665. }
  22666. function runClearTimeout(marker) {
  22667. if (cachedClearTimeout === clearTimeout) {
  22668. //normal enviroments in sane situations
  22669. return clearTimeout(marker);
  22670. }
  22671. // if clearTimeout wasn't available but was latter defined
  22672. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  22673. cachedClearTimeout = clearTimeout;
  22674. return clearTimeout(marker);
  22675. }
  22676. try {
  22677. // when when somebody has screwed with setTimeout but no I.E. maddness
  22678. return cachedClearTimeout(marker);
  22679. } catch (e){
  22680. try {
  22681. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  22682. return cachedClearTimeout.call(null, marker);
  22683. } catch (e){
  22684. // 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.
  22685. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  22686. return cachedClearTimeout.call(this, marker);
  22687. }
  22688. }
  22689. }
  22690. var queue = [];
  22691. var draining = false;
  22692. var currentQueue;
  22693. var queueIndex = -1;
  22694. function cleanUpNextTick() {
  22695. if (!draining || !currentQueue) {
  22696. return;
  22697. }
  22698. draining = false;
  22699. if (currentQueue.length) {
  22700. queue = currentQueue.concat(queue);
  22701. } else {
  22702. queueIndex = -1;
  22703. }
  22704. if (queue.length) {
  22705. drainQueue();
  22706. }
  22707. }
  22708. function drainQueue() {
  22709. if (draining) {
  22710. return;
  22711. }
  22712. var timeout = runTimeout(cleanUpNextTick);
  22713. draining = true;
  22714. var len = queue.length;
  22715. while(len) {
  22716. currentQueue = queue;
  22717. queue = [];
  22718. while (++queueIndex < len) {
  22719. if (currentQueue) {
  22720. currentQueue[queueIndex].run();
  22721. }
  22722. }
  22723. queueIndex = -1;
  22724. len = queue.length;
  22725. }
  22726. currentQueue = null;
  22727. draining = false;
  22728. runClearTimeout(timeout);
  22729. }
  22730. process.nextTick = function (fun) {
  22731. var args = new Array(arguments.length - 1);
  22732. if (arguments.length > 1) {
  22733. for (var i = 1; i < arguments.length; i++) {
  22734. args[i - 1] = arguments[i];
  22735. }
  22736. }
  22737. queue.push(new Item(fun, args));
  22738. if (queue.length === 1 && !draining) {
  22739. runTimeout(drainQueue);
  22740. }
  22741. };
  22742. // v8 likes predictible objects
  22743. function Item(fun, array) {
  22744. this.fun = fun;
  22745. this.array = array;
  22746. }
  22747. Item.prototype.run = function () {
  22748. this.fun.apply(null, this.array);
  22749. };
  22750. process.title = 'browser';
  22751. process.browser = true;
  22752. process.env = {};
  22753. process.argv = [];
  22754. process.version = ''; // empty string to avoid regexp issues
  22755. process.versions = {};
  22756. function noop() {}
  22757. process.on = noop;
  22758. process.addListener = noop;
  22759. process.once = noop;
  22760. process.off = noop;
  22761. process.removeListener = noop;
  22762. process.removeAllListeners = noop;
  22763. process.emit = noop;
  22764. process.prependListener = noop;
  22765. process.prependOnceListener = noop;
  22766. process.listeners = function (name) { return [] }
  22767. process.binding = function (name) {
  22768. throw new Error('process.binding is not supported');
  22769. };
  22770. process.cwd = function () { return '/' };
  22771. process.chdir = function (dir) {
  22772. throw new Error('process.chdir is not supported');
  22773. };
  22774. process.umask = function() { return 0; };
  22775. },{}],36:[function(require,module,exports){
  22776. var grammar = module.exports = {
  22777. v: [{
  22778. name: 'version',
  22779. reg: /^(\d*)$/
  22780. }],
  22781. o: [{
  22782. // o=- 20518 0 IN IP4 203.0.113.1
  22783. // NB: sessionId will be a String in most cases because it is huge
  22784. name: 'origin',
  22785. reg: /^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,
  22786. names: ['username', 'sessionId', 'sessionVersion', 'netType', 'ipVer', 'address'],
  22787. format: '%s %s %d %s IP%d %s'
  22788. }],
  22789. // default parsing of these only (though some of these feel outdated)
  22790. s: [{ name: 'name' }],
  22791. i: [{ name: 'description' }],
  22792. u: [{ name: 'uri' }],
  22793. e: [{ name: 'email' }],
  22794. p: [{ name: 'phone' }],
  22795. z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly...
  22796. r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly
  22797. // k: [{}], // outdated thing ignored
  22798. t: [{
  22799. // t=0 0
  22800. name: 'timing',
  22801. reg: /^(\d*) (\d*)/,
  22802. names: ['start', 'stop'],
  22803. format: '%d %d'
  22804. }],
  22805. c: [{
  22806. // c=IN IP4 10.47.197.26
  22807. name: 'connection',
  22808. reg: /^IN IP(\d) (\S*)/,
  22809. names: ['version', 'ip'],
  22810. format: 'IN IP%d %s'
  22811. }],
  22812. b: [{
  22813. // b=AS:4000
  22814. push: 'bandwidth',
  22815. reg: /^(TIAS|AS|CT|RR|RS):(\d*)/,
  22816. names: ['type', 'limit'],
  22817. format: '%s:%s'
  22818. }],
  22819. m: [{
  22820. // m=video 51744 RTP/AVP 126 97 98 34 31
  22821. // NB: special - pushes to session
  22822. // TODO: rtp/fmtp should be filtered by the payloads found here?
  22823. reg: /^(\w*) (\d*) ([\w/]*)(?: (.*))?/,
  22824. names: ['type', 'port', 'protocol', 'payloads'],
  22825. format: '%s %d %s %s'
  22826. }],
  22827. a: [
  22828. {
  22829. // a=rtpmap:110 opus/48000/2
  22830. push: 'rtp',
  22831. reg: /^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,
  22832. names: ['payload', 'codec', 'rate', 'encoding'],
  22833. format: function (o) {
  22834. return (o.encoding)
  22835. ? 'rtpmap:%d %s/%s/%s'
  22836. : o.rate
  22837. ? 'rtpmap:%d %s/%s'
  22838. : 'rtpmap:%d %s';
  22839. }
  22840. },
  22841. {
  22842. // a=fmtp:108 profile-level-id=24;object=23;bitrate=64000
  22843. // a=fmtp:111 minptime=10; useinbandfec=1
  22844. push: 'fmtp',
  22845. reg: /^fmtp:(\d*) ([\S| ]*)/,
  22846. names: ['payload', 'config'],
  22847. format: 'fmtp:%d %s'
  22848. },
  22849. {
  22850. // a=control:streamid=0
  22851. name: 'control',
  22852. reg: /^control:(.*)/,
  22853. format: 'control:%s'
  22854. },
  22855. {
  22856. // a=rtcp:65179 IN IP4 193.84.77.194
  22857. name: 'rtcp',
  22858. reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,
  22859. names: ['port', 'netType', 'ipVer', 'address'],
  22860. format: function (o) {
  22861. return (o.address != null)
  22862. ? 'rtcp:%d %s IP%d %s'
  22863. : 'rtcp:%d';
  22864. }
  22865. },
  22866. {
  22867. // a=rtcp-fb:98 trr-int 100
  22868. push: 'rtcpFbTrrInt',
  22869. reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/,
  22870. names: ['payload', 'value'],
  22871. format: 'rtcp-fb:%d trr-int %d'
  22872. },
  22873. {
  22874. // a=rtcp-fb:98 nack rpsi
  22875. push: 'rtcpFb',
  22876. reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,
  22877. names: ['payload', 'type', 'subtype'],
  22878. format: function (o) {
  22879. return (o.subtype != null)
  22880. ? 'rtcp-fb:%s %s %s'
  22881. : 'rtcp-fb:%s %s';
  22882. }
  22883. },
  22884. {
  22885. // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  22886. // a=extmap:1/recvonly URI-gps-string
  22887. // a=extmap:3 urn:ietf:params:rtp-hdrext:encrypt urn:ietf:params:rtp-hdrext:smpte-tc 25@600/24
  22888. push: 'ext',
  22889. reg: /^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,
  22890. names: ['value', 'direction', 'encrypt-uri', 'uri', 'config'],
  22891. format: function (o) {
  22892. return (
  22893. 'extmap:%d' +
  22894. (o.direction ? '/%s' : '%v') +
  22895. (o['encrypt-uri'] ? ' %s' : '%v') +
  22896. ' %s' +
  22897. (o.config ? ' %s' : '')
  22898. );
  22899. }
  22900. },
  22901. {
  22902. // a=extmap-allow-mixed
  22903. name: 'extmapAllowMixed',
  22904. reg: /^(extmap-allow-mixed)/
  22905. },
  22906. {
  22907. // a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32
  22908. push: 'crypto',
  22909. reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,
  22910. names: ['id', 'suite', 'config', 'sessionConfig'],
  22911. format: function (o) {
  22912. return (o.sessionConfig != null)
  22913. ? 'crypto:%d %s %s %s'
  22914. : 'crypto:%d %s %s';
  22915. }
  22916. },
  22917. {
  22918. // a=setup:actpass
  22919. name: 'setup',
  22920. reg: /^setup:(\w*)/,
  22921. format: 'setup:%s'
  22922. },
  22923. {
  22924. // a=connection:new
  22925. name: 'connectionType',
  22926. reg: /^connection:(new|existing)/,
  22927. format: 'connection:%s'
  22928. },
  22929. {
  22930. // a=mid:1
  22931. name: 'mid',
  22932. reg: /^mid:([^\s]*)/,
  22933. format: 'mid:%s'
  22934. },
  22935. {
  22936. // a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a
  22937. name: 'msid',
  22938. reg: /^msid:(.*)/,
  22939. format: 'msid:%s'
  22940. },
  22941. {
  22942. // a=ptime:20
  22943. name: 'ptime',
  22944. reg: /^ptime:(\d*(?:\.\d*)*)/,
  22945. format: 'ptime:%d'
  22946. },
  22947. {
  22948. // a=maxptime:60
  22949. name: 'maxptime',
  22950. reg: /^maxptime:(\d*(?:\.\d*)*)/,
  22951. format: 'maxptime:%d'
  22952. },
  22953. {
  22954. // a=sendrecv
  22955. name: 'direction',
  22956. reg: /^(sendrecv|recvonly|sendonly|inactive)/
  22957. },
  22958. {
  22959. // a=ice-lite
  22960. name: 'icelite',
  22961. reg: /^(ice-lite)/
  22962. },
  22963. {
  22964. // a=ice-ufrag:F7gI
  22965. name: 'iceUfrag',
  22966. reg: /^ice-ufrag:(\S*)/,
  22967. format: 'ice-ufrag:%s'
  22968. },
  22969. {
  22970. // a=ice-pwd:x9cml/YzichV2+XlhiMu8g
  22971. name: 'icePwd',
  22972. reg: /^ice-pwd:(\S*)/,
  22973. format: 'ice-pwd:%s'
  22974. },
  22975. {
  22976. // a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
  22977. name: 'fingerprint',
  22978. reg: /^fingerprint:(\S*) (\S*)/,
  22979. names: ['type', 'hash'],
  22980. format: 'fingerprint:%s %s'
  22981. },
  22982. {
  22983. // a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
  22984. // a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10
  22985. // 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
  22986. // a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10
  22987. // 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
  22988. push:'candidates',
  22989. reg: /^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,
  22990. names: ['foundation', 'component', 'transport', 'priority', 'ip', 'port', 'type', 'raddr', 'rport', 'tcptype', 'generation', 'network-id', 'network-cost'],
  22991. format: function (o) {
  22992. var str = 'candidate:%s %d %s %d %s %d typ %s';
  22993. str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v';
  22994. // NB: candidate has three optional chunks, so %void middles one if it's missing
  22995. str += (o.tcptype != null) ? ' tcptype %s' : '%v';
  22996. if (o.generation != null) {
  22997. str += ' generation %d';
  22998. }
  22999. str += (o['network-id'] != null) ? ' network-id %d' : '%v';
  23000. str += (o['network-cost'] != null) ? ' network-cost %d' : '%v';
  23001. return str;
  23002. }
  23003. },
  23004. {
  23005. // a=end-of-candidates (keep after the candidates line for readability)
  23006. name: 'endOfCandidates',
  23007. reg: /^(end-of-candidates)/
  23008. },
  23009. {
  23010. // a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ...
  23011. name: 'remoteCandidates',
  23012. reg: /^remote-candidates:(.*)/,
  23013. format: 'remote-candidates:%s'
  23014. },
  23015. {
  23016. // a=ice-options:google-ice
  23017. name: 'iceOptions',
  23018. reg: /^ice-options:(\S*)/,
  23019. format: 'ice-options:%s'
  23020. },
  23021. {
  23022. // a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1
  23023. push: 'ssrcs',
  23024. reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,
  23025. names: ['id', 'attribute', 'value'],
  23026. format: function (o) {
  23027. var str = 'ssrc:%d';
  23028. if (o.attribute != null) {
  23029. str += ' %s';
  23030. if (o.value != null) {
  23031. str += ':%s';
  23032. }
  23033. }
  23034. return str;
  23035. }
  23036. },
  23037. {
  23038. // a=ssrc-group:FEC 1 2
  23039. // a=ssrc-group:FEC-FR 3004364195 1080772241
  23040. push: 'ssrcGroups',
  23041. // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E
  23042. reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,
  23043. names: ['semantics', 'ssrcs'],
  23044. format: 'ssrc-group:%s %s'
  23045. },
  23046. {
  23047. // a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV
  23048. name: 'msidSemantic',
  23049. reg: /^msid-semantic:\s?(\w*) (\S*)/,
  23050. names: ['semantic', 'token'],
  23051. format: 'msid-semantic: %s %s' // space after ':' is not accidental
  23052. },
  23053. {
  23054. // a=group:BUNDLE audio video
  23055. push: 'groups',
  23056. reg: /^group:(\w*) (.*)/,
  23057. names: ['type', 'mids'],
  23058. format: 'group:%s %s'
  23059. },
  23060. {
  23061. // a=rtcp-mux
  23062. name: 'rtcpMux',
  23063. reg: /^(rtcp-mux)/
  23064. },
  23065. {
  23066. // a=rtcp-rsize
  23067. name: 'rtcpRsize',
  23068. reg: /^(rtcp-rsize)/
  23069. },
  23070. {
  23071. // a=sctpmap:5000 webrtc-datachannel 1024
  23072. name: 'sctpmap',
  23073. reg: /^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,
  23074. names: ['sctpmapNumber', 'app', 'maxMessageSize'],
  23075. format: function (o) {
  23076. return (o.maxMessageSize != null)
  23077. ? 'sctpmap:%s %s %s'
  23078. : 'sctpmap:%s %s';
  23079. }
  23080. },
  23081. {
  23082. // a=x-google-flag:conference
  23083. name: 'xGoogleFlag',
  23084. reg: /^x-google-flag:([^\s]*)/,
  23085. format: 'x-google-flag:%s'
  23086. },
  23087. {
  23088. // a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0
  23089. push: 'rids',
  23090. reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,
  23091. names: ['id', 'direction', 'params'],
  23092. format: function (o) {
  23093. return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s';
  23094. }
  23095. },
  23096. {
  23097. // a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250]
  23098. // a=imageattr:* send [x=800,y=640] recv *
  23099. // a=imageattr:100 recv [x=320,y=240]
  23100. push: 'imageattrs',
  23101. reg: new RegExp(
  23102. // a=imageattr:97
  23103. '^imageattr:(\\d+|\\*)' +
  23104. // send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320]
  23105. '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' +
  23106. // recv [x=330,y=250]
  23107. '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?'
  23108. ),
  23109. names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'],
  23110. format: function (o) {
  23111. return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : '');
  23112. }
  23113. },
  23114. {
  23115. // a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8
  23116. // a=simulcast:recv 1;4,5 send 6;7
  23117. name: 'simulcast',
  23118. reg: new RegExp(
  23119. // a=simulcast:
  23120. '^simulcast:' +
  23121. // send 1,2,3;~4,~5
  23122. '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' +
  23123. // space + recv 6;~7,~8
  23124. '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' +
  23125. // end
  23126. '$'
  23127. ),
  23128. names: ['dir1', 'list1', 'dir2', 'list2'],
  23129. format: function (o) {
  23130. return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : '');
  23131. }
  23132. },
  23133. {
  23134. // old simulcast draft 03 (implemented by Firefox)
  23135. // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03
  23136. // a=simulcast: recv pt=97;98 send pt=97
  23137. // a=simulcast: send rid=5;6;7 paused=6,7
  23138. name: 'simulcast_03',
  23139. reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/,
  23140. names: ['value'],
  23141. format: 'simulcast: %s'
  23142. },
  23143. {
  23144. // a=framerate:25
  23145. // a=framerate:29.97
  23146. name: 'framerate',
  23147. reg: /^framerate:(\d+(?:$|\.\d+))/,
  23148. format: 'framerate:%s'
  23149. },
  23150. {
  23151. // RFC4570
  23152. // a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5
  23153. name: 'sourceFilter',
  23154. reg: /^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,
  23155. names: ['filterMode', 'netType', 'addressTypes', 'destAddress', 'srcList'],
  23156. format: 'source-filter: %s %s %s %s %s'
  23157. },
  23158. {
  23159. // a=bundle-only
  23160. name: 'bundleOnly',
  23161. reg: /^(bundle-only)/
  23162. },
  23163. {
  23164. // a=label:1
  23165. name: 'label',
  23166. reg: /^label:(.+)/,
  23167. format: 'label:%s'
  23168. },
  23169. {
  23170. // RFC version 26 for SCTP over DTLS
  23171. // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5
  23172. name: 'sctpPort',
  23173. reg: /^sctp-port:(\d+)$/,
  23174. format: 'sctp-port:%s'
  23175. },
  23176. {
  23177. // RFC version 26 for SCTP over DTLS
  23178. // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
  23179. name: 'maxMessageSize',
  23180. reg: /^max-message-size:(\d+)$/,
  23181. format: 'max-message-size:%s'
  23182. },
  23183. {
  23184. // RFC7273
  23185. // a=ts-refclk:ptp=IEEE1588-2008:39-A7-94-FF-FE-07-CB-D0:37
  23186. push:'tsRefClocks',
  23187. reg: /^ts-refclk:([^\s=]*)(?:=(\S*))?/,
  23188. names: ['clksrc', 'clksrcExt'],
  23189. format: function (o) {
  23190. return 'ts-refclk:%s' + (o.clksrcExt != null ? '=%s' : '');
  23191. }
  23192. },
  23193. {
  23194. // RFC7273
  23195. // a=mediaclk:direct=963214424
  23196. name:'mediaClk',
  23197. reg: /^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,
  23198. names: ['id', 'mediaClockName', 'mediaClockValue', 'rateNumerator', 'rateDenominator'],
  23199. format: function (o) {
  23200. var str = 'mediaclk:';
  23201. str += (o.id != null ? 'id=%s %s' : '%v%s');
  23202. str += (o.mediaClockValue != null ? '=%s' : '');
  23203. str += (o.rateNumerator != null ? ' rate=%s' : '');
  23204. str += (o.rateDenominator != null ? '/%s' : '');
  23205. return str;
  23206. }
  23207. },
  23208. {
  23209. // a=keywds:keywords
  23210. name: 'keywords',
  23211. reg: /^keywds:(.+)$/,
  23212. format: 'keywds:%s'
  23213. },
  23214. {
  23215. // a=content:main
  23216. name: 'content',
  23217. reg: /^content:(.+)/,
  23218. format: 'content:%s'
  23219. },
  23220. // BFCP https://tools.ietf.org/html/rfc4583
  23221. {
  23222. // a=floorctrl:c-s
  23223. name: 'bfcpFloorCtrl',
  23224. reg: /^floorctrl:(c-only|s-only|c-s)/,
  23225. format: 'floorctrl:%s'
  23226. },
  23227. {
  23228. // a=confid:1
  23229. name: 'bfcpConfId',
  23230. reg: /^confid:(\d+)/,
  23231. format: 'confid:%s'
  23232. },
  23233. {
  23234. // a=userid:1
  23235. name: 'bfcpUserId',
  23236. reg: /^userid:(\d+)/,
  23237. format: 'userid:%s'
  23238. },
  23239. {
  23240. // a=floorid:1
  23241. name: 'bfcpFloorId',
  23242. reg: /^floorid:(.+) (?:m-stream|mstrm):(.+)/,
  23243. names: ['id', 'mStream'],
  23244. format: 'floorid:%s mstrm:%s'
  23245. },
  23246. {
  23247. // any a= that we don't understand is kept verbatim on media.invalid
  23248. push: 'invalid',
  23249. names: ['value']
  23250. }
  23251. ]
  23252. };
  23253. // set sensible defaults to avoid polluting the grammar with boring details
  23254. Object.keys(grammar).forEach(function (key) {
  23255. var objs = grammar[key];
  23256. objs.forEach(function (obj) {
  23257. if (!obj.reg) {
  23258. obj.reg = /(.*)/;
  23259. }
  23260. if (!obj.format) {
  23261. obj.format = '%s';
  23262. }
  23263. });
  23264. });
  23265. },{}],37:[function(require,module,exports){
  23266. var parser = require('./parser');
  23267. var writer = require('./writer');
  23268. exports.write = writer;
  23269. exports.parse = parser.parse;
  23270. exports.parseParams = parser.parseParams;
  23271. exports.parseFmtpConfig = parser.parseFmtpConfig; // Alias of parseParams().
  23272. exports.parsePayloads = parser.parsePayloads;
  23273. exports.parseRemoteCandidates = parser.parseRemoteCandidates;
  23274. exports.parseImageAttributes = parser.parseImageAttributes;
  23275. exports.parseSimulcastStreamList = parser.parseSimulcastStreamList;
  23276. },{"./parser":38,"./writer":39}],38:[function(require,module,exports){
  23277. var toIntIfInt = function (v) {
  23278. return String(Number(v)) === v ? Number(v) : v;
  23279. };
  23280. var attachProperties = function (match, location, names, rawName) {
  23281. if (rawName && !names) {
  23282. location[rawName] = toIntIfInt(match[1]);
  23283. }
  23284. else {
  23285. for (var i = 0; i < names.length; i += 1) {
  23286. if (match[i+1] != null) {
  23287. location[names[i]] = toIntIfInt(match[i+1]);
  23288. }
  23289. }
  23290. }
  23291. };
  23292. var parseReg = function (obj, location, content) {
  23293. var needsBlank = obj.name && obj.names;
  23294. if (obj.push && !location[obj.push]) {
  23295. location[obj.push] = [];
  23296. }
  23297. else if (needsBlank && !location[obj.name]) {
  23298. location[obj.name] = {};
  23299. }
  23300. var keyLocation = obj.push ?
  23301. {} : // blank object that will be pushed
  23302. needsBlank ? location[obj.name] : location; // otherwise, named location or root
  23303. attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name);
  23304. if (obj.push) {
  23305. location[obj.push].push(keyLocation);
  23306. }
  23307. };
  23308. var grammar = require('./grammar');
  23309. var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/);
  23310. exports.parse = function (sdp) {
  23311. var session = {}
  23312. , media = []
  23313. , location = session; // points at where properties go under (one of the above)
  23314. // parse lines we understand
  23315. sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) {
  23316. var type = l[0];
  23317. var content = l.slice(2);
  23318. if (type === 'm') {
  23319. media.push({rtp: [], fmtp: []});
  23320. location = media[media.length-1]; // point at latest media line
  23321. }
  23322. for (var j = 0; j < (grammar[type] || []).length; j += 1) {
  23323. var obj = grammar[type][j];
  23324. if (obj.reg.test(content)) {
  23325. return parseReg(obj, location, content);
  23326. }
  23327. }
  23328. });
  23329. session.media = media; // link it up
  23330. return session;
  23331. };
  23332. var paramReducer = function (acc, expr) {
  23333. var s = expr.split(/=(.+)/, 2);
  23334. if (s.length === 2) {
  23335. acc[s[0]] = toIntIfInt(s[1]);
  23336. } else if (s.length === 1 && expr.length > 1) {
  23337. acc[s[0]] = undefined;
  23338. }
  23339. return acc;
  23340. };
  23341. exports.parseParams = function (str) {
  23342. return str.split(/;\s?/).reduce(paramReducer, {});
  23343. };
  23344. // For backward compatibility - alias will be removed in 3.0.0
  23345. exports.parseFmtpConfig = exports.parseParams;
  23346. exports.parsePayloads = function (str) {
  23347. return str.toString().split(' ').map(Number);
  23348. };
  23349. exports.parseRemoteCandidates = function (str) {
  23350. var candidates = [];
  23351. var parts = str.split(' ').map(toIntIfInt);
  23352. for (var i = 0; i < parts.length; i += 3) {
  23353. candidates.push({
  23354. component: parts[i],
  23355. ip: parts[i + 1],
  23356. port: parts[i + 2]
  23357. });
  23358. }
  23359. return candidates;
  23360. };
  23361. exports.parseImageAttributes = function (str) {
  23362. return str.split(' ').map(function (item) {
  23363. return item.substring(1, item.length-1).split(',').reduce(paramReducer, {});
  23364. });
  23365. };
  23366. exports.parseSimulcastStreamList = function (str) {
  23367. return str.split(';').map(function (stream) {
  23368. return stream.split(',').map(function (format) {
  23369. var scid, paused = false;
  23370. if (format[0] !== '~') {
  23371. scid = toIntIfInt(format);
  23372. } else {
  23373. scid = toIntIfInt(format.substring(1, format.length));
  23374. paused = true;
  23375. }
  23376. return {
  23377. scid: scid,
  23378. paused: paused
  23379. };
  23380. });
  23381. });
  23382. };
  23383. },{"./grammar":36}],39:[function(require,module,exports){
  23384. var grammar = require('./grammar');
  23385. // customized util.format - discards excess arguments and can void middle ones
  23386. var formatRegExp = /%[sdv%]/g;
  23387. var format = function (formatStr) {
  23388. var i = 1;
  23389. var args = arguments;
  23390. var len = args.length;
  23391. return formatStr.replace(formatRegExp, function (x) {
  23392. if (i >= len) {
  23393. return x; // missing argument
  23394. }
  23395. var arg = args[i];
  23396. i += 1;
  23397. switch (x) {
  23398. case '%%':
  23399. return '%';
  23400. case '%s':
  23401. return String(arg);
  23402. case '%d':
  23403. return Number(arg);
  23404. case '%v':
  23405. return '';
  23406. }
  23407. });
  23408. // NB: we discard excess arguments - they are typically undefined from makeLine
  23409. };
  23410. var makeLine = function (type, obj, location) {
  23411. var str = obj.format instanceof Function ?
  23412. (obj.format(obj.push ? location : location[obj.name])) :
  23413. obj.format;
  23414. var args = [type + '=' + str];
  23415. if (obj.names) {
  23416. for (var i = 0; i < obj.names.length; i += 1) {
  23417. var n = obj.names[i];
  23418. if (obj.name) {
  23419. args.push(location[obj.name][n]);
  23420. }
  23421. else { // for mLine and push attributes
  23422. args.push(location[obj.names[i]]);
  23423. }
  23424. }
  23425. }
  23426. else {
  23427. args.push(location[obj.name]);
  23428. }
  23429. return format.apply(null, args);
  23430. };
  23431. // RFC specified order
  23432. // TODO: extend this with all the rest
  23433. var defaultOuterOrder = [
  23434. 'v', 'o', 's', 'i',
  23435. 'u', 'e', 'p', 'c',
  23436. 'b', 't', 'r', 'z', 'a'
  23437. ];
  23438. var defaultInnerOrder = ['i', 'c', 'b', 'a'];
  23439. module.exports = function (session, opts) {
  23440. opts = opts || {};
  23441. // ensure certain properties exist
  23442. if (session.version == null) {
  23443. session.version = 0; // 'v=0' must be there (only defined version atm)
  23444. }
  23445. if (session.name == null) {
  23446. session.name = ' '; // 's= ' must be there if no meaningful name set
  23447. }
  23448. session.media.forEach(function (mLine) {
  23449. if (mLine.payloads == null) {
  23450. mLine.payloads = '';
  23451. }
  23452. });
  23453. var outerOrder = opts.outerOrder || defaultOuterOrder;
  23454. var innerOrder = opts.innerOrder || defaultInnerOrder;
  23455. var sdp = [];
  23456. // loop through outerOrder for matching properties on session
  23457. outerOrder.forEach(function (type) {
  23458. grammar[type].forEach(function (obj) {
  23459. if (obj.name in session && session[obj.name] != null) {
  23460. sdp.push(makeLine(type, obj, session));
  23461. }
  23462. else if (obj.push in session && session[obj.push] != null) {
  23463. session[obj.push].forEach(function (el) {
  23464. sdp.push(makeLine(type, obj, el));
  23465. });
  23466. }
  23467. });
  23468. });
  23469. // then for each media line, follow the innerOrder
  23470. session.media.forEach(function (mLine) {
  23471. sdp.push(makeLine('m', grammar.m[0], mLine));
  23472. innerOrder.forEach(function (type) {
  23473. grammar[type].forEach(function (obj) {
  23474. if (obj.name in mLine && mLine[obj.name] != null) {
  23475. sdp.push(makeLine(type, obj, mLine));
  23476. }
  23477. else if (obj.push in mLine && mLine[obj.push] != null) {
  23478. mLine[obj.push].forEach(function (el) {
  23479. sdp.push(makeLine(type, obj, el));
  23480. });
  23481. }
  23482. });
  23483. });
  23484. });
  23485. return sdp.join('\r\n') + '\r\n';
  23486. };
  23487. },{"./grammar":36}],40:[function(require,module,exports){
  23488. module.exports={
  23489. "name": "jssip",
  23490. "title": "JsSIP",
  23491. "description": "the Javascript SIP library",
  23492. "version": "3.9.1",
  23493. "homepage": "https://jssip.net",
  23494. "contributors": [
  23495. "José Luis Millán <jmillan@aliax.net> (https://github.com/jmillan)",
  23496. "Iñaki Baz Castillo <ibc@aliax.net> (https://inakibaz.me)"
  23497. ],
  23498. "types": "lib/JsSIP.d.ts",
  23499. "main": "lib-es5/JsSIP.js",
  23500. "keywords": [
  23501. "sip",
  23502. "websocket",
  23503. "webrtc",
  23504. "node",
  23505. "browser",
  23506. "library"
  23507. ],
  23508. "license": "MIT",
  23509. "repository": {
  23510. "type": "git",
  23511. "url": "https://github.com/versatica/JsSIP.git"
  23512. },
  23513. "bugs": {
  23514. "url": "https://github.com/versatica/JsSIP/issues"
  23515. },
  23516. "dependencies": {
  23517. "@types/debug": "^4.1.5",
  23518. "@types/node": "^14.14.34",
  23519. "debug": "^4.3.1",
  23520. "events": "^3.3.0",
  23521. "sdp-transform": "^2.14.1"
  23522. },
  23523. "devDependencies": {
  23524. "@babel/core": "^7.13.10",
  23525. "@babel/preset-env": "^7.13.10",
  23526. "ansi-colors": "^3.2.4",
  23527. "browserify": "^16.5.1",
  23528. "eslint": "^5.16.0",
  23529. "fancy-log": "^1.3.3",
  23530. "gulp": "^4.0.2",
  23531. "gulp-babel": "^8.0.0",
  23532. "gulp-eslint": "^5.0.0",
  23533. "gulp-expect-file": "^1.0.2",
  23534. "gulp-header": "^2.0.9",
  23535. "gulp-nodeunit-runner": "^0.2.2",
  23536. "gulp-plumber": "^1.2.1",
  23537. "gulp-rename": "^1.4.0",
  23538. "gulp-uglify-es": "^1.0.4",
  23539. "pegjs": "^0.7.0",
  23540. "vinyl-buffer": "^1.0.1",
  23541. "vinyl-source-stream": "^2.0.0"
  23542. },
  23543. "scripts": {
  23544. "lint": "gulp lint",
  23545. "test": "gulp test",
  23546. "prepublishOnly": "gulp babel"
  23547. }
  23548. }
  23549. },{}]},{},[8])(8)
  23550. });