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 72KB

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