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.

videolayout.js 70KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  1. var VideoLayout = (function (my) {
  2. var currentDominantSpeaker = null;
  3. var lastNCount = config.channelLastN;
  4. var lastNEndpointsCache = [];
  5. var largeVideoState = {
  6. updateInProgress: false,
  7. newSrc: ''
  8. };
  9. my.connectionIndicators = {};
  10. my.changeLocalAudio = function(stream) {
  11. connection.jingle.localAudio = stream;
  12. RTC.attachMediaStream($('#localAudio'), stream);
  13. document.getElementById('localAudio').autoplay = true;
  14. document.getElementById('localAudio').volume = 0;
  15. };
  16. my.changeLocalVideo = function(stream, flipX) {
  17. connection.jingle.localVideo = stream;
  18. var localVideo = document.createElement('video');
  19. localVideo.id = 'localVideo_' + stream.id;
  20. localVideo.autoplay = true;
  21. localVideo.volume = 0; // is it required if audio is separated ?
  22. localVideo.oncontextmenu = function () { return false; };
  23. var localVideoContainer = document.getElementById('localVideoWrapper');
  24. localVideoContainer.appendChild(localVideo);
  25. // Set default display name.
  26. setDisplayName('localVideoContainer');
  27. if(!VideoLayout.connectionIndicators["localVideoContainer"]) {
  28. VideoLayout.connectionIndicators["localVideoContainer"]
  29. = new ConnectionIndicator($("#localVideoContainer")[0], null);
  30. }
  31. AudioLevels.updateAudioLevelCanvas();
  32. var localVideoSelector = $('#' + localVideo.id);
  33. // Add click handler to both video and video wrapper elements in case
  34. // there's no video.
  35. localVideoSelector.click(function () {
  36. VideoLayout.handleVideoThumbClicked(localVideo.src);
  37. });
  38. $('#localVideoContainer').click(function () {
  39. VideoLayout.handleVideoThumbClicked(localVideo.src);
  40. });
  41. // Add hover handler
  42. $('#localVideoContainer').hover(
  43. function() {
  44. VideoLayout.showDisplayName('localVideoContainer', true);
  45. },
  46. function() {
  47. if (!VideoLayout.isLargeVideoVisible()
  48. || localVideo.src !== $('#largeVideo').attr('src'))
  49. VideoLayout.showDisplayName('localVideoContainer', false);
  50. }
  51. );
  52. // Add stream ended handler
  53. stream.onended = function () {
  54. localVideoContainer.removeChild(localVideo);
  55. VideoLayout.updateRemovedVideo(localVideo.src);
  56. };
  57. // Flip video x axis if needed
  58. flipXLocalVideo = flipX;
  59. if (flipX) {
  60. localVideoSelector.addClass("flipVideoX");
  61. }
  62. // Attach WebRTC stream
  63. var videoStream = simulcast.getLocalVideoStream();
  64. RTC.attachMediaStream(localVideoSelector, videoStream);
  65. localVideoSrc = localVideo.src;
  66. VideoLayout.updateLargeVideo(localVideoSrc, 0);
  67. };
  68. /**
  69. * Checks if removed video is currently displayed and tries to display
  70. * another one instead.
  71. * @param removedVideoSrc src stream identifier of the video.
  72. */
  73. my.updateRemovedVideo = function(removedVideoSrc) {
  74. if (removedVideoSrc === $('#largeVideo').attr('src')) {
  75. // this is currently displayed as large
  76. // pick the last visible video in the row
  77. // if nobody else is left, this picks the local video
  78. var pick
  79. = $('#remoteVideos>span[id!="mixedstream"]:visible:last>video')
  80. .get(0);
  81. if (!pick) {
  82. console.info("Last visible video no longer exists");
  83. pick = $('#remoteVideos>span[id!="mixedstream"]>video').get(0);
  84. if (!pick || !pick.src) {
  85. // Try local video
  86. console.info("Fallback to local video...");
  87. pick = $('#remoteVideos>span>span>video').get(0);
  88. }
  89. }
  90. // mute if localvideo
  91. if (pick) {
  92. VideoLayout.updateLargeVideo(pick.src, pick.volume);
  93. } else {
  94. console.warn("Failed to elect large video");
  95. }
  96. }
  97. };
  98. /**
  99. * Updates the large video with the given new video source.
  100. */
  101. my.updateLargeVideo = function(newSrc, vol) {
  102. console.log('hover in', newSrc);
  103. if ($('#largeVideo').attr('src') != newSrc) {
  104. // Due to the simulcast the localVideoSrc may have changed when the
  105. // fadeOut event triggers. In that case the getJidFromVideoSrc and
  106. // isVideoSrcDesktop methods will not function correctly.
  107. //
  108. // Also, again due to the simulcast, the updateLargeVideo method can
  109. // be called multiple times almost simultaneously. Therefore, we
  110. // store the state here and update only once.
  111. largeVideoState.newSrc = newSrc;
  112. largeVideoState.isVisible = $('#largeVideo').is(':visible');
  113. largeVideoState.isDesktop = isVideoSrcDesktop(newSrc);
  114. largeVideoState.userJid = getJidFromVideoSrc(newSrc);
  115. // Screen stream is already rotated
  116. largeVideoState.flipX = (newSrc === localVideoSrc) && flipXLocalVideo;
  117. var oldSrc = $('#largeVideo').attr('src');
  118. largeVideoState.oldJid = getJidFromVideoSrc(oldSrc);
  119. var userChanged = false;
  120. if (largeVideoState.oldJid != largeVideoState.userJid) {
  121. userChanged = true;
  122. // we want the notification to trigger even if userJid is undefined,
  123. // or null.
  124. $(document).trigger("selectedendpointchanged", [largeVideoState.userJid]);
  125. }
  126. if (!largeVideoState.updateInProgress) {
  127. largeVideoState.updateInProgress = true;
  128. var doUpdate = function () {
  129. if (!userChanged && largeVideoState.preload
  130. && largeVideoState.preload != null
  131. && $(largeVideoState.preload).attr('src') == newSrc) {
  132. console.info('Switching to preloaded video');
  133. var attributes = $('#largeVideo').prop("attributes");
  134. // loop through largeVideo attributes and apply them on
  135. // preload.
  136. $.each(attributes, function () {
  137. if (this.name != 'id' && this.name != 'src') {
  138. largeVideoState.preload.attr(this.name, this.value);
  139. }
  140. });
  141. largeVideoState.preload.appendTo($('#largeVideoContainer'));
  142. $('#largeVideo').attr('id', 'previousLargeVideo');
  143. largeVideoState.preload.attr('id', 'largeVideo');
  144. $('#previousLargeVideo').remove();
  145. largeVideoState.preload.on('loadedmetadata', function (e) {
  146. currentVideoWidth = this.videoWidth;
  147. currentVideoHeight = this.videoHeight;
  148. VideoLayout.positionLarge(currentVideoWidth, currentVideoHeight);
  149. });
  150. largeVideoState.preload = null;
  151. largeVideoState.preload_ssrc = 0;
  152. } else {
  153. $('#largeVideo').attr('src', largeVideoState.newSrc);
  154. }
  155. var videoTransform = document.getElementById('largeVideo')
  156. .style.webkitTransform;
  157. if (largeVideoState.flipX && videoTransform !== 'scaleX(-1)') {
  158. document.getElementById('largeVideo').style.webkitTransform
  159. = "scaleX(-1)";
  160. }
  161. else if (!largeVideoState.flipX && videoTransform === 'scaleX(-1)') {
  162. document.getElementById('largeVideo').style.webkitTransform
  163. = "none";
  164. }
  165. // Change the way we'll be measuring and positioning large video
  166. getVideoSize = largeVideoState.isDesktop
  167. ? getDesktopVideoSize
  168. : getCameraVideoSize;
  169. getVideoPosition = largeVideoState.isDesktop
  170. ? getDesktopVideoPosition
  171. : getCameraVideoPosition;
  172. // Only if the large video is currently visible.
  173. // Disable previous dominant speaker video.
  174. if (largeVideoState.oldJid) {
  175. var oldResourceJid = Strophe.getResourceFromJid(largeVideoState.oldJid);
  176. VideoLayout.enableDominantSpeaker(oldResourceJid, false);
  177. }
  178. // Enable new dominant speaker in the remote videos section.
  179. if (largeVideoState.userJid) {
  180. var resourceJid = Strophe.getResourceFromJid(largeVideoState.userJid);
  181. VideoLayout.enableDominantSpeaker(resourceJid, true);
  182. }
  183. if (userChanged && largeVideoState.isVisible) {
  184. // using "this" should be ok because we're called
  185. // from within the fadeOut event.
  186. $(this).fadeIn(300);
  187. }
  188. largeVideoState.updateInProgress = false;
  189. };
  190. if (userChanged) {
  191. $('#largeVideo').fadeOut(300, doUpdate);
  192. } else {
  193. doUpdate();
  194. }
  195. }
  196. }
  197. };
  198. my.handleVideoThumbClicked = function(videoSrc) {
  199. // Restore style for previously focused video
  200. var focusJid = getJidFromVideoSrc(focusedVideoSrc);
  201. var oldContainer = getParticipantContainer(focusJid);
  202. if (oldContainer) {
  203. oldContainer.removeClass("videoContainerFocused");
  204. }
  205. // Unlock current focused.
  206. if (focusedVideoSrc === videoSrc)
  207. {
  208. focusedVideoSrc = null;
  209. var dominantSpeakerVideo = null;
  210. // Enable the currently set dominant speaker.
  211. if (currentDominantSpeaker) {
  212. dominantSpeakerVideo
  213. = $('#participant_' + currentDominantSpeaker + '>video')
  214. .get(0);
  215. if (dominantSpeakerVideo) {
  216. VideoLayout.updateLargeVideo(dominantSpeakerVideo.src, 1);
  217. }
  218. }
  219. return;
  220. }
  221. // Lock new video
  222. focusedVideoSrc = videoSrc;
  223. // Update focused/pinned interface.
  224. var userJid = getJidFromVideoSrc(videoSrc);
  225. if (userJid)
  226. {
  227. var container = getParticipantContainer(userJid);
  228. container.addClass("videoContainerFocused");
  229. }
  230. // Triggers a "video.selected" event. The "false" parameter indicates
  231. // this isn't a prezi.
  232. $(document).trigger("video.selected", [false]);
  233. VideoLayout.updateLargeVideo(videoSrc, 1);
  234. $('audio').each(function (idx, el) {
  235. if (el.id.indexOf('mixedmslabel') !== -1) {
  236. el.volume = 0;
  237. el.volume = 1;
  238. }
  239. });
  240. };
  241. /**
  242. * Positions the large video.
  243. *
  244. * @param videoWidth the stream video width
  245. * @param videoHeight the stream video height
  246. */
  247. my.positionLarge = function (videoWidth, videoHeight) {
  248. var videoSpaceWidth = $('#videospace').width();
  249. var videoSpaceHeight = window.innerHeight;
  250. var videoSize = getVideoSize(videoWidth,
  251. videoHeight,
  252. videoSpaceWidth,
  253. videoSpaceHeight);
  254. var largeVideoWidth = videoSize[0];
  255. var largeVideoHeight = videoSize[1];
  256. var videoPosition = getVideoPosition(largeVideoWidth,
  257. largeVideoHeight,
  258. videoSpaceWidth,
  259. videoSpaceHeight);
  260. var horizontalIndent = videoPosition[0];
  261. var verticalIndent = videoPosition[1];
  262. positionVideo($('#largeVideo'),
  263. largeVideoWidth,
  264. largeVideoHeight,
  265. horizontalIndent, verticalIndent);
  266. };
  267. /**
  268. * Shows/hides the large video.
  269. */
  270. my.setLargeVideoVisible = function(isVisible) {
  271. var largeVideoJid = getJidFromVideoSrc($('#largeVideo').attr('src'));
  272. var resourceJid = Strophe.getResourceFromJid(largeVideoJid);
  273. if (isVisible) {
  274. $('#largeVideo').css({visibility: 'visible'});
  275. $('.watermark').css({visibility: 'visible'});
  276. VideoLayout.enableDominantSpeaker(resourceJid, true);
  277. }
  278. else {
  279. $('#largeVideo').css({visibility: 'hidden'});
  280. $('.watermark').css({visibility: 'hidden'});
  281. VideoLayout.enableDominantSpeaker(resourceJid, false);
  282. }
  283. };
  284. /**
  285. * Indicates if the large video is currently visible.
  286. *
  287. * @return <tt>true</tt> if visible, <tt>false</tt> - otherwise
  288. */
  289. my.isLargeVideoVisible = function() {
  290. return $('#largeVideo').is(':visible');
  291. };
  292. /**
  293. * Checks if container for participant identified by given peerJid exists
  294. * in the document and creates it eventually.
  295. *
  296. * @param peerJid peer Jid to check.
  297. *
  298. * @return Returns <tt>true</tt> if the peer container exists,
  299. * <tt>false</tt> - otherwise
  300. */
  301. my.ensurePeerContainerExists = function(peerJid) {
  302. ContactList.ensureAddContact(peerJid);
  303. var resourceJid = Strophe.getResourceFromJid(peerJid);
  304. var videoSpanId = 'participant_' + resourceJid;
  305. if ($('#' + videoSpanId).length > 0) {
  306. // If there's been a focus change, make sure we add focus related
  307. // interface!!
  308. if (focus && $('#remote_popupmenu_' + resourceJid).length <= 0)
  309. addRemoteVideoMenu( peerJid,
  310. document.getElementById(videoSpanId));
  311. }
  312. else {
  313. var container
  314. = VideoLayout.addRemoteVideoContainer(peerJid, videoSpanId);
  315. // Set default display name.
  316. setDisplayName(videoSpanId);
  317. VideoLayout.connectionIndicators[videoSpanId] = new ConnectionIndicator(container, peerJid);
  318. var nickfield = document.createElement('span');
  319. nickfield.className = "nick";
  320. nickfield.appendChild(document.createTextNode(resourceJid));
  321. container.appendChild(nickfield);
  322. // In case this is not currently in the last n we don't show it.
  323. if (lastNCount
  324. && lastNCount > 0
  325. && $('#remoteVideos>span').length >= lastNCount + 2) {
  326. showPeerContainer(resourceJid, false);
  327. }
  328. else
  329. VideoLayout.resizeThumbnails();
  330. }
  331. };
  332. my.addRemoteVideoContainer = function(peerJid, spanId) {
  333. var container = document.createElement('span');
  334. container.id = spanId;
  335. container.className = 'videocontainer';
  336. var remotes = document.getElementById('remoteVideos');
  337. // If the peerJid is null then this video span couldn't be directly
  338. // associated with a participant (this could happen in the case of prezi).
  339. if (focus && peerJid != null)
  340. addRemoteVideoMenu(peerJid, container);
  341. remotes.appendChild(container);
  342. AudioLevels.updateAudioLevelCanvas(peerJid);
  343. return container;
  344. };
  345. /**
  346. * Creates an audio or video stream element.
  347. */
  348. my.createStreamElement = function (sid, stream) {
  349. var isVideo = stream.getVideoTracks().length > 0;
  350. var element = isVideo
  351. ? document.createElement('video')
  352. : document.createElement('audio');
  353. var id = (isVideo ? 'remoteVideo_' : 'remoteAudio_')
  354. + sid + '_' + stream.id;
  355. element.id = id;
  356. element.autoplay = true;
  357. element.oncontextmenu = function () { return false; };
  358. return element;
  359. };
  360. my.addRemoteStreamElement
  361. = function (container, sid, stream, peerJid, thessrc) {
  362. var newElementId = null;
  363. var isVideo = stream.getVideoTracks().length > 0;
  364. if (container) {
  365. var streamElement = VideoLayout.createStreamElement(sid, stream);
  366. newElementId = streamElement.id;
  367. container.appendChild(streamElement);
  368. var sel = $('#' + newElementId);
  369. sel.hide();
  370. // If the container is currently visible we attach the stream.
  371. if (!isVideo
  372. || (container.offsetParent !== null && isVideo)) {
  373. var videoStream = simulcast.getReceivingVideoStream(stream);
  374. RTC.attachMediaStream(sel, videoStream);
  375. if (isVideo)
  376. waitForRemoteVideo(sel, thessrc, stream);
  377. }
  378. stream.onended = function () {
  379. console.log('stream ended', this);
  380. VideoLayout.removeRemoteStreamElement(
  381. stream, isVideo, container);
  382. if (peerJid)
  383. ContactList.removeContact(peerJid);
  384. };
  385. // Add click handler.
  386. container.onclick = function (event) {
  387. /*
  388. * FIXME It turns out that videoThumb may not exist (if there is
  389. * no actual video).
  390. */
  391. var videoThumb = $('#' + container.id + '>video').get(0);
  392. if (videoThumb)
  393. VideoLayout.handleVideoThumbClicked(videoThumb.src);
  394. event.preventDefault();
  395. return false;
  396. };
  397. // Add hover handler
  398. $(container).hover(
  399. function() {
  400. VideoLayout.showDisplayName(container.id, true);
  401. },
  402. function() {
  403. var videoSrc = null;
  404. if ($('#' + container.id + '>video')
  405. && $('#' + container.id + '>video').length > 0) {
  406. videoSrc = $('#' + container.id + '>video').get(0).src;
  407. }
  408. // If the video has been "pinned" by the user we want to
  409. // keep the display name on place.
  410. if (!VideoLayout.isLargeVideoVisible()
  411. || videoSrc !== $('#largeVideo').attr('src'))
  412. VideoLayout.showDisplayName(container.id, false);
  413. }
  414. );
  415. }
  416. return newElementId;
  417. };
  418. /**
  419. * Removes the remote stream element corresponding to the given stream and
  420. * parent container.
  421. *
  422. * @param stream the stream
  423. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  424. * @param container
  425. */
  426. my.removeRemoteStreamElement = function (stream, isVideo, container) {
  427. if (!container)
  428. return;
  429. var select = null;
  430. var removedVideoSrc = null;
  431. if (isVideo) {
  432. select = $('#' + container.id + '>video');
  433. removedVideoSrc = select.get(0).src;
  434. }
  435. else
  436. select = $('#' + container.id + '>audio');
  437. // Remove video source from the mapping.
  438. delete videoSrcToSsrc[removedVideoSrc];
  439. // Mark video as removed to cancel waiting loop(if video is removed
  440. // before has started)
  441. select.removed = true;
  442. select.remove();
  443. var audioCount = $('#' + container.id + '>audio').length;
  444. var videoCount = $('#' + container.id + '>video').length;
  445. if (!audioCount && !videoCount) {
  446. console.log("Remove whole user", container.id);
  447. if(VideoLayout.connectionIndicators[container.id])
  448. VideoLayout.connectionIndicators[container.id].remove();
  449. // Remove whole container
  450. container.remove();
  451. Util.playSoundNotification('userLeft');
  452. VideoLayout.resizeThumbnails();
  453. }
  454. if (removedVideoSrc)
  455. VideoLayout.updateRemovedVideo(removedVideoSrc);
  456. };
  457. /**
  458. * Show/hide peer container for the given resourceJid.
  459. */
  460. function showPeerContainer(resourceJid, isShow) {
  461. var peerContainer = $('#participant_' + resourceJid);
  462. if (!peerContainer)
  463. return;
  464. if (!peerContainer.is(':visible') && isShow)
  465. peerContainer.show();
  466. else if (peerContainer.is(':visible') && !isShow)
  467. {
  468. peerContainer.hide();
  469. if(VideoLayout.connectionIndicators['participant_' + resourceJid])
  470. VideoLayout.connectionIndicators['participant_' + resourceJid].hide();
  471. }
  472. VideoLayout.resizeThumbnails();
  473. ContactList.setClickable(resourceJid, isShow);
  474. };
  475. /**
  476. * Sets the display name for the given video span id.
  477. */
  478. function setDisplayName(videoSpanId, displayName) {
  479. var nameSpan = $('#' + videoSpanId + '>span.displayname');
  480. var defaultLocalDisplayName = "Me";
  481. // If we already have a display name for this video.
  482. if (nameSpan.length > 0) {
  483. var nameSpanElement = nameSpan.get(0);
  484. if (nameSpanElement.id === 'localDisplayName' &&
  485. $('#localDisplayName').text() !== displayName) {
  486. if (displayName && displayName.length > 0)
  487. $('#localDisplayName').text(displayName + ' (me)');
  488. else
  489. $('#localDisplayName').text(defaultLocalDisplayName);
  490. } else {
  491. if (displayName && displayName.length > 0)
  492. $('#' + videoSpanId + '_name').text(displayName);
  493. else
  494. $('#' + videoSpanId + '_name').text(interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  495. }
  496. } else {
  497. var editButton = null;
  498. nameSpan = document.createElement('span');
  499. nameSpan.className = 'displayname';
  500. $('#' + videoSpanId)[0].appendChild(nameSpan);
  501. if (videoSpanId === 'localVideoContainer') {
  502. editButton = createEditDisplayNameButton();
  503. nameSpan.innerText = defaultLocalDisplayName;
  504. }
  505. else {
  506. nameSpan.innerText = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  507. }
  508. if (displayName && displayName.length > 0) {
  509. nameSpan.innerText = displayName;
  510. }
  511. if (!editButton) {
  512. nameSpan.id = videoSpanId + '_name';
  513. } else {
  514. nameSpan.id = 'localDisplayName';
  515. $('#' + videoSpanId)[0].appendChild(editButton);
  516. var editableText = document.createElement('input');
  517. editableText.className = 'displayname';
  518. editableText.type = 'text';
  519. editableText.id = 'editDisplayName';
  520. if (displayName && displayName.length) {
  521. editableText.value
  522. = displayName.substring(0, displayName.indexOf(' (me)'));
  523. }
  524. editableText.setAttribute('style', 'display:none;');
  525. editableText.setAttribute('placeholder', 'ex. Jane Pink');
  526. $('#' + videoSpanId)[0].appendChild(editableText);
  527. $('#localVideoContainer .displayname')
  528. .bind("click", function (e) {
  529. e.preventDefault();
  530. $('#localDisplayName').hide();
  531. $('#editDisplayName').show();
  532. $('#editDisplayName').focus();
  533. $('#editDisplayName').select();
  534. $('#editDisplayName').one("focusout", function (e) {
  535. VideoLayout.inputDisplayNameHandler(this.value);
  536. });
  537. $('#editDisplayName').on('keydown', function (e) {
  538. if (e.keyCode === 13) {
  539. e.preventDefault();
  540. VideoLayout.inputDisplayNameHandler(this.value);
  541. }
  542. });
  543. });
  544. }
  545. }
  546. };
  547. my.inputDisplayNameHandler = function (name) {
  548. if (nickname !== name) {
  549. nickname = name;
  550. window.localStorage.displayname = nickname;
  551. connection.emuc.addDisplayNameToPresence(nickname);
  552. connection.emuc.sendPresence();
  553. Chat.setChatConversationMode(true);
  554. }
  555. if (!$('#localDisplayName').is(":visible")) {
  556. if (nickname)
  557. $('#localDisplayName').text(nickname + " (me)");
  558. else
  559. $('#localDisplayName')
  560. .text(defaultLocalDisplayName);
  561. $('#localDisplayName').show();
  562. }
  563. $('#editDisplayName').hide();
  564. };
  565. /**
  566. * Shows/hides the display name on the remote video.
  567. * @param videoSpanId the identifier of the video span element
  568. * @param isShow indicates if the display name should be shown or hidden
  569. */
  570. my.showDisplayName = function(videoSpanId, isShow) {
  571. var nameSpan = $('#' + videoSpanId + '>span.displayname').get(0);
  572. if (isShow) {
  573. if (nameSpan && nameSpan.innerHTML && nameSpan.innerHTML.length)
  574. nameSpan.setAttribute("style", "display:inline-block;");
  575. }
  576. else {
  577. if (nameSpan)
  578. nameSpan.setAttribute("style", "display:none;");
  579. }
  580. };
  581. /**
  582. * Shows the presence status message for the given video.
  583. */
  584. my.setPresenceStatus = function (videoSpanId, statusMsg) {
  585. if (!$('#' + videoSpanId).length) {
  586. // No container
  587. return;
  588. }
  589. var statusSpan = $('#' + videoSpanId + '>span.status');
  590. if (!statusSpan.length) {
  591. //Add status span
  592. statusSpan = document.createElement('span');
  593. statusSpan.className = 'status';
  594. statusSpan.id = videoSpanId + '_status';
  595. $('#' + videoSpanId)[0].appendChild(statusSpan);
  596. statusSpan = $('#' + videoSpanId + '>span.status');
  597. }
  598. // Display status
  599. if (statusMsg && statusMsg.length) {
  600. $('#' + videoSpanId + '_status').text(statusMsg);
  601. statusSpan.get(0).setAttribute("style", "display:inline-block;");
  602. }
  603. else {
  604. // Hide
  605. statusSpan.get(0).setAttribute("style", "display:none;");
  606. }
  607. };
  608. /**
  609. * Shows a visual indicator for the focus of the conference.
  610. * Currently if we're not the owner of the conference we obtain the focus
  611. * from the connection.jingle.sessions.
  612. */
  613. my.showFocusIndicator = function() {
  614. if (focus !== null) {
  615. var indicatorSpan = $('#localVideoContainer .focusindicator');
  616. if (indicatorSpan.children().length === 0)
  617. {
  618. createFocusIndicatorElement(indicatorSpan[0]);
  619. }
  620. }
  621. else if (Object.keys(connection.jingle.sessions).length > 0) {
  622. // If we're only a participant the focus will be the only session we have.
  623. var session
  624. = connection.jingle.sessions
  625. [Object.keys(connection.jingle.sessions)[0]];
  626. var focusId
  627. = 'participant_' + Strophe.getResourceFromJid(session.peerjid);
  628. var focusContainer = document.getElementById(focusId);
  629. if (!focusContainer) {
  630. console.error("No focus container!");
  631. return;
  632. }
  633. var indicatorSpan = $('#' + focusId + ' .focusindicator');
  634. if (!indicatorSpan || indicatorSpan.length === 0) {
  635. indicatorSpan = document.createElement('span');
  636. indicatorSpan.className = 'focusindicator';
  637. focusContainer.appendChild(indicatorSpan);
  638. createFocusIndicatorElement(indicatorSpan);
  639. }
  640. }
  641. };
  642. /**
  643. * Shows video muted indicator over small videos.
  644. */
  645. my.showVideoIndicator = function(videoSpanId, isMuted) {
  646. var videoMutedSpan = $('#' + videoSpanId + '>span.videoMuted');
  647. if (isMuted === 'false') {
  648. if (videoMutedSpan.length > 0) {
  649. videoMutedSpan.remove();
  650. }
  651. }
  652. else {
  653. if(videoMutedSpan.length == 0) {
  654. videoMutedSpan = document.createElement('span');
  655. videoMutedSpan.className = 'videoMuted';
  656. $('#' + videoSpanId)[0].appendChild(videoMutedSpan);
  657. var mutedIndicator = document.createElement('i');
  658. mutedIndicator.className = 'icon-camera-disabled';
  659. Util.setTooltip(mutedIndicator,
  660. "Participant has<br/>stopped the camera.",
  661. "top");
  662. videoMutedSpan.appendChild(mutedIndicator);
  663. }
  664. VideoLayout.updateMutePosition(videoSpanId);
  665. }
  666. };
  667. my.updateMutePosition = function (videoSpanId) {
  668. var audioMutedSpan = $('#' + videoSpanId + '>span.audioMuted');
  669. var connectionIndicator = $('#' + videoSpanId + '>div.connectionindicator');
  670. var videoMutedSpan = $('#' + videoSpanId + '>span.videoMuted');
  671. if(connectionIndicator.length > 0
  672. && connectionIndicator[0].style.display != "none") {
  673. audioMutedSpan.css({right: "23px"});
  674. videoMutedSpan.css({right: ((audioMutedSpan.length > 0? 23 : 0) + 30) + "px"});
  675. }
  676. else
  677. {
  678. audioMutedSpan.css({right: "0px"});
  679. videoMutedSpan.css({right: (audioMutedSpan.length > 0? 30 : 0) + "px"});
  680. }
  681. }
  682. /**
  683. * Shows audio muted indicator over small videos.
  684. * @param {string} isMuted
  685. */
  686. my.showAudioIndicator = function(videoSpanId, isMuted) {
  687. var audioMutedSpan = $('#' + videoSpanId + '>span.audioMuted');
  688. if (isMuted === 'false') {
  689. if (audioMutedSpan.length > 0) {
  690. audioMutedSpan.popover('hide');
  691. audioMutedSpan.remove();
  692. }
  693. }
  694. else {
  695. if(audioMutedSpan.length == 0 ) {
  696. audioMutedSpan = document.createElement('span');
  697. audioMutedSpan.className = 'audioMuted';
  698. Util.setTooltip(audioMutedSpan,
  699. "Participant is muted",
  700. "top");
  701. $('#' + videoSpanId)[0].appendChild(audioMutedSpan);
  702. var mutedIndicator = document.createElement('i');
  703. mutedIndicator.className = 'icon-mic-disabled';
  704. audioMutedSpan.appendChild(mutedIndicator);
  705. }
  706. VideoLayout.updateMutePosition(videoSpanId);
  707. }
  708. };
  709. /*
  710. * Shows or hides the audio muted indicator over the local thumbnail video.
  711. * @param {boolean} isMuted
  712. */
  713. my.showLocalAudioIndicator = function(isMuted) {
  714. VideoLayout.showAudioIndicator('localVideoContainer', isMuted.toString());
  715. };
  716. /**
  717. * Resizes the large video container.
  718. */
  719. my.resizeLargeVideoContainer = function () {
  720. Chat.resizeChat();
  721. var availableHeight = window.innerHeight;
  722. var availableWidth = Util.getAvailableVideoWidth();
  723. if (availableWidth < 0 || availableHeight < 0) return;
  724. $('#videospace').width(availableWidth);
  725. $('#videospace').height(availableHeight);
  726. $('#largeVideoContainer').width(availableWidth);
  727. $('#largeVideoContainer').height(availableHeight);
  728. VideoLayout.resizeThumbnails();
  729. };
  730. /**
  731. * Resizes thumbnails.
  732. */
  733. my.resizeThumbnails = function() {
  734. var videoSpaceWidth = $('#remoteVideos').width();
  735. var thumbnailSize = VideoLayout.calculateThumbnailSize(videoSpaceWidth);
  736. var width = thumbnailSize[0];
  737. var height = thumbnailSize[1];
  738. // size videos so that while keeping AR and max height, we have a
  739. // nice fit
  740. $('#remoteVideos').height(height);
  741. $('#remoteVideos>span').width(width);
  742. $('#remoteVideos>span').height(height);
  743. $(document).trigger("remotevideo.resized", [width, height]);
  744. };
  745. /**
  746. * Enables the dominant speaker UI.
  747. *
  748. * @param resourceJid the jid indicating the video element to
  749. * activate/deactivate
  750. * @param isEnable indicates if the dominant speaker should be enabled or
  751. * disabled
  752. */
  753. my.enableDominantSpeaker = function(resourceJid, isEnable) {
  754. var videoSpanId = null;
  755. var videoContainerId = null;
  756. if (resourceJid
  757. === Strophe.getResourceFromJid(connection.emuc.myroomjid)) {
  758. videoSpanId = 'localVideoWrapper';
  759. videoContainerId = 'localVideoContainer';
  760. }
  761. else {
  762. videoSpanId = 'participant_' + resourceJid;
  763. videoContainerId = videoSpanId;
  764. }
  765. var displayName = resourceJid;
  766. var nameSpan = $('#' + videoContainerId + '>span.displayname');
  767. if (nameSpan.length > 0)
  768. displayName = nameSpan.text();
  769. console.log("UI enable dominant speaker",
  770. displayName,
  771. resourceJid,
  772. isEnable);
  773. videoSpan = document.getElementById(videoContainerId);
  774. if (!videoSpan) {
  775. console.error("No video element for jid", resourceJid);
  776. return;
  777. }
  778. var video = $('#' + videoSpanId + '>video');
  779. if (video && video.length > 0) {
  780. if (isEnable) {
  781. VideoLayout.showDisplayName(videoContainerId, true);
  782. if (!videoSpan.classList.contains("dominantspeaker"))
  783. videoSpan.classList.add("dominantspeaker");
  784. video.css({visibility: 'hidden'});
  785. }
  786. else {
  787. VideoLayout.showDisplayName(videoContainerId, false);
  788. if (videoSpan.classList.contains("dominantspeaker"))
  789. videoSpan.classList.remove("dominantspeaker");
  790. video.css({visibility: 'visible'});
  791. }
  792. }
  793. };
  794. /**
  795. * Gets the selector of video thumbnail container for the user identified by
  796. * given <tt>userJid</tt>
  797. * @param userJid user's Jid for whom we want to get the video container.
  798. */
  799. function getParticipantContainer(userJid)
  800. {
  801. if (!userJid)
  802. return null;
  803. if (userJid === connection.emuc.myroomjid)
  804. return $("#localVideoContainer");
  805. else
  806. return $("#participant_" + Strophe.getResourceFromJid(userJid));
  807. }
  808. /**
  809. * Sets the size and position of the given video element.
  810. *
  811. * @param video the video element to position
  812. * @param width the desired video width
  813. * @param height the desired video height
  814. * @param horizontalIndent the left and right indent
  815. * @param verticalIndent the top and bottom indent
  816. */
  817. function positionVideo(video,
  818. width,
  819. height,
  820. horizontalIndent,
  821. verticalIndent) {
  822. video.width(width);
  823. video.height(height);
  824. video.css({ top: verticalIndent + 'px',
  825. bottom: verticalIndent + 'px',
  826. left: horizontalIndent + 'px',
  827. right: horizontalIndent + 'px'});
  828. }
  829. /**
  830. * Calculates the thumbnail size.
  831. *
  832. * @param videoSpaceWidth the width of the video space
  833. */
  834. my.calculateThumbnailSize = function (videoSpaceWidth) {
  835. // Calculate the available height, which is the inner window height minus
  836. // 39px for the header minus 2px for the delimiter lines on the top and
  837. // bottom of the large video, minus the 36px space inside the remoteVideos
  838. // container used for highlighting shadow.
  839. var availableHeight = 100;
  840. var numvids = $('#remoteVideos>span:visible').length;
  841. if (lastNCount && lastNCount > 0) {
  842. numvids = Math.min(lastNCount + 1, numvids);
  843. }
  844. // Remove the 3px borders arround videos and border around the remote
  845. // videos area and the 4 pixels between the local video and the others
  846. //TODO: Find out where the 4 pixels come from and remove them
  847. var availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
  848. var availableWidth = availableWinWidth / numvids;
  849. var aspectRatio = 16.0 / 9.0;
  850. var maxHeight = Math.min(160, availableHeight);
  851. availableHeight = Math.min(maxHeight, availableWidth / aspectRatio);
  852. if (availableHeight < availableWidth / aspectRatio) {
  853. availableWidth = Math.floor(availableHeight * aspectRatio);
  854. }
  855. return [availableWidth, availableHeight];
  856. };
  857. /**
  858. * Returns an array of the video dimensions, so that it keeps it's aspect
  859. * ratio and fits available area with it's larger dimension. This method
  860. * ensures that whole video will be visible and can leave empty areas.
  861. *
  862. * @return an array with 2 elements, the video width and the video height
  863. */
  864. function getDesktopVideoSize(videoWidth,
  865. videoHeight,
  866. videoSpaceWidth,
  867. videoSpaceHeight) {
  868. if (!videoWidth)
  869. videoWidth = currentVideoWidth;
  870. if (!videoHeight)
  871. videoHeight = currentVideoHeight;
  872. var aspectRatio = videoWidth / videoHeight;
  873. var availableWidth = Math.max(videoWidth, videoSpaceWidth);
  874. var availableHeight = Math.max(videoHeight, videoSpaceHeight);
  875. videoSpaceHeight -= $('#remoteVideos').outerHeight();
  876. if (availableWidth / aspectRatio >= videoSpaceHeight)
  877. {
  878. availableHeight = videoSpaceHeight;
  879. availableWidth = availableHeight * aspectRatio;
  880. }
  881. if (availableHeight * aspectRatio >= videoSpaceWidth)
  882. {
  883. availableWidth = videoSpaceWidth;
  884. availableHeight = availableWidth / aspectRatio;
  885. }
  886. return [availableWidth, availableHeight];
  887. }
  888. /**
  889. * Creates the edit display name button.
  890. *
  891. * @returns the edit button
  892. */
  893. function createEditDisplayNameButton() {
  894. var editButton = document.createElement('a');
  895. editButton.className = 'displayname';
  896. Util.setTooltip(editButton,
  897. 'Click to edit your<br/>display name',
  898. "top");
  899. editButton.innerHTML = '<i class="fa fa-pencil"></i>';
  900. return editButton;
  901. }
  902. /**
  903. * Creates the element indicating the focus of the conference.
  904. *
  905. * @param parentElement the parent element where the focus indicator will
  906. * be added
  907. */
  908. function createFocusIndicatorElement(parentElement) {
  909. var focusIndicator = document.createElement('i');
  910. focusIndicator.className = 'fa fa-star';
  911. parentElement.appendChild(focusIndicator);
  912. Util.setTooltip(parentElement,
  913. "The owner of<br/>this conference",
  914. "top");
  915. }
  916. /**
  917. * Updates the remote video menu.
  918. *
  919. * @param jid the jid indicating the video for which we're adding a menu.
  920. * @param isMuted indicates the current mute state
  921. */
  922. my.updateRemoteVideoMenu = function(jid, isMuted) {
  923. var muteMenuItem
  924. = $('#remote_popupmenu_'
  925. + Strophe.getResourceFromJid(jid)
  926. + '>li>a.mutelink');
  927. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  928. if (muteMenuItem.length) {
  929. var muteLink = muteMenuItem.get(0);
  930. if (isMuted === 'true') {
  931. muteLink.innerHTML = mutedIndicator + ' Muted';
  932. muteLink.className = 'mutelink disabled';
  933. }
  934. else {
  935. muteLink.innerHTML = mutedIndicator + ' Mute';
  936. muteLink.className = 'mutelink';
  937. }
  938. }
  939. };
  940. /**
  941. * Returns the current dominant speaker resource jid.
  942. */
  943. my.getDominantSpeakerResourceJid = function () {
  944. return currentDominantSpeaker;
  945. };
  946. /**
  947. * Returns the corresponding resource jid to the given peer container
  948. * DOM element.
  949. *
  950. * @return the corresponding resource jid to the given peer container
  951. * DOM element
  952. */
  953. my.getPeerContainerResourceJid = function (containerElement) {
  954. var i = containerElement.id.indexOf('participant_');
  955. if (i >= 0)
  956. return containerElement.id.substring(i + 12);
  957. };
  958. /**
  959. * Adds the remote video menu element for the given <tt>jid</tt> in the
  960. * given <tt>parentElement</tt>.
  961. *
  962. * @param jid the jid indicating the video for which we're adding a menu.
  963. * @param parentElement the parent element where this menu will be added
  964. */
  965. function addRemoteVideoMenu(jid, parentElement) {
  966. var spanElement = document.createElement('span');
  967. spanElement.className = 'remotevideomenu';
  968. parentElement.appendChild(spanElement);
  969. var menuElement = document.createElement('i');
  970. menuElement.className = 'fa fa-angle-down';
  971. menuElement.title = 'Remote user controls';
  972. spanElement.appendChild(menuElement);
  973. // <ul class="popupmenu">
  974. // <li><a href="#">Mute</a></li>
  975. // <li><a href="#">Eject</a></li>
  976. // </ul>
  977. var popupmenuElement = document.createElement('ul');
  978. popupmenuElement.className = 'popupmenu';
  979. popupmenuElement.id
  980. = 'remote_popupmenu_' + Strophe.getResourceFromJid(jid);
  981. spanElement.appendChild(popupmenuElement);
  982. var muteMenuItem = document.createElement('li');
  983. var muteLinkItem = document.createElement('a');
  984. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  985. if (!mutedAudios[jid]) {
  986. muteLinkItem.innerHTML = mutedIndicator + 'Mute';
  987. muteLinkItem.className = 'mutelink';
  988. }
  989. else {
  990. muteLinkItem.innerHTML = mutedIndicator + ' Muted';
  991. muteLinkItem.className = 'mutelink disabled';
  992. }
  993. muteLinkItem.onclick = function(){
  994. if ($(this).attr('disabled') != undefined) {
  995. event.preventDefault();
  996. }
  997. var isMute = !mutedAudios[jid];
  998. connection.moderate.setMute(jid, isMute);
  999. popupmenuElement.setAttribute('style', 'display:none;');
  1000. if (isMute) {
  1001. this.innerHTML = mutedIndicator + ' Muted';
  1002. this.className = 'mutelink disabled';
  1003. }
  1004. else {
  1005. this.innerHTML = mutedIndicator + ' Mute';
  1006. this.className = 'mutelink';
  1007. }
  1008. };
  1009. muteMenuItem.appendChild(muteLinkItem);
  1010. popupmenuElement.appendChild(muteMenuItem);
  1011. var ejectIndicator = "<i class='fa fa-eject'></i>";
  1012. var ejectMenuItem = document.createElement('li');
  1013. var ejectLinkItem = document.createElement('a');
  1014. ejectLinkItem.innerHTML = ejectIndicator + ' Kick out';
  1015. ejectLinkItem.onclick = function(){
  1016. connection.moderate.eject(jid);
  1017. popupmenuElement.setAttribute('style', 'display:none;');
  1018. };
  1019. ejectMenuItem.appendChild(ejectLinkItem);
  1020. popupmenuElement.appendChild(ejectMenuItem);
  1021. var paddingSpan = document.createElement('span');
  1022. paddingSpan.className = 'popupmenuPadding';
  1023. popupmenuElement.appendChild(paddingSpan);
  1024. }
  1025. /**
  1026. * On audio muted event.
  1027. */
  1028. $(document).bind('audiomuted.muc', function (event, jid, isMuted) {
  1029. if (jid === connection.emuc.myroomjid) {
  1030. // The local mute indicator is controlled locally
  1031. return;
  1032. }
  1033. VideoLayout.ensurePeerContainerExists(jid);
  1034. if (focus) {
  1035. mutedAudios[jid] = isMuted;
  1036. VideoLayout.updateRemoteVideoMenu(jid, isMuted);
  1037. }
  1038. var videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  1039. if (videoSpanId)
  1040. VideoLayout.showAudioIndicator(videoSpanId, isMuted);
  1041. });
  1042. /**
  1043. * On video muted event.
  1044. */
  1045. $(document).bind('videomuted.muc', function (event, jid, isMuted) {
  1046. var videoSpanId = null;
  1047. if (jid === connection.emuc.myroomjid) {
  1048. videoSpanId = 'localVideoContainer';
  1049. } else {
  1050. VideoLayout.ensurePeerContainerExists(jid);
  1051. videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  1052. }
  1053. if (videoSpanId)
  1054. VideoLayout.showVideoIndicator(videoSpanId, isMuted);
  1055. });
  1056. /**
  1057. * Display name changed.
  1058. */
  1059. $(document).bind('displaynamechanged',
  1060. function (event, jid, displayName, status) {
  1061. var name = null;
  1062. if (jid === 'localVideoContainer'
  1063. || jid === connection.emuc.myroomjid) {
  1064. name = nickname;
  1065. setDisplayName('localVideoContainer',
  1066. displayName);
  1067. } else {
  1068. VideoLayout.ensurePeerContainerExists(jid);
  1069. name = $('#participant_' + Strophe.getResourceFromJid(jid) + "_name").text();
  1070. setDisplayName(
  1071. 'participant_' + Strophe.getResourceFromJid(jid),
  1072. displayName,
  1073. status);
  1074. }
  1075. if(APIConnector.isEnabled() && APIConnector.isEventEnabled("displayNameChange"))
  1076. {
  1077. if(jid === 'localVideoContainer')
  1078. jid = connection.emuc.myroomjid;
  1079. if(!name || name != displayName)
  1080. APIConnector.triggerEvent("displayNameChange",{jid: jid, displayname: displayName});
  1081. }
  1082. });
  1083. /**
  1084. * On dominant speaker changed event.
  1085. */
  1086. $(document).bind('dominantspeakerchanged', function (event, resourceJid) {
  1087. // We ignore local user events.
  1088. if (resourceJid
  1089. === Strophe.getResourceFromJid(connection.emuc.myroomjid))
  1090. return;
  1091. // Update the current dominant speaker.
  1092. if (resourceJid !== currentDominantSpeaker) {
  1093. var oldSpeakerVideoSpanId = "participant_" + currentDominantSpeaker,
  1094. newSpeakerVideoSpanId = "participant_" + resourceJid;
  1095. if($("#" + oldSpeakerVideoSpanId + ">span.displayname").text() ===
  1096. interfaceConfig.DEFAULT_DOMINANT_SPEAKER_DISPLAY_NAME) {
  1097. setDisplayName(oldSpeakerVideoSpanId, null);
  1098. }
  1099. if($("#" + newSpeakerVideoSpanId + ">span.displayname").text() ===
  1100. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME) {
  1101. setDisplayName(newSpeakerVideoSpanId,
  1102. interfaceConfig.DEFAULT_DOMINANT_SPEAKER_DISPLAY_NAME);
  1103. }
  1104. currentDominantSpeaker = resourceJid;
  1105. } else {
  1106. return;
  1107. }
  1108. // Obtain container for new dominant speaker.
  1109. var container = document.getElementById(
  1110. 'participant_' + resourceJid);
  1111. // Local video will not have container found, but that's ok
  1112. // since we don't want to switch to local video.
  1113. if (container && !focusedVideoSrc)
  1114. {
  1115. var video = container.getElementsByTagName("video");
  1116. // Update the large video if the video source is already available,
  1117. // otherwise wait for the "videoactive.jingle" event.
  1118. if (video.length && video[0].currentTime > 0)
  1119. VideoLayout.updateLargeVideo(video[0].src);
  1120. }
  1121. });
  1122. /**
  1123. * On last N change event.
  1124. *
  1125. * @param event the event that notified us
  1126. * @param lastNEndpoints the list of last N endpoints
  1127. * @param endpointsEnteringLastN the list currently entering last N
  1128. * endpoints
  1129. */
  1130. $(document).bind('lastnchanged', function ( event,
  1131. lastNEndpoints,
  1132. endpointsEnteringLastN,
  1133. stream) {
  1134. if (lastNCount !== lastNEndpoints.length)
  1135. lastNCount = lastNEndpoints.length;
  1136. lastNEndpointsCache = lastNEndpoints;
  1137. $('#remoteVideos>span').each(function( index, element ) {
  1138. var resourceJid = VideoLayout.getPeerContainerResourceJid(element);
  1139. if (resourceJid
  1140. && lastNEndpoints.indexOf(resourceJid) < 0) {
  1141. console.log("Remove from last N", resourceJid);
  1142. showPeerContainer(resourceJid, false);
  1143. }
  1144. });
  1145. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  1146. endpointsEnteringLastN = lastNEndpoints;
  1147. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  1148. endpointsEnteringLastN.forEach(function (resourceJid) {
  1149. if (!$('#participant_' + resourceJid).is(':visible')) {
  1150. console.log("Add to last N", resourceJid);
  1151. showPeerContainer(resourceJid, true);
  1152. mediaStreams.some(function (mediaStream) {
  1153. if (mediaStream.peerjid
  1154. && Strophe.getResourceFromJid(mediaStream.peerjid)
  1155. === resourceJid
  1156. && mediaStream.type === mediaStream.VIDEO_TYPE) {
  1157. var sel = $('#participant_' + resourceJid + '>video');
  1158. var videoStream = simulcast.getReceivingVideoStream(mediaStream.stream);
  1159. RTC.attachMediaStream(sel, videoStream);
  1160. waitForRemoteVideo(
  1161. sel,
  1162. mediaStream.ssrc,
  1163. mediaStream.stream);
  1164. return true;
  1165. }
  1166. });
  1167. }
  1168. });
  1169. }
  1170. });
  1171. $(document).bind('videoactive.jingle', function (event, videoelem) {
  1172. if (videoelem.attr('id').indexOf('mixedmslabel') === -1) {
  1173. // ignore mixedmslabela0 and v0
  1174. videoelem.show();
  1175. VideoLayout.resizeThumbnails();
  1176. var videoParent = videoelem.parent();
  1177. var parentResourceJid = null;
  1178. if (videoParent)
  1179. parentResourceJid
  1180. = VideoLayout.getPeerContainerResourceJid(videoParent[0]);
  1181. // Update the large video to the last added video only if there's no
  1182. // current dominant or focused speaker or update it to the current
  1183. // dominant speaker.
  1184. if ((!focusedVideoSrc && !VideoLayout.getDominantSpeakerResourceJid())
  1185. || (parentResourceJid
  1186. && VideoLayout.getDominantSpeakerResourceJid()
  1187. === parentResourceJid)) {
  1188. VideoLayout.updateLargeVideo(videoelem.attr('src'), 1);
  1189. }
  1190. VideoLayout.showFocusIndicator();
  1191. }
  1192. });
  1193. $(document).bind('simulcastlayerschanging', function (event, endpointSimulcastLayers) {
  1194. endpointSimulcastLayers.forEach(function (esl) {
  1195. var primarySSRC = esl.simulcastLayer.primarySSRC;
  1196. // Get session and stream from primary ssrc.
  1197. var res = simulcast.getReceivingVideoStreamBySSRC(primarySSRC);
  1198. var session = res.session;
  1199. var electedStream = res.stream;
  1200. if (session && electedStream) {
  1201. var msid = simulcast.getRemoteVideoStreamIdBySSRC(primarySSRC);
  1202. console.info([esl, primarySSRC, msid, session, electedStream]);
  1203. var msidParts = msid.split(' ');
  1204. var selRemoteVideo = $(['#', 'remoteVideo_', session.sid, '_', msidParts[0]].join(''));
  1205. var preload = (ssrc2jid[videoSrcToSsrc[selRemoteVideo.attr('src')]]
  1206. == ssrc2jid[videoSrcToSsrc[largeVideoState.newSrc]]);
  1207. if (preload) {
  1208. if (largeVideoState.preload)
  1209. {
  1210. $(largeVideoState.preload).remove();
  1211. }
  1212. console.info('Preloading remote video');
  1213. largeVideoState.preload = $('<video autoplay></video>');
  1214. // ssrcs are unique in an rtp session
  1215. largeVideoState.preload_ssrc = primarySSRC;
  1216. var electedStreamUrl = webkitURL.createObjectURL(electedStream);
  1217. largeVideoState.preload
  1218. .attr('src', electedStreamUrl);
  1219. }
  1220. } else {
  1221. console.error('Could not find a stream or a session.', session, electedStream);
  1222. }
  1223. });
  1224. });
  1225. /**
  1226. * On simulcast layers changed event.
  1227. */
  1228. $(document).bind('simulcastlayerschanged', function (event, endpointSimulcastLayers) {
  1229. endpointSimulcastLayers.forEach(function (esl) {
  1230. var primarySSRC = esl.simulcastLayer.primarySSRC;
  1231. // Get session and stream from primary ssrc.
  1232. var res = simulcast.getReceivingVideoStreamBySSRC(primarySSRC);
  1233. var session = res.session;
  1234. var electedStream = res.stream;
  1235. if (session && electedStream) {
  1236. var msid = simulcast.getRemoteVideoStreamIdBySSRC(primarySSRC);
  1237. console.info('Switching simulcast substream.');
  1238. console.info([esl, primarySSRC, msid, session, electedStream]);
  1239. var msidParts = msid.split(' ');
  1240. var selRemoteVideo = $(['#', 'remoteVideo_', session.sid, '_', msidParts[0]].join(''));
  1241. var updateLargeVideo = (ssrc2jid[videoSrcToSsrc[selRemoteVideo.attr('src')]]
  1242. == ssrc2jid[videoSrcToSsrc[largeVideoState.newSrc]]);
  1243. var updateFocusedVideoSrc = (selRemoteVideo.attr('src') == focusedVideoSrc);
  1244. var electedStreamUrl;
  1245. if (largeVideoState.preload_ssrc == primarySSRC)
  1246. {
  1247. electedStreamUrl = $(largeVideoState.preload).attr('src');
  1248. }
  1249. else
  1250. {
  1251. if (largeVideoState.preload
  1252. && largeVideoState.preload != null) {
  1253. $(largeVideoState.preload).remove();
  1254. }
  1255. largeVideoState.preload_ssrc = 0;
  1256. electedStreamUrl = webkitURL.createObjectURL(electedStream);
  1257. }
  1258. selRemoteVideo.attr('src', electedStreamUrl);
  1259. videoSrcToSsrc[selRemoteVideo.attr('src')] = primarySSRC;
  1260. if (updateLargeVideo) {
  1261. VideoLayout.updateLargeVideo(electedStreamUrl);
  1262. }
  1263. if (updateFocusedVideoSrc) {
  1264. focusedVideoSrc = electedStreamUrl;
  1265. }
  1266. var jid = ssrc2jid[primarySSRC];
  1267. var videoId;
  1268. if(jid == connection.emuc.myroomjid)
  1269. {
  1270. videoId = "localVideoContainer";
  1271. }
  1272. else
  1273. {
  1274. videoId = "participant_" + Strophe.getResourceFromJid(jid);
  1275. }
  1276. var connectionIndicator = VideoLayout.connectionIndicators[videoId];
  1277. if(connectionIndicator)
  1278. connectionIndicator.updatePopoverData();
  1279. } else {
  1280. console.error('Could not find a stream or a session.', session, electedStream);
  1281. }
  1282. });
  1283. });
  1284. /**
  1285. * Constructs new connection indicator.
  1286. * @param videoContainer the video container associated with the indicator.
  1287. * @constructor
  1288. */
  1289. function ConnectionIndicator(videoContainer, jid)
  1290. {
  1291. this.videoContainer = videoContainer;
  1292. this.bandwidth = null;
  1293. this.packetLoss = null;
  1294. this.bitrate = null;
  1295. this.showMoreValue = false;
  1296. this.resolution = null;
  1297. this.transport = [];
  1298. this.popover = null;
  1299. this.jid = jid;
  1300. this.create();
  1301. }
  1302. /**
  1303. * Values for the connection quality
  1304. * @type {{98: string, 81: string, 64: string, 47: string, 30: string, 0: string}}
  1305. */
  1306. ConnectionIndicator.connectionQualityValues = {
  1307. 98: "18px", //full
  1308. 81: "15px",//4 bars
  1309. 64: "11px",//3 bars
  1310. 47: "7px",//2 bars
  1311. 30: "3px",//1 bar
  1312. 0: "0px"//empty
  1313. };
  1314. ConnectionIndicator.getIP = function(value)
  1315. {
  1316. return value.substring(0, value.lastIndexOf(":"));
  1317. };
  1318. ConnectionIndicator.getPort = function(value)
  1319. {
  1320. return value.substring(value.lastIndexOf(":") + 1, value.length);
  1321. };
  1322. ConnectionIndicator.getStringFromArray = function (array) {
  1323. var res = "";
  1324. for(var i = 0; i < array.length; i++)
  1325. {
  1326. res += (i == 0? "" : ", ") + array[i];
  1327. }
  1328. return res;
  1329. }
  1330. /**
  1331. * Generates the html content.
  1332. * @returns {string} the html content.
  1333. */
  1334. ConnectionIndicator.prototype.generateText = function () {
  1335. var downloadBitrate, uploadBitrate, packetLoss, resolution;
  1336. if(this.bitrate === null)
  1337. {
  1338. downloadBitrate = "N/A";
  1339. uploadBitrate = "N/A";
  1340. }
  1341. else
  1342. {
  1343. downloadBitrate = this.bitrate.download? this.bitrate.download + " Kbps" : "N/A";
  1344. uploadBitrate = this.bitrate.upload? this.bitrate.upload + " Kbps" : "N/A";
  1345. }
  1346. if(this.packetLoss === null)
  1347. {
  1348. packetLoss = "N/A";
  1349. }
  1350. else
  1351. {
  1352. packetLoss = "<span class='jitsipopover_green'>&darr;</span>" +
  1353. (this.packetLoss.download != null? this.packetLoss.download : "N/A") +
  1354. "% <span class='jitsipopover_orange'>&uarr;</span>" +
  1355. (this.packetLoss.upload != null? this.packetLoss.upload : "N/A") + "%";
  1356. }
  1357. var resolutionValue = null;
  1358. if(this.resolution)
  1359. {
  1360. var keys = Object.keys(this.resolution);
  1361. if(keys.length == 1)
  1362. {
  1363. for(var ssrc in this.resolution)
  1364. {
  1365. resolutionValue = this.resolution[ssrc];
  1366. }
  1367. }
  1368. else if(keys.length > 1)
  1369. {
  1370. var displayedSsrc = simulcast.getReceivingSSRC(this.jid);
  1371. resolutionValue = this.resolution[displayedSsrc];
  1372. }
  1373. }
  1374. if(this.jid==null)
  1375. {
  1376. resolution = "";
  1377. for(var i in this.resolution)
  1378. {
  1379. resolutionValue = this.resolution[i];
  1380. if(resolutionValue)
  1381. {
  1382. if(resolutionValue.height &&
  1383. resolutionValue.width)
  1384. {
  1385. resolution += (resolution == ""? "" : ", ")
  1386. + resolutionValue.width + "x" + resolutionValue.height;
  1387. }
  1388. }
  1389. }
  1390. }
  1391. else if(!resolutionValue ||
  1392. !resolutionValue.height ||
  1393. !resolutionValue.width)
  1394. {
  1395. resolution = "N/A";
  1396. }
  1397. else
  1398. {
  1399. resolution = resolutionValue.width + "x" + resolutionValue.height;
  1400. }
  1401. var result = "<table style='width:100%'><tr><td><span class='jitsipopover_blue'>Bitrate:</span></td><td><span class='jitsipopover_green'>&darr;</span>" +
  1402. downloadBitrate + " <span class='jitsipopover_orange'>&uarr;</span>" +
  1403. uploadBitrate + "</td></tr><tr><td>" +
  1404. "<tr><td><span class='jitsipopover_blue'>Packet loss: </span></td><td>" + packetLoss + "</td></tr><tr><td>" +
  1405. "<span class='jitsipopover_blue'>Resolution:</span></td><td>" + resolution + "</td></tr></table>";
  1406. if(this.videoContainer.id == "localVideoContainer")
  1407. result += "<div class=\"jitsipopover_showmore\" onclick = \"VideoLayout.connectionIndicators['" +
  1408. this.videoContainer.id + "'].showMore()\">" + (this.showMoreValue? "Show less" : "Show More") + "</div><br />";
  1409. if(this.showMoreValue)
  1410. {
  1411. var downloadBandwidth, uploadBandwidth, transport;
  1412. if(this.bandwidth === null)
  1413. {
  1414. downloadBandwidth = "N/A";
  1415. uploadBandwidth = "N/A";
  1416. }
  1417. else
  1418. {
  1419. downloadBandwidth = this.bandwidth.download? this.bandwidth.download + " Kbps" : "N/A";
  1420. uploadBandwidth = this.bandwidth.upload? this.bandwidth.upload + " Kbps" : "N/A";
  1421. }
  1422. if(!this.transport || this.transport.length === 0)
  1423. {
  1424. transport = "<tr><td><span class='jitsipopover_blue'>Address:</span></td><td> N/A</td></tr>";
  1425. }
  1426. else
  1427. {
  1428. var data = {remoteIP: [], localIP:[], remotePort:[], localPort:[]};
  1429. for(var i = 0; i < this.transport.length; i++)
  1430. {
  1431. var ip = ConnectionIndicator.getIP(this.transport[i].ip);
  1432. var port = ConnectionIndicator.getPort(this.transport[i].ip);
  1433. var localIP = ConnectionIndicator.getIP(this.transport[i].localip);
  1434. var localPort = ConnectionIndicator.getPort(this.transport[i].localip);
  1435. if(data.remoteIP.indexOf(ip) == -1)
  1436. {
  1437. data.remoteIP.push(ip);
  1438. }
  1439. if(data.remotePort.indexOf(port) == -1)
  1440. {
  1441. data.remotePort.push(port);
  1442. }
  1443. if(data.localIP.indexOf(localIP) == -1)
  1444. {
  1445. data.localIP.push(localIP);
  1446. }
  1447. if(data.localPort.indexOf(localPort) == -1)
  1448. {
  1449. data.localPort.push(localPort);
  1450. }
  1451. }
  1452. var localTransport = "<tr><td><span class='jitsipopover_blue'>Local address" +
  1453. (data.localIP.length > 1? "es" : "") + ": </span></td><td> " +
  1454. ConnectionIndicator.getStringFromArray(data.localIP) + "</td></tr>";
  1455. transport = "<tr><td><span class='jitsipopover_blue'>Remote address"+
  1456. (data.remoteIP.length > 1? "es" : "") + ":</span></td><td> " +
  1457. ConnectionIndicator.getStringFromArray(data.remoteIP) + "</td></tr>";
  1458. if(this.transport.length > 1)
  1459. {
  1460. transport += "<tr><td><span class='jitsipopover_blue'>Remote ports:</span></td><td>";
  1461. localTransport += "<tr><td><span class='jitsipopover_blue'>Local ports:</span></td><td>";
  1462. }
  1463. else
  1464. {
  1465. transport += "<tr><td><span class='jitsipopover_blue'>Remote port:</span></td><td>";
  1466. localTransport += "<tr><td><span class='jitsipopover_blue'>Local port:</span></td><td>";
  1467. }
  1468. transport += ConnectionIndicator.getStringFromArray(data.remotePort);
  1469. localTransport += ConnectionIndicator.getStringFromArray(data.localPort);
  1470. transport += "</td></tr>";
  1471. transport += localTransport + "</td></tr>";
  1472. transport +="<tr><td><span class='jitsipopover_blue'>Transport:</span></td><td>" + this.transport[0].type + "</td></tr>";
  1473. }
  1474. result += "<table style='width:100%'><tr><td><span class='jitsipopover_blue'>Estimated bandwidth:</span> </td><td>" +
  1475. "<span class='jitsipopover_green'>&darr;</span>" + downloadBandwidth +
  1476. " <span class='jitsipopover_orange'>&uarr;</span>" +
  1477. uploadBandwidth + "</td></tr>";
  1478. result += transport + "</table>";
  1479. }
  1480. return result;
  1481. };
  1482. /**
  1483. * Shows or hide the additional information.
  1484. */
  1485. ConnectionIndicator.prototype.showMore = function () {
  1486. this.showMoreValue = !this.showMoreValue;
  1487. this.updatePopoverData();
  1488. };
  1489. /**
  1490. * Creates the indicator
  1491. */
  1492. ConnectionIndicator.prototype.create = function () {
  1493. this.connectionIndicatorContainer = document.createElement("div");
  1494. this.connectionIndicatorContainer.className = "connectionindicator";
  1495. this.connectionIndicatorContainer.style.display = "none";
  1496. this.videoContainer.appendChild(this.connectionIndicatorContainer);
  1497. this.popover = new JitsiPopover($("#" + this.videoContainer.id + " > .connectionindicator"),
  1498. {content: "<div class=\"connection_info\">Come back here for " +
  1499. "connection information once the conference starts</div>", skin: "black"});
  1500. function createIcon(classes)
  1501. {
  1502. var icon = document.createElement("span");
  1503. for(var i in classes)
  1504. {
  1505. icon.classList.add(classes[i]);
  1506. }
  1507. icon.appendChild(document.createElement("i")).classList.add("icon-connection");
  1508. return icon;
  1509. }
  1510. this.emptyIcon = this.connectionIndicatorContainer.appendChild(
  1511. createIcon(["connection", "connection_empty"]));
  1512. this.fullIcon = this.connectionIndicatorContainer.appendChild(
  1513. createIcon(["connection", "connection_full"]));
  1514. };
  1515. /**
  1516. * Removes the indicator
  1517. */
  1518. ConnectionIndicator.prototype.remove = function()
  1519. {
  1520. this.connectionIndicatorContainer.remove();
  1521. this.popover.forceHide();
  1522. };
  1523. /**
  1524. * Updates the data of the indicator
  1525. * @param percent the percent of connection quality
  1526. * @param object the statistics data.
  1527. */
  1528. ConnectionIndicator.prototype.updateConnectionQuality = function (percent, object) {
  1529. if(percent === null)
  1530. {
  1531. this.connectionIndicatorContainer.style.display = "none";
  1532. this.popover.forceHide();
  1533. return;
  1534. }
  1535. else
  1536. {
  1537. if(this.connectionIndicatorContainer.style.display == "none") {
  1538. this.connectionIndicatorContainer.style.display = "block";
  1539. VideoLayout.updateMutePosition(this.videoContainer.id);
  1540. }
  1541. }
  1542. this.bandwidth = object.bandwidth;
  1543. this.bitrate = object.bitrate;
  1544. this.packetLoss = object.packetLoss;
  1545. this.transport = object.transport;
  1546. if(object.resolution)
  1547. {
  1548. this.resolution = object.resolution;
  1549. }
  1550. for(var quality in ConnectionIndicator.connectionQualityValues)
  1551. {
  1552. if(percent >= quality)
  1553. {
  1554. this.fullIcon.style.width = ConnectionIndicator.connectionQualityValues[quality];
  1555. }
  1556. }
  1557. this.updatePopoverData();
  1558. };
  1559. /**
  1560. * Updates the resolution
  1561. * @param resolution the new resolution
  1562. */
  1563. ConnectionIndicator.prototype.updateResolution = function (resolution) {
  1564. this.resolution = resolution;
  1565. this.updatePopoverData();
  1566. };
  1567. /**
  1568. * Updates the content of the popover
  1569. */
  1570. ConnectionIndicator.prototype.updatePopoverData = function () {
  1571. this.popover.updateContent("<div class=\"connection_info\">" + this.generateText() + "</div>");
  1572. };
  1573. /**
  1574. * Hides the popover
  1575. */
  1576. ConnectionIndicator.prototype.hide = function () {
  1577. this.popover.forceHide();
  1578. };
  1579. /**
  1580. * Hides the indicator
  1581. */
  1582. ConnectionIndicator.prototype.hideIndicator = function () {
  1583. this.connectionIndicatorContainer.style.display = "none";
  1584. if(this.popover)
  1585. this.popover.forceHide();
  1586. };
  1587. /**
  1588. * Updates the data for the indicator
  1589. * @param id the id of the indicator
  1590. * @param percent the percent for connection quality
  1591. * @param object the data
  1592. */
  1593. function updateStatsIndicator(id, percent, object) {
  1594. if(VideoLayout.connectionIndicators[id])
  1595. VideoLayout.connectionIndicators[id].updateConnectionQuality(percent, object);
  1596. }
  1597. /**
  1598. * Updates local stats
  1599. * @param percent
  1600. * @param object
  1601. */
  1602. my.updateLocalConnectionStats = function (percent, object) {
  1603. var resolution = null;
  1604. if(object.resolution !== null)
  1605. {
  1606. resolution = object.resolution;
  1607. object.resolution = resolution[connection.emuc.myroomjid];
  1608. delete resolution[connection.emuc.myroomjid];
  1609. }
  1610. updateStatsIndicator("localVideoContainer", percent, object);
  1611. for(var jid in resolution)
  1612. {
  1613. if(resolution[jid] === null)
  1614. continue;
  1615. var id = 'participant_' + Strophe.getResourceFromJid(jid);
  1616. if(VideoLayout.connectionIndicators[id])
  1617. {
  1618. VideoLayout.connectionIndicators[id].updateResolution(resolution[jid]);
  1619. }
  1620. }
  1621. };
  1622. /**
  1623. * Updates remote stats.
  1624. * @param jid the jid associated with the stats
  1625. * @param percent the connection quality percent
  1626. * @param object the stats data
  1627. */
  1628. my.updateConnectionStats = function (jid, percent, object) {
  1629. var resourceJid = Strophe.getResourceFromJid(jid);
  1630. var videoSpanId = 'participant_' + resourceJid;
  1631. updateStatsIndicator(videoSpanId, percent, object);
  1632. };
  1633. /**
  1634. * Removes the connection
  1635. * @param jid
  1636. */
  1637. my.removeConnectionIndicator = function (jid) {
  1638. if(VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)])
  1639. VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)].remove();
  1640. };
  1641. /**
  1642. * Hides the connection indicator
  1643. * @param jid
  1644. */
  1645. my.hideConnectionIndicator = function (jid) {
  1646. if(VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)])
  1647. VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)].hide();
  1648. };
  1649. /**
  1650. * Hides all the indicators
  1651. */
  1652. my.onStatsStop = function () {
  1653. for(var indicator in VideoLayout.connectionIndicators)
  1654. {
  1655. VideoLayout.connectionIndicators[indicator].hideIndicator();
  1656. }
  1657. };
  1658. return my;
  1659. }(VideoLayout || {}));