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

videolayout.js 72KB

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