Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

videolayout.js 70KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  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. var jid = connection.emuc.findJidFromResource(resourceJid);
  1143. messageHandler.notify(
  1144. connection.emuc.members[jid].displayName || 'Somebody',
  1145. 'lastN',
  1146. 'is out of dominant speakers'
  1147. );
  1148. showPeerContainer(resourceJid, false);
  1149. }
  1150. });
  1151. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  1152. endpointsEnteringLastN = lastNEndpoints;
  1153. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  1154. endpointsEnteringLastN.forEach(function (resourceJid) {
  1155. if (!$('#participant_' + resourceJid).is(':visible')) {
  1156. console.log("Add to last N", resourceJid);
  1157. var jid = connection.emuc.findJidFromResource(resourceJid);
  1158. messageHandler.notify(
  1159. connection.emuc.members[jid].displayName || 'Somebody',
  1160. 'lastN',
  1161. 'is in dominant speakers');
  1162. showPeerContainer(resourceJid, true);
  1163. mediaStreams.some(function (mediaStream) {
  1164. if (mediaStream.peerjid
  1165. && Strophe.getResourceFromJid(mediaStream.peerjid)
  1166. === resourceJid
  1167. && mediaStream.type === mediaStream.VIDEO_TYPE) {
  1168. var sel = $('#participant_' + resourceJid + '>video');
  1169. var videoStream = simulcast.getReceivingVideoStream(mediaStream.stream);
  1170. RTC.attachMediaStream(sel, videoStream);
  1171. waitForRemoteVideo(
  1172. sel,
  1173. mediaStream.ssrc,
  1174. mediaStream.stream);
  1175. return true;
  1176. }
  1177. });
  1178. }
  1179. });
  1180. }
  1181. });
  1182. $(document).bind('videoactive.jingle', function (event, videoelem) {
  1183. if (videoelem.attr('id').indexOf('mixedmslabel') === -1) {
  1184. // ignore mixedmslabela0 and v0
  1185. videoelem.show();
  1186. VideoLayout.resizeThumbnails();
  1187. var videoParent = videoelem.parent();
  1188. var parentResourceJid = null;
  1189. if (videoParent)
  1190. parentResourceJid
  1191. = VideoLayout.getPeerContainerResourceJid(videoParent[0]);
  1192. // Update the large video to the last added video only if there's no
  1193. // current dominant or focused speaker or update it to the current
  1194. // dominant speaker.
  1195. if ((!focusedVideoSrc && !VideoLayout.getDominantSpeakerResourceJid())
  1196. || (parentResourceJid
  1197. && VideoLayout.getDominantSpeakerResourceJid()
  1198. === parentResourceJid)) {
  1199. VideoLayout.updateLargeVideo(videoelem.attr('src'), 1);
  1200. }
  1201. VideoLayout.showFocusIndicator();
  1202. }
  1203. });
  1204. $(document).bind('simulcastlayerschanging', function (event, endpointSimulcastLayers) {
  1205. endpointSimulcastLayers.forEach(function (esl) {
  1206. var primarySSRC = esl.simulcastLayer.primarySSRC;
  1207. // Get session and stream from primary ssrc.
  1208. var res = simulcast.getReceivingVideoStreamBySSRC(primarySSRC);
  1209. var session = res.session;
  1210. var electedStream = res.stream;
  1211. if (session && electedStream) {
  1212. var msid = simulcast.getRemoteVideoStreamIdBySSRC(primarySSRC);
  1213. console.info([esl, primarySSRC, msid, session, electedStream]);
  1214. var msidParts = msid.split(' ');
  1215. var selRemoteVideo = $(['#', 'remoteVideo_', session.sid, '_', msidParts[0]].join(''));
  1216. var preload = (ssrc2jid[videoSrcToSsrc[selRemoteVideo.attr('src')]]
  1217. == ssrc2jid[videoSrcToSsrc[largeVideoState.newSrc]]);
  1218. if (preload) {
  1219. if (largeVideoState.preload)
  1220. {
  1221. $(largeVideoState.preload).remove();
  1222. }
  1223. console.info('Preloading remote video');
  1224. largeVideoState.preload = $('<video autoplay></video>');
  1225. // ssrcs are unique in an rtp session
  1226. largeVideoState.preload_ssrc = primarySSRC;
  1227. var electedStreamUrl = webkitURL.createObjectURL(electedStream);
  1228. largeVideoState.preload
  1229. .attr('src', electedStreamUrl);
  1230. }
  1231. } else {
  1232. console.error('Could not find a stream or a session.', session, electedStream);
  1233. }
  1234. });
  1235. });
  1236. /**
  1237. * On simulcast layers changed event.
  1238. */
  1239. $(document).bind('simulcastlayerschanged', function (event, endpointSimulcastLayers) {
  1240. endpointSimulcastLayers.forEach(function (esl) {
  1241. var primarySSRC = esl.simulcastLayer.primarySSRC;
  1242. // Get session and stream from primary ssrc.
  1243. var res = simulcast.getReceivingVideoStreamBySSRC(primarySSRC);
  1244. var session = res.session;
  1245. var electedStream = res.stream;
  1246. if (session && electedStream) {
  1247. var msid = simulcast.getRemoteVideoStreamIdBySSRC(primarySSRC);
  1248. console.info('Switching simulcast substream.');
  1249. console.info([esl, primarySSRC, msid, session, electedStream]);
  1250. var msidParts = msid.split(' ');
  1251. var selRemoteVideo = $(['#', 'remoteVideo_', session.sid, '_', msidParts[0]].join(''));
  1252. var updateLargeVideo = (ssrc2jid[videoSrcToSsrc[selRemoteVideo.attr('src')]]
  1253. == ssrc2jid[videoSrcToSsrc[largeVideoState.newSrc]]);
  1254. var updateFocusedVideoSrc = (selRemoteVideo.attr('src') == focusedVideoSrc);
  1255. var electedStreamUrl;
  1256. if (largeVideoState.preload_ssrc == primarySSRC)
  1257. {
  1258. electedStreamUrl = $(largeVideoState.preload).attr('src');
  1259. }
  1260. else
  1261. {
  1262. if (largeVideoState.preload
  1263. && largeVideoState.preload != null) {
  1264. $(largeVideoState.preload).remove();
  1265. }
  1266. largeVideoState.preload_ssrc = 0;
  1267. electedStreamUrl = webkitURL.createObjectURL(electedStream);
  1268. }
  1269. selRemoteVideo.attr('src', electedStreamUrl);
  1270. videoSrcToSsrc[selRemoteVideo.attr('src')] = primarySSRC;
  1271. if (updateLargeVideo) {
  1272. VideoLayout.updateLargeVideo(electedStreamUrl);
  1273. }
  1274. if (updateFocusedVideoSrc) {
  1275. focusedVideoSrc = electedStreamUrl;
  1276. }
  1277. var jid = ssrc2jid[primarySSRC];
  1278. var videoId;
  1279. if(jid == connection.emuc.myroomjid)
  1280. {
  1281. videoId = "localVideoContainer";
  1282. }
  1283. else
  1284. {
  1285. videoId = "participant_" + Strophe.getResourceFromJid(jid);
  1286. }
  1287. var connectionIndicator = VideoLayout.connectionIndicators[videoId];
  1288. if(connectionIndicator)
  1289. connectionIndicator.updatePopoverData();
  1290. } else {
  1291. console.error('Could not find a stream or a session.', session, electedStream);
  1292. }
  1293. });
  1294. });
  1295. /**
  1296. * Constructs new connection indicator.
  1297. * @param videoContainer the video container associated with the indicator.
  1298. * @constructor
  1299. */
  1300. function ConnectionIndicator(videoContainer, jid)
  1301. {
  1302. this.videoContainer = videoContainer;
  1303. this.bandwidth = null;
  1304. this.packetLoss = null;
  1305. this.bitrate = null;
  1306. this.showMoreValue = false;
  1307. this.resolution = null;
  1308. this.transport = [];
  1309. this.popover = null;
  1310. this.jid = jid;
  1311. this.create();
  1312. }
  1313. /**
  1314. * Values for the connection quality
  1315. * @type {{98: string, 81: string, 64: string, 47: string, 30: string, 0: string}}
  1316. */
  1317. ConnectionIndicator.connectionQualityValues = {
  1318. 98: "18px", //full
  1319. 81: "15px",//4 bars
  1320. 64: "11px",//3 bars
  1321. 47: "7px",//2 bars
  1322. 30: "3px",//1 bar
  1323. 0: "0px"//empty
  1324. };
  1325. ConnectionIndicator.getIP = function(value)
  1326. {
  1327. return value.substring(0, value.lastIndexOf(":"));
  1328. };
  1329. ConnectionIndicator.getPort = function(value)
  1330. {
  1331. return value.substring(value.lastIndexOf(":") + 1, value.length);
  1332. };
  1333. ConnectionIndicator.getStringFromArray = function (array) {
  1334. var res = "";
  1335. for(var i = 0; i < array.length; i++)
  1336. {
  1337. res += (i == 0? "" : ", ") + array[i];
  1338. }
  1339. return res;
  1340. }
  1341. /**
  1342. * Generates the html content.
  1343. * @returns {string} the html content.
  1344. */
  1345. ConnectionIndicator.prototype.generateText = function () {
  1346. var downloadBitrate, uploadBitrate, packetLoss, resolution;
  1347. if(this.bitrate === null)
  1348. {
  1349. downloadBitrate = "N/A";
  1350. uploadBitrate = "N/A";
  1351. }
  1352. else
  1353. {
  1354. downloadBitrate = this.bitrate.download? this.bitrate.download + " Kbps" : "N/A";
  1355. uploadBitrate = this.bitrate.upload? this.bitrate.upload + " Kbps" : "N/A";
  1356. }
  1357. if(this.packetLoss === null)
  1358. {
  1359. packetLoss = "N/A";
  1360. }
  1361. else
  1362. {
  1363. packetLoss = "<span class='jitsipopover_green'>&darr;</span>" +
  1364. (this.packetLoss.download != null? this.packetLoss.download : "N/A") +
  1365. "% <span class='jitsipopover_orange'>&uarr;</span>" +
  1366. (this.packetLoss.upload != null? this.packetLoss.upload : "N/A") + "%";
  1367. }
  1368. var resolutionValue = null;
  1369. if(this.resolution)
  1370. {
  1371. var keys = Object.keys(this.resolution);
  1372. if(keys.length == 1)
  1373. {
  1374. for(var ssrc in this.resolution)
  1375. {
  1376. resolutionValue = this.resolution[ssrc];
  1377. }
  1378. }
  1379. else if(keys.length > 1)
  1380. {
  1381. var displayedSsrc = simulcast.getReceivingSSRC(this.jid);
  1382. resolutionValue = this.resolution[displayedSsrc];
  1383. }
  1384. }
  1385. if(this.jid==null)
  1386. {
  1387. resolution = "";
  1388. for(var i in this.resolution)
  1389. {
  1390. resolutionValue = this.resolution[i];
  1391. if(resolutionValue)
  1392. {
  1393. if(resolutionValue.height &&
  1394. resolutionValue.width)
  1395. {
  1396. resolution += (resolution == ""? "" : ", ")
  1397. + resolutionValue.width + "x" + resolutionValue.height;
  1398. }
  1399. }
  1400. }
  1401. }
  1402. else if(!resolutionValue ||
  1403. !resolutionValue.height ||
  1404. !resolutionValue.width)
  1405. {
  1406. resolution = "N/A";
  1407. }
  1408. else
  1409. {
  1410. resolution = resolutionValue.width + "x" + resolutionValue.height;
  1411. }
  1412. var result = "<table style='width:100%'><tr><td><span class='jitsipopover_blue'>Bitrate:</span></td><td><span class='jitsipopover_green'>&darr;</span>" +
  1413. downloadBitrate + " <span class='jitsipopover_orange'>&uarr;</span>" +
  1414. uploadBitrate + "</td></tr><tr><td>" +
  1415. "<tr><td><span class='jitsipopover_blue'>Packet loss: </span></td><td>" + packetLoss + "</td></tr><tr><td>" +
  1416. "<span class='jitsipopover_blue'>Resolution:</span></td><td>" + resolution + "</td></tr></table>";
  1417. if(this.videoContainer.id == "localVideoContainer")
  1418. result += "<div class=\"jitsipopover_showmore\" onclick = \"VideoLayout.connectionIndicators['" +
  1419. this.videoContainer.id + "'].showMore()\">" + (this.showMoreValue? "Show less" : "Show More") + "</div><br />";
  1420. if(this.showMoreValue)
  1421. {
  1422. var downloadBandwidth, uploadBandwidth, transport;
  1423. if(this.bandwidth === null)
  1424. {
  1425. downloadBandwidth = "N/A";
  1426. uploadBandwidth = "N/A";
  1427. }
  1428. else
  1429. {
  1430. downloadBandwidth = this.bandwidth.download? this.bandwidth.download + " Kbps" : "N/A";
  1431. uploadBandwidth = this.bandwidth.upload? this.bandwidth.upload + " Kbps" : "N/A";
  1432. }
  1433. if(!this.transport || this.transport.length === 0)
  1434. {
  1435. transport = "<tr><td><span class='jitsipopover_blue'>Address:</span></td><td> N/A</td></tr>";
  1436. }
  1437. else
  1438. {
  1439. var data = {remoteIP: [], localIP:[], remotePort:[], localPort:[]};
  1440. for(var i = 0; i < this.transport.length; i++)
  1441. {
  1442. var ip = ConnectionIndicator.getIP(this.transport[i].ip);
  1443. var port = ConnectionIndicator.getPort(this.transport[i].ip);
  1444. var localIP = ConnectionIndicator.getIP(this.transport[i].localip);
  1445. var localPort = ConnectionIndicator.getPort(this.transport[i].localip);
  1446. if(data.remoteIP.indexOf(ip) == -1)
  1447. {
  1448. data.remoteIP.push(ip);
  1449. }
  1450. if(data.remotePort.indexOf(port) == -1)
  1451. {
  1452. data.remotePort.push(port);
  1453. }
  1454. if(data.localIP.indexOf(localIP) == -1)
  1455. {
  1456. data.localIP.push(localIP);
  1457. }
  1458. if(data.localPort.indexOf(localPort) == -1)
  1459. {
  1460. data.localPort.push(localPort);
  1461. }
  1462. }
  1463. var localTransport = "<tr><td><span class='jitsipopover_blue'>Local address" +
  1464. (data.localIP.length > 1? "es" : "") + ": </span></td><td> " +
  1465. ConnectionIndicator.getStringFromArray(data.localIP) + "</td></tr>";
  1466. transport = "<tr><td><span class='jitsipopover_blue'>Remote address"+
  1467. (data.remoteIP.length > 1? "es" : "") + ":</span></td><td> " +
  1468. ConnectionIndicator.getStringFromArray(data.remoteIP) + "</td></tr>";
  1469. if(this.transport.length > 1)
  1470. {
  1471. transport += "<tr><td><span class='jitsipopover_blue'>Remote ports:</span></td><td>";
  1472. localTransport += "<tr><td><span class='jitsipopover_blue'>Local ports:</span></td><td>";
  1473. }
  1474. else
  1475. {
  1476. transport += "<tr><td><span class='jitsipopover_blue'>Remote port:</span></td><td>";
  1477. localTransport += "<tr><td><span class='jitsipopover_blue'>Local port:</span></td><td>";
  1478. }
  1479. transport += ConnectionIndicator.getStringFromArray(data.remotePort);
  1480. localTransport += ConnectionIndicator.getStringFromArray(data.localPort);
  1481. transport += "</td></tr>";
  1482. transport += localTransport + "</td></tr>";
  1483. transport +="<tr><td><span class='jitsipopover_blue'>Transport:</span></td><td>" + this.transport[0].type + "</td></tr>";
  1484. }
  1485. result += "<table style='width:100%'><tr><td><span class='jitsipopover_blue'>Estimated bandwidth:</span> </td><td>" +
  1486. "<span class='jitsipopover_green'>&darr;</span>" + downloadBandwidth +
  1487. " <span class='jitsipopover_orange'>&uarr;</span>" +
  1488. uploadBandwidth + "</td></tr>";
  1489. result += transport + "</table>";
  1490. }
  1491. return result;
  1492. };
  1493. /**
  1494. * Shows or hide the additional information.
  1495. */
  1496. ConnectionIndicator.prototype.showMore = function () {
  1497. this.showMoreValue = !this.showMoreValue;
  1498. this.updatePopoverData();
  1499. };
  1500. /**
  1501. * Creates the indicator
  1502. */
  1503. ConnectionIndicator.prototype.create = function () {
  1504. this.connectionIndicatorContainer = document.createElement("div");
  1505. this.connectionIndicatorContainer.className = "connectionindicator";
  1506. this.connectionIndicatorContainer.style.display = "none";
  1507. this.videoContainer.appendChild(this.connectionIndicatorContainer);
  1508. this.popover = new JitsiPopover($("#" + this.videoContainer.id + " > .connectionindicator"),
  1509. {content: "<div class=\"connection_info\">Come back here for " +
  1510. "connection information once the conference starts</div>", skin: "black"});
  1511. function createIcon(classes)
  1512. {
  1513. var icon = document.createElement("span");
  1514. for(var i in classes)
  1515. {
  1516. icon.classList.add(classes[i]);
  1517. }
  1518. icon.appendChild(document.createElement("i")).classList.add("icon-connection");
  1519. return icon;
  1520. }
  1521. this.emptyIcon = this.connectionIndicatorContainer.appendChild(
  1522. createIcon(["connection", "connection_empty"]));
  1523. this.fullIcon = this.connectionIndicatorContainer.appendChild(
  1524. createIcon(["connection", "connection_full"]));
  1525. };
  1526. /**
  1527. * Removes the indicator
  1528. */
  1529. ConnectionIndicator.prototype.remove = function()
  1530. {
  1531. this.connectionIndicatorContainer.remove();
  1532. this.popover.forceHide();
  1533. };
  1534. /**
  1535. * Updates the data of the indicator
  1536. * @param percent the percent of connection quality
  1537. * @param object the statistics data.
  1538. */
  1539. ConnectionIndicator.prototype.updateConnectionQuality = function (percent, object) {
  1540. if(percent === null)
  1541. {
  1542. this.connectionIndicatorContainer.style.display = "none";
  1543. this.popover.forceHide();
  1544. return;
  1545. }
  1546. else
  1547. {
  1548. if(this.connectionIndicatorContainer.style.display == "none") {
  1549. this.connectionIndicatorContainer.style.display = "block";
  1550. VideoLayout.updateMutePosition(this.videoContainer.id);
  1551. }
  1552. }
  1553. this.bandwidth = object.bandwidth;
  1554. this.bitrate = object.bitrate;
  1555. this.packetLoss = object.packetLoss;
  1556. this.transport = object.transport;
  1557. if(object.resolution)
  1558. {
  1559. this.resolution = object.resolution;
  1560. }
  1561. for(var quality in ConnectionIndicator.connectionQualityValues)
  1562. {
  1563. if(percent >= quality)
  1564. {
  1565. this.fullIcon.style.width = ConnectionIndicator.connectionQualityValues[quality];
  1566. }
  1567. }
  1568. this.updatePopoverData();
  1569. };
  1570. /**
  1571. * Updates the resolution
  1572. * @param resolution the new resolution
  1573. */
  1574. ConnectionIndicator.prototype.updateResolution = function (resolution) {
  1575. this.resolution = resolution;
  1576. this.updatePopoverData();
  1577. };
  1578. /**
  1579. * Updates the content of the popover
  1580. */
  1581. ConnectionIndicator.prototype.updatePopoverData = function () {
  1582. this.popover.updateContent("<div class=\"connection_info\">" + this.generateText() + "</div>");
  1583. };
  1584. /**
  1585. * Hides the popover
  1586. */
  1587. ConnectionIndicator.prototype.hide = function () {
  1588. this.popover.forceHide();
  1589. };
  1590. /**
  1591. * Hides the indicator
  1592. */
  1593. ConnectionIndicator.prototype.hideIndicator = function () {
  1594. this.connectionIndicatorContainer.style.display = "none";
  1595. if(this.popover)
  1596. this.popover.forceHide();
  1597. };
  1598. /**
  1599. * Updates the data for the indicator
  1600. * @param id the id of the indicator
  1601. * @param percent the percent for connection quality
  1602. * @param object the data
  1603. */
  1604. function updateStatsIndicator(id, percent, object) {
  1605. if(VideoLayout.connectionIndicators[id])
  1606. VideoLayout.connectionIndicators[id].updateConnectionQuality(percent, object);
  1607. }
  1608. /**
  1609. * Updates local stats
  1610. * @param percent
  1611. * @param object
  1612. */
  1613. my.updateLocalConnectionStats = function (percent, object) {
  1614. var resolution = null;
  1615. if(object.resolution !== null)
  1616. {
  1617. resolution = object.resolution;
  1618. object.resolution = resolution[connection.emuc.myroomjid];
  1619. delete resolution[connection.emuc.myroomjid];
  1620. }
  1621. updateStatsIndicator("localVideoContainer", percent, object);
  1622. for(var jid in resolution)
  1623. {
  1624. if(resolution[jid] === null)
  1625. continue;
  1626. var id = 'participant_' + Strophe.getResourceFromJid(jid);
  1627. if(VideoLayout.connectionIndicators[id])
  1628. {
  1629. VideoLayout.connectionIndicators[id].updateResolution(resolution[jid]);
  1630. }
  1631. }
  1632. };
  1633. /**
  1634. * Updates remote stats.
  1635. * @param jid the jid associated with the stats
  1636. * @param percent the connection quality percent
  1637. * @param object the stats data
  1638. */
  1639. my.updateConnectionStats = function (jid, percent, object) {
  1640. var resourceJid = Strophe.getResourceFromJid(jid);
  1641. var videoSpanId = 'participant_' + resourceJid;
  1642. updateStatsIndicator(videoSpanId, percent, object);
  1643. };
  1644. /**
  1645. * Removes the connection
  1646. * @param jid
  1647. */
  1648. my.removeConnectionIndicator = function (jid) {
  1649. if(VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)])
  1650. VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)].remove();
  1651. };
  1652. /**
  1653. * Hides the connection indicator
  1654. * @param jid
  1655. */
  1656. my.hideConnectionIndicator = function (jid) {
  1657. if(VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)])
  1658. VideoLayout.connectionIndicators['participant_' + Strophe.getResourceFromJid(jid)].hide();
  1659. };
  1660. /**
  1661. * Hides all the indicators
  1662. */
  1663. my.onStatsStop = function () {
  1664. for(var indicator in VideoLayout.connectionIndicators)
  1665. {
  1666. VideoLayout.connectionIndicators[indicator].hideIndicator();
  1667. }
  1668. };
  1669. return my;
  1670. }(VideoLayout || {}));