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

UI.bundle.js 223KB

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