| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118 | 
							- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.xmpp=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
 - /* jshint -W117 */
 - var TraceablePeerConnection = require("./TraceablePeerConnection");
 - var SDPDiffer = require("./SDPDiffer");
 - var SDPUtil = require("./SDPUtil");
 - var SDP = require("./SDP");
 - 
 - // Jingle stuff
 - function JingleSession(me, sid, connection, service) {
 -     this.me = me;
 -     this.sid = sid;
 -     this.connection = connection;
 -     this.initiator = null;
 -     this.responder = null;
 -     this.isInitiator = null;
 -     this.peerjid = null;
 -     this.state = null;
 -     this.localSDP = null;
 -     this.remoteSDP = null;
 -     this.relayedStreams = [];
 -     this.startTime = null;
 -     this.stopTime = null;
 -     this.media_constraints = null;
 -     this.pc_constraints = null;
 -     this.ice_config = {};
 -     this.drip_container = [];
 -     this.service = service;
 - 
 -     this.usetrickle = true;
 -     this.usepranswer = false; // early transport warmup -- mind you, this might fail. depends on webrtc issue 1718
 -     this.usedrip = false; // dripping is sending trickle candidates not one-by-one
 - 
 -     this.hadstuncandidate = false;
 -     this.hadturncandidate = false;
 -     this.lasticecandidate = false;
 - 
 -     this.statsinterval = null;
 - 
 -     this.reason = null;
 - 
 -     this.addssrc = [];
 -     this.removessrc = [];
 -     this.pendingop = null;
 -     this.switchstreams = false;
 - 
 -     this.wait = true;
 -     this.localStreamsSSRC = null;
 - 
 -     /**
 -      * The indicator which determines whether the (local) video has been muted
 -      * in response to a user command in contrast to an automatic decision made
 -      * by the application logic.
 -      */
 -     this.videoMuteByUser = false;
 - }
 - 
 - //TODO: this array must be removed when firefox implement multistream support
 - JingleSession.notReceivedSSRCs = [];
 - 
 - JingleSession.prototype.initiate = function (peerjid, isInitiator) {
 -     var self = this;
 -     if (this.state !== null) {
 -         console.error('attempt to initiate on session ' + this.sid +
 -             'in state ' + this.state);
 -         return;
 -     }
 -     this.isInitiator = isInitiator;
 -     this.state = 'pending';
 -     this.initiator = isInitiator ? this.me : peerjid;
 -     this.responder = !isInitiator ? this.me : peerjid;
 -     this.peerjid = peerjid;
 -     this.hadstuncandidate = false;
 -     this.hadturncandidate = false;
 -     this.lasticecandidate = false;
 - 
 -     this.peerconnection
 -         = new TraceablePeerConnection(
 -             this.connection.jingle.ice_config,
 -             this.connection.jingle.pc_constraints );
 - 
 -     this.peerconnection.onicecandidate = function (event) {
 -         self.sendIceCandidate(event.candidate);
 -     };
 -     this.peerconnection.onaddstream = function (event) {
 -         console.log("REMOTE STREAM ADDED: " + event.stream + " - " + event.stream.id);
 -         self.remoteStreamAdded(event);
 -     };
 -     this.peerconnection.onremovestream = function (event) {
 -         // Remove the stream from remoteStreams
 -         // FIXME: remotestreamremoved.jingle not defined anywhere(unused)
 -         $(document).trigger('remotestreamremoved.jingle', [event, self.sid]);
 -     };
 -     this.peerconnection.onsignalingstatechange = function (event) {
 -         if (!(self && self.peerconnection)) return;
 -     };
 -     this.peerconnection.oniceconnectionstatechange = function (event) {
 -         if (!(self && self.peerconnection)) return;
 -         switch (self.peerconnection.iceConnectionState) {
 -             case 'connected':
 -                 this.startTime = new Date();
 -                 break;
 -             case 'disconnected':
 -                 this.stopTime = new Date();
 -                 break;
 -         }
 -         onIceConnectionStateChange(self.sid, self);
 -     };
 -     // add any local and relayed stream
 -     RTC.localStreams.forEach(function(stream) {
 -         self.peerconnection.addStream(stream.getOriginalStream());
 -     });
 -     this.relayedStreams.forEach(function(stream) {
 -         self.peerconnection.addStream(stream);
 -     });
 - };
 - 
 - function onIceConnectionStateChange(sid, session) {
 -     switch (session.peerconnection.iceConnectionState) {
 -         case 'checking':
 -             session.timeChecking = (new Date()).getTime();
 -             session.firstconnect = true;
 -             break;
 -         case 'completed': // on caller side
 -         case 'connected':
 -             if (session.firstconnect) {
 -                 session.firstconnect = false;
 -                 var metadata = {};
 -                 metadata.setupTime
 -                     = (new Date()).getTime() - session.timeChecking;
 -                 session.peerconnection.getStats(function (res) {
 -                     if(res && res.result) {
 -                         res.result().forEach(function (report) {
 -                             if (report.type == 'googCandidatePair' &&
 -                                 report.stat('googActiveConnection') == 'true') {
 -                                 metadata.localCandidateType
 -                                     = report.stat('googLocalCandidateType');
 -                                 metadata.remoteCandidateType
 -                                     = report.stat('googRemoteCandidateType');
 - 
 -                                 // log pair as well so we can get nice pie
 -                                 // charts
 -                                 metadata.candidatePair
 -                                     = report.stat('googLocalCandidateType') +
 -                                         ';' +
 -                                         report.stat('googRemoteCandidateType');
 - 
 -                                 if (report.stat('googRemoteAddress').indexOf('[') === 0)
 -                                 {
 -                                     metadata.ipv6 = true;
 -                                 }
 -                             }
 -                         });
 -                     }
 -                 });
 -             }
 -             break;
 -     }
 - }
 - 
 - JingleSession.prototype.accept = function () {
 -     var self = this;
 -     this.state = 'active';
 - 
 -     var pranswer = this.peerconnection.localDescription;
 -     if (!pranswer || pranswer.type != 'pranswer') {
 -         return;
 -     }
 -     console.log('going from pranswer to answer');
 -     if (this.usetrickle) {
 -         // remove candidates already sent from session-accept
 -         var lines = SDPUtil.find_lines(pranswer.sdp, 'a=candidate:');
 -         for (var i = 0; i < lines.length; i++) {
 -             pranswer.sdp = pranswer.sdp.replace(lines[i] + '\r\n', '');
 -         }
 -     }
 -     while (SDPUtil.find_line(pranswer.sdp, 'a=inactive')) {
 -         // FIXME: change any inactive to sendrecv or whatever they were originally
 -         pranswer.sdp = pranswer.sdp.replace('a=inactive', 'a=sendrecv');
 -     }
 -     pranswer = simulcast.reverseTransformLocalDescription(pranswer);
 -     var prsdp = new SDP(pranswer.sdp);
 -     var accept = $iq({to: this.peerjid,
 -         type: 'set'})
 -         .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
 -             action: 'session-accept',
 -             initiator: this.initiator,
 -             responder: this.responder,
 -             sid: this.sid });
 -     prsdp.toJingle(accept, this.initiator == this.me ? 'initiator' : 'responder', this.localStreamsSSRC);
 -     var sdp = this.peerconnection.localDescription.sdp;
 -     while (SDPUtil.find_line(sdp, 'a=inactive')) {
 -         // FIXME: change any inactive to sendrecv or whatever they were originally
 -         sdp = sdp.replace('a=inactive', 'a=sendrecv');
 -     }
 -     var self = this;
 -     this.peerconnection.setLocalDescription(new RTCSessionDescription({type: 'answer', sdp: sdp}),
 -         function () {
 -             //console.log('setLocalDescription success');
 -             self.setLocalDescription();
 - 
 -             self.connection.sendIQ(accept,
 -                 function () {
 -                     var ack = {};
 -                     ack.source = 'answer';
 -                     $(document).trigger('ack.jingle', [self.sid, ack]);
 -                 },
 -                 function (stanza) {
 -                     var error = ($(stanza).find('error').length) ? {
 -                         code: $(stanza).find('error').attr('code'),
 -                         reason: $(stanza).find('error :first')[0].tagName
 -                     }:{};
 -                     error.source = 'answer';
 -                     JingleSession.onJingleError(self.sid, error);
 -                 },
 -                 10000);
 -         },
 -         function (e) {
 -             console.error('setLocalDescription failed', e);
 -         }
 -     );
 - };
 - 
 - JingleSession.prototype.terminate = function (reason) {
 -     this.state = 'ended';
 -     this.reason = reason;
 -     this.peerconnection.close();
 -     if (this.statsinterval !== null) {
 -         window.clearInterval(this.statsinterval);
 -         this.statsinterval = null;
 -     }
 - };
 - 
 - JingleSession.prototype.active = function () {
 -     return this.state == 'active';
 - };
 - 
 - JingleSession.prototype.sendIceCandidate = function (candidate) {
 -     var self = this;
 -     if (candidate && !this.lasticecandidate) {
 -         var ice = SDPUtil.iceparams(this.localSDP.media[candidate.sdpMLineIndex], this.localSDP.session);
 -         var jcand = SDPUtil.candidateToJingle(candidate.candidate);
 -         if (!(ice && jcand)) {
 -             console.error('failed to get ice && jcand');
 -             return;
 -         }
 -         ice.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
 - 
 -         if (jcand.type === 'srflx') {
 -             this.hadstuncandidate = true;
 -         } else if (jcand.type === 'relay') {
 -             this.hadturncandidate = true;
 -         }
 - 
 -         if (this.usetrickle) {
 -             if (this.usedrip) {
 -                 if (this.drip_container.length === 0) {
 -                     // start 20ms callout
 -                     window.setTimeout(function () {
 -                         if (self.drip_container.length === 0) return;
 -                         self.sendIceCandidates(self.drip_container);
 -                         self.drip_container = [];
 -                     }, 20);
 - 
 -                 }
 -                 this.drip_container.push(candidate);
 -                 return;
 -             } else {
 -                 self.sendIceCandidate([candidate]);
 -             }
 -         }
 -     } else {
 -         //console.log('sendIceCandidate: last candidate.');
 -         if (!this.usetrickle) {
 -             //console.log('should send full offer now...');
 -             var init = $iq({to: this.peerjid,
 -                 type: 'set'})
 -                 .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
 -                     action: this.peerconnection.localDescription.type == 'offer' ? 'session-initiate' : 'session-accept',
 -                     initiator: this.initiator,
 -                     sid: this.sid});
 -             this.localSDP = new SDP(this.peerconnection.localDescription.sdp);
 -             var self = this;
 -             var sendJingle = function (ssrc) {
 -                 if(!ssrc)
 -                     ssrc = {};
 -                 self.localSDP.toJingle(init, self.initiator == self.me ? 'initiator' : 'responder', ssrc);
 -                 self.connection.sendIQ(init,
 -                     function () {
 -                         //console.log('session initiate ack');
 -                         var ack = {};
 -                         ack.source = 'offer';
 -                         $(document).trigger('ack.jingle', [self.sid, ack]);
 -                     },
 -                     function (stanza) {
 -                         self.state = 'error';
 -                         self.peerconnection.close();
 -                         var error = ($(stanza).find('error').length) ? {
 -                             code: $(stanza).find('error').attr('code'),
 -                             reason: $(stanza).find('error :first')[0].tagName,
 -                         }:{};
 -                         error.source = 'offer';
 -                         JingleSession.onJingleError(self.sid, error);
 -                     },
 -                     10000);
 -             }
 -             sendJingle();
 -         }
 -         this.lasticecandidate = true;
 -         console.log('Have we encountered any srflx candidates? ' + this.hadstuncandidate);
 -         console.log('Have we encountered any relay candidates? ' + this.hadturncandidate);
 - 
 -         if (!(this.hadstuncandidate || this.hadturncandidate) && this.peerconnection.signalingState != 'closed') {
 -             $(document).trigger('nostuncandidates.jingle', [this.sid]);
 -         }
 -     }
 - };
 - 
 - JingleSession.prototype.sendIceCandidates = function (candidates) {
 -     console.log('sendIceCandidates', candidates);
 -     var cand = $iq({to: this.peerjid, type: 'set'})
 -         .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
 -             action: 'transport-info',
 -             initiator: this.initiator,
 -             sid: this.sid});
 -     for (var mid = 0; mid < this.localSDP.media.length; mid++) {
 -         var cands = candidates.filter(function (el) { return el.sdpMLineIndex == mid; });
 -         var mline = SDPUtil.parse_mline(this.localSDP.media[mid].split('\r\n')[0]);
 -         if (cands.length > 0) {
 -             var ice = SDPUtil.iceparams(this.localSDP.media[mid], this.localSDP.session);
 -             ice.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
 -             cand.c('content', {creator: this.initiator == this.me ? 'initiator' : 'responder',
 -                 name: (cands[0].sdpMid? cands[0].sdpMid : mline.media)
 -             }).c('transport', ice);
 -             for (var i = 0; i < cands.length; i++) {
 -                 cand.c('candidate', SDPUtil.candidateToJingle(cands[i].candidate)).up();
 -             }
 -             // add fingerprint
 -             if (SDPUtil.find_line(this.localSDP.media[mid], 'a=fingerprint:', this.localSDP.session)) {
 -                 var tmp = SDPUtil.parse_fingerprint(SDPUtil.find_line(this.localSDP.media[mid], 'a=fingerprint:', this.localSDP.session));
 -                 tmp.required = true;
 -                 cand.c(
 -                     'fingerprint',
 -                     {xmlns: 'urn:xmpp:jingle:apps:dtls:0'})
 -                     .t(tmp.fingerprint);
 -                 delete tmp.fingerprint;
 -                 cand.attrs(tmp);
 -                 cand.up();
 -             }
 -             cand.up(); // transport
 -             cand.up(); // content
 -         }
 -     }
 -     // might merge last-candidate notification into this, but it is called alot later. See webrtc issue #2340
 -     //console.log('was this the last candidate', this.lasticecandidate);
 -     this.connection.sendIQ(cand,
 -         function () {
 -             var ack = {};
 -             ack.source = 'transportinfo';
 -             $(document).trigger('ack.jingle', [this.sid, ack]);
 -         },
 -         function (stanza) {
 -             var error = ($(stanza).find('error').length) ? {
 -                 code: $(stanza).find('error').attr('code'),
 -                 reason: $(stanza).find('error :first')[0].tagName,
 -             }:{};
 -             error.source = 'transportinfo';
 -             JingleSession.onJingleError(this.sid, error);
 -         },
 -         10000);
 - };
 - 
 - 
 - JingleSession.prototype.sendOffer = function () {
 -     //console.log('sendOffer...');
 -     var self = this;
 -     this.peerconnection.createOffer(function (sdp) {
 -             self.createdOffer(sdp);
 -         },
 -         function (e) {
 -             console.error('createOffer failed', e);
 -         },
 -         this.media_constraints
 -     );
 - };
 - 
 - JingleSession.prototype.createdOffer = function (sdp) {
 -     //console.log('createdOffer', sdp);
 -     var self = this;
 -     this.localSDP = new SDP(sdp.sdp);
 -     //this.localSDP.mangle();
 -     var sendJingle = function () {
 -         var init = $iq({to: this.peerjid,
 -             type: 'set'})
 -             .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
 -                 action: 'session-initiate',
 -                 initiator: this.initiator,
 -                 sid: this.sid});
 -         self.localSDP.toJingle(init, this.initiator == this.me ? 'initiator' : 'responder', this.localStreamsSSRC);
 -         self.connection.sendIQ(init,
 -             function () {
 -                 var ack = {};
 -                 ack.source = 'offer';
 -                 $(document).trigger('ack.jingle', [self.sid, ack]);
 -             },
 -             function (stanza) {
 -                 self.state = 'error';
 -                 self.peerconnection.close();
 -                 var error = ($(stanza).find('error').length) ? {
 -                     code: $(stanza).find('error').attr('code'),
 -                     reason: $(stanza).find('error :first')[0].tagName,
 -                 }:{};
 -                 error.source = 'offer';
 -                 JingleSession.onJingleError(self.sid, error);
 -             },
 -             10000);
 -     }
 -     sdp.sdp = this.localSDP.raw;
 -     this.peerconnection.setLocalDescription(sdp,
 -         function () {
 -             if(self.usetrickle)
 -             {
 -                 sendJingle();
 -             }
 -             self.setLocalDescription();
 -             //console.log('setLocalDescription success');
 -         },
 -         function (e) {
 -             console.error('setLocalDescription failed', e);
 -         }
 -     );
 -     var cands = SDPUtil.find_lines(this.localSDP.raw, 'a=candidate:');
 -     for (var i = 0; i < cands.length; i++) {
 -         var cand = SDPUtil.parse_icecandidate(cands[i]);
 -         if (cand.type == 'srflx') {
 -             this.hadstuncandidate = true;
 -         } else if (cand.type == 'relay') {
 -             this.hadturncandidate = true;
 -         }
 -     }
 - };
 - 
 - JingleSession.prototype.setRemoteDescription = function (elem, desctype) {
 -     //console.log('setting remote description... ', desctype);
 -     this.remoteSDP = new SDP('');
 -     this.remoteSDP.fromJingle(elem);
 -     if (this.peerconnection.remoteDescription !== null) {
 -         console.log('setRemoteDescription when remote description is not null, should be pranswer', this.peerconnection.remoteDescription);
 -         if (this.peerconnection.remoteDescription.type == 'pranswer') {
 -             var pranswer = new SDP(this.peerconnection.remoteDescription.sdp);
 -             for (var i = 0; i < pranswer.media.length; i++) {
 -                 // make sure we have ice ufrag and pwd
 -                 if (!SDPUtil.find_line(this.remoteSDP.media[i], 'a=ice-ufrag:', this.remoteSDP.session)) {
 -                     if (SDPUtil.find_line(pranswer.media[i], 'a=ice-ufrag:', pranswer.session)) {
 -                         this.remoteSDP.media[i] += SDPUtil.find_line(pranswer.media[i], 'a=ice-ufrag:', pranswer.session) + '\r\n';
 -                     } else {
 -                         console.warn('no ice ufrag?');
 -                     }
 -                     if (SDPUtil.find_line(pranswer.media[i], 'a=ice-pwd:', pranswer.session)) {
 -                         this.remoteSDP.media[i] += SDPUtil.find_line(pranswer.media[i], 'a=ice-pwd:', pranswer.session) + '\r\n';
 -                     } else {
 -                         console.warn('no ice pwd?');
 -                     }
 -                 }
 -                 // copy over candidates
 -                 var lines = SDPUtil.find_lines(pranswer.media[i], 'a=candidate:');
 -                 for (var j = 0; j < lines.length; j++) {
 -                     this.remoteSDP.media[i] += lines[j] + '\r\n';
 -                 }
 -             }
 -             this.remoteSDP.raw = this.remoteSDP.session + this.remoteSDP.media.join('');
 -         }
 -     }
 -     var remotedesc = new RTCSessionDescription({type: desctype, sdp: this.remoteSDP.raw});
 - 
 -     this.peerconnection.setRemoteDescription(remotedesc,
 -         function () {
 -             //console.log('setRemoteDescription success');
 -         },
 -         function (e) {
 -             console.error('setRemoteDescription error', e);
 -             JingleSession.onJingleFatalError(self, e);
 -         }
 -     );
 - };
 - 
 - JingleSession.prototype.addIceCandidate = function (elem) {
 -     var self = this;
 -     if (this.peerconnection.signalingState == 'closed') {
 -         return;
 -     }
 -     if (!this.peerconnection.remoteDescription && this.peerconnection.signalingState == 'have-local-offer') {
 -         console.log('trickle ice candidate arriving before session accept...');
 -         // create a PRANSWER for setRemoteDescription
 -         if (!this.remoteSDP) {
 -             var cobbled = 'v=0\r\n' +
 -                 'o=- ' + '1923518516' + ' 2 IN IP4 0.0.0.0\r\n' +// FIXME
 -                 's=-\r\n' +
 -                 't=0 0\r\n';
 -             // first, take some things from the local description
 -             for (var i = 0; i < this.localSDP.media.length; i++) {
 -                 cobbled += SDPUtil.find_line(this.localSDP.media[i], 'm=') + '\r\n';
 -                 cobbled += SDPUtil.find_lines(this.localSDP.media[i], 'a=rtpmap:').join('\r\n') + '\r\n';
 -                 if (SDPUtil.find_line(this.localSDP.media[i], 'a=mid:')) {
 -                     cobbled += SDPUtil.find_line(this.localSDP.media[i], 'a=mid:') + '\r\n';
 -                 }
 -                 cobbled += 'a=inactive\r\n';
 -             }
 -             this.remoteSDP = new SDP(cobbled);
 -         }
 -         // then add things like ice and dtls from remote candidate
 -         elem.each(function () {
 -             for (var i = 0; i < self.remoteSDP.media.length; i++) {
 -                 if (SDPUtil.find_line(self.remoteSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
 -                     self.remoteSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
 -                     if (!SDPUtil.find_line(self.remoteSDP.media[i], 'a=ice-ufrag:')) {
 -                         var tmp = $(this).find('transport');
 -                         self.remoteSDP.media[i] += 'a=ice-ufrag:' + tmp.attr('ufrag') + '\r\n';
 -                         self.remoteSDP.media[i] += 'a=ice-pwd:' + tmp.attr('pwd') + '\r\n';
 -                         tmp = $(this).find('transport>fingerprint');
 -                         if (tmp.length) {
 -                             self.remoteSDP.media[i] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
 -                         } else {
 -                             console.log('no dtls fingerprint (webrtc issue #1718?)');
 -                             self.remoteSDP.media[i] += 'a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:BAADBAADBAADBAADBAADBAADBAADBAADBAADBAAD\r\n';
 -                         }
 -                         break;
 -                     }
 -                 }
 -             }
 -         });
 -         this.remoteSDP.raw = this.remoteSDP.session + this.remoteSDP.media.join('');
 - 
 -         // we need a complete SDP with ice-ufrag/ice-pwd in all parts
 -         // this makes the assumption that the PRANSWER is constructed such that the ice-ufrag is in all mediaparts
 -         // but it could be in the session part as well. since the code above constructs this sdp this can't happen however
 -         var iscomplete = this.remoteSDP.media.filter(function (mediapart) {
 -             return SDPUtil.find_line(mediapart, 'a=ice-ufrag:');
 -         }).length == this.remoteSDP.media.length;
 - 
 -         if (iscomplete) {
 -             console.log('setting pranswer');
 -             try {
 -                 this.peerconnection.setRemoteDescription(new RTCSessionDescription({type: 'pranswer', sdp: this.remoteSDP.raw }),
 -                     function() {
 -                     },
 -                     function(e) {
 -                         console.log('setRemoteDescription pranswer failed', e.toString());
 -                     });
 -             } catch (e) {
 -                 console.error('setting pranswer failed', e);
 -             }
 -         } else {
 -             //console.log('not yet setting pranswer');
 -         }
 -     }
 -     // operate on each content element
 -     elem.each(function () {
 -         // would love to deactivate this, but firefox still requires it
 -         var idx = -1;
 -         var i;
 -         for (i = 0; i < self.remoteSDP.media.length; i++) {
 -             if (SDPUtil.find_line(self.remoteSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
 -                 self.remoteSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
 -                 idx = i;
 -                 break;
 -             }
 -         }
 -         if (idx == -1) { // fall back to localdescription
 -             for (i = 0; i < self.localSDP.media.length; i++) {
 -                 if (SDPUtil.find_line(self.localSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
 -                     self.localSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
 -                     idx = i;
 -                     break;
 -                 }
 -             }
 -         }
 -         var name = $(this).attr('name');
 -         // TODO: check ice-pwd and ice-ufrag?
 -         $(this).find('transport>candidate').each(function () {
 -             var line, candidate;
 -             line = SDPUtil.candidateFromJingle(this);
 -             candidate = new RTCIceCandidate({sdpMLineIndex: idx,
 -                 sdpMid: name,
 -                 candidate: line});
 -             try {
 -                 self.peerconnection.addIceCandidate(candidate);
 -             } catch (e) {
 -                 console.error('addIceCandidate failed', e.toString(), line);
 -             }
 -         });
 -     });
 - };
 - 
 - JingleSession.prototype.sendAnswer = function (provisional) {
 -     //console.log('createAnswer', provisional);
 -     var self = this;
 -     this.peerconnection.createAnswer(
 -         function (sdp) {
 -             self.createdAnswer(sdp, provisional);
 -         },
 -         function (e) {
 -             console.error('createAnswer failed', e);
 -         },
 -         this.media_constraints
 -     );
 - };
 - 
 - JingleSession.prototype.createdAnswer = function (sdp, provisional) {
 -     //console.log('createAnswer callback');
 -     var self = this;
 -     this.localSDP = new SDP(sdp.sdp);
 -     //this.localSDP.mangle();
 -     this.usepranswer = provisional === true;
 -     if (this.usetrickle) {
 -         if (this.usepranswer) {
 -             sdp.type = 'pranswer';
 -             for (var i = 0; i < this.localSDP.media.length; i++) {
 -                 this.localSDP.media[i] = this.localSDP.media[i].replace('a=sendrecv\r\n', 'a=inactive\r\n');
 -             }
 -             this.localSDP.raw = this.localSDP.session + '\r\n' + this.localSDP.media.join('');
 -         }
 -     }
 -     var self = this;
 -     var sendJingle = function (ssrcs) {
 - 
 -                 var accept = $iq({to: self.peerjid,
 -                     type: 'set'})
 -                     .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
 -                         action: 'session-accept',
 -                         initiator: self.initiator,
 -                         responder: self.responder,
 -                         sid: self.sid });
 -                 var publicLocalDesc = simulcast.reverseTransformLocalDescription(sdp);
 -                 var publicLocalSDP = new SDP(publicLocalDesc.sdp);
 -                 publicLocalSDP.toJingle(accept, self.initiator == self.me ? 'initiator' : 'responder', ssrcs);
 -                 self.connection.sendIQ(accept,
 -                     function () {
 -                         var ack = {};
 -                         ack.source = 'answer';
 -                         $(document).trigger('ack.jingle', [self.sid, ack]);
 -                     },
 -                     function (stanza) {
 -                         var error = ($(stanza).find('error').length) ? {
 -                             code: $(stanza).find('error').attr('code'),
 -                             reason: $(stanza).find('error :first')[0].tagName,
 -                         }:{};
 -                         error.source = 'answer';
 -                         JingleSession.onJingleError(self.sid, error);
 -                     },
 -                     10000);
 -     }
 -     sdp.sdp = this.localSDP.raw;
 -     this.peerconnection.setLocalDescription(sdp,
 -         function () {
 - 
 -             //console.log('setLocalDescription success');
 -             if (self.usetrickle && !self.usepranswer) {
 -                 sendJingle();
 -             }
 -             self.setLocalDescription();
 -         },
 -         function (e) {
 -             console.error('setLocalDescription failed', e);
 -         }
 -     );
 -     var cands = SDPUtil.find_lines(this.localSDP.raw, 'a=candidate:');
 -     for (var j = 0; j < cands.length; j++) {
 -         var cand = SDPUtil.parse_icecandidate(cands[j]);
 -         if (cand.type == 'srflx') {
 -             this.hadstuncandidate = true;
 -         } else if (cand.type == 'relay') {
 -             this.hadturncandidate = true;
 -         }
 -     }
 - };
 - 
 - JingleSession.prototype.sendTerminate = function (reason, text) {
 -     var self = this,
 -         term = $iq({to: this.peerjid,
 -             type: 'set'})
 -             .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
 -                 action: 'session-terminate',
 -                 initiator: this.initiator,
 -                 sid: this.sid})
 -             .c('reason')
 -             .c(reason || 'success');
 - 
 -     if (text) {
 -         term.up().c('text').t(text);
 -     }
 - 
 -     this.connection.sendIQ(term,
 -         function () {
 -             self.peerconnection.close();
 -             self.peerconnection = null;
 -             self.terminate();
 -             var ack = {};
 -             ack.source = 'terminate';
 -             $(document).trigger('ack.jingle', [self.sid, ack]);
 -         },
 -         function (stanza) {
 -             var error = ($(stanza).find('error').length) ? {
 -                 code: $(stanza).find('error').attr('code'),
 -                 reason: $(stanza).find('error :first')[0].tagName,
 -             }:{};
 -             $(document).trigger('ack.jingle', [self.sid, error]);
 -         },
 -         10000);
 -     if (this.statsinterval !== null) {
 -         window.clearInterval(this.statsinterval);
 -         this.statsinterval = null;
 -     }
 - };
 - 
 - JingleSession.prototype.addSource = function (elem, fromJid) {
 - 
 -     var self = this;
 -     // FIXME: dirty waiting
 -     if (!this.peerconnection.localDescription)
 -     {
 -         console.warn("addSource - localDescription not ready yet")
 -         setTimeout(function()
 -             {
 -                 self.addSource(elem, fromJid);
 -             },
 -             200
 -         );
 -         return;
 -     }
 - 
 -     console.log('addssrc', new Date().getTime());
 -     console.log('ice', this.peerconnection.iceConnectionState);
 -     var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
 -     var mySdp = new SDP(this.peerconnection.localDescription.sdp);
 - 
 -     $(elem).each(function (idx, content) {
 -         var name = $(content).attr('name');
 -         var lines = '';
 -         tmp = $(content).find('ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]').each(function() {
 -             var semantics = this.getAttribute('semantics');
 -             var ssrcs = $(this).find('>source').map(function () {
 -                 return this.getAttribute('ssrc');
 -             }).get();
 - 
 -             if (ssrcs.length != 0) {
 -                 lines += 'a=ssrc-group:' + semantics + ' ' + ssrcs.join(' ') + '\r\n';
 -             }
 -         });
 -         tmp = $(content).find('source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]'); // can handle both >source and >description>source
 -         tmp.each(function () {
 -             var ssrc = $(this).attr('ssrc');
 -             if(mySdp.containsSSRC(ssrc)){
 -                 /**
 -                  * This happens when multiple participants change their streams at the same time and
 -                  * ColibriFocus.modifySources have to wait for stable state. In the meantime multiple
 -                  * addssrc are scheduled for update IQ. See
 -                  */
 -                 console.warn("Got add stream request for my own ssrc: "+ssrc);
 -                 return;
 -             }
 -             $(this).find('>parameter').each(function () {
 -                 lines += 'a=ssrc:' + ssrc + ' ' + $(this).attr('name');
 -                 if ($(this).attr('value') && $(this).attr('value').length)
 -                     lines += ':' + $(this).attr('value');
 -                 lines += '\r\n';
 -             });
 -         });
 -         sdp.media.forEach(function(media, idx) {
 -             if (!SDPUtil.find_line(media, 'a=mid:' + name))
 -                 return;
 -             sdp.media[idx] += lines;
 -             if (!self.addssrc[idx]) self.addssrc[idx] = '';
 -             self.addssrc[idx] += lines;
 -         });
 -         sdp.raw = sdp.session + sdp.media.join('');
 -     });
 -     this.modifySources();
 - };
 - 
 - JingleSession.prototype.removeSource = function (elem, fromJid) {
 - 
 -     var self = this;
 -     // FIXME: dirty waiting
 -     if (!this.peerconnection.localDescription)
 -     {
 -         console.warn("removeSource - localDescription not ready yet")
 -         setTimeout(function()
 -             {
 -                 self.removeSource(elem, fromJid);
 -             },
 -             200
 -         );
 -         return;
 -     }
 - 
 -     console.log('removessrc', new Date().getTime());
 -     console.log('ice', this.peerconnection.iceConnectionState);
 -     var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
 -     var mySdp = new SDP(this.peerconnection.localDescription.sdp);
 - 
 -     $(elem).each(function (idx, content) {
 -         var name = $(content).attr('name');
 -         var lines = '';
 -         tmp = $(content).find('ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]').each(function() {
 -             var semantics = this.getAttribute('semantics');
 -             var ssrcs = $(this).find('>source').map(function () {
 -                 return this.getAttribute('ssrc');
 -             }).get();
 - 
 -             if (ssrcs.length != 0) {
 -                 lines += 'a=ssrc-group:' + semantics + ' ' + ssrcs.join(' ') + '\r\n';
 -             }
 -         });
 -         tmp = $(content).find('source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]'); // can handle both >source and >description>source
 -         tmp.each(function () {
 -             var ssrc = $(this).attr('ssrc');
 -             // This should never happen, but can be useful for bug detection
 -             if(mySdp.containsSSRC(ssrc)){
 -                 console.error("Got remove stream request for my own ssrc: "+ssrc);
 -                 return;
 -             }
 -             $(this).find('>parameter').each(function () {
 -                 lines += 'a=ssrc:' + ssrc + ' ' + $(this).attr('name');
 -                 if ($(this).attr('value') && $(this).attr('value').length)
 -                     lines += ':' + $(this).attr('value');
 -                 lines += '\r\n';
 -             });
 -         });
 -         sdp.media.forEach(function(media, idx) {
 -             if (!SDPUtil.find_line(media, 'a=mid:' + name))
 -                 return;
 -             sdp.media[idx] += lines;
 -             if (!self.removessrc[idx]) self.removessrc[idx] = '';
 -             self.removessrc[idx] += lines;
 -         });
 -         sdp.raw = sdp.session + sdp.media.join('');
 -     });
 -     this.modifySources();
 - };
 - 
 - JingleSession.prototype.modifySources = function (successCallback) {
 -     var self = this;
 -     if (this.peerconnection.signalingState == 'closed') return;
 -     if (!(this.addssrc.length || this.removessrc.length || this.pendingop !== null || this.switchstreams)){
 -         // There is nothing to do since scheduled job might have been executed by another succeeding call
 -         this.setLocalDescription();
 -         if(successCallback){
 -             successCallback();
 -         }
 -         return;
 -     }
 - 
 -     // FIXME: this is a big hack
 -     // https://code.google.com/p/webrtc/issues/detail?id=2688
 -     // ^ has been fixed.
 -     if (!(this.peerconnection.signalingState == 'stable' && this.peerconnection.iceConnectionState == 'connected')) {
 -         console.warn('modifySources not yet', this.peerconnection.signalingState, this.peerconnection.iceConnectionState);
 -         this.wait = true;
 -         window.setTimeout(function() { self.modifySources(successCallback); }, 250);
 -         return;
 -     }
 -     if (this.wait) {
 -         window.setTimeout(function() { self.modifySources(successCallback); }, 2500);
 -         this.wait = false;
 -         return;
 -     }
 - 
 -     // Reset switch streams flag
 -     this.switchstreams = false;
 - 
 -     var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
 - 
 -     // add sources
 -     this.addssrc.forEach(function(lines, idx) {
 -         sdp.media[idx] += lines;
 -     });
 -     this.addssrc = [];
 - 
 -     // remove sources
 -     this.removessrc.forEach(function(lines, idx) {
 -         lines = lines.split('\r\n');
 -         lines.pop(); // remove empty last element;
 -         lines.forEach(function(line) {
 -             sdp.media[idx] = sdp.media[idx].replace(line + '\r\n', '');
 -         });
 -     });
 -     this.removessrc = [];
 - 
 -     // FIXME:
 -     // this was a hack for the situation when only one peer exists
 -     // in the conference.
 -     // check if still required and remove
 -     if (sdp.media[0])
 -         sdp.media[0] = sdp.media[0].replace('a=recvonly', 'a=sendrecv');
 -     if (sdp.media[1])
 -         sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
 - 
 -     sdp.raw = sdp.session + sdp.media.join('');
 -     this.peerconnection.setRemoteDescription(new RTCSessionDescription({type: 'offer', sdp: sdp.raw}),
 -         function() {
 - 
 -             if(self.signalingState == 'closed') {
 -                 console.error("createAnswer attempt on closed state");
 -                 return;
 -             }
 - 
 -             self.peerconnection.createAnswer(
 -                 function(modifiedAnswer) {
 -                     // change video direction, see https://github.com/jitsi/jitmeet/issues/41
 -                     if (self.pendingop !== null) {
 -                         var sdp = new SDP(modifiedAnswer.sdp);
 -                         if (sdp.media.length > 1) {
 -                             switch(self.pendingop) {
 -                                 case 'mute':
 -                                     sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
 -                                     break;
 -                                 case 'unmute':
 -                                     sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
 -                                     break;
 -                             }
 -                             sdp.raw = sdp.session + sdp.media.join('');
 -                             modifiedAnswer.sdp = sdp.raw;
 -                         }
 -                         self.pendingop = null;
 -                     }
 - 
 -                     // FIXME: pushing down an answer while ice connection state
 -                     // is still checking is bad...
 -                     //console.log(self.peerconnection.iceConnectionState);
 - 
 -                     // trying to work around another chrome bug
 -                     //modifiedAnswer.sdp = modifiedAnswer.sdp.replace(/a=setup:active/g, 'a=setup:actpass');
 -                     self.peerconnection.setLocalDescription(modifiedAnswer,
 -                         function() {
 -                             //console.log('modified setLocalDescription ok');
 -                             self.setLocalDescription();
 -                             if(successCallback){
 -                                 successCallback();
 -                             }
 -                         },
 -                         function(error) {
 -                             console.error('modified setLocalDescription failed', error);
 -                         }
 -                     );
 -                 },
 -                 function(error) {
 -                     console.error('modified answer failed', error);
 -                 }
 -             );
 -         },
 -         function(error) {
 -             console.error('modify failed', error);
 -         }
 -     );
 - };
 - 
 - /**
 -  * Switches video streams.
 -  * @param new_stream new stream that will be used as video of this session.
 -  * @param oldStream old video stream of this session.
 -  * @param success_callback callback executed after successful stream switch.
 -  */
 - JingleSession.prototype.switchStreams = function (new_stream, oldStream, success_callback) {
 - 
 -     var self = this;
 - 
 -     // Remember SDP to figure out added/removed SSRCs
 -     var oldSdp = null;
 -     if(self.peerconnection) {
 -         if(self.peerconnection.localDescription) {
 -             oldSdp = new SDP(self.peerconnection.localDescription.sdp);
 -         }
 -         self.peerconnection.removeStream(oldStream, true);
 -         self.peerconnection.addStream(new_stream);
 -     }
 - 
 -     RTC.switchVideoStreams(new_stream, oldStream);
 - 
 -     // Conference is not active
 -     if(!oldSdp || !self.peerconnection) {
 -         success_callback();
 -         return;
 -     }
 - 
 -     self.switchstreams = true;
 -     self.modifySources(function() {
 -         console.log('modify sources done');
 - 
 -         success_callback();
 - 
 -         var newSdp = new SDP(self.peerconnection.localDescription.sdp);
 -         console.log("SDPs", oldSdp, newSdp);
 -         self.notifyMySSRCUpdate(oldSdp, newSdp);
 -     });
 - };
 - 
 - /**
 -  * Figures out added/removed ssrcs and send update IQs.
 -  * @param old_sdp SDP object for old description.
 -  * @param new_sdp SDP object for new description.
 -  */
 - JingleSession.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
 - 
 -     if (!(this.peerconnection.signalingState == 'stable' &&
 -         this.peerconnection.iceConnectionState == 'connected')){
 -         console.log("Too early to send updates");
 -         return;
 -     }
 - 
 -     // send source-remove IQ.
 -     sdpDiffer = new SDPDiffer(new_sdp, old_sdp);
 -     var remove = $iq({to: this.peerjid, type: 'set'})
 -         .c('jingle', {
 -             xmlns: 'urn:xmpp:jingle:1',
 -             action: 'source-remove',
 -             initiator: this.initiator,
 -             sid: this.sid
 -         }
 -     );
 -     var removed = sdpDiffer.toJingle(remove);
 -     if (removed) {
 -         this.connection.sendIQ(remove,
 -             function (res) {
 -                 console.info('got remove result', res);
 -             },
 -             function (err) {
 -                 console.error('got remove error', err);
 -             }
 -         );
 -     } else {
 -         console.log('removal not necessary');
 -     }
 - 
 -     // send source-add IQ.
 -     var sdpDiffer = new SDPDiffer(old_sdp, new_sdp);
 -     var add = $iq({to: this.peerjid, type: 'set'})
 -         .c('jingle', {
 -             xmlns: 'urn:xmpp:jingle:1',
 -             action: 'source-add',
 -             initiator: this.initiator,
 -             sid: this.sid
 -         }
 -     );
 -     var added = sdpDiffer.toJingle(add);
 -     if (added) {
 -         this.connection.sendIQ(add,
 -             function (res) {
 -                 console.info('got add result', res);
 -             },
 -             function (err) {
 -                 console.error('got add error', err);
 -             }
 -         );
 -     } else {
 -         console.log('addition not necessary');
 -     }
 - };
 - 
 - /**
 -  * Determines whether the (local) video is mute i.e. all video tracks are
 -  * disabled.
 -  *
 -  * @return <tt>true</tt> if the (local) video is mute i.e. all video tracks are
 -  * disabled; otherwise, <tt>false</tt>
 -  */
 - JingleSession.prototype.isVideoMute = function () {
 -     var tracks = RTC.localVideo.getVideoTracks();
 -     var mute = true;
 - 
 -     for (var i = 0; i < tracks.length; ++i) {
 -         if (tracks[i].enabled) {
 -             mute = false;
 -             break;
 -         }
 -     }
 -     return mute;
 - };
 - 
 - /**
 -  * Mutes/unmutes the (local) video i.e. enables/disables all video tracks.
 -  *
 -  * @param mute <tt>true</tt> to mute the (local) video i.e. to disable all video
 -  * tracks; otherwise, <tt>false</tt>
 -  * @param callback a function to be invoked with <tt>mute</tt> after all video
 -  * tracks have been enabled/disabled. The function may, optionally, return
 -  * another function which is to be invoked after the whole mute/unmute operation
 -  * has completed successfully.
 -  * @param options an object which specifies optional arguments such as the
 -  * <tt>boolean</tt> key <tt>byUser</tt> with default value <tt>true</tt> which
 -  * specifies whether the method was initiated in response to a user command (in
 -  * contrast to an automatic decision made by the application logic)
 -  */
 - JingleSession.prototype.setVideoMute = function (mute, callback, options) {
 -     var byUser;
 - 
 -     if (options) {
 -         byUser = options.byUser;
 -         if (typeof byUser === 'undefined') {
 -             byUser = true;
 -         }
 -     } else {
 -         byUser = true;
 -     }
 -     // The user's command to mute the (local) video takes precedence over any
 -     // automatic decision made by the application logic.
 -     if (byUser) {
 -         this.videoMuteByUser = mute;
 -     } else if (this.videoMuteByUser) {
 -         return;
 -     }
 - 
 -     var self = this;
 -     var localCallback = function (mute) {
 -         self.connection.emuc.addVideoInfoToPresence(mute);
 -         self.connection.emuc.sendPresence();
 -         return callback(mute)
 -     };
 - 
 -     if (mute == RTC.localVideo.isMuted())
 -     {
 -         // Even if no change occurs, the specified callback is to be executed.
 -         // The specified callback may, optionally, return a successCallback
 -         // which is to be executed as well.
 -         var successCallback = localCallback(mute);
 - 
 -         if (successCallback) {
 -             successCallback();
 -         }
 -     } else {
 -         RTC.localVideo.setMute(!mute);
 - 
 -         this.hardMuteVideo(mute);
 - 
 -         this.modifySources(localCallback(mute));
 -     }
 - };
 - 
 - // SDP-based mute by going recvonly/sendrecv
 - // FIXME: should probably black out the screen as well
 - JingleSession.prototype.toggleVideoMute = function (callback) {
 -     this.service.setVideoMute(RTC.localVideo.isMuted(), callback);
 - };
 - 
 - JingleSession.prototype.hardMuteVideo = function (muted) {
 -     this.pendingop = muted ? 'mute' : 'unmute';
 - };
 - 
 - JingleSession.prototype.sendMute = function (muted, content) {
 -     var info = $iq({to: this.peerjid,
 -         type: 'set'})
 -         .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
 -             action: 'session-info',
 -             initiator: this.initiator,
 -             sid: this.sid });
 -     info.c(muted ? 'mute' : 'unmute', {xmlns: 'urn:xmpp:jingle:apps:rtp:info:1'});
 -     info.attrs({'creator': this.me == this.initiator ? 'creator' : 'responder'});
 -     if (content) {
 -         info.attrs({'name': content});
 -     }
 -     this.connection.send(info);
 - };
 - 
 - JingleSession.prototype.sendRinging = function () {
 -     var info = $iq({to: this.peerjid,
 -         type: 'set'})
 -         .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
 -             action: 'session-info',
 -             initiator: this.initiator,
 -             sid: this.sid });
 -     info.c('ringing', {xmlns: 'urn:xmpp:jingle:apps:rtp:info:1'});
 -     this.connection.send(info);
 - };
 - 
 - JingleSession.prototype.getStats = function (interval) {
 -     var self = this;
 -     var recv = {audio: 0, video: 0};
 -     var lost = {audio: 0, video: 0};
 -     var lastrecv = {audio: 0, video: 0};
 -     var lastlost = {audio: 0, video: 0};
 -     var loss = {audio: 0, video: 0};
 -     var delta = {audio: 0, video: 0};
 -     this.statsinterval = window.setInterval(function () {
 -         if (self && self.peerconnection && self.peerconnection.getStats) {
 -             self.peerconnection.getStats(function (stats) {
 -                 var results = stats.result();
 -                 // TODO: there are so much statistics you can get from this..
 -                 for (var i = 0; i < results.length; ++i) {
 -                     if (results[i].type == 'ssrc') {
 -                         var packetsrecv = results[i].stat('packetsReceived');
 -                         var packetslost = results[i].stat('packetsLost');
 -                         if (packetsrecv && packetslost) {
 -                             packetsrecv = parseInt(packetsrecv, 10);
 -                             packetslost = parseInt(packetslost, 10);
 - 
 -                             if (results[i].stat('googFrameRateReceived')) {
 -                                 lastlost.video = lost.video;
 -                                 lastrecv.video = recv.video;
 -                                 recv.video = packetsrecv;
 -                                 lost.video = packetslost;
 -                             } else {
 -                                 lastlost.audio = lost.audio;
 -                                 lastrecv.audio = recv.audio;
 -                                 recv.audio = packetsrecv;
 -                                 lost.audio = packetslost;
 -                             }
 -                         }
 -                     }
 -                 }
 -                 delta.audio = recv.audio - lastrecv.audio;
 -                 delta.video = recv.video - lastrecv.video;
 -                 loss.audio = (delta.audio > 0) ? Math.ceil(100 * (lost.audio - lastlost.audio) / delta.audio) : 0;
 -                 loss.video = (delta.video > 0) ? Math.ceil(100 * (lost.video - lastlost.video) / delta.video) : 0;
 -                 $(document).trigger('packetloss.jingle', [self.sid, loss]);
 -             });
 -         }
 -     }, interval || 3000);
 -     return this.statsinterval;
 - };
 - 
 - JingleSession.onJingleError = function (session, error)
 - {
 -     console.error("Jingle error", error);
 - }
 - 
 - JingleSession.onJingleFatalError = function (session, error)
 - {
 -     this.service.sessionTerminated = true;
 -     connection.emuc.doLeave();
 -     UI.messageHandler.showError(  "Sorry",
 -         "Internal application error[setRemoteDescription]");
 - }
 - 
 - JingleSession.prototype.setLocalDescription = function () {
 -     // put our ssrcs into presence so other clients can identify our stream
 -     var newssrcs = [];
 -     var media = simulcast.parseMedia(this.peerconnection.localDescription);
 -     media.forEach(function (media) {
 - 
 -         if(Object.keys(media.sources).length > 0) {
 -             // TODO(gp) maybe exclude FID streams?
 -             Object.keys(media.sources).forEach(function (ssrc) {
 -                 newssrcs.push({
 -                     'ssrc': ssrc,
 -                     'type': media.type,
 -                     'direction': media.direction
 -                 });
 -             });
 -         }
 -         else if(this.localStreamsSSRC && this.localStreamsSSRC[media.type])
 -         {
 -             newssrcs.push({
 -                 'ssrc': this.localStreamsSSRC[media.type],
 -                 'type': media.type,
 -                 'direction': media.direction
 -             });
 -         }
 - 
 -     });
 - 
 -     console.log('new ssrcs', newssrcs);
 - 
 -     // Have to clear presence map to get rid of removed streams
 -     this.connection.emuc.clearPresenceMedia();
 - 
 -     if (newssrcs.length > 0) {
 -         for (var i = 1; i <= newssrcs.length; i ++) {
 -             // Change video type to screen
 -             if (newssrcs[i-1].type === 'video' && desktopsharing.isUsingScreenStream()) {
 -                 newssrcs[i-1].type = 'screen';
 -             }
 -             this.connection.emuc.addMediaToPresence(i,
 -                 newssrcs[i-1].type, newssrcs[i-1].ssrc, newssrcs[i-1].direction);
 -         }
 - 
 -         this.connection.emuc.sendPresence();
 -     }
 - }
 - 
 - // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
 - function sendKeyframe(pc) {
 -     console.log('sendkeyframe', pc.iceConnectionState);
 -     if (pc.iceConnectionState !== 'connected') return; // safe...
 -     pc.setRemoteDescription(
 -         pc.remoteDescription,
 -         function () {
 -             pc.createAnswer(
 -                 function (modifiedAnswer) {
 -                     pc.setLocalDescription(
 -                         modifiedAnswer,
 -                         function () {
 -                             // noop
 -                         },
 -                         function (error) {
 -                             console.log('triggerKeyframe setLocalDescription failed', error);
 -                             UI.messageHandler.showError();
 -                         }
 -                     );
 -                 },
 -                 function (error) {
 -                     console.log('triggerKeyframe createAnswer failed', error);
 -                     UI.messageHandler.showError();
 -                 }
 -             );
 -         },
 -         function (error) {
 -             console.log('triggerKeyframe setRemoteDescription failed', error);
 -             UI.messageHandler.showError();
 -         }
 -     );
 - }
 - 
 - 
 - JingleSession.prototype.remoteStreamAdded = function (data) {
 -     var self = this;
 -     var thessrc;
 - 
 -     // look up an associated JID for a stream id
 -     if (data.stream.id && data.stream.id.indexOf('mixedmslabel') === -1) {
 -         // look only at a=ssrc: and _not_ at a=ssrc-group: lines
 - 
 -         var ssrclines
 -             = SDPUtil.find_lines(this.peerconnection.remoteDescription.sdp, 'a=ssrc:');
 -         ssrclines = ssrclines.filter(function (line) {
 -             // NOTE(gp) previously we filtered on the mslabel, but that property
 -             // is not always present.
 -             // return line.indexOf('mslabel:' + data.stream.label) !== -1;
 - 
 -             return ((line.indexOf('msid:' + data.stream.id) !== -1));
 -         });
 -         if (ssrclines.length) {
 -             thessrc = ssrclines[0].substring(7).split(' ')[0];
 - 
 -             // We signal our streams (through Jingle to the focus) before we set
 -             // our presence (through which peers associate remote streams to
 -             // jids). So, it might arrive that a remote stream is added but
 -             // ssrc2jid is not yet updated and thus data.peerjid cannot be
 -             // successfully set. Here we wait for up to a second for the
 -             // presence to arrive.
 - 
 -             if (!ssrc2jid[thessrc]) {
 -                 // TODO(gp) limit wait duration to 1 sec.
 -                 setTimeout(function(d) {
 -                     return function() {
 -                         self.remoteStreamAdded(d);
 -                     }
 -                 }(data), 250);
 -                 return;
 -             }
 - 
 -             // ok to overwrite the one from focus? might save work in colibri.js
 -             console.log('associated jid', ssrc2jid[thessrc], data.peerjid);
 -             if (ssrc2jid[thessrc]) {
 -                 data.peerjid = ssrc2jid[thessrc];
 -             }
 -         }
 -     }
 - 
 -     //TODO: this code should be removed when firefox implement multistream support
 -     if(RTC.getBrowserType() == RTCBrowserType.RTC_BROWSER_FIREFOX)
 -     {
 -         if((JingleSession.notReceivedSSRCs.length == 0) ||
 -             !ssrc2jid[JingleSession.notReceivedSSRCs[JingleSession.notReceivedSSRCs.length - 1]])
 -         {
 -             // TODO(gp) limit wait duration to 1 sec.
 -             setTimeout(function(d) {
 -                 return function() {
 -                     self.remoteStreamAdded(d);
 -                 }
 -             }(data), 250);
 -             return;
 -         }
 - 
 -         thessrc = JingleSession.notReceivedSSRCs.pop();
 -         if (ssrc2jid[thessrc]) {
 -             data.peerjid = ssrc2jid[thessrc];
 -         }
 -     }
 - 
 -     RTC.createRemoteStream(data, this.sid, thessrc);
 - 
 -     var isVideo = data.stream.getVideoTracks().length > 0;
 -     // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
 -     if (isVideo &&
 -         data.peerjid && this.peerjid === data.peerjid &&
 -         data.stream.getVideoTracks().length === 0 &&
 -         RTC.localVideo.getTracks().length > 0) {
 -         window.setTimeout(function () {
 -             sendKeyframe(self.peerconnection);
 -         }, 3000);
 -     }
 - }
 - 
 - module.exports = JingleSession;
 - },{"./SDP":2,"./SDPDiffer":3,"./SDPUtil":4,"./TraceablePeerConnection":5}],2:[function(require,module,exports){
 - /* jshint -W117 */
 - var SDPUtil = require("./SDPUtil");
 - 
 - // SDP STUFF
 - function SDP(sdp) {
 -     this.media = sdp.split('\r\nm=');
 -     for (var i = 1; i < this.media.length; i++) {
 -         this.media[i] = 'm=' + this.media[i];
 -         if (i != this.media.length - 1) {
 -             this.media[i] += '\r\n';
 -         }
 -     }
 -     this.session = this.media.shift() + '\r\n';
 -     this.raw = this.session + this.media.join('');
 - }
 - /**
 -  * Returns map of MediaChannel mapped per channel idx.
 -  */
 - SDP.prototype.getMediaSsrcMap = function() {
 -     var self = this;
 -     var media_ssrcs = {};
 -     var tmp;
 -     for (var mediaindex = 0; mediaindex < self.media.length; mediaindex++) {
 -         tmp = SDPUtil.find_lines(self.media[mediaindex], 'a=ssrc:');
 -         var mid = SDPUtil.parse_mid(SDPUtil.find_line(self.media[mediaindex], 'a=mid:'));
 -         var media = {
 -             mediaindex: mediaindex,
 -             mid: mid,
 -             ssrcs: {},
 -             ssrcGroups: []
 -         };
 -         media_ssrcs[mediaindex] = media;
 -         tmp.forEach(function (line) {
 -             var linessrc = line.substring(7).split(' ')[0];
 -             // allocate new ChannelSsrc
 -             if(!media.ssrcs[linessrc]) {
 -                 media.ssrcs[linessrc] = {
 -                     ssrc: linessrc,
 -                     lines: []
 -                 };
 -             }
 -             media.ssrcs[linessrc].lines.push(line);
 -         });
 -         tmp = SDPUtil.find_lines(self.media[mediaindex], 'a=ssrc-group:');
 -         tmp.forEach(function(line){
 -             var semantics = line.substr(0, idx).substr(13);
 -             var ssrcs = line.substr(14 + semantics.length).split(' ');
 -             if (ssrcs.length != 0) {
 -                 media.ssrcGroups.push({
 -                     semantics: semantics,
 -                     ssrcs: ssrcs
 -                 });
 -             }
 -         });
 -     }
 -     return media_ssrcs;
 - };
 - /**
 -  * Returns <tt>true</tt> if this SDP contains given SSRC.
 -  * @param ssrc the ssrc to check.
 -  * @returns {boolean} <tt>true</tt> if this SDP contains given SSRC.
 -  */
 - SDP.prototype.containsSSRC = function(ssrc) {
 -     var medias = this.getMediaSsrcMap();
 -     var contains = false;
 -     Object.keys(medias).forEach(function(mediaindex){
 -         var media = medias[mediaindex];
 -         //console.log("Check", channel, ssrc);
 -         if(Object.keys(media.ssrcs).indexOf(ssrc) != -1){
 -             contains = true;
 -         }
 -     });
 -     return contains;
 - };
 - 
 - 
 - // remove iSAC and CN from SDP
 - SDP.prototype.mangle = function () {
 -     var i, j, mline, lines, rtpmap, newdesc;
 -     for (i = 0; i < this.media.length; i++) {
 -         lines = this.media[i].split('\r\n');
 -         lines.pop(); // remove empty last element
 -         mline = SDPUtil.parse_mline(lines.shift());
 -         if (mline.media != 'audio')
 -             continue;
 -         newdesc = '';
 -         mline.fmt.length = 0;
 -         for (j = 0; j < lines.length; j++) {
 -             if (lines[j].substr(0, 9) == 'a=rtpmap:') {
 -                 rtpmap = SDPUtil.parse_rtpmap(lines[j]);
 -                 if (rtpmap.name == 'CN' || rtpmap.name == 'ISAC')
 -                     continue;
 -                 mline.fmt.push(rtpmap.id);
 -                 newdesc += lines[j] + '\r\n';
 -             } else {
 -                 newdesc += lines[j] + '\r\n';
 -             }
 -         }
 -         this.media[i] = SDPUtil.build_mline(mline) + '\r\n';
 -         this.media[i] += newdesc;
 -     }
 -     this.raw = this.session + this.media.join('');
 - };
 - 
 - // remove lines matching prefix from session section
 - SDP.prototype.removeSessionLines = function(prefix) {
 -     var self = this;
 -     var lines = SDPUtil.find_lines(this.session, prefix);
 -     lines.forEach(function(line) {
 -         self.session = self.session.replace(line + '\r\n', '');
 -     });
 -     this.raw = this.session + this.media.join('');
 -     return lines;
 - }
 - // remove lines matching prefix from a media section specified by mediaindex
 - // TODO: non-numeric mediaindex could match mid
 - SDP.prototype.removeMediaLines = function(mediaindex, prefix) {
 -     var self = this;
 -     var lines = SDPUtil.find_lines(this.media[mediaindex], prefix);
 -     lines.forEach(function(line) {
 -         self.media[mediaindex] = self.media[mediaindex].replace(line + '\r\n', '');
 -     });
 -     this.raw = this.session + this.media.join('');
 -     return lines;
 - }
 - 
 - // add content's to a jingle element
 - SDP.prototype.toJingle = function (elem, thecreator, ssrcs) {
 - //    console.log("SSRC" + ssrcs["audio"] + " - " + ssrcs["video"]);
 -     var i, j, k, mline, ssrc, rtpmap, tmp, line, lines;
 -     var self = this;
 -     // new bundle plan
 -     if (SDPUtil.find_line(this.session, 'a=group:')) {
 -         lines = SDPUtil.find_lines(this.session, 'a=group:');
 -         for (i = 0; i < lines.length; i++) {
 -             tmp = lines[i].split(' ');
 -             var semantics = tmp.shift().substr(8);
 -             elem.c('group', {xmlns: 'urn:xmpp:jingle:apps:grouping:0', semantics:semantics});
 -             for (j = 0; j < tmp.length; j++) {
 -                 elem.c('content', {name: tmp[j]}).up();
 -             }
 -             elem.up();
 -         }
 -     }
 -     for (i = 0; i < this.media.length; i++) {
 -         mline = SDPUtil.parse_mline(this.media[i].split('\r\n')[0]);
 -         if (!(mline.media === 'audio' ||
 -               mline.media === 'video' ||
 -               mline.media === 'application'))
 -         {
 -             continue;
 -         }
 -         if (SDPUtil.find_line(this.media[i], 'a=ssrc:')) {
 -             ssrc = SDPUtil.find_line(this.media[i], 'a=ssrc:').substring(7).split(' ')[0]; // take the first
 -         } else {
 -             if(ssrcs && ssrcs[mline.media])
 -             {
 -                 ssrc = ssrcs[mline.media];
 -             }
 -             else
 -                 ssrc = false;
 -         }
 - 
 -         elem.c('content', {creator: thecreator, name: mline.media});
 -         if (SDPUtil.find_line(this.media[i], 'a=mid:')) {
 -             // prefer identifier from a=mid if present
 -             var mid = SDPUtil.parse_mid(SDPUtil.find_line(this.media[i], 'a=mid:'));
 -             elem.attrs({ name: mid });
 -         }
 - 
 -         if (SDPUtil.find_line(this.media[i], 'a=rtpmap:').length)
 -         {
 -             elem.c('description',
 -                 {xmlns: 'urn:xmpp:jingle:apps:rtp:1',
 -                     media: mline.media });
 -             if (ssrc) {
 -                 elem.attrs({ssrc: ssrc});
 -             }
 -             for (j = 0; j < mline.fmt.length; j++) {
 -                 rtpmap = SDPUtil.find_line(this.media[i], 'a=rtpmap:' + mline.fmt[j]);
 -                 elem.c('payload-type', SDPUtil.parse_rtpmap(rtpmap));
 -                 // put any 'a=fmtp:' + mline.fmt[j] lines into <param name=foo value=bar/>
 -                 if (SDPUtil.find_line(this.media[i], 'a=fmtp:' + mline.fmt[j])) {
 -                     tmp = SDPUtil.parse_fmtp(SDPUtil.find_line(this.media[i], 'a=fmtp:' + mline.fmt[j]));
 -                     for (k = 0; k < tmp.length; k++) {
 -                         elem.c('parameter', tmp[k]).up();
 -                     }
 -                 }
 -                 this.RtcpFbToJingle(i, elem, mline.fmt[j]); // XEP-0293 -- map a=rtcp-fb
 - 
 -                 elem.up();
 -             }
 -             if (SDPUtil.find_line(this.media[i], 'a=crypto:', this.session)) {
 -                 elem.c('encryption', {required: 1});
 -                 var crypto = SDPUtil.find_lines(this.media[i], 'a=crypto:', this.session);
 -                 crypto.forEach(function(line) {
 -                     elem.c('crypto', SDPUtil.parse_crypto(line)).up();
 -                 });
 -                 elem.up(); // end of encryption
 -             }
 - 
 -             if (ssrc) {
 -                 // new style mapping
 -                 elem.c('source', { ssrc: ssrc, xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0' });
 -                 // FIXME: group by ssrc and support multiple different ssrcs
 -                 var ssrclines = SDPUtil.find_lines(this.media[i], 'a=ssrc:');
 -                 if(ssrclines.length > 0) {
 -                     ssrclines.forEach(function (line) {
 -                         idx = line.indexOf(' ');
 -                         var linessrc = line.substr(0, idx).substr(7);
 -                         if (linessrc != ssrc) {
 -                             elem.up();
 -                             ssrc = linessrc;
 -                             elem.c('source', { ssrc: ssrc, xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0' });
 -                         }
 -                         var kv = line.substr(idx + 1);
 -                         elem.c('parameter');
 -                         if (kv.indexOf(':') == -1) {
 -                             elem.attrs({ name: kv });
 -                         } else {
 -                             elem.attrs({ name: kv.split(':', 2)[0] });
 -                             elem.attrs({ value: kv.split(':', 2)[1] });
 -                         }
 -                         elem.up();
 -                     });
 -                     elem.up();
 -                 }
 -                 else
 -                 {
 -                     elem.up();
 -                     elem.c('source', { ssrc: ssrc, xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0' });
 -                     elem.c('parameter');
 -                     elem.attrs({name: "cname", value:Math.random().toString(36).substring(7)});
 -                     elem.up();
 -                     var msid = null;
 -                     if(mline.media == "audio")
 -                     {
 -                         msid = RTC.localAudio.getId();
 -                     }
 -                     else
 -                     {
 -                         msid = RTC.localVideo.getId();
 -                     }
 -                     if(msid != null)
 -                     {
 -                         msid = msid.replace(/[\{,\}]/g,"");
 -                         elem.c('parameter');
 -                         elem.attrs({name: "msid", value:msid});
 -                         elem.up();
 -                         elem.c('parameter');
 -                         elem.attrs({name: "mslabel", value:msid});
 -                         elem.up();
 -                         elem.c('parameter');
 -                         elem.attrs({name: "label", value:msid});
 -                         elem.up();
 -                         elem.up();
 -                     }
 - 
 - 
 -                 }
 - 
 -                 // XEP-0339 handle ssrc-group attributes
 -                 var ssrc_group_lines = SDPUtil.find_lines(this.media[i], 'a=ssrc-group:');
 -                 ssrc_group_lines.forEach(function(line) {
 -                     idx = line.indexOf(' ');
 -                     var semantics = line.substr(0, idx).substr(13);
 -                     var ssrcs = line.substr(14 + semantics.length).split(' ');
 -                     if (ssrcs.length != 0) {
 -                         elem.c('ssrc-group', { semantics: semantics, xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0' });
 -                         ssrcs.forEach(function(ssrc) {
 -                             elem.c('source', { ssrc: ssrc })
 -                                 .up();
 -                         });
 -                         elem.up();
 -                     }
 -                 });
 -             }
 - 
 -             if (SDPUtil.find_line(this.media[i], 'a=rtcp-mux')) {
 -                 elem.c('rtcp-mux').up();
 -             }
 - 
 -             // XEP-0293 -- map a=rtcp-fb:*
 -             this.RtcpFbToJingle(i, elem, '*');
 - 
 -             // XEP-0294
 -             if (SDPUtil.find_line(this.media[i], 'a=extmap:')) {
 -                 lines = SDPUtil.find_lines(this.media[i], 'a=extmap:');
 -                 for (j = 0; j < lines.length; j++) {
 -                     tmp = SDPUtil.parse_extmap(lines[j]);
 -                     elem.c('rtp-hdrext', { xmlns: 'urn:xmpp:jingle:apps:rtp:rtp-hdrext:0',
 -                         uri: tmp.uri,
 -                         id: tmp.value });
 -                     if (tmp.hasOwnProperty('direction')) {
 -                         switch (tmp.direction) {
 -                             case 'sendonly':
 -                                 elem.attrs({senders: 'responder'});
 -                                 break;
 -                             case 'recvonly':
 -                                 elem.attrs({senders: 'initiator'});
 -                                 break;
 -                             case 'sendrecv':
 -                                 elem.attrs({senders: 'both'});
 -                                 break;
 -                             case 'inactive':
 -                                 elem.attrs({senders: 'none'});
 -                                 break;
 -                         }
 -                     }
 -                     // TODO: handle params
 -                     elem.up();
 -                 }
 -             }
 -             elem.up(); // end of description
 -         }
 - 
 -         // map ice-ufrag/pwd, dtls fingerprint, candidates
 -         this.TransportToJingle(i, elem);
 - 
 -         if (SDPUtil.find_line(this.media[i], 'a=sendrecv', this.session)) {
 -             elem.attrs({senders: 'both'});
 -         } else if (SDPUtil.find_line(this.media[i], 'a=sendonly', this.session)) {
 -             elem.attrs({senders: 'initiator'});
 -         } else if (SDPUtil.find_line(this.media[i], 'a=recvonly', this.session)) {
 -             elem.attrs({senders: 'responder'});
 -         } else if (SDPUtil.find_line(this.media[i], 'a=inactive', this.session)) {
 -             elem.attrs({senders: 'none'});
 -         }
 -         if (mline.port == '0') {
 -             // estos hack to reject an m-line
 -             elem.attrs({senders: 'rejected'});
 -         }
 -         elem.up(); // end of content
 -     }
 -     elem.up();
 -     return elem;
 - };
 - 
 - SDP.prototype.TransportToJingle = function (mediaindex, elem) {
 -     var i = mediaindex;
 -     var tmp;
 -     var self = this;
 -     elem.c('transport');
 - 
 -     // XEP-0343 DTLS/SCTP
 -     if (SDPUtil.find_line(this.media[mediaindex], 'a=sctpmap:').length)
 -     {
 -         var sctpmap = SDPUtil.find_line(
 -             this.media[i], 'a=sctpmap:', self.session);
 -         if (sctpmap)
 -         {
 -             var sctpAttrs = SDPUtil.parse_sctpmap(sctpmap);
 -             elem.c('sctpmap',
 -                 {
 -                     xmlns: 'urn:xmpp:jingle:transports:dtls-sctp:1',
 -                     number: sctpAttrs[0], /* SCTP port */
 -                     protocol: sctpAttrs[1], /* protocol */
 -                 });
 -             // Optional stream count attribute
 -             if (sctpAttrs.length > 2)
 -                 elem.attrs({ streams: sctpAttrs[2]});
 -             elem.up();
 -         }
 -     }
 -     // XEP-0320
 -     var fingerprints = SDPUtil.find_lines(this.media[mediaindex], 'a=fingerprint:', this.session);
 -     fingerprints.forEach(function(line) {
 -         tmp = SDPUtil.parse_fingerprint(line);
 -         tmp.xmlns = 'urn:xmpp:jingle:apps:dtls:0';
 -         elem.c('fingerprint').t(tmp.fingerprint);
 -         delete tmp.fingerprint;
 -         line = SDPUtil.find_line(self.media[mediaindex], 'a=setup:', self.session);
 -         if (line) {
 -             tmp.setup = line.substr(8);
 -         }
 -         elem.attrs(tmp);
 -         elem.up(); // end of fingerprint
 -     });
 -     tmp = SDPUtil.iceparams(this.media[mediaindex], this.session);
 -     if (tmp) {
 -         tmp.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
 -         elem.attrs(tmp);
 -         // XEP-0176
 -         if (SDPUtil.find_line(this.media[mediaindex], 'a=candidate:', this.session)) { // add any a=candidate lines
 -             var lines = SDPUtil.find_lines(this.media[mediaindex], 'a=candidate:', this.session);
 -             lines.forEach(function (line) {
 -                 elem.c('candidate', SDPUtil.candidateToJingle(line)).up();
 -             });
 -         }
 -     }
 -     elem.up(); // end of transport
 - }
 - 
 - SDP.prototype.RtcpFbToJingle = function (mediaindex, elem, payloadtype) { // XEP-0293
 -     var lines = SDPUtil.find_lines(this.media[mediaindex], 'a=rtcp-fb:' + payloadtype);
 -     lines.forEach(function (line) {
 -         var tmp = SDPUtil.parse_rtcpfb(line);
 -         if (tmp.type == 'trr-int') {
 -             elem.c('rtcp-fb-trr-int', {xmlns: 'urn:xmpp:jingle:apps:rtp:rtcp-fb:0', value: tmp.params[0]});
 -             elem.up();
 -         } else {
 -             elem.c('rtcp-fb', {xmlns: 'urn:xmpp:jingle:apps:rtp:rtcp-fb:0', type: tmp.type});
 -             if (tmp.params.length > 0) {
 -                 elem.attrs({'subtype': tmp.params[0]});
 -             }
 -             elem.up();
 -         }
 -     });
 - };
 - 
 - SDP.prototype.RtcpFbFromJingle = function (elem, payloadtype) { // XEP-0293
 -     var media = '';
 -     var tmp = elem.find('>rtcp-fb-trr-int[xmlns="urn:xmpp:jingle:apps:rtp:rtcp-fb:0"]');
 -     if (tmp.length) {
 -         media += 'a=rtcp-fb:' + '*' + ' ' + 'trr-int' + ' ';
 -         if (tmp.attr('value')) {
 -             media += tmp.attr('value');
 -         } else {
 -             media += '0';
 -         }
 -         media += '\r\n';
 -     }
 -     tmp = elem.find('>rtcp-fb[xmlns="urn:xmpp:jingle:apps:rtp:rtcp-fb:0"]');
 -     tmp.each(function () {
 -         media += 'a=rtcp-fb:' + payloadtype + ' ' + $(this).attr('type');
 -         if ($(this).attr('subtype')) {
 -             media += ' ' + $(this).attr('subtype');
 -         }
 -         media += '\r\n';
 -     });
 -     return media;
 - };
 - 
 - // construct an SDP from a jingle stanza
 - SDP.prototype.fromJingle = function (jingle) {
 -     var self = this;
 -     this.raw = 'v=0\r\n' +
 -         'o=- ' + '1923518516' + ' 2 IN IP4 0.0.0.0\r\n' +// FIXME
 -         's=-\r\n' +
 -         't=0 0\r\n';
 -     // http://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-04#section-8
 -     if ($(jingle).find('>group[xmlns="urn:xmpp:jingle:apps:grouping:0"]').length) {
 -         $(jingle).find('>group[xmlns="urn:xmpp:jingle:apps:grouping:0"]').each(function (idx, group) {
 -             var contents = $(group).find('>content').map(function (idx, content) {
 -                 return content.getAttribute('name');
 -             }).get();
 -             if (contents.length > 0) {
 -                 self.raw += 'a=group:' + (group.getAttribute('semantics') || group.getAttribute('type')) + ' ' + contents.join(' ') + '\r\n';
 -             }
 -         });
 -     }
 - 
 -     this.session = this.raw;
 -     jingle.find('>content').each(function () {
 -         var m = self.jingle2media($(this));
 -         self.media.push(m);
 -     });
 - 
 -     // reconstruct msid-semantic -- apparently not necessary
 -     /*
 -      var msid = SDPUtil.parse_ssrc(this.raw);
 -      if (msid.hasOwnProperty('mslabel')) {
 -      this.session += "a=msid-semantic: WMS " + msid.mslabel + "\r\n";
 -      }
 -      */
 - 
 -     this.raw = this.session + this.media.join('');
 - };
 - 
 - // translate a jingle content element into an an SDP media part
 - SDP.prototype.jingle2media = function (content) {
 -     var media = '',
 -         desc = content.find('description'),
 -         ssrc = desc.attr('ssrc'),
 -         self = this,
 -         tmp;
 -     var sctp = content.find(
 -         '>transport>sctpmap[xmlns="urn:xmpp:jingle:transports:dtls-sctp:1"]');
 - 
 -     tmp = { media: desc.attr('media') };
 -     tmp.port = '1';
 -     if (content.attr('senders') == 'rejected') {
 -         // estos hack to reject an m-line.
 -         tmp.port = '0';
 -     }
 -     if (content.find('>transport>fingerprint').length || desc.find('encryption').length) {
 -         if (sctp.length)
 -             tmp.proto = 'DTLS/SCTP';
 -         else
 -             tmp.proto = 'RTP/SAVPF';
 -     } else {
 -         tmp.proto = 'RTP/AVPF';
 -     }
 -     if (!sctp.length)
 -     {
 -         tmp.fmt = desc.find('payload-type').map(
 -             function () { return this.getAttribute('id'); }).get();
 -         media += SDPUtil.build_mline(tmp) + '\r\n';
 -     }
 -     else
 -     {
 -         media += 'm=application 1 DTLS/SCTP ' + sctp.attr('number') + '\r\n';
 -         media += 'a=sctpmap:' + sctp.attr('number') +
 -             ' ' + sctp.attr('protocol');
 - 
 -         var streamCount = sctp.attr('streams');
 -         if (streamCount)
 -             media += ' ' + streamCount + '\r\n';
 -         else
 -             media += '\r\n';
 -     }
 - 
 -     media += 'c=IN IP4 0.0.0.0\r\n';
 -     if (!sctp.length)
 -         media += 'a=rtcp:1 IN IP4 0.0.0.0\r\n';
 -     tmp = content.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
 -     if (tmp.length) {
 -         if (tmp.attr('ufrag')) {
 -             media += SDPUtil.build_iceufrag(tmp.attr('ufrag')) + '\r\n';
 -         }
 -         if (tmp.attr('pwd')) {
 -             media += SDPUtil.build_icepwd(tmp.attr('pwd')) + '\r\n';
 -         }
 -         tmp.find('>fingerprint').each(function () {
 -             // FIXME: check namespace at some point
 -             media += 'a=fingerprint:' + this.getAttribute('hash');
 -             media += ' ' + $(this).text();
 -             media += '\r\n';
 -             if (this.getAttribute('setup')) {
 -                 media += 'a=setup:' + this.getAttribute('setup') + '\r\n';
 -             }
 -         });
 -     }
 -     switch (content.attr('senders')) {
 -         case 'initiator':
 -             media += 'a=sendonly\r\n';
 -             break;
 -         case 'responder':
 -             media += 'a=recvonly\r\n';
 -             break;
 -         case 'none':
 -             media += 'a=inactive\r\n';
 -             break;
 -         case 'both':
 -             media += 'a=sendrecv\r\n';
 -             break;
 -     }
 -     media += 'a=mid:' + content.attr('name') + '\r\n';
 - 
 -     // <description><rtcp-mux/></description>
 -     // see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec though
 -     // and http://mail.jabber.org/pipermail/jingle/2011-December/001761.html
 -     if (desc.find('rtcp-mux').length) {
 -         media += 'a=rtcp-mux\r\n';
 -     }
 - 
 -     if (desc.find('encryption').length) {
 -         desc.find('encryption>crypto').each(function () {
 -             media += 'a=crypto:' + this.getAttribute('tag');
 -             media += ' ' + this.getAttribute('crypto-suite');
 -             media += ' ' + this.getAttribute('key-params');
 -             if (this.getAttribute('session-params')) {
 -                 media += ' ' + this.getAttribute('session-params');
 -             }
 -             media += '\r\n';
 -         });
 -     }
 -     desc.find('payload-type').each(function () {
 -         media += SDPUtil.build_rtpmap(this) + '\r\n';
 -         if ($(this).find('>parameter').length) {
 -             media += 'a=fmtp:' + this.getAttribute('id') + ' ';
 -             media += $(this).find('parameter').map(function () { return (this.getAttribute('name') ? (this.getAttribute('name') + '=') : '') + this.getAttribute('value'); }).get().join('; ');
 -             media += '\r\n';
 -         }
 -         // xep-0293
 -         media += self.RtcpFbFromJingle($(this), this.getAttribute('id'));
 -     });
 - 
 -     // xep-0293
 -     media += self.RtcpFbFromJingle(desc, '*');
 - 
 -     // xep-0294
 -     tmp = desc.find('>rtp-hdrext[xmlns="urn:xmpp:jingle:apps:rtp:rtp-hdrext:0"]');
 -     tmp.each(function () {
 -         media += 'a=extmap:' + this.getAttribute('id') + ' ' + this.getAttribute('uri') + '\r\n';
 -     });
 - 
 -     content.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]>candidate').each(function () {
 -         media += SDPUtil.candidateFromJingle(this);
 -     });
 - 
 -     // XEP-0339 handle ssrc-group attributes
 -     tmp = content.find('description>ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]').each(function() {
 -         var semantics = this.getAttribute('semantics');
 -         var ssrcs = $(this).find('>source').map(function() {
 -             return this.getAttribute('ssrc');
 -         }).get();
 - 
 -         if (ssrcs.length != 0) {
 -             media += 'a=ssrc-group:' + semantics + ' ' + ssrcs.join(' ') + '\r\n';
 -         }
 -     });
 - 
 -     tmp = content.find('description>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
 -     tmp.each(function () {
 -         var ssrc = this.getAttribute('ssrc');
 -         $(this).find('>parameter').each(function () {
 -             media += 'a=ssrc:' + ssrc + ' ' + this.getAttribute('name');
 -             if (this.getAttribute('value') && this.getAttribute('value').length)
 -                 media += ':' + this.getAttribute('value');
 -             media += '\r\n';
 -         });
 -     });
 - 
 -     return media;
 - };
 - 
 - 
 - module.exports = SDP;
 - 
 - 
 - },{"./SDPUtil":4}],3:[function(require,module,exports){
 - function SDPDiffer(mySDP, otherSDP) {
 -     this.mySDP = mySDP;
 -     this.otherSDP = otherSDP;
 - }
 - 
 - /**
 -  * Returns map of MediaChannel that contains only media not contained in <tt>otherSdp</tt>. Mapped by channel idx.
 -  * @param otherSdp the other SDP to check ssrc with.
 -  */
 - SDPDiffer.prototype.getNewMedia = function() {
 - 
 -     // this could be useful in Array.prototype.
 -     function arrayEquals(array) {
 -         // if the other array is a falsy value, return
 -         if (!array)
 -             return false;
 - 
 -         // compare lengths - can save a lot of time
 -         if (this.length != array.length)
 -             return false;
 - 
 -         for (var i = 0, l=this.length; i < l; i++) {
 -             // Check if we have nested arrays
 -             if (this[i] instanceof Array && array[i] instanceof Array) {
 -                 // recurse into the nested arrays
 -                 if (!this[i].equals(array[i]))
 -                     return false;
 -             }
 -             else if (this[i] != array[i]) {
 -                 // Warning - two different object instances will never be equal: {x:20} != {x:20}
 -                 return false;
 -             }
 -         }
 -         return true;
 -     }
 - 
 -     var myMedias = this.mySDP.getMediaSsrcMap();
 -     var othersMedias = this.otherSDP.getMediaSsrcMap();
 -     var newMedia = {};
 -     Object.keys(othersMedias).forEach(function(othersMediaIdx) {
 -         var myMedia = myMedias[othersMediaIdx];
 -         var othersMedia = othersMedias[othersMediaIdx];
 -         if(!myMedia && othersMedia) {
 -             // Add whole channel
 -             newMedia[othersMediaIdx] = othersMedia;
 -             return;
 -         }
 -         // Look for new ssrcs accross the channel
 -         Object.keys(othersMedia.ssrcs).forEach(function(ssrc) {
 -             if(Object.keys(myMedia.ssrcs).indexOf(ssrc) === -1) {
 -                 // Allocate channel if we've found ssrc that doesn't exist in our channel
 -                 if(!newMedia[othersMediaIdx]){
 -                     newMedia[othersMediaIdx] = {
 -                         mediaindex: othersMedia.mediaindex,
 -                         mid: othersMedia.mid,
 -                         ssrcs: {},
 -                         ssrcGroups: []
 -                     };
 -                 }
 -                 newMedia[othersMediaIdx].ssrcs[ssrc] = othersMedia.ssrcs[ssrc];
 -             }
 -         });
 - 
 -         // Look for new ssrc groups across the channels
 -         othersMedia.ssrcGroups.forEach(function(otherSsrcGroup){
 - 
 -             // try to match the other ssrc-group with an ssrc-group of ours
 -             var matched = false;
 -             for (var i = 0; i < myMedia.ssrcGroups.length; i++) {
 -                 var mySsrcGroup = myMedia.ssrcGroups[i];
 -                 if (otherSsrcGroup.semantics == mySsrcGroup.semantics
 -                     && arrayEquals.apply(otherSsrcGroup.ssrcs, [mySsrcGroup.ssrcs])) {
 - 
 -                     matched = true;
 -                     break;
 -                 }
 -             }
 - 
 -             if (!matched) {
 -                 // Allocate channel if we've found an ssrc-group that doesn't
 -                 // exist in our channel
 - 
 -                 if(!newMedia[othersMediaIdx]){
 -                     newMedia[othersMediaIdx] = {
 -                         mediaindex: othersMedia.mediaindex,
 -                         mid: othersMedia.mid,
 -                         ssrcs: {},
 -                         ssrcGroups: []
 -                     };
 -                 }
 -                 newMedia[othersMediaIdx].ssrcGroups.push(otherSsrcGroup);
 -             }
 -         });
 -     });
 -     return newMedia;
 - };
 - 
 - /**
 -  * Sends SSRC update IQ.
 -  * @param sdpMediaSsrcs SSRCs map obtained from SDP.getNewMedia. Cntains SSRCs to add/remove.
 -  * @param sid session identifier that will be put into the IQ.
 -  * @param initiator initiator identifier.
 -  * @param toJid destination Jid
 -  * @param isAdd indicates if this is remove or add operation.
 -  */
 - SDPDiffer.prototype.toJingle = function(modify) {
 -     var sdpMediaSsrcs = this.getNewMedia();
 -     var self = this;
 - 
 -     // FIXME: only announce video ssrcs since we mix audio and dont need
 -     //      the audio ssrcs therefore
 -     var modified = false;
 -     Object.keys(sdpMediaSsrcs).forEach(function(mediaindex){
 -         modified = true;
 -         var media = sdpMediaSsrcs[mediaindex];
 -         modify.c('content', {name: media.mid});
 - 
 -         modify.c('description', {xmlns:'urn:xmpp:jingle:apps:rtp:1', media: media.mid});
 -         // FIXME: not completly sure this operates on blocks and / or handles different ssrcs correctly
 -         // generate sources from lines
 -         Object.keys(media.ssrcs).forEach(function(ssrcNum) {
 -             var mediaSsrc = media.ssrcs[ssrcNum];
 -             modify.c('source', { xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0' });
 -             modify.attrs({ssrc: mediaSsrc.ssrc});
 -             // iterate over ssrc lines
 -             mediaSsrc.lines.forEach(function (line) {
 -                 var idx = line.indexOf(' ');
 -                 var kv = line.substr(idx + 1);
 -                 modify.c('parameter');
 -                 if (kv.indexOf(':') == -1) {
 -                     modify.attrs({ name: kv });
 -                 } else {
 -                     modify.attrs({ name: kv.split(':', 2)[0] });
 -                     modify.attrs({ value: kv.split(':', 2)[1] });
 -                 }
 -                 modify.up(); // end of parameter
 -             });
 -             modify.up(); // end of source
 -         });
 - 
 -         // generate source groups from lines
 -         media.ssrcGroups.forEach(function(ssrcGroup) {
 -             if (ssrcGroup.ssrcs.length != 0) {
 - 
 -                 modify.c('ssrc-group', {
 -                     semantics: ssrcGroup.semantics,
 -                     xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0'
 -                 });
 - 
 -                 ssrcGroup.ssrcs.forEach(function (ssrc) {
 -                     modify.c('source', { ssrc: ssrc })
 -                         .up(); // end of source
 -                 });
 -                 modify.up(); // end of ssrc-group
 -             }
 -         });
 - 
 -         modify.up(); // end of description
 -         modify.up(); // end of content
 -     });
 - 
 -     return modified;
 - };
 - 
 - module.exports = SDPDiffer;
 - },{}],4:[function(require,module,exports){
 - SDPUtil = {
 -     iceparams: function (mediadesc, sessiondesc) {
 -         var data = null;
 -         if (SDPUtil.find_line(mediadesc, 'a=ice-ufrag:', sessiondesc) &&
 -             SDPUtil.find_line(mediadesc, 'a=ice-pwd:', sessiondesc)) {
 -             data = {
 -                 ufrag: SDPUtil.parse_iceufrag(SDPUtil.find_line(mediadesc, 'a=ice-ufrag:', sessiondesc)),
 -                 pwd: SDPUtil.parse_icepwd(SDPUtil.find_line(mediadesc, 'a=ice-pwd:', sessiondesc))
 -             };
 -         }
 -         return data;
 -     },
 -     parse_iceufrag: function (line) {
 -         return line.substring(12);
 -     },
 -     build_iceufrag: function (frag) {
 -         return 'a=ice-ufrag:' + frag;
 -     },
 -     parse_icepwd: function (line) {
 -         return line.substring(10);
 -     },
 -     build_icepwd: function (pwd) {
 -         return 'a=ice-pwd:' + pwd;
 -     },
 -     parse_mid: function (line) {
 -         return line.substring(6);
 -     },
 -     parse_mline: function (line) {
 -         var parts = line.substring(2).split(' '),
 -             data = {};
 -         data.media = parts.shift();
 -         data.port = parts.shift();
 -         data.proto = parts.shift();
 -         if (parts[parts.length - 1] === '') { // trailing whitespace
 -             parts.pop();
 -         }
 -         data.fmt = parts;
 -         return data;
 -     },
 -     build_mline: function (mline) {
 -         return 'm=' + mline.media + ' ' + mline.port + ' ' + mline.proto + ' ' + mline.fmt.join(' ');
 -     },
 -     parse_rtpmap: function (line) {
 -         var parts = line.substring(9).split(' '),
 -             data = {};
 -         data.id = parts.shift();
 -         parts = parts[0].split('/');
 -         data.name = parts.shift();
 -         data.clockrate = parts.shift();
 -         data.channels = parts.length ? parts.shift() : '1';
 -         return data;
 -     },
 -     /**
 -      * Parses SDP line "a=sctpmap:..." and extracts SCTP port from it.
 -      * @param line eg. "a=sctpmap:5000 webrtc-datachannel"
 -      * @returns [SCTP port number, protocol, streams]
 -      */
 -     parse_sctpmap: function (line)
 -     {
 -         var parts = line.substring(10).split(' ');
 -         var sctpPort = parts[0];
 -         var protocol = parts[1];
 -         // Stream count is optional
 -         var streamCount = parts.length > 2 ? parts[2] : null;
 -         return [sctpPort, protocol, streamCount];// SCTP port
 -     },
 -     build_rtpmap: function (el) {
 -         var line = 'a=rtpmap:' + el.getAttribute('id') + ' ' + el.getAttribute('name') + '/' + el.getAttribute('clockrate');
 -         if (el.getAttribute('channels') && el.getAttribute('channels') != '1') {
 -             line += '/' + el.getAttribute('channels');
 -         }
 -         return line;
 -     },
 -     parse_crypto: function (line) {
 -         var parts = line.substring(9).split(' '),
 -             data = {};
 -         data.tag = parts.shift();
 -         data['crypto-suite'] = parts.shift();
 -         data['key-params'] = parts.shift();
 -         if (parts.length) {
 -             data['session-params'] = parts.join(' ');
 -         }
 -         return data;
 -     },
 -     parse_fingerprint: function (line) { // RFC 4572
 -         var parts = line.substring(14).split(' '),
 -             data = {};
 -         data.hash = parts.shift();
 -         data.fingerprint = parts.shift();
 -         // TODO assert that fingerprint satisfies 2UHEX *(":" 2UHEX) ?
 -         return data;
 -     },
 -     parse_fmtp: function (line) {
 -         var parts = line.split(' '),
 -             i, key, value,
 -             data = [];
 -         parts.shift();
 -         parts = parts.join(' ').split(';');
 -         for (i = 0; i < parts.length; i++) {
 -             key = parts[i].split('=')[0];
 -             while (key.length && key[0] == ' ') {
 -                 key = key.substring(1);
 -             }
 -             value = parts[i].split('=')[1];
 -             if (key && value) {
 -                 data.push({name: key, value: value});
 -             } else if (key) {
 -                 // rfc 4733 (DTMF) style stuff
 -                 data.push({name: '', value: key});
 -             }
 -         }
 -         return data;
 -     },
 -     parse_icecandidate: function (line) {
 -         var candidate = {},
 -             elems = line.split(' ');
 -         candidate.foundation = elems[0].substring(12);
 -         candidate.component = elems[1];
 -         candidate.protocol = elems[2].toLowerCase();
 -         candidate.priority = elems[3];
 -         candidate.ip = elems[4];
 -         candidate.port = elems[5];
 -         // elems[6] => "typ"
 -         candidate.type = elems[7];
 -         candidate.generation = 0; // default value, may be overwritten below
 -         for (var i = 8; i < elems.length; i += 2) {
 -             switch (elems[i]) {
 -                 case 'raddr':
 -                     candidate['rel-addr'] = elems[i + 1];
 -                     break;
 -                 case 'rport':
 -                     candidate['rel-port'] = elems[i + 1];
 -                     break;
 -                 case 'generation':
 -                     candidate.generation = elems[i + 1];
 -                     break;
 -                 case 'tcptype':
 -                     candidate.tcptype = elems[i + 1];
 -                     break;
 -                 default: // TODO
 -                     console.log('parse_icecandidate not translating "' + elems[i] + '" = "' + elems[i + 1] + '"');
 -             }
 -         }
 -         candidate.network = '1';
 -         candidate.id = Math.random().toString(36).substr(2, 10); // not applicable to SDP -- FIXME: should be unique, not just random
 -         return candidate;
 -     },
 -     build_icecandidate: function (cand) {
 -         var line = ['a=candidate:' + cand.foundation, cand.component, cand.protocol, cand.priority, cand.ip, cand.port, 'typ', cand.type].join(' ');
 -         line += ' ';
 -         switch (cand.type) {
 -             case 'srflx':
 -             case 'prflx':
 -             case 'relay':
 -                 if (cand.hasOwnAttribute('rel-addr') && cand.hasOwnAttribute('rel-port')) {
 -                     line += 'raddr';
 -                     line += ' ';
 -                     line += cand['rel-addr'];
 -                     line += ' ';
 -                     line += 'rport';
 -                     line += ' ';
 -                     line += cand['rel-port'];
 -                     line += ' ';
 -                 }
 -                 break;
 -         }
 -         if (cand.hasOwnAttribute('tcptype')) {
 -             line += 'tcptype';
 -             line += ' ';
 -             line += cand.tcptype;
 -             line += ' ';
 -         }
 -         line += 'generation';
 -         line += ' ';
 -         line += cand.hasOwnAttribute('generation') ? cand.generation : '0';
 -         return line;
 -     },
 -     parse_ssrc: function (desc) {
 -         // proprietary mapping of a=ssrc lines
 -         // TODO: see "Jingle RTP Source Description" by Juberti and P. Thatcher on google docs
 -         // and parse according to that
 -         var lines = desc.split('\r\n'),
 -             data = {};
 -         for (var i = 0; i < lines.length; i++) {
 -             if (lines[i].substring(0, 7) == 'a=ssrc:') {
 -                 var idx = lines[i].indexOf(' ');
 -                 data[lines[i].substr(idx + 1).split(':', 2)[0]] = lines[i].substr(idx + 1).split(':', 2)[1];
 -             }
 -         }
 -         return data;
 -     },
 -     parse_rtcpfb: function (line) {
 -         var parts = line.substr(10).split(' ');
 -         var data = {};
 -         data.pt = parts.shift();
 -         data.type = parts.shift();
 -         data.params = parts;
 -         return data;
 -     },
 -     parse_extmap: function (line) {
 -         var parts = line.substr(9).split(' ');
 -         var data = {};
 -         data.value = parts.shift();
 -         if (data.value.indexOf('/') != -1) {
 -             data.direction = data.value.substr(data.value.indexOf('/') + 1);
 -             data.value = data.value.substr(0, data.value.indexOf('/'));
 -         } else {
 -             data.direction = 'both';
 -         }
 -         data.uri = parts.shift();
 -         data.params = parts;
 -         return data;
 -     },
 -     find_line: function (haystack, needle, sessionpart) {
 -         var lines = haystack.split('\r\n');
 -         for (var i = 0; i < lines.length; i++) {
 -             if (lines[i].substring(0, needle.length) == needle) {
 -                 return lines[i];
 -             }
 -         }
 -         if (!sessionpart) {
 -             return false;
 -         }
 -         // search session part
 -         lines = sessionpart.split('\r\n');
 -         for (var j = 0; j < lines.length; j++) {
 -             if (lines[j].substring(0, needle.length) == needle) {
 -                 return lines[j];
 -             }
 -         }
 -         return false;
 -     },
 -     find_lines: function (haystack, needle, sessionpart) {
 -         var lines = haystack.split('\r\n'),
 -             needles = [];
 -         for (var i = 0; i < lines.length; i++) {
 -             if (lines[i].substring(0, needle.length) == needle)
 -                 needles.push(lines[i]);
 -         }
 -         if (needles.length || !sessionpart) {
 -             return needles;
 -         }
 -         // search session part
 -         lines = sessionpart.split('\r\n');
 -         for (var j = 0; j < lines.length; j++) {
 -             if (lines[j].substring(0, needle.length) == needle) {
 -                 needles.push(lines[j]);
 -             }
 -         }
 -         return needles;
 -     },
 -     candidateToJingle: function (line) {
 -         // a=candidate:2979166662 1 udp 2113937151 192.168.2.100 57698 typ host generation 0
 -         //      <candidate component=... foundation=... generation=... id=... ip=... network=... port=... priority=... protocol=... type=.../>
 -         if (line.indexOf('candidate:') === 0) {
 -             line = 'a=' + line;
 -         } else if (line.substring(0, 12) != 'a=candidate:') {
 -             console.log('parseCandidate called with a line that is not a candidate line');
 -             console.log(line);
 -             return null;
 -         }
 -         if (line.substring(line.length - 2) == '\r\n') // chomp it
 -             line = line.substring(0, line.length - 2);
 -         var candidate = {},
 -             elems = line.split(' '),
 -             i;
 -         if (elems[6] != 'typ') {
 -             console.log('did not find typ in the right place');
 -             console.log(line);
 -             return null;
 -         }
 -         candidate.foundation = elems[0].substring(12);
 -         candidate.component = elems[1];
 -         candidate.protocol = elems[2].toLowerCase();
 -         candidate.priority = elems[3];
 -         candidate.ip = elems[4];
 -         candidate.port = elems[5];
 -         // elems[6] => "typ"
 -         candidate.type = elems[7];
 - 
 -         candidate.generation = '0'; // default, may be overwritten below
 -         for (i = 8; i < elems.length; i += 2) {
 -             switch (elems[i]) {
 -                 case 'raddr':
 -                     candidate['rel-addr'] = elems[i + 1];
 -                     break;
 -                 case 'rport':
 -                     candidate['rel-port'] = elems[i + 1];
 -                     break;
 -                 case 'generation':
 -                     candidate.generation = elems[i + 1];
 -                     break;
 -                 case 'tcptype':
 -                     candidate.tcptype = elems[i + 1];
 -                     break;
 -                 default: // TODO
 -                     console.log('not translating "' + elems[i] + '" = "' + elems[i + 1] + '"');
 -             }
 -         }
 -         candidate.network = '1';
 -         candidate.id = Math.random().toString(36).substr(2, 10); // not applicable to SDP -- FIXME: should be unique, not just random
 -         return candidate;
 -     },
 -     candidateFromJingle: function (cand) {
 -         var line = 'a=candidate:';
 -         line += cand.getAttribute('foundation');
 -         line += ' ';
 -         line += cand.getAttribute('component');
 -         line += ' ';
 -         line += cand.getAttribute('protocol'); //.toUpperCase(); // chrome M23 doesn't like this
 -         line += ' ';
 -         line += cand.getAttribute('priority');
 -         line += ' ';
 -         line += cand.getAttribute('ip');
 -         line += ' ';
 -         line += cand.getAttribute('port');
 -         line += ' ';
 -         line += 'typ';
 -         line += ' ' + cand.getAttribute('type');
 -         line += ' ';
 -         switch (cand.getAttribute('type')) {
 -             case 'srflx':
 -             case 'prflx':
 -             case 'relay':
 -                 if (cand.getAttribute('rel-addr') && cand.getAttribute('rel-port')) {
 -                     line += 'raddr';
 -                     line += ' ';
 -                     line += cand.getAttribute('rel-addr');
 -                     line += ' ';
 -                     line += 'rport';
 -                     line += ' ';
 -                     line += cand.getAttribute('rel-port');
 -                     line += ' ';
 -                 }
 -                 break;
 -         }
 -         if (cand.getAttribute('protocol').toLowerCase() == 'tcp') {
 -             line += 'tcptype';
 -             line += ' ';
 -             line += cand.getAttribute('tcptype');
 -             line += ' ';
 -         }
 -         line += 'generation';
 -         line += ' ';
 -         line += cand.getAttribute('generation') || '0';
 -         return line + '\r\n';
 -     }
 - };
 - module.exports = SDPUtil;
 - },{}],5:[function(require,module,exports){
 - function TraceablePeerConnection(ice_config, constraints) {
 -     var self = this;
 -     var RTCPeerconnection = navigator.mozGetUserMedia ? mozRTCPeerConnection : webkitRTCPeerConnection;
 -     this.peerconnection = new RTCPeerconnection(ice_config, constraints);
 -     this.updateLog = [];
 -     this.stats = {};
 -     this.statsinterval = null;
 -     this.maxstats = 0; // limit to 300 values, i.e. 5 minutes; set to 0 to disable
 - 
 -     // override as desired
 -     this.trace = function (what, info) {
 -         //console.warn('WTRACE', what, info);
 -         self.updateLog.push({
 -             time: new Date(),
 -             type: what,
 -             value: info || ""
 -         });
 -     };
 -     this.onicecandidate = null;
 -     this.peerconnection.onicecandidate = function (event) {
 -         self.trace('onicecandidate', JSON.stringify(event.candidate, null, ' '));
 -         if (self.onicecandidate !== null) {
 -             self.onicecandidate(event);
 -         }
 -     };
 -     this.onaddstream = null;
 -     this.peerconnection.onaddstream = function (event) {
 -         self.trace('onaddstream', event.stream.id);
 -         if (self.onaddstream !== null) {
 -             self.onaddstream(event);
 -         }
 -     };
 -     this.onremovestream = null;
 -     this.peerconnection.onremovestream = function (event) {
 -         self.trace('onremovestream', event.stream.id);
 -         if (self.onremovestream !== null) {
 -             self.onremovestream(event);
 -         }
 -     };
 -     this.onsignalingstatechange = null;
 -     this.peerconnection.onsignalingstatechange = function (event) {
 -         self.trace('onsignalingstatechange', self.signalingState);
 -         if (self.onsignalingstatechange !== null) {
 -             self.onsignalingstatechange(event);
 -         }
 -     };
 -     this.oniceconnectionstatechange = null;
 -     this.peerconnection.oniceconnectionstatechange = function (event) {
 -         self.trace('oniceconnectionstatechange', self.iceConnectionState);
 -         if (self.oniceconnectionstatechange !== null) {
 -             self.oniceconnectionstatechange(event);
 -         }
 -     };
 -     this.onnegotiationneeded = null;
 -     this.peerconnection.onnegotiationneeded = function (event) {
 -         self.trace('onnegotiationneeded');
 -         if (self.onnegotiationneeded !== null) {
 -             self.onnegotiationneeded(event);
 -         }
 -     };
 -     self.ondatachannel = null;
 -     this.peerconnection.ondatachannel = function (event) {
 -         self.trace('ondatachannel', event);
 -         if (self.ondatachannel !== null) {
 -             self.ondatachannel(event);
 -         }
 -     };
 -     if (!navigator.mozGetUserMedia && this.maxstats) {
 -         this.statsinterval = window.setInterval(function() {
 -             self.peerconnection.getStats(function(stats) {
 -                 var results = stats.result();
 -                 for (var i = 0; i < results.length; ++i) {
 -                     //console.log(results[i].type, results[i].id, results[i].names())
 -                     var now = new Date();
 -                     results[i].names().forEach(function (name) {
 -                         var id = results[i].id + '-' + name;
 -                         if (!self.stats[id]) {
 -                             self.stats[id] = {
 -                                 startTime: now,
 -                                 endTime: now,
 -                                 values: [],
 -                                 times: []
 -                             };
 -                         }
 -                         self.stats[id].values.push(results[i].stat(name));
 -                         self.stats[id].times.push(now.getTime());
 -                         if (self.stats[id].values.length > self.maxstats) {
 -                             self.stats[id].values.shift();
 -                             self.stats[id].times.shift();
 -                         }
 -                         self.stats[id].endTime = now;
 -                     });
 -                 }
 -             });
 - 
 -         }, 1000);
 -     }
 - };
 - 
 - dumpSDP = function(description) {
 -     return 'type: ' + description.type + '\r\n' + description.sdp;
 - }
 - 
 - if (TraceablePeerConnection.prototype.__defineGetter__ !== undefined) {
 -     TraceablePeerConnection.prototype.__defineGetter__('signalingState', function() { return this.peerconnection.signalingState; });
 -     TraceablePeerConnection.prototype.__defineGetter__('iceConnectionState', function() { return this.peerconnection.iceConnectionState; });
 -     TraceablePeerConnection.prototype.__defineGetter__('localDescription', function() {
 -         var publicLocalDescription = simulcast.reverseTransformLocalDescription(this.peerconnection.localDescription);
 -         return publicLocalDescription;
 -     });
 -     TraceablePeerConnection.prototype.__defineGetter__('remoteDescription', function() {
 -         var publicRemoteDescription = simulcast.reverseTransformRemoteDescription(this.peerconnection.remoteDescription);
 -         return publicRemoteDescription;
 -     });
 - }
 - 
 - TraceablePeerConnection.prototype.addStream = function (stream) {
 -     this.trace('addStream', stream.id);
 -     simulcast.resetSender();
 -     try
 -     {
 -         this.peerconnection.addStream(stream);
 -     }
 -     catch (e)
 -     {
 -         console.error(e);
 -         return;
 -     }
 - };
 - 
 - TraceablePeerConnection.prototype.removeStream = function (stream, stopStreams) {
 -     this.trace('removeStream', stream.id);
 -     simulcast.resetSender();
 -     if(stopStreams) {
 -         stream.getAudioTracks().forEach(function (track) {
 -             track.stop();
 -         });
 -         stream.getVideoTracks().forEach(function (track) {
 -             track.stop();
 -         });
 -     }
 -     this.peerconnection.removeStream(stream);
 - };
 - 
 - TraceablePeerConnection.prototype.createDataChannel = function (label, opts) {
 -     this.trace('createDataChannel', label, opts);
 -     return this.peerconnection.createDataChannel(label, opts);
 - };
 - 
 - TraceablePeerConnection.prototype.setLocalDescription = function (description, successCallback, failureCallback) {
 -     var self = this;
 -     description = simulcast.transformLocalDescription(description);
 -     this.trace('setLocalDescription', dumpSDP(description));
 -     this.peerconnection.setLocalDescription(description,
 -         function () {
 -             self.trace('setLocalDescriptionOnSuccess');
 -             successCallback();
 -         },
 -         function (err) {
 -             self.trace('setLocalDescriptionOnFailure', err);
 -             failureCallback(err);
 -         }
 -     );
 -     /*
 -      if (this.statsinterval === null && this.maxstats > 0) {
 -      // start gathering stats
 -      }
 -      */
 - };
 - 
 - TraceablePeerConnection.prototype.setRemoteDescription = function (description, successCallback, failureCallback) {
 -     var self = this;
 -     description = simulcast.transformRemoteDescription(description);
 -     this.trace('setRemoteDescription', dumpSDP(description));
 -     this.peerconnection.setRemoteDescription(description,
 -         function () {
 -             self.trace('setRemoteDescriptionOnSuccess');
 -             successCallback();
 -         },
 -         function (err) {
 -             self.trace('setRemoteDescriptionOnFailure', err);
 -             failureCallback(err);
 -         }
 -     );
 -     /*
 -      if (this.statsinterval === null && this.maxstats > 0) {
 -      // start gathering stats
 -      }
 -      */
 - };
 - 
 - TraceablePeerConnection.prototype.close = function () {
 -     this.trace('stop');
 -     if (this.statsinterval !== null) {
 -         window.clearInterval(this.statsinterval);
 -         this.statsinterval = null;
 -     }
 -     this.peerconnection.close();
 - };
 - 
 - TraceablePeerConnection.prototype.createOffer = function (successCallback, failureCallback, constraints) {
 -     var self = this;
 -     this.trace('createOffer', JSON.stringify(constraints, null, ' '));
 -     this.peerconnection.createOffer(
 -         function (offer) {
 -             self.trace('createOfferOnSuccess', dumpSDP(offer));
 -             successCallback(offer);
 -         },
 -         function(err) {
 -             self.trace('createOfferOnFailure', err);
 -             failureCallback(err);
 -         },
 -         constraints
 -     );
 - };
 - 
 - TraceablePeerConnection.prototype.createAnswer = function (successCallback, failureCallback, constraints) {
 -     var self = this;
 -     this.trace('createAnswer', JSON.stringify(constraints, null, ' '));
 -     this.peerconnection.createAnswer(
 -         function (answer) {
 -             answer = simulcast.transformAnswer(answer);
 -             self.trace('createAnswerOnSuccess', dumpSDP(answer));
 -             successCallback(answer);
 -         },
 -         function(err) {
 -             self.trace('createAnswerOnFailure', err);
 -             failureCallback(err);
 -         },
 -         constraints
 -     );
 - };
 - 
 - TraceablePeerConnection.prototype.addIceCandidate = function (candidate, successCallback, failureCallback) {
 -     var self = this;
 -     this.trace('addIceCandidate', JSON.stringify(candidate, null, ' '));
 -     this.peerconnection.addIceCandidate(candidate);
 -     /* maybe later
 -      this.peerconnection.addIceCandidate(candidate,
 -      function () {
 -      self.trace('addIceCandidateOnSuccess');
 -      successCallback();
 -      },
 -      function (err) {
 -      self.trace('addIceCandidateOnFailure', err);
 -      failureCallback(err);
 -      }
 -      );
 -      */
 - };
 - 
 - TraceablePeerConnection.prototype.getStats = function(callback, errback) {
 -     if (navigator.mozGetUserMedia) {
 -         // ignore for now...
 -         if(!errback)
 -             errback = function () {
 - 
 -             }
 -         this.peerconnection.getStats(null,callback,errback);
 -     } else {
 -         this.peerconnection.getStats(callback);
 -     }
 - };
 - 
 - module.exports = TraceablePeerConnection;
 - 
 - 
 - },{}],6:[function(require,module,exports){
 - /* global $, $iq, config, connection, UI, messageHandler,
 -  roomName, sessionTerminated, Strophe, Util */
 - /**
 -  * Contains logic responsible for enabling/disabling functionality available
 -  * only to moderator users.
 -  */
 - var connection = null;
 - var focusUserJid;
 - var getNextTimeout = Util.createExpBackoffTimer(1000);
 - var getNextErrorTimeout = Util.createExpBackoffTimer(1000);
 - // External authentication stuff
 - var externalAuthEnabled = false;
 - // Sip gateway can be enabled by configuring Jigasi host in config.js or
 - // it will be enabled automatically if focus detects the component through
 - // service discovery.
 - var sipGatewayEnabled = config.hosts.call_control !== undefined;
 - 
 - var Moderator = {
 -     isModerator: function () {
 -         return connection && connection.emuc.isModerator();
 -     },
 - 
 -     isPeerModerator: function (peerJid) {
 -         return connection &&
 -             connection.emuc.getMemberRole(peerJid) === 'moderator';
 -     },
 - 
 -     isExternalAuthEnabled: function () {
 -         return externalAuthEnabled;
 -     },
 - 
 -     isSipGatewayEnabled: function () {
 -         return sipGatewayEnabled;
 -     },
 - 
 -     setConnection: function (con) {
 -         connection = con;
 -     },
 - 
 -     init: function (xmpp) {
 -         this.xmppService = xmpp;
 -         this.onLocalRoleChange = function (from, member, pres) {
 -             UI.onModeratorStatusChanged(Moderator.isModerator());
 -         };
 -     },
 - 
 -     onMucLeft: function (jid) {
 -         console.info("Someone left is it focus ? " + jid);
 -         var resource = Strophe.getResourceFromJid(jid);
 -         if (resource === 'focus' && !this.xmppService.sessionTerminated) {
 -             console.info(
 -                 "Focus has left the room - leaving conference");
 -             //hangUp();
 -             // We'd rather reload to have everything re-initialized
 -             // FIXME: show some message before reload
 -             location.reload();
 -         }
 -     },
 -     
 -     setFocusUserJid: function (focusJid) {
 -         if (!focusUserJid) {
 -             focusUserJid = focusJid;
 -             console.info("Focus jid set to: " + focusUserJid);
 -         }
 -     },
 - 
 -     getFocusUserJid: function () {
 -         return focusUserJid;
 -     },
 - 
 -     getFocusComponent: function () {
 -         // Get focus component address
 -         var focusComponent = config.hosts.focus;
 -         // If not specified use default: 'focus.domain'
 -         if (!focusComponent) {
 -             focusComponent = 'focus.' + config.hosts.domain;
 -         }
 -         return focusComponent;
 -     },
 - 
 -     createConferenceIq: function (roomName) {
 -         // Generate create conference IQ
 -         var elem = $iq({to: Moderator.getFocusComponent(), type: 'set'});
 -         elem.c('conference', {
 -             xmlns: 'http://jitsi.org/protocol/focus',
 -             room: roomName
 -         });
 -         if (config.hosts.bridge !== undefined) {
 -             elem.c(
 -                 'property',
 -                 { name: 'bridge', value: config.hosts.bridge})
 -                 .up();
 -         }
 -         // Tell the focus we have Jigasi configured
 -         if (config.hosts.call_control !== undefined) {
 -             elem.c(
 -                 'property',
 -                 { name: 'call_control', value: config.hosts.call_control})
 -                 .up();
 -         }
 -         if (config.channelLastN !== undefined) {
 -             elem.c(
 -                 'property',
 -                 { name: 'channelLastN', value: config.channelLastN})
 -                 .up();
 -         }
 -         if (config.adaptiveLastN !== undefined) {
 -             elem.c(
 -                 'property',
 -                 { name: 'adaptiveLastN', value: config.adaptiveLastN})
 -                 .up();
 -         }
 -         if (config.adaptiveSimulcast !== undefined) {
 -             elem.c(
 -                 'property',
 -                 { name: 'adaptiveSimulcast', value: config.adaptiveSimulcast})
 -                 .up();
 -         }
 -         if (config.openSctp !== undefined) {
 -             elem.c(
 -                 'property',
 -                 { name: 'openSctp', value: config.openSctp})
 -                 .up();
 -         }
 -         if (config.enableFirefoxSupport !== undefined) {
 -             elem.c(
 -                 'property',
 -                 { name: 'enableFirefoxHacks',
 -                     value: config.enableFirefoxSupport})
 -                 .up();
 -         }
 -         elem.up();
 -         return elem;
 -     },
 - 
 -     parseConfigOptions: function (resultIq) {
 -     
 -         Moderator.setFocusUserJid(
 -             $(resultIq).find('conference').attr('focusjid'));
 -     
 -         var extAuthParam
 -             = $(resultIq).find('>conference>property[name=\'externalAuth\']');
 -         if (extAuthParam.length) {
 -             externalAuthEnabled = extAuthParam.attr('value') === 'true';
 -         }
 -     
 -         console.info("External authentication enabled: " + externalAuthEnabled);
 -     
 -         // Check if focus has auto-detected Jigasi component(this will be also
 -         // included if we have passed our host from the config)
 -         if ($(resultIq).find(
 -             '>conference>property[name=\'sipGatewayEnabled\']').length) {
 -             sipGatewayEnabled = true;
 -         }
 -     
 -         console.info("Sip gateway enabled: " + sipGatewayEnabled);
 -     },
 - 
 -     // FIXME: we need to show the fact that we're waiting for the focus
 -     // to the user(or that focus is not available)
 -     allocateConferenceFocus: function (roomName, callback) {
 -         // Try to use focus user JID from the config
 -         Moderator.setFocusUserJid(config.focusUserJid);
 -         // Send create conference IQ
 -         var iq = Moderator.createConferenceIq(roomName);
 -         var self = this;
 -         connection.sendIQ(
 -             iq,
 -             function (result) {
 -                 if ('true' === $(result).find('conference').attr('ready')) {
 -                     // Reset both timers
 -                     getNextTimeout(true);
 -                     getNextErrorTimeout(true);
 -                     // Setup config options
 -                     Moderator.parseConfigOptions(result);
 -                     // Exec callback
 -                     callback();
 -                 } else {
 -                     var waitMs = getNextTimeout();
 -                     console.info("Waiting for the focus... " + waitMs);
 -                     // Reset error timeout
 -                     getNextErrorTimeout(true);
 -                     window.setTimeout(
 -                         function () {
 -                             Moderator.allocateConferenceFocus(
 -                                 roomName, callback);
 -                         }, waitMs);
 -                 }
 -             },
 -             function (error) {
 -                 // Not authorized to create new room
 -                 if ($(error).find('>error>not-authorized').length) {
 -                     console.warn("Unauthorized to start the conference");
 -                     var toDomain
 -                         = Strophe.getDomainFromJid(error.getAttribute('to'));
 -                     if (toDomain === config.hosts.anonymousdomain) {
 -                         // we are connected with anonymous domain and
 -                         // only non anonymous users can create rooms
 -                         // we must authorize the user
 - 
 -                         self.xmppService.promptLogin();
 -                     } else {
 -                         // External authentication mode
 -                         UI.onAuthenticationRequired(function () {
 -                             Moderator.allocateConferenceFocus(
 -                                 roomName, callback);
 -                         });
 -                     }
 -                     return;
 -                 }
 -                 var waitMs = getNextErrorTimeout();
 -                 console.error("Focus error, retry after " + waitMs, error);
 -                 // Show message
 -                 UI.messageHandler.notify(
 -                     'Conference focus', 'disconnected',
 -                         Moderator.getFocusComponent() +
 -                         ' not available - retry in ' +
 -                         (waitMs / 1000) + ' sec');
 -                 // Reset response timeout
 -                 getNextTimeout(true);
 -                 window.setTimeout(
 -                     function () {
 -                         Moderator.allocateConferenceFocus(roomName, callback);
 -                     }, waitMs);
 -             }
 -         );
 -     },
 - 
 -     getAuthUrl: function (roomName, urlCallback) {
 -         var iq = $iq({to: Moderator.getFocusComponent(), type: 'get'});
 -         iq.c('auth-url', {
 -             xmlns: 'http://jitsi.org/protocol/focus',
 -             room: roomName
 -         });
 -         connection.sendIQ(
 -             iq,
 -             function (result) {
 -                 var url = $(result).find('auth-url').attr('url');
 -                 if (url) {
 -                     console.info("Got auth url: " + url);
 -                     urlCallback(url);
 -                 } else {
 -                     console.error(
 -                         "Failed to get auth url fro mthe focus", result);
 -                 }
 -             },
 -             function (error) {
 -                 console.error("Get auth url error", error);
 -             }
 -         );
 -     }
 - };
 - 
 - module.exports = Moderator;
 - 
 - 
 - 
 - 
 - },{}],7:[function(require,module,exports){
 - /* global $, $iq, config, connection, focusMucJid, messageHandler, Moderator,
 -    Toolbar, Util */
 - var Moderator = require("./moderator");
 - 
 - 
 - var recordingToken = null;
 - var recordingEnabled;
 - 
 - /**
 -  * Whether to use a jirecon component for recording, or use the videobridge
 -  * through COLIBRI.
 -  */
 - var useJirecon = (typeof config.hosts.jirecon != "undefined");
 - 
 - /**
 -  * The ID of the jirecon recording session. Jirecon generates it when we
 -  * initially start recording, and it needs to be used in subsequent requests
 -  * to jirecon.
 -  */
 - var jireconRid = null;
 - 
 - function setRecordingToken(token) {
 -     recordingToken = token;
 - }
 - 
 - function setRecording(state, token, callback, connection) {
 -     if (useJirecon){
 -         this.setRecordingJirecon(state, token, callback, connection);
 -     } else {
 -         this.setRecordingColibri(state, token, callback, connection);
 -     }
 - }
 - 
 - function setRecordingJirecon(state, token, callback, connection) {
 -     if (state == recordingEnabled){
 -         return;
 -     }
 - 
 -     var iq = $iq({to: config.hosts.jirecon, type: 'set'})
 -         .c('recording', {xmlns: 'http://jitsi.org/protocol/jirecon',
 -             action: state ? 'start' : 'stop',
 -             mucjid: connection.emuc.roomjid});
 -     if (!state){
 -         iq.attrs({rid: jireconRid});
 -     }
 - 
 -     console.log('Start recording');
 - 
 -     connection.sendIQ(
 -         iq,
 -         function (result) {
 -             // TODO wait for an IQ with the real status, since this is
 -             // provisional?
 -             jireconRid = $(result).find('recording').attr('rid');
 -             console.log('Recording ' + (state ? 'started' : 'stopped') +
 -                 '(jirecon)' + result);
 -             recordingEnabled = state;
 -             if (!state){
 -                 jireconRid = null;
 -             }
 - 
 -             callback(state);
 -         },
 -         function (error) {
 -             console.log('Failed to start recording, error: ', error);
 -             callback(recordingEnabled);
 -         });
 - }
 - 
 - // Sends a COLIBRI message which enables or disables (according to 'state')
 - // the recording on the bridge. Waits for the result IQ and calls 'callback'
 - // with the new recording state, according to the IQ.
 - function setRecordingColibri(state, token, callback, connection) {
 -     var elem = $iq({to: connection.emuc.focusMucJid, type: 'set'});
 -     elem.c('conference', {
 -         xmlns: 'http://jitsi.org/protocol/colibri'
 -     });
 -     elem.c('recording', {state: state, token: token});
 - 
 -     connection.sendIQ(elem,
 -         function (result) {
 -             console.log('Set recording "', state, '". Result:', result);
 -             var recordingElem = $(result).find('>conference>recording');
 -             var newState = ('true' === recordingElem.attr('state'));
 - 
 -             recordingEnabled = newState;
 -             callback(newState);
 -         },
 -         function (error) {
 -             console.warn(error);
 -             callback(recordingEnabled);
 -         }
 -     );
 - }
 - 
 - var Recording = {
 -     toggleRecording: function (tokenEmptyCallback,
 -                                startingCallback, startedCallback, connection) {
 -         if (!Moderator.isModerator()) {
 -             console.log(
 -                     'non-focus, or conference not yet organized:' +
 -                     ' not enabling recording');
 -             return;
 -         }
 - 
 -         // Jirecon does not (currently) support a token.
 -         if (!recordingToken && !useJirecon) {
 -             tokenEmptyCallback(function (value) {
 -                 setRecordingToken(value);
 -                 this.toggleRecording();
 -             });
 - 
 -             return;
 -         }
 - 
 -         var oldState = recordingEnabled;
 -         startingCallback(!oldState);
 -         setRecording(!oldState,
 -             recordingToken,
 -             function (state) {
 -                 console.log("New recording state: ", state);
 -                 if (state === oldState) {
 -                     // FIXME: new focus:
 -                     // this will not work when moderator changes
 -                     // during active session. Then it will assume that
 -                     // recording status has changed to true, but it might have
 -                     // been already true(and we only received actual status from
 -                     // the focus).
 -                     //
 -                     // SO we start with status null, so that it is initialized
 -                     // here and will fail only after second click, so if invalid
 -                     // token was used we have to press the button twice before
 -                     // current status will be fetched and token will be reset.
 -                     //
 -                     // Reliable way would be to return authentication error.
 -                     // Or status update when moderator connects.
 -                     // Or we have to stop recording session when current
 -                     // moderator leaves the room.
 - 
 -                     // Failed to change, reset the token because it might
 -                     // have been wrong
 -                     setRecordingToken(null);
 -                 }
 -                 startedCallback(state);
 - 
 -             },
 -             connection
 -         );
 -     }
 - 
 - }
 - 
 - module.exports = Recording;
 - },{"./moderator":6}],8:[function(require,module,exports){
 - /* jshint -W117 */
 - /* a simple MUC connection plugin
 -  * can only handle a single MUC room
 -  */
 - 
 - var bridgeIsDown = false;
 - 
 - var Moderator = require("./moderator");
 - var JingleSession = require("./JingleSession");
 - 
 - module.exports = function(XMPP, eventEmitter) {
 -     Strophe.addConnectionPlugin('emuc', {
 -         connection: null,
 -         roomjid: null,
 -         myroomjid: null,
 -         members: {},
 -         list_members: [], // so we can elect a new focus
 -         presMap: {},
 -         preziMap: {},
 -         joined: false,
 -         isOwner: false,
 -         role: null,
 -         focusMucJid: null,
 -         init: function (conn) {
 -             this.connection = conn;
 -         },
 -         initPresenceMap: function (myroomjid) {
 -             this.presMap['to'] = myroomjid;
 -             this.presMap['xns'] = 'http://jabber.org/protocol/muc';
 -         },
 -         doJoin: function (jid, password) {
 -             this.myroomjid = jid;
 - 
 -             console.info("Joined MUC as " + this.myroomjid);
 - 
 -             this.initPresenceMap(this.myroomjid);
 - 
 -             if (!this.roomjid) {
 -                 this.roomjid = Strophe.getBareJidFromJid(jid);
 -                 // add handlers (just once)
 -                 this.connection.addHandler(this.onPresence.bind(this), null, 'presence', null, null, this.roomjid, {matchBare: true});
 -                 this.connection.addHandler(this.onPresenceUnavailable.bind(this), null, 'presence', 'unavailable', null, this.roomjid, {matchBare: true});
 -                 this.connection.addHandler(this.onPresenceError.bind(this), null, 'presence', 'error', null, this.roomjid, {matchBare: true});
 -                 this.connection.addHandler(this.onMessage.bind(this), null, 'message', null, null, this.roomjid, {matchBare: true});
 -             }
 -             if (password !== undefined) {
 -                 this.presMap['password'] = password;
 -             }
 -             this.sendPresence();
 -         },
 -         doLeave: function () {
 -             console.log("do leave", this.myroomjid);
 -             var pres = $pres({to: this.myroomjid, type: 'unavailable' });
 -             this.presMap.length = 0;
 -             this.connection.send(pres);
 -         },
 -         createNonAnonymousRoom: function () {
 -             // http://xmpp.org/extensions/xep-0045.html#createroom-reserved
 - 
 -             var getForm = $iq({type: 'get', to: this.roomjid})
 -                 .c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'})
 -                 .c('x', {xmlns: 'jabber:x:data', type: 'submit'});
 - 
 -             this.connection.sendIQ(getForm, function (form) {
 - 
 -                 if (!$(form).find(
 -                         '>query>x[xmlns="jabber:x:data"]' +
 -                         '>field[var="muc#roomconfig_whois"]').length) {
 - 
 -                     console.error('non-anonymous rooms not supported');
 -                     return;
 -                 }
 - 
 -                 var formSubmit = $iq({to: this.roomjid, type: 'set'})
 -                     .c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'});
 - 
 -                 formSubmit.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
 - 
 -                 formSubmit.c('field', {'var': 'FORM_TYPE'})
 -                     .c('value')
 -                     .t('http://jabber.org/protocol/muc#roomconfig').up().up();
 - 
 -                 formSubmit.c('field', {'var': 'muc#roomconfig_whois'})
 -                     .c('value').t('anyone').up().up();
 - 
 -                 this.connection.sendIQ(formSubmit);
 - 
 -             }, function (error) {
 -                 console.error("Error getting room configuration form");
 -             });
 -         },
 -         onPresence: function (pres) {
 -             var from = pres.getAttribute('from');
 - 
 -             // What is this for? A workaround for something?
 -             if (pres.getAttribute('type')) {
 -                 return true;
 -             }
 - 
 -             // Parse etherpad tag.
 -             var etherpad = $(pres).find('>etherpad');
 -             if (etherpad.length) {
 -                 if (config.etherpad_base && !Moderator.isModerator()) {
 -                     UI.initEtherpad(etherpad.text());
 -                 }
 -             }
 - 
 -             // Parse prezi tag.
 -             var presentation = $(pres).find('>prezi');
 -             if (presentation.length) {
 -                 var url = presentation.attr('url');
 -                 var current = presentation.find('>current').text();
 - 
 -                 console.log('presentation info received from', from, url);
 - 
 -                 if (this.preziMap[from] == null) {
 -                     this.preziMap[from] = url;
 - 
 -                     $(document).trigger('presentationadded.muc', [from, url, current]);
 -                 }
 -                 else {
 -                     $(document).trigger('gotoslide.muc', [from, url, current]);
 -                 }
 -             }
 -             else if (this.preziMap[from] != null) {
 -                 var url = this.preziMap[from];
 -                 delete this.preziMap[from];
 -                 $(document).trigger('presentationremoved.muc', [from, url]);
 -             }
 - 
 -             // Parse audio info tag.
 -             var audioMuted = $(pres).find('>audiomuted');
 -             if (audioMuted.length) {
 -                 $(document).trigger('audiomuted.muc', [from, audioMuted.text()]);
 -             }
 - 
 -             // Parse video info tag.
 -             var videoMuted = $(pres).find('>videomuted');
 -             if (videoMuted.length) {
 -                 $(document).trigger('videomuted.muc', [from, videoMuted.text()]);
 -             }
 - 
 -             var stats = $(pres).find('>stats');
 -             if (stats.length) {
 -                 var statsObj = {};
 -                 Strophe.forEachChild(stats[0], "stat", function (el) {
 -                     statsObj[el.getAttribute("name")] = el.getAttribute("value");
 -                 });
 -                 connectionquality.updateRemoteStats(from, statsObj);
 -             }
 - 
 -             // Parse status.
 -             if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="201"]').length) {
 -                 this.isOwner = true;
 -                 this.createNonAnonymousRoom();
 -             }
 - 
 -             // Parse roles.
 -             var member = {};
 -             member.show = $(pres).find('>show').text();
 -             member.status = $(pres).find('>status').text();
 -             var tmp = $(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>item');
 -             member.affiliation = tmp.attr('affiliation');
 -             member.role = tmp.attr('role');
 - 
 -             // Focus recognition
 -             member.jid = tmp.attr('jid');
 -             member.isFocus = false;
 -             if (member.jid
 -                 && member.jid.indexOf(Moderator.getFocusUserJid() + "/") == 0) {
 -                 member.isFocus = true;
 -             }
 - 
 -             var nicktag = $(pres).find('>nick[xmlns="http://jabber.org/protocol/nick"]');
 -             member.displayName = (nicktag.length > 0 ? nicktag.html() : null);
 - 
 -             if (from == this.myroomjid) {
 -                 if (member.affiliation == 'owner') this.isOwner = true;
 -                 if (this.role !== member.role) {
 -                     this.role = member.role;
 -                     if (Moderator.onLocalRoleChange)
 -                         Moderator.onLocalRoleChange(from, member, pres);
 -                     UI.onLocalRoleChange(from, member, pres);
 -                 }
 -                 if (!this.joined) {
 -                     this.joined = true;
 -                     eventEmitter.emit(XMPPEvents.MUC_JOINED, from, member);
 -                     this.list_members.push(from);
 -                 }
 -             } else if (this.members[from] === undefined) {
 -                 // new participant
 -                 this.members[from] = member;
 -                 this.list_members.push(from);
 -                 console.log('entered', from, member);
 -                 if (member.isFocus) {
 -                     this.focusMucJid = from;
 -                     console.info("Ignore focus: " + from + ", real JID: " + member.jid);
 -                 }
 -                 else {
 -                     var id = $(pres).find('>userID').text();
 -                     var email = $(pres).find('>email');
 -                     if (email.length > 0) {
 -                         id = email.text();
 -                     }
 -                     UI.onMucEntered(from, id, member.displayName);
 -                     API.triggerEvent("participantJoined", {jid: from});
 -                 }
 -             } else {
 -                 // Presence update for existing participant
 -                 // Watch role change:
 -                 if (this.members[from].role != member.role) {
 -                     this.members[from].role = member.role;
 -                     UI.onMucRoleChanged(member.role, member.displayName);
 -                 }
 -             }
 - 
 -             // Always trigger presence to update bindings
 -             $(document).trigger('presence.muc', [from, member, pres]);
 -             this.parsePresence(from, member, pres);
 - 
 -             // Trigger status message update
 -             if (member.status) {
 -                 UI.onMucPresenceStatus(from, member);
 -             }
 - 
 -             return true;
 -         },
 -         onPresenceUnavailable: function (pres) {
 -             var from = pres.getAttribute('from');
 -             // Status code 110 indicates that this notification is "self-presence".
 -             if (!$(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="110"]').length) {
 -                 delete this.members[from];
 -                 this.list_members.splice(this.list_members.indexOf(from), 1);
 -                 this.onParticipantLeft(from);
 -             }
 -             // If the status code is 110 this means we're leaving and we would like
 -             // to remove everyone else from our view, so we trigger the event.
 -             else if (this.list_members.length > 1) {
 -                 for (var i = 0; i < this.list_members.length; i++) {
 -                     var member = this.list_members[i];
 -                     delete this.members[i];
 -                     this.list_members.splice(i, 1);
 -                     this.onParticipantLeft(member);
 -                 }
 -             }
 -             if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
 -                 $(document).trigger('kicked.muc', [from]);
 -                 if (this.myroomjid === from) {
 -                     XMPP.disposeConference(false);
 -                     eventEmitter.emit(XMPPEvents.KICKED);
 -                 }
 -             }
 -             return true;
 -         },
 -         onPresenceError: function (pres) {
 -             var from = pres.getAttribute('from');
 -             if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
 -                 console.log('on password required', from);
 -                 var self = this;
 -                 UI.onPasswordReqiured(function (value) {
 -                     self.doJoin(from, value);
 -                 });
 -             } else if ($(pres).find(
 -                 '>error[type="cancel"]>not-allowed[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
 -                 var toDomain = Strophe.getDomainFromJid(pres.getAttribute('to'));
 -                 if (toDomain === config.hosts.anonymousdomain) {
 -                     // enter the room by replying with 'not-authorized'. This would
 -                     // result in reconnection from authorized domain.
 -                     // We're either missing Jicofo/Prosody config for anonymous
 -                     // domains or something is wrong.
 - //                    XMPP.promptLogin();
 -                     UI.messageHandler.openReportDialog(null,
 -                         'Oops ! We couldn`t join the conference.' +
 -                         ' There might be some problem with security' +
 -                         ' configuration. Please contact service' +
 -                         ' administrator.', pres);
 -                 } else {
 -                     console.warn('onPresError ', pres);
 -                     UI.messageHandler.openReportDialog(null,
 -                         'Oops! Something went wrong and we couldn`t connect to the conference.',
 -                         pres);
 -                 }
 -             } else {
 -                 console.warn('onPresError ', pres);
 -                 UI.messageHandler.openReportDialog(null,
 -                     'Oops! Something went wrong and we couldn`t connect to the conference.',
 -                     pres);
 -             }
 -             return true;
 -         },
 -         sendMessage: function (body, nickname) {
 -             var msg = $msg({to: this.roomjid, type: 'groupchat'});
 -             msg.c('body', body).up();
 -             if (nickname) {
 -                 msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
 -             }
 -             this.connection.send(msg);
 -             API.triggerEvent("outgoingMessage", {"message": body});
 -         },
 -         setSubject: function (subject) {
 -             var msg = $msg({to: this.roomjid, type: 'groupchat'});
 -             msg.c('subject', subject);
 -             this.connection.send(msg);
 -             console.log("topic changed to " + subject);
 -         },
 -         onMessage: function (msg) {
 -             // FIXME: this is a hack. but jingle on muc makes nickchanges hard
 -             var from = msg.getAttribute('from');
 -             var nick = $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]').text() || Strophe.getResourceFromJid(from);
 - 
 -             var txt = $(msg).find('>body').text();
 -             var type = msg.getAttribute("type");
 -             if (type == "error") {
 -                 UI.chatAddError($(msg).find('>text').text(), txt);
 -                 return true;
 -             }
 - 
 -             var subject = $(msg).find('>subject');
 -             if (subject.length) {
 -                 var subjectText = subject.text();
 -                 if (subjectText || subjectText == "") {
 -                     UI.chatSetSubject(subjectText);
 -                     console.log("Subject is changed to " + subjectText);
 -                 }
 -             }
 - 
 - 
 -             if (txt) {
 -                 console.log('chat', nick, txt);
 -                 UI.updateChatConversation(from, nick, txt);
 -                 if (from != this.myroomjid)
 -                     API.triggerEvent("incomingMessage",
 -                         {"from": from, "nick": nick, "message": txt});
 -             }
 -             return true;
 -         },
 -         lockRoom: function (key, onSuccess, onError, onNotSupported) {
 -             //http://xmpp.org/extensions/xep-0045.html#roomconfig
 -             var ob = this;
 -             this.connection.sendIQ($iq({to: this.roomjid, type: 'get'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'}),
 -                 function (res) {
 -                     if ($(res).find('>query>x[xmlns="jabber:x:data"]>field[var="muc#roomconfig_roomsecret"]').length) {
 -                         var formsubmit = $iq({to: ob.roomjid, type: 'set'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'});
 -                         formsubmit.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
 -                         formsubmit.c('field', {'var': 'FORM_TYPE'}).c('value').t('http://jabber.org/protocol/muc#roomconfig').up().up();
 -                         formsubmit.c('field', {'var': 'muc#roomconfig_roomsecret'}).c('value').t(key).up().up();
 -                         // Fixes a bug in prosody 0.9.+ https://code.google.com/p/lxmppd/issues/detail?id=373
 -                         formsubmit.c('field', {'var': 'muc#roomconfig_whois'}).c('value').t('anyone').up().up();
 -                         // FIXME: is muc#roomconfig_passwordprotectedroom required?
 -                         this.connection.sendIQ(formsubmit,
 -                             onSuccess,
 -                             onError);
 -                     } else {
 -                         onNotSupported();
 -                     }
 -                 }, onError);
 -         },
 -         kick: function (jid) {
 -             var kickIQ = $iq({to: this.roomjid, type: 'set'})
 -                 .c('query', {xmlns: 'http://jabber.org/protocol/muc#admin'})
 -                 .c('item', {nick: Strophe.getResourceFromJid(jid), role: 'none'})
 -                 .c('reason').t('You have been kicked.').up().up().up();
 - 
 -             this.connection.sendIQ(
 -                 kickIQ,
 -                 function (result) {
 -                     console.log('Kick participant with jid: ', jid, result);
 -                 },
 -                 function (error) {
 -                     console.log('Kick participant error: ', error);
 -                 });
 -         },
 -         sendPresence: function () {
 -             var pres = $pres({to: this.presMap['to'] });
 -             pres.c('x', {xmlns: this.presMap['xns']});
 - 
 -             if (this.presMap['password']) {
 -                 pres.c('password').t(this.presMap['password']).up();
 -             }
 - 
 -             pres.up();
 - 
 -             // Send XEP-0115 'c' stanza that contains our capabilities info
 -             if (this.connection.caps) {
 -                 this.connection.caps.node = config.clientNode;
 -                 pres.c('c', this.connection.caps.generateCapsAttrs()).up();
 -             }
 - 
 -             pres.c('user-agent', {xmlns: 'http://jitsi.org/jitmeet/user-agent'})
 -                 .t(navigator.userAgent).up();
 - 
 -             if (this.presMap['bridgeIsDown']) {
 -                 pres.c('bridgeIsDown').up();
 -             }
 - 
 -             if (this.presMap['email']) {
 -                 pres.c('email').t(this.presMap['email']).up();
 -             }
 - 
 -             if (this.presMap['userId']) {
 -                 pres.c('userId').t(this.presMap['userId']).up();
 -             }
 - 
 -             if (this.presMap['displayName']) {
 -                 // XEP-0172
 -                 pres.c('nick', {xmlns: 'http://jabber.org/protocol/nick'})
 -                     .t(this.presMap['displayName']).up();
 -             }
 - 
 -             if (this.presMap['audions']) {
 -                 pres.c('audiomuted', {xmlns: this.presMap['audions']})
 -                     .t(this.presMap['audiomuted']).up();
 -             }
 - 
 -             if (this.presMap['videons']) {
 -                 pres.c('videomuted', {xmlns: this.presMap['videons']})
 -                     .t(this.presMap['videomuted']).up();
 -             }
 - 
 -             if (this.presMap['statsns']) {
 -                 var stats = pres.c('stats', {xmlns: this.presMap['statsns']});
 -                 for (var stat in this.presMap["stats"])
 -                     if (this.presMap["stats"][stat] != null)
 -                         stats.c("stat", {name: stat, value: this.presMap["stats"][stat]}).up();
 -                 pres.up();
 -             }
 - 
 -             if (this.presMap['prezins']) {
 -                 pres.c('prezi',
 -                     {xmlns: this.presMap['prezins'],
 -                         'url': this.presMap['preziurl']})
 -                     .c('current').t(this.presMap['prezicurrent']).up().up();
 -             }
 - 
 -             if (this.presMap['etherpadns']) {
 -                 pres.c('etherpad', {xmlns: this.presMap['etherpadns']})
 -                     .t(this.presMap['etherpadname']).up();
 -             }
 - 
 -             if (this.presMap['medians']) {
 -                 pres.c('media', {xmlns: this.presMap['medians']});
 -                 var sourceNumber = 0;
 -                 Object.keys(this.presMap).forEach(function (key) {
 -                     if (key.indexOf('source') >= 0) {
 -                         sourceNumber++;
 -                     }
 -                 });
 -                 if (sourceNumber > 0)
 -                     for (var i = 1; i <= sourceNumber / 3; i++) {
 -                         pres.c('source',
 -                             {type: this.presMap['source' + i + '_type'],
 -                                 ssrc: this.presMap['source' + i + '_ssrc'],
 -                                 direction: this.presMap['source' + i + '_direction']
 -                                     || 'sendrecv' }
 -                         ).up();
 -                     }
 -             }
 - 
 -             pres.up();
 - //        console.debug(pres.toString());
 -             this.connection.send(pres);
 -         },
 -         addDisplayNameToPresence: function (displayName) {
 -             this.presMap['displayName'] = displayName;
 -         },
 -         addMediaToPresence: function (sourceNumber, mtype, ssrcs, direction) {
 -             if (!this.presMap['medians'])
 -                 this.presMap['medians'] = 'http://estos.de/ns/mjs';
 - 
 -             this.presMap['source' + sourceNumber + '_type'] = mtype;
 -             this.presMap['source' + sourceNumber + '_ssrc'] = ssrcs;
 -             this.presMap['source' + sourceNumber + '_direction'] = direction;
 -         },
 -         clearPresenceMedia: function () {
 -             var self = this;
 -             Object.keys(this.presMap).forEach(function (key) {
 -                 if (key.indexOf('source') != -1) {
 -                     delete self.presMap[key];
 -                 }
 -             });
 -         },
 -         addPreziToPresence: function (url, currentSlide) {
 -             this.presMap['prezins'] = 'http://jitsi.org/jitmeet/prezi';
 -             this.presMap['preziurl'] = url;
 -             this.presMap['prezicurrent'] = currentSlide;
 -         },
 -         removePreziFromPresence: function () {
 -             delete this.presMap['prezins'];
 -             delete this.presMap['preziurl'];
 -             delete this.presMap['prezicurrent'];
 -         },
 -         addCurrentSlideToPresence: function (currentSlide) {
 -             this.presMap['prezicurrent'] = currentSlide;
 -         },
 -         getPrezi: function (roomjid) {
 -             return this.preziMap[roomjid];
 -         },
 -         addEtherpadToPresence: function (etherpadName) {
 -             this.presMap['etherpadns'] = 'http://jitsi.org/jitmeet/etherpad';
 -             this.presMap['etherpadname'] = etherpadName;
 -         },
 -         addAudioInfoToPresence: function (isMuted) {
 -             this.presMap['audions'] = 'http://jitsi.org/jitmeet/audio';
 -             this.presMap['audiomuted'] = isMuted.toString();
 -         },
 -         addVideoInfoToPresence: function (isMuted) {
 -             this.presMap['videons'] = 'http://jitsi.org/jitmeet/video';
 -             this.presMap['videomuted'] = isMuted.toString();
 -         },
 -         addConnectionInfoToPresence: function (stats) {
 -             this.presMap['statsns'] = 'http://jitsi.org/jitmeet/stats';
 -             this.presMap['stats'] = stats;
 -         },
 -         findJidFromResource: function (resourceJid) {
 -             if (resourceJid &&
 -                 resourceJid === Strophe.getResourceFromJid(this.myroomjid)) {
 -                 return this.myroomjid;
 -             }
 -             var peerJid = null;
 -             Object.keys(this.members).some(function (jid) {
 -                 peerJid = jid;
 -                 return Strophe.getResourceFromJid(jid) === resourceJid;
 -             });
 -             return peerJid;
 -         },
 -         addBridgeIsDownToPresence: function () {
 -             this.presMap['bridgeIsDown'] = true;
 -         },
 -         addEmailToPresence: function (email) {
 -             this.presMap['email'] = email;
 -         },
 -         addUserIdToPresence: function (userId) {
 -             this.presMap['userId'] = userId;
 -         },
 -         isModerator: function () {
 -             return this.role === 'moderator';
 -         },
 -         getMemberRole: function (peerJid) {
 -             if (this.members[peerJid]) {
 -                 return this.members[peerJid].role;
 -             }
 -             return null;
 -         },
 -         onParticipantLeft: function (jid) {
 -             UI.onMucLeft(jid);
 - 
 -             API.triggerEvent("participantLeft", {jid: jid});
 - 
 -             this.connection.jingle.terminateByJid(jid);
 - 
 -             if (this.getPrezi(jid)) {
 -                 $(document).trigger('presentationremoved.muc',
 -                     [jid, this.getPrezi(jid)]);
 -             }
 - 
 -             Moderator.onMucLeft(jid);
 -         },
 -         parsePresence: function (from, memeber, pres) {
 -             if($(pres).find(">bridgeIsDown").length > 0 && !bridgeIsDown) {
 -                 bridgeIsDown = true;
 -                 eventEmitter.emit(XMPPEvents.BRIDGE_DOWN);
 -             }
 - 
 -             if(memeber.isFocus)
 -                 return;
 - 
 -             // Remove old ssrcs coming from the jid
 -             Object.keys(ssrc2jid).forEach(function (ssrc) {
 -                 if (ssrc2jid[ssrc] == jid) {
 -                     delete ssrc2jid[ssrc];
 -                 }
 -             });
 - 
 -             var changedStreams = [];
 -             $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
 -                 //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
 -                 var ssrcV = ssrc.getAttribute('ssrc');
 -                 ssrc2jid[ssrcV] = from;
 -                 JingleSession.notReceivedSSRCs.push(ssrcV);
 - 
 - 
 -                 var type = ssrc.getAttribute('type');
 - 
 -                 var direction = ssrc.getAttribute('direction');
 - 
 -                 changedStreams.push({type: type, direction: direction});
 - 
 -             });
 - 
 -             eventEmitter.emit(XMPPEvents.CHANGED_STREAMS, from, changedStreams);
 - 
 -             var displayName = !config.displayJids
 -                 ? memeber.displayName : Strophe.getResourceFromJid(from);
 - 
 -             if (displayName && displayName.length > 0)
 -             {
 - //                $(document).trigger('displaynamechanged',
 - //                    [jid, displayName]);
 -                 eventEmitter.emit(XMPPEvents.DISPLAY_NAME_CHANGED, from, displayName);
 -             }
 - 
 - 
 -             var id = $(pres).find('>userID').text();
 -             var email = $(pres).find('>email');
 -             if(email.length > 0) {
 -                 id = email.text();
 -             }
 - 
 -             eventEmitter.emit(XMPPEvents.USER_ID_CHANGED, from, id);
 -         }
 -     });
 - };
 - 
 - 
 - },{"./JingleSession":1,"./moderator":6}],9:[function(require,module,exports){
 - /* jshint -W117 */
 - 
 - var JingleSession = require("./JingleSession");
 - 
 - module.exports = function(XMPP)
 - {
 -     function CallIncomingJingle(sid, connection) {
 -         var sess = connection.jingle.sessions[sid];
 - 
 -         // TODO: do we check activecall == null?
 -         connection.jingle.activecall = sess;
 - 
 -         statistics.onConferenceCreated(sess);
 -         RTC.onConferenceCreated(sess);
 - 
 -         // TODO: check affiliation and/or role
 -         console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
 -         sess.usedrip = true; // not-so-naive trickle ice
 -         sess.sendAnswer();
 -         sess.accept();
 - 
 -     };
 - 
 -     Strophe.addConnectionPlugin('jingle', {
 -         connection: null,
 -         sessions: {},
 -         jid2session: {},
 -         ice_config: {iceServers: []},
 -         pc_constraints: {},
 -         activecall: null,
 -         media_constraints: {
 -             mandatory: {
 -                 'OfferToReceiveAudio': true,
 -                 'OfferToReceiveVideo': true
 -             }
 -             // MozDontOfferDataChannel: true when this is firefox
 -         },
 -         init: function (conn) {
 -             this.connection = conn;
 -             if (this.connection.disco) {
 -                 // http://xmpp.org/extensions/xep-0167.html#support
 -                 // http://xmpp.org/extensions/xep-0176.html#support
 -                 this.connection.disco.addFeature('urn:xmpp:jingle:1');
 -                 this.connection.disco.addFeature('urn:xmpp:jingle:apps:rtp:1');
 -                 this.connection.disco.addFeature('urn:xmpp:jingle:transports:ice-udp:1');
 -                 this.connection.disco.addFeature('urn:xmpp:jingle:transports:dtls-sctp:1');
 -                 this.connection.disco.addFeature('urn:xmpp:jingle:apps:rtp:audio');
 -                 this.connection.disco.addFeature('urn:xmpp:jingle:apps:rtp:video');
 - 
 - 
 -                 // this is dealt with by SDP O/A so we don't need to annouce this
 -                 //this.connection.disco.addFeature('urn:xmpp:jingle:apps:rtp:rtcp-fb:0'); // XEP-0293
 -                 //this.connection.disco.addFeature('urn:xmpp:jingle:apps:rtp:rtp-hdrext:0'); // XEP-0294
 -                 if (config.useRtcpMux) {
 -                     this.connection.disco.addFeature('urn:ietf:rfc:5761'); // rtcp-mux
 -                 }
 -                 if (config.useBundle) {
 -                     this.connection.disco.addFeature('urn:ietf:rfc:5888'); // a=group, e.g. bundle
 -                 }
 -                 //this.connection.disco.addFeature('urn:ietf:rfc:5576'); // a=ssrc
 -             }
 -             this.connection.addHandler(this.onJingle.bind(this), 'urn:xmpp:jingle:1', 'iq', 'set', null, null);
 -         },
 -         onJingle: function (iq) {
 -             var sid = $(iq).find('jingle').attr('sid');
 -             var action = $(iq).find('jingle').attr('action');
 -             var fromJid = iq.getAttribute('from');
 -             // send ack first
 -             var ack = $iq({type: 'result',
 -                 to: fromJid,
 -                 id: iq.getAttribute('id')
 -             });
 -             console.log('on jingle ' + action + ' from ' + fromJid, iq);
 -             var sess = this.sessions[sid];
 -             if ('session-initiate' != action) {
 -                 if (sess === null) {
 -                     ack.type = 'error';
 -                     ack.c('error', {type: 'cancel'})
 -                         .c('item-not-found', {xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas'}).up()
 -                         .c('unknown-session', {xmlns: 'urn:xmpp:jingle:errors:1'});
 -                     this.connection.send(ack);
 -                     return true;
 -                 }
 -                 // compare from to sess.peerjid (bare jid comparison for later compat with message-mode)
 -                 // local jid is not checked
 -                 if (Strophe.getBareJidFromJid(fromJid) != Strophe.getBareJidFromJid(sess.peerjid)) {
 -                     console.warn('jid mismatch for session id', sid, fromJid, sess.peerjid);
 -                     ack.type = 'error';
 -                     ack.c('error', {type: 'cancel'})
 -                         .c('item-not-found', {xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas'}).up()
 -                         .c('unknown-session', {xmlns: 'urn:xmpp:jingle:errors:1'});
 -                     this.connection.send(ack);
 -                     return true;
 -                 }
 -             } else if (sess !== undefined) {
 -                 // existing session with same session id
 -                 // this might be out-of-order if the sess.peerjid is the same as from
 -                 ack.type = 'error';
 -                 ack.c('error', {type: 'cancel'})
 -                     .c('service-unavailable', {xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas'}).up();
 -                 console.warn('duplicate session id', sid);
 -                 this.connection.send(ack);
 -                 return true;
 -             }
 -             // FIXME: check for a defined action
 -             this.connection.send(ack);
 -             // see http://xmpp.org/extensions/xep-0166.html#concepts-session
 -             switch (action) {
 -                 case 'session-initiate':
 -                     sess = new JingleSession(
 -                         $(iq).attr('to'), $(iq).find('jingle').attr('sid'),
 -                         this.connection, XMPP);
 -                     // configure session
 - 
 -                     sess.media_constraints = this.media_constraints;
 -                     sess.pc_constraints = this.pc_constraints;
 -                     sess.ice_config = this.ice_config;
 - 
 -                     sess.initiate(fromJid, false);
 -                     // FIXME: setRemoteDescription should only be done when this call is to be accepted
 -                     sess.setRemoteDescription($(iq).find('>jingle'), 'offer');
 - 
 -                     this.sessions[sess.sid] = sess;
 -                     this.jid2session[sess.peerjid] = sess;
 - 
 -                     // the callback should either
 -                     // .sendAnswer and .accept
 -                     // or .sendTerminate -- not necessarily synchronus
 -                     CallIncomingJingle(sess.sid, this.connection);
 -                     break;
 -                 case 'session-accept':
 -                     sess.setRemoteDescription($(iq).find('>jingle'), 'answer');
 -                     sess.accept();
 -                     $(document).trigger('callaccepted.jingle', [sess.sid]);
 -                     break;
 -                 case 'session-terminate':
 -                     // If this is not the focus sending the terminate, we have
 -                     // nothing more to do here.
 -                     if (Object.keys(this.sessions).length < 1
 -                         || !(this.sessions[Object.keys(this.sessions)[0]]
 -                             instanceof JingleSession))
 -                     {
 -                         break;
 -                     }
 -                     console.log('terminating...', sess.sid);
 -                     sess.terminate();
 -                     this.terminate(sess.sid);
 -                     if ($(iq).find('>jingle>reason').length) {
 -                         $(document).trigger('callterminated.jingle', [
 -                             sess.sid,
 -                             sess.peerjid,
 -                             $(iq).find('>jingle>reason>:first')[0].tagName,
 -                             $(iq).find('>jingle>reason>text').text()
 -                         ]);
 -                     } else {
 -                         $(document).trigger('callterminated.jingle',
 -                             [sess.sid, sess.peerjid]);
 -                     }
 -                     break;
 -                 case 'transport-info':
 -                     sess.addIceCandidate($(iq).find('>jingle>content'));
 -                     break;
 -                 case 'session-info':
 -                     var affected;
 -                     if ($(iq).find('>jingle>ringing[xmlns="urn:xmpp:jingle:apps:rtp:info:1"]').length) {
 -                         $(document).trigger('ringing.jingle', [sess.sid]);
 -                     } else if ($(iq).find('>jingle>mute[xmlns="urn:xmpp:jingle:apps:rtp:info:1"]').length) {
 -                         affected = $(iq).find('>jingle>mute[xmlns="urn:xmpp:jingle:apps:rtp:info:1"]').attr('name');
 -                         $(document).trigger('mute.jingle', [sess.sid, affected]);
 -                     } else if ($(iq).find('>jingle>unmute[xmlns="urn:xmpp:jingle:apps:rtp:info:1"]').length) {
 -                         affected = $(iq).find('>jingle>unmute[xmlns="urn:xmpp:jingle:apps:rtp:info:1"]').attr('name');
 -                         $(document).trigger('unmute.jingle', [sess.sid, affected]);
 -                     }
 -                     break;
 -                 case 'addsource': // FIXME: proprietary, un-jingleish
 -                 case 'source-add': // FIXME: proprietary
 -                     sess.addSource($(iq).find('>jingle>content'), fromJid);
 -                     break;
 -                 case 'removesource': // FIXME: proprietary, un-jingleish
 -                 case 'source-remove': // FIXME: proprietary
 -                     sess.removeSource($(iq).find('>jingle>content'), fromJid);
 -                     break;
 -                 default:
 -                     console.warn('jingle action not implemented', action);
 -                     break;
 -             }
 -             return true;
 -         },
 -         initiate: function (peerjid, myjid) { // initiate a new jinglesession to peerjid
 -             var sess = new JingleSession(myjid || this.connection.jid,
 -                 Math.random().toString(36).substr(2, 12), // random string
 -                 this.connection, XMPP);
 -             // configure session
 - 
 -             sess.media_constraints = this.media_constraints;
 -             sess.pc_constraints = this.pc_constraints;
 -             sess.ice_config = this.ice_config;
 - 
 -             sess.initiate(peerjid, true);
 -             this.sessions[sess.sid] = sess;
 -             this.jid2session[sess.peerjid] = sess;
 -             sess.sendOffer();
 -             return sess;
 -         },
 -         terminate: function (sid, reason, text) { // terminate by sessionid (or all sessions)
 -             if (sid === null || sid === undefined) {
 -                 for (sid in this.sessions) {
 -                     if (this.sessions[sid].state != 'ended') {
 -                         this.sessions[sid].sendTerminate(reason || (!this.sessions[sid].active()) ? 'cancel' : null, text);
 -                         this.sessions[sid].terminate();
 -                     }
 -                     delete this.jid2session[this.sessions[sid].peerjid];
 -                     delete this.sessions[sid];
 -                 }
 -             } else if (this.sessions.hasOwnProperty(sid)) {
 -                 if (this.sessions[sid].state != 'ended') {
 -                     this.sessions[sid].sendTerminate(reason || (!this.sessions[sid].active()) ? 'cancel' : null, text);
 -                     this.sessions[sid].terminate();
 -                 }
 -                 delete this.jid2session[this.sessions[sid].peerjid];
 -                 delete this.sessions[sid];
 -             }
 -         },
 -         // Used to terminate a session when an unavailable presence is received.
 -         terminateByJid: function (jid) {
 -             if (this.jid2session.hasOwnProperty(jid)) {
 -                 var sess = this.jid2session[jid];
 -                 if (sess) {
 -                     sess.terminate();
 -                     console.log('peer went away silently', jid);
 -                     delete this.sessions[sess.sid];
 -                     delete this.jid2session[jid];
 -                     $(document).trigger('callterminated.jingle',
 -                         [sess.sid, jid], 'gone');
 -                 }
 -             }
 -         },
 -         terminateRemoteByJid: function (jid, reason) {
 -             if (this.jid2session.hasOwnProperty(jid)) {
 -                 var sess = this.jid2session[jid];
 -                 if (sess) {
 -                     sess.sendTerminate(reason || (!sess.active()) ? 'kick' : null);
 -                     sess.terminate();
 -                     console.log('terminate peer with jid', sess.sid, jid);
 -                     delete this.sessions[sess.sid];
 -                     delete this.jid2session[jid];
 -                     $(document).trigger('callterminated.jingle',
 -                         [sess.sid, jid, 'kicked']);
 -                 }
 -             }
 -         },
 -         getStunAndTurnCredentials: function () {
 -             // get stun and turn configuration from server via xep-0215
 -             // uses time-limited credentials as described in
 -             // http://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
 -             //
 -             // see https://code.google.com/p/prosody-modules/source/browse/mod_turncredentials/mod_turncredentials.lua
 -             // for a prosody module which implements this
 -             //
 -             // currently, this doesn't work with updateIce and therefore credentials with a long
 -             // validity have to be fetched before creating the peerconnection
 -             // TODO: implement refresh via updateIce as described in
 -             //      https://code.google.com/p/webrtc/issues/detail?id=1650
 -             var self = this;
 -             this.connection.sendIQ(
 -                 $iq({type: 'get', to: this.connection.domain})
 -                     .c('services', {xmlns: 'urn:xmpp:extdisco:1'}).c('service', {host: 'turn.' + this.connection.domain}),
 -                 function (res) {
 -                     var iceservers = [];
 -                     $(res).find('>services>service').each(function (idx, el) {
 -                         el = $(el);
 -                         var dict = {};
 -                         var type = el.attr('type');
 -                         switch (type) {
 -                             case 'stun':
 -                                 dict.url = 'stun:' + el.attr('host');
 -                                 if (el.attr('port')) {
 -                                     dict.url += ':' + el.attr('port');
 -                                 }
 -                                 iceservers.push(dict);
 -                                 break;
 -                             case 'turn':
 -                             case 'turns':
 -                                 dict.url = type + ':';
 -                                 if (el.attr('username')) { // https://code.google.com/p/webrtc/issues/detail?id=1508
 -                                     if (navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./) && parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2], 10) < 28) {
 -                                         dict.url += el.attr('username') + '@';
 -                                     } else {
 -                                         dict.username = el.attr('username'); // only works in M28
 -                                     }
 -                                 }
 -                                 dict.url += el.attr('host');
 -                                 if (el.attr('port') && el.attr('port') != '3478') {
 -                                     dict.url += ':' + el.attr('port');
 -                                 }
 -                                 if (el.attr('transport') && el.attr('transport') != 'udp') {
 -                                     dict.url += '?transport=' + el.attr('transport');
 -                                 }
 -                                 if (el.attr('password')) {
 -                                     dict.credential = el.attr('password');
 -                                 }
 -                                 iceservers.push(dict);
 -                                 break;
 -                         }
 -                     });
 -                     self.ice_config.iceServers = iceservers;
 -                 },
 -                 function (err) {
 -                     console.warn('getting turn credentials failed', err);
 -                     console.warn('is mod_turncredentials or similar installed?');
 -                 }
 -             );
 -             // implement push?
 -         },
 - 
 -         /**
 -          * Populates the log data
 -          */
 -         populateData: function () {
 -             var data = {};
 -             Object.keys(this.sessions).forEach(function (sid) {
 -                 var session = this.sessions[sid];
 -                 if (session.peerconnection && session.peerconnection.updateLog) {
 -                     // FIXME: should probably be a .dump call
 -                     data["jingle_" + session.sid] = {
 -                         updateLog: session.peerconnection.updateLog,
 -                         stats: session.peerconnection.stats,
 -                         url: window.location.href
 -                     };
 -                 }
 -             });
 -             return data;
 -         }
 -     });
 - };
 - 
 - 
 - },{"./JingleSession":1}],10:[function(require,module,exports){
 - /* global Strophe */
 - module.exports = function () {
 - 
 -     Strophe.addConnectionPlugin('logger', {
 -         // logs raw stanzas and makes them available for download as JSON
 -         connection: null,
 -         log: [],
 -         init: function (conn) {
 -             this.connection = conn;
 -             this.connection.rawInput = this.log_incoming.bind(this);
 -             this.connection.rawOutput = this.log_outgoing.bind(this);
 -         },
 -         log_incoming: function (stanza) {
 -             this.log.push([new Date().getTime(), 'incoming', stanza]);
 -         },
 -         log_outgoing: function (stanza) {
 -             this.log.push([new Date().getTime(), 'outgoing', stanza]);
 -         }
 -     });
 - };
 - },{}],11:[function(require,module,exports){
 - /* global $, $iq, config, connection, focusMucJid, forceMuted,
 -    setAudioMuted, Strophe */
 - /**
 -  * Moderate connection plugin.
 -  */
 - module.exports = function (XMPP) {
 -     Strophe.addConnectionPlugin('moderate', {
 -         connection: null,
 -         init: function (conn) {
 -             this.connection = conn;
 - 
 -             this.connection.addHandler(this.onMute.bind(this),
 -                 'http://jitsi.org/jitmeet/audio',
 -                 'iq',
 -                 'set',
 -                 null,
 -                 null);
 -         },
 -         setMute: function (jid, mute) {
 -             console.info("set mute", mute);
 -             var iqToFocus = $iq({to: this.connection.emuc.focusMucJid, type: 'set'})
 -                 .c('mute', {
 -                     xmlns: 'http://jitsi.org/jitmeet/audio',
 -                     jid: jid
 -                 })
 -                 .t(mute.toString())
 -                 .up();
 - 
 -             this.connection.sendIQ(
 -                 iqToFocus,
 -                 function (result) {
 -                     console.log('set mute', result);
 -                 },
 -                 function (error) {
 -                     console.log('set mute error', error);
 -                 });
 -         },
 -         onMute: function (iq) {
 -             var from = iq.getAttribute('from');
 -             if (from !== this.connection.emuc.focusMucJid) {
 -                 console.warn("Ignored mute from non focus peer");
 -                 return false;
 -             }
 -             var mute = $(iq).find('mute');
 -             if (mute.length) {
 -                 var doMuteAudio = mute.text() === "true";
 -                 UI.setAudioMuted(doMuteAudio);
 -                 XMPP.forceMuted = doMuteAudio;
 -             }
 -             return true;
 -         },
 -         eject: function (jid) {
 -             // We're not the focus, so can't terminate
 -             //connection.jingle.terminateRemoteByJid(jid, 'kick');
 -             this.connection.emuc.kick(jid);
 -         }
 -     });
 - }
 - },{}],12:[function(require,module,exports){
 - /* jshint -W117 */
 - module.exports = function() {
 -     Strophe.addConnectionPlugin('rayo',
 -         {
 -             RAYO_XMLNS: 'urn:xmpp:rayo:1',
 -             connection: null,
 -             init: function (conn) {
 -                 this.connection = conn;
 -                 if (this.connection.disco) {
 -                     this.connection.disco.addFeature('urn:xmpp:rayo:client:1');
 -                 }
 - 
 -                 this.connection.addHandler(
 -                     this.onRayo.bind(this), this.RAYO_XMLNS, 'iq', 'set', null, null);
 -             },
 -             onRayo: function (iq) {
 -                 console.info("Rayo IQ", iq);
 -             },
 -             dial: function (to, from, roomName, roomPass) {
 -                 var self = this;
 -                 var req = $iq(
 -                     {
 -                         type: 'set',
 -                         to: this.connection.emuc.focusMucJid
 -                     }
 -                 );
 -                 req.c('dial',
 -                     {
 -                         xmlns: this.RAYO_XMLNS,
 -                         to: to,
 -                         from: from
 -                     });
 -                 req.c('header',
 -                     {
 -                         name: 'JvbRoomName',
 -                         value: roomName
 -                     }).up();
 - 
 -                 if (roomPass !== null && roomPass.length) {
 - 
 -                     req.c('header',
 -                         {
 -                             name: 'JvbRoomPassword',
 -                             value: roomPass
 -                         }).up();
 -                 }
 - 
 -                 this.connection.sendIQ(
 -                     req,
 -                     function (result) {
 -                         console.info('Dial result ', result);
 - 
 -                         var resource = $(result).find('ref').attr('uri');
 -                         this.call_resource = resource.substr('xmpp:'.length);
 -                         console.info(
 -                                 "Received call resource: " + this.call_resource);
 -                     },
 -                     function (error) {
 -                         console.info('Dial error ', error);
 -                     }
 -                 );
 -             },
 -             hang_up: function () {
 -                 if (!this.call_resource) {
 -                     console.warn("No call in progress");
 -                     return;
 -                 }
 - 
 -                 var self = this;
 -                 var req = $iq(
 -                     {
 -                         type: 'set',
 -                         to: this.call_resource
 -                     }
 -                 );
 -                 req.c('hangup',
 -                     {
 -                         xmlns: this.RAYO_XMLNS
 -                     });
 - 
 -                 this.connection.sendIQ(
 -                     req,
 -                     function (result) {
 -                         console.info('Hangup result ', result);
 -                         self.call_resource = null;
 -                     },
 -                     function (error) {
 -                         console.info('Hangup error ', error);
 -                         self.call_resource = null;
 -                     }
 -                 );
 -             }
 -         }
 -     );
 - };
 - 
 - },{}],13:[function(require,module,exports){
 - /**
 -  * Strophe logger implementation. Logs from level WARN and above.
 -  */
 - module.exports = function () {
 - 
 -     Strophe.log = function (level, msg) {
 -         switch (level) {
 -             case Strophe.LogLevel.WARN:
 -                 console.warn("Strophe: " + msg);
 -                 break;
 -             case Strophe.LogLevel.ERROR:
 -             case Strophe.LogLevel.FATAL:
 -                 console.error("Strophe: " + msg);
 -                 break;
 -         }
 -     };
 - 
 -     Strophe.getStatusString = function (status) {
 -         switch (status) {
 -             case Strophe.Status.ERROR:
 -                 return "ERROR";
 -             case Strophe.Status.CONNECTING:
 -                 return "CONNECTING";
 -             case Strophe.Status.CONNFAIL:
 -                 return "CONNFAIL";
 -             case Strophe.Status.AUTHENTICATING:
 -                 return "AUTHENTICATING";
 -             case Strophe.Status.AUTHFAIL:
 -                 return "AUTHFAIL";
 -             case Strophe.Status.CONNECTED:
 -                 return "CONNECTED";
 -             case Strophe.Status.DISCONNECTED:
 -                 return "DISCONNECTED";
 -             case Strophe.Status.DISCONNECTING:
 -                 return "DISCONNECTING";
 -             case Strophe.Status.ATTACHED:
 -                 return "ATTACHED";
 -             default:
 -                 return "unknown";
 -         }
 -     };
 - };
 - 
 - },{}],14:[function(require,module,exports){
 - var Moderator = require("./moderator");
 - var EventEmitter = require("events");
 - var Recording = require("./recording");
 - var SDP = require("./SDP");
 - 
 - var eventEmitter = new EventEmitter();
 - var connection = null;
 - var authenticatedUser = false;
 - 
 - function connect(jid, password, uiCredentials) {
 -     var bosh
 -         = uiCredentials.bosh || config.bosh || '/http-bind';
 -     connection = new Strophe.Connection(bosh);
 -     Moderator.setConnection(connection);
 - 
 -     var settings = UI.getSettings();
 -     var email = settings.email;
 -     var displayName = settings.displayName;
 -     if(email) {
 -         connection.emuc.addEmailToPresence(email);
 -     } else {
 -         connection.emuc.addUserIdToPresence(settings.uid);
 -     }
 -     if(displayName) {
 -         connection.emuc.addDisplayNameToPresence(displayName);
 -     }
 - 
 -     if (connection.disco) {
 -         // for chrome, add multistream cap
 -     }
 -     connection.jingle.pc_constraints = RTC.getPCConstraints();
 -     if (config.useIPv6) {
 -         // https://code.google.com/p/webrtc/issues/detail?id=2828
 -         if (!connection.jingle.pc_constraints.optional)
 -             connection.jingle.pc_constraints.optional = [];
 -         connection.jingle.pc_constraints.optional.push({googIPv6: true});
 -     }
 - 
 -     if(!password)
 -         password = uiCredentials.password;
 - 
 -     var anonymousConnectionFailed = false;
 -     connection.connect(jid, password, function (status, msg) {
 -         console.log('Strophe status changed to',
 -             Strophe.getStatusString(status));
 -         if (status === Strophe.Status.CONNECTED) {
 -             if (config.useStunTurn) {
 -                 connection.jingle.getStunAndTurnCredentials();
 -             }
 -             UI.disableConnect();
 - 
 -             console.info("My Jabber ID: " + connection.jid);
 - 
 -             if(password)
 -                 authenticatedUser = true;
 -             maybeDoJoin();
 -         } else if (status === Strophe.Status.CONNFAIL) {
 -             if(msg === 'x-strophe-bad-non-anon-jid') {
 -                 anonymousConnectionFailed = true;
 -             }
 -         } else if (status === Strophe.Status.DISCONNECTED) {
 -             if(anonymousConnectionFailed) {
 -                 // prompt user for username and password
 -                 XMPP.promptLogin();
 -             }
 -         } else if (status === Strophe.Status.AUTHFAIL) {
 -             // wrong password or username, prompt user
 -             XMPP.promptLogin();
 - 
 -         }
 -     });
 - }
 - 
 - 
 - 
 - function maybeDoJoin() {
 -     if (connection && connection.connected &&
 -         Strophe.getResourceFromJid(connection.jid)
 -         && (RTC.localAudio || RTC.localVideo)) {
 -         // .connected is true while connecting?
 -         doJoin();
 -     }
 - }
 - 
 - function doJoin() {
 -     var roomName = UI.generateRoomName();
 - 
 -     Moderator.allocateConferenceFocus(
 -         roomName, UI.checkForNicknameAndJoin);
 - }
 - 
 - function initStrophePlugins()
 - {
 -     require("./strophe.emuc")(XMPP, eventEmitter);
 -     require("./strophe.jingle")();
 -     require("./strophe.moderate")(XMPP);
 -     require("./strophe.util")();
 -     require("./strophe.rayo")();
 -     require("./strophe.logger")();
 - }
 - 
 - function registerListeners() {
 -     RTC.addStreamListener(maybeDoJoin,
 -         StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
 - }
 - 
 - function setupEvents() {
 -     $(window).bind('beforeunload', function () {
 -         if (connection && connection.connected) {
 -             // ensure signout
 -             $.ajax({
 -                 type: 'POST',
 -                 url: config.bosh,
 -                 async: false,
 -                 cache: false,
 -                 contentType: 'application/xml',
 -                 data: "<body rid='" + (connection.rid || connection._proto.rid)
 -                     + "' xmlns='http://jabber.org/protocol/httpbind' sid='"
 -                     + (connection.sid || connection._proto.sid)
 -                     + "' type='terminate'>" +
 -                     "<presence xmlns='jabber:client' type='unavailable'/>" +
 -                     "</body>",
 -                 success: function (data) {
 -                     console.log('signed out');
 -                     console.log(data);
 -                 },
 -                 error: function (XMLHttpRequest, textStatus, errorThrown) {
 -                     console.log('signout error',
 -                             textStatus + ' (' + errorThrown + ')');
 -                 }
 -             });
 -         }
 -         XMPP.disposeConference(true);
 -     });
 - }
 - 
 - var XMPP = {
 -     sessionTerminated: false,
 -     /**
 -      * Remembers if we were muted by the focus.
 -      * @type {boolean}
 -      */
 -     forceMuted: false,
 -     start: function (uiCredentials) {
 -         setupEvents();
 -         initStrophePlugins();
 -         registerListeners();
 -         Moderator.init();
 -         var configDomain = config.hosts.anonymousdomain || config.hosts.domain;
 -         // Force authenticated domain if room is appended with '?login=true'
 -         if (config.hosts.anonymousdomain &&
 -             window.location.search.indexOf("login=true") !== -1) {
 -             configDomain = config.hosts.domain;
 -         }
 -         var jid = uiCredentials.jid || configDomain || window.location.hostname;
 -         connect(jid, null, uiCredentials);
 -     },
 -     promptLogin: function () {
 -         UI.showLoginPopup(connect);
 -     },
 -     joinRooom: function(roomName, useNicks, nick)
 -     {
 -         var roomjid;
 -         roomjid = roomName;
 - 
 -         if (useNicks) {
 -             if (nick) {
 -                 roomjid += '/' + nick;
 -             } else {
 -                 roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
 -             }
 -         } else {
 - 
 -             var tmpJid = Strophe.getNodeFromJid(connection.jid);
 - 
 -             if(!authenticatedUser)
 -                 tmpJid = tmpJid.substr(0, 8);
 - 
 -             roomjid += '/' + tmpJid;
 -         }
 -         connection.emuc.doJoin(roomjid);
 -     },
 -     myJid: function () {
 -         if(!connection)
 -             return null;
 -         return connection.emuc.myroomjid;
 -     },
 -     myResource: function () {
 -         if(!connection || ! connection.emuc.myroomjid)
 -             return null;
 -         return Strophe.getResourceFromJid(connection.emuc.myroomjid);
 -     },
 -     disposeConference: function (onUnload) {
 -         eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE, onUnload);
 -         var handler = connection.jingle.activecall;
 -         if (handler && handler.peerconnection) {
 -             // FIXME: probably removing streams is not required and close() should
 -             // be enough
 -             if (RTC.localAudio) {
 -                 handler.peerconnection.removeStream(RTC.localAudio.getOriginalStream(), onUnload);
 -             }
 -             if (RTC.localVideo) {
 -                 handler.peerconnection.removeStream(RTC.localVideo.getOriginalStream(), onUnload);
 -             }
 -             handler.peerconnection.close();
 -         }
 -         connection.jingle.activecall = null;
 -         if(!onUnload)
 -         {
 -             this.sessionTerminated = true;
 -             connection.emuc.doLeave();
 -         }
 -     },
 -     addListener: function(type, listener)
 -     {
 -         eventEmitter.on(type, listener);
 -     },
 -     removeListener: function (type, listener) {
 -         eventEmitter.removeListener(type, listener);
 -     },
 -     allocateConferenceFocus: function(roomName, callback) {
 -         Moderator.allocateConferenceFocus(roomName, callback);
 -     },
 -     isModerator: function () {
 -         return Moderator.isModerator();
 -     },
 -     isSipGatewayEnabled: function () {
 -         return Moderator.isSipGatewayEnabled();
 -     },
 -     isExternalAuthEnabled: function () {
 -         return Moderator.isExternalAuthEnabled();
 -     },
 -     switchStreams: function (stream, oldStream, callback) {
 -         if (connection && connection.jingle.activecall) {
 -             // FIXME: will block switchInProgress on true value in case of exception
 -             connection.jingle.activecall.switchStreams(stream, oldStream, callback);
 -         } else {
 -             // We are done immediately
 -             console.error("No conference handler");
 -             UI.messageHandler.showError('Error',
 -                 'Unable to switch video stream.');
 -             callback();
 -         }
 -     },
 -     setVideoMute: function (mute, callback, options) {
 -        if(connection && RTC.localVideo && connection.jingle.activecall)
 -        {
 -            connection.jingle.activecall.setVideoMute(mute, callback, options);
 -        }
 -     },
 -     setAudioMute: function (mute, callback) {
 -         if (!(connection && RTC.localAudio)) {
 -             return false;
 -         }
 - 
 - 
 -         if (this.forceMuted && !mute) {
 -             console.info("Asking focus for unmute");
 -             connection.moderate.setMute(connection.emuc.myroomjid, mute);
 -             // FIXME: wait for result before resetting muted status
 -             this.forceMuted = false;
 -         }
 - 
 -         if (mute == RTC.localAudio.isMuted()) {
 -             // Nothing to do
 -             return true;
 -         }
 - 
 -         // It is not clear what is the right way to handle multiple tracks.
 -         // So at least make sure that they are all muted or all unmuted and
 -         // that we send presence just once.
 -         RTC.localAudio.mute();
 -         // isMuted is the opposite of audioEnabled
 -         connection.emuc.addAudioInfoToPresence(mute);
 -         connection.emuc.sendPresence();
 -         callback();
 -         return true;
 -     },
 -     // Really mute video, i.e. dont even send black frames
 -     muteVideo: function (pc, unmute) {
 -         // FIXME: this probably needs another of those lovely state safeguards...
 -         // which checks for iceconn == connected and sigstate == stable
 -         pc.setRemoteDescription(pc.remoteDescription,
 -             function () {
 -                 pc.createAnswer(
 -                     function (answer) {
 -                         var sdp = new SDP(answer.sdp);
 -                         if (sdp.media.length > 1) {
 -                             if (unmute)
 -                                 sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
 -                             else
 -                                 sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
 -                             sdp.raw = sdp.session + sdp.media.join('');
 -                             answer.sdp = sdp.raw;
 -                         }
 -                         pc.setLocalDescription(answer,
 -                             function () {
 -                                 console.log('mute SLD ok');
 -                             },
 -                             function (error) {
 -                                 console.log('mute SLD error');
 -                                 UI.messageHandler.showError('Error',
 -                                         'Oops! Something went wrong and we failed to ' +
 -                                         'mute! (SLD Failure)');
 -                             }
 -                         );
 -                     },
 -                     function (error) {
 -                         console.log(error);
 -                         UI.messageHandler.showError();
 -                     }
 -                 );
 -             },
 -             function (error) {
 -                 console.log('muteVideo SRD error');
 -                 UI.messageHandler.showError('Error',
 -                         'Oops! Something went wrong and we failed to stop video!' +
 -                         '(SRD Failure)');
 - 
 -             }
 -         );
 -     },
 -     toggleRecording: function (tokenEmptyCallback,
 -                                startingCallback, startedCallback) {
 -         Recording.toggleRecording(tokenEmptyCallback,
 -             startingCallback, startedCallback, connection);
 -     },
 -     addToPresence: function (name, value, dontSend) {
 -         switch (name)
 -         {
 -             case "displayName":
 -                 connection.emuc.addDisplayNameToPresence(value);
 -                 break;
 -             case "etherpad":
 -                 connection.emuc.addEtherpadToPresence(value);
 -                 break;
 -             case "prezi":
 -                 connection.emuc.addPreziToPresence(value, 0);
 -                 break;
 -             case "preziSlide":
 -                 connection.emuc.addCurrentSlideToPresence(value);
 -                 break;
 -             case "connectionQuality":
 -                 connection.emuc.addConnectionInfoToPresence(value);
 -                 break;
 -             case "email":
 -                 connection.emuc.addEmailToPresence(value);
 -             default :
 -                 console.log("Unknown tag for presence.");
 -                 return;
 -         }
 -         if(!dontSend)
 -             connection.emuc.sendPresence();
 -     },
 -     sendLogs: function (data) {
 -         if(!connection.emuc.focusMucJid)
 -             return;
 - 
 -         var deflate = true;
 - 
 -         var content = JSON.stringify(data);
 -         if (deflate) {
 -             content = String.fromCharCode.apply(null, Pako.deflateRaw(content));
 -         }
 -         content = Base64.encode(content);
 -         // XEP-0337-ish
 -         var message = $msg({to: connection.emuc.focusMucJid, type: 'normal'});
 -         message.c('log', { xmlns: 'urn:xmpp:eventlog',
 -             id: 'PeerConnectionStats'});
 -         message.c('message').t(content).up();
 -         if (deflate) {
 -             message.c('tag', {name: "deflated", value: "true"}).up();
 -         }
 -         message.up();
 - 
 -         connection.send(message);
 -     },
 -     populateData: function () {
 -         var data = {};
 -         if (connection.jingle) {
 -             data = connection.jingle.populateData();
 -         }
 -         return data;
 -     },
 -     getLogger: function () {
 -         if(connection.logger)
 -             return connection.logger.log;
 -         return null;
 -     },
 -     getPrezi: function () {
 -         return connection.emuc.getPrezi(this.myJid());
 -     },
 -     removePreziFromPresence: function () {
 -         connection.emuc.removePreziFromPresence();
 -         connection.emuc.sendPresence();
 -     },
 -     sendChatMessage: function (message, nickname) {
 -         connection.emuc.sendMessage(message, nickname);
 -     },
 -     setSubject: function (topic) {
 -         connection.emuc.setSubject(topic);
 -     },
 -     lockRoom: function (key, onSuccess, onError, onNotSupported) {
 -         connection.emuc.lockRoom(key, onSuccess, onError, onNotSupported);
 -     },
 -     dial: function (to, from, roomName,roomPass) {
 -         connection.rayo.dial(to, from, roomName,roomPass);
 -     },
 -     setMute: function (jid, mute) {
 -         connection.moderate.setMute(jid, mute);
 -     },
 -     eject: function (jid) {
 -         connection.moderate.eject(jid);
 -     },
 -     findJidFromResource: function (resource) {
 -         return connection.emuc.findJidFromResource(resource);
 -     },
 -     getMembers: function () {
 -         return connection.emuc.members;
 -     }
 - 
 - };
 - 
 - module.exports = XMPP;
 - },{"./SDP":2,"./moderator":6,"./recording":7,"./strophe.emuc":8,"./strophe.jingle":9,"./strophe.logger":10,"./strophe.moderate":11,"./strophe.rayo":12,"./strophe.util":13,"events":15}],15:[function(require,module,exports){
 - // Copyright Joyent, Inc. and other Node contributors.
 - //
 - // Permission is hereby granted, free of charge, to any person obtaining a
 - // copy of this software and associated documentation files (the
 - // "Software"), to deal in the Software without restriction, including
 - // without limitation the rights to use, copy, modify, merge, publish,
 - // distribute, sublicense, and/or sell copies of the Software, and to permit
 - // persons to whom the Software is furnished to do so, subject to the
 - // following conditions:
 - //
 - // The above copyright notice and this permission notice shall be included
 - // in all copies or substantial portions of the Software.
 - //
 - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
 - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 - // USE OR OTHER DEALINGS IN THE SOFTWARE.
 - 
 - function EventEmitter() {
 -   this._events = this._events || {};
 -   this._maxListeners = this._maxListeners || undefined;
 - }
 - module.exports = EventEmitter;
 - 
 - // Backwards-compat with node 0.10.x
 - EventEmitter.EventEmitter = EventEmitter;
 - 
 - EventEmitter.prototype._events = undefined;
 - EventEmitter.prototype._maxListeners = undefined;
 - 
 - // By default EventEmitters will print a warning if more than 10 listeners are
 - // added to it. This is a useful default which helps finding memory leaks.
 - EventEmitter.defaultMaxListeners = 10;
 - 
 - // Obviously not all Emitters should be limited to 10. This function allows
 - // that to be increased. Set to zero for unlimited.
 - EventEmitter.prototype.setMaxListeners = function(n) {
 -   if (!isNumber(n) || n < 0 || isNaN(n))
 -     throw TypeError('n must be a positive number');
 -   this._maxListeners = n;
 -   return this;
 - };
 - 
 - EventEmitter.prototype.emit = function(type) {
 -   var er, handler, len, args, i, listeners;
 - 
 -   if (!this._events)
 -     this._events = {};
 - 
 -   // If there is no 'error' event listener then throw.
 -   if (type === 'error') {
 -     if (!this._events.error ||
 -         (isObject(this._events.error) && !this._events.error.length)) {
 -       er = arguments[1];
 -       if (er instanceof Error) {
 -         throw er; // Unhandled 'error' event
 -       } else {
 -         throw TypeError('Uncaught, unspecified "error" event.');
 -       }
 -       return false;
 -     }
 -   }
 - 
 -   handler = this._events[type];
 - 
 -   if (isUndefined(handler))
 -     return false;
 - 
 -   if (isFunction(handler)) {
 -     switch (arguments.length) {
 -       // fast cases
 -       case 1:
 -         handler.call(this);
 -         break;
 -       case 2:
 -         handler.call(this, arguments[1]);
 -         break;
 -       case 3:
 -         handler.call(this, arguments[1], arguments[2]);
 -         break;
 -       // slower
 -       default:
 -         len = arguments.length;
 -         args = new Array(len - 1);
 -         for (i = 1; i < len; i++)
 -           args[i - 1] = arguments[i];
 -         handler.apply(this, args);
 -     }
 -   } else if (isObject(handler)) {
 -     len = arguments.length;
 -     args = new Array(len - 1);
 -     for (i = 1; i < len; i++)
 -       args[i - 1] = arguments[i];
 - 
 -     listeners = handler.slice();
 -     len = listeners.length;
 -     for (i = 0; i < len; i++)
 -       listeners[i].apply(this, args);
 -   }
 - 
 -   return true;
 - };
 - 
 - EventEmitter.prototype.addListener = function(type, listener) {
 -   var m;
 - 
 -   if (!isFunction(listener))
 -     throw TypeError('listener must be a function');
 - 
 -   if (!this._events)
 -     this._events = {};
 - 
 -   // To avoid recursion in the case that type === "newListener"! Before
 -   // adding it to the listeners, first emit "newListener".
 -   if (this._events.newListener)
 -     this.emit('newListener', type,
 -               isFunction(listener.listener) ?
 -               listener.listener : listener);
 - 
 -   if (!this._events[type])
 -     // Optimize the case of one listener. Don't need the extra array object.
 -     this._events[type] = listener;
 -   else if (isObject(this._events[type]))
 -     // If we've already got an array, just append.
 -     this._events[type].push(listener);
 -   else
 -     // Adding the second element, need to change to array.
 -     this._events[type] = [this._events[type], listener];
 - 
 -   // Check for listener leak
 -   if (isObject(this._events[type]) && !this._events[type].warned) {
 -     var m;
 -     if (!isUndefined(this._maxListeners)) {
 -       m = this._maxListeners;
 -     } else {
 -       m = EventEmitter.defaultMaxListeners;
 -     }
 - 
 -     if (m && m > 0 && this._events[type].length > m) {
 -       this._events[type].warned = true;
 -       console.error('(node) warning: possible EventEmitter memory ' +
 -                     'leak detected. %d listeners added. ' +
 -                     'Use emitter.setMaxListeners() to increase limit.',
 -                     this._events[type].length);
 -       if (typeof console.trace === 'function') {
 -         // not supported in IE 10
 -         console.trace();
 -       }
 -     }
 -   }
 - 
 -   return this;
 - };
 - 
 - EventEmitter.prototype.on = EventEmitter.prototype.addListener;
 - 
 - EventEmitter.prototype.once = function(type, listener) {
 -   if (!isFunction(listener))
 -     throw TypeError('listener must be a function');
 - 
 -   var fired = false;
 - 
 -   function g() {
 -     this.removeListener(type, g);
 - 
 -     if (!fired) {
 -       fired = true;
 -       listener.apply(this, arguments);
 -     }
 -   }
 - 
 -   g.listener = listener;
 -   this.on(type, g);
 - 
 -   return this;
 - };
 - 
 - // emits a 'removeListener' event iff the listener was removed
 - EventEmitter.prototype.removeListener = function(type, listener) {
 -   var list, position, length, i;
 - 
 -   if (!isFunction(listener))
 -     throw TypeError('listener must be a function');
 - 
 -   if (!this._events || !this._events[type])
 -     return this;
 - 
 -   list = this._events[type];
 -   length = list.length;
 -   position = -1;
 - 
 -   if (list === listener ||
 -       (isFunction(list.listener) && list.listener === listener)) {
 -     delete this._events[type];
 -     if (this._events.removeListener)
 -       this.emit('removeListener', type, listener);
 - 
 -   } else if (isObject(list)) {
 -     for (i = length; i-- > 0;) {
 -       if (list[i] === listener ||
 -           (list[i].listener && list[i].listener === listener)) {
 -         position = i;
 -         break;
 -       }
 -     }
 - 
 -     if (position < 0)
 -       return this;
 - 
 -     if (list.length === 1) {
 -       list.length = 0;
 -       delete this._events[type];
 -     } else {
 -       list.splice(position, 1);
 -     }
 - 
 -     if (this._events.removeListener)
 -       this.emit('removeListener', type, listener);
 -   }
 - 
 -   return this;
 - };
 - 
 - EventEmitter.prototype.removeAllListeners = function(type) {
 -   var key, listeners;
 - 
 -   if (!this._events)
 -     return this;
 - 
 -   // not listening for removeListener, no need to emit
 -   if (!this._events.removeListener) {
 -     if (arguments.length === 0)
 -       this._events = {};
 -     else if (this._events[type])
 -       delete this._events[type];
 -     return this;
 -   }
 - 
 -   // emit removeListener for all listeners on all events
 -   if (arguments.length === 0) {
 -     for (key in this._events) {
 -       if (key === 'removeListener') continue;
 -       this.removeAllListeners(key);
 -     }
 -     this.removeAllListeners('removeListener');
 -     this._events = {};
 -     return this;
 -   }
 - 
 -   listeners = this._events[type];
 - 
 -   if (isFunction(listeners)) {
 -     this.removeListener(type, listeners);
 -   } else {
 -     // LIFO order
 -     while (listeners.length)
 -       this.removeListener(type, listeners[listeners.length - 1]);
 -   }
 -   delete this._events[type];
 - 
 -   return this;
 - };
 - 
 - EventEmitter.prototype.listeners = function(type) {
 -   var ret;
 -   if (!this._events || !this._events[type])
 -     ret = [];
 -   else if (isFunction(this._events[type]))
 -     ret = [this._events[type]];
 -   else
 -     ret = this._events[type].slice();
 -   return ret;
 - };
 - 
 - EventEmitter.listenerCount = function(emitter, type) {
 -   var ret;
 -   if (!emitter._events || !emitter._events[type])
 -     ret = 0;
 -   else if (isFunction(emitter._events[type]))
 -     ret = 1;
 -   else
 -     ret = emitter._events[type].length;
 -   return ret;
 - };
 - 
 - function isFunction(arg) {
 -   return typeof arg === 'function';
 - }
 - 
 - function isNumber(arg) {
 -   return typeof arg === 'number';
 - }
 - 
 - function isObject(arg) {
 -   return typeof arg === 'object' && arg !== null;
 - }
 - 
 - function isUndefined(arg) {
 -   return arg === void 0;
 - }
 - 
 - },{}]},{},[14])(14)
 - });
 
 
  |