Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

UI.bundle.js 233KB

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