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

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