You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.bundle.js 223KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867
  1. !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.UI=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){
  2. var UI = {};
  3. var VideoLayout = require("./videolayout/VideoLayout.js");
  4. var AudioLevels = require("./audio_levels/AudioLevels.js");
  5. var Prezi = require("./prezi/Prezi.js");
  6. var Etherpad = require("./etherpad/Etherpad.js");
  7. var Chat = require("./side_pannels/chat/Chat.js");
  8. var Toolbar = require("./toolbars/toolbar");
  9. var ToolbarToggler = require("./toolbars/toolbartoggler");
  10. var BottomToolbar = require("./toolbars/BottomToolbar");
  11. var ContactList = require("./side_pannels/contactlist/ContactList");
  12. var Avatar = require("./avatar/Avatar");
  13. //var EventEmitter = require("events");
  14. var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
  15. var Settings = require("./side_pannels/settings/Settings");
  16. var PanelToggler = require("./side_pannels/SidePanelToggler");
  17. var RoomNameGenerator = require("./welcome_page/RoomnameGenerator");
  18. UI.messageHandler = require("./util/MessageHandler");
  19. var messageHandler = UI.messageHandler;
  20. var Authentication = require("./authentication/Authentication");
  21. var UIUtil = require("./util/UIUtil");
  22. //var eventEmitter = new EventEmitter();
  23. var roomName = null;
  24. function setupPrezi()
  25. {
  26. $("#reloadPresentationLink").click(function()
  27. {
  28. Prezi.reloadPresentation();
  29. });
  30. }
  31. function setupChat()
  32. {
  33. Chat.init();
  34. $("#toggle_smileys").click(function() {
  35. Chat.toggleSmileys();
  36. });
  37. }
  38. function setupToolbars() {
  39. Toolbar.init(UI);
  40. Toolbar.setupButtonsFromConfig();
  41. BottomToolbar.init();
  42. }
  43. function streamHandler(stream) {
  44. switch (stream.type)
  45. {
  46. case "audio":
  47. VideoLayout.changeLocalAudio(stream);
  48. break;
  49. case "video":
  50. VideoLayout.changeLocalVideo(stream);
  51. break;
  52. case "stream":
  53. VideoLayout.changeLocalStream(stream);
  54. break;
  55. }
  56. }
  57. function onDisposeConference(unload) {
  58. Toolbar.showAuthenticateButton(false);
  59. };
  60. function onDisplayNameChanged(jid, displayName) {
  61. ContactList.onDisplayNameChange(jid, displayName);
  62. SettingsMenu.onDisplayNameChange(jid, displayName);
  63. VideoLayout.onDisplayNameChanged(jid, displayName);
  64. }
  65. function registerListeners() {
  66. RTC.addStreamListener(streamHandler, StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
  67. RTC.addStreamListener(streamHandler, StreamEventTypes.EVENT_TYPE_LOCAL_CHANGED);
  68. RTC.addStreamListener(function (stream) {
  69. VideoLayout.onRemoteStreamAdded(stream);
  70. }, StreamEventTypes.EVENT_TYPE_REMOTE_CREATED);
  71. VideoLayout.init();
  72. statistics.addAudioLevelListener(function(jid, audioLevel)
  73. {
  74. var resourceJid;
  75. if(jid === statistics.LOCAL_JID)
  76. {
  77. resourceJid = AudioLevels.LOCAL_LEVEL;
  78. if(RTC.localAudio.isMuted())
  79. {
  80. audioLevel = 0;
  81. }
  82. }
  83. else
  84. {
  85. resourceJid = Strophe.getResourceFromJid(jid);
  86. }
  87. AudioLevels.updateAudioLevel(resourceJid, audioLevel,
  88. UI.getLargeVideoState().userResourceJid);
  89. });
  90. desktopsharing.addListener(function () {
  91. ToolbarToggler.showDesktopSharingButton();
  92. }, DesktopSharingEventTypes.INIT);
  93. desktopsharing.addListener(
  94. Toolbar.changeDesktopSharingButtonState,
  95. DesktopSharingEventTypes.SWITCHING_DONE);
  96. xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
  97. xmpp.addListener(XMPPEvents.KICKED, function () {
  98. messageHandler.openMessageDialog("Session Terminated",
  99. "Ouch! You have been kicked out of the meet!");
  100. });
  101. xmpp.addListener(XMPPEvents.BRIDGE_DOWN, function () {
  102. messageHandler.showError("Error",
  103. "Jitsi Videobridge is currently unavailable. Please try again later!");
  104. });
  105. xmpp.addListener(XMPPEvents.USER_ID_CHANGED, Avatar.setUserAvatar);
  106. xmpp.addListener(XMPPEvents.CHANGED_STREAMS, function (jid, changedStreams) {
  107. for(stream in changedStreams)
  108. {
  109. // might need to update the direction if participant just went from sendrecv to recvonly
  110. if (stream.type === 'video' || stream.type === 'screen') {
  111. var el = $('#participant_' + Strophe.getResourceFromJid(jid) + '>video');
  112. switch (stream.direction) {
  113. case 'sendrecv':
  114. el.show();
  115. break;
  116. case 'recvonly':
  117. el.hide();
  118. // FIXME: Check if we have to change large video
  119. //VideoLayout.updateLargeVideo(el);
  120. break;
  121. }
  122. }
  123. }
  124. });
  125. xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
  126. xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
  127. }
  128. function bindEvents()
  129. {
  130. /**
  131. * Resizes and repositions videos in full screen mode.
  132. */
  133. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
  134. function () {
  135. VideoLayout.resizeLargeVideoContainer();
  136. VideoLayout.positionLarge();
  137. }
  138. );
  139. $(window).resize(function () {
  140. VideoLayout.resizeLargeVideoContainer();
  141. VideoLayout.positionLarge();
  142. });
  143. }
  144. UI.start = function () {
  145. document.title = interfaceConfig.APP_NAME;
  146. if(config.enableWelcomePage && window.location.pathname == "/" &&
  147. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  148. {
  149. $("#videoconference_page").hide();
  150. var setupWelcomePage = require("./welcome_page/WelcomePage");
  151. setupWelcomePage();
  152. return;
  153. }
  154. if (interfaceConfig.SHOW_JITSI_WATERMARK) {
  155. var leftWatermarkDiv
  156. = $("#largeVideoContainer div[class='watermark leftwatermark']");
  157. leftWatermarkDiv.css({display: 'block'});
  158. leftWatermarkDiv.parent().get(0).href
  159. = interfaceConfig.JITSI_WATERMARK_LINK;
  160. }
  161. if (interfaceConfig.SHOW_BRAND_WATERMARK) {
  162. var rightWatermarkDiv
  163. = $("#largeVideoContainer div[class='watermark rightwatermark']");
  164. rightWatermarkDiv.css({display: 'block'});
  165. rightWatermarkDiv.parent().get(0).href
  166. = interfaceConfig.BRAND_WATERMARK_LINK;
  167. rightWatermarkDiv.get(0).style.backgroundImage
  168. = "url(images/rightwatermark.png)";
  169. }
  170. if (interfaceConfig.SHOW_POWERED_BY) {
  171. $("#largeVideoContainer>a[class='poweredby']").css({display: 'block'});
  172. }
  173. $("#welcome_page").hide();
  174. $('body').popover({ selector: '[data-toggle=popover]',
  175. trigger: 'click hover',
  176. content: function() {
  177. return this.getAttribute("content") +
  178. KeyboardShortcut.getShortcut(this.getAttribute("shortcut"));
  179. }
  180. });
  181. VideoLayout.resizeLargeVideoContainer();
  182. $("#videospace").mousemove(function () {
  183. return ToolbarToggler.showToolbar();
  184. });
  185. // Set the defaults for prompt dialogs.
  186. jQuery.prompt.setDefaults({persistent: false});
  187. // KeyboardShortcut.init();
  188. registerListeners();
  189. bindEvents();
  190. setupPrezi();
  191. setupToolbars();
  192. setupChat();
  193. document.title = interfaceConfig.APP_NAME;
  194. $("#downloadlog").click(function (event) {
  195. dump(event.target);
  196. });
  197. if(config.enableWelcomePage && window.location.pathname == "/" &&
  198. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  199. {
  200. $("#videoconference_page").hide();
  201. var setupWelcomePage = require("./welcome_page/WelcomePage");
  202. setupWelcomePage();
  203. return;
  204. }
  205. $("#welcome_page").hide();
  206. document.getElementById('largeVideo').volume = 0;
  207. if (!$('#settings').is(':visible')) {
  208. console.log('init');
  209. init();
  210. } else {
  211. loginInfo.onsubmit = function (e) {
  212. if (e.preventDefault) e.preventDefault();
  213. $('#settings').hide();
  214. init();
  215. };
  216. }
  217. toastr.options = {
  218. "closeButton": true,
  219. "debug": false,
  220. "positionClass": "notification-bottom-right",
  221. "onclick": null,
  222. "showDuration": "300",
  223. "hideDuration": "1000",
  224. "timeOut": "2000",
  225. "extendedTimeOut": "1000",
  226. "showEasing": "swing",
  227. "hideEasing": "linear",
  228. "showMethod": "fadeIn",
  229. "hideMethod": "fadeOut",
  230. "reposition": function() {
  231. if(PanelToggler.isVisible()) {
  232. $("#toast-container").addClass("notification-bottom-right-center");
  233. } else {
  234. $("#toast-container").removeClass("notification-bottom-right-center");
  235. }
  236. },
  237. "newestOnTop": false
  238. };
  239. $('#settingsmenu>input').keyup(function(event){
  240. if(event.keyCode === 13) {//enter
  241. SettingsMenu.update();
  242. }
  243. });
  244. $("#updateSettings").click(function () {
  245. SettingsMenu.update();
  246. });
  247. };
  248. UI.toggleSmileys = function () {
  249. Chat.toggleSmileys();
  250. };
  251. UI.chatAddError = function(errorMessage, originalText)
  252. {
  253. return Chat.chatAddError(errorMessage, originalText);
  254. };
  255. UI.chatSetSubject = function(text)
  256. {
  257. return Chat.chatSetSubject(text);
  258. };
  259. UI.updateChatConversation = function (from, displayName, message) {
  260. return Chat.updateChatConversation(from, displayName, message);
  261. };
  262. function onMucJoined(jid, info) {
  263. Toolbar.updateRoomUrl(window.location.href);
  264. document.getElementById('localNick').appendChild(
  265. document.createTextNode(Strophe.getResourceFromJid(jid) + ' (me)')
  266. );
  267. var settings = Settings.getSettings();
  268. // Add myself to the contact list.
  269. ContactList.addContact(jid, settings.email || settings.uid);
  270. // Once we've joined the muc show the toolbar
  271. ToolbarToggler.showToolbar();
  272. // Show authenticate button if needed
  273. Toolbar.showAuthenticateButton(
  274. xmpp.isExternalAuthEnabled() && !xmpp.isModerator());
  275. var displayName = !config.displayJids
  276. ? info.displayName : Strophe.getResourceFromJid(jid);
  277. if (displayName)
  278. onDisplayNameChanged('localVideoContainer', displayName + ' (me)');
  279. }
  280. UI.initEtherpad = function (name) {
  281. Etherpad.init(name);
  282. };
  283. UI.onMucLeft = function (jid) {
  284. console.log('left.muc', jid);
  285. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  286. '>.displayname').html();
  287. messageHandler.notify(displayName || 'Somebody',
  288. 'disconnected',
  289. 'disconnected');
  290. // Need to call this with a slight delay, otherwise the element couldn't be
  291. // found for some reason.
  292. // XXX(gp) it works fine without the timeout for me (with Chrome 38).
  293. window.setTimeout(function () {
  294. var container = document.getElementById(
  295. 'participant_' + Strophe.getResourceFromJid(jid));
  296. if (container) {
  297. ContactList.removeContact(jid);
  298. VideoLayout.removeConnectionIndicator(jid);
  299. // hide here, wait for video to close before removing
  300. $(container).hide();
  301. VideoLayout.resizeThumbnails();
  302. }
  303. }, 10);
  304. VideoLayout.participantLeft(jid);
  305. };
  306. UI.getSettings = function () {
  307. return Settings.getSettings();
  308. };
  309. UI.toggleFilmStrip = function () {
  310. return BottomToolbar.toggleFilmStrip();
  311. };
  312. UI.toggleChat = function () {
  313. return BottomToolbar.toggleChat();
  314. };
  315. UI.toggleContactList = function () {
  316. return BottomToolbar.toggleContactList();
  317. };
  318. UI.onLocalRoleChange = function (jid, info, pres) {
  319. console.info("My role changed, new role: " + info.role);
  320. var isModerator = xmpp.isModerator();
  321. VideoLayout.showModeratorIndicator();
  322. Toolbar.showAuthenticateButton(
  323. xmpp.isExternalAuthEnabled() && !isModerator);
  324. if (isModerator) {
  325. Authentication.closeAuthenticationWindow();
  326. messageHandler.notify(
  327. 'Me', 'connected', 'Moderator rights granted !');
  328. }
  329. };
  330. UI.onModeratorStatusChanged = function (isModerator) {
  331. Toolbar.showSipCallButton(isModerator);
  332. Toolbar.showRecordingButton(
  333. isModerator); //&&
  334. // FIXME:
  335. // Recording visible if
  336. // there are at least 2(+ 1 focus) participants
  337. //Object.keys(connection.emuc.members).length >= 3);
  338. if (isModerator && config.etherpad_base) {
  339. Etherpad.init();
  340. }
  341. };
  342. UI.onPasswordReqiured = function (callback) {
  343. // password is required
  344. Toolbar.lockLockButton();
  345. messageHandler.openTwoButtonDialog(null,
  346. '<h2>Password required</h2>' +
  347. '<input id="lockKey" type="text" placeholder="password" autofocus>',
  348. true,
  349. "Ok",
  350. function (e, v, m, f) {},
  351. function (event) {
  352. document.getElementById('lockKey').focus();
  353. },
  354. function (e, v, m, f) {
  355. if (v) {
  356. var lockKey = document.getElementById('lockKey');
  357. if (lockKey.value !== null) {
  358. Toolbar.setSharedKey(lockKey.value);
  359. callback(lockKey.value);
  360. }
  361. }
  362. }
  363. );
  364. };
  365. UI.onAuthenticationRequired = function (intervalCallback) {
  366. Authentication.openAuthenticationDialog(
  367. roomName, intervalCallback, function () {
  368. Toolbar.authenticateClicked();
  369. });
  370. };
  371. UI.setRecordingButtonState = function (state) {
  372. Toolbar.setRecordingButtonState(state);
  373. };
  374. UI.inputDisplayNameHandler = function (value) {
  375. VideoLayout.inputDisplayNameHandler(value);
  376. };
  377. UI.onMucEntered = function (jid, id, displayName) {
  378. messageHandler.notify(displayName || 'Somebody',
  379. 'connected',
  380. 'connected');
  381. // Add Peer's container
  382. VideoLayout.ensurePeerContainerExists(jid,id);
  383. };
  384. UI.onMucPresenceStatus = function ( jid, info) {
  385. VideoLayout.setPresenceStatus(
  386. 'participant_' + Strophe.getResourceFromJid(jid), info.status);
  387. };
  388. UI.onMucRoleChanged = function (role, displayName) {
  389. VideoLayout.showModeratorIndicator();
  390. if (role === 'moderator') {
  391. var displayName = displayName;
  392. if (!displayName) {
  393. displayName = 'Somebody';
  394. }
  395. messageHandler.notify(
  396. displayName,
  397. 'connected',
  398. 'Moderator rights granted to ' + displayName + '!');
  399. }
  400. };
  401. UI.updateLocalConnectionStats = function(percent, stats)
  402. {
  403. VideoLayout.updateLocalConnectionStats(percent, stats);
  404. };
  405. UI.updateConnectionStats = function(jid, percent, stats)
  406. {
  407. VideoLayout.updateConnectionStats(jid, percent, stats);
  408. };
  409. UI.onStatsStop = function () {
  410. VideoLayout.onStatsStop();
  411. };
  412. UI.getLargeVideoState = function()
  413. {
  414. return VideoLayout.getLargeVideoState();
  415. };
  416. UI.showLocalAudioIndicator = function (mute) {
  417. VideoLayout.showLocalAudioIndicator(mute);
  418. };
  419. UI.generateRoomName = function() {
  420. if(roomName)
  421. return roomName;
  422. var roomnode = null;
  423. var path = window.location.pathname;
  424. // determinde the room node from the url
  425. // TODO: just the roomnode or the whole bare jid?
  426. if (config.getroomnode && typeof config.getroomnode === 'function') {
  427. // custom function might be responsible for doing the pushstate
  428. roomnode = config.getroomnode(path);
  429. } else {
  430. /* fall back to default strategy
  431. * this is making assumptions about how the URL->room mapping happens.
  432. * It currently assumes deployment at root, with a rewrite like the
  433. * following one (for nginx):
  434. location ~ ^/([a-zA-Z0-9]+)$ {
  435. rewrite ^/(.*)$ / break;
  436. }
  437. */
  438. if (path.length > 1) {
  439. roomnode = path.substr(1).toLowerCase();
  440. } else {
  441. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  442. roomnode = word.toLowerCase();
  443. window.history.pushState('VideoChat',
  444. 'Room: ' + word, window.location.pathname + word);
  445. }
  446. }
  447. roomName = roomnode + '@' + config.hosts.muc;
  448. return roomName;
  449. };
  450. UI.connectionIndicatorShowMore = function(id)
  451. {
  452. return VideoLayout.connectionIndicators[id].showMore();
  453. };
  454. UI.showToolbar = function () {
  455. return ToolbarToggler.showToolbar();
  456. };
  457. UI.dockToolbar = function (isDock) {
  458. return ToolbarToggler.dockToolbar(isDock);
  459. };
  460. UI.getCreadentials = function () {
  461. return {
  462. bosh: document.getElementById('boshURL').value,
  463. password: document.getElementById('password').value,
  464. jid: document.getElementById('jid').value
  465. };
  466. };
  467. UI.disableConnect = function () {
  468. document.getElementById('connect').disabled = true;
  469. };
  470. UI.showLoginPopup = function(callback)
  471. {
  472. console.log('password is required');
  473. UI.messageHandler.openTwoButtonDialog(null,
  474. '<h2>Password required</h2>' +
  475. '<input id="passwordrequired.username" type="text" placeholder="user@domain.net" autofocus>' +
  476. '<input id="passwordrequired.password" type="password" placeholder="user password">',
  477. true,
  478. "Ok",
  479. function (e, v, m, f) {
  480. if (v) {
  481. var username = document.getElementById('passwordrequired.username');
  482. var password = document.getElementById('passwordrequired.password');
  483. if (username.value !== null && password.value != null) {
  484. callback(username.value, password.value);
  485. }
  486. }
  487. },
  488. function (event) {
  489. document.getElementById('passwordrequired.username').focus();
  490. }
  491. );
  492. }
  493. UI.checkForNicknameAndJoin = function () {
  494. Authentication.closeAuthenticationDialog();
  495. Authentication.stopInterval();
  496. var nick = null;
  497. if (config.useNicks) {
  498. nick = window.prompt('Your nickname (optional)');
  499. }
  500. xmpp.joinRooom(roomName, config.useNicks, nick);
  501. }
  502. function dump(elem, filename) {
  503. elem = elem.parentNode;
  504. elem.download = filename || 'meetlog.json';
  505. elem.href = 'data:application/json;charset=utf-8,\n';
  506. var data = xmpp.populateData();
  507. var metadata = {};
  508. metadata.time = new Date();
  509. metadata.url = window.location.href;
  510. metadata.ua = navigator.userAgent;
  511. var log = xmpp.getLogger();
  512. if (log) {
  513. metadata.xmpp = log;
  514. }
  515. data.metadata = metadata;
  516. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  517. return false;
  518. }
  519. UI.getRoomName = function () {
  520. return roomName;
  521. }
  522. /**
  523. * Mutes/unmutes the local video.
  524. *
  525. * @param mute <tt>true</tt> to mute the local video; otherwise, <tt>false</tt>
  526. * @param options an object which specifies optional arguments such as the
  527. * <tt>boolean</tt> key <tt>byUser</tt> with default value <tt>true</tt> which
  528. * specifies whether the method was initiated in response to a user command (in
  529. * contrast to an automatic decision taken by the application logic)
  530. */
  531. function setVideoMute(mute, options) {
  532. xmpp.setVideoMute(
  533. mute,
  534. function (mute) {
  535. var video = $('#video');
  536. var communicativeClass = "icon-camera";
  537. var muteClass = "icon-camera icon-camera-disabled";
  538. if (mute) {
  539. video.removeClass(communicativeClass);
  540. video.addClass(muteClass);
  541. } else {
  542. video.removeClass(muteClass);
  543. video.addClass(communicativeClass);
  544. }
  545. },
  546. options);
  547. }
  548. /**
  549. * Mutes/unmutes the local video.
  550. */
  551. UI.toggleVideo = function () {
  552. UIUtil.buttonClick("#video", "icon-camera icon-camera-disabled");
  553. setVideoMute(!RTC.localVideo.isMuted());
  554. };
  555. /**
  556. * Mutes / unmutes audio for the local participant.
  557. */
  558. UI.toggleAudio = function() {
  559. UI.setAudioMuted(!RTC.localAudio.isMuted());
  560. };
  561. /**
  562. * Sets muted audio state for the local participant.
  563. */
  564. UI.setAudioMuted = function (mute) {
  565. if(!xmpp.setAudioMute(mute, function () {
  566. UI.showLocalAudioIndicator(mute);
  567. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  568. }))
  569. {
  570. // We still click the button.
  571. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  572. return;
  573. }
  574. }
  575. UI.onLastNChanged = function (oldValue, newValue) {
  576. if (config.muteLocalVideoIfNotInLastN) {
  577. setVideoMute(!newValue, { 'byUser': false });
  578. }
  579. }
  580. module.exports = UI;
  581. },{"./audio_levels/AudioLevels.js":2,"./authentication/Authentication":4,"./avatar/Avatar":5,"./etherpad/Etherpad.js":6,"./prezi/Prezi.js":7,"./side_pannels/SidePanelToggler":8,"./side_pannels/chat/Chat.js":9,"./side_pannels/contactlist/ContactList":13,"./side_pannels/settings/Settings":14,"./side_pannels/settings/SettingsMenu":15,"./toolbars/BottomToolbar":16,"./toolbars/toolbar":18,"./toolbars/toolbartoggler":19,"./util/MessageHandler":21,"./util/UIUtil":22,"./videolayout/VideoLayout.js":24,"./welcome_page/RoomnameGenerator":25,"./welcome_page/WelcomePage":26}],2:[function(require,module,exports){
  582. var CanvasUtil = require("./CanvasUtils");
  583. /**
  584. * The audio Levels plugin.
  585. */
  586. var AudioLevels = (function(my) {
  587. var audioLevelCanvasCache = {};
  588. my.LOCAL_LEVEL = 'local';
  589. /**
  590. * Updates the audio level canvas for the given peerJid. If the canvas
  591. * didn't exist we create it.
  592. */
  593. my.updateAudioLevelCanvas = function (peerJid, VideoLayout) {
  594. var resourceJid = null;
  595. var videoSpanId = null;
  596. if (!peerJid)
  597. videoSpanId = 'localVideoContainer';
  598. else {
  599. resourceJid = Strophe.getResourceFromJid(peerJid);
  600. videoSpanId = 'participant_' + resourceJid;
  601. }
  602. var videoSpan = document.getElementById(videoSpanId);
  603. if (!videoSpan) {
  604. if (resourceJid)
  605. console.error("No video element for jid", resourceJid);
  606. else
  607. console.error("No video element for local video.");
  608. return;
  609. }
  610. var audioLevelCanvas = $('#' + videoSpanId + '>canvas');
  611. var videoSpaceWidth = $('#remoteVideos').width();
  612. var thumbnailSize = VideoLayout.calculateThumbnailSize(videoSpaceWidth);
  613. var thumbnailWidth = thumbnailSize[0];
  614. var thumbnailHeight = thumbnailSize[1];
  615. if (!audioLevelCanvas || audioLevelCanvas.length === 0) {
  616. audioLevelCanvas = document.createElement('canvas');
  617. audioLevelCanvas.className = "audiolevel";
  618. audioLevelCanvas.style.bottom = "-" + interfaceConfig.CANVAS_EXTRA/2 + "px";
  619. audioLevelCanvas.style.left = "-" + interfaceConfig.CANVAS_EXTRA/2 + "px";
  620. resizeAudioLevelCanvas( audioLevelCanvas,
  621. thumbnailWidth,
  622. thumbnailHeight);
  623. videoSpan.appendChild(audioLevelCanvas);
  624. } else {
  625. audioLevelCanvas = audioLevelCanvas.get(0);
  626. resizeAudioLevelCanvas( audioLevelCanvas,
  627. thumbnailWidth,
  628. thumbnailHeight);
  629. }
  630. };
  631. /**
  632. * Updates the audio level UI for the given resourceJid.
  633. *
  634. * @param resourceJid the resource jid indicating the video element for
  635. * which we draw the audio level
  636. * @param audioLevel the newAudio level to render
  637. */
  638. my.updateAudioLevel = function (resourceJid, audioLevel, largeVideoResourceJid) {
  639. drawAudioLevelCanvas(resourceJid, audioLevel);
  640. var videoSpanId = getVideoSpanId(resourceJid);
  641. var audioLevelCanvas = $('#' + videoSpanId + '>canvas').get(0);
  642. if (!audioLevelCanvas)
  643. return;
  644. var drawContext = audioLevelCanvas.getContext('2d');
  645. var canvasCache = audioLevelCanvasCache[resourceJid];
  646. drawContext.clearRect (0, 0,
  647. audioLevelCanvas.width, audioLevelCanvas.height);
  648. drawContext.drawImage(canvasCache, 0, 0);
  649. if(resourceJid === AudioLevels.LOCAL_LEVEL) {
  650. if(!xmpp.myJid()) {
  651. return;
  652. }
  653. resourceJid = xmpp.myResource();
  654. }
  655. if(resourceJid === largeVideoResourceJid) {
  656. AudioLevels.updateActiveSpeakerAudioLevel(audioLevel);
  657. }
  658. };
  659. my.updateActiveSpeakerAudioLevel = function(audioLevel) {
  660. var drawContext = $('#activeSpeakerAudioLevel')[0].getContext('2d');
  661. var r = interfaceConfig.ACTIVE_SPEAKER_AVATAR_SIZE / 2;
  662. var center = (interfaceConfig.ACTIVE_SPEAKER_AVATAR_SIZE + r) / 2;
  663. // Save the previous state of the context.
  664. drawContext.save();
  665. drawContext.clearRect(0, 0, 300, 300);
  666. // Draw a circle.
  667. drawContext.arc(center, center, r, 0, 2 * Math.PI);
  668. // Add a shadow around the circle
  669. drawContext.shadowColor = interfaceConfig.SHADOW_COLOR;
  670. drawContext.shadowBlur = getShadowLevel(audioLevel);
  671. drawContext.shadowOffsetX = 0;
  672. drawContext.shadowOffsetY = 0;
  673. // Fill the shape.
  674. drawContext.fill();
  675. drawContext.save();
  676. drawContext.restore();
  677. drawContext.arc(center, center, r, 0, 2 * Math.PI);
  678. drawContext.clip();
  679. drawContext.clearRect(0, 0, 277, 200);
  680. // Restore the previous context state.
  681. drawContext.restore();
  682. };
  683. /**
  684. * Resizes the given audio level canvas to match the given thumbnail size.
  685. */
  686. function resizeAudioLevelCanvas(audioLevelCanvas,
  687. thumbnailWidth,
  688. thumbnailHeight) {
  689. audioLevelCanvas.width = thumbnailWidth + interfaceConfig.CANVAS_EXTRA;
  690. audioLevelCanvas.height = thumbnailHeight + interfaceConfig.CANVAS_EXTRA;
  691. }
  692. /**
  693. * Draws the audio level canvas into the cached canvas object.
  694. *
  695. * @param resourceJid the resource jid indicating the video element for
  696. * which we draw the audio level
  697. * @param audioLevel the newAudio level to render
  698. */
  699. function drawAudioLevelCanvas(resourceJid, audioLevel) {
  700. if (!audioLevelCanvasCache[resourceJid]) {
  701. var videoSpanId = getVideoSpanId(resourceJid);
  702. var audioLevelCanvasOrig = $('#' + videoSpanId + '>canvas').get(0);
  703. /*
  704. * FIXME Testing has shown that audioLevelCanvasOrig may not exist.
  705. * In such a case, the method CanvasUtil.cloneCanvas may throw an
  706. * error. Since audio levels are frequently updated, the errors have
  707. * been observed to pile into the console, strain the CPU.
  708. */
  709. if (audioLevelCanvasOrig)
  710. {
  711. audioLevelCanvasCache[resourceJid]
  712. = CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
  713. }
  714. }
  715. var canvas = audioLevelCanvasCache[resourceJid];
  716. if (!canvas)
  717. return;
  718. var drawContext = canvas.getContext('2d');
  719. drawContext.clearRect(0, 0, canvas.width, canvas.height);
  720. var shadowLevel = getShadowLevel(audioLevel);
  721. if (shadowLevel > 0)
  722. // drawContext, x, y, w, h, r, shadowColor, shadowLevel
  723. CanvasUtil.drawRoundRectGlow( drawContext,
  724. interfaceConfig.CANVAS_EXTRA/2, interfaceConfig.CANVAS_EXTRA/2,
  725. canvas.width - interfaceConfig.CANVAS_EXTRA,
  726. canvas.height - interfaceConfig.CANVAS_EXTRA,
  727. interfaceConfig.CANVAS_RADIUS,
  728. interfaceConfig.SHADOW_COLOR,
  729. shadowLevel);
  730. }
  731. /**
  732. * Returns the shadow/glow level for the given audio level.
  733. *
  734. * @param audioLevel the audio level from which we determine the shadow
  735. * level
  736. */
  737. function getShadowLevel (audioLevel) {
  738. var shadowLevel = 0;
  739. if (audioLevel <= 0.3) {
  740. shadowLevel = Math.round(interfaceConfig.CANVAS_EXTRA/2*(audioLevel/0.3));
  741. }
  742. else if (audioLevel <= 0.6) {
  743. shadowLevel = Math.round(interfaceConfig.CANVAS_EXTRA/2*((audioLevel - 0.3) / 0.3));
  744. }
  745. else {
  746. shadowLevel = Math.round(interfaceConfig.CANVAS_EXTRA/2*((audioLevel - 0.6) / 0.4));
  747. }
  748. return shadowLevel;
  749. }
  750. /**
  751. * Returns the video span id corresponding to the given resourceJid or local
  752. * user.
  753. */
  754. function getVideoSpanId(resourceJid) {
  755. var videoSpanId = null;
  756. if (resourceJid === AudioLevels.LOCAL_LEVEL
  757. || (xmpp.myResource() && resourceJid
  758. === xmpp.myResource()))
  759. videoSpanId = 'localVideoContainer';
  760. else
  761. videoSpanId = 'participant_' + resourceJid;
  762. return videoSpanId;
  763. }
  764. /**
  765. * Indicates that the remote video has been resized.
  766. */
  767. $(document).bind('remotevideo.resized', function (event, width, height) {
  768. var resized = false;
  769. $('#remoteVideos>span>canvas').each(function() {
  770. var canvas = $(this).get(0);
  771. if (canvas.width !== width + interfaceConfig.CANVAS_EXTRA) {
  772. canvas.width = width + interfaceConfig.CANVAS_EXTRA;
  773. resized = true;
  774. }
  775. if (canvas.heigh !== height + interfaceConfig.CANVAS_EXTRA) {
  776. canvas.height = height + interfaceConfig.CANVAS_EXTRA;
  777. resized = true;
  778. }
  779. });
  780. if (resized)
  781. Object.keys(audioLevelCanvasCache).forEach(function (resourceJid) {
  782. audioLevelCanvasCache[resourceJid].width
  783. = width + interfaceConfig.CANVAS_EXTRA;
  784. audioLevelCanvasCache[resourceJid].height
  785. = height + interfaceConfig.CANVAS_EXTRA;
  786. });
  787. });
  788. return my;
  789. })(AudioLevels || {});
  790. module.exports = AudioLevels;
  791. },{"./CanvasUtils":3}],3:[function(require,module,exports){
  792. /**
  793. * Utility class for drawing canvas shapes.
  794. */
  795. var CanvasUtil = (function(my) {
  796. /**
  797. * Draws a round rectangle with a glow. The glowWidth indicates the depth
  798. * of the glow.
  799. *
  800. * @param drawContext the context of the canvas to draw to
  801. * @param x the x coordinate of the round rectangle
  802. * @param y the y coordinate of the round rectangle
  803. * @param w the width of the round rectangle
  804. * @param h the height of the round rectangle
  805. * @param glowColor the color of the glow
  806. * @param glowWidth the width of the glow
  807. */
  808. my.drawRoundRectGlow
  809. = function(drawContext, x, y, w, h, r, glowColor, glowWidth) {
  810. // Save the previous state of the context.
  811. drawContext.save();
  812. if (w < 2 * r) r = w / 2;
  813. if (h < 2 * r) r = h / 2;
  814. // Draw a round rectangle.
  815. drawContext.beginPath();
  816. drawContext.moveTo(x+r, y);
  817. drawContext.arcTo(x+w, y, x+w, y+h, r);
  818. drawContext.arcTo(x+w, y+h, x, y+h, r);
  819. drawContext.arcTo(x, y+h, x, y, r);
  820. drawContext.arcTo(x, y, x+w, y, r);
  821. drawContext.closePath();
  822. // Add a shadow around the rectangle
  823. drawContext.shadowColor = glowColor;
  824. drawContext.shadowBlur = glowWidth;
  825. drawContext.shadowOffsetX = 0;
  826. drawContext.shadowOffsetY = 0;
  827. // Fill the shape.
  828. drawContext.fill();
  829. drawContext.save();
  830. drawContext.restore();
  831. // 1) Uncomment this line to use Composite Operation, which is doing the
  832. // same as the clip function below and is also antialiasing the round
  833. // border, but is said to be less fast performance wise.
  834. // drawContext.globalCompositeOperation='destination-out';
  835. drawContext.beginPath();
  836. drawContext.moveTo(x+r, y);
  837. drawContext.arcTo(x+w, y, x+w, y+h, r);
  838. drawContext.arcTo(x+w, y+h, x, y+h, r);
  839. drawContext.arcTo(x, y+h, x, y, r);
  840. drawContext.arcTo(x, y, x+w, y, r);
  841. drawContext.closePath();
  842. // 2) Uncomment this line to use Composite Operation, which is doing the
  843. // same as the clip function below and is also antialiasing the round
  844. // border, but is said to be less fast performance wise.
  845. // drawContext.fill();
  846. // Comment these two lines if choosing to do the same with composite
  847. // operation above 1 and 2.
  848. drawContext.clip();
  849. drawContext.clearRect(0, 0, 277, 200);
  850. // Restore the previous context state.
  851. drawContext.restore();
  852. };
  853. /**
  854. * Clones the given canvas.
  855. *
  856. * @return the new cloned canvas.
  857. */
  858. my.cloneCanvas = function (oldCanvas) {
  859. /*
  860. * FIXME Testing has shown that oldCanvas may not exist. In such a case,
  861. * the method CanvasUtil.cloneCanvas may throw an error. Since audio
  862. * levels are frequently updated, the errors have been observed to pile
  863. * into the console, strain the CPU.
  864. */
  865. if (!oldCanvas)
  866. return oldCanvas;
  867. //create a new canvas
  868. var newCanvas = document.createElement('canvas');
  869. var context = newCanvas.getContext('2d');
  870. //set dimensions
  871. newCanvas.width = oldCanvas.width;
  872. newCanvas.height = oldCanvas.height;
  873. //apply the old canvas to the new one
  874. context.drawImage(oldCanvas, 0, 0);
  875. //return the new canvas
  876. return newCanvas;
  877. };
  878. return my;
  879. })(CanvasUtil || {});
  880. module.exports = CanvasUtil;
  881. },{}],4:[function(require,module,exports){
  882. /* Initial "authentication required" dialog */
  883. var authDialog = null;
  884. /* Loop retry ID that wits for other user to create the room */
  885. var authRetryId = null;
  886. var authenticationWindow = null;
  887. var Authentication = {
  888. openAuthenticationDialog: function (roomName, intervalCallback, callback) {
  889. // This is the loop that will wait for the room to be created by
  890. // someone else. 'auth_required.moderator' will bring us back here.
  891. authRetryId = window.setTimeout(intervalCallback , 5000);
  892. // Show prompt only if it's not open
  893. if (authDialog !== null) {
  894. return;
  895. }
  896. // extract room name from 'room@muc.server.net'
  897. var room = roomName.substr(0, roomName.indexOf('@'));
  898. authDialog = messageHandler.openDialog(
  899. 'Stop',
  900. 'Authentication is required to create room:<br/><b>' + room +
  901. '</b></br> You can either authenticate to create the room or ' +
  902. 'just wait for someone else to do so.',
  903. true,
  904. {
  905. Authenticate: 'authNow'
  906. },
  907. function (onSubmitEvent, submitValue) {
  908. // Do not close the dialog yet
  909. onSubmitEvent.preventDefault();
  910. // Open login popup
  911. if (submitValue === 'authNow') {
  912. callback();
  913. }
  914. }
  915. );
  916. },
  917. closeAuthenticationWindow:function () {
  918. if (authenticationWindow) {
  919. authenticationWindow.close();
  920. authenticationWindow = null;
  921. }
  922. },
  923. focusAuthenticationWindow: function () {
  924. // If auth window exists just bring it to the front
  925. if (authenticationWindow) {
  926. authenticationWindow.focus();
  927. return;
  928. }
  929. },
  930. closeAuthenticationDialog: function () {
  931. // Close authentication dialog if opened
  932. if (authDialog) {
  933. UI.messageHandler.closeDialog();
  934. authDialog = null;
  935. }
  936. },
  937. createAuthenticationWindow: function (callback, url) {
  938. authenticationWindow = messageHandler.openCenteredPopup(
  939. url, 910, 660,
  940. // On closed
  941. function () {
  942. // Close authentication dialog if opened
  943. if (authDialog) {
  944. messageHandler.closeDialog();
  945. authDialog = null;
  946. }
  947. callback();
  948. authenticationWindow = null;
  949. });
  950. return authenticationWindow;
  951. },
  952. stopInterval: function () {
  953. // Clear retry interval, so that we don't call 'doJoinAfterFocus' twice
  954. if (authRetryId) {
  955. window.clearTimeout(authRetryId);
  956. authRetryId = null;
  957. }
  958. }
  959. };
  960. module.exports = Authentication;
  961. },{}],5:[function(require,module,exports){
  962. var Settings = require("../side_pannels/settings/Settings");
  963. var users = {};
  964. var activeSpeakerJid;
  965. function setVisibility(selector, show) {
  966. if (selector && selector.length > 0) {
  967. selector.css("visibility", show ? "visible" : "hidden");
  968. }
  969. }
  970. function isUserMuted(jid) {
  971. // XXX(gp) we may want to rename this method to something like
  972. // isUserStreaming, for example.
  973. if (jid && jid != xmpp.myJid()) {
  974. var resource = Strophe.getResourceFromJid(jid);
  975. if (!require("../videolayout/VideoLayout").isInLastN(resource)) {
  976. return true;
  977. }
  978. }
  979. if (!RTC.remoteStreams[jid] || !RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]) {
  980. return null;
  981. }
  982. return RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE].muted;
  983. }
  984. function getGravatarUrl(id, size) {
  985. if(id === xmpp.myJid() || !id) {
  986. id = Settings.getSettings().uid;
  987. }
  988. return 'https://www.gravatar.com/avatar/' +
  989. MD5.hexdigest(id.trim().toLowerCase()) +
  990. "?d=wavatar&size=" + (size || "30");
  991. }
  992. var Avatar = {
  993. /**
  994. * Sets the user's avatar in the settings menu(if local user), contact list
  995. * and thumbnail
  996. * @param jid jid of the user
  997. * @param id email or userID to be used as a hash
  998. */
  999. setUserAvatar: function (jid, id) {
  1000. if (id) {
  1001. if (users[jid] === id) {
  1002. return;
  1003. }
  1004. users[jid] = id;
  1005. }
  1006. var thumbUrl = getGravatarUrl(users[jid] || jid, 100);
  1007. var contactListUrl = getGravatarUrl(users[jid] || jid);
  1008. var resourceJid = Strophe.getResourceFromJid(jid);
  1009. var thumbnail = $('#participant_' + resourceJid);
  1010. var avatar = $('#avatar_' + resourceJid);
  1011. // set the avatar in the settings menu if it is local user and get the
  1012. // local video container
  1013. if (jid === xmpp.myJid()) {
  1014. $('#avatar').get(0).src = thumbUrl;
  1015. thumbnail = $('#localVideoContainer');
  1016. }
  1017. // set the avatar in the contact list
  1018. var contact = $('#' + resourceJid + '>img');
  1019. if (contact && contact.length > 0) {
  1020. contact.get(0).src = contactListUrl;
  1021. }
  1022. // set the avatar in the thumbnail
  1023. if (avatar && avatar.length > 0) {
  1024. avatar[0].src = thumbUrl;
  1025. } else {
  1026. if (thumbnail && thumbnail.length > 0) {
  1027. avatar = document.createElement('img');
  1028. avatar.id = 'avatar_' + resourceJid;
  1029. avatar.className = 'userAvatar';
  1030. avatar.src = thumbUrl;
  1031. thumbnail.append(avatar);
  1032. }
  1033. }
  1034. //if the user is the current active speaker - update the active speaker
  1035. // avatar
  1036. if (jid === activeSpeakerJid) {
  1037. this.updateActiveSpeakerAvatarSrc(jid);
  1038. }
  1039. },
  1040. /**
  1041. * Hides or shows the user's avatar
  1042. * @param jid jid of the user
  1043. * @param show whether we should show the avatar or not
  1044. * video because there is no dominant speaker and no focused speaker
  1045. */
  1046. showUserAvatar: function (jid, show) {
  1047. if (users[jid]) {
  1048. var resourceJid = Strophe.getResourceFromJid(jid);
  1049. var video = $('#participant_' + resourceJid + '>video');
  1050. var avatar = $('#avatar_' + resourceJid);
  1051. if (jid === xmpp.myJid()) {
  1052. video = $('#localVideoWrapper>video');
  1053. }
  1054. if (show === undefined || show === null) {
  1055. show = isUserMuted(jid);
  1056. }
  1057. //if the user is the currently focused, the dominant speaker or if
  1058. //there is no focused and no dominant speaker and the large video is
  1059. //currently shown
  1060. if (activeSpeakerJid === jid && require("../videolayout/VideoLayout").isLargeVideoOnTop()) {
  1061. setVisibility($("#largeVideo"), !show);
  1062. setVisibility($('#activeSpeaker'), show);
  1063. setVisibility(avatar, false);
  1064. setVisibility(video, false);
  1065. } else {
  1066. if (video && video.length > 0) {
  1067. setVisibility(video, !show);
  1068. setVisibility(avatar, show);
  1069. }
  1070. }
  1071. }
  1072. },
  1073. /**
  1074. * Updates the src of the active speaker avatar
  1075. * @param jid of the current active speaker
  1076. */
  1077. updateActiveSpeakerAvatarSrc: function (jid) {
  1078. if (!jid) {
  1079. jid = xmpp.findJidFromResource(
  1080. require("../videolayout/VideoLayout").getLargeVideoState().userResourceJid);
  1081. }
  1082. var avatar = $("#activeSpeakerAvatar")[0];
  1083. var url = getGravatarUrl(users[jid],
  1084. interfaceConfig.ACTIVE_SPEAKER_AVATAR_SIZE);
  1085. if (jid === activeSpeakerJid && avatar.src === url) {
  1086. return;
  1087. }
  1088. activeSpeakerJid = jid;
  1089. var isMuted = isUserMuted(jid);
  1090. if (jid && isMuted !== null) {
  1091. avatar.src = url;
  1092. setVisibility($("#largeVideo"), !isMuted);
  1093. Avatar.showUserAvatar(jid, isMuted);
  1094. }
  1095. }
  1096. };
  1097. module.exports = Avatar;
  1098. },{"../side_pannels/settings/Settings":14,"../videolayout/VideoLayout":24}],6:[function(require,module,exports){
  1099. /* global $, config, dockToolbar,
  1100. setLargeVideoVisible, Util */
  1101. var VideoLayout = require("../videolayout/VideoLayout");
  1102. var Prezi = require("../prezi/Prezi");
  1103. var UIUtil = require("../util/UIUtil");
  1104. var etherpadName = null;
  1105. var etherpadIFrame = null;
  1106. var domain = null;
  1107. var options = "?showControls=true&showChat=false&showLineNumbers=true&useMonospaceFont=false";
  1108. /**
  1109. * Resizes the etherpad.
  1110. */
  1111. function resize() {
  1112. if ($('#etherpad>iframe').length) {
  1113. var remoteVideos = $('#remoteVideos');
  1114. var availableHeight
  1115. = window.innerHeight - remoteVideos.outerHeight();
  1116. var availableWidth = UIUtil.getAvailableVideoWidth();
  1117. $('#etherpad>iframe').width(availableWidth);
  1118. $('#etherpad>iframe').height(availableHeight);
  1119. }
  1120. }
  1121. /**
  1122. * Shares the Etherpad name with other participants.
  1123. */
  1124. function shareEtherpad() {
  1125. xmpp.addToPresence("etherpad", etherpadName);
  1126. }
  1127. /**
  1128. * Creates the Etherpad button and adds it to the toolbar.
  1129. */
  1130. function enableEtherpadButton() {
  1131. if (!$('#etherpadButton').is(":visible"))
  1132. $('#etherpadButton').css({display: 'inline-block'});
  1133. }
  1134. /**
  1135. * Creates the IFrame for the etherpad.
  1136. */
  1137. function createIFrame() {
  1138. etherpadIFrame = document.createElement('iframe');
  1139. etherpadIFrame.src = domain + etherpadName + options;
  1140. etherpadIFrame.frameBorder = 0;
  1141. etherpadIFrame.scrolling = "no";
  1142. etherpadIFrame.width = $('#largeVideoContainer').width() || 640;
  1143. etherpadIFrame.height = $('#largeVideoContainer').height() || 480;
  1144. etherpadIFrame.setAttribute('style', 'visibility: hidden;');
  1145. document.getElementById('etherpad').appendChild(etherpadIFrame);
  1146. etherpadIFrame.onload = function() {
  1147. document.domain = document.domain;
  1148. bubbleIframeMouseMove(etherpadIFrame);
  1149. setTimeout(function() {
  1150. // the iframes inside of the etherpad are
  1151. // not yet loaded when the etherpad iframe is loaded
  1152. var outer = etherpadIFrame.
  1153. contentDocument.getElementsByName("ace_outer")[0];
  1154. bubbleIframeMouseMove(outer);
  1155. var inner = outer.
  1156. contentDocument.getElementsByName("ace_inner")[0];
  1157. bubbleIframeMouseMove(inner);
  1158. }, 2000);
  1159. };
  1160. }
  1161. function bubbleIframeMouseMove(iframe){
  1162. var existingOnMouseMove = iframe.contentWindow.onmousemove;
  1163. iframe.contentWindow.onmousemove = function(e){
  1164. if(existingOnMouseMove) existingOnMouseMove(e);
  1165. var evt = document.createEvent("MouseEvents");
  1166. var boundingClientRect = iframe.getBoundingClientRect();
  1167. evt.initMouseEvent(
  1168. "mousemove",
  1169. true, // bubbles
  1170. false, // not cancelable
  1171. window,
  1172. e.detail,
  1173. e.screenX,
  1174. e.screenY,
  1175. e.clientX + boundingClientRect.left,
  1176. e.clientY + boundingClientRect.top,
  1177. e.ctrlKey,
  1178. e.altKey,
  1179. e.shiftKey,
  1180. e.metaKey,
  1181. e.button,
  1182. null // no related element
  1183. );
  1184. iframe.dispatchEvent(evt);
  1185. };
  1186. }
  1187. /**
  1188. * On video selected event.
  1189. */
  1190. $(document).bind('video.selected', function (event, isPresentation) {
  1191. if (config.etherpad_base && etherpadIFrame && etherpadIFrame.style.visibility !== 'hidden')
  1192. Etherpad.toggleEtherpad(isPresentation);
  1193. });
  1194. var Etherpad = {
  1195. /**
  1196. * Initializes the etherpad.
  1197. */
  1198. init: function (name) {
  1199. if (config.etherpad_base && !etherpadName) {
  1200. domain = config.etherpad_base;
  1201. if (!name) {
  1202. // In case we're the focus we generate the name.
  1203. etherpadName = Math.random().toString(36).substring(7) +
  1204. '_' + (new Date().getTime()).toString();
  1205. shareEtherpad();
  1206. }
  1207. else
  1208. etherpadName = name;
  1209. enableEtherpadButton();
  1210. /**
  1211. * Resizes the etherpad, when the window is resized.
  1212. */
  1213. $(window).resize(function () {
  1214. resize();
  1215. });
  1216. }
  1217. },
  1218. /**
  1219. * Opens/hides the Etherpad.
  1220. */
  1221. toggleEtherpad: function (isPresentation) {
  1222. if (!etherpadIFrame)
  1223. createIFrame();
  1224. var largeVideo = null;
  1225. if (Prezi.isPresentationVisible())
  1226. largeVideo = $('#presentation>iframe');
  1227. else
  1228. largeVideo = $('#largeVideo');
  1229. if ($('#etherpad>iframe').css('visibility') === 'hidden') {
  1230. $('#activeSpeaker').css('visibility', 'hidden');
  1231. largeVideo.fadeOut(300, function () {
  1232. if (Prezi.isPresentationVisible()) {
  1233. largeVideo.css({opacity: '0'});
  1234. } else {
  1235. VideoLayout.setLargeVideoVisible(false);
  1236. }
  1237. });
  1238. $('#etherpad>iframe').fadeIn(300, function () {
  1239. document.body.style.background = '#eeeeee';
  1240. $('#etherpad>iframe').css({visibility: 'visible'});
  1241. $('#etherpad').css({zIndex: 2});
  1242. });
  1243. }
  1244. else if ($('#etherpad>iframe')) {
  1245. $('#etherpad>iframe').fadeOut(300, function () {
  1246. $('#etherpad>iframe').css({visibility: 'hidden'});
  1247. $('#etherpad').css({zIndex: 0});
  1248. document.body.style.background = 'black';
  1249. });
  1250. if (!isPresentation) {
  1251. $('#largeVideo').fadeIn(300, function () {
  1252. VideoLayout.setLargeVideoVisible(true);
  1253. });
  1254. }
  1255. }
  1256. resize();
  1257. },
  1258. isVisible: function() {
  1259. var etherpadIframe = $('#etherpad>iframe');
  1260. return etherpadIframe && etherpadIframe.is(':visible');
  1261. }
  1262. };
  1263. module.exports = Etherpad;
  1264. },{"../prezi/Prezi":7,"../util/UIUtil":22,"../videolayout/VideoLayout":24}],7:[function(require,module,exports){
  1265. var ToolbarToggler = require("../toolbars/ToolbarToggler");
  1266. var UIUtil = require("../util/UIUtil");
  1267. var VideoLayout = require("../videolayout/VideoLayout");
  1268. var messageHandler = require("../util/MessageHandler");
  1269. var preziPlayer = null;
  1270. var Prezi = {
  1271. /**
  1272. * Reloads the current presentation.
  1273. */
  1274. reloadPresentation: function() {
  1275. var iframe = document.getElementById(preziPlayer.options.preziId);
  1276. iframe.src = iframe.src;
  1277. },
  1278. /**
  1279. * Returns <tt>true</tt> if the presentation is visible, <tt>false</tt> -
  1280. * otherwise.
  1281. */
  1282. isPresentationVisible: function () {
  1283. return ($('#presentation>iframe') != null
  1284. && $('#presentation>iframe').css('opacity') == 1);
  1285. },
  1286. /**
  1287. * Opens the Prezi dialog, from which the user could choose a presentation
  1288. * to load.
  1289. */
  1290. openPreziDialog: function() {
  1291. var myprezi = xmpp.getPrezi();
  1292. if (myprezi) {
  1293. messageHandler.openTwoButtonDialog("Remove Prezi",
  1294. "Are you sure you would like to remove your Prezi?",
  1295. false,
  1296. "Remove",
  1297. function(e,v,m,f) {
  1298. if(v) {
  1299. xmpp.removePreziFromPresence();
  1300. }
  1301. }
  1302. );
  1303. }
  1304. else if (preziPlayer != null) {
  1305. messageHandler.openTwoButtonDialog("Share a Prezi",
  1306. "Another participant is already sharing a Prezi." +
  1307. "This conference allows only one Prezi at a time.",
  1308. false,
  1309. "Ok",
  1310. function(e,v,m,f) {
  1311. $.prompt.close();
  1312. }
  1313. );
  1314. }
  1315. else {
  1316. var openPreziState = {
  1317. state0: {
  1318. html: '<h2>Share a Prezi</h2>' +
  1319. '<input id="preziUrl" type="text" ' +
  1320. 'placeholder="e.g. ' +
  1321. 'http://prezi.com/wz7vhjycl7e6/my-prezi" autofocus>',
  1322. persistent: false,
  1323. buttons: { "Share": true , "Cancel": false},
  1324. defaultButton: 1,
  1325. submit: function(e,v,m,f){
  1326. e.preventDefault();
  1327. if(v)
  1328. {
  1329. var preziUrl = document.getElementById('preziUrl');
  1330. if (preziUrl.value)
  1331. {
  1332. var urlValue
  1333. = encodeURI(Util.escapeHtml(preziUrl.value));
  1334. if (urlValue.indexOf('http://prezi.com/') != 0
  1335. && urlValue.indexOf('https://prezi.com/') != 0)
  1336. {
  1337. $.prompt.goToState('state1');
  1338. return false;
  1339. }
  1340. else {
  1341. var presIdTmp = urlValue.substring(
  1342. urlValue.indexOf("prezi.com/") + 10);
  1343. if (!isAlphanumeric(presIdTmp)
  1344. || presIdTmp.indexOf('/') < 2) {
  1345. $.prompt.goToState('state1');
  1346. return false;
  1347. }
  1348. else {
  1349. xmpp.addToPresence("prezi", urlValue);
  1350. $.prompt.close();
  1351. }
  1352. }
  1353. }
  1354. }
  1355. else
  1356. $.prompt.close();
  1357. }
  1358. },
  1359. state1: {
  1360. html: '<h2>Share a Prezi</h2>' +
  1361. 'Please provide a correct prezi link.',
  1362. persistent: false,
  1363. buttons: { "Back": true, "Cancel": false },
  1364. defaultButton: 1,
  1365. submit:function(e,v,m,f) {
  1366. e.preventDefault();
  1367. if(v==0)
  1368. $.prompt.close();
  1369. else
  1370. $.prompt.goToState('state0');
  1371. }
  1372. }
  1373. };
  1374. var focusPreziUrl = function(e) {
  1375. document.getElementById('preziUrl').focus();
  1376. };
  1377. messageHandler.openDialogWithStates(openPreziState, focusPreziUrl, focusPreziUrl);
  1378. }
  1379. }
  1380. };
  1381. /**
  1382. * A new presentation has been added.
  1383. *
  1384. * @param event the event indicating the add of a presentation
  1385. * @param jid the jid from which the presentation was added
  1386. * @param presUrl url of the presentation
  1387. * @param currentSlide the current slide to which we should move
  1388. */
  1389. function presentationAdded(event, jid, presUrl, currentSlide) {
  1390. console.log("presentation added", presUrl);
  1391. var presId = getPresentationId(presUrl);
  1392. var elementId = 'participant_'
  1393. + Strophe.getResourceFromJid(jid)
  1394. + '_' + presId;
  1395. // We explicitly don't specify the peer jid here, because we don't want
  1396. // this video to be dealt with as a peer related one (for example we
  1397. // don't want to show a mute/kick menu for this one, etc.).
  1398. VideoLayout.addRemoteVideoContainer(null, elementId);
  1399. VideoLayout.resizeThumbnails();
  1400. var controlsEnabled = false;
  1401. if (jid === xmpp.myJid())
  1402. controlsEnabled = true;
  1403. setPresentationVisible(true);
  1404. $('#largeVideoContainer').hover(
  1405. function (event) {
  1406. if (Prezi.isPresentationVisible()) {
  1407. var reloadButtonRight = window.innerWidth
  1408. - $('#presentation>iframe').offset().left
  1409. - $('#presentation>iframe').width();
  1410. $('#reloadPresentation').css({ right: reloadButtonRight,
  1411. display:'inline-block'});
  1412. }
  1413. },
  1414. function (event) {
  1415. if (!Prezi.isPresentationVisible())
  1416. $('#reloadPresentation').css({display:'none'});
  1417. else {
  1418. var e = event.toElement || event.relatedTarget;
  1419. if (e && e.id != 'reloadPresentation' && e.id != 'header')
  1420. $('#reloadPresentation').css({display:'none'});
  1421. }
  1422. });
  1423. preziPlayer = new PreziPlayer(
  1424. 'presentation',
  1425. {preziId: presId,
  1426. width: getPresentationWidth(),
  1427. height: getPresentationHeihgt(),
  1428. controls: controlsEnabled,
  1429. debug: true
  1430. });
  1431. $('#presentation>iframe').attr('id', preziPlayer.options.preziId);
  1432. preziPlayer.on(PreziPlayer.EVENT_STATUS, function(event) {
  1433. console.log("prezi status", event.value);
  1434. if (event.value == PreziPlayer.STATUS_CONTENT_READY) {
  1435. if (jid != xmpp.myJid())
  1436. preziPlayer.flyToStep(currentSlide);
  1437. }
  1438. });
  1439. preziPlayer.on(PreziPlayer.EVENT_CURRENT_STEP, function(event) {
  1440. console.log("event value", event.value);
  1441. xmpp.addToPresence("preziSlide", event.value);
  1442. });
  1443. $("#" + elementId).css( 'background-image',
  1444. 'url(../images/avatarprezi.png)');
  1445. $("#" + elementId).click(
  1446. function () {
  1447. setPresentationVisible(true);
  1448. }
  1449. );
  1450. };
  1451. /**
  1452. * A presentation has been removed.
  1453. *
  1454. * @param event the event indicating the remove of a presentation
  1455. * @param jid the jid for which the presentation was removed
  1456. * @param the url of the presentation
  1457. */
  1458. function presentationRemoved(event, jid, presUrl) {
  1459. console.log('presentation removed', presUrl);
  1460. var presId = getPresentationId(presUrl);
  1461. setPresentationVisible(false);
  1462. $('#participant_'
  1463. + Strophe.getResourceFromJid(jid)
  1464. + '_' + presId).remove();
  1465. $('#presentation>iframe').remove();
  1466. if (preziPlayer != null) {
  1467. preziPlayer.destroy();
  1468. preziPlayer = null;
  1469. }
  1470. };
  1471. /**
  1472. * Indicates if the given string is an alphanumeric string.
  1473. * Note that some special characters are also allowed (-, _ , /, &, ?, =, ;) for the
  1474. * purpose of checking URIs.
  1475. */
  1476. function isAlphanumeric(unsafeText) {
  1477. var regex = /^[a-z0-9-_\/&\?=;]+$/i;
  1478. return regex.test(unsafeText);
  1479. }
  1480. /**
  1481. * Returns the presentation id from the given url.
  1482. */
  1483. function getPresentationId (presUrl) {
  1484. var presIdTmp = presUrl.substring(presUrl.indexOf("prezi.com/") + 10);
  1485. return presIdTmp.substring(0, presIdTmp.indexOf('/'));
  1486. }
  1487. /**
  1488. * Returns the presentation width.
  1489. */
  1490. function getPresentationWidth() {
  1491. var availableWidth = UIUtil.getAvailableVideoWidth();
  1492. var availableHeight = getPresentationHeihgt();
  1493. var aspectRatio = 16.0 / 9.0;
  1494. if (availableHeight < availableWidth / aspectRatio) {
  1495. availableWidth = Math.floor(availableHeight * aspectRatio);
  1496. }
  1497. return availableWidth;
  1498. }
  1499. /**
  1500. * Returns the presentation height.
  1501. */
  1502. function getPresentationHeihgt() {
  1503. var remoteVideos = $('#remoteVideos');
  1504. return window.innerHeight - remoteVideos.outerHeight();
  1505. }
  1506. /**
  1507. * Resizes the presentation iframe.
  1508. */
  1509. function resize() {
  1510. if ($('#presentation>iframe')) {
  1511. $('#presentation>iframe').width(getPresentationWidth());
  1512. $('#presentation>iframe').height(getPresentationHeihgt());
  1513. }
  1514. }
  1515. /**
  1516. * Shows/hides a presentation.
  1517. */
  1518. function setPresentationVisible(visible) {
  1519. var prezi = $('#presentation>iframe');
  1520. if (visible) {
  1521. // Trigger the video.selected event to indicate a change in the
  1522. // large video.
  1523. $(document).trigger("video.selected", [true]);
  1524. $('#largeVideo').fadeOut(300);
  1525. prezi.fadeIn(300, function() {
  1526. prezi.css({opacity:'1'});
  1527. ToolbarToggler.dockToolbar(true);
  1528. VideoLayout.setLargeVideoVisible(false);
  1529. });
  1530. $('#activeSpeaker').css('visibility', 'hidden');
  1531. }
  1532. else {
  1533. if (prezi.css('opacity') == '1') {
  1534. prezi.fadeOut(300, function () {
  1535. prezi.css({opacity:'0'});
  1536. $('#reloadPresentation').css({display:'none'});
  1537. $('#largeVideo').fadeIn(300, function() {
  1538. VideoLayout.setLargeVideoVisible(true);
  1539. ToolbarToggler.dockToolbar(false);
  1540. });
  1541. });
  1542. }
  1543. }
  1544. }
  1545. /**
  1546. * Presentation has been removed.
  1547. */
  1548. $(document).bind('presentationremoved.muc', presentationRemoved);
  1549. /**
  1550. * Presentation has been added.
  1551. */
  1552. $(document).bind('presentationadded.muc', presentationAdded);
  1553. /*
  1554. * Indicates presentation slide change.
  1555. */
  1556. $(document).bind('gotoslide.muc', function (event, jid, presUrl, current) {
  1557. if (preziPlayer && preziPlayer.getCurrentStep() != current) {
  1558. preziPlayer.flyToStep(current);
  1559. var animationStepsArray = preziPlayer.getAnimationCountOnSteps();
  1560. for (var i = 0; i < parseInt(animationStepsArray[current]); i++) {
  1561. preziPlayer.flyToStep(current, i);
  1562. }
  1563. }
  1564. });
  1565. /**
  1566. * On video selected event.
  1567. */
  1568. $(document).bind('video.selected', function (event, isPresentation) {
  1569. if (!isPresentation && $('#presentation>iframe')) {
  1570. setPresentationVisible(false);
  1571. }
  1572. });
  1573. $(window).resize(function () {
  1574. resize();
  1575. });
  1576. module.exports = Prezi;
  1577. },{"../toolbars/ToolbarToggler":17,"../util/MessageHandler":21,"../util/UIUtil":22,"../videolayout/VideoLayout":24}],8:[function(require,module,exports){
  1578. var Chat = require("./chat/Chat");
  1579. var ContactList = require("./contactlist/ContactList");
  1580. var Settings = require("./settings/Settings");
  1581. var SettingsMenu = require("./settings/SettingsMenu");
  1582. var VideoLayout = require("../videolayout/VideoLayout");
  1583. var ToolbarToggler = require("../toolbars/ToolbarToggler");
  1584. var UIUtil = require("../util/UIUtil");
  1585. /**
  1586. * Toggler for the chat, contact list, settings menu, etc..
  1587. */
  1588. var PanelToggler = (function(my) {
  1589. var currentlyOpen = null;
  1590. var buttons = {
  1591. '#chatspace': '#chatBottomButton',
  1592. '#contactlist': '#contactListButton',
  1593. '#settingsmenu': '#settingsButton'
  1594. };
  1595. /**
  1596. * Resizes the video area
  1597. * @param isClosing whether the side panel is going to be closed or is going to open / remain opened
  1598. * @param completeFunction a function to be called when the video space is resized
  1599. */
  1600. var resizeVideoArea = function(isClosing, completeFunction) {
  1601. var videospace = $('#videospace');
  1602. var panelSize = isClosing ? [0, 0] : PanelToggler.getPanelSize();
  1603. var videospaceWidth = window.innerWidth - panelSize[0];
  1604. var videospaceHeight = window.innerHeight;
  1605. var videoSize
  1606. = VideoLayout.getVideoSize(null, null, videospaceWidth, videospaceHeight);
  1607. var videoWidth = videoSize[0];
  1608. var videoHeight = videoSize[1];
  1609. var videoPosition = VideoLayout.getVideoPosition(videoWidth,
  1610. videoHeight,
  1611. videospaceWidth,
  1612. videospaceHeight);
  1613. var horizontalIndent = videoPosition[0];
  1614. var verticalIndent = videoPosition[1];
  1615. var thumbnailSize = VideoLayout.calculateThumbnailSize(videospaceWidth);
  1616. var thumbnailsWidth = thumbnailSize[0];
  1617. var thumbnailsHeight = thumbnailSize[1];
  1618. //for chat
  1619. videospace.animate({
  1620. right: panelSize[0],
  1621. width: videospaceWidth,
  1622. height: videospaceHeight
  1623. },
  1624. {
  1625. queue: false,
  1626. duration: 500,
  1627. complete: completeFunction
  1628. });
  1629. $('#remoteVideos').animate({
  1630. height: thumbnailsHeight
  1631. },
  1632. {
  1633. queue: false,
  1634. duration: 500
  1635. });
  1636. $('#remoteVideos>span').animate({
  1637. height: thumbnailsHeight,
  1638. width: thumbnailsWidth
  1639. },
  1640. {
  1641. queue: false,
  1642. duration: 500,
  1643. complete: function () {
  1644. $(document).trigger(
  1645. "remotevideo.resized",
  1646. [thumbnailsWidth,
  1647. thumbnailsHeight]);
  1648. }
  1649. });
  1650. $('#largeVideoContainer').animate({
  1651. width: videospaceWidth,
  1652. height: videospaceHeight
  1653. },
  1654. {
  1655. queue: false,
  1656. duration: 500
  1657. });
  1658. $('#largeVideo').animate({
  1659. width: videoWidth,
  1660. height: videoHeight,
  1661. top: verticalIndent,
  1662. bottom: verticalIndent,
  1663. left: horizontalIndent,
  1664. right: horizontalIndent
  1665. },
  1666. {
  1667. queue: false,
  1668. duration: 500
  1669. });
  1670. };
  1671. /**
  1672. * Toggles the windows in the side panel
  1673. * @param object the window that should be shown
  1674. * @param selector the selector for the element containing the panel
  1675. * @param onOpenComplete function to be called when the panel is opened
  1676. * @param onOpen function to be called if the window is going to be opened
  1677. * @param onClose function to be called if the window is going to be closed
  1678. */
  1679. var toggle = function(object, selector, onOpenComplete, onOpen, onClose) {
  1680. UIUtil.buttonClick(buttons[selector], "active");
  1681. if (object.isVisible()) {
  1682. $("#toast-container").animate({
  1683. right: '5px'
  1684. },
  1685. {
  1686. queue: false,
  1687. duration: 500
  1688. });
  1689. $(selector).hide("slide", {
  1690. direction: "right",
  1691. queue: false,
  1692. duration: 500
  1693. });
  1694. if(typeof onClose === "function") {
  1695. onClose();
  1696. }
  1697. currentlyOpen = null;
  1698. }
  1699. else {
  1700. // Undock the toolbar when the chat is shown and if we're in a
  1701. // video mode.
  1702. if (VideoLayout.isLargeVideoVisible()) {
  1703. ToolbarToggler.dockToolbar(false);
  1704. }
  1705. if(currentlyOpen) {
  1706. var current = $(currentlyOpen);
  1707. UIUtil.buttonClick(buttons[currentlyOpen], "active");
  1708. current.css('z-index', 4);
  1709. setTimeout(function () {
  1710. current.css('display', 'none');
  1711. current.css('z-index', 5);
  1712. }, 500);
  1713. }
  1714. $("#toast-container").animate({
  1715. right: (PanelToggler.getPanelSize()[0] + 5) + 'px'
  1716. },
  1717. {
  1718. queue: false,
  1719. duration: 500
  1720. });
  1721. $(selector).show("slide", {
  1722. direction: "right",
  1723. queue: false,
  1724. duration: 500,
  1725. complete: onOpenComplete
  1726. });
  1727. if(typeof onOpen === "function") {
  1728. onOpen();
  1729. }
  1730. currentlyOpen = selector;
  1731. }
  1732. };
  1733. /**
  1734. * Opens / closes the chat area.
  1735. */
  1736. my.toggleChat = function() {
  1737. var chatCompleteFunction = Chat.isVisible() ?
  1738. function() {} : function () {
  1739. Chat.scrollChatToBottom();
  1740. $('#chatspace').trigger('shown');
  1741. };
  1742. resizeVideoArea(Chat.isVisible(), chatCompleteFunction);
  1743. toggle(Chat,
  1744. '#chatspace',
  1745. function () {
  1746. // Request the focus in the nickname field or the chat input field.
  1747. if ($('#nickname').css('visibility') === 'visible') {
  1748. $('#nickinput').focus();
  1749. } else {
  1750. $('#usermsg').focus();
  1751. }
  1752. },
  1753. null,
  1754. Chat.resizeChat,
  1755. null);
  1756. };
  1757. /**
  1758. * Opens / closes the contact list area.
  1759. */
  1760. my.toggleContactList = function () {
  1761. var completeFunction = ContactList.isVisible() ?
  1762. function() {} : function () { $('#contactlist').trigger('shown');};
  1763. resizeVideoArea(ContactList.isVisible(), completeFunction);
  1764. toggle(ContactList,
  1765. '#contactlist',
  1766. null,
  1767. function() {
  1768. ContactList.setVisualNotification(false);
  1769. },
  1770. null);
  1771. };
  1772. /**
  1773. * Opens / closes the settings menu
  1774. */
  1775. my.toggleSettingsMenu = function() {
  1776. resizeVideoArea(SettingsMenu.isVisible(), function (){});
  1777. toggle(SettingsMenu,
  1778. '#settingsmenu',
  1779. null,
  1780. function() {
  1781. var settings = Settings.getSettings();
  1782. $('#setDisplayName').get(0).value = settings.displayName;
  1783. $('#setEmail').get(0).value = settings.email;
  1784. },
  1785. null);
  1786. };
  1787. /**
  1788. * Returns the size of the side panel.
  1789. */
  1790. my.getPanelSize = function () {
  1791. var availableHeight = window.innerHeight;
  1792. var availableWidth = window.innerWidth;
  1793. var panelWidth = 200;
  1794. if (availableWidth * 0.2 < 200) {
  1795. panelWidth = availableWidth * 0.2;
  1796. }
  1797. return [panelWidth, availableHeight];
  1798. };
  1799. my.isVisible = function() {
  1800. return (Chat.isVisible() || ContactList.isVisible() || SettingsMenu.isVisible());
  1801. };
  1802. return my;
  1803. }(PanelToggler || {}));
  1804. module.exports = PanelToggler;
  1805. },{"../toolbars/ToolbarToggler":17,"../util/UIUtil":22,"../videolayout/VideoLayout":24,"./chat/Chat":9,"./contactlist/ContactList":13,"./settings/Settings":14,"./settings/SettingsMenu":15}],9:[function(require,module,exports){
  1806. /* global $, Util, nickname:true, showToolbar */
  1807. var Replacement = require("./Replacement");
  1808. var CommandsProcessor = require("./Commands");
  1809. var ToolbarToggler = require("../../toolbars/ToolbarToggler");
  1810. var smileys = require("./smileys.json").smileys;
  1811. var notificationInterval = false;
  1812. var unreadMessages = 0;
  1813. /**
  1814. * Shows/hides a visual notification, indicating that a message has arrived.
  1815. */
  1816. function setVisualNotification(show) {
  1817. var unreadMsgElement = document.getElementById('unreadMessages');
  1818. var unreadMsgBottomElement
  1819. = document.getElementById('bottomUnreadMessages');
  1820. var glower = $('#chatButton');
  1821. var bottomGlower = $('#chatBottomButton');
  1822. if (unreadMessages) {
  1823. unreadMsgElement.innerHTML = unreadMessages.toString();
  1824. unreadMsgBottomElement.innerHTML = unreadMessages.toString();
  1825. ToolbarToggler.dockToolbar(true);
  1826. var chatButtonElement
  1827. = document.getElementById('chatButton').parentNode;
  1828. var leftIndent = (Util.getTextWidth(chatButtonElement) -
  1829. Util.getTextWidth(unreadMsgElement)) / 2;
  1830. var topIndent = (Util.getTextHeight(chatButtonElement) -
  1831. Util.getTextHeight(unreadMsgElement)) / 2 - 3;
  1832. unreadMsgElement.setAttribute(
  1833. 'style',
  1834. 'top:' + topIndent +
  1835. '; left:' + leftIndent + ';');
  1836. var chatBottomButtonElement
  1837. = document.getElementById('chatBottomButton').parentNode;
  1838. var bottomLeftIndent = (Util.getTextWidth(chatBottomButtonElement) -
  1839. Util.getTextWidth(unreadMsgBottomElement)) / 2;
  1840. var bottomTopIndent = (Util.getTextHeight(chatBottomButtonElement) -
  1841. Util.getTextHeight(unreadMsgBottomElement)) / 2 - 2;
  1842. unreadMsgBottomElement.setAttribute(
  1843. 'style',
  1844. 'top:' + bottomTopIndent +
  1845. '; left:' + bottomLeftIndent + ';');
  1846. if (!glower.hasClass('icon-chat-simple')) {
  1847. glower.removeClass('icon-chat');
  1848. glower.addClass('icon-chat-simple');
  1849. }
  1850. }
  1851. else {
  1852. unreadMsgElement.innerHTML = '';
  1853. unreadMsgBottomElement.innerHTML = '';
  1854. glower.removeClass('icon-chat-simple');
  1855. glower.addClass('icon-chat');
  1856. }
  1857. if (show && !notificationInterval) {
  1858. notificationInterval = window.setInterval(function () {
  1859. glower.toggleClass('active');
  1860. bottomGlower.toggleClass('active glowing');
  1861. }, 800);
  1862. }
  1863. else if (!show && notificationInterval) {
  1864. window.clearInterval(notificationInterval);
  1865. notificationInterval = false;
  1866. glower.removeClass('active');
  1867. bottomGlower.removeClass('glowing');
  1868. bottomGlower.addClass('active');
  1869. }
  1870. }
  1871. /**
  1872. * Returns the current time in the format it is shown to the user
  1873. * @returns {string}
  1874. */
  1875. function getCurrentTime() {
  1876. var now = new Date();
  1877. var hour = now.getHours();
  1878. var minute = now.getMinutes();
  1879. var second = now.getSeconds();
  1880. if(hour.toString().length === 1) {
  1881. hour = '0'+hour;
  1882. }
  1883. if(minute.toString().length === 1) {
  1884. minute = '0'+minute;
  1885. }
  1886. if(second.toString().length === 1) {
  1887. second = '0'+second;
  1888. }
  1889. return hour+':'+minute+':'+second;
  1890. }
  1891. function toggleSmileys()
  1892. {
  1893. var smileys = $('#smileysContainer');
  1894. if(!smileys.is(':visible')) {
  1895. smileys.show("slide", { direction: "down", duration: 300});
  1896. } else {
  1897. smileys.hide("slide", { direction: "down", duration: 300});
  1898. }
  1899. $('#usermsg').focus();
  1900. }
  1901. function addClickFunction(smiley, number) {
  1902. smiley.onclick = function addSmileyToMessage() {
  1903. var usermsg = $('#usermsg');
  1904. var message = usermsg.val();
  1905. message += smileys['smiley' + number];
  1906. usermsg.val(message);
  1907. usermsg.get(0).setSelectionRange(message.length, message.length);
  1908. toggleSmileys();
  1909. usermsg.focus();
  1910. };
  1911. }
  1912. /**
  1913. * Adds the smileys container to the chat
  1914. */
  1915. function addSmileys() {
  1916. var smileysContainer = document.createElement('div');
  1917. smileysContainer.id = 'smileysContainer';
  1918. for(var i = 1; i <= 21; i++) {
  1919. var smileyContainer = document.createElement('div');
  1920. smileyContainer.id = 'smiley' + i;
  1921. smileyContainer.className = 'smileyContainer';
  1922. var smiley = document.createElement('img');
  1923. smiley.src = 'images/smileys/smiley' + i + '.svg';
  1924. smiley.className = 'smiley';
  1925. addClickFunction(smiley, i);
  1926. smileyContainer.appendChild(smiley);
  1927. smileysContainer.appendChild(smileyContainer);
  1928. }
  1929. $("#chatspace").append(smileysContainer);
  1930. }
  1931. /**
  1932. * Resizes the chat conversation.
  1933. */
  1934. function resizeChatConversation() {
  1935. var msgareaHeight = $('#usermsg').outerHeight();
  1936. var chatspace = $('#chatspace');
  1937. var width = chatspace.width();
  1938. var chat = $('#chatconversation');
  1939. var smileys = $('#smileysarea');
  1940. smileys.height(msgareaHeight);
  1941. $("#smileys").css('bottom', (msgareaHeight - 26) / 2);
  1942. $('#smileysContainer').css('bottom', msgareaHeight);
  1943. chat.width(width - 10);
  1944. chat.height(window.innerHeight - 15 - msgareaHeight);
  1945. }
  1946. /**
  1947. * Chat related user interface.
  1948. */
  1949. var Chat = (function (my) {
  1950. /**
  1951. * Initializes chat related interface.
  1952. */
  1953. my.init = function () {
  1954. var storedDisplayName = window.localStorage.displayname;
  1955. if (storedDisplayName) {
  1956. nickname = storedDisplayName;
  1957. Chat.setChatConversationMode(true);
  1958. }
  1959. $('#nickinput').keydown(function (event) {
  1960. if (event.keyCode === 13) {
  1961. event.preventDefault();
  1962. var val = Util.escapeHtml(this.value);
  1963. this.value = '';
  1964. if (!nickname) {
  1965. nickname = val;
  1966. window.localStorage.displayname = nickname;
  1967. xmpp.addToPresence("displayName", nickname);
  1968. Chat.setChatConversationMode(true);
  1969. return;
  1970. }
  1971. }
  1972. });
  1973. $('#usermsg').keydown(function (event) {
  1974. if (event.keyCode === 13) {
  1975. event.preventDefault();
  1976. var value = this.value;
  1977. $('#usermsg').val('').trigger('autosize.resize');
  1978. this.focus();
  1979. var command = new CommandsProcessor(value);
  1980. if(command.isCommand())
  1981. {
  1982. command.processCommand();
  1983. }
  1984. else
  1985. {
  1986. var message = Util.escapeHtml(value);
  1987. xmpp.sendChatMessage(message, nickname);
  1988. }
  1989. }
  1990. });
  1991. var onTextAreaResize = function () {
  1992. resizeChatConversation();
  1993. Chat.scrollChatToBottom();
  1994. };
  1995. $('#usermsg').autosize({callback: onTextAreaResize});
  1996. $("#chatspace").bind("shown",
  1997. function () {
  1998. unreadMessages = 0;
  1999. setVisualNotification(false);
  2000. });
  2001. addSmileys();
  2002. };
  2003. /**
  2004. * Appends the given message to the chat conversation.
  2005. */
  2006. my.updateChatConversation = function (from, displayName, message) {
  2007. var divClassName = '';
  2008. if (xmpp.myJid() === from) {
  2009. divClassName = "localuser";
  2010. }
  2011. else {
  2012. divClassName = "remoteuser";
  2013. if (!Chat.isVisible()) {
  2014. unreadMessages++;
  2015. Util.playSoundNotification('chatNotification');
  2016. setVisualNotification(true);
  2017. }
  2018. }
  2019. // replace links and smileys
  2020. // Strophe already escapes special symbols on sending,
  2021. // so we escape here only tags to avoid double &amp;
  2022. var escMessage = message.replace(/</g, '&lt;').
  2023. replace(/>/g, '&gt;').replace(/\n/g, '<br/>');
  2024. var escDisplayName = Util.escapeHtml(displayName);
  2025. message = Replacement.processReplacements(escMessage);
  2026. var messageContainer =
  2027. '<div class="chatmessage">'+
  2028. '<img src="../images/chatArrow.svg" class="chatArrow">' +
  2029. '<div class="username ' + divClassName +'">' + escDisplayName +
  2030. '</div>' + '<div class="timestamp">' + getCurrentTime() +
  2031. '</div>' + '<div class="usermessage">' + message + '</div>' +
  2032. '</div>';
  2033. $('#chatconversation').append(messageContainer);
  2034. $('#chatconversation').animate(
  2035. { scrollTop: $('#chatconversation')[0].scrollHeight}, 1000);
  2036. };
  2037. /**
  2038. * Appends error message to the conversation
  2039. * @param errorMessage the received error message.
  2040. * @param originalText the original message.
  2041. */
  2042. my.chatAddError = function(errorMessage, originalText)
  2043. {
  2044. errorMessage = Util.escapeHtml(errorMessage);
  2045. originalText = Util.escapeHtml(originalText);
  2046. $('#chatconversation').append(
  2047. '<div class="errorMessage"><b>Error: </b>' + 'Your message' +
  2048. (originalText? (' \"'+ originalText + '\"') : "") +
  2049. ' was not sent.' +
  2050. (errorMessage? (' Reason: ' + errorMessage) : '') + '</div>');
  2051. $('#chatconversation').animate(
  2052. { scrollTop: $('#chatconversation')[0].scrollHeight}, 1000);
  2053. };
  2054. /**
  2055. * Sets the subject to the UI
  2056. * @param subject the subject
  2057. */
  2058. my.chatSetSubject = function(subject)
  2059. {
  2060. if(subject)
  2061. subject = subject.trim();
  2062. $('#subject').html(Replacement.linkify(Util.escapeHtml(subject)));
  2063. if(subject === "")
  2064. {
  2065. $("#subject").css({display: "none"});
  2066. }
  2067. else
  2068. {
  2069. $("#subject").css({display: "block"});
  2070. }
  2071. };
  2072. /**
  2073. * Sets the chat conversation mode.
  2074. */
  2075. my.setChatConversationMode = function (isConversationMode) {
  2076. if (isConversationMode) {
  2077. $('#nickname').css({visibility: 'hidden'});
  2078. $('#chatconversation').css({visibility: 'visible'});
  2079. $('#usermsg').css({visibility: 'visible'});
  2080. $('#smileysarea').css({visibility: 'visible'});
  2081. $('#usermsg').focus();
  2082. }
  2083. };
  2084. /**
  2085. * Resizes the chat area.
  2086. */
  2087. my.resizeChat = function () {
  2088. var chatSize = require("../SidePanelToggler").getPanelSize();
  2089. $('#chatspace').width(chatSize[0]);
  2090. $('#chatspace').height(chatSize[1]);
  2091. resizeChatConversation();
  2092. };
  2093. /**
  2094. * Indicates if the chat is currently visible.
  2095. */
  2096. my.isVisible = function () {
  2097. return $('#chatspace').is(":visible");
  2098. };
  2099. /**
  2100. * Shows and hides the window with the smileys
  2101. */
  2102. my.toggleSmileys = toggleSmileys;
  2103. /**
  2104. * Scrolls chat to the bottom.
  2105. */
  2106. my.scrollChatToBottom = function() {
  2107. setTimeout(function () {
  2108. $('#chatconversation').scrollTop(
  2109. $('#chatconversation')[0].scrollHeight);
  2110. }, 5);
  2111. };
  2112. return my;
  2113. }(Chat || {}));
  2114. module.exports = Chat;
  2115. },{"../../toolbars/ToolbarToggler":17,"../SidePanelToggler":8,"./Commands":10,"./Replacement":11,"./smileys.json":12}],10:[function(require,module,exports){
  2116. /**
  2117. * List with supported commands. The keys are the names of the commands and
  2118. * the value is the function that processes the message.
  2119. * @type {{String: function}}
  2120. */
  2121. var commands = {
  2122. "topic" : processTopic
  2123. };
  2124. /**
  2125. * Extracts the command from the message.
  2126. * @param message the received message
  2127. * @returns {string} the command
  2128. */
  2129. function getCommand(message)
  2130. {
  2131. if(message)
  2132. {
  2133. for(var command in commands)
  2134. {
  2135. if(message.indexOf("/" + command) == 0)
  2136. return command;
  2137. }
  2138. }
  2139. return "";
  2140. };
  2141. /**
  2142. * Processes the data for topic command.
  2143. * @param commandArguments the arguments of the topic command.
  2144. */
  2145. function processTopic(commandArguments)
  2146. {
  2147. var topic = Util.escapeHtml(commandArguments);
  2148. xmpp.setSubject(topic);
  2149. }
  2150. /**
  2151. * Constructs new CommandProccessor instance from a message that
  2152. * handles commands received via chat messages.
  2153. * @param message the message
  2154. * @constructor
  2155. */
  2156. function CommandsProcessor(message)
  2157. {
  2158. var command = getCommand(message);
  2159. /**
  2160. * Returns the name of the command.
  2161. * @returns {String} the command
  2162. */
  2163. this.getCommand = function()
  2164. {
  2165. return command;
  2166. };
  2167. var messageArgument = message.substr(command.length + 2);
  2168. /**
  2169. * Returns the arguments of the command.
  2170. * @returns {string}
  2171. */
  2172. this.getArgument = function()
  2173. {
  2174. return messageArgument;
  2175. };
  2176. }
  2177. /**
  2178. * Checks whether this instance is valid command or not.
  2179. * @returns {boolean}
  2180. */
  2181. CommandsProcessor.prototype.isCommand = function()
  2182. {
  2183. if(this.getCommand())
  2184. return true;
  2185. return false;
  2186. };
  2187. /**
  2188. * Processes the command.
  2189. */
  2190. CommandsProcessor.prototype.processCommand = function()
  2191. {
  2192. if(!this.isCommand())
  2193. return;
  2194. commands[this.getCommand()](this.getArgument());
  2195. };
  2196. module.exports = CommandsProcessor;
  2197. },{}],11:[function(require,module,exports){
  2198. var Smileys = require("./smileys.json");
  2199. /**
  2200. * Processes links and smileys in "body"
  2201. */
  2202. function processReplacements(body)
  2203. {
  2204. //make links clickable
  2205. body = linkify(body);
  2206. //add smileys
  2207. body = smilify(body);
  2208. return body;
  2209. }
  2210. /**
  2211. * Finds and replaces all links in the links in "body"
  2212. * with their <a href=""></a>
  2213. */
  2214. function linkify(inputText)
  2215. {
  2216. var replacedText, replacePattern1, replacePattern2, replacePattern3;
  2217. //URLs starting with http://, https://, or ftp://
  2218. replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
  2219. replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
  2220. //URLs starting with "www." (without // before it, or it'd re-link the ones done above).
  2221. replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
  2222. replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
  2223. //Change email addresses to mailto:: links.
  2224. replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
  2225. replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
  2226. return replacedText;
  2227. }
  2228. /**
  2229. * Replaces common smiley strings with images
  2230. */
  2231. function smilify(body)
  2232. {
  2233. if(!body) {
  2234. return body;
  2235. }
  2236. var regexs = Smileys["regexs"];
  2237. for(var smiley in regexs) {
  2238. if(regexs.hasOwnProperty(smiley)) {
  2239. body = body.replace(regexs[smiley],
  2240. '<img class="smiley" src="images/smileys/' + smiley + '.svg">');
  2241. }
  2242. }
  2243. return body;
  2244. }
  2245. module.exports = {
  2246. processReplacements: processReplacements,
  2247. linkify: linkify
  2248. };
  2249. },{"./smileys.json":12}],12:[function(require,module,exports){
  2250. module.exports={
  2251. "smileys": {
  2252. "smiley1": ":)",
  2253. "smiley2": ":(",
  2254. "smiley3": ":D",
  2255. "smiley4": "(y)",
  2256. "smiley5": " :P",
  2257. "smiley6": "(wave)",
  2258. "smiley7": "(blush)",
  2259. "smiley8": "(chuckle)",
  2260. "smiley9": "(shocked)",
  2261. "smiley10": ":*",
  2262. "smiley11": "(n)",
  2263. "smiley12": "(search)",
  2264. "smiley13": " <3",
  2265. "smiley14": "(oops)",
  2266. "smiley15": "(angry)",
  2267. "smiley16": "(angel)",
  2268. "smiley17": "(sick)",
  2269. "smiley18": ";(",
  2270. "smiley19": "(bomb)",
  2271. "smiley20": "(clap)",
  2272. "smiley21": " ;)"
  2273. },
  2274. "regexs": {
  2275. "smiley2": /(:-\(\(|:-\(|:\(\(|:\(|\(sad\))/gi,
  2276. "smiley3": /(:-\)\)|:\)\)|\(lol\)|:-D|:D)/gi,
  2277. "smiley1": /(:-\)|:\))/gi,
  2278. "smiley4": /(\(y\)|\(Y\)|\(ok\))/gi,
  2279. "smiley5": /(:-P|:P|:-p|:p)/gi,
  2280. "smiley6": /(\(wave\))/gi,
  2281. "smiley7": /(\(blush\))/gi,
  2282. "smiley8": /(\(chuckle\))/gi,
  2283. "smiley9": /(:-0|\(shocked\))/gi,
  2284. "smiley10": /(:-\*|:\*|\(kiss\))/gi,
  2285. "smiley11": /(\(n\))/gi,
  2286. "smiley12": /(\(search\))/g,
  2287. "smiley13": /(<3|&lt;3|&amp;lt;3|\(L\)|\(l\)|\(H\)|\(h\))/gi,
  2288. "smiley14": /(\(oops\))/gi,
  2289. "smiley15": /(\(angry\))/gi,
  2290. "smiley16": /(\(angel\))/gi,
  2291. "smiley17": /(\(sick\))/gi,
  2292. "smiley18": /(;-\(\(|;\(\(|;-\(|;\(|:"\(|:"-\(|:~-\(|:~\(|\(upset\))/gi,
  2293. "smiley19": /(\(bomb\))/gi,
  2294. "smiley20": /(\(clap\))/gi,
  2295. "smiley21": /(;-\)|;\)|;-\)\)|;\)\)|;-D|;D|\(wink\))/gi
  2296. }
  2297. }
  2298. },{}],13:[function(require,module,exports){
  2299. var numberOfContacts = 0;
  2300. var notificationInterval;
  2301. /**
  2302. * Updates the number of participants in the contact list button and sets
  2303. * the glow
  2304. * @param delta indicates whether a new user has joined (1) or someone has
  2305. * left(-1)
  2306. */
  2307. function updateNumberOfParticipants(delta) {
  2308. //when the user is alone we don't show the number of participants
  2309. if(numberOfContacts === 0) {
  2310. $("#numberOfParticipants").text('');
  2311. numberOfContacts += delta;
  2312. } else if(numberOfContacts !== 0 && !ContactList.isVisible()) {
  2313. ContactList.setVisualNotification(true);
  2314. numberOfContacts += delta;
  2315. $("#numberOfParticipants").text(numberOfContacts);
  2316. }
  2317. }
  2318. /**
  2319. * Creates the avatar element.
  2320. *
  2321. * @return the newly created avatar element
  2322. */
  2323. function createAvatar(id) {
  2324. var avatar = document.createElement('img');
  2325. avatar.className = "icon-avatar avatar";
  2326. avatar.src = "https://www.gravatar.com/avatar/" + id + "?d=wavatar&size=30";
  2327. return avatar;
  2328. }
  2329. /**
  2330. * Creates the display name paragraph.
  2331. *
  2332. * @param displayName the display name to set
  2333. */
  2334. function createDisplayNameParagraph(displayName) {
  2335. var p = document.createElement('p');
  2336. p.innerText = displayName;
  2337. return p;
  2338. }
  2339. function stopGlowing(glower) {
  2340. window.clearInterval(notificationInterval);
  2341. notificationInterval = false;
  2342. glower.removeClass('glowing');
  2343. if (!ContactList.isVisible()) {
  2344. glower.removeClass('active');
  2345. }
  2346. }
  2347. /**
  2348. * Contact list.
  2349. */
  2350. var ContactList = {
  2351. /**
  2352. * Indicates if the chat is currently visible.
  2353. *
  2354. * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
  2355. * otherwise
  2356. */
  2357. isVisible: function () {
  2358. return $('#contactlist').is(":visible");
  2359. },
  2360. /**
  2361. * Adds a contact for the given peerJid if such doesn't yet exist.
  2362. *
  2363. * @param peerJid the peerJid corresponding to the contact
  2364. * @param id the user's email or userId used to get the user's avatar
  2365. */
  2366. ensureAddContact: function (peerJid, id) {
  2367. var resourceJid = Strophe.getResourceFromJid(peerJid);
  2368. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  2369. if (!contact || contact.length <= 0)
  2370. ContactList.addContact(peerJid, id);
  2371. },
  2372. /**
  2373. * Adds a contact for the given peer jid.
  2374. *
  2375. * @param peerJid the jid of the contact to add
  2376. * @param id the email or userId of the user
  2377. */
  2378. addContact: function (peerJid, id) {
  2379. var resourceJid = Strophe.getResourceFromJid(peerJid);
  2380. var contactlist = $('#contactlist>ul');
  2381. var newContact = document.createElement('li');
  2382. newContact.id = resourceJid;
  2383. newContact.className = "clickable";
  2384. newContact.onclick = function (event) {
  2385. if (event.currentTarget.className === "clickable") {
  2386. $(ContactList).trigger('contactclicked', [peerJid]);
  2387. }
  2388. };
  2389. newContact.appendChild(createAvatar(id));
  2390. newContact.appendChild(createDisplayNameParagraph("Participant"));
  2391. var clElement = contactlist.get(0);
  2392. if (resourceJid === xmpp.myResource()
  2393. && $('#contactlist>ul .title')[0].nextSibling.nextSibling) {
  2394. clElement.insertBefore(newContact,
  2395. $('#contactlist>ul .title')[0].nextSibling.nextSibling);
  2396. }
  2397. else {
  2398. clElement.appendChild(newContact);
  2399. }
  2400. updateNumberOfParticipants(1);
  2401. },
  2402. /**
  2403. * Removes a contact for the given peer jid.
  2404. *
  2405. * @param peerJid the peerJid corresponding to the contact to remove
  2406. */
  2407. removeContact: function (peerJid) {
  2408. var resourceJid = Strophe.getResourceFromJid(peerJid);
  2409. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  2410. if (contact && contact.length > 0) {
  2411. var contactlist = $('#contactlist>ul');
  2412. contactlist.get(0).removeChild(contact.get(0));
  2413. updateNumberOfParticipants(-1);
  2414. }
  2415. },
  2416. setVisualNotification: function (show, stopGlowingIn) {
  2417. var glower = $('#contactListButton');
  2418. if (show && !notificationInterval) {
  2419. notificationInterval = window.setInterval(function () {
  2420. glower.toggleClass('active glowing');
  2421. }, 800);
  2422. }
  2423. else if (!show && notificationInterval) {
  2424. stopGlowing(glower);
  2425. }
  2426. if (stopGlowingIn) {
  2427. setTimeout(function () {
  2428. stopGlowing(glower);
  2429. }, stopGlowingIn);
  2430. }
  2431. },
  2432. setClickable: function (resourceJid, isClickable) {
  2433. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  2434. if (isClickable) {
  2435. contact.addClass('clickable');
  2436. } else {
  2437. contact.removeClass('clickable');
  2438. }
  2439. },
  2440. onDisplayNameChange: function (peerJid, displayName) {
  2441. if (peerJid === 'localVideoContainer')
  2442. peerJid = xmpp.myJid();
  2443. var resourceJid = Strophe.getResourceFromJid(peerJid);
  2444. var contactName = $('#contactlist #' + resourceJid + '>p');
  2445. if (contactName && displayName && displayName.length > 0)
  2446. contactName.html(displayName);
  2447. }
  2448. };
  2449. module.exports = ContactList;
  2450. },{}],14:[function(require,module,exports){
  2451. var email = '';
  2452. var displayName = '';
  2453. var userId;
  2454. function supportsLocalStorage() {
  2455. try {
  2456. return 'localStorage' in window && window.localStorage !== null;
  2457. } catch (e) {
  2458. console.log("localstorage is not supported");
  2459. return false;
  2460. }
  2461. }
  2462. function generateUniqueId() {
  2463. function _p8() {
  2464. return (Math.random().toString(16)+"000000000").substr(2,8);
  2465. }
  2466. return _p8() + _p8() + _p8() + _p8();
  2467. }
  2468. if(supportsLocalStorage()) {
  2469. if(!window.localStorage.jitsiMeetId) {
  2470. window.localStorage.jitsiMeetId = generateUniqueId();
  2471. console.log("generated id", window.localStorage.jitsiMeetId);
  2472. }
  2473. userId = window.localStorage.jitsiMeetId || '';
  2474. email = window.localStorage.email || '';
  2475. displayName = window.localStorage.displayname || '';
  2476. } else {
  2477. console.log("local storage is not supported");
  2478. userId = generateUniqueId();
  2479. }
  2480. var Settings =
  2481. {
  2482. setDisplayName: function (newDisplayName) {
  2483. displayName = newDisplayName;
  2484. window.localStorage.displayname = displayName;
  2485. return displayName;
  2486. },
  2487. setEmail: function(newEmail)
  2488. {
  2489. email = newEmail;
  2490. window.localStorage.email = newEmail;
  2491. return email;
  2492. },
  2493. getSettings: function () {
  2494. return {
  2495. email: email,
  2496. displayName: displayName,
  2497. uid: userId
  2498. };
  2499. }
  2500. };
  2501. module.exports = Settings;
  2502. },{}],15:[function(require,module,exports){
  2503. var Avatar = require("../../avatar/Avatar");
  2504. var Settings = require("./Settings");
  2505. var SettingsMenu = {
  2506. update: function() {
  2507. var newDisplayName = Util.escapeHtml($('#setDisplayName').get(0).value);
  2508. var newEmail = Util.escapeHtml($('#setEmail').get(0).value);
  2509. if(newDisplayName) {
  2510. var displayName = Settings.setDisplayName(newDisplayName);
  2511. xmpp.addToPresence("displayName", displayName, true);
  2512. }
  2513. xmpp.addToPresence("email", newEmail);
  2514. var email = Settings.setEmail(newEmail);
  2515. Avatar.setUserAvatar(xmpp.myJid(), email);
  2516. },
  2517. isVisible: function() {
  2518. return $('#settingsmenu').is(':visible');
  2519. },
  2520. setDisplayName: function(newDisplayName) {
  2521. var displayName = Settings.setDisplayName(newDisplayName);
  2522. $('#setDisplayName').get(0).value = displayName;
  2523. },
  2524. onDisplayNameChange: function(peerJid, newDisplayName) {
  2525. if(peerJid === 'localVideoContainer' ||
  2526. peerJid === xmpp.myJid()) {
  2527. this.setDisplayName(newDisplayName);
  2528. }
  2529. }
  2530. };
  2531. module.exports = SettingsMenu;
  2532. },{"../../avatar/Avatar":5,"./Settings":14}],16:[function(require,module,exports){
  2533. var PanelToggler = require("../side_pannels/SidePanelToggler");
  2534. var buttonHandlers = {
  2535. "bottom_toolbar_contact_list": function () {
  2536. BottomToolbar.toggleContactList();
  2537. },
  2538. "bottom_toolbar_film_strip": function () {
  2539. BottomToolbar.toggleFilmStrip();
  2540. },
  2541. "bottom_toolbar_chat": function () {
  2542. BottomToolbar.toggleChat();
  2543. }
  2544. };
  2545. var BottomToolbar = (function (my) {
  2546. my.init = function () {
  2547. for(var k in buttonHandlers)
  2548. $("#" + k).click(buttonHandlers[k]);
  2549. };
  2550. my.toggleChat = function() {
  2551. PanelToggler.toggleChat();
  2552. };
  2553. my.toggleContactList = function() {
  2554. PanelToggler.toggleContactList();
  2555. };
  2556. my.toggleFilmStrip = function() {
  2557. var filmstrip = $("#remoteVideos");
  2558. filmstrip.toggleClass("hidden");
  2559. };
  2560. $(document).bind("remotevideo.resized", function (event, width, height) {
  2561. var bottom = (height - $('#bottomToolbar').outerHeight())/2 + 18;
  2562. $('#bottomToolbar').css({bottom: bottom + 'px'});
  2563. });
  2564. return my;
  2565. }(BottomToolbar || {}));
  2566. module.exports = BottomToolbar;
  2567. },{"../side_pannels/SidePanelToggler":8}],17:[function(require,module,exports){
  2568. /* global $, interfaceConfig, Moderator, DesktopStreaming.showDesktopSharingButton */
  2569. var toolbarTimeoutObject,
  2570. toolbarTimeout = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
  2571. function showDesktopSharingButton() {
  2572. if (desktopsharing.isDesktopSharingEnabled()) {
  2573. $('#desktopsharing').css({display: "inline"});
  2574. } else {
  2575. $('#desktopsharing').css({display: "none"});
  2576. }
  2577. }
  2578. /**
  2579. * Hides the toolbar.
  2580. */
  2581. function hideToolbar() {
  2582. var header = $("#header"),
  2583. bottomToolbar = $("#bottomToolbar");
  2584. var isToolbarHover = false;
  2585. header.find('*').each(function () {
  2586. var id = $(this).attr('id');
  2587. if ($("#" + id + ":hover").length > 0) {
  2588. isToolbarHover = true;
  2589. }
  2590. });
  2591. if ($("#bottomToolbar:hover").length > 0) {
  2592. isToolbarHover = true;
  2593. }
  2594. clearTimeout(toolbarTimeoutObject);
  2595. toolbarTimeoutObject = null;
  2596. if (!isToolbarHover) {
  2597. header.hide("slide", { direction: "up", duration: 300});
  2598. $('#subject').animate({top: "-=40"}, 300);
  2599. if ($("#remoteVideos").hasClass("hidden")) {
  2600. bottomToolbar.hide(
  2601. "slide", {direction: "right", duration: 300});
  2602. }
  2603. }
  2604. else {
  2605. toolbarTimeoutObject = setTimeout(hideToolbar, toolbarTimeout);
  2606. }
  2607. }
  2608. var ToolbarToggler = {
  2609. /**
  2610. * Shows the main toolbar.
  2611. */
  2612. showToolbar: function () {
  2613. var header = $("#header"),
  2614. bottomToolbar = $("#bottomToolbar");
  2615. if (!header.is(':visible') || !bottomToolbar.is(":visible")) {
  2616. header.show("slide", { direction: "up", duration: 300});
  2617. $('#subject').animate({top: "+=40"}, 300);
  2618. if (!bottomToolbar.is(":visible")) {
  2619. bottomToolbar.show(
  2620. "slide", {direction: "right", duration: 300});
  2621. }
  2622. if (toolbarTimeoutObject) {
  2623. clearTimeout(toolbarTimeoutObject);
  2624. toolbarTimeoutObject = null;
  2625. }
  2626. toolbarTimeoutObject = setTimeout(hideToolbar, toolbarTimeout);
  2627. toolbarTimeout = interfaceConfig.TOOLBAR_TIMEOUT;
  2628. }
  2629. if (xmpp.isModerator())
  2630. {
  2631. // TODO: Enable settings functionality.
  2632. // Need to uncomment the settings button in index.html.
  2633. // $('#settingsButton').css({visibility:"visible"});
  2634. }
  2635. // Show/hide desktop sharing button
  2636. showDesktopSharingButton();
  2637. },
  2638. /**
  2639. * Docks/undocks the toolbar.
  2640. *
  2641. * @param isDock indicates what operation to perform
  2642. */
  2643. dockToolbar: function (isDock) {
  2644. if (isDock) {
  2645. // First make sure the toolbar is shown.
  2646. if (!$('#header').is(':visible')) {
  2647. this.showToolbar();
  2648. }
  2649. // Then clear the time out, to dock the toolbar.
  2650. if (toolbarTimeoutObject) {
  2651. clearTimeout(toolbarTimeoutObject);
  2652. toolbarTimeoutObject = null;
  2653. }
  2654. }
  2655. else {
  2656. if (!$('#header').is(':visible')) {
  2657. this.showToolbar();
  2658. }
  2659. else {
  2660. toolbarTimeoutObject = setTimeout(hideToolbar, toolbarTimeout);
  2661. }
  2662. }
  2663. },
  2664. showDesktopSharingButton: showDesktopSharingButton
  2665. };
  2666. module.exports = ToolbarToggler;
  2667. },{}],18:[function(require,module,exports){
  2668. /* global $, buttonClick, config, lockRoom,
  2669. setSharedKey, Util */
  2670. var messageHandler = require("../util/MessageHandler");
  2671. var BottomToolbar = require("./BottomToolbar");
  2672. var Prezi = require("../prezi/Prezi");
  2673. var Etherpad = require("../etherpad/Etherpad");
  2674. var PanelToggler = require("../side_pannels/SidePanelToggler");
  2675. var Authentication = require("../authentication/Authentication");
  2676. var UIUtil = require("../util/UIUtil");
  2677. var roomUrl = null;
  2678. var sharedKey = '';
  2679. var UI = null;
  2680. var buttonHandlers =
  2681. {
  2682. "toolbar_button_mute": function () {
  2683. return UI.toggleAudio();
  2684. },
  2685. "toolbar_button_camera": function () {
  2686. return UI.toggleVideo();
  2687. },
  2688. "toolbar_button_authentication": function () {
  2689. return Toolbar.authenticateClicked();
  2690. },
  2691. "toolbar_button_record": function () {
  2692. return toggleRecording();
  2693. },
  2694. "toolbar_button_security": function () {
  2695. return Toolbar.openLockDialog();
  2696. },
  2697. "toolbar_button_link": function () {
  2698. return Toolbar.openLinkDialog();
  2699. },
  2700. "toolbar_button_chat": function () {
  2701. return BottomToolbar.toggleChat();
  2702. },
  2703. "toolbar_button_prezi": function () {
  2704. return Prezi.openPreziDialog();
  2705. },
  2706. "toolbar_button_etherpad": function () {
  2707. return Etherpad.toggleEtherpad(0);
  2708. },
  2709. "toolbar_button_desktopsharing": function () {
  2710. return desktopsharing.toggleScreenSharing();
  2711. },
  2712. "toolbar_button_fullScreen": function()
  2713. {
  2714. UIUtil.buttonClick("#fullScreen", "icon-full-screen icon-exit-full-screen");
  2715. return Toolbar.toggleFullScreen();
  2716. },
  2717. "toolbar_button_sip": function () {
  2718. return callSipButtonClicked();
  2719. },
  2720. "toolbar_button_settings": function () {
  2721. PanelToggler.toggleSettingsMenu();
  2722. },
  2723. "toolbar_button_hangup": function () {
  2724. return hangup();
  2725. }
  2726. };
  2727. function hangup() {
  2728. xmpp.disposeConference();
  2729. if(config.enableWelcomePage)
  2730. {
  2731. setTimeout(function()
  2732. {
  2733. window.localStorage.welcomePageDisabled = false;
  2734. window.location.pathname = "/";
  2735. }, 10000);
  2736. }
  2737. UI.messageHandler.openDialog(
  2738. "Session Terminated",
  2739. "You hung up the call",
  2740. true,
  2741. { "Join again": true },
  2742. function(event, value, message, formVals)
  2743. {
  2744. window.location.reload();
  2745. return false;
  2746. }
  2747. );
  2748. }
  2749. /**
  2750. * Starts or stops the recording for the conference.
  2751. */
  2752. function toggleRecording() {
  2753. xmpp.toggleRecording(function (callback) {
  2754. UI.messageHandler.openTwoButtonDialog(null,
  2755. '<h2>Enter recording token</h2>' +
  2756. '<input id="recordingToken" type="text" ' +
  2757. 'placeholder="token" autofocus>',
  2758. false,
  2759. "Save",
  2760. function (e, v, m, f) {
  2761. if (v) {
  2762. var token = document.getElementById('recordingToken');
  2763. if (token.value) {
  2764. callback(Util.escapeHtml(token.value));
  2765. }
  2766. }
  2767. },
  2768. function (event) {
  2769. document.getElementById('recordingToken').focus();
  2770. },
  2771. function () {
  2772. }
  2773. );
  2774. }, Toolbar.setRecordingButtonState, Toolbar.setRecordingButtonState);
  2775. }
  2776. /**
  2777. * Locks / unlocks the room.
  2778. */
  2779. function lockRoom(lock) {
  2780. var currentSharedKey = '';
  2781. if (lock)
  2782. currentSharedKey = sharedKey;
  2783. xmpp.lockRoom(currentSharedKey, function (res) {
  2784. // password is required
  2785. if (sharedKey)
  2786. {
  2787. console.log('set room password');
  2788. Toolbar.lockLockButton();
  2789. }
  2790. else
  2791. {
  2792. console.log('removed room password');
  2793. Toolbar.unlockLockButton();
  2794. }
  2795. }, function (err) {
  2796. console.warn('setting password failed', err);
  2797. messageHandler.showError('Lock failed',
  2798. 'Failed to lock conference.',
  2799. err);
  2800. Toolbar.setSharedKey('');
  2801. }, function () {
  2802. console.warn('room passwords not supported');
  2803. messageHandler.showError('Warning',
  2804. 'Room passwords are currently not supported.');
  2805. Toolbar.setSharedKey('');
  2806. });
  2807. };
  2808. /**
  2809. * Invite participants to conference.
  2810. */
  2811. function inviteParticipants() {
  2812. if (roomUrl === null)
  2813. return;
  2814. var sharedKeyText = "";
  2815. if (sharedKey && sharedKey.length > 0) {
  2816. sharedKeyText =
  2817. "This conference is password protected. Please use the " +
  2818. "following pin when joining:%0D%0A%0D%0A" +
  2819. sharedKey + "%0D%0A%0D%0A";
  2820. }
  2821. var conferenceName = roomUrl.substring(roomUrl.lastIndexOf('/') + 1);
  2822. var subject = "Invitation to a " + interfaceConfig.APP_NAME + " (" + conferenceName + ")";
  2823. var body = "Hey there, I%27d like to invite you to a " + interfaceConfig.APP_NAME +
  2824. " conference I%27ve just set up.%0D%0A%0D%0A" +
  2825. "Please click on the following link in order" +
  2826. " to join the conference.%0D%0A%0D%0A" +
  2827. roomUrl +
  2828. "%0D%0A%0D%0A" +
  2829. sharedKeyText +
  2830. "Note that " + interfaceConfig.APP_NAME + " is currently" +
  2831. " only supported by Chromium," +
  2832. " Google Chrome and Opera, so you need" +
  2833. " to be using one of these browsers.%0D%0A%0D%0A" +
  2834. "Talk to you in a sec!";
  2835. if (window.localStorage.displayname) {
  2836. body += "%0D%0A%0D%0A" + window.localStorage.displayname;
  2837. }
  2838. if (interfaceConfig.INVITATION_POWERED_BY) {
  2839. body += "%0D%0A%0D%0A--%0D%0Apowered by jitsi.org";
  2840. }
  2841. window.open("mailto:?subject=" + subject + "&body=" + body, '_blank');
  2842. }
  2843. function callSipButtonClicked()
  2844. {
  2845. var defaultNumber
  2846. = config.defaultSipNumber ? config.defaultSipNumber : '';
  2847. messageHandler.openTwoButtonDialog(null,
  2848. '<h2>Enter SIP number</h2>' +
  2849. '<input id="sipNumber" type="text"' +
  2850. ' value="' + defaultNumber + '" autofocus>',
  2851. false,
  2852. "Dial",
  2853. function (e, v, m, f) {
  2854. if (v) {
  2855. var numberInput = document.getElementById('sipNumber');
  2856. if (numberInput.value) {
  2857. xmpp.dial(numberInput.value, 'fromnumber',
  2858. UI.getRoomName(), sharedKey);
  2859. }
  2860. }
  2861. },
  2862. function (event) {
  2863. document.getElementById('sipNumber').focus();
  2864. }
  2865. );
  2866. }
  2867. var Toolbar = (function (my) {
  2868. my.init = function (ui) {
  2869. for(var k in buttonHandlers)
  2870. $("#" + k).click(buttonHandlers[k]);
  2871. UI = ui;
  2872. }
  2873. /**
  2874. * Sets shared key
  2875. * @param sKey the shared key
  2876. */
  2877. my.setSharedKey = function (sKey) {
  2878. sharedKey = sKey;
  2879. };
  2880. my.authenticateClicked = function () {
  2881. Authentication.focusAuthenticationWindow();
  2882. // Get authentication URL
  2883. xmpp.getAuthUrl(UI.getRoomName(), function (url) {
  2884. // Open popup with authentication URL
  2885. var authenticationWindow = Authentication.createAuthenticationWindow(function () {
  2886. // On popup closed - retry room allocation
  2887. xmpp.allocateConferenceFocus(UI.getRoomName(), UI.checkForNicknameAndJoin);
  2888. }, url);
  2889. if (!authenticationWindow) {
  2890. Toolbar.showAuthenticateButton(true);
  2891. messageHandler.openMessageDialog(
  2892. null, "Your browser is blocking popup windows from this site." +
  2893. " Please enable popups in your browser security settings" +
  2894. " and try again.");
  2895. }
  2896. });
  2897. };
  2898. /**
  2899. * Updates the room invite url.
  2900. */
  2901. my.updateRoomUrl = function (newRoomUrl) {
  2902. roomUrl = newRoomUrl;
  2903. // If the invite dialog has been already opened we update the information.
  2904. var inviteLink = document.getElementById('inviteLinkRef');
  2905. if (inviteLink) {
  2906. inviteLink.value = roomUrl;
  2907. inviteLink.select();
  2908. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  2909. }
  2910. };
  2911. /**
  2912. * Disables and enables some of the buttons.
  2913. */
  2914. my.setupButtonsFromConfig = function () {
  2915. if (config.disablePrezi)
  2916. {
  2917. $("#prezi_button").css({display: "none"});
  2918. }
  2919. };
  2920. /**
  2921. * Opens the lock room dialog.
  2922. */
  2923. my.openLockDialog = function () {
  2924. // Only the focus is able to set a shared key.
  2925. if (!xmpp.isModerator()) {
  2926. if (sharedKey) {
  2927. messageHandler.openMessageDialog(null,
  2928. "This conversation is currently protected by" +
  2929. " a password. Only the owner of the conference" +
  2930. " could set a password.",
  2931. false,
  2932. "Password");
  2933. } else {
  2934. messageHandler.openMessageDialog(null,
  2935. "This conversation isn't currently protected by" +
  2936. " a password. Only the owner of the conference" +
  2937. " could set a password.",
  2938. false,
  2939. "Password");
  2940. }
  2941. } else {
  2942. if (sharedKey) {
  2943. messageHandler.openTwoButtonDialog(null,
  2944. "Are you sure you would like to remove your password?",
  2945. false,
  2946. "Remove",
  2947. function (e, v) {
  2948. if (v) {
  2949. Toolbar.setSharedKey('');
  2950. lockRoom(false);
  2951. }
  2952. });
  2953. } else {
  2954. messageHandler.openTwoButtonDialog(null,
  2955. '<h2>Set a password to lock your room</h2>' +
  2956. '<input id="lockKey" type="text"' +
  2957. 'placeholder="your password" autofocus>',
  2958. false,
  2959. "Save",
  2960. function (e, v) {
  2961. if (v) {
  2962. var lockKey = document.getElementById('lockKey');
  2963. if (lockKey.value) {
  2964. Toolbar.setSharedKey(Util.escapeHtml(lockKey.value));
  2965. lockRoom(true);
  2966. }
  2967. }
  2968. },
  2969. function () {
  2970. document.getElementById('lockKey').focus();
  2971. }
  2972. );
  2973. }
  2974. }
  2975. };
  2976. /**
  2977. * Opens the invite link dialog.
  2978. */
  2979. my.openLinkDialog = function () {
  2980. var inviteLink;
  2981. if (roomUrl === null) {
  2982. inviteLink = "Your conference is currently being created...";
  2983. } else {
  2984. inviteLink = encodeURI(roomUrl);
  2985. }
  2986. messageHandler.openTwoButtonDialog(
  2987. "Share this link with everyone you want to invite",
  2988. '<input id="inviteLinkRef" type="text" value="' +
  2989. inviteLink + '" onclick="this.select();" readonly>',
  2990. false,
  2991. "Invite",
  2992. function (e, v) {
  2993. if (v) {
  2994. if (roomUrl) {
  2995. inviteParticipants();
  2996. }
  2997. }
  2998. },
  2999. function () {
  3000. if (roomUrl) {
  3001. document.getElementById('inviteLinkRef').select();
  3002. } else {
  3003. document.getElementById('jqi_state0_buttonInvite')
  3004. .disabled = true;
  3005. }
  3006. }
  3007. );
  3008. };
  3009. /**
  3010. * Opens the settings dialog.
  3011. */
  3012. my.openSettingsDialog = function () {
  3013. messageHandler.openTwoButtonDialog(
  3014. '<h2>Configure your conference</h2>' +
  3015. '<input type="checkbox" id="initMuted">' +
  3016. 'Participants join muted<br/>' +
  3017. '<input type="checkbox" id="requireNicknames">' +
  3018. 'Require nicknames<br/><br/>' +
  3019. 'Set a password to lock your room:' +
  3020. '<input id="lockKey" type="text" placeholder="your password"' +
  3021. 'autofocus>',
  3022. null,
  3023. false,
  3024. "Save",
  3025. function () {
  3026. document.getElementById('lockKey').focus();
  3027. },
  3028. function (e, v) {
  3029. if (v) {
  3030. if ($('#initMuted').is(":checked")) {
  3031. // it is checked
  3032. }
  3033. if ($('#requireNicknames').is(":checked")) {
  3034. // it is checked
  3035. }
  3036. /*
  3037. var lockKey = document.getElementById('lockKey');
  3038. if (lockKey.value) {
  3039. setSharedKey(lockKey.value);
  3040. lockRoom(true);
  3041. }
  3042. */
  3043. }
  3044. }
  3045. );
  3046. };
  3047. /**
  3048. * Toggles the application in and out of full screen mode
  3049. * (a.k.a. presentation mode in Chrome).
  3050. */
  3051. my.toggleFullScreen = function () {
  3052. var fsElement = document.documentElement;
  3053. if (!document.mozFullScreen && !document.webkitIsFullScreen) {
  3054. //Enter Full Screen
  3055. if (fsElement.mozRequestFullScreen) {
  3056. fsElement.mozRequestFullScreen();
  3057. }
  3058. else {
  3059. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  3060. }
  3061. } else {
  3062. //Exit Full Screen
  3063. if (document.mozCancelFullScreen) {
  3064. document.mozCancelFullScreen();
  3065. } else {
  3066. document.webkitCancelFullScreen();
  3067. }
  3068. }
  3069. };
  3070. /**
  3071. * Unlocks the lock button state.
  3072. */
  3073. my.unlockLockButton = function () {
  3074. if ($("#lockIcon").hasClass("icon-security-locked"))
  3075. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  3076. };
  3077. /**
  3078. * Updates the lock button state to locked.
  3079. */
  3080. my.lockLockButton = function () {
  3081. if ($("#lockIcon").hasClass("icon-security"))
  3082. UIUtil.buttonClick("#lockIcon", "icon-security icon-security-locked");
  3083. };
  3084. /**
  3085. * Shows or hides authentication button
  3086. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  3087. */
  3088. my.showAuthenticateButton = function (show) {
  3089. if (show) {
  3090. $('#authentication').css({display: "inline"});
  3091. }
  3092. else {
  3093. $('#authentication').css({display: "none"});
  3094. }
  3095. };
  3096. // Shows or hides the 'recording' button.
  3097. my.showRecordingButton = function (show) {
  3098. if (!config.enableRecording) {
  3099. return;
  3100. }
  3101. if (show) {
  3102. $('#recording').css({display: "inline"});
  3103. }
  3104. else {
  3105. $('#recording').css({display: "none"});
  3106. }
  3107. };
  3108. // Sets the state of the recording button
  3109. my.setRecordingButtonState = function (isRecording) {
  3110. if (isRecording) {
  3111. $('#recordButton').removeClass("icon-recEnable");
  3112. $('#recordButton').addClass("icon-recEnable active");
  3113. } else {
  3114. $('#recordButton').removeClass("icon-recEnable active");
  3115. $('#recordButton').addClass("icon-recEnable");
  3116. }
  3117. };
  3118. // Shows or hides SIP calls button
  3119. my.showSipCallButton = function (show) {
  3120. if (xmpp.isSipGatewayEnabled() && show) {
  3121. $('#sipCallButton').css({display: "inline"});
  3122. } else {
  3123. $('#sipCallButton').css({display: "none"});
  3124. }
  3125. };
  3126. /**
  3127. * Sets the state of the button. The button has blue glow if desktop
  3128. * streaming is active.
  3129. * @param active the state of the desktop streaming.
  3130. */
  3131. my.changeDesktopSharingButtonState = function (active) {
  3132. var button = $("#desktopsharing > a");
  3133. if (active)
  3134. {
  3135. button.addClass("glow");
  3136. }
  3137. else
  3138. {
  3139. button.removeClass("glow");
  3140. }
  3141. };
  3142. return my;
  3143. }(Toolbar || {}));
  3144. module.exports = Toolbar;
  3145. },{"../authentication/Authentication":4,"../etherpad/Etherpad":6,"../prezi/Prezi":7,"../side_pannels/SidePanelToggler":8,"../util/MessageHandler":21,"../util/UIUtil":22,"./BottomToolbar":16}],19:[function(require,module,exports){
  3146. module.exports=require(17)
  3147. },{}],20:[function(require,module,exports){
  3148. var JitsiPopover = (function () {
  3149. /**
  3150. * Constructs new JitsiPopover and attaches it to the element
  3151. * @param element jquery selector
  3152. * @param options the options for the popover.
  3153. * @constructor
  3154. */
  3155. function JitsiPopover(element, options)
  3156. {
  3157. this.options = {
  3158. skin: "white",
  3159. content: ""
  3160. };
  3161. if(options)
  3162. {
  3163. if(options.skin)
  3164. this.options.skin = options.skin;
  3165. if(options.content)
  3166. this.options.content = options.content;
  3167. }
  3168. this.elementIsHovered = false;
  3169. this.popoverIsHovered = false;
  3170. this.popoverShown = false;
  3171. element.data("jitsi_popover", this);
  3172. this.element = element;
  3173. this.template = ' <div class="jitsipopover ' + this.options.skin +
  3174. '"><div class="arrow"></div><div class="jitsipopover-content"></div>' +
  3175. '<div class="jitsiPopupmenuPadding"></div></div>';
  3176. var self = this;
  3177. this.element.on("mouseenter", function () {
  3178. self.elementIsHovered = true;
  3179. self.show();
  3180. }).on("mouseleave", function () {
  3181. self.elementIsHovered = false;
  3182. setTimeout(function () {
  3183. self.hide();
  3184. }, 10);
  3185. });
  3186. }
  3187. /**
  3188. * Shows the popover
  3189. */
  3190. JitsiPopover.prototype.show = function () {
  3191. this.createPopover();
  3192. this.popoverShown = true;
  3193. };
  3194. /**
  3195. * Hides the popover
  3196. */
  3197. JitsiPopover.prototype.hide = function () {
  3198. if(!this.elementIsHovered && !this.popoverIsHovered && this.popoverShown)
  3199. {
  3200. this.forceHide();
  3201. }
  3202. };
  3203. /**
  3204. * Hides the popover
  3205. */
  3206. JitsiPopover.prototype.forceHide = function () {
  3207. $(".jitsipopover").remove();
  3208. this.popoverShown = false;
  3209. };
  3210. /**
  3211. * Creates the popover html
  3212. */
  3213. JitsiPopover.prototype.createPopover = function () {
  3214. $("body").append(this.template);
  3215. $(".jitsipopover > .jitsipopover-content").html(this.options.content);
  3216. var self = this;
  3217. $(".jitsipopover").on("mouseenter", function () {
  3218. self.popoverIsHovered = true;
  3219. }).on("mouseleave", function () {
  3220. self.popoverIsHovered = false;
  3221. self.hide();
  3222. });
  3223. this.refreshPosition();
  3224. };
  3225. /**
  3226. * Refreshes the position of the popover
  3227. */
  3228. JitsiPopover.prototype.refreshPosition = function () {
  3229. $(".jitsipopover").position({
  3230. my: "bottom",
  3231. at: "top",
  3232. collision: "fit",
  3233. of: this.element,
  3234. using: function (position, elements) {
  3235. var calcLeft = elements.target.left - elements.element.left + elements.target.width/2;
  3236. $(".jitsipopover").css({top: position.top, left: position.left, display: "table"});
  3237. $(".jitsipopover > .arrow").css({left: calcLeft});
  3238. $(".jitsipopover > .jitsiPopupmenuPadding").css({left: calcLeft - 50});
  3239. }
  3240. });
  3241. };
  3242. /**
  3243. * Updates the content of popover.
  3244. * @param content new content
  3245. */
  3246. JitsiPopover.prototype.updateContent = function (content) {
  3247. this.options.content = content;
  3248. if(!this.popoverShown)
  3249. return;
  3250. $(".jitsipopover").remove();
  3251. this.createPopover();
  3252. };
  3253. return JitsiPopover;
  3254. })();
  3255. module.exports = JitsiPopover;
  3256. },{}],21:[function(require,module,exports){
  3257. /* global $, jQuery */
  3258. var messageHandler = (function(my) {
  3259. /**
  3260. * Shows a message to the user.
  3261. *
  3262. * @param titleString the title of the message
  3263. * @param messageString the text of the message
  3264. */
  3265. my.openMessageDialog = function(titleString, messageString) {
  3266. $.prompt(messageString,
  3267. {
  3268. title: titleString,
  3269. persistent: false
  3270. }
  3271. );
  3272. };
  3273. /**
  3274. * Shows a message to the user with two buttons: first is given as a parameter and the second is Cancel.
  3275. *
  3276. * @param titleString the title of the message
  3277. * @param msgString the text of the message
  3278. * @param persistent boolean value which determines whether the message is persistent or not
  3279. * @param leftButton the fist button's text
  3280. * @param submitFunction function to be called on submit
  3281. * @param loadedFunction function to be called after the prompt is fully loaded
  3282. * @param closeFunction function to be called after the prompt is closed
  3283. */
  3284. my.openTwoButtonDialog = function(titleString, msgString, persistent, leftButton,
  3285. submitFunction, loadedFunction, closeFunction) {
  3286. var buttons = {};
  3287. buttons[leftButton] = true;
  3288. buttons.Cancel = false;
  3289. $.prompt(msgString, {
  3290. title: titleString,
  3291. persistent: false,
  3292. buttons: buttons,
  3293. defaultButton: 1,
  3294. loaded: loadedFunction,
  3295. submit: submitFunction,
  3296. close: closeFunction
  3297. });
  3298. };
  3299. /**
  3300. * Shows a message to the user with two buttons: first is given as a parameter and the second is Cancel.
  3301. *
  3302. * @param titleString the title of the message
  3303. * @param msgString the text of the message
  3304. * @param persistent boolean value which determines whether the message is persistent or not
  3305. * @param buttons object with the buttons. The keys must be the name of the button and value is the value
  3306. * that will be passed to submitFunction
  3307. * @param submitFunction function to be called on submit
  3308. * @param loadedFunction function to be called after the prompt is fully loaded
  3309. */
  3310. my.openDialog = function (titleString, msgString, persistent, buttons,
  3311. submitFunction, loadedFunction) {
  3312. var args = {
  3313. title: titleString,
  3314. persistent: persistent,
  3315. buttons: buttons,
  3316. defaultButton: 1,
  3317. loaded: loadedFunction,
  3318. submit: submitFunction
  3319. };
  3320. if (persistent) {
  3321. args.closeText = '';
  3322. }
  3323. return $.prompt(msgString, args);
  3324. };
  3325. /**
  3326. * Closes currently opened dialog.
  3327. */
  3328. my.closeDialog = function () {
  3329. $.prompt.close();
  3330. };
  3331. /**
  3332. * Shows a dialog with different states to the user.
  3333. *
  3334. * @param statesObject object containing all the states of the dialog
  3335. * @param loadedFunction function to be called after the prompt is fully loaded
  3336. * @param stateChangedFunction function to be called when the state of the dialog is changed
  3337. */
  3338. my.openDialogWithStates = function(statesObject, loadedFunction, stateChangedFunction) {
  3339. var myPrompt = $.prompt(statesObject);
  3340. myPrompt.on('impromptu:loaded', loadedFunction);
  3341. myPrompt.on('impromptu:statechanged', stateChangedFunction);
  3342. };
  3343. /**
  3344. * Opens new popup window for given <tt>url</tt> centered over current
  3345. * window.
  3346. *
  3347. * @param url the URL to be displayed in the popup window
  3348. * @param w the width of the popup window
  3349. * @param h the height of the popup window
  3350. * @param onPopupClosed optional callback function called when popup window
  3351. * has been closed.
  3352. *
  3353. * @returns popup window object if opened successfully or undefined
  3354. * in case we failed to open it(popup blocked)
  3355. */
  3356. my.openCenteredPopup = function (url, w, h, onPopupClosed) {
  3357. var l = window.screenX + (window.innerWidth / 2) - (w / 2);
  3358. var t = window.screenY + (window.innerHeight / 2) - (h / 2);
  3359. var popup = window.open(
  3360. url, '_blank',
  3361. 'top=' + t + ', left=' + l + ', width=' + w + ', height=' + h + '');
  3362. if (popup && onPopupClosed) {
  3363. var pollTimer = window.setInterval(function () {
  3364. if (popup.closed !== false) {
  3365. window.clearInterval(pollTimer);
  3366. onPopupClosed();
  3367. }
  3368. }, 200);
  3369. }
  3370. return popup;
  3371. };
  3372. /**
  3373. * Shows a dialog prompting the user to send an error report.
  3374. *
  3375. * @param titleString the title of the message
  3376. * @param msgString the text of the message
  3377. * @param error the error that is being reported
  3378. */
  3379. my.openReportDialog = function(titleString, msgString, error) {
  3380. my.openMessageDialog(titleString, msgString);
  3381. console.log(error);
  3382. //FIXME send the error to the server
  3383. };
  3384. /**
  3385. * Shows an error dialog to the user.
  3386. * @param title the title of the message
  3387. * @param message the text of the messafe
  3388. */
  3389. my.showError = function(title, message) {
  3390. if(!(title || message)) {
  3391. title = title || "Oops!";
  3392. message = message || "There was some kind of error";
  3393. }
  3394. messageHandler.openMessageDialog(title, message);
  3395. };
  3396. my.notify = function(displayName, cls, message) {
  3397. toastr.info(
  3398. '<span class="nickname">' +
  3399. displayName +
  3400. '</span><br>' +
  3401. '<span class=' + cls + '>' +
  3402. message +
  3403. '</span>');
  3404. };
  3405. return my;
  3406. }(messageHandler || {}));
  3407. module.exports = messageHandler;
  3408. },{}],22:[function(require,module,exports){
  3409. /**
  3410. * Created by hristo on 12/22/14.
  3411. */
  3412. module.exports = {
  3413. /**
  3414. * Returns the available video width.
  3415. */
  3416. getAvailableVideoWidth: function () {
  3417. var PanelToggler = require("../side_pannels/SidePanelToggler");
  3418. var rightPanelWidth
  3419. = PanelToggler.isVisible() ? PanelToggler.getPanelSize()[0] : 0;
  3420. return window.innerWidth - rightPanelWidth;
  3421. },
  3422. /**
  3423. * Changes the style class of the element given by id.
  3424. */
  3425. buttonClick: function(id, classname) {
  3426. $(id).toggleClass(classname); // add the class to the clicked element
  3427. }
  3428. };
  3429. },{"../side_pannels/SidePanelToggler":8}],23:[function(require,module,exports){
  3430. var JitsiPopover = require("../util/JitsiPopover");
  3431. /**
  3432. * Constructs new connection indicator.
  3433. * @param videoContainer the video container associated with the indicator.
  3434. * @constructor
  3435. */
  3436. function ConnectionIndicator(videoContainer, jid, VideoLayout)
  3437. {
  3438. this.videoContainer = videoContainer;
  3439. this.bandwidth = null;
  3440. this.packetLoss = null;
  3441. this.bitrate = null;
  3442. this.showMoreValue = false;
  3443. this.resolution = null;
  3444. this.transport = [];
  3445. this.popover = null;
  3446. this.jid = jid;
  3447. this.create();
  3448. this.videoLayout = VideoLayout;
  3449. }
  3450. /**
  3451. * Values for the connection quality
  3452. * @type {{98: string,
  3453. * 81: string,
  3454. * 64: string,
  3455. * 47: string,
  3456. * 30: string,
  3457. * 0: string}}
  3458. */
  3459. ConnectionIndicator.connectionQualityValues = {
  3460. 98: "18px", //full
  3461. 81: "15px",//4 bars
  3462. 64: "11px",//3 bars
  3463. 47: "7px",//2 bars
  3464. 30: "3px",//1 bar
  3465. 0: "0px"//empty
  3466. };
  3467. ConnectionIndicator.getIP = function(value)
  3468. {
  3469. return value.substring(0, value.lastIndexOf(":"));
  3470. };
  3471. ConnectionIndicator.getPort = function(value)
  3472. {
  3473. return value.substring(value.lastIndexOf(":") + 1, value.length);
  3474. };
  3475. ConnectionIndicator.getStringFromArray = function (array) {
  3476. var res = "";
  3477. for(var i = 0; i < array.length; i++)
  3478. {
  3479. res += (i === 0? "" : ", ") + array[i];
  3480. }
  3481. return res;
  3482. };
  3483. /**
  3484. * Generates the html content.
  3485. * @returns {string} the html content.
  3486. */
  3487. ConnectionIndicator.prototype.generateText = function () {
  3488. var downloadBitrate, uploadBitrate, packetLoss, resolution, i;
  3489. if(this.bitrate === null)
  3490. {
  3491. downloadBitrate = "N/A";
  3492. uploadBitrate = "N/A";
  3493. }
  3494. else
  3495. {
  3496. downloadBitrate =
  3497. this.bitrate.download? this.bitrate.download + " Kbps" : "N/A";
  3498. uploadBitrate =
  3499. this.bitrate.upload? this.bitrate.upload + " Kbps" : "N/A";
  3500. }
  3501. if(this.packetLoss === null)
  3502. {
  3503. packetLoss = "N/A";
  3504. }
  3505. else
  3506. {
  3507. packetLoss = "<span class='jitsipopover_green'>&darr;</span>" +
  3508. (this.packetLoss.download !== null? this.packetLoss.download : "N/A") +
  3509. "% <span class='jitsipopover_orange'>&uarr;</span>" +
  3510. (this.packetLoss.upload !== null? this.packetLoss.upload : "N/A") + "%";
  3511. }
  3512. var resolutionValue = null;
  3513. if(this.resolution && this.jid != null)
  3514. {
  3515. var keys = Object.keys(this.resolution);
  3516. if(keys.length == 1)
  3517. {
  3518. for(var ssrc in this.resolution)
  3519. {
  3520. resolutionValue = this.resolution[ssrc];
  3521. }
  3522. }
  3523. else if(keys.length > 1)
  3524. {
  3525. var displayedSsrc = simulcast.getReceivingSSRC(this.jid);
  3526. resolutionValue = this.resolution[displayedSsrc];
  3527. }
  3528. }
  3529. if(this.jid === null)
  3530. {
  3531. resolution = "";
  3532. if(this.resolution === null || !Object.keys(this.resolution) ||
  3533. Object.keys(this.resolution).length === 0)
  3534. {
  3535. resolution = "N/A";
  3536. }
  3537. else
  3538. for(i in this.resolution)
  3539. {
  3540. resolutionValue = this.resolution[i];
  3541. if(resolutionValue)
  3542. {
  3543. if(resolutionValue.height &&
  3544. resolutionValue.width)
  3545. {
  3546. resolution += (resolution === ""? "" : ", ") +
  3547. resolutionValue.width + "x" +
  3548. resolutionValue.height;
  3549. }
  3550. }
  3551. }
  3552. }
  3553. else if(!resolutionValue ||
  3554. !resolutionValue.height ||
  3555. !resolutionValue.width)
  3556. {
  3557. resolution = "N/A";
  3558. }
  3559. else
  3560. {
  3561. resolution = resolutionValue.width + "x" + resolutionValue.height;
  3562. }
  3563. var result = "<table style='width:100%'>" +
  3564. "<tr>" +
  3565. "<td><span class='jitsipopover_blue'>Bitrate:</span></td>" +
  3566. "<td><span class='jitsipopover_green'>&darr;</span>" +
  3567. downloadBitrate + " <span class='jitsipopover_orange'>&uarr;</span>" +
  3568. uploadBitrate + "</td>" +
  3569. "</tr><tr>" +
  3570. "<td><span class='jitsipopover_blue'>Packet loss: </span></td>" +
  3571. "<td>" + packetLoss + "</td>" +
  3572. "</tr><tr>" +
  3573. "<td><span class='jitsipopover_blue'>Resolution:</span></td>" +
  3574. "<td>" + resolution + "</td></tr></table>";
  3575. if(this.videoContainer.id == "localVideoContainer")
  3576. result += "<div class=\"jitsipopover_showmore\" " +
  3577. "onclick = \"UI.connectionIndicatorShowMore('" +
  3578. this.videoContainer.id + "')\">" +
  3579. (this.showMoreValue? "Show less" : "Show More") + "</div><br />";
  3580. if(this.showMoreValue)
  3581. {
  3582. var downloadBandwidth, uploadBandwidth, transport;
  3583. if(this.bandwidth === null)
  3584. {
  3585. downloadBandwidth = "N/A";
  3586. uploadBandwidth = "N/A";
  3587. }
  3588. else
  3589. {
  3590. downloadBandwidth = this.bandwidth.download?
  3591. this.bandwidth.download + " Kbps" :
  3592. "N/A";
  3593. uploadBandwidth = this.bandwidth.upload?
  3594. this.bandwidth.upload + " Kbps" :
  3595. "N/A";
  3596. }
  3597. if(!this.transport || this.transport.length === 0)
  3598. {
  3599. transport = "<tr>" +
  3600. "<td><span class='jitsipopover_blue'>Address:</span></td>" +
  3601. "<td> N/A</td></tr>";
  3602. }
  3603. else
  3604. {
  3605. var data = {remoteIP: [], localIP:[], remotePort:[], localPort:[]};
  3606. for(i = 0; i < this.transport.length; i++)
  3607. {
  3608. var ip = ConnectionIndicator.getIP(this.transport[i].ip);
  3609. var port = ConnectionIndicator.getPort(this.transport[i].ip);
  3610. var localIP =
  3611. ConnectionIndicator.getIP(this.transport[i].localip);
  3612. var localPort =
  3613. ConnectionIndicator.getPort(this.transport[i].localip);
  3614. if(data.remoteIP.indexOf(ip) == -1)
  3615. {
  3616. data.remoteIP.push(ip);
  3617. }
  3618. if(data.remotePort.indexOf(port) == -1)
  3619. {
  3620. data.remotePort.push(port);
  3621. }
  3622. if(data.localIP.indexOf(localIP) == -1)
  3623. {
  3624. data.localIP.push(localIP);
  3625. }
  3626. if(data.localPort.indexOf(localPort) == -1)
  3627. {
  3628. data.localPort.push(localPort);
  3629. }
  3630. }
  3631. var localTransport =
  3632. "<tr><td><span class='jitsipopover_blue'>Local address" +
  3633. (data.localIP.length > 1? "es" : "") + ": </span></td><td> " +
  3634. ConnectionIndicator.getStringFromArray(data.localIP) +
  3635. "</td></tr>";
  3636. transport =
  3637. "<tr><td><span class='jitsipopover_blue'>Remote address"+
  3638. (data.remoteIP.length > 1? "es" : "") + ":</span></td><td> " +
  3639. ConnectionIndicator.getStringFromArray(data.remoteIP) +
  3640. "</td></tr>";
  3641. if(this.transport.length > 1)
  3642. {
  3643. transport += "<tr>" +
  3644. "<td>" +
  3645. "<span class='jitsipopover_blue'>Remote ports:</span>" +
  3646. "</td><td>";
  3647. localTransport += "<tr>" +
  3648. "<td>" +
  3649. "<span class='jitsipopover_blue'>Local ports:</span>" +
  3650. "</td><td>";
  3651. }
  3652. else
  3653. {
  3654. transport +=
  3655. "<tr>" +
  3656. "<td>" +
  3657. "<span class='jitsipopover_blue'>Remote port:</span>" +
  3658. "</td><td>";
  3659. localTransport +=
  3660. "<tr>" +
  3661. "<td>" +
  3662. "<span class='jitsipopover_blue'>Local port:</span>" +
  3663. "</td><td>";
  3664. }
  3665. transport +=
  3666. ConnectionIndicator.getStringFromArray(data.remotePort);
  3667. localTransport +=
  3668. ConnectionIndicator.getStringFromArray(data.localPort);
  3669. transport += "</td></tr>";
  3670. transport += localTransport + "</td></tr>";
  3671. transport +="<tr>" +
  3672. "<td><span class='jitsipopover_blue'>Transport:</span></td>" +
  3673. "<td>" + this.transport[0].type + "</td></tr>";
  3674. }
  3675. result += "<table style='width:100%'>" +
  3676. "<tr>" +
  3677. "<td>" +
  3678. "<span class='jitsipopover_blue'>Estimated bandwidth:</span>" +
  3679. "</td><td>" +
  3680. "<span class='jitsipopover_green'>&darr;</span>" +
  3681. downloadBandwidth +
  3682. " <span class='jitsipopover_orange'>&uarr;</span>" +
  3683. uploadBandwidth + "</td></tr>";
  3684. result += transport + "</table>";
  3685. }
  3686. return result;
  3687. };
  3688. /**
  3689. * Shows or hide the additional information.
  3690. */
  3691. ConnectionIndicator.prototype.showMore = function () {
  3692. this.showMoreValue = !this.showMoreValue;
  3693. this.updatePopoverData();
  3694. };
  3695. function createIcon(classes)
  3696. {
  3697. var icon = document.createElement("span");
  3698. for(var i in classes)
  3699. {
  3700. icon.classList.add(classes[i]);
  3701. }
  3702. icon.appendChild(
  3703. document.createElement("i")).classList.add("icon-connection");
  3704. return icon;
  3705. }
  3706. /**
  3707. * Creates the indicator
  3708. */
  3709. ConnectionIndicator.prototype.create = function () {
  3710. this.connectionIndicatorContainer = document.createElement("div");
  3711. this.connectionIndicatorContainer.className = "connectionindicator";
  3712. this.connectionIndicatorContainer.style.display = "none";
  3713. this.videoContainer.appendChild(this.connectionIndicatorContainer);
  3714. this.popover = new JitsiPopover(
  3715. $("#" + this.videoContainer.id + " > .connectionindicator"),
  3716. {content: "<div class=\"connection_info\">Come back here for " +
  3717. "connection information once the conference starts</div>",
  3718. skin: "black"});
  3719. this.emptyIcon = this.connectionIndicatorContainer.appendChild(
  3720. createIcon(["connection", "connection_empty"]));
  3721. this.fullIcon = this.connectionIndicatorContainer.appendChild(
  3722. createIcon(["connection", "connection_full"]));
  3723. };
  3724. /**
  3725. * Removes the indicator
  3726. */
  3727. ConnectionIndicator.prototype.remove = function()
  3728. {
  3729. this.connectionIndicatorContainer.remove();
  3730. this.popover.forceHide();
  3731. };
  3732. /**
  3733. * Updates the data of the indicator
  3734. * @param percent the percent of connection quality
  3735. * @param object the statistics data.
  3736. */
  3737. ConnectionIndicator.prototype.updateConnectionQuality =
  3738. function (percent, object) {
  3739. if(percent === null)
  3740. {
  3741. this.connectionIndicatorContainer.style.display = "none";
  3742. this.popover.forceHide();
  3743. return;
  3744. }
  3745. else
  3746. {
  3747. if(this.connectionIndicatorContainer.style.display == "none") {
  3748. this.connectionIndicatorContainer.style.display = "block";
  3749. this.videoLayout.updateMutePosition(this.videoContainer.id);
  3750. }
  3751. }
  3752. this.bandwidth = object.bandwidth;
  3753. this.bitrate = object.bitrate;
  3754. this.packetLoss = object.packetLoss;
  3755. this.transport = object.transport;
  3756. if(object.resolution)
  3757. {
  3758. this.resolution = object.resolution;
  3759. }
  3760. for(var quality in ConnectionIndicator.connectionQualityValues)
  3761. {
  3762. if(percent >= quality)
  3763. {
  3764. this.fullIcon.style.width =
  3765. ConnectionIndicator.connectionQualityValues[quality];
  3766. }
  3767. }
  3768. this.updatePopoverData();
  3769. };
  3770. /**
  3771. * Updates the resolution
  3772. * @param resolution the new resolution
  3773. */
  3774. ConnectionIndicator.prototype.updateResolution = function (resolution) {
  3775. this.resolution = resolution;
  3776. this.updatePopoverData();
  3777. };
  3778. /**
  3779. * Updates the content of the popover
  3780. */
  3781. ConnectionIndicator.prototype.updatePopoverData = function () {
  3782. this.popover.updateContent(
  3783. "<div class=\"connection_info\">" + this.generateText() + "</div>");
  3784. };
  3785. /**
  3786. * Hides the popover
  3787. */
  3788. ConnectionIndicator.prototype.hide = function () {
  3789. this.popover.forceHide();
  3790. };
  3791. /**
  3792. * Hides the indicator
  3793. */
  3794. ConnectionIndicator.prototype.hideIndicator = function () {
  3795. this.connectionIndicatorContainer.style.display = "none";
  3796. if(this.popover)
  3797. this.popover.forceHide();
  3798. };
  3799. module.exports = ConnectionIndicator;
  3800. },{"../util/JitsiPopover":20}],24:[function(require,module,exports){
  3801. var AudioLevels = require("../audio_levels/AudioLevels");
  3802. var Avatar = require("../avatar/Avatar");
  3803. var Chat = require("../side_pannels/chat/Chat");
  3804. var ContactList = require("../side_pannels/contactlist/ContactList");
  3805. var UIUtil = require("../util/UIUtil");
  3806. var ConnectionIndicator = require("./ConnectionIndicator");
  3807. var currentDominantSpeaker = null;
  3808. var lastNCount = config.channelLastN;
  3809. var localLastNCount = config.channelLastN;
  3810. var localLastNSet = [];
  3811. var lastNEndpointsCache = [];
  3812. var lastNPickupJid = null;
  3813. var largeVideoState = {
  3814. updateInProgress: false,
  3815. newSrc: ''
  3816. };
  3817. /**
  3818. * Currently focused video "src"(displayed in large video).
  3819. * @type {String}
  3820. */
  3821. var focusedVideoInfo = null;
  3822. /**
  3823. * Indicates if we have muted our audio before the conference has started.
  3824. * @type {boolean}
  3825. */
  3826. var preMuted = false;
  3827. var mutedAudios = {};
  3828. var flipXLocalVideo = true;
  3829. var currentVideoWidth = null;
  3830. var currentVideoHeight = null;
  3831. var localVideoSrc = null;
  3832. var defaultLocalDisplayName = "Me";
  3833. function videoactive( videoelem) {
  3834. if (videoelem.attr('id').indexOf('mixedmslabel') === -1) {
  3835. // ignore mixedmslabela0 and v0
  3836. videoelem.show();
  3837. VideoLayout.resizeThumbnails();
  3838. var videoParent = videoelem.parent();
  3839. var parentResourceJid = null;
  3840. if (videoParent)
  3841. parentResourceJid
  3842. = VideoLayout.getPeerContainerResourceJid(videoParent[0]);
  3843. // Update the large video to the last added video only if there's no
  3844. // current dominant, focused speaker or prezi playing or update it to
  3845. // the current dominant speaker.
  3846. if ((!focusedVideoInfo &&
  3847. !VideoLayout.getDominantSpeakerResourceJid() &&
  3848. !require("../prezi/Prezi").isPresentationVisible()) ||
  3849. (parentResourceJid &&
  3850. VideoLayout.getDominantSpeakerResourceJid() === parentResourceJid)) {
  3851. VideoLayout.updateLargeVideo(
  3852. RTC.getVideoSrc(videoelem[0]),
  3853. 1,
  3854. parentResourceJid);
  3855. }
  3856. VideoLayout.showModeratorIndicator();
  3857. }
  3858. }
  3859. function waitForRemoteVideo(selector, ssrc, stream, jid) {
  3860. // XXX(gp) so, every call to this function is *always* preceded by a call
  3861. // to the RTC.attachMediaStream() function but that call is *not* followed
  3862. // by an update to the videoSrcToSsrc map!
  3863. //
  3864. // The above way of doing things results in video SRCs that don't correspond
  3865. // to any SSRC for a short period of time (to be more precise, for as long
  3866. // the waitForRemoteVideo takes to complete). This causes problems (see
  3867. // bellow).
  3868. //
  3869. // I'm wondering why we need to do that; i.e. why call RTC.attachMediaStream()
  3870. // a second time in here and only then update the videoSrcToSsrc map? Why
  3871. // not simply update the videoSrcToSsrc map when the RTC.attachMediaStream()
  3872. // is called the first time? I actually do that in the lastN changed event
  3873. // handler because the "orphan" video SRC is causing troubles there. The
  3874. // purpose of this method would then be to fire the "videoactive.jingle".
  3875. //
  3876. // Food for though I guess :-)
  3877. if (selector.removed || !selector.parent().is(":visible")) {
  3878. console.warn("Media removed before had started", selector);
  3879. return;
  3880. }
  3881. if (stream.id === 'mixedmslabel') return;
  3882. if (selector[0].currentTime > 0) {
  3883. var videoStream = simulcast.getReceivingVideoStream(stream);
  3884. RTC.attachMediaStream(selector, videoStream); // FIXME: why do i have to do this for FF?
  3885. videoactive(selector);
  3886. } else {
  3887. setTimeout(function () {
  3888. waitForRemoteVideo(selector, ssrc, stream, jid);
  3889. }, 250);
  3890. }
  3891. }
  3892. /**
  3893. * Returns an array of the video horizontal and vertical indents,
  3894. * so that if fits its parent.
  3895. *
  3896. * @return an array with 2 elements, the horizontal indent and the vertical
  3897. * indent
  3898. */
  3899. function getCameraVideoPosition(videoWidth,
  3900. videoHeight,
  3901. videoSpaceWidth,
  3902. videoSpaceHeight) {
  3903. // Parent height isn't completely calculated when we position the video in
  3904. // full screen mode and this is why we use the screen height in this case.
  3905. // Need to think it further at some point and implement it properly.
  3906. var isFullScreen = document.fullScreen ||
  3907. document.mozFullScreen ||
  3908. document.webkitIsFullScreen;
  3909. if (isFullScreen)
  3910. videoSpaceHeight = window.innerHeight;
  3911. var horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
  3912. var verticalIndent = (videoSpaceHeight - videoHeight) / 2;
  3913. return [horizontalIndent, verticalIndent];
  3914. }
  3915. /**
  3916. * Returns an array of the video horizontal and vertical indents.
  3917. * Centers horizontally and top aligns vertically.
  3918. *
  3919. * @return an array with 2 elements, the horizontal indent and the vertical
  3920. * indent
  3921. */
  3922. function getDesktopVideoPosition(videoWidth,
  3923. videoHeight,
  3924. videoSpaceWidth,
  3925. videoSpaceHeight) {
  3926. var horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
  3927. var verticalIndent = 0;// Top aligned
  3928. return [horizontalIndent, verticalIndent];
  3929. }
  3930. /**
  3931. * Returns an array of the video dimensions, so that it covers the screen.
  3932. * It leaves no empty areas, but some parts of the video might not be visible.
  3933. *
  3934. * @return an array with 2 elements, the video width and the video height
  3935. */
  3936. function getCameraVideoSize(videoWidth,
  3937. videoHeight,
  3938. videoSpaceWidth,
  3939. videoSpaceHeight) {
  3940. if (!videoWidth)
  3941. videoWidth = currentVideoWidth;
  3942. if (!videoHeight)
  3943. videoHeight = currentVideoHeight;
  3944. var aspectRatio = videoWidth / videoHeight;
  3945. var availableWidth = Math.max(videoWidth, videoSpaceWidth);
  3946. var availableHeight = Math.max(videoHeight, videoSpaceHeight);
  3947. if (availableWidth / aspectRatio < videoSpaceHeight) {
  3948. availableHeight = videoSpaceHeight;
  3949. availableWidth = availableHeight * aspectRatio;
  3950. }
  3951. if (availableHeight * aspectRatio < videoSpaceWidth) {
  3952. availableWidth = videoSpaceWidth;
  3953. availableHeight = availableWidth / aspectRatio;
  3954. }
  3955. return [availableWidth, availableHeight];
  3956. }
  3957. /**
  3958. * Sets the display name for the given video span id.
  3959. */
  3960. function setDisplayName(videoSpanId, displayName) {
  3961. var nameSpan = $('#' + videoSpanId + '>span.displayname');
  3962. var defaultLocalDisplayName = interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME;
  3963. // If we already have a display name for this video.
  3964. if (nameSpan.length > 0) {
  3965. var nameSpanElement = nameSpan.get(0);
  3966. if (nameSpanElement.id === 'localDisplayName' &&
  3967. $('#localDisplayName').text() !== displayName) {
  3968. if (displayName && displayName.length > 0)
  3969. $('#localDisplayName').html(displayName + ' (me)');
  3970. else
  3971. $('#localDisplayName').text(defaultLocalDisplayName);
  3972. } else {
  3973. if (displayName && displayName.length > 0)
  3974. $('#' + videoSpanId + '_name').html(displayName);
  3975. else
  3976. $('#' + videoSpanId + '_name').text(interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  3977. }
  3978. } else {
  3979. var editButton = null;
  3980. nameSpan = document.createElement('span');
  3981. nameSpan.className = 'displayname';
  3982. $('#' + videoSpanId)[0].appendChild(nameSpan);
  3983. if (videoSpanId === 'localVideoContainer') {
  3984. editButton = createEditDisplayNameButton();
  3985. nameSpan.innerText = defaultLocalDisplayName;
  3986. }
  3987. else {
  3988. nameSpan.innerText = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  3989. }
  3990. if (displayName && displayName.length > 0) {
  3991. nameSpan.innerText = displayName;
  3992. }
  3993. if (!editButton) {
  3994. nameSpan.id = videoSpanId + '_name';
  3995. } else {
  3996. nameSpan.id = 'localDisplayName';
  3997. $('#' + videoSpanId)[0].appendChild(editButton);
  3998. var editableText = document.createElement('input');
  3999. editableText.className = 'displayname';
  4000. editableText.type = 'text';
  4001. editableText.id = 'editDisplayName';
  4002. if (displayName && displayName.length) {
  4003. editableText.value
  4004. = displayName.substring(0, displayName.indexOf(' (me)'));
  4005. }
  4006. editableText.setAttribute('style', 'display:none;');
  4007. editableText.setAttribute('placeholder', 'ex. Jane Pink');
  4008. $('#' + videoSpanId)[0].appendChild(editableText);
  4009. $('#localVideoContainer .displayname')
  4010. .bind("click", function (e) {
  4011. e.preventDefault();
  4012. e.stopPropagation();
  4013. $('#localDisplayName').hide();
  4014. $('#editDisplayName').show();
  4015. $('#editDisplayName').focus();
  4016. $('#editDisplayName').select();
  4017. $('#editDisplayName').one("focusout", function (e) {
  4018. VideoLayout.inputDisplayNameHandler(this.value);
  4019. });
  4020. $('#editDisplayName').on('keydown', function (e) {
  4021. if (e.keyCode === 13) {
  4022. e.preventDefault();
  4023. VideoLayout.inputDisplayNameHandler(this.value);
  4024. }
  4025. });
  4026. });
  4027. }
  4028. }
  4029. }
  4030. /**
  4031. * Gets the selector of video thumbnail container for the user identified by
  4032. * given <tt>userJid</tt>
  4033. * @param resourceJid user's Jid for whom we want to get the video container.
  4034. */
  4035. function getParticipantContainer(resourceJid)
  4036. {
  4037. if (!resourceJid)
  4038. return null;
  4039. if (resourceJid === xmpp.myResource())
  4040. return $("#localVideoContainer");
  4041. else
  4042. return $("#participant_" + resourceJid);
  4043. }
  4044. /**
  4045. * Sets the size and position of the given video element.
  4046. *
  4047. * @param video the video element to position
  4048. * @param width the desired video width
  4049. * @param height the desired video height
  4050. * @param horizontalIndent the left and right indent
  4051. * @param verticalIndent the top and bottom indent
  4052. */
  4053. function positionVideo(video,
  4054. width,
  4055. height,
  4056. horizontalIndent,
  4057. verticalIndent) {
  4058. video.width(width);
  4059. video.height(height);
  4060. video.css({ top: verticalIndent + 'px',
  4061. bottom: verticalIndent + 'px',
  4062. left: horizontalIndent + 'px',
  4063. right: horizontalIndent + 'px'});
  4064. }
  4065. /**
  4066. * Adds the remote video menu element for the given <tt>jid</tt> in the
  4067. * given <tt>parentElement</tt>.
  4068. *
  4069. * @param jid the jid indicating the video for which we're adding a menu.
  4070. * @param parentElement the parent element where this menu will be added
  4071. */
  4072. function addRemoteVideoMenu(jid, parentElement) {
  4073. var spanElement = document.createElement('span');
  4074. spanElement.className = 'remotevideomenu';
  4075. parentElement.appendChild(spanElement);
  4076. var menuElement = document.createElement('i');
  4077. menuElement.className = 'fa fa-angle-down';
  4078. menuElement.title = 'Remote user controls';
  4079. spanElement.appendChild(menuElement);
  4080. // <ul class="popupmenu">
  4081. // <li><a href="#">Mute</a></li>
  4082. // <li><a href="#">Eject</a></li>
  4083. // </ul>
  4084. var popupmenuElement = document.createElement('ul');
  4085. popupmenuElement.className = 'popupmenu';
  4086. popupmenuElement.id
  4087. = 'remote_popupmenu_' + Strophe.getResourceFromJid(jid);
  4088. spanElement.appendChild(popupmenuElement);
  4089. var muteMenuItem = document.createElement('li');
  4090. var muteLinkItem = document.createElement('a');
  4091. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  4092. if (!mutedAudios[jid]) {
  4093. muteLinkItem.innerHTML = mutedIndicator + 'Mute';
  4094. muteLinkItem.className = 'mutelink';
  4095. }
  4096. else {
  4097. muteLinkItem.innerHTML = mutedIndicator + ' Muted';
  4098. muteLinkItem.className = 'mutelink disabled';
  4099. }
  4100. muteLinkItem.onclick = function(){
  4101. if ($(this).attr('disabled') != undefined) {
  4102. event.preventDefault();
  4103. }
  4104. var isMute = mutedAudios[jid] == true;
  4105. xmpp.setMute(jid, !isMute);
  4106. popupmenuElement.setAttribute('style', 'display:none;');
  4107. if (isMute) {
  4108. this.innerHTML = mutedIndicator + ' Muted';
  4109. this.className = 'mutelink disabled';
  4110. }
  4111. else {
  4112. this.innerHTML = mutedIndicator + ' Mute';
  4113. this.className = 'mutelink';
  4114. }
  4115. };
  4116. muteMenuItem.appendChild(muteLinkItem);
  4117. popupmenuElement.appendChild(muteMenuItem);
  4118. var ejectIndicator = "<i class='fa fa-eject'></i>";
  4119. var ejectMenuItem = document.createElement('li');
  4120. var ejectLinkItem = document.createElement('a');
  4121. ejectLinkItem.innerHTML = ejectIndicator + ' Kick out';
  4122. ejectLinkItem.onclick = function(){
  4123. xmpp.eject(jid);
  4124. popupmenuElement.setAttribute('style', 'display:none;');
  4125. };
  4126. ejectMenuItem.appendChild(ejectLinkItem);
  4127. popupmenuElement.appendChild(ejectMenuItem);
  4128. var paddingSpan = document.createElement('span');
  4129. paddingSpan.className = 'popupmenuPadding';
  4130. popupmenuElement.appendChild(paddingSpan);
  4131. }
  4132. /**
  4133. * Removes remote video menu element from video element identified by
  4134. * given <tt>videoElementId</tt>.
  4135. *
  4136. * @param videoElementId the id of local or remote video element.
  4137. */
  4138. function removeRemoteVideoMenu(videoElementId) {
  4139. var menuSpan = $('#' + videoElementId + '>span.remotevideomenu');
  4140. if (menuSpan.length) {
  4141. menuSpan.remove();
  4142. }
  4143. }
  4144. /**
  4145. * Updates the data for the indicator
  4146. * @param id the id of the indicator
  4147. * @param percent the percent for connection quality
  4148. * @param object the data
  4149. */
  4150. function updateStatsIndicator(id, percent, object) {
  4151. if(VideoLayout.connectionIndicators[id])
  4152. VideoLayout.connectionIndicators[id].updateConnectionQuality(percent, object);
  4153. }
  4154. /**
  4155. * Returns an array of the video dimensions, so that it keeps it's aspect
  4156. * ratio and fits available area with it's larger dimension. This method
  4157. * ensures that whole video will be visible and can leave empty areas.
  4158. *
  4159. * @return an array with 2 elements, the video width and the video height
  4160. */
  4161. function getDesktopVideoSize(videoWidth,
  4162. videoHeight,
  4163. videoSpaceWidth,
  4164. videoSpaceHeight) {
  4165. if (!videoWidth)
  4166. videoWidth = currentVideoWidth;
  4167. if (!videoHeight)
  4168. videoHeight = currentVideoHeight;
  4169. var aspectRatio = videoWidth / videoHeight;
  4170. var availableWidth = Math.max(videoWidth, videoSpaceWidth);
  4171. var availableHeight = Math.max(videoHeight, videoSpaceHeight);
  4172. videoSpaceHeight -= $('#remoteVideos').outerHeight();
  4173. if (availableWidth / aspectRatio >= videoSpaceHeight)
  4174. {
  4175. availableHeight = videoSpaceHeight;
  4176. availableWidth = availableHeight * aspectRatio;
  4177. }
  4178. if (availableHeight * aspectRatio >= videoSpaceWidth)
  4179. {
  4180. availableWidth = videoSpaceWidth;
  4181. availableHeight = availableWidth / aspectRatio;
  4182. }
  4183. return [availableWidth, availableHeight];
  4184. }
  4185. /**
  4186. * Creates the edit display name button.
  4187. *
  4188. * @returns the edit button
  4189. */
  4190. function createEditDisplayNameButton() {
  4191. var editButton = document.createElement('a');
  4192. editButton.className = 'displayname';
  4193. Util.setTooltip(editButton,
  4194. 'Click to edit your<br/>display name',
  4195. "top");
  4196. editButton.innerHTML = '<i class="fa fa-pencil"></i>';
  4197. return editButton;
  4198. }
  4199. /**
  4200. * Creates the element indicating the moderator(owner) of the conference.
  4201. *
  4202. * @param parentElement the parent element where the owner indicator will
  4203. * be added
  4204. */
  4205. function createModeratorIndicatorElement(parentElement) {
  4206. var moderatorIndicator = document.createElement('i');
  4207. moderatorIndicator.className = 'fa fa-star';
  4208. parentElement.appendChild(moderatorIndicator);
  4209. Util.setTooltip(parentElement,
  4210. "The owner of<br/>this conference",
  4211. "top");
  4212. }
  4213. var VideoLayout = (function (my) {
  4214. my.connectionIndicators = {};
  4215. // By default we use camera
  4216. my.getVideoSize = getCameraVideoSize;
  4217. my.getVideoPosition = getCameraVideoPosition;
  4218. my.init = function () {
  4219. // Listen for large video size updates
  4220. document.getElementById('largeVideo')
  4221. .addEventListener('loadedmetadata', function (e) {
  4222. currentVideoWidth = this.videoWidth;
  4223. currentVideoHeight = this.videoHeight;
  4224. VideoLayout.positionLarge(currentVideoWidth, currentVideoHeight);
  4225. });
  4226. };
  4227. my.isInLastN = function(resource) {
  4228. return lastNCount < 0 // lastN is disabled, return true
  4229. || (lastNCount > 0 && lastNEndpointsCache.length == 0) // lastNEndpoints cache not built yet, return true
  4230. || (lastNEndpointsCache && lastNEndpointsCache.indexOf(resource) !== -1);
  4231. };
  4232. my.changeLocalStream = function (stream) {
  4233. VideoLayout.changeLocalVideo(stream);
  4234. };
  4235. my.changeLocalAudio = function(stream) {
  4236. RTC.attachMediaStream($('#localAudio'), stream.getOriginalStream());
  4237. document.getElementById('localAudio').autoplay = true;
  4238. document.getElementById('localAudio').volume = 0;
  4239. if (preMuted) {
  4240. if(!UI.setAudioMuted(true))
  4241. {
  4242. preMuted = mute;
  4243. }
  4244. preMuted = false;
  4245. }
  4246. };
  4247. my.changeLocalVideo = function(stream) {
  4248. var flipX = true;
  4249. if(stream.videoType == "screen")
  4250. flipX = false;
  4251. var localVideo = document.createElement('video');
  4252. localVideo.id = 'localVideo_' +
  4253. RTC.getStreamID(stream.getOriginalStream());
  4254. localVideo.autoplay = true;
  4255. localVideo.volume = 0; // is it required if audio is separated ?
  4256. localVideo.oncontextmenu = function () { return false; };
  4257. var localVideoContainer = document.getElementById('localVideoWrapper');
  4258. localVideoContainer.appendChild(localVideo);
  4259. // Set default display name.
  4260. setDisplayName('localVideoContainer');
  4261. if(!VideoLayout.connectionIndicators["localVideoContainer"]) {
  4262. VideoLayout.connectionIndicators["localVideoContainer"]
  4263. = new ConnectionIndicator($("#localVideoContainer")[0], null, VideoLayout);
  4264. }
  4265. AudioLevels.updateAudioLevelCanvas(null, VideoLayout);
  4266. var localVideoSelector = $('#' + localVideo.id);
  4267. // Add click handler to both video and video wrapper elements in case
  4268. // there's no video.
  4269. localVideoSelector.click(function (event) {
  4270. event.stopPropagation();
  4271. VideoLayout.handleVideoThumbClicked(
  4272. RTC.getVideoSrc(localVideo),
  4273. false,
  4274. xmpp.myResource());
  4275. });
  4276. $('#localVideoContainer').click(function (event) {
  4277. event.stopPropagation();
  4278. VideoLayout.handleVideoThumbClicked(
  4279. RTC.getVideoSrc(localVideo),
  4280. false,
  4281. xmpp.myResource());
  4282. });
  4283. // Add hover handler
  4284. $('#localVideoContainer').hover(
  4285. function() {
  4286. VideoLayout.showDisplayName('localVideoContainer', true);
  4287. },
  4288. function() {
  4289. if (!VideoLayout.isLargeVideoVisible()
  4290. || RTC.getVideoSrc(localVideo) !== RTC.getVideoSrc($('#largeVideo')[0]))
  4291. VideoLayout.showDisplayName('localVideoContainer', false);
  4292. }
  4293. );
  4294. // Add stream ended handler
  4295. stream.getOriginalStream().onended = function () {
  4296. localVideoContainer.removeChild(localVideo);
  4297. VideoLayout.updateRemovedVideo(RTC.getVideoSrc(localVideo));
  4298. };
  4299. // Flip video x axis if needed
  4300. flipXLocalVideo = flipX;
  4301. if (flipX) {
  4302. localVideoSelector.addClass("flipVideoX");
  4303. }
  4304. // Attach WebRTC stream
  4305. var videoStream = simulcast.getLocalVideoStream();
  4306. RTC.attachMediaStream(localVideoSelector, videoStream);
  4307. localVideoSrc = RTC.getVideoSrc(localVideo);
  4308. var myResourceJid = xmpp.myResource();
  4309. VideoLayout.updateLargeVideo(localVideoSrc, 0,
  4310. myResourceJid);
  4311. };
  4312. /**
  4313. * Checks if removed video is currently displayed and tries to display
  4314. * another one instead.
  4315. * @param removedVideoSrc src stream identifier of the video.
  4316. */
  4317. my.updateRemovedVideo = function(removedVideoSrc) {
  4318. if (removedVideoSrc === RTC.getVideoSrc($('#largeVideo')[0])) {
  4319. // this is currently displayed as large
  4320. // pick the last visible video in the row
  4321. // if nobody else is left, this picks the local video
  4322. var pick
  4323. = $('#remoteVideos>span[id!="mixedstream"]:visible:last>video')
  4324. .get(0);
  4325. if (!pick) {
  4326. console.info("Last visible video no longer exists");
  4327. pick = $('#remoteVideos>span[id!="mixedstream"]>video').get(0);
  4328. if (!pick || !RTC.getVideoSrc(pick)) {
  4329. // Try local video
  4330. console.info("Fallback to local video...");
  4331. pick = $('#remoteVideos>span>span>video').get(0);
  4332. }
  4333. }
  4334. // mute if localvideo
  4335. if (pick) {
  4336. var container = pick.parentNode;
  4337. var jid = null;
  4338. if(container)
  4339. {
  4340. if(container.id == "localVideoWrapper")
  4341. {
  4342. jid = xmpp.myResource();
  4343. }
  4344. else
  4345. {
  4346. jid = VideoLayout.getPeerContainerResourceJid(container);
  4347. }
  4348. }
  4349. VideoLayout.updateLargeVideo(RTC.getVideoSrc(pick), pick.volume, jid);
  4350. } else {
  4351. console.warn("Failed to elect large video");
  4352. }
  4353. }
  4354. };
  4355. my.onRemoteStreamAdded = function (stream) {
  4356. var container;
  4357. var remotes = document.getElementById('remoteVideos');
  4358. if (stream.peerjid) {
  4359. VideoLayout.ensurePeerContainerExists(stream.peerjid);
  4360. container = document.getElementById(
  4361. 'participant_' + Strophe.getResourceFromJid(stream.peerjid));
  4362. } else {
  4363. var id = stream.getOriginalStream().id;
  4364. if (id !== 'mixedmslabel'
  4365. // FIXME: default stream is added always with new focus
  4366. // (to be investigated)
  4367. && id !== 'default') {
  4368. console.error('can not associate stream',
  4369. id,
  4370. 'with a participant');
  4371. // We don't want to add it here since it will cause troubles
  4372. return;
  4373. }
  4374. // FIXME: for the mixed ms we dont need a video -- currently
  4375. container = document.createElement('span');
  4376. container.id = 'mixedstream';
  4377. container.className = 'videocontainer';
  4378. remotes.appendChild(container);
  4379. Util.playSoundNotification('userJoined');
  4380. }
  4381. if (container) {
  4382. VideoLayout.addRemoteStreamElement( container,
  4383. stream.sid,
  4384. stream.getOriginalStream(),
  4385. stream.peerjid,
  4386. stream.ssrc);
  4387. }
  4388. }
  4389. my.getLargeVideoState = function () {
  4390. return largeVideoState;
  4391. };
  4392. /**
  4393. * Updates the large video with the given new video source.
  4394. */
  4395. my.updateLargeVideo = function(newSrc, vol, resourceJid) {
  4396. console.log('hover in', newSrc);
  4397. if (RTC.getVideoSrc($('#largeVideo')[0]) !== newSrc) {
  4398. $('#activeSpeaker').css('visibility', 'hidden');
  4399. // Due to the simulcast the localVideoSrc may have changed when the
  4400. // fadeOut event triggers. In that case the getJidFromVideoSrc and
  4401. // isVideoSrcDesktop methods will not function correctly.
  4402. //
  4403. // Also, again due to the simulcast, the updateLargeVideo method can
  4404. // be called multiple times almost simultaneously. Therefore, we
  4405. // store the state here and update only once.
  4406. largeVideoState.newSrc = newSrc;
  4407. largeVideoState.isVisible = $('#largeVideo').is(':visible');
  4408. largeVideoState.isDesktop = RTC.isVideoSrcDesktop(resourceJid);
  4409. if(largeVideoState.userResourceJid) {
  4410. largeVideoState.oldResourceJid = largeVideoState.userResourceJid;
  4411. } else {
  4412. largeVideoState.oldResourceJid = null;
  4413. }
  4414. largeVideoState.userResourceJid = resourceJid;
  4415. // Screen stream is already rotated
  4416. largeVideoState.flipX = (newSrc === localVideoSrc) && flipXLocalVideo;
  4417. var userChanged = false;
  4418. if (largeVideoState.oldResourceJid !== largeVideoState.userResourceJid) {
  4419. userChanged = true;
  4420. // we want the notification to trigger even if userJid is undefined,
  4421. // or null.
  4422. $(document).trigger("selectedendpointchanged", [largeVideoState.userResourceJid]);
  4423. }
  4424. if (!largeVideoState.updateInProgress) {
  4425. largeVideoState.updateInProgress = true;
  4426. var doUpdate = function () {
  4427. Avatar.updateActiveSpeakerAvatarSrc(
  4428. xmpp.findJidFromResource(
  4429. largeVideoState.userResourceJid));
  4430. if (!userChanged && largeVideoState.preload &&
  4431. largeVideoState.preload !== null &&
  4432. RTC.getVideoSrc($(largeVideoState.preload)[0]) === newSrc)
  4433. {
  4434. console.info('Switching to preloaded video');
  4435. var attributes = $('#largeVideo').prop("attributes");
  4436. // loop through largeVideo attributes and apply them on
  4437. // preload.
  4438. $.each(attributes, function () {
  4439. if (this.name !== 'id' && this.name !== 'src') {
  4440. largeVideoState.preload.attr(this.name, this.value);
  4441. }
  4442. });
  4443. largeVideoState.preload.appendTo($('#largeVideoContainer'));
  4444. $('#largeVideo').attr('id', 'previousLargeVideo');
  4445. largeVideoState.preload.attr('id', 'largeVideo');
  4446. $('#previousLargeVideo').remove();
  4447. largeVideoState.preload.on('loadedmetadata', function (e) {
  4448. currentVideoWidth = this.videoWidth;
  4449. currentVideoHeight = this.videoHeight;
  4450. VideoLayout.positionLarge(currentVideoWidth, currentVideoHeight);
  4451. });
  4452. largeVideoState.preload = null;
  4453. largeVideoState.preload_ssrc = 0;
  4454. } else {
  4455. RTC.setVideoSrc($('#largeVideo')[0], largeVideoState.newSrc);
  4456. }
  4457. var videoTransform = document.getElementById('largeVideo')
  4458. .style.webkitTransform;
  4459. if (largeVideoState.flipX && videoTransform !== 'scaleX(-1)') {
  4460. document.getElementById('largeVideo').style.webkitTransform
  4461. = "scaleX(-1)";
  4462. }
  4463. else if (!largeVideoState.flipX && videoTransform === 'scaleX(-1)') {
  4464. document.getElementById('largeVideo').style.webkitTransform
  4465. = "none";
  4466. }
  4467. // Change the way we'll be measuring and positioning large video
  4468. VideoLayout.getVideoSize = largeVideoState.isDesktop
  4469. ? getDesktopVideoSize
  4470. : getCameraVideoSize;
  4471. VideoLayout.getVideoPosition = largeVideoState.isDesktop
  4472. ? getDesktopVideoPosition
  4473. : getCameraVideoPosition;
  4474. // Only if the large video is currently visible.
  4475. // Disable previous dominant speaker video.
  4476. if (largeVideoState.oldResourceJid) {
  4477. VideoLayout.enableDominantSpeaker(
  4478. largeVideoState.oldResourceJid,
  4479. false);
  4480. }
  4481. // Enable new dominant speaker in the remote videos section.
  4482. if (largeVideoState.userResourceJid) {
  4483. VideoLayout.enableDominantSpeaker(
  4484. largeVideoState.userResourceJid,
  4485. true);
  4486. }
  4487. if (userChanged && largeVideoState.isVisible) {
  4488. // using "this" should be ok because we're called
  4489. // from within the fadeOut event.
  4490. $(this).fadeIn(300);
  4491. }
  4492. if(userChanged) {
  4493. Avatar.showUserAvatar(
  4494. xmpp.findJidFromResource(
  4495. largeVideoState.oldResourceJid));
  4496. }
  4497. largeVideoState.updateInProgress = false;
  4498. };
  4499. if (userChanged) {
  4500. $('#largeVideo').fadeOut(300, doUpdate);
  4501. } else {
  4502. doUpdate();
  4503. }
  4504. }
  4505. } else {
  4506. Avatar.showUserAvatar(
  4507. xmpp.findJidFromResource(
  4508. largeVideoState.userResourceJid));
  4509. }
  4510. };
  4511. my.handleVideoThumbClicked = function(videoSrc,
  4512. noPinnedEndpointChangedEvent,
  4513. resourceJid) {
  4514. // Restore style for previously focused video
  4515. var oldContainer = null;
  4516. if(focusedVideoInfo) {
  4517. var focusResourceJid = focusedVideoInfo.resourceJid;
  4518. oldContainer = getParticipantContainer(focusResourceJid);
  4519. }
  4520. if (oldContainer) {
  4521. oldContainer.removeClass("videoContainerFocused");
  4522. }
  4523. // Unlock current focused.
  4524. if (focusedVideoInfo && focusedVideoInfo.src === videoSrc)
  4525. {
  4526. focusedVideoInfo = null;
  4527. var dominantSpeakerVideo = null;
  4528. // Enable the currently set dominant speaker.
  4529. if (currentDominantSpeaker) {
  4530. dominantSpeakerVideo
  4531. = $('#participant_' + currentDominantSpeaker + '>video')
  4532. .get(0);
  4533. if (dominantSpeakerVideo) {
  4534. VideoLayout.updateLargeVideo(
  4535. RTC.getVideoSrc(dominantSpeakerVideo),
  4536. 1,
  4537. currentDominantSpeaker);
  4538. }
  4539. }
  4540. if (!noPinnedEndpointChangedEvent) {
  4541. $(document).trigger("pinnedendpointchanged");
  4542. }
  4543. return;
  4544. }
  4545. // Lock new video
  4546. focusedVideoInfo = {
  4547. src: videoSrc,
  4548. resourceJid: resourceJid
  4549. };
  4550. // Update focused/pinned interface.
  4551. if (resourceJid)
  4552. {
  4553. var container = getParticipantContainer(resourceJid);
  4554. container.addClass("videoContainerFocused");
  4555. if (!noPinnedEndpointChangedEvent) {
  4556. $(document).trigger("pinnedendpointchanged", [resourceJid]);
  4557. }
  4558. }
  4559. if ($('#largeVideo').attr('src') === videoSrc &&
  4560. VideoLayout.isLargeVideoOnTop()) {
  4561. return;
  4562. }
  4563. // Triggers a "video.selected" event. The "false" parameter indicates
  4564. // this isn't a prezi.
  4565. $(document).trigger("video.selected", [false]);
  4566. VideoLayout.updateLargeVideo(videoSrc, 1, resourceJid);
  4567. $('audio').each(function (idx, el) {
  4568. if (el.id.indexOf('mixedmslabel') !== -1) {
  4569. el.volume = 0;
  4570. el.volume = 1;
  4571. }
  4572. });
  4573. };
  4574. /**
  4575. * Positions the large video.
  4576. *
  4577. * @param videoWidth the stream video width
  4578. * @param videoHeight the stream video height
  4579. */
  4580. my.positionLarge = function (videoWidth, videoHeight) {
  4581. var videoSpaceWidth = $('#videospace').width();
  4582. var videoSpaceHeight = window.innerHeight;
  4583. var videoSize = VideoLayout.getVideoSize(videoWidth,
  4584. videoHeight,
  4585. videoSpaceWidth,
  4586. videoSpaceHeight);
  4587. var largeVideoWidth = videoSize[0];
  4588. var largeVideoHeight = videoSize[1];
  4589. var videoPosition = VideoLayout.getVideoPosition(largeVideoWidth,
  4590. largeVideoHeight,
  4591. videoSpaceWidth,
  4592. videoSpaceHeight);
  4593. var horizontalIndent = videoPosition[0];
  4594. var verticalIndent = videoPosition[1];
  4595. positionVideo($('#largeVideo'),
  4596. largeVideoWidth,
  4597. largeVideoHeight,
  4598. horizontalIndent, verticalIndent);
  4599. };
  4600. /**
  4601. * Shows/hides the large video.
  4602. */
  4603. my.setLargeVideoVisible = function(isVisible) {
  4604. var resourceJid = largeVideoState.userResourceJid;
  4605. if (isVisible) {
  4606. $('#largeVideo').css({visibility: 'visible'});
  4607. $('.watermark').css({visibility: 'visible'});
  4608. VideoLayout.enableDominantSpeaker(resourceJid, true);
  4609. }
  4610. else {
  4611. $('#largeVideo').css({visibility: 'hidden'});
  4612. $('#activeSpeaker').css('visibility', 'hidden');
  4613. $('.watermark').css({visibility: 'hidden'});
  4614. VideoLayout.enableDominantSpeaker(resourceJid, false);
  4615. if(focusedVideoInfo) {
  4616. var focusResourceJid = focusedVideoInfo.resourceJid;
  4617. var oldContainer = getParticipantContainer(focusResourceJid);
  4618. if (oldContainer && oldContainer.length > 0) {
  4619. oldContainer.removeClass("videoContainerFocused");
  4620. }
  4621. focusedVideoInfo = null;
  4622. if(focusResourceJid) {
  4623. Avatar.showUserAvatar(
  4624. xmpp.findJidFromResource(focusResourceJid));
  4625. }
  4626. }
  4627. }
  4628. };
  4629. /**
  4630. * Indicates if the large video is currently visible.
  4631. *
  4632. * @return <tt>true</tt> if visible, <tt>false</tt> - otherwise
  4633. */
  4634. my.isLargeVideoVisible = function() {
  4635. return $('#largeVideo').is(':visible');
  4636. };
  4637. my.isLargeVideoOnTop = function () {
  4638. var Etherpad = require("../etherpad/Etherpad");
  4639. var Prezi = require("../prezi/Prezi");
  4640. return !Prezi.isPresentationVisible() && !Etherpad.isVisible();
  4641. };
  4642. /**
  4643. * Checks if container for participant identified by given peerJid exists
  4644. * in the document and creates it eventually.
  4645. *
  4646. * @param peerJid peer Jid to check.
  4647. * @param userId user email or id for setting the avatar
  4648. *
  4649. * @return Returns <tt>true</tt> if the peer container exists,
  4650. * <tt>false</tt> - otherwise
  4651. */
  4652. my.ensurePeerContainerExists = function(peerJid, userId) {
  4653. ContactList.ensureAddContact(peerJid, userId);
  4654. var resourceJid = Strophe.getResourceFromJid(peerJid);
  4655. var videoSpanId = 'participant_' + resourceJid;
  4656. if (!$('#' + videoSpanId).length) {
  4657. var container =
  4658. VideoLayout.addRemoteVideoContainer(peerJid, videoSpanId, userId);
  4659. Avatar.setUserAvatar(peerJid, userId);
  4660. // Set default display name.
  4661. setDisplayName(videoSpanId);
  4662. VideoLayout.connectionIndicators[videoSpanId] =
  4663. new ConnectionIndicator(container, peerJid, VideoLayout);
  4664. var nickfield = document.createElement('span');
  4665. nickfield.className = "nick";
  4666. nickfield.appendChild(document.createTextNode(resourceJid));
  4667. container.appendChild(nickfield);
  4668. // In case this is not currently in the last n we don't show it.
  4669. if (localLastNCount
  4670. && localLastNCount > 0
  4671. && $('#remoteVideos>span').length >= localLastNCount + 2) {
  4672. showPeerContainer(resourceJid, 'hide');
  4673. }
  4674. else
  4675. VideoLayout.resizeThumbnails();
  4676. }
  4677. };
  4678. my.addRemoteVideoContainer = function(peerJid, spanId) {
  4679. var container = document.createElement('span');
  4680. container.id = spanId;
  4681. container.className = 'videocontainer';
  4682. var remotes = document.getElementById('remoteVideos');
  4683. // If the peerJid is null then this video span couldn't be directly
  4684. // associated with a participant (this could happen in the case of prezi).
  4685. if (xmpp.isModerator() && peerJid !== null)
  4686. addRemoteVideoMenu(peerJid, container);
  4687. remotes.appendChild(container);
  4688. AudioLevels.updateAudioLevelCanvas(peerJid, VideoLayout);
  4689. return container;
  4690. };
  4691. /**
  4692. * Creates an audio or video stream element.
  4693. */
  4694. my.createStreamElement = function (sid, stream) {
  4695. var isVideo = stream.getVideoTracks().length > 0;
  4696. var element = isVideo
  4697. ? document.createElement('video')
  4698. : document.createElement('audio');
  4699. var id = (isVideo ? 'remoteVideo_' : 'remoteAudio_')
  4700. + sid + '_' + RTC.getStreamID(stream);
  4701. element.id = id;
  4702. element.autoplay = true;
  4703. element.oncontextmenu = function () { return false; };
  4704. return element;
  4705. };
  4706. my.addRemoteStreamElement
  4707. = function (container, sid, stream, peerJid, thessrc) {
  4708. var newElementId = null;
  4709. var isVideo = stream.getVideoTracks().length > 0;
  4710. if (container) {
  4711. var streamElement = VideoLayout.createStreamElement(sid, stream);
  4712. newElementId = streamElement.id;
  4713. container.appendChild(streamElement);
  4714. var sel = $('#' + newElementId);
  4715. sel.hide();
  4716. // If the container is currently visible we attach the stream.
  4717. if (!isVideo
  4718. || (container.offsetParent !== null && isVideo)) {
  4719. var videoStream = simulcast.getReceivingVideoStream(stream);
  4720. RTC.attachMediaStream(sel, videoStream);
  4721. if (isVideo)
  4722. waitForRemoteVideo(sel, thessrc, stream, peerJid);
  4723. }
  4724. stream.onended = function () {
  4725. console.log('stream ended', this);
  4726. VideoLayout.removeRemoteStreamElement(
  4727. stream, isVideo, container);
  4728. // NOTE(gp) it seems that under certain circumstances, the
  4729. // onended event is not fired and thus the contact list is not
  4730. // updated.
  4731. //
  4732. // The onended event of a stream should be fired when the SSRCs
  4733. // corresponding to that stream are removed from the SDP; but
  4734. // this doesn't seem to always be the case, resulting in ghost
  4735. // contacts.
  4736. //
  4737. // In an attempt to fix the ghost contacts problem, I'm moving
  4738. // the removeContact() method call in app.js, inside the
  4739. // 'muc.left' event handler.
  4740. //if (peerJid)
  4741. // ContactList.removeContact(peerJid);
  4742. };
  4743. // Add click handler.
  4744. container.onclick = function (event) {
  4745. /*
  4746. * FIXME It turns out that videoThumb may not exist (if there is
  4747. * no actual video).
  4748. */
  4749. var videoThumb = $('#' + container.id + '>video').get(0);
  4750. if (videoThumb) {
  4751. VideoLayout.handleVideoThumbClicked(
  4752. RTC.getVideoSrc(videoThumb),
  4753. false,
  4754. Strophe.getResourceFromJid(peerJid));
  4755. }
  4756. event.stopPropagation();
  4757. event.preventDefault();
  4758. return false;
  4759. };
  4760. // Add hover handler
  4761. $(container).hover(
  4762. function() {
  4763. VideoLayout.showDisplayName(container.id, true);
  4764. },
  4765. function() {
  4766. var videoSrc = null;
  4767. if ($('#' + container.id + '>video')
  4768. && $('#' + container.id + '>video').length > 0) {
  4769. videoSrc = RTC.getVideoSrc($('#' + container.id + '>video').get(0));
  4770. }
  4771. // If the video has been "pinned" by the user we want to
  4772. // keep the display name on place.
  4773. if (!VideoLayout.isLargeVideoVisible()
  4774. || videoSrc !== RTC.getVideoSrc($('#largeVideo')[0]))
  4775. VideoLayout.showDisplayName(container.id, false);
  4776. }
  4777. );
  4778. }
  4779. return newElementId;
  4780. };
  4781. /**
  4782. * Removes the remote stream element corresponding to the given stream and
  4783. * parent container.
  4784. *
  4785. * @param stream the stream
  4786. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  4787. * @param container
  4788. */
  4789. my.removeRemoteStreamElement = function (stream, isVideo, container) {
  4790. if (!container)
  4791. return;
  4792. var select = null;
  4793. var removedVideoSrc = null;
  4794. if (isVideo) {
  4795. select = $('#' + container.id + '>video');
  4796. removedVideoSrc = RTC.getVideoSrc(select.get(0));
  4797. }
  4798. else
  4799. select = $('#' + container.id + '>audio');
  4800. // Mark video as removed to cancel waiting loop(if video is removed
  4801. // before has started)
  4802. select.removed = true;
  4803. select.remove();
  4804. var audioCount = $('#' + container.id + '>audio').length;
  4805. var videoCount = $('#' + container.id + '>video').length;
  4806. if (!audioCount && !videoCount) {
  4807. console.log("Remove whole user", container.id);
  4808. if(VideoLayout.connectionIndicators[container.id])
  4809. VideoLayout.connectionIndicators[container.id].remove();
  4810. // Remove whole container
  4811. container.remove();
  4812. Util.playSoundNotification('userLeft');
  4813. VideoLayout.resizeThumbnails();
  4814. }
  4815. if (removedVideoSrc)
  4816. VideoLayout.updateRemovedVideo(removedVideoSrc);
  4817. };
  4818. /**
  4819. * Show/hide peer container for the given resourceJid.
  4820. */
  4821. function showPeerContainer(resourceJid, state) {
  4822. var peerContainer = $('#participant_' + resourceJid);
  4823. if (!peerContainer)
  4824. return;
  4825. var isHide = state === 'hide';
  4826. var resizeThumbnails = false;
  4827. if (!isHide) {
  4828. if (!peerContainer.is(':visible')) {
  4829. resizeThumbnails = true;
  4830. peerContainer.show();
  4831. }
  4832. if (state == 'show')
  4833. {
  4834. // peerContainer.css('-webkit-filter', '');
  4835. var jid = xmpp.findJidFromResource(resourceJid);
  4836. Avatar.showUserAvatar(jid, false);
  4837. }
  4838. else // if (state == 'avatar')
  4839. {
  4840. // peerContainer.css('-webkit-filter', 'grayscale(100%)');
  4841. var jid = xmpp.findJidFromResource(resourceJid);
  4842. Avatar.showUserAvatar(jid, true);
  4843. }
  4844. }
  4845. else if (peerContainer.is(':visible') && isHide)
  4846. {
  4847. resizeThumbnails = true;
  4848. peerContainer.hide();
  4849. if(VideoLayout.connectionIndicators['participant_' + resourceJid])
  4850. VideoLayout.connectionIndicators['participant_' + resourceJid].hide();
  4851. }
  4852. if (resizeThumbnails) {
  4853. VideoLayout.resizeThumbnails();
  4854. }
  4855. // We want to be able to pin a participant from the contact list, even
  4856. // if he's not in the lastN set!
  4857. // ContactList.setClickable(resourceJid, !isHide);
  4858. };
  4859. my.inputDisplayNameHandler = function (name) {
  4860. if (name && nickname !== name) {
  4861. nickname = name;
  4862. window.localStorage.displayname = nickname;
  4863. xmpp.addToPresence("displayName", nickname);
  4864. Chat.setChatConversationMode(true);
  4865. }
  4866. if (!$('#localDisplayName').is(":visible")) {
  4867. if (nickname)
  4868. $('#localDisplayName').text(nickname + " (me)");
  4869. else
  4870. $('#localDisplayName')
  4871. .text(interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
  4872. $('#localDisplayName').show();
  4873. }
  4874. $('#editDisplayName').hide();
  4875. };
  4876. /**
  4877. * Shows/hides the display name on the remote video.
  4878. * @param videoSpanId the identifier of the video span element
  4879. * @param isShow indicates if the display name should be shown or hidden
  4880. */
  4881. my.showDisplayName = function(videoSpanId, isShow) {
  4882. var nameSpan = $('#' + videoSpanId + '>span.displayname').get(0);
  4883. if (isShow) {
  4884. if (nameSpan && nameSpan.innerHTML && nameSpan.innerHTML.length)
  4885. nameSpan.setAttribute("style", "display:inline-block;");
  4886. }
  4887. else {
  4888. if (nameSpan)
  4889. nameSpan.setAttribute("style", "display:none;");
  4890. }
  4891. };
  4892. /**
  4893. * Shows the presence status message for the given video.
  4894. */
  4895. my.setPresenceStatus = function (videoSpanId, statusMsg) {
  4896. if (!$('#' + videoSpanId).length) {
  4897. // No container
  4898. return;
  4899. }
  4900. var statusSpan = $('#' + videoSpanId + '>span.status');
  4901. if (!statusSpan.length) {
  4902. //Add status span
  4903. statusSpan = document.createElement('span');
  4904. statusSpan.className = 'status';
  4905. statusSpan.id = videoSpanId + '_status';
  4906. $('#' + videoSpanId)[0].appendChild(statusSpan);
  4907. statusSpan = $('#' + videoSpanId + '>span.status');
  4908. }
  4909. // Display status
  4910. if (statusMsg && statusMsg.length) {
  4911. $('#' + videoSpanId + '_status').text(statusMsg);
  4912. statusSpan.get(0).setAttribute("style", "display:inline-block;");
  4913. }
  4914. else {
  4915. // Hide
  4916. statusSpan.get(0).setAttribute("style", "display:none;");
  4917. }
  4918. };
  4919. /**
  4920. * Shows a visual indicator for the moderator of the conference.
  4921. */
  4922. my.showModeratorIndicator = function () {
  4923. var isModerator = xmpp.isModerator();
  4924. if (isModerator) {
  4925. var indicatorSpan = $('#localVideoContainer .focusindicator');
  4926. if (indicatorSpan.children().length === 0)
  4927. {
  4928. createModeratorIndicatorElement(indicatorSpan[0]);
  4929. }
  4930. }
  4931. var members = xmpp.getMembers();
  4932. Object.keys(members).forEach(function (jid) {
  4933. if (Strophe.getResourceFromJid(jid) === 'focus') {
  4934. // Skip server side focus
  4935. return;
  4936. }
  4937. var resourceJid = Strophe.getResourceFromJid(jid);
  4938. var videoSpanId = 'participant_' + resourceJid;
  4939. var videoContainer = document.getElementById(videoSpanId);
  4940. if (!videoContainer) {
  4941. console.error("No video container for " + jid);
  4942. return;
  4943. }
  4944. var member = members[jid];
  4945. if (member.role === 'moderator') {
  4946. // Remove menu if peer is moderator
  4947. var menuSpan = $('#' + videoSpanId + '>span.remotevideomenu');
  4948. if (menuSpan.length) {
  4949. removeRemoteVideoMenu(videoSpanId);
  4950. }
  4951. // Show moderator indicator
  4952. var indicatorSpan
  4953. = $('#' + videoSpanId + ' .focusindicator');
  4954. if (!indicatorSpan || indicatorSpan.length === 0) {
  4955. indicatorSpan = document.createElement('span');
  4956. indicatorSpan.className = 'focusindicator';
  4957. videoContainer.appendChild(indicatorSpan);
  4958. createModeratorIndicatorElement(indicatorSpan);
  4959. }
  4960. } else if (isModerator) {
  4961. // We are moderator, but user is not - add menu
  4962. if ($('#remote_popupmenu_' + resourceJid).length <= 0) {
  4963. addRemoteVideoMenu(
  4964. jid,
  4965. document.getElementById('participant_' + resourceJid));
  4966. }
  4967. }
  4968. });
  4969. };
  4970. /**
  4971. * Shows video muted indicator over small videos.
  4972. */
  4973. my.showVideoIndicator = function(videoSpanId, isMuted) {
  4974. var videoMutedSpan = $('#' + videoSpanId + '>span.videoMuted');
  4975. if (isMuted === 'false') {
  4976. if (videoMutedSpan.length > 0) {
  4977. videoMutedSpan.remove();
  4978. }
  4979. }
  4980. else {
  4981. if(videoMutedSpan.length == 0) {
  4982. videoMutedSpan = document.createElement('span');
  4983. videoMutedSpan.className = 'videoMuted';
  4984. $('#' + videoSpanId)[0].appendChild(videoMutedSpan);
  4985. var mutedIndicator = document.createElement('i');
  4986. mutedIndicator.className = 'icon-camera-disabled';
  4987. Util.setTooltip(mutedIndicator,
  4988. "Participant has<br/>stopped the camera.",
  4989. "top");
  4990. videoMutedSpan.appendChild(mutedIndicator);
  4991. }
  4992. VideoLayout.updateMutePosition(videoSpanId);
  4993. }
  4994. };
  4995. my.updateMutePosition = function (videoSpanId) {
  4996. var audioMutedSpan = $('#' + videoSpanId + '>span.audioMuted');
  4997. var connectionIndicator = $('#' + videoSpanId + '>div.connectionindicator');
  4998. var videoMutedSpan = $('#' + videoSpanId + '>span.videoMuted');
  4999. if(connectionIndicator.length > 0
  5000. && connectionIndicator[0].style.display != "none") {
  5001. audioMutedSpan.css({right: "23px"});
  5002. videoMutedSpan.css({right: ((audioMutedSpan.length > 0? 23 : 0) + 30) + "px"});
  5003. }
  5004. else
  5005. {
  5006. audioMutedSpan.css({right: "0px"});
  5007. videoMutedSpan.css({right: (audioMutedSpan.length > 0? 30 : 0) + "px"});
  5008. }
  5009. }
  5010. /**
  5011. * Shows audio muted indicator over small videos.
  5012. * @param {string} isMuted
  5013. */
  5014. my.showAudioIndicator = function(videoSpanId, isMuted) {
  5015. var audioMutedSpan = $('#' + videoSpanId + '>span.audioMuted');
  5016. if (isMuted === 'false') {
  5017. if (audioMutedSpan.length > 0) {
  5018. audioMutedSpan.popover('hide');
  5019. audioMutedSpan.remove();
  5020. }
  5021. }
  5022. else {
  5023. if(audioMutedSpan.length == 0 ) {
  5024. audioMutedSpan = document.createElement('span');
  5025. audioMutedSpan.className = 'audioMuted';
  5026. Util.setTooltip(audioMutedSpan,
  5027. "Participant is muted",
  5028. "top");
  5029. $('#' + videoSpanId)[0].appendChild(audioMutedSpan);
  5030. var mutedIndicator = document.createElement('i');
  5031. mutedIndicator.className = 'icon-mic-disabled';
  5032. audioMutedSpan.appendChild(mutedIndicator);
  5033. }
  5034. VideoLayout.updateMutePosition(videoSpanId);
  5035. }
  5036. };
  5037. /*
  5038. * Shows or hides the audio muted indicator over the local thumbnail video.
  5039. * @param {boolean} isMuted
  5040. */
  5041. my.showLocalAudioIndicator = function(isMuted) {
  5042. VideoLayout.showAudioIndicator('localVideoContainer', isMuted.toString());
  5043. };
  5044. /**
  5045. * Resizes the large video container.
  5046. */
  5047. my.resizeLargeVideoContainer = function () {
  5048. Chat.resizeChat();
  5049. var availableHeight = window.innerHeight;
  5050. var availableWidth = UIUtil.getAvailableVideoWidth();
  5051. if (availableWidth < 0 || availableHeight < 0) return;
  5052. $('#videospace').width(availableWidth);
  5053. $('#videospace').height(availableHeight);
  5054. $('#largeVideoContainer').width(availableWidth);
  5055. $('#largeVideoContainer').height(availableHeight);
  5056. var avatarSize = interfaceConfig.ACTIVE_SPEAKER_AVATAR_SIZE;
  5057. var top = availableHeight / 2 - avatarSize / 4 * 3;
  5058. $('#activeSpeaker').css('top', top);
  5059. VideoLayout.resizeThumbnails();
  5060. };
  5061. /**
  5062. * Resizes thumbnails.
  5063. */
  5064. my.resizeThumbnails = function() {
  5065. var videoSpaceWidth = $('#remoteVideos').width();
  5066. var thumbnailSize = VideoLayout.calculateThumbnailSize(videoSpaceWidth);
  5067. var width = thumbnailSize[0];
  5068. var height = thumbnailSize[1];
  5069. // size videos so that while keeping AR and max height, we have a
  5070. // nice fit
  5071. $('#remoteVideos').height(height);
  5072. $('#remoteVideos>span').width(width);
  5073. $('#remoteVideos>span').height(height);
  5074. $('.userAvatar').css('left', (width - height) / 2);
  5075. $(document).trigger("remotevideo.resized", [width, height]);
  5076. };
  5077. /**
  5078. * Enables the dominant speaker UI.
  5079. *
  5080. * @param resourceJid the jid indicating the video element to
  5081. * activate/deactivate
  5082. * @param isEnable indicates if the dominant speaker should be enabled or
  5083. * disabled
  5084. */
  5085. my.enableDominantSpeaker = function(resourceJid, isEnable) {
  5086. var videoSpanId = null;
  5087. var videoContainerId = null;
  5088. if (resourceJid
  5089. === xmpp.myResource()) {
  5090. videoSpanId = 'localVideoWrapper';
  5091. videoContainerId = 'localVideoContainer';
  5092. }
  5093. else {
  5094. videoSpanId = 'participant_' + resourceJid;
  5095. videoContainerId = videoSpanId;
  5096. }
  5097. var displayName = resourceJid;
  5098. var nameSpan = $('#' + videoContainerId + '>span.displayname');
  5099. if (nameSpan.length > 0)
  5100. displayName = nameSpan.html();
  5101. console.log("UI enable dominant speaker",
  5102. displayName,
  5103. resourceJid,
  5104. isEnable);
  5105. videoSpan = document.getElementById(videoContainerId);
  5106. if (!videoSpan) {
  5107. return;
  5108. }
  5109. var video = $('#' + videoSpanId + '>video');
  5110. if (video && video.length > 0) {
  5111. if (isEnable) {
  5112. var isLargeVideoVisible = VideoLayout.isLargeVideoOnTop();
  5113. VideoLayout.showDisplayName(videoContainerId, isLargeVideoVisible);
  5114. if (!videoSpan.classList.contains("dominantspeaker"))
  5115. videoSpan.classList.add("dominantspeaker");
  5116. }
  5117. else {
  5118. VideoLayout.showDisplayName(videoContainerId, false);
  5119. if (videoSpan.classList.contains("dominantspeaker"))
  5120. videoSpan.classList.remove("dominantspeaker");
  5121. }
  5122. Avatar.showUserAvatar(
  5123. xmpp.findJidFromResource(resourceJid));
  5124. }
  5125. };
  5126. /**
  5127. * Calculates the thumbnail size.
  5128. *
  5129. * @param videoSpaceWidth the width of the video space
  5130. */
  5131. my.calculateThumbnailSize = function (videoSpaceWidth) {
  5132. // Calculate the available height, which is the inner window height minus
  5133. // 39px for the header minus 2px for the delimiter lines on the top and
  5134. // bottom of the large video, minus the 36px space inside the remoteVideos
  5135. // container used for highlighting shadow.
  5136. var availableHeight = 100;
  5137. var numvids = $('#remoteVideos>span:visible').length;
  5138. if (localLastNCount && localLastNCount > 0) {
  5139. numvids = Math.min(localLastNCount + 1, numvids);
  5140. }
  5141. // Remove the 3px borders arround videos and border around the remote
  5142. // videos area and the 4 pixels between the local video and the others
  5143. //TODO: Find out where the 4 pixels come from and remove them
  5144. var availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
  5145. var availableWidth = availableWinWidth / numvids;
  5146. var aspectRatio = 16.0 / 9.0;
  5147. var maxHeight = Math.min(160, availableHeight);
  5148. availableHeight = Math.min(maxHeight, availableWidth / aspectRatio);
  5149. if (availableHeight < availableWidth / aspectRatio) {
  5150. availableWidth = Math.floor(availableHeight * aspectRatio);
  5151. }
  5152. return [availableWidth, availableHeight];
  5153. };
  5154. /**
  5155. * Updates the remote video menu.
  5156. *
  5157. * @param jid the jid indicating the video for which we're adding a menu.
  5158. * @param isMuted indicates the current mute state
  5159. */
  5160. my.updateRemoteVideoMenu = function(jid, isMuted) {
  5161. var muteMenuItem
  5162. = $('#remote_popupmenu_'
  5163. + Strophe.getResourceFromJid(jid)
  5164. + '>li>a.mutelink');
  5165. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  5166. if (muteMenuItem.length) {
  5167. var muteLink = muteMenuItem.get(0);
  5168. if (isMuted === 'true') {
  5169. muteLink.innerHTML = mutedIndicator + ' Muted';
  5170. muteLink.className = 'mutelink disabled';
  5171. }
  5172. else {
  5173. muteLink.innerHTML = mutedIndicator + ' Mute';
  5174. muteLink.className = 'mutelink';
  5175. }
  5176. }
  5177. };
  5178. /**
  5179. * Returns the current dominant speaker resource jid.
  5180. */
  5181. my.getDominantSpeakerResourceJid = function () {
  5182. return currentDominantSpeaker;
  5183. };
  5184. /**
  5185. * Returns the corresponding resource jid to the given peer container
  5186. * DOM element.
  5187. *
  5188. * @return the corresponding resource jid to the given peer container
  5189. * DOM element
  5190. */
  5191. my.getPeerContainerResourceJid = function (containerElement) {
  5192. var i = containerElement.id.indexOf('participant_');
  5193. if (i >= 0)
  5194. return containerElement.id.substring(i + 12);
  5195. };
  5196. /**
  5197. * On contact list item clicked.
  5198. */
  5199. $(ContactList).bind('contactclicked', function(event, jid) {
  5200. if (!jid) {
  5201. return;
  5202. }
  5203. var resource = Strophe.getResourceFromJid(jid);
  5204. var videoContainer = $("#participant_" + resource);
  5205. if (videoContainer.length > 0) {
  5206. var videoThumb = $('video', videoContainer).get(0);
  5207. // It is not always the case that a videoThumb exists (if there is
  5208. // no actual video).
  5209. if (videoThumb) {
  5210. if (videoThumb.src && videoThumb.src != '') {
  5211. // We have a video src, great! Let's update the large video
  5212. // now.
  5213. VideoLayout.handleVideoThumbClicked(
  5214. videoThumb.src,
  5215. false,
  5216. Strophe.getResourceFromJid(jid));
  5217. } else {
  5218. // If we don't have a video src for jid, there's absolutely
  5219. // no point in calling handleVideoThumbClicked; Quite
  5220. // simply, it won't work because it needs an src to attach
  5221. // to the large video.
  5222. //
  5223. // Instead, we trigger the pinned endpoint changed event to
  5224. // let the bridge adjust its lastN set for myjid and store
  5225. // the pinned user in the lastNPickupJid variable to be
  5226. // picked up later by the lastN changed event handler.
  5227. lastNPickupJid = jid;
  5228. $(document).trigger("pinnedendpointchanged", [Strophe.getResourceFromJid(jid)]);
  5229. }
  5230. } else if (jid == xmpp.myJid()) {
  5231. $("#localVideoContainer").click();
  5232. }
  5233. }
  5234. });
  5235. /**
  5236. * On audio muted event.
  5237. */
  5238. $(document).bind('audiomuted.muc', function (event, jid, isMuted) {
  5239. /*
  5240. // FIXME: but focus can not mute in this case ? - check
  5241. if (jid === xmpp.myJid()) {
  5242. // The local mute indicator is controlled locally
  5243. return;
  5244. }*/
  5245. var videoSpanId = null;
  5246. if (jid === xmpp.myJid()) {
  5247. videoSpanId = 'localVideoContainer';
  5248. } else {
  5249. VideoLayout.ensurePeerContainerExists(jid);
  5250. videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  5251. }
  5252. mutedAudios[jid] = isMuted;
  5253. if (xmpp.isModerator()) {
  5254. VideoLayout.updateRemoteVideoMenu(jid, isMuted);
  5255. }
  5256. if (videoSpanId)
  5257. VideoLayout.showAudioIndicator(videoSpanId, isMuted);
  5258. });
  5259. /**
  5260. * On video muted event.
  5261. */
  5262. $(document).bind('videomuted.muc', function (event, jid, value) {
  5263. var isMuted = (value === "true");
  5264. if(!RTC.muteRemoteVideoStream(jid, isMuted))
  5265. return;
  5266. Avatar.showUserAvatar(jid, isMuted);
  5267. var videoSpanId = null;
  5268. if (jid === xmpp.myJid()) {
  5269. videoSpanId = 'localVideoContainer';
  5270. } else {
  5271. VideoLayout.ensurePeerContainerExists(jid);
  5272. videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  5273. }
  5274. if (videoSpanId)
  5275. VideoLayout.showVideoIndicator(videoSpanId, value);
  5276. });
  5277. /**
  5278. * Display name changed.
  5279. */
  5280. my.onDisplayNameChanged =
  5281. function (jid, displayName, status) {
  5282. var name = null;
  5283. if (jid === 'localVideoContainer'
  5284. || jid === xmpp.myJid()) {
  5285. name = nickname;
  5286. setDisplayName('localVideoContainer',
  5287. displayName);
  5288. } else {
  5289. VideoLayout.ensurePeerContainerExists(jid);
  5290. name = $('#participant_' + Strophe.getResourceFromJid(jid) + "_name").text();
  5291. setDisplayName(
  5292. 'participant_' + Strophe.getResourceFromJid(jid),
  5293. displayName,
  5294. status);
  5295. }
  5296. if(jid === 'localVideoContainer')
  5297. jid = xmpp.myJid();
  5298. if(!name || name != displayName)
  5299. API.triggerEvent("displayNameChange",{jid: jid, displayname: displayName});
  5300. };
  5301. /**
  5302. * On dominant speaker changed event.
  5303. */
  5304. $(document).bind('dominantspeakerchanged', function (event, resourceJid) {
  5305. // We ignore local user events.
  5306. if (resourceJid
  5307. === xmpp.myResource())
  5308. return;
  5309. // Update the current dominant speaker.
  5310. if (resourceJid !== currentDominantSpeaker) {
  5311. var oldSpeakerVideoSpanId = "participant_" + currentDominantSpeaker,
  5312. newSpeakerVideoSpanId = "participant_" + resourceJid;
  5313. if($("#" + oldSpeakerVideoSpanId + ">span.displayname").text() ===
  5314. interfaceConfig.DEFAULT_DOMINANT_SPEAKER_DISPLAY_NAME) {
  5315. setDisplayName(oldSpeakerVideoSpanId, null);
  5316. }
  5317. if($("#" + newSpeakerVideoSpanId + ">span.displayname").text() ===
  5318. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME) {
  5319. setDisplayName(newSpeakerVideoSpanId,
  5320. interfaceConfig.DEFAULT_DOMINANT_SPEAKER_DISPLAY_NAME);
  5321. }
  5322. currentDominantSpeaker = resourceJid;
  5323. } else {
  5324. return;
  5325. }
  5326. // Obtain container for new dominant speaker.
  5327. var container = document.getElementById(
  5328. 'participant_' + resourceJid);
  5329. // Local video will not have container found, but that's ok
  5330. // since we don't want to switch to local video.
  5331. if (container && !focusedVideoInfo)
  5332. {
  5333. var video = container.getElementsByTagName("video");
  5334. // Update the large video if the video source is already available,
  5335. // otherwise wait for the "videoactive.jingle" event.
  5336. if (video.length && video[0].currentTime > 0)
  5337. VideoLayout.updateLargeVideo(RTC.getVideoSrc(video[0]), resourceJid);
  5338. }
  5339. });
  5340. /**
  5341. * On last N change event.
  5342. *
  5343. * @param event the event that notified us
  5344. * @param lastNEndpoints the list of last N endpoints
  5345. * @param endpointsEnteringLastN the list currently entering last N
  5346. * endpoints
  5347. */
  5348. $(document).bind('lastnchanged', function ( event,
  5349. lastNEndpoints,
  5350. endpointsEnteringLastN,
  5351. stream) {
  5352. if (lastNCount !== lastNEndpoints.length)
  5353. lastNCount = lastNEndpoints.length;
  5354. lastNEndpointsCache = lastNEndpoints;
  5355. // Say A, B, C, D, E, and F are in a conference and LastN = 3.
  5356. //
  5357. // If LastN drops to, say, 2, because of adaptivity, then E should see
  5358. // thumbnails for A, B and C. A and B are in E's server side LastN set,
  5359. // so E sees them. C is only in E's local LastN set.
  5360. //
  5361. // If F starts talking and LastN = 3, then E should see thumbnails for
  5362. // F, A, B. B gets "ejected" from E's server side LastN set, but it
  5363. // enters E's local LastN ejecting C.
  5364. // Increase the local LastN set size, if necessary.
  5365. if (lastNCount > localLastNCount) {
  5366. localLastNCount = lastNCount;
  5367. }
  5368. // Update the local LastN set preserving the order in which the
  5369. // endpoints appeared in the LastN/local LastN set.
  5370. var nextLocalLastNSet = lastNEndpoints.slice(0);
  5371. for (var i = 0; i < localLastNSet.length; i++) {
  5372. if (nextLocalLastNSet.length >= localLastNCount) {
  5373. break;
  5374. }
  5375. var resourceJid = localLastNSet[i];
  5376. if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
  5377. nextLocalLastNSet.push(resourceJid);
  5378. }
  5379. }
  5380. localLastNSet = nextLocalLastNSet;
  5381. var updateLargeVideo = false;
  5382. // Handle LastN/local LastN changes.
  5383. $('#remoteVideos>span').each(function( index, element ) {
  5384. var resourceJid = VideoLayout.getPeerContainerResourceJid(element);
  5385. var isReceived = true;
  5386. if (resourceJid
  5387. && lastNEndpoints.indexOf(resourceJid) < 0
  5388. && localLastNSet.indexOf(resourceJid) < 0) {
  5389. console.log("Remove from last N", resourceJid);
  5390. showPeerContainer(resourceJid, 'hide');
  5391. isReceived = false;
  5392. } else if (resourceJid
  5393. && $('#participant_' + resourceJid).is(':visible')
  5394. && lastNEndpoints.indexOf(resourceJid) < 0
  5395. && localLastNSet.indexOf(resourceJid) >= 0) {
  5396. showPeerContainer(resourceJid, 'avatar');
  5397. isReceived = false;
  5398. }
  5399. if (!isReceived) {
  5400. // resourceJid has dropped out of the server side lastN set, so
  5401. // it is no longer being received. If resourceJid was being
  5402. // displayed in the large video we have to switch to another
  5403. // user.
  5404. var largeVideoResource = largeVideoState.userResourceJid;
  5405. if (!updateLargeVideo && resourceJid === largeVideoResource) {
  5406. updateLargeVideo = true;
  5407. }
  5408. }
  5409. });
  5410. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  5411. endpointsEnteringLastN = lastNEndpoints;
  5412. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  5413. endpointsEnteringLastN.forEach(function (resourceJid) {
  5414. var isVisible = $('#participant_' + resourceJid).is(':visible');
  5415. showPeerContainer(resourceJid, 'show');
  5416. if (!isVisible) {
  5417. console.log("Add to last N", resourceJid);
  5418. var jid = xmpp.findJidFromResource(resourceJid);
  5419. var mediaStream = RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE];
  5420. var sel = $('#participant_' + resourceJid + '>video');
  5421. var videoStream = simulcast.getReceivingVideoStream(
  5422. mediaStream.stream);
  5423. RTC.attachMediaStream(sel, videoStream);
  5424. if (lastNPickupJid == mediaStream.peerjid) {
  5425. // Clean up the lastN pickup jid.
  5426. lastNPickupJid = null;
  5427. // Don't fire the events again, they've already
  5428. // been fired in the contact list click handler.
  5429. VideoLayout.handleVideoThumbClicked(
  5430. $(sel).attr('src'),
  5431. false,
  5432. Strophe.getResourceFromJid(mediaStream.peerjid));
  5433. updateLargeVideo = false;
  5434. }
  5435. waitForRemoteVideo(sel, mediaStream.ssrc, mediaStream.stream, resourceJid);
  5436. }
  5437. })
  5438. }
  5439. // The endpoint that was being shown in the large video has dropped out
  5440. // of the lastN set and there was no lastN pickup jid. We need to update
  5441. // the large video now.
  5442. if (updateLargeVideo) {
  5443. var resource, container, src;
  5444. var myResource
  5445. = xmpp.myResource();
  5446. // Find out which endpoint to show in the large video.
  5447. for (var i = 0; i < lastNEndpoints.length; i++) {
  5448. resource = lastNEndpoints[i];
  5449. if (!resource || resource === myResource)
  5450. continue;
  5451. container = $("#participant_" + resource);
  5452. if (container.length == 0)
  5453. continue;
  5454. src = $('video', container).attr('src');
  5455. if (!src)
  5456. continue;
  5457. // videoSrcToSsrc needs to be update for this call to succeed.
  5458. VideoLayout.updateLargeVideo(src);
  5459. break;
  5460. }
  5461. }
  5462. });
  5463. $(document).bind('simulcastlayerschanging', function (event, endpointSimulcastLayers) {
  5464. endpointSimulcastLayers.forEach(function (esl) {
  5465. var resource = esl.endpoint;
  5466. // if lastN is enabled *and* the endpoint is *not* in the lastN set,
  5467. // then ignore the event (= do not preload anything).
  5468. //
  5469. // The bridge could probably stop sending this message if it's for
  5470. // an endpoint that's not in lastN.
  5471. if (lastNCount != -1
  5472. && (lastNCount < 1 || lastNEndpointsCache.indexOf(resource) === -1)) {
  5473. return;
  5474. }
  5475. var primarySSRC = esl.simulcastLayer.primarySSRC;
  5476. // Get session and stream from primary ssrc.
  5477. var res = simulcast.getReceivingVideoStreamBySSRC(primarySSRC);
  5478. var sid = res.sid;
  5479. var electedStream = res.stream;
  5480. if (sid && electedStream) {
  5481. var msid = simulcast.getRemoteVideoStreamIdBySSRC(primarySSRC);
  5482. console.info([esl, primarySSRC, msid, sid, electedStream]);
  5483. var msidParts = msid.split(' ');
  5484. var preload = (Strophe.getResourceFromJid(xmpp.getJidFromSSRC(primarySSRC)) == largeVideoState.userResourceJid);
  5485. if (preload) {
  5486. if (largeVideoState.preload)
  5487. {
  5488. $(largeVideoState.preload).remove();
  5489. }
  5490. console.info('Preloading remote video');
  5491. largeVideoState.preload = $('<video autoplay></video>');
  5492. // ssrcs are unique in an rtp session
  5493. largeVideoState.preload_ssrc = primarySSRC;
  5494. RTC.attachMediaStream(largeVideoState.preload, electedStream)
  5495. }
  5496. } else {
  5497. console.error('Could not find a stream or a session.', sid, electedStream);
  5498. }
  5499. });
  5500. });
  5501. /**
  5502. * On simulcast layers changed event.
  5503. */
  5504. $(document).bind('simulcastlayerschanged', function (event, endpointSimulcastLayers) {
  5505. endpointSimulcastLayers.forEach(function (esl) {
  5506. var resource = esl.endpoint;
  5507. // if lastN is enabled *and* the endpoint is *not* in the lastN set,
  5508. // then ignore the event (= do not change large video/thumbnail
  5509. // SRCs).
  5510. //
  5511. // Note that even if we ignore the "changed" event in this event
  5512. // handler, the bridge must continue sending these events because
  5513. // the simulcast code in simulcast.js uses it to know what's going
  5514. // to be streamed by the bridge when/if the endpoint gets back into
  5515. // the lastN set.
  5516. if (lastNCount != -1
  5517. && (lastNCount < 1 || lastNEndpointsCache.indexOf(resource) === -1)) {
  5518. return;
  5519. }
  5520. var primarySSRC = esl.simulcastLayer.primarySSRC;
  5521. // Get session and stream from primary ssrc.
  5522. var res = simulcast.getReceivingVideoStreamBySSRC(primarySSRC);
  5523. var sid = res.sid;
  5524. var electedStream = res.stream;
  5525. if (sid && electedStream) {
  5526. var msid = simulcast.getRemoteVideoStreamIdBySSRC(primarySSRC);
  5527. console.info('Switching simulcast substream.');
  5528. console.info([esl, primarySSRC, msid, sid, electedStream]);
  5529. var msidParts = msid.split(' ');
  5530. var selRemoteVideo = $(['#', 'remoteVideo_', sid, '_', msidParts[0]].join(''));
  5531. var updateLargeVideo = (Strophe.getResourceFromJid(xmpp.getJidFromSSRC(primarySSRC))
  5532. == largeVideoState.userResourceJid);
  5533. var updateFocusedVideoSrc = (focusedVideoInfo && focusedVideoInfo.src && focusedVideoInfo.src != '' &&
  5534. (RTC.getVideoSrc(selRemoteVideo[0]) == focusedVideoInfo.src));
  5535. var electedStreamUrl;
  5536. if (largeVideoState.preload_ssrc == primarySSRC)
  5537. {
  5538. RTC.setVideoSrc(selRemoteVideo[0], RTC.getVideoSrc(largeVideoState.preload[0]));
  5539. }
  5540. else
  5541. {
  5542. if (largeVideoState.preload
  5543. && largeVideoState.preload != null) {
  5544. $(largeVideoState.preload).remove();
  5545. }
  5546. largeVideoState.preload_ssrc = 0;
  5547. RTC.attachMediaStream(selRemoteVideo, electedStream);
  5548. }
  5549. var jid = xmpp.getJidFromSSRC(primarySSRC);
  5550. if (updateLargeVideo) {
  5551. VideoLayout.updateLargeVideo(RTC.getVideoSrc(selRemoteVideo[0]), null,
  5552. Strophe.getResourceFromJid(jid));
  5553. }
  5554. if (updateFocusedVideoSrc) {
  5555. focusedVideoInfo.src = RTC.getVideoSrc(selRemoteVideo[0]);
  5556. }
  5557. var videoId;
  5558. if(resource == xmpp.myResource())
  5559. {
  5560. videoId = "localVideoContainer";
  5561. }
  5562. else
  5563. {
  5564. videoId = "participant_" + resource;
  5565. }
  5566. var connectionIndicator = VideoLayout.connectionIndicators[videoId];
  5567. if(connectionIndicator)
  5568. connectionIndicator.updatePopoverData();
  5569. } else {
  5570. console.error('Could not find a stream or a sid.', sid, electedStream);
  5571. }
  5572. });
  5573. });
  5574. /**
  5575. * Updates local stats
  5576. * @param percent
  5577. * @param object
  5578. */
  5579. my.updateLocalConnectionStats = function (percent, object) {
  5580. var resolution = null;
  5581. if(object.resolution !== null)
  5582. {
  5583. resolution = object.resolution;
  5584. object.resolution = resolution[xmpp.myJid()];
  5585. delete resolution[xmpp.myJid()];
  5586. }
  5587. updateStatsIndicator("localVideoContainer", percent, object);
  5588. for(var jid in resolution)
  5589. {
  5590. if(resolution[jid] === null)
  5591. continue;
  5592. var id = 'participant_' + Strophe.getResourceFromJid(jid);
  5593. if(VideoLayout.connectionIndicators[id])
  5594. {
  5595. VideoLayout.connectionIndicators[id].updateResolution(resolution[jid]);
  5596. }
  5597. }
  5598. };
  5599. /**
  5600. * Updates remote stats.
  5601. * @param jid the jid associated with the stats
  5602. * @param percent the connection quality percent
  5603. * @param object the stats data
  5604. */
  5605. my.updateConnectionStats = function (jid, percent, object) {
  5606. var resourceJid = Strophe.getResourceFromJid(jid);
  5607. var videoSpanId = 'participant_' + resourceJid;
  5608. updateStatsIndicator(videoSpanId, percent, object);
  5609. };
  5610. /**
  5611. * Removes the connection
  5612. * @param jid
  5613. */
  5614. my.removeConnectionIndicator = function (jid) {
  5615. if(VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)])
  5616. VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)].remove();
  5617. };
  5618. /**
  5619. * Hides the connection indicator
  5620. * @param jid
  5621. */
  5622. my.hideConnectionIndicator = function (jid) {
  5623. if(VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)])
  5624. VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)].hide();
  5625. };
  5626. /**
  5627. * Hides all the indicators
  5628. */
  5629. my.onStatsStop = function () {
  5630. for(var indicator in VideoLayout.connectionIndicators)
  5631. {
  5632. VideoLayout.connectionIndicators[indicator].hideIndicator();
  5633. }
  5634. };
  5635. my.participantLeft = function (jid) {
  5636. // Unlock large video
  5637. if (focusedVideoInfo && focusedVideoInfo.jid === jid)
  5638. {
  5639. console.info("Focused video owner has left the conference");
  5640. focusedVideoInfo = null;
  5641. }
  5642. }
  5643. return my;
  5644. }(VideoLayout || {}));
  5645. module.exports = VideoLayout;
  5646. },{"../audio_levels/AudioLevels":2,"../avatar/Avatar":5,"../etherpad/Etherpad":6,"../prezi/Prezi":7,"../side_pannels/chat/Chat":9,"../side_pannels/contactlist/ContactList":13,"../util/UIUtil":22,"./ConnectionIndicator":23}],25:[function(require,module,exports){
  5647. //var nouns = [
  5648. //];
  5649. var pluralNouns = [
  5650. "Aliens", "Animals", "Antelopes", "Ants", "Apes", "Apples", "Baboons", "Bacteria", "Badgers", "Bananas", "Bats",
  5651. "Bears", "Birds", "Bonobos", "Brides", "Bugs", "Bulls", "Butterflies", "Cheetahs",
  5652. "Cherries", "Chicken", "Children", "Chimps", "Clowns", "Cows", "Creatures", "Dinosaurs", "Dogs", "Dolphins",
  5653. "Donkeys", "Dragons", "Ducks", "Dwarfs", "Eagles", "Elephants", "Elves", "FAIL", "Fathers",
  5654. "Fish", "Flowers", "Frogs", "Fruit", "Fungi", "Galaxies", "Geese", "Goats",
  5655. "Gorillas", "Hedgehogs", "Hippos", "Horses", "Hunters", "Insects", "Kids", "Knights",
  5656. "Lemons", "Lemurs", "Leopards", "LifeForms", "Lions", "Lizards", "Mice", "Monkeys", "Monsters",
  5657. "Mushrooms", "Octopodes", "Oranges", "Orangutans", "Organisms", "Pants", "Parrots", "Penguins",
  5658. "People", "Pigeons", "Pigs", "Pineapples", "Plants", "Potatoes", "Priests", "Rats", "Reptiles", "Reptilians",
  5659. "Rhinos", "Seagulls", "Sheep", "Siblings", "Snakes", "Spaghetti", "Spiders", "Squid", "Squirrels",
  5660. "Stars", "Students", "Teachers", "Tigers", "Tomatoes", "Trees", "Vampires", "Vegetables", "Viruses", "Vulcans",
  5661. "Warewolves", "Weasels", "Whales", "Witches", "Wizards", "Wolves", "Workers", "Worms", "Zebras"
  5662. ];
  5663. //var places = [
  5664. //"Pub", "University", "Airport", "Library", "Mall", "Theater", "Stadium", "Office", "Show", "Gallows", "Beach",
  5665. // "Cemetery", "Hospital", "Reception", "Restaurant", "Bar", "Church", "House", "School", "Square", "Village",
  5666. // "Cinema", "Movies", "Party", "Restroom", "End", "Jail", "PostOffice", "Station", "Circus", "Gates", "Entrance",
  5667. // "Bridge"
  5668. //];
  5669. var verbs = [
  5670. "Abandon", "Adapt", "Advertise", "Answer", "Anticipate", "Appreciate",
  5671. "Approach", "Argue", "Ask", "Bite", "Blossom", "Blush", "Breathe", "Breed", "Bribe", "Burn", "Calculate",
  5672. "Clean", "Code", "Communicate", "Compute", "Confess", "Confiscate", "Conjugate", "Conjure", "Consume",
  5673. "Contemplate", "Crawl", "Dance", "Delegate", "Devour", "Develop", "Differ", "Discuss",
  5674. "Dissolve", "Drink", "Eat", "Elaborate", "Emancipate", "Estimate", "Expire", "Extinguish",
  5675. "Extract", "FAIL", "Facilitate", "Fall", "Feed", "Finish", "Floss", "Fly", "Follow", "Fragment", "Freeze",
  5676. "Gather", "Glow", "Grow", "Hex", "Hide", "Hug", "Hurry", "Improve", "Intersect", "Investigate", "Jinx",
  5677. "Joke", "Jubilate", "Kiss", "Laugh", "Manage", "Meet", "Merge", "Move", "Object", "Observe", "Offer",
  5678. "Paint", "Participate", "Party", "Perform", "Plan", "Pursue", "Pierce", "Play", "Postpone", "Pray", "Proclaim",
  5679. "Question", "Read", "Reckon", "Rejoice", "Represent", "Resize", "Rhyme", "Scream", "Search", "Select", "Share", "Shoot",
  5680. "Shout", "Signal", "Sing", "Skate", "Sleep", "Smile", "Smoke", "Solve", "Spell", "Steer", "Stink",
  5681. "Substitute", "Swim", "Taste", "Teach", "Terminate", "Think", "Type", "Unite", "Vanish", "Worship"
  5682. ];
  5683. var adverbs = [
  5684. "Absently", "Accurately", "Accusingly", "Adorably", "AllTheTime", "Alone", "Always", "Amazingly", "Angrily",
  5685. "Anxiously", "Anywhere", "Appallingly", "Apparently", "Articulately", "Astonishingly", "Badly", "Barely",
  5686. "Beautifully", "Blindly", "Bravely", "Brightly", "Briskly", "Brutally", "Calmly", "Carefully", "Casually",
  5687. "Cautiously", "Cleverly", "Constantly", "Correctly", "Crazily", "Curiously", "Cynically", "Daily",
  5688. "Dangerously", "Deliberately", "Delicately", "Desperately", "Discreetly", "Eagerly", "Easily", "Euphoricly",
  5689. "Evenly", "Everywhere", "Exactly", "Expectantly", "Extensively", "FAIL", "Ferociously", "Fiercely", "Finely",
  5690. "Flatly", "Frequently", "Frighteningly", "Gently", "Gloriously", "Grimly", "Guiltily", "Happily",
  5691. "Hard", "Hastily", "Heroically", "High", "Highly", "Hourly", "Humbly", "Hysterically", "Immensely",
  5692. "Impartially", "Impolitely", "Indifferently", "Intensely", "Jealously", "Jovially", "Kindly", "Lazily",
  5693. "Lightly", "Loudly", "Lovingly", "Loyally", "Magnificently", "Malevolently", "Merrily", "Mightily", "Miserably",
  5694. "Mysteriously", "NOT", "Nervously", "Nicely", "Nowhere", "Objectively", "Obnoxiously", "Obsessively",
  5695. "Obviously", "Often", "Painfully", "Patiently", "Playfully", "Politely", "Poorly", "Precisely", "Promptly",
  5696. "Quickly", "Quietly", "Randomly", "Rapidly", "Rarely", "Recklessly", "Regularly", "Remorsefully", "Responsibly",
  5697. "Rudely", "Ruthlessly", "Sadly", "Scornfully", "Seamlessly", "Seldom", "Selfishly", "Seriously", "Shakily",
  5698. "Sharply", "Sideways", "Silently", "Sleepily", "Slightly", "Slowly", "Slyly", "Smoothly", "Softly", "Solemnly", "Steadily", "Sternly", "Strangely", "Strongly", "Stunningly", "Surely", "Tenderly", "Thoughtfully",
  5699. "Tightly", "Uneasily", "Vanishingly", "Violently", "Warmly", "Weakly", "Wearily", "Weekly", "Weirdly", "Well",
  5700. "Well", "Wickedly", "Wildly", "Wisely", "Wonderfully", "Yearly"
  5701. ];
  5702. var adjectives = [
  5703. "Abominable", "Accurate", "Adorable", "All", "Alleged", "Ancient", "Angry", "Angry", "Anxious", "Appalling",
  5704. "Apparent", "Astonishing", "Attractive", "Awesome", "Baby", "Bad", "Beautiful", "Benign", "Big", "Bitter",
  5705. "Blind", "Blue", "Bold", "Brave", "Bright", "Brisk", "Calm", "Camouflaged", "Casual", "Cautious",
  5706. "Choppy", "Chosen", "Clever", "Cold", "Cool", "Crawly", "Crazy", "Creepy", "Cruel", "Curious", "Cynical",
  5707. "Dangerous", "Dark", "Delicate", "Desperate", "Difficult", "Discreet", "Disguised", "Dizzy",
  5708. "Dumb", "Eager", "Easy", "Edgy", "Electric", "Elegant", "Emancipated", "Enormous", "Euphoric", "Evil",
  5709. "FAIL", "Fast", "Ferocious", "Fierce", "Fine", "Flawed", "Flying", "Foolish", "Foxy",
  5710. "Freezing", "Funny", "Furious", "Gentle", "Glorious", "Golden", "Good", "Green", "Green", "Guilty",
  5711. "Hairy", "Happy", "Hard", "Hasty", "Hazy", "Heroic", "Hostile", "Hot", "Humble", "Humongous",
  5712. "Humorous", "Hysterical", "Idealistic", "Ignorant", "Immense", "Impartial", "Impolite", "Indifferent",
  5713. "Infuriated", "Insightful", "Intense", "Interesting", "Intimidated", "Intriguing", "Jealous", "Jolly", "Jovial",
  5714. "Jumpy", "Kind", "Laughing", "Lazy", "Liquid", "Lonely", "Longing", "Loud", "Loving", "Loyal", "Macabre", "Mad",
  5715. "Magical", "Magnificent", "Malevolent", "Medieval", "Memorable", "Mere", "Merry", "Mighty",
  5716. "Mischievous", "Miserable", "Modified", "Moody", "Most", "Mysterious", "Mystical", "Needy",
  5717. "Nervous", "Nice", "Objective", "Obnoxious", "Obsessive", "Obvious", "Opinionated", "Orange",
  5718. "Painful", "Passionate", "Perfect", "Pink", "Playful", "Poisonous", "Polite", "Poor", "Popular", "Powerful",
  5719. "Precise", "Preserved", "Pretty", "Purple", "Quick", "Quiet", "Random", "Rapid", "Rare", "Real",
  5720. "Reassuring", "Reckless", "Red", "Regular", "Remorseful", "Responsible", "Rich", "Rude", "Ruthless",
  5721. "Sad", "Scared", "Scary", "Scornful", "Screaming", "Selfish", "Serious", "Shady", "Shaky", "Sharp",
  5722. "Shiny", "Shy", "Simple", "Sleepy", "Slow", "Sly", "Small", "Smart", "Smelly", "Smiling", "Smooth",
  5723. "Smug", "Sober", "Soft", "Solemn", "Square", "Square", "Steady", "Strange", "Strong",
  5724. "Stunning", "Subjective", "Successful", "Surly", "Sweet", "Tactful", "Tense",
  5725. "Thoughtful", "Tight", "Tiny", "Tolerant", "Uneasy", "Unique", "Unseen", "Warm", "Weak",
  5726. "Weird", "WellCooked", "Wild", "Wise", "Witty", "Wonderful", "Worried", "Yellow", "Young",
  5727. "Zealous"
  5728. ];
  5729. //var pronouns = [
  5730. //];
  5731. //var conjunctions = [
  5732. //"And", "Or", "For", "Above", "Before", "Against", "Between"
  5733. //];
  5734. /*
  5735. * Maps a string (category name) to the array of words from that category.
  5736. */
  5737. var CATEGORIES =
  5738. {
  5739. //"_NOUN_": nouns,
  5740. "_PLURALNOUN_": pluralNouns,
  5741. //"_PLACE_": places,
  5742. "_VERB_": verbs,
  5743. "_ADVERB_": adverbs,
  5744. "_ADJECTIVE_": adjectives
  5745. //"_PRONOUN_": pronouns,
  5746. //"_CONJUNCTION_": conjunctions,
  5747. };
  5748. var PATTERNS = [
  5749. "_ADJECTIVE__PLURALNOUN__VERB__ADVERB_"
  5750. // BeautifulFungiOrSpaghetti
  5751. //"_ADJECTIVE__PLURALNOUN__CONJUNCTION__PLURALNOUN_",
  5752. // AmazinglyScaryToy
  5753. //"_ADVERB__ADJECTIVE__NOUN_",
  5754. // NeitherTrashNorRifle
  5755. //"Neither_NOUN_Nor_NOUN_",
  5756. //"Either_NOUN_Or_NOUN_",
  5757. // EitherCopulateOrInvestigate
  5758. //"Either_VERB_Or_VERB_",
  5759. //"Neither_VERB_Nor_VERB_",
  5760. //"The_ADJECTIVE__ADJECTIVE__NOUN_",
  5761. //"The_ADVERB__ADJECTIVE__NOUN_",
  5762. //"The_ADVERB__ADJECTIVE__NOUN_s",
  5763. //"The_ADVERB__ADJECTIVE__PLURALNOUN__VERB_",
  5764. // WolvesComputeBadly
  5765. //"_PLURALNOUN__VERB__ADVERB_",
  5766. // UniteFacilitateAndMerge
  5767. //"_VERB__VERB_And_VERB_",
  5768. //NastyWitchesAtThePub
  5769. //"_ADJECTIVE__PLURALNOUN_AtThe_PLACE_",
  5770. ];
  5771. /*
  5772. * Returns a random element from the array 'arr'
  5773. */
  5774. function randomElement(arr)
  5775. {
  5776. return arr[Math.floor(Math.random() * arr.length)];
  5777. }
  5778. /*
  5779. * Returns true if the string 's' contains one of the
  5780. * template strings.
  5781. */
  5782. function hasTemplate(s)
  5783. {
  5784. for (var template in CATEGORIES){
  5785. if (s.indexOf(template) >= 0){
  5786. return true;
  5787. }
  5788. }
  5789. }
  5790. /**
  5791. * Generates new room name.
  5792. */
  5793. var RoomNameGenerator = {
  5794. generateRoomWithoutSeparator: function()
  5795. {
  5796. // Note that if more than one pattern is available, the choice of 'name' won't be random (names from patterns
  5797. // with fewer options will have higher probability of being chosen that names from patterns with more options).
  5798. var name = randomElement(PATTERNS);
  5799. var word;
  5800. while (hasTemplate(name)){
  5801. for (var template in CATEGORIES){
  5802. word = randomElement(CATEGORIES[template]);
  5803. name = name.replace(template, word);
  5804. }
  5805. }
  5806. return name;
  5807. }
  5808. }
  5809. module.exports = RoomNameGenerator;
  5810. },{}],26:[function(require,module,exports){
  5811. var animateTimeout, updateTimeout;
  5812. var RoomNameGenerator = require("./RoomnameGenerator");
  5813. function enter_room()
  5814. {
  5815. var val = $("#enter_room_field").val();
  5816. if(!val) {
  5817. val = $("#enter_room_field").attr("room_name");
  5818. }
  5819. if (val) {
  5820. window.location.pathname = "/" + val;
  5821. }
  5822. }
  5823. function animate(word) {
  5824. var currentVal = $("#enter_room_field").attr("placeholder");
  5825. $("#enter_room_field").attr("placeholder", currentVal + word.substr(0, 1));
  5826. animateTimeout = setTimeout(function() {
  5827. animate(word.substring(1, word.length))
  5828. }, 70);
  5829. }
  5830. function update_roomname()
  5831. {
  5832. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  5833. $("#enter_room_field").attr("room_name", word);
  5834. $("#enter_room_field").attr("placeholder", "");
  5835. clearTimeout(animateTimeout);
  5836. animate(word);
  5837. updateTimeout = setTimeout(update_roomname, 10000);
  5838. }
  5839. function setupWelcomePage()
  5840. {
  5841. $("#videoconference_page").hide();
  5842. $("#domain_name").text(
  5843. window.location.protocol + "//" + window.location.host + "/");
  5844. $("span[name='appName']").text(interfaceConfig.APP_NAME);
  5845. if (interfaceConfig.SHOW_JITSI_WATERMARK) {
  5846. var leftWatermarkDiv
  5847. = $("#welcome_page_header div[class='watermark leftwatermark']");
  5848. if(leftWatermarkDiv && leftWatermarkDiv.length > 0)
  5849. {
  5850. leftWatermarkDiv.css({display: 'block'});
  5851. leftWatermarkDiv.parent().get(0).href
  5852. = interfaceConfig.JITSI_WATERMARK_LINK;
  5853. }
  5854. }
  5855. if (interfaceConfig.SHOW_BRAND_WATERMARK) {
  5856. var rightWatermarkDiv
  5857. = $("#welcome_page_header div[class='watermark rightwatermark']");
  5858. if(rightWatermarkDiv && rightWatermarkDiv.length > 0) {
  5859. rightWatermarkDiv.css({display: 'block'});
  5860. rightWatermarkDiv.parent().get(0).href
  5861. = interfaceConfig.BRAND_WATERMARK_LINK;
  5862. rightWatermarkDiv.get(0).style.backgroundImage
  5863. = "url(images/rightwatermark.png)";
  5864. }
  5865. }
  5866. if (interfaceConfig.SHOW_POWERED_BY) {
  5867. $("#welcome_page_header>a[class='poweredby']")
  5868. .css({display: 'block'});
  5869. }
  5870. $("#enter_room_button").click(function()
  5871. {
  5872. enter_room();
  5873. });
  5874. $("#enter_room_field").keydown(function (event) {
  5875. if (event.keyCode === 13 /* enter */) {
  5876. enter_room();
  5877. }
  5878. });
  5879. if (!(interfaceConfig.GENERATE_ROOMNAMES_ON_WELCOME_PAGE === false)){
  5880. var updateTimeout;
  5881. var animateTimeout;
  5882. $("#reload_roomname").click(function () {
  5883. clearTimeout(updateTimeout);
  5884. clearTimeout(animateTimeout);
  5885. update_roomname();
  5886. });
  5887. $("#reload_roomname").show();
  5888. update_roomname();
  5889. }
  5890. $("#disable_welcome").click(function () {
  5891. window.localStorage.welcomePageDisabled
  5892. = $("#disable_welcome").is(":checked");
  5893. });
  5894. }
  5895. module.exports = setupWelcomePage;
  5896. },{"./RoomnameGenerator":25}]},{},[1])(1)
  5897. });